* move some more vars from the session context to strbuf (the use of StrBufAppendTemp...
authorWilfried Göesgens <willi@citadel.org>
Thu, 8 Jan 2009 23:11:56 +0000 (23:11 +0000)
committerWilfried Göesgens <willi@citadel.org>
Thu, 8 Jan 2009 23:11:56 +0000 (23:11 +0000)
* move the default template params to a standard structure, so adding further controll structures here gets more easy
* move some cases to GetServerStatus() to evaluate the server status feedback to queries.

55 files changed:
webcit/addressbook_popup.c
webcit/auth.c
webcit/calendar.c
webcit/calendar_view.c
webcit/context_loop.c
webcit/cookie_conversion.c
webcit/downloads.c
webcit/floors.c
webcit/gettext.c
webcit/graphics.c
webcit/groupdav.h
webcit/groupdav_delete.c
webcit/groupdav_get.c
webcit/groupdav_main.c
webcit/groupdav_options.c
webcit/groupdav_propfind.c
webcit/groupdav_put.c
webcit/http_datestring.c
webcit/ical_dezonify.c
webcit/iconbar.c
webcit/inetconf.c
webcit/listsub.c
webcit/mainmenu.c
webcit/messages.c
webcit/msg_renderers.c
webcit/netconf.c
webcit/notes.c
webcit/openid.c
webcit/paging.c
webcit/paramhandling.c
webcit/preferences.c
webcit/pushemail.c
webcit/roomops.c
webcit/rss.c
webcit/serv_func.c
webcit/siteconfig.c
webcit/smtpqueue.c
webcit/static/bt.css
webcit/static/instant_messenger.html
webcit/static/prototype.js
webcit/static/wclib.js
webcit/static/webcit.css
webcit/subst.c
webcit/subst.h
webcit/summary.c
webcit/sysmsgs.c
webcit/useredit.c
webcit/userlist.c
webcit/utils.c
webcit/vcard_edit.c
webcit/wc_gettext.h
webcit/webcit.c
webcit/webcit.h
webcit/who.c
webcit/wiki.c

index 3cb23ebddbd3366b2b4c947cf73fd5f4f5dc16f2..711a73c904c51f61eb3ac5022e42e04d7030fe1a 100644 (file)
@@ -51,7 +51,7 @@ void display_address_book_middle_div(void) {
        wprintf("<option value=\"__LOCAL_USERS__\" %s>", 
                (strcmp(ChrPtr(DefAddrBook), "__LOCAL_USERS__") == 0)?
                "selected=\"selected\" ":"");
-       escputs(serv_info.serv_humannode);
+       escputs(ChrPtr(serv_info.serv_humannode));
        wprintf("</option>\n");
 
        
@@ -113,7 +113,7 @@ void display_address_book_inner_div() {
        HashList *List;
        HashPos  *it;
        int i;
-       char saved_roomname[128];
+       StrBuf *saved_roomname;
 
        begin_ajax_response();
 
@@ -149,8 +149,8 @@ void display_address_book_inner_div() {
 
        else {
                set_room_pref("defaddrbook",NewStrBufDup(sbstr("which_addr_book")), 0);
-               safestrncpy(saved_roomname, WC->wc_roomname, sizeof saved_roomname);
-               gotoroom(bstr("which_addr_book"));
+               saved_roomname = NewStrBufDup(WC->wc_roomname);
+               gotoroom(sbstr("which_addr_book"));
                serv_puts("DVCA");
                serv_getln(buf, sizeof buf);
                if (buf[0] == '1') while(len = serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
@@ -171,6 +171,7 @@ void display_address_book_inner_div() {
                DeleteHashPos(&it);
                DeleteHash(&List);
                gotoroom(saved_roomname);
+               FreeStrBuf(&saved_roomname);
        }
 
        wprintf("</select>\n");
index 93480d86bcc9f46b7e1651596cfaeed048597ed2..77dc5c4752bc3224074d52e72356c5ec09a01574 100644 (file)
@@ -91,22 +91,27 @@ void display_openid_login(char *mesg)
 }
 
 
-void display_openid_name_request(char *claimed_id, char *username) {
-       char buf[SIZ];
+void display_openid_name_request(const StrBuf *claimed_id, const StrBuf *username) 
+{
+       StrBuf *Buf = NULL;
 
        output_headers(1, 1, 2, 0, 0, 0);
        wprintf("<div id=\"login_screen\">\n");
 
-       stresc(buf, sizeof buf, claimed_id, 0, 0);
+       Buf = NewStrBufPlain(NULL, StrLength(claimed_id));
+       StrEscAppend(Buf, claimed_id, NULL, 0, 0);
        svprintf(HKEY("VERIFIED"), WCS_STRING, _("Your OpenID <tt>%s</tt> was successfully verified."),
-               claimed_id);
-       svput("CLAIMED_ID", WCS_STRING, claimed_id);
+                ChrPtr(Buf));
+       SVPutBuf("CLAIMED_ID", Buf, 0);
 
 
-       if (!IsEmptyStr(username)) {
-               stresc(buf, sizeof buf, username, 0, 0);
-               svprintf(HKEY("REASON"), WCS_STRING,
-                       _("However, the user name '%s' conflicts with an existing user."), username);
+       if (StrLength(username) > 0) {
+                       Buf = NewStrBufPlain(NULL, StrLength(username));
+                       StrEscAppend(Buf, claimed_id, NULL, 0, 0);
+                       svprintf(HKEY("REASON"), WCS_STRING,
+                                _("However, the user name '%s' conflicts with an existing user."), 
+                                ChrPtr(Buf));
+                       FreeStrBuf(&Buf);
        }
        else {
                svput("REASON", WCS_STRING, "");
@@ -119,7 +124,7 @@ void display_openid_name_request(char *claimed_id, char *username) {
        svput("EXIT_BUTTON", WCS_STRING, _("Exit"));
 
        svprintf(HKEY("BOXTITLE"), WCS_STRING, _("%s - powered by <a href=\"http://www.citadel.org\">Citadel</a>"),
-               serv_info.serv_humannode);
+                ChrPtr(serv_info.serv_humannode));
 
        do_template("openid_manual_create", NULL);
        wDumpContent(2);
@@ -139,18 +144,36 @@ void display_openid_name_request(char *claimed_id, char *username) {
  * pass                        his password
  * serv_response       The parameters returned from a Citadel USER or NEWU command
  */
-void become_logged_in(char *user, char *pass, char *serv_response)
+void become_logged_in(const StrBuf *user, const StrBuf *pass, StrBuf *serv_response)
 {
+       wcsession *WCC = WC;
        char buf[SIZ];
        StrBuf *FloorDiv;
 
        WC->logged_in = 1;
-       extract_token(WC->wc_fullname, &serv_response[4], 0, '|', sizeof WC->wc_fullname);
-       safestrncpy(WC->wc_username, user, sizeof WC->wc_username);
-       safestrncpy(WC->wc_password, pass, sizeof WC->wc_password);
-       WC->axlevel = extract_int(&serv_response[4], 1);
-       if (WC->axlevel >= 6) {
-               WC->is_aide = 1;
+
+       if (WCC->wc_fullname == NULL)
+               WCC->wc_fullname = NewStrBufPlain(NULL, StrLength(serv_response));
+       StrBufExtract_token(WCC->wc_fullname, serv_response, 0, '|');
+       StrBufCutLeft(WCC->wc_fullname, 4 );
+       
+       if (WCC->wc_username == NULL)
+               WCC->wc_username = NewStrBufDup(user);
+       else {
+               FlushStrBuf(WCC->wc_username);
+               StrBufAppendBuf(WCC->wc_username, user, 0);
+       }
+
+       if (WCC->wc_password == NULL)
+               WCC->wc_password = NewStrBufDup(pass);
+       else {
+               FlushStrBuf(WCC->wc_password);
+               StrBufAppendBuf(WCC->wc_password, pass, 0);
+       }
+
+       WCC->axlevel = StrBufExtract_int(serv_response, 1, '|');
+       if (WCC->axlevel >= 6) { /* TODO: make this a define, else it might trick us later */
+               WCC->is_aide = 1;
        }
 
        load_preferences();
@@ -177,7 +200,7 @@ void become_logged_in(char *user, char *pass, char *serv_response)
 void do_login(void)
 {
        wcsession *WCC = WC;
-       char buf[SIZ];
+       StrBuf *Buf;
 
        if (havebstr("language")) {
                set_selected_language(bstr("language"));
@@ -188,28 +211,31 @@ void do_login(void)
                do_logout();
                return;
        }
+       Buf = NewStrBuf();
        if (havebstr("login_action")) {
                serv_printf("USER %s", bstr("name"));
-               serv_getln(buf, sizeof buf);
-               if (buf[0] == '3') {
+               StrBuf_ServGetln(Buf);
+               if (GetServerStatus(Buf, NULL) == 3) {
                        serv_printf("PASS %s", bstr("pass"));
-                       serv_getln(buf, sizeof buf);
-                       if (buf[0] == '2') {
-                               become_logged_in(bstr("name"), bstr("pass"), buf);
+                       StrBuf_ServGetln(Buf);
+                       if (GetServerStatus(Buf, NULL) == 2) {
+                               become_logged_in(sbstr("name"), sbstr("pass"), Buf);
                        } else {
                                snprintf(WCC->ImportantMessage, 
                                         sizeof (WCC->ImportantMessage), 
                                         "%s", 
-                                        &buf[4]);
+                                        &(ChrPtr(Buf))[4]);
                                display_login();
+                               FreeStrBuf(&Buf);
                                return;
                        }
                } else {
                        snprintf(WCC->ImportantMessage, 
                                 sizeof (WCC->ImportantMessage), 
                                 "%s", 
-                                &buf[4]);
+                                &(ChrPtr(Buf))[4]);
                        display_login();
+                       FreeStrBuf(&Buf);
                        return;
                }
        }
@@ -220,20 +246,22 @@ void do_login(void)
                                 "%s", 
                                 _("Blank passwords are not allowed."));
                        display_login();
+                       FreeStrBuf(&Buf);
                        return;
                }
                serv_printf("NEWU %s", bstr("name"));
-               serv_getln(buf, sizeof buf);
-               if (buf[0] == '2') {
-                       become_logged_in(bstr("name"), bstr("pass"), buf);
+               StrBuf_ServGetln(Buf);
+               if (GetServerStatus(Buf, NULL) == 2) {
+                       become_logged_in(sbstr("name"), sbstr("pass"), Buf);
                        serv_printf("SETP %s", bstr("pass"));
-                       serv_getln(buf, sizeof buf);
+                       StrBuf_ServGetln(Buf); /* Don't care? */
                } else {
                        snprintf(WCC->ImportantMessage, 
                                 sizeof (WCC->ImportantMessage), 
                                 "%s", 
-                                &buf[4]);
+                                &(ChrPtr(Buf))[4]);
                        display_login();
+                       FreeStrBuf(&Buf);
                        return;
                }
        }
@@ -253,7 +281,7 @@ void do_login(void)
                         _("Your password was not accepted."));
                display_login();
        }
-
+       FreeStrBuf(&Buf);
 }
 
 /* 
@@ -261,7 +289,7 @@ void do_login(void)
  */
 void openid_manual_create(void)
 {
-       char buf[1024];
+       StrBuf *Buf;
 
        if (havebstr("exit_action")) {
                do_logout();
@@ -269,14 +297,20 @@ void openid_manual_create(void)
        }
 
        if (havebstr("newuser_action")) {
+               Buf = NewStrBuf();
                serv_printf("OIDC %s", bstr("name"));
-               serv_getln(buf, sizeof buf);
-               if (buf[0] == '2') {
-                       char gpass[1024] = "";
+               StrBuf_ServGetln(Buf);
+               if (GetServerStatus(Buf, NULL) == 2) {
+                       StrBuf *gpass;
+
+                       gpass = NewStrBuf();
                        serv_puts("SETP GENERATE_RANDOM_PASSWORD");
-                       serv_getln(gpass, sizeof gpass);
-                       become_logged_in(bstr("name"), &gpass[4], buf);
+                       StrBuf_ServGetln(gpass);
+                       StrBufCutLeft(gpass, 4);
+                       become_logged_in(sbstr("name"), gpass, Buf);
+                       FreeStrBuf(&gpass);
                }
+               FreeStrBuf(&Buf);
        }
 
        if (WC->logged_in) {
@@ -288,7 +322,7 @@ void openid_manual_create(void)
                        do_welcome();
                }
        } else {
-               display_openid_name_request(bstr("openid_url"), bstr("name"));
+               display_openid_name_request(sbstr("openid_url"), sbstr("name"));
        }
 
 }
@@ -342,23 +376,22 @@ void do_openid_login(void)
  */
 void finalize_openid_login(void)
 {
-       char buf[1024];
+       StrBuf *Buf;
        wcsession *WCC = WC;
        int already_logged_in = (WCC->logged_in) ;
        int linecount = 0;
-       char result[128] = "";
-       char username[128] = "";
-       char password[128] = "";
-       char logged_in_response[1024] = "";
-       char claimed_id[1024] = "";
+       StrBuf *result = NULL;
+       StrBuf *username = NULL;
+       StrBuf *password = NULL;
+       StrBuf *logged_in_response = NULL;
+       StrBuf *claimed_id = NULL;
 
        if (havebstr("openid.mode")) {
                if (!strcasecmp(bstr("openid.mode"), "id_res")) {
-
+                       Buf = NewStrBuf();
                        serv_puts("OIDF");
-                       serv_getln(buf, sizeof buf);
-
-                       if (buf[0] == '8') {
+                       StrBuf_ServGetln(Buf);
+                       if (GetServerStatus(Buf, NULL) == 8) {
                                urlcontent *u;
                                void *U;
                                long HKLen;
@@ -376,44 +409,52 @@ void finalize_openid_login(void)
                                serv_puts("000");
 
                                linecount = 0;
-                               while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
-                                       if (linecount == 0) safestrncpy(result, buf, sizeof result);
-                                       if (!strcasecmp(result, "authenticate")) {
+                               while (StrBuf_ServGetln(Buf), 
+                                      (StrLength(Buf)==3) && 
+                                      !strcmp(ChrPtr(Buf), "000")) 
+                               {
+                                       if (linecount == 0) result = NewStrBufDup(Buf);
+                                       if (!strcasecmp(ChrPtr(result), "authenticate")) {
                                                if (linecount == 1) {
-                                                       safestrncpy(username, buf, sizeof username);
+                                                       username = NewStrBufDup(Buf);
                                                }
                                                else if (linecount == 2) {
-                                                       safestrncpy(password, buf, sizeof password);
+                                                       password = NewStrBufDup(Buf);
                                                }
                                                else if (linecount == 3) {
-                                                       safestrncpy(logged_in_response, buf,
-                                                               sizeof logged_in_response);
+                                                       logged_in_response = NewStrBufDup(Buf);
                                                }
                                        }
-                                       else if (!strcasecmp(result, "verify_only")) {
+                                       else if (!strcasecmp(ChrPtr(result), "verify_only")) {
                                                if (linecount == 1) {
-                                                       safestrncpy(claimed_id, buf, sizeof claimed_id);
+                                                       claimed_id = NewStrBufDup(Buf);
                                                }
                                                if (linecount == 2) {
-                                                       safestrncpy(username, buf, sizeof username);
+                                                       username = NewStrBufDup(Buf);
                                                }
                                        }
                                        ++linecount;
                                }
                        }
+                       FreeStrBuf(&Buf);
                }
        }
 
        /* If we were already logged in, this was an attempt to associate an OpenID account */
        if (already_logged_in) {
                display_openids();
+               FreeStrBuf(&result);
+               FreeStrBuf(&username);
+               FreeStrBuf(&password);
+               FreeStrBuf(&claimed_id);
+               FreeStrBuf(&logged_in_response);
                return;
        }
 
        /* If this operation logged us in, either by connecting with an existing account or by
         * auto-creating one using Simple Registration Extension, we're already on our way.
         */
-       if (!strcasecmp(result, "authenticate")) {
+       if (!strcasecmp(ChrPtr(result), "authenticate")) {
                become_logged_in(username, password, logged_in_response);
        }
 
@@ -421,7 +462,7 @@ void finalize_openid_login(void)
         * or conflicts with an existing user.  Either way the user will need to specify a new name.
         */
 
-       else if (!strcasecmp(result, "verify_only")) {
+       else if (!strcasecmp(ChrPtr(result), "verify_only")) {
                display_openid_name_request(claimed_id, username);
        }
 
@@ -436,6 +477,11 @@ void finalize_openid_login(void)
                display_openid_login(_("Your password was not accepted."));
        }
 
+       FreeStrBuf(&result);
+       FreeStrBuf(&username);
+       FreeStrBuf(&password);
+       FreeStrBuf(&claimed_id);
+       FreeStrBuf(&logged_in_response);
 }
 
 
@@ -524,10 +570,10 @@ void do_logout(void)
 {
        char buf[SIZ];
 
-       safestrncpy(WC->wc_username, "", sizeof WC->wc_username);
-       safestrncpy(WC->wc_password, "", sizeof WC->wc_password);
-       safestrncpy(WC->wc_roomname, "", sizeof WC->wc_roomname);
-       safestrncpy(WC->wc_fullname, "", sizeof WC->wc_fullname);
+       FlushStrBuf(WC->wc_username);
+       FlushStrBuf(WC->wc_password);
+       FlushStrBuf(WC->wc_roomname);
+       FlushStrBuf(WC->wc_fullname);
 
        /** Calling output_headers() this way causes the cookies to be un-set */
        output_headers(1, 1, 0, 1, 0, 0);
@@ -746,12 +792,16 @@ void display_reg(int during_login)
  */
 void display_changepw(void)
 {
+       WCTemplputParams SubTP;
        char buf[SIZ];
        StrBuf *Buf;
        output_headers(1, 1, 1, 0, 0, 0);
 
        Buf = NewStrBufPlain(_("Change your password"), -1);
-       DoTemplate(HKEY("beginbox"), NULL, Buf, CTX_STRBUF);
+       memset(&SubTP, 0, sizeof(WCTemplputParams));
+       SubTP.ContextType = CTX_STRBUF;
+       SubTP.Context = Buf;
+       DoTemplate(HKEY("beginbox"), NULL, &SubTP);
 
        FreeStrBuf(&Buf);
 
@@ -831,7 +881,12 @@ void changepw(void)
        serv_getln(buf, sizeof buf);
        sprintf(WC->ImportantMessage, "%s", &buf[4]);
        if (buf[0] == '2') {
-               safestrncpy(WC->wc_password, buf, sizeof WC->wc_password);
+               if (WC->wc_password == NULL)
+                       WC->wc_password = NewStrBufPlain(buf, -1);
+               else {
+                       FlushStrBuf(WC->wc_password);
+                       StrBufAppendBufPlain(WC->wc_password,  buf, -1, 0);
+               }
                display_main_menu();
        }
        else {
@@ -839,17 +894,17 @@ void changepw(void)
        }
 }
 
-int ConditionalAide(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalAide(StrBuf *Target, WCTemplputParams *TP)
 {
        return (WC->is_aide == 0);
 }
 
-int ConditionalRoomAide(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalRoomAide(StrBuf *Target, WCTemplputParams *TP)
 {
        return (WC->is_room_aide == 0);
 }
 
-int ConditionalRoomAcessDelete(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalRoomAcessDelete(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        return ( (WCC->is_room_aide) || (WCC->is_mailbox) || (WCC->room_flags2 & QR2_COLLABDEL) );
index 9012e8966ac000f0dd116b0cc1e49363238c60ca..a059acb8ffa78ca274c271dbc735913640448918 100644 (file)
@@ -1058,7 +1058,7 @@ void display_edit_task(void) {
                        
        /* Force change the room if we have to */
        if (havebstr("taskrm")) {
-               gotoroom((char *)bstr("taskrm"));
+               gotoroom(sbstr("taskrm"));
        }
 
        msgnum = lbstr("msgnum");
index f9863836bf81e9b5314b3716ee0def62686bc485..0af1842ec1d2ec48c207c3cf76322130f4d67ec9 100644 (file)
@@ -1304,7 +1304,7 @@ void calendar_summary_view(void) {
                                                        "?gotofirst=",
                                                        Cal->cal_msgnum
                                                );
-                                               escputs(WCC->wc_roomname);
+                                               escputs(ChrPtr(WCC->wc_roomname));
                                                wprintf("\">");
                                        }
                                        else {
@@ -1320,7 +1320,7 @@ void calendar_summary_view(void) {
                                                        today_tm.tm_mon + 1,
                                                        today_tm.tm_mday
                                                );
-                                               escputs(WCC->wc_roomname);
+                                               escputs(ChrPtr(WCC->wc_roomname));
                                                wprintf("\">");
                                        }
                                        escputs((char *) icalproperty_get_comment(p));
@@ -1552,7 +1552,7 @@ void do_tasks_view(void) {
                p = icalcomponent_get_first_property(Cal->cal,
                        ICAL_SUMMARY_PROPERTY);
                wprintf("<a href=\"display_edit_task?msgnum=%ld?taskrm=", Cal->cal_msgnum);
-               urlescputs(WC->wc_roomname);
+               urlescputs(ChrPtr(WC->wc_roomname));
                wprintf("\">");
                /* wprintf("<img align=middle "
                "src=\"static/taskmanag_16x.gif\" border=0>&nbsp;"); */
index 0248c384f29d8e6c168aad5dbb60e90d54bad830..e0a816e1d351bb3b3e605fa09783807bf8d3b843 100644 (file)
@@ -43,6 +43,12 @@ void DestroySession(wcsession **sessions_to_kill)
        FreeStrBuf(&((*sessions_to_kill)->WBuf));
        FreeStrBuf(&((*sessions_to_kill)->HBuf));
        FreeStrBuf(&((*sessions_to_kill)->CLineBuf));
+       FreeStrBuf(&((*sessions_to_kill)->wc_username));
+       FreeStrBuf(&((*sessions_to_kill)->wc_fullname));
+       FreeStrBuf(&((*sessions_to_kill)->wc_password));
+       FreeStrBuf(&((*sessions_to_kill)->wc_roomname));
+       FreeStrBuf(&((*sessions_to_kill)->httpauth_user));
+       FreeStrBuf(&((*sessions_to_kill)->httpauth_pass));
        free((*sessions_to_kill));
        (*sessions_to_kill) = NULL;
 }
@@ -353,7 +359,7 @@ authentication
        if (GetHash(HTTPHeaders, HKEY("COOKIE"), &vLine) && 
            (vLine != NULL)) {
                cookie_to_stuff(vLine, &desired_session,
-                               NULL, 0, NULL, 0, NULL, 0);
+                               NULL, NULL, NULL);
                got_cookie = 1;
        }
 
@@ -471,8 +477,8 @@ authentication
 
                        /** If HTTP-AUTH, look for a session with matching credentials */
                        if ( (!IsEmptyStr(httpauth_user))
-                          &&(!strcasecmp(sptr->httpauth_user, httpauth_user))
-                          &&(!strcasecmp(sptr->httpauth_pass, httpauth_pass)) ) {
+                            &&(!strcasecmp(ChrPtr(sptr->httpauth_user), httpauth_user))
+                            &&(!strcasecmp(ChrPtr(sptr->httpauth_pass), httpauth_pass)) ) {
                                TheSession = sptr;
                        }
 
@@ -509,8 +515,17 @@ authentication
                        TheSession->wc_session = desired_session;
                }
 
-               strcpy(TheSession->httpauth_user, httpauth_user);
-               strcpy(TheSession->httpauth_pass, httpauth_pass);
+               if (TheSession->httpauth_user != NULL){
+                       FlushStrBuf(TheSession->httpauth_user);
+                       StrBufAppendBufPlain(TheSession->httpauth_user, httpauth_user, -1, 0);
+               }
+               else TheSession->httpauth_user = NewStrBufPlain(httpauth_user, -1);
+               if (TheSession->httpauth_user != NULL){
+                       FlushStrBuf(TheSession->httpauth_pass);
+                       StrBufAppendBufPlain(TheSession->httpauth_pass, httpauth_user, -1, 0);
+               }
+               else TheSession->httpauth_pass = NewStrBufPlain(httpauth_user, -1);
+
                TheSession->hash_prefs = NewHash(1,NULL);       /* Get a hash table for the user preferences */
                pthread_mutex_init(&TheSession->SessionMutex, NULL);
                pthread_mutex_lock(&SessionListMutex);
@@ -574,16 +589,30 @@ authentication
        
 }
 
-void tmpl_nonce(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_nonce(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        StrBufAppendPrintf(Target, "%ld",
                           (WCC != NULL)? WCC->nonce:0);                   
 }
 
+void tmplput_current_user(StrBuf *Target, WCTemplputParams *TP)
+{
+       StrBufAppendTemplate(Target, TP, WC->wc_fullname, 0);
+}
+
+void tmplput_current_room(StrBuf *Target, WCTemplputParams *TP)
+{
+       StrBufAppendTemplate(Target, TP, WC->wc_roomname, 0); 
+}
+
+
+
 void 
 InitModule_CONTEXT
 (void)
 {
-       RegisterNamespace("NONCE", 0, 0, tmpl_nonce, 0);
+       RegisterNamespace("CURRENT_USER", 0, 1, tmplput_current_user, CTX_NONE);
+       RegisterNamespace("CURRENT_ROOM", 0, 1, tmplput_current_room, CTX_NONE);
+       RegisterNamespace("NONCE", 0, 0, tmplput_nonce, 0);
 }
index 844798ea06bf94673561d6e1b7ca736e9e21ccf4..172536fc4f6409376eacefbbfd76c03ba3ac4103 100644 (file)
@@ -27,13 +27,18 @@ typedef unsigned char byte;       /**< Byte type */
  * \param room the room he wants to enter
  */
 void stuff_to_cookie(char *cookie, size_t clen, int session,
-               char *user, char *pass, char *room)
+               StrBuf *user, StrBuf *pass, StrBuf *room)
 {
        char buf[SIZ];
        int i;
        int len;
 
-       len = snprintf(buf, SIZ, "%d|%s|%s|%s|", session, user, pass, room);
+       len = snprintf(buf, SIZ, "%d|%s|%s|%s|", 
+                      session, 
+                      ChrPtr(user), 
+                      ChrPtr(pass), 
+                      ChrPtr(room));
+
        strcpy(cookie, "");
        for (i=0; (i < len) && (i * 2 < clen); ++i) {
                snprintf(&cookie[i*2], clen - i * 2, "%02X", buf[i]);
@@ -78,12 +83,13 @@ int xtoi(const char *in, size_t len)
  * \param room_len the length of the room string
  */
 void cookie_to_stuff(StrBuf *cookie, int *session,
-               char *user, size_t user_len,
-               char *pass, size_t pass_len,
-               char *room, size_t room_len)
+                    StrBuf *user,
+                    StrBuf *pass,
+                    StrBuf *room)
 {
        const char *pch;
        char buf[SIZ];
+       StrBuf *Buf;
        int i, len;
 
        pch = strstr(ChrPtr(cookie), "webcit=");
@@ -98,6 +104,7 @@ void cookie_to_stuff(StrBuf *cookie, int *session,
                buf[i] = xtoi(&pch[i*2], 2);
                buf[i+1] = 0;
        }
+       Buf = NewStrBufPlain(buf, i);
 
 /* debug
        char t[256];
@@ -112,12 +119,13 @@ void cookie_to_stuff(StrBuf *cookie, int *session,
  debug */
 
        if (session != NULL)
-               *session = extract_int(buf, 0);
+               *session = StrBufExtract_int(Buf, 0, '|');
        if (user != NULL)
-               extract_token(user, buf, 1, '|', user_len);
+               StrBufExtract_token(user, Buf, 1, '|');
        if (pass != NULL)
-               extract_token(pass, buf, 2, '|', pass_len);
+               StrBufExtract_token(pass, Buf, 2, '|');
        if (room != NULL)
-               extract_token(room, buf, 3, '|', room_len);
+               StrBufExtract_token(room, Buf, 3, '|');
+       FreeStrBuf(&Buf);
 }
 /*@}*/
index ed78c74c6bdfc07a188b45bbcea8440230d5ac6f..ea6ad4d9b218c5befe7c4233b394106bef2f51c2 100644 (file)
@@ -25,32 +25,32 @@ void FreeFiles(void *vFile)
 }
 
 /* -------------------------------------------------------------------------------- */
-void tmplput_FILE_NAME(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_FILE_NAME(StrBuf *Target, WCTemplputParams *TP)
 {
-       FileListStruct *F = (FileListStruct*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, F->Filename, 0);
+       FileListStruct *F = (FileListStruct*) CTX;
+       StrBufAppendTemplate(Target, TP, F->Filename, 0);
 }
-void tmplput_FILE_SIZE(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_FILE_SIZE(StrBuf *Target, WCTemplputParams *TP)
 {
-       FileListStruct *F = (FileListStruct*) Context;
+       FileListStruct *F = (FileListStruct*) CTX;
        StrBufAppendPrintf(Target, "%ld", F->FileSize);
 }
-void tmplput_FILEMIMETYPE(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_FILEMIMETYPE(StrBuf *Target, WCTemplputParams *TP)
 {
-       FileListStruct *F = (FileListStruct*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, F->MimeType, 0);
+       FileListStruct *F = (FileListStruct*) CTX;
+       StrBufAppendTemplate(Target, TP, F->MimeType, 0);
 }
-void tmplput_FILE_COMMENT(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_FILE_COMMENT(StrBuf *Target, WCTemplputParams *TP)
 {
-       FileListStruct *F = (FileListStruct*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, F->Comment, 0);
+       FileListStruct *F = (FileListStruct*) CTX;
+       StrBufAppendTemplate(Target, TP, F->Comment, 0);
 }
 
 /* -------------------------------------------------------------------------------- */
 
-int Conditional_FILE_ISPIC(WCTemplateToken *Tokens, void *Context, int ContextType)
+int Conditional_FILE_ISPIC(StrBuf *Target, WCTemplputParams *TP)
 {
-       FileListStruct *F = (FileListStruct*) Context;
+       FileListStruct *F = (FileListStruct*) CTX;
        return F->IsPic;
 }
 
@@ -163,7 +163,7 @@ int GroupchangeFilelistBySequence(const void *vFile1, const void *vFile2)
 }
 
 /* -------------------------------------------------------------------------------- */
-HashList* LoadFileList(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+HashList* LoadFileList(StrBuf *Target, WCTemplputParams *TP)
 {
        FileListStruct *Entry;
        StrBuf *Buf;
@@ -173,7 +173,9 @@ HashList* LoadFileList(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void
        char buf[1024];
        CompareFunc SortIt;
        int HavePic;
+       WCTemplputParams SubTP;
 
+       memset(&TP, 0, sizeof(WCTemplputParams));
        serv_puts("RDIR");
        serv_getln(buf, sizeof buf);
        if (buf[0] != '1') return NULL;
@@ -208,7 +210,8 @@ HashList* LoadFileList(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void
                }
                Put(Files, SKEY(Entry->Filename), Entry, FreeFiles);
        }
-       SortIt = RetrieveSort(CTX_FILELIST, NULL, HKEY("fileunsorted"), 0);
+       SubTP.ContextType = CTX_FILELIST;
+       SortIt = RetrieveSort(&SubTP, NULL, HKEY("fileunsorted"), 0);
        if (SortIt != NULL)
                SortByPayload(Files, SortIt);
        else 
index 1b52c9aece5ed91bc01fcdae8e30e72042d8c61f..78227221b6f5353de6cd27b9ce667ae38894347c 100644 (file)
@@ -145,7 +145,7 @@ void delete_floor(void) {
        
        StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err);
 
-       if (ChrPtr(Buf)[0] == '2') {
+       if (GetServerStatus(Buf, NULL) == 2) {
                StrBufPlain(Buf, _("Floor has been deleted."),-1);
        }
        else {
@@ -167,7 +167,7 @@ void create_floor(void) {
        serv_printf("CFLR %s|1", bstr("floorname"));
        StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err);
 
-       if (ChrPtr(Buf)[0] == '2') {
+       if (GetServerStatus(Buf, NULL) == 2) {
                StrBufPlain(Buf, _("New floor has been created."),-1);
        }
        else {
index 241fb9eedd6924d4d94044a01ab3337347ff833c..930d9df38abb4e33b425b54e2fdd2b048ab6c618 100644 (file)
@@ -167,7 +167,8 @@ void httplang_to_locale(StrBuf *LocaleString)
  * depending on the browser locale change the sequence of the 
  * language chooser.
  */
-void tmplput_offer_languages(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) {
+void tmplput_offer_languages(StrBuf *Target, WCTemplputParams *TP)
+{
        int i;
 #ifndef HAVE_USELOCALE
        char *Lang = getenv("LANG");
@@ -306,7 +307,8 @@ void ShutdownLocale(void)
 
 #else  /* ENABLE_NLS */
 /** \brief dummy for non NLS enabled systems */
-void tmplput_offer_languages(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) {
+void tmplput_offer_languages(StrBuf *Target, WCTemplputParams *TP)
+{
        wprintf("English (US)");
 }
 
@@ -328,9 +330,9 @@ void preset_locale(void)
 #endif /* ENABLE_NLS */
 
 
-void TmplGettext(StrBuf *Target, int nTokens, WCTemplateToken *Tokens)
+void TmplGettext(StrBuf *Target, WCTemplputParams *TP)
 {
-       StrBufAppendBufPlain(Target, _(Tokens->Params[0]->Start), -1, 0);
+       StrBufAppendBufPlain(Target, _(TP->Tokens->Params[0]->Start), -1, 0);
 }
 
 
index 378cdfbc5e922375921ce81a735a0d023fba4c2a..ba879dc35aac4bd09d9e47da2acff8444d594160 100644 (file)
@@ -9,6 +9,7 @@
 
 void display_graphics_upload(char *description, char *filename, char *uplurl)
 {
+       WCTemplputParams SubTP;
        StrBuf *Buf;
        char buf[SIZ];
 
@@ -26,7 +27,10 @@ void display_graphics_upload(char *description, char *filename, char *uplurl)
        output_headers(1, 1, 1, 0, 0, 0);
 
        Buf = NewStrBufPlain(_("Image upload"), -1);
-       DoTemplate(HKEY("beginbox"), NULL, Buf, CTX_STRBUF);
+       memset(&SubTP, 0, sizeof(WCTemplputParams));
+       SubTP.ContextType = CTX_STRBUF;
+       SubTP.Context = Buf;
+       DoTemplate(HKEY("beginbox"), NULL, &SubTP);
 
        FreeStrBuf(&Buf);
 
index 42709a5b795a9d4ade63cd4fa208638ecf8c0930..ee7ffff8012ffd1f437f1a7b7a8d958a9a784c4d 100644 (file)
@@ -21,15 +21,15 @@ void groupdav_main(HashList *HTTPHeaders,
                   int dav_content_length,
                   StrBuf *dav_content,
                   int Offset);
-void groupdav_get(const char *dav_pathname);
-void groupdav_put(const char *dav_pathname, char *dav_ifmatch,
+void groupdav_get(StrBuf *dav_pathname);
+void groupdav_put(StrBuf *dav_pathname, char *dav_ifmatch,
                  const char *dav_content_type, StrBuf *dav_content,
                  int offset);
 void groupdav_delete(StrBuf *dav_pathname, char *dav_ifmatch);
-void groupdav_propfind(const char *dav_pathname, int dav_depth, StrBuf *dav_content_type, StrBuf *dav_content, int offset);
-void groupdav_options(const char *dav_pathname);
-long locate_message_by_uid(char *);
+void groupdav_propfind(StrBuf *dav_pathname, int dav_depth, StrBuf *dav_content_type, StrBuf *dav_content, int offset);
+void groupdav_options(StrBuf *dav_pathname);
+long locate_message_by_uid(const char *);
 void groupdav_folder_list(void);
-void euid_escapize(char *, char *);
-void euid_unescapize(char *, char *);
+void euid_escapize(char *, const char *);
+void euid_unescapize(char *, const char *);
 void groupdav_identify_host(void);
index 2a76687b1e811fde160cf17ef9309a9d81a570f0..20915900f5b4eb742bd7d904e10c0c81a0747f7e 100644 (file)
@@ -14,7 +14,6 @@
  * The pathname is always going to be /groupdav/room_name/euid
  */
 void groupdav_delete(StrBuf *dav_pathname, char *dav_ifmatch) {
-       char dav_roomname[SIZ];
        char dav_uid[SIZ];
        long dav_msgnum = (-1);
        char buf[SIZ];
@@ -35,13 +34,12 @@ void groupdav_delete(StrBuf *dav_pathname, char *dav_ifmatch) {
        if ((len > 0) && (ChrPtr(dav_pathname)[len-1] == '/')) {
                StrBufCutRight(dav_pathname, 1);
        }
-       strcpy(dav_roomname, ChrPtr(dav_pathname));
 
        /* Go to the correct room. */
-       if (strcasecmp(WC->wc_roomname, dav_roomname)) {
-               gotoroom(dav_roomname);
+       if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_pathname))) {
+               gotoroom(dav_pathname);
        }
-       if (strcasecmp(WC->wc_roomname, dav_roomname)) {
+       if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_pathname))) {
                hprintf("HTTP/1.1 404 not found\r\n");
                groupdav_common_headers();
                hprintf("Content-Length: 0\r\n\r\n");
index 85f643b83111cf7a44e6bc028f93552a431e7ece..39008e53a23a4214c7a671ee7038d0e6fc2c2817 100644 (file)
@@ -86,9 +86,9 @@ void extract_preferred(char *name, char *filename, char *partnum, char *disp,
  * /groupdav/room_name/euid    (GroupDAV)
  * /groupdav/room_name         (webcal)
  */
-void groupdav_get(const char *dav_pathname) {
-       char dav_roomname[1024];
-       char dav_uid[1024];
+void groupdav_get(StrBuf *dav_pathname) {
+       StrBuf *dav_roomname;
+       StrBuf *dav_uid;
        long dav_msgnum = (-1);
        char buf[1024];
        int in_body = 0;
@@ -104,7 +104,7 @@ void groupdav_get(const char *dav_pathname) {
        char date[128];
        struct epdata epdata;
 
-       if (num_tokens(dav_pathname, '/') < 3) {
+       if (StrBufNum_tokens(dav_pathname, '/') < 3) {
                hprintf("HTTP/1.1 404 not found\r\n");
                groupdav_common_headers();
                hprintf("Content-Type: text/plain\r\n");
@@ -113,34 +113,41 @@ void groupdav_get(const char *dav_pathname) {
                return;
        }
 
-       extract_token(dav_roomname, dav_pathname, 2, '/', sizeof dav_roomname);
-       extract_token(dav_uid, dav_pathname, 3, '/', sizeof dav_uid);
-       if ((!strcasecmp(dav_uid, "ics")) || (!strcasecmp(dav_uid, "calendar.ics"))) {
-               strcpy(dav_uid, "");
+       dav_roomname = NewStrBuf();;
+       dav_uid = NewStrBuf();;
+       StrBufExtract_token(dav_roomname, dav_pathname, 2, '/');
+       StrBufExtract_token(dav_uid, dav_pathname, 3, '/');
+       if ((!strcasecmp(ChrPtr(dav_uid), "ics")) || 
+           (!strcasecmp(ChrPtr(dav_uid), "calendar.ics"))) {
+               FlushStrBuf(dav_uid);
        }
 
        /* Go to the correct room. */
-       if (strcasecmp(WC->wc_roomname, dav_roomname)) {
+       if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_roomname))) {
                gotoroom(dav_roomname);
        }
-       if (strcasecmp(WC->wc_roomname, dav_roomname)) {
+       if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_roomname))) {
                hprintf("HTTP/1.1 404 not found\r\n");
                groupdav_common_headers();
                hprintf("Content-Type: text/plain\r\n");
                wprintf("There is no folder called \"%s\" on this server.\r\n",
-                       dav_roomname);
+                       ChrPtr(dav_roomname));
                end_burst();
+               FreeStrBuf(&dav_roomname);
+               FreeStrBuf(&dav_uid);
                return;
        }
 
        /** GET on the collection itself returns an ICS of the entire collection.
         */
-       if (!strcasecmp(dav_uid, "")) {
+       if (StrLength(dav_uid) > 0) {
                groupdav_get_big_ics();
+               FreeStrBuf(&dav_roomname);
+               FreeStrBuf(&dav_uid);
                return;
        }
 
-       dav_msgnum = locate_message_by_uid(dav_uid);
+       dav_msgnum = locate_message_by_uid(ChrPtr(dav_uid));
        serv_printf("MSG2 %ld", dav_msgnum);
        serv_getln(buf, sizeof buf);
        if (buf[0] != '1') {
@@ -148,11 +155,15 @@ void groupdav_get(const char *dav_pathname) {
                groupdav_common_headers();
                hprintf("Content-Type: text/plain\r\n");
                wprintf("Object \"%s\" was not found in the \"%s\" folder.\r\n",
-                       dav_uid,
-                       dav_roomname);
+                       ChrPtr(dav_uid),
+                       ChrPtr(dav_roomname));
                end_burst();
+               FreeStrBuf(&dav_roomname);
+               FreeStrBuf(&dav_uid);
                return;
        }
+       FreeStrBuf(&dav_roomname);
+       FreeStrBuf(&dav_uid);
 
        /* We got it; a message is now arriving from the server.  Read it in. */
 
index b761875ef4fad701ed15e5ebc3af28161a93e591..19b060c13eca53c369e064eac0a20f9c148a4343 100644 (file)
@@ -22,7 +22,7 @@ void groupdav_common_headers(void) {
        hprintf(
                "Server: %s / %s\r\n"
                "Connection: close\r\n",
-               PACKAGE_STRING, serv_info.serv_software
+               PACKAGE_STRING, ChrPtr(serv_info.serv_software)
        );
 }
 
@@ -31,7 +31,7 @@ void groupdav_common_headers(void) {
 /*
  * string conversion function
  */
-void euid_escapize(char *target, char *source) {
+void euid_escapize(char *target, const char *source) {
        int i, len;
        int target_length = 0;
 
@@ -52,7 +52,7 @@ void euid_escapize(char *target, char *source) {
 /*
  * string conversion function
  */
-void euid_unescapize(char *target, char *source) {
+void euid_unescapize(char *target, const char *source) {
        int a, b, len;
        char hex[3];
        int target_length = 0;
@@ -129,7 +129,7 @@ void groupdav_main(HashList *HTTPHeaders,
                hprintf("HTTP/1.1 401 Unauthorized\r\n");
                groupdav_common_headers();
                hprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n",
-                       serv_info.serv_humannode);
+                       ChrPtr(serv_info.serv_humannode));
                hprintf("Content-Length: 0\r\n");
                end_burst();
                return;
@@ -186,7 +186,7 @@ void groupdav_main(HashList *HTTPHeaders,
         * other variants of DAV in the future.
         */
        if (!strcasecmp(ChrPtr(DavMethod), "OPTIONS")) {
-               groupdav_options(ChrPtr(DavPathname));
+               groupdav_options(DavPathname);
                return;
        }
 
@@ -195,7 +195,7 @@ void groupdav_main(HashList *HTTPHeaders,
         * room, or to list all relevant rooms on the server.
         */
        if (!strcasecmp(ChrPtr(DavMethod), "PROPFIND")) {
-               groupdav_propfind(ChrPtr(DavPathname), dav_depth,
+               groupdav_propfind(DavPathname, dav_depth,
                                  dav_content_type, dav_content, 
                                  Offset);
                return;
@@ -205,7 +205,7 @@ void groupdav_main(HashList *HTTPHeaders,
         * The GET method is used for fetching individual items.
         */
        if (!strcasecmp(ChrPtr(DavMethod), "GET")) {
-               groupdav_get(ChrPtr(DavPathname));
+               groupdav_get(DavPathname);
                return;
        }
 
@@ -213,7 +213,7 @@ void groupdav_main(HashList *HTTPHeaders,
         * The PUT method is used to add or modify items.
         */
        if (!strcasecmp(ChrPtr(DavMethod), "PUT")) {
-               groupdav_put(ChrPtr(DavPathname), dav_ifmatch,
+               groupdav_put(DavPathname, dav_ifmatch,
                             ChrPtr(dav_content_type), dav_content, 
                             Offset);
                return;
index 366f5ffe3ce580a6e3fe76766f252838f05c586e..5f678c1e647b6e2485f44d8ad51ef276c2f0bab7 100644 (file)
@@ -12,9 +12,9 @@
 /*
  * The pathname is always going to be /groupdav/room_name/msg_num
  */
-void groupdav_options(const char *dav_pathname) {
-       char dav_roomname[256];
-       char dav_uid[256];
+void groupdav_options(StrBuf *dav_pathname) {
+       StrBuf *dav_roomname;
+       StrBuf *dav_uid;
        long dav_msgnum = (-1);
        char datestring[256];
        time_t now;
@@ -22,13 +22,15 @@ void groupdav_options(const char *dav_pathname) {
        now = time(NULL);
        http_datestring(datestring, sizeof datestring, now);
 
-       extract_token(dav_roomname, dav_pathname, 2, '/', sizeof dav_roomname);
-       extract_token(dav_uid, dav_pathname, 3, '/', sizeof dav_uid);
+       dav_roomname = NewStrBuf();
+       dav_uid = NewStrBuf();
+       StrBufExtract_token(dav_roomname, dav_pathname, 2, '/');
+       StrBufExtract_token(dav_uid, dav_pathname, 3, '/');
 
        /*
         * If the room name is blank, the client is doing a top-level OPTIONS.
         */
-       if (IsEmptyStr(dav_roomname)) {
+       if (StrLength(dav_roomname) == 0) {
                hprintf("HTTP/1.1 200 OK\r\n");
                groupdav_common_headers();
                hprintf("Date: %s\r\n", datestring);
@@ -37,15 +39,17 @@ void groupdav_options(const char *dav_pathname) {
                hprintf("\r\n");
                begin_burst();
                end_burst();
+               FreeStrBuf(&dav_roomname);
+               FreeStrBuf(&dav_uid);
                return;
        }
 
        /* Go to the correct room. */
-       if (strcasecmp(WC->wc_roomname, dav_roomname)) {
+       if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_roomname))) {
                gotoroom(dav_roomname);
        }
 
-       if (strcasecmp(WC->wc_roomname, dav_roomname)) {
+       if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_roomname))) {
                hprintf("HTTP/1.1 404 not found\r\n");
                groupdav_common_headers();
                hprintf("Date: %s\r\n", datestring);
@@ -53,19 +57,21 @@ void groupdav_options(const char *dav_pathname) {
                        "Content-Type: text/plain\r\n"
                        "\r\n"
                        "There is no folder called \"%s\" on this server.\r\n",
-                       dav_roomname
+                       ChrPtr(dav_roomname)
                );
                begin_burst();
                end_burst();
+               FreeStrBuf(&dav_roomname);
+               FreeStrBuf(&dav_uid);
                return;
        }
 
        /* If dav_uid is non-empty, client is requesting an OPTIONS on
         * a specific item in the room.
         */
-       if (!IsEmptyStr(dav_uid)) {
+       if (StrLength(dav_uid) != 0) {
 
-               dav_msgnum = locate_message_by_uid(dav_uid);
+               dav_msgnum = locate_message_by_uid(ChrPtr(dav_uid));
                if (dav_msgnum < 0) {
                        hprintf("HTTP/1.1 404 not found\r\n");
                        groupdav_common_headers();
@@ -73,9 +79,11 @@ void groupdav_options(const char *dav_pathname) {
                                "Content-Type: text/plain\r\n"
                                "\r\n"
                                "Object \"%s\" was not found in the \"%s\" folder.\r\n",
-                               dav_uid,
-                               dav_roomname
+                               ChrPtr(dav_uid),
+                               ChrPtr(dav_roomname)
                        );
+                       FreeStrBuf(&dav_roomname);
+                       FreeStrBuf(&dav_uid);
                        begin_burst();end_burst();return;
                }
 
@@ -87,9 +95,14 @@ void groupdav_options(const char *dav_pathname) {
                hprintf("\r\n");
                begin_burst();
                end_burst();
+               FreeStrBuf(&dav_roomname);
+               FreeStrBuf(&dav_uid);
                return;
        }
 
+       FreeStrBuf(&dav_roomname);
+       FreeStrBuf(&dav_uid);
+
        /*
         * We got to this point, which means that the client is requesting
         * an OPTIONS on the room itself.
index 017dc91a91b53bb434d2640cb9d38a22ade6ec5f..c0f702f4a560361a9a3e235b57cafe8911c2a14e 100644 (file)
@@ -25,7 +25,7 @@
  * if not found.
  *
  */
-long locate_message_by_uid(char *uid) {
+long locate_message_by_uid(const char *uid) {
        char buf[256];
        char decoded_uid[1024];
        long retval = (-1L);
@@ -227,9 +227,9 @@ void groupdav_collection_list(const char *dav_pathname, int dav_depth)
 /*
  * The pathname is always going to be /groupdav/room_name/msg_num
  */
-void groupdav_propfind(const char *dav_pathname, int dav_depth, StrBuf *dav_content_type, StrBuf *dav_content, int offset) {
-       char dav_roomname[256];
-       char dav_uid[256];
+void groupdav_propfind(StrBuf *dav_pathname, int dav_depth, StrBuf *dav_content_type, StrBuf *dav_content, int offset) {
+       StrBuf *dav_roomname;
+       StrBuf *dav_uid;
        char msgnum[256];
        long dav_msgnum = (-1);
        char buf[256];
@@ -244,31 +244,37 @@ void groupdav_propfind(const char *dav_pathname, int dav_depth, StrBuf *dav_cont
        now = time(NULL);
        http_datestring(datestring, sizeof datestring, now);
 
-       extract_token(dav_roomname, dav_pathname, 2, '/', sizeof dav_roomname);
-       extract_token(dav_uid, dav_pathname, 3, '/', sizeof dav_uid);
+       dav_roomname = NewStrBuf();
+       dav_uid = NewStrBuf();
+       StrBufExtract_token(dav_roomname, dav_pathname, 2, '/');
+       StrBufExtract_token(dav_uid, dav_pathname, 3, '/');
 
        /*
         * If the room name is blank, the client is requesting a
         * folder list.
         */
-       if (IsEmptyStr(dav_roomname)) {
-               groupdav_collection_list(dav_pathname, dav_depth);
+       if (StrLength(dav_roomname) == 0) {
+               groupdav_collection_list(ChrPtr(dav_pathname), dav_depth);
+               FreeStrBuf(&dav_roomname);
+               FreeStrBuf(&dav_uid);
                return;
        }
 
        /* Go to the correct room. */
-       if (strcasecmp(WC->wc_roomname, dav_roomname)) {
+       if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_roomname))) {
                gotoroom(dav_roomname);
        }
-       if (strcasecmp(WC->wc_roomname, dav_roomname)) {
+       if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_roomname))) {
                hprintf("HTTP/1.1 404 not found\r\n");
                groupdav_common_headers();
                hprintf("Date: %s\r\n", datestring);
                hprintf("Content-Type: text/plain\r\n");
                wprintf("There is no folder called \"%s\" on this server.\r\n",
-                       dav_roomname
+                       ChrPtr(dav_roomname)
                );
                end_burst();
+               FreeStrBuf(&dav_roomname);
+               FreeStrBuf(&dav_uid);
                return;
        }
 
@@ -276,18 +282,20 @@ void groupdav_propfind(const char *dav_pathname, int dav_depth, StrBuf *dav_cont
         * a specific item in the room.  This is not valid GroupDAV, but
         * it is valid WebDAV.
         */
-       if (!IsEmptyStr(dav_uid)) {
+       if (StrLength(dav_uid) != 0) {
 
-               dav_msgnum = locate_message_by_uid(dav_uid);
+               dav_msgnum = locate_message_by_uid(ChrPtr(dav_uid));
                if (dav_msgnum < 0) {
                        hprintf("HTTP/1.1 404 not found\r\n");
                        groupdav_common_headers();
                        hprintf("Content-Type: text/plain\r\n");
                        wprintf("Object \"%s\" was not found in the \"%s\" folder.\r\n",
-                               dav_uid,
-                               dav_roomname
+                               ChrPtr(dav_uid),
+                               ChrPtr(dav_roomname)
                        );
                        end_burst();
+                       FreeStrBuf(&dav_roomname);
+                       FreeStrBuf(&dav_uid);
                        return;
                }
 
@@ -312,8 +320,8 @@ void groupdav_propfind(const char *dav_pathname, int dav_depth, StrBuf *dav_cont
                wprintf("<href>");
                groupdav_identify_host();
                wprintf("/groupdav/");
-               urlescputs(WC->wc_roomname);
-               euid_escapize(encoded_uid, dav_uid);
+               urlescputs(ChrPtr(WC->wc_roomname));
+               euid_escapize(encoded_uid, ChrPtr(dav_uid));
                wprintf("/%s", encoded_uid);
                wprintf("</href>");
                wprintf("<propstat>");
@@ -329,8 +337,12 @@ void groupdav_propfind(const char *dav_pathname, int dav_depth, StrBuf *dav_cont
                wprintf("</response>\n");
                wprintf("</multistatus>\n");
                end_burst();
+               FreeStrBuf(&dav_roomname);
+               FreeStrBuf(&dav_uid);
                return;
        }
+       FreeStrBuf(&dav_roomname);
+       FreeStrBuf(&dav_uid);
 
 
        /*
@@ -360,14 +372,14 @@ void groupdav_propfind(const char *dav_pathname, int dav_depth, StrBuf *dav_cont
        wprintf("<href>");
                groupdav_identify_host();
                wprintf("/groupdav/");
-               urlescputs(WC->wc_roomname);
+               urlescputs(ChrPtr(WC->wc_roomname));
        wprintf("</href>");
 
        wprintf("<propstat>");
        wprintf("<status>HTTP/1.1 200 OK</status>");
        wprintf("<prop>");
        wprintf("<displayname>");
-       escputs(WC->wc_roomname);
+       escputs(ChrPtr(WC->wc_roomname));
        wprintf("</displayname>");
        wprintf("<resourcetype><collection/>");
 
@@ -422,7 +434,7 @@ void groupdav_propfind(const char *dav_pathname, int dav_depth, StrBuf *dav_cont
                                wprintf("<href>");
                                        groupdav_identify_host();
                                        wprintf("/groupdav/");
-                                       urlescputs(WC->wc_roomname);
+                                       urlescputs(ChrPtr(WC->wc_roomname));
                                        euid_escapize(encoded_uid, uid);
                                        wprintf("/%s", encoded_uid);
                                wprintf("</href>");
index 63d3a8dae9bf4bc6d66aa921ce42029abece2767..512cea0980e79068d52e0fe1cbcbd940c725f201 100644 (file)
@@ -54,18 +54,18 @@ void groupdav_put_bigics(StrBuf *dav_content, int offset)
  * /groupdav/room_name/euid    (GroupDAV)
  * /groupdav/room_name         (webcal)
  */
-void groupdav_put(const char *dav_pathname, char *dav_ifmatch,
+void groupdav_put(StrBuf *dav_pathname, char *dav_ifmatch,
                  const char *dav_content_type, StrBuf *dav_content,
                  int offset) 
 {
-       char dav_roomname[1024];
-       char dav_uid[1024];
+       StrBuf *dav_roomname;
+       StrBuf *dav_uid;
        long new_msgnum = (-2L);
        long old_msgnum = (-1L);
        char buf[SIZ];
        int n = 0;
 
-       if (num_tokens(dav_pathname, '/') < 3) {
+       if (StrBufNum_tokens(dav_pathname, '/') < 3) {
                hprintf("HTTP/1.1 404 not found\r\n");
                groupdav_common_headers();
                hprintf("Content-Type: text/plain\r\n");
@@ -74,23 +74,28 @@ void groupdav_put(const char *dav_pathname, char *dav_ifmatch,
                return;
        }
 
-       extract_token(dav_roomname, dav_pathname, 2, '/', sizeof dav_roomname);
-       extract_token(dav_uid, dav_pathname, 3, '/', sizeof dav_uid);
-       if ((!strcasecmp(dav_uid, "ics")) || (!strcasecmp(dav_uid, "calendar.ics"))) {
-               strcpy(dav_uid, "");
+       dav_roomname = NewStrBuf();;
+       dav_uid = NewStrBuf();;
+       StrBufExtract_token(dav_roomname, dav_pathname, 2, '/');
+       StrBufExtract_token(dav_uid, dav_pathname, 3, '/');
+       if ((!strcasecmp(ChrPtr(dav_uid), "ics")) || 
+           (!strcasecmp(ChrPtr(dav_uid), "calendar.ics"))) {
+               FlushStrBuf(dav_uid);
        }
 
        /* Go to the correct room. */
-       if (strcasecmp(WC->wc_roomname, dav_roomname)) {
+       if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_roomname))) {
                gotoroom(dav_roomname);
        }
-       if (strcasecmp(WC->wc_roomname, dav_roomname)) {
+       if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_roomname))) {
                hprintf("HTTP/1.1 404 not found\r\n");
                groupdav_common_headers();
                hprintf("Content-Type: text/plain\r\n");
                wprintf("There is no folder called \"%s\" on this server.\r\n",
-                       dav_roomname);
+                       ChrPtr(dav_roomname));
                end_burst();
+               FreeStrBuf(&dav_roomname);
+               FreeStrBuf(&dav_uid);           
                return;
        }
 
@@ -103,7 +108,7 @@ void groupdav_put(const char *dav_pathname, char *dav_ifmatch,
         */
        if (!IsEmptyStr(dav_ifmatch)) {
                lprintf(9, "dav_ifmatch: %s\n", dav_ifmatch);
-               old_msgnum = locate_message_by_uid(dav_uid);
+               old_msgnum = locate_message_by_uid(ChrPtr(dav_uid));
                lprintf(9, "old_msgnum:  %ld\n", old_msgnum);
                if (atol(dav_ifmatch) != old_msgnum) {
                        hprintf("HTTP/1.1 412 Precondition Failed\r\n");
@@ -112,14 +117,18 @@ void groupdav_put(const char *dav_pathname, char *dav_ifmatch,
                        groupdav_common_headers();
                        hprintf("Content-Length: 0\r\n");
                        end_burst();
+                       FreeStrBuf(&dav_roomname);
+                       FreeStrBuf(&dav_uid);
                        return;
                }
        }
 
        /** PUT on the collection itself uploads an ICS of the entire collection.
         */
-       if (!strcasecmp(dav_uid, "")) {
+       if (StrLength(dav_uid) > 0) {
                groupdav_put_bigics(dav_content, offset);
+               FreeStrBuf(&dav_roomname);
+               FreeStrBuf(&dav_uid);
                return;
        }
 
@@ -147,17 +156,20 @@ void groupdav_put(const char *dav_pathname, char *dav_ifmatch,
 
        /* Fetch the reply from the Citadel server */
        n = 0;
-       strcpy(dav_uid, "");
+       FlushStrBuf(dav_uid);
        while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
                switch(n++) {
-                       case 0: new_msgnum = atol(buf);
-                               break;
-                       case 1: lprintf(9, "new_msgnum=%ld (%s)\n", new_msgnum, buf);
-                               break;
-                       case 2: strcpy(dav_uid, buf);
-                               break;
-                       default:
-                               break;
+               case 0: 
+                       new_msgnum = atol(buf);
+                       break;
+               case 1: 
+                       lprintf(9, "new_msgnum=%ld (%s)\n", new_msgnum, buf);
+                       break;
+               case 2: 
+                       StrBufAppendBufPlain(dav_uid, buf, -1, 0);
+                       break;
+               default:
+                       break;
                }
        }
 
@@ -171,6 +183,8 @@ void groupdav_put(const char *dav_pathname, char *dav_ifmatch,
                wprintf("new_msgnum is %ld\r\n"
                        "\r\n", new_msgnum);
                end_burst();
+               FreeStrBuf(&dav_roomname);
+               FreeStrBuf(&dav_uid);
                return;
        }
 
@@ -184,10 +198,12 @@ void groupdav_put(const char *dav_pathname, char *dav_ifmatch,
                hprintf("Location: ");
                groupdav_identify_host();
                hprintf("/groupdav/");/* TODO */
-               hurlescputs(dav_roomname);
-               euid_escapize(escaped_uid, dav_uid);
+               hurlescputs(ChrPtr(dav_roomname));
+               euid_escapize(escaped_uid, ChrPtr(dav_uid));
                hprintf("/%s\r\n", escaped_uid);
                end_burst();
+               FreeStrBuf(&dav_roomname);
+               FreeStrBuf(&dav_uid);
                return;
        }
 
@@ -204,5 +220,7 @@ void groupdav_put(const char *dav_pathname, char *dav_ifmatch,
        serv_printf("DELE %ld", old_msgnum);
        serv_getln(buf, sizeof buf);
        end_burst();
+       FreeStrBuf(&dav_roomname);
+       FreeStrBuf(&dav_uid);
        return;
 }
index 908e65424e1e00bbf8f1d60ec062c8462164b48b..f3db04ce9783427b1d5ed8060121eebb37b4e389 100644 (file)
@@ -64,13 +64,13 @@ void http_datestring(char *buf, size_t n, time_t xtime) {
 }
 
 
-void tmplput_nowstr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_nowstr(StrBuf *Target, WCTemplputParams *TP)
 {
        time_t now;
        now = time(NULL);
        StrEscAppend(Target, NULL, asctime(localtime(&now)), 0, 0);
 }
-void tmplput_nowno(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_nowno(StrBuf *Target, WCTemplputParams *TP)
 {
        time_t now;
        now = time(NULL);
index 11609590855f0c3cd9ba62fb8e36cfa42372eb9c..044825592e4d213c0eeda42f6149c55a74eb96b1 100644 (file)
@@ -21,7 +21,7 @@
 icaltimezone *get_default_icaltimezone(void) {
 
         icaltimezone *zone = NULL;
-       char *default_zone_name = serv_info.serv_default_cal_zone;
+       const char *default_zone_name = ChrPtr(serv_info.serv_default_cal_zone);
 
         if (!zone) {
                 zone = icaltimezone_get_builtin_timezone(default_zone_name);
index a55e72c71466c448f0f40886ae6be7cf75ad3c54..ee216df1df16947bcbcaafbd0819309d10a8a1a0 100644 (file)
@@ -804,7 +804,7 @@ void commit_iconbar(void) {
 }
 
 
-void tmplput_iconbar(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_iconbar(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        
index 97820b7ab6473208726daee9f53405b6bd5e9826..5e0bd5b11403f45604577734de56451748c308ce 100644 (file)
@@ -175,12 +175,12 @@ void new_save_inetconf(void) {
        url_do_template();
 }
 
-void InetCfgSubst(StrBuf *TemplBuffer, void *vContext, WCTemplateToken *Tokens)
+void InetCfgSubst(StrBuf *TemplBuffer, WCTemplputParams *TP)
 {
-       SVPutBuf("SERVCFG:INET:HOSTNAME", vContext, 1);
+       SVPutBuf("SERVCFG:INET:HOSTNAME", CTX, 1);
 }
 
-void DeleteInetConfHash(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void DeleteInetConfHash(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
 
@@ -190,7 +190,7 @@ void DeleteInetConfHash(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void
 }
 
 
-HashList *GetInetConfHash(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+HashList *GetInetConfHash(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        void *vHash;
@@ -198,7 +198,7 @@ HashList *GetInetConfHash(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo
        if (WCC->InetCfg == NULL)
                load_inetconf();
        GetHash(WCC->InetCfg, TKEY(2), &vHash);
-       svprintf(HKEY("SERVCFG:INET:TYPE"), WCS_STRING, Tokens->Params[2]->Start);
+       svprintf(HKEY("SERVCFG:INET:TYPE"), WCS_STRING, TP->Tokens->Params[2]->Start);
        return vHash;
 }
 
index 0f2fd8e86a395d7873f97f937befd9b9117a0320..a694cd227e6cf689efc6f1723c5f4559c959861c 100644 (file)
@@ -23,10 +23,10 @@ void do_listsub(void)
        int self;
        char sroom[SIZ];
 
-       strcpy(WC->wc_fullname, "");
-       strcpy(WC->wc_username, "");
-       strcpy(WC->wc_password, "");
-       strcpy(WC->wc_roomname, "");
+       FlushStrBuf(WC->wc_fullname);
+       FlushStrBuf(WC->wc_username);
+       FlushStrBuf(WC->wc_password);
+       FlushStrBuf(WC->wc_roomname);
 
        output_headers(1, 0, 0, 1, 1, 0);
        begin_burst();
index 60de06cb5be02e70e2fdb9eb89ddeef23220dcac..82c28918baaafb6b92037f56714454e7672d4ba8 100644 (file)
@@ -11,7 +11,7 @@ void display_main_menu(void)
 {
        begin_burst();
        output_headers(1, 0, 0, 0, 1, 0);
-       DoTemplate(HKEY("display_main_menu"), NULL, NULL, 0);
+       DoTemplate(HKEY("display_main_menu"), NULL, &NoCtx);
        end_burst();
 
 /*
@@ -161,7 +161,7 @@ void display_aide_menu(void)
 {
        begin_burst();
        output_headers(1, 0, 0, 0, 1, 0);
-       DoTemplate(HKEY("display_aide_menu"), NULL, NULL, 0);
+       DoTemplate(HKEY("display_aide_menu"), NULL, &NoCtx);
        end_burst();
 /*
        output_headers(1, 1, 2, 0, 0, 0);
@@ -369,7 +369,7 @@ void display_shutdown(void)
                }
                begin_burst();
                output_headers(1, 0, 0, 0, 1, 0);
-               DoTemplate(HKEY("display_serverrestart"), NULL, NULL, 0);
+               DoTemplate(HKEY("display_serverrestart"), NULL, &NoCtx);
                end_burst();
                lingering_close(WC->http_sock);
                sleeeeeeeeeep(10);
@@ -384,7 +384,7 @@ void display_shutdown(void)
                {
                        begin_burst();
                        output_headers(1, 0, 0, 0, 1, 0);
-                       DoTemplate(HKEY("display_serverrestartpage"), NULL, NULL, 0);
+                       DoTemplate(HKEY("display_serverrestartpage"), NULL, &NoCtx);
                        end_burst();
                }
                else
@@ -393,7 +393,7 @@ void display_shutdown(void)
                        serv_getln(buf, sizeof buf); /* TODO: should we care? */
                        begin_burst();
                        output_headers(1, 0, 0, 0, 1, 0);
-                       DoTemplate(HKEY("display_serverrestartpagedo"), NULL, NULL, 0);
+                       DoTemplate(HKEY("display_serverrestartpagedo"), NULL, &NoCtx);
                        end_burst();                    
                }
        }
@@ -409,7 +409,7 @@ void display_shutdown(void)
                }
                begin_burst();
                output_headers(1, 0, 0, 0, 1, 0);
-               DoTemplate(HKEY("display_aide_menu"), NULL, NULL, 0);
+               DoTemplate(HKEY("display_aide_menu"), NULL, &NoCtx);
                end_burst();                    
        }
 }
index 141a63a74f53dc0fca0d7199aeeaf870a85282f1..2aca9e37c782371d98a0f161cc2a3c4d66839ccb 100644 (file)
@@ -64,6 +64,7 @@ int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, in
        int state=0;
        long len;
        const char *Key;
+       WCTemplputParams SubTP;
 
        Buf = NewStrBuf();
        lprintf(1, "----------%s---------MSG4 %ld|%s--------------\n", tmpl, msgnum, ChrPtr(PartNum));
@@ -213,8 +214,8 @@ int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, in
        else 
        {
                if ((StrLength(Msg->OtherNode)>0) && 
-                   (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_nodename)) &&
-                   (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_humannode)) ) 
+                   (strcasecmp(ChrPtr(Msg->OtherNode), ChrPtr(serv_info.serv_nodename))) &&
+                   (strcasecmp(ChrPtr(Msg->OtherNode), ChrPtr(serv_info.serv_humannode)) ))
                {
                        if (Msg->reply_to == NULL)
                                Msg->reply_to = NewStrBuf();
@@ -239,8 +240,10 @@ int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, in
                evaluate_mime_part(Msg, Mime);
        }
        DeleteHashPos(&it);
-
-       DoTemplate(tmpl, tmpllen, Target, Msg, CTX_MAILSUM);
+       memset(&SubTP, 0, sizeof(WCTemplputParams));
+       SubTP.ContextType = CTX_MAILSUM;
+       SubTP.Context = Msg;
+       DoTemplate(tmpl, tmpllen, Target, &SubTP);
 
        DestroyMessageSummary(Msg);
        FreeStrBuf(&FoundCharset);
@@ -444,8 +447,8 @@ int load_msg_ptrs(char *servcmd, int with_headers)
                                StrBufExtract_token(Buf2, Buf, 3, '|');
                                if ((StrLength(Buf2) !=0 ) &&
                                    ( ((WCC->room_flags & QR_NETWORK)
-                                      || ((strcasecmp(ChrPtr(Buf2), serv_info.serv_nodename)
-                                           && (strcasecmp(ChrPtr(Buf2), serv_info.serv_fqdn)))))))
+                                      || ((strcasecmp(ChrPtr(Buf2), ChrPtr(serv_info.serv_nodename))
+                                           && (strcasecmp(ChrPtr(Buf2), ChrPtr(serv_info.serv_fqdn))))))))
                                {
                                        StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
                                        StrBufAppendBuf(Msg->from, Buf2, 0);
@@ -512,7 +515,11 @@ long DrawMessageDropdown(StrBuf *Selector, long maxmsgs, long startmsg, int nMes
        int nItems;
        HashPos *At;
        long vector[16];
+       WCTemplputParams SubTP;
 
+       memset(&SubTP, 0, sizeof(WCTemplputParams));
+       SubTP.ContextType = CTX_LONGVECTOR;
+       SubTP.Context = &vector;
        TmpBuf = NewStrBuf();
        At = GetNewHashPos(WCC->summ, nMessages);
        nItems = GetCount(WCC->summ);
@@ -563,7 +570,7 @@ long DrawMessageDropdown(StrBuf *Selector, long maxmsgs, long startmsg, int nMes
                vector[6] = lo;
                FlushStrBuf(TmpBuf);
                dbg_print_longvector(vector);
-               DoTemplate(HKEY("select_messageindex"), TmpBuf, &vector, CTX_LONGVECTOR);
+               DoTemplate(HKEY("select_messageindex"), TmpBuf, &SubTP);
                StrBufAppendBuf(Selector, TmpBuf, 0);
        }
        vector[6] = 0;
@@ -571,7 +578,7 @@ long DrawMessageDropdown(StrBuf *Selector, long maxmsgs, long startmsg, int nMes
        vector[1] = lbstr("maxmsgs") == 9999999;
        vector[2] = 0;
        dbg_print_longvector(vector);
-       DoTemplate(HKEY("select_messageindex_all"), TmpBuf, &vector, CTX_LONGVECTOR);
+       DoTemplate(HKEY("select_messageindex_all"), TmpBuf, &SubTP);
        StrBufAppendBuf(Selector, TmpBuf, 0);
        FreeStrBuf(&TmpBuf);
        DeleteHashPos(&At);
@@ -591,7 +598,7 @@ void load_seen_flags(void)
        OldMsg = NewStrBuf();
        serv_puts("GTSN");
        StrBuf_ServGetln(OldMsg);
-       if (ChrPtr(OldMsg)[0] == '2') {
+       if (GetServerStatus(OldMsg, NULL) == 2) {
                StrBufCutLeft(OldMsg, 4);
        }
        else {
@@ -651,13 +658,14 @@ void readloop(long oper)
        int load_seen = 0;
        int sortit = 0;
        int defaultsortorder = 0;
+       WCTemplputParams SubTP;
 
        if (havebstr("is_summary") && (1 == (ibstr("is_summary"))))
                WCC->wc_view = VIEW_MAILBOX;
 
        switch (WCC->wc_view) {
        case VIEW_WIKI:
-               sprintf(buf, "wiki?room=%s&page=home", WCC->wc_roomname);
+               sprintf(buf, "wiki?room=%s&page=home", ChrPtr(WCC->wc_roomname));
                http_redirect(buf);
                return;
        case VIEW_CALBRIEF:
@@ -745,7 +753,10 @@ void readloop(long oper)
 
        if (sortit) {
                CompareFunc SortIt;
-               SortIt =  RetrieveSort(CTX_MAILSUM, NULL, 
+               memset(&SubTP, 0, sizeof(WCTemplputParams));
+               SubTP.ContextType = CTX_NONE;
+               SubTP.Context = NULL;
+               SortIt =  RetrieveSort(&SubTP, NULL, 
                                       HKEY("date"), defaultsortorder);
                if (SortIt != NULL)
                        SortByPayload(WCC->summ, SortIt);
@@ -784,7 +795,10 @@ void readloop(long oper)
                                maxmsgs = abs(maxmsgs);
 
                }
-               DoTemplate(HKEY("msg_listselector_top"), BBViewToolBar, MessageDropdown, CTX_STRBUF);
+               memset(&SubTP, 0, sizeof(WCTemplputParams));
+               SubTP.ContextType = CTX_STRBUF;
+               SubTP.Context = MessageDropdown;
+               DoTemplate(HKEY("msg_listselector_top"), BBViewToolBar, &SubTP);
                StrBufAppendBuf(WCC->WBuf, BBViewToolBar, 0);
                FlushStrBuf(BBViewToolBar);
                break;
@@ -821,7 +835,10 @@ void readloop(long oper)
                                addrbook[num_ab-1].ab_msgnum = Msg->msgnum;
                                break;
                        case VIEW_MAILBOX: /* here we just need the abstract, so render it now. */
-                               DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
+                               memset(&SubTP, 0, sizeof(WCTemplputParams));
+                               SubTP.ContextType = CTX_MAILSUM;
+                               SubTP.Context = Msg;
+                               DoTemplate(HKEY("section_mailsummary"), NULL, &SubTP);
                        
                                num_displayed++;
                                break;
@@ -865,7 +882,10 @@ void readloop(long oper)
                        free(displayed_msgs);
                        displayed_msgs = NULL;
                }
-               DoTemplate(HKEY("msg_listselector_bottom"), BBViewToolBar, MessageDropdown, CTX_STRBUF);
+               memset(&SubTP, 0, sizeof(WCTemplputParams));
+               SubTP.ContextType = CTX_STRBUF;
+               SubTP.Context = MessageDropdown;
+               DoTemplate(HKEY("msg_listselector_bottom"), BBViewToolBar, &SubTP);
                StrBufAppendBuf(WCC->WBuf, BBViewToolBar, 0);
 
                FreeStrBuf(&BBViewToolBar);
@@ -924,12 +944,12 @@ void post_mime_to_server(void) {
        char *txtmail = NULL;
 
        sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
-               serv_info.serv_fqdn,
+               ChrPtr(serv_info.serv_fqdn),
                getpid(),
                ++seq
        );
        sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
-               serv_info.serv_fqdn,
+               ChrPtr(serv_info.serv_fqdn),
                getpid(),
                ++seq
        );
@@ -1029,7 +1049,7 @@ void post_message(void)
        wcsession *WCC = WC;
        
        if (havebstr("force_room")) {
-               gotoroom(bstr("force_room"));
+               gotoroom(sbstr("force_room"));
        }
 
        if (havebstr("display_name")) {
@@ -1222,7 +1242,7 @@ void display_enter(void)
        now = time(NULL);
 
        if (havebstr("force_room")) {
-               gotoroom(bstr("force_room"));
+               gotoroom(sbstr("force_room"));
        }
 
        display_name = sbstr("display_name");
@@ -1254,7 +1274,7 @@ void display_enter(void)
         * message" command really means "add new entry."
         */
        if (WCC->wc_default_view == VIEW_ADDRESSBOOK) {
-               do_edit_vcard(-1, "", "", WCC->wc_roomname);
+               do_edit_vcard(-1, "", "", ChrPtr(WCC->wc_roomname));
                return;
        }
 
@@ -1331,7 +1351,7 @@ void display_enter(void)
 
        begin_burst();
        output_headers(1, 0, 0, 0, 1, 0);
-       DoTemplate(HKEY("edit_message"), NULL, NULL, CTX_NONE);
+       DoTemplate(HKEY("edit_message"), NULL, &NoCtx);
        end_burst();
 
        return;
index a124070568399b7903a09abd1cc4a1a81503f6df..450e66889137ce3376a363ced50d7aaf30efbea1 100644 (file)
@@ -233,9 +233,9 @@ void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
        if (!strncasecmp(ChrPtr(HdrLine), "yes", 8))
                Msg->nhdr = 1;
 }
-int Conditional_ANONYMOUS_MESSAGE(WCTemplateToken *Tokens, void *Context, int ContextType)
+int Conditional_ANONYMOUS_MESSAGE(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
+       message_summary *Msg = (message_summary*) CTX;
        return Msg->nhdr != 0;
 }
 
@@ -252,10 +252,10 @@ void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
        Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
        StrBuf_RFC822_to_Utf8(Msg->from, HdrLine, WC->DefaultCharset, FoundCharset);
 }
-void tmplput_MAIL_SUMM_FROM(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MAIL_SUMM_FROM(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->from, 0);
+       message_summary *Msg = (message_summary*) CTX;
+       StrBufAppendTemplate(Target, TP, Msg->from, 0);
 }
 
 
@@ -266,11 +266,11 @@ void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
        Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
        StrBuf_RFC822_to_Utf8(Msg->subj, HdrLine, WC->DefaultCharset, FoundCharset);
 }
-void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
 {/*////TODO: Fwd: and RE: filter!!*/
 
-       message_summary *Msg = (message_summary*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->subj, 0);
+       message_summary *Msg = (message_summary*) CTX;
+       StrBufAppendTemplate(Target, TP, Msg->subj, 0);
 }
 
 
@@ -280,15 +280,15 @@ void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
        Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
        StrBuf_RFC822_to_Utf8(Msg->reply_inreplyto, HdrLine, WC->DefaultCharset, FoundCharset);
 }
-void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->reply_inreplyto, 0);
+       message_summary *Msg = (message_summary*) CTX;
+       StrBufAppendTemplate(Target, TP, Msg->reply_inreplyto, 0);
 }
 
-int Conditional_MAIL_SUMM_UNREAD(WCTemplateToken *Tokens, void *Context, int ContextType)
+int Conditional_MAIL_SUMM_UNREAD(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
+       message_summary *Msg = (message_summary*) CTX;
        return Msg->is_new != 0;
 }
 
@@ -298,10 +298,10 @@ void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
        Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
        StrBuf_RFC822_to_Utf8(Msg->reply_references, HdrLine, WC->DefaultCharset, FoundCharset);
 }
-void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->reply_references, 0);
+       message_summary *Msg = (message_summary*) CTX;
+       StrBufAppendTemplate(Target, TP, Msg->reply_references, 0);
 }
 
 
@@ -317,25 +317,25 @@ void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
        }
        StrBufAppendBuf(Msg->AllRcpt, Msg->cccc, 0);
 }
-void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->cccc, 0);
+       message_summary *Msg = (message_summary*) CTX;
+       StrBufAppendTemplate(Target, TP, Msg->cccc, 0);
 }
 
 
 void examine_room(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
 {
        if ((StrLength(HdrLine) > 0) &&
-           (strcasecmp(ChrPtr(HdrLine), WC->wc_roomname))) {
+           (strcasecmp(ChrPtr(HdrLine), ChrPtr(WC->wc_roomname)))) {
                FreeStrBuf(&Msg->Room);
                Msg->Room = NewStrBufDup(HdrLine);              
        }
 }
-void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->Room, 0);
+       message_summary *Msg = (message_summary*) CTX;
+       StrBufAppendTemplate(Target, TP, Msg->Room, 0);
 }
 
 
@@ -344,14 +344,14 @@ void examine_rfca(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
        FreeStrBuf(&Msg->Rfca);
        Msg->Rfca = NewStrBufDup(HdrLine);
 }
-void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->Rfca, 0);
+       message_summary *Msg = (message_summary*) CTX;
+       StrBufAppendTemplate(Target, TP, Msg->Rfca, 0);
 }
-int Conditional_MAIL_SUMM_RFCA(WCTemplateToken *Tokens, void *Context, int ContextType)
+int Conditional_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
+       message_summary *Msg = (message_summary*) CTX;
        return StrLength(Msg->Rfca) > 0;
 }
 
@@ -359,20 +359,20 @@ void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
 {
        if ( (StrLength(HdrLine) > 0) &&
             ((WC->room_flags & QR_NETWORK)
-             || ((strcasecmp(ChrPtr(HdrLine), serv_info.serv_nodename)
-                  && (strcasecmp(ChrPtr(HdrLine), serv_info.serv_fqdn)))))) {
+             || ((strcasecmp(ChrPtr(HdrLine), ChrPtr(serv_info.serv_nodename))
+                  && (strcasecmp(ChrPtr(HdrLine), ChrPtr(serv_info.serv_fqdn))))))) {
                FreeStrBuf(&Msg->OtherNode);
                Msg->OtherNode = NewStrBufDup(HdrLine);
        }
 }
-void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->OtherNode, 0);
+       message_summary *Msg = (message_summary*) CTX;
+       StrBufAppendTemplate(Target, TP, Msg->OtherNode, 0);
 }
-int Conditional_MAIL_SUMM_OTHERNODE(WCTemplateToken *Tokens, void *Context, int ContextType)
+int Conditional_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
+       message_summary *Msg = (message_summary*) CTX;
        return StrLength(Msg->OtherNode) > 0;
 }
 
@@ -389,19 +389,19 @@ void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
        }
        StrBufAppendBuf(Msg->AllRcpt, Msg->to, 0);
 }
-void tmplput_MAIL_SUMM_TO(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->to, 0);
+       message_summary *Msg = (message_summary*) CTX;
+       StrBufAppendTemplate(Target, TP, Msg->to, 0);
 }
-void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->AllRcpt, 0);
+       message_summary *Msg = (message_summary*) CTX;
+       StrBufAppendTemplate(Target, TP, Msg->AllRcpt, 0);
 }
 
 
-HashList *iterate_get_mailsumm_All(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+HashList *iterate_get_mailsumm_All(StrBuf *Target, WCTemplputParams *TP)
 {
        return WC->summ;
 }
@@ -410,23 +410,25 @@ void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
 {
        Msg->date = StrTol(HdrLine);
 }
-void tmplput_MAIL_SUMM_DATE_BRIEF(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+
+void tmplput_MAIL_SUMM_DATE_BRIEF(StrBuf *Target, WCTemplputParams *TP)
 {
        char datebuf[64];
-       message_summary *Msg = (message_summary*) Context;
+       message_summary *Msg = (message_summary*) CTX;
        webcit_fmt_date(datebuf, Msg->date, 1);
        StrBufAppendBufPlain(Target, datebuf, -1, 0);
 }
-void tmplput_MAIL_SUMM_DATE_FULL(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+
+void tmplput_MAIL_SUMM_DATE_FULL(StrBuf *Target, WCTemplputParams *TP)
 {
        char datebuf[64];
-       message_summary *Msg = (message_summary*) Context;
+       message_summary *Msg = (message_summary*) CTX;
        webcit_fmt_date(datebuf, Msg->date, 0);
        StrBufAppendBufPlain(Target, datebuf, -1, 0);
 }
-void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
+       message_summary *Msg = (message_summary*) CTX;
        StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
 }
 
@@ -451,13 +453,14 @@ void render_MAIL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset
 
 void render_MIME_VCard(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
 {
+       wcsession *WCC = WC;
        MimeLoadData(Mime);
        if (StrLength(Mime->Data) > 0) {
                StrBuf *Buf;
                Buf = NewStrBuf();
                /** If it's my vCard I can edit it */
-               if (    (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
-                       || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
+               if (    (!strcasecmp(ChrPtr(WCC->wc_roomname), USERCONFIGROOM))
+                       || (!strcasecmp(&(ChrPtr(WCC->wc_roomname)[11]), USERCONFIGROOM))
                        || (WC->wc_view == VIEW_ADDRESSBOOK)
                        ) {
                        StrBufAppendPrintf(Buf, "<a href=\"edit_vcard?msgnum=%ld&partnum=%s\">",
@@ -579,9 +582,9 @@ void evaluate_mime_part(message_summary *Msg, wc_mime_attachment *Mime)
        }
 }
 
-void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
+       message_summary *Msg = (message_summary*) CTX;
        StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments));
 }
 
@@ -592,14 +595,14 @@ void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
        Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
        StrBuf_RFC822_to_Utf8(Msg->hnod, HdrLine, WC->DefaultCharset, FoundCharset);
 }
-void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->hnod, 0);
+       message_summary *Msg = (message_summary*) CTX;
+       StrBufAppendTemplate(Target, TP, Msg->hnod, 0);
 }
-int Conditional_MAIL_SUMM_H_NODE(WCTemplateToken *Tokens, void *Context, int ContextType)
+int Conditional_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
+       message_summary *Msg = (message_summary*) CTX;
        return StrLength(Msg->hnod) > 0;
 }
 
@@ -674,42 +677,42 @@ void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCh
        }
 }
 
-void tmplput_MAIL_SUMM_N(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MAIL_SUMM_N(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
+       message_summary *Msg = (message_summary*) CTX;
        StrBufAppendPrintf(Target, "%ld", Msg->msgnum);
 }
 
 
 
-int Conditional_MAIL_MIME_ALL(WCTemplateToken *Tokens, void *Context, int ContextType)
+int Conditional_MAIL_MIME_ALL(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
+       message_summary *Msg = (message_summary*) CTX;
        return GetCount(Msg->Attachments) > 0;
 }
 
-int Conditional_MAIL_MIME_SUBMESSAGES(WCTemplateToken *Tokens, void *Context, int ContextType)
+int Conditional_MAIL_MIME_SUBMESSAGES(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
+       message_summary *Msg = (message_summary*) CTX;
        return GetCount(Msg->Submessages) > 0;
 }
 
-int Conditional_MAIL_MIME_ATTACHLINKS(WCTemplateToken *Tokens, void *Context, int ContextType)
+int Conditional_MAIL_MIME_ATTACHLINKS(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
+       message_summary *Msg = (message_summary*) CTX;
        return GetCount(Msg->AttachLinks) > 0;
 }
 
-int Conditional_MAIL_MIME_ATTACH(WCTemplateToken *Tokens, void *Context, int ContextType)
+int Conditional_MAIL_MIME_ATTACH(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
+       message_summary *Msg = (message_summary*) CTX;
        return GetCount(Msg->AllAttach) > 0;
 }
 
 
 
 /*----------------------------------------------------------------------------*/
-void tmplput_QUOTED_MAIL_BODY(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_QUOTED_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
 {
        long MsgNum;
        StrBuf *Buf;
@@ -717,14 +720,14 @@ void tmplput_QUOTED_MAIL_BODY(StrBuf *Target, int nArgs, WCTemplateToken *Tokens
        MsgNum = LBstr(TKEY(0));
        Buf = NewStrBuf();
        read_message(Buf, HKEY("view_message_replyquote"), MsgNum, 0, NULL);
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Buf, 1);
+       StrBufAppendTemplate(Target, TP, Buf, 1);
        FreeStrBuf(&Buf);
 }
 
-void tmplput_MAIL_BODY(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->MsgBody->Data, 0);
+       message_summary *Msg = (message_summary*) CTX;
+       StrBufAppendTemplate(Target, TP, Msg->MsgBody->Data, 0);
 }
 
 
@@ -880,61 +883,61 @@ void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *Foun
 
 
 
-HashList *iterate_get_mime_All(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+HashList *iterate_get_mime_All(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
+       message_summary *Msg = (message_summary*) CTX;
        return Msg->Attachments;
 }
-HashList *iterate_get_mime_Submessages(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+HashList *iterate_get_mime_Submessages(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
+       message_summary *Msg = (message_summary*) CTX;
        return Msg->Submessages;
 }
-HashList *iterate_get_mime_AttachLinks(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+HashList *iterate_get_mime_AttachLinks(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
+       message_summary *Msg = (message_summary*) CTX;
        return Msg->AttachLinks;
 }
-HashList *iterate_get_mime_Attachments(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+HashList *iterate_get_mime_Attachments(StrBuf *Target, WCTemplputParams *TP)
 {
-       message_summary *Msg = (message_summary*) Context;
+       message_summary *Msg = (message_summary*) CTX;
        return Msg->AllAttach;
 }
 
-void tmplput_MIME_Name(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MIME_Name(StrBuf *Target, WCTemplputParams *TP)
 {
-       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, mime->Name, 0);
+       wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
+       StrBufAppendTemplate(Target, TP, mime->Name, 0);
 }
 
-void tmplput_MIME_FileName(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MIME_FileName(StrBuf *Target, WCTemplputParams *TP)
 {
-       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, mime->FileName, 0);
+       wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
+       StrBufAppendTemplate(Target, TP, mime->FileName, 0);
 }
 
-void tmplput_MIME_PartNum(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MIME_PartNum(StrBuf *Target, WCTemplputParams *TP)
 {
-       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, mime->PartNum, 0);
+       wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
+       StrBufAppendTemplate(Target, TP, mime->PartNum, 0);
 }
 
-void tmplput_MIME_MsgNum(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MIME_MsgNum(StrBuf *Target, WCTemplputParams *TP)
 {
-       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
+       wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
        StrBufAppendPrintf(Target, "%ld", mime->msgnum);
 }
 
-void tmplput_MIME_Disposition(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MIME_Disposition(StrBuf *Target, WCTemplputParams *TP)
 {
-       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, mime->Disposition, 0);
+       wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
+       StrBufAppendTemplate(Target, TP, mime->Disposition, 0);
 }
 
-void tmplput_MIME_ContentType(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MIME_ContentType(StrBuf *Target, WCTemplputParams *TP)
 {
-       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, mime->ContentType, 0);
+       wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
+       StrBufAppendTemplate(Target, TP, mime->ContentType, 0);
 }
 
 void examine_charset(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
@@ -942,25 +945,25 @@ void examine_charset(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset
        Msg->MsgBody->Charset = NewStrBufDup(HdrLine);
 }
 
-void tmplput_MIME_Charset(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MIME_Charset(StrBuf *Target, WCTemplputParams *TP)
 {
-       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, mime->Charset, 0);
+       wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
+       StrBufAppendTemplate(Target, TP, mime->Charset, 0);
 }
 
-void tmplput_MIME_Data(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MIME_Data(StrBuf *Target, WCTemplputParams *TP)
 {
-       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
+       wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
        if (mime->Renderer != NULL)
                mime->Renderer->f(mime, NULL, NULL);
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, mime->Data, 0);
+       StrBufAppendTemplate(Target, TP, mime->Data, 0);
        /* TODO: check whether we need to load it now? */
 }
 
-void tmplput_MIME_LoadData(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MIME_LoadData(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;    
-       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
+       wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
        wc_mime_attachment *att;
        
        if ( (!strcasecmp(ChrPtr(mime->Disposition), "inline"))||
@@ -985,13 +988,13 @@ void tmplput_MIME_LoadData(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, v
        }
 }
 
-void tmplput_MIME_Length(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_MIME_Length(StrBuf *Target, WCTemplputParams *TP)
 {
-       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
+       wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
        StrBufAppendPrintf(Target, "%ld", mime->length);
 }
 
-HashList *iterate_get_registered_Attachments(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+HashList *iterate_get_registered_Attachments(StrBuf *Target, WCTemplputParams *TP)
 {
        return WC->attachments;
 }
index 456b7f6c7340bdf601435685aa32e5b54ed296c9..5f9087228076de8e9abdd5957c8759f4049839ae 100644 (file)
@@ -81,7 +81,7 @@ void SerializeNode(NodeConf *Node, StrBuf *Buf)
 }
 
 
-HashList *load_netconf(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+HashList *load_netconf(StrBuf *Target, WCTemplputParams *TP)
 {
        StrBuf *Buf;
        HashList *Hash;
@@ -113,16 +113,6 @@ HashList *load_netconf(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void
 }
 
 
-void NodeCfgSubst(StrBuf *TemplBuffer, void *vContext, WCTemplateToken *Token)
-{
-       NodeConf *Node= (NodeConf*)vContext;
-
-       SVPutBuf("CFG:IGNET:NODE", Node->NodeName, 1);
-       SVPutBuf("CFG:IGNET:SECRET", Node->Secret, 1);
-       SVPutBuf("CFG:IGNET:HOST", Node->Host, 1);
-       SVPutBuf("CFG:IGNET:PORT", Node->Port, 1);
-}
-
 
 void save_net_conf(HashList *Nodelist)
 {
@@ -178,7 +168,7 @@ void edit_node(void) {
                        return;
                }
                        
-               NodeConfig = load_netconf(NULL, 0, NULL, NULL, CTX_NONE);
+               NodeConfig = load_netconf(NULL, &NoCtx);
                Put(NodeConfig, ChrPtr(Index), StrLength(Index), NewNode, DeleteNodeConf);
                save_net_conf(NodeConfig);
                DeleteHash(&NodeConfig);
@@ -192,9 +182,11 @@ void edit_node(void) {
  */
 void display_edit_node(void)
 {
+       WCTemplputParams SubTP;
        HashList *NodeConfig;
        const StrBuf *Index;
        void *vNode;
+       const StrBuf *Tmpl;
 
        Index = sbstr("index");
        if (Index == NULL) {
@@ -203,7 +195,7 @@ void display_edit_node(void)
                return;
        }
 
-       NodeConfig = load_netconf(NULL, 0, NULL, NULL, CTX_NONE);
+       NodeConfig = load_netconf(NULL, &NoCtx);
        if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || 
            (vNode == NULL)) {
                sprintf(WC->ImportantMessage, _("Invalid Parameter"));
@@ -212,10 +204,15 @@ void display_edit_node(void)
                return;
        }
        
-       NodeCfgSubst(NULL, vNode, NULL);
+       memset(&SubTP, 0, sizeof(WCTemplputParams));
        SVPutBuf("ITERATE:KEY", Index, 1);
-       url_do_template();
-
+       SubTP.ContextType = CTX_NODECONF;
+       SubTP.Context = vNode;
+       begin_burst();
+       Tmpl = sbstr("template");
+        output_headers(1, 0, 0, 0, 1, 0);
+        DoTemplate(SKEY(Tmpl), NULL, &SubTP);
+        end_burst();                                                                               
        DeleteHash(&NodeConfig);
        
 }
@@ -255,7 +252,7 @@ void delete_node(void)
                return;
        }
 
-       NodeConfig = load_netconf(NULL, 0, NULL, NULL, CTX_NONE);
+       NodeConfig = load_netconf(NULL, &NoCtx);
        if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || 
            (vNode == NULL)) {
                sprintf(WC->ImportantMessage, _("Invalid Parameter"));
@@ -272,6 +269,31 @@ void delete_node(void)
 
 }
 
+
+void tmplput_NodeName(StrBuf *Target, WCTemplputParams *TP)
+{
+       NodeConf *Node = (NodeConf*) CTX;       
+       StrBufAppendTemplate(Target, TP, Node->NodeName, 0);
+}
+
+void tmplput_Secret(StrBuf *Target, WCTemplputParams *TP)
+{
+       NodeConf *Node = (NodeConf*) CTX;
+       StrBufAppendTemplate(Target, TP, Node->Secret, 0);
+}
+
+void tmplput_Host(StrBuf *Target, WCTemplputParams *TP) 
+{
+       NodeConf *Node= (NodeConf*) CTX;
+       StrBufAppendTemplate(Target, TP, Node->Host, 0);
+}
+
+void tmplput_Port(StrBuf *Target, WCTemplputParams *TP)
+{
+       NodeConf *Node= (NodeConf*) CTX;
+       StrBufAppendTemplate(Target, TP, Node->Port, 0);
+}
+
 void 
 InitModule_NETCONF
 (void)
@@ -282,6 +304,13 @@ InitModule_NETCONF
        WebcitAddUrlHandler(HKEY("display_netconf"), display_netconf, 0);
        WebcitAddUrlHandler(HKEY("display_confirm_delete_node"), display_confirm_delete_node, 0);
        WebcitAddUrlHandler(HKEY("delete_node"), delete_node, 0);
-       RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NodeCfgSubst, DeleteHash, CTX_NODECONF, CTX_NONE, IT_NOFLAG);
+
+                                                                                          
+        RegisterNamespace("CFG:IGNET:NODE", 0, 1, tmplput_NodeName, CTX_NODECONF);
+        RegisterNamespace("CFG:IGNET:SECRET", 0, 1, tmplput_Secret, CTX_NODECONF);
+        RegisterNamespace("CFG:IGNET:HOST", 0, 1, tmplput_Host, CTX_NODECONF);
+        RegisterNamespace("CFG:IGNET:PORT", 0, 1, tmplput_Port, CTX_NODECONF);
+
+       RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NULL, DeleteHash, CTX_NODECONF, CTX_NONE, IT_NOFLAG);
 }
 /*@}*/
index 48582a9fb2b9f79c939fd990d7f107cf504a7df4..d55fd2f813fabbc9b7eed7d7cd690d5219355854 100644 (file)
@@ -27,7 +27,7 @@ void display_vnote_div(struct vnote *v) {
        int i;
 
 
-       wprintf("<div id=\"note-%s\" ", v->uid);        // begin outer div
+       wprintf("<div id=\"note-%s\" ", v->uid);        /* begin outer div */
        wprintf("class=\"stickynote_outer\" ");
        wprintf("style=\"");
        wprintf("left: %dpx; ", v->pos_left);
@@ -41,7 +41,7 @@ void display_vnote_div(struct vnote *v) {
 
 
 
-       wprintf("<div id=\"titlebar-%s\" ", v->uid);    // begin title bar div
+       wprintf("<div id=\"titlebar-%s\" ", v->uid);    /* begin title bar div */
        wprintf("class=\"stickynote_titlebar\" ");
        wprintf("onMouseDown=\"NotesDragMouseDown(event,'%s')\" ", v->uid);
        wprintf("style=\"");
@@ -339,12 +339,16 @@ void ajax_update_note(void) {
  */
 void display_note(message_summary *Msg, int unread) {
        struct vnote *v;
+       WCTemplputParams TP;
 
+       memset(&TP, 0, sizeof(WCTemplputParams));
+       TP.ContextType = CTX_VNOTE;
        v = vnote_new_from_msg(Msg->msgnum);
        if (v) {
 //             display_vnote_div(v);
+               TP.Context = v;
                DoTemplate(HKEY("vnoteitem"),
-                          WC->WBuf, v, CTX_VNOTE);
+                          WC->WBuf, &TP);
                        
 
                /* uncomment these lines to see ugly debugging info 
@@ -386,63 +390,63 @@ void add_new_note(void) {
 }
 
 
-void tmpl_vcard_put_posleft(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmpl_vcard_put_posleft(StrBuf *Target, WCTemplputParams *TP)
 {
-       struct vnote *v = (struct vnote *) Context;
+       struct vnote *v = (struct vnote *) CTX;
        StrBufAppendPrintf(Target, "%d", v->pos_left);
 }
 
-void tmpl_vcard_put_postop(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmpl_vcard_put_postop(StrBuf *Target, WCTemplputParams *TP)
 {
-       struct vnote *v = (struct vnote *) Context;
+       struct vnote *v = (struct vnote *) CTX;
        StrBufAppendPrintf(Target, "%d", v->pos_top);
 }
 
-void tmpl_vcard_put_poswidth(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmpl_vcard_put_poswidth(StrBuf *Target, WCTemplputParams *TP)
 {
-       struct vnote *v = (struct vnote *) Context;
+       struct vnote *v = (struct vnote *) CTX;
        StrBufAppendPrintf(Target, "%d", v->pos_width);
 }
 
-void tmpl_vcard_put_posheight(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmpl_vcard_put_posheight(StrBuf *Target, WCTemplputParams *TP)
 {
-       struct vnote *v = (struct vnote *) Context;
+       struct vnote *v = (struct vnote *) CTX;
        StrBufAppendPrintf(Target, "%d", v->pos_height);
 }
 
-void tmpl_vcard_put_posheight2(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmpl_vcard_put_posheight2(StrBuf *Target, WCTemplputParams *TP)
 {
-       struct vnote *v = (struct vnote *) Context;
+       struct vnote *v = (struct vnote *) CTX;
        StrBufAppendPrintf(Target, "%d", (v->pos_height / 16) - 5);
 }
 
-void tmpl_vcard_put_width2(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmpl_vcard_put_width2(StrBuf *Target, WCTemplputParams *TP)
 {
-       struct vnote *v = (struct vnote *) Context;
+       struct vnote *v = (struct vnote *) CTX;
        StrBufAppendPrintf(Target, "%d", (v->pos_width / 9) - 1);
 }
 
-void tmpl_vcard_put_color(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmpl_vcard_put_color(StrBuf *Target, WCTemplputParams *TP)
 {
-       struct vnote *v = (struct vnote *) Context;
+       struct vnote *v = (struct vnote *) CTX;
        StrBufAppendPrintf(Target, "%02X%02X%02X", v->color_red, v->color_green, v->color_blue);
 }
 
-void tmpl_vcard_put_bgcolor(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmpl_vcard_put_bgcolor(StrBuf *Target, WCTemplputParams *TP)
 {
-       struct vnote *v = (struct vnote *) Context;
+       struct vnote *v = (struct vnote *) CTX;
        StrBufAppendPrintf(Target, "%02X%02X%02X", v->color_red/2, v->color_green/2, v->color_blue/2);
 }
 
-void tmpl_vcard_put_message(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmpl_vcard_put_message(StrBuf *Target, WCTemplputParams *TP)
 {
-       struct vnote *v = (struct vnote *) Context;
+       struct vnote *v = (struct vnote *) CTX;
        StrEscAppend(Target, NULL, v->body, 0, 0); ///TODO?
 }
 
-void tmpl_vcard_put_uid(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmpl_vcard_put_uid(StrBuf *Target, WCTemplputParams *TP)
 {
-       struct vnote *v = (struct vnote *) Context;
+       struct vnote *v = (struct vnote *) CTX;
        StrBufAppendBufPlain(Target, v->uid, -1, 0);
 }
 
index 464f3c91242dfde6c38db5170e7cd3e8998b5d8d..dc6d09838f20ae8ddc3383e2034e96dc1548e044 100644 (file)
@@ -51,7 +51,7 @@ void display_openids(void)
        }
 
        else {
-               wprintf(_("%s does not permit authentication via OpenID."), serv_info.serv_humannode);
+               wprintf(_("%s does not permit authentication via OpenID."), ChrPtr(serv_info.serv_humannode));
        }
 
        do_template("endbox", NULL);
index acfcdd97c57d4b76c6730e26cfb2d092e74d219b..d3319f127f3bebaf891ed073eb5d92ef6a099e82 100644 (file)
@@ -107,10 +107,13 @@ void do_chat(void)
        char buf[SIZ];
 
        /** First, check to make sure we're still allowed in this room. */
-       serv_printf("GOTO %s", WC->wc_roomname);
+       serv_printf("GOTO %s", ChrPtr(WC->wc_roomname));
        serv_getln(buf, sizeof buf);
        if (buf[0] != '2') {
-               smart_goto("_BASEROOM_");
+               StrBuf *Buf;
+               Buf = NewStrBufPlain(HKEY("_BASEROOM_"));
+               smart_goto(Buf);
+               FreeStrBuf(&Buf);
                return;
        }
 
@@ -229,13 +232,13 @@ int setup_chat_socket(void) {
 
                serv_getln(buf, sizeof buf);
                if (buf[0] == '2') {
-                       serv_printf("USER %s", WC->wc_username);
+                       serv_printf("USER %s", ChrPtr(WC->wc_username));
                        serv_getln(buf, sizeof buf);
                        if (buf[0] == '3') {
-                               serv_printf("PASS %s", WC->wc_password);
+                               serv_printf("PASS %s", ChrPtr(WC->wc_password));
                                serv_getln(buf, sizeof buf);
                                if (buf[0] == '2') {
-                                       serv_printf("GOTO %s", WC->wc_roomname);
+                                       serv_printf("GOTO %s", ChrPtr(WC->wc_roomname));
                                        serv_getln(buf, sizeof buf);
                                        if (buf[0] == '2') {
                                                serv_puts("CHAT");
@@ -382,7 +385,7 @@ void chat_recv(void) {
                                if (strcasecmp(cl_user, WC->last_chat_user)) {
                                        wprintf("<B>");
        
-                                       if (!strcasecmp(cl_user, WC->wc_fullname)) {
+                                       if (!strcasecmp(cl_user, ChrPtr(WC->wc_fullname))) {
                                                wprintf("<FONT COLOR=&quot;#FF0000&quot;>");
                                        }
                                        else {
index 2ebc3530536f8c7be3081d60276199958eb7c7df..c514c44a86dc160c256e0a58ace5aa9391fd5095 100644 (file)
@@ -352,26 +352,24 @@ void PutBstr(const char *key, long keylen, StrBuf *Value)
 
 
 
-int ConditionalBstr(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalBstr(StrBuf *Target, WCTemplputParams *TP)
 {
-       if(Tokens->nParameters == 3)
+       if(TP->Tokens->nParameters == 3)
                return HaveBstr(TKEY(2));
        else {
-               if (Tokens->Params[3]->Type == TYPE_LONG)
-                       return LBstr(TKEY(2)) == Tokens->Params[3]->lvalue;
+               if (TP->Tokens->Params[3]->Type == TYPE_LONG)
+                       return LBstr(TKEY(2)) == TP->Tokens->Params[3]->lvalue;
                else 
                        return strcmp(Bstr(TKEY(2)),
-                                     Tokens->Params[3]->Start) == 0;
+                                     TP->Tokens->Params[3]->Start) == 0;
        }
 }
 
-void tmplput_bstr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_bstr(StrBuf *Target, WCTemplputParams *TP)
 {
        const StrBuf *Buf = SBstr(TKEY(0));
        if (Buf != NULL)
-               StrBufAppendTemplate(Target, nArgs, Tokens, 
-                                    Context, ContextType,
-                                    Buf, 1);
+               StrBufAppendTemplate(Target, TP, Buf, 1);
 }
 
 void diagnostics(void)
@@ -392,37 +390,22 @@ void diagnostics(void)
 }
 
 
-void tmplput_url_part(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_url_part(StrBuf *Target, WCTemplputParams *TP)
 {
        StrBuf *UrlBuf;
        wcsession *WCC = WC;
        
        if (WCC != NULL) {
-               if (Tokens->Params[0]->lvalue == 0)
+               if (TP->Tokens->Params[0]->lvalue == 0)
                        UrlBuf = WCC->UrlFragment1;
-               else if (Tokens->Params[0]->lvalue == 1)
+               else if (TP->Tokens->Params[0]->lvalue == 1)
                        UrlBuf = WCC->UrlFragment2;
                else
                        UrlBuf = WCC->UrlFragment3;
                if (UrlBuf == NULL)  {
-                       lprintf(1, "urlbuf [%s] not set. (in '%s' line %ld);[%s]\n", 
-                               Tokens->Params[0]->Start,
-                               ChrPtr(Tokens->FileName),
-                               Tokens->Line,
-                               ChrPtr(Tokens->FlatToken));
-                       StrBufAppendPrintf(
-                               Target, 
-                               "<pre>\nurlbuf [%s] not set (in '%s' line %ld)\n[%s]\n</pre>\n", 
-                               Tokens->Params[0]->Start,
-                               ChrPtr(Tokens->FileName),
-                               Tokens->Line,
-                               ChrPtr(Tokens->FlatToken));
-
-
-
+                       LogTemplateError(Target, "urlbuf", ERR_PARM1, TP, "not set.");
                }
-               StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType,
-                                    UrlBuf, 2);
+               StrBufAppendTemplate(Target, TP, UrlBuf, 2);
        }
 }
 
index 8118e6eb8792518d513ba7e6a738911729660b4d..46e439f7f1984c70c72cae9dab6442cc521c4633 100644 (file)
@@ -122,7 +122,7 @@ void load_preferences(void)
        }
 
        /* Go back to the room we're supposed to be in */
-       serv_printf("GOTO %s", WC->wc_roomname);
+       serv_printf("GOTO %s", ChrPtr(WC->wc_roomname));
        serv_getln(buf, sizeof buf);
 }
 
@@ -234,7 +234,7 @@ void save_preferences(void) {
        }
 
        /** Go back to the room we're supposed to be in */
-       serv_printf("GOTO %s", WC->wc_roomname);
+       serv_printf("GOTO %s", ChrPtr(WC->wc_roomname));
        serv_getln(buf, sizeof buf);
 }
 
@@ -341,7 +341,7 @@ StrBuf *get_ROOM_PREFS(const char *key, size_t keylen)
        StrBuf *pref_name, *pref_value;
        
        pref_name = NewStrBuf ();
-       StrBufPrintf(pref_name, "%s %s", key, WC->wc_roomname);
+       StrBufPrintf(pref_name, "%s %s", key, ChrPtr(WC->wc_roomname));
        get_pref(pref_name, &pref_value);
        FreeStrBuf(&pref_name);
        return pref_value;
@@ -352,7 +352,7 @@ void set_ROOM_PREFS(const char *key, size_t keylen, StrBuf *value, int save_to_s
        StrBuf *pref_name;
        
        pref_name = NewStrBuf ();
-       StrBufPrintf(pref_name, "%s %s", key, WC->wc_roomname);
+       StrBufPrintf(pref_name, "%s %s", key, ChrPtr(WC->wc_roomname));
        set_PREFERENCE(ChrPtr(pref_name), StrLength(pref_name), value, save_to_server);
        FreeStrBuf(&pref_name);
 }
@@ -360,7 +360,8 @@ void set_ROOM_PREFS(const char *key, size_t keylen, StrBuf *value, int save_to_s
 /*
  * Offer to make any page the user's "start page."
  */
-void offer_start_page(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType) {
+void offer_start_page(StrBuf *Target, WCTemplputParams *TP)
+{
        wprintf("<a href=\"change_start_page?startpage=");
        urlescputs(WC->this_page);
        wprintf("\">");
@@ -368,9 +369,9 @@ void offer_start_page(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *C
        wprintf("</a>");
 #ifdef TECH_PREVIEW
        wprintf("<br/><a href=\"rss?room=");
-       urlescputs(WC->wc_roomname);
+       urlescputs(ChrPtr(WC->wc_roomname));
        wprintf("\" title=\"RSS 2.0 feed for ");
-       escputs(WC->wc_roomname);
+       escputs(ChrPtr(WC->wc_roomname));
        wprintf("\"><img alt=\"RSS\" border=\"0\" src=\"static/xml_button.gif\"/></a>\n");
 #endif
 }
@@ -456,14 +457,14 @@ void set_preferences(void)
 #define PRF_YESNO 4
 
 
-void tmplput_CFG_Value(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_CFG_Value(StrBuf *Target, WCTemplputParams *TP)
 {
        StrBuf *Setting;
        if (get_PREFERENCE(TKEY(0), &Setting))
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Setting, 1);
+       StrBufAppendTemplate(Target, TP, Setting, 1);
 }
 
-void tmplput_CFG_Descr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_CFG_Descr(StrBuf *Target, WCTemplputParams *TP)
 {
        const char *SettingStr;
        SettingStr = PrefGetLocalStr(TKEY(0));
@@ -472,31 +473,31 @@ void tmplput_CFG_Descr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void
 }
 
 
-void CfgZoneTempl(StrBuf *TemplBuffer, void *vContext, WCTemplateToken *Token)
+void CfgZoneTempl(StrBuf *TemplBuffer, WCTemplputParams *TP)
 {
-       StrBuf *Zone = (StrBuf*) vContext;
+       StrBuf *Zone = (StrBuf*) CTX;
 
        SVPutBuf("ZONENAME", Zone, 1);
 }
 
-int ConditionalPreference(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalPreference(StrBuf *Target, WCTemplputParams *TP)
 {
        StrBuf *Pref;
 
        if (!get_PREFERENCE(TKEY(2), &Pref)) 
                return 0;
        
-       if (Tokens->nParameters == 3) {
+       if (TP->Tokens->nParameters == 3) {
                return 1;
        }
-       else if (Tokens->Params[3]->Type == TYPE_STR)
-               return ((Tokens->Params[3]->len == StrLength(Pref)) &&
-                       (strcmp(Tokens->Params[3]->Start, ChrPtr(Pref)) == 0));
+       else if (TP->Tokens->Params[3]->Type == TYPE_STR)
+               return ((TP->Tokens->Params[3]->len == StrLength(Pref)) &&
+                       (strcmp(TP->Tokens->Params[3]->Start, ChrPtr(Pref)) == 0));
        else 
-               return (StrTol(Pref) == Tokens->Params[3]->lvalue);
+               return (StrTol(Pref) == TP->Tokens->Params[3]->lvalue);
 }
 
-int ConditionalHazePreference(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalHazePreference(StrBuf *Target, WCTemplputParams *TP)
 {
        StrBuf *Pref;
 
@@ -507,7 +508,7 @@ int ConditionalHazePreference(WCTemplateToken *Tokens, void *Context, int Contex
                return 1;
 }
 
-HashList *GetGVEAHash(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+HashList *GetGVEAHash(StrBuf *Target, WCTemplputParams *TP)
 {
        StrBuf *Rcp;
        HashList *List = NULL;
@@ -518,7 +519,7 @@ HashList *GetGVEAHash(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *
        Rcp = NewStrBuf();
        serv_puts("GVEA");
        StrBuf_ServGetln(Rcp);
-       if (ChrPtr(Rcp)[0] == '1') {
+       if (GetServerStatus(Rcp, NULL) == 1) {
                FlushStrBuf(Rcp);
                List = NewHash(1, NULL);
                while (!Done && (StrBuf_ServGetln(Rcp)>=0)) {
@@ -544,7 +545,7 @@ void DeleteGVEAHash(HashList **KillMe)
        DeleteHash(KillMe);
 }
 
-HashList *GetGVSNHash(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+HashList *GetGVSNHash(StrBuf *Target, WCTemplputParams *TP)
 {
        StrBuf *Rcp;
        HashList *List = NULL;
@@ -555,7 +556,7 @@ HashList *GetGVSNHash(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *
        Rcp = NewStrBuf();
        serv_puts("GVSN");
        StrBuf_ServGetln(Rcp);
-       if (ChrPtr(Rcp)[0] == '1') {
+       if (GetServerStatus(Rcp, NULL) == 1) {
                FlushStrBuf(Rcp);
                List = NewHash(1, NULL);
                while (!Done && (StrBuf_ServGetln(Rcp)>=0)) {
@@ -602,7 +603,7 @@ InitModule_PREFERENCES
        RegisterPreference("defaultfrom", _("Preferred email address"), PRF_STRING);
        RegisterPreference("defaultname", _("Preferred display name for email messages"), PRF_STRING);
        RegisterPreference("defaulthandle", _("Preferred display name for bulletin board posts"), PRF_STRING);
-       
+       RegisterNamespace("OFFERSTARTPAGE", 0, 0, offer_start_page, CTX_NONE);
        RegisterNamespace("PREF:VALUE", 1, 2, tmplput_CFG_Value, CTX_NONE);
        RegisterNamespace("PREF:DESCR", 1, 1, tmplput_CFG_Descr, CTX_NONE);
        RegisterIterator("PREF:ZONE", 0, ZoneHash, NULL, CfgZoneTempl, NULL, CTX_PREF, CTX_NONE, IT_NOFLAG);
index 3346d83ba2061de9ead1acf3b96f2a6946d1f86e..2f8c6a13069acaf3b6efac4eda08fb1aea504269 100644 (file)
@@ -59,7 +59,7 @@ void display_pushemail(void) {
        } else if (is_funambol) {
                svput("PUSH_FNBL", WCS_STRING, "checked=\"checked\"");
        }
-       serv_printf("GOTO %s", WC->wc_roomname);
+       serv_printf("GOTO %s", ChrPtr(WC->wc_roomname));
        serv_getln(buf, sizeof  buf);
        }
        output_headers(1, 1, 2, 0, 0, 0);
@@ -107,7 +107,7 @@ void save_pushemail(void) {
        }
 
        /** Go back to the room we're supposed to be in */
-       serv_printf("GOTO %s", WC->wc_roomname);
+       serv_printf("GOTO %s", ChrPtr(WC->wc_roomname));
        serv_getln(buf, sizeof buf);
        http_redirect("display_pushemail");
 }
index 1e20e12a168715079b037d8e906a2b8a824c8e2f..5efd7109ab5d9673373c1bbf007fc009e4f5fb14 100644 (file)
@@ -96,14 +96,14 @@ void free_march_list(wcsession *wcf)
 /*
  * remove a room from the march list
  */
-void remove_march(char *aaa)
+void remove_march(const StrBuf *aaa)
 {
        struct march *mptr, *mptr2;
 
        if (WC->march == NULL)
                return;
 
-       if (!strcasecmp(WC->march->march_name, aaa)) {
+       if (!strcasecmp(WC->march->march_name, ChrPtr(aaa))) {
                mptr = WC->march->next;
                free(WC->march);
                WC->march = mptr;
@@ -111,7 +111,7 @@ void remove_march(char *aaa)
        }
        mptr2 = WC->march;
        for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
-               if (!strcasecmp(mptr->march_name, aaa)) {
+               if (!strcasecmp(mptr->march_name, ChrPtr(aaa))) {
                        mptr2->next = mptr->next;
                        free(mptr);
                        mptr = mptr2;
@@ -256,11 +256,15 @@ void listrms(char *variety)
  */
 void zapped_list(void)
 {
+       WCTemplputParams SubTP;
        StrBuf *Buf;
-       output_headers(1, 1, 1, 0, 0, 0);
 
+       output_headers(1, 1, 1, 0, 0, 0);
+       memset(&SubTP, 0, sizeof(WCTemplputParams));
        Buf = NewStrBufPlain(_("Zapped (forgotten) rooms"), -1);
-       DoTemplate(HKEY("beginbox"), NULL, Buf, CTX_STRBUF);
+       SubTP.ContextType = CTX_STRBUF;
+       SubTP.Context = Buf;
+       DoTemplate(HKEY("beginbox"), NULL, &SubTP);
 
        FreeStrBuf(&Buf);
 
@@ -276,7 +280,7 @@ void zapped_list(void)
 /**
  * \brief read this room's info file (set v to 1 for verbose mode)
  */
-void readinfo(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void readinfo(StrBuf *Target, WCTemplputParams *TP)
 {
        char buf[256];
        char briefinfo[128];
@@ -325,14 +329,15 @@ void readinfo(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context,
  * keep the browser from using a cached icon from 
  * another room.
  */
-void embed_room_graphic(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) {
+void embed_room_graphic(StrBuf *Target, WCTemplputParams *TP)
+{
        char buf[SIZ];
 
        serv_puts("OIMG _roompic_");
        serv_getln(buf, sizeof buf);
        if (buf[0] == '2') {
                wprintf("<img height=\"64px\" src=\"image&name=_roompic_&room=");
-               urlescputs(WC->wc_roomname);
+               urlescputs(ChrPtr(WC->wc_roomname));
                wprintf("\">");
                serv_puts("CLOS");
                serv_getln(buf, sizeof buf);
@@ -381,7 +386,8 @@ void embed_room_graphic(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void
 /**
  * \brief Display the current view and offer an option to change it
  */
-void embed_view_o_matic(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) {
+void embed_view_o_matic(StrBuf *Target, WCTemplputParams *TP)
+{
        int i;
 
        wprintf("<form name=\"viewomatic\" action=\"changeview\">\n");
@@ -422,7 +428,8 @@ void embed_view_o_matic(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void
 /**
  * \brief Display a search box
  */
-void embed_search_o_matic(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) {
+void embed_search_o_matic(StrBuf *Target, WCTemplputParams *TP)
+{
        wprintf("<form name=\"searchomatic\" action=\"do_search\">\n");
        wprintf("<div style=\"display: inline;\"><input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
        wprintf("<label for=\"search_name\">");
@@ -455,9 +462,9 @@ void embed_room_banner(char *got, int navbar_style) {
         * If it isn't supplied, we fake it by issuing our own GOTO.
         */
        if (got == NULL) {
-               memset(buf, 20, '0');
+               memset(buf, '0', 20);
                buf[20] = '\0';
-               serv_printf("GOTO %s", WC->wc_roomname);
+               serv_printf("GOTO %s", ChrPtr(WC->wc_roomname));
                serv_getln(buf, sizeof buf);
                got = buf;
        }
@@ -475,7 +482,7 @@ void embed_room_banner(char *got, int navbar_style) {
         * a "skip" or "gotonext" or something like that.
         */
        snprintf(WC->this_page, sizeof(WC->this_page), "dotskip&room=%s",
-               WC->wc_roomname);
+                ChrPtr(WC->wc_roomname));
 
        /** Check for new mail. */
        WC->new_mail = extract_int(&got[4], 9);
@@ -745,51 +752,56 @@ void embed_room_banner(char *got, int navbar_style) {
 /*
  * back end routine to take the session to a new room
  */
-int gotoroom(char *gname)
+long gotoroom(const StrBuf *gname)
 {
+       StrBuf *Buf;
        char buf[SIZ];
        static long ls = (-1L);
-       int err = 0;
+       long err = 0;
 
        /* store ungoto information */
-       strcpy(WC->ugname, WC->wc_roomname);
+       strcpy(WC->ugname, ChrPtr(WC->wc_roomname));
        WC->uglsn = ls;
-
+       Buf = NewStrBuf();
        /** move to the new room */
-       serv_printf("GOTO %s", gname);
-       serv_getln(buf, sizeof buf);
-       if (buf[0] != '2') {
-               buf[3] = 0;
-               err = atoi(buf);
-               serv_puts("GOTO _BASEROOM_");
-               serv_getln(buf, sizeof buf);
-       }
-       if (buf[0] != '2') {
-               buf[3] = 0;
-               err = atoi(buf);
+       serv_printf("GOTO %s", ChrPtr(gname));
+       StrBuf_ServGetln(Buf);
+       if  (GetServerStatus(Buf, &err) != 2) {
+               FreeStrBuf(&Buf);
                return err;
        }
-       extract_token(WC->wc_roomname, &buf[4], 0, '|', sizeof WC->wc_roomname);
-       WC->room_flags = extract_int(&buf[4], 4);
+
+       serv_puts("GOTO _BASEROOM_");
+       serv_getln(buf, sizeof buf);
+
+       if (WC->wc_roomname == NULL)
+               WC->wc_roomname = NewStrBuf();
+       else
+               FlushStrBuf(WC->wc_roomname);
+
+       StrBufExtract_token(WC->wc_roomname, Buf, 0, '|');
+       StrBufCutLeft(WC->wc_roomname, 4);
+       WC->room_flags = StrBufExtract_int(Buf, 4, '|');
        /* highest_msg_read = extract_int(&buf[4],6);
           maxmsgnum = extract_int(&buf[4],5);
         */
-       WC->is_mailbox = extract_int(&buf[4],7);
-       ls = extract_long(&buf[4], 6);
-       WC->wc_floor = extract_int(&buf[4], 10);
-       WC->wc_view = extract_int(&buf[4], 11);
-       WC->wc_default_view = extract_int(&buf[4], 12);
-       WC->wc_is_trash = extract_int(&buf[4], 13);
-       WC->room_flags2 = extract_int(&buf[4], 14);
+       WC->is_mailbox = StrBufExtract_int(Buf, 7, '|');   
+       ls = StrBufExtract_long(Buf, 6, '|');
+       WC->wc_floor = StrBufExtract_int(Buf, 10, '|');
+       WC->wc_view = StrBufExtract_int(Buf, 11, '|');
+       WC->wc_default_view = StrBufExtract_int(Buf, 12, '|');
+       WC->wc_is_trash = StrBufExtract_int(Buf, 13, '|');
+       WC->room_flags2 = StrBufExtract_int(Buf, 14, '|');
 
        if (WC->is_aide)
                WC->is_room_aide = WC->is_aide;
        else
-               WC->is_room_aide = (char) extract_int(&buf[4], 8);
+               WC->is_room_aide = (char) StrBufExtract_int(Buf, 8, '|');
 
        remove_march(WC->wc_roomname);
-       if (!strcasecmp(gname, "_BASEROOM_"))
+       if (!strcasecmp(ChrPtr(gname), "_BASEROOM_"))
                remove_march(gname);
+       FreeStrBuf(&Buf);
 
        return err;
 }
@@ -852,7 +864,7 @@ void gotonext(void)
        struct march *mptr = NULL;
        struct march *mptr2 = NULL;
        char room_name[128];
-       char next_room[128];
+       StrBuf *next_room;
        int ELoop = 0;
 
        /*
@@ -874,7 +886,7 @@ void gotonext(void)
                                        continue;                                       
                                }
                                extract_token(room_name, buf, 0, '|', sizeof room_name);
-                               if (strcasecmp(room_name, WC->wc_roomname)) {
+                               if (strcasecmp(room_name, ChrPtr(WC->wc_roomname))) {
                                        mptr = (struct march *) malloc(sizeof(struct march));
                                        mptr->next = NULL;
                                        safestrncpy(mptr->march_name, room_name, sizeof mptr->march_name);
@@ -912,20 +924,21 @@ void gotonext(void)
                remove_march(WC->wc_roomname);
        }
        if (WC->march != NULL) {
-               strcpy(next_room, pop_march(-1));
+               next_room = NewStrBufPlain(pop_march(-1), -1);/*TODO: migrate march to strbuf */
        } else {
-               strcpy(next_room, "_BASEROOM_");
+               next_room = NewStrBufPlain(HKEY("_BASEROOM_"));
        }
 
 
        smart_goto(next_room);
+       FreeStrBuf(&next_room);
 }
 
 
 /*
  * goto next room
  */
-void smart_goto(char *next_room) {
+void smart_goto(const StrBuf *next_room) {
        gotoroom(next_room);
        readloop(readnew);
 }
@@ -949,25 +962,29 @@ void slrp_highest(void)
  */
 void ungoto(void)
 {
-       char buf[SIZ];
+       StrBuf *Buf;
 
        if (!strcmp(WC->ugname, "")) {
                smart_goto(WC->wc_roomname);
                return;
        }
        serv_printf("GOTO %s", WC->ugname);
-       serv_getln(buf, sizeof buf);
-       if (buf[0] != '2') {
+       Buf = NewStrBuf();
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) != 2) {
                smart_goto(WC->wc_roomname);
+               FreeStrBuf(&Buf);
                return;
        }
        if (WC->uglsn >= 0L) {
                serv_printf("SLRP %ld", WC->uglsn);
-               serv_getln(buf, sizeof buf);
+               StrBuf_ServGetln(Buf);
        }
-       strcpy(buf, WC->ugname);
+       FlushStrBuf(Buf);
+       StrBufAppendBufPlain(Buf, WC->ugname, -1, 0);
        strcpy(WC->ugname, "");
-       smart_goto(buf);
+       smart_goto(Buf);
+       FreeStrBuf(&Buf);
 }
 
 typedef struct __room_states {
@@ -1817,7 +1834,7 @@ void display_editroom(void)
                        wprintf("<tr><td>");
                        wprintf(_("Message expire policy for this room"));
                        wprintf("<br />(");
-                       escputs(WC->wc_roomname);
+                       escputs(ChrPtr(WC->wc_roomname));
                        wprintf(")</td><td>");
                        wprintf("<input type=\"radio\" NAME=\"roompolicy\" VALUE=\"0\" %s>",
                                ((roompolicy == 0) ? "CHECKED" : "") );
@@ -2083,11 +2100,12 @@ void toggle_self_service(void) {
  */
 void editroom(void)
 {
-       char buf[SIZ];
-       char er_name[128];
-       char er_password[10];
-       char er_dirname[15];
-       char er_roomaide[26];
+       const StrBuf *Ptr;
+       StrBuf *Buf;
+       StrBuf *er_name;
+       StrBuf *er_password;
+       StrBuf *er_dirname;
+       StrBuf *er_roomaide;
        int er_floor;
        unsigned er_flags;
        int er_listingorder;
@@ -2103,60 +2121,68 @@ void editroom(void)
                return;
        }
        serv_puts("GETR");
-       serv_getln(buf, sizeof buf);
-
-       if (buf[0] != '2') {
-               strcpy(WC->ImportantMessage, &buf[4]);
+       Buf = NewStrBuf();
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) != 2) {
+               StrBufCutLeft(Buf, 4);
+               strcpy(WC->ImportantMessage, ChrPtr(Buf));
                display_editroom();
+               FreeStrBuf(&Buf);
                return;
        }
-       extract_token(er_name, &buf[4], 0, '|', sizeof er_name);
-       extract_token(er_password, &buf[4], 1, '|', sizeof er_password);
-       extract_token(er_dirname, &buf[4], 2, '|', sizeof er_dirname);
-       er_flags = extract_int(&buf[4], 3);
-       er_listingorder = extract_int(&buf[4], 5);
-       er_defaultview = extract_int(&buf[4], 6);
-       er_flags2 = extract_int(&buf[4], 7);
-
-       strcpy(er_roomaide, bstr("er_roomaide"));
-       if (IsEmptyStr(er_roomaide)) {
+       StrBufCutLeft(Buf, 4);
+       StrBufExtract_token(er_name, Buf, 0, '|');
+       StrBufExtract_token(er_password, Buf, 1, '|');
+       StrBufExtract_token(er_dirname, Buf, 2, '|');
+       er_flags = StrBufExtract_int(Buf, 3, '|');
+       er_listingorder = StrBufExtract_int(Buf, 5, '|');
+       er_defaultview = StrBufExtract_int(Buf, 6, '|');
+       er_flags2 = StrBufExtract_int(Buf, 7, '|');
+
+       er_roomaide = NewStrBufDup(sbstr("er_roomaide"));
+       if (StrLength(er_roomaide) == 0) {
                serv_puts("GETA");
-               serv_getln(buf, sizeof buf);
-               if (buf[0] != '2') {
-                       strcpy(er_roomaide, "");
+               StrBuf_ServGetln(Buf);
+               if (GetServerStatus(Buf, NULL) != 2) {
+                       FlushStrBuf(er_roomaide);
                } else {
-                       extract_token(er_roomaide, &buf[4], 0, '|', sizeof er_roomaide);
+                       StrBufCutLeft(Buf, 4);
+                       StrBufExtract_token(er_roomaide, Buf, 0, '|');
                }
        }
-       strcpy(buf, bstr("er_name"));
-       buf[128] = 0;
-       if (!IsEmptyStr(buf)) {
-               strcpy(er_name, buf);
+       Ptr = sbstr("er_name");
+       if (StrLength(Ptr) > 0) {
+               FlushStrBuf(er_name);
+               StrBufAppendBuf(er_name, Ptr, 0);
+       }
+
+       Ptr = sbstr("er_password");
+       if (StrLength(Ptr) > 0) {
+               FlushStrBuf(er_password);
+               StrBufAppendBuf(er_password, Ptr, 0);
        }
+               
 
-       strcpy(buf, bstr("er_password"));
-       buf[10] = 0;
-       if (!IsEmptyStr(buf))
-               strcpy(er_password, buf);
+       Ptr = sbstr("er_dirname");
+       if (StrLength(Ptr) > 0) { /* todo: cut 15 */
+               FlushStrBuf(er_dirname);
+               StrBufAppendBuf(er_dirname, Ptr, 0);
+       }
 
-       strcpy(buf, bstr("er_dirname"));
-       buf[15] = 0;
-       if (!IsEmptyStr(buf))
-               strcpy(er_dirname, buf);
 
-       strcpy(buf, bstr("type"));
+       Ptr = sbstr("type");
        er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
 
-       if (!strcmp(buf, "invonly")) {
+       if (!strcmp(ChrPtr(Ptr), "invonly")) {
                er_flags |= (QR_PRIVATE);
        }
-       if (!strcmp(buf, "hidden")) {
+       if (!strcmp(ChrPtr(Ptr), "hidden")) {
                er_flags |= (QR_PRIVATE | QR_GUESSNAME);
        }
-       if (!strcmp(buf, "passworded")) {
+       if (!strcmp(ChrPtr(Ptr), "passworded")) {
                er_flags |= (QR_PRIVATE | QR_PASSWORDED);
        }
-       if (!strcmp(buf, "personal")) {
+       if (!strcmp(ChrPtr(Ptr), "personal")) {
                er_flags |= QR_MAILBOX;
        } else {
                er_flags &= ~QR_MAILBOX;
@@ -2223,45 +2249,64 @@ void editroom(void)
                er_flags &= ~QR_VISDIR;
        }
 
-       strcpy(buf, bstr("anon"));
+       Ptr = sbstr("anon");
 
        er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
-       if (!strcmp(buf, "anononly"))
+       if (!strcmp(ChrPtr(Ptr), "anononly"))
                er_flags |= QR_ANONONLY;
-       if (!strcmp(buf, "anon2"))
+       if (!strcmp(ChrPtr(Ptr), "anon2"))
                er_flags |= QR_ANONOPT;
 
-       bump = 0;
-       if (!strcmp(bstr("bump"), "yes"))
-               bump = 1;
+       bump = yesbstr("bump");
 
        er_floor = ibstr("er_floor");
 
-       sprintf(buf, "SETR %s|%s|%s|%u|%d|%d|%d|%d|%u",
-               er_name, er_password, er_dirname, er_flags, bump, er_floor,
-               er_listingorder, er_defaultview, er_flags2);
-       serv_puts(buf);
-       serv_getln(buf, sizeof buf);
-       if (buf[0] != '2') {
-               strcpy(WC->ImportantMessage, &buf[4]);
+       StrBufPrintf(Buf, "SETR %s|%s|%s|%u|%d|%d|%d|%d|%u",
+                    ChrPtr(er_name), 
+                    ChrPtr(er_password), 
+                    ChrPtr(er_dirname), 
+                    er_flags, 
+                    bump, 
+                    er_floor,
+                    er_listingorder, 
+                    er_defaultview, 
+                    er_flags2);
+       serv_putbuf(Buf);
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) != 2) {
+               strcpy(WC->ImportantMessage, &ChrPtr(Buf)[4]);
                display_editroom();
+               FreeStrBuf(&Buf);
+               FreeStrBuf(&er_name);
+               FreeStrBuf(&er_password);
+               FreeStrBuf(&er_dirname);
+               FreeStrBuf(&er_roomaide);
                return;
        }
        gotoroom(er_name);
 
-       if (!IsEmptyStr(er_roomaide)) {
-               sprintf(buf, "SETA %s", er_roomaide);
-               serv_puts(buf);
-               serv_getln(buf, sizeof buf);
-               if (buf[0] != '2') {
-                       strcpy(WC->ImportantMessage, &buf[4]);
+       if (StrLength(er_roomaide) > 0) {
+               serv_printf("SETA %s", ChrPtr(er_roomaide));
+               StrBuf_ServGetln(Buf);
+               if (GetServerStatus(Buf, NULL) != 2) {
+                       strcpy(WC->ImportantMessage, &ChrPtr(Buf)[4]);
                        display_main_menu();
+                       FreeStrBuf(&Buf);
+                       FreeStrBuf(&er_name);
+                       FreeStrBuf(&er_password);
+                       FreeStrBuf(&er_dirname);
+                       FreeStrBuf(&er_roomaide);
                        return;
                }
        }
        gotoroom(er_name);
        strcpy(WC->ImportantMessage, _("Your changes have been saved."));
        display_editroom();
+       FreeStrBuf(&Buf);
+       FreeStrBuf(&er_name);
+       FreeStrBuf(&er_password);
+       FreeStrBuf(&er_dirname);
+       FreeStrBuf(&er_roomaide);
        return;
 }
 
@@ -2582,9 +2627,9 @@ void er_set_default_view(int newview) {
 void entroom(void)
 {
        char buf[SIZ];
-       char er_name[SIZ];
-       char er_type[SIZ];
-       char er_password[SIZ];
+       const StrBuf *er_name;
+       const StrBuf *er_type;
+       const StrBuf *er_password;
        int er_floor;
        int er_num_type;
        int er_view;
@@ -2595,25 +2640,30 @@ void entroom(void)
                display_main_menu();
                return;
        }
-       strcpy(er_name, bstr("er_name"));
-       strcpy(er_type, bstr("type"));
-       strcpy(er_password, bstr("er_password"));
+       er_name = sbstr("er_name");
+       er_type = sbstr("type");
+       er_password = sbstr("er_password");
        er_floor = ibstr("er_floor");
        er_view = ibstr("er_view");
 
        er_num_type = 0;
-       if (!strcmp(er_type, "hidden"))
+       if (!strcmp(ChrPtr(er_type), "hidden"))
                er_num_type = 1;
-       if (!strcmp(er_type, "passworded"))
+       else if (!strcmp(ChrPtr(er_type), "passworded"))
                er_num_type = 2;
-       if (!strcmp(er_type, "invonly"))
+       else if (!strcmp(ChrPtr(er_type), "invonly"))
                er_num_type = 3;
-       if (!strcmp(er_type, "personal"))
+       else if (!strcmp(ChrPtr(er_type), "personal"))
                er_num_type = 4;
 
-       sprintf(buf, "CRE8 1|%s|%d|%s|%d|%d|%d", 
-               er_name, er_num_type, er_password, er_floor, 0, er_view);
-       serv_puts(buf);
+       serv_printf("CRE8 1|%s|%d|%s|%d|%d|%d", 
+                   ChrPtr(er_name), 
+                   er_num_type, 
+                   ChrPtr(er_password), 
+                   er_floor, 
+                   0, 
+                   er_view);
+
        serv_getln(buf, sizeof buf);
        if (buf[0] != '2') {
                strcpy(WC->ImportantMessage, &buf[4]);
@@ -2634,11 +2684,15 @@ void entroom(void)
  */
 void display_private(char *rname, int req_pass)
 {
+       WCTemplputParams SubTP;
        StrBuf *Buf;
        output_headers(1, 1, 1, 0, 0, 0);
 
        Buf = NewStrBufPlain(_("Go to a hidden room"), -1);
-       DoTemplate(HKEY("beginbox"), NULL, Buf, CTX_STRBUF);
+       memset(&SubTP, 0, sizeof(WCTemplputParams));
+       SubTP.ContextType = CTX_STRBUF;
+       SubTP.Context = Buf;
+       DoTemplate(HKEY("beginbox"), NULL, &SubTP);
 
        FreeStrBuf(&Buf);
 
@@ -2694,16 +2748,14 @@ void goto_private(void)
                display_main_menu();
                return;
        }
-       strcpy(hold_rm, WC->wc_roomname);
-       strcpy(buf, "GOTO ");
-       strcat(buf, bstr("gr_name"));
-       strcat(buf, "|");
-       strcat(buf, bstr("gr_pass"));
-       serv_puts(buf);
+       strcpy(hold_rm, ChrPtr(WC->wc_roomname));
+       serv_printf("GOTO %s|%s",
+                   bstr("gr_name"),
+                   bstr("gr_pass"));
        serv_getln(buf, sizeof buf);
 
        if (buf[0] == '2') {
-               smart_goto(bstr("gr_name"));
+               smart_goto(sbstr("gr_name"));
                return;
        }
        if (!strncmp(buf, "540", 3)) {
@@ -2733,8 +2785,8 @@ void display_zap(void)
        wprintf("<div id=\"content\" class=\"service\">\n");
 
        wprintf(_("If you select this option, <em>%s</em> will "
-               "disappear from your room list.  Is this what you wish "
-               "to do?<br />\n"), WC->wc_roomname);
+                 "disappear from your room list.  Is this what you wish "
+                 "to do?<br />\n"), ChrPtr(WC->wc_roomname));
 
        wprintf("<form method=\"POST\" action=\"zap\">\n");
        wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
@@ -2752,26 +2804,28 @@ void display_zap(void)
 void zap(void)
 {
        char buf[SIZ];
-       char final_destination[SIZ];
+       StrBuf *final_destination;
 
        /**
         * If the forget-room routine fails for any reason, we fall back
         * to the current room; otherwise, we go to the Lobby
         */
-       strcpy(final_destination, WC->wc_roomname);
+       final_destination = NewStrBufDup(WC->wc_roomname);
 
        if (havebstr("ok_button")) {
-               serv_printf("GOTO %s", WC->wc_roomname);
+               serv_printf("GOTO %s", ChrPtr(WC->wc_roomname));
                serv_getln(buf, sizeof buf);
                if (buf[0] == '2') {
                        serv_puts("FORG");
                        serv_getln(buf, sizeof buf);
                        if (buf[0] == '2') {
-                               strcpy(final_destination, "_BASEROOM_");
+                               FlushStrBuf(final_destination);
+                               StrBufAppendBufPlain(final_destination, HKEY("_BASEROOM_"), 0);
                        }
                }
        }
        smart_goto(final_destination);
+       FreeStrBuf(&final_destination);
 }
 
 
@@ -2792,7 +2846,11 @@ void delete_room(void)
                display_main_menu();
                return;
        } else {
-               smart_goto("_BASEROOM_");
+               StrBuf *Buf;
+               
+               Buf = NewStrBufPlain(HKEY("_BASEROOM_"));
+               smart_goto(Buf);
+               FreeStrBuf(&Buf);
        }
 }
 
@@ -3145,9 +3203,13 @@ void do_rooms_view(struct folder *fold, int max_folders, int num_floors) {
 
                if (levels == 1) {
                        StrBuf *Buf;
-                       
+                       WCTemplputParams SubTP;
+
                        Buf = NewStrBufPlain(floor_name, -1);
-                       DoTemplate(HKEY("beginbox"), NULL, Buf, CTX_STRBUF);
+                       memset(&SubTP, 0, sizeof(WCTemplputParams));
+                       SubTP.ContextType = CTX_STRBUF;
+                       SubTP.Context = Buf;
+                       DoTemplate(HKEY("beginbox"), NULL, &SubTP);
                        
                        FreeStrBuf(&Buf);
                }
@@ -3594,7 +3656,7 @@ void knrooms(void)
        /** offer the ability to switch views */
        wprintf("<ul class=\"room_actions\">\n");
        wprintf("<li class=\"start_page\">");
-       offer_start_page(NULL, 0, NULL, NULL, CTX_NONE);
+       offer_start_page(NULL, &NoCtx);
        wprintf("</li>");
        wprintf("<li><form name=\"roomlistomatic\">\n"
                "<select name=\"newview\" size=\"1\" "
@@ -3654,25 +3716,22 @@ void set_room_policy(void) {
 }
 
 
-void tmplput_RoomName(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_RoomName(StrBuf *Target, WCTemplputParams *TP)
 {
-       StrBuf *tmp;
-       tmp = NewStrBufPlain(WC->wc_roomname, -1);;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, tmp, 0);
-       FreeStrBuf(&tmp);
+       StrBufAppendTemplate(Target, TP, WC->wc_roomname, 0);
 }
 
 void _gotonext(void) { slrp_highest(); gotonext(); }
-void dotskip(void) {smart_goto(bstr("room"));}
+void dotskip(void) {smart_goto(sbstr("room"));}
 void _display_private(void) { display_private("", 0); }
 void dotgoto(void) {
        if (WC->wc_view != VIEW_MAILBOX) {      /* dotgoto acts like dotskip when we're in a mailbox view */
                slrp_highest();
        }
-       smart_goto(bstr("room"));
+       smart_goto(sbstr("room"));
 }
 
-void tmplput_roombanner(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_roombanner(StrBuf *Target, WCTemplputParams *TP)
 {
        wprintf("<div id=\"banner\">\n");
        embed_room_banner(NULL, navbar_default);
@@ -3680,7 +3739,7 @@ void tmplput_roombanner(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void
 }
 
 
-void tmplput_ungoto(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_ungoto(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
 
@@ -3690,19 +3749,16 @@ void tmplput_ungoto(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Co
 }
 
 
-int ConditionalHaveUngoto(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalHaveUngoto(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        
        return ((WCC!=NULL) && 
                (!IsEmptyStr(WCC->ugname)) && 
-               (strcasecmp(WCC->ugname, WCC->wc_roomname) == 0));
+               (strcasecmp(WCC->ugname, ChrPtr(WCC->wc_roomname)) == 0));
 }
 
-
-
-
-int ConditionalRoomHas_QR_PERMANENT(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalRoomHas_QR_PERMANENT(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        
@@ -3710,7 +3766,7 @@ int ConditionalRoomHas_QR_PERMANENT(WCTemplateToken *Tokens, void *Context, int
                ((WCC->room_flags & QR_PERMANENT) != 0));
 }
 
-int ConditionalRoomHas_QR_INUSE(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalRoomHas_QR_INUSE(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        
@@ -3718,7 +3774,7 @@ int ConditionalRoomHas_QR_INUSE(WCTemplateToken *Tokens, void *Context, int Cont
                ((WCC->room_flags & QR_INUSE) != 0));
 }
 
-int ConditionalRoomHas_QR_PRIVATE(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalRoomHas_QR_PRIVATE(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        
@@ -3726,7 +3782,7 @@ int ConditionalRoomHas_QR_PRIVATE(WCTemplateToken *Tokens, void *Context, int Co
                ((WCC->room_flags & QR_PRIVATE) != 0));
 }
 
-int ConditionalRoomHas_QR_PASSWORDED(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalRoomHas_QR_PASSWORDED(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        
@@ -3734,7 +3790,7 @@ int ConditionalRoomHas_QR_PASSWORDED(WCTemplateToken *Tokens, void *Context, int
                ((WCC->room_flags & QR_PASSWORDED) != 0));
 }
 
-int ConditionalRoomHas_QR_GUESSNAME(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalRoomHas_QR_GUESSNAME(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        
@@ -3742,7 +3798,7 @@ int ConditionalRoomHas_QR_GUESSNAME(WCTemplateToken *Tokens, void *Context, int
                ((WCC->room_flags & QR_GUESSNAME) != 0));
 }
 
-int ConditionalRoomHas_QR_DIRECTORY(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalRoomHas_QR_DIRECTORY(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        
@@ -3750,7 +3806,7 @@ int ConditionalRoomHas_QR_DIRECTORY(WCTemplateToken *Tokens, void *Context, int
                ((WCC->room_flags & QR_DIRECTORY) != 0));
 }
 
-int ConditionalRoomHas_QR_UPLOAD(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalRoomHas_QR_UPLOAD(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        
@@ -3758,7 +3814,7 @@ int ConditionalRoomHas_QR_UPLOAD(WCTemplateToken *Tokens, void *Context, int Con
                ((WCC->room_flags & QR_UPLOAD) != 0));
 }
 
-int ConditionalRoomHas_QR_DOWNLOAD(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalRoomHas_QR_DOWNLOAD(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        
@@ -3766,7 +3822,7 @@ int ConditionalRoomHas_QR_DOWNLOAD(WCTemplateToken *Tokens, void *Context, int C
                ((WCC->room_flags & QR_DOWNLOAD) != 0));
 }
 
-int ConditionalRoomHas_QR_VISDIR(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalRoomHas_QR_VISDIR(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        
@@ -3774,7 +3830,7 @@ int ConditionalRoomHas_QR_VISDIR(WCTemplateToken *Tokens, void *Context, int Con
                ((WCC->room_flags & QR_VISDIR) != 0));
 }
 
-int ConditionalRoomHas_QR_ANONONLY(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalRoomHas_QR_ANONONLY(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        
@@ -3782,7 +3838,7 @@ int ConditionalRoomHas_QR_ANONONLY(WCTemplateToken *Tokens, void *Context, int C
                ((WCC->room_flags & QR_ANONONLY) != 0));
 }
 
-int ConditionalRoomHas_QR_ANONOPT(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalRoomHas_QR_ANONOPT(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        
@@ -3790,7 +3846,7 @@ int ConditionalRoomHas_QR_ANONOPT(WCTemplateToken *Tokens, void *Context, int Co
                ((WCC->room_flags & QR_ANONOPT) != 0));
 }
 
-int ConditionalRoomHas_QR_NETWORK(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalRoomHas_QR_NETWORK(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        
@@ -3798,7 +3854,7 @@ int ConditionalRoomHas_QR_NETWORK(WCTemplateToken *Tokens, void *Context, int Co
                ((WCC->room_flags & QR_NETWORK) != 0));
 }
 
-int ConditionalRoomHas_QR_PREFONLY(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalRoomHas_QR_PREFONLY(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        
@@ -3806,7 +3862,7 @@ int ConditionalRoomHas_QR_PREFONLY(WCTemplateToken *Tokens, void *Context, int C
                ((WCC->room_flags & QR_PREFONLY) != 0));
 }
 
-int ConditionalRoomHas_QR_READONLY(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalRoomHas_QR_READONLY(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        
@@ -3814,7 +3870,7 @@ int ConditionalRoomHas_QR_READONLY(WCTemplateToken *Tokens, void *Context, int C
                ((WCC->room_flags & QR_READONLY) != 0));
 }
 
-int ConditionalRoomHas_QR_MAILBOX(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalRoomHas_QR_MAILBOX(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        
@@ -3823,11 +3879,7 @@ int ConditionalRoomHas_QR_MAILBOX(WCTemplateToken *Tokens, void *Context, int Co
 }
 
 
-
-
-
-
-int ConditionalHaveRoomeditRights(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalHaveRoomeditRights(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
 
index 385091c4c0f1a15a8b0c3d62e99c6c66f1504f6a..536de951263e8f7878e12164954442bd085297e5 100644 (file)
@@ -43,7 +43,7 @@ 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(const StrBuf *roomname, StrBuf *request_method)
 {
        message_summary *Msg;
        wcsession *WCC = WC;
@@ -76,19 +76,28 @@ void display_rss(char *roomname, StrBuf *request_method)
        
        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);
+
+               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(roomname)) {
                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");
@@ -153,8 +162,8 @@ void display_rss(char *roomname, StrBuf *request_method)
        /* <?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, WCC->wc_roomname);
-       svput("NODE", WCS_STRING, serv_info.serv_humannode);
+       SVPutBuf("ROOM", WCC->wc_roomname, 1);
+       SVPutBuf("NODE", serv_info.serv_humannode, 1);
        /* TODO:  Fix me */
        svprintf(HKEY("ROOM_LINK"), WCS_STRING, "%s://%s/", (is_https ? "https" : "http"), WCC->http_host);
        
@@ -224,7 +233,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(serv_info.serv_humannode)) && !IsEmptyStr(hnod)) {
                        svprintf(HKEY("NODE"), WCS_STRING, _(" on %s"), hnod);
                }
                if (now) {
index 00b30479893f3de601944921a5d9fbe713f92138..5592ca8c0418eaaf85ab22d474fd5da636e78f3a 100644 (file)
@@ -14,6 +14,7 @@ struct serv_info serv_info; /**< our connection data to the server */
  */
 void get_serv_info(char *browser_host, char *user_agent)
 {
+       StrBuf *Buf;
        char buf[SIZ];
        int a;
 
@@ -46,56 +47,58 @@ void get_serv_info(char *browser_host, char *user_agent)
                return;
 
        a = 0;
-       while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+       Buf = NewStrBuf();
+       while (StrBuf_ServGetln(Buf), (strcmp(ChrPtr(Buf), "000")!= 0)) {
+/*             lprintf (1, "a: %d [%s]", a, ChrPtr(Buf));*/
                switch (a) {
                case 0:
-                       serv_info.serv_pid = atoi(buf);
+                       serv_info.serv_pid = StrToi(Buf);
                        WC->ctdl_pid = serv_info.serv_pid;
                        break;
                case 1:
-                       safestrncpy(serv_info.serv_nodename, buf, sizeof serv_info.serv_nodename);
+                       serv_info.serv_nodename = NewStrBufDup(Buf);
                        break;
                case 2:
-                       safestrncpy(serv_info.serv_humannode, buf, sizeof serv_info.serv_humannode);
+                       serv_info.serv_humannode = NewStrBufDup(Buf);
                        break;
                case 3:
-                       safestrncpy(serv_info.serv_fqdn, buf, sizeof serv_info.serv_fqdn);
+                       serv_info.serv_fqdn = NewStrBufDup(Buf);
                        break;
                case 4:
-                       safestrncpy(serv_info.serv_software, buf, sizeof serv_info.serv_software);
+                       serv_info.serv_software = NewStrBufDup(Buf);
                        break;
                case 5:
-                       serv_info.serv_rev_level = atoi(buf);
+                       serv_info.serv_rev_level = StrToi(Buf);
                        break;
                case 6:
-                       safestrncpy(serv_info.serv_bbs_city, buf, sizeof serv_info.serv_bbs_city);
+                       serv_info.serv_bbs_city = NewStrBufDup(Buf);
                        break;
                case 7:
-                       safestrncpy(serv_info.serv_sysadm, buf, sizeof serv_info.serv_sysadm);
+                       serv_info.serv_sysadm = NewStrBufDup(Buf);
                        break;
                case 9:
-                       safestrncpy(serv_info.serv_moreprompt, buf, sizeof serv_info.serv_moreprompt);
+                       serv_info.serv_moreprompt = NewStrBufDup(Buf);
                        break;
                case 14:
-                       serv_info.serv_supports_ldap = atoi(buf);
+                       serv_info.serv_supports_ldap = StrToi(Buf);
                        break;
                case 15:
-                       serv_info.serv_newuser_disabled = atoi(buf);
+                       serv_info.serv_newuser_disabled = StrToi(Buf);
                        break;
                case 16:
-                       safestrncpy(serv_info.serv_default_cal_zone, buf, sizeof serv_info.serv_default_cal_zone);
+                       serv_info.serv_default_cal_zone = NewStrBufDup(Buf);
                        break;
                case 20:
-                       serv_info.serv_supports_sieve = atoi(buf);
+                       serv_info.serv_supports_sieve = StrToi(Buf);
                        break;
                case 21:
-                       serv_info.serv_fulltext_enabled = atoi(buf);
+                       serv_info.serv_fulltext_enabled = StrToi(Buf);
                        break;
                case 22:
-                       safestrncpy(serv_info.serv_svn_revision, buf, sizeof serv_info.serv_svn_revision);
+                       serv_info.serv_svn_revision = NewStrBufDup(Buf);
                        break;
                case 23:
-                       serv_info.serv_supports_openid = atoi(buf);
+                       serv_info.serv_supports_openid = StrToi(Buf);
                        break;
                }
                ++a;
@@ -437,8 +440,8 @@ int read_server_binary(StrBuf *Ret, size_t total_len)
                serv_printf("READ %d|%d", (int)bytes, (int)thisblock);
                if (StrBuf_ServGetln(Buf) > 0)
                {
-                   if (ChrPtr(Buf)[0] == '6')
-                   {
+                       if (GetServerStatus(Buf, NULL) == 6)
+                       {
                            StrBufCutLeft(Buf, 4); /*/ TODO : thisblock = (size_t)atoi(&buf[4]); */
                            thisblock = StrTol(Buf);
                            if (!WC->connected) {
@@ -502,63 +505,53 @@ int GetServerStatus(StrBuf *Line, long* FullState)
 }
 
 
-void tmplput_serv_ip(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_serv_ip(StrBuf *Target, WCTemplputParams *TP)
 {
        StrBufAppendPrintf(Target, "%d", WC->ctdl_pid);
 }
 
-void tmplput_serv_nodename(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_serv_nodename(StrBuf *Target, WCTemplputParams *TP)
 {
-       StrEscAppend(Target, NULL, serv_info.serv_nodename, 0, 0);
+       StrBufAppendTemplate(Target, TP, serv_info.serv_nodename, 0);
 }
 
-void tmplput_serv_humannode(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_serv_humannode(StrBuf *Target, WCTemplputParams *TP)
 {
-       StrEscAppend(Target, NULL, serv_info.serv_humannode, 0, 0);
+       StrBufAppendTemplate(Target, TP, serv_info.serv_humannode, 0);
 }
 
-void tmplput_serv_fqdn(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_serv_fqdn(StrBuf *Target, WCTemplputParams *TP)
 {
-       StrEscAppend(Target, NULL, serv_info.serv_fqdn, 0, 0);
+       StrBufAppendTemplate(Target, TP, serv_info.serv_fqdn, 0);
 }
 
-void tmplput_serv_software(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_serv_software(StrBuf *Target, WCTemplputParams *TP)
 {
-       StrEscAppend(Target, NULL, serv_info.serv_software, 0, 0);
+       StrBufAppendTemplate(Target, TP, serv_info.serv_software, 0);
 }
 
-void tmplput_serv_rev_level(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_serv_rev_level(StrBuf *Target, WCTemplputParams *TP)
 {
        StrBufAppendPrintf(Target, "%d.%02d",
                            serv_info.serv_rev_level / 100,
                            serv_info.serv_rev_level % 100);
 }
-int conditional_serv_newuser_disabled(WCTemplateToken *Tokens, void *Context, int ContextType)
+int conditional_serv_newuser_disabled(StrBuf *Target, WCTemplputParams *TP)
 {
        return serv_info.serv_newuser_disabled != 0;
 }
-int conditional_serv_supports_openid(WCTemplateToken *Tokens, void *Context, int ContextType)
+int conditional_serv_supports_openid(StrBuf *Target, WCTemplputParams *TP)
 {
        return serv_info.serv_supports_openid != 0;
 }
 
-void tmplput_serv_bbs_city(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
-{
-       StrEscAppend(Target, NULL, serv_info.serv_bbs_city, 0, 0);
-}
-
-void tmplput_current_user(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
-{
-       StrEscAppend(Target, NULL, WC->wc_fullname, 0, 0);
-}
-
-void tmplput_current_room(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_serv_bbs_city(StrBuf *Target, WCTemplputParams *TP)
 {
-       StrEscAppend(Target, NULL, WC->wc_roomname, 0, 0);
+       StrBufAppendTemplate(Target, TP, serv_info.serv_bbs_city, 0);
 }
 
 
-void tmplput_mesg(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_mesg(StrBuf *Target, WCTemplputParams *TP)
 {
        int n = 0;
        int Done = 0;
@@ -567,7 +560,7 @@ void tmplput_mesg(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Cont
 
        Buf = NewStrBuf();
        Line = NewStrBuf();
-       serv_printf("MESG %s", Tokens->Params[0]->Start);
+       serv_printf("MESG %s", TP->Tokens->Params[0]->Start);
        StrBuf_ServGetln(Line);
        while (!Done &&  (StrBuf_ServGetln(Line)>=0)) {
                if ( (StrLength(Line)==3) && 
@@ -583,7 +576,7 @@ void tmplput_mesg(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Cont
        }
        FlushStrBuf(Line);
        FmOut(Line, "center", Buf);
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Line, 1);
+       StrBufAppendTemplate(Target, TP, Line, 1);
        FreeStrBuf(&Buf);
        FreeStrBuf(&Line);
 }
@@ -595,15 +588,13 @@ InitModule_SERVFUNC
 
        RegisterConditional(HKEY("COND:SERV:OPENID"), 2, conditional_serv_supports_openid, CTX_NONE);
        RegisterConditional(HKEY("COND:SERV:NEWU"), 2, conditional_serv_newuser_disabled, CTX_NONE);
-       RegisterNamespace("CURRENT_USER", 0, 0, tmplput_current_user, CTX_NONE);
-       RegisterNamespace("CURRENT_ROOM", 0, 0, tmplput_current_room, CTX_NONE);
        RegisterNamespace("SERV:PID", 0, 0, tmplput_serv_ip, CTX_NONE);
-       RegisterNamespace("SERV:NODENAME", 0, 0, tmplput_serv_nodename, CTX_NONE);
-       RegisterNamespace("SERV:HUMANNODE", 0, 0, tmplput_serv_humannode, CTX_NONE);
-       RegisterNamespace("SERV:FQDN", 0, 0, tmplput_serv_fqdn, CTX_NONE);
-       RegisterNamespace("SERV:SOFTWARE", 0, 0, tmplput_serv_software, CTX_NONE);
+       RegisterNamespace("SERV:NODENAME", 0, 1, tmplput_serv_nodename, CTX_NONE);
+       RegisterNamespace("SERV:HUMANNODE", 0, 1, tmplput_serv_humannode, CTX_NONE);
+       RegisterNamespace("SERV:FQDN", 0, 1, tmplput_serv_fqdn, CTX_NONE);
+       RegisterNamespace("SERV:SOFTWARE", 0, 1, tmplput_serv_software, CTX_NONE);
        RegisterNamespace("SERV:REV_LEVEL", 0, 0, tmplput_serv_rev_level, CTX_NONE);
-       RegisterNamespace("SERV:BBS_CITY", 0, 0, tmplput_serv_bbs_city, CTX_NONE);
+       RegisterNamespace("SERV:BBS_CITY", 0, 1, tmplput_serv_bbs_city, CTX_NONE);
        RegisterNamespace("SERV:MESG", 1, 2, tmplput_mesg, CTX_NONE);
 /*TODO //      RegisterNamespace("SERV:LDAP_SUPP", 0, 0, tmplput_serv_ldap_enabled, 0); */
 }
index 7d1a0b732bf1bab0ef75c71ea0c5cb1a468d1d72..709693e59f20535e8b2d502e658c60d307720716 100644 (file)
@@ -162,7 +162,7 @@ void load_siteconfig(void)
        Buf = NewStrBuf();
        CfgToken = NULL;
        StrBuf_ServGetln(Buf);
-       if (ChrPtr(Buf)[0] == '2') {
+       if (GetServerStatus(Buf, NULL) == 2) {
                StrBufCutLeft(Buf, 4);
 
                CfgToken = NewStrBuf();
@@ -236,8 +236,8 @@ void siteconfig(void)
        serv_getln(buf, sizeof buf);
        serv_printf("SPEX mailboxes|%d|%d", ibstr("mboxpolicy"), ibstr("mboxvalue"));
        serv_getln(buf, sizeof buf);
-
-       strcpy(serv_info.serv_default_cal_zone, bstr("c_default_cal_zone"));
+       FreeStrBuf(&serv_info.serv_default_cal_zone);
+       serv_info.serv_default_cal_zone = NewStrBufDup(sbstr("c_default_cal_zone"));
 
        safestrncpy(WCC->ImportantMessage, _("Your system configuration has been updated."),
                sizeof WCC->ImportantMessage);
@@ -245,7 +245,7 @@ void siteconfig(void)
        display_aide_menu();
 }
 
-void tmplput_servcfg(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_servcfg(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        void *vBuf;
@@ -256,11 +256,11 @@ void tmplput_servcfg(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *C
                        load_siteconfig();
                GetHash(WCC->ServCfg, TKEY(0), &vBuf);
                Buf = (StrBuf*) vBuf;
-               StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Buf, 1);
+               StrBufAppendTemplate(Target, TP, Buf, 1);
        }
 }
 
-int ConditionalServCfg(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalServCfg(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        void *vBuf;
@@ -272,17 +272,17 @@ int ConditionalServCfg(WCTemplateToken *Tokens, void *Context, int ContextType)
                GetHash(WCC->ServCfg, TKEY(2), &vBuf);
                if (vBuf == NULL) return 0;
                Buf = (StrBuf*) vBuf;
-               if (Tokens->nParameters == 3) {
+               if (TP->Tokens->nParameters == 3) {
                        return 1;
                }
-               else if (Tokens->Params[3]->Type == TYPE_STR)
-                       return (strcmp(Tokens->Params[3]->Start, ChrPtr(Buf)) == 0);
-               else return (StrTol(Buf) == Tokens->Params[3]->lvalue);
+               else if (TP->Tokens->Params[3]->Type == TYPE_STR)
+                       return (strcmp(TP->Tokens->Params[3]->Start, ChrPtr(Buf)) == 0);
+               else return (StrTol(Buf) == TP->Tokens->Params[3]->lvalue);
        }
        else return 0;
 }
 
-int ConditionalServCfgSubst(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalServCfgSubst(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        void *vBuf;
@@ -295,7 +295,7 @@ int ConditionalServCfgSubst(WCTemplateToken *Tokens, void *Context, int ContextT
                if (vBuf == NULL) return 0;
                Buf = (StrBuf*) vBuf;
 
-               return CompareSubstToStrBuf(Buf, Tokens->Params[3]);
+               return CompareSubstToStrBuf(Buf, TP->Tokens->Params[3]);
        }
        else return 0;
 }
index dd2003c7e29b180a60c9bd77ea141403d68192fc..1f86b3f27bf438bc1d1b89486af09aec999bc8f4 100644 (file)
@@ -90,7 +90,7 @@ void display_queue_msg(long msgnum)
                                atsign = strchr(sender, '@');
                                if (atsign != NULL) {
                                        ++atsign;
-                                       if (!strcasecmp(atsign, serv_info.serv_nodename)) {
+                                       if (!strcasecmp(atsign, ChrPtr(serv_info.serv_nodename))) {
                                                --atsign;
                                                *atsign = 0;
                                        }
@@ -168,12 +168,15 @@ void display_smtpqueue_inner_div(void) {
        wcsession *WCC = WC;
        int i;
        int num_msgs;
+       StrBuf *Buf;
 
        /* Check to see if we can go to the __CitadelSMTPspoolout__ room.
         * If not, we don't have access to the queue.
         */
-       gotoroom("__CitadelSMTPspoolout__");
-       if (!strcasecmp(WCC->wc_roomname, "__CitadelSMTPspoolout__")) {
+       Buf = NewStrBufPlain(HKEY("__CitadelSMTPspoolout__"));
+       gotoroom(Buf);
+       FreeStrBuf(&Buf);
+       if (!strcasecmp(ChrPtr(WCC->wc_roomname), "__CitadelSMTPspoolout__")) {
 
                num_msgs = load_msg_ptrs("MSGS ALL", 0);
                if (num_msgs > 0) {
index d7bee83ba44d1ede68358bc4ad2ddd1c493bde70..1759de0717492f3ca8e563ea24c1a88e2a5a7d15 100644 (file)
@@ -4,12 +4,11 @@
        font:lighter 11px/1.3 sans-serif;\r
        text-decoration:none;\r
        text-align:left;\r
-       overflow:hidden;\r
 }\r
 \r
 .tooltip span.top {\r
        padding: 30px 8px 0;\r
-       background: url(bt.gif) no-repeat top left;\r
+       background: url(bt.gif) no-repeat top\r
 }\r
 \r
 .tooltip b.bottom {\r
index a78fc57cd388354dbf0a17b898fc62ce46e5c762..0ecdcc772d6c99622e1266fa3cba86451e868a5d 100644 (file)
@@ -47,7 +47,7 @@ function SendSomething(which_div, sendform, recipient) {
 
        // Send the text to the server
        parms = 'r=' + Math.random()
-               + '&g_cmd=SEXP ' + recipient + '|-&g_input=' + encodeURIComponent(thetext);
+               + '&g_cmd=SEXP ' + recipient + '|-\n' + escape(thetext);
        new Ajax.Request('../ajax_servcmd',
                {
                        method: 'post',
index 6385503a1c526d4d13ccc770bce74200826ecd6a..dfe8ab4e13652153903d481a1b006878df6a1f3b 100644 (file)
@@ -1,4 +1,4 @@
-/*  Prototype JavaScript framework, version 1.6.0.2
+/*  Prototype JavaScript framework, version 1.6.0.3
  *  (c) 2005-2008 Sam Stephenson
  *
  *  Prototype is freely distributable under the terms of an MIT-style license.
@@ -7,23 +7,26 @@
  *--------------------------------------------------------------------------*/
 
 var Prototype = {
-  Version: '1.6.0.2',
+  Version: '1.6.0.3',
 
   Browser: {
-    IE:     !!(window.attachEvent && !window.opera),
-    Opera:  !!window.opera,
+    IE:     !!(window.attachEvent &&
+      navigator.userAgent.indexOf('Opera') === -1),
+    Opera:  navigator.userAgent.indexOf('Opera') > -1,
     WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
-    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
+    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 &&
+      navigator.userAgent.indexOf('KHTML') === -1,
     MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
   },
 
   BrowserFeatures: {
     XPath: !!document.evaluate,
+    SelectorsAPI: !!document.querySelector,
     ElementExtensions: !!window.HTMLElement,
     SpecificElementExtensions:
-      document.createElement('div').__proto__ &&
-      document.createElement('div').__proto__ !==
-        document.createElement('form').__proto__
+      document.createElement('div')['__proto__'] &&
+      document.createElement('div')['__proto__'] !==
+        document.createElement('form')['__proto__']
   },
 
   ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script>',
@@ -83,12 +86,13 @@ Class.Methods = {
       var property = properties[i], value = source[property];
       if (ancestor && Object.isFunction(value) &&
           value.argumentNames().first() == "$super") {
-        var method = value, value = Object.extend((function(m) {
+        var method = value;
+        value = (function(m) {
           return function() { return ancestor[m].apply(this, arguments) };
-        })(property).wrap(method), {
-          valueOf:  function() { return method },
-          toString: function() { return method.toString() }
-        });
+        })(property).wrap(method);
+
+        value.valueOf = method.valueOf.bind(method);
+        value.toString = method.toString.bind(method);
       }
       this.prototype[property] = value;
     }
@@ -167,7 +171,7 @@ Object.extend(Object, {
   },
 
   isElement: function(object) {
-    return object && object.nodeType == 1;
+    return !!(object && object.nodeType == 1);
   },
 
   isArray: function(object) {
@@ -198,7 +202,8 @@ Object.extend(Object, {
 
 Object.extend(Function.prototype, {
   argumentNames: function() {
-    var names = this.toString().match(/^[\s\(]*function[^(]*\((.*?)\)/)[1].split(",").invoke("strip");
+    var names = this.toString().match(/^[\s\(]*function[^(]*\(([^\)]*)\)/)[1]
+      .replace(/\s+/g, '').split(',');
     return names.length == 1 && !names[0] ? [] : names;
   },
 
@@ -232,6 +237,11 @@ Object.extend(Function.prototype, {
     }, timeout);
   },
 
+  defer: function() {
+    var args = [0.01].concat($A(arguments));
+    return this.delay.apply(this, args);
+  },
+
   wrap: function(wrapper) {
     var __method = this;
     return function() {
@@ -248,8 +258,6 @@ Object.extend(Function.prototype, {
   }
 });
 
-Function.prototype.defer = Function.prototype.delay.curry(0.01);
-
 Date.prototype.toJSON = function() {
   return '"' + this.getUTCFullYear() + '-' +
     (this.getUTCMonth() + 1).toPaddedString(2) + '-' +
@@ -530,7 +538,7 @@ if (Prototype.Browser.WebKit || Prototype.Browser.IE) Object.extend(String.proto
     return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
   },
   unescapeHTML: function() {
-    return this.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>');
+    return this.stripTags().replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>');
   }
 });
 
@@ -547,7 +555,7 @@ Object.extend(String.prototype.escapeHTML, {
   text: document.createTextNode('')
 });
 
-with (String.prototype.escapeHTML) div.appendChild(text);
+String.prototype.escapeHTML.div.appendChild(String.prototype.escapeHTML.text);
 
 var Template = Class.create({
   initialize: function(template, pattern) {
@@ -589,10 +597,9 @@ var $break = { };
 var Enumerable = {
   each: function(iterator, context) {
     var index = 0;
-    iterator = iterator.bind(context);
     try {
       this._each(function(value) {
-        iterator(value, index++);
+        iterator.call(context, value, index++);
       });
     } catch (e) {
       if (e != $break) throw e;
@@ -601,47 +608,46 @@ var Enumerable = {
   },
 
   eachSlice: function(number, iterator, context) {
-    iterator = iterator ? iterator.bind(context) : Prototype.K;
     var index = -number, slices = [], array = this.toArray();
+    if (number < 1) return array;
     while ((index += number) < array.length)
       slices.push(array.slice(index, index+number));
     return slices.collect(iterator, context);
   },
 
   all: function(iterator, context) {
-    iterator = iterator ? iterator.bind(context) : Prototype.K;
+    iterator = iterator || Prototype.K;
     var result = true;
     this.each(function(value, index) {
-      result = result && !!iterator(value, index);
+      result = result && !!iterator.call(context, value, index);
       if (!result) throw $break;
     });
     return result;
   },
 
   any: function(iterator, context) {
-    iterator = iterator ? iterator.bind(context) : Prototype.K;
+    iterator = iterator || Prototype.K;
     var result = false;
     this.each(function(value, index) {
-      if (result = !!iterator(value, index))
+      if (result = !!iterator.call(context, value, index))
         throw $break;
     });
     return result;
   },
 
   collect: function(iterator, context) {
-    iterator = iterator ? iterator.bind(context) : Prototype.K;
+    iterator = iterator || Prototype.K;
     var results = [];
     this.each(function(value, index) {
-      results.push(iterator(value, index));
+      results.push(iterator.call(context, value, index));
     });
     return results;
   },
 
   detect: function(iterator, context) {
-    iterator = iterator.bind(context);
     var result;
     this.each(function(value, index) {
-      if (iterator(value, index)) {
+      if (iterator.call(context, value, index)) {
         result = value;
         throw $break;
       }
@@ -650,17 +656,16 @@ var Enumerable = {
   },
 
   findAll: function(iterator, context) {
-    iterator = iterator.bind(context);
     var results = [];
     this.each(function(value, index) {
-      if (iterator(value, index))
+      if (iterator.call(context, value, index))
         results.push(value);
     });
     return results;
   },
 
   grep: function(filter, iterator, context) {
-    iterator = iterator ? iterator.bind(context) : Prototype.K;
+    iterator = iterator || Prototype.K;
     var results = [];
 
     if (Object.isString(filter))
@@ -668,7 +673,7 @@ var Enumerable = {
 
     this.each(function(value, index) {
       if (filter.match(value))
-        results.push(iterator(value, index));
+        results.push(iterator.call(context, value, index));
     });
     return results;
   },
@@ -696,9 +701,8 @@ var Enumerable = {
   },
 
   inject: function(memo, iterator, context) {
-    iterator = iterator.bind(context);
     this.each(function(value, index) {
-      memo = iterator(memo, value, index);
+      memo = iterator.call(context, memo, value, index);
     });
     return memo;
   },
@@ -711,10 +715,10 @@ var Enumerable = {
   },
 
   max: function(iterator, context) {
-    iterator = iterator ? iterator.bind(context) : Prototype.K;
+    iterator = iterator || Prototype.K;
     var result;
     this.each(function(value, index) {
-      value = iterator(value, index);
+      value = iterator.call(context, value, index);
       if (result == null || value >= result)
         result = value;
     });
@@ -722,10 +726,10 @@ var Enumerable = {
   },
 
   min: function(iterator, context) {
-    iterator = iterator ? iterator.bind(context) : Prototype.K;
+    iterator = iterator || Prototype.K;
     var result;
     this.each(function(value, index) {
-      value = iterator(value, index);
+      value = iterator.call(context, value, index);
       if (result == null || value < result)
         result = value;
     });
@@ -733,10 +737,10 @@ var Enumerable = {
   },
 
   partition: function(iterator, context) {
-    iterator = iterator ? iterator.bind(context) : Prototype.K;
+    iterator = iterator || Prototype.K;
     var trues = [], falses = [];
     this.each(function(value, index) {
-      (iterator(value, index) ?
+      (iterator.call(context, value, index) ?
         trues : falses).push(value);
     });
     return [trues, falses];
@@ -751,19 +755,20 @@ var Enumerable = {
   },
 
   reject: function(iterator, context) {
-    iterator = iterator.bind(context);
     var results = [];
     this.each(function(value, index) {
-      if (!iterator(value, index))
+      if (!iterator.call(context, value, index))
         results.push(value);
     });
     return results;
   },
 
   sortBy: function(iterator, context) {
-    iterator = iterator.bind(context);
     return this.map(function(value, index) {
-      return {value: value, criteria: iterator(value, index)};
+      return {
+        value: value,
+        criteria: iterator.call(context, value, index)
+      };
     }).sort(function(left, right) {
       var a = left.criteria, b = right.criteria;
       return a < b ? -1 : a > b ? 1 : 0;
@@ -815,8 +820,12 @@ function $A(iterable) {
 if (Prototype.Browser.WebKit) {
   $A = function(iterable) {
     if (!iterable) return [];
-    if (!(Object.isFunction(iterable) && iterable == '[object NodeList]') &&
-        iterable.toArray) return iterable.toArray();
+    // In Safari, only use the `toArray` method if it's not a NodeList.
+    // A NodeList is a function, has an function `item` property, and a numeric
+    // `length` property. Adapted from Google Doctype.
+    if (!(typeof iterable === 'function' && typeof iterable.length ===
+        'number' && typeof iterable.item === 'function') && iterable.toArray)
+      return iterable.toArray();
     var length = iterable.length || 0, results = new Array(length);
     while (length--) results[length] = iterable[length];
     return results;
@@ -963,8 +972,8 @@ Object.extend(Number.prototype, {
     return this + 1;
   },
 
-  times: function(iterator) {
-    $R(0, this, true).each(iterator);
+  times: function(iterator, context) {
+    $R(0, this, true).each(iterator, context);
     return this;
   },
 
@@ -1011,7 +1020,9 @@ var Hash = Class.create(Enumerable, (function() {
     },
 
     get: function(key) {
-      return this._object[key];
+      // simulating poorly supported hasOwnProperty
+      if (this._object[key] !== Object.prototype[key])
+        return this._object[key];
     },
 
     unset: function(key) {
@@ -1051,14 +1062,14 @@ var Hash = Class.create(Enumerable, (function() {
     },
 
     toQueryString: function() {
-      return this.map(function(pair) {
+      return this.inject([], function(results, pair) {
         var key = encodeURIComponent(pair.key), values = pair.value;
 
         if (values && typeof values == 'object') {
           if (Object.isArray(values))
-            return values.map(toQueryPair.curry(key)).join('&');
-        }
-        return toQueryPair(key, values);
+            return results.concat(values.map(toQueryPair.curry(key)));
+        } else results.push(toQueryPair(key, values));
+        return results;
       }).join('&');
     },
 
@@ -1558,6 +1569,7 @@ if (!Node.ELEMENT_NODE) {
     return Element.writeAttribute(cache[tagName].cloneNode(false), attributes);
   };
   Object.extend(this.Element, element || { });
+  if (element) this.Element.prototype = element.prototype;
 }).call(window);
 
 Element.cache = { };
@@ -1574,12 +1586,14 @@ Element.Methods = {
   },
 
   hide: function(element) {
-    $(element).style.display = 'none';
+    element = $(element);
+    element.style.display = 'none';
     return element;
   },
 
   show: function(element) {
-    $(element).style.display = '';
+    element = $(element);
+    element.style.display = '';
     return element;
   },
 
@@ -1733,7 +1747,7 @@ Element.Methods = {
     element = $(element);
     if (arguments.length == 1) return element.firstDescendant();
     return Object.isNumber(expression) ? element.descendants()[expression] :
-      element.select(expression)[index || 0];
+      Element.select(element, expression)[index || 0];
   },
 
   previous: function(element, expression, index) {
@@ -1863,24 +1877,16 @@ Element.Methods = {
 
   descendantOf: function(element, ancestor) {
     element = $(element), ancestor = $(ancestor);
-    var originalAncestor = ancestor;
 
     if (element.compareDocumentPosition)
       return (element.compareDocumentPosition(ancestor) & 8) === 8;
 
-    if (element.sourceIndex && !Prototype.Browser.Opera) {
-      var e = element.sourceIndex, a = ancestor.sourceIndex,
-       nextAncestor = ancestor.nextSibling;
-      if (!nextAncestor) {
-        do { ancestor = ancestor.parentNode; }
-        while (!(nextAncestor = ancestor.nextSibling) && ancestor.parentNode);
-      }
-      if (nextAncestor && nextAncestor.sourceIndex)
-       return (e > a && e < nextAncestor.sourceIndex);
-    }
+    if (ancestor.contains)
+      return ancestor.contains(element) && ancestor !== element;
 
     while (element = element.parentNode)
-      if (element == originalAncestor) return true;
+      if (element == ancestor) return true;
+
     return false;
   },
 
@@ -1895,7 +1901,7 @@ Element.Methods = {
     element = $(element);
     style = style == 'float' ? 'cssFloat' : style.camelize();
     var value = element.style[style];
-    if (!value) {
+    if (!value || value == 'auto') {
       var css = document.defaultView.getComputedStyle(element, null);
       value = css ? css[style] : null;
     }
@@ -1934,7 +1940,7 @@ Element.Methods = {
 
   getDimensions: function(element) {
     element = $(element);
-    var display = $(element).getStyle('display');
+    var display = element.getStyle('display');
     if (display != 'none' && display != null) // Safari bug
       return {width: element.offsetWidth, height: element.offsetHeight};
 
@@ -1963,7 +1969,7 @@ Element.Methods = {
       element.style.position = 'relative';
       // Opera returns the offset relative to the positioning context, when an
       // element is position relative but top and left have not been defined
-      if (window.opera) {
+      if (Prototype.Browser.Opera) {
         element.style.top = 0;
         element.style.left = 0;
       }
@@ -2018,7 +2024,7 @@ Element.Methods = {
       valueL += element.offsetLeft || 0;
       element = element.offsetParent;
       if (element) {
-        if (element.tagName == 'BODY') break;
+        if (element.tagName.toUpperCase() == 'BODY') break;
         var p = Element.getStyle(element, 'position');
         if (p !== 'static') break;
       }
@@ -2028,7 +2034,7 @@ Element.Methods = {
 
   absolutize: function(element) {
     element = $(element);
-    if (element.getStyle('position') == 'absolute') return;
+    if (element.getStyle('position') == 'absolute') return element;
     // Position.prepare(); // To be done manually by Scripty when it needs it.
 
     var offsets = element.positionedOffset();
@@ -2052,7 +2058,7 @@ Element.Methods = {
 
   relativize: function(element) {
     element = $(element);
-    if (element.getStyle('position') == 'relative') return;
+    if (element.getStyle('position') == 'relative') return element;
     // Position.prepare(); // To be done manually by Scripty when it needs it.
 
     element.style.position = 'relative';
@@ -2103,7 +2109,7 @@ Element.Methods = {
 
     element = forElement;
     do {
-      if (!Prototype.Browser.Opera || element.tagName == 'BODY') {
+      if (!Prototype.Browser.Opera || (element.tagName && (element.tagName.toUpperCase() == 'BODY'))) {
         valueT -= element.scrollTop  || 0;
         valueL -= element.scrollLeft || 0;
       }
@@ -2218,6 +2224,9 @@ else if (Prototype.Browser.IE) {
   Element.Methods.getOffsetParent = Element.Methods.getOffsetParent.wrap(
     function(proceed, element) {
       element = $(element);
+      // IE throws an error if element is not in document
+      try { element.offsetParent }
+      catch(e) { return $(document.body) }
       var position = element.getStyle('position');
       if (position !== 'static') return proceed(element);
       element.setStyle({ position: 'relative' });
@@ -2231,6 +2240,8 @@ else if (Prototype.Browser.IE) {
     Element.Methods[method] = Element.Methods[method].wrap(
       function(proceed, element) {
         element = $(element);
+        try { element.offsetParent }
+        catch(e) { return Element._returnOffset(0,0) }
         var position = element.getStyle('position');
         if (position !== 'static') return proceed(element);
         // Trigger hasLayout on the offset parent so that IE6 reports
@@ -2246,6 +2257,14 @@ else if (Prototype.Browser.IE) {
     );
   });
 
+  Element.Methods.cumulativeOffset = Element.Methods.cumulativeOffset.wrap(
+    function(proceed, element) {
+      try { element.offsetParent }
+      catch(e) { return Element._returnOffset(0,0) }
+      return proceed(element);
+    }
+  );
+
   Element.Methods.getStyle = function(element, style) {
     element = $(element);
     style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize();
@@ -2337,7 +2356,7 @@ else if (Prototype.Browser.IE) {
   Element._attributeTranslations.has = {};
 
   $w('colSpan rowSpan vAlign dateTime accessKey tabIndex ' +
-      'encType maxLength readOnly longDesc').each(function(attr) {
+      'encType maxLength readOnly longDesc frameBorder').each(function(attr) {
     Element._attributeTranslations.write.names[attr.toLowerCase()] = attr;
     Element._attributeTranslations.has[attr.toLowerCase()] = attr;
   });
@@ -2390,7 +2409,7 @@ else if (Prototype.Browser.WebKit) {
       (value < 0.00001) ? 0 : value;
 
     if (value == 1)
-      if(element.tagName == 'IMG' && element.width) {
+      if(element.tagName.toUpperCase() == 'IMG' && element.width) {
         element.width++; element.width--;
       } else try {
         var n = document.createTextNode(' ');
@@ -2521,7 +2540,7 @@ Element.Methods.Simulated = {
   hasAttribute: function(element, attribute) {
     attribute = Element._attributeTranslations.has[attribute] || attribute;
     var node = $(element).getAttributeNode(attribute);
-    return node && node.specified;
+    return !!(node && node.specified);
   }
 };
 
@@ -2530,9 +2549,9 @@ Element.Methods.ByTag = { };
 Object.extend(Element, Element.Methods);
 
 if (!Prototype.BrowserFeatures.ElementExtensions &&
-    document.createElement('div').__proto__) {
+    document.createElement('div')['__proto__']) {
   window.HTMLElement = { };
-  window.HTMLElement.prototype = document.createElement('div').__proto__;
+  window.HTMLElement.prototype = document.createElement('div')['__proto__'];
   Prototype.BrowserFeatures.ElementExtensions = true;
 }
 
@@ -2547,7 +2566,7 @@ Element.extend = (function() {
         element.nodeType != 1 || element == window) return element;
 
     var methods = Object.clone(Methods),
-      tagName = element.tagName, property, value;
+      tagName = element.tagName.toUpperCase(), property, value;
 
     // extend methods for specific tags
     if (ByTag[tagName]) Object.extend(methods, ByTag[tagName]);
@@ -2643,7 +2662,7 @@ Element.addMethods = function(methods) {
     if (window[klass]) return window[klass];
 
     window[klass] = { };
-    window[klass].prototype = document.createElement(tagName).__proto__;
+    window[klass].prototype = document.createElement(tagName)['__proto__'];
     return window[klass];
   }
 
@@ -2669,12 +2688,18 @@ Element.addMethods = function(methods) {
 
 document.viewport = {
   getDimensions: function() {
-    var dimensions = { };
-    var B = Prototype.Browser;
+    var dimensions = { }, B = Prototype.Browser;
     $w('width height').each(function(d) {
       var D = d.capitalize();
-      dimensions[d] = (B.WebKit && !document.evaluate) ? self['inner' + D] :
-        (B.Opera) ? document.body['client' + D] : document.documentElement['client' + D];
+      if (B.WebKit && !document.evaluate) {
+        // Safari <3.0 needs self.innerWidth/Height
+        dimensions[d] = self['inner' + D];
+      } else if (B.Opera && parseFloat(window.opera.version()) < 9.5) {
+        // Opera <9.5 needs document.body.clientWidth/Height
+        dimensions[d] = document.body['client' + D]
+      } else {
+        dimensions[d] = document.documentElement['client' + D];
+      }
     });
     return dimensions;
   },
@@ -2693,14 +2718,24 @@ document.viewport = {
       window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop);
   }
 };
-/* Portions of the Selector class are derived from Jack Slocums DomQuery,
+/* Portions of the Selector class are derived from Jack Slocum's DomQuery,
  * part of YUI-Ext version 0.40, distributed under the terms of an MIT-style
  * license.  Please see http://www.yui-ext.com/ for more information. */
 
 var Selector = Class.create({
   initialize: function(expression) {
     this.expression = expression.strip();
-    this.compileMatcher();
+
+    if (this.shouldUseSelectorsAPI()) {
+      this.mode = 'selectorsAPI';
+    } else if (this.shouldUseXPath()) {
+      this.mode = 'xpath';
+      this.compileXPathMatcher();
+    } else {
+      this.mode = "normal";
+      this.compileMatcher();
+    }
+
   },
 
   shouldUseXPath: function() {
@@ -2715,16 +2750,29 @@ var Selector = Class.create({
 
     // XPath can't do namespaced attributes, nor can it read
     // the "checked" property from DOM nodes
-    if ((/(\[[\w-]*?:|:checked)/).test(this.expression))
+    if ((/(\[[\w-]*?:|:checked)/).test(e))
       return false;
 
     return true;
   },
 
-  compileMatcher: function() {
-    if (this.shouldUseXPath())
-      return this.compileXPathMatcher();
+  shouldUseSelectorsAPI: function() {
+    if (!Prototype.BrowserFeatures.SelectorsAPI) return false;
+
+    if (!Selector._div) Selector._div = new Element('div');
+
+    // Make sure the browser treats the selector as valid. Test on an
+    // isolated element to minimize cost of this check.
+    try {
+      Selector._div.querySelector(this.expression);
+    } catch(e) {
+      return false;
+    }
+
+    return true;
+  },
 
+  compileMatcher: function() {
     var e = this.expression, ps = Selector.patterns, h = Selector.handlers,
         c = Selector.criteria, le, p, m;
 
@@ -2742,7 +2790,7 @@ var Selector = Class.create({
         p = ps[i];
         if (m = e.match(p)) {
           this.matcher.push(Object.isFunction(c[i]) ? c[i](m) :
-             new Template(c[i]).evaluate(m));
+            new Template(c[i]).evaluate(m));
           e = e.replace(m[0], '');
           break;
         }
@@ -2781,8 +2829,27 @@ var Selector = Class.create({
 
   findElements: function(root) {
     root = root || document;
-    if (this.xpath) return document._getElementsByXPath(this.xpath, root);
-    return this.matcher(root);
+    var e = this.expression, results;
+
+    switch (this.mode) {
+      case 'selectorsAPI':
+        // querySelectorAll queries document-wide, then filters to descendants
+        // of the context element. That's not what we want.
+        // Add an explicit context to the selector if necessary.
+        if (root !== document) {
+          var oldId = root.id, id = $(root).identify();
+          e = "#" + id + " " + e;
+        }
+
+        results = $A(root.querySelectorAll(e)).map(Element.extend);
+        root.id = oldId;
+
+        return results;
+      case 'xpath':
+        return document._getElementsByXPath(this.xpath, root);
+      default:
+       return this.matcher(root);
+    }
   },
 
   match: function(element) {
@@ -2873,10 +2940,10 @@ Object.extend(Selector, {
       'first-child': '[not(preceding-sibling::*)]',
       'last-child':  '[not(following-sibling::*)]',
       'only-child':  '[not(preceding-sibling::* or following-sibling::*)]',
-      'empty':       "[count(*) = 0 and (count(text()) = 0 or translate(text(), ' \t\r\n', '') = '')]",
+      'empty':       "[count(*) = 0 and (count(text()) = 0)]",
       'checked':     "[@checked]",
-      'disabled':    "[@disabled]",
-      'enabled':     "[not(@disabled)]",
+      'disabled':    "[(@disabled) and (@type!='hidden')]",
+      'enabled':     "[not(@disabled) and (@type!='hidden')]",
       'not': function(m) {
         var e = m[6], p = Selector.patterns,
             x = Selector.xpath, le, v;
@@ -2968,7 +3035,7 @@ Object.extend(Selector, {
     className:    /^\.([\w\-\*]+)(\b|$)/,
     pseudo:
 /^:((first|last|nth|nth-last|only)(-child|-of-type)|empty|checked|(en|dis)abled|not)(\((.*?)\))?(\b|$|(?=\s|[:+~>]))/,
-    attrPresence: /^\[([\w]+)\]/,
+    attrPresence: /^\[((?:[\w]+:)?[\w]+)\]/,
     attr:         /\[((?:[\w-]*:)?[\w-]+)\s*(?:([!^$*~|]?=)\s*((['"])([^\4]*?)\4|([^'"][^\]]*?)))?\]/
   },
 
@@ -3081,7 +3148,7 @@ Object.extend(Selector, {
 
     nextElementSibling: function(node) {
       while (node = node.nextSibling)
-             if (node.nodeType == 1) return node;
+        if (node.nodeType == 1) return node;
       return null;
     },
 
@@ -3270,7 +3337,7 @@ Object.extend(Selector, {
     'empty': function(nodes, value, root) {
       for (var i = 0, results = [], node; node = nodes[i]; i++) {
         // IE treats comments as element nodes
-        if (node.tagName == '!' || (node.firstChild && !node.innerHTML.match(/^\s*$/))) continue;
+        if (node.tagName == '!' || node.firstChild) continue;
         results.push(node);
       }
       return results;
@@ -3288,7 +3355,8 @@ Object.extend(Selector, {
 
     'enabled': function(nodes, value, root) {
       for (var i = 0, results = [], node; node = nodes[i]; i++)
-        if (!node.disabled) results.push(node);
+        if (!node.disabled && (!node.type || node.type !== 'hidden'))
+          results.push(node);
       return results;
     },
 
@@ -3308,11 +3376,14 @@ Object.extend(Selector, {
   operators: {
     '=':  function(nv, v) { return nv == v; },
     '!=': function(nv, v) { return nv != v; },
-    '^=': function(nv, v) { return nv.startsWith(v); },
+    '^=': function(nv, v) { return nv == v || nv && nv.startsWith(v); },
+    '$=': function(nv, v) { return nv == v || nv && nv.endsWith(v); },
+    '*=': function(nv, v) { return nv == v || nv && nv.include(v); },
     '$=': function(nv, v) { return nv.endsWith(v); },
     '*=': function(nv, v) { return nv.include(v); },
     '~=': function(nv, v) { return (' ' + nv + ' ').include(' ' + v + ' '); },
-    '|=': function(nv, v) { return ('-' + nv.toUpperCase() + '-').include('-' + v.toUpperCase() + '-'); }
+    '|=': function(nv, v) { return ('-' + (nv || "").toUpperCase() +
+     '-').include('-' + (v || "").toUpperCase() + '-'); }
   },
 
   split: function(expression) {
@@ -3386,7 +3457,7 @@ var Form = {
     var data = elements.inject({ }, function(result, element) {
       if (!element.disabled && element.name) {
         key = element.name; value = $(element).getValue();
-        if (value != null && (element.type != 'submit' || (!submitted &&
+        if (value != null && element.type != 'file' && (element.type != 'submit' || (!submitted &&
             submit !== false && (!submit || key == submit) && (submitted = true)))) {
           if (key in result) {
             // a key is already present; construct an array of values
@@ -3547,7 +3618,6 @@ Form.Element.Methods = {
 
   disable: function(element) {
     element = $(element);
-    element.blur();
     element.disabled = true;
     return element;
   },
@@ -3587,22 +3657,22 @@ Form.Element.Serializers = {
     else element.value = value;
   },
 
-  select: function(element, index) {
-    if (Object.isUndefined(index))
+  select: function(element, value) {
+    if (Object.isUndefined(value))
       return this[element.type == 'select-one' ?
         'selectOne' : 'selectMany'](element);
     else {
-      var opt, value, single = !Object.isArray(index);
+      var opt, currentValue, single = !Object.isArray(value);
       for (var i = 0, length = element.length; i < length; i++) {
         opt = element.options[i];
-        value = this.optionValue(opt);
+        currentValue = this.optionValue(opt);
         if (single) {
-          if (value == index) {
+          if (currentValue == value) {
             opt.selected = true;
             return;
           }
         }
-        else opt.selected = index.include(value);
+        else opt.selected = value.include(currentValue);
       }
     }
   },
@@ -3773,8 +3843,23 @@ Event.Methods = (function() {
     isRightClick:  function(event) { return isButton(event, 2) },
 
     element: function(event) {
-      var node = Event.extend(event).target;
-      return Element.extend(node.nodeType == Node.TEXT_NODE ? node.parentNode : node);
+      event = Event.extend(event);
+
+      var node          = event.target,
+          type          = event.type,
+          currentTarget = event.currentTarget;
+
+      if (currentTarget && currentTarget.tagName) {
+        // Firefox screws up the "click" event when moving between radio buttons
+        // via arrow keys. It also screws up the "load" and "error" events on images,
+        // reporting the document as the target instead of the original image.
+        if (type === 'load' || type === 'error' ||
+          (type === 'click' && currentTarget.tagName.toLowerCase() === 'input'
+            && currentTarget.type === 'radio'))
+              node = currentTarget;
+      }
+      if (node.nodeType == Node.TEXT_NODE) node = node.parentNode;
+      return Element.extend(node);
     },
 
     findElement: function(event, expression) {
@@ -3785,11 +3870,15 @@ Event.Methods = (function() {
     },
 
     pointer: function(event) {
+      var docElement = document.documentElement,
+      body = document.body || { scrollLeft: 0, scrollTop: 0 };
       return {
         x: event.pageX || (event.clientX +
-          (document.documentElement.scrollLeft || document.body.scrollLeft)),
+          (docElement.scrollLeft || body.scrollLeft) -
+          (docElement.clientLeft || 0)),
         y: event.pageY || (event.clientY +
-          (document.documentElement.scrollTop || document.body.scrollTop))
+          (docElement.scrollTop || body.scrollTop) -
+          (docElement.clientTop || 0))
       };
     },
 
@@ -3834,7 +3923,7 @@ Event.extend = (function() {
     };
 
   } else {
-    Event.prototype = Event.prototype || document.createEvent("HTMLEvents").__proto__;
+    Event.prototype = Event.prototype || document.createEvent("HTMLEvents")['__proto__'];
     Object.extend(Event.prototype, methods);
     return Prototype.K;
   }
@@ -3899,10 +3988,20 @@ Object.extend(Event, (function() {
         cache[id][eventName] = null;
   }
 
+
+  // Internet Explorer needs to remove event handlers on page unload
+  // in order to avoid memory leaks.
   if (window.attachEvent) {
     window.attachEvent("onunload", destroyCache);
   }
 
+  // Safari has a dummy event handler on page unload so that it won't
+  // use its bfcache. Safari <= 3.1 has an issue with restoring the "document"
+  // object when page is returned to via the back button using its bfcache.
+  if (Prototype.Browser.WebKit) {
+    window.addEventListener('unload', Prototype.emptyFunction, false);
+  }
+
   return {
     observe: function(element, eventName, handler) {
       element = $(element);
index fc5b56dead664d19978f38f0f0b84c7bdecbd5d0..1d04a9e50fc516d8c5c5669c238253f62ed4e855 100644 (file)
@@ -967,23 +967,18 @@ function TaskViewGatherCategoriesFromTable() {
        var table = $('taskview');
        
 }
-function attachDatePicker(relative, wclang) {
+function attachDatePicker(relative) {
        var dpck = new DatePicker({
        relative: relative,
-       language: wclang.substr(0,2),
-       disableFutureDate: false,
-       dateFormat: [ ["yyyy", "mm", "dd"], "-"],
-       showDuration: 0.2,
-       closeEffectDuration: 0.2
+       language: 'en', // fix please
+       disableFutureDate: false
        });
        document.getElementById(relative).dpck = dpck; // attach a ref to it
 }
-
 function eventEditAllDay() {
-       var allDayCheck = $('alldayevent');
-       var dtend = $('dtendcell');
-
-       if (allDayCheck.checked) {
+       var allDayCheck = document.getElementById("alldayevent");
+       var dtend= document.getElementById("dtendcell");
+       if(allDayCheck.checked) {
                //dtend.disabled = true;
                dtend.style.textDecoration = "line-through";
        } else {
@@ -991,84 +986,3 @@ function eventEditAllDay() {
                dtend.style.textDecoration = "";
        }
 }
-
-
-
-
-// Functions which handle show/hide of various elements in the recurrence editor
-
-function RecurrenceShowHide() {
-
-       if ($('is_recur').checked) {
-               $('rrule_div').style.display = 'block';
-       }
-       else {
-               $('rrule_div').style.display = 'none';
-       }
-
-       if ($('freq_selector').selectedIndex == 4) {
-               $('weekday_selector').style.display = 'block';
-       }
-       else {
-               $('weekday_selector').style.display = 'none';
-       }
-
-       if ($('freq_selector').selectedIndex == 5) {
-               $('monthday_selector').style.display = 'block';
-       }
-       else {
-               $('monthday_selector').style.display = 'none';
-       }
-
-       if ($('rrend_count').checked) {
-               $('rrcount').disabled = false;
-       }
-       else {
-               $('rrcount').disabled = true;
-       }
-
-       if ($('rrend_until').checked) {
-               $('rruntil').disabled = false;
-       }
-       else {
-               $('rruntil').disabled = true;
-       }
-
-       if ($('rrmonthtype_mday').checked) {
-               $('rrmday').disabled = false;
-       }
-       else {
-               $('rrmday').disabled = true;
-       }
-
-       if ($('rrmonthtype_wday').checked) {
-               $('rrmweek').disabled = false;
-               $('rrmweekday').disabled = false;
-       }
-       else {
-               $('rrmweek').disabled = true;
-               $('rrmweekday').disabled = true;
-       }
-
-       if ($('freq_selector').selectedIndex == 6) {
-               $('yearday_selector').style.display = 'block';
-       }
-       else {
-               $('yearday_selector').style.display = 'none';
-       }
-
-       $('ymday').innerHTML = 'XXXX-' + $('dtstart').value.substr(5);
-       $('rrmday').innerHTML = $('dtstart').value.substr(8);
-
-       if ($('rryeartype_ywday').checked) {
-               $('rrymweek').disabled = false;
-               $('rrymweekday').disabled = false;
-               $('rrymonth').disabled = false;
-       }
-       else {
-               $('rrymweek').disabled = true;
-               $('rrymweekday').disabled = true;
-               $('rrymonth').disabled = true;
-       }
-
-}
index fe7df4762264c6cc724f48c006ab1fde58a6360e..8f07e72f7572d38f9ea596d6b5e3bb0b0155b189 100644 (file)
@@ -67,7 +67,6 @@ body {
 
 #room_infos, #address_book_popup, .mimepart, .room_actions form select {
        border: 1px solid #333;
-       overflow: hidden;
 }
 
 
@@ -1162,7 +1161,7 @@ ul.tabbed_dialog li {
 
 .tabcontent_submit {
         margin: 0 auto 0 auto;
-        width: 96%;
+        width: 50%;
         padding: 10px;
         text-align: center;
 }
index a43cdcffdd96bd70a00c9ae5af07ee8c36264048..28afdebc850c96d350fd8684f0c31f9914794f66 100644 (file)
@@ -33,6 +33,7 @@ HashList *Conditionals;
 HashList *SortHash;
 
 int LoadTemplates = 0;
+WCTemplputParams NoCtx;
 
 #define SV_GETTEXT 1
 #define SV_CONDITIONAL 2
@@ -57,7 +58,7 @@ typedef struct _HashHandler {
 }HashHandler;
 
 void *load_template(StrBuf *filename, StrBuf *Key, HashList *PutThere);
-int EvaluateConditional(StrBuf *Target, WCTemplateToken *Tokens, WCTemplate *pTmpl, void *Context, int Neg, int state, int ContextType);
+int EvaluateConditional(StrBuf *Target, int Neg, int state, WCTemplputParams *TP);
 
 typedef struct _SortStruct {
        StrBuf *Name;
@@ -77,6 +78,52 @@ void DestroySortStruct(void *vSort)
        free (Sort);
 }
 
+void LogTemplateError (StrBuf *Target, const char *Type, int ErrorPos, WCTemplputParams *TP, const char *Format, ...)
+{
+       StrBuf *Error;
+       StrBuf *Info;
+        va_list arg_ptr;
+       const char *Err = NULL;
+
+       Info = NewStrBuf();
+       Error = NewStrBuf();
+
+        va_start(arg_ptr, Format);
+       StrBufVAppendPrintf(Error, Format, arg_ptr);
+       va_end(arg_ptr);
+
+       switch (ErrorPos) {
+       default:
+       case ERR_NAME: /* the main token name... */ 
+               Err = TP->Tokens->pName;
+               break;
+       case ERR_PARM1:
+               Err = TP->Tokens->Params[0]->Start;
+               break;
+       case ERR_PARM2:
+               Err = TP->Tokens->Params[1]->Start;
+               break;
+       }
+       lprintf(1, "%s [%s]  (in '%s' line %ld); %s; [%s]\n", 
+               Type, 
+               Err, 
+               ChrPtr(TP->Tokens->FileName),
+               TP->Tokens->Line, 
+               ChrPtr(Error), 
+               ChrPtr(TP->Tokens->FlatToken));
+       if (Target != NULL) {
+               StrBufAppendPrintf(                                                          
+                       Target,                                                              
+                       "<pre>\n%s [%s] (in '%s' line %ld); %s\n[%s]\n</pre>\n",
+                       Type, 
+                       Err, 
+                       ChrPtr(TP->Tokens->FileName),
+                       TP->Tokens->Line,
+                       ChrPtr(Error),
+                       ChrPtr(TP->Tokens->FlatToken));
+       }
+}
+
 
 void RegisterNS(const char *NSName, 
                long len, 
@@ -484,24 +531,26 @@ void pvo_do_cmd(StrBuf *Target, StrBuf *servcmd) {
        }
 }
 
-void GetTemplateTokenString(WCTemplateToken *Tokens,
-                           int N, 
+void GetTemplateTokenString(WCTemplputParams *TP,
+                           int N,
                            const char **Value, 
                            long *len)
 {
        StrBuf *Buf;
 
-       if (Tokens->nParameters < N) {
+       if (TP->Tokens->nParameters < N) {
+               lprintf(1, "invalid token. this shouldn't have come till here.\n");
+               wc_backtrace(); 
                *Value = "";
                *len = 0;
                return;
        }
 
-       switch (Tokens->Params[N]->Type) {
+       switch (TP->Tokens->Params[N]->Type) {
 
        case TYPE_STR:
-               *Value = Tokens->Params[N]->Start;
-               *len = Tokens->Params[N]->len;
+               *Value = TP->Tokens->Params[N]->Start;
+               *len = TP->Tokens->Params[N]->len;
                break;
        case TYPE_BSTR:
                Buf = (StrBuf*) SBstr(TKEY(N));
@@ -517,7 +566,7 @@ void GetTemplateTokenString(WCTemplateToken *Tokens,
        case TYPE_PREFINT:
                break; /* todo: string to text? */
        case TYPE_GETTEXT:
-               *Value = _(Tokens->Params[N]->Start);
+               *Value = _(TP->Tokens->Params[N]->Start);
                *len = strlen(*Value);
                break;
        default:
@@ -532,21 +581,22 @@ void GetTemplateTokenString(WCTemplateToken *Tokens,
  * \brief Print the value of a variable
  * \param keyname get a key to print
  */
-void print_value_of(StrBuf *Target, WCTemplateToken *Tokens, void *Context, int ContextType) {
+void print_value_of(StrBuf *Target, WCTemplputParams *TP)
+{
        wcsession *WCC = WC;
        wcsubst *ptr;
        void *vVar;
 
        /*if (WCC->vars != NULL) PrintHash(WCC->vars, VarPrintTransition, VarPrintEntry);*/
        /* TODO: depricated! */
-       if (Tokens->pName[0] == '=') {
-               DoTemplate(Tokens->pName+1, Tokens->NameEnd - 1, NULL, NULL, 0);
+       if (TP->Tokens->pName[0] == '=') {
+               DoTemplate(TP->Tokens->pName+1, TP->Tokens->NameEnd - 1, NULL, &NoCtx);
        }
-
 /*/////TODO: if param[1] == "U" -> urlescape
 /// X -> escputs */
        /** Page-local variables */
-       if ((WCC->vars!= NULL) && GetHash(WCC->vars, Tokens->pName, Tokens->NameEnd, &vVar)) {
+       if ((WCC->vars!= NULL) && GetHash(WCC->vars, TP->Tokens->pName, TP->Tokens->NameEnd, &vVar)) {
                ptr = (wcsubst*) vVar;
                switch(ptr->wcs_type) {
                case WCS_STRING:
@@ -556,7 +606,7 @@ void print_value_of(StrBuf *Target, WCTemplateToken *Tokens, void *Context, int
                        pvo_do_cmd(Target, ptr->wcs_value);
                        break;
                case WCS_FUNCTION:
-                       (*ptr->wcs_function) (Target, Tokens->nParameters, Tokens, Context, ContextType);
+                       (*ptr->wcs_function) (Target, TP);
                        break;
                case WCS_STRBUF:
                case WCS_STRBUF_REF:
@@ -566,17 +616,15 @@ void print_value_of(StrBuf *Target, WCTemplateToken *Tokens, void *Context, int
                        StrBufAppendPrintf(Target, "%ld", ptr->lvalue);
                        break;
                default:
-                       lprintf(1,"WARNING: invalid value in SV-Hash at %s!\n", Tokens->pName);
-                       StrBufAppendPrintf(Target, "<pre>WARNING: \ninvalid value in SV-Hash at %s!\n</pre>", Tokens->pName);
+                       LogTemplateError(
+                                Target, "Subst", ERR_NAME, TP,
+                               "WARNING: invalid value in SV-Hash at %s!", TP->Tokens->pName);
                }
        }
        else {
-               lprintf(1, "didn't find Handler [%s] (in '%s' line %ld); "
-                       " [%s]\n", 
-                       Tokens->pName,
-                       ChrPtr(Tokens->FileName),
-                       Tokens->Line,
-                       ChrPtr(Tokens->FlatToken));
+               LogTemplateError(
+                       Target, "Token", ERR_NAME, TP,
+                       "didn't find Handler");
                wc_backtrace();
        }
 }
@@ -657,19 +705,17 @@ int CompareSubstToStrBuf(StrBuf *Compare, TemplateParam *ParamToLookup)
  * \param FormatTypeIndex where should we look for escape types if?
  */
 void StrBufAppendTemplate(StrBuf *Target, 
-                         int nArgs, 
-                         WCTemplateToken *Tokens,
-                         void *Context, int ContextType,
+                         WCTemplputParams *TP,
                          const StrBuf *Source, int FormatTypeIndex)
 {
         wcsession *WCC;
        StrBuf *Buf;
        char EscapeAs = ' ';
 
-       if ((FormatTypeIndex < Tokens->nParameters) &&
-           (Tokens->Params[FormatTypeIndex]->Type == TYPE_STR) &&
-           (Tokens->Params[FormatTypeIndex]->len == 1)) {
-               EscapeAs = *Tokens->Params[FormatTypeIndex]->Start;
+       if ((FormatTypeIndex < TP->Tokens->nParameters) &&
+           (TP->Tokens->Params[FormatTypeIndex]->Type == TYPE_STR) &&
+           (TP->Tokens->Params[FormatTypeIndex]->len == 1)) {
+               EscapeAs = *TP->Tokens->Params[FormatTypeIndex]->Start;
        }
 
        switch(EscapeAs)
@@ -809,12 +855,14 @@ TemplateParam *GetNextParameter(StrBuf *Buf, const char **pCh, const char *pe, W
                }
                else {
                        Parm->lvalue = 0;
+/* TODO whUT?
                        lprintf(1, "Error (in '%s' line %ld); "
                                "evaluating long template param [%s] in Token [%s]\n",
                                ChrPtr(pTmpl->FileName),
                                Tokens->Line,
                                ChrPtr(Tokens->FlatToken),
                                *pCh);
+                               */
                        free(Parm);
                        return NULL;
                }
@@ -840,7 +888,9 @@ WCTemplateToken *NewTemplateSubstitute(StrBuf *Buf,
        const char *pch;
        TemplateParam *Param;
        WCTemplateToken *NewToken = (WCTemplateToken*)malloc(sizeof(WCTemplateToken));
+       WCTemplputParams TP;
 
+       TP.Tokens = NewToken;
        NewToken->FileName = pTmpl->FileName; /* to print meaningfull log messages... */
        NewToken->Flags = 0;
        NewToken->Line = Line + 1;
@@ -865,23 +915,20 @@ WCTemplateToken *NewTemplateSubstitute(StrBuf *Buf,
                        NewToken->NameEnd = pch - NewToken->pName;
                        pch ++;
                        if (*(pTmplEnd - 1) != ')') {
-                               lprintf(1, "Warning, Non welformed Token; missing right parenthesis (in '%s' line %ld); "
-                                       "[%s]\n", 
-                                       ChrPtr(pTmpl->FileName),
-                                       NewToken->Line,
-                                       ChrPtr(NewToken->FlatToken));
+                               LogTemplateError(
+                                       NULL, "Parseerror", ERR_NAME, &TP, 
+                                       "Warning, Non welformed Token; missing right parenthesis");
                        }
                        while (pch < pTmplEnd - 1) {
                                Param = GetNextParameter(Buf, &pch, pTmplEnd - 1, NewToken, pTmpl);
                                if (Param != NULL) {
                                        NewToken->HaveParameters = 1;
                                        if (NewToken->nParameters > MAXPARAM) {
-                                               lprintf(1, "Error (in '%s' line %ld); "
-                                                       "only [%ld] Params allowed in Tokens [%s]\n",
-                                                       ChrPtr(pTmpl->FileName),
-                                                       NewToken->Line,
-                                                       MAXPARAM,
-                                                       ChrPtr(NewToken->FlatToken));
+                                               LogTemplateError(
+                                                       NULL, "Parseerror", ERR_NAME, &TP,
+                                                       "only [%ld] Params allowed in Tokens",
+                                                       MAXPARAM);
+
                                                free(Param);
                                                FreeToken(&NewToken);
                                                return NULL;
@@ -917,13 +964,11 @@ WCTemplateToken *NewTemplateSubstitute(StrBuf *Buf,
                        Handler = (HashHandler*) vVar;
                        if ((NewToken->nParameters < Handler->nMinArgs) || 
                            (NewToken->nParameters > Handler->nMaxArgs)) {
-                               lprintf(1, "Handler [%s] (in '%s' line %ld); "
-                                       "doesn't work with %ld params [%s]\n", 
-                                       NewToken->pName,
-                                       ChrPtr(pTmpl->FileName),
-                                       NewToken->Line,
-                                       NewToken->nParameters, 
-                                       ChrPtr(NewToken->FlatToken));
+                               LogTemplateError(
+                                       NULL, "Token", ERR_NAME, &TP,
+                                       "doesn't work with %ld params", 
+                                       NewToken->nParameters);
+
                        }
                        else {
                                NewToken->PreEval = Handler;
@@ -933,24 +978,20 @@ WCTemplateToken *NewTemplateSubstitute(StrBuf *Buf,
                break;
        case SV_GETTEXT:
                if (NewToken->nParameters !=1) {
-                       lprintf(1, "Gettext (in '%s' line %ld); "
-                               "requires exactly 1 parameter, you gave %ld params [%s]\n", 
-                               ChrPtr(pTmpl->FileName),
-                               NewToken->Line,
-                               NewToken->nParameters, 
-                               ChrPtr(NewToken->FlatToken));
+                       LogTemplateError(                               
+                               NULL, "Gettext", ERR_NAME, &TP,
+                               "requires exactly 1 parameter, you gave %ld params", 
+                               NewToken->nParameters);
                        NewToken->Flags = 0;
                        break;
                }
                break;
        case SV_SUBTEMPL:
                if (NewToken->nParameters != 1) {
-                       lprintf(1, "Subtemplates (in '%s' line %ld); "
-                               "require exactly 1 parameter, you gave %ld params [%s]\n", 
-                               ChrPtr(pTmpl->FileName),
-                               NewToken->Line,
-                               NewToken->nParameters, 
-                               ChrPtr(NewToken->FlatToken));
+                       LogTemplateError(
+                               NULL, "Subtemplates", ERR_NAME, &TP,
+                               "require exactly 1 parameter, you gave %ld params", 
+                               NewToken->nParameters);
                        break;
                }
                break;
@@ -958,21 +999,17 @@ WCTemplateToken *NewTemplateSubstitute(StrBuf *Buf,
        case SV_CONDITIONAL:
        case SV_NEG_CONDITIONAL:
                if (NewToken->nParameters <2) {
-                       lprintf(1, "Conditional (in '%s' line %ld); "
-                               "require at least 2 parameters, you gave %ld params [%s]\n", 
-                               ChrPtr(pTmpl->FileName),
-                               NewToken->Line,
-                               NewToken->nParameters, 
-                               ChrPtr(NewToken->FlatToken));
+                       LogTemplateError(
+                               NULL, "Conditional", ERR_NAME, &TP,
+                               "require at least 2 parameters, you gave %ld params", 
+                               NewToken->nParameters);
                        NewToken->Flags = 0;
                        break;
                }
                if (NewToken->Params[1]->lvalue == 0) {
-                       lprintf(1, "Conditional (in '%s' line %ld); "
-                               "Conditional ID mustn't be 0! [%s]\n", 
-                               ChrPtr(pTmpl->FileName),
-                               NewToken->Line,
-                               ChrPtr(NewToken->FlatToken));
+                       LogTemplateError(
+                               NULL, "Conditional", ERR_NAME, &TP,
+                               "Conditional ID (Parameter 1) mustn't be 0!");
                        NewToken->Flags = 0;
                        break;
                }
@@ -984,11 +1021,9 @@ WCTemplateToken *NewTemplateSubstitute(StrBuf *Buf,
                        if ((NewToken->Params[0]->len == 1) &&
                            (NewToken->Params[0]->Start[0] == 'X'))
                                break;
-                       lprintf(1, "Conditional [%s] (in '%s' line %ld); Not found![%s]\n", 
-                               NewToken->Params[0]->Start,
-                               ChrPtr(pTmpl->FileName),
-                               NewToken->Line,
-                               ChrPtr(NewToken->FlatToken));
+                       LogTemplateError(
+                               NULL, "Conditional", ERR_NAME, &TP,
+                               "Not found!");
 /*
                        NewToken->Error = NewStrBuf();
                        StrBufAppendPrintf(
@@ -1207,7 +1242,7 @@ void InitTemplateCache(void)
  * \param state are we in conditional state?
  * \param ContextType what type of information does context giv us?
  */
-int EvaluateToken(StrBuf *Target, WCTemplateToken *Tokens, WCTemplate *pTmpl, void *Context, int state, int ContextType)
+int EvaluateToken(StrBuf *Target, int state, WCTemplputParams *TP)
 {
        const char *AppendMe;
        long AppendMeLen;
@@ -1217,27 +1252,27 @@ int EvaluateToken(StrBuf *Target, WCTemplateToken *Tokens, WCTemplate *pTmpl, vo
        lprintf(1,"Doing token: %s\n",Token->pName);
 */
 
-       switch (Tokens->Flags) {
+       switch (TP->Tokens->Flags) {
        case SV_GETTEXT:
-               TmplGettext(Target, Tokens->nParameters, Tokens);
+               TmplGettext(Target, TP);
                break;
        case SV_CONDITIONAL: /** Forward conditional evaluation */
-               return EvaluateConditional(Target, Tokens, pTmpl, Context, 1, state, ContextType);
+               return EvaluateConditional(Target, 1, state, TP);
                break;
        case SV_NEG_CONDITIONAL: /** Reverse conditional evaluation */
-               return EvaluateConditional(Target, Tokens, pTmpl, Context, 0, state, ContextType);
+               return EvaluateConditional(Target, 0, state, TP);
                break;
        case SV_CUST_STR_CONDITIONAL: /** Conditional put custom strings from params */
-               if (Tokens->nParameters >= 6) {
-                       if (EvaluateConditional(Target, Tokens, pTmpl, Context, 0, state, ContextType)) {
-                               GetTemplateTokenString(Tokens, 5, &AppendMe, &AppendMeLen);
+               if (TP->Tokens->nParameters >= 6) {
+                       if (EvaluateConditional(Target, 0, state, TP)) {
+                               GetTemplateTokenString(TP, 5, &AppendMe, &AppendMeLen);
                                StrBufAppendBufPlain(Target, 
                                                     AppendMe, 
                                                     AppendMeLen,
                                                     0);
                        }
                        else{
-                               GetTemplateTokenString(Tokens, 4, &AppendMe, &AppendMeLen);
+                               GetTemplateTokenString(TP, 4, &AppendMe, &AppendMeLen);
                                StrBufAppendBufPlain(Target, 
                                                     AppendMe, 
                                                     AppendMeLen,
@@ -1245,110 +1280,56 @@ int EvaluateToken(StrBuf *Target, WCTemplateToken *Tokens, WCTemplate *pTmpl, vo
                        }
                }
                else  {
-                       lprintf(1, "Conditional [%s] (in '%s' line %ld); needs at least 6 Params![%s]\n", 
-                               Tokens->Params[0]->Start,
-                               ChrPtr(pTmpl->FileName),
-                               Tokens->Line,
-                               ChrPtr(Tokens->FlatToken));
-                       StrBufAppendPrintf(
-                               Target, 
-                               "<pre>\nConditional [%s] (in '%s' line %ld); needs 6 Params!\n[%s]\n</pre>\n", 
-                               Tokens->Params[0]->Start,
-                               ChrPtr(pTmpl->FileName),
-                               Tokens->Line,
-                               ChrPtr(Tokens->FlatToken));
+                       LogTemplateError(
+                               Target, "Conditional", ERR_NAME, TP,
+                               "needs at least 6 Params!"); 
                }
                break;
        case SV_SUBTEMPL:
-               if (Tokens->nParameters == 1)
-                       DoTemplate(TKEY(0), NULL, NULL, ContextType);
+               if (TP->Tokens->nParameters == 1)
+                       DoTemplate(TKEY(0), NULL, TP);
                break;
        case SV_PREEVALUATED:
-               Handler = (HashHandler*) Tokens->PreEval;
+               Handler = (HashHandler*) TP->Tokens->PreEval;
                if ((Handler->ContextRequired != CTX_NONE) &&
-                   (Handler->ContextRequired != ContextType)) {
-                       lprintf(1, "Handler [%s] (in '%s' line %ld); "
-                               "requires context of type %ld, have %ld [%s]\n", 
-                               Tokens->pName,
-                               ChrPtr(pTmpl->FileName),
-                               Tokens->Line,
-                               Handler->ContextRequired, 
-                               ContextType,
-                               ChrPtr(Tokens->FlatToken));
-                       StrBufAppendPrintf(
-                               Target, 
-                               "<pre>\nHandler [%s] (in '%s' line %ld);"
-                               " requires context of type %ld, have %ld!\n[%s]\n</pre>\n", 
-                               Tokens->pName,
-                               ChrPtr(pTmpl->FileName),
-                               Tokens->Line,
+                   (Handler->ContextRequired != TP->ContextType)) {
+                       LogTemplateError(
+                               Target, "Token", ERR_NAME, TP,
+                               "requires context of type %ld, have %ld", 
                                Handler->ContextRequired, 
-                               ContextType,
-                               ChrPtr(Tokens->FlatToken));
+                               TP->ContextType);
                        return -1;
 
                }
-               Handler->HandlerFunc(Target, 
-                                    Tokens->nParameters,
-                                    Tokens,
-                                    Context, 
-                                    ContextType); 
+               Handler->HandlerFunc(Target, TP);
                break;          
        default:
-               if (GetHash(GlobalNS, Tokens->pName, Tokens->NameEnd, &vVar)) {
+               if (GetHash(GlobalNS, TP->Tokens->pName, TP->Tokens->NameEnd, &vVar)) {
                        Handler = (HashHandler*) vVar;
                        if ((Handler->ContextRequired != CTX_NONE) &&
-                           (Handler->ContextRequired != ContextType)) {
-                               lprintf(1, "Handler [%s] (in '%s' line %ld); "
-                                       "requires context of type %ld, have %ld [%s]\n", 
-                                       Tokens->pName,
-                                       ChrPtr(pTmpl->FileName),
-                                       Tokens->Line,
-                                       Handler->ContextRequired, 
-                                       ContextType,
-                                       ChrPtr(Tokens->FlatToken));
-                               StrBufAppendPrintf(
-                                       Target, 
-                                       "<pre>\nHandler [%s] (in '%s' line %ld);"
-                                       " requires context of type %ld, have %ld!\n[%s]\n</pre>\n", 
-                                       Tokens->pName,
-                                       ChrPtr(pTmpl->FileName),
-                                       Tokens->Line,
+                           (Handler->ContextRequired != TP->ContextType)) {
+                               LogTemplateError(
+                                       Target, "Token", ERR_NAME, TP,
+                                       "requires context of type %ld, have %ld",
                                        Handler->ContextRequired, 
-                                       ContextType,
-                                       ChrPtr(Tokens->FlatToken));
+                                       TP->ContextType);
                                return -1;
                        }
-                       else if ((Tokens->nParameters < Handler->nMinArgs) || 
-                                (Tokens->nParameters > Handler->nMaxArgs)) {
-                               lprintf(1, "Handler [%s] (in '%s' line %ld); "
-                                       "doesn't work with %ld params [%s]\n", 
-                                       Tokens->pName,
-                                       ChrPtr(pTmpl->FileName),
-                                       Tokens->Line,
-                                       Tokens->nParameters, 
-                                       ChrPtr(Tokens->FlatToken));
-                               StrBufAppendPrintf(
-                                       Target, 
-                                       "<pre>\nHandler [%s] (in '%s' line %ld);"
-                                       " doesn't work with %ld params!\n[%s]\n</pre>\n", 
-                                       Tokens->pName,
-                                       ChrPtr(pTmpl->FileName),
-                                       Tokens->Line,
-                                       Tokens->nParameters,
-                                       ChrPtr(Tokens->FlatToken));
+                       else if ((TP->Tokens->nParameters < Handler->nMinArgs) || 
+                                (TP->Tokens->nParameters > Handler->nMaxArgs)) {
+                               LogTemplateError(
+                                       Target, "Token", ERR_NAME, TP,
+                                       "doesn't work with %ld params need  > %ld  < %ld", 
+                                       TP->Tokens->nParameters, 
+                                       Handler->nMaxArgs,
+                                       Handler->nMinArgs);
                        }
                        else {
-                               Handler->HandlerFunc(Target, 
-                                                    Tokens->nParameters,
-                                                    Tokens,
-                                                    Context, 
-                                                    ContextType); /*TODO: subset of that */
-                               
+                               Handler->HandlerFunc(Target, TP);
                        }
                }
                else {
-                       print_value_of(Target, Tokens, Context, ContextType);
+                       print_value_of(Target, TP);
                }
        }
        return 0;
@@ -1363,6 +1344,10 @@ void ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, void *Context, int Contex
        int i, state;
        const char *pData, *pS;
        long len;
+       WCTemplputParams TP;
+
+       TP.Context = Context;
+       TP.ContextType = ContextType;
 
        if (LoadTemplates != 0) {                       
                if (LoadTemplates > 1)
@@ -1395,20 +1380,22 @@ void ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, void *Context, int Contex
                        StrBufAppendBufPlain(
                                Target, pData, 
                                pTmpl->Tokens[i]->pTokenStart - pData, 0);
-                       state = EvaluateToken(Target, pTmpl->Tokens[i], pTmpl, Context, state, ContextType);
+                       TP.Tokens = pTmpl->Tokens[i];
+                       TP.nArgs = pTmpl->Tokens[i]->nParameters;
+                       state = EvaluateToken(Target, state, &TP);
+
                        while ((state != 0) && (i+1 < pTmpl->nTokensUsed)) {
                        /* condition told us to skip till its end condition */
                                i++;
+                               TP.Tokens = pTmpl->Tokens[i];
+                               TP.nArgs = pTmpl->Tokens[i]->nParameters;
                                if ((pTmpl->Tokens[i]->Flags == SV_CONDITIONAL) ||
                                    (pTmpl->Tokens[i]->Flags == SV_NEG_CONDITIONAL)) {
                                        if (state == EvaluateConditional(
-                                                   Target,
-                                                   pTmpl->Tokens[i], 
-                                                   pTmpl,
-                                                   Context, 
-                                                   pTmpl->Tokens[i]->Flags,
+                                                   Target, 
+                                                   pTmpl->Tokens[i]->Flags, 
                                                    state, 
-                                                   ContextType))
+                                                   &TP))
                                                state = 0;
                                }
                        }
@@ -1426,7 +1413,7 @@ void ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, void *Context, int Contex
  * \brief Display a variable-substituted template
  * \param templatename template file to load
  */
-void DoTemplate(const char *templatename, long len, StrBuf *Target, void *Context, int ContextType
+void DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputParams *TP
 {
        HashList *Static;
        HashList *StaticLocal;
@@ -1464,7 +1451,7 @@ void DoTemplate(const char *templatename, long len, StrBuf *Target, void *Contex
        }
        if (vTmpl == NULL) 
                return;
-       ProcessTemplate(vTmpl, Target, Context, ContextType);
+       ProcessTemplate(vTmpl, Target, TP->Context, TP->ContextType);
 }
 
 /*-----------------------------------------------------------------------------
@@ -1503,13 +1490,13 @@ void RegisterITERATOR(const char *Name, long len,
        Put(Iterators, Name, len, It, NULL);
 }
 
-void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmpl_iterate_subtmpl(StrBuf *Target, WCTemplputParams *TP)
 {
        void *vIt;
        HashIterator *It;
        HashList *List;
        HashPos  *it;
-       SortStruct *SortBy;
+       SortStruct *SortBy = NULL;
        void *vSortBy;
        int DetectGroupChange = 0;
        int nMembersUsed;
@@ -1517,76 +1504,42 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo
        long len; 
        const char *Key;
        void *vContext;
-       void *vLastContext;
+       void *vLastContext = NULL;
        StrBuf *SubBuf;
        int oddeven = 0;
+       WCTemplputParams SubTP;
+
+       memcpy (&SubTP, &TP, sizeof(WCTemplputParams));
        
        if (!GetHash(Iterators, TKEY(0), &vIt)) {
-               lprintf(1, "unknown Iterator [%s] (in '%s' line %ld); "
-                       " [%s]\n", 
-                       Tokens->Params[0]->Start,
-                       ChrPtr(Tokens->FileName),
-                       Tokens->Line,
-                       ChrPtr(Tokens->FlatToken));
-               StrBufAppendPrintf(
-                       Target,
-                       "<pre>\nunknown Iterator [%s] (in '%s' line %ld); \n"
-                       " [%s]\n</pre>", 
-                       Tokens->Params[0]->Start,
-                       ChrPtr(Tokens->FileName),
-                       Tokens->Line,
-                       ChrPtr(Tokens->FlatToken));
+               LogTemplateError(
+                       Target, "Iterator", ERR_PARM1, TP, "Unknown!");
                return;
        }
 
        It = (HashIterator*) vIt;
 
-       if (Tokens->nParameters < It->AdditionalParams + 2) {
-               lprintf(1, "Iterator [%s] (in '%s' line %ld); "
-                       "doesn't work with %ld params [%s]\n", 
-                       Tokens->Params[0]->Start,
-                       ChrPtr(Tokens->FileName),
-                       Tokens->Line,
-                       Tokens->nParameters, 
-                       ChrPtr(Tokens->FlatToken));
-               StrBufAppendPrintf(
-                       Target,
-                       "<pre>Iterator [%s] \n(in '%s' line %ld);\n"
-                       "doesn't work with %ld params \n[%s]\n</pre>", 
-                       Tokens->Params[0]->Start,
-                       ChrPtr(Tokens->FileName),
-                       Tokens->Line,
-                       Tokens->nParameters, 
-                       ChrPtr(Tokens->FlatToken));
+       if (TP->Tokens->nParameters < It->AdditionalParams + 2) {
+               LogTemplateError(                               
+                       Target, "Iterator", ERR_PARM1, TP,
+                       "doesn't work with %ld params", 
+                       TP->Tokens->nParameters);
                return;
        }
 
        if ((It->XPectContextType != CTX_NONE) &&
-           (It->XPectContextType != ContextType)) {
-               lprintf(1, "Iterator [%s] (in '%s' line %ld); "
-                       "requires context of type %ld, have %ld [%s]\n", 
-                       Tokens->pName,
-                       ChrPtr(Tokens->FileName),
-                       Tokens->Line,
-                       It->XPectContextType, 
-                       ContextType,
-                       ChrPtr(Tokens->FlatToken));
-               StrBufAppendPrintf(
-                       Target, 
-                       "<pre>\nIterator [%s] (in '%s' line %ld);"
-                       " requires context of type %ld, have %ld!\n[%s]\n</pre>\n", 
-                       Tokens->pName,
-                       ChrPtr(Tokens->FileName),
-                       Tokens->Line,
+           (It->XPectContextType != TP->ContextType)) {
+               LogTemplateError(
+                       Target, "Iterator", ERR_PARM1, TP,
+                       "requires context of type %ld, have %ld", 
                        It->XPectContextType, 
-                       ContextType,
-                       ChrPtr(Tokens->FlatToken));
+                       TP->ContextType);
                return ;
                
        }
 
        if (It->StaticList == NULL)
-               List = It->GetHash(Target, nArgs, Tokens, Context, ContextType);
+               List = It->GetHash(Target, TP);
        else
                List = It->StaticList;
 
@@ -1611,6 +1564,7 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo
        }
        nMembersUsed = GetCount(List);
        SubBuf = NewStrBuf();
+       SubTP.ContextType = It->ContextType;
        it = GetNewHashPos(List, 0);
        while (GetNextHashPos(List, it, &len, &Key, &vContext)) {
                if (DetectGroupChange && nMembersCounted > 0) {
@@ -1624,10 +1578,10 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo
                svprintf(HKEY("ITERATE:KEY"), WCS_STRING, "%s", Key);
                svputlong("ITERATE:N", nMembersCounted);
                svputlong("ITERATE:LASTN", ++nMembersCounted == nMembersUsed);
-
+               SubTP.Context = vContext;
                if (It->DoSubTemplate != NULL)
-                       It->DoSubTemplate(SubBuf, vContext, Tokens);
-               DoTemplate(TKEY(1), SubBuf, vContext, It->ContextType);
+                       It->DoSubTemplate(SubBuf, &SubTP);
+               DoTemplate(TKEY(1), SubBuf, &SubTP);
                        
                StrBufAppendBuf(Target, SubBuf, 0);
                FlushStrBuf(SubBuf);
@@ -1645,47 +1599,36 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo
 /*-----------------------------------------------------------------------------
  *                      Conditionals
  */
-int EvaluateConditional(StrBuf *Target, WCTemplateToken *Tokens, WCTemplate *pTmpl, void *Context, int Neg, int state, int ContextType)
+int EvaluateConditional(StrBuf *Target, int Neg, int state, WCTemplputParams *TP)
 {
        ConditionalStruct *Cond;
 
-       if ((Tokens->Params[0]->len == 1) &&
-           (Tokens->Params[0]->Start[0] == 'X'))
-               return (state != 0)?Tokens->Params[1]->lvalue:0;
+       if ((TP->Tokens->Params[0]->len == 1) &&
+           (TP->Tokens->Params[0]->Start[0] == 'X'))
+               return (state != 0)?TP->Tokens->Params[1]->lvalue:0;
            
-       Cond = (ConditionalStruct *) Tokens->PreEval;
+       Cond = (ConditionalStruct *) TP->Tokens->PreEval;
        if (Cond == NULL) {
-               lprintf(1, "Conditional [%s] (in '%s' line %ld); unknown![%s]\n", 
-                       Tokens->Params[0]->Start,
-                       ChrPtr(pTmpl->FileName),
-                       Tokens->Line,
-                       ChrPtr(Tokens->FlatToken));
+               LogTemplateError(
+                       Target, "Conditional", ERR_PARM1, TP,
+                       "unknown!");
                return 1;
        }
 
-       if (Tokens->nParameters < Cond->nParams) {
-               lprintf(1, "Conditional [%s] (in '%s' line %ld); needs %ld Params![%s]\n", 
-                       Tokens->Params[0]->Start,
-                       ChrPtr(pTmpl->FileName),
-                       Tokens->Line,
-                       Cond->nParams,
-                       ChrPtr(Tokens->FlatToken));
-               StrBufAppendPrintf(
-                       Target, 
-                       "<pre>\nConditional [%s] (in '%s' line %ld); needs %ld Params!\n[%s]\n</pre>\n", 
-                       Tokens->Params[0]->Start,
-                       ChrPtr(pTmpl->FileName),
-                       Tokens->Line,
+       if (TP->Tokens->nParameters < Cond->nParams) {
+               LogTemplateError(                               
+                       Target, "Conditional", ERR_PARM1, TP,
+                       "needs %ld Params, have %ld!", 
                        Cond->nParams,
-                       ChrPtr(Tokens->FlatToken));
+                       TP->Tokens->nParameters);
                return 0;
        }
-       if (Cond->CondF(Tokens, Context, ContextType) == Neg)
-               return Tokens->Params[1]->lvalue;
+       if (Cond->CondF(Target, TP) == Neg)
+               return TP->Tokens->Params[1]->lvalue;
        return 0;
 }
 
-int ConditionalVar(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalVar(StrBuf *Target, WCTemplputParams *TP)
 {
        void *vsubst;
        wcsubst *subst;
@@ -1694,8 +1637,11 @@ int ConditionalVar(WCTemplateToken *Tokens, void *Context, int ContextType)
                return 0;
        subst = (wcsubst*) vsubst;
        if ((subst->ContextRequired != CTX_NONE) &&
-           (subst->ContextRequired != ContextType)) {
-               lprintf(1,"  WARNING: Conditional requires Context: [%ld]!\n", Tokens->Params[2]->Start);
+           (subst->ContextRequired != TP->ContextType)) {
+                LogTemplateError(
+                        Target, "ConditionalVar", ERR_PARM1, TP,
+                       "  WARNING: Conditional requires Context: [%ld], have [%ld]!", 
+                       subst->ContextRequired, CTX);
                return -1;
        }
 
@@ -1708,13 +1654,13 @@ int ConditionalVar(WCTemplateToken *Tokens, void *Context, int ContextType)
        case WCS_STRING:
        case WCS_STRBUF:
        case WCS_STRBUF_REF:
-               if (Tokens->nParameters < 4)
+               if (TP->Tokens->nParameters < 4)
                        return 1;
-               return (strcmp(Tokens->Params[3]->Start, ChrPtr(subst->wcs_value)) == 0);
+               return (strcmp(TP->Tokens->Params[3]->Start, ChrPtr(subst->wcs_value)) == 0);
        case WCS_LONG:
-               if (Tokens->nParameters < 4)
+               if (TP->Tokens->nParameters < 4)
                        return (subst->lvalue != 0);
-               return (subst->lvalue == Tokens->Params[3]->lvalue);
+               return (subst->lvalue == TP->Tokens->Params[3]->lvalue);
        default:
                lprintf(1,"  WARNING: invalid type: [%ld]!\n", subst->wcs_type);
                return -1;
@@ -1739,17 +1685,17 @@ void RegisterConditional(const char *Name, long len,
 /*-----------------------------------------------------------------------------
  *                      Context Strings
  */
-void tmplput_ContextString(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_ContextString(StrBuf *Target, WCTemplputParams *TP)
 {
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, (StrBuf*)Context, 0);
+       StrBufAppendTemplate(Target, TP, (StrBuf*)CTX, 0);
 }
-int ConditionalContextStr(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalContextStr(StrBuf *Target, WCTemplputParams *TP)
 {
-       StrBuf *TokenText = (StrBuf*) Context;
+       StrBuf *TokenText = (StrBuf*) CTX;
        const char *CompareToken;
        long len;
 
-       GetTemplateTokenString(Tokens, 2, &CompareToken, &len);
+       GetTemplateTokenString(TP, 2, &CompareToken, &len);
        return strcmp(ChrPtr(TokenText), CompareToken) == 0;
 }
 
@@ -1757,28 +1703,32 @@ int ConditionalContextStr(WCTemplateToken *Tokens, void *Context, int ContextTyp
  *                      Boxed-API
  */
 
-void tmpl_do_boxed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmpl_do_boxed(StrBuf *Target, WCTemplputParams *TP)
 {
+       WCTemplputParams SubTP;
+
        StrBuf *Headline;
-       if (nArgs == 2) {
-               if (Tokens->Params[1]->Type == TYPE_STR) {
+       if (TP->Tokens->nParameters == 2) {
+               if (TP->Tokens->Params[1]->Type == TYPE_STR) {
                        Headline = NewStrBuf();
-                       DoTemplate(TKEY(1), Headline, Context, ContextType);
+                       DoTemplate(TKEY(1), Headline, TP);
                }
                else {
                        const char *Ch;
                        long len;
-                       GetTemplateTokenString(Tokens
+                       GetTemplateTokenString(TP
                                               1,
                                               &Ch,
                                               &len);
                        Headline = NewStrBufPlain(Ch, len);
                }
        }
-       
-       DoTemplate(HKEY("beginbox"), Target, Headline, CTX_STRBUF);
-       DoTemplate(TKEY(0), Target, Context, ContextType);
-       DoTemplate(HKEY("endbox"), Target, Context, ContextType);
+       memcpy (&SubTP, TP, sizeof(WCTemplputParams));
+       SubTP.Context = Headline;
+       SubTP.ContextType = CTX_STRBUF;
+       DoTemplate(HKEY("beginbox"), Target, &SubTP);
+       DoTemplate(TKEY(0), Target, TP);
+       DoTemplate(HKEY("endbox"), Target, TP);
        FreeStrBuf(&Headline);
 }
 
@@ -1786,24 +1736,24 @@ void tmpl_do_boxed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Con
  *                      Tabbed-API
  */
 
-void tmpl_do_tabbed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmpl_do_tabbed(StrBuf *Target, WCTemplputParams *TP)
 {
        StrBuf **TabNames;
        int i, ntabs, nTabs;
 
-       nTabs = ntabs = Tokens->nParameters / 2;
+       nTabs = ntabs = TP->Tokens->nParameters / 2;
        TabNames = (StrBuf **) malloc(ntabs * sizeof(StrBuf*));
 
        for (i = 0; i < ntabs; i++) {
-               if ((Tokens->Params[i * 2]->Type == TYPE_STR) &&
-                   (Tokens->Params[i * 2]->len > 0)) {
+               if ((TP->Tokens->Params[i * 2]->Type == TYPE_STR) &&
+                   (TP->Tokens->Params[i * 2]->len > 0)) {
                        TabNames[i] = NewStrBuf();
-                       DoTemplate(TKEY(i * 2), TabNames[i], Context, ContextType);
+                       DoTemplate(TKEY(i * 2), TabNames[i], TP);
                }
-               else if (Tokens->Params[i * 2]->Type == TYPE_GETTEXT) {
+               else if (TP->Tokens->Params[i * 2]->Type == TYPE_GETTEXT) {
                        const char *Ch;
                        long len;
-                       GetTemplateTokenString(Tokens
+                       GetTemplateTokenString(TP
                                               i * 2,
                                               &Ch,
                                               &len);
@@ -1818,7 +1768,7 @@ void tmpl_do_tabbed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Co
        StrTabbedDialog(Target, nTabs, TabNames);
        for (i = 0; i < ntabs; i++) {
                StrBeginTab(Target, i, nTabs);
-               DoTemplate(TKEY(i * 2 + 1), Target, Context, ContextType);
+               DoTemplate(TKEY(i * 2 + 1), Target, TP);
                StrEndTab(Target, i, nTabs);
        }
 }
@@ -1849,11 +1799,11 @@ void RegisterSortFunc(const char *name, long len,
        Put(SortHash, name, len, NewSort, DestroySortStruct);
 }
 
-CompareFunc RetrieveSort(long ContextType, const char *OtherPrefix, 
+CompareFunc RetrieveSort(WCTemplputParams *TP, const char *OtherPrefix, 
                         const char *Default, long ldefault, long DefaultDirection)
 {
        int isdefault = 0;
-       const StrBuf *BSort;
+       const StrBuf *BSort = NULL;
        SortStruct *SortBy;
        void *vSortBy;
        long SortOrder = -1;
@@ -1883,7 +1833,9 @@ CompareFunc RetrieveSort(long ContextType, const char *OtherPrefix,
                isdefault = 1;
                if (!GetHash(SortHash, Default, ldefault, &vSortBy) || 
                    (vSortBy == NULL)) {
-                       lprintf(1, "Illegal default sort: [%s]\n", Default);
+                       LogTemplateError(
+                               NULL, "Sorting", ERR_PARM1, TP,
+                               "Illegal default sort: [%s]", Default);
                        wc_backtrace();
                }
        }
@@ -1894,7 +1846,7 @@ CompareFunc RetrieveSort(long ContextType, const char *OtherPrefix,
                SortOrder = LBSTR("SortOrder");
        }
        else { /** Try to fallback to our remembered values... */
-               StrBuf *Buf;
+               StrBuf *Buf = NULL;
                if (SortBy->PrefPrepend == NULL) {
                        Buf = get_room_pref("SortOrder");
                        SortOrder = StrTol(Buf);
@@ -1942,7 +1894,7 @@ ConstStr SortNextOrder[] = {
 };
 
 
-int GetSortMetric(WCTemplateToken *Tokens, SortStruct **Next, SortStruct **Param, long *SortOrder)
+int GetSortMetric(WCTemplputParams *TP, SortStruct **Next, SortStruct **Param, long *SortOrder)
 {
        int bSortError = eNOT_SPECIFIED;
        const StrBuf *BSort;
@@ -1965,7 +1917,7 @@ int GetSortMetric(WCTemplateToken *Tokens, SortStruct **Next, SortStruct **Param
                        BSort = get_room_pref("sort");
                }
                else {
-                       /* TODO: nail prefprepend to sort, and lookup this! */
+                       BSort = NULL;/* TODO: nail prefprepend to sort, and lookup this! */
                }
        }
 
@@ -1984,7 +1936,7 @@ int GetSortMetric(WCTemplateToken *Tokens, SortStruct **Next, SortStruct **Param
                        *SortOrder = StrTol(get_room_pref("SortOrder"));
                }
                else {
-                       /* TODO: nail prefprepend to sort, and lookup this! */
+                       *SortOrder = 0;/* TODO: nail prefprepend to sort, and lookup this! */
                }
        }
        if (*SortOrder > 2)
@@ -1994,40 +1946,24 @@ int GetSortMetric(WCTemplateToken *Tokens, SortStruct **Next, SortStruct **Param
 }
 
 
-void tmplput_SORT_ICON(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_SORT_ICON(StrBuf *Target, WCTemplputParams *TP)
 {
        long SortOrder;
        SortStruct *Next;
        SortStruct *Param;
        const ConstStr *SortIcon;
 
-       switch (GetSortMetric(Tokens, &Next, &Param, &SortOrder)){
+       switch (GetSortMetric(TP, &Next, &Param, &SortOrder)){
        case eNO_SUCH_SORT:
-               lprintf(1, "[%s] (in '%s' line %ld); "
-                       " Sorter [%s] unknown! [%s]\n", 
-                       Tokens->pName,
-                       ChrPtr(Tokens->FileName),
-                       Tokens->Line,
-                       Tokens->Params[0]->Start,
-                       ChrPtr(Tokens->FlatToken));
-               StrBufAppendPrintf(
-                       Target, 
-                       "<pre>\n [%s] (in '%s' line %ld);"
-                       " Sorter [%s] unknown!\n[%s]\n</pre>\n", 
-                       Tokens->pName,
-                       ChrPtr(Tokens->FileName),
-                       Tokens->Line,
-                       Tokens->Params[0]->Start,
-                       ChrPtr(Tokens->FlatToken));
+                LogTemplateError(
+                        Target, "Sorter", ERR_PARM1, TP,
+                       " Sorter [%s] unknown!", 
+                       TP->Tokens->Params[0]->Start);
                break;          
        case eINVALID_PARAM:
-               lprintf(1, "[%s] (in '%s' line %ld); "
-                       " Sorter specified by BSTR 'SortBy' [%s] unknown! [%s]\n", 
-                       Tokens->pName,
-                       ChrPtr(Tokens->FileName),
-                       Tokens->Line,
-                       bstr("SortBy"),
-                       ChrPtr(Tokens->FlatToken));
+                LogTemplateError(NULL, "Sorter", ERR_PARM1, TP,
+                                " Sorter specified by BSTR 'SortBy' [%s] unknown!", 
+                                bstr("SortBy"));
        case eNOT_SPECIFIED:
        case eFOUND:
                if (Next == Param) {
@@ -2040,40 +1976,24 @@ void tmplput_SORT_ICON(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void
        }
 }
 
-void tmplput_SORT_NEXT(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_SORT_NEXT(StrBuf *Target, WCTemplputParams *TP)
 {
        long SortOrder;
        SortStruct *Next;
        SortStruct *Param;
 
-       switch (GetSortMetric(Tokens, &Next, &Param, &SortOrder)){
+       switch (GetSortMetric(TP, &Next, &Param, &SortOrder)){
        case eNO_SUCH_SORT:
-               lprintf(1, "[%s] (in '%s' line %ld); "
-                       " Sorter [%s] unknown! [%s]\n", 
-                       Tokens->pName,
-                       ChrPtr(Tokens->FileName),
-                       Tokens->Line,
-                       Tokens->Params[0]->Start,
-                       ChrPtr(Tokens->FlatToken));
-               StrBufAppendPrintf(
-                       Target, 
-                       "<pre>\n [%s] (in '%s' line %ld);"
-                       " Sorter [%s] unknown!\n[%s]\n</pre>\n", 
-                       Tokens->pName,
-                       ChrPtr(Tokens->FileName),
-                       Tokens->Line,
-                       Tokens->Params[0]->Start,
-                       ChrPtr(Tokens->FlatToken));
+                LogTemplateError(
+                        Target, "Sorter", ERR_PARM1, TP,                                  
+                       " Sorter [%s] unknown!", 
+                       TP->Tokens->Params[0]->Start);
                break;          
        case eINVALID_PARAM:
-               lprintf(1, "[%s] (in '%s' line %ld); "
-                       " Sorter specified by BSTR 'SortBy' [%s] unknown! [%s]\n", 
-                       Tokens->pName,
-                       ChrPtr(Tokens->FileName),
-                       Tokens->Line,
-                       bstr("SortBy"),
-                       ChrPtr(Tokens->FlatToken));
-
+                LogTemplateError(
+                        NULL, "Sorter", ERR_PARM1, TP,
+                       " Sorter specified by BSTR 'SortBy' [%s] unknown!", 
+                       bstr("SortBy"));
        case eNOT_SPECIFIED:
        case eFOUND:
                StrBufAppendBuf(Target, Param->Name, 0);
@@ -2081,41 +2001,25 @@ void tmplput_SORT_NEXT(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void
        }
 }
 
-void tmplput_SORT_ORDER(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_SORT_ORDER(StrBuf *Target, WCTemplputParams *TP)
 {
        long SortOrder;
        const ConstStr *SortOrderStr;
        SortStruct *Next;
        SortStruct *Param;
 
-       switch (GetSortMetric(Tokens, &Next, &Param, &SortOrder)){
+       switch (GetSortMetric(TP, &Next, &Param, &SortOrder)){
        case eNO_SUCH_SORT:
-               lprintf(1, "[%s] (in '%s' line %ld); "
-                       " Sorter [%s] unknown! [%s]\n", 
-                       Tokens->pName,
-                       ChrPtr(Tokens->FileName),
-                       Tokens->Line,
-                       Tokens->Params[0]->Start,
-                       ChrPtr(Tokens->FlatToken));
-               StrBufAppendPrintf(
-                       Target, 
-                       "<pre>\n [%s] (in '%s' line %ld);"
-                       " Sorter [%s] unknown!\n[%s]\n</pre>\n", 
-                       Tokens->pName,
-                       ChrPtr(Tokens->FileName),
-                       Tokens->Line,
-                       Tokens->Params[0]->Start,
-                       ChrPtr(Tokens->FlatToken));
+                LogTemplateError(
+                        Target, "Sorter", ERR_PARM1, TP,
+                        " Sorter [%s] unknown!",
+                        TP->Tokens->Params[0]->Start);
                break;          
        case eINVALID_PARAM:
-               lprintf(1, "[%s] (in '%s' line %ld); "
-                       " Sorter specified by BSTR 'SortBy' [%s] unknown! [%s]\n", 
-                       Tokens->pName,
-                       ChrPtr(Tokens->FileName),
-                       Tokens->Line,
-                       bstr("SortBy"),
-                       ChrPtr(Tokens->FlatToken));
-
+                LogTemplateError(
+                        NULL, "Sorter", ERR_PARM1, TP,
+                        " Sorter specified by BSTR 'SortBy' [%s] unknown!",
+                        bstr("SortBy"));
        case eNOT_SPECIFIED:
        case eFOUND:
                if (Next == Param) {
@@ -2129,50 +2033,28 @@ void tmplput_SORT_ORDER(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void
 }
 
 
-void tmplput_long_vector(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_long_vector(StrBuf *Target, WCTemplputParams *TP)
 {
-       long *LongVector = (long*) Context;
+       long *LongVector = (long*) CTX;
 
-       if ((Tokens->Params[0]->Type == TYPE_LONG) && 
-           (Tokens->Params[0]->lvalue <= LongVector[0]))
+       if ((TP->Tokens->Params[0]->Type == TYPE_LONG) && 
+           (TP->Tokens->Params[0]->lvalue <= LongVector[0]))
        {
-               StrBufAppendPrintf(Target, "%ld", LongVector[Tokens->Params[0]->lvalue]);
+               StrBufAppendPrintf(Target, "%ld", LongVector[TP->Tokens->Params[0]->lvalue]);
        }
        else
        {
-               if (Tokens->Params[0]->Type == TYPE_LONG) {
-                       lprintf(1, "longvector [%s] (in '%s' line %ld); needs a long Parameter![%s]\n", 
-                               Tokens->Params[0]->Start,
-                               ChrPtr(Tokens->FileName),
-                               Tokens->Line,
-                               ChrPtr(Tokens->FlatToken));
-                       StrBufAppendPrintf(
-                               Target, 
-                               "<pre>\nlongvector [%s] (in '%s' line %ld); needs a numerical Parameter!\n[%s]\n</pre>\n", 
-                               Tokens->Params[0]->Start,
-                               ChrPtr(Tokens->FileName),
-                               Tokens->Line,
-                               ChrPtr(Tokens->FlatToken));
+               if (TP->Tokens->Params[0]->Type != TYPE_LONG) {
+                       LogTemplateError(
+                               Target, "Longvector", ERR_NAME, TP,
+                               "needs a numerical Parameter!");
                }
                else {
-                       lprintf(1, "longvector [%s] (in '%s' line %ld); doesn't have %ld Parameters,"
-                               " its just the size of %ld![%s]\n", 
-                               Tokens->Params[0]->Start,
-                               ChrPtr(Tokens->FileName),
-                               Tokens->Line,
-                               Tokens->Params[0]->lvalue,
-                               LongVector[0],
-                               ChrPtr(Tokens->FlatToken));
-                       StrBufAppendPrintf(
-                               Target, 
-                               "<pre>\nlongvector [%s] (in '%s' line %ld); doesn't have %ld Parameters,"
-                               " its just the size of %ld!\n[%s]\n</pre>\n", 
-                               Tokens->Params[0]->Start,
-                               ChrPtr(Tokens->FileName),
-                               Tokens->Line,
-                               Tokens->Params[0]->lvalue,
-                               LongVector[0],
-                               ChrPtr(Tokens->FlatToken));             
+                       LogTemplateError(
+                               Target, "LongVector", ERR_PARM1, TP,
+                               "doesn't have %ld Parameters, its just the size of %ld!", 
+                               TP->Tokens->Params[0]->lvalue,
+                               LongVector[0]);
                }
        }
 }
@@ -2194,37 +2076,33 @@ void dbg_print_longvector(long *LongVector)
        FreeStrBuf(&Buf);
 }
 
-int ConditionalLongVector(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalLongVector(StrBuf *Target, WCTemplputParams *TP)
 {
-       long *LongVector = (long*) Context;
+       long *LongVector = (long*) CTX;
 
-       if ((Tokens->Params[2]->Type == TYPE_LONG) && 
-           (Tokens->Params[2]->lvalue <= LongVector[0])&&
-           (Tokens->Params[3]->Type == TYPE_LONG) && 
-           (Tokens->Params[3]->lvalue <= LongVector[0]))
+       if ((TP->Tokens->Params[2]->Type == TYPE_LONG) && 
+           (TP->Tokens->Params[2]->lvalue <= LongVector[0])&&
+           (TP->Tokens->Params[3]->Type == TYPE_LONG) && 
+           (TP->Tokens->Params[3]->lvalue <= LongVector[0]))
        {
-               return LongVector[Tokens->Params[2]->lvalue] == LongVector[Tokens->Params[3]->lvalue];
+               return LongVector[TP->Tokens->Params[2]->lvalue] == 
+                       LongVector[TP->Tokens->Params[3]->lvalue];
        }
        else
        {
-               if ((Tokens->Params[2]->Type == TYPE_LONG) ||
-                   (Tokens->Params[2]->Type == TYPE_LONG)) {
-                       lprintf(1, "ConditionalLongVector [%s] (in '%s' line %ld); needs two long Parameter![%s]\n", 
-                               Tokens->Params[0]->Start,
-                               ChrPtr(Tokens->FileName),
-                               Tokens->Line,
-                               ChrPtr(Tokens->FlatToken));
+               if ((TP->Tokens->Params[2]->Type == TYPE_LONG) ||
+                   (TP->Tokens->Params[2]->Type == TYPE_LONG)) {
+                       LogTemplateError(
+                               Target, "ConditionalLongvector", ERR_PARM1, TP,
+                               "needs two long Parameter!");
                }
                else {
-                       lprintf(1, "longvector [%s] (in '%s' line %ld); doesn't have %ld / %ld Parameters,"
-                               " its just the size of %ld![%s]\n", 
-                               Tokens->Params[0]->Start,
-                               ChrPtr(Tokens->FileName),
-                               Tokens->Line,
-                               Tokens->Params[2]->lvalue,
-                               Tokens->Params[3]->lvalue,
-                               LongVector[0],
-                               ChrPtr(Tokens->FlatToken));
+                       LogTemplateError(
+                               Target, "Longvector", ERR_PARM1, TP,
+                               "doesn't have %ld / %ld Parameters, its just the size of %ld!",
+                               TP->Tokens->Params[2]->lvalue,
+                               TP->Tokens->Params[3]->lvalue,
+                               LongVector[0]);
                }
        }
        return 0;
@@ -2234,6 +2112,7 @@ void
 InitModule_SUBST
 (void)
 {
+       memset(&NoCtx, 0, sizeof(WCTemplputParams));
        RegisterNamespace("SORT:ICON", 1, 1, tmplput_SORT_ICON, CTX_NONE);
        RegisterNamespace("SORT:ORDER", 1, 1, tmplput_SORT_ORDER, CTX_NONE);
        RegisterNamespace("SORT:NEXT", 1, 1, tmplput_SORT_NEXT, CTX_NONE);
index bffa39d20a9bd1b9a9b02405b6ab8a4b8f841d0c..2d669b3e9d8036493c45844c9a8480d6296b0151 100644 (file)
@@ -29,7 +29,9 @@ enum {
        WCS_LONG          /* its an integer */
 };
 
-
+typedef struct WCTemplateToken WCTemplateToken;
+typedef struct WCTemplputParams WCTemplputParams;
+typedef void (*WCHandlerFunc)(StrBuf *Target, WCTemplputParams *TP);
 
 typedef struct _TemplateParam {
        const char *Start;
@@ -39,8 +41,8 @@ typedef struct _TemplateParam {
 } TemplateParam;
 
 /* make a template token a lookup key: */
-#define TKEY(a) Tokens->Params[a]->Start, Tokens->Params[a]->len
-typedef struct _TemplateToken {
+#define TKEY(a) TP->Tokens->Params[a]->Start, TP->Tokens->Params[a]->len
+struct WCTemplateToken {
        const StrBuf *FileName; /* Reference to print error messages; not to be freed */
        StrBuf *FlatToken;
        long Line;
@@ -57,9 +59,7 @@ typedef struct _TemplateToken {
        int HaveParameters;
        int nParameters;
        TemplateParam *Params[MAXPARAM];
-} WCTemplateToken;
-
-typedef void (*WCHandlerFunc)();
+};
 
 
 /*
@@ -74,6 +74,20 @@ typedef struct _wcsubst {
        WCHandlerFunc wcs_function; /* funcion hook ???*/
 } wcsubst;
 
+struct WCTemplputParams {
+       int nArgs;
+       WCTemplateToken *Tokens;
+       void *Context;
+       int ContextType;
+};
+
+
+extern WCTemplputParams NoCtx;
+
+#define CTX TP->Context
+
+
+
 #define CTX_NONE 0
 #define CTX_SITECFG 1
 #define CTX_SESSION 2
@@ -97,7 +111,7 @@ void RegisterNS(const char *NSName, long len,
                int ContextRequired);
 #define RegisterNamespace(a, b, c, d, e) RegisterNS(a, sizeof(a)-1, b, c, d, e)
 
-typedef int (*WCConditionalFunc)(WCTemplateToken *Token, void *Context, int ContextType);
+typedef int (*WCConditionalFunc)(StrBuf *Target, WCTemplputParams *TP);
 typedef struct _ConditionalStruct {
        const char *PlainName;
        int nParams;
@@ -111,8 +125,8 @@ void RegisterConditional(const char *Name, long len,
 
 
 
-typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, void *Context, WCTemplateToken *Token);
-typedef HashList *(*RetrieveHashlistFunc)(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType);
+typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, WCTemplputParams *TP);
+typedef HashList *(*RetrieveHashlistFunc)(StrBuf *Target, WCTemplputParams *TP);
 typedef void (*HashDestructorFunc) (HashList **KillMe);
 void RegisterITERATOR(const char *Name, long len, /* Our identifier */
                      int AdditionalParams,       /* doe we use more parameters? */
@@ -129,8 +143,8 @@ void RegisterITERATOR(const char *Name, long len, /* Our identifier */
 
 #define RegisterIterator(a, b, c, d, e, f, g, h, i) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h, i)
 
-void GetTemplateTokenString(WCTemplateToken *Tokens,
-                           int N, 
+void GetTemplateTokenString(WCTemplputParams *TP,
+                           int N,
                            const char **Value, 
                            long *len);
 
@@ -148,19 +162,18 @@ void SVCallback(char *keyname, size_t keylen,  WCHandlerFunc fcn_ptr);
 void SVPUTBuf(const char *keyname, int keylen, const StrBuf *Buf, int ref);
 #define SVPutBuf(a, b, c); SVPUTBuf(a, sizeof(a) - 1, b, c)
 
-void DoTemplate(const char *templatename, long len, StrBuf *Target, void *Context, int ContextType);
-#define do_template(a, b) DoTemplate(a, sizeof(a) -1, NULL, b, 0);
+void DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputParams *TP);
+#define do_template(a, b) DoTemplate(a, sizeof(a) -1, NULL, &NoCtx);
 void url_do_template(void);
 
 int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup);
 int CompareSubstToStrBuf(StrBuf *Compare, TemplateParam *ParamToLookup);
 
 void StrBufAppendTemplate(StrBuf *Target, 
-                         int nArgs, 
-                         WCTemplateToken *Tokens,
-                         void *Context, int ContextType,
-                         const StrBuf *Source, int FormatTypeIndex);
-CompareFunc RetrieveSort(long ContextType, const char *OtherPrefix, 
+                         WCTemplputParams *TP,
+                         const StrBuf *Source, 
+                         int FormatTypeIndex);
+CompareFunc RetrieveSort(WCTemplputParams *TP, const char *OtherPrefix, 
                         const char *Default, long ldefault, long DefaultDirection);
 void RegisterSortFunc(const char *name, long len, 
                      const char *prepend, long preplen,
@@ -170,3 +183,13 @@ void RegisterSortFunc(const char *name, long len,
                      long ContextType);
 
 void dbg_print_longvector(long *LongVector);
+
+
+#define ERR_NAME 0
+#define ERR_PARM1 1
+#define ERR_PARM2 2
+void LogTemplateError (StrBuf *Target, 
+                      const char *Type, 
+                      int ErrorPos, 
+                      WCTemplputParams *TP, 
+                      const char *Format, ...);
index d48643b13f2dde21a67ed27dad804f723cb80787..cb9ef3b5c24ca1538f08bc10c5dda456b9f464b0 100644 (file)
@@ -83,8 +83,11 @@ void tasks_section(void) {
        void *vMsg;
        message_summary *Msg;
        wcsession *WCC = WC;
+       StrBuf *Buf;
 
-       gotoroom("_TASKS_");
+       Buf = NewStrBufPlain(HKEY("_TASKS_"));
+       gotoroom(Buf);
+       FreeStrBuf(&Buf);
        if (WCC->wc_view != VIEW_TASKS) {
                num_msgs = 0;
        }
@@ -121,8 +124,11 @@ void calendar_section(void) {
        message_summary *Msg;
        wcsession *WCC = WC;
        struct calview c;
+       StrBuf *Buf;
 
-       gotoroom("_CALENDAR_");
+       Buf = NewStrBufPlain(HKEY("_CALENDAR_"));
+       gotoroom(Buf);
+       FreeStrBuf(&Buf);
        if ( (WC->wc_view != VIEW_CALENDAR) && (WC->wc_view != VIEW_CALBRIEF) ) {
                num_msgs = 0;
        }
@@ -155,12 +161,12 @@ void server_info_section(void) {
 
        snprintf(message, sizeof message,
                _("You are connected to %s, running %s with %s, server build %s and located in %s.  Your system administrator is %s."),
-               serv_info.serv_humannode,
-               serv_info.serv_software,
-               PACKAGE_STRING,
-               serv_info.serv_svn_revision,
-               serv_info.serv_bbs_city,
-               serv_info.serv_sysadm);
+                ChrPtr(serv_info.serv_humannode),
+                ChrPtr(serv_info.serv_software),
+                PACKAGE_STRING,
+                ChrPtr(serv_info.serv_svn_revision),
+                ChrPtr(serv_info.serv_bbs_city),
+                ChrPtr(serv_info.serv_sysadm));
        escputs(message);
 }
 
@@ -262,14 +268,14 @@ void summary(void) {
        wprintf("<div class=\"room_banner\">");
         wprintf("<img src=\"static/summscreen_48x.gif\">");
         wprintf("<h1>");
-        snprintf(title, sizeof title, _("Summary page for %s"), WC->wc_fullname);
+        snprintf(title, sizeof title, _("Summary page for %s"), ChrPtr(WC->wc_fullname));
         escputs(title);
         wprintf("</h1><h2>");
         output_date();
         wprintf("</h2></div>");
        wprintf("<ul class=\"room_actions\">\n");
        wprintf("<li class=\"start_page\">");
-       offer_start_page(NULL, 0, NULL, NULL, CTX_NONE);
+       offer_start_page(NULL, &NoCtx);
         wprintf("</li></ul>");
         wprintf("</div>");
 
index 009cd051b7f6e5f7ad8f8a69d4be87d28fb7c320..00b4181d246d12bf97eae784d812da38fb90f1ae 100644 (file)
@@ -101,7 +101,7 @@ void editinfo(void) {save_edit(_("Room info"), "EINF 1", 1);}
 void display_editbio(void) {
        char buf[SIZ];
 
-       snprintf(buf, SIZ, "RBIO %s", WC->wc_fullname);
+       snprintf(buf, SIZ, "RBIO %s", ChrPtr(WC->wc_fullname));
        display_edit(_("Your bio"), "NOOP", buf, "editbio", 3);
 }
 void editbio(void) { save_edit(_("Your bio"), "EBIO", 0); }
index 6228f75081ebb251a4dc47843587157efc0db74e..f4f136ebb9a9a0f149f26acc0b94188a88dbd70d 100644 (file)
@@ -197,7 +197,7 @@ int ComparenPostsRev(const void *vUser1, const void *vUser2)
 }
 
 
-HashList *iterate_load_userlist(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+HashList *iterate_load_userlist(StrBuf *Target, WCTemplputParams *TP)
 {
        HashList *Hash;
        char buf[SIZ];
@@ -268,76 +268,76 @@ HashList *iterate_load_userlist(StrBuf *Target, int nArgs, WCTemplateToken *Toke
 }
 
 
-void tmplput_USERLIST_UserName(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_USERLIST_UserName(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserListEntry *ul = (UserListEntry*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, ul->UserName, 0);
+       UserListEntry *ul = (UserListEntry*) CTX;
+       StrBufAppendTemplate(Target, TP, ul->UserName, 0);
 }
 
-void tmplput_USERLIST_AccessLevelNo(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_USERLIST_AccessLevelNo(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserListEntry *ul = (UserListEntry*) Context;
+       UserListEntry *ul = (UserListEntry*) CTX;
 
        StrBufAppendPrintf(Target, "%d", ul->AccessLevel, 0);
 }
 
-void tmplput_USERLIST_AccessLevelStr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_USERLIST_AccessLevelStr(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserListEntry *ul = (UserListEntry*) Context;
+       UserListEntry *ul = (UserListEntry*) CTX;
        
        StrBufAppendBufPlain(Target, _(axdefs[ul->AccessLevel]), -1, 0);
 }
 
-void tmplput_USERLIST_UID(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_USERLIST_UID(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserListEntry *ul = (UserListEntry*) Context;
+       UserListEntry *ul = (UserListEntry*) CTX;
 
        StrBufAppendPrintf(Target, "%d", ul->UID, 0);
 }
 
-void tmplput_USERLIST_LastLogonNo(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_USERLIST_LastLogonNo(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserListEntry *ul = (UserListEntry*) Context;
+       UserListEntry *ul = (UserListEntry*) CTX;
 
        StrBufAppendPrintf(Target,"%ld", ul->LastLogonT, 0);
 }
-void tmplput_USERLIST_LastLogonStr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_USERLIST_LastLogonStr(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserListEntry *ul = (UserListEntry*) Context;
+       UserListEntry *ul = (UserListEntry*) CTX;
        StrEscAppend(Target, NULL, asctime(localtime(&ul->LastLogonT)), 0, 0);
 }
 
-void tmplput_USERLIST_nLogons(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_USERLIST_nLogons(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserListEntry *ul = (UserListEntry*) Context;
+       UserListEntry *ul = (UserListEntry*) CTX;
 
        StrBufAppendPrintf(Target, "%d", ul->nLogons, 0);
 }
 
-void tmplput_USERLIST_nPosts(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_USERLIST_nPosts(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserListEntry *ul = (UserListEntry*) Context;
+       UserListEntry *ul = (UserListEntry*) CTX;
 
        StrBufAppendPrintf(Target, "%d", ul->nPosts, 0);
 }
 
-void tmplput_USERLIST_Flags(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_USERLIST_Flags(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserListEntry *ul = (UserListEntry*) Context;
+       UserListEntry *ul = (UserListEntry*) CTX;
 
        StrBufAppendPrintf(Target, "%d", ul->Flags, 0);
 }
 
-void tmplput_USERLIST_DaysTillPurge(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_USERLIST_DaysTillPurge(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserListEntry *ul = (UserListEntry*) Context;
+       UserListEntry *ul = (UserListEntry*) CTX;
 
        StrBufAppendPrintf(Target, "%d", ul->DaysTillPurge, 0);
 }
 
-int ConditionalUser(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalUser(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserListEntry *ul = (UserListEntry*) Context;
+       UserListEntry *ul = (UserListEntry*) CTX;
        if (havebstr("usernum")) {
                return ibstr("usernum") == ul->UID;
        }
@@ -348,18 +348,18 @@ int ConditionalUser(WCTemplateToken *Tokens, void *Context, int ContextType)
                return 0;
 }
 
-int ConditionalFlagINetEmail(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalFlagINetEmail(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserListEntry *ul = (UserListEntry*) Context;
+       UserListEntry *ul = (UserListEntry*) CTX;
        return (ul->Flags & US_INTERNET) != 0;
 }
 
-int ConditionalUserAccess(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalUserAccess(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserListEntry *ul = (UserListEntry*) Context;
+       UserListEntry *ul = (UserListEntry*) CTX;
 
-       if (Tokens->Params[3]->Type == TYPE_LONG)
-               return (Tokens->Params[3]->lvalue == ul->AccessLevel);
+       if (TP->Tokens->Params[3]->Type == TYPE_LONG)
+               return (TP->Tokens->Params[3]->lvalue == ul->AccessLevel);
        else
                return 0;
 }
@@ -516,8 +516,12 @@ void display_edituser(char *supplied_username, int is_new) {
                        delete_user(username);
                }
                else {
+                       WCTemplputParams SubTP;
+                       memset(&SubTP, 0, sizeof(WCTemplputParams));
+                       SubTP.ContextType = CTX_USERLIST;
+                       SubTP.Context = UL;
                        output_headers(1, 0, 0, 0, 1, 0);
-                       DoTemplate(HKEY("userlist_detailview"), NULL, (void*) UL, CTX_USERLIST);
+                       DoTemplate(HKEY("userlist_detailview"), NULL, &SubTP);
                        end_burst();
                }
                DeleteUserListEntry(UL);
index 3a9df29877cdc51544048d073d8a3791a4ee29e6..f0b8325acb127d22942c2b01ee3da9bed9580b1b 100644 (file)
@@ -39,7 +39,7 @@ void userlist(void)
        output_headers(1, 1, 2, 0, 0, 0);
        wprintf("<div id=\"banner\">\n");
        wprintf("<h1>");
-       snprintf(title, sizeof title, _("User list for %s"), serv_info.serv_humannode);
+       snprintf(title, sizeof title, _("User list for %s"), ChrPtr(serv_info.serv_humannode));
        escputs(title);
        wprintf("</h1>");
         wprintf("</div>");
index c2a4c02fa424f99d5fc5b36c9bc4c24d8891c922..0c10e4d9a3e59d2a0985afda75d71d09529cd8c7 100644 (file)
@@ -130,7 +130,7 @@ long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks)
 }
 
 
-void escputs1(char *strbuf, int nbsp, int nolinebreaks)
+void escputs1(const char *strbuf, int nbsp, int nolinebreaks)
 {
        StrEscAppend(WC->WBuf, NULL, strbuf, nbsp, nolinebreaks);
 }
@@ -143,7 +143,7 @@ void StrEscputs1(const StrBuf *strbuf, int nbsp, int nolinebreaks)
 /* 
  * static wrapper for ecsputs1
  */
-void escputs(char *strbuf)
+void escputs(const char *strbuf)
 {
        escputs1(strbuf, 0, 0);
 }
index bc0ed9174a1b3ec68a987758005faa7c61072882..f56fd1c09e3f780f819734c6263917c2baa8b600 100644 (file)
@@ -61,8 +61,8 @@ void display_addressbook(long msgnum, char alpha) {
                        display_vcard(WC->WBuf, vcard_source, alpha, 0, NULL,msgnum);
 
                        /** If it's my vCard I can edit it */
-                       if (    (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
-                               || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
+                       if (    (!strcasecmp(ChrPtr(WC->wc_roomname), USERCONFIGROOM))
+                               || (!strcasecmp(&(ChrPtr(WC->wc_roomname)[11]), USERCONFIGROOM))
                                || (WC->wc_view == VIEW_ADDRESSBOOK)
                        ) {
                                wprintf("<a href=\"edit_vcard?"
@@ -648,7 +648,7 @@ void do_addrbook_view(addrbookent *addrbook, int num_ab) {
  * and MIME part number to fetch.  Or, specify -1 for the message number
  * to start with a blank card.
  */
-void do_edit_vcard(long msgnum, char *partnum, char *return_to, char *force_room) {
+void do_edit_vcard(long msgnum, char *partnum, char *return_to, const char *force_room) {
        char buf[SIZ];
        char *serialized_vcard = NULL;
        size_t total_len = 0;
@@ -1026,7 +1026,7 @@ void submit_vcard(void) {
        }
 
        if (havebstr("force_room")) {
-               gotoroom(bstr("force_room"));
+               gotoroom(sbstr("force_room"));
        }
 
        sprintf(buf, "ENT0 1|||4||");
index 9a9d89b3aaf9c7b5e321997216f0bf32296f22ab..5aee1f15452bb35cbd0ae27033d9b3dfa61029eb 100644 (file)
@@ -2,7 +2,7 @@
 void initialize_locales(void);
 void ShutdownLocale(void);
 #endif
-void TmplGettext(StrBuf *Target, int nTokens, WCTemplateToken *Token);
+void TmplGettext(StrBuf *Target, WCTemplputParams *TP);
 void offer_languages(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType);
 void set_selected_language(const char *);
 void go_selected_language(void);
index a7069f14d5a8b30cf55d1abdfc218f1125fe84ab..56371be92483eb26d0f212ab1f7da52ff590b7a9 100644 (file)
@@ -118,7 +118,8 @@ void output_headers(        int do_httpheaders,     /* 1 = output HTTP headers
                hprintf("Content-type: text/html; charset=utf-8\r\n"
                        "Server: %s / %s\n"
                        "Connection: close\r\n",
-                       PACKAGE_STRING, serv_info.serv_software
+                       PACKAGE_STRING, 
+                       ChrPtr(serv_info.serv_software)
                );
        }
 
@@ -143,7 +144,8 @@ void output_headers(        int do_httpheaders,     /* 1 = output HTTP headers
                );
        }
 
-       stuff_to_cookie(cookie, 1024, WC->wc_session, WC->wc_username,
+       stuff_to_cookie(cookie, 1024, 
+                       WC->wc_session, WC->wc_username,
                        WC->wc_password, WC->wc_roomname);
 
        if (unset_cookies) {
@@ -365,7 +367,7 @@ void url_do_template(void) {
        const StrBuf *Tmpl = sbstr("template");
        begin_burst();
        output_headers(1, 0, 0, 0, 1, 0);
-       DoTemplate(ChrPtr(Tmpl), StrLength(Tmpl), NULL, NULL, 0);
+       DoTemplate(SKEY(Tmpl), NULL, &NoCtx);
        end_burst();
 }
 
@@ -387,7 +389,7 @@ void display_success(char *successmessage)
 void authorization_required(const char *message)
 {
        hprintf("HTTP/1.1 401 Authorization Required\r\n");
-       hprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n", serv_info.serv_humannode);
+       hprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n", ChrPtr(serv_info.serv_humannode));
        hprintf("Content-Type: text/html\r\n");
        wprintf("<h1>");
        wprintf(_("Authorization Required"));
@@ -491,7 +493,7 @@ void seconds_since_last_gexp(void)
                wprintf("NO\n");
        }
        else {
-               memset(buf, 5, 0);
+               memset(buf, 0, 5);
                serv_puts("NOOP");
                serv_getln(buf, sizeof buf);
                if (buf[3] == '*') {
@@ -528,6 +530,7 @@ int is_mobile_ua(char *user_agent) {
  */
 void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method, StrBuf *ReadBuf)
 {
+       StrBuf *Buf;
        const char *pch, *pchs, *pche;
        void *vLine;
        char action[1024];
@@ -554,20 +557,21 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
         * We stuff these with the values coming from the client cookies,
         * so we can use them to reconnect a timed out session if we have to.
         */
-       char c_username[SIZ];
-       char c_password[SIZ];
-       char c_roomname[SIZ];
+       StrBuf *c_username;
+       StrBuf *c_password;
+       StrBuf *c_roomname;
        char c_httpauth_string[SIZ];
-       char c_httpauth_user[SIZ];
-       char c_httpauth_pass[SIZ];
+       StrBuf *c_httpauth_user;
+       StrBuf *c_httpauth_pass;
        wcsession *WCC;
        
-       safestrncpy(c_username, "", sizeof c_username);
-       safestrncpy(c_password, "", sizeof c_password);
-       safestrncpy(c_roomname, "", sizeof c_roomname);
+       Buf = NewStrBuf();
+       c_username = NewStrBuf();
+       c_password = NewStrBuf();
+       c_roomname = NewStrBuf();
        safestrncpy(c_httpauth_string, "", sizeof c_httpauth_string);
-       safestrncpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER, sizeof c_httpauth_user);
-       safestrncpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS, sizeof c_httpauth_pass);
+       c_httpauth_user = NewStrBufPlain(HKEY(DEFAULT_HTTPAUTH_USER));
+       c_httpauth_pass = NewStrBufPlain(HKEY(DEFAULT_HTTPAUTH_PASS));
        strcpy(browser_host, "");
 
        WCC= WC;
@@ -611,15 +615,18 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
        if (GetHash(HTTPHeaders, HKEY("COOKIE"), &vLine) && 
            (vLine != NULL)){
                cookie_to_stuff((StrBuf *)vLine, NULL,
-                               c_username, sizeof c_username,
-                               c_password, sizeof c_password,
-                               c_roomname, sizeof c_roomname);
+                               c_username,
+                               c_password,
+                               c_roomname);
        }
        if (GetHash(HTTPHeaders, HKEY("AUTHORIZATION"), &vLine) &&
            (vLine!=NULL)) {
+/* TODO: wrap base64 in strbuf */
                CtdlDecodeBase64(c_httpauth_string, ChrPtr((StrBuf*)vLine), StrLength((StrBuf*)vLine));
-               extract_token(c_httpauth_user, c_httpauth_string, 0, ':', sizeof c_httpauth_user);
-               extract_token(c_httpauth_pass, c_httpauth_string, 1, ':', sizeof c_httpauth_pass);
+               FlushStrBuf(Buf);
+               StrBufAppendBufPlain(Buf, c_httpauth_string, -1, 0);
+               StrBufExtract_token(c_httpauth_user, Buf, 0, ':');
+               StrBufExtract_token(c_httpauth_pass, Buf, 1, ':');
        }
        if (GetHash(HTTPHeaders, HKEY("CONTENT-LENGTH"), &vLine) &&
            (vLine!=NULL)) {
@@ -843,21 +850,34 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
         * try logging in to Citadel using that.
         */
        if ((!WCC->logged_in)
-          && (strlen(c_httpauth_user) > 0)
-          && (strlen(c_httpauth_pass) > 0)) {
-               serv_printf("USER %s", c_httpauth_user);
-               serv_getln(buf, sizeof buf);
-               if (buf[0] == '3') {
-                       serv_printf("PASS %s", c_httpauth_pass);
-                       serv_getln(buf, sizeof buf);
-                       if (buf[0] == '2') {
+           && (StrLength(c_httpauth_user) > 0)
+           && (StrLength(c_httpauth_pass) > 0))
+       {
+               FlushStrBuf(Buf);
+               serv_printf("USER %s", ChrPtr(c_httpauth_user));
+               StrBuf_ServGetln(Buf);
+               if (GetServerStatus(Buf, NULL) == 3) {
+                       serv_printf("PASS %s", ChrPtr(c_httpauth_pass));
+                       StrBuf_ServGetln(Buf);
+                       if (GetServerStatus(Buf, NULL) == 2) {
                                become_logged_in(c_httpauth_user,
-                                               c_httpauth_pass, buf);
-                               safestrncpy(WCC->httpauth_user, c_httpauth_user, sizeof WCC->httpauth_user);
-                               safestrncpy(WCC->httpauth_pass, c_httpauth_pass, sizeof WCC->httpauth_pass);
+                                               c_httpauth_pass, Buf);
+                               if (WCC->httpauth_user == NULL)
+                                       WCC->httpauth_user = NewStrBufDup(c_httpauth_user);
+                               else {
+                                       FlushStrBuf(WCC->httpauth_user);
+                                       StrBufAppendBuf(WCC->httpauth_user, c_httpauth_user, 0);
+                               }
+                               if (WCC->httpauth_pass == NULL)
+                                       WCC->httpauth_pass = NewStrBufDup(c_httpauth_pass);
+                               else {
+                                       FlushStrBuf(WCC->httpauth_pass);
+                                       StrBufAppendBuf(WCC->httpauth_pass, c_httpauth_pass, 0);
+                               }
                        } else {
                                /* Should only display when password is wrong */
                                authorization_required(&buf[4]);
+                               FreeStrBuf(&Buf);
                                goto SKIP_ALL_THIS_CRAP;
                        }
                }
@@ -866,7 +886,7 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
        /* This needs to run early */
 #ifdef TECH_PREVIEW
        if (!strcasecmp(action, "rss")) {
-               display_rss(bstr("room"), request_method);
+               display_rss(sbstr("room"), request_method);
                goto SKIP_ALL_THIS_CRAP;
        }
 #endif
@@ -906,16 +926,16 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
         * supplied by the browser, try using them to log in.
         */
        if ((!WCC->logged_in)
-          && (!IsEmptyStr(c_username))
-          && (!IsEmptyStr(c_password))) {
-               serv_printf("USER %s", c_username);
-               serv_getln(buf, sizeof buf);
-               if (buf[0] == '3') {
-                       serv_printf("PASS %s", c_password);
-                       serv_getln(buf, sizeof buf);
-                       if (buf[0] == '2') {
+          && (StrLength(c_username)>0)
+          && (StrLength(c_password)>0)) {
+               serv_printf("USER %s", ChrPtr(c_username));
+               StrBuf_ServGetln(Buf);
+               if (GetServerStatus(Buf, NULL) == 3) {
+                       serv_printf("PASS %s", ChrPtr(c_password));
+                       StrBuf_ServGetln(Buf);
+                       if (GetServerStatus(Buf, NULL) == 2) {
                                StrBuf *Lang;
-                               become_logged_in(c_username, c_password, buf);
+                               become_logged_in(c_username, c_password, Buf);
                                if (get_preference("language", &Lang)) {
                                        set_selected_language(ChrPtr(Lang));
                                        go_selected_language();         /* set locale */
@@ -930,18 +950,24 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
         * prior to doing anything else.
         */
        if (havebstr("gotofirst")) {
-               gotoroom(bstr("gotofirst"));    /* do this quietly to avoid session output! */
+               gotoroom(sbstr("gotofirst"));   /* do this quietly to avoid session output! */
        }
 
        /*
         * If we don't have a current room, but a cookie specifying the
         * current room is supplied, make an effort to go there.
         */
-       if ((IsEmptyStr(WCC->wc_roomname)) && (!IsEmptyStr(c_roomname))) {
-               serv_printf("GOTO %s", c_roomname);
-               serv_getln(buf, sizeof buf);
-               if (buf[0] == '2') {
-                       safestrncpy(WCC->wc_roomname, c_roomname, sizeof WCC->wc_roomname);
+       if ((StrLength(WCC->wc_roomname) == 0) && (StrLength(c_roomname) > 0)) {
+               serv_printf("GOTO %s", ChrPtr(c_roomname));
+               StrBuf_ServGetln(Buf);
+               if (GetServerStatus(Buf, NULL) == 2) {
+                       if (WCC->wc_roomname == NULL) {
+                               WCC->wc_roomname = NewStrBufDup(c_roomname);
+                       }
+                       else {
+                               FlushStrBuf(WCC->wc_roomname);
+                               StrBufAppendBuf(WCC->wc_roomname, c_roomname, 0);
+                       }
                }
        }
        
@@ -979,6 +1005,12 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method
        }
 
 SKIP_ALL_THIS_CRAP:
+       FreeStrBuf(&Buf);
+       FreeStrBuf(&c_username);
+       FreeStrBuf(&c_password);
+       FreeStrBuf(&c_roomname);
+       FreeStrBuf(&c_httpauth_user);
+       FreeStrBuf(&c_httpauth_pass);
        fflush(stdout);
        if (content != NULL) {
                FreeStrBuf(&content);
@@ -1006,7 +1038,7 @@ void sleeeeeeeeeep(int seconds)
 }
 
 
-int ConditionalImportantMesage(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalImportantMesage(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        if (WCC != NULL)
@@ -1015,7 +1047,7 @@ int ConditionalImportantMesage(WCTemplateToken *Tokens, void *Context, int Conte
                return 0;
 }
 
-void tmplput_importantmessage(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_importantmessage(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        
@@ -1029,16 +1061,15 @@ void tmplput_importantmessage(StrBuf *Target, int nArgs, WCTemplateToken *Tokens
        }
 }
 
-void tmplput_trailing_javascript(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
+void tmplput_trailing_javascript(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
 
        if (WCC != NULL)
-               StrBufAppendTemplate(Target, nArgs, Tokens, vContext, ContextType,
-                                    WCC->trailing_javascript, 0);
+               StrBufAppendTemplate(Target, TP, WCC->trailing_javascript, 0);
 }
 
-void tmplput_csslocal(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_csslocal(StrBuf *Target, WCTemplputParams *TP)
 {
        extern StrBuf *csslocal;
        StrBufAppendBuf(Target, 
@@ -1060,6 +1091,5 @@ InitModule_WEBCIT
        RegisterConditional(HKEY("COND:IMPMSG"), 0, ConditionalImportantMesage, CTX_NONE);
        RegisterNamespace("CSSLOCAL", 0, 0, tmplput_csslocal, CTX_NONE);
        RegisterNamespace("IMPORTANTMESSAGE", 0, 0, tmplput_importantmessage, CTX_NONE);
-       RegisterNamespace("OFFERSTARTPAGE", 0, 0, offer_start_page, CTX_NONE);
        RegisterNamespace("TRAILING_JAVASCRIPT", 0, 0, tmplput_trailing_javascript, CTX_NONE);
 }
index 1464bf583f5f8735811fa37c959b7a639a854569..88b1e20f1ba1e97f860bb4159181b7d0672aaed3 100644 (file)
@@ -216,21 +216,21 @@ struct urlcontent {
  */ 
 struct serv_info {
        int serv_pid;                   /* Process ID of the Citadel server */
-       char serv_nodename[32];         /* Node name of the Citadel server */
-       char serv_humannode[64];        /* human readable node name of the Citadel server */
-       char serv_fqdn[64];             /* fully quallified Domain Name (such as uncensored.citadel.org) */
-       char serv_software[64];         /* What version does our connected citadel server use */
+       StrBuf *serv_nodename;          /* Node name of the Citadel server */
+       StrBuf *serv_humannode;         /* human readable node name of the Citadel server */
+       StrBuf *serv_fqdn;              /* fully quallified Domain Name (such as uncensored.citadel.org) */
+       StrBuf *serv_software;          /* What version does our connected citadel server use */
        int serv_rev_level;             /* Whats the citadel server revision */
-       char serv_bbs_city[64];         /* Geographic location of the Citadel server */
-       char serv_sysadm[64];           /* Name of system administrator */
-       char serv_moreprompt[256];      /* Whats the commandline textprompt */
+       StrBuf *serv_bbs_city;          /* Geographic location of the Citadel server */
+       StrBuf *serv_sysadm;            /* Name of system administrator */
+       StrBuf *serv_moreprompt;        /* Whats the commandline textprompt */
        int serv_ok_floors;             /* nonzero == server supports floors */
        int serv_supports_ldap;         /* is the server linked against an ldap tree for adresses? */
        int serv_newuser_disabled;      /* Has the server disabled self-service new user creation? */
-       char serv_default_cal_zone[128];/* Default timezone for unspecified calendar items */
+       StrBuf *serv_default_cal_zone;  /* Default timezone for unspecified calendar items */
        int serv_supports_sieve;        /* Does the server support Sieve mail filtering? */
        int serv_fulltext_enabled;      /* Does the server have the full text index enabled? */
-       char serv_svn_revision[256];    /* SVN revision of the server */
+       StrBuf *serv_svn_revision;      /* SVN revision of the server */
        int serv_supports_openid;       /* Does the server support authentication via OpenID? */
 };
 
@@ -330,10 +330,10 @@ typedef struct wcsession wcsession;
 struct wcsession {
        wcsession *next;                        /**< Linked list */
        int wc_session;                         /**< WebCit session ID */
-       char wc_username[128];                  /**< login name of current user */
-       char wc_fullname[128];                  /**< Screen name of current user */
-       char wc_password[128];                  /**< Password of current user */
-       char wc_roomname[256];                  /**< Room we are currently in */
+       StrBuf *wc_username;                    /**< login name of current user */
+       StrBuf *wc_fullname;                    /**< Screen name of current user */
+       StrBuf *wc_password;                    /**< Password of current user */
+       StrBuf *wc_roomname;                    /**< Room we are currently in */
        int connected;                          /**< nonzero == we are connected to Citadel */
        int logged_in;                          /**< nonzero == we are logged in  */
        int axlevel;                            /**< this user's access level */
@@ -376,8 +376,8 @@ struct wcsession {
        char last_chat_user[256];               /**< ??? todo */
        char ImportantMessage[SIZ];             /**< ??? todo */
        int ctdl_pid;                           /**< Session ID on the Citadel server */
-       char httpauth_user[256];                /**< only for GroupDAV sessions */
-       char httpauth_pass[256];                /**< only for GroupDAV sessions */
+       StrBuf *httpauth_user;                  /**< only for GroupDAV sessions */
+       StrBuf *httpauth_pass;                  /**< only for GroupDAV sessions */
        int gzip_ok;                            /**< Nonzero if Accept-encoding: gzip */
        int is_mailbox;                         /**< the current room is a private mailbox */
        struct folder *cache_fold;              /**< cache the iconbar room list */
@@ -477,13 +477,13 @@ void end_critical_section(int which_one);
 
 
 void stuff_to_cookie(char *cookie, size_t clen, int session,
-                       char *user, char *pass, char *room);
+                       StrBuf *user, StrBuf *pass, StrBuf *room);
 void cookie_to_stuff(StrBuf *cookie, int *session,
-                char *user, size_t user_len,
-                char *pass, size_t pass_len,
-                char *room, size_t room_len);
+                    StrBuf *user,
+                    StrBuf *pass,
+                    StrBuf *room);
 void locate_host(char *, int);
-void become_logged_in(char *, char *, char *);
+void become_logged_in(const StrBuf *user, const StrBuf *pass, StrBuf *serv_response);
 void openid_manual_create(void);
 void display_login();
 void display_openids(void);
@@ -535,10 +535,10 @@ void output_static(char *what);
 
 void print_menu_box(char* Title, char *Class, int nLines, ...);
 long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks);
-void escputs(char *strbuf);
+void escputs(const char *strbuf);
 void url(char *buf, size_t bufsize);
 void UrlizeText(StrBuf* Target, StrBuf *Source, StrBuf *WrkBuf);
-void escputs1(char *strbuf, int nbsp, int nolinebreaks);
+void escputs1(const char *strbuf, int nbsp, int nolinebreaks);
 void msgesc(char *target, size_t tlen, char *strbuf);
 void msgescputs(char *strbuf);
 void msgescputs1(char *strbuf);
@@ -560,7 +560,7 @@ void server_to_text(void);
 void save_edit(char *description, char *enter_cmd, int regoto);
 void display_edit(char *description, char *check_cmd,
                  char *read_cmd, char *save_cmd, int with_room_banner);
-int gotoroom(char *gname);
+long gotoroom(const StrBuf *gname);
 void confirm_delete_room(void);
 void validate(void);
 void display_graphics_upload(char *, char *, char *);
@@ -574,7 +574,7 @@ void serv_printf(const char *format,...)__attribute__((__format__(__printf__,1,2
 void load_floorlist(void);
 void shutdown_sessions(void);
 void do_housekeeping(void);
-void smart_goto(char *);
+void smart_goto(const StrBuf *);
 void worker_entry(void);
 void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *ReqType, StrBuf *ReadBuf);
 size_t wc_strftime(char *s, size_t max, const char *format, const struct tm *tm);
@@ -597,7 +597,7 @@ void remove_token(char *source, int parmnum, char separator);
 char *load_mimepart(long msgnum, char *partnum);
 void MimeLoadData(wc_mime_attachment *Mime);
 int pattern2(char *search, char *patn);
-void do_edit_vcard(long, char *, char *, char *);
+void do_edit_vcard(long, char *, char *, const char *);
 void striplt(char *);
 void stripltlen(char *, int *);
 void select_user_to_edit(char *message, char *preselect);
@@ -608,7 +608,7 @@ void folders(void);
 
 
 void display_addressbook(long msgnum, char alpha);
-void offer_start_page(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType);
+void offer_start_page(StrBuf *Target, WCTemplputParams *TP);
 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext);
 void output_html(const char *, int, int, StrBuf *, StrBuf *);
 void do_listsub(void);
@@ -671,7 +671,7 @@ void http_transmit_thing(const char *content_type, int is_static);
 long unescape_input(char *buf);
 void do_selected_iconbar(void);
 void spawn_another_worker_thread(void);
-void display_rss(char *roomname, StrBuf *request_method);
+void display_rss(const StrBuf *roomname, StrBuf *request_method);
 void StrEndTab(StrBuf *Target, int tabnum, int num_tabs);
 void StrBeginTab(StrBuf *Target, int tabnum, int num_tabs);
 void StrTabbedDialog(StrBuf *Target, int num_tabs, StrBuf *tabnames[]);
index 2edf9c64a1bb2d77897dbee4821d005f2688383e..9e1e3c90e797f39573186947d651f83e3ca7109a 100644 (file)
@@ -209,7 +209,8 @@ void _terminate_session(void) {
        terminate_session();
 }
 
-HashList *GetWholistHash(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+HashList *GetWholistHash(StrBuf *Target, WCTemplputParams *TP)
+
 {
        HashList *List;
        char buf[SIZ];
@@ -235,80 +236,80 @@ void DeleteWholistHash(HashList **KillMe)
        DeleteHash(KillMe);
 }
 
-void tmplput_who_username(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
+void tmplput_who_username(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserStateStruct *User = (UserStateStruct*) vContext;
-       StrBufAppendTemplate(Target, nArgs, Tokens, vContext, ContextType, User->UserName, 0);
+       UserStateStruct *User = (UserStateStruct*) CTX;
+       StrBufAppendTemplate(Target, TP, User->UserName, 0);
 }
 
-void tmplput_who_room(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
+void tmplput_who_room(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserStateStruct *User = (UserStateStruct*) vContext;
-       StrBufAppendTemplate(Target, nArgs, Tokens, vContext, ContextType, User->Room, 0);
+       UserStateStruct *User = (UserStateStruct*) CTX;
+       StrBufAppendTemplate(Target, TP, User->Room, 0);
 }
 
-void tmplput_who_host(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
+void tmplput_who_host(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserStateStruct *User = (UserStateStruct*) vContext;
-       StrBufAppendTemplate(Target, nArgs, Tokens, vContext, ContextType, User->Host, 0);
+       UserStateStruct *User = (UserStateStruct*) CTX;
+       StrBufAppendTemplate(Target, TP, User->Host, 0);
 }
 
-void tmplput_who_realroom(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
+void tmplput_who_realroom(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserStateStruct *User = (UserStateStruct*) vContext;
-       StrBufAppendTemplate(Target, nArgs, Tokens, vContext, ContextType, User->RealRoom, 0);
+       UserStateStruct *User = (UserStateStruct*) CTX;
+       StrBufAppendTemplate(Target, TP, User->RealRoom, 0);
 }
-int conditional_who_realroom(WCTemplateToken *Tokens, void *vContext, int ContextType)
+int conditional_who_realroom(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserStateStruct *User = (UserStateStruct*) vContext;
+       UserStateStruct *User = (UserStateStruct*) CTX;
        return StrLength(User->RealRoom) > 0;
 }
 
-void tmplput_who_realhost(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
+void tmplput_who_realhost(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserStateStruct *User = (UserStateStruct*) vContext;
-       StrBufAppendTemplate(Target, nArgs, Tokens, vContext, ContextType, User->RealHost, 0);
+       UserStateStruct *User = (UserStateStruct*) CTX;
+       StrBufAppendTemplate(Target, TP, User->RealHost, 0);
 }
 
-void tmplput_who_lastactive(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
+void tmplput_who_lastactive(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserStateStruct *User = (UserStateStruct*) vContext;
+       UserStateStruct *User = (UserStateStruct*) CTX;
        StrBufAppendPrintf(Target, "%d", User->LastActive);
 }
 
-void tmplput_who_idlesince(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
+void tmplput_who_idlesince(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserStateStruct *User = (UserStateStruct*) vContext;
+       UserStateStruct *User = (UserStateStruct*) CTX;
        StrBufAppendPrintf(Target, "%d", User->IdleSince);
 }
 
-void tmplput_who_session(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
+void tmplput_who_session(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserStateStruct *User = (UserStateStruct*) vContext;
+       UserStateStruct *User = (UserStateStruct*) CTX;
        StrBufAppendPrintf(Target, "%d", User->Session);
 }
 
-int conditional_who_idle(WCTemplateToken *Tokens, void *vContext, int ContextType)
+int conditional_who_idle(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserStateStruct *User = (UserStateStruct*) vContext;
+       UserStateStruct *User = (UserStateStruct*) CTX;
        return User->Idle;
 }
 
-int conditional_who_nsessions(WCTemplateToken *Tokens, void *vContext, int ContextType)
+int conditional_who_nsessions(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserStateStruct *User = (UserStateStruct*) vContext;
+       UserStateStruct *User = (UserStateStruct*) CTX;
        return User->SessionCount;
 }
 
-void tmplput_who_nsessions(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
+void tmplput_who_nsessions(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserStateStruct *User = (UserStateStruct*) vContext;
+       UserStateStruct *User = (UserStateStruct*) CTX;
        StrBufAppendPrintf(Target, "%d", User->SessionCount);
 }
 
-int conditional_who_isme(WCTemplateToken *Tokens, void *vContext, int ContextType)
+int conditional_who_isme(StrBuf *Target, WCTemplputParams *TP)
 {
-       UserStateStruct *User = (UserStateStruct*) vContext;
+       UserStateStruct *User = (UserStateStruct*) CTX;
        return (User->Session == WC->ctdl_pid);
 }
 
index 067ac6d3821ca1d4cde9f4b697638fcbb347b202..1bbb38dbe88711dc7733187081a24c6e839a2a27 100644 (file)
@@ -34,27 +34,27 @@ void str_wiki_index(char *s)
  */
 void display_wiki_page(void)
 {
-       char roomname[128];
+       const StrBuf *roomname;
        char pagename[128];
        char errmsg[256];
        long msgnum = (-1L);
 
-       safestrncpy(roomname, bstr("room"), sizeof roomname);
+       roomname = sbstr("room");
        safestrncpy(pagename, bstr("page"), sizeof pagename);
        str_wiki_index(pagename);
 
-       if (!IsEmptyStr(roomname)) {
+       if (StrLength(roomname) > 0) {
 
                /* If we're not in the correct room, try going there. */
-               if (strcasecmp(roomname, WC->wc_roomname)) {
+               if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
                        gotoroom(roomname);
                }
        
                /* If we're still not in the correct room, it doesn't exist. */
-               if (strcasecmp(roomname, WC->wc_roomname)) {
+               if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
                        snprintf(errmsg, sizeof errmsg,
-                               _("There is no room called '%s'."),
-                               roomname);
+                                _("There is no room called '%s'."),
+                                ChrPtr(roomname));
                        convenience_page("FF0000", _("Error"), errmsg);
                        return;
                }
@@ -64,7 +64,7 @@ void display_wiki_page(void)
        if (WC->wc_view != VIEW_WIKI) {
                snprintf(errmsg, sizeof errmsg,
                        _("'%s' is not a Wiki room."),
-                       roomname);
+                        ChrPtr(roomname));
                convenience_page("FF0000", _("Error"), errmsg);
                return;
        }