Moved to new module init structure.
[citadel.git] / citadel / serv_extensions.c
index 44a1dcceafa01c8c1b0acaca3c889a7d68b11deb..1acd40e099cbce6bc63c9785c5bebd6243858f40 100644 (file)
@@ -37,6 +37,8 @@ struct NetprocFunctionHook *NetprocHookTable = NULL;
 struct DeleteFunctionHook *DeleteHookTable = NULL;
 struct ServiceFunctionHook *ServiceHookTable = NULL;
 struct FixedOutputHook *FixedOutputTable = NULL;
+struct RoomFunctionHook *RoomHookTable = NULL;
+
 
 struct ProtoFunctionHook {
        void (*handler) (char *cmdbuf);
@@ -58,12 +60,13 @@ static size_t nSizErrmsg = 0;
 
 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.";
@@ -102,6 +105,10 @@ void LogPrintMessages(long err)
        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);
 }
 
@@ -135,16 +142,30 @@ void AppendString(char **target, char *append, size_t *len, size_t rate)
                }
        }
        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';
+       }       
 }
 
 
@@ -228,11 +249,14 @@ int DLoader_Exec_Cmd(char *cmdbuf)
        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());
@@ -250,22 +274,22 @@ void initialize_server_extensions(void)
        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))
 {
@@ -481,6 +505,53 @@ void CtdlDestroyMessageHook(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;
@@ -739,7 +810,8 @@ void CtdlRegisterServiceHook(int tcp_port,
                                              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) {
@@ -751,7 +823,6 @@ void CtdlRegisterServiceHook(int tcp_port,
                AddPortError(message, error);
                strcat(message, "FAILED.");
                lprintf(CTDL_CRIT, "%s\n", message);
-               free (message);
                free(error);
                free(newfcn);
        }
@@ -873,6 +944,22 @@ int PerformMessageHooks(struct CtdlMessage *msg, 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)
 {