"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/osipparser2/osip_from.c" between
libosip2-5.0.0.tar.gz and libosip2-5.1.0.tar.gz

About: The GNU oSIP library is an implementation of SIP (RFC3261).

osip_from.c  (libosip2-5.0.0):osip_from.c  (libosip2-5.1.0)
skipping to change at line 103 skipping to change at line 103
osip_free (from); osip_free (from);
} }
/* parses the string as a from header. */ /* parses the string as a from header. */
/* INPUT : const char *string | pointer to a from string.*/ /* INPUT : const char *string | pointer to a from string.*/
/* OUTPUT: osip_from_t *from | structure to save results. */ /* OUTPUT: osip_from_t *from | structure to save results. */
/* returns -1 on error. */ /* returns -1 on error. */
int int
osip_from_parse (osip_from_t * from, const char *hvalue) osip_from_parse (osip_from_t * from, const char *hvalue)
{ {
const char *displayname=NULL; const char *displayname = NULL;
const char *url=NULL; const char *url = NULL;
const char *url_end=NULL; const char *url_end = NULL;
const char *gen_params; const char *gen_params;
const char *ptr; const char *ptr;
int i; int i;
if (from == NULL || hvalue == NULL) if (from == NULL || hvalue == NULL)
return OSIP_BADPARAMETER; return OSIP_BADPARAMETER;
/* How to parse: /* How to parse:
we'll place the pointers: we'll place the pointers:
displayname => beginning of displayname displayname => beginning of displayname
skipping to change at line 130 skipping to change at line 130
examples: examples:
jack <sip:amoizard@antisip.com>;tag=34erZ jack <sip:amoizard@antisip.com>;tag=34erZ
^ ^ ^ ^ ^ ^ ^ ^
sip:amoizard@antisip.com;tag=34erZ sip:amoizard@antisip.com;tag=34erZ
^ ^^ ^ ^^
*/ */
/* search for first char */ /* search for first char */
ptr = hvalue; ptr = hvalue;
while (ptr[0]!='\0') { while (ptr[0] != '\0') {
if (ptr[0]==' ') { if (ptr[0] == ' ') {
ptr++; ptr++;
continue; continue;
} }
if (ptr[0]=='"') { if (ptr[0] == '"') {
displayname = ptr; displayname = ptr;
break; break;
} }
break; break;
} }
if (ptr[0]=='\0') if (ptr[0] == '\0')
return OSIP_SUCCESS; /* empty header allowed? */ return OSIP_SUCCESS; /* empty header allowed? */
if (displayname!=NULL) { if (displayname != NULL) {
/* displayname IS A quoted-string (not a '*token') */ /* displayname IS A quoted-string (not a '*token') */
const char *second = NULL; const char *second = NULL;
/* search for quotes */ /* search for quotes */
second = __osip_quote_find (displayname + 1); second = __osip_quote_find (displayname + 1);
if (second == NULL) if (second == NULL)
return OSIP_SYNTAXERROR; /* missing quote */ return OSIP_SYNTAXERROR; /* missing quote */
if (second - displayname + 2 >= 2) { if (second - displayname + 2 >= 2) {
from->displayname = (char *) osip_malloc (second - displayname + 2); from->displayname = (char *) osip_malloc (second - displayname + 2);
if (from->displayname == NULL) if (from->displayname == NULL)
return OSIP_NOMEM; return OSIP_NOMEM;
osip_strncpy (from->displayname, displayname, second - displayname + 1); osip_strncpy (from->displayname, displayname, second - displayname + 1);
/* osip_clrspace(from->displayname); *//*should we do that? */ /* osip_clrspace(from->displayname); *//*should we do that? */
/* special case: "<sip:joe@big.org>" <sip:joe@really.big.com> */ /* special case: "<sip:joe@big.org>" <sip:joe@really.big.com> */
} /* else displayname is empty? */ } /* else displayname is empty? */
ptr=second+1; ptr = second + 1;
while (ptr[0]!='\0') { while (ptr[0] != '\0') {
if (ptr[0]==' ') { if (ptr[0] == ' ') {
ptr++; ptr++;
continue; continue;
} }
if (ptr[0]=='<') { if (ptr[0] == '<') {
url = ptr; url = ptr;
break; break;
} }
break; break;
} }
if (url == NULL) if (url == NULL)
return OSIP_SYNTAXERROR; /* '<' MUST exist */ return OSIP_SYNTAXERROR; /* '<' MUST exist */
if (ptr[1] == '\0') if (ptr[1] == '\0')
return OSIP_SYNTAXERROR; /* '<' MUST contain something */ return OSIP_SYNTAXERROR; /* '<' MUST contain something */
} else { }
else {
/* 1*(alphanum / "-" / "." / "!" / "%" / "*" / "_" / "+" / "`" / "'" / "~" ) */ /* 1*(alphanum / "-" / "." / "!" / "%" / "*" / "_" / "+" / "`" / "'" / "~" ) */
/* search for URL -> continue until non allowed element is found */ /* search for URL -> continue until non allowed element is found */
const char *beg=ptr; const char *beg = ptr;
while (ptr[0]!='\0') {
if (ptr[0]==' ') { while (ptr[0] != '\0') {
if (ptr[0] == ' ') {
ptr++; ptr++;
continue; continue;
} }
if (ptr[0] >= 'a' && ptr[0] <= 'z') { if (ptr[0] >= 'a' && ptr[0] <= 'z') {
ptr++; ptr++;
continue; continue;
} }
if (ptr[0] >= 'A' && ptr[0] <= 'Z') { if (ptr[0] >= 'A' && ptr[0] <= 'Z') {
ptr++; ptr++;
continue; continue;
} }
if (ptr[0] >= '0' && ptr[0] <= '9') { if (ptr[0] >= '0' && ptr[0] <= '9') {
ptr++; ptr++;
continue; continue;
} }
if (ptr[0]=='-' || ptr[0]=='.' || ptr[0]=='!' || ptr[0]=='%' || ptr[0]=='* ' || ptr[0]=='_' || ptr[0]=='+' || ptr[0]=='`' || ptr[0]=='\'' || ptr[0]=='~') { if (ptr[0] == '-' || ptr[0] == '.' || ptr[0] == '!' || ptr[0] == '%' || pt r[0] == '*' || ptr[0] == '_' || ptr[0] == '+' || ptr[0] == '`' || ptr[0] == '\'' || ptr[0] == '~') {
ptr++; ptr++;
continue; continue;
} }
url = ptr; url = ptr;
break; break;
} }
if (ptr[0]=='\0' || url==NULL) if (ptr[0] == '\0' || url == NULL)
return OSIP_SYNTAXERROR; /* not special char found? broken header? */ return OSIP_SYNTAXERROR; /* not special char found? broken header? */
if (ptr[0]=='<') { if (ptr[0] == '<') {
/* "<" found for URI */ /* "<" found for URI */
if (ptr[1] == '\0') if (ptr[1] == '\0')
return OSIP_SYNTAXERROR; /* '<' MUST contain something */ return OSIP_SYNTAXERROR; /* '<' MUST contain something */
if (url - beg>0) { if (url - beg > 0) {
from->displayname = (char *) osip_malloc (url - beg + 1); from->displayname = (char *) osip_malloc (url - beg + 1);
if (from->displayname == NULL) if (from->displayname == NULL)
return OSIP_NOMEM; return OSIP_NOMEM;
osip_clrncpy (from->displayname, hvalue, url - beg); osip_clrncpy (from->displayname, hvalue, url - beg);
} }
} else if (ptr[0]==':') { }
else if (ptr[0] == ':') {
/* this was a scheme for a URL? */ /* this was a scheme for a URL? */
url=beg; url = beg;
} else { }
else {
/* this is some non URL header? */ /* this is some non URL header? */
url=beg; url = beg;
} }
} }
/* define url_end and gen_params for name-addr */ /* define url_end and gen_params for name-addr */
if (url[0]=='<') { if (url[0] == '<') {
url++; url++;
ptr=url; ptr = url;
/* first occurence of ">" is the end of url */ /* first occurence of ">" is the end of url */
url_end = strchr (ptr, '>'); url_end = strchr (ptr, '>');
if (url_end==NULL) if (url_end == NULL)
return OSIP_SYNTAXERROR; return OSIP_SYNTAXERROR;
url_end--; url_end--;
gen_params = strchr (url_end, ';'); gen_params = strchr (url_end, ';');
} }
/* define url_end and gen_params for addr-spec */ /* define url_end and gen_params for addr-spec */
if (url_end==NULL) { if (url_end == NULL) {
/* rfc3261 // 20.10 Contact: /* rfc3261 // 20.10 Contact:
Even if the "display-name" is empty, the "name-addr" form MUST be Even if the "display-name" is empty, the "name-addr" form MUST be
used if the "addr-spec" contains a comma, semicolon, or question used if the "addr-spec" contains a comma, semicolon, or question
mark. There may or may not be LWS between the display-name and the mark. There may or may not be LWS between the display-name and the
"<". "<".
Conclusion: there is no semicolon (in username) before the semicolon generic Conclusion: there is no semicolon (in username) before the semicolon gene
param delimiter... */ ric param delimiter... */
gen_params = strchr (url, ';'); gen_params = strchr (url, ';');
if (gen_params != NULL) if (gen_params != NULL)
url_end = gen_params - 1; url_end = gen_params - 1;
else else
url_end = url + strlen (url); url_end = url + strlen (url);
} }
if (gen_params != NULL) { /* now we are sure a param exist */ if (gen_params != NULL) { /* now we are sure a param exist */
i = __osip_generic_param_parseall (&from->gen_params, gen_params); i = __osip_generic_param_parseall (&from->gen_params, gen_params);
if (i != 0) { if (i != 0) {
skipping to change at line 332 skipping to change at line 336
/* from rfc2543bis-04: for authentication related issue! /* from rfc2543bis-04: for authentication related issue!
"The To and From header fields always include the < and > "The To and From header fields always include the < and >
delimiters even if the display-name is empty." */ delimiters even if the display-name is empty." */
sprintf (buf, "<%s>", url); sprintf (buf, "<%s>", url);
osip_free (url); osip_free (url);
{ {
size_t plen; size_t plen;
char *tmp; char *tmp;
osip_list_iterator_t it; osip_list_iterator_t it;
osip_generic_param_t *u_param = (osip_generic_param_t*) osip_list_get_first( osip_generic_param_t *u_param = (osip_generic_param_t *) osip_list_get_first
&from->gen_params, &it); (&from->gen_params, &it);
while (u_param != OSIP_SUCCESS) { while (u_param != OSIP_SUCCESS) {
if (u_param->gvalue == NULL) if (u_param->gvalue == NULL)
plen = strlen (u_param->gname) + 2; plen = strlen (u_param->gname) + 2;
else else
plen = strlen (u_param->gname) + strlen (u_param->gvalue) + 3; plen = strlen (u_param->gname) + strlen (u_param->gvalue) + 3;
len = len + plen; len = len + plen;
buf = (char *) osip_realloc (buf, len); buf = (char *) osip_realloc (buf, len);
tmp = buf; tmp = buf;
tmp = tmp + strlen (tmp); tmp = tmp + strlen (tmp);
if (u_param->gvalue == NULL) if (u_param->gvalue == NULL)
snprintf (tmp, len - (tmp - buf), ";%s", u_param->gname); snprintf (tmp, len - (tmp - buf), ";%s", u_param->gname);
else else
snprintf (tmp, len - (tmp - buf), ";%s=%s", u_param->gname, u_param->gva lue); snprintf (tmp, len - (tmp - buf), ";%s=%s", u_param->gname, u_param->gva lue);
u_param = (osip_generic_param_t *) osip_list_get_next(&it); u_param = (osip_generic_param_t *) osip_list_get_next (&it);
} }
} }
*dest = buf; *dest = buf;
return OSIP_SUCCESS; return OSIP_SUCCESS;
} }
char * char *
osip_from_get_displayname (osip_from_t * from) osip_from_get_displayname (osip_from_t * from)
{ {
if (from == NULL) if (from == NULL)
skipping to change at line 464 skipping to change at line 469
if (0 != strcmp (from1->url->host, from2->url->host)) if (0 != strcmp (from1->url->host, from2->url->host))
return OSIP_UNDEFINED_ERROR; return OSIP_UNDEFINED_ERROR;
if (from1->url->username != NULL && from2->url->username != NULL) if (from1->url->username != NULL && from2->url->username != NULL)
if (0 != strcmp (from1->url->username, from2->url->username)) if (0 != strcmp (from1->url->username, from2->url->username))
return OSIP_UNDEFINED_ERROR; return OSIP_UNDEFINED_ERROR;
tag1 = NULL; tag1 = NULL;
tag2 = NULL; tag2 = NULL;
{ {
osip_list_iterator_t it; osip_list_iterator_t it;
osip_generic_param_t *u_param = (osip_generic_param_t*) osip_list_get_first( osip_generic_param_t *u_param = (osip_generic_param_t *) osip_list_get_first
&from1->gen_params, &it); (&from1->gen_params, &it);
while (u_param != OSIP_SUCCESS) { while (u_param != OSIP_SUCCESS) {
if (0 == strncmp (u_param->gname, "tag", 3)) { if (0 == strncmp (u_param->gname, "tag", 3)) {
tag1 = u_param->gvalue; tag1 = u_param->gvalue;
break; break;
} }
u_param = (osip_generic_param_t *) osip_list_get_next(&it); u_param = (osip_generic_param_t *) osip_list_get_next (&it);
} }
} }
{ {
osip_list_iterator_t it; osip_list_iterator_t it;
osip_generic_param_t *u_param = (osip_generic_param_t*) osip_list_get_first( osip_generic_param_t *u_param = (osip_generic_param_t *) osip_list_get_first
&from2->gen_params, &it); (&from2->gen_params, &it);
while (u_param != OSIP_SUCCESS) { while (u_param != OSIP_SUCCESS) {
if (0 == strncmp (u_param->gname, "tag", 3)) { if (0 == strncmp (u_param->gname, "tag", 3)) {
tag2 = u_param->gvalue; tag2 = u_param->gvalue;
break; break;
} }
u_param = (osip_generic_param_t *) osip_list_get_next(&it); u_param = (osip_generic_param_t *) osip_list_get_next (&it);
} }
} }
/* sounds like a BUG! /* sounds like a BUG!
if tag2 exists and tag1 does not, then it will if tag2 exists and tag1 does not, then it will
return OSIP_SUCCESS; return OSIP_SUCCESS;
in the first request, (INVITE) the To field does not in the first request, (INVITE) the To field does not
contain any tag. The response contains one! and the contain any tag. The response contains one! and the
response must match the request.... response must match the request....
*/ */
skipping to change at line 524 skipping to change at line 531
/* find '=' wich is the separator for one param */ /* find '=' wich is the separator for one param */
/* find ';' wich is the separator for multiple params */ /* find ';' wich is the separator for multiple params */
equal = next_separator (params + 1, '=', ';'); equal = next_separator (params + 1, '=', ';');
comma = strchr (params + 1, ';'); comma = strchr (params + 1, ';');
/* If comma points after value start quote, move it to after end quote */ /* If comma points after value start quote, move it to after end quote */
if (equal != NULL) { if (equal != NULL) {
const char *tmp; const char *tmp;
startquote=NULL;
for (tmp=equal+1;tmp[0]==' ';tmp++) { startquote = NULL;
for (tmp = equal + 1; tmp[0] == ' '; tmp++) {
} }
if (tmp[0]=='"') if (tmp[0] == '"')
startquote = tmp; startquote = tmp;
if (startquote != NULL && comma > startquote) { if (startquote != NULL && comma > startquote) {
comma = NULL; comma = NULL;
endquote = __osip_quote_find(startquote + 1); endquote = __osip_quote_find (startquote + 1);
if (endquote) if (endquote)
comma = strchr(endquote, ';'); comma = strchr (endquote, ';');
} }
} }
while (comma != NULL) { while (comma != NULL) {
if (equal == NULL) { if (equal == NULL) {
equal = comma; equal = comma;
pvalue = NULL; pvalue = NULL;
} }
else { else {
const char *tmp; const char *tmp;
/* check for NULL param with an '=' character */ /* check for NULL param with an '=' character */
tmp = equal + 1; tmp = equal + 1;
for (; *tmp == '\t' || *tmp == ' '; tmp++) { tmp += strspn (tmp, "\t ");
}
pvalue = NULL; pvalue = NULL;
if (*tmp != ',' && *tmp != '\0') { if (*tmp != ',' && *tmp != '\0') {
if (comma - equal < 2) if (comma - equal < 2)
return OSIP_SYNTAXERROR; return OSIP_SYNTAXERROR;
pvalue = (char *) osip_malloc (comma - equal); pvalue = (char *) osip_malloc (comma - equal);
if (pvalue == NULL) if (pvalue == NULL)
return OSIP_NOMEM; return OSIP_NOMEM;
osip_strncpy (pvalue, equal + 1, comma - equal - 1); osip_strncpy (pvalue, equal + 1, comma - equal - 1);
} }
} }
skipping to change at line 586 skipping to change at line 593
return OSIP_NOMEM; return OSIP_NOMEM;
} }
params = comma; params = comma;
equal = next_separator (params + 1, '=', ';'); equal = next_separator (params + 1, '=', ';');
comma = strchr (params + 1, ';'); comma = strchr (params + 1, ';');
/* If comma points after value start quote, move it to after end quote */ /* If comma points after value start quote, move it to after end quote */
if (equal != NULL) { if (equal != NULL) {
const char *tmp; const char *tmp;
startquote=NULL;
for (tmp=equal+1;tmp[0]==' ';tmp++) { startquote = NULL;
for (tmp = equal + 1; tmp[0] == ' '; tmp++) {
} }
if (tmp[0]=='"') if (tmp[0] == '"')
startquote = tmp; startquote = tmp;
if (startquote != NULL && comma > startquote) { if (startquote != NULL && comma > startquote) {
comma = NULL; comma = NULL;
endquote = __osip_quote_find(startquote + 1); endquote = __osip_quote_find (startquote + 1);
if (endquote) if (endquote)
comma = strchr(endquote, ';'); comma = strchr (endquote, ';');
} }
} }
} }
/* this is the last header (comma==NULL) */ /* this is the last header (comma==NULL) */
comma = params + strlen (params); comma = params + strlen (params);
if (equal == NULL) { if (equal == NULL) {
equal = comma; /* at the end */ equal = comma; /* at the end */
pvalue = NULL; pvalue = NULL;
if (equal - params < 2) { if (equal - params < 2) {
osip_free (pvalue); osip_free (pvalue);
return OSIP_SUCCESS; /* empty comma? */ return OSIP_SUCCESS; /* empty comma? */
} }
} }
else { else {
const char *tmp; const char *tmp;
/* check for NULL param with an '=' character */ /* check for NULL param with an '=' character */
tmp = equal + 1; tmp = equal + 1;
for (; *tmp == '\t' || *tmp == ' '; tmp++) { tmp += strspn (tmp, "\t ");
}
pvalue = NULL; pvalue = NULL;
if (*tmp != ',' && *tmp != '\0') { if (*tmp != ',' && *tmp != '\0') {
if (comma - equal < 2) if (comma - equal < 2)
return OSIP_SYNTAXERROR; return OSIP_SYNTAXERROR;
pvalue = (char *) osip_malloc (comma - equal); pvalue = (char *) osip_malloc (comma - equal);
if (pvalue == NULL) if (pvalue == NULL)
return OSIP_NOMEM; return OSIP_NOMEM;
osip_strncpy (pvalue, equal + 1, comma - equal - 1); osip_strncpy (pvalue, equal + 1, comma - equal - 1);
} }
} }
 End of changes. 40 change blocks. 
63 lines changed or deleted 70 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)