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];
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(WCC->serv_info->serv_software)
);
}
);
}
- 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);
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)) {
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(ChrPtr(Tmpl), StrLength(Tmpl), NULL, NULL, 0);
- 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", 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"));
wprintf("NO\n");
}
else {
- memset(buf, 5, 0);
+ memset(buf, 0, 5);
serv_puts("NOOP");
serv_getln(buf, sizeof buf);
if (buf[3] == '*') {
} 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;
*/
void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method, StrBuf *ReadBuf)
{
+ StrBuf *Buf;
const char *pch, *pchs, *pche;
void *vLine;
char action[1024];
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;
* 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);
- 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)
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
+/*/// index[9] = &foo; todo */
nBackDots = 0;
nEmpty = 0;
for ( a = 0; a < 9; ++a)
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)) {
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);
{
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();
}
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;
}
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) {
+ 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
+/*///////todo: restore language in this case */
/*
* Functions which can be performed without logging in
*/
* 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;
}
}
/* 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
* 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 */
}
}
}
+
+ /*
+ * 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);
+ }
}
}
}
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;
}
}
-int ConditionalImportantMesage(WCTemplateToken *Tokens, void *Context, int ContextType)
+int ConditionalImportantMesage(StrBuf *Target, WCTemplputParams *TP)
{
wcsession *WCC = WC;
if (WCC != NULL)
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;
}
}
-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,
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);
}