| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
#include "../../modules/http_client/curl_api.h" |
| 35 |
|
| 36 |
#include "../../core/mod_fix.h" |
| 37 |
#include "../../core/sr_module.h" |
| 38 |
#include "../../core/ut.h" |
| 39 |
#include "../../core/locking.h" |
| 40 |
|
| 41 |
#include "../../core/pvar.h" |
| 42 |
#include "../../core/mem/mem.h" |
| 43 |
#include "../../core/dprint.h" |
| 44 |
|
| 45 |
#include "../../core/script_cb.h" |
| 46 |
|
| 47 |
#include "functions.h" |
| 48 |
|
| 49 |
MODULE_VERSION |
| 50 |
|
| 51 |
|
| 52 |
httpc_api_t httpapi; |
| 53 |
|
| 54 |
|
| 55 |
int lost_geoloc_type = 0; |
| 56 |
|
| 57 |
int lost_geoloc_order = 0; |
| 58 |
|
| 59 |
int lost_geoloc_3d = 0; |
| 60 |
|
| 61 |
int lost_recursion = 1; |
| 62 |
|
| 63 |
int lost_profile = 0; |
| 64 |
|
| 65 |
int lost_verbose = 0; |
| 66 |
|
| 67 |
int held_resp_time = 0; |
| 68 |
|
| 69 |
int held_exact_type = 0; |
| 70 |
|
| 71 |
int held_post_req = 0; |
| 72 |
|
| 73 |
str held_loc_type = STR_NULL; |
| 74 |
|
| 75 |
|
| 76 |
static int mod_init(void); |
| 77 |
static int child_init(int); |
| 78 |
static void destroy(void); |
| 79 |
|
| 80 |
|
| 81 |
static int fixup_lost_held_query(void **param, int param_no); |
| 82 |
static int fixup_free_lost_held_query(void **param, int param_no); |
| 83 |
static int fixup_lost_held_query_id(void **param, int param_no); |
| 84 |
static int fixup_free_lost_held_query_id(void **param, int param_no); |
| 85 |
static int fixup_lost_held_deref(void **param, int param_no); |
| 86 |
static int fixup_free_lost_held_deref(void **param, int param_no); |
| 87 |
|
| 88 |
static int fixup_lost_query(void **param, int param_no); |
| 89 |
static int fixup_free_lost_query(void **param, int param_no); |
| 90 |
static int fixup_lost_query_all(void **param, int param_no); |
| 91 |
static int fixup_free_lost_query_all(void **param, int param_no); |
| 92 |
|
| 93 |
|
| 94 |
static int w_lost_held_query( |
| 95 |
struct sip_msg *_m, char *_con, char *_pidf, char *_url, char *_err); |
| 96 |
static int w_lost_held_query_id(struct sip_msg *_m, char *_con, char *_id, |
| 97 |
char *_pidf, char *_url, char *_err); |
| 98 |
static int w_lost_held_deref(struct sip_msg *_m, char *_url, char *_rtime, |
| 99 |
char *_rtype, char *_pidf, char *_err); |
| 100 |
static int w_lost_query( |
| 101 |
struct sip_msg *_m, char *_con, char *_uri, char *_name, char *_err); |
| 102 |
static int w_lost_query_all(struct sip_msg *_m, char *_con, char *_pidf, |
| 103 |
char *_urn, char *_uri, char *_name, char *_err); |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
static cmd_export_t cmds[] = { |
| 108 |
{"lost_held_query", (cmd_function)w_lost_held_query, 4, |
| 109 |
fixup_lost_held_query, fixup_free_lost_held_query, |
| 110 |
REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE}, |
| 111 |
{"lost_held_query", (cmd_function)w_lost_held_query_id, 5, |
| 112 |
fixup_lost_held_query_id, fixup_free_lost_held_query_id, |
| 113 |
REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE}, |
| 114 |
{"lost_held_dereference", (cmd_function)w_lost_held_deref, 5, |
| 115 |
fixup_lost_held_deref, fixup_free_lost_held_deref, |
| 116 |
REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE}, |
| 117 |
{"lost_query", (cmd_function)w_lost_query, 4, fixup_lost_query, |
| 118 |
fixup_free_lost_query, |
| 119 |
REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE}, |
| 120 |
{"lost_query", (cmd_function)w_lost_query_all, 6, fixup_lost_query_all, |
| 121 |
fixup_free_lost_query_all, |
| 122 |
REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE}, |
| 123 |
{0, 0, 0, 0, 0, 0} |
| 124 |
}; |
| 125 |
|
| 126 |
|
| 127 |
static param_export_t params[] = {{"exact_type", PARAM_INT, &held_exact_type}, |
| 128 |
{"response_time", PARAM_INT, &held_resp_time}, |
| 129 |
{"post_request", PARAM_INT, &held_post_req}, |
| 130 |
{"location_type", PARAM_STR, &held_loc_type}, |
| 131 |
{"recursion", PARAM_INT, &lost_recursion}, |
| 132 |
{"location_profile", PARAM_INT, &lost_profile}, |
| 133 |
{"location_3d", PARAM_INT, &lost_geoloc_3d}, |
| 134 |
{"verbose", PARAM_INT, &lost_verbose}, |
| 135 |
{"geoheader_type", PARAM_INT, &lost_geoloc_type}, |
| 136 |
{"geoheader_order", PARAM_INT, &lost_geoloc_order}, {0, 0, 0} |
| 137 |
}; |
| 138 |
|
| 139 |
|
| 140 |
struct module_exports exports = { |
| 141 |
"lost", |
| 142 |
DEFAULT_DLFLAGS, |
| 143 |
cmds, |
| 144 |
params, |
| 145 |
0, |
| 146 |
0, |
| 147 |
0, |
| 148 |
mod_init, |
| 149 |
child_init, |
| 150 |
destroy |
| 151 |
}; |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
static int mod_init(void) |
| 156 |
{ |
| 157 |
LM_DBG("init lost module\n"); |
| 158 |
|
| 159 |
if(httpc_load_api(&httpapi) != 0) { |
| 160 |
LM_ERR("can not bind to http_client API \n"); |
| 161 |
return -1; |
| 162 |
} |
| 163 |
|
| 164 |
if(held_loc_type.len > 0) { |
| 165 |
held_loc_type.s = lost_held_type( |
| 166 |
held_loc_type.s, &held_exact_type, &held_loc_type.len); |
| 167 |
LM_DBG("**** init lost: held location type: %.*s \n", held_loc_type.len, |
| 168 |
held_loc_type.s); |
| 169 |
} |
| 170 |
|
| 171 |
LM_DBG("**** init lost: held response time: %d \n", held_resp_time); |
| 172 |
|
| 173 |
LM_DBG("**** init lost module done.\n"); |
| 174 |
|
| 175 |
return 0; |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
static int child_init(int rank) |
| 180 |
{ |
| 181 |
return 0; |
| 182 |
} |
| 183 |
|
| 184 |
static void destroy(void) |
| 185 |
{ |
| 186 |
if(held_loc_type.s != NULL && held_loc_type.len > 0) { |
| 187 |
pkg_free(held_loc_type.s); |
| 188 |
held_loc_type.s = NULL; |
| 189 |
held_loc_type.len = 0; |
| 190 |
} |
| 191 |
|
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
static int fixup_lost_held_query(void **param, int param_no) |
| 199 |
{ |
| 200 |
if(param_no == 1) { |
| 201 |
return fixup_spve_null(param, 1); |
| 202 |
} |
| 203 |
if((param_no == 2) || (param_no == 3) || (param_no == 4)) { |
| 204 |
if(fixup_pvar_null(param, 1) != 0) { |
| 205 |
LM_ERR("failed to fixup result pvar\n"); |
| 206 |
return -1; |
| 207 |
} |
| 208 |
if(((pv_spec_t *)(*param))->setf == NULL) { |
| 209 |
LM_ERR("result pvar is not writable\n"); |
| 210 |
return -1; |
| 211 |
} |
| 212 |
return 0; |
| 213 |
} |
| 214 |
LM_ERR("invalid parameter number <%d>\n", param_no); |
| 215 |
return -1; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
static int fixup_free_lost_held_query(void **param, int param_no) |
| 222 |
{ |
| 223 |
if(param_no == 1) { |
| 224 |
return fixup_spve_null(param, 1); |
| 225 |
} |
| 226 |
if((param_no == 2) || (param_no == 3) || (param_no == 4)) { |
| 227 |
return fixup_free_pvar_null(param, 1); |
| 228 |
} |
| 229 |
LM_ERR("invalid parameter number <%d>\n", param_no); |
| 230 |
return -1; |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
static int fixup_lost_held_query_id(void **param, int param_no) |
| 238 |
{ |
| 239 |
if((param_no == 1) || (param_no == 2)) { |
| 240 |
return fixup_spve_null(param, 1); |
| 241 |
} |
| 242 |
if((param_no == 3) || (param_no == 4) || (param_no == 5)) { |
| 243 |
if(fixup_pvar_null(param, 1) != 0) { |
| 244 |
LM_ERR("failed to fixup result pvar\n"); |
| 245 |
return -1; |
| 246 |
} |
| 247 |
if(((pv_spec_t *)(*param))->setf == NULL) { |
| 248 |
LM_ERR("result pvar is not writable\n"); |
| 249 |
return -1; |
| 250 |
} |
| 251 |
return 0; |
| 252 |
} |
| 253 |
LM_ERR("invalid parameter number <%d>\n", param_no); |
| 254 |
return -1; |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
static int fixup_free_lost_held_query_id(void **param, int param_no) |
| 261 |
{ |
| 262 |
if((param_no == 1) || (param_no == 2)) { |
| 263 |
return fixup_free_spve_null(param, 1); |
| 264 |
} |
| 265 |
if((param_no == 3) || (param_no == 4) || (param_no == 5)) { |
| 266 |
return fixup_free_pvar_null(param, 1); |
| 267 |
} |
| 268 |
LM_ERR("invalid parameter number <%d>\n", param_no); |
| 269 |
return -1; |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
static int fixup_lost_held_deref(void **param, int param_no) |
| 277 |
{ |
| 278 |
if((param_no == 1) || (param_no == 2) || (param_no == 3)) { |
| 279 |
return fixup_spve_null(param, 1); |
| 280 |
} |
| 281 |
if((param_no == 4) || (param_no == 5)) { |
| 282 |
if(fixup_pvar_null(param, 1) != 0) { |
| 283 |
LM_ERR("failed to fixup result pvar\n"); |
| 284 |
return -1; |
| 285 |
} |
| 286 |
if(((pv_spec_t *)(*param))->setf == NULL) { |
| 287 |
LM_ERR("result pvar is not writable\n"); |
| 288 |
return -1; |
| 289 |
} |
| 290 |
return 0; |
| 291 |
} |
| 292 |
LM_ERR("invalid parameter number <%d>\n", param_no); |
| 293 |
return -1; |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
static int fixup_free_lost_held_deref(void **param, int param_no) |
| 300 |
{ |
| 301 |
if((param_no == 1) || (param_no == 2) || (param_no == 3)) { |
| 302 |
return fixup_free_spve_null(param, 1); |
| 303 |
} |
| 304 |
if((param_no == 4) || (param_no == 5)) { |
| 305 |
return fixup_free_pvar_null(param, 1); |
| 306 |
} |
| 307 |
LM_ERR("invalid parameter number <%d>\n", param_no); |
| 308 |
return -1; |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
static int fixup_lost_query(void **param, int param_no) |
| 316 |
{ |
| 317 |
if(param_no == 1) { |
| 318 |
return fixup_spve_null(param, 1); |
| 319 |
} |
| 320 |
if((param_no == 2) || (param_no == 3) || (param_no == 4)) { |
| 321 |
if(fixup_pvar_null(param, 1) != 0) { |
| 322 |
LM_ERR("failed to fixup result pvar\n"); |
| 323 |
return -1; |
| 324 |
} |
| 325 |
if(((pv_spec_t *)(*param))->setf == NULL) { |
| 326 |
LM_ERR("result pvar is not writable\n"); |
| 327 |
return -1; |
| 328 |
} |
| 329 |
return 0; |
| 330 |
} |
| 331 |
LM_ERR("invalid parameter number <%d>\n", param_no); |
| 332 |
return -1; |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
static int fixup_free_lost_query(void **param, int param_no) |
| 339 |
{ |
| 340 |
if(param_no == 1) { |
| 341 |
return fixup_free_spve_null(param, 1); |
| 342 |
} |
| 343 |
if((param_no == 2) || (param_no == 3) || (param_no == 4)) { |
| 344 |
return fixup_free_pvar_null(param, 1); |
| 345 |
} |
| 346 |
LM_ERR("invalid parameter number <%d>\n", param_no); |
| 347 |
return -1; |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
static int fixup_lost_query_all(void **param, int param_no) |
| 355 |
{ |
| 356 |
if(param_no == 1) { |
| 357 |
return fixup_spve_null(param, 1); |
| 358 |
} |
| 359 |
if((param_no == 2) || (param_no == 3)) { |
| 360 |
return fixup_spve_null(param, 1); |
| 361 |
} |
| 362 |
if((param_no == 4) || (param_no == 5) || (param_no == 6)) { |
| 363 |
if(fixup_pvar_null(param, 1) != 0) { |
| 364 |
LM_ERR("failed to fixup result pvar\n"); |
| 365 |
return -1; |
| 366 |
} |
| 367 |
if(((pv_spec_t *)(*param))->setf == NULL) { |
| 368 |
LM_ERR("result pvar is not writable\n"); |
| 369 |
return -1; |
| 370 |
} |
| 371 |
return 0; |
| 372 |
} |
| 373 |
LM_ERR("invalid parameter number <%d>\n", param_no); |
| 374 |
return -1; |
| 375 |
} |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
static int fixup_free_lost_query_all(void **param, int param_no) |
| 381 |
{ |
| 382 |
if(param_no == 1) { |
| 383 |
return fixup_free_spve_null(param, 1); |
| 384 |
} |
| 385 |
if((param_no == 2) || (param_no == 3)) { |
| 386 |
return fixup_free_spve_null(param, 1); |
| 387 |
} |
| 388 |
if((param_no == 4) || (param_no == 5) || (param_no == 6)) { |
| 389 |
return fixup_free_pvar_null(param, 1); |
| 390 |
} |
| 391 |
LM_ERR("invalid parameter number <%d>\n", param_no); |
| 392 |
return -1; |
| 393 |
} |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
static int w_lost_held_query( |
| 399 |
struct sip_msg *_m, char *_con, char *_pidf, char *_url, char *_err) |
| 400 |
{ |
| 401 |
return lost_held_function(_m, _con, _pidf, _url, _err, NULL); |
| 402 |
} |
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
static int w_lost_held_query_id(struct sip_msg *_m, char *_con, char *_id, |
| 408 |
char *_pidf, char *_url, char *_err) |
| 409 |
{ |
| 410 |
return lost_held_function(_m, _con, _pidf, _url, _err, _id); |
| 411 |
} |
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
static int w_lost_held_deref(struct sip_msg *_m, char *_url, char *_rtime, |
| 417 |
char *_rtype, char *_pidf, char *_err) |
| 418 |
{ |
| 419 |
return lost_held_dereference(_m, _url, _pidf, _err, _rtime, _rtype); |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
static int w_lost_query( |
| 426 |
struct sip_msg *_m, char *_con, char *_uri, char *_name, char *_err) |
| 427 |
{ |
| 428 |
return lost_function(_m, _con, _uri, _name, _err, NULL, NULL); |
| 429 |
} |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
static int w_lost_query_all(struct sip_msg *_m, char *_con, char *_pidf, |
| 435 |
char *_urn, char *_uri, char *_name, char *_err) |
| 436 |
{ |
| 437 |
return lost_function(_m, _con, _uri, _name, _err, _pidf, _urn); |
| 438 |
} |