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
00030
00031
00032
00033 #include <stdio.h>
00034 #include <stdlib.h>
00035 #include <string.h>
00036 #include <libxml/parser.h>
00037 #include <time.h>
00038
00039 #include "../../sr_module.h"
00040 #include "../../dprint.h"
00041 #include "../../str.h"
00042 #include "../../pt.h"
00043 #include "../../mem/mem.h"
00044 #include "../../mem/shm_mem.h"
00045 #include "../../parser/parse_expires.h"
00046 #include "../../parser/msg_parser.h"
00047 #include "../tm/tm_load.h"
00048 #include "../xmpp/xmpp_api.h"
00049 #include "../pua/pua_bind.h"
00050
00051 #include "pua_xmpp.h"
00052 #include "xmpp2simple.h"
00053 #include "simple2xmpp.h"
00054 #include "request_winfo.h"
00055
00056 MODULE_VERSION
00057
00058 struct tm_binds tmb;
00059
00060
00061 pua_api_t pua;
00062 send_publish_t pua_send_publish;
00063 send_subscribe_t pua_send_subscribe;
00064 query_dialog_t pua_is_dialog;
00065
00066
00067 xmpp_api_t xmpp_api;
00068 xmpp_send_xsubscribe_f xmpp_subscribe;
00069 xmpp_send_xnotify_f xmpp_notify;
00070 xmpp_send_xpacket_f xmpp_packet;
00071 xmpp_translate_uri_f duri_sip_xmpp;
00072 xmpp_translate_uri_f euri_sip_xmpp;
00073 xmpp_translate_uri_f duri_xmpp_sip;
00074 xmpp_translate_uri_f euri_xmpp_sip;
00075
00076
00077 xmlNodeGetAttrContentByName_t XMLNodeGetAttrContentByName;
00078 xmlDocGetNodeByName_t XMLDocGetNodeByName;
00079 xmlNodeGetNodeByName_t XMLNodeGetNodeByName;
00080 xmlNodeGetNodeContentByName_t XMLNodeGetNodeContentByName;
00081
00082 str server_address= {0, 0};
00083
00084
00085
00086 static int mod_init(void);
00087 static int child_init(int);
00088
00089 static int fixup_pua_xmpp(void** param, int param_no);
00090
00091 static cmd_export_t cmds[]=
00092 {
00093 {"pua_xmpp_notify", (cmd_function)Notify2Xmpp, 0, 0, 0, REQUEST_ROUTE},
00094 {"pua_xmpp_req_winfo", (cmd_function)request_winfo, 2, fixup_pua_xmpp, 0, REQUEST_ROUTE},
00095 {0, 0, 0, 0, 0, 0}
00096 };
00097
00098 static param_export_t params[]={
00099 {"server_address", STR_PARAM, &server_address },
00100 {0, 0, 0 }
00101 };
00102
00103
00104 struct module_exports exports= {
00105 "pua_xmpp",
00106 DEFAULT_DLFLAGS,
00107 cmds,
00108 params,
00109 0,
00110 0,
00111 0,
00112 0,
00113 mod_init,
00114 0,
00115 0,
00116 child_init
00117 };
00118
00119
00120
00121
00122 static int mod_init(void)
00123 {
00124 load_tm_f load_tm;
00125 bind_pua_t bind_pua;
00126 bind_xmpp_t bind_xmpp;
00127 bind_libxml_t bind_libxml;
00128 libxml_api_t libxml_api;
00129
00130
00131 if(server_address.s== NULL)
00132 {
00133 LM_ERR("compulsory 'server_address' parameter not set!");
00134 return -1;
00135 }
00136 server_address.len= strlen(server_address.s);
00137
00138
00139 if((load_tm=(load_tm_f)find_export("load_tm", 0, 0))==NULL)
00140 {
00141 LM_ERR("can't import load_tm\n");
00142 return -1;
00143 }
00144
00145
00146 if(load_tm(&tmb)==-1)
00147 {
00148 LM_ERR("can't load tm functions\n");
00149 return -1;
00150 }
00151
00152
00153 if((bind_libxml= (bind_libxml_t)find_export("bind_libxml_api", 1, 0))== NULL)
00154 {
00155 LM_ERR("can't import bind_libxml_api\n");
00156 return -1;
00157 }
00158 if(bind_libxml(&libxml_api)< 0)
00159 {
00160 LM_ERR("can not bind libxml api\n");
00161 return -1;
00162 }
00163 XMLNodeGetAttrContentByName= libxml_api.xmlNodeGetAttrContentByName;
00164 XMLDocGetNodeByName= libxml_api.xmlDocGetNodeByName;
00165 XMLNodeGetNodeByName= libxml_api.xmlNodeGetNodeByName;
00166 XMLNodeGetNodeContentByName= libxml_api.xmlNodeGetNodeContentByName;
00167
00168 if(XMLNodeGetAttrContentByName== NULL || XMLDocGetNodeByName== NULL ||
00169 XMLNodeGetNodeByName== NULL || XMLNodeGetNodeContentByName== NULL)
00170 {
00171 LM_ERR("libxml wrapper functions could not be bound\n");
00172 return -1;
00173 }
00174
00175
00176
00177 bind_xmpp= (bind_xmpp_t)find_export("bind_xmpp", 0,0);
00178 if (!bind_xmpp)
00179 {
00180 LM_ERR("Can't bind to the XMPP module.\n");
00181 return -1;
00182 }
00183 if(bind_xmpp(&xmpp_api)< 0)
00184 {
00185 LM_ERR("Can't bind to the XMPP module.\n");
00186 return -1;
00187 }
00188 if(xmpp_api.xsubscribe== NULL)
00189 {
00190 LM_ERR("Could not import xsubscribe from the XMPP module. Version mismatch?\n");
00191 return -1;
00192 }
00193 xmpp_subscribe= xmpp_api.xsubscribe;
00194
00195 if(xmpp_api.xnotify== NULL)
00196 {
00197 LM_ERR("Could not import xnotify from the XMPP module. Version mismatch?\n");
00198 return -1;
00199 }
00200 xmpp_notify= xmpp_api.xnotify;
00201
00202 if(xmpp_api.xpacket== NULL)
00203 {
00204 LM_ERR("Could not import xnotify from the XMPP module. Version mismatch?\n");
00205 return -1;
00206 }
00207 xmpp_packet= xmpp_api.xpacket;
00208
00209 if(xmpp_api.register_callback== NULL)
00210 {
00211 LM_ERR("Could not import register_callback"
00212 " to xmpp\n");
00213 return -1;
00214 }
00215 if(xmpp_api.register_callback(XMPP_RCV_PRESENCE, pres_Xmpp2Sip, NULL)< 0)
00216 {
00217 LM_ERR("ERROR while registering callback"
00218 " to xmpp\n");
00219 return -1;
00220 }
00221 if(xmpp_api.decode_uri_sip_xmpp== NULL)
00222 {
00223 LM_ERR("Could not import decode_uri_sip_xmpp"
00224 " from xmpp\n");
00225 return -1;
00226 }
00227 duri_sip_xmpp= xmpp_api.decode_uri_sip_xmpp;
00228
00229 if(xmpp_api.encode_uri_sip_xmpp== NULL)
00230 {
00231 LM_ERR("Could not import encode_uri_sip_xmpp"
00232 " from xmpp\n");
00233 return -1;
00234 }
00235 euri_sip_xmpp= xmpp_api.encode_uri_sip_xmpp;
00236
00237 if(xmpp_api.decode_uri_xmpp_sip== NULL)
00238 {
00239 LM_ERR("Could not import decode_uri_xmpp_sip"
00240 " from xmpp\n");
00241 return -1;
00242 }
00243 duri_xmpp_sip= xmpp_api.decode_uri_xmpp_sip;
00244
00245 if(xmpp_api.encode_uri_xmpp_sip== NULL)
00246 {
00247 LM_ERR("Could not import encode_uri_xmpp_sip"
00248 " from xmpp\n");
00249 return -1;
00250 }
00251 euri_xmpp_sip= xmpp_api.encode_uri_xmpp_sip;
00252
00253
00254 bind_pua= (bind_pua_t)find_export("bind_pua", 1,0);
00255 if (!bind_pua)
00256 {
00257 LM_ERR("Can't bind to PUA module\n");
00258 return -1;
00259 }
00260
00261 if (bind_pua(&pua) < 0)
00262 {
00263 LM_ERR("Can't bind to PUA module\n");
00264 return -1;
00265 }
00266 if(pua.send_publish == NULL)
00267 {
00268 LM_ERR("Could not import send_publish() in module PUA. Version mismatch?\n");
00269 return -1;
00270 }
00271 pua_send_publish= pua.send_publish;
00272
00273 if(pua.send_subscribe == NULL)
00274 {
00275 LM_ERR("Could not import send_publish() in module PUA. Version mismatch?\n");
00276 return -1;
00277 }
00278 pua_send_subscribe= pua.send_subscribe;
00279
00280 if(pua.is_dialog == NULL)
00281 {
00282 LM_ERR("Could not import send_subscribe() in module PUA. Version mismatch?\n");
00283 return -1;
00284 }
00285 pua_is_dialog= pua.is_dialog;
00286
00287 if(pua.register_puacb(XMPP_INITIAL_SUBS, Sipreply2Xmpp, NULL)< 0)
00288 {
00289 LM_ERR("Could not register PUA callback\n");
00290 return -1;
00291 }
00292
00293 return 0;
00294 }
00295
00296 static int child_init(int rank)
00297 {
00298 LM_DBG("child [%d] pid [%d]\n", rank, getpid());
00299 return 0;
00300 }
00301
00302 static int fixup_pua_xmpp(void** param, int param_no)
00303 {
00304 pv_elem_t *model;
00305 str s;
00306 if(*param)
00307 {
00308 s.s = (char*)(*param); s.len = strlen(s.s);
00309 if(pv_parse_format(&s, &model)<0)
00310 {
00311 LM_ERR("wrong format[%s]\n",(char*)(*param));
00312 return E_UNSPEC;
00313 }
00314
00315 *param = (void*)model;
00316 return 0;
00317 }
00318 LM_ERR("null format\n");
00319 return E_UNSPEC;
00320 }
00321