00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00037 #include <stdio.h>
00038 #include <stdlib.h>
00039 #include <string.h>
00040 #include <libxml/parser.h>
00041 #include <time.h>
00042
00043 #include "../../script_cb.h"
00044 #include "../../sr_module.h"
00045 #include "../../parser/parse_expires.h"
00046 #include "../../dprint.h"
00047 #include "../../mem/shm_mem.h"
00048 #include "../../parser/msg_parser.h"
00049 #include "../../str.h"
00050 #include "../../mem/mem.h"
00051 #include "../../pt.h"
00052 #include "../usrloc/ul_mod.h"
00053 #include "../usrloc/usrloc.h"
00054 #include "../usrloc/ul_callback.h"
00055 #include "../pua/pua_bind.h"
00056 #include "pua_usrloc.h"
00057 #include "api.h"
00058
00059 MODULE_VERSION
00060
00061 str default_domain= {NULL, 0};
00062
00063 int pua_ul_publish = 0;
00064 int pua_ul_bflag = -1;
00065 int pua_ul_bmask = 0;
00066
00067 pua_api_t pua;
00068 str pres_prefix= {0, 0};
00069
00071 usrloc_api_t ul;
00072
00075 static int mod_init(void);
00076
00077 int pua_set_publish(struct sip_msg* , char*, char*);
00078
00079 send_publish_t pua_send_publish;
00080 send_subscribe_t pua_send_subscribe;
00081
00082 static cmd_export_t cmds[]=
00083 {
00084 {"pua_set_publish", (cmd_function)pua_set_publish, 0, 0, 0, REQUEST_ROUTE},
00085 {"bind_pua_usrloc", (cmd_function)bind_pua_usrloc, 1, 0, 0, 0},
00086 {0, 0, 0, 0, 0, 0}
00087 };
00088
00089 static param_export_t params[]={
00090 {"default_domain", STR_PARAM, &default_domain.s },
00091 {"entity_prefix", STR_PARAM, &pres_prefix.s },
00092 {"branch_flag", INT_PARAM, &pua_ul_bflag },
00093 {0, 0, 0 }
00094 };
00095
00096 struct module_exports exports= {
00097 "pua_usrloc",
00098 DEFAULT_DLFLAGS,
00099 cmds,
00100 params,
00101 0,
00102 0,
00103 0,
00104 0,
00105 mod_init,
00106 0,
00107 0,
00108 0
00109 };
00110
00114 static int mod_init(void)
00115 {
00116 bind_usrloc_t bind_usrloc;
00117 bind_pua_t bind_pua;
00118
00119 if(default_domain.s == NULL )
00120 {
00121 LM_ERR("default domain parameter not set\n");
00122 return -1;
00123 }
00124 default_domain.len= strlen(default_domain.s);
00125
00126 if(pres_prefix.s == NULL )
00127 {
00128 LM_DBG("No pres_prefix configured\n");
00129 }
00130 else
00131 pres_prefix.len= strlen(pres_prefix.s);
00132
00133 bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0);
00134 if (!bind_usrloc)
00135 {
00136 LM_ERR("Can't bind usrloc\n");
00137 return -1;
00138 }
00139 if (bind_usrloc(&ul) < 0)
00140 {
00141 LM_ERR("Can't bind usrloc\n");
00142 return -1;
00143 }
00144 if(ul.register_ulcb == NULL)
00145 {
00146 LM_ERR("Could not import ul_register_ulcb\n");
00147 return -1;
00148 }
00149
00150 if(ul.register_ulcb(UL_CONTACT_INSERT, ul_publish, 0)< 0)
00151 {
00152 LM_ERR("can not register callback for"
00153 " insert\n");
00154 return -1;
00155 }
00156 if(ul.register_ulcb(UL_CONTACT_EXPIRE, ul_publish, 0)< 0)
00157 {
00158 LM_ERR("can not register callback for"
00159 " expire\n");
00160 return -1;
00161 }
00162
00163 if(ul.register_ulcb(UL_CONTACT_UPDATE, ul_publish, 0)< 0)
00164 {
00165 LM_ERR("can not register callback for update\n");
00166 return -1;
00167 }
00168
00169 if(ul.register_ulcb(UL_CONTACT_DELETE, ul_publish, 0)< 0)
00170 {
00171 LM_ERR("can not register callback for delete\n");
00172 return -1;
00173 }
00174
00175 bind_pua= (bind_pua_t)find_export("bind_pua", 1,0);
00176 if (!bind_pua)
00177 {
00178 LM_ERR("Can't bind pua\n");
00179 return -1;
00180 }
00181
00182 if (bind_pua(&pua) < 0)
00183 {
00184 LM_ERR("Can't bind pua\n");
00185 return -1;
00186 }
00187 if(pua.send_publish == NULL)
00188 {
00189 LM_ERR("Could not import send_publish\n");
00190 return -1;
00191 }
00192 pua_send_publish= pua.send_publish;
00193
00194 if(pua.send_subscribe == NULL)
00195 {
00196 LM_ERR("Could not import send_subscribe\n");
00197 return -1;
00198 }
00199 pua_send_subscribe= pua.send_subscribe;
00200
00201
00202 if(register_script_cb(pua_unset_publish, POST_SCRIPT_CB|REQUEST_CB, 0)<0)
00203 {
00204 LM_ERR("failed to register POST request callback\n");
00205 return -1;
00206 }
00207
00208 if(pua_ul_bflag!=-1)
00209 pua_ul_bmask = 1 << pua_ul_bflag;
00210
00211 return 0;
00212 }
00213
00214 int bind_pua_usrloc(struct pua_usrloc_binds *pxb)
00215 {
00216 if (pxb == NULL)
00217 {
00218 LM_WARN("bind_pua_usrloc: Cannot load pua_usrloc API into a NULL pointer\n");
00219 return -1;
00220 }
00221
00222 pxb->pua_set_publish = pua_set_publish;
00223 return 0;
00224 }