+ static char serv_sock_name[PATH_MAX] = "";
+ if (IsEmptyStr(serv_sock_name)) {
+ snprintf(serv_sock_name, sizeof serv_sock_name, "%s/citadel.socket", ctdl_dir);
+ }
+ WC->serv_sock = connect_to_citadel(serv_sock_name);
+
+ if (WC->serv_sock < 0) {
+ WC->connected = 0;
+ FreeStrBuf(&WC->ReadBuf);
+ return 1;
+ }
+ else {
+ long Status;
+ int short_status;
+ Buf = NewStrBuf();
+ WC->connected = 1;
+ StrBuf_ServGetln(Buf); // get the server greeting
+ short_status = GetServerStatus(Buf, &Status);
+ FreeStrBuf(&Buf);
+
+ // Server isn't ready for us?
+ if (short_status != 2) {
+ if (Status == 551) {
+ hprintf("HTTP/1.1 503 Service Unavailable\r\n");
+ hprintf("Content-type: text/plain; charset=utf-8\r\n");
+ wc_printf(_("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."));
+ }
+ else {
+ wc_printf("%ld %s\n",
+ Status,
+ _("Received unexpected answer from Citadel server; bailing out.")
+ );
+ hprintf("HTTP/1.1 502 Bad Gateway\r\n");
+ hprintf("Content-type: text/plain; charset=utf-8\r\n");
+ }
+ end_burst();
+ end_webcit_session();
+ return 1;
+ }
+
+ // 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) || (StrLength(WC->Hdr->HR.browser_host) == 0) ) {
+ if (WC->Hdr->HR.browser_host == NULL) {
+ WC->Hdr->HR.browser_host = NewStrBuf();
+ Put(WC->Hdr->HTTPHeaders, HKEY("FreeMeWithTheOtherHeaders"),
+ WC->Hdr->HR.browser_host, HFreeStrBuf);
+ }
+ locate_host(WC->Hdr->HR.browser_host, WC->Hdr->http_sock);
+ }
+ if (WC->serv_info == NULL) {
+ WC->serv_info = get_serv_info(WC->Hdr->HR.browser_host, WC->Hdr->HR.user_agent);
+ }
+ if (WC->serv_info == NULL){
+ begin_burst();
+ wc_printf(_("Received unexpected answer from Citadel server; bailing out."));
+ hprintf("HTTP/1.1 502 Bad Gateway\r\n");
+ hprintf("Content-type: text/plain; charset=utf-8\r\n");
+ end_burst();
+ end_webcit_session();
+ return 1;
+ }
+ if (WC->serv_info->serv_rev_level < MINIMUM_CIT_VERSION) {
+ begin_burst();
+ wc_printf(_("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"),
+ WC->serv_info->serv_rev_level,
+ 0,
+ MINIMUM_CIT_VERSION,
+ 0
+ );
+ hprintf("HTTP/1.1 200 OK\r\n");
+ hprintf("Content-type: text/plain; charset=utf-8\r\n");
+ end_burst();
+ end_webcit_session();
+ return 1;
+ }
+ SetInlinMimeRenderers();
+ }
+ return 0;