Thu Jan 8 15:13:56 CST 2009 Pekka Pessi <first.last@nokia.com>

* sip: using <sofia-sip/su_string.h> functions



git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11806 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2009-02-11 16:52:15 +00:00
parent d8f68d7a56
commit cefbcf0a29
16 changed files with 83 additions and 78 deletions

View File

@ -1 +1 @@
Wed Feb 11 10:51:28 CST 2009
Wed Feb 11 10:52:05 CST 2009

View File

@ -41,7 +41,7 @@
#define MSG_HDR_T union sip_header_u
#include <sofia-sip/su_alloc.h>
#include <sofia-sip/string0.h>
#include <sofia-sip/su_string.h>
#include "sofia-sip/sip_parser.h"
#include <sofia-sip/sip_util.h>
@ -940,7 +940,7 @@ static int sip_addr_update(msg_common_t *h,
if (name == NULL) {
a->a_tag = NULL;
}
else if (namelen == strlen("tag") && !strncasecmp(name, "tag", namelen)) {
else if (namelen == strlen("tag") && su_casenmatch(name, "tag", namelen)) {
a->a_tag = value;
}
@ -983,7 +983,7 @@ int sip_addr_tag(su_home_t *home, sip_addr_t *a, char const *tag)
value = tag;
if (a->a_tag) {
if (strcasecmp(a->a_tag, value) == 0)
if (su_casematch(a->a_tag, value))
return 0;
else
return -1;
@ -1456,12 +1456,12 @@ static int sip_contact_update(msg_common_t *h,
m->m_q = NULL;
m->m_expires = NULL;
}
else if (namelen == 1 && strncasecmp(name, "q", 1) == 0) {
else if (namelen == 1 && su_casenmatch(name, "q", 1)) {
/* XXX - check for invalid value? */
m->m_q = value;
}
else if (namelen == strlen("expires") &&
!strncasecmp(name, "expires", namelen)) {
su_casenmatch(name, "expires", namelen)) {
m->m_expires = value;
}
@ -2086,7 +2086,7 @@ static int sip_retry_after_update(msg_common_t *h,
af->af_duration = NULL;
}
else if (namelen == strlen("duration") &&
!strncasecmp(name, "duration", namelen)) {
su_casenmatch(name, "duration", namelen)) {
af->af_duration = value;
}
@ -2635,7 +2635,7 @@ static int sip_via_update(msg_common_t *h,
v->v_rport = NULL;
v->v_comp = NULL;
}
#define MATCH(s) (namelen == strlen(#s) && !strncasecmp(name, #s, strlen(#s)))
#define MATCH(s) (namelen == strlen(#s) && su_casenmatch(name, #s, strlen(#s)))
else if (MATCH(ttl)) {
v->v_ttl = value;
@ -2761,7 +2761,7 @@ char const *sip_via_port(sip_via_t const *v, int *using_rport)
if (v->v_rport && !v->v_maddr /* multicast */) {
if (v->v_protocol == sip_transport_udp ||
strcasecmp(v->v_protocol, sip_transport_udp) == 0)
su_casematch(v->v_protocol, sip_transport_udp))
port = v->v_rport, *using_rport = 0;
else if (*using_rport)
port = v->v_rport;

View File

@ -205,7 +205,7 @@ issize_t sip_caller_prefs_d(su_home_t *home, sip_header_t *h,
*s = '\0', s += span_lws(s + 1) + 1;
/* Kludge: support PoC IS spec with a typo... */
if (strncasecmp(s, "*,", 2) == 0)
if (su_casenmatch(s, "*,", 2))
s[1] = ';', kludge = 0;
else if (s[0] != '*' && s[0] != '<') {
/* Kludge: missing URL - */
@ -346,7 +346,7 @@ static int sip_accept_contact_update(msg_common_t *h,
cp->cp_require = 0;
cp->cp_explicit = 0;
}
#define MATCH(s) (namelen == strlen(#s) && !strncasecmp(name, #s, strlen(#s)))
#define MATCH(s) (namelen == strlen(#s) && su_casenmatch(name, #s, strlen(#s)))
#if nomore
else if (MATCH(q)) {

View File

@ -159,7 +159,7 @@ static int sip_event_update(msg_common_t *h,
if (name == NULL) {
o->o_id = NULL;
}
else if (namelen == strlen("id") && !strncasecmp(name, "id", namelen)) {
else if (namelen == strlen("id") && su_casenmatch(name, "id", namelen)) {
o->o_id = value;
}
@ -373,7 +373,7 @@ static int sip_subscription_state_update(msg_common_t *h,
ss->ss_retry_after = NULL;
ss->ss_expires = NULL;
}
#define MATCH(s) (namelen == strlen(#s) && !strncasecmp(name, #s, strlen(#s)))
#define MATCH(s) (namelen == strlen(#s) && su_casenmatch(name, #s, strlen(#s)))
else if (MATCH(reason)) {
ss->ss_reason = value;
@ -498,9 +498,9 @@ su_inline void sip_publication_update(sip_publication_t *pub)
if (pub->pub_params)
for (i = 0; pub->pub_params[i]; i++) {
if (strncasecmp(pub->pub_params[i], "stream=", strlen("stream=")) == 0)
if (su_casenmatch(pub->pub_params[i], "stream=", strlen("stream=")))
pub->pub_stream = pub->pub_params[i] + strlen("stream=");
else if (strncasecmp(pub->pub_params[i], "type=", strlen("type=")) == 0)
else if (su_casenmatch(pub->pub_params[i], "type=", strlen("type=")))
pub->pub_type = pub->pub_params[i] + strlen("type=");
}
}

View File

@ -132,10 +132,10 @@ issize_t sip_call_info_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
* Update parameter in a @CallInfo object.
*
*/
static
int sip_call_info_update(msg_common_t *h,
char const *name, isize_t namelen,
char const *value)
static int
sip_call_info_update(msg_common_t *h,
char const *name, isize_t namelen,
char const *value)
{
sip_call_info_t *ci = (sip_call_info_t *)h;
@ -143,7 +143,7 @@ int sip_call_info_update(msg_common_t *h,
ci->ci_purpose = NULL;
}
else if (namelen == strlen("purpose") &&
!strncasecmp(name, "purpose", namelen)) {
su_casenmatch(name, "purpose", namelen)) {
ci->ci_purpose = value;
}
@ -1213,7 +1213,7 @@ static int sip_remote_party_id_update(msg_common_t *h,
rpid->rpid_privacy = NULL;
}
#define MATCH(s) (namelen == strlen(#s) && !strncasecmp(name, #s, strlen(#s)))
#define MATCH(s) (namelen == strlen(#s) && su_casenmatch(name, #s, strlen(#s)))
else if (MATCH(screen))
rpid->rpid_screen = value;

View File

@ -425,21 +425,21 @@ sip_has_unsupported_any(su_home_t *home,
msg_param_t feature = require->k_items[i++];
for (j = 0; slist[j]; j++)
if (strcasecmp(feature, slist[j]) == 0) {
if (su_casematch(feature, slist[j])) {
feature = NULL;
break;
}
if (feature)
for (j = 0; rlist[j]; j++)
if (strcasecmp(feature, rlist[j]) == 0) {
if (su_casematch(feature, rlist[j])) {
feature = NULL;
break;
}
if (feature)
for (j = 0; prlist[j]; j++)
if (strcasecmp(feature, prlist[j]) == 0) {
if (su_casematch(feature, prlist[j])) {
feature = NULL;
break;
}
@ -478,7 +478,7 @@ int sip_has_feature(msg_list_t const *supported, char const *feature)
for (; supported; supported = supported->k_next)
if (supported->k_items)
for (i = 0; supported->k_items[i]; i++)
if (strcasecmp(feature, supported->k_items[i]) == 0)
if (su_casematch(feature, supported->k_items[i]))
return 1;
return 0;

View File

@ -39,6 +39,7 @@
#define MSG_HDR_T union sip_header_u
#include <sofia-sip/su_tagarg.h>
#include <sofia-sip/su_string.h>
#include "sofia-sip/sip_parser.h"
#include <sofia-sip/msg_mclass.h>
@ -231,7 +232,7 @@ int sip_version_d(char **ss, char const **ver)
char const *result;
size_t const version_size = sizeof(sip_version_2_0) - 1;
if (strncasecmp(s, sip_version_2_0, version_size) == 0 &&
if (su_casenmatch(s, sip_version_2_0, version_size) &&
!IS_TOKEN(s[version_size])) {
result = sip_version_2_0;
s += version_size;
@ -260,7 +261,7 @@ int sip_version_d(char **ss, char const **ver)
s[l1 + 1 + l2] = 0;
/* Compare again with compacted version */
if (strcasecmp(s, sip_version_2_0) == 0)
if (su_casematch(s, sip_version_2_0))
result = sip_version_2_0;
}
@ -459,10 +460,10 @@ issize_t sip_transport_d(char **ss, char const **ttransport)
char *s = *ss;
#define TRANSPORT_MATCH(t) \
(strncasecmp(s+7, t+7, sizeof(t)-8) == 0 && (IS_LWS(s[sizeof(t)])) \
(su_casenmatch(s + 7, t + 7, (sizeof t) - 8) && (IS_LWS(s[sizeof(t)])) \
&& (transport = t, s += sizeof(t) - 1))
if (strncasecmp(s, "SIP/2.0", 7) != 0 ||
if (!su_casenmatch(s, "SIP/2.0", 7) ||
(!TRANSPORT_MATCH(sip_transport_udp) &&
!TRANSPORT_MATCH(sip_transport_tcp) &&
!TRANSPORT_MATCH(sip_transport_sctp) &&
@ -502,13 +503,13 @@ issize_t sip_transport_d(char **ss, char const **ttransport)
pt[pt_len] = '\0';
/* extra whitespace? */
if (!strcasecmp(transport, sip_transport_udp))
if (su_casematch(transport, sip_transport_udp))
transport = sip_transport_udp;
else if (!strcasecmp(transport, sip_transport_tcp))
else if (su_casematch(transport, sip_transport_tcp))
transport = sip_transport_tcp;
else if (!strcasecmp(transport, sip_transport_sctp))
else if (su_casematch(transport, sip_transport_sctp))
transport = sip_transport_sctp;
else if (!strcasecmp(transport, sip_transport_tls))
else if (su_casematch(transport, sip_transport_tls))
transport = sip_transport_tls;
}
}
@ -526,10 +527,10 @@ isize_t sip_transport_xtra(char const *transport)
transport == sip_transport_tcp ||
transport == sip_transport_sctp ||
transport == sip_transport_tls ||
strcasecmp(transport, sip_transport_udp) == 0 ||
strcasecmp(transport, sip_transport_tcp) == 0 ||
strcasecmp(transport, sip_transport_sctp) == 0 ||
strcasecmp(transport, sip_transport_tls) == 0)
su_casematch(transport, sip_transport_udp) ||
su_casematch(transport, sip_transport_tcp) ||
su_casematch(transport, sip_transport_sctp) ||
su_casematch(transport, sip_transport_tls))
return 0;
return MSG_STRING_SIZE(transport);
@ -546,13 +547,13 @@ void sip_transport_dup(char **pp, char const **dd, char const *s)
*dd = s;
else if (s == sip_transport_tls)
*dd = s;
else if (strcasecmp(s, sip_transport_udp) == 0)
else if (su_casematch(s, sip_transport_udp))
*dd = sip_transport_udp;
else if (strcasecmp(s, sip_transport_tcp) == 0)
else if (su_casematch(s, sip_transport_tcp))
*dd = sip_transport_tcp;
else if (strcasecmp(s, sip_transport_sctp) == 0)
else if (su_casematch(s, sip_transport_sctp))
*dd = sip_transport_sctp;
else if (strcasecmp(s, sip_transport_tls) == 0)
else if (su_casematch(s, sip_transport_tls))
*dd = sip_transport_tls;
else
MSG_STRING_DUP(*pp, *dd, s);

View File

@ -67,8 +67,8 @@ int sip_prefs_parse(union sip_pref *sp,
if (old_type == sp_init) {
if (s[0] == '\0' ||
strcasecmp(s, "TRUE") == 0 ||
strcasecmp(s, "\"TRUE\"") == 0) {
su_casematch(s, "TRUE") ||
su_casematch(s, "\"TRUE\"")) {
/* Boolean */
sp->sp_type = sp_literal;
sp->sp_literal.spl_value = "TRUE";
@ -76,8 +76,8 @@ int sip_prefs_parse(union sip_pref *sp,
*return_negation = 0;
*in_out_s = s + strlen(s);
return 1;
} else if (strcasecmp(s, "FALSE") == 0 ||
strcasecmp(s, "\"FALSE\"") == 0) {
} else if (su_casematch(s, "FALSE") ||
su_casematch(s, "\"FALSE\"")) {
/* Boolean */
sp->sp_type = sp_literal;
sp->sp_literal.spl_value = "FALSE";
@ -213,8 +213,8 @@ int sip_prefs_match(union sip_pref const *a,
case sp_literal:
return
a->sp_literal.spl_length == b->sp_literal.spl_length &&
strncasecmp(a->sp_literal.spl_value, b->sp_literal.spl_value,
a->sp_literal.spl_length) == 0;
su_casenmatch(a->sp_literal.spl_value, b->sp_literal.spl_value,
a->sp_literal.spl_length);
case sp_string:
return
a->sp_string.sps_length == b->sp_string.sps_length &&
@ -307,7 +307,7 @@ int sip_prefs_matching(char const *pvalue,
int sip_is_callerpref(char const *param)
{
#define MATCH(s) \
(strncasecmp(param + 1, s + 1, strlen(s) - 1) == 0 && \
(su_casenmatch(param + 1, s + 1, strlen(s) - 1) && \
(param[strlen(s)] == '=' || param[strlen(s)] == '\0'))
int xor = 0, base = 0;

View File

@ -160,7 +160,7 @@ static int sip_reason_update(msg_common_t *h,
re->re_cause = NULL;
re->re_text = NULL;
}
#define MATCH(s) (namelen == strlen(#s) && !strncasecmp(name, #s, strlen(#s)))
#define MATCH(s) (namelen == strlen(#s) && su_casenmatch(name, #s, strlen(#s)))
else if (MATCH(cause)) {
re->re_cause = value;

View File

@ -289,7 +289,7 @@ static int sip_referred_by_update(msg_common_t *h,
if (name == NULL) {
b->b_cid = NULL;
}
else if (namelen == strlen("cid") && !strncasecmp(name, "cid", namelen)) {
else if (namelen == strlen("cid") && su_casenmatch(name, "cid", namelen)) {
b->b_cid = value;
}
@ -425,7 +425,7 @@ static int sip_replaces_update(msg_common_t *h,
rp->rp_from_tag = NULL;
rp->rp_early_only = 0;
}
#define MATCH(s) (namelen == strlen(#s) && !strncasecmp(name, #s, strlen(#s)))
#define MATCH(s) (namelen == strlen(#s) && su_casenmatch(name, #s, strlen(#s)))
else if (MATCH(to-tag)) {
rp->rp_to_tag = value;
@ -502,8 +502,8 @@ issize_t sip_refer_sub_d(su_home_t *home,
if (msg_token_d(&s, &rs->rs_value) < 0)
return -1;
if (strcasecmp(rs->rs_value, "false") &&
strcasecmp(rs->rs_value, "true"))
if (!su_casematch(rs->rs_value, "false") &&
!su_casematch(rs->rs_value, "true"))
return -1;
if (*s)

View File

@ -525,7 +525,7 @@ static int sip_security_agree_update(msg_common_t *h,
sa->sa_d_qop = NULL;
sa->sa_d_ver = NULL;
}
#define MATCH(s) (namelen == strlen(#s) && !strncasecmp(name, #s, strlen(#s)))
#define MATCH(s) (namelen == strlen(#s) && su_casenmatch(name, #s, strlen(#s)))
else if (MATCH(q)) {
sa->sa_q = value;

View File

@ -154,7 +154,7 @@ static int sip_session_expires_update(msg_common_t *h,
x->x_refresher = NULL;
}
else if (namelen == strlen("refresher") &&
!strncasecmp(name, "refresher", namelen)) {
su_casenmatch(name, "refresher", namelen)) {
x->x_refresher = value;
}

View File

@ -450,15 +450,15 @@ tagi_t *sip_url_query_as_taglist(su_home_t *home, char const *query,
if (n == 0)
break;
if (n == 4 && strncasecmp(hnv, "body", 4) == 0)
if (n == 4 && su_casenmatch(hnv, "body", 4))
t = siptag_payload, hc = sip_payload_class;
else {
for (j = 0; (t = sip_tag_list[j]); j++) {
hc = (msg_hclass_t *)sip_tag_list[j]->tt_magic;
if (n == 1 && strncasecmp(hnv, hc->hc_short, 1) == 0)
if (n == 1 && su_casenmatch(hnv, hc->hc_short, 1))
break;
else if (n == (size_t)hc->hc_len &&
strncasecmp(hnv, hc->hc_name, n) == 0)
su_casenmatch(hnv, hc->hc_name, n))
break;
}
}

View File

@ -39,7 +39,7 @@
#include <sofia-sip/su_alloc.h>
#include <sofia-sip/su_strlst.h>
#include <sofia-sip/string0.h>
#include <sofia-sip/su_string.h>
#include "sofia-sip/sip_parser.h"
#include <sofia-sip/sip_header.h>
@ -59,8 +59,7 @@
#include <limits.h>
#include <ctype.h>
/**
* Compare two SIP addresses ( @From or @To headers).
/**Compare two SIP addresses ( @From or @To headers).
*
* @retval nonzero if matching.
* @retval zero if not matching.
@ -69,13 +68,13 @@ int sip_addr_match(sip_addr_t const *a, sip_addr_t const *b)
{
return
(a->a_tag == NULL || b->a_tag == NULL ||
strcmp(a->a_tag, b->a_tag) == 0)
su_casematch(a->a_tag, b->a_tag))
&&
str0casecmp(a->a_host, b->a_host) == 0
su_casematch(a->a_host, b->a_host)
&&
str0cmp(a->a_user, b->a_user) == 0
su_strmatch(a->a_user, b->a_user)
&&
str0cmp(a->a_url->url_scheme, b->a_url->url_scheme);
su_strmatch(a->a_url->url_scheme, b->a_url->url_scheme);
}
@ -164,7 +163,7 @@ sip_contact_create_from_via(su_home_t *home,
tp = v->v_protocol;
if (tp == sip_transport_udp ||
strcasecmp(tp, sip_transport_udp) == 0) /* Default is UDP */
su_casematch(tp, sip_transport_udp)) /* Default is UDP */
tp = NULL;
return sip_contact_create_from_via_with_transport(home, v, user, tp);
@ -253,7 +252,7 @@ sip_contact_string_from_via(su_home_t *home,
port = NULL;
}
if (transport && strncasecmp(transport, "SIP/2.0/", 8) == 0)
if (su_casenmatch(transport, "SIP/2.0/", 8))
transport += 8;
/* Make transport parameter lowercase */
@ -292,8 +291,8 @@ int sip_transport_has_tls(char const *transport_name)
/* transport name starts with TLS or SIP/2.0/TLS */
return
strncasecmp(transport_name, "TLS", 3) == 0 ||
strncasecmp(transport_name, sip_transport_tls, 11) == 0;
su_casenmatch(transport_name, "TLS", 3) ||
su_casenmatch(transport_name, sip_transport_tls, 11);
}
/**Perform sanity check on a SIP message
@ -339,9 +338,10 @@ sip_sanity_check(sip_t const *sip)
if (sip->sip_request->rq_method != sip->sip_cseq->cs_method)
return -1;
if (sip->sip_request->rq_method == sip_method_unknown &&
str0casecmp(sip->sip_request->rq_method_name,
sip->sip_cseq->cs_method_name))
!su_strmatch(sip->sip_request->rq_method_name,
sip->sip_cseq->cs_method_name))
return -1;
}
@ -810,10 +810,10 @@ int sip_security_verify_compare(sip_security_server_t const *s,
if (s == NULL || v == NULL)
return (s == NULL) - (v == NULL);
if ((retval = str0cmp(s->sa_mec, v->sa_mec)))
if ((retval = su_strcmp(s->sa_mec, v->sa_mec)))
return retval;
digest = strcasecmp(s->sa_mec, "Digest") == 0;
digest = su_casematch(s->sa_mec, "Digest");
s_params = s->sa_params, v_params = v->sa_params;
@ -828,13 +828,13 @@ int sip_security_verify_compare(sip_security_server_t const *s,
for (i = 0, j = 0;; i++, j++) {
if (digest && v_params[j] &&
strncasecmp(v_params[j], "d-ver=", 6) == 0) {
su_casenmatch(v_params[j], "d-ver=", 6)) {
if (return_d_ver)
*return_d_ver = v_params[j] + strlen("d-ver=");
j++;
}
retval = str0cmp(s_params[i], v_params[j]);
retval = su_strcmp(s_params[i], v_params[j]);
if (retval || s_params[i] == NULL || v_params[j] == NULL)
break;
@ -861,7 +861,7 @@ sip_security_client_select(sip_security_client_t const *client,
for (s = server; s; s = s->sa_next) {
for (c = client; c; c = c->sa_next) {
if (str0cmp(s->sa_mec, c->sa_mec) == 0)
if (su_strmatch(s->sa_mec, c->sa_mec))
return c;
}
}

View File

@ -60,6 +60,10 @@
#include <sofia-sip/sip_header.h>
#endif
#ifndef SOFIA_SIP_SU_STRING_H
#include <sofia-sip/su_string.h>
#endif
SOFIA_BEGIN_DECLS
/* ---------------------------------------------------------------------------

View File

@ -36,7 +36,7 @@
#include "config.h"
#include <stdio.h>
#include <sofia-sip/string0.h>
#include <sofia-sip/su_string.h>
#include <stddef.h>
#include <stdlib.h>
@ -62,7 +62,7 @@ int main(int ac, char *av[])
t = ((31 + 27) * 24) * 60 * 60;
delta = (365 * 24 + 6) * 60 * 60;
if (str0cmp(av[1], "-v") == 0)
if (su_strmatch(av[1], "-v"))
verbatim = 1, av++;
if ((s = av[1])) {