X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fwebcit.c;h=d7beab0c3bd9ca85d17ca3082f3fe0b96740f667;hb=95dc5a0e6b544972e69372c1c620dbff08246d5f;hp=9303f65e641eb1524419ef1417ebf6a8abc9fd53;hpb=5ce2f5c9a18d4b8a9fd7fcc82fea11dc0f2b3d32;p=citadel.git diff --git a/webcit/webcit.c b/webcit/webcit.c index 9303f65e6..d7beab0c3 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -108,6 +108,7 @@ void output_headers( int do_httpheaders, /* 1 = output HTTP headers int suppress_check, /* 1 = suppress check for instant messages */ int cache /* 1 = allow browser to cache this page */ ) { + wcsession *WCC = WC; char cookie[1024]; char httpnow[128]; @@ -115,11 +116,17 @@ void output_headers( int do_httpheaders, /* 1 = output HTTP headers http_datestring(httpnow, sizeof httpnow, time(NULL)); if (do_httpheaders) { - hprintf("Content-type: text/html; charset=utf-8\r\n" - "Server: %s / %s\n" - "Connection: close\r\n", - PACKAGE_STRING, serv_info.serv_software - ); + if (WCC->serv_info != NULL) + hprintf("Content-type: text/html; charset=utf-8\r\n" + "Server: %s / %s\n" + "Connection: close\r\n", + PACKAGE_STRING, + ChrPtr(WCC->serv_info->serv_software)); + else + hprintf("Content-type: text/html; charset=utf-8\r\n" + "Server: %s / [n/a]\n" + "Connection: close\r\n", + PACKAGE_STRING); } if (cache) { @@ -143,8 +150,9 @@ void output_headers( int do_httpheaders, /* 1 = output HTTP headers ); } - stuff_to_cookie(cookie, 1024, WC->wc_session, WC->wc_username, - WC->wc_password, WC->wc_roomname); + stuff_to_cookie(cookie, 1024, + WCC->wc_session, WCC->wc_username, + WCC->wc_password, WCC->wc_roomname); if (unset_cookies) { hprintf("Set-cookie: webcit=%s; path=/\r\n", unset); @@ -158,11 +166,6 @@ void output_headers( int do_httpheaders, /* 1 = output HTTP headers if (do_htmlhead) { begin_burst(); do_template("head", NULL); - } - - /* ICONBAR */ - if (do_htmlhead) { - begin_burst(); /* check for ImportantMessages (these display in a div overlaying the main screen) */ if (!IsEmptyStr(WC->ImportantMessage)) { @@ -171,18 +174,16 @@ void output_headers( int do_httpheaders, /* 1 = output HTTP headers escputs(WC->ImportantMessage); wprintf("
\n" "\n" - "\n"); - WC->ImportantMessage[0] = 0; + ); + StrBufAppendPrintf(WCC->trailing_javascript, + "setTimeout('hide_imsg_popup()', 5000); \n" + ); + WCC->ImportantMessage[0] = 0; } - if ( (WC->logged_in) && (!unset_cookies) ) { - wprintf("
"); - do_selected_iconbar(); - /** check for instant messages (these display in a new window) */ + if ( (WCC->logged_in) && (!unset_cookies) ) { + //DoTemplate(HKEY("iconbar"), NULL, &NoCtx); page_popup(); - wprintf("
"); } if (do_room_banner == 1) { @@ -197,6 +198,13 @@ void output_headers( int do_httpheaders, /* 1 = output HTTP headers } } +void output_custom_content_header(const char *ctype) { + hprintf("HTTP/1.1 200 OK\r\n"); + hprintf("Content-type: %s; charset=utf-8\r\n",ctype); + hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software)); + hprintf("Connection: close\r\n"); +} + /* * Generic function to do an HTTP redirect. Easy and fun. @@ -275,7 +283,7 @@ void print_menu_box(char* Title, char *Class, int nLines, ...) /* * dump out static pages from disk */ -void output_static(char *what) +void output_static(const char *what) { int fd; struct stat statbuf; @@ -338,7 +346,7 @@ void output_static(char *what) * titlebarmsg text to display in the title bar * messagetext body of the box */ -void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext) +void convenience_page(const char *titlebarcolor, const char *titlebarmsg, const char *messagetext) { hprintf("HTTP/1.1 200 OK\n"); output_headers(1, 1, 2, 0, 0, 0); @@ -367,11 +375,11 @@ void blank_page(void) { * A template has been requested */ void url_do_template(void) { + const StrBuf *MimeType; const StrBuf *Tmpl = sbstr("template"); begin_burst(); - output_headers(1, 0, 0, 0, 1, 0); - DoTemplate(ChrPtr(Tmpl), StrLength(Tmpl), NULL, NULL, 0); - end_burst(); + MimeType = DoTemplate(SKEY(Tmpl), NULL, &NoCtx); + http_transmit_thing(ChrPtr(MimeType), 0); } @@ -392,7 +400,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(WC->serv_info->serv_humannode)); hprintf("Content-Type: text/html\r\n"); wprintf("

"); wprintf(_("Authorization Required")); @@ -432,44 +440,54 @@ void end_ajax_response(void) { */ void ajax_servcmd(void) { - char buf[1024]; - char gcontent[1024]; + wcsession *WCC = WC; + int Done = 0; + StrBuf *Buf; char *junk; size_t len; begin_ajax_response(); - - serv_printf("%s", bstr("g_cmd")); - serv_getln(buf, sizeof buf); - wprintf("%s\n", buf); - - if (buf[0] == '8') { - serv_printf("\n\n000"); - } - if ((buf[0] == '1') || (buf[0] == '8')) { - while (serv_getln(gcontent, sizeof gcontent), strcmp(gcontent, "000")) { - wprintf("%s\n", gcontent); + Buf = NewStrBuf(); + serv_puts(bstr("g_cmd")); + StrBuf_ServGetln(Buf); + StrBufAppendBuf(WCC->WBuf, Buf, 0); + StrBufAppendBufPlain(WCC->WBuf, HKEY("\n"), 0); + + switch (GetServerStatus(Buf, NULL)) { + case 8: + serv_puts("\n\n000"); + if ( (StrLength(Buf)==3) && + !strcmp(ChrPtr(Buf), "000")) { + StrBufAppendBufPlain(WCC->WBuf, HKEY("\000"), 0); + break; } - wprintf("000"); - } - if (buf[0] == '4') { + case 1: + while (!Done) { + StrBuf_ServGetlnBuffered(Buf); + if ( (StrLength(Buf)==3) && + !strcmp(ChrPtr(Buf), "000")) { + Done = 1; + } + StrBufAppendBuf(WCC->WBuf, Buf, 0); + StrBufAppendBufPlain(WCC->WBuf, HKEY("\n"), 0); + } + break; + case 4: text_to_server(bstr("g_input")); serv_puts("000"); - } - if (buf[0] == '6') { - len = atol(&buf[4]); - junk = malloc(len); - serv_read(junk, len); - free(junk); - } - if (buf[0] == '7') { - len = atol(&buf[4]); + break; + case 6: + len = atol(&ChrPtr(Buf)[4]); + StrBuf_ServGetBLOBBuffered(Buf, len); + break; + case 7: + len = atol(&ChrPtr(Buf)[4]); junk = malloc(len); memset(junk, 0, len); serv_write(junk, len); free(junk); } - + end_ajax_response(); /* @@ -479,8 +497,9 @@ void ajax_servcmd(void) * that page_popup() doesn't try to open it a second time. */ if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) { - WC->last_pager_check = time(NULL); + WCC->last_pager_check = time(NULL); } + FreeStrBuf(&Buf); } @@ -496,7 +515,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] == '*') { @@ -521,7 +540,7 @@ int is_mobile_ua(char *user_agent) { } else if (strstr(user_agent, "Opera Mobi") != NULL) { return 1; } else if (strstr(user_agent, "Firefox/2.0.0 Opera 9.51 Beta") != NULL) { - // For some reason a new install of Opera 9.51beta decided to spoof. + /* For some reason a new install of Opera 9.51beta decided to spoof. */ return 1; } return 0; @@ -531,8 +550,13 @@ int is_mobile_ua(char *user_agent) { /* * Entry point for WebCit transaction */ -void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method, StrBuf *ReadBuf) +void session_loop(HashList *HTTPHeaders, + StrBuf *ReqLine, + StrBuf *request_method, + StrBuf *ReadBuf, + const char **Pos) { + StrBuf *Buf; const char *pch, *pchs, *pche; void *vLine; char action[1024]; @@ -546,7 +570,7 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method StrBuf *UrlLine = NULL; StrBuf *content = NULL; const char *content_end = NULL; - char browser_host[256]; + StrBuf *browser_host = NULL; char user_agent[256]; int body_start = 0; int is_static = 0; @@ -554,26 +578,30 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method int len = 0; void *vHandler; WebcitHandler *Handler; + struct timeval tx_start; + struct timeval tx_finish; /* * 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; + + gettimeofday(&tx_start, NULL); /* start a stopwatch for performance timing */ - 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); - strcpy(browser_host, ""); + c_httpauth_user = NewStrBufPlain(HKEY(DEFAULT_HTTPAUTH_USER)); + c_httpauth_pass = NewStrBufPlain(HKEY(DEFAULT_HTTPAUTH_PASS)); WCC= WC; if (WCC->WBuf == NULL) @@ -588,6 +616,7 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method WCC->upload = NULL; WCC->is_mobile = 0; WCC->trailing_javascript = NewStrBuf(); + WCC->nWildfireHeaders = 0; /** Figure out the action */ index[0] = action; @@ -597,7 +626,6 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method index[a] = arg[a-1]; sizes[a] = sizeof arg[a-1]; } -//// index[9] = &foo; todo nBackDots = 0; nEmpty = 0; for ( a = 0; a < 9; ++a) @@ -616,15 +644,15 @@ 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)) { - 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); + StrBufDecodeBase64((StrBuf*)vLine); + StrBufExtract_token(c_httpauth_user, (StrBuf*)vLine, 0, ':'); + StrBufExtract_token(c_httpauth_pass, (StrBuf*)vLine, 1, ':'); } if (GetHash(HTTPHeaders, HKEY("CONTENT-LENGTH"), &vLine) && (vLine!=NULL)) { @@ -649,27 +677,22 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method if ((follow_xff) && GetHash(HTTPHeaders, HKEY("X-FORWARDED-HOST"), &vLine) && (vLine != NULL)) { - safestrncpy(WCC->http_host, - ChrPtr((StrBuf*)vLine), - sizeof WCC->http_host); + WCC->http_host = (StrBuf*)vLine; } - if (IsEmptyStr(WCC->http_host) && + if ((StrLength(WCC->http_host) == 0) && GetHash(HTTPHeaders, HKEY("HOST"), &vLine) && (vLine!=NULL)) { - safestrncpy(WCC->http_host, - ChrPtr((StrBuf*)vLine), - sizeof WCC->http_host); - + WCC->http_host = (StrBuf*)vLine; } + if (GetHash(HTTPHeaders, HKEY("X-FORWARDED-FOR"), &vLine) && (vLine!=NULL)) { - safestrncpy(browser_host, - ChrPtr((StrBuf*) vLine), - sizeof browser_host); - while (num_tokens(browser_host, ',') > 1) { - remove_token(browser_host, 0, ','); + browser_host = (StrBuf*) vLine; + + while (StrBufNum_tokens(browser_host, ',') > 1) { + StrBufRemove_token(browser_host, 0, ','); } - striplt(browser_host); + StrBufTrim(browser_host); } if (ContentLength > 0) { @@ -685,7 +708,11 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method body_start = StrLength(content); /** Read the entire input data at once. */ - client_read(&WCC->http_sock, content, ReadBuf, ContentLength + body_start); + client_read_to(&WCC->http_sock, + content, + ReadBuf, Pos, + ContentLength, + SLEEPING); if (!strncasecmp(ChrPtr(ContentType), "application/x-www-form-urlencoded", 33)) { StrBufCutLeft(content, body_start); @@ -699,9 +726,9 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method } /* make a note of where we are in case the user wants to save it */ - safestrncpy(WCC->this_page, ChrPtr(ReqLine), sizeof(WCC->this_page)); - remove_token(WCC->this_page, 2, ' '); - remove_token(WCC->this_page, 0, ' '); + WCC->this_page = NewStrBufDup(ReqLine); + StrBufRemove_token(WCC->this_page, 2, ' '); + StrBufRemove_token(WCC->this_page, 0, ' '); /* If there are variables in the URL, we must grab them now */ UrlLine = NewStrBufDup(ReqLine); @@ -757,7 +784,7 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method { lprintf(9, "Suspicious request. Ignoring."); hprintf("HTTP/1.1 404 Security check failed\r\n"); - hprintf("Content-Type: text/plain\r\n"); + hprintf("Content-Type: text/plain\r\n\r\n"); wprintf("You have sent a malformed or invalid request.\r\n"); end_burst(); } @@ -771,7 +798,7 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method if (ibstr("nonce") != WCC->nonce) { lprintf(9, "Ignoring request with mismatched nonce.\n"); hprintf("HTTP/1.1 404 Security check failed\r\n"); - hprintf("Content-Type: text/plain\r\n"); + hprintf("Content-Type: text/plain\r\n\r\n"); wprintf("Security check failed.\r\n"); end_burst(); goto SKIP_ALL_THIS_CRAP; @@ -783,6 +810,8 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method * connection now. */ if (!WCC->connected) { + if (WCC->ReadBuf == NULL) + WCC->ReadBuf = NewStrBuf(); if (!strcasecmp(ctdlhost, "uds")) { /* unix domain socket */ snprintf(buf, SIZ, "%s/citadel.socket", ctdlport); @@ -795,42 +824,68 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method if (WCC->serv_sock < 0) { do_logout(); + FreeStrBuf(&WCC->ReadBuf); goto SKIP_ALL_THIS_CRAP; } else { WCC->connected = 1; - serv_getln(buf, sizeof buf); /** get the server welcome message */ + serv_getln(buf, sizeof buf); /* get the server greeting */ - /** + /* Are there too many users already logged in? */ + if (!strncmp(buf, "571", 3)) { + wprintf(_("This server is already serving its maximum number of users and cannot accept any additional logins at this time. Please try again later or contact your system administrator.")); + end_burst(); + end_webcit_session(); + goto SKIP_ALL_THIS_CRAP; + } + + /* * From what host is our user connecting? Go with * the host at the other end of the HTTP socket, * unless we are following X-Forwarded-For: headers * and such a header has already turned up something. */ - if ( (!follow_xff) || (strlen(browser_host) == 0) ) { + if ( (!follow_xff) || (StrLength(browser_host) == 0) ) { + if (browser_host == NULL) { + browser_host = NewStrBuf(); + Put(HTTPHeaders, HKEY("FreeMeWithTheOtherHeaders"), + browser_host, HFreeStrBuf); + } locate_host(browser_host, WCC->http_sock); } - - get_serv_info(browser_host, user_agent); - if (serv_info.serv_rev_level < MINIMUM_CIT_VERSION) { + if (WCC->serv_info == NULL) + WCC->serv_info = get_serv_info(browser_host, user_agent); + if (WCC->serv_info == NULL){ + begin_burst(); + wprintf(_("Received unexpected answer from Citadel " + "server; bailing out.")); + hprintf("HTTP/1.1 200 OK\r\n"); + hprintf("Content-type: text/plain; charset=utf-8\r\n"); + end_burst(); + end_webcit_session(); + goto SKIP_ALL_THIS_CRAP; + } + if (WCC->serv_info->serv_rev_level < MINIMUM_CIT_VERSION) { begin_burst(); wprintf(_("You are connected to a Citadel " "server running Citadel %d.%02d. \n" "In order to run this version of WebCit " "you must also have Citadel %d.%02d or" " newer.\n\n\n"), - serv_info.serv_rev_level / 100, - serv_info.serv_rev_level % 100, + WCC->serv_info->serv_rev_level / 100, + WCC->serv_info->serv_rev_level % 100, MINIMUM_CIT_VERSION / 100, MINIMUM_CIT_VERSION % 100 ); + hprintf("HTTP/1.1 200 OK\r\n"); + hprintf("Content-type: text/plain; charset=utf-8\r\n"); end_burst(); end_webcit_session(); goto SKIP_ALL_THIS_CRAP; } } } -////////todo: restore language in this case + /* * Functions which can be performed without logging in */ @@ -848,21 +903,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; } } @@ -871,7 +939,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 @@ -911,33 +979,43 @@ 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') { - StrBuf *Lang; - become_logged_in(c_username, c_password, buf); - if (get_preference("language", &Lang)) { - set_selected_language(ChrPtr(Lang)); - go_selected_language(); /* set locale */ - } + && (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) { + become_logged_in(c_username, c_password, Buf); get_preference("default_header_charset", &WCC->DefaultCharset); } } } + + /* + * If a 'gotofirst' parameter has been specified, attempt to goto that room + * prior to doing anything else. + */ + if (havebstr("gotofirst")) { + 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); + } } } @@ -955,9 +1033,12 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method WCC->UrlFragment2 = NewStrBuf(); if (WCC->UrlFragment3 == NULL) WCC->UrlFragment3 = NewStrBuf(); - StrBufPrintf(WCC->UrlFragment1, "%s", index[0]); - StrBufPrintf(WCC->UrlFragment2, "%s", index[1]); - StrBufPrintf(WCC->UrlFragment3, "%s", index[2]); + if (WCC->UrlFragment4 == NULL) + WCC->UrlFragment4 = NewStrBuf(); + StrBufPlain(WCC->UrlFragment1, index[0], -1); + StrBufPlain(WCC->UrlFragment2, index[1], -1); + StrBufPlain(WCC->UrlFragment3, index[2], -1); + StrBufPlain(WCC->UrlFragment4, index[3], -1); } if ((Handler->Flags & AJAX) != 0) begin_ajax_response(); @@ -975,6 +1056,17 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method } SKIP_ALL_THIS_CRAP: + if (WCC->SavePrefsToServer) { + save_preferences(); + WCC->SavePrefsToServer = 0; + } + FreeStrBuf(&Buf); + FreeStrBuf(&c_username); + FreeStrBuf(&c_password); + FreeStrBuf(&c_roomname); + FreeStrBuf(&c_httpauth_user); + FreeStrBuf(&c_httpauth_pass); + FreeStrBuf(&WCC->this_page); fflush(stdout); if (content != NULL) { FreeStrBuf(&content); @@ -986,6 +1078,15 @@ SKIP_ALL_THIS_CRAP: WCC->upload_length = 0; } FreeStrBuf(&WCC->trailing_javascript); + WCC->http_host = NULL; + + /* How long did this transaction take? */ + gettimeofday(&tx_finish, NULL); + + lprintf(9, "Transaction completed in %ld.%06ld seconds.\n", + ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) / 1000000, + ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) % 1000000 + ); } @@ -1002,7 +1103,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) @@ -1011,7 +1112,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; @@ -1025,16 +1126,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, @@ -1056,6 +1156,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); }