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
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032 #include <libxml/parser.h>
00033 #include <time.h>
00034
00035 #include "../../script_cb.h"
00036 #include "../../sr_module.h"
00037 #include "../../parser/parse_expires.h"
00038 #include "../../dprint.h"
00039 #include "../../mem/shm_mem.h"
00040 #include "../../parser/msg_parser.h"
00041 #include "../../str.h"
00042 #include "../../mem/mem.h"
00043 #include "../../pt.h"
00044 #include "../usrloc/ul_mod.h"
00045 #include "../usrloc/usrloc.h"
00046 #include "../usrloc/ul_callback.h"
00047 #include "../pua/pua_bind.h"
00048 #include "pua_usrloc.h"
00049
00050 MODULE_VERSION
00051
00052 str default_domain= {NULL, 0};
00053 int pua_ul_publish= 0;
00054 pua_api_t pua;
00055 str pres_prefix= {0, 0};
00056
00057
00058 usrloc_api_t ul;
00059
00060
00061
00062 static int mod_init(void);
00063
00064 int pua_set_publish(struct sip_msg* , char*, char*);
00065
00066
00067 static cmd_export_t cmds[]=
00068 {
00069 {"pua_set_publish", (cmd_function)pua_set_publish, 0, 0, 0, REQUEST_ROUTE},
00070 {0, 0, 0, 0, 0, 0}
00071 };
00072
00073 static param_export_t params[]={
00074 {"default_domain", STR_PARAM, &default_domain.s },
00075 {"entity_prefix", STR_PARAM, &pres_prefix.s },
00076 {0, 0, 0 }
00077 };
00078
00079 struct module_exports exports= {
00080 "pua_usrloc",
00081 DEFAULT_DLFLAGS,
00082 cmds,
00083 params,
00084 0,
00085 0,
00086 0,
00087 0,
00088 mod_init,
00089 0,
00090 0,
00091 0
00092 };
00093
00094
00095
00096
00097 static int mod_init(void)
00098 {
00099 bind_usrloc_t bind_usrloc;
00100 bind_pua_t bind_pua;
00101
00102 if(default_domain.s == NULL )
00103 {
00104 LM_ERR("default domain parameter not set\n");
00105 return -1;
00106 }
00107 default_domain.len= strlen(default_domain.s);
00108
00109 if(pres_prefix.s == NULL )
00110 {
00111 LM_DBG("No pres_prefix configured\n");
00112 }
00113 else
00114 pres_prefix.len= strlen(pres_prefix.s);
00115
00116 bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0);
00117 if (!bind_usrloc)
00118 {
00119 LM_ERR("Can't bind usrloc\n");
00120 return -1;
00121 }
00122 if (bind_usrloc(&ul) < 0)
00123 {
00124 LM_ERR("Can't bind usrloc\n");
00125 return -1;
00126 }
00127 if(ul.register_ulcb == NULL)
00128 {
00129 LM_ERR("Could not import ul_register_ulcb\n");
00130 return -1;
00131 }
00132
00133 if(ul.register_ulcb(UL_CONTACT_INSERT, ul_publish, 0)< 0)
00134 {
00135 LM_ERR("can not register callback for"
00136 " insert\n");
00137 return -1;
00138 }
00139 if(ul.register_ulcb(UL_CONTACT_EXPIRE, ul_publish, 0)< 0)
00140 {
00141 LM_ERR("can not register callback for"
00142 " expire\n");
00143 return -1;
00144 }
00145
00146 if(ul.register_ulcb(UL_CONTACT_UPDATE, ul_publish, 0)< 0)
00147 {
00148 LM_ERR("can not register callback for update\n");
00149 return -1;
00150 }
00151
00152 if(ul.register_ulcb(UL_CONTACT_DELETE, ul_publish, 0)< 0)
00153 {
00154 LM_ERR("can not register callback for delete\n");
00155 return -1;
00156 }
00157
00158 bind_pua= (bind_pua_t)find_export("bind_pua", 1,0);
00159 if (!bind_pua)
00160 {
00161 LM_ERR("Can't bind pua\n");
00162 return -1;
00163 }
00164
00165 if (bind_pua(&pua) < 0)
00166 {
00167 LM_ERR("Can't bind pua\n");
00168 return -1;
00169 }
00170 if(pua.send_publish == NULL)
00171 {
00172 LM_ERR("Could not import send_publish\n");
00173 return -1;
00174 }
00175 pua_send_publish= pua.send_publish;
00176
00177 if(pua.send_subscribe == NULL)
00178 {
00179 LM_ERR("Could not import send_subscribe\n");
00180 return -1;
00181 }
00182 pua_send_subscribe= pua.send_subscribe;
00183
00184
00185 if(register_script_cb(pua_unset_publish, POST_SCRIPT_CB|REQ_TYPE_CB, 0)<0)
00186 {
00187 LM_ERR("failed to register POST request callback\n");
00188 return -1;
00189 }
00190
00191
00192 return 0;
00193 }