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); }
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); }
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 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); }
void DeleteWebcitHandler(void *vHandler) { WebcitHandler *Handler = (WebcitHandler*) vHandler; FreeStrBuf(&Handler->Name); FreeStrBuf(&Handler->DisplayName); free (Handler); }
/* * Hand off a copy of a message to be journalized. */ void JournalBackgroundSubmit(struct CtdlMessage *msg, StrBuf *saved_rfc822_version, recptypes *recps) { struct jnlq *jptr = NULL; /* Avoid double journaling! */ if (!CM_IsEmpty(msg, eJournal)) { FreeStrBuf(&saved_rfc822_version); return; } jptr = (struct jnlq *)malloc(sizeof(struct jnlq)); if (jptr == NULL) { FreeStrBuf(&saved_rfc822_version); return; } memset(jptr, 0, sizeof(struct jnlq)); if (recps != NULL) memcpy(&jptr->recps, recps, sizeof(recptypes)); if (!CM_IsEmpty(msg, eAuthor)) jptr->from = strdup(msg->cm_fields[eAuthor]); if (!CM_IsEmpty(msg, eNodeName)) jptr->node = strdup(msg->cm_fields[eNodeName]); if (!CM_IsEmpty(msg, erFc822Addr)) jptr->rfca = strdup(msg->cm_fields[erFc822Addr]); if (!CM_IsEmpty(msg, eMsgSubject)) jptr->subj = strdup(msg->cm_fields[eMsgSubject]); if (!CM_IsEmpty(msg, emessageId)) jptr->msgn = strdup(msg->cm_fields[emessageId]); jptr->rfc822 = SmashStrBuf(&saved_rfc822_version); /* Add to the queue */ begin_critical_section(S_JOURNAL_QUEUE); jptr->next = jnlq; jnlq = jptr; end_critical_section(S_JOURNAL_QUEUE); }
void HfreeFetchItem(void *vItem) { FetchItem *Item = (FetchItem*) vItem; FreeStrBuf(&Item->MsgUIDL); FreeStrBuf(&Item->MsgUID); free(Item); }
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; }
static void CreateWildfireSampleMessage(StrBuf *OutBuf) { JsonValue *Error; StrBuf *Buf; StrBuf *Header; StrBuf *Json; int n = 1; Header = NewStrBuf(); Json = NewStrBuf(); Error = WildFireMessagePlain(HKEY(__FILE__), __LINE__, HKEY("Info message"), eINFO); SerializeJson(Json, Error, 1); WildFireSerializePayload(Json, Header, &n, NULL); StrBufAppendBuf(OutBuf, Header, 0); FlushStrBuf(Json); FlushStrBuf(Header); Error = WildFireMessagePlain(HKEY(__FILE__), __LINE__, HKEY("Warn message"), eWARN); SerializeJson(Json, Error, 1); WildFireSerializePayload(Json, Header, &n, NULL); StrBufAppendBuf(OutBuf, Header, 0); FlushStrBuf(Json); FlushStrBuf(Header); Error = WildFireMessagePlain(HKEY(__FILE__), __LINE__, HKEY("Error message"), eERROR); SerializeJson(Json, Error, 1); WildFireSerializePayload(Json, Header, &n, NULL); StrBufAppendBuf(OutBuf, Header, 0); FlushStrBuf(Json); FlushStrBuf(Header); Error = WildFireMessagePlain(HKEY(__FILE__), __LINE__, HKEY("Info message"), eINFO); SerializeJson(Json, Error, 1); WildFireSerializePayload(Json, Header, &n, NULL); StrBufAppendBuf(OutBuf, Header, 0); FlushStrBuf(Json); FlushStrBuf(Header); Error = WildFireMessagePlain(HKEY(__FILE__), __LINE__, HKEY("Info message"), eINFO); SerializeJson(Json, Error, 1); WildFireSerializePayload(Json, Header, &n, NULL); StrBufAppendBuf(OutBuf, Header, 0); FlushStrBuf(Json); FlushStrBuf(Header); Buf = NewStrBufPlain(HKEY("test error message")); Error = WildFireException(HKEY(__FILE__), __LINE__, Buf, 1); SerializeJson(Json, Error, 1); WildFireSerializePayload(Json, Header, &n, NULL); StrBufAppendBuf(OutBuf, Header, 0); FreeStrBuf(&Buf); FreeStrBuf(&Json); FreeStrBuf(&Header); }
void DeleteConflict(void *vConflict) { CalendarConflict *c = (CalendarConflict *) vConflict; FreeStrBuf(&c->conflict_event_uid); FreeStrBuf(&c->conflict_event_summary); free(c); }
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); }
void DeleteNodeConf(void *vNode) { NodeConf *Node = (NodeConf*) vNode; FreeStrBuf(&Node->NodeName); FreeStrBuf(&Node->Secret); FreeStrBuf(&Node->Host); FreeStrBuf(&Node->Port); free(Node); }
void SessionDestroyModule_WEBCIT (wcsession *sess) { FreeStrBuf(&sess->WBuf); FreeStrBuf(&sess->HBuf); FreeStrBuf(&sess->ImportantMsg); FreeStrBuf(&sess->PushedDestination); }
OneQueItem *DeserializeQueueItem(StrBuf *RawQItem, long QueMsgID) { OneQueItem *Item; const char *pLine = NULL; StrBuf *Line; StrBuf *Token; void *v; Item = (OneQueItem*)malloc(sizeof(OneQueItem)); memset(Item, 0, sizeof(OneQueItem)); Item->Retry = SMTP_RETRY_INTERVAL; Item->MessageID = -1; Item->QueMsgID = QueMsgID; Token = NewStrBuf(); Line = NewStrBufPlain(NULL, 128); while (pLine != StrBufNOTNULL) { const char *pItemPart = NULL; void *vHandler; StrBufExtract_NextToken(Line, RawQItem, &pLine, '\n'); if (StrLength(Line) == 0) continue; StrBufExtract_NextToken(Token, Line, &pItemPart, '|'); if (GetHash(QItemHandlers, SKEY(Token), &vHandler)) { QItemHandlerStruct *HS; HS = (QItemHandlerStruct*) vHandler; HS->H(Item, Line, &pItemPart); } } FreeStrBuf(&Line); FreeStrBuf(&Token); if (Item->Retry >= MaxRetry) Item->FailNow = 1; pthread_mutex_lock(&ActiveQItemsLock); if (GetHash(ActiveQItems, LKEY(Item->MessageID), &v)) { /* WHOOPS. somebody else is already working on this. */ pthread_mutex_unlock(&ActiveQItemsLock); FreeQueItem(&Item); return NULL; } else { /* mark our claim on this. */ Put(ActiveQItems, LKEY(Item->MessageID), Item, HFreeQueItem); pthread_mutex_unlock(&ActiveQItemsLock); } return Item; }
void Free_ctdl_openid(ctdl_openid **FreeMe) { if (*FreeMe == NULL) { return; } FreeStrBuf(&(*FreeMe)->op_url); FreeStrBuf(&(*FreeMe)->claimed_id); DeleteHash(&(*FreeMe)->sreg_keys); free(*FreeMe); *FreeMe = NULL; }
void HttpDestroyModule_CONTEXT (ParsedHttpHdrs *httpreq) { FreeStrBuf(&httpreq->this_page); FreeStrBuf(&httpreq->PlainArgs); FreeStrBuf(&httpreq->this_page); FreeStrBuf(&httpreq->PlainArgs); FreeStrBuf(&httpreq->HostHeader); DeleteHash(&httpreq->HTTPHeaders); }
void FreeMailQEntry(void *qv) { MailQEntry *Q = qv; /* SMTPC_syslog(LOG_DEBUG, "---------------%s--------------", __FUNCTION__); cit_backtrace(); */ FreeStrBuf(&Q->Recipient); FreeStrBuf(&Q->StatusMessage); FreeStrBuf(&Q->AllStatusMessages); memset(Q, 0, sizeof(MailQEntry)); free(Q); }
void FreeQueItem(OneQueItem **Item) { /* SMTPC_syslog(LOG_DEBUG, "---------------%s--------------", __FUNCTION__); cit_backtrace(); */ DeleteHash(&(*Item)->MailQEntries); FreeStrBuf(&(*Item)->EnvelopeFrom); FreeStrBuf(&(*Item)->BounceTo); FreeStrBuf(&(*Item)->SenderRoom); FreeURL(&(*Item)->URL); memset(*Item, 0, sizeof(OneQueItem)); free(*Item); Item = NULL; }
void ServerShutdownModule_WEBCIT (void) { FreeStrBuf(&csslocal); DeleteHash(&HandlerHash); }
void DestroyHttpHeaderHandler(void *V) { OneHttpHeader *pHdr; pHdr = (OneHttpHeader*) V; FreeStrBuf(&pHdr->Val); free(pHdr); }
/* * 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); }
void save_net_conf(HashList *Nodelist) { char buf[SIZ]; StrBuf *Buf; HashPos *where; void *vNode; NodeConf *Node; const char *Key; long KeyLen; serv_puts("CONF putsys|application/x-citadel-ignet-config"); serv_getln(buf, sizeof buf); if (buf[0] == '4') { if ((Nodelist != NULL) && (GetCount(Nodelist) > 0)) { where = GetNewHashPos(Nodelist, 0); Buf = NewStrBuf(); while (GetNextHashPos(Nodelist, where, &KeyLen, &Key, &vNode)) { Node = (NodeConf*) vNode; if (Node->DeleteMe==0) { SerializeNode(Node, Buf); serv_putbuf(Buf); } } FreeStrBuf(&Buf); DeleteHashPos(&where); } serv_puts("000"); } }
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; }
// 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); }
static void GetInputChar (void) /* Read the next character from the input stream and make CurC and NextC * valid. If end of line is reached, both are set to NUL, no more lines * are read by this function. */ { /* Drop all pushed fragments that don't have data left */ while (SB_GetIndex (Line) >= SB_GetLen (Line)) { /* Cannot read more from this line, check next line on stack if any */ if (CollCount (&InputStack) == 0) { /* This is THE line */ break; } FreeStrBuf (Line); Line = CollPop (&InputStack); } /* Now get the next characters from the line */ if (SB_GetIndex (Line) >= SB_GetLen (Line)) { CurC = NextC = '\0'; } else { CurC = SB_AtUnchecked (Line, SB_GetIndex (Line)); if (SB_GetIndex (Line) + 1 < SB_GetLen (Line)) { /* NextC comes from this fragment */ NextC = SB_AtUnchecked (Line, SB_GetIndex (Line) + 1); } else { /* NextC comes from next fragment */ if (CollCount (&InputStack) > 0) { NextC = ' '; } else { NextC = '\0'; } } } }
void FreeAsyncIOContents(AsyncIO *IO) { CitContext *Ctx = IO->CitContext; FreeStrBuf(&IO->IOBuf); FreeStrBuf(&IO->SendBuf.Buf); FreeStrBuf(&IO->RecvBuf.Buf); FreeURL(&IO->ConnectMe); FreeStrBuf(&IO->HttpReq.ReplyData); if (Ctx) { Ctx->state = CON_IDLE; Ctx->kill_me = 1; IO->CitContext = NULL; } }
void Header_HandleHost(StrBuf *Line, ParsedHttpHdrs *hdr) { if (hdr->HostHeader != NULL) { FreeStrBuf(&hdr->HostHeader); } hdr->HostHeader = NewStrBuf(); StrBufAppendPrintf(hdr->HostHeader, "%s://", (is_https ? "https" : "http") ); StrBufAppendBuf(hdr->HostHeader, Line, 0); }
void DeleteSmtpOutMsg(void *v) { SmtpOutMsg *Msg = v; AsyncIO *IO = &Msg->IO; EV_syslog(LOG_DEBUG, "%s Exit\n", __FUNCTION__); /* these are kept in our own space and free'd below */ Msg->IO.ConnectMe = NULL; ares_free_data(Msg->AllMX); if (Msg->HostLookup.VParsedDNSReply != NULL) Msg->HostLookup.DNSReplyFree(Msg->HostLookup.VParsedDNSReply); FreeURL(&Msg->Relay); FreeStrBuf(&Msg->msgtext); FreeStrBuf(&Msg->MultiLineBuf); FreeAsyncIOContents(&Msg->IO); memset (Msg, 0, sizeof(SmtpOutMsg)); /* just to be shure... */ free(Msg); }
void network_process_participate(SpoolControl *sc, struct CtdlMessage *omsg, long *delete_after_send) { struct CtdlMessage *msg = NULL; int ok_to_participate = 0; StrBuf *Buf = NULL; recptypes *valid; /* * Process client-side list participations for this room */ if (sc->Users[participate] == NULL) return; msg = CM_Duplicate(omsg); /* Only send messages which originated on our own * Citadel network, otherwise we'll end up sending the * remote mailing list's messages back to it, which * is rude... */ ok_to_participate = 0; if (!CM_IsEmpty(msg, eNodeName)) { if (!strcasecmp(msg->cm_fields[eNodeName], config.c_nodename)) { ok_to_participate = 1; } Buf = NewStrBufPlain(CM_KEY(msg, eNodeName)); if (CtdlIsValidNode(NULL, NULL, Buf, sc->working_ignetcfg, sc->the_netmap) == 0) { ok_to_participate = 1; } } if (ok_to_participate) { /* Replace the Internet email address of the * actual author with the email address of the * room itself, so the remote listserv doesn't * reject us. */ CM_SetField(msg, erFc822Addr, SKEY(sc->Users[roommailalias])); valid = validate_recipients(ChrPtr(sc->Users[participate]) , NULL, 0); CM_SetField(msg, eRecipient, SKEY(sc->Users[roommailalias])); CtdlSubmitMsg(msg, valid, "", 0); free_recipients(valid); } FreeStrBuf(&Buf); CM_Free(msg); }
// display the picture (icon, photo, whatever) associated with the current room void display_roompic(void) { off_t bytes; StrBuf *Buf = NewStrBuf(); serv_printf("DLRI"); StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 6) { StrBufCutLeft(Buf, 4); bytes = StrBufExtract_long(Buf, 0, '|'); StrBuf *content_type = NewStrBuf(); StrBufExtract_token(content_type, Buf, 3, '|'); WC->WBuf = NewStrBuf(); StrBuf_ServGetBLOBBuffered(WC->WBuf, bytes); http_transmit_thing(ChrPtr(content_type), 0); FreeStrBuf(&content_type); } else { output_error_pic("", ""); } FreeStrBuf(&Buf); }