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];
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,
- ChrPtr(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) {
}
stuff_to_cookie(cookie, 1024,
- WC->wc_session, WC->wc_username,
- WC->wc_password, WC->wc_roomname);
+ WCC->wc_session, WCC->wc_username,
+ WCC->wc_password, WCC->wc_roomname);
if (unset_cookies) {
hprintf("Set-cookie: webcit=%s; path=/\r\n", unset);
escputs(WC->ImportantMessage);
wprintf("</span><br />\n"
"</div>\n"
- "<script type=\"text/javascript\">\n"
- " setTimeout('hide_imsg_popup()', 5000); \n"
- "</script>\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("<div id=\"iconbar\">");
- 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("</div>");
}
if (do_room_banner == 1) {
}
}
+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.
* 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(SKEY(Tmpl), NULL, &NoCtx);
- end_burst();
+ output_headers(0, 0, 0, 0, 1, 0);
+ MimeType = DoTemplate(SKEY(Tmpl), NULL, &NoCtx);
+ http_transmit_thing(ChrPtr(MimeType), 0);
}
void authorization_required(const char *message)
{
hprintf("HTTP/1.1 401 Authorization Required\r\n");
- hprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n", ChrPtr(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("<h1>");
wprintf(_("Authorization Required"));
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;
safestrncpy(c_httpauth_string, "", sizeof c_httpauth_string);
c_httpauth_user = NewStrBufPlain(HKEY(DEFAULT_HTTPAUTH_USER));
c_httpauth_pass = NewStrBufPlain(HKEY(DEFAULT_HTTPAUTH_PASS));
- strcpy(browser_host, "");
WCC= WC;
if (WCC->WBuf == NULL)
WCC->upload = NULL;
WCC->is_mobile = 0;
WCC->trailing_javascript = NewStrBuf();
+ WCC->nWildfireHeaders = 0;
/** Figure out the action */
index[0] = action;
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)
}
if (GetHash(HTTPHeaders, HKEY("AUTHORIZATION"), &vLine) &&
(vLine!=NULL)) {
-/* TODO: wrap base64 in strbuf */
- CtdlDecodeBase64(c_httpauth_string, ChrPtr((StrBuf*)vLine), StrLength((StrBuf*)vLine));
- FlushStrBuf(Buf);
- StrBufAppendBufPlain(Buf, c_httpauth_string, -1, 0);
- StrBufExtract_token(c_httpauth_user, Buf, 0, ':');
- StrBufExtract_token(c_httpauth_pass, Buf, 1, ':');
+ 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)) {
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) {
}
/* 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);
* connection now.
*/
if (!WCC->connected) {
+ WCC->ReadBuf = NewStrBuf();
if (!strcasecmp(ctdlhost, "uds")) {
/* unix domain socket */
snprintf(buf, SIZ, "%s/citadel.socket", ctdlport);
}
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->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
);
}
}
}
-/*///////todo: restore language in this case */
+
/*
* Functions which can be performed without logging in
*/
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);
- if (get_preference("language", &Lang)) {
- set_selected_language(ChrPtr(Lang));
- go_selected_language(); /* set locale */
- }
get_preference("default_header_charset", &WCC->DefaultCharset);
}
}
}
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);
WCC->upload_length = 0;
}
FreeStrBuf(&WCC->trailing_javascript);
+ WCC->http_host = NULL;
}