From: Wilfried Goesgens Date: Tue, 24 Apr 2012 18:27:06 +0000 (+0200) Subject: Merge branch 'master' of ssh://git.citadel.org/appl/gitroot/citadel X-Git-Tag: v8.11~67 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=94ef7564c4585129c6025debe797c8dade2e6885;hp=0e825f80816d1166a72cee722663a9a2d3c16782;p=citadel.git Merge branch 'master' of ssh://git.citadel.org/appl/gitroot/citadel --- diff --git a/citadel/modules/network/serv_networkclient.c b/citadel/modules/network/serv_networkclient.c index a8aaa06e5..91dd4ad4d 100644 --- a/citadel/modules/network/serv_networkclient.c +++ b/citadel/modules/network/serv_networkclient.c @@ -91,22 +91,26 @@ struct CitContext networker_client_CC; #define NODE ChrPtr(((AsyncNetworker*)IO->Data)->node) #define N ((AsyncNetworker*)IO->Data)->n +int NetworkClientDebugEnabled = 0; + +#define DBGLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (NetworkClientDebugEnabled != 0)) + #define EVN_syslog(LEVEL, FORMAT, ...) \ - syslog(LEVEL, \ + DBGLOG(LEVEL) syslog(LEVEL, \ "IO[%ld]CC[%d]NW[%s][%ld]" FORMAT, \ IO->ID, CCID, NODE, N, __VA_ARGS__) #define EVNM_syslog(LEVEL, FORMAT) \ - syslog(LEVEL, \ + DBGLOG(LEVEL) syslog(LEVEL, \ "IO[%ld]CC[%d]NW[%s][%ld]" FORMAT, \ IO->ID, CCID, NODE, N) #define EVNCS_syslog(LEVEL, FORMAT, ...) \ - syslog(LEVEL, "IO[%ld]NW[%s][%ld]" FORMAT, \ + DBGLOG(LEVEL) syslog(LEVEL, "IO[%ld]NW[%s][%ld]" FORMAT, \ IO->ID, NODE, N, __VA_ARGS__) #define EVNCSM_syslog(LEVEL, FORMAT) \ - syslog(LEVEL, "IO[%ld]NW[%s][%ld]" FORMAT, \ + DBGLOG(LEVEL) syslog(LEVEL, "IO[%ld]NW[%s][%ld]" FORMAT, \ IO->ID, NODE, N) @@ -1033,8 +1037,10 @@ void network_do_clientqueue(void) free(working_ignetcfg); } - - +void LogDebugEnableNetworkClient(void) +{ + NetworkClientDebugEnabled = 1; +} /* * Module entry point */ @@ -1045,6 +1051,8 @@ CTDL_MODULE_INIT(network_client) CtdlFillSystemContext(&networker_client_CC, "CitNetworker"); CtdlRegisterSessionHook(network_do_clientqueue, EVT_TIMER); + CtdlRegisterDebugFlagHook(HKEY("networkclient"), LogDebugEnableNetworkClient); + } - return "network_client"; + return "networkclient"; } diff --git a/citadel/modules/smtp/serv_smtpeventclient.c b/citadel/modules/smtp/serv_smtpeventclient.c index 3037b0c0c..2869b8d44 100644 --- a/citadel/modules/smtp/serv_smtpeventclient.c +++ b/citadel/modules/smtp/serv_smtpeventclient.c @@ -90,6 +90,7 @@ #include "smtpqueue.h" #include "smtp_clienthandlers.h" +int SMTPClientDebugEnabled = 0; const unsigned short DefaultMXPort = 25; void DeleteSmtpOutMsg(void *v) { @@ -829,7 +830,14 @@ eReadState SMTP_C_ReadServerStatus(AsyncIO *IO) return Finished; } +void LogDebugEnableSMTPClient(void) +{ + SMTPClientDebugEnabled = 1; +} + CTDL_MODULE_INIT(smtp_eventclient) { + if (!threading) + CtdlRegisterDebugFlagHook(HKEY("smtpeventclient"), LogDebugEnableSMTPClient); return "smtpeventclient"; } diff --git a/citadel/modules/smtp/smtp_clienthandlers.c b/citadel/modules/smtp/smtp_clienthandlers.c index 09a1bd881..0a01805c6 100644 --- a/citadel/modules/smtp/smtp_clienthandlers.c +++ b/citadel/modules/smtp/smtp_clienthandlers.c @@ -90,16 +90,16 @@ #define SMTP_ERROR(WHICH_ERR, ERRSTR) do { \ Msg->MyQEntry->Status = WHICH_ERR; \ - StrBufAppendBufPlain(Msg->MyQEntry->StatusMessage, \ + StrBufAppendBufPlain(Msg->MyQEntry->StatusMessage, \ HKEY(ERRSTR), 0); \ return eAbort; } \ while (0) #define SMTP_VERROR(WHICH_ERR) do { \ Msg->MyQEntry->Status = WHICH_ERR; \ - StrBufPlain(Msg->MyQEntry->StatusMessage, \ - ChrPtr(Msg->IO.IOBuf) + 4, \ - StrLength(Msg->IO.IOBuf) - 4); \ + StrBufPlain(Msg->MyQEntry->StatusMessage, \ + ChrPtr(Msg->IO.IOBuf) + 4, \ + StrLength(Msg->IO.IOBuf) - 4); \ return eAbort; } \ while (0) diff --git a/citadel/modules/smtp/smtp_clienthandlers.h b/citadel/modules/smtp/smtp_clienthandlers.h index 38a7f58f4..46532c032 100644 --- a/citadel/modules/smtp/smtp_clienthandlers.h +++ b/citadel/modules/smtp/smtp_clienthandlers.h @@ -87,26 +87,28 @@ const double SMTP_C_ConnTimeout; #define F_HAVE_MX (1<<3) /* we have a list of mx records to go through.*/ #define F_DIRECT (1<<4) /* no mx record found, trying direct connect. */ +extern int SMTPClientDebugEnabled; int smtp_resolve_recipients(SmtpOutMsg *SendMsg); #define QID ((SmtpOutMsg*)IO->Data)->MyQItem->MessageID #define N ((SmtpOutMsg*)IO->Data)->n +#define DBGLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (SMTPClientDebugEnabled != 0)) #define EVS_syslog(LEVEL, FORMAT, ...) \ - syslog(LEVEL, \ + DBGLOG(LEVEL) syslog(LEVEL, \ "IO[%ld]CC[%d]S[%ld][%ld]" FORMAT, \ IO->ID, CCID, QID, N, __VA_ARGS__) #define EVSM_syslog(LEVEL, FORMAT) \ - syslog(LEVEL, \ + DBGLOG(LEVEL) syslog(LEVEL, \ "IO[%ld]CC[%d]S[%ld][%ld]" FORMAT, \ IO->ID, CCID, QID, N) #define EVNCS_syslog(LEVEL, FORMAT, ...) \ - syslog(LEVEL, "IO[%ld]S[%ld][%ld]" FORMAT, \ + DBGLOG(LEVEL) syslog(LEVEL, "IO[%ld]S[%ld][%ld]" FORMAT, \ IO->ID, QID, N, __VA_ARGS__) #define EVNCSM_syslog(LEVEL, FORMAT) \ - syslog(LEVEL, "IO[%ld]S[%ld][%ld]" FORMAT, \ + DBGLOG(LEVEL) syslog(LEVEL, "IO[%ld]S[%ld][%ld]" FORMAT, \ IO->ID, QID, N) diff --git a/citadel/serv_extensions.c b/citadel/serv_extensions.c index 40ab17c77..45221c514 100644 --- a/citadel/serv_extensions.c +++ b/citadel/serv_extensions.c @@ -46,19 +46,154 @@ #include "snprintf.h" #endif -struct CleanupFunctionHook *CleanupHookTable = NULL; -struct CleanupFunctionHook *EVCleanupHookTable = NULL; -struct SessionFunctionHook *SessionHookTable = NULL; -struct UserFunctionHook *UserHookTable = NULL; -struct XmsgFunctionHook *XmsgHookTable = NULL; -struct MessageFunctionHook *MessageHookTable = NULL; -struct NetprocFunctionHook *NetprocHookTable = NULL; -struct DeleteFunctionHook *DeleteHookTable = NULL; -struct ServiceFunctionHook *ServiceHookTable = NULL; -struct FixedOutputHook *FixedOutputTable = NULL; -struct RoomFunctionHook *RoomHookTable = NULL; -struct SearchFunctionHook *SearchFunctionHookTable = NULL; + +/* + * Structure defentitions for hook tables + */ + +typedef struct __LogDebugEntry { + CtdlDbgFunction F; + const char *Name; + long Len; +} LogDebugEntry; +HashList *LogDebugEntryTable = NULL; + +typedef struct LogFunctionHook LogFunctionHook; +struct LogFunctionHook { + LogFunctionHook *next; + int loglevel; + void (*h_function_pointer) (char *); +}; +extern LogFunctionHook *LogHookTable; + +typedef struct FixedOutputHook FixedOutputHook; +struct FixedOutputHook { + FixedOutputHook *next; + char content_type[64]; + void (*h_function_pointer) (char *, int); +}; +extern FixedOutputHook *FixedOutputTable; + + + +/* + * SessionFunctionHook extensions are used for any type of hook for which + * the context in which it's being called (which is determined by the event + * type) will make it obvious for the hook function to know where to look for + * pertinent data. + */ +typedef struct SessionFunctionHook SessionFunctionHook; +struct SessionFunctionHook { + SessionFunctionHook *next; + void (*h_function_pointer) (void); + int eventtype; +}; +extern SessionFunctionHook *SessionHookTable; + + +/* + * UserFunctionHook extensions are used for any type of hook which implements + * an operation on a user or username (potentially) other than the one + * operating the current session. + */ +typedef struct UserFunctionHook UserFunctionHook; +struct UserFunctionHook { + UserFunctionHook *next; + void (*h_function_pointer) (struct ctdluser *usbuf); + int eventtype; +}; +extern UserFunctionHook *UserHookTable; + +/* + * MessageFunctionHook extensions are used for hooks which implement handlers + * for various types of message operations (save, read, etc.) + */ +typedef struct MessageFunctionHook MessageFunctionHook; +struct MessageFunctionHook { + MessageFunctionHook *next; + int (*h_function_pointer) (struct CtdlMessage *msg); + int eventtype; +}; +extern MessageFunctionHook *MessageHookTable; + + +/* + * NetprocFunctionHook extensions are used for hooks which implement handlers + * for incoming network messages. + */ +typedef struct NetprocFunctionHook NetprocFunctionHook; +struct NetprocFunctionHook { + NetprocFunctionHook *next; + int (*h_function_pointer) (struct CtdlMessage *msg, char *target_room); +}; +extern NetprocFunctionHook *NetprocHookTable; + + +/* + * DeleteFunctionHook extensions are used for hooks which get called when a + * message is about to be deleted. + */ +typedef struct DeleteFunctionHook DeleteFunctionHook; +struct DeleteFunctionHook { + DeleteFunctionHook *next; + void (*h_function_pointer) (char *target_room, long msgnum); +}; +extern DeleteFunctionHook *DeleteHookTable; + +/* + * ExpressMessageFunctionHook extensions are used for hooks which implement + * the sending of an instant message through various channels. Any function + * registered should return the number of recipients to whom the message was + * successfully transmitted. + */ +typedef struct XmsgFunctionHook XmsgFunctionHook; +struct XmsgFunctionHook { + XmsgFunctionHook *next; + int (*h_function_pointer) (char *, char *, char *, char *); + int order; +}; +extern XmsgFunctionHook *XmsgHookTable; + + + + +/* + * RoomFunctionHook extensions are used for hooks which impliment room + * processing functions when new messages are added EG. SIEVE. + */ +typedef struct RoomFunctionHook RoomFunctionHook; +struct RoomFunctionHook { + RoomFunctionHook *next; + int (*fcn_ptr) (struct ctdlroom *); +}; +extern RoomFunctionHook *RoomHookTable; + + + +typedef struct SearchFunctionHook SearchFunctionHook; +struct SearchFunctionHook { + SearchFunctionHook *next; + void (*fcn_ptr) (int *, long **, const char *); + char *name; +}; +extern SearchFunctionHook *SearchFunctionHookTable; + + +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 { void (*handler) (char *cmdbuf); const char *cmd; @@ -172,10 +307,10 @@ void AddPortError(char *Port, char *ErrorMessage) int DLoader_Exec_Cmd(char *cmdbuf) { void *vP; - struct ProtoFunctionHook *p; + ProtoFunctionHook *p; if (GetHash(ProtoHookList, cmdbuf, 4, &vP) && (vP != NULL)) { - p = (struct ProtoFunctionHook*) vP; + p = (ProtoFunctionHook*) vP; p->handler(&cmdbuf[5]); return 1; } @@ -197,17 +332,88 @@ long FourHash(const char *key, long length) return ret; } +/* +typedef struct __LogDebugEntry { + CtdlDbgFunction F; + const char *Name; + long Len; +} LogDebugEntry; +HashList *LogDebugEntryTable = NULL; +*/ +void CtdlRegisterDebugFlagHook(const char *Name, long Len, CtdlDbgFunction F) +{ + LogDebugEntry *E; + if (LogDebugEntryTable == NULL) + LogDebugEntryTable = NewHash(1, NULL); + E = (LogDebugEntry*) malloc(sizeof(LogDebugEntry)); + E->F = F; + E->Name = Name; + E->Len = Len; + Put(LogDebugEntryTable, Name, Len, E, NULL); + +} +void CtdlSetDebugLogFacilities(const char **Str, long n) +{ + StrBuf *Token = NULL; + StrBuf *Buf = NULL; + const char *ch; + int i; + int DoAll = 0; + void *vptr; + + for (i=0; i < n; i++){ + if ((Str[i] != NULL) && !IsEmptyStr(Str[i])) { + if (strcmp(Str[i], "all") == 0) { + DoAll = 1; + continue; + } + Buf = NewStrBufPlain(Str[i], -1); + ch = NULL; + if (Token == NULL) + Token = NewStrBufPlain(NULL, StrLength(Buf)); + while ((ch != StrBufNOTNULL) && + StrBufExtract_NextToken(Token, Buf, &ch, ',')) { + if (GetHash(LogDebugEntryTable, SKEY(Token), &vptr) && + (vptr != NULL)) + { + LogDebugEntry *E = (LogDebugEntry*)vptr; + E->F(); + } + } + } + FreeStrBuf(&Buf); + } + FreeStrBuf(&Token); + if (DoAll) { + long HKLen; + const char *ch; + HashPos *Pos; + + Pos = GetNewHashPos(LogDebugEntryTable, 0); + while (GetNextHashPos(LogDebugEntryTable, Pos, &HKLen, &ch, &vptr)) { + LogDebugEntry *E = (LogDebugEntry*)vptr; + E->F(); + } + + DeleteHashPos(&Pos); + } +} +void CtdlDestroyDebugTable(void) +{ + + DeleteHash(&LogDebugEntryTable); +} void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc) { - struct ProtoFunctionHook *p; + ProtoFunctionHook *p; if (ProtoHookList == NULL) ProtoHookList = NewHash (1, FourHash); - p = (struct ProtoFunctionHook *) - malloc(sizeof(struct ProtoFunctionHook)); + p = (ProtoFunctionHook *) + malloc(sizeof(ProtoFunctionHook)); if (p == NULL) { fprintf(stderr, "can't malloc new ProtoFunctionHook\n"); @@ -231,10 +437,10 @@ void CtdlDestroyProtoHooks(void) void CtdlRegisterCleanupHook(void (*fcn_ptr) (void)) { - struct CleanupFunctionHook *newfcn; + CleanupFunctionHook *newfcn; - newfcn = (struct CleanupFunctionHook *) - malloc(sizeof(struct CleanupFunctionHook)); + newfcn = (CleanupFunctionHook *) + malloc(sizeof(CleanupFunctionHook)); newfcn->next = CleanupHookTable; newfcn->h_function_pointer = fcn_ptr; CleanupHookTable = newfcn; @@ -245,7 +451,7 @@ void CtdlRegisterCleanupHook(void (*fcn_ptr) (void)) void CtdlUnregisterCleanupHook(void (*fcn_ptr) (void)) { - struct CleanupFunctionHook *cur, *p; + CleanupFunctionHook *cur, *p; for (cur = CleanupHookTable; cur != NULL; cur = cur->next) { /* This will also remove duplicates if any */ @@ -265,7 +471,7 @@ void CtdlUnregisterCleanupHook(void (*fcn_ptr) (void)) void CtdlDestroyCleanupHooks(void) { - struct CleanupFunctionHook *cur, *p; + CleanupFunctionHook *cur, *p; cur = CleanupHookTable; while (cur != NULL) @@ -281,10 +487,10 @@ void CtdlDestroyCleanupHooks(void) void CtdlRegisterEVCleanupHook(void (*fcn_ptr) (void)) { - struct CleanupFunctionHook *newfcn; + CleanupFunctionHook *newfcn; - newfcn = (struct CleanupFunctionHook *) - malloc(sizeof(struct CleanupFunctionHook)); + newfcn = (CleanupFunctionHook *) + malloc(sizeof(CleanupFunctionHook)); newfcn->next = EVCleanupHookTable; newfcn->h_function_pointer = fcn_ptr; EVCleanupHookTable = newfcn; @@ -295,7 +501,7 @@ void CtdlRegisterEVCleanupHook(void (*fcn_ptr) (void)) void CtdlUnregisterEVCleanupHook(void (*fcn_ptr) (void)) { - struct CleanupFunctionHook *cur, *p; + CleanupFunctionHook *cur, *p; for (cur = EVCleanupHookTable; cur != NULL; cur = cur->next) { /* This will also remove duplicates if any */ @@ -315,7 +521,7 @@ void CtdlUnregisterEVCleanupHook(void (*fcn_ptr) (void)) void CtdlDestroyEVCleanupHooks(void) { - struct CleanupFunctionHook *cur, *p; + CleanupFunctionHook *cur, *p; cur = EVCleanupHookTable; while (cur != NULL) @@ -332,10 +538,10 @@ void CtdlDestroyEVCleanupHooks(void) void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType) { - struct SessionFunctionHook *newfcn; + SessionFunctionHook *newfcn; - newfcn = (struct SessionFunctionHook *) - malloc(sizeof(struct SessionFunctionHook)); + newfcn = (SessionFunctionHook *) + malloc(sizeof(SessionFunctionHook)); newfcn->next = SessionHookTable; newfcn->h_function_pointer = fcn_ptr; newfcn->eventtype = EventType; @@ -348,7 +554,7 @@ void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType) void CtdlUnregisterSessionHook(void (*fcn_ptr) (void), int EventType) { - struct SessionFunctionHook *cur, *p; + SessionFunctionHook *cur, *p; for (cur = SessionHookTable; cur != NULL; cur = cur->next) { /* This will also remove duplicates if any */ @@ -369,7 +575,7 @@ void CtdlUnregisterSessionHook(void (*fcn_ptr) (void), int EventType) void CtdlDestroySessionHooks(void) { - struct SessionFunctionHook *cur, *p; + SessionFunctionHook *cur, *p; cur = SessionHookTable; while (cur != NULL) @@ -383,13 +589,13 @@ void CtdlDestroySessionHooks(void) } -void CtdlRegisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType) +void CtdlRegisterUserHook(void (*fcn_ptr) (ctdluser *), int EventType) { - struct UserFunctionHook *newfcn; + UserFunctionHook *newfcn; - newfcn = (struct UserFunctionHook *) - malloc(sizeof(struct UserFunctionHook)); + newfcn = (UserFunctionHook *) + malloc(sizeof(UserFunctionHook)); newfcn->next = UserHookTable; newfcn->h_function_pointer = fcn_ptr; newfcn->eventtype = EventType; @@ -402,7 +608,7 @@ void CtdlRegisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType) void CtdlUnregisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType) { - struct UserFunctionHook *cur, *p; + UserFunctionHook *cur, *p; for (cur = UserHookTable; cur != NULL; cur = cur->next) { /* This will also remove duplicates if any */ @@ -423,7 +629,7 @@ void CtdlUnregisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType) void CtdlDestroyUserHooks(void) { - struct UserFunctionHook *cur, *p; + UserFunctionHook *cur, *p; cur = UserHookTable; while (cur != NULL) @@ -441,10 +647,10 @@ void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *), int EventType) { - struct MessageFunctionHook *newfcn; + MessageFunctionHook *newfcn; - newfcn = (struct MessageFunctionHook *) - malloc(sizeof(struct MessageFunctionHook)); + newfcn = (MessageFunctionHook *) + malloc(sizeof(MessageFunctionHook)); newfcn->next = MessageHookTable; newfcn->h_function_pointer = handler; newfcn->eventtype = EventType; @@ -458,7 +664,7 @@ void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *), void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *), int EventType) { - struct MessageFunctionHook *cur, *p; + MessageFunctionHook *cur, *p; for (cur = MessageHookTable; cur != NULL; cur = cur->next) { /* This will also remove duplicates if any */ @@ -479,7 +685,7 @@ void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *), void CtdlDestroyMessageHook(void) { - struct MessageFunctionHook *cur, *p; + MessageFunctionHook *cur, *p; cur = MessageHookTable; while (cur != NULL) @@ -495,10 +701,10 @@ void CtdlDestroyMessageHook(void) void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *)) { - struct RoomFunctionHook *newfcn; + RoomFunctionHook *newfcn; - newfcn = (struct RoomFunctionHook *) - malloc(sizeof(struct RoomFunctionHook)); + newfcn = (RoomFunctionHook *) + malloc(sizeof(RoomFunctionHook)); newfcn->next = RoomHookTable; newfcn->fcn_ptr = fcn_ptr; RoomHookTable = newfcn; @@ -509,7 +715,7 @@ void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *)) void CtdlUnregisterRoomHook(int (*fcn_ptr)(struct ctdlroom *)) { - struct RoomFunctionHook *cur, *p; + RoomFunctionHook *cur, *p; for (cur = RoomHookTable; cur != NULL; cur = cur->next) { while (cur != NULL && fcn_ptr == cur->fcn_ptr) { @@ -527,7 +733,7 @@ void CtdlUnregisterRoomHook(int (*fcn_ptr)(struct ctdlroom *)) void CtdlDestroyRoomHooks(void) { - struct RoomFunctionHook *cur, *p; + RoomFunctionHook *cur, *p; cur = RoomHookTable; while (cur != NULL) @@ -542,10 +748,10 @@ void CtdlDestroyRoomHooks(void) void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) ) { - struct NetprocFunctionHook *newfcn; + NetprocFunctionHook *newfcn; - newfcn = (struct NetprocFunctionHook *) - malloc(sizeof(struct NetprocFunctionHook)); + newfcn = (NetprocFunctionHook *) + malloc(sizeof(NetprocFunctionHook)); newfcn->next = NetprocHookTable; newfcn->h_function_pointer = handler; NetprocHookTable = newfcn; @@ -556,7 +762,7 @@ void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) ) void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) ) { - struct NetprocFunctionHook *cur, *p; + NetprocFunctionHook *cur, *p; for (cur = NetprocHookTable; cur != NULL; cur = cur->next) { /* This will also remove duplicates if any */ @@ -575,7 +781,7 @@ void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) ) void CtdlDestroyNetprocHooks(void) { - struct NetprocFunctionHook *cur, *p; + NetprocFunctionHook *cur, *p; cur = NetprocHookTable; while (cur != NULL) @@ -591,10 +797,10 @@ void CtdlDestroyNetprocHooks(void) void CtdlRegisterDeleteHook(void (*handler)(char *, long) ) { - struct DeleteFunctionHook *newfcn; + DeleteFunctionHook *newfcn; - newfcn = (struct DeleteFunctionHook *) - malloc(sizeof(struct DeleteFunctionHook)); + newfcn = (DeleteFunctionHook *) + malloc(sizeof(DeleteFunctionHook)); newfcn->next = DeleteHookTable; newfcn->h_function_pointer = handler; DeleteHookTable = newfcn; @@ -605,7 +811,7 @@ void CtdlRegisterDeleteHook(void (*handler)(char *, long) ) void CtdlUnregisterDeleteHook(void (*handler)(char *, long) ) { - struct DeleteFunctionHook *cur, *p; + DeleteFunctionHook *cur, *p; for (cur = DeleteHookTable; cur != NULL; cur = cur->next) { /* This will also remove duplicates if any */ @@ -623,7 +829,7 @@ void CtdlUnregisterDeleteHook(void (*handler)(char *, long) ) } void CtdlDestroyDeleteHooks(void) { - struct DeleteFunctionHook *cur, *p; + DeleteFunctionHook *cur, *p; cur = DeleteHookTable; while (cur != NULL) @@ -641,10 +847,10 @@ void CtdlDestroyDeleteHooks(void) void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int) ) { - struct FixedOutputHook *newfcn; + FixedOutputHook *newfcn; - newfcn = (struct FixedOutputHook *) - malloc(sizeof(struct FixedOutputHook)); + newfcn = (FixedOutputHook *) + malloc(sizeof(FixedOutputHook)); newfcn->next = FixedOutputTable; newfcn->h_function_pointer = handler; safestrncpy(newfcn->content_type, content_type, sizeof newfcn->content_type); @@ -656,7 +862,7 @@ void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int void CtdlUnregisterFixedOutputHook(char *content_type) { - struct FixedOutputHook *cur, *p; + FixedOutputHook *cur, *p; for (cur = FixedOutputTable; cur != NULL; cur = cur->next) { /* This will also remove duplicates if any */ @@ -674,7 +880,7 @@ void CtdlUnregisterFixedOutputHook(char *content_type) void CtdlDestroyFixedOutputHooks(void) { - struct FixedOutputHook *cur, *p; + FixedOutputHook *cur, *p; cur = FixedOutputTable; while (cur != NULL) @@ -691,7 +897,7 @@ void CtdlDestroyFixedOutputHooks(void) /* returns nonzero if we found a hook and used it */ int PerformFixedOutputHooks(char *content_type, char *content, int content_length) { - struct FixedOutputHook *fcn; + FixedOutputHook *fcn; for (fcn = FixedOutputTable; fcn != NULL; fcn = fcn->next) { if (!strcasecmp(content_type, fcn->content_type)) { @@ -709,9 +915,9 @@ int PerformFixedOutputHooks(char *content_type, char *content, int content_lengt void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order) { - struct XmsgFunctionHook *newfcn; + XmsgFunctionHook *newfcn; - newfcn = (struct XmsgFunctionHook *) malloc(sizeof(struct XmsgFunctionHook)); + newfcn = (XmsgFunctionHook *) malloc(sizeof(XmsgFunctionHook)); newfcn->next = XmsgHookTable; newfcn->order = order; newfcn->h_function_pointer = fcn_ptr; @@ -722,7 +928,7 @@ void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int o void CtdlUnregisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order) { - struct XmsgFunctionHook *cur, *p; + XmsgFunctionHook *cur, *p; for (cur = XmsgHookTable; cur != NULL; cur = cur->next) { /* This will also remove duplicates if any */ @@ -743,7 +949,7 @@ void CtdlUnregisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int void CtdlDestroyXmsgHooks(void) { - struct XmsgFunctionHook *cur, *p; + XmsgFunctionHook *cur, *p; cur = XmsgHookTable; while (cur != NULL) @@ -766,12 +972,12 @@ void CtdlRegisterServiceHook(int tcp_port, void (*h_async_function) (void), const char *ServiceName) { - struct ServiceFunctionHook *newfcn; + ServiceFunctionHook *newfcn; char *message; char error[SIZ]; strcpy(error, ""); - newfcn = (struct ServiceFunctionHook *) malloc(sizeof(struct ServiceFunctionHook)); + newfcn = (ServiceFunctionHook *) malloc(sizeof(ServiceFunctionHook)); message = (char*) malloc (SIZ + SIZ); newfcn->next = ServiceHookTable; @@ -822,7 +1028,7 @@ void CtdlUnregisterServiceHook(int tcp_port, char *sockpath, void (*h_async_function) (void) ) { - struct ServiceFunctionHook *cur, *p; + ServiceFunctionHook *cur, *p; cur = ServiceHookTable; while (cur != NULL) { @@ -858,7 +1064,7 @@ void CtdlUnregisterServiceHook(int tcp_port, char *sockpath, void CtdlShutdownServiceHooks(void) { /* sort of a duplicate of close_masters() but called earlier */ - struct ServiceFunctionHook *cur; + ServiceFunctionHook *cur; cur = ServiceHookTable; while (cur != NULL) @@ -883,7 +1089,7 @@ void CtdlShutdownServiceHooks(void) void CtdlDestroyServiceHook(void) { - struct ServiceFunctionHook *cur, *p; + ServiceFunctionHook *cur, *p; cur = ServiceHookTable; while (cur != NULL) @@ -907,14 +1113,14 @@ void CtdlDestroyServiceHook(void) void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name) { - struct SearchFunctionHook *newfcn; + SearchFunctionHook *newfcn; if (!name || !fcn_ptr) { return; } - newfcn = (struct SearchFunctionHook *) - malloc(sizeof(struct SearchFunctionHook)); + newfcn = (SearchFunctionHook *) + malloc(sizeof(SearchFunctionHook)); newfcn->next = SearchFunctionHookTable; newfcn->name = name; newfcn->fcn_ptr = fcn_ptr; @@ -925,7 +1131,7 @@ void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), c void CtdlUnregisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name) { - struct SearchFunctionHook *cur, *p; + SearchFunctionHook *cur, *p; for (cur = SearchFunctionHookTable; cur != NULL; cur = cur->next) { while (fcn_ptr && (cur->fcn_ptr == fcn_ptr) && name && !strcmp(name, cur->name)) { @@ -942,7 +1148,7 @@ void CtdlUnregisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), void CtdlDestroySearchHooks(void) { - struct SearchFunctionHook *cur, *p; + SearchFunctionHook *cur, *p; cur = SearchFunctionHookTable; SearchFunctionHookTable = NULL; @@ -955,7 +1161,7 @@ void CtdlDestroySearchHooks(void) void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, const char *search_string, const char *func_name) { - struct SearchFunctionHook *fcn = NULL; + SearchFunctionHook *fcn = NULL; for (fcn = SearchFunctionHookTable; fcn != NULL; fcn = fcn->next) { if (!func_name || !strcmp(func_name, fcn->name)) { @@ -969,7 +1175,7 @@ void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, const char *search_st void PerformSessionHooks(int EventType) { - struct SessionFunctionHook *fcn = NULL; + SessionFunctionHook *fcn = NULL; for (fcn = SessionHookTable; fcn != NULL; fcn = fcn->next) { if (fcn->eventtype == EventType) { @@ -981,9 +1187,9 @@ void PerformSessionHooks(int EventType) } } -void PerformUserHooks(struct ctdluser *usbuf, int EventType) +void PerformUserHooks(ctdluser *usbuf, int EventType) { - struct UserFunctionHook *fcn = NULL; + UserFunctionHook *fcn = NULL; for (fcn = UserHookTable; fcn != NULL; fcn = fcn->next) { if (fcn->eventtype == EventType) { @@ -994,7 +1200,7 @@ void PerformUserHooks(struct ctdluser *usbuf, int EventType) int PerformMessageHooks(struct CtdlMessage *msg, int EventType) { - struct MessageFunctionHook *fcn = NULL; + MessageFunctionHook *fcn = NULL; int total_retval = 0; /* Other code may elect to protect this message from server-side @@ -1024,7 +1230,7 @@ int PerformMessageHooks(struct CtdlMessage *msg, int EventType) int PerformRoomHooks(struct ctdlroom *target_room) { - struct RoomFunctionHook *fcn; + RoomFunctionHook *fcn; int total_retval = 0; syslog(LOG_DEBUG, "Performing room hooks for <%s>\n", target_room->QRname); @@ -1041,7 +1247,7 @@ int PerformRoomHooks(struct ctdlroom *target_room) int PerformNetprocHooks(struct CtdlMessage *msg, char *target_room) { - struct NetprocFunctionHook *fcn; + NetprocFunctionHook *fcn; int total_retval = 0; for (fcn = NetprocHookTable; fcn != NULL; fcn = fcn->next) { @@ -1058,7 +1264,7 @@ int PerformNetprocHooks(struct CtdlMessage *msg, char *target_room) void PerformDeleteHooks(char *room, long msgnum) { - struct DeleteFunctionHook *fcn; + DeleteFunctionHook *fcn; for (fcn = DeleteHookTable; fcn != NULL; fcn = fcn->next) { (*fcn->h_function_pointer) (room, msgnum); @@ -1071,7 +1277,7 @@ void PerformDeleteHooks(char *room, long msgnum) int PerformXmsgHooks(char *sender, char *sender_email, char *recp, char *msg) { - struct XmsgFunctionHook *fcn; + XmsgFunctionHook *fcn; int total_sent = 0; int p; diff --git a/citadel/serv_extensions.h b/citadel/serv_extensions.h index b2d556377..0ef8e1408 100644 --- a/citadel/serv_extensions.h +++ b/citadel/serv_extensions.h @@ -15,117 +15,17 @@ /* */ +typedef void (*CtdlDbgFunction) (void); - -/* - * Structure defentitions for hook tables - */ - - -struct LogFunctionHook { - struct LogFunctionHook *next; - int loglevel; - void (*h_function_pointer) (char *); -}; -extern struct LogFunctionHook *LogHookTable; - -struct CleanupFunctionHook { - struct CleanupFunctionHook *next; - void (*h_function_pointer) (void); -}; -extern struct CleanupFunctionHook *CleanupHookTable; - -struct FixedOutputHook { - struct FixedOutputHook *next; - char content_type[64]; - void (*h_function_pointer) (char *, int); -}; -extern struct FixedOutputHook *FixedOutputTable; - - - -/* - * SessionFunctionHook extensions are used for any type of hook for which - * the context in which it's being called (which is determined by the event - * type) will make it obvious for the hook function to know where to look for - * pertinent data. - */ -struct SessionFunctionHook { - struct SessionFunctionHook *next; - void (*h_function_pointer) (void); - int eventtype; -}; -extern struct SessionFunctionHook *SessionHookTable; - - -/* - * UserFunctionHook extensions are used for any type of hook which implements - * an operation on a user or username (potentially) other than the one - * operating the current session. - */ -struct UserFunctionHook { - struct UserFunctionHook *next; - void (*h_function_pointer) (struct ctdluser *usbuf); - int eventtype; -}; -extern struct UserFunctionHook *UserHookTable; - -/* - * MessageFunctionHook extensions are used for hooks which implement handlers - * for various types of message operations (save, read, etc.) - */ -struct MessageFunctionHook { - struct MessageFunctionHook *next; - int (*h_function_pointer) (struct CtdlMessage *msg); - int eventtype; -}; -extern struct MessageFunctionHook *MessageHookTable; - - -/* - * NetprocFunctionHook extensions are used for hooks which implement handlers - * for incoming network messages. - */ -struct NetprocFunctionHook { - struct NetprocFunctionHook *next; - int (*h_function_pointer) (struct CtdlMessage *msg, char *target_room); -}; -extern struct NetprocFunctionHook *NetprocHookTable; - - -/* - * DeleteFunctionHook extensions are used for hooks which get called when a - * message is about to be deleted. - */ -struct DeleteFunctionHook { - struct DeleteFunctionHook *next; - void (*h_function_pointer) (char *target_room, long msgnum); -}; -extern struct DeleteFunctionHook *DeleteHookTable; - - -/* - * ExpressMessageFunctionHook extensions are used for hooks which implement - * the sending of an instant message through various channels. Any function - * registered should return the number of recipients to whom the message was - * successfully transmitted. - */ -struct XmsgFunctionHook { - struct XmsgFunctionHook *next; - int (*h_function_pointer) (char *, char *, char *, char *); - int order; -}; -extern struct XmsgFunctionHook *XmsgHookTable; - - /* * ServiceFunctionHook extensions are used for hooks which implement various * protocols (either on TCP or on unix domain sockets) directly in the Citadel server. */ +typedef struct ServiceFunctionHook ServiceFunctionHook; struct ServiceFunctionHook { - struct ServiceFunctionHook *next; + ServiceFunctionHook *next; int tcp_port; char *sockpath; void (*h_greeting_function) (void) ; @@ -134,30 +34,16 @@ struct ServiceFunctionHook { int msock; const char* ServiceName; /* this is just for debugging and logging purposes. */ }; -extern struct ServiceFunctionHook *ServiceHookTable; - +extern ServiceFunctionHook *ServiceHookTable; -/* - * RoomFunctionHook extensions are used for hooks which impliment room - * processing functions when new messages are added EG. SIEVE. - */ -struct RoomFunctionHook { - struct RoomFunctionHook *next; - int (*fcn_ptr) (struct ctdlroom *); +typedef struct CleanupFunctionHook CleanupFunctionHook; +struct CleanupFunctionHook { + CleanupFunctionHook *next; + void (*h_function_pointer) (void); }; -extern struct RoomFunctionHook *RoomHookTable; - - +extern CleanupFunctionHook *CleanupHookTable; -struct SearchFunctionHook { - struct SearchFunctionHook *next; - void (*fcn_ptr) (int *, long **, const char *); - char *name; -}; -extern struct SearchFunctionHook *SearchFunctionHookTable; - - void initialize_server_extensions(void); int DLoader_Exec_Cmd(char *cmdbuf); char *Dynamic_Module_Init(void); @@ -199,5 +85,8 @@ void CtdlDestroySearchHooks(void); void CtdlDestroyFixedOutputHooks(void); int PerformFixedOutputHooks(char *, char *, int); +void CtdlRegisterDebugFlagHook(const char *Name, long len, CtdlDbgFunction F); +void CtdlSetDebugLogFacilities(const char **Str, long n); +void CtdlDestroyDebugTable(void); #endif /* SERV_EXTENSIONS_H */ diff --git a/citadel/server_main.c b/citadel/server_main.c index bab3ab69f..0dc52a0e4 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -100,6 +100,7 @@ int main(int argc, char **argv) char relhome[PATH_MAX]=""; char ctdldir[PATH_MAX]=CTDLDIR; int syslog_facility = LOG_DAEMON; + const char *eDebuglist[] = {NULL, NULL}; #ifdef HAVE_RUN_DIR struct stat filestats; #endif @@ -136,7 +137,8 @@ int main(int argc, char **argv) home=1; break; - case 'x': /* deprecated */ + case 'x': + eDebuglist [0] = optarg; break; case 't': /* deprecated */ @@ -314,6 +316,9 @@ int main(int argc, char **argv) initialise_modules(0); + eDebuglist[1] = getenv("CITADEL_LOGDEBUG"); + CtdlSetDebugLogFacilities(eDebuglist, 2); + /* * If we need host auth, start our chkpwd daemon. */ diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 422370772..b8d190a8b 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -972,6 +972,7 @@ void sysdep_master_cleanup(void) { CtdlDestroyServiceHook(); CtdlDestroyRoomHooks(); CtdlDestroySearchHooks(); + CtdlDestroyDebugTable(); #ifdef HAVE_BACKTRACE /// eCrash_Uninit(); #endif