static void TestEncodeEmail(void) { StrBuf *Target; StrBuf *Source; StrBuf *UserName = NewStrBuf(); StrBuf *EmailAddress = NewStrBuf(); StrBuf *EncBuf = NewStrBuf(); Source = NewStrBuf(); // Source = NewStrBufPlain(HKEY("Art Cancro <*****@*****.**>, Art Cancro <*****@*****.**>")); Source = NewStrBufPlain(HKEY("\"Alexandra Weiz, Restless GmbH\" <*****@*****.**>, \"NetIN\" <*****@*****.**>, \" יריב ברקאי, מולטימדי\" <*****@*****.**>")); Target = StrBufSanitizeEmailRecipientVector( Source, UserName, EmailAddress, EncBuf ); TestRevalidateStrBuf(Target); printf("the source:>%s<\n", ChrPtr(Source)); printf("the target:>%s<\n", ChrPtr(Target)); FreeStrBuf(&Target); FreeStrBuf(&UserName); FreeStrBuf(&EmailAddress); FreeStrBuf(&EncBuf); FreeStrBuf(&Source); }
/* * Attempt to attach an OpenID to an existing, logged-in account */ void openid_attach(void) { char buf[4096]; if (havebstr("attach_button")) { syslog(LOG_DEBUG, "Attempting to attach %s\n", bstr("openid_url")); snprintf(buf, sizeof buf, "OIDS %s|%s/finalize_openid_login?attach_existing=1|%s", bstr("openid_url"), ChrPtr(site_prefix), ChrPtr(site_prefix) ); serv_puts(buf); serv_getln(buf, sizeof buf); if (buf[0] == '2') { syslog(LOG_DEBUG, "OpenID server contacted; redirecting to %s\n", &buf[4]); http_redirect(&buf[4]); return; } else { syslog(LOG_DEBUG, "OpenID attach failed: %s\n", &buf[4]); } } /* If we get to this point then something failed. */ display_openids(); }
static void TestEncodeEmailSTDIN(void) { int fdin = 0;// STDIN const char *Err; StrBuf *Target; StrBuf *Source; StrBuf *UserName = NewStrBuf(); StrBuf *EmailAddress = NewStrBuf(); StrBuf *EncBuf = NewStrBuf(); Source = NewStrBuf(); while (fdin == 0) { StrBufTCP_read_line(Source, &fdin, 0, &Err); printf("the source:>%s<\n", ChrPtr(Source)); Target = StrBufSanitizeEmailRecipientVector( Source, UserName, EmailAddress, EncBuf ); TestRevalidateStrBuf(Target); printf("the target:>%s<\n", ChrPtr(Target)); FreeStrBuf(&Target); } FreeStrBuf(&UserName); FreeStrBuf(&EmailAddress); FreeStrBuf(&EncBuf); FreeStrBuf(&Source); }
eNextState SMTPC_read_EHLO_reply(SmtpOutMsg *Msg) { AsyncIO *IO = &Msg->IO; SMTP_DBG_READ(); if (SMTP_IS_STATE('2')) { READ_NEXT_STATE(eSMTPAuth); if ((Msg->pCurrRelay == NULL) || (Msg->pCurrRelay->User == NULL)) READ_NEXT_STATE(eFROM); /* Skip auth... */ if (Msg->pCurrRelay != NULL) { if (strstr(ChrPtr(Msg->IO.IOBuf), "LOGIN") != NULL) Msg->SendLogin = 1; else if ((Msg->MultiLineBuf != NULL) && strstr(ChrPtr(Msg->MultiLineBuf), "LOGIN") != NULL) { Msg->SendLogin = 1; } } } /* else we fall back to 'helo' */ return eSendReply; }
/* * Authorization required page (sends a 401, causing the browser to request login credentials) */ void authorization_required(void) { wcsession *WCC = WC; const char *message = ""; hprintf("HTTP/1.1 401 Authorization Required\r\n"); hprintf( "Server: %s / %s\r\n" "Connection: close\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software) ); hprintf("WWW-Authenticate: Basic realm=\"%s\"\r\n", ChrPtr(WC->serv_info->serv_humannode)); /* if this is a false cookie authentication, remove it to avoid endless loops. */ if (StrLength(WCC->Hdr->HR.RawCookie) > 0) stuff_to_cookie(1); hprintf("Content-Type: text/html\r\n"); begin_burst(); wc_printf("<h1>"); wc_printf(_("Authorization Required")); wc_printf("</h1>\r\n"); if (WCC->ImportantMsg != NULL) { message = ChrPtr(WCC->ImportantMsg); } wc_printf( _("The resource you requested requires a valid username and password. " "You could not be logged in: %s\n"), message ); wDumpContent(0); }
// upload the picture (icon, photo, whatever) associated with the current room void common_code_for_editroompic_and_editpic(char *servcmd) { if (havebstr("cancel_button")) { AppendImportantMessage(_("Graphics upload has been cancelled."), -1); display_main_menu(); return; } if (WC->upload_length == 0) { AppendImportantMessage(_("You didn't upload a file."), -1); display_main_menu(); return; } serv_printf("%s %ld|%s", servcmd, (long)WC->upload_length, GuessMimeType(ChrPtr(WC->upload), WC->upload_length)); StrBuf *Line = NewStrBuf(); StrBuf_ServGetln(Line); if (GetServerStatusMsg(Line, NULL, 0, 0) == 7) { serv_write(ChrPtr(WC->upload), WC->upload_length); display_success(ChrPtr(Line) + 4); } else { AppendImportantMessage((ChrPtr(Line) + 4), -1); display_main_menu(); } FreeStrBuf(&Line); }
eNextState POP3C_GetOneMessageIDState(pop3aggr *RecvMsg) { AsyncIO *IO = &RecvMsg->IO; #if 0 int rc; rc = TestValidateHash(RecvMsg->MsgNumbers); if (rc != 0) EVP3CCS_syslog(LOG_DEBUG, "Hash Invalid: %d\n", rc); #endif POP3C_DBG_READ(); if (!POP3C_OK) return eTerminateConnection; RecvMsg->CurrMsg->MsgUIDL = NewStrBufPlain(NULL, StrLength(RecvMsg->IO.IOBuf)); RecvMsg->CurrMsg->MsgUID = NewStrBufPlain(NULL, StrLength(RecvMsg->IO.IOBuf) * 2); StrBufExtract_token(RecvMsg->CurrMsg->MsgUIDL, RecvMsg->IO.IOBuf, 2, ' '); StrBufPrintf(RecvMsg->CurrMsg->MsgUID, "pop3/%s/%s:%s@%s", ChrPtr(RecvMsg->RoomName), ChrPtr(RecvMsg->CurrMsg->MsgUIDL), RecvMsg->IO.ConnectMe->User, RecvMsg->IO.ConnectMe->Host); RecvMsg->State --; return eSendReply; }
/* * Go to the URL saved by push_destination() */ void pop_destination(void) { wcsession *WCC = WC; /* * If we are in the middle of a new user signup, the server may request that * we first pass through a registration screen. */ if ((WCC) && (WCC->need_regi)) { if ((WCC->PushedDestination != NULL) && (StrLength(WCC->PushedDestination) > 0)) { /* Registering will take us to the My Citadel Config room, so save our place */ StrBufAppendBufPlain(WCC->PushedDestination, HKEY("?go="), 0); StrBufUrlescAppend(WCC->PushedDestination, WCC->CurRoom.name, NULL); } WCC->need_regi = 0; display_reg(1); return; } /* * Do something reasonable if we somehow ended up requesting a pop without * having first done a push. */ if ( (!WCC) || (WCC->PushedDestination == NULL) || (StrLength(WCC->PushedDestination) == 0) ) { do_welcome(); return; } /* * All righty then! We have a destination saved, so go there now. */ if (verbose) syslog(LOG_DEBUG, "Pop: %s", ChrPtr(WCC->PushedDestination)); http_redirect(ChrPtr(WCC->PushedDestination)); }
/** * this one has to have the context for loading the message via the redirect buffer... */ StrBuf *smtp_load_msg(OneQueItem *MyQItem, int n, char **Author, char **Address) { CitContext *CCC=CC; StrBuf *SendMsg; CCC->redirect_buffer = NewStrBufPlain(NULL, SIZ); CtdlOutputMsg(MyQItem->MessageID, MT_RFC822, HEADERS_ALL, 0, 1, NULL, (ESC_DOT|SUPPRESS_ENV_TO), Author, Address, NULL); SendMsg = CCC->redirect_buffer; CCC->redirect_buffer = NULL; if ((StrLength(SendMsg) > 0) && ChrPtr(SendMsg)[StrLength(SendMsg) - 1] != '\n') { SMTPC_syslog(LOG_WARNING, "[%d] Possible problem: message did not " "correctly terminate. (expecting 0x10, got 0x%02x)\n", MsgCount, //yes uncool, but best choice here... ChrPtr(SendMsg)[StrLength(SendMsg) - 1] ); StrBufAppendBufPlain(SendMsg, HKEY("\r\n"), 0); } return SendMsg; }
eNextState POP3C_GetListOneLine(pop3aggr *RecvMsg) { AsyncIO *IO = &RecvMsg->IO; #if 0 int rc; #endif const char *pch; FetchItem *OneMsg = NULL; POP3C_DBG_READ(); if ((StrLength(RecvMsg->IO.IOBuf) == 1) && (ChrPtr(RecvMsg->IO.IOBuf)[0] == '.')) { if (GetCount(RecvMsg->MsgNumbers) == 0) { //// RecvMsg->Sate = ReadQuitState; } else { RecvMsg->Pos = GetNewHashPos(RecvMsg->MsgNumbers, 0); } return eSendReply; } /* * work around buggy pop3 servers which send * empty lines in their listings. */ if ((StrLength(RecvMsg->IO.IOBuf) == 0) || !isdigit(ChrPtr(RecvMsg->IO.IOBuf)[0])) { return eReadMore; } OneMsg = (FetchItem*) malloc(sizeof(FetchItem)); memset(OneMsg, 0, sizeof(FetchItem)); OneMsg->MSGID = atol(ChrPtr(RecvMsg->IO.IOBuf)); pch = strchr(ChrPtr(RecvMsg->IO.IOBuf), ' '); if (pch != NULL) { OneMsg->MSGSize = atol(pch + 1); } #if 0 rc = TestValidateHash(RecvMsg->MsgNumbers); if (rc != 0) EVP3CCS_syslog(LOG_DEBUG, "Hash Invalid: %d\n", rc); #endif Put(RecvMsg->MsgNumbers, LKEY(OneMsg->MSGID), OneMsg, HfreeFetchItem); #if 0 rc = TestValidateHash(RecvMsg->MsgNumbers); if (rc != 0) EVP3CCS_syslog(LOG_DEBUG, "Hash Invalid: %d\n", rc); #endif //RecvMsg->State --; /* read next Line */ return eReadMore; }
void SerializeNode(NodeConf *Node, StrBuf *Buf) { StrBufPrintf(Buf, "%s|%s|%s|%s", ChrPtr(Node->NodeName), ChrPtr(Node->Secret), ChrPtr(Node->Host), ChrPtr(Node->Port)); }
void do_graphics_upload(char *filename) { StrBuf *Line; const char *MimeType; wcsession *WCC = WC; int bytes_remaining; int pos = 0; int thisblock; bytes_remaining = WCC->upload_length; if (havebstr("cancel_button")) { AppendImportantMessage(_("Graphics upload has been cancelled."), -1); display_main_menu(); return; } if (WCC->upload_length == 0) { AppendImportantMessage(_("You didn't upload a file."), -1); display_main_menu(); return; } MimeType = GuessMimeType(ChrPtr(WCC->upload), bytes_remaining); serv_printf("UIMG 1|%s|%s", MimeType, filename); Line = NewStrBuf(); StrBuf_ServGetln(Line); if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) { display_main_menu(); FreeStrBuf(&Line); return; } while (bytes_remaining) { thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining); serv_printf("WRIT %d", thisblock); StrBuf_ServGetln(Line); if (GetServerStatusMsg(Line, NULL, 1, 7) != 7) { serv_puts("UCLS 0"); StrBuf_ServGetln(Line); display_main_menu(); FreeStrBuf(&Line); return; } thisblock = extract_int(ChrPtr(Line) +4, 0); serv_write(&ChrPtr(WCC->upload)[pos], thisblock); pos += thisblock; bytes_remaining -= thisblock; } serv_puts("UCLS 1"); StrBuf_ServGetln(Line); if (*ChrPtr(Line) != 'x') { display_success(ChrPtr(Line) + 4); } FreeStrBuf(&Line); }
eNextState evcurl_handle_start(AsyncIO *IO) { CURLMcode msta; CURLcode sta; CURL *chnd; SetEVState(IO, eCurlStart); chnd = IO->HttpReq.chnd; EVCURL_syslog(LOG_DEBUG, "EVCURL: Loading URL: %s\n", IO->ConnectMe->PlainUrl); OPT(URL, IO->ConnectMe->PlainUrl); if (StrLength(IO->ConnectMe->CurlCreds)) { OPT(HTTPAUTH, (long)CURLAUTH_BASIC); OPT(USERPWD, ChrPtr(IO->ConnectMe->CurlCreds)); } if (StrLength(IO->HttpReq.PostData) > 0) { OPT(POSTFIELDS, ChrPtr(IO->HttpReq.PostData)); OPT(POSTFIELDSIZE, StrLength(IO->HttpReq.PostData)); } else if ((IO->HttpReq.PlainPostDataLen != 0) && (IO->HttpReq.PlainPostData != NULL)) { OPT(POSTFIELDS, IO->HttpReq.PlainPostData); OPT(POSTFIELDSIZE, IO->HttpReq.PlainPostDataLen); } OPT(HTTPHEADER, IO->HttpReq.headers); IO->NextState = eConnect; EVCURLM_syslog(LOG_DEBUG, "EVCURL: attaching to curl multi handle\n"); msta = curl_multi_add_handle(global.mhnd, IO->HttpReq.chnd); if (msta) { EVCURL_syslog(LOG_ERR, "EVCURL: error attaching to curl multi handle: %s\n", curl_multi_strerror(msta)); } IO->HttpReq.attached = 1; ev_async_send (event_base, &WakeupCurl); ev_cleanup_init(&IO->abort_by_shutdown, IOcurl_abort_shutdown_callback); ev_cleanup_start(event_base, &IO->abort_by_shutdown); return eReadMessage; }
wcsession *FindSession(wcsession **wclist, ParsedHttpHdrs *Hdr, pthread_mutex_t *ListMutex) { wcsession *sptr = NULL; wcsession *TheSession = NULL; if (Hdr->HR.got_auth == AUTH_BASIC) { GetAuthBasic(Hdr); } CtdlLogResult(pthread_mutex_lock(ListMutex)); for (sptr = *wclist; ((sptr != NULL) && (TheSession == NULL)); sptr = sptr->next) { /* If HTTP-AUTH, look for a session with matching credentials */ switch (Hdr->HR.got_auth) { case AUTH_BASIC: if ( (!strcasecmp(ChrPtr(Hdr->c_username), ChrPtr(sptr->wc_username))) && (!strcasecmp(ChrPtr(Hdr->c_password), ChrPtr(sptr->wc_password))) && (sptr->killthis == 0) ) { if (verbose) syslog(LOG_DEBUG, "Matched a session with the same http-auth"); TheSession = sptr; } break; case AUTH_COOKIE: /* If cookie-session, look for a session with matching session ID */ if ( (Hdr->HR.desired_session != 0) && (sptr->wc_session == Hdr->HR.desired_session) ) { if (verbose) syslog(LOG_DEBUG, "Matched a session with the same cookie"); TheSession = sptr; } break; case NO_AUTH: /* Any unbound session is a candidate */ if ( (sptr->wc_session == 0) && (sptr->inuse == 0) ) { if (verbose) syslog(LOG_DEBUG, "Reusing an unbound session"); TheSession = sptr; } break; } } CtdlLogResult(pthread_mutex_unlock(ListMutex)); if (TheSession == NULL) { syslog(LOG_DEBUG, "No existing session was matched"); } return TheSession; }
int ReadPostData(void) { int rc; int urlencoded_post = 0; wcsession *WCC = WC; StrBuf *content = NULL; urlencoded_post = (strncasecmp(ChrPtr(WCC->Hdr->HR.ContentType), "application/x-www-form-urlencoded", 33) == 0) ; content = NewStrBufPlain(NULL, WCC->Hdr->HR.ContentLength + 256); if (!urlencoded_post) { StrBufPrintf(content, "Content-type: %s\n" "Content-length: %ld\n\n", ChrPtr(WCC->Hdr->HR.ContentType), WCC->Hdr->HR.ContentLength); } /** Read the entire input data at once. */ rc = client_read_to(WCC->Hdr, content, WCC->Hdr->HR.ContentLength, SLEEPING); if (rc < 0) return rc; if (urlencoded_post) { ParseURLParams(content); } else if (!strncasecmp(ChrPtr(WCC->Hdr->HR.ContentType), "multipart", 9)) { char *Buf; char *BufEnd; long len; len = StrLength(content); Buf = SmashStrBuf(&content); BufEnd = Buf + len; mime_parser(Buf, BufEnd, *upload_handler, NULL, NULL, NULL, 0); free(Buf); } else if (WCC->Hdr->HR.ContentLength > 0) { WCC->upload = content; WCC->upload_length = StrLength(WCC->upload); content = NULL; } FreeStrBuf(&content); return 1; }
/* * modify an existing node */ void display_edit_node(void) { WCTemplputParams SubTP; HashList *NodeConfig; const StrBuf *Index; void *vNode; const StrBuf *Tmpl; Index = sbstr("index"); if (Index == NULL) { AppendImportantMessage(_("Invalid Parameter"), -1); url_do_template(); return; } NodeConfig = load_netconf(NULL, &NoCtx); if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || (vNode == NULL)) { AppendImportantMessage(_("Invalid Parameter"), -1); url_do_template(); DeleteHash(&NodeConfig); return; } StackContext(NULL, &SubTP, vNode, CTX_NODECONF, 0, NULL); { begin_burst(); Tmpl = sbstr("template"); output_headers(1, 0, 0, 0, 1, 0); DoTemplate(SKEY(Tmpl), NULL, &SubTP); end_burst(); } UnStackContext(&SubTP); DeleteHash(&NodeConfig); }
/* * A template has been requested */ void url_do_template(void) { const StrBuf *MimeType; const StrBuf *Tmpl = sbstr("template"); begin_burst(); MimeType = DoTemplate(SKEY(Tmpl), NULL, &NoCtx); http_transmit_thing(ChrPtr(MimeType), 0); }
/* * actually delete the node */ void delete_node(void) { HashList *NodeConfig; const StrBuf *Index; NodeConf *Node; void *vNode; Index = sbstr("index"); if (Index == NULL) { AppendImportantMessage(_("Invalid Parameter"), -1); url_do_template(); return; } NodeConfig = load_netconf(NULL, &NoCtx); if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || (vNode == NULL)) { AppendImportantMessage(_("Invalid Parameter"), -1); url_do_template(); DeleteHash(&NodeConfig); return; } Node = (NodeConf *) vNode; Node->DeleteMe = 1; save_net_conf(NodeConfig); DeleteHash(&NodeConfig); url_do_template(); }
int pop3_do_fetching(pop3aggr *cpptr) { AsyncIO *IO = &cpptr->IO; InitIOStruct(IO, cpptr, eReadMessage, POP3_C_ReadServerStatus, POP3_C_DNSFail, POP3_C_DispatchWriteDone, POP3_C_DispatchReadDone, POP3_C_Terminate, POP3_C_TerminateDB, POP3_C_ConnFail, POP3_C_Timeout, POP3_C_Shutdown); safestrncpy(((CitContext *)cpptr->IO.CitContext)->cs_host, ChrPtr(cpptr->Url), sizeof(((CitContext *)cpptr->IO.CitContext)->cs_host)); if (cpptr->IO.ConnectMe->IsIP) { QueueEventContext(&cpptr->IO, pop3_connect_ip); } else { QueueEventContext(&cpptr->IO, pop3_get_one_host_ip); } return 1; }
/* * Fetch the "mortuary" - a list of dead buddies which we keep around forever * so we can remove them from any client's roster that still has them listed */ void xmpp_store_mortuary(HashList *mortuary) { HashPos *HashPos; long len; void *Value; const char *Key; StrBuf *themsg; themsg = NewStrBuf(); StrBufPrintf(themsg, "Content-type: " XMPPMORTUARY "\n" "Content-transfer-encoding: 7bit\n" "\n" ); HashPos = GetNewHashPos(mortuary, 0); while (GetNextHashPos(mortuary, HashPos, &len, &Key, &Value) != 0) { StrBufAppendPrintf(themsg, "%s\n", (char *)Value); } DeleteHashPos(&HashPos); /* Delete the old mortuary */ CtdlDeleteMessages(USERCONFIGROOM, NULL, 0, XMPPMORTUARY); /* And save the new one to disk */ quickie_message("Citadel", NULL, NULL, USERCONFIGROOM, ChrPtr(themsg), 4, "XMPP Mortuary"); FreeStrBuf(&themsg); }
int main(int argc, char* argv[]) { StrBuf *WFBuf; StrBuf *OutBuf; StrBuf *Info; int nWildfireHeaders = 0; StartLibCitadel(8); printf("%s == %d?\n", libcitadel_version_string(), libcitadel_version_number()); WildFireInitBacktrace(argv[0], 0); WFBuf = NewStrBuf(); OutBuf = NewStrBuf(); Info = NewStrBufPlain(HKEY("this is just a test message")); SerializeJson(WFBuf, WildFireException(HKEY(__FILE__), __LINE__, Info, 1), 1); SerializeJson(WFBuf, WildFireException(HKEY(__FILE__), __LINE__, Info, 1), 1); SerializeJson(WFBuf, WildFireException(HKEY(__FILE__), __LINE__, Info, 1), 1); SerializeJson(WFBuf, WildFireException(HKEY(__FILE__), __LINE__, Info, 1), 1); SerializeJson(WFBuf, WildFireException(HKEY(__FILE__), __LINE__, Info, 1), 1); SerializeJson(WFBuf, WildFireException(HKEY(__FILE__), __LINE__, Info, 1), 1); SerializeJson(WFBuf, WildFireException(HKEY(__FILE__), __LINE__, Info, 1), 1); WildFireSerializePayload(WFBuf, OutBuf, &nWildfireHeaders, NULL); CreateWildfireSampleMessage(OutBuf); printf("%s\n\n", ChrPtr(OutBuf)); FreeStrBuf(&WFBuf); FreeStrBuf(&OutBuf); FreeStrBuf(&Info); ShutDownLibCitadel(); return 0; }
HashList *load_netconf(StrBuf *Target, WCTemplputParams *TP) { StrBuf *Buf; HashList *Hash; char nnn[64]; char buf[SIZ]; int nUsed; NodeConf *Node; serv_puts("CONF getsys|application/x-citadel-ignet-config"); serv_getln(buf, sizeof buf); if (buf[0] == '1') { Hash = NewHash(1, NULL); Buf = NewStrBuf(); while (StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) { Node = NewNode(Buf); if (Node != NULL) { nUsed = GetCount(Hash); nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1); Put(Hash, nnn, nUsed, Node, DeleteNodeConf); } } FreeStrBuf(&Buf); return Hash; } return NULL; }
static void StrBufRFC2047encodeMessageStdin(void) { int fdin = 0;// STDIN const char *Err; StrBuf *Target; StrBuf *Source; StrBuf *Src; Source = NewStrBuf(); Src = NewStrBuf(); printf("["); while (fdin == 0) { StrBufTCP_read_line(Source, &fdin, 0, &Err); StrBufAppendBuf(Src, Source, 0); StrBufAppendBufPlain(Src, HKEY("\n"), 0); } Target = StrBufRFC2047encodeMessage(Src); printf("Target: \n%s\n", ChrPtr(Target)); FreeStrBuf(&Source); FreeStrBuf(&Src); FreeStrBuf(&Target); }
static void TestRFC822DecodeStdin(void) { int fdin = 0;// STDIN const char *Err; StrBuf *Target; StrBuf *Source; StrBuf *DefaultCharset; StrBuf *FoundCharset; DefaultCharset = NewStrBufPlain(HKEY("iso-8859-1")); FoundCharset = NewStrBuf(); Source = NewStrBuf(); while (fdin == 0) { StrBufTCP_read_line(Source, &fdin, 0, &Err); Target = NewStrBuf(); StrBuf_RFC822_to_Utf8(Target, Source, DefaultCharset, FoundCharset); TestRevalidateStrBuf(Target); printf("the ugly multi:>%s<\n", ChrPtr(Target)); FreeStrBuf(&Target); } FreeStrBuf(&Source); FreeStrBuf(&FoundCharset); FreeStrBuf(&DefaultCharset); }
/* * Deliver list messages to everyone on the list ... efficiently */ void network_deliver_list(struct CtdlMessage *msg, SpoolControl *sc, const char *RoomName) { recptypes *valid; char bounce_to[256]; /* Don't do this if there were no recipients! */ if (sc->Users[listrecp] == NULL) return; /* Now generate the delivery instructions */ /* Where do we want bounces and other noise to be heard? * Surely not the list members! */ snprintf(bounce_to, sizeof bounce_to, "room_aide@%s", config.c_fqdn); /* Now submit the message */ valid = validate_recipients(ChrPtr(sc->Users[listrecp]), NULL, 0); if (valid != NULL) { valid->bounce_to = strdup(bounce_to); valid->envelope_from = strdup(bounce_to); valid->sending_room = strdup(RoomName); CtdlSubmitMsg(msg, valid, NULL, 0); free_recipients(valid); } /* Do not call CM_Free(msg) here; the caller will free it. */ }
/* * Embed the room banner * * got The information returned from a GOTO server command * navbar_style Determines which navigation buttons to display */ void tmplput_roombanner(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; /* Refresh current room states. Doesn't work? gotoroom(NULL); */ wc_printf("<div id=\"banner\">\n"); /* The browser needs some information for its own use */ wc_printf("<script type=\"text/javascript\"> \n" " room_is_trash = %d; \n" "</script>\n", ((WC->CurRoom.RAFlags & UA_ISTRASH) != 0) ); /* * If the user happens to select the "make this my start page" link, * we want it to remember the URL as a "/dotskip" one instead of * a "skip" or "gotonext" or something like that. */ if (WCC->Hdr->this_page == NULL) { WCC->Hdr->this_page = NewStrBuf(); } StrBufPrintf(WCC->Hdr->this_page, "dotskip?room=%s", ChrPtr(WC->CurRoom.name)); do_template("roombanner"); do_template("navbar"); wc_printf("</div>\n"); }
/* * Look for URL's embedded in a buffer and make them linkable. We use a * target window in order to keep the Citadel session in its own window. */ void UrlizeText(StrBuf* Target, StrBuf *Source, StrBuf *WrkBuf) { int len, UrlLen, Offset, TrailerLen; const char *start, *end, *pos; FlushStrBuf(Target); start = NULL; len = StrLength(Source); end = ChrPtr(Source) + len; for (pos = ChrPtr(Source); (pos < end) && (start == NULL); ++pos) { if (!strncasecmp(pos, "http://", 7)) start = pos; else if (!strncasecmp(pos, "ftp://", 6)) start = pos; } if (start == NULL) { StrBufAppendBuf(Target, Source, 0); return; } FlushStrBuf(WrkBuf); for (pos = ChrPtr(Source) + len; pos > start; --pos) { if ( (!isprint(*pos)) || (isspace(*pos)) || (*pos == '{') || (*pos == '}') || (*pos == '|') || (*pos == '\\') || (*pos == '^') || (*pos == '[') || (*pos == ']') || (*pos == '`') || (*pos == '<') || (*pos == '>') || (*pos == '(') || (*pos == ')') ) { end = pos; } } UrlLen = end - start; StrBufAppendBufPlain(WrkBuf, start, UrlLen, 0); Offset = start - ChrPtr(Source); if (Offset != 0) StrBufAppendBufPlain(Target, ChrPtr(Source), Offset, 0); StrBufAppendPrintf(Target, "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c", LB, QU, ChrPtr(WrkBuf), QU, QU, TARGET, QU, RB, ChrPtr(WrkBuf), LB, RB); TrailerLen = StrLength(Source) - (end - ChrPtr(Source)); if (TrailerLen > 0) StrBufAppendBufPlain(Target, end, TrailerLen, 0); }
/* * Deliver digest messages */ void network_deliver_digest(SpoolControl *sc) { struct CitContext *CCC = CC; long len; char buf[SIZ]; char *pbuf; struct CtdlMessage *msg = NULL; long msglen; recptypes *valid; char bounce_to[256]; if (sc->Users[digestrecp] == NULL) return; msg = malloc(sizeof(struct CtdlMessage)); memset(msg, 0, sizeof(struct CtdlMessage)); msg->cm_magic = CTDLMESSAGE_MAGIC; msg->cm_format_type = FMT_RFC822; msg->cm_anon_type = MES_NORMAL; CM_SetFieldLONG(msg, eTimestamp, time(NULL)); CM_SetField(msg, eAuthor, CCC->room.QRname, strlen(CCC->room.QRname)); len = snprintf(buf, sizeof buf, "[%s]", CCC->room.QRname); CM_SetField(msg, eMsgSubject, buf, len); CM_SetField(msg, erFc822Addr, SKEY(sc->Users[roommailalias])); CM_SetField(msg, eRecipient, SKEY(sc->Users[roommailalias])); /* Set the 'List-ID' header */ CM_SetField(msg, eListID, SKEY(sc->ListID)); /* * Go fetch the contents of the digest */ fseek(sc->digestfp, 0L, SEEK_END); msglen = ftell(sc->digestfp); pbuf = malloc(msglen + 1); fseek(sc->digestfp, 0L, SEEK_SET); fread(pbuf, (size_t)msglen, 1, sc->digestfp); pbuf[msglen] = '\0'; CM_SetAsField(msg, eMesageText, &pbuf, msglen); /* Now generate the delivery instructions */ /* Where do we want bounces and other noise to be heard? * Surely not the list members! */ snprintf(bounce_to, sizeof bounce_to, "room_aide@%s", config.c_fqdn); /* Now submit the message */ valid = validate_recipients(ChrPtr(sc->Users[digestrecp]), NULL, 0); if (valid != NULL) { valid->bounce_to = strdup(bounce_to); valid->envelope_from = strdup(bounce_to); CtdlSubmitMsg(msg, valid, NULL, 0); } CM_Free(msg); free_recipients(valid); }
const char *smtp_get_Recipients(void) { citsmtp *sSMTP = SMTP; if (sSMTP == NULL) return NULL; else return ChrPtr(sSMTP->from); }
int ConditionalHavewikiType(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; const char *pch; long len; GetTemplateTokenString(Target, TP, 2, &pch, &len); return bmstrcasestr((char *)ChrPtr(WCC->Hdr->HR.ReqLine), pch) != NULL; }