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

Function fixup_parse_hname

modules/sipmsgops/sipmsgops.c:709–763  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

707
708
709static int fixup_parse_hname(void** param)
710{
711 char *c;
712 int len;
713 struct hdr_field hdr;
714 int_str_t *outval;
715 str *hn = (str *)*param;
716
717 outval = pkg_malloc(sizeof *outval + hn->len + 1);
718 if (!outval) {
719 LM_ERR("oom\n");
720 return -1;
721 }
722 memset(outval, 0, sizeof *outval);
723
724 /* parse_hname2() accepts a minimum 4 bytes len buffer
725 * for parsing, so whatever is the len of the header name,
726 * fill it up to 4 */
727 len = (hn->len < 3) ? (4) : (hn->len + 1);
728 c = pkg_malloc( len );
729 if (!c)
730 return E_OUT_OF_MEM;
731
732 memcpy(c, hn->s, hn->len);
733 c[hn->len] = ':';
734
735 if (parse_hname2(c, c + len, &hdr) == 0)
736 {
737 LM_ERR("error parsing header name\n");
738 goto err_free;
739 }
740
741 pkg_free(c);
742
743 if (hdr.type != HDR_OTHER_T && hdr.type != HDR_ERROR_T)
744 {
745 LM_DBG("using hdr type (%d) instead of <%.*s>\n",
746 hdr.type, hn->len, hn->s);
747
748 outval->i = hdr.type;
749 } else {
750 outval->is_str = 1;
751 outval->s.s = (char *)(outval + 1);
752 memcpy(outval->s.s, hn->s, hn->len);
753 outval->s.len = hn->len;
754 outval->s.s[outval->s.len] = '\0';
755 }
756
757 *param = outval;
758 return 0;
759
760err_free:
761 pkg_free(outval);
762 return E_UNSPEC;
763}
764
765/*
766 * Convert char* method to str* parameter

Callers

nothing calls this directly

Calls 1

parse_hname2Function · 0.85

Tested by

no test coverage detected