ctdl_tcp_server and ctdl_uds_server improved handling of error
[citadel.git] / citadel / serv_extensions.c
index 0624713e38a52244f1545fccd56deb21aa9e3212..73a1b7911094dc48858a5cf95b5d2c824c1fcee5 100644 (file)
@@ -2,7 +2,7 @@
  * Citadel Extension Loader
  * Originally written by Brian Costello <btx@calyx.net>
  *
- * Copyright (c) 1987-2017 by the citadel.org team
+ * Copyright (c) 1987-2019 by the citadel.org team
  *
  * This program is open source software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License, version 3.
@@ -81,18 +81,6 @@ struct MessageFunctionHook {
 MessageFunctionHook *MessageHookTable = NULL;
 
 
-/*
- * 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);
-};
-NetprocFunctionHook *NetprocHookTable = NULL;
-
-
 /*
  * DeleteFunctionHook extensions are used for hooks which get called when a
  * message is about to be deleted.
@@ -159,7 +147,6 @@ HashList *ProtoHookList = NULL;
 
 
 static StrBuf *portlist = NULL;
-
 static StrBuf *errormessages = NULL;
 
 
@@ -180,9 +167,7 @@ ConstStr ErrPortShort = { HKEY("We couldn't bind all ports you configured to be
 ConstStr ErrPortWhere = { HKEY("\"Admin->System Preferences->Network\".\n\nThe failed ports and sockets are: ")};
 ConstStr ErrPortHint  = { HKEY("If you want Citadel to provide you with that functionality, "
                               "check the output of \"netstat -lnp\" on Linux, or \"netstat -na\" on BSD"
-                              " and stop the program that binds these ports.\n You should eventually remove "
-                              " their initscripts in /etc/init.d so that you won't get this trouble once more.\n"
-                              " After that goto \"Administration -> Shutdown Citadel\" to make Citadel restart & retry to bind this port.\n")};
+                              " and disable the program that binds these ports.\n")};
 
 
 void LogPrintMessages(long err)
@@ -666,63 +651,6 @@ void CtdlDestroyRoomHooks(void)
        RoomHookTable = NULL;
 }
 
-void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
-{
-       NetprocFunctionHook *newfcn;
-
-       newfcn = (NetprocFunctionHook *)
-           malloc(sizeof(NetprocFunctionHook));
-       newfcn->next = NetprocHookTable;
-       newfcn->h_function_pointer = handler;
-       NetprocHookTable = newfcn;
-
-       syslog(LOG_DEBUG, "extensions: registered a new netproc function");
-}
-
-
-void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
-{
-       NetprocFunctionHook *cur, *p, *last;
-
-       cur = NetprocHookTable;
-       last = NULL;
-
-       while (cur != NULL) {
-               if (handler == cur->h_function_pointer)
-               {
-                       syslog(LOG_DEBUG, "extensions: unregistered netproc function");
-                       p = cur->next;
-                       free(cur);
-                       if (last != NULL) {
-                               last->next = p;
-                       }
-                       else {
-                               NetprocHookTable = p;
-                       }
-                       cur = p;
-               }
-               else {
-                       last = cur;
-                       cur = cur->next;
-               }
-       }
-}
-
-void CtdlDestroyNetprocHooks(void)
-{
-       NetprocFunctionHook *cur, *p;
-
-       cur = NetprocHookTable;
-       while (cur != NULL)
-       {
-               syslog(LOG_DEBUG, "extensions: destroyed netproc function");
-               p = cur->next;
-               free(cur);
-               cur = p;
-       }
-       NetprocHookTable = NULL;
-}
-
 
 void CtdlRegisterDeleteHook(void (*handler)(char *, long) )
 {
@@ -925,9 +853,7 @@ void CtdlRegisterServiceHook(int tcp_port,
 {
        ServiceFunctionHook *newfcn;
        char *message;
-       char error[SIZ];
 
-       strcpy(error, "");
        newfcn = (ServiceFunctionHook *) malloc(sizeof(ServiceFunctionHook));
        message = (char*) malloc (SIZ + SIZ);
        
@@ -940,7 +866,7 @@ void CtdlRegisterServiceHook(int tcp_port,
        newfcn->ServiceName = ServiceName;
 
        if (sockpath != NULL) {
-               newfcn->msock = ctdl_uds_server(sockpath, CtdlGetConfigInt("c_maxsessions"), error);
+               newfcn->msock = ctdl_uds_server(sockpath, CtdlGetConfigInt("c_maxsessions"));
                snprintf(message, SIZ, "extensions: unix domain socket '%s': ", sockpath);
        }
        else if (tcp_port <= 0) {       /* port -1 to disable */
@@ -950,10 +876,7 @@ void CtdlRegisterServiceHook(int tcp_port,
                return;
        }
        else {
-               newfcn->msock = ctdl_tcp_server(CtdlGetConfigStr("c_ip_addr"),
-                                             tcp_port,
-                                             CtdlGetConfigInt("c_maxsessions"), 
-                                             error);
+               newfcn->msock = ctdl_tcp_server(CtdlGetConfigStr("c_ip_addr"), tcp_port, CtdlGetConfigInt("c_maxsessions"));
                snprintf(message, SIZ, "extensions: TCP port %s:%d: (%s) ", 
                         CtdlGetConfigStr("c_ip_addr"), tcp_port, ServiceName);
        }
@@ -964,7 +887,7 @@ void CtdlRegisterServiceHook(int tcp_port,
                syslog(LOG_INFO, "%s", message);
        }
        else {
-               AddPortError(message, error);
+               AddPortError(message, "failed");
                strcat(message, "FAILED.");
                syslog(LOG_ERR, "%s", message);
                free(newfcn);
@@ -1216,23 +1139,6 @@ int PerformRoomHooks(struct ctdlroom *target_room)
 }
 
 
-int PerformNetprocHooks(struct CtdlMessage *msg, char *target_room)
-{
-       NetprocFunctionHook *fcn;
-       int total_retval = 0;
-
-       for (fcn = NetprocHookTable; fcn != NULL; fcn = fcn->next) {
-               total_retval = total_retval +
-                       (*fcn->h_function_pointer) (msg, target_room);
-       }
-
-       /* Return the sum of the return codes from the hook functions.
-        * A nonzero return code will cause the message to *not* be imported.
-        */
-       return total_retval;
-}
-
-
 void PerformDeleteHooks(char *room, long msgnum)
 {
        DeleteFunctionHook *fcn;
@@ -1243,9 +1149,6 @@ void PerformDeleteHooks(char *room, long msgnum)
 }
 
 
-
-
-
 int PerformXmsgHooks(char *sender, char *sender_email, char *recp, char *msg)
 {
        XmsgFunctionHook *fcn;