MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / print_dset

Function print_dset

dset.c:491–580  ·  view source on GitHub ↗

! \brief * Create a Contact header field from the dset * array */

Source from the content-addressed store, hash-verified

489 * array
490 */
491char* print_dset(struct sip_msg* msg, int* len)
492{
493 int cnt, i, idx;
494 unsigned int qlen;
495 char* p, *qbuf;
496 static char *dset = NULL;
497 static unsigned int dset_len = 0;
498 struct msg_branch *br;
499
500 if (msg->new_uri.s) {
501 cnt = 1;
502 *len = msg->new_uri.len+2 /*for <>*/;
503 if (get_ruri_q(msg) != Q_UNSPECIFIED) {
504 *len += Q_PARAM_LEN + len_q(get_ruri_q(msg));
505 }
506 } else {
507 cnt = 0;
508 *len = 0;
509 }
510
511 for( idx=0 ; (br=get_msg_branch(idx))!=NULL ; idx++ ) {
512 cnt++;
513 *len += br->uri.len+2 /*for <>*/ ;
514 if (br->q != Q_UNSPECIFIED) {
515 *len += Q_PARAM_LEN + len_q(br->q);
516 }
517 }
518
519 if (cnt == 0) return 0;
520
521 *len += CONTACT_LEN + CRLF_LEN + (cnt - 1) * CONTACT_DELIM_LEN;
522
523 /* does the current buffer fit the new dset ? */
524 if (*len + 1 > dset_len) {
525 /* need to resize */
526 dset = pkg_realloc(dset, *len + 1);
527 if (!dset) {
528 dset_len = 0;
529 LM_ERR("failed to allocate redirect buffer for %d bytes\n", *len + 1);
530 return NULL;
531 }
532 dset_len = *len + 1;
533 }
534
535 memcpy(dset, CONTACT, CONTACT_LEN);
536 p = dset + CONTACT_LEN;
537 if (msg->new_uri.s) {
538 *p++ = '<';
539 memcpy(p, msg->new_uri.s, msg->new_uri.len);
540 p += msg->new_uri.len;
541 *p++ = '>';
542
543 if (get_ruri_q(msg) != Q_UNSPECIFIED) {
544 memcpy(p, Q_PARAM, Q_PARAM_LEN);
545 p += Q_PARAM_LEN;
546
547 qbuf = q2str(get_ruri_q(msg), &qlen);
548 memcpy(p, qbuf, qlen);

Callers 3

pv_get_dsetFunction · 0.85
sl_send_reply_helperFunction · 0.85
_replyFunction · 0.85

Calls 3

len_qFunction · 0.85
get_msg_branchFunction · 0.85
q2strFunction · 0.85

Tested by

no test coverage detected