# HG changeset patch # User Mychaela Falconia # Date 1664061233 28800 # Node ID ff5e96162430f59f8f2ae1265e218beb536cbcfc # Parent a9137bdb6047606aa2b7b5e28c86b9cc9c2f811c libsip: new function for extracting Call-ID and CSeq from responses diff -r a9137bdb6047 -r ff5e96162430 libsip/Makefile --- a/libsip/Makefile Fri Sep 23 19:18:07 2022 -0800 +++ b/libsip/Makefile Sat Sep 24 15:13:53 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 to_tag.o uas_basic.o uri_utils.o +OBJS= get_header.o grok_from.o out_msg.o primary_parse.o req_supp.o \ + resp_ident.o sdp_gen.o sdp_parse.o to_tag.o uas_basic.o uri_utils.o LIB= libsip.a all: ${LIB} diff -r a9137bdb6047 -r ff5e96162430 libsip/resp_ident.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libsip/resp_ident.c Sat Sep 24 15:13:53 2022 -0800 @@ -0,0 +1,52 @@ +/* + * In this module we implement an essential step in the process + * of handling incoming SIP response messages: extracting Call-ID + * and CSeq headers and preparsing the latter, providing key info + * for matching these incoming responses with call state and + * with outstanding UAC requests. + */ + +#include +#include +#include +#include +#include +#include "parse.h" +#include "resp_ident.h" + +extern char *get_single_header(); + +sip_resp_extract_ident(msg, id) + struct sip_pkt_rx *msg; + struct sip_resp_ident *id; +{ + char *hval, *cp; + int dup_flag = 0; + + hval = get_single_header(msg, "Call-ID", "i", &dup_flag); + if (!hval || dup_flag) { + id->error_field = "Call-ID"; + return(-1); + } + id->call_id = hval; + hval = get_single_header(msg, "CSeq", (char *) 0, &dup_flag); + if (!hval || dup_flag) { +bad_cseq: id->error_field = "CSeq"; + return(-1); + } + if (!isdigit(*hval)) + goto bad_cseq; + id->cseq_num = strtoul(hval, &cp, 10); + if (!isspace(*cp)) + goto bad_cseq; + while (isspace(*cp)) + cp++; + if (!isupper(*cp)) + goto bad_cseq; + id->cseq_method = cp; + while (isalnum(*cp)) + cp++; + if (*cp) + goto bad_cseq; + return(0); +} diff -r a9137bdb6047 -r ff5e96162430 libsip/resp_ident.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libsip/resp_ident.h Sat Sep 24 15:13:53 2022 -0800 @@ -0,0 +1,13 @@ +/* + * Here we define struct sip_resp_ident, a structure that captures + * Call-ID and CSeq headers from initial parsing of SIP responses, + * allowing these responses to be matched with call state and + * with UAC requests that elicited them. + */ + +struct sip_resp_ident { + char *call_id; + unsigned cseq_num; + char *cseq_method; + char *error_field; +};