view libsip/req_supp.c @ 124:7e04d28fae8b

sip-in: default use-100rel to no BulkVS servers act badly when we send a reliable 180 Ringing response to an incoming call, even though they advertise 100rel support in the Supported header in the INVITE packet, and we probably won't be implementing 100rel for outbound because doing per-the-spec PRACK as a UAC is just too burdensome. Therefore, we need to consider 100rel extension as not-really-supported in themwi-system-sw.
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 01 Oct 2022 15:54:50 -0800
parents dec31b1a8b96
children
line wrap: on
line source

/*
 * Here we parse Require and Supported headers in a SIP request,
 * checking whether our supported extensions are also supported
 * or required by the client, and catching any client requirements
 * which we don't support.
 */

#include <ctype.h>
#include <string.h>
#include <strings.h>
#include "parse.h"
#include "req_supp.h"

parse_require_supported(msg, lsupp, nlsupp, unsupp)
	struct sip_pkt_rx *msg;
	struct supported_ext *lsupp;
	unsigned nlsupp;
	char **unsupp;
{
	struct sip_parse_hdr *hdr, *endhdr;
	char *cp, *np;
	unsigned n;

	endhdr = msg->hdr_fields + msg->num_hdr_fields;
	/* check Require first */
	for (hdr = msg->hdr_fields; hdr < endhdr; hdr++) {
		if (strcasecmp(hdr->field_name, "Require"))
			continue;
		cp = hdr->field_value;
		for (;;) {
			while (isspace(*cp) || *cp == ',')
				cp++;
			if (!*cp)
				break;
			np = cp;
			while (*cp && !isspace(*cp) && *cp != ',')
				cp++;
			if (*cp)
				*cp++ = '\0';
			for (n = 0; n < nlsupp; n++) {
				if (!strcasecmp(np, lsupp[n].name)) {
					*lsupp[n].req_flag = 1;
					break;
				} else {
					if (unsupp)
						*unsupp = np;
					return(-1);
				}
			}
		}
	}
	/* now check Supported */
	for (hdr = msg->hdr_fields; hdr < endhdr; hdr++) {
		if (strcasecmp(hdr->field_name, "Supported") &&
		    strcasecmp(hdr->field_name, "k"))
			continue;
		cp = hdr->field_value;
		for (;;) {
			while (isspace(*cp) || *cp == ',')
				cp++;
			if (!*cp)
				break;
			np = cp;
			while (*cp && !isspace(*cp) && *cp != ',')
				cp++;
			if (*cp)
				*cp++ = '\0';
			for (n = 0; n < nlsupp; n++) {
				if (!strcasecmp(np, lsupp[n].name)) {
					*lsupp[n].sup_flag = 1;
					break;
				}
			}
		}
	}
	return(0);
}