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 "../../sr_module.h"
00032 #include "../../dprint.h"
00033 #include "../usrloc/usrloc.h"
00034 #include "../../parser/msg_parser.h"
00035 #include "../../parser/parse_from.h"
00036 #include "pua_bla.h"
00037 #include "registrar_cb.h"
00038
00039 MODULE_VERSION
00040
00041 pua_api_t pua;
00042
00043 usrloc_api_t ul;
00044 str default_domain= {NULL, 0};
00045 str header_name= {0, 0};
00046 str bla_outbound_proxy= {0, 0};
00047 int is_bla_aor= 0;
00048 str reg_from_uri= {0, 0};
00049 static int mod_init(void);
00050
00051 send_publish_t pua_send_publish;
00052 send_subscribe_t pua_send_subscribe;
00053 query_dialog_t pua_is_dialog;
00054 int bla_set_flag(struct sip_msg* , char*, char*);
00055 str server_address= {0, 0};
00056 static cmd_export_t cmds[]=
00057 {
00058 {"bla_set_flag", (cmd_function)bla_set_flag, 0, 0, 0, REQUEST_ROUTE},
00059 {"bla_handle_notify", (cmd_function)bla_handle_notify, 0, 0, 0, REQUEST_ROUTE},
00060 {0, 0, 0, 0, 0, 0}
00061 };
00062 static param_export_t params[]=
00063 {
00064 {"server_address", STR_PARAM, &server_address.s },
00065 {"default_domain", STR_PARAM, &default_domain.s },
00066 {"header_name", STR_PARAM, &header_name.s },
00067 {"outbound_proxy", STR_PARAM, &bla_outbound_proxy.s },
00068 {0, 0, 0 }
00069 };
00070
00071
00072 struct module_exports exports= {
00073 "pua_bla",
00074 DEFAULT_DLFLAGS,
00075 cmds,
00076 params,
00077 0,
00078 0,
00079 0,
00080 0,
00081 mod_init,
00082 0,
00083 0,
00084 0
00085 };
00086
00087
00088
00089
00090 static int mod_init(void)
00091 {
00092 bind_pua_t bind_pua;
00093 bind_usrloc_t bind_usrloc;
00094
00095 if(server_address.s== NULL)
00096 {
00097 LM_ERR("compulsory 'server_address' parameter not set!");
00098 return -1;
00099 }
00100 server_address.len= strlen(server_address.s);
00101
00102 if(default_domain.s == NULL )
00103 {
00104 LM_ERR("default domain not found\n");
00105 return -1;
00106 }
00107 default_domain.len= strlen(default_domain.s);
00108
00109 if(header_name.s == NULL )
00110 {
00111 LM_ERR("header_name parameter not set\n");
00112 return -1;
00113 }
00114 header_name.len= strlen(header_name.s);
00115
00116 if(bla_outbound_proxy.s == NULL )
00117 {
00118 LM_DBG("No outbound proxy set\n");
00119 }
00120 else
00121 bla_outbound_proxy.len= strlen(bla_outbound_proxy.s);
00122
00123 bind_pua= (bind_pua_t)find_export("bind_pua", 1,0);
00124 if (!bind_pua)
00125 {
00126 LM_ERR("Can't bind pua\n");
00127 return -1;
00128 }
00129
00130 if (bind_pua(&pua) < 0)
00131 {
00132 LM_ERR("Can't bind pua\n");
00133 return -1;
00134 }
00135 if(pua.send_publish == NULL)
00136 {
00137 LM_ERR("Could not import send_publish\n");
00138 return -1;
00139 }
00140 pua_send_publish= pua.send_publish;
00141
00142 if(pua.send_subscribe == NULL)
00143 {
00144 LM_ERR("Could not import send_subscribe\n");
00145 return -1;
00146 }
00147 pua_send_subscribe= pua.send_subscribe;
00148
00149 if(pua.is_dialog == NULL)
00150 {
00151 LM_ERR("Could not import send_subscribe\n");
00152 return -1;
00153 }
00154 pua_is_dialog= pua.is_dialog;
00155
00156 if(pua.register_puacb== NULL)
00157 {
00158 LM_ERR("Could not import register callback\n");
00159 return -1;
00160 }
00161
00162 bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0);
00163 if (!bind_usrloc)
00164 {
00165 LM_ERR("Can't bind usrloc\n");
00166 return -1;
00167 }
00168 if (bind_usrloc(&ul) < 0)
00169 {
00170 LM_ERR("Can't bind usrloc\n");
00171 return -1;
00172 }
00173 if(ul.register_ulcb == NULL)
00174 {
00175 LM_ERR("Could not import ul_register_ulcb\n");
00176 return -1;
00177 }
00178
00179 if(ul.register_ulcb(UL_CONTACT_INSERT, bla_cb , 0)< 0)
00180 {
00181 LM_ERR("can not register callback for"
00182 " insert\n");
00183 return -1;
00184 }
00185 if(ul.register_ulcb(UL_CONTACT_EXPIRE, bla_cb, 0)< 0)
00186 {
00187 LM_ERR("can not register callback for"
00188 " insert\n");
00189 return -1;
00190 }
00191 if(ul.register_ulcb(UL_CONTACT_UPDATE, bla_cb, 0)< 0)
00192 {
00193 LM_ERR("can not register callback for"
00194 " update\n");
00195 return -1;
00196 }
00197 if(ul.register_ulcb(UL_CONTACT_DELETE, bla_cb, 0)< 0)
00198 {
00199 LM_ERR("can not register callback for"
00200 " delete\n");
00201 return -1;
00202 }
00203
00204 return 0;
00205 }
00206
00207
00208 int bla_set_flag(struct sip_msg* msg , char* s1, char* s2)
00209 {
00210 LM_DBG("mark as bla aor\n");
00211
00212 is_bla_aor= 1;
00213
00214 if( parse_headers(msg,HDR_EOH_F, 0)==-1 )
00215 {
00216 LM_ERR("parsing headers\n");
00217 return -1;
00218 }
00219
00220
00221 if (msg->from->parsed == NULL)
00222 {
00223 if ( parse_from_header( msg )<0 )
00224 {
00225 LM_DBG("cannot parse From header\n");
00226 return -1;
00227 }
00228 }
00229
00230 reg_from_uri= ((struct to_body*)(msg->from->parsed))->uri;
00231
00232 return 1;
00233 }
00234