00001
00031 #include <stdio.h>
00032 #include <string.h>
00033 #include <stdlib.h>
00034 #include <sys/types.h>
00035 #include <unistd.h>
00036
00037 #include "../../sr_module.h"
00038 #include "../../dprint.h"
00039 #include "../../error.h"
00040 #include "../../ut.h"
00041 #include "../../mem/mem.h"
00042
00043 #include "dispatcher.h"
00044 #include "ds_rpc.h"
00045
00046 MODULE_VERSION
00047
00049 char *dslistfile = CFG_DIR"dispatcher.list";
00050 int force_dst = 0;
00051 int ds_flags = 0;
00052 char *ds_activelist;
00053 char ***ds_setp_a, ***ds_setp_b;
00054 int **ds_setlen_a, **ds_setlen_b;
00055
00057 static int mod_init(void);
00058 static int child_init(int);
00059
00060 static int w_ds_select_dst(struct sip_msg*, char*, char*);
00061 static int w_ds_select_new(struct sip_msg*, char*, char*);
00062
00063 static void destroy(void);
00064
00065 static cmd_export_t cmds[]={
00066 {"ds_select_dst", w_ds_select_dst, 2, fixup_var_int_12, REQUEST_ROUTE|FAILURE_ROUTE},
00067 {"ds_select_new", w_ds_select_new, 2, fixup_var_int_12, REQUEST_ROUTE|FAILURE_ROUTE},
00068 {0,0,0,0,0}
00069 };
00070
00071 static param_export_t params[]={
00072 {"list_file", PARAM_STRING, &dslistfile},
00073 {"force_dst", PARAM_INT, &force_dst},
00074 {"flags", PARAM_INT, &ds_flags},
00075 {0,0,0}
00076 };
00077
00078
00080 struct module_exports exports= {
00081 "dispatcher",
00082 cmds,
00083 rpc_methods,
00084 params,
00085 mod_init,
00086 (response_function) 0,
00087 (destroy_function) destroy,
00088 0,
00089 child_init
00090 };
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 static int mod_init(void)
00102 {
00103 DBG("DISPATCHER: initializing ...\n");
00104
00105 if(ds_init_memory() != 0) {
00106 LOG(L_ERR, "DISPATCHER:mod_init:ERROR -- memory allocation error\n");
00107 return -1;
00108 }
00109
00110
00111 ds_clean_list();
00112 DS_SWITCH_ACTIVE_LIST
00113 ds_clean_list();
00114
00115 if(ds_load_list(dslistfile)!=0)
00116 {
00117 LOG(L_ERR, "DISPATCHER:mod_init:ERROR -- couldn't load list file\n");
00118 return -1;
00119 }
00120
00121 DS_SWITCH_ACTIVE_LIST
00122
00123 return 0;
00124 }
00125
00129 static int child_init(int rank)
00130 {
00131 DBG("DISPATCHER:init_child #%d / pid <%d>\n", rank, getpid());
00132 return 0;
00133 }
00134
00138 static int w_ds_select_dst(struct sip_msg* msg, char* set, char* alg)
00139 {
00140 if(msg==NULL)
00141 return -1;
00142
00143 return ds_select_dst(msg, set, alg);
00144 }
00145
00149 static int w_ds_select_new(struct sip_msg* msg, char* set, char* alg)
00150 {
00151 if(msg==NULL)
00152 return -1;
00153
00154 return ds_select_new(msg, set, alg);
00155 }
00156
00160 static void destroy(void)
00161 {
00162 DBG("DISPATCHER: destroy module ...\n");
00163 ds_destroy_lists();
00164 }