Commit 7b931799 authored by Pekka Pessi's avatar Pekka Pessi

url: added url_strip_param_string().

darcs-hash:20061005140634-65a35-cf011eb9cdb3bc357df25b14b1d7ea06e4fefe67.gz
parent bbc3d6bb
......@@ -147,7 +147,7 @@ SOFIAPUBFUN isize_t url_param(char const *params, char const *tag,
/** Check for a parameter. */
SOFIAPUBFUN int url_has_param(url_t const *url, char const *name);
/** Check for a presence of a parameter. */
/** Check for a presence of a parameter in string. */
SOFIAPUBFUN isize_t url_have_param(char const *params, char const *tag);
/** Add a parameter. */
......@@ -156,6 +156,9 @@ SOFIAPUBFUN int url_param_add(su_home_t *h, url_t *url, char const *param);
/** Strip transport-specific stuff away from URI. */
SOFIAPUBFUN int url_strip_transport(url_t *u);
/** Strip parameter away from URI. */
SOFIAPUBFUN char *url_strip_param_string(char *params, char const *name);
/** Test if url has any transport-specific stuff. */
SOFIAPUBFUN int url_have_transport(url_t const *u);
......
......@@ -342,6 +342,11 @@ int test_sip(void)
TEST_S(pu, s);
}
s = su_strdup(home, "ttl;transport=tcp;ttl=15;ttl=;method=INVITE;ttl");
TEST_1(s);
s = url_strip_param_string(s, "ttl");
TEST_S(s, "transport=tcp;method=INVITE");
u = url_hdup(home, (void*)"sip:u:p@host:5060;maddr=127.0.0.1;transport=tcp");
TEST_1(u);
TEST_1(url_have_transport(u));
......
......@@ -1290,6 +1290,52 @@ int url_param_add(su_home_t *h, url_t *url, char const *param)
return 0;
}
/** Remove a named parameter from url_param string.
*
* Remove a named parameter and its possible value from the URL parameter
* string (url_s##url_param).
*
* @return Pointer to modified string, or NULL if nothing is left in there.
*/
char *url_strip_param_string(char *params, char const *name)
{
if (params && name) {
size_t i, n = strlen(name), remove, rest;
for (i = 0; params[i];) {
if (strncasecmp(params + i, name, n) ||
(params[i + n] != '=' && params[i + n] != ';' && params[i + n])) {
i = i + strcspn(params + i, ";");
if (!params[i++])
break;
continue;
}
remove = n + strcspn(params + i + n, ";");
if (params[i + remove] == ';')
remove++;
if (i == 0) {
params += remove;
continue;
}
rest = strlen(params + i + remove);
if (!rest) {
if (i == 0)
return NULL; /* removed everything */
params[i - 1] = '\0';
break;
}
memmove(params + i, params + i + remove, rest + 1);
}
if (!params[0])
return NULL;
}
return params;
}
int url_string_p(url_string_t const *url)
{
return URL_STRING_P(url);
......@@ -1341,7 +1387,7 @@ int url_strip_transport2(url_t *url, int modify)
if (p != d) {
if (!modify)
return 1;
memcpy(d, p, n + 1);
memmove(d, p, n + 1);
}
}
d += n;
......
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