#define PRIO_UNSTEALTH 45000
/* Priorities for EVT_STEALTH */
#define PRIO_STEALTH 50000
+void CtdlRegisterTDAPVetoHook(int (*fcn_ptr)(StrBuf*), int EventType, int Priority);
+void CtdlUnregisterTDAPVetoHook(int (*fcn_ptr) (StrBuf*), int EventType);
+
+
void CtdlRegisterSessionHook(void (*fcn_ptr)(void), int EventType, int Priority);
void CtdlUnregisterSessionHook(void (*fcn_ptr)(void), int EventType);
void CtdlShutdownServiceHooks(void);
* Purge the use table of old entries.
*
*/
-int PurgeUseTable(void) {
+int PurgeUseTable(StrBuf *ErrMsg) {
int purged = 0;
struct cdbdata *cdbut;
struct UseTable ut;
struct UPurgeList *uptr;
/* Phase 1: traverse through the table, discovering old records... */
+ if (CheckTDAPVeto(CDB_USETABLE, ErrMsg))
+ {
+ syslog(LOG_DEBUG, "Purge use table: VETO!");
+ return 0;
+ }
+
syslog(LOG_DEBUG, "Purge use table: phase 1");
cdb_rewind(CDB_USETABLE);
while(cdbut = cdb_next_item(CDB_USETABLE), cdbut != NULL) {
if (!server_shutting_down)
{
- retval = PurgeUseTable();
+ StrBuf *ErrMsg;
+
+ ErrMsg = NewStrBuf ();
+ retval = PurgeUseTable(ErrMsg);
syslog(LOG_NOTICE, "Purged %d entries from the use table.", retval);
+////TODO: fix errmsg
+ FreeStrBuf(&ErrMsg);
}
if (!server_shutting_down)
int RSSAtomParserDebugEnabled = 0;
-#define N ((rss_aggregator*)IO->Data)->QRnumber
+#define N ((rss_aggregator*)IO->Data)->Cfg.QRnumber
#define DBGLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (RSSAtomParserDebugEnabled != 0))
StrBuf *reLinkTitle;
} networker_save_message;
+typedef struct RSSCfgLine RSSCfgLine;
+struct RSSCfgLine {
+ StrBuf *Url;
+ time_t last_known_good;
+ RSSCfgLine *Next;
+};
+
+typedef struct __pRSSConfig {
+ const RSSCfgLine *pCfg;
+ long QRnumber;
+}pRSSConfig;
+
struct rss_aggregator {
AsyncIO IO;
XML_Parser xp;
time_t next_poll;
StrBuf *Url;
StrBuf *rooms;
- long QRnumber;
+ pRSSConfig Cfg;
HashList *OtherQRnumbers;
StrBuf *CData;
struct rssnetcfg *rnclist = NULL;
int RSSClientDebugEnabled = 0;
-#define N ((rss_aggregator*)IO->Data)->QRnumber
+#define N ((rss_aggregator*)IO->Data)->Cfg.QRnumber
#define DBGLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (RSSClientDebugEnabled != 0))
void UnlinkRooms(rss_aggregator *RSSAggr)
{
- DeleteRoomReference(RSSAggr->QRnumber);
+ DeleteRoomReference(RSSAggr->Cfg.QRnumber);
if (RSSAggr->OtherQRnumbers != NULL)
{
long HKLen;
&vData) &&
(vData != NULL))
{
- long *lData = (long*) vData;
- DeleteRoomReference(*lData);
+ pRSSConfig *Data = (pRSSConfig*) vData;
+ DeleteRoomReference(Data->QRnumber);
}
DeleteHashPos(&At);
return eSendMore;
}
+void UpdateLastKnownGood(pRSSConfig *pCfg, time_t now)
+{
+ OneRoomNetCfg* pRNCfg;
+ begin_critical_section(S_NETCONFIGS);
+ pRNCfg = CtdlGetNetCfgForRoom (pCfg->QRnumber);
+ if (pRNCfg != NULL)
+ {
+ RSSCfgLine *RSSCfg = (RSSCfgLine *)pRNCfg->NetConfigs[rssclient];
+
+ while (RSSCfg != NULL)
+ {
+ if (RSSCfg == pCfg->pCfg)
+ break;
+
+ RSSCfg = RSSCfg->Next;
+ }
+ if (RSSCfg != NULL)
+ {
+ pRNCfg->changed = 1;
+ RSSCfg->last_known_good = now;
+ }
+ }
+
+ end_critical_section(S_NETCONFIGS);
+}
+
eNextState RSSAggregator_AnalyseReply(AsyncIO *IO)
{
+ HashPos *it = NULL;
+ long len;
+ const char *Key;
+ pRSSConfig *pCfg;
u_char rawdigest[MD5_DIGEST_LEN];
struct MD5Context md5context;
StrBuf *guid;
IO->HttpReq.httpcode);
return eAbort;
}
+
+ pCfg = &Ctx->Cfg;
+
+ while (pCfg != NULL)
+ {
+ UpdateLastKnownGood (pCfg, IO->Now);
+ if ((Ctx->roomlist_parts > 1) &&
+ (it == NULL))
+ {
+ it = GetNewHashPos(RSSFetchUrls, 0);
+ }
+ if (it != NULL)
+ {
+ void *vptr;
+ GetNextHashPos(Ctx->OtherQRnumbers, it, &len, &Key, &vptr);
+ pCfg = vptr;
+ }
+ else
+ pCfg = NULL;
+ }
+ DeleteHashPos (&it);
+
SetRSSState(IO, eRSSUT);
MD5Init(&md5context);
*/
void rssclient_scan_room(struct ctdlroom *qrbuf, void *data, OneRoomNetCfg *OneRNCFG)
{
- const RoomNetCfgLine *pLine;
+ const RSSCfgLine *RSSCfg = (RSSCfgLine *)OneRNCFG->NetConfigs[rssclient];
rss_aggregator *RSSAggr = NULL;
rss_aggregator *use_this_RSSAggr = NULL;
void *vptr;
if (server_shutting_down) return;
- pLine = OneRNCFG->NetConfigs[rssclient];
-
- while (pLine != NULL)
+ while (RSSCfg != NULL)
{
- const char *lPtr = NULL;
-
- RSSAggr = (rss_aggregator *) malloc(
- sizeof(rss_aggregator));
-
- memset (RSSAggr, 0, sizeof(rss_aggregator));
- RSSAggr->QRnumber = qrbuf->QRnumber;
- RSSAggr->roomlist_parts = 1;
- RSSAggr->Url = NewStrBufPlain(NULL, StrLength(pLine->Value[0]));
- StrBufExtract_NextToken(RSSAggr->Url,
- pLine->Value[0],
- &lPtr,
- '|');
-
pthread_mutex_lock(&RSSQueueMutex);
GetHash(RSSFetchUrls,
- SKEY(RSSAggr->Url),
+ SKEY(RSSCfg->Url),
&vptr);
use_this_RSSAggr = (rss_aggregator *)vptr;
if (use_this_RSSAggr != NULL)
{
- long *QRnumber;
+ pRSSConfig *pRSSCfg;
+
StrBufAppendBufPlain(
use_this_RSSAggr->rooms,
qrbuf->QRname,
use_this_RSSAggr->OtherQRnumbers
= NewHash(1, lFlathash);
}
- QRnumber = (long*)malloc(sizeof(long));
- *QRnumber = qrbuf->QRnumber;
+
+ pRSSCfg = (pRSSConfig *) malloc(sizeof(pRSSConfig));
+
+ pRSSCfg->QRnumber = qrbuf->QRnumber;
+ pRSSCfg->pCfg = RSSCfg;
+
Put(use_this_RSSAggr->OtherQRnumbers,
LKEY(qrbuf->QRnumber),
- QRnumber,
+ pRSSCfg,
NULL);
use_this_RSSAggr->roomlist_parts++;
pthread_mutex_unlock(&RSSQueueMutex);
- FreeStrBuf(&RSSAggr->Url);
- free(RSSAggr);
- RSSAggr = NULL;
- pLine = pLine->next;
+ RSSCfg = RSSCfg->Next;
continue;
}
pthread_mutex_unlock(&RSSQueueMutex);
+ RSSAggr = (rss_aggregator *) malloc(
+ sizeof(rss_aggregator));
+
+ memset (RSSAggr, 0, sizeof(rss_aggregator));
+ RSSAggr->Cfg.QRnumber = qrbuf->QRnumber;
+ RSSAggr->Cfg.pCfg = RSSCfg;
+ RSSAggr->roomlist_parts = 1;
+ RSSAggr->Url = NewStrBufDup(RSSCfg->Url);
+
RSSAggr->ItemType = RSS_UNSET;
RSSAggr->rooms = NewStrBufPlain(
DeleteRssCfg);
pthread_mutex_unlock(&RSSQueueMutex);
- pLine = pLine->next;
+ RSSCfg = RSSCfg->Next;
}
}
RSSClientDebugEnabled = n;
}
+
+typedef struct __RSSVetoInfo {
+ StrBuf *ErrMsg;
+ time_t Now;
+ int Veto;
+}RSSVetoInfo;
+
+void rssclient_veto_scan_room(struct ctdlroom *qrbuf, void *data, OneRoomNetCfg *OneRNCFG)
+{
+ RSSVetoInfo *Info = (RSSVetoInfo *) data;
+ const RSSCfgLine *RSSCfg = (RSSCfgLine *)OneRNCFG->NetConfigs[rssclient];
+
+ while (RSSCfg != NULL)
+ {
+ if ((RSSCfg->last_known_good != 0) &&
+ (RSSCfg->last_known_good + USETABLE_ANTIEXPIRE < Info->Now))
+ {
+ StrBufAppendPrintf(Info->ErrMsg,
+ "RSS feed not seen for a %d days:: <",
+ (Info->Now - RSSCfg->last_known_good) / (24 * 60 * 60));
+
+ StrBufAppendBuf(Info->ErrMsg, RSSCfg->Url, 0);
+ StrBufAppendBufPlain(Info->ErrMsg, HKEY(">\n"), 0);
+ }
+ RSSCfg = RSSCfg->Next;
+ }
+}
+
+int RSSCheckUsetableVeto(StrBuf *ErrMsg)
+{
+ RSSVetoInfo Info;
+
+ Info.ErrMsg = ErrMsg;
+ Info.Now = time (NULL);
+ Info.Veto = 0;
+
+ CtdlForEachNetCfgRoom(rssclient_veto_scan_room, &Info, rssclient);
+
+ return Info.Veto;;
+}
+
+
+
+
+void ParseRSSClientCfgLine(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *OneRNCFG)
+{
+ RSSCfgLine *RSSCfg;
+
+ RSSCfg = (RSSCfgLine *) malloc (sizeof(RSSCfgLine));
+ RSSCfg->Url = NewStrBufPlain (NULL, StrLength (Line));
+
+
+ StrBufExtract_NextToken(RSSCfg->Url, Line, &LinePos, '|');
+ RSSCfg->last_known_good = StrBufExtractNext_long(Line, &LinePos, '|');
+
+
+ RSSCfg->Next = (RSSCfgLine *)OneRNCFG->NetConfigs[ThisOne->C];
+ OneRNCFG->NetConfigs[ThisOne->C] = (RoomNetCfgLine*) RSSCfg;
+}
+
+void SerializeRSSClientCfgLine(const CfgLineType *ThisOne, StrBuf *OutputBuffer, OneRoomNetCfg *RNCfg, RoomNetCfgLine *data)
+{
+ RSSCfgLine *RSSCfg = (RSSCfgLine*) data;
+
+ StrBufAppendBufPlain(OutputBuffer, CKEY(ThisOne->Str), 0);
+ StrBufAppendBufPlain(OutputBuffer, HKEY("|"), 0);
+ StrBufAppendBufPlain(OutputBuffer, SKEY(RSSCfg->Url), 0);
+ StrBufAppendPrintf(OutputBuffer, "|%ld\n", RSSCfg->last_known_good);
+}
+
+void DeleteRSSClientCfgLine(const CfgLineType *ThisOne, RoomNetCfgLine **data)
+{
+ RSSCfgLine *RSSCfg = (RSSCfgLine*) data;
+
+ FreeStrBuf(&RSSCfg->Url);
+ free(*data);
+ *data = NULL;
+}
+
+
CTDL_MODULE_INIT(rssclient)
{
if (!threading)
{
- CtdlREGISTERRoomCfgType(rssclient, ParseGeneric, 0, 1, SerializeGeneric, DeleteGenericCfgLine); /// todo: implement rss specific parser
+ CtdlRegisterTDAPVetoHook (RSSCheckUsetableVeto, CDB_USETABLE, 0);
+
+ CtdlREGISTERRoomCfgType(rssclient, ParseRSSClientCfgLine, 0, 1, SerializeRSSClientCfgLine, DeleteRSSClientCfgLine);
pthread_mutex_init(&RSSQueueMutex, NULL);
RSSQueueRooms = NewHash(1, lFlathash);
RSSFetchUrls = NewHash(1, NULL);
int loglevel;
void (*h_function_pointer) (char *);
};
-extern LogFunctionHook *LogHookTable;
+
+LogFunctionHook *LogHookTable = NULL;
typedef struct FixedOutputHook FixedOutputHook;
struct FixedOutputHook {
char content_type[64];
void (*h_function_pointer) (char *, int);
};
-extern FixedOutputHook *FixedOutputTable;
+FixedOutputHook *FixedOutputTable = NULL;
+
+
+
+/*
+ * TDAPVetoHookFunctionHook extensions are used for any type of hook for which
+ * may prevent the autopurger to run for this specific data class.
+ * the function should at least LOG_INFO that it does so.
+ */
+typedef struct TDAPVetoHookFunctionHook TDAPVetoHookFunctionHook;
+struct TDAPVetoHookFunctionHook {
+ TDAPVetoHookFunctionHook *next;
+ int Priority;
+ int (*h_function_pointer) (StrBuf *);
+ int eventtype;
+};
+TDAPVetoHookFunctionHook *TDAPVetoHookTable = NULL;
void (*h_function_pointer) (void);
int eventtype;
};
-extern SessionFunctionHook *SessionHookTable;
-
+SessionFunctionHook *SessionHookTable = NULL;
/*
* UserFunctionHook extensions are used for any type of hook which implements
void (*h_function_pointer) (struct ctdluser *usbuf);
int eventtype;
};
-extern UserFunctionHook *UserHookTable;
+UserFunctionHook *UserHookTable = NULL;
/*
* MessageFunctionHook extensions are used for hooks which implement handlers
int (*h_function_pointer) (struct CtdlMessage *msg);
int eventtype;
};
-extern MessageFunctionHook *MessageHookTable;
+MessageFunctionHook *MessageHookTable = NULL;
/*
NetprocFunctionHook *next;
int (*h_function_pointer) (struct CtdlMessage *msg, char *target_room);
};
-extern NetprocFunctionHook *NetprocHookTable;
+NetprocFunctionHook *NetprocHookTable = NULL;
/*
DeleteFunctionHook *next;
void (*h_function_pointer) (char *target_room, long msgnum);
};
-extern DeleteFunctionHook *DeleteHookTable;
+DeleteFunctionHook *DeleteHookTable = NULL;
/*
int (*h_function_pointer) (char *, char *, char *, char *);
int order;
};
-extern XmsgFunctionHook *XmsgHookTable;
+XmsgFunctionHook *XmsgHookTable = NULL;
RoomFunctionHook *next;
int (*fcn_ptr) (struct ctdlroom *);
};
-extern RoomFunctionHook *RoomHookTable;
+RoomFunctionHook *RoomHookTable = NULL;
void (*fcn_ptr) (int *, long **, const char *);
char *name;
};
-extern SearchFunctionHook *SearchFunctionHookTable;
-
+SearchFunctionHook *SearchFunctionHookTable = NULL;
CleanupFunctionHook *CleanupHookTable = NULL;
CleanupFunctionHook *EVCleanupHookTable = NULL;
-SessionFunctionHook *SessionHookTable = NULL;
-UserFunctionHook *UserHookTable = NULL;
-XmsgFunctionHook *XmsgHookTable = NULL;
-MessageFunctionHook *MessageHookTable = NULL;
-NetprocFunctionHook *NetprocHookTable = NULL;
-DeleteFunctionHook *DeleteHookTable = NULL;
+
ServiceFunctionHook *ServiceHookTable = NULL;
-FixedOutputHook *FixedOutputTable = NULL;
-RoomFunctionHook *RoomHookTable = NULL;
-SearchFunctionHook *SearchFunctionHookTable = NULL;
typedef struct ProtoFunctionHook ProtoFunctionHook;
struct ProtoFunctionHook {
EVCleanupHookTable = NULL;
}
+void CtdlRegisterTDAPVetoHook(int (*fcn_ptr) (StrBuf*), int EventType, int Priority)
+{
+ TDAPVetoHookFunctionHook *newfcn;
+
+ newfcn = (TDAPVetoHookFunctionHook *)
+ malloc(sizeof(TDAPVetoHookFunctionHook));
+ newfcn->Priority = Priority;
+ newfcn->h_function_pointer = fcn_ptr;
+ newfcn->eventtype = EventType;
+
+ TDAPVetoHookFunctionHook **pfcn;
+ pfcn = &TDAPVetoHookTable;
+ while ((*pfcn != NULL) &&
+ ((*pfcn)->Priority < newfcn->Priority) &&
+ ((*pfcn)->next != NULL))
+ pfcn = &(*pfcn)->next;
+
+ newfcn->next = *pfcn;
+ *pfcn = newfcn;
+
+ MOD_syslog(LOG_DEBUG, "Registered a new TDAP Veto function (type %d Priority %d)\n",
+ EventType, Priority);
+}
+
+
+void CtdlUnregisterTDAPVetoHook(int (*fcn_ptr) (StrBuf*), int EventType)
+{
+ TDAPVetoHookFunctionHook *cur, *p, *last;
+ last = NULL;
+ cur = TDAPVetoHookTable;
+ while (cur != NULL) {
+ if ((fcn_ptr == cur->h_function_pointer) &&
+ (EventType == cur->eventtype))
+ {
+ MOD_syslog(LOG_DEBUG, "Unregistered TDAP Veto function (type %d)\n",
+ EventType);
+ p = cur->next;
+
+ free(cur);
+ cur = NULL;
+
+ if (last != NULL)
+ last->next = p;
+ else
+ TDAPVetoHookTable = p;
+ cur = p;
+ }
+ else {
+ last = cur;
+ cur = cur->next;
+ }
+ }
+}
+
+void CtdlDestroyTDAPVetoHooks(void)
+{
+ TDAPVetoHookFunctionHook *cur, *p;
+
+ cur = TDAPVetoHookTable;
+ while (cur != NULL)
+ {
+ MODM_syslog(LOG_DEBUG, "Destroyed TDAP Veto function\n");
+ p = cur->next;
+ free(cur);
+ cur = p;
+ }
+ TDAPVetoHookTable = NULL;
+}
+
void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType, int Priority)
{
*num_msgs = 0;
}
+int CheckTDAPVeto (int DBType, StrBuf *ErrMsg)
+{
+ int Result = 0;
+ TDAPVetoHookFunctionHook *fcn = NULL;
+
+ for (fcn = TDAPVetoHookTable; (fcn != NULL) && (Result == 0); fcn = fcn->next) {
+ if (fcn->eventtype == DBType) {
+ Result = (*fcn->h_function_pointer) (ErrMsg);
+ }
+ }
+ return Result;
+}
void PerformSessionHooks(int EventType)
{
void CtdlDestroySessionHooks(void);
void PerformSessionHooks(int EventType);
+int CheckTDAPVeto (int DBType, StrBuf *ErrMsg);
+void CtdlDestroyTDAPVetoHooks(void);
+
void CtdlDestroyUserHooks(void);
void PerformUserHooks(struct ctdluser *usbuf, int EventType);
CtdlDestroyCleanupHooks();
CtdlDestroyFixedOutputHooks();
CtdlDestroySessionHooks();
+ CtdlDestroyTDAPVetoHooks();
CtdlDestroyServiceHook();
CtdlDestroyRoomHooks();
CtdlDestroySearchHooks();
#include <unistd.h>
#include <sys/types.h>
+#include <libcitadel.h>
+
#include "auth.h"
#include "config.h"
#include "citadel_dirs.h"