unixsock.c

00001 /*
00002  * $Id$
00003  *
00004  * Copyright (C) 2005 iptelorg GmbH
00005  *
00006  * This file is part of ser, a free SIP server.
00007  *
00008  * ser is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * For a license to use the ser software under conditions
00014  * other than those described here, or to purchase support for this
00015  * software, please contact iptel.org by e-mail at the following addresses:
00016  *    info@iptel.org
00017  *
00018  * ser is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  */
00027 
00028 #include "../../str.h"
00029 #include "../../sr_module.h"
00030 #include "../../error.h"
00031 #include "../../mem/mem.h"
00032 #include "../../parser/msg_parser.h"
00033 #include "../../ut.h"
00034 #include "../../dprint.h"
00035 #include "../../pt.h"
00036 #include "unixsock_server.h"
00037 
00038 MODULE_VERSION
00039 
00040 static int mod_init(void);
00041 static int child_init(int rank);
00042 
00043 /*
00044  * Exported functions
00045  */
00046 static cmd_export_t cmds[] = {
00047         {0, 0, 0, 0, 0}
00048 };
00049 
00050 /*
00051  * Exported parameters
00052  */
00053 static param_export_t params[] = {
00054         {"socket",       PARAM_STRING, &unixsock_name      },
00055         {"children",     PARAM_INT,    &unixsock_children  },
00056         {"send_timeout", PARAM_INT,    &unixsock_tx_timeout},
00057         {"socket_user",  PARAM_STRING, &unixsock_user      },
00058         {"socket_mode",  PARAM_STRING, &unixsock_mode      },
00059         {"socket_group", PARAM_STRING, &unixsock_group     },
00060         {0, 0, 0}
00061 };
00062 
00063 
00064 struct module_exports exports = {
00065         "unixsock",
00066         cmds,           /* Exported commands */
00067         0,              /* Exported RPC methods */
00068         params,         /* Exported parameters */
00069         mod_init,       /* module initialization function */
00070         0,              /* response function*/
00071         0,              /* destroy function */
00072         0,              /* oncancel function */
00073         child_init      /* per-child init function */
00074 };
00075 
00076 
00077 static int mod_init(void)
00078 {
00079         if (init_unixsock_socket() < 0) return -1;
00080              /* Signal to the core that we will be
00081               * creating additional processes
00082               */
00083         if (unixsock_name) register_procs(unixsock_children);
00084         return 0;
00085 }
00086 
00087 
00088 static int child_init(int rank)
00089 {
00090         if (rank == PROC_MAIN) {
00091                 if (init_unixsock_children() < 0) return -1;
00092         }
00093         return 0;
00094 }