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 QItem_Handle_Recipient(OneQueItem *Item, StrBuf *Line, const char **Pos) { if (Item->Current == NULL) NewMailQEntry(Item); if (Item->Current->Recipient == NULL) Item->Current->Recipient=NewStrBufPlain(NULL, StrLength(Line)); StrBufExtract_NextToken(Item->Current->Recipient, Line, Pos, '|'); Item->Current->Status = StrBufExtractNext_int(Line, Pos, '|'); StrBufExtract_NextToken(Item->Current->StatusMessage, Line, Pos, '|'); Item->Current = NULL; // TODO: is this always right? }
HashList *iterate_FindConflict(StrBuf *Target, WCTemplputParams *TP) { StrBuf *Line; HashList *Conflicts = NULL; CalendarConflict *Conflict; wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH); serv_printf("ICAL conflicts|%ld|%s|", Mime->msgnum, ChrPtr(Mime->PartNum)); Line = NewStrBuf(); StrBuf_ServGetln(Line); if (GetServerStatus(Line, NULL) == 1) { const char *Pos = NULL; int Done = 0; int n = 0; Conflicts = NewHash(1, Flathash); while(!Done && (StrBuf_ServGetln(Line) >= 0) ) if ( (StrLength(Line)==3) && !strcmp(ChrPtr(Line), "000")) { Done = 1; } else { Conflict = (CalendarConflict *) malloc(sizeof(CalendarConflict)); Conflict->conflict_event_uid = NewStrBufPlain(NULL, StrLength(Line)); Conflict->conflict_event_summary = NewStrBufPlain(NULL, StrLength(Line)); Conflict->existing_msgnum = StrBufExtractNext_long(Line, &Pos, '|'); StrBufSkip_NTokenS(Line, &Pos, '|', 1); StrBufExtract_NextToken(Conflict->conflict_event_uid, Line, &Pos, '|'); StrBufExtract_NextToken(Conflict->conflict_event_summary, Line, &Pos, '|'); Conflict->is_update = StrBufExtractNext_long(Line, &Pos, '|'); Put(Conflicts, IKEY(n), Conflict, DeleteConflict); n++; Pos = NULL; } } FreeStrBuf(&Line); syslog(LOG_DEBUG, "...done.\n"); return Conflicts; }
void SortPregetMatter(HashList *Cals) { disp_cal *Cal; void *vCal; const char *Key; long KLen; IcalEnumMap *SortMap[10]; IcalEnumMap *Map; void *vSort; const char *Next = NULL; const StrBuf *SortVector; StrBuf *SortBy; int i = 0; HashPos *It; SortVector = SBSTR("ICALSortVec"); if (SortVector == NULL) return; for (i = 0; i < 10; i++) SortMap[i] = NULL; SortBy = NewStrBuf(); while (StrBufExtract_NextToken(SortBy, SortVector, &Next, ':') > 0) { GetHash(IcalComponentMap, SKEY(SortBy), &vSort); Map = (IcalEnumMap*) vSort; SortMap[i] = Map; i++; if (i > 9) break; } if (i == 0) return; switch (SortMap[i - 1]->map) { /* case */ default: break; } It = GetNewHashPos(Cals, 0); while (GetNextHashPos(Cals, It, &KLen, &Key, &vCal)) { i = 0; Cal = (disp_cal*) vCal; Cal->Status = icalcomponent_get_status(Cal->cal); Cal->SortBy = Cal->cal; while ((SortMap[i] != NULL) && (Cal->SortBy != NULL)) { /****Cal->SortBy = icalcomponent_get_first_property(Cal->SortBy, SortMap[i++]->map); */ } } }
int main(int argc, char **argv) { StrBuf *setstr; StrBuf *lostr; StrBuf *histr; StrBuf *vset; const char *pvset; int i = 0; // char *teststring = "40:24524,24662,24673,27869:27935,28393,28426,31247:31258,31731,31749,31761,31778,31782,31801:31803,31813,31904,31915,33708,33935,34619,34672,34720:34723,34766,34835,37594,38854,39235,39942,40030,40142,40520,40815,40907,41201,41578,41781,41954,42292,43110,43565,43801,43998,44180,44241,44295,44401,44561,44635,44798,44861,44946,45022,45137:45148,45166,45179,45707,47114,47141:47157,47194,47314,47349,47386,47489,47496,47534:47543,54460,54601,54637:54652"; char *teststring = "one,two,three"; setstr = NewStrBuf(); vset = NewStrBufPlain(teststring, -1); while (StrBufExtract_NextToken(setstr, vset, &pvset, ',')) { printf("Token: '%s'\n", ChrPtr(setstr)); } exit(0); }
/* * Setup an OpenID authentication */ void cmd_oids(char *argbuf) { struct CitContext *CCC = CC; /* CachedCitContext - performance boost */ const char *Pos = NULL; StrBuf *ArgBuf = NULL; StrBuf *ReplyBuf = NULL; StrBuf *return_to = NULL; StrBuf *RedirectUrl = NULL; ctdl_openid *oiddata; int discovery_succeeded = 0; if (CtdlGetConfigInt("c_disable_newu")) { cprintf("%d this system does not support openid.\n", ERROR + CMD_NOT_SUPPORTED); return; } Free_ctdl_openid ((ctdl_openid**)&CCC->openid_data); CCC->openid_data = oiddata = malloc(sizeof(ctdl_openid)); if (oiddata == NULL) { syslog(LOG_ALERT, "malloc() failed: %s", strerror(errno)); cprintf("%d malloc failed\n", ERROR + INTERNAL_ERROR); return; } memset(oiddata, 0, sizeof(ctdl_openid)); ArgBuf = NewStrBufPlain(argbuf, -1); oiddata->verified = 0; oiddata->claimed_id = NewStrBufPlain(NULL, StrLength(ArgBuf)); return_to = NewStrBufPlain(NULL, StrLength(ArgBuf)); StrBufExtract_NextToken(oiddata->claimed_id, ArgBuf, &Pos, '|'); StrBufExtract_NextToken(return_to, ArgBuf, &Pos, '|'); syslog(LOG_DEBUG, "User-Supplied Identifier is: %s", ChrPtr(oiddata->claimed_id)); /********** OpenID 2.0 section 7.3 - Discovery **********/ /* Section 7.3.1 says we have to attempt XRI based discovery. * No one is using this, no one is asking for it, no one wants it. * So we're not even going to bother attempting this mode. */ /* Attempt section 7.3.2 (Yadis discovery) and section 7.3.3 (HTML discovery); */ discovery_succeeded = perform_openid2_discovery(oiddata->claimed_id); if (discovery_succeeded == 0) { cprintf("%d There is no OpenID identity provider at this location.\n", ERROR); } else { /* * If we get to this point we are in possession of a valid OpenID Provider URL. */ syslog(LOG_DEBUG, "OP URI '%s' discovered using method %d", ChrPtr(oiddata->op_url), discovery_succeeded ); /* We have to "normalize" our Claimed ID otherwise it will cause some OP's to barf */ if (cbmstrcasestr(ChrPtr(oiddata->claimed_id), "://") == NULL) { StrBuf *cid = oiddata->claimed_id; oiddata->claimed_id = NewStrBufPlain(HKEY("http://")); StrBufAppendBuf(oiddata->claimed_id, cid, 0); FreeStrBuf(&cid); } /* * OpenID 2.0 section 9: request authentication * Assemble a URL to which the user-agent will be redirected. */ RedirectUrl = NewStrBufDup(oiddata->op_url); StrBufAppendBufPlain(RedirectUrl, HKEY("?openid.ns="), 0); StrBufUrlescAppend(RedirectUrl, NULL, "http://specs.openid.net/auth/2.0"); StrBufAppendBufPlain(RedirectUrl, HKEY("&openid.mode=checkid_setup"), 0); StrBufAppendBufPlain(RedirectUrl, HKEY("&openid.claimed_id="), 0); StrBufUrlescAppend(RedirectUrl, oiddata->claimed_id, NULL); StrBufAppendBufPlain(RedirectUrl, HKEY("&openid.identity="), 0); StrBufUrlescAppend(RedirectUrl, oiddata->claimed_id, NULL); /* return_to tells the provider how to complete the round trip back to our site */ StrBufAppendBufPlain(RedirectUrl, HKEY("&openid.return_to="), 0); StrBufUrlescAppend(RedirectUrl, return_to, NULL); /* Attribute Exchange * See: * http://openid.net/specs/openid-attribute-exchange-1_0.html * http://code.google.com/apis/accounts/docs/OpenID.html#endpoint * http://test-id.net/OP/AXFetch.aspx */ StrBufAppendBufPlain(RedirectUrl, HKEY("&openid.ns.ax="), 0); StrBufUrlescAppend(RedirectUrl, NULL, "http://openid.net/srv/ax/1.0"); StrBufAppendBufPlain(RedirectUrl, HKEY("&openid.ax.mode=fetch_request"), 0); StrBufAppendBufPlain(RedirectUrl, HKEY("&openid.ax.required=firstname,lastname,friendly,nickname"), 0); StrBufAppendBufPlain(RedirectUrl, HKEY("&openid.ax.type.firstname="), 0); StrBufUrlescAppend(RedirectUrl, NULL, "http://axschema.org/namePerson/first"); StrBufAppendBufPlain(RedirectUrl, HKEY("&openid.ax.type.lastname="), 0); StrBufUrlescAppend(RedirectUrl, NULL, "http://axschema.org/namePerson/last"); StrBufAppendBufPlain(RedirectUrl, HKEY("&openid.ax.type.friendly="), 0); StrBufUrlescAppend(RedirectUrl, NULL, "http://axschema.org/namePerson/friendly"); StrBufAppendBufPlain(RedirectUrl, HKEY("&openid.ax.type.nickname="), 0); StrBufUrlescAppend(RedirectUrl, NULL, "http://axschema.org/namePerson/nickname"); syslog(LOG_DEBUG, "OpenID: redirecting client to %s", ChrPtr(RedirectUrl)); cprintf("%d %s\n", CIT_OK, ChrPtr(RedirectUrl)); } FreeStrBuf(&ArgBuf); FreeStrBuf(&ReplyBuf); FreeStrBuf(&return_to); FreeStrBuf(&RedirectUrl); }
void cmd_gvdn(char *argbuf) { const ConfType *pCfg; char *confptr; long min = atol(argbuf); const char *Pos = NULL; const char *PPos = NULL; const char *HKey; long HKLen; StrBuf *Line; StrBuf *Config; StrBuf *Cfg; StrBuf *CfgToken; HashList *List; HashPos *It; void *vptr; List = NewHash(1, NULL); Cfg = NewStrBufPlain(config.c_fqdn, -1); Put(List, SKEY(Cfg), Cfg, HFreeStrBuf); Cfg = NULL; confptr = CtdlGetSysConfig(INTERNETCFG); Config = NewStrBufPlain(confptr, -1); free(confptr); Line = NewStrBufPlain(NULL, StrLength(Config)); CfgToken = NewStrBufPlain(NULL, StrLength(Config)); while (StrBufSipLine(Line, Config, &Pos)) { if (Cfg == NULL) Cfg = NewStrBufPlain(NULL, StrLength(Line)); PPos = NULL; StrBufExtract_NextToken(Cfg, Line, &PPos, '|'); StrBufExtract_NextToken(CfgToken, Line, &PPos, '|'); if (GetHash(CfgNameHash, SKEY(CfgToken), &vptr) && (vptr != NULL)) { pCfg = (ConfType *) vptr; if (pCfg->Type <= min) { Put(List, SKEY(Cfg), Cfg, HFreeStrBuf); Cfg = NULL; } } } cprintf("%d Valid Domains\n", LISTING_FOLLOWS); It = GetNewHashPos(List, 1); while (GetNextHashPos(List, It, &HKLen, &HKey, &vptr)) { cputbuf(vptr); cprintf("\n"); } cprintf("000\n"); DeleteHashPos(&It); DeleteHash(&List); FreeStrBuf(&Cfg); FreeStrBuf(&Line); FreeStrBuf(&CfgToken); FreeStrBuf(&Config); }
void network_process_ignetpush(SpoolControl *sc, struct CtdlMessage *omsg, long *delete_after_send) { StrBuf *Recipient; StrBuf *RemoteRoom; const char *Pos = NULL; struct CtdlMessage *msg = NULL; struct CitContext *CCC = CC; struct ser_ret sermsg; char buf[SIZ]; char filename[PATH_MAX]; FILE *fp; StrBuf *Buf = NULL; int i; int bang = 0; int send = 1; if (sc->Users[ignet_push_share] == NULL) return; /* * Process IGnet push shares */ msg = CM_Duplicate(omsg); /* Prepend our node name to the Path field whenever * sending a message to another IGnet node */ Netmap_AddMe(msg, HKEY("username")); /* * Determine if this message is set to be deleted * after sending out on the network */ if (!CM_IsEmpty(msg, eSpecialField)) { if (!strcasecmp(msg->cm_fields[eSpecialField], "CANCEL")) { *delete_after_send = 1; } } /* Now send it to every node */ Recipient = NewStrBufPlain(NULL, StrLength(sc->Users[ignet_push_share])); RemoteRoom = NewStrBufPlain(NULL, StrLength(sc->Users[ignet_push_share])); while ((Pos != StrBufNOTNULL) && StrBufExtract_NextToken(Recipient, sc->Users[ignet_push_share], &Pos, ',')) { StrBufExtract_NextToken(RemoteRoom, sc->Users[ignet_push_share], &Pos, ','); send = 1; NewStrBufDupAppendFlush(&Buf, Recipient, NULL, 1); /* Check for valid node name */ if (CtdlIsValidNode(NULL, NULL, Buf, sc->working_ignetcfg, sc->the_netmap) != 0) { QN_syslog(LOG_ERR, "Invalid node <%s>\n", ChrPtr(Recipient)); send = 0; } /* Check for split horizon */ QN_syslog(LOG_DEBUG, "Path is %s\n", msg->cm_fields[eMessagePath]); bang = num_tokens(msg->cm_fields[eMessagePath], '!'); if (bang > 1) { for (i=0; i<(bang-1); ++i) { extract_token(buf, msg->cm_fields[eMessagePath], i, '!', sizeof buf); QN_syslog(LOG_DEBUG, "Compare <%s> to <%s>\n", buf, ChrPtr(Recipient)) ; if (!strcasecmp(buf, ChrPtr(Recipient))) { send = 0; break; } } QN_syslog(LOG_INFO, " %sSending to %s\n", (send)?"":"Not ", ChrPtr(Recipient)); } /* Send the message */ if (send == 1) { /* * Force the message to appear in the correct * room on the far end by setting the C field * correctly */ if (StrLength(RemoteRoom) > 0) { CM_SetField(msg, eRemoteRoom, SKEY(RemoteRoom)); } else { CM_SetField(msg, eRemoteRoom, CCC->room.QRname, strlen(CCC->room.QRname)); } /* serialize it for transmission */ CtdlSerializeMessage(&sermsg, msg); if (sermsg.len > 0) { /* write it to a spool file */ snprintf(filename, sizeof(filename), "%s/%s@%lx%x", ctdl_netout_dir, ChrPtr(Recipient), time(NULL), rand() ); QN_syslog(LOG_DEBUG, "Appending to %s\n", filename); fp = fopen(filename, "ab"); if (fp != NULL) { fwrite(sermsg.ser, sermsg.len, 1, fp); fclose(fp); } else { QN_syslog(LOG_ERR, "%s: %s\n", filename, strerror(errno)); } /* free the serialized version */ free(sermsg.ser); } } } FreeStrBuf(&Buf); FreeStrBuf(&Recipient); FreeStrBuf(&RemoteRoom); CM_Free(msg); }
int ReadHttpSubject(ParsedHttpHdrs *Hdr, StrBuf *Line, StrBuf *Buf) { const char *Args; void *vLine, *vHandler; const char *Pos = NULL; Hdr->HR.ReqLine = Line; /* The requesttype... GET, POST... */ StrBufExtract_token(Buf, Hdr->HR.ReqLine, 0, ' '); if (GetHash(HttpReqTypes, SKEY(Buf), &vLine) && (vLine != NULL)) { Hdr->HR.eReqType = *(long*)vLine; } else { Hdr->HR.eReqType = eGET; return 1; } StrBufCutLeft(Hdr->HR.ReqLine, StrLength(Buf) + 1); /* the HTTP Version... */ StrBufExtract_token(Buf, Hdr->HR.ReqLine, 1, ' '); StrBufCutRight(Hdr->HR.ReqLine, StrLength(Buf) + 1); if (StrLength(Buf) == 0) { Hdr->HR.eReqType = eGET; return 1; } StrBufAppendBuf(Hdr->this_page, Hdr->HR.ReqLine, 0); /* chop Filename / query arguments */ Args = strchr(ChrPtr(Hdr->HR.ReqLine), '?'); if (Args == NULL) /* whe're not that picky about params... TODO: this will spoil '&' in filenames.*/ Args = strchr(ChrPtr(Hdr->HR.ReqLine), '&'); if (Args != NULL) { Args ++; /* skip the ? */ StrBufPlain(Hdr->PlainArgs, Args, StrLength(Hdr->HR.ReqLine) - (Args - ChrPtr(Hdr->HR.ReqLine))); StrBufCutAt(Hdr->HR.ReqLine, 0, Args - 1); } /* don't parse them yet, maybe we don't even care... */ /* now lookup what we are going to do with this... */ /* skip first slash */ StrBufExtract_NextToken(Buf, Hdr->HR.ReqLine, &Pos, '/'); do { StrBufExtract_NextToken(Buf, Hdr->HR.ReqLine, &Pos, '/'); GetHash(HandlerHash, SKEY(Buf), &vHandler), Hdr->HR.Handler = (WebcitHandler*) vHandler; if (Hdr->HR.Handler == NULL) break; /* * If the request is prefixed by "/webcit" then chop that off. This * allows a front end web server to forward all /webcit requests to us * while still using the same web server port for other things. */ if ((Hdr->HR.Handler->Flags & URLNAMESPACE) != 0) continue; break; } while (1); /* remove the handlername from the URL */ if ((Pos != NULL) && (Pos != StrBufNOTNULL)){ StrBufCutLeft(Hdr->HR.ReqLine, Pos - ChrPtr(Hdr->HR.ReqLine)); } if (Hdr->HR.Handler != NULL) { if ((Hdr->HR.Handler->Flags & BOGUS) != 0) { return 1; } Hdr->HR.DontNeedAuth = ( ((Hdr->HR.Handler->Flags & ISSTATIC) != 0) || ((Hdr->HR.Handler->Flags & ANONYMOUS) != 0) ); } else { /* If this is a "flat" request for the root, display the configured landing page. */ int return_value; StrBuf *NewLine = NewStrBuf(); Hdr->HR.DontNeedAuth = 1; StrBufAppendPrintf(NewLine, "GET /landing?go=%s?failvisibly=1 HTTP/1.0", ChrPtr(Buf)); if (verbose) syslog(LOG_DEBUG, "Replacing with: %s", ChrPtr(NewLine)); return_value = ReadHttpSubject(Hdr, NewLine, Buf); FreeStrBuf(&NewLine); return return_value; } return 0; }
ParsedURL *LoadRelayUrls(OneQueItem *MyQItem, char *Author, char *Address) { int nRelays = 0; ParsedURL *RelayUrls = NULL; char mxbuf[SIZ]; ParsedURL **Url = &MyQItem->URL; nRelays = get_hosts(mxbuf, "fallbackhost"); if (nRelays > 0) { StrBuf *All; StrBuf *One; const char *Pos = NULL; All = NewStrBufPlain(mxbuf, -1); One = NewStrBufPlain(NULL, StrLength(All) + 1); while ((Pos != StrBufNOTNULL) && ((Pos == NULL) || !IsEmptyStr(Pos))) { StrBufExtract_NextToken(One, All, &Pos, '|'); if (!ParseURL(Url, One, DefaultMXPort)) { SMTPC_syslog(LOG_DEBUG, "Failed to parse: %s\n", ChrPtr(One)); } else { (*Url)->IsRelay = 1; MyQItem->HaveRelay = 1; } } FreeStrBuf(&All); FreeStrBuf(&One); } nRelays = get_hosts(mxbuf, "smarthost"); if (nRelays > 0) { char *User; StrBuf *All; StrBuf *One; const char *Pos = NULL; All = NewStrBufPlain(mxbuf, -1); One = NewStrBufPlain(NULL, StrLength(All) + 1); while ((Pos != StrBufNOTNULL) && ((Pos == NULL) || !IsEmptyStr(Pos))) { StrBufExtract_NextToken(One, All, &Pos, '|'); User = strchr(ChrPtr(One), ' '); if (User != NULL) { if (!strcmp(User + 1, Author) || !strcmp(User + 1, Address)) StrBufCutAt(One, 0, User); else { MyQItem->HaveRelay = 1; continue; } } if (!ParseURL(Url, One, DefaultMXPort)) { SMTPC_syslog(LOG_DEBUG, "Failed to parse: %s\n", ChrPtr(One)); } else { ///if (!Url->IsIP)) // todo dupe me fork ipv6 (*Url)->IsRelay = 1; MyQItem->HaveRelay = 1; } } FreeStrBuf(&All); FreeStrBuf(&One); } return RelayUrls; }
void QItem_Handle_SenderRoom(OneQueItem *Item, StrBuf *Line, const char **Pos) { if (Item->SenderRoom == NULL) Item->SenderRoom = NewStrBufPlain(NULL, StrLength(Line)); StrBufExtract_NextToken(Item->SenderRoom, Line, Pos, '|'); }
void QItem_Handle_BounceTo(OneQueItem *Item, StrBuf *Line, const char **Pos) { if (Item->BounceTo == NULL) Item->BounceTo = NewStrBufPlain(NULL, StrLength(Line)); StrBufExtract_NextToken(Item->BounceTo, Line, Pos, '|'); }