* move stuff from Hdr into substruct that may be easily wiped by memset 0'ing them
[citadel.git] / webcit / rss.c
index d17fe3896eaa5c3fd192663a655ebac41b4a766e..08d90cd289244e6ece582ce264f72c2aef7bed76 100644 (file)
@@ -12,7 +12,6 @@
 #define ALLOW_ANON_RSS 0
 #define ANON_RSS_USER ""
 #define ANON_RSS_PASS ""
-time_t if_modified_since;    /**< the last modified stamp */
 
 /*
  * view rss Config menu
@@ -43,8 +42,10 @@ void display_rss_control(char *reply_to, char *subject)
  * roomname the room we sould print out as rss 
  * request_method the way the rss is requested????
  */
-void display_rss(char *roomname, StrBuf *request_method)
+void display_rss(void)
 {
+       message_summary *Msg;
+       wcsession *WCC = WC;
        int nummsgs;
        int a, b;
        int bq = 0;
@@ -58,6 +59,7 @@ void display_rss(char *roomname, StrBuf *request_method)
        size_t obuflen;               /**< Length of output buffer              */
        char *osav;                   /**< Saved pointer to output buffer       */
 #endif
+       char description[SIZ] = "";
        char buf[SIZ];
        char date[30];
        char from[256];
@@ -71,21 +73,30 @@ void display_rss(char *roomname, StrBuf *request_method)
        char content_type[256];
        char charset[256];
        
-       if (!WC->logged_in) {
+       if (!WCC->logged_in) {
                #ifdef ALLOW_ANON_RSS
+               StrBuf *User;
+               StrBuf *Pass;
+               StrBuf *Buf;
                serv_printf("USER %s", ANON_RSS_USER);
                serv_getln(buf, sizeof buf);
                serv_printf("PASS %s", ANON_RSS_PASS);
-               serv_getln(buf, sizeof buf);
-               become_logged_in(ANON_RSS_USER, ANON_RSS_PASS, buf);
-               WC->killthis = 1;
+
+               StrBuf_ServGetln(Buf);
+               User = NewStrBufPlain(HKEY(ANON_RSS_USER));
+               Pass = NewStrBufPlain(HKEY(ANON_RSS_PASS));
+               become_logged_in(User, Pass, Buf);
+               WCC->killthis = 1;
+               FreeStrBuf(&User);
+               FreeStrBuf(&Pass);
+               FreeStrBuf(&Buf);
                #else
                authorization_required(_("Not logged in"));
                return;
                #endif
        }
 
-       if (gotoroom((char *)roomname)) {
+       if (gotoroom(WCC->Hdr->HR.ReqLine)) {
                lprintf(3, "RSS: Can't goto requested room\n");
                hprintf("HTTP/1.1 404 Not Found\r\n");
                hprintf("Content-Type: text/html\r\n");
@@ -106,7 +117,9 @@ void display_rss(char *roomname, StrBuf *request_method)
        
 
        /** Read time of last message immediately */
-       serv_printf("MSG4 %ld", WC->msgarr[nummsgs - 1]);
+       Msg = GetMessagePtrAt(nummsgs - 1, WCC->summ);
+
+       serv_printf("MSG4 %ld", (Msg==NULL)? 0 : Msg->msgnum);
        serv_getln(buf, sizeof buf);
        if (buf[0] == '1') {
                while (serv_getln(buf, sizeof buf), strcasecmp(buf, "000")) {
@@ -120,8 +133,8 @@ void display_rss(char *roomname, StrBuf *request_method)
                        }
                }
        }
-       // Commented out. Play dumb for now, also doesn't work with anonrss hack
-       /* if (if_modified_since > 0 && if_modified_since > now) {
+       /*/ Commented out. Play dumb for now, also doesn't work with anonrss hack */
+       /* if (WCC->Hdr->if_modified_since > 0 && WCC->Hdr->if_modified_since > now) {
                lprintf(3, "RSS: Feed not updated since the last time you looked\n");
                hprintf("HTTP/1.1 304 Not Modified\r\n");
                hprintf("Last-Modified: %s\r\n", date);
@@ -129,10 +142,10 @@ void display_rss(char *roomname, StrBuf *request_method)
                gmtime_r(&now, &now_tm);
                strftime(date, sizeof date, "%a, %d %b %Y %H:%M:%S GMT", &now_tm);
                hprintf("Date: %s\r\n", date);
-               if (*msgn) hprintf("ETag: %s\r\n", msgn); */
+               if (*msgn) hprintf("ETag: %s\r\n", msgn); * /
                // wDumpContent(0);
                // return;
-       //} 
+               //} */
 
        /* Do RSS header */
        lprintf(3, "RSS: Yum yum! This feed is tasty!\n");
@@ -142,21 +155,20 @@ void display_rss(char *roomname, StrBuf *request_method)
        hprintf("Content-Type: application/rss+xml\r\n");
        hprintf("Server: %s\r\n", PACKAGE_STRING);
        hprintf("Connection: close\r\n");
-       if (!strcasecmp(ChrPtr(request_method), "HEAD"))
+       if (WCC->Hdr->HR.eReqType == eHEAD)
                return;
 
        /* <?xml.. etc confuses our subst parser, so do it here */
        svput("XML_HEAD", WCS_STRING, "<?xml version=\"1.0\" ?>");
        svput("XML_STYLE", WCS_STRING, "<?xml-stylesheet type=\"text/css\" href=\"/static/rss_browser.css\" ?>");
-       svput("ROOM", WCS_STRING, WC->wc_roomname);
-       svput("NODE", WCS_STRING, serv_info.serv_humannode);
-       // Fix me
-       svprintf(HKEY("ROOM_LINK"), WCS_STRING, "%s://%s/", (is_https ? "https" : "http"), WC->http_host);
+       SVPutBuf("ROOM", WCC->wc_roomname, 1);
+       SVPutBuf("NODE", WCC->serv_info->serv_humannode, 1);
+       /* TODO:  Fix me */
+       svprintf(HKEY("ROOM_LINK"), WCS_STRING, "%s://%s/", (is_https ? "https" : "http"), ChrPtr(WCC->Hdr->HR.http_host));
        
        /** Get room info for description */
        serv_puts("RINF");
        serv_getln(buf, sizeof buf);
-       char description[SIZ] = "";
        if (buf[0] == '1') {
                while (1) {
                        serv_getln(buf, sizeof buf);
@@ -175,7 +187,8 @@ void display_rss(char *roomname, StrBuf *request_method)
        /** Read all messages and output as RSS items */
        for (a = 0; a < nummsgs; ++a) {
                /** Read message and output each as RSS item */
-               serv_printf("MSG4 %ld", WC->msgarr[a]);
+               Msg = GetMessagePtrAt(a, WCC->summ);
+               serv_printf("MSG4 %ld", (Msg==NULL)? 0 : Msg->msgnum);
                serv_getln(buf, sizeof buf);
                if (buf[0] != '1') continue;
 
@@ -219,7 +232,7 @@ void display_rss(char *roomname, StrBuf *request_method)
                        svput("SUBJ", WCS_STRING, _("From"));
                }
                svprintf(HKEY("IN_ROOM"), WCS_STRING, _("%s in %s"), from, room);
-               if (strcmp(hnod, serv_info.serv_humannode) && !IsEmptyStr(hnod)) {
+               if (strcmp(hnod, ChrPtr(WCC->serv_info->serv_humannode)) && !IsEmptyStr(hnod)) {
                        svprintf(HKEY("NODE"), WCS_STRING, _(" on %s"), hnod);
                }
                if (now) {
@@ -334,11 +347,13 @@ void display_rss(char *roomname, StrBuf *request_method)
                } 
                /** HTML is fun, but we've got to strip it first */
                else if (!strcasecmp(content_type, "text/html")) {
-                       output_html(charset, 0, WC->msgarr[a], NULL,  NULL); 
+                       Msg = GetMessagePtrAt(a, WCC->summ);
+
+                       output_html(charset, 0, (Msg==NULL)? 0 : Msg->msgnum, NULL,  NULL); 
                } 
 
 ENDBODY:
-               //wprintf("   </item>\n");
+               /* wprintf("   </item>\n"); */
                do_template("rss_item_end", NULL);
 ENDITEM:
                now = 0L;
@@ -354,3 +369,10 @@ ENDITEM:
 }
 
 
+void 
+InitModule_RSS
+(void)
+{
+       WebcitAddUrlHandler(HKEY("do_welcome"), display_rss, COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
+
+}