| 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 |
#include "asterisk.h" |
| 29 |
|
| 30 |
#include <pjsip.h> |
| 31 |
#include <pjsip_ua.h> |
| 32 |
|
| 33 |
#include "asterisk/res_pjsip.h" |
| 34 |
#include "asterisk/res_pjsip_session.h" |
| 35 |
#include "asterisk/channel.h" |
| 36 |
#include "asterisk/pbx.h" |
| 37 |
#include "asterisk/app.h" |
| 38 |
#include "asterisk/module.h" |
| 39 |
#include "asterisk/utils.h" |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
struct hdr_list_entry { |
| 409 |
pjsip_hdr *hdr; |
| 410 |
AST_LIST_ENTRY(hdr_list_entry) nextptr; |
| 411 |
}; |
| 412 |
AST_LIST_HEAD_NOLOCK(hdr_list, hdr_list_entry); |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
static void *inheritable_headers_duplicate(void *data) |
| 421 |
{ |
| 422 |
return ast_variables_dup(data); |
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
static void inheritable_headers_destroy(void *data) |
| 430 |
{ |
| 431 |
ast_variables_destroy(data); |
| 432 |
} |
| 433 |
|
| 434 |
|
| 435 |
static const struct ast_datastore_info session_header_datastore = { |
| 436 |
.type = "session_header_datastore", |
| 437 |
|
| 438 |
}; |
| 439 |
|
| 440 |
|
| 441 |
static const struct ast_datastore_info inheritable_header_datastore = { |
| 442 |
.type = "inheritable_header_datastore", |
| 443 |
.duplicate = inheritable_headers_duplicate, |
| 444 |
.destroy = inheritable_headers_destroy, |
| 445 |
}; |
| 446 |
|
| 447 |
|
| 448 |
static const struct ast_datastore_info response_header_datastore = { |
| 449 |
.type = "response_header_datastore", |
| 450 |
}; |
| 451 |
|
| 452 |
|
| 453 |
struct header_data { |
| 454 |
struct ast_sip_channel_pvt *channel; |
| 455 |
char *header_name; |
| 456 |
const char *header_value; |
| 457 |
char *buf; |
| 458 |
int header_number; |
| 459 |
size_t len; |
| 460 |
const struct ast_datastore_info *header_datastore; |
| 461 |
}; |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
static int insert_headers(pj_pool_t * pool, struct hdr_list *list, pjsip_msg * msg) |
| 471 |
{ |
| 472 |
pjsip_hdr *hdr = msg->hdr.next; |
| 473 |
struct hdr_list_entry *le; |
| 474 |
|
| 475 |
while (hdr && hdr != &msg->hdr) { |
| 476 |
le = pj_pool_zalloc(pool, sizeof(struct hdr_list_entry)); |
| 477 |
le->hdr = pjsip_hdr_clone(pool, hdr); |
| 478 |
AST_LIST_INSERT_TAIL(list, le, nextptr); |
| 479 |
hdr = hdr->next; |
| 480 |
} |
| 481 |
|
| 482 |
return 0; |
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
static int incoming_request(struct ast_sip_session *session, pjsip_rx_data * rdata) |
| 494 |
{ |
| 495 |
pj_pool_t *pool = session->inv_session->dlg->pool; |
| 496 |
RAII_VAR(struct ast_datastore *, datastore, |
| 497 |
ast_sip_session_get_datastore(session, session_header_datastore.type), ao2_cleanup); |
| 498 |
|
| 499 |
if (!datastore) { |
| 500 |
if (!(datastore = |
| 501 |
ast_sip_session_alloc_datastore(&session_header_datastore, session_header_datastore.type)) |
| 502 |
|| |
| 503 |
!(datastore->data = pj_pool_alloc(pool, sizeof(struct hdr_list))) || |
| 504 |
ast_sip_session_add_datastore(session, datastore)) { |
| 505 |
ast_log(AST_LOG_ERROR, "Unable to create datastore for header functions.\n"); |
| 506 |
return 0; |
| 507 |
} |
| 508 |
AST_LIST_HEAD_INIT_NOLOCK((struct hdr_list *) datastore->data); |
| 509 |
} |
| 510 |
insert_headers(pool, (struct hdr_list *) datastore->data, rdata->msg_info.msg); |
| 511 |
|
| 512 |
return 0; |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
static void incoming_response(struct ast_sip_session *session, pjsip_rx_data * rdata) |
| 524 |
{ |
| 525 |
pj_pool_t *pool = session->inv_session->dlg->pool; |
| 526 |
RAII_VAR(struct ast_datastore *, datastore, |
| 527 |
ast_sip_session_get_datastore(session, response_header_datastore.type), ao2_cleanup); |
| 528 |
pjsip_status_line status = rdata->msg_info.msg->line.status; |
| 529 |
|
| 530 |
|
| 531 |
if (session->inv_session->state != PJSIP_INV_STATE_CONNECTING || status.code!=200) { |
| 532 |
return; |
| 533 |
} |
| 534 |
|
| 535 |
if (!datastore) { |
| 536 |
if (!(datastore = |
| 537 |
ast_sip_session_alloc_datastore(&response_header_datastore, response_header_datastore.type)) |
| 538 |
|| |
| 539 |
!(datastore->data = pj_pool_alloc(pool, sizeof(struct hdr_list))) || |
| 540 |
ast_sip_session_add_datastore(session, datastore)) { |
| 541 |
ast_log(AST_LOG_ERROR, "Unable to create datastore for header functions.\n"); |
| 542 |
return; |
| 543 |
} |
| 544 |
AST_LIST_HEAD_INIT_NOLOCK((struct hdr_list *) datastore->data); |
| 545 |
} |
| 546 |
insert_headers(pool, (struct hdr_list *) datastore->data, rdata->msg_info.msg); |
| 547 |
|
| 548 |
return; |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
static pjsip_hdr *find_header(struct hdr_list *list, const char *header_name, |
| 556 |
int header_number) |
| 557 |
{ |
| 558 |
struct hdr_list_entry *le; |
| 559 |
pjsip_hdr *hdr = NULL; |
| 560 |
int i = 1; |
| 561 |
|
| 562 |
if (!list || ast_strlen_zero(header_name) || header_number < 1) { |
| 563 |
return NULL; |
| 564 |
} |
| 565 |
|
| 566 |
AST_LIST_TRAVERSE(list, le, nextptr) { |
| 567 |
if (pj_stricmp2(&le->hdr->name, header_name) == 0 && i++ == header_number) { |
| 568 |
hdr = le->hdr; |
| 569 |
break; |
| 570 |
} |
| 571 |
} |
| 572 |
|
| 573 |
return hdr; |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
static int read_headers(void *obj) |
| 587 |
{ |
| 588 |
struct header_data *data = obj; |
| 589 |
size_t len = !ast_strlen_zero(data->header_name) ? strlen(data->header_name) : 0; |
| 590 |
pjsip_hdr *hdr = NULL; |
| 591 |
char *pj_hdr_string; |
| 592 |
int pj_hdr_string_len; |
| 593 |
char *p; |
| 594 |
char *pos; |
| 595 |
size_t plen, wlen = 0; |
| 596 |
struct hdr_list_entry *le; |
| 597 |
struct hdr_list *list; |
| 598 |
|
| 599 |
RAII_VAR(struct ast_datastore *, datastore, |
| 600 |
ast_sip_session_get_datastore(data->channel->session, data->header_datastore->type), |
| 601 |
ao2_cleanup); |
| 602 |
|
| 603 |
if (!datastore || !datastore->data) { |
| 604 |
ast_debug(1, "There was no datastore from which to read headers.\n"); |
| 605 |
return -1; |
| 606 |
} |
| 607 |
|
| 608 |
list = datastore->data; |
| 609 |
pj_hdr_string = ast_alloca(data->len); |
| 610 |
AST_LIST_TRAVERSE(list, le, nextptr) { |
| 611 |
if (!len || pj_strnicmp2(&le->hdr->name, data->header_name, len) == 0) { |
| 612 |
|
| 613 |
hdr = le->hdr; |
| 614 |
|
| 615 |
pj_hdr_string_len = pjsip_hdr_print_on(hdr, pj_hdr_string, data->len - 1); |
| 616 |
if (pj_hdr_string_len == -1) { |
| 617 |
ast_log(AST_LOG_ERROR, |
| 618 |
"Not enough buffer space in pjsip_hdr_print_on\n"); |
| 619 |
return -1; |
| 620 |
} |
| 621 |
pj_hdr_string[pj_hdr_string_len] = '\0'; |
| 622 |
p = strchr(pj_hdr_string, ':'); |
| 623 |
if (!p) { |
| 624 |
ast_log(AST_LOG_WARNING, |
| 625 |
"A malformed header was returned from pjsip_hdr_print_on\n"); |
| 626 |
continue; |
| 627 |
} |
| 628 |
|
| 629 |
pj_hdr_string[p - pj_hdr_string] = '\0'; |
| 630 |
p = ast_strip(pj_hdr_string); |
| 631 |
plen = strlen(p); |
| 632 |
if (wlen + plen + 1 > data->len) { |
| 633 |
ast_log(AST_LOG_ERROR, |
| 634 |
"Buffer isn't big enough to hold header value. %zu > %zu\n", plen + 1, |
| 635 |
data->len); |
| 636 |
return -1; |
| 637 |
} |
| 638 |
pos = strstr(data->buf, p); |
| 639 |
if (pos && pos[1] == ',') { |
| 640 |
if (pos == data->buf) { |
| 641 |
continue; |
| 642 |
} else if (pos[-1] == ',') { |
| 643 |
continue; |
| 644 |
} |
| 645 |
} |
| 646 |
ast_copy_string(data->buf + wlen, p, data->len - wlen); |
| 647 |
wlen += plen; |
| 648 |
ast_copy_string(data->buf + wlen, ",", data->len - wlen); |
| 649 |
wlen++; |
| 650 |
} |
| 651 |
} |
| 652 |
|
| 653 |
if (wlen == 0) { |
| 654 |
if (!len) { |
| 655 |
|
| 656 |
return 0; |
| 657 |
} else { |
| 658 |
ast_debug(1, "There was no header beginning with %s.\n", data->header_name); |
| 659 |
return -1; |
| 660 |
} |
| 661 |
} else { |
| 662 |
data->buf[wlen-1] = '\0'; |
| 663 |
} |
| 664 |
return 0; |
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
static int read_header(void *obj) |
| 678 |
{ |
| 679 |
struct header_data *data = obj; |
| 680 |
size_t len = strlen(data->header_name); |
| 681 |
pjsip_hdr *hdr = NULL; |
| 682 |
char *pj_hdr_string; |
| 683 |
int pj_hdr_string_len; |
| 684 |
char *p; |
| 685 |
size_t plen; |
| 686 |
struct hdr_list_entry *le; |
| 687 |
struct hdr_list *list; |
| 688 |
int i = 1; |
| 689 |
RAII_VAR(struct ast_datastore *, datastore, |
| 690 |
ast_sip_session_get_datastore(data->channel->session, data->header_datastore->type), |
| 691 |
ao2_cleanup); |
| 692 |
|
| 693 |
if (!datastore || !datastore->data) { |
| 694 |
ast_debug(1, "There was no datastore from which to read headers.\n"); |
| 695 |
return -1; |
| 696 |
} |
| 697 |
|
| 698 |
list = datastore->data; |
| 699 |
AST_LIST_TRAVERSE(list, le, nextptr) { |
| 700 |
if (len >= 1 && data->header_name[len - 1] == '*') { |
| 701 |
if (pj_strnicmp2(&le->hdr->name, data->header_name, len - 1) == 0 && i++ == data->header_number) { |
| 702 |
hdr = le->hdr; |
| 703 |
break; |
| 704 |
} |
| 705 |
} else { |
| 706 |
if (pj_stricmp2(&le->hdr->name, data->header_name) == 0 && i++ == data->header_number) { |
| 707 |
hdr = le->hdr; |
| 708 |
break; |
| 709 |
} |
| 710 |
} |
| 711 |
} |
| 712 |
|
| 713 |
if (!hdr) { |
| 714 |
ast_debug(1, "There was no header named %s.\n", data->header_name); |
| 715 |
return -1; |
| 716 |
} |
| 717 |
|
| 718 |
pj_hdr_string = ast_alloca(data->len); |
| 719 |
pj_hdr_string_len = pjsip_hdr_print_on(hdr, pj_hdr_string, data->len - 1); |
| 720 |
if (pj_hdr_string_len == -1) { |
| 721 |
ast_log(AST_LOG_ERROR, |
| 722 |
"Not enough buffer space in pjsip_hdr_print_on\n"); |
| 723 |
return -1; |
| 724 |
} |
| 725 |
|
| 726 |
pj_hdr_string[pj_hdr_string_len] = '\0'; |
| 727 |
|
| 728 |
p = strchr(pj_hdr_string, ':'); |
| 729 |
if (!p) { |
| 730 |
ast_log(AST_LOG_ERROR, |
| 731 |
"A malformed header was returned from pjsip_hdr_print_on.\n"); |
| 732 |
return -1; |
| 733 |
} |
| 734 |
|
| 735 |
++p; |
| 736 |
p = ast_strip(p); |
| 737 |
plen = strlen(p); |
| 738 |
if (plen + 1 > data->len) { |
| 739 |
ast_log(AST_LOG_ERROR, |
| 740 |
"Buffer isn't big enough to hold header value. %zu > %zu\n", plen + 1, |
| 741 |
data->len); |
| 742 |
return -1; |
| 743 |
} |
| 744 |
|
| 745 |
ast_copy_string(data->buf, p, data->len); |
| 746 |
|
| 747 |
return 0; |
| 748 |
} |
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
static int add_header(void *obj) |
| 761 |
{ |
| 762 |
struct header_data *data = obj; |
| 763 |
struct ast_sip_session *session = data->channel->session; |
| 764 |
pj_pool_t *pool = session->inv_session->dlg->pool; |
| 765 |
pj_str_t pj_header_name; |
| 766 |
pj_str_t pj_header_value; |
| 767 |
struct hdr_list_entry *le; |
| 768 |
struct hdr_list *list; |
| 769 |
|
| 770 |
RAII_VAR(struct ast_datastore *, datastore, |
| 771 |
ast_sip_session_get_datastore(session, session_header_datastore.type), ao2_cleanup); |
| 772 |
|
| 773 |
if (!datastore) { |
| 774 |
if (!(datastore = ast_sip_session_alloc_datastore(&session_header_datastore, |
| 775 |
session_header_datastore.type)) |
| 776 |
|| !(datastore->data = pj_pool_alloc(pool, sizeof(struct hdr_list))) |
| 777 |
|| ast_sip_session_add_datastore(session, datastore)) { |
| 778 |
ast_log(AST_LOG_ERROR, "Unable to create datastore for header functions.\n"); |
| 779 |
return -1; |
| 780 |
} |
| 781 |
AST_LIST_HEAD_INIT_NOLOCK((struct hdr_list *) datastore->data); |
| 782 |
} |
| 783 |
|
| 784 |
ast_debug(1, "Adding header %s with value %s\n", data->header_name, |
| 785 |
data->header_value); |
| 786 |
|
| 787 |
pj_cstr(&pj_header_name, data->header_name); |
| 788 |
pj_cstr(&pj_header_value, data->header_value); |
| 789 |
le = pj_pool_zalloc(pool, sizeof(struct hdr_list_entry)); |
| 790 |
le->hdr = (pjsip_hdr *) pjsip_generic_string_hdr_create(pool, &pj_header_name, |
| 791 |
&pj_header_value); |
| 792 |
list = datastore->data; |
| 793 |
|
| 794 |
AST_LIST_INSERT_TAIL(list, le, nextptr); |
| 795 |
|
| 796 |
return 0; |
| 797 |
} |
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
static int add_inheritable_header(struct ast_channel *channel, const char *header_name, const char *header_value) |
| 812 |
{ |
| 813 |
struct ast_variable *headers = NULL; |
| 814 |
|
| 815 |
|
| 816 |
struct ast_datastore *chan_datastore; |
| 817 |
struct ast_variable *new_var; |
| 818 |
|
| 819 |
ast_channel_lock(channel); |
| 820 |
chan_datastore = ast_channel_datastore_find(channel, &inheritable_header_datastore, NULL); |
| 821 |
ast_debug(3, "Adding inheritable header %s with value %s to channel %s\n", header_name, |
| 822 |
header_value, ast_channel_name(channel)); |
| 823 |
|
| 824 |
if (!chan_datastore) { |
| 825 |
|
| 826 |
chan_datastore = ast_datastore_alloc(&inheritable_header_datastore, |
| 827 |
inheritable_header_datastore.type); |
| 828 |
if (chan_datastore) { |
| 829 |
chan_datastore->data = NULL; |
| 830 |
chan_datastore->inheritance = DATASTORE_INHERIT_FOREVER; |
| 831 |
ast_channel_datastore_add(channel, chan_datastore); |
| 832 |
ast_debug(3, "Created new inheritable SIP header channel datastore for channel %s\n", |
| 833 |
ast_channel_name(channel)); |
| 834 |
} else { |
| 835 |
ast_log(LOG_ERROR, "Failed to allocate channel datastore for channel %s to store inheritable SIP headers\n", |
| 836 |
ast_channel_name(channel)); |
| 837 |
ast_channel_unlock(channel); |
| 838 |
return -1; |
| 839 |
} |
| 840 |
} else { |
| 841 |
|
| 842 |
if (!chan_datastore->inheritance) { |
| 843 |
chan_datastore->inheritance = DATASTORE_INHERIT_FOREVER; |
| 844 |
ast_debug(3, "Upgraded SIP header channel datastore to inheritable for channel %s\n", |
| 845 |
ast_channel_name(channel)); |
| 846 |
} |
| 847 |
} |
| 848 |
|
| 849 |
|
| 850 |
headers = chan_datastore->data; |
| 851 |
new_var = ast_variable_new(header_name, header_value, ""); |
| 852 |
if (!new_var) { |
| 853 |
ast_log(LOG_ERROR, "Failed to allocate variable for channel %s to store inheritable SIP headers\n", |
| 854 |
ast_channel_name(channel)); |
| 855 |
ast_channel_unlock(channel); |
| 856 |
return -1; |
| 857 |
} |
| 858 |
|
| 859 |
|
| 860 |
new_var->next = headers; |
| 861 |
chan_datastore->data = new_var; |
| 862 |
|
| 863 |
ast_debug(1, "Inherited Header %s added with value %s for channel %s\n", |
| 864 |
header_name, header_value, ast_channel_name(channel)); |
| 865 |
|
| 866 |
ast_channel_unlock(channel); |
| 867 |
|
| 868 |
return 0; |
| 869 |
} |
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
static int update_header(void *obj) |
| 882 |
{ |
| 883 |
struct header_data *data = obj; |
| 884 |
pj_pool_t *pool = data->channel->session->inv_session->dlg->pool; |
| 885 |
pjsip_hdr *hdr = NULL; |
| 886 |
RAII_VAR(struct ast_datastore *, datastore, |
| 887 |
ast_sip_session_get_datastore(data->channel->session, session_header_datastore.type), |
| 888 |
ao2_cleanup); |
| 889 |
|
| 890 |
ast_debug(3, "Attempting to update header %s for channel %p\n", data->header_name, |
| 891 |
data->channel->session->channel ? ast_channel_name(data->channel->session->channel) : "(none)"); |
| 892 |
|
| 893 |
if (!datastore || !datastore->data) { |
| 894 |
ast_log(AST_LOG_ERROR, "No headers had been previously added to this session.\n"); |
| 895 |
return -1; |
| 896 |
} |
| 897 |
|
| 898 |
hdr = find_header((struct hdr_list *) datastore->data, data->header_name, |
| 899 |
data->header_number); |
| 900 |
|
| 901 |
if (!hdr) { |
| 902 |
ast_log(AST_LOG_ERROR, "There was no header named %s.\n", data->header_name); |
| 903 |
return -1; |
| 904 |
} |
| 905 |
|
| 906 |
ast_debug(3, "Found header %s in session datastore, updating value to %s for channel %p\n", |
| 907 |
data->header_name, data->header_value, |
| 908 |
data->channel->session->channel ? ast_channel_name(data->channel->session->channel) : "(none)"); |
| 909 |
pj_strdup2(pool, &((pjsip_generic_string_hdr *) hdr)->hvalue, data->header_value); |
| 910 |
|
| 911 |
return 0; |
| 912 |
} |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
static int update_inheritable_header(struct ast_channel *channel, const char *header_name, const char *header_value, int header_number) |
| 926 |
{ |
| 927 |
struct ast_datastore *inherited_datastore; |
| 928 |
struct ast_variable *headers = NULL; |
| 929 |
struct ast_variable *var, *prev = NULL; |
| 930 |
int i = 1, num_matching_headers = 0, target_header_index; |
| 931 |
|
| 932 |
ast_channel_lock(channel); |
| 933 |
inherited_datastore = ast_channel_datastore_find(channel, &inheritable_header_datastore, NULL); |
| 934 |
ast_debug(3, "Attempting to update header %s for channel %s\n", header_name, |
| 935 |
ast_channel_name(channel)); |
| 936 |
|
| 937 |
if (!inherited_datastore || !inherited_datastore->data) { |
| 938 |
ast_log(AST_LOG_ERROR, "No inheritable headers had been previously added to this channel.\n"); |
| 939 |
ast_channel_unlock(channel); |
| 940 |
return -1; |
| 941 |
} |
| 942 |
|
| 943 |
headers = inherited_datastore->data; |
| 944 |
|
| 945 |
|
| 946 |
for (var = headers; var; var = var->next) { |
| 947 |
if (strcasecmp(var->name, header_name) == 0) { |
| 948 |
num_matching_headers++; |
| 949 |
} |
| 950 |
} |
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
if (num_matching_headers == 0) { |
| 955 |
ast_log(AST_LOG_ERROR, "There was no header named %s on channel %s.\n", header_name, |
| 956 |
ast_channel_name(channel)); |
| 957 |
ast_channel_unlock(channel); |
| 958 |
return -1; |
| 959 |
} else if (num_matching_headers < header_number) { |
| 960 |
ast_log(AST_LOG_ERROR, "There were only %d headers named %s on channel %s, cannot update header number %d.\n", |
| 961 |
num_matching_headers, header_name, ast_channel_name(channel), header_number); |
| 962 |
ast_channel_unlock(channel); |
| 963 |
return -1; |
| 964 |
} |
| 965 |
|
| 966 |
target_header_index = num_matching_headers - header_number + 1; |
| 967 |
|
| 968 |
for (var = headers; var; var = var->next) { |
| 969 |
if (strcasecmp(var->name, header_name) == 0 && i++ == target_header_index) { |
| 970 |
|
| 971 |
struct ast_variable *new_var = ast_variable_new(header_name, header_value, ""); |
| 972 |
if (!new_var) { |
| 973 |
ast_log(AST_LOG_ERROR, "Failed to allocate variable for updated header for channel %s\n", |
| 974 |
ast_channel_name(channel)); |
| 975 |
ast_channel_unlock(channel); |
| 976 |
return -1; |
| 977 |
} |
| 978 |
|
| 979 |
new_var->next = var->next; |
| 980 |
|
| 981 |
if (var == headers) { |
| 982 |
|
| 983 |
inherited_datastore->data = new_var; |
| 984 |
} else if (prev) { |
| 985 |
|
| 986 |
prev->next = new_var; |
| 987 |
} |
| 988 |
|
| 989 |
var->next = NULL; |
| 990 |
inheritable_headers_destroy(var); |
| 991 |
|
| 992 |
ast_debug(3, "Updated header %s with new value %s for channel %s\n", |
| 993 |
header_name, header_value, ast_channel_name(channel)); |
| 994 |
ast_channel_unlock(channel); |
| 995 |
return 0; |
| 996 |
} |
| 997 |
prev = var; |
| 998 |
} |
| 999 |
|
| 1000 |
|
| 1001 |
ast_log(AST_LOG_ERROR, "Unable to update header %s on channel %s.\n", header_name, |
| 1002 |
ast_channel_name(channel)); |
| 1003 |
ast_channel_unlock(channel); |
| 1004 |
return -1; |
| 1005 |
} |
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
static int remove_header(void *obj) |
| 1016 |
{ |
| 1017 |
struct header_data *data = obj; |
| 1018 |
size_t len = strlen(data->header_name); |
| 1019 |
struct hdr_list *list; |
| 1020 |
struct hdr_list_entry *le; |
| 1021 |
int removed_count = 0; |
| 1022 |
RAII_VAR(struct ast_datastore *, datastore, |
| 1023 |
ast_sip_session_get_datastore(data->channel->session, session_header_datastore.type), |
| 1024 |
ao2_cleanup); |
| 1025 |
|
| 1026 |
ast_debug(3, "Attempting to remove header %s from channel %p\n", data->header_name, |
| 1027 |
data->channel->session->channel ? ast_channel_name(data->channel->session->channel) : "(none)"); |
| 1028 |
|
| 1029 |
if (!datastore || !datastore->data) { |
| 1030 |
ast_log(AST_LOG_ERROR, "No headers had been previously added to this session.\n"); |
| 1031 |
return -1; |
| 1032 |
} |
| 1033 |
|
| 1034 |
list = datastore->data; |
| 1035 |
AST_LIST_TRAVERSE_SAFE_BEGIN(list, le, nextptr) { |
| 1036 |
if (len >= 1 && data->header_name[len - 1] == '*') { |
| 1037 |
if (pj_strnicmp2(&le->hdr->name, data->header_name, len - 1) == 0) { |
| 1038 |
ast_debug(3, "Found wildcard match, removing header %.*s from channel %p\n", |
| 1039 |
(int)le->hdr->name.slen, le->hdr->name.ptr, |
| 1040 |
data->channel->session->channel ? ast_channel_name(data->channel->session->channel) : "(none)"); |
| 1041 |
AST_LIST_REMOVE_CURRENT(nextptr); |
| 1042 |
removed_count++; |
| 1043 |
} |
| 1044 |
} else { |
| 1045 |
if (pj_stricmp2(&le->hdr->name, data->header_name) == 0) { |
| 1046 |
ast_debug(3, "Found exact match, removing header %.*s from channel %p\n", |
| 1047 |
(int)le->hdr->name.slen, le->hdr->name.ptr, |
| 1048 |
data->channel->session->channel ? ast_channel_name(data->channel->session->channel) : "(none)"); |
| 1049 |
AST_LIST_REMOVE_CURRENT(nextptr); |
| 1050 |
removed_count++; |
| 1051 |
} |
| 1052 |
} |
| 1053 |
} |
| 1054 |
AST_LIST_TRAVERSE_SAFE_END; |
| 1055 |
|
| 1056 |
if (removed_count == 0) { |
| 1057 |
ast_debug(3, "No headers named %s found to remove on channel %s.\n", data->header_name, |
| 1058 |
data->channel->session->channel ? ast_channel_name(data->channel->session->channel) : "(none)"); |
| 1059 |
} |
| 1060 |
|
| 1061 |
if (data->buf && data->len) { |
| 1062 |
snprintf(data->buf, data->len, "%d", removed_count); |
| 1063 |
ast_debug(3, "Removed %d headers matching %s from channel %s\n", removed_count, data->header_name, |
| 1064 |
data->channel->session->channel ? ast_channel_name(data->channel->session->channel) : "(none)"); |
| 1065 |
} |
| 1066 |
|
| 1067 |
return 0; |
| 1068 |
} |
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
static int remove_inheritable_header(struct ast_channel *channel, const char *header_name) |
| 1080 |
{ |
| 1081 |
size_t len = strlen(header_name); |
| 1082 |
struct ast_variable *headers = NULL; |
| 1083 |
struct ast_variable *var, *prev = NULL; |
| 1084 |
int removed_count = 0; |
| 1085 |
struct ast_datastore *inherited_datastore; |
| 1086 |
|
| 1087 |
ast_channel_lock(channel); |
| 1088 |
inherited_datastore = ast_channel_datastore_find(channel, &inheritable_header_datastore, NULL); |
| 1089 |
ast_debug(3, "Attempting to remove header %s from channel %s\n", |
| 1090 |
header_name, ast_channel_name(channel)); |
| 1091 |
|
| 1092 |
|
| 1093 |
if (!inherited_datastore || !inherited_datastore->data) { |
| 1094 |
ast_log(AST_LOG_ERROR, "No inheritable headers had been previously added to channel %s.\n", |
| 1095 |
ast_channel_name(channel)); |
| 1096 |
ast_channel_unlock(channel); |
| 1097 |
return -1; |
| 1098 |
} |
| 1099 |
|
| 1100 |
headers = inherited_datastore->data; |
| 1101 |
|
| 1102 |
|
| 1103 |
if (strcmp(header_name, "*") == 0) { |
| 1104 |
inheritable_headers_destroy(headers); |
| 1105 |
inherited_datastore->data = NULL; |
| 1106 |
ast_debug(3, "Removed all inheritable headers from channel %s\n", |
| 1107 |
ast_channel_name(channel)); |
| 1108 |
ast_channel_unlock(channel); |
| 1109 |
return 0; |
| 1110 |
} |
| 1111 |
|
| 1112 |
|
| 1113 |
var = headers; |
| 1114 |
while (var) { |
| 1115 |
struct ast_variable *next = var->next; |
| 1116 |
int match = 0; |
| 1117 |
|
| 1118 |
if (len >= 1 && header_name[len - 1] == '*') { |
| 1119 |
|
| 1120 |
match = (strncasecmp(var->name, header_name, len - 1) == 0); |
| 1121 |
if (match) { |
| 1122 |
ast_debug(3, "Found wildcard match, removing header %s with value %s from channel %s\n", |
| 1123 |
var->name, var->value, ast_channel_name(channel)); |
| 1124 |
} |
| 1125 |
} else { |
| 1126 |
|
| 1127 |
match = (strcasecmp(var->name, header_name) == 0); |
| 1128 |
if (match) { |
| 1129 |
ast_debug(3, "Found exact match, removing header %s with value %s from channel %s\n", |
| 1130 |
var->name, var->value, ast_channel_name(channel)); |
| 1131 |
} |
| 1132 |
} |
| 1133 |
|
| 1134 |
if (match) { |
| 1135 |
|
| 1136 |
if (var == headers) { |
| 1137 |
|
| 1138 |
headers = next; |
| 1139 |
inherited_datastore->data = headers; |
| 1140 |
} else if (prev) { |
| 1141 |
|
| 1142 |
prev->next = next; |
| 1143 |
} |
| 1144 |
|
| 1145 |
|
| 1146 |
var->next = NULL; |
| 1147 |
ast_variables_destroy(var); |
| 1148 |
removed_count++; |
| 1149 |
var = next; |
| 1150 |
} else { |
| 1151 |
prev = var; |
| 1152 |
var = next; |
| 1153 |
} |
| 1154 |
} |
| 1155 |
|
| 1156 |
|
| 1157 |
inherited_datastore->data = headers; |
| 1158 |
|
| 1159 |
if (removed_count == 0) { |
| 1160 |
ast_debug(3, "No headers matching %s found for channel %s\n", |
| 1161 |
header_name, ast_channel_name(channel)); |
| 1162 |
} |
| 1163 |
|
| 1164 |
ast_debug(3, "Removed %d headers matching %s from channel %s\n", removed_count, header_name, |
| 1165 |
ast_channel_name(channel)); |
| 1166 |
|
| 1167 |
ast_channel_unlock(channel); |
| 1168 |
return 0; |
| 1169 |
} |
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
static int func_read_headers(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len) |
| 1175 |
{ |
| 1176 |
struct ast_sip_channel_pvt *channel = chan ? ast_channel_tech_pvt(chan) : NULL; |
| 1177 |
struct header_data header_data; |
| 1178 |
AST_DECLARE_APP_ARGS(args, |
| 1179 |
AST_APP_ARG(header_pattern); |
| 1180 |
); |
| 1181 |
AST_STANDARD_APP_ARGS(args, data); |
| 1182 |
|
| 1183 |
if (!chan || strncmp(ast_channel_name(chan), "PJSIP/", 6)) { |
| 1184 |
ast_log(LOG_ERROR, "This function requires a PJSIP channel.\n"); |
| 1185 |
return -1; |
| 1186 |
} |
| 1187 |
|
| 1188 |
header_data.channel = channel; |
| 1189 |
header_data.header_name = args.header_pattern; |
| 1190 |
header_data.header_value = NULL; |
| 1191 |
header_data.buf = buf; |
| 1192 |
header_data.len = len; |
| 1193 |
header_data.header_datastore = &session_header_datastore; |
| 1194 |
|
| 1195 |
return ast_sip_push_task_wait_serializer(channel->session->serializer, read_headers, &header_data); |
| 1196 |
|
| 1197 |
} |
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
static int func_response_read_headers(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len) |
| 1203 |
{ |
| 1204 |
struct ast_sip_channel_pvt *channel = chan ? ast_channel_tech_pvt(chan) : NULL; |
| 1205 |
struct header_data header_data; |
| 1206 |
AST_DECLARE_APP_ARGS(args, |
| 1207 |
AST_APP_ARG(header_pattern); |
| 1208 |
); |
| 1209 |
AST_STANDARD_APP_ARGS(args, data); |
| 1210 |
|
| 1211 |
if (!chan || strncmp(ast_channel_name(chan), "PJSIP/", 6)) { |
| 1212 |
ast_log(LOG_ERROR, "This function requires a PJSIP channel.\n"); |
| 1213 |
return -1; |
| 1214 |
} |
| 1215 |
|
| 1216 |
if (ast_strlen_zero(args.header_pattern)) { |
| 1217 |
ast_log(AST_LOG_ERROR, "This function requires a pattern.\n"); |
| 1218 |
return -1; |
| 1219 |
} |
| 1220 |
|
| 1221 |
header_data.channel = channel; |
| 1222 |
header_data.header_name = args.header_pattern; |
| 1223 |
header_data.header_value = NULL; |
| 1224 |
header_data.buf = buf; |
| 1225 |
header_data.len = len; |
| 1226 |
header_data.header_datastore = &response_header_datastore; |
| 1227 |
|
| 1228 |
return ast_sip_push_task_wait_serializer(channel->session->serializer, read_headers, &header_data); |
| 1229 |
|
| 1230 |
} |
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
static int func_read_header(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len) |
| 1238 |
{ |
| 1239 |
struct ast_sip_channel_pvt *channel = chan ? ast_channel_tech_pvt(chan) : NULL; |
| 1240 |
struct header_data header_data; |
| 1241 |
int number; |
| 1242 |
AST_DECLARE_APP_ARGS(args, |
| 1243 |
AST_APP_ARG(action); |
| 1244 |
AST_APP_ARG(header_name); AST_APP_ARG(header_number);); |
| 1245 |
AST_STANDARD_APP_ARGS(args, data); |
| 1246 |
|
| 1247 |
if (!channel || strncmp(ast_channel_name(chan), "PJSIP/", 6)) { |
| 1248 |
ast_log(LOG_ERROR, "This function requires a PJSIP channel.\n"); |
| 1249 |
return -1; |
| 1250 |
} |
| 1251 |
|
| 1252 |
if (ast_strlen_zero(args.action)) { |
| 1253 |
ast_log(AST_LOG_ERROR, "This function requires an action.\n"); |
| 1254 |
return -1; |
| 1255 |
} |
| 1256 |
if (ast_strlen_zero(args.header_name)) { |
| 1257 |
ast_log(AST_LOG_ERROR, "This function requires a header name.\n"); |
| 1258 |
return -1; |
| 1259 |
} |
| 1260 |
if (!args.header_number) { |
| 1261 |
number = 1; |
| 1262 |
} else { |
| 1263 |
sscanf(args.header_number, "%30d", &number); |
| 1264 |
if (number < 1) { |
| 1265 |
number = 1; |
| 1266 |
} |
| 1267 |
} |
| 1268 |
|
| 1269 |
header_data.channel = channel; |
| 1270 |
header_data.header_name = args.header_name; |
| 1271 |
header_data.header_number = number; |
| 1272 |
header_data.header_value = NULL; |
| 1273 |
header_data.buf = buf; |
| 1274 |
header_data.len = len; |
| 1275 |
header_data.header_datastore = &session_header_datastore; |
| 1276 |
|
| 1277 |
if (!strcasecmp(args.action, "read")) { |
| 1278 |
return ast_sip_push_task_wait_serializer(channel->session->serializer, read_header, &header_data); |
| 1279 |
} else if (!strcasecmp(args.action, "remove")) { |
| 1280 |
return ast_sip_push_task_wait_serializer(channel->session->serializer, |
| 1281 |
remove_header, &header_data); |
| 1282 |
} else { |
| 1283 |
ast_log(AST_LOG_ERROR, |
| 1284 |
"Unknown action '%s' is not valid, must be 'read' or 'remove'.\n", |
| 1285 |
args.action); |
| 1286 |
return -1; |
| 1287 |
} |
| 1288 |
} |
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
static int func_response_read_header(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len) |
| 1296 |
{ |
| 1297 |
struct ast_sip_channel_pvt *channel = chan ? ast_channel_tech_pvt(chan) : NULL; |
| 1298 |
struct header_data header_data; |
| 1299 |
int number; |
| 1300 |
AST_DECLARE_APP_ARGS(args, |
| 1301 |
AST_APP_ARG(action); |
| 1302 |
AST_APP_ARG(header_name); AST_APP_ARG(header_number);); |
| 1303 |
AST_STANDARD_APP_ARGS(args, data); |
| 1304 |
|
| 1305 |
if (!channel || strncmp(ast_channel_name(chan), "PJSIP/", 6)) { |
| 1306 |
ast_log(LOG_ERROR, "This function requires a PJSIP channel.\n"); |
| 1307 |
return -1; |
| 1308 |
} |
| 1309 |
|
| 1310 |
if (ast_strlen_zero(args.action)) { |
| 1311 |
ast_log(AST_LOG_ERROR, "This function requires an action.\n"); |
| 1312 |
return -1; |
| 1313 |
} |
| 1314 |
if (ast_strlen_zero(args.header_name)) { |
| 1315 |
ast_log(AST_LOG_ERROR, "This function requires a header name.\n"); |
| 1316 |
return -1; |
| 1317 |
} |
| 1318 |
if (!args.header_number) { |
| 1319 |
number = 1; |
| 1320 |
} else { |
| 1321 |
sscanf(args.header_number, "%30d", &number); |
| 1322 |
if (number < 1) { |
| 1323 |
number = 1; |
| 1324 |
} |
| 1325 |
} |
| 1326 |
|
| 1327 |
header_data.channel = channel; |
| 1328 |
header_data.header_name = args.header_name; |
| 1329 |
header_data.header_number = number; |
| 1330 |
header_data.header_value = NULL; |
| 1331 |
header_data.buf = buf; |
| 1332 |
header_data.len = len; |
| 1333 |
header_data.header_datastore = &response_header_datastore; |
| 1334 |
|
| 1335 |
if (!strcasecmp(args.action, "read")) { |
| 1336 |
return ast_sip_push_task_wait_serializer(channel->session->serializer, read_header, &header_data); |
| 1337 |
} else { |
| 1338 |
ast_log(AST_LOG_ERROR, |
| 1339 |
"Unknown action '%s' is not valid, must be 'read'.\n", |
| 1340 |
args.action); |
| 1341 |
return -1; |
| 1342 |
} |
| 1343 |
} |
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
static int func_write_header(struct ast_channel *chan, const char *cmd, char *data, |
| 1351 |
const char *value) |
| 1352 |
{ |
| 1353 |
struct ast_sip_channel_pvt *channel = chan ? ast_channel_tech_pvt(chan) : NULL; |
| 1354 |
struct header_data header_data; |
| 1355 |
int header_number; |
| 1356 |
AST_DECLARE_APP_ARGS(args, |
| 1357 |
AST_APP_ARG(action); |
| 1358 |
AST_APP_ARG(header_name); |
| 1359 |
AST_APP_ARG(header_number);); |
| 1360 |
AST_STANDARD_APP_ARGS(args, data); |
| 1361 |
|
| 1362 |
if (!channel || strncmp(ast_channel_name(chan), "PJSIP/", 6)) { |
| 1363 |
ast_log(LOG_ERROR, "This function requires a PJSIP channel.\n"); |
| 1364 |
return -1; |
| 1365 |
} |
| 1366 |
|
| 1367 |
if (ast_strlen_zero(args.action)) { |
| 1368 |
ast_log(AST_LOG_ERROR, "This function requires an action.\n"); |
| 1369 |
return -1; |
| 1370 |
} |
| 1371 |
if (ast_strlen_zero(args.header_name)) { |
| 1372 |
ast_log(AST_LOG_ERROR, "This function requires a header name.\n"); |
| 1373 |
return -1; |
| 1374 |
} |
| 1375 |
if (!args.header_number) { |
| 1376 |
header_number = 1; |
| 1377 |
} else { |
| 1378 |
sscanf(args.header_number, "%30d", &header_number); |
| 1379 |
if (header_number < 1) { |
| 1380 |
header_number = 1; |
| 1381 |
} |
| 1382 |
} |
| 1383 |
|
| 1384 |
header_data.channel = channel; |
| 1385 |
header_data.header_name = args.header_name; |
| 1386 |
header_data.header_number = header_number; |
| 1387 |
header_data.header_value = value; |
| 1388 |
header_data.buf = NULL; |
| 1389 |
header_data.len = 0; |
| 1390 |
header_data.header_datastore = &session_header_datastore; |
| 1391 |
|
| 1392 |
if (!strcasecmp(args.action, "add")) { |
| 1393 |
return ast_sip_push_task_wait_serializer(channel->session->serializer, |
| 1394 |
add_header, &header_data); |
| 1395 |
} else if (!strcasecmp(args.action, "update")) { |
| 1396 |
return ast_sip_push_task_wait_serializer(channel->session->serializer, |
| 1397 |
update_header, &header_data); |
| 1398 |
} else if (!strcasecmp(args.action, "remove")) { |
| 1399 |
return ast_sip_push_task_wait_serializer(channel->session->serializer, |
| 1400 |
remove_header, &header_data); |
| 1401 |
} else { |
| 1402 |
ast_log(AST_LOG_ERROR, |
| 1403 |
"Unknown action '%s' is not valid, must be 'add', 'update', or 'remove'.\n", |
| 1404 |
args.action); |
| 1405 |
return -1; |
| 1406 |
} |
| 1407 |
} |
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
static int func_write_inheritable_header(struct ast_channel *chan, const char *cmd, char *data, |
| 1415 |
const char *value) |
| 1416 |
{ |
| 1417 |
int header_number; |
| 1418 |
AST_DECLARE_APP_ARGS(args, |
| 1419 |
AST_APP_ARG(action); |
| 1420 |
AST_APP_ARG(header_name); |
| 1421 |
AST_APP_ARG(header_number);); |
| 1422 |
AST_STANDARD_APP_ARGS(args, data); |
| 1423 |
|
| 1424 |
if (!chan) { |
| 1425 |
ast_log(LOG_ERROR, "The PJSIP_INHERITABLE_HEADER function requires a channel.\n"); |
| 1426 |
return -1; |
| 1427 |
} |
| 1428 |
if (ast_strlen_zero(args.action)) { |
| 1429 |
ast_log(AST_LOG_ERROR, "The PJSIP_INHERITABLE_HEADER function requires an action.\n"); |
| 1430 |
return -1; |
| 1431 |
} |
| 1432 |
if (ast_strlen_zero(args.header_name)) { |
| 1433 |
ast_log(AST_LOG_ERROR, "The PJSIP_INHERITABLE_HEADER function requires a header name.\n"); |
| 1434 |
return -1; |
| 1435 |
} |
| 1436 |
if (!args.header_number) { |
| 1437 |
header_number = 1; |
| 1438 |
} else { |
| 1439 |
sscanf(args.header_number, "%30d", &header_number); |
| 1440 |
if (header_number < 1) { |
| 1441 |
header_number = 1; |
| 1442 |
} |
| 1443 |
} |
| 1444 |
|
| 1445 |
|
| 1446 |
if (!strcasecmp(args.action, "add")) { |
| 1447 |
return add_inheritable_header(chan, args.header_name, value); |
| 1448 |
} else if (!strcasecmp(args.action, "update")) { |
| 1449 |
return update_inheritable_header(chan, args.header_name, value, header_number); |
| 1450 |
} else if (!strcasecmp(args.action, "remove")) { |
| 1451 |
return remove_inheritable_header(chan, args.header_name); |
| 1452 |
} else { |
| 1453 |
ast_log(AST_LOG_ERROR, |
| 1454 |
"Unknown action '%s' is not valid, must be 'add', 'update', or 'remove'.\n", |
| 1455 |
args.action); |
| 1456 |
return -1; |
| 1457 |
} |
| 1458 |
} |
| 1459 |
|
| 1460 |
static struct ast_custom_function pjsip_header_function = { |
| 1461 |
.name = "PJSIP_HEADER", |
| 1462 |
.read = func_read_header, |
| 1463 |
.write = func_write_header, |
| 1464 |
}; |
| 1465 |
|
| 1466 |
static struct ast_custom_function pjsip_header_inherit_function = { |
| 1467 |
.name = "PJSIP_INHERITABLE_HEADER", |
| 1468 |
.write = func_write_inheritable_header, |
| 1469 |
}; |
| 1470 |
|
| 1471 |
static struct ast_custom_function pjsip_headers_function = { |
| 1472 |
.name = "PJSIP_HEADERS", |
| 1473 |
.read = func_read_headers |
| 1474 |
}; |
| 1475 |
|
| 1476 |
static struct ast_custom_function pjsip_response_header_function = { |
| 1477 |
.name = "PJSIP_RESPONSE_HEADER", |
| 1478 |
.read = func_response_read_header |
| 1479 |
}; |
| 1480 |
|
| 1481 |
static struct ast_custom_function pjsip_response_headers_function = { |
| 1482 |
.name = "PJSIP_RESPONSE_HEADERS", |
| 1483 |
.read = func_response_read_headers |
| 1484 |
}; |
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
static void outgoing_request(struct ast_sip_session *session, pjsip_tx_data * tdata) |
| 1499 |
{ |
| 1500 |
struct hdr_list *hdr_list; |
| 1501 |
struct hdr_list_entry *le; |
| 1502 |
int header_count = 0; |
| 1503 |
struct ast_datastore *inherited_datastore = NULL; |
| 1504 |
RAII_VAR(struct ast_datastore *, session_datastore, |
| 1505 |
ast_sip_session_get_datastore(session, session_header_datastore.type), ao2_cleanup); |
| 1506 |
|
| 1507 |
|
| 1508 |
if (session->inv_session->state >= PJSIP_INV_STATE_CONFIRMED) { |
| 1509 |
ast_debug(3, "Already confirmed (state=%d)\n", |
| 1510 |
session->inv_session->state); |
| 1511 |
return; |
| 1512 |
} |
| 1513 |
|
| 1514 |
|
| 1515 |
if (session->channel && session->inv_session->role == PJSIP_ROLE_UAC) { |
| 1516 |
struct ast_datastore *chan_datastore = NULL; |
| 1517 |
|
| 1518 |
ast_channel_lock(session->channel); |
| 1519 |
|
| 1520 |
chan_datastore = ast_channel_datastore_find(session->channel, &inheritable_header_datastore, NULL); |
| 1521 |
|
| 1522 |
if (chan_datastore && chan_datastore->inheritance && chan_datastore->data) { |
| 1523 |
inherited_datastore = ast_sip_session_alloc_datastore(&inheritable_header_datastore, |
| 1524 |
inheritable_header_datastore.type); |
| 1525 |
|
| 1526 |
if (inherited_datastore) { |
| 1527 |
|
| 1528 |
|
| 1529 |
inherited_datastore->data = ast_variables_reverse((struct ast_variable *) |
| 1530 |
inheritable_headers_duplicate((struct ast_variable *) chan_datastore->data)); |
| 1531 |
if (inherited_datastore->data) { |
| 1532 |
inherited_datastore->inheritance = chan_datastore->inheritance; |
| 1533 |
ast_sip_session_add_datastore(session, inherited_datastore); |
| 1534 |
} else { |
| 1535 |
ast_log(LOG_ERROR, "Failed to duplicate ast_variable list for channel %s\n", |
| 1536 |
session->channel ? ast_channel_name(session->channel) : "(none)"); |
| 1537 |
ao2_ref(inherited_datastore, -1); |
| 1538 |
inherited_datastore = NULL; |
| 1539 |
} |
| 1540 |
} else { |
| 1541 |
ast_log(LOG_ERROR, "Failed to allocate inherited session datastore for channel %s\n", |
| 1542 |
session->channel ? ast_channel_name(session->channel) : "(none)"); |
| 1543 |
} |
| 1544 |
} |
| 1545 |
ast_channel_unlock(session->channel); |
| 1546 |
} |
| 1547 |
|
| 1548 |
|
| 1549 |
if (!session_datastore && !inherited_datastore) { |
| 1550 |
return; |
| 1551 |
} |
| 1552 |
|
| 1553 |
|
| 1554 |
if (session_datastore && session_datastore->data) { |
| 1555 |
hdr_list = session_datastore->data; |
| 1556 |
AST_LIST_TRAVERSE(hdr_list, le, nextptr) { |
| 1557 |
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) pjsip_hdr_clone(tdata->pool, le->hdr)); |
| 1558 |
header_count++; |
| 1559 |
} |
| 1560 |
ast_debug(3, "Added %d regular header(s) to channel %s\n", header_count, |
| 1561 |
session->channel ? ast_channel_name(session->channel) : "(none)"); |
| 1562 |
|
| 1563 |
ast_sip_session_remove_datastore(session, session_datastore->uid); |
| 1564 |
} |
| 1565 |
|
| 1566 |
|
| 1567 |
if (inherited_datastore && inherited_datastore->data) { |
| 1568 |
int inherited_count = 0; |
| 1569 |
struct ast_variable *headers = inherited_datastore->data; |
| 1570 |
struct ast_variable *var; |
| 1571 |
|
| 1572 |
for (var = headers; var; var = var->next) { |
| 1573 |
if (!ast_sip_add_header(tdata, var->name, var->value)) { |
| 1574 |
inherited_count++; |
| 1575 |
} |
| 1576 |
} |
| 1577 |
ast_debug(3, "Added %d inherited header(s) to channel %s\n", inherited_count, |
| 1578 |
session->channel ? ast_channel_name(session->channel) : "(none)"); |
| 1579 |
header_count += inherited_count; |
| 1580 |
|
| 1581 |
ast_sip_session_remove_datastore(session, inherited_datastore->uid); |
| 1582 |
ao2_ref(inherited_datastore, -1); |
| 1583 |
} |
| 1584 |
|
| 1585 |
ast_debug(3, "Added total of %d header(s) to channel %s\n", header_count, |
| 1586 |
session->channel ? ast_channel_name(session->channel) : "(none)"); |
| 1587 |
} |
| 1588 |
|
| 1589 |
static struct ast_sip_session_supplement header_funcs_supplement = { |
| 1590 |
.method = "INVITE", |
| 1591 |
.priority = AST_SIP_SUPPLEMENT_PRIORITY_CHANNEL - 1000, |
| 1592 |
.incoming_request = incoming_request, |
| 1593 |
.outgoing_request = outgoing_request, |
| 1594 |
.incoming_response = incoming_response, |
| 1595 |
}; |
| 1596 |
|
| 1597 |
enum param_type { |
| 1598 |
PARAMETER_HEADER, |
| 1599 |
PARAMETER_URI, |
| 1600 |
}; |
| 1601 |
|
| 1602 |
struct param_data { |
| 1603 |
struct ast_sip_channel_pvt *channel; |
| 1604 |
char *header_name; |
| 1605 |
char *param_name; |
| 1606 |
const char *param_value; |
| 1607 |
enum param_type paramtype; |
| 1608 |
|
| 1609 |
char *buf; |
| 1610 |
size_t len; |
| 1611 |
}; |
| 1612 |
|
| 1613 |
static int read_param(void *obj) |
| 1614 |
{ |
| 1615 |
struct param_data *data = obj; |
| 1616 |
struct ast_sip_session *session = data->channel->session; |
| 1617 |
pj_str_t param_name; |
| 1618 |
|
| 1619 |
pjsip_fromto_hdr *dlg_info; |
| 1620 |
pjsip_name_addr *dlg_info_name_addr; |
| 1621 |
pjsip_sip_uri *dlg_info_uri; |
| 1622 |
pjsip_param *param; |
| 1623 |
size_t param_len; |
| 1624 |
|
| 1625 |
dlg_info = session->inv_session->dlg->remote.info; |
| 1626 |
dlg_info_name_addr = (pjsip_name_addr *) dlg_info->uri; |
| 1627 |
dlg_info_uri = pjsip_uri_get_uri(dlg_info_name_addr); |
| 1628 |
|
| 1629 |
pj_cstr(¶m_name, data->param_name); |
| 1630 |
|
| 1631 |
if (data->paramtype == PARAMETER_URI) { |
| 1632 |
param = pjsip_param_find(&dlg_info_uri->other_param, ¶m_name); |
| 1633 |
} else { |
| 1634 |
param = pjsip_param_find(&dlg_info->other_param, ¶m_name); |
| 1635 |
} |
| 1636 |
|
| 1637 |
if (!param) { |
| 1638 |
ast_debug(1, "No %s parameter found named %s\n", |
| 1639 |
data->paramtype == PARAMETER_URI ? "URI" : "header", data->param_name); |
| 1640 |
return -1; |
| 1641 |
} |
| 1642 |
|
| 1643 |
param_len = pj_strlen(¶m->value); |
| 1644 |
if (param_len >= data->len) { |
| 1645 |
ast_log(LOG_ERROR, "Buffer is too small for parameter value (%zu > %zu)\n", param_len, data->len); |
| 1646 |
return -1; |
| 1647 |
} |
| 1648 |
|
| 1649 |
ast_debug(2, "Successfully read %s parameter %s (length %zu)\n", |
| 1650 |
data->paramtype == PARAMETER_URI ? "URI" : "header", data->param_name, param_len); |
| 1651 |
if (param_len) { |
| 1652 |
ast_copy_string(data->buf, pj_strbuf(¶m->value), data->len); |
| 1653 |
} |
| 1654 |
data->buf[param_len] = '\0'; |
| 1655 |
|
| 1656 |
return 0; |
| 1657 |
} |
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
static int add_param(void *obj) |
| 1666 |
{ |
| 1667 |
struct param_data *data = obj; |
| 1668 |
struct ast_sip_session *session = data->channel->session; |
| 1669 |
pj_pool_t *pool = session->inv_session->dlg->pool; |
| 1670 |
|
| 1671 |
pjsip_fromto_hdr *dlg_info; |
| 1672 |
pjsip_name_addr *dlg_info_name_addr; |
| 1673 |
pjsip_sip_uri *dlg_info_uri; |
| 1674 |
|
| 1675 |
dlg_info = session->inv_session->dlg->local.info; |
| 1676 |
dlg_info_name_addr = (pjsip_name_addr *) dlg_info->uri; |
| 1677 |
dlg_info_uri = pjsip_uri_get_uri(dlg_info_name_addr); |
| 1678 |
if (!PJSIP_URI_SCHEME_IS_SIP(dlg_info_uri) && !PJSIP_URI_SCHEME_IS_SIPS(dlg_info_uri)) { |
| 1679 |
ast_log(LOG_WARNING, "Non SIP/SIPS URI\n"); |
| 1680 |
return -1; |
| 1681 |
} |
| 1682 |
|
| 1683 |
ast_debug(1, "Adding custom %s param %s = %s\n", |
| 1684 |
data->paramtype == PARAMETER_URI ? "URI" : "header", data->param_name, data->param_value); |
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
#define param_add(pool, list, pname, pvalue) { \ |
| 1697 |
pjsip_param *param; \ |
| 1698 |
param = PJ_POOL_ALLOC_T(pool, pjsip_param); \ |
| 1699 |
pj_strdup2(pool, ¶m->name, pname); \ |
| 1700 |
pj_strdup2(pool, ¶m->value, pvalue); \ |
| 1701 |
pj_list_insert_before(list, param); \ |
| 1702 |
} |
| 1703 |
|
| 1704 |
if (data->paramtype == PARAMETER_URI) { |
| 1705 |
param_add(pool, &dlg_info_uri->other_param, data->param_name, S_OR(data->param_value, "")); |
| 1706 |
} else { |
| 1707 |
param_add(pool, &dlg_info->other_param, data->param_name, S_OR(data->param_value, "")); |
| 1708 |
} |
| 1709 |
|
| 1710 |
return 0; |
| 1711 |
} |
| 1712 |
|
| 1713 |
static int func_read_param(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len) |
| 1714 |
{ |
| 1715 |
struct ast_sip_channel_pvt *channel = chan ? ast_channel_tech_pvt(chan) : NULL; |
| 1716 |
struct param_data param_data; |
| 1717 |
|
| 1718 |
AST_DECLARE_APP_ARGS(args, |
| 1719 |
AST_APP_ARG(header_name); |
| 1720 |
AST_APP_ARG(param_type); |
| 1721 |
AST_APP_ARG(param_name); |
| 1722 |
); |
| 1723 |
|
| 1724 |
AST_STANDARD_APP_ARGS(args, data); |
| 1725 |
|
| 1726 |
param_data.channel = channel; |
| 1727 |
|
| 1728 |
if (!channel || strncmp(ast_channel_name(chan), "PJSIP/", 6)) { |
| 1729 |
ast_log(LOG_ERROR, "This function requires a PJSIP channel.\n"); |
| 1730 |
return -1; |
| 1731 |
} |
| 1732 |
if (ast_strlen_zero(args.param_type)) { |
| 1733 |
ast_log(AST_LOG_ERROR, "This function requires a parameter type.\n"); |
| 1734 |
return -1; |
| 1735 |
} |
| 1736 |
if (ast_strlen_zero(args.param_name)) { |
| 1737 |
ast_log(AST_LOG_ERROR, "This function requires a parameter name.\n"); |
| 1738 |
return -1; |
| 1739 |
} |
| 1740 |
|
| 1741 |
|
| 1742 |
if (ast_strlen_zero(args.header_name) || strcasecmp(args.header_name, "From")) { |
| 1743 |
ast_log(LOG_WARNING, "Only the From header is currently supported\n"); |
| 1744 |
return -1; |
| 1745 |
} |
| 1746 |
|
| 1747 |
param_data.param_name = args.param_name; |
| 1748 |
if (!strcasecmp(args.param_type, "header")) { |
| 1749 |
param_data.paramtype = PARAMETER_HEADER; |
| 1750 |
} else if (!strcasecmp(args.param_type, "uri")) { |
| 1751 |
param_data.paramtype = PARAMETER_URI; |
| 1752 |
} else { |
| 1753 |
ast_log(LOG_WARNING, "Parameter type '%s' is invalid: must be 'header' or 'uri'\n", args.param_type); |
| 1754 |
return -1; |
| 1755 |
} |
| 1756 |
|
| 1757 |
param_data.buf = buf; |
| 1758 |
param_data.len = len; |
| 1759 |
|
| 1760 |
return ast_sip_push_task_wait_serializer(channel->session->serializer, read_param, ¶m_data); |
| 1761 |
} |
| 1762 |
|
| 1763 |
static int func_write_param(struct ast_channel *chan, const char *cmd, char *data, const char *value) |
| 1764 |
{ |
| 1765 |
struct ast_sip_channel_pvt *channel = chan ? ast_channel_tech_pvt(chan) : NULL; |
| 1766 |
struct param_data param_data; |
| 1767 |
AST_DECLARE_APP_ARGS(args, |
| 1768 |
AST_APP_ARG(header_name); |
| 1769 |
AST_APP_ARG(param_type); |
| 1770 |
AST_APP_ARG(param_name); |
| 1771 |
); |
| 1772 |
|
| 1773 |
AST_STANDARD_APP_ARGS(args, data); |
| 1774 |
|
| 1775 |
param_data.channel = channel; |
| 1776 |
|
| 1777 |
if (!channel || strncmp(ast_channel_name(chan), "PJSIP/", 6)) { |
| 1778 |
ast_log(LOG_ERROR, "This function requires a PJSIP channel.\n"); |
| 1779 |
return -1; |
| 1780 |
} |
| 1781 |
if (ast_strlen_zero(args.param_type)) { |
| 1782 |
ast_log(AST_LOG_ERROR, "This function requires a parameter type.\n"); |
| 1783 |
return -1; |
| 1784 |
} |
| 1785 |
if (ast_strlen_zero(args.param_name)) { |
| 1786 |
ast_log(AST_LOG_ERROR, "This function requires a parameter name.\n"); |
| 1787 |
return -1; |
| 1788 |
} |
| 1789 |
|
| 1790 |
|
| 1791 |
if (ast_strlen_zero(args.header_name) || strcasecmp(args.header_name, "From")) { |
| 1792 |
ast_log(LOG_WARNING, "Only the From header is currently supported\n"); |
| 1793 |
return -1; |
| 1794 |
} |
| 1795 |
|
| 1796 |
param_data.param_name = args.param_name; |
| 1797 |
if (!strcasecmp(args.param_type, "header")) { |
| 1798 |
param_data.paramtype = PARAMETER_HEADER; |
| 1799 |
} else if (!strcasecmp(args.param_type, "uri")) { |
| 1800 |
param_data.paramtype = PARAMETER_URI; |
| 1801 |
} else { |
| 1802 |
ast_log(LOG_WARNING, "Parameter type '%s' is invalid: must be 'header' or 'uri'\n", args.param_type); |
| 1803 |
return -1; |
| 1804 |
} |
| 1805 |
param_data.param_value = value; |
| 1806 |
|
| 1807 |
return ast_sip_push_task_wait_serializer(channel->session->serializer, add_param, ¶m_data); |
| 1808 |
} |
| 1809 |
|
| 1810 |
static struct ast_custom_function pjsip_header_param_function = { |
| 1811 |
.name = "PJSIP_HEADER_PARAM", |
| 1812 |
.read = func_read_param, |
| 1813 |
.write = func_write_param, |
| 1814 |
}; |
| 1815 |
|
| 1816 |
static int load_module(void) |
| 1817 |
{ |
| 1818 |
ast_sip_session_register_supplement(&header_funcs_supplement); |
| 1819 |
ast_custom_function_register(&pjsip_header_function); |
| 1820 |
ast_custom_function_register(&pjsip_header_inherit_function); |
| 1821 |
ast_custom_function_register(&pjsip_headers_function); |
| 1822 |
ast_custom_function_register(&pjsip_response_header_function); |
| 1823 |
ast_custom_function_register(&pjsip_response_headers_function); |
| 1824 |
ast_custom_function_register(&pjsip_header_param_function); |
| 1825 |
|
| 1826 |
return AST_MODULE_LOAD_SUCCESS; |
| 1827 |
} |
| 1828 |
|
| 1829 |
static int unload_module(void) |
| 1830 |
{ |
| 1831 |
ast_custom_function_unregister(&pjsip_header_function); |
| 1832 |
ast_custom_function_unregister(&pjsip_header_inherit_function); |
| 1833 |
ast_custom_function_unregister(&pjsip_headers_function); |
| 1834 |
ast_custom_function_unregister(&pjsip_response_header_function); |
| 1835 |
ast_custom_function_unregister(&pjsip_response_headers_function); |
| 1836 |
ast_custom_function_unregister(&pjsip_header_param_function); |
| 1837 |
ast_sip_session_unregister_supplement(&header_funcs_supplement); |
| 1838 |
return 0; |
| 1839 |
} |
| 1840 |
|
| 1841 |
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Header Functions", |
| 1842 |
.support_level = AST_MODULE_SUPPORT_CORE, |
| 1843 |
.load = load_module, |
| 1844 |
.unload = unload_module, |
| 1845 |
.load_pri = AST_MODPRI_APP_DEPEND, |
| 1846 |
.requires = "res_pjsip,res_pjsip_session", |
| 1847 |
); |