NodeConf *HttpGetNewNode(void) { NodeConf *Node; if (!havebstr("node") || !havebstr("secret")|| !havebstr("host")|| !havebstr("port")) return NULL; Node = (NodeConf *) malloc(sizeof(NodeConf)); Node->DeleteMe = 0; Node->NodeName = NewStrBufDup(sbstr("node")); Node->Secret = NewStrBufDup(sbstr("secret")); Node->Host = NewStrBufDup(sbstr("host")); Node->Port = NewStrBufDup(sbstr("port")); return Node; }
/* * Save a URL destination so we can go to it later */ void push_destination(void) { wcsession *WCC = WC; if (!WCC) { wc_printf("no session"); return; } FreeStrBuf(&WCC->PushedDestination); WCC->PushedDestination = NewStrBufDup(SBSTR("url")); if (verbose) syslog(LOG_DEBUG, "Push: %s", ChrPtr(WCC->PushedDestination)); wc_printf("OK"); }
void tmplput_ThisRoomInfoText(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; long nchars = 0; LoadXRoomInfoText(); nchars = GetTemplateTokenNumber(Target, TP, 0, 0); if (!nchars) { /* the whole thing */ StrBufAppendTemplate(Target, TP, WCC->CurRoom.XInfoText, 1); } else { /* only a certain number of characters */ StrBuf *SubBuf; SubBuf = NewStrBufDup(WCC->CurRoom.XInfoText); if (StrLength(SubBuf) > nchars) { StrBuf_Utf8StrCut(SubBuf, nchars); StrBufAppendBufPlain(SubBuf, HKEY("..."), 0); } StrBufAppendTemplate(Target, TP, SubBuf, 1); FreeStrBuf(&SubBuf); } }
/* * 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 render_MIME_ICS_TPL(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset) { wc_mime_attachment *Mime = CTX(CTX_MIME_ATACH); icalproperty_method the_method = ICAL_METHOD_NONE; icalproperty *method = NULL; icalcomponent *cal = NULL; icalcomponent *c = NULL; WCTemplputParams SubTP; WCTemplputParams SuperTP; static int divcount = 0; if (StrLength(Mime->Data) == 0) { MimeLoadData(Mime); } if (StrLength(Mime->Data) > 0) { cal = icalcomponent_new_from_string(ChrPtr(Mime->Data)); } if (cal == NULL) { StrBufAppendPrintf(Mime->Data, _("There was an error parsing this calendar item.")); StrBufAppendPrintf(Mime->Data, "<br>\n"); return; } putlbstr("divname", ++divcount); putbstr("cal_partnum", NewStrBufDup(Mime->PartNum)); putlbstr("msgnum", Mime->msgnum); memset(&SubTP, 0, sizeof(WCTemplputParams)); memset(&SuperTP, 0, sizeof(WCTemplputParams)); /*//ical_dezonify(cal); */ /* If the component has subcomponents, recurse through them. */ c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT); c = (c != NULL) ? c : cal; method = icalcomponent_get_first_property(cal, ICAL_METHOD_PROPERTY); if (method != NULL) { the_method = icalproperty_get_method(method); } StackContext (TP, &SuperTP, &the_method, CTX_ICALMETHOD, 0, TP->Tokens); StackContext (&SuperTP, &SubTP, c, CTX_ICAL, 0, SuperTP.Tokens); FlushStrBuf(Mime->Data); /// DoTemplate(HKEY("ical_attachment_display"), Mime->Data, &SubTP); DoTemplate(HKEY("ical_edit"), Mime->Data, &SubTP); /*/ cal_process_object(Mime->Data, cal, 0, Mime->msgnum, ChrPtr(Mime->PartNum)); */ /* Free the memory we obtained from libical's constructor */ StrBufPlain(Mime->ContentType, HKEY("text/html")); StrBufAppendPrintf(WC->trailing_javascript, "eventEditAllDay(); \n" "RecurrenceShowHide(); \n" "EnableOrDisableCheckButton(); \n" ); UnStackContext(&SuperTP); UnStackContext(&SubTP); icalcomponent_free(cal); }
/* * Scan a room's netconfig to determine whether it requires POP3 aggregation */ void pop3client_scan_room(struct ctdlroom *qrbuf, void *data, OneRoomNetCfg *OneRNCFG) { const RoomNetCfgLine *pLine; void *vptr; pthread_mutex_lock(&POP3QueueMutex); if (GetHash(POP3QueueRooms, LKEY(qrbuf->QRnumber), &vptr)) { pthread_mutex_unlock(&POP3QueueMutex); EVP3CQ_syslog(LOG_DEBUG, "pop3client: [%ld] %s already in progress.", qrbuf->QRnumber, qrbuf->QRname); return; } pthread_mutex_unlock(&POP3QueueMutex); if (server_shutting_down) return; pLine = OneRNCFG->NetConfigs[pop3client]; while (pLine != NULL) { pop3aggr *cptr; cptr = (pop3aggr *) malloc(sizeof(pop3aggr)); memset(cptr, 0, sizeof(pop3aggr)); ///TODO do we need this? cptr->roomlist_parts=1; cptr->RoomName = NewStrBufPlain(qrbuf->QRname, -1); cptr->pop3user = NewStrBufDup(pLine->Value[1]); cptr->pop3pass = NewStrBufDup(pLine->Value[2]); cptr->Url = NewStrBuf(); cptr->Host = NewStrBufDup(pLine->Value[0]); cptr->keep = atol(ChrPtr(pLine->Value[3])); cptr->interval = atol(ChrPtr(pLine->Value[4])); StrBufAppendBufPlain(cptr->Url, HKEY("pop3://"), 0); StrBufUrlescUPAppend(cptr->Url, cptr->pop3user, NULL); StrBufAppendBufPlain(cptr->Url, HKEY(":"), 0); StrBufUrlescUPAppend(cptr->Url, cptr->pop3pass, NULL); StrBufAppendBufPlain(cptr->Url, HKEY("@"), 0); StrBufAppendBuf(cptr->Url, cptr->Host, 0); StrBufAppendBufPlain(cptr->Url, HKEY("/"), 0); StrBufUrlescAppend(cptr->Url, cptr->RoomName, NULL); ParseURL(&cptr->IO.ConnectMe, cptr->Url, 110); #if 0 /* todo: we need to reunite the url to be shure. */ pthread_mutex_lock(&POP3ueueMutex); GetHash(POP3FetchUrls, SKEY(ptr->Url), &vptr); use_this_cptr = (pop3aggr *)vptr; if (use_this_rncptr != NULL) { /* mustn't attach to an active session */ if (use_this_cptr->RefCount > 0) { DeletePOP3Cfg(cptr); /// Count->count--; } else { long *QRnumber; StrBufAppendBufPlain( use_this_cptr->rooms, qrbuf->QRname, -1, 0); if (use_this_cptr->roomlist_parts == 1) { use_this_cptr->OtherQRnumbers = NewHash(1, lFlathash); } QRnumber = (long*)malloc(sizeof(long)); *QRnumber = qrbuf->QRnumber; Put(use_this_cptr->OtherQRnumbers, LKEY(qrbuf->QRnumber), QRnumber, NULL); use_this_cptr->roomlist_parts++; } pthread_mutex_unlock(&POP3QueueMutex); continue; } pthread_mutex_unlock(&RSSQueueMutex); #endif cptr->n = Pop3ClientID++; pthread_mutex_lock(&POP3QueueMutex); Put(POP3FetchUrls, SKEY(cptr->Url), cptr, DeletePOP3Aggregator); pthread_mutex_unlock(&POP3QueueMutex); pLine = pLine->next; } }
void smtp_try_one_queue_entry(OneQueItem *MyQItem, MailQEntry *MyQEntry, StrBuf *MsgText, /*KeepMsgText allows us to use MsgText as ours.*/ int KeepMsgText, int MsgCount) { SmtpOutMsg *Msg; SMTPC_syslog(LOG_DEBUG, "%s\n", __FUNCTION__); Msg = new_smtp_outmsg(MyQItem, MyQEntry, MsgCount); if (Msg == NULL) { SMTPC_syslog(LOG_DEBUG, "%s Failed to alocate message context.\n", __FUNCTION__); if (KeepMsgText) FreeStrBuf (&MsgText); return; } if (KeepMsgText) Msg->msgtext = MsgText; else Msg->msgtext = NewStrBufDup(MsgText); if (smtp_resolve_recipients(Msg) && (!MyQItem->HaveRelay || (MyQItem->URL != NULL))) { safestrncpy( ((CitContext *)Msg->IO.CitContext)->cs_host, Msg->node, sizeof(((CitContext *) Msg->IO.CitContext)->cs_host)); SMTPC_syslog(LOG_DEBUG, "Starting: [%ld] <%s> CC <%d> \n", Msg->MyQItem->MessageID, ChrPtr(Msg->MyQEntry->Recipient), ((CitContext*)Msg->IO.CitContext)->cs_pid); if (Msg->pCurrRelay == NULL) { SetSMTPState(&Msg->IO, eSTMPmxlookup); QueueEventContext(&Msg->IO, resolve_mx_records); } else { /* oh... via relay host */ Msg->IsRelay = 1; if (Msg->pCurrRelay->IsIP) { SetSMTPState(&Msg->IO, eSTMPconnecting); QueueEventContext(&Msg->IO, mx_connect_ip); } else { SetSMTPState(&Msg->IO, eSTMPalookup); /* uneducated admin has chosen to add DNS to the equation... */ QueueEventContext(&Msg->IO, get_one_mx_host_ip); } } } else { SetSMTPState(&Msg->IO, eSMTPFailTotal); /* No recipients? well fail then. */ if (Msg->MyQEntry != NULL) { Msg->MyQEntry->Status = 5; if (StrLength(Msg->MyQEntry->StatusMessage) == 0) StrBufPlain(Msg->MyQEntry->StatusMessage, HKEY("Invalid Recipient!")); } FinalizeMessageSend_DB(&Msg->IO); DeleteSmtpOutMsg(Msg); } }