#include "tools.h"
#include "config.h"
+#include "modules/crypto/serv_crypto.h" /* Needed until a universal crypto startup hook is implimented for CtdlStartTLS */
+
#ifndef HAVE_SNPRINTF
#include <stdarg.h>
#include "snprintf.h"
struct DeleteFunctionHook *DeleteHookTable = NULL;
struct ServiceFunctionHook *ServiceHookTable = NULL;
struct FixedOutputHook *FixedOutputTable = NULL;
+struct RoomFunctionHook *RoomHookTable = NULL;
+struct MaintenanceThreadHook *MaintenanceThreadHookTable = NULL;
+struct SearchFunctionHook *SearchFunctionHookTable = NULL;
struct ProtoFunctionHook {
void (*handler) (char *cmdbuf);
static long DetailErrorFlags;
-
char *ErrSubject = "Startup Problems";
char *ErrGeneral = "Citadel had trouble on starting up. %s This means, citadel won't be the service provider for a specific service you configured it to.\n\n"
"If you don't want citadel to provide these services, turn them off in WebCit via %s%s\n\n%s\n\n"
"To make both ways actualy take place restart the citserver with \"sendcommand down\"\n\n"
-"The errors returned by the system were:\n%s\n";
+"The errors returned by the system were:\n%s\n"
+"You can recheck the above if you follow this faq item:\n"
+"http://www.citadel.org/doku.php/faq:mastering_your_os:net#netstat";
char *ErrPortShort = "We couldn't bind all ports you configured to be provided by citadel server.";
snprintf(Message, n * SIZ, ErrGeneral, Short, Where, List, Hint, DetailList);
quickie_message("Citadel", NULL, NULL, AIDEROOM, Message, FMT_FIXED, ErrSubject);
+ if (errormessages!=NULL) free (errormessages);
+ errormessages = NULL;
+ if (portlist!=NULL) free (portlist);
+ portlist = NULL;
free(Message);
}
}
}
memcpy (*target + oLen, append, AddLen);
- (*target)[AddLen + 1] = '\n';
- (*target)[AddLen + 2] = '\0';
+ (*target)[oLen + AddLen + 1] = '\n';
+ (*target)[oLen + AddLen + 2] = '\0';
}
void AddPortError(char *Port, char *ErrorMessage)
{
+ char *pos;
+ long len;
+
DetailErrorFlags |= ERR_PORT;
AppendString(&errormessages, ErrorMessage, &nSizErrmsg, 10);
AppendString(&portlist, Port, &nSizPort, 2);
+
+ pos = strchr (portlist, ':');
+ if (pos != NULL) *pos = ';';
+
+ len = strlen (errormessages);
+ if (nSizErrmsg * SIZ > len + 3)
+ {
+ errormessages[len] = ';';
+ errormessages[len+1] = ' ';
+ errormessages[len+2] = '\0';
+ }
}
return 0;
}
+#if 0
void initialize_server_extensions(void)
{
long filter;
- lprintf(CTDL_INFO, "%s\n", serv_bio_init());
+ nSizErrmsg = 0;
+
+ /*lprintf(CTDL_INFO, "%s\n", serv_bio_init());
lprintf(CTDL_INFO, "%s\n", serv_calendar_init());
lprintf(CTDL_INFO, "%s\n", serv_notes_init());
lprintf(CTDL_INFO, "%s\n", serv_ldap_init());
lprintf(CTDL_INFO, "%s\n", serv_smtp_init());
lprintf(CTDL_INFO, "%s\n", serv_pop3_init());
lprintf(CTDL_INFO, "%s\n", serv_rwho_init());
- lprintf(CTDL_INFO, "%s\n", serv_spam_init());
+ lprintf(CTDL_INFO, "%s\n", serv_spam_init());*/
/* lprintf(CTDL_INFO, "%s\n", serv_test_init()); */
- lprintf(CTDL_INFO, "%s\n", serv_vandelay_init());
+ /*lprintf(CTDL_INFO, "%s\n", serv_vandelay_init());
lprintf(CTDL_INFO, "%s\n", serv_vcard_init());
lprintf(CTDL_INFO, "%s\n", serv_fulltext_init());
lprintf(CTDL_INFO, "%s\n", serv_autocompletion_init());
lprintf(CTDL_INFO, "%s\n", serv_postfix_tcpdict());
lprintf(CTDL_INFO, "%s\n", serv_sieve_init());
lprintf(CTDL_INFO, "%s\n", serv_managesieve_init());
- lprintf(CTDL_INFO, "%s\n", serv_funambol_init());
+ lprintf(CTDL_INFO, "%s\n", serv_funambol_init());*/
for (filter = 1; filter != 0; filter = filter << 1)
if ((filter & DetailErrorFlags) != 0)
LogPrintMessages(filter);
}
-
+#endif
void CtdlRegisterCleanupHook(void (*fcn_ptr) (void))
{
}
+void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
+{
+ struct RoomFunctionHook *newfcn;
+
+ newfcn = (struct RoomFunctionHook *)
+ malloc(sizeof(struct RoomFunctionHook));
+ newfcn->next = RoomHookTable;
+ newfcn->fcn_ptr = fcn_ptr;
+ RoomHookTable = newfcn;
+
+ lprintf(CTDL_INFO, "Registered a new room function\n");
+}
+
+
+void CtdlUnregisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
+{
+ struct RoomFunctionHook *cur, *p;
+
+ for (cur = RoomHookTable; cur != NULL; cur = cur->next) {
+ while (cur != NULL && fcn_ptr == cur->fcn_ptr) {
+ lprintf(CTDL_INFO, "Unregistered room function\n");
+ p = cur->next;
+ if (cur == RoomHookTable) {
+ RoomHookTable = p;
+ }
+ free(cur);
+ cur = p;
+ }
+ }
+}
+
+
+void CtdlDestroyRoomHooks(void)
+{
+ struct RoomFunctionHook *cur, *p;
+
+ cur = RoomHookTable;
+ while (cur != NULL)
+ {
+ lprintf(CTDL_INFO, "Unregistered room function\n");
+ p = cur->next;
+ free(cur);
+ cur = p;
+ }
+ RoomHookTable = NULL;
+}
+
void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
{
struct NetprocFunctionHook *newfcn;
tcp_port,
config.c_maxsessions,
&error);
- snprintf(message, SIZ, "TCP port %d: ", tcp_port);
+ snprintf(message, SIZ, "TCP port %s:%d: ",
+ config.c_ip_addr, tcp_port);
}
if (newfcn->msock > 0) {
AddPortError(message, error);
strcat(message, "FAILED.");
lprintf(CTDL_CRIT, "%s\n", message);
- free (message);
free(error);
free(newfcn);
}
ServiceHookTable = NULL;
}
+void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, char *), char *name)
+{
+ struct SearchFunctionHook *newfcn;
+
+ if (!name || !fcn_ptr) {
+ return;
+ }
+
+ newfcn = (struct SearchFunctionHook *)
+ malloc(sizeof(struct SearchFunctionHook));
+ newfcn->next = SearchFunctionHookTable;
+ newfcn->name = name;
+ newfcn->fcn_ptr = fcn_ptr;
+ SearchFunctionHookTable = newfcn;
+
+ lprintf(CTDL_INFO, "Registered a new search function (%s)\n", name);
+}
+
+void CtdlUnregisterSearchFuncHook(void (*fcn_ptr)(int *, long **, char *), char *name)
+{
+ struct SearchFunctionHook *cur, *p;
+
+ for (cur = SearchFunctionHookTable; cur != NULL; cur = cur->next) {
+ while (fcn_ptr && (cur->fcn_ptr == fcn_ptr) && name && !strcmp(name, cur->name)) {
+ lprintf(CTDL_INFO, "Unregistered search function(%s)\n", name);
+ p = cur->next;
+ if (cur == SearchFunctionHookTable) {
+ SearchFunctionHookTable = p;
+ }
+ free (cur);
+ cur = p;
+ }
+ }
+}
+
+void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, char *search_string, char *func_name)
+{
+ struct SearchFunctionHook *fcn = NULL;
+
+ for (fcn = SearchFunctionHookTable; fcn != NULL; fcn = fcn->next) {
+ if (!func_name || !strcmp(func_name, fcn->name)) {
+ (*fcn->fcn_ptr) (num_msgs, search_msgs, search_string);
+ return;
+ }
+ }
+ *num_msgs = 0;
+}
+
void PerformSessionHooks(int EventType)
{
}
+int PerformRoomHooks(struct ctdlroom *target_room)
+{
+ struct RoomFunctionHook *fcn;
+ int total_retval = 0;
+
+ lprintf(CTDL_DEBUG, "Performing room hooks for <%s>\n", target_room->QRname);
+
+ for (fcn = RoomHookTable; fcn != NULL; fcn = fcn->next) {
+ total_retval = total_retval + (*fcn->fcn_ptr) (target_room);
+ }
+
+ /* Return the sum of the return codes from the hook functions.
+ */
+ return total_retval;
+}
+
int PerformNetprocHooks(struct CtdlMessage *msg, char *target_room)
{
}
return total_sent;
}
+
+void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc)(void *arg))
+{
+ struct MaintenanceThreadHook *newfcn;
+
+ newfcn = (struct MaintenanceThreadHook *)
+ malloc(sizeof(struct MaintenanceThreadHook));
+ newfcn->name = name;
+ newfcn->next = MaintenanceThreadHookTable;
+ newfcn->fcn_ptr = thread_proc;
+ MaintenanceThreadHookTable = newfcn;
+
+ lprintf(CTDL_INFO, "Registered a new maintenance thread function\n");
+}
+
+
+/*
+ * Dirty hack until we impliment a hook mechanism for this
+ */
+void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response)
+{
+#ifdef HAVE_OPENSSL
+ CtdlStartTLS (ok_response, nosup_response, error_response);
+#endif
+}