if StrBuf_ServGetln() is called in a loop, its return value has to be checked for...
[citadel.git] / webcit / who.c
index 1c19f775796badd2400a7fe9ed6315ced801cff6..9fdd9a90b53838f47377cde67ad00a520bee23eb 100644 (file)
@@ -1,6 +1,3 @@
-/*
- * $Id$
- */
 
 #include "webcit.h"
 
@@ -51,7 +48,10 @@ int GetWholistSection(HashList *List, time_t now, StrBuf *Buf)
        serv_puts("RWHO");
        StrBuf_ServGetln(Buf);
        if (GetServerStatus(Buf, NULL) == 1) {
-               while (BufLen = StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
+               while (BufLen = StrBuf_ServGetln(Buf), 
+                      ((BufLen >= 0) && 
+                       ((BufLen != 3) || strcmp(ChrPtr(Buf), "000"))))
+               {
                        if (BufLen <= 0)
                            continue;
                        Pos = NULL;
@@ -148,58 +148,58 @@ void edit_me(void)
        } else {
                output_headers(1, 1, 0, 0, 0, 0);
 
-               wprintf("<div id=\"banner\">\n");
-               wprintf("<table class=\"who_banner\"><tr><td>");
-               wprintf("<span class=\"titlebar\">");
-               wprintf(_("Edit your session display"));
-               wprintf("</span></td></tr></table>\n");
-               wprintf("</div>\n<div id=\"content\">\n");
+               wc_printf("<div id=\"banner\">\n");
+               wc_printf("<table class=\"who_banner\"><tr><td>");
+               wc_printf("<span class=\"titlebar\">");
+               wc_printf(_("Edit your session display"));
+               wc_printf("</span></td></tr></table>\n");
+               wc_printf("</div>\n<div id=\"content\">\n");
 
-               wprintf(_("This screen allows you to change the way your "
+               wc_printf(_("This screen allows you to change the way your "
                        "session appears in the 'Who is online' listing. "
                        "To turn off any 'fake' name you've previously "
                        "set, simply click the appropriate 'change' button "
                        "without typing anything in the corresponding box. "));
-               wprintf("<br />\n");
+               wc_printf("<br>\n");
 
-               wprintf("<form method=\"POST\" action=\"edit_me\">\n");
-               wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
+               wc_printf("<form method=\"POST\" action=\"edit_me\">\n");
+               wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
 
-               wprintf("<table border=0 width=100%%>\n");
+               wc_printf("<table border=0 width=100%%>\n");
 
-               wprintf("<tr><td><b>");
-               wprintf(_("Room name:"));
-               wprintf("</b></td>\n<td>");
-               wprintf("<input type=\"text\" name=\"fake_roomname\" maxlength=\"64\">\n");
-               wprintf("</td>\n<td align=center>");
-               wprintf("<input type=\"submit\" name=\"change_room_name_button\" value=\"%s\">",
+               wc_printf("<tr><td><b>");
+               wc_printf(_("Room name:"));
+               wc_printf("</b></td>\n<td>");
+               wc_printf("<input type=\"text\" name=\"fake_roomname\" maxlength=\"64\">\n");
+               wc_printf("</td>\n<td align=center>");
+               wc_printf("<input type=\"submit\" name=\"change_room_name_button\" value=\"%s\">",
                        _("Change room name"));
-               wprintf("</td>\n</tr>\n");
-
-               wprintf("<tr><td><b>");
-               wprintf(_("Host name:"));
-               wprintf("</b></td><td>");
-               wprintf("<input type=\"text\" name=\"fake_hostname\" maxlength=\"64\">\n");
-               wprintf("</td>\n<td align=center>");
-               wprintf("<input type=\"submit\" name=\"change_host_name_button\" value=\"%s\">",
+               wc_printf("</td>\n</tr>\n");
+
+               wc_printf("<tr><td><b>");
+               wc_printf(_("Host name:"));
+               wc_printf("</b></td><td>");
+               wc_printf("<input type=\"text\" name=\"fake_hostname\" maxlength=\"64\">\n");
+               wc_printf("</td>\n<td align=center>");
+               wc_printf("<input type=\"submit\" name=\"change_host_name_button\" value=\"%s\">",
                        _("Change host name"));
-               wprintf("</td>\n</tr>\n");
+               wc_printf("</td>\n</tr>\n");
 
                if (WC->is_aide) {
-                       wprintf("<tr><td><b>");
-                       wprintf(_("User name:"));
-                       wprintf("</b></td><td>");
-                       wprintf("<input type=\"text\" name=\"fake_username\" maxlength=\"64\">\n");
-                       wprintf("</td>\n<td align=center>");
-                       wprintf("<input type=\"submit\" name \"change_user_name_button\" value=\"%s\">",
+                       wc_printf("<tr><td><b>");
+                       wc_printf(_("User name:"));
+                       wc_printf("</b></td><td>");
+                       wc_printf("<input type=\"text\" name=\"fake_username\" maxlength=\"64\">\n");
+                       wc_printf("</td>\n<td align=center>");
+                       wc_printf("<input type=\"submit\" name \"change_user_name_button\" value=\"%s\">",
                                _("Change user name"));
-                       wprintf("</td>\n</tr>\n");
+                       wc_printf("</td>\n</tr>\n");
                }
-               wprintf("<tr><td> </td><td> </td><td align=center>");
-               wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">",
+               wc_printf("<tr><td> </td><td> </td><td align=center>");
+               wc_printf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">",
                        _("Cancel"));
-               wprintf("</td></tr></table>\n");
-               wprintf("</form></center>\n");
+               wc_printf("</td></tr></table>\n");
+               wc_printf("</form></center>\n");
                wDumpContent(1);
        }
 }
@@ -274,6 +274,11 @@ void tmplput_who_realhost(StrBuf *Target, WCTemplputParams *TP)
        UserStateStruct *User = (UserStateStruct*) CTX;
        StrBufAppendTemplate(Target, TP, User->RealHost, 0);
 }
+int conditional_who_realhost(StrBuf *Target, WCTemplputParams *TP)
+{
+       UserStateStruct *User = (UserStateStruct*) CTX;
+       return StrLength(User->RealHost) > 0;
+}
 
 void tmplput_who_lastactive(StrBuf *Target, WCTemplputParams *TP)
 {
@@ -321,24 +326,27 @@ void
 InitModule_WHO
 (void)
 {
-       WebcitAddUrlHandler(HKEY("terminate_session"), _terminate_session, 0);
-       WebcitAddUrlHandler(HKEY("edit_me"), edit_me, 0);
+       
+
+       WebcitAddUrlHandler(HKEY("terminate_session"), "", 0, _terminate_session, 0);
+       WebcitAddUrlHandler(HKEY("edit_me"), "", 0, edit_me, 0);
 
        RegisterIterator("WHOLIST", 0, NULL, GetWholistHash, NULL, DeleteWholistHash, CTX_WHO, CTX_NONE, IT_NOFLAG);
 
-       RegisterNamespace("WHO:NAME",        0, 1, tmplput_who_username, CTX_WHO);
-       RegisterNamespace("WHO:ROOM",        0, 1, tmplput_who_room, CTX_WHO);
-       RegisterNamespace("WHO:HOST",        0, 1, tmplput_who_host, CTX_WHO);
-       RegisterNamespace("WHO:REALROOM",    0, 1, tmplput_who_realroom, CTX_WHO);
-       RegisterNamespace("WHO:REALHOST",    0, 1, tmplput_who_realhost, CTX_WHO);
-       RegisterNamespace("WHO:LASTACTIVE",  0, 1, tmplput_who_lastactive, CTX_WHO);
-       RegisterNamespace("WHO:IDLESINCE",   0, 1, tmplput_who_idlesince, CTX_WHO);
-       RegisterNamespace("WHO:SESSION",     0, 1, tmplput_who_session, CTX_WHO);
-       RegisterNamespace("WHO:NSESSIONS",   0, 1, tmplput_who_nsessions, CTX_WHO);
-       RegisterNamespace("WHO:NSESSIONS",   0, 1, tmplput_who_nsessions, CTX_WHO);
+       RegisterNamespace("WHO:NAME",        0, 1, tmplput_who_username, NULL, CTX_WHO);
+       RegisterNamespace("WHO:ROOM",        0, 1, tmplput_who_room, NULL, CTX_WHO);
+       RegisterNamespace("WHO:HOST",        0, 1, tmplput_who_host, NULL, CTX_WHO);
+       RegisterNamespace("WHO:REALROOM",    0, 1, tmplput_who_realroom, NULL, CTX_WHO);
+       RegisterNamespace("WHO:REALHOST",    0, 1, tmplput_who_realhost, NULL, CTX_WHO);
+       RegisterNamespace("WHO:LASTACTIVE",  0, 1, tmplput_who_lastactive, NULL, CTX_WHO);
+       RegisterNamespace("WHO:IDLESINCE",   0, 1, tmplput_who_idlesince, NULL, CTX_WHO);
+       RegisterNamespace("WHO:SESSION",     0, 1, tmplput_who_session, NULL, CTX_WHO);
+       RegisterNamespace("WHO:NSESSIONS",   0, 1, tmplput_who_nsessions, NULL, CTX_WHO);
+       RegisterNamespace("WHO:NSESSIONS",   0, 1, tmplput_who_nsessions, NULL, CTX_WHO);
 
        RegisterConditional(HKEY("WHO:IDLE"),      1, conditional_who_idle, CTX_WHO);
        RegisterConditional(HKEY("WHO:NSESSIONS"), 1, conditional_who_nsessions, CTX_WHO);
        RegisterConditional(HKEY("WHO:ISME"),      1, conditional_who_isme, CTX_WHO);
        RegisterConditional(HKEY("WHO:REALROOM"),  1, conditional_who_realroom, CTX_WHO);
+       RegisterConditional(HKEY("WHO:REALHOST"),  1, conditional_who_realhost, CTX_WHO);
 }