X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fpop3client%2Fserv_pop3client.c;h=6adaf154981f8c3b65335bb6074ea3a1b3ec9dd6;hb=2b402dc292b6dcdbc7a3786a6c722e06e3be5ab5;hp=117b505240e13c2268908b78a7e36d2d9b75021f;hpb=0a9ce8b874c26e7d17c5af0de174111dd1536791;p=citadel.git diff --git a/citadel/modules/pop3client/serv_pop3client.c b/citadel/modules/pop3client/serv_pop3client.c index 117b50524..6adaf1549 100644 --- a/citadel/modules/pop3client/serv_pop3client.c +++ b/citadel/modules/pop3client/serv_pop3client.c @@ -55,7 +55,7 @@ struct CitContext pop3_client_CC; -citthread_mutex_t POP3QueueMutex; /* locks the access to the following vars: */ +pthread_mutex_t POP3QueueMutex; /* locks the access to the following vars: */ HashList *POP3QueueRooms = NULL; /* rss_room_counter */ HashList *POP3FetchUrls = NULL; /* -> rss_aggregator; ->RefCount access to be locked too. */ @@ -156,15 +156,15 @@ eNextState FinalizePOP3AggrRun(AsyncIO *IO) HashPos *It; pop3aggr *cptr = (pop3aggr *)IO->Data; - CtdlLogPrintf(CTDL_DEBUG, "Terminating Aggregator; bye.\n"); + syslog(LOG_DEBUG, "Terminating Aggregator; bye.\n"); It = GetNewHashPos(POP3FetchUrls, 0); - citthread_mutex_lock(&POP3QueueMutex); + pthread_mutex_lock(&POP3QueueMutex); { GetHashPosFromKey(POP3FetchUrls, SKEY(cptr->Url), It); DeleteEntryFromHash(POP3FetchUrls, It); } - citthread_mutex_unlock(&POP3QueueMutex); + pthread_mutex_unlock(&POP3QueueMutex); DeleteHashPos(&It); return eAbort; } @@ -174,8 +174,9 @@ eNextState FailAggregationRun(AsyncIO *IO) return eAbort; } -#define POP3C_DBG_SEND() CtdlLogPrintf(CTDL_DEBUG, "POP3 client[%ld]: > %s\n", RecvMsg->n, ChrPtr(RecvMsg->IO.SendBuf.Buf)) -#define POP3C_DBG_READ() CtdlLogPrintf(CTDL_DEBUG, "POP3 client[%ld]: < %s\n", RecvMsg->n, ChrPtr(RecvMsg->IO.IOBuf)) + +#define POP3C_DBG_SEND() syslog(LOG_DEBUG, "POP3 client[%ld]: > %s\n", RecvMsg->n, ChrPtr(RecvMsg->IO.SendBuf.Buf)) +#define POP3C_DBG_READ() syslog(LOG_DEBUG, "POP3 client[%ld]: < %s\n", RecvMsg->n, ChrPtr(RecvMsg->IO.IOBuf)) #define POP3C_OK (strncasecmp(ChrPtr(RecvMsg->IO.IOBuf), "+OK", 3) == 0) eNextState POP3C_ReadGreeting(pop3aggr *RecvMsg) @@ -186,7 +187,6 @@ eNextState POP3C_ReadGreeting(pop3aggr *RecvMsg) else return eSendReply; } - eNextState POP3C_SendUser(pop3aggr *RecvMsg) { /* Identify ourselves. NOTE: we have to append a CR to each command. The LF will @@ -212,7 +212,7 @@ eNextState POP3C_SendPassword(pop3aggr *RecvMsg) /* Password */ StrBufPrintf(RecvMsg->IO.SendBuf.Buf, "PASS %s\r\n", ChrPtr(RecvMsg->pop3pass)); - CtdlLogPrintf(CTDL_DEBUG, "\n"); + syslog(LOG_DEBUG, "\n"); // POP3C_DBG_SEND(); return eReadMessage; } @@ -277,14 +277,14 @@ eNextState POP3C_GetListOneLine(pop3aggr *RecvMsg) #if 0 rc = TestValidateHash(RecvMsg->MsgNumbers); if (rc != 0) - CtdlLogPrintf(CTDL_DEBUG, "Hash Invalid: %d\n", rc); + 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) - CtdlLogPrintf(CTDL_DEBUG, "Hash Invalid: %d\n", rc); + syslog(LOG_DEBUG, "Hash Invalid: %d\n", rc); #endif //RecvMsg->State --; /* read next Line */ return eReadMore; @@ -301,9 +301,11 @@ eNextState POP3_FetchNetworkUsetableEntry(AsyncIO *IO) if(GetNextHashPos(RecvMsg->MsgNumbers, RecvMsg->Pos, &HKLen, &HKey, &vData)) { struct UseTable ut; - + if (server_shutting_down) + return eAbort; + RecvMsg->CurrMsg = (FetchItem*) vData; - CtdlLogPrintf(CTDL_DEBUG, "CHECKING: whether %s has already been seen: ", ChrPtr(RecvMsg->CurrMsg->MsgUID)); + syslog(LOG_DEBUG, "CHECKING: whether %s has already been seen: ", ChrPtr(RecvMsg->CurrMsg->MsgUID)); /* Find out if we've already seen this item */ safestrncpy(ut.ut_msgid, ChrPtr(RecvMsg->CurrMsg->MsgUID), @@ -313,7 +315,7 @@ eNextState POP3_FetchNetworkUsetableEntry(AsyncIO *IO) cdbut = cdb_fetch(CDB_USETABLE, SKEY(RecvMsg->CurrMsg->MsgUID)); if (cdbut != NULL) { /* Item has already been seen */ - CtdlLogPrintf(CTDL_DEBUG, "YES\n"); + syslog(LOG_DEBUG, "YES\n"); cdb_free(cdbut); /* rewrite the record anyway, to update the timestamp */ @@ -324,7 +326,7 @@ eNextState POP3_FetchNetworkUsetableEntry(AsyncIO *IO) } else { - CtdlLogPrintf(CTDL_DEBUG, "NO\n"); + syslog(LOG_DEBUG, "NO\n"); RecvMsg->CurrMsg->NeedFetch = 1; } return NextDBOperation(&RecvMsg->IO, POP3_FetchNetworkUsetableEntry); @@ -348,7 +350,7 @@ eNextState POP3C_GetOneMessagID(pop3aggr *RecvMsg) int rc; rc = TestValidateHash(RecvMsg->MsgNumbers); if (rc != 0) - CtdlLogPrintf(CTDL_DEBUG, "Hash Invalid: %d\n", rc); + syslog(LOG_DEBUG, "Hash Invalid: %d\n", rc); #endif if(GetNextHashPos(RecvMsg->MsgNumbers, RecvMsg->Pos, &HKLen, &HKey, &vData)) { @@ -375,7 +377,7 @@ eNextState POP3C_GetOneMessageIDState(pop3aggr *RecvMsg) int rc; rc = TestValidateHash(RecvMsg->MsgNumbers); if (rc != 0) - CtdlLogPrintf(CTDL_DEBUG, "Hash Invalid: %d\n", rc); + syslog(LOG_DEBUG, "Hash Invalid: %d\n", rc); #endif POP3C_DBG_READ(); @@ -440,7 +442,7 @@ eNextState POP3C_StoreMsgRead(AsyncIO *IO) pop3aggr *RecvMsg = (pop3aggr *) IO->Data; struct UseTable ut; - CtdlLogPrintf(CTDL_DEBUG, "MARKING: %s as seen: ", ChrPtr(RecvMsg->CurrMsg->MsgUID)); + syslog(LOG_DEBUG, "MARKING: %s as seen: ", ChrPtr(RecvMsg->CurrMsg->MsgUID)); safestrncpy(ut.ut_msgid, ChrPtr(RecvMsg->CurrMsg->MsgUID), @@ -475,7 +477,7 @@ eNextState POP3C_SaveMsg(AsyncIO *IO) eNextState POP3C_ReadMessageBody(pop3aggr *RecvMsg) { - CtdlLogPrintf(CTDL_DEBUG, "Converting message...\n"); + syslog(LOG_DEBUG, "Converting message...\n"); RecvMsg->CurrMsg->Msg = convert_internet_message_buf(&RecvMsg->IO.ReadMsg->MsgBuf); return QueueDBOperation(&RecvMsg->IO, POP3C_SaveMsg); @@ -587,7 +589,7 @@ void POP3SetTimeout(eNextState NextTCPState, pop3aggr *pMsg) { double Timeout = 0.0; - CtdlLogPrintf(CTDL_DEBUG, "POP3: %s\n", __FUNCTION__); + syslog(LOG_DEBUG, "POP3: %s\n", __FUNCTION__); switch (NextTCPState) { case eSendReply: @@ -629,7 +631,7 @@ void POP3SetTimeout(eNextState NextTCPState, pop3aggr *pMsg) } eNextState POP3_C_DispatchReadDone(AsyncIO *IO) { - CtdlLogPrintf(CTDL_DEBUG, "POP3: %s\n", __FUNCTION__); + syslog(LOG_DEBUG, "POP3: %s\n", __FUNCTION__); pop3aggr *pMsg = IO->Data; eNextState rc; @@ -641,7 +643,7 @@ eNextState POP3_C_DispatchReadDone(AsyncIO *IO) } eNextState POP3_C_DispatchWriteDone(AsyncIO *IO) { - CtdlLogPrintf(CTDL_DEBUG, "POP3: %s\n", __FUNCTION__); + syslog(LOG_DEBUG, "POP3: %s\n", __FUNCTION__); pop3aggr *pMsg = IO->Data; eNextState rc; @@ -658,7 +660,7 @@ eNextState POP3_C_Terminate(AsyncIO *IO) { /// pop3aggr *pMsg = (pop3aggr *)IO->Data; - CtdlLogPrintf(CTDL_DEBUG, "POP3: %s\n", __FUNCTION__); + syslog(LOG_DEBUG, "POP3: %s\n", __FUNCTION__); FinalizePOP3AggrRun(IO); return eAbort; } @@ -666,7 +668,7 @@ eNextState POP3_C_Timeout(AsyncIO *IO) { pop3aggr *pMsg = IO->Data; - CtdlLogPrintf(CTDL_DEBUG, "POP3: %s\n", __FUNCTION__); + syslog(LOG_DEBUG, "POP3: %s\n", __FUNCTION__); StrBufPlain(IO->ErrMsg, CKEY(POP3C_ReadErrors[pMsg->State])); return FailAggregationRun(IO); } @@ -674,13 +676,13 @@ eNextState POP3_C_ConnFail(AsyncIO *IO) { pop3aggr *pMsg = (pop3aggr *)IO->Data; - CtdlLogPrintf(CTDL_DEBUG, "POP3: %s\n", __FUNCTION__); + syslog(LOG_DEBUG, "POP3: %s\n", __FUNCTION__); StrBufPlain(IO->ErrMsg, CKEY(POP3C_ReadErrors[pMsg->State])); return FailAggregationRun(IO); } eNextState POP3_C_Shutdown(AsyncIO *IO) { - CtdlLogPrintf(CTDL_DEBUG, "POP3: %s\n", __FUNCTION__); + syslog(LOG_DEBUG, "POP3: %s\n", __FUNCTION__); //// pop3aggr *pMsg = IO->Data; ////pMsg->MyQEntry->Status = 3; @@ -726,7 +728,7 @@ eNextState POP3_C_ReAttachToFetchMessages(AsyncIO *IO) { pop3aggr *cpptr = IO->Data; - CtdlLogPrintf(CTDL_DEBUG, "POP3: %s\n", __FUNCTION__); + syslog(LOG_DEBUG, "POP3: %s\n", __FUNCTION__); ////??? cpptr->State ++; if (cpptr->Pos == NULL) cpptr->Pos = GetNewHashPos(cpptr->MsgNumbers, 0); @@ -741,7 +743,7 @@ eNextState connect_ip(AsyncIO *IO) { pop3aggr *cpptr = IO->Data; - CtdlLogPrintf(CTDL_DEBUG, "POP3: %s\n", __FUNCTION__); + syslog(LOG_DEBUG, "POP3: %s\n", __FUNCTION__); //// IO->ConnectMe = &cpptr->Pop3Host; /* Bypass the ns lookup result like this: IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1"); */ @@ -803,9 +805,9 @@ eNextState get_one_host_ip(AsyncIO *IO) InitC_ares_dns(IO); - CtdlLogPrintf(CTDL_DEBUG, "POP3: %s\n", __FUNCTION__); + syslog(LOG_DEBUG, "POP3: %s\n", __FUNCTION__); - CtdlLogPrintf(CTDL_DEBUG, + syslog(LOG_DEBUG, "POP3 client[%ld]: looking up %s-Record %s : %d ...\n", cpptr->n, (cpptr->IO.ConnectMe->IPv6)? "aaaa": "a", @@ -843,8 +845,8 @@ int pop3_do_fetching(pop3aggr *cpptr) cpptr->IO.NextState = eReadMessage; /* TODO - CtdlLogPrintf(CTDL_DEBUG, "POP3: %s %s %s \n", roomname, pop3host, pop3user); - CtdlLogPrintf(CTDL_NOTICE, "Connecting to <%s>\n", pop3host); + syslog(LOG_DEBUG, "POP3: %s %s %s \n", roomname, pop3host, pop3user); + syslog(LOG_DEBUG, "Connecting to <%s>\n", pop3host); */ SubC = CloneContext (&pop3_client_CC); @@ -882,48 +884,50 @@ void pop3client_scan_room(struct ctdlroom *qrbuf, void *data) // pop3_room_counter *Count = NULL; // pop3aggr *cpptr; - citthread_mutex_lock(&POP3QueueMutex); + pthread_mutex_lock(&POP3QueueMutex); if (GetHash(POP3QueueRooms, LKEY(qrbuf->QRnumber), &vptr)) { - CtdlLogPrintf(CTDL_DEBUG, + syslog(LOG_DEBUG, "pop3client: [%ld] %s already in progress.\n", qrbuf->QRnumber, qrbuf->QRname); - citthread_mutex_unlock(&POP3QueueMutex); - return; + pthread_mutex_unlock(&POP3QueueMutex); } - citthread_mutex_unlock(&POP3QueueMutex); + pthread_mutex_unlock(&POP3QueueMutex); + + if (server_shutting_down) + return; assoc_file_name(filename, sizeof filename, qrbuf, ctdl_netcfg_dir); - if (CtdlThreadCheckStop()) + if (server_shutting_down) return; /* Only do net processing for rooms that have netconfigs */ fd = open(filename, 0); if (fd <= 0) { - //CtdlLogPrintf(CTDL_DEBUG, "rssclient: %s no config.\n", qrbuf->QRname); + //syslog(LOG_DEBUG, "rssclient: %s no config.\n", qrbuf->QRname); return; } - if (CtdlThreadCheckStop()) + if (server_shutting_down) return; if (fstat(fd, &statbuf) == -1) { - CtdlLogPrintf(CTDL_DEBUG, "ERROR: could not stat configfile '%s' - %s\n", + syslog(LOG_DEBUG, "ERROR: could not stat configfile '%s' - %s\n", filename, strerror(errno)); return; } - if (CtdlThreadCheckStop()) + if (server_shutting_down) return; CfgData = NewStrBufPlain(NULL, statbuf.st_size + 1); if (StrBufReadBLOB(CfgData, &fd, 1, statbuf.st_size, &Err) < 0) { close(fd); FreeStrBuf(&CfgData); - CtdlLogPrintf(CTDL_DEBUG, "ERROR: reading config '%s' - %s
\n", + syslog(LOG_DEBUG, "ERROR: reading config '%s' - %s
\n", filename, strerror(errno)); return; } close(fd); - if (CtdlThreadCheckStop()) + if (server_shutting_down) return; CfgPtr = NULL; @@ -977,7 +981,7 @@ void pop3client_scan_room(struct ctdlroom *qrbuf, void *data) #if 0 /* todo: we need to reunite the url to be shure. */ - citthread_mutex_lock(&POP3ueueMutex); + pthread_mutex_lock(&POP3ueueMutex); GetHash(POP3FetchUrls, SKEY(ptr->Url), &vptr); use_this_cptr = (pop3aggr *)vptr; @@ -1004,15 +1008,15 @@ void pop3client_scan_room(struct ctdlroom *qrbuf, void *data) Put(use_this_cptr->OtherQRnumbers, LKEY(qrbuf->QRnumber), QRnumber, NULL); use_this_cptr->roomlist_parts++; } - citthread_mutex_unlock(&POP3QueueMutex); + pthread_mutex_unlock(&POP3QueueMutex); continue; } - citthread_mutex_unlock(&RSSQueueMutex); + pthread_mutex_unlock(&RSSQueueMutex); #endif - citthread_mutex_lock(&POP3QueueMutex); + pthread_mutex_lock(&POP3QueueMutex); Put(POP3FetchUrls, SKEY(cptr->Url), cptr, DeletePOP3Aggregator); - citthread_mutex_unlock(&POP3QueueMutex); + pthread_mutex_unlock(&POP3QueueMutex); } @@ -1059,23 +1063,33 @@ void pop3client_scan(void) { if (doing_pop3client) return; doing_pop3client = 1; - CtdlLogPrintf(CTDL_DEBUG, "pop3client started\n"); + syslog(LOG_DEBUG, "pop3client started\n"); CtdlForEachRoom(pop3client_scan_room, NULL); - - citthread_mutex_lock(&POP3QueueMutex); + pthread_mutex_lock(&POP3QueueMutex); it = GetNewHashPos(POP3FetchUrls, 0); - while (GetNextHashPos(POP3FetchUrls, it, &len, &Key, &vrptr) && + while (!server_shutting_down && + GetNextHashPos(POP3FetchUrls, it, &len, &Key, &vrptr) && (vrptr != NULL)) { cptr = (pop3aggr *)vrptr; if (cptr->RefCount == 0) if (!pop3_do_fetching(cptr)) DeletePOP3Aggregator(cptr);////TODO + +/* + if ((palist->interval && time(NULL) > (last_run + palist->interval)) + || (time(NULL) > last_run + config.c_pop3_fetch)) + pop3_do_fetching(palist->roomname, palist->pop3host, + palist->pop3user, palist->pop3pass, palist->keep); + pptr = palist; + palist = palist->next; + free(pptr); +*/ } DeleteHashPos(&it); - citthread_mutex_unlock(&POP3QueueMutex); + pthread_mutex_unlock(&POP3QueueMutex); - CtdlLogPrintf(CTDL_DEBUG, "pop3client ended\n"); + syslog(LOG_DEBUG, "pop3client ended\n"); last_run = time(NULL); doing_pop3client = 0; } @@ -1083,7 +1097,7 @@ void pop3client_scan(void) { void pop3_cleanup(void) { - citthread_mutex_destroy(&POP3QueueMutex); + /* citthread_mutex_destroy(&POP3QueueMutex); TODO */ DeleteHash(&POP3FetchUrls); DeleteHash(&POP3QueueRooms); } @@ -1093,7 +1107,7 @@ CTDL_MODULE_INIT(pop3client) if (!threading) { CtdlFillSystemContext(&pop3_client_CC, "POP3aggr"); - citthread_mutex_init(&POP3QueueMutex, NULL); + pthread_mutex_init(&POP3QueueMutex, NULL); POP3QueueRooms = NewHash(1, lFlathash); POP3FetchUrls = NewHash(1, NULL); CtdlRegisterSessionHook(pop3client_scan, EVT_TIMER);