Commit 0a5c2262 authored by Pekka Pessi's avatar Pekka Pessi

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

darcs-hash:20090108205649-db55f-5fcf235445ca01c4a53423cb208cef3b1e8af687.gz
parent db70ea24
......@@ -42,6 +42,7 @@
#include <string.h>
#include <assert.h>
#include <sofia-sip/su_string.h>
#include <sofia-sip/msg_date.h>
#include <sofia-sip/bnf.h>
......@@ -238,7 +239,7 @@ issize_t msg_date_d(char const **ss, msg_time_t *date)
if (time_d(&s, &hour, &min, &sec) < 0) return -1;
if (*s) {
tz = s; skip_token(&s); skip_lws(&s);
if (strncasecmp(tz, "GMT", 3) && strncasecmp(tz, "UCT", 3))
if (!su_casenmatch(tz, "GMT", 3) && !su_casenmatch(tz, "UCT", 3))
return -1;
}
}
......
......@@ -47,6 +47,7 @@
#include <sofia-sip/su.h>
#include <sofia-sip/su_alloc.h>
#include <sofia-sip/su_string.h>
#include "msg_internal.h"
#include "sofia-sip/msg_parser.h"
......@@ -351,7 +352,7 @@ msg_href_t const *msg_find_hclass(msg_mclass_t const *mc,
/* long form */
for (hr = NULL; (hc = mc->mc_hash[i].hr_class); i = (i + 1) % N) {
if (m == hc->hc_len && strncasecmp(s, hc->hc_name, m) == 0) {
if (m == hc->hc_len && su_casenmatch(s, hc->hc_name, m)) {
hr = &mc->mc_hash[i];
break;
}
......
......@@ -38,14 +38,8 @@
#define _GNU_SOURCE 1
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include <assert.h>
#include <sofia-sip/su_alloc.h>
#include <sofia-sip/su_string.h>
#include "msg_internal.h"
#include "sofia-sip/msg.h"
......@@ -54,16 +48,18 @@
#include <sofia-sip/su_uniqueid.h>
#include <sofia-sip/su_errno.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include <assert.h>
#if !HAVE_MEMMEM
void *memmem(const void *haystack, size_t haystacklen,
const void *needle, size_t needlelen);
#endif
size_t memspn(const void *mem, size_t memlen,
const void *accept, size_t acceptlen);
size_t memcspn(const void *mem, size_t memlen,
const void *reject, size_t rejectlen);
/** Protocol version of MIME */
char const msg_mime_version_1_0[] = "MIME/1.0";
......@@ -154,7 +150,7 @@ char const msg_mime_version_1_0[] = "MIME/1.0";
* argument to msg_multipart_parse() function:
* @code
* if (sip->sip_content_type &&
* strncasecmp(sip->sip_content_type, "multipart/", 10) == 0) {
* su_casenmatch(sip->sip_content_type, "multipart/", 10)) {
* msg_multipart_t *mp;
*
* if (sip->sip_multipart)
......@@ -316,7 +312,7 @@ msg_multipart_search_boundary(su_home_t *home, char const *p, size_t len)
/* Boundary looks like LF -- string SP* [CR] LF */
if (memcmp("--", p, 2) == 0) {
/* We can be at boundary beginning, there is no CR LF */
m = 2 + memspn(p + 2, len - 2, bchars, bchars_len);
m = 2 + su_memspn(p + 2, len - 2, bchars, bchars_len);
if (m + 2 >= len)
return NULL;
crlf = p[m] == '\r' ? 1 + (p[m + 1] == '\n') : (p[m] == '\n');
......@@ -336,7 +332,7 @@ msg_multipart_search_boundary(su_home_t *home, char const *p, size_t len)
/* Look for LF -- */
for (;(p = memmem(p, end - p, LF "--", 3)); p += 3) {
len = end - p;
m = 3 + memspn(p + 3, len - 3, bchars, bchars_len);
m = 3 + su_memspn(p + 3, len - 3, bchars, bchars_len);
if (m + 2 >= len)
return NULL;
crlf = p[m] == '\r' ? 1 + (p[m + 1] == '\n') : (p[m] == '\n');
......@@ -1146,7 +1142,7 @@ int msg_accept_update(msg_common_t *h,
if (name == NULL) {
ac->ac_q = NULL;
}
else if (namelen == 1 && strncasecmp(name, "q", 1) == 0) {
else if (namelen == 1 && su_casenmatch(name, "q", 1)) {
/* XXX - check for invalid value? */
ac->ac_q = value;
}
......@@ -1233,7 +1229,7 @@ int msg_accept_any_update(msg_common_t *h,
if (name == NULL) {
aa->aa_q = NULL;
}
else if (namelen == 1 && strncasecmp(name, "q", 1) == 0) {
else if (namelen == 1 && su_casenmatch(name, "q", 1)) {
aa->aa_q = value;
}
......@@ -1523,10 +1519,10 @@ int msg_content_disposition_update(msg_common_t *h,
cd->cd_handling = NULL, cd->cd_required = 0, cd->cd_optional = 0;
}
else if (namelen == strlen("handling") &&
strncasecmp(name, "handling", namelen) == 0) {
su_casenmatch(name, "handling", namelen)) {
cd->cd_handling = value;
cd->cd_required = strcasecmp(value, "required") == 0;
cd->cd_optional = strcasecmp(value, "optional") == 0;
cd->cd_required = su_casematch(value, "required");
cd->cd_optional = su_casematch(value, "optional");
}
return 0;
......
......@@ -47,6 +47,7 @@
#include <sofia-sip/su.h>
#include <sofia-sip/su_alloc.h>
#include <sofia-sip/su_string.h>
#include "msg_internal.h"
#include "sofia-sip/msg_parser.h"
......@@ -871,7 +872,7 @@ int msg_header_param_modify(su_home_t *home, msg_common_t *h,
}
}
else {
if (strncasecmp(maybe, param, plen) == 0 &&
if (su_casenmatch(maybe, param, plen) &&
(maybe[plen] == '=' || maybe[plen] == 0))
break;
}
......@@ -1212,7 +1213,7 @@ msg_param_t msg_params_find(msg_param_t const params[], msg_param_t token)
for (i = 0; params[i]; i++) {
msg_param_t param = params[i];
if (strncasecmp(param, token, n) == 0) {
if (su_casenmatch(param, token, n)) {
if (param[n] == '=')
return param + n + 1;
else if (param[n] == 0)
......@@ -1246,7 +1247,7 @@ msg_param_t *msg_params_find_slot(msg_param_t params[], msg_param_t token)
for (i = 0; params[i]; i++) {
msg_param_t param = params[i];
if (strncasecmp(param, token, n) == 0) {
if (su_casenmatch(param, token, n)) {
if (param[n] == '=')
return params + i;
else if (param[n] == 0 || token[n - 1] == '=')
......@@ -1295,7 +1296,7 @@ int msg_params_replace(su_home_t *home,
for (i = 0; params[i]; i++) {
msg_param_t maybe = params[i];
if (!(strncasecmp(maybe, param, n))) {
if (su_casenmatch(maybe, param, n)) {
if (maybe[n] == '=' || maybe[n] == 0) {
params[i] = param;
return 1;
......@@ -1327,7 +1328,7 @@ int msg_params_remove(msg_param_t *params, msg_param_t param)
for (i = 0; params[i]; i++) {
msg_param_t maybe = params[i];
if (strncasecmp(maybe, param, n) == 0) {
if (su_casenmatch(maybe, param, n)) {
if (maybe[n] == '=' || maybe[n] == 0) {
/* Remove */
do {
......@@ -1415,10 +1416,10 @@ int msg_param_prune(msg_param_t const d[], msg_param_t p, unsigned prune)
for (i = 0; d[i]; i++) {
if ((prune == 1 &&
strncasecmp(p, d[i], nlen) == 0
su_casenmatch(p, d[i], nlen)
&& (d[i][nlen] == '=' || d[i][nlen] == '\0'))
||
(prune == 2 && strcasecmp(p, d[i]) == 0)
(prune == 2 && su_casematch(p, d[i]))
||
(prune == 3 && strcmp(p, d[i]) == 0))
return 1;
......@@ -1649,7 +1650,7 @@ int msg_params_cmp(char const * const a[], char const * const b[])
if (*a == NULL || *b == NULL)
return (*a != NULL) - (*b != NULL);
nlen = strcspn(*a, "=");
if ((c = strncasecmp(*a, *b, nlen)))
if ((c = su_strncasecmp(*a, *b, nlen)))
return c;
if ((c = strcmp(*a + nlen, *b + nlen)))
return c;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment