# HG changeset patch # User Mychaela Falconia # Date 1663700050 28800 # Node ID 9ca6f07082376f3e8a1349bc835aa919000737bf # Parent d74b545a3c2abdf1db1baa8b056c03eecb4dcfb8 libsip: add extract_to_tag() function diff -r d74b545a3c2a -r 9ca6f0708237 libsip/Makefile --- a/libsip/Makefile Tue Sep 20 10:14:18 2022 -0800 +++ b/libsip/Makefile Tue Sep 20 10:54:10 2022 -0800 @@ -1,7 +1,7 @@ CC= gcc CFLAGS= -O2 OBJS= get_header.o grok_from.o out_msg.o primary_parse.o req_supp.o sdp_gen.o\ - sdp_parse.o uas_basic.o uri_utils.o + sdp_parse.o to_tag.o uas_basic.o uri_utils.o LIB= libsip.a all: ${LIB} diff -r d74b545a3c2a -r 9ca6f0708237 libsip/to_tag.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libsip/to_tag.c Tue Sep 20 10:54:10 2022 -0800 @@ -0,0 +1,76 @@ +/* + * The function implemented in this module extracts the tag + * from the To header of a SIP destination server's response. + */ + +#include +#include +#include +#include +#include +#include "parse.h" + +extern char *get_single_header(); + +char * +extract_to_tag(msg, expect_uri) + struct sip_pkt_rx *msg; + char *expect_uri; +{ + char *cp, *tag; + int bracketed, c; + unsigned expect_uri_len; + + cp = get_single_header(msg, "To", "t", (int *) 0); + if (!cp) + return 0; + if (*cp == '<') { + cp++; + bracketed = 1; + } else + bracketed = 0; + expect_uri_len = strlen(expect_uri); + if (strncasecmp(cp, expect_uri, expect_uri_len)) + return 0; + cp += expect_uri_len; + if (bracketed) { + if (*cp++ != '>') + return 0; + } + while (isspace(*cp)) + cp++; + if (*cp++ != ';') + return 0; + while (isspace(*cp)) + cp++; + if (strncasecmp(cp, "tag", 3)) + return 0; + cp += 3; + while (isspace(*cp)) + cp++; + if (*cp++ != '=') + return 0; + while (isspace(*cp)) + cp++; + tag = cp; + for (; c = *cp; cp++) { + switch (c) { + case '-': + case '.': + case '!': + case '%': + case '*': + case '_': + case '+': + case '`': + case '\'': + case '~': + continue; + default: + if (isalnum(c)) + continue; + return 0; + } + } + return tag; +}