"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/osipparser2/osip_message_parse.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_message_parse.c  (libosip2-5.0.0):osip_message_parse.c  (libosip2-5.1.0)
skipping to change at line 259 skipping to change at line 259
} }
int int
__osip_find_next_occurence (const char *str, const char *buf, const char **index _of_str, const char *end_of_buf) __osip_find_next_occurence (const char *str, const char *buf, const char **index _of_str, const char *end_of_buf)
{ {
int i; int i;
*index_of_str = NULL; /* AMD fix */ *index_of_str = NULL; /* AMD fix */
if ((NULL == str) || (NULL == buf)) if ((NULL == str) || (NULL == buf))
return OSIP_BADPARAMETER; return OSIP_BADPARAMETER;
/* TODO? we may prefer strcasestr instead of strstr? */ /* TODO? we may prefer strcasestr instead of strstr? // TODO? with large binar
for (i = 0; i < 1000; i++) { y, it will break at 10000 loop with a syntax error */
for (i = 0; i < 10000; i++) {
*index_of_str = strstr (buf, str); *index_of_str = strstr (buf, str);
if (NULL == (*index_of_str)) { if (NULL == (*index_of_str)) {
/* if '\0' (when binary data is used) is located before the separator, /* if '\0' (when binary data is used) is located before the separator,
then we have to continue searching */ then we have to continue searching */
const char *ptr = buf + strlen (buf); const char *ptr = buf + strlen (buf);
if (end_of_buf - ptr > 0) { if (end_of_buf - ptr > 0) {
buf = ptr + 1; buf = ptr + 1;
continue; continue;
} }
skipping to change at line 432 skipping to change at line 432
int int
osip_message_set_multiple_header (osip_message_t * sip, char *hname, char *hvalu e) osip_message_set_multiple_header (osip_message_t * sip, char *hname, char *hvalu e)
{ {
int i; int i;
char *ptr, *p; /* current location of the search */ char *ptr, *p; /* current location of the search */
char *comma; /* This is the separator we are elooking for */ char *comma; /* This is the separator we are elooking for */
char *beg; /* beg of a header */ char *beg; /* beg of a header */
char *end; /* end of a header */ char *end; /* end of a header */
int inquotes, inuri; /* state for inside/outside of double-qoutes or URI */ int inquotes, inuri; /* state for inside/outside of double-qoutes or URI */
size_t hname_len;
/* Find header based upon lowercase comparison */ /* Find header based upon lowercase comparison */
osip_tolower (hname); osip_tolower (hname);
if (hvalue == NULL) { if (hvalue == NULL) {
i = osip_message_set__header (sip, hname, hvalue); i = osip_message_set__header (sip, hname, hvalue);
if (i != 0) if (i != 0)
return i; return i;
return OSIP_SUCCESS; return OSIP_SUCCESS;
} }
ptr = hvalue; ptr = hvalue;
comma = strchr (ptr, ','); comma = strchr (ptr, ',');
hname_len = strlen (hname); /* if there is a COMMA, we check if the header is allowed on multiple line fro
m an internal
if (comma == NULL || (hname_len == 4 && strncmp (hname, "date", 4) == 0) list: those headers are defined in rfc to support the following format.
|| (hname_len == 1 && strncmp (hname, "t", 1) == 0) header = "header-name" HCOLON header-value *(COMMA header-value)
|| (hname_len == 2 && strncmp (hname, "to", 2) == 0) We cannot guess for any other headers and thus, we will handle other header
|| (hname_len == 1 && strncmp (hname, "f", 1) == 0) s as one header.
|| (hname_len == 4 && strncmp (hname, "from", 4) == 0) */
|| (hname_len == 1 && strncmp (hname, "i", 1) == 0) if (comma == NULL || __osip_message_is_header_comma_separated (hname) != OSIP_
|| (hname_len == 7 && strncmp (hname, "call-id", 7) == 0) SUCCESS) {
|| (hname_len == 4 && strncmp (hname, "cseq", 4) == 0)
|| (hname_len == 1 && strncmp (hname, "s", 1) == 0)
|| (hname_len == 7 && strncmp (hname, "subject", 7) == 0)
|| (hname_len == 7 && strncmp (hname, "expires", 7) == 0)
|| (hname_len == 6 && strncmp (hname, "server", 6) == 0)
|| (hname_len == 10 && strncmp (hname, "user-agent", 10) == 0)
|| (hname_len == 16 && strncmp (hname, "www-authenticate", 16) == 0)
|| (hname_len == 19 && strncmp (hname, "authentication-info", 19) == 0)
|| (hname_len == 18 && strncmp (hname, "proxy-authenticate", 18) == 0)
|| (hname_len == 19 && strncmp (hname, "proxy-authorization", 19) == 0)
|| (hname_len == 25 && strncmp (hname, "proxy-authentication-info", 25) ==
0)
|| (hname_len == 12 && strncmp (hname, "organization", 12) == 0)
|| (hname_len == 13 && strncmp (hname, "authorization", 13) == 0)
|| (hname_len == 1 && strncmp (hname, "r", 1) == 0) /* refer-to */
|| (hname_len == 8 && strncmp (hname, "refer-to", 8) == 0)
|| (hname_len == 1 && strncmp (hname, "b", 1) == 0) /* referred-by */
|| (hname_len == 11 && strncmp (hname, "referred-by", 11) == 0))
/* there is no multiple header! likely */
/* to happen most of the time... */
/* or hname is a TEXT-UTF8-TRIM and may */
/* contain a comma. this is not a separator */
/* THIS DOES NOT WORK FOR UNKNOWN HEADER!!!! */
{
i = osip_message_set__header (sip, hname, hvalue); i = osip_message_set__header (sip, hname, hvalue);
if (i != 0) if (i != 0)
return i; return i;
return OSIP_SUCCESS; return OSIP_SUCCESS;
} }
beg = hvalue; beg = hvalue;
inquotes = 0; inquotes = 0;
inuri = 0; inuri = 0;
/* Seach for a comma that is not within quotes or a URI */ /* Seach for a comma that is not within quotes or a URI */
for (;; ptr++) for (;; ptr++) {
{ switch (*ptr) {
switch (*ptr)
{
case '"': case '"':
/* Check that the '"' is not escaped */ /* Check that the '"' is not escaped */
for (i = 0, p = ptr; p >= beg && *p == '\\'; p--, i++); for (i = 0, p = ptr - 1; p >= beg && *p == '\\'; p--, i++);
if (i % 2 == 0) if (i % 2 == 0)
inquotes = !inquotes; /* the '"' was not escaped */ inquotes = !inquotes; /* the '"' was not escaped */
break; break;
case '<': case '<':
if (!inquotes) if (!inquotes) {
{ if (!inuri) {
if (!inuri) if ((osip_strncasecmp (ptr + 1, "sip:", 4) == 0 || osip_strncasecmp (p
{ tr + 1, "sips:", 5) == 0 || osip_strncasecmp (ptr + 1, "http:", 5) == 0 || osip_
if((osip_strncasecmp(ptr+1, "sip:", 4) == 0 strncasecmp (ptr + 1, "https:", 6) == 0 || osip_strncasecmp (ptr + 1, "tel:", 4)
|| osip_strncasecmp(ptr+1, "sips:", 5) == 0 == 0)
|| osip_strncasecmp(ptr+1, "http:", 5) == 0 && strchr (ptr, '>'))
|| osip_strncasecmp(ptr+1, "https:", 6) == 0
|| osip_strncasecmp(ptr+1, "tel:", 4) == 0)
&& strchr(ptr, '>'))
inuri = 1; inuri = 1;
} }
/* /*
else { else {
if we found such sequence: "<sip:" "<sip:" ">" if we found such sequence: "<sip:" "<sip:" ">"
It might be a valid header containing data and not URIs. It might be a valid header containing data and not URIs.
Thus, we ignore inuri Thus, we ignore inuri
} }
*/ */
} }
break; break;
case '>': case '>':
if (!inquotes) if (!inquotes) {
{
if (inuri) if (inuri)
inuri = 0; inuri = 0;
} }
break; break;
case '\0': case '\0':
/* we discard any validation we tried: no valid uri detected */ /* we discard any validation we tried: no valid uri detected */
inquotes=0; inquotes = 0;
inuri=0; inuri = 0;
case ',': case ',':
if (!inquotes && !inuri) if (!inquotes && !inuri) {
{
char *avalue; char *avalue;
if (beg[0] == '\0') if (beg[0] == '\0')
return OSIP_SUCCESS; /* empty header */ return OSIP_SUCCESS; /* empty header */
end = ptr; end = ptr;
if (end - beg + 1 < 2) if (end - beg + 1 < 2) {
{ beg = end + 1;
beg=end+1; break; /* skip empty header */
break; /* skip empty header */ }
}
avalue = (char *) osip_malloc (end - beg + 1); avalue = (char *) osip_malloc (end - beg + 1);
if (avalue==NULL) if (avalue == NULL)
return OSIP_NOMEM; return OSIP_NOMEM;
osip_clrncpy (avalue, beg, end - beg); osip_clrncpy (avalue, beg, end - beg);
/* really store the header in the sip structure */ /* really store the header in the sip structure */
i = osip_message_set__header (sip, hname, avalue); i = osip_message_set__header (sip, hname, avalue);
osip_free (avalue); osip_free (avalue);
if (i != 0) if (i != 0)
return i; return i;
beg = end + 1; beg = end + 1;
} }
if (*ptr == '\0') if (*ptr == '\0')
skipping to change at line 707 skipping to change at line 669
/* update length (without CRLFCRLF */ /* update length (without CRLFCRLF */
length = length - (start_of_body - start_of_buf); /* fixed 24 08 2004 */ length = length - (start_of_body - start_of_buf); /* fixed 24 08 2004 */
if (length <= 0) if (length <= 0)
return OSIP_SYNTAXERROR; return OSIP_SYNTAXERROR;
if (sip->content_length != NULL) if (sip->content_length != NULL)
osip_body_len = osip_atoi (sip->content_length->value); osip_body_len = osip_atoi (sip->content_length->value);
else { else {
/* if content_length does not exist, set it. */ /* if content_length does not exist, set it. */
char tmp[16]; char tmp[16];
osip_body_len = length; osip_body_len = length;
sprintf (tmp, "%i", (int) osip_body_len); sprintf (tmp, "%i", (int) osip_body_len);
i = osip_message_set_content_length (sip, tmp); i = osip_message_set_content_length (sip, tmp);
if (i != 0) if (i != 0)
return i; return i;
} }
if (length < osip_body_len) { if (length < osip_body_len) {
OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Message was not receieved enterely. length=%i osip_body_len=%i\n", (int) length, (int) osip _body_len)); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Message was not receieved enterely. length=%i osip_body_len=%i\n", (int) length, (int) osip _body_len));
return OSIP_SYNTAXERROR; return OSIP_SYNTAXERROR;
} }
end_of_body = start_of_body + osip_body_len; end_of_body = start_of_body + osip_body_len;
tmp = osip_malloc (end_of_body - start_of_body + 2); tmp = osip_malloc (end_of_body - start_of_body + 2);
if (tmp == NULL) if (tmp == NULL)
skipping to change at line 785 skipping to change at line 748
if (i != 0) { if (i != 0) {
osip_free (sep_boundary); osip_free (sep_boundary);
return i; return i;
} }
/* this is the real beginning of body */ /* this is the real beginning of body */
start_of_body = start_of_body + len_sep_boundary + 1; start_of_body = start_of_body + len_sep_boundary + 1;
if ('\n' == start_of_body[0] || '\r' == start_of_body[0]) if ('\n' == start_of_body[0] || '\r' == start_of_body[0])
start_of_body++; start_of_body++;
/* if message body is empty or contains a single CR/LF */
if (end_of_body <= start_of_body) {
osip_free (sep_boundary);
return OSIP_SYNTAXERROR;
}
body_len = end_of_body - start_of_body; body_len = end_of_body - start_of_body;
/* Skip CR before end boundary. */ /* Skip CR before end boundary. */
if (*(end_of_body - 1) == '\r') if (*(end_of_body - 1) == '\r')
body_len--; body_len--;
tmp = osip_malloc (body_len + 2); tmp = osip_malloc (body_len + 2);
if (tmp == NULL) { if (tmp == NULL) {
osip_free (sep_boundary); osip_free (sep_boundary);
return OSIP_NOMEM; return OSIP_NOMEM;
skipping to change at line 838 skipping to change at line 807
tmp = osip_malloc (length + 2); tmp = osip_malloc (length + 2);
if (tmp == NULL) { if (tmp == NULL) {
OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not all ocate memory.\n")); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not all ocate memory.\n"));
return OSIP_NOMEM; return OSIP_NOMEM;
} }
beg = tmp; beg = tmp;
memcpy (tmp, buf, length); /* may contain binary data */ memcpy (tmp, buf, length); /* may contain binary data */
tmp[length] = '\0'; tmp[length] = '\0';
/* skip initial \r\n */ /* skip initial \r\n */
while (tmp[0] == '\r' || tmp[0] == '\n') tmp += strspn (tmp, "\r\n");
tmp++;
osip_util_replace_all_lws (tmp); osip_util_replace_all_lws (tmp);
/* parse request or status line */ /* parse request or status line */
i = __osip_message_startline_parse (sip, tmp, &next_header_index); i = __osip_message_startline_parse (sip, tmp, &next_header_index);
if (i != 0 && !sipfrag) { if (i != 0 && !sipfrag) {
OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not par se start line of message.\n")); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not par se start line of message.\n"));
osip_free (beg); osip_free (beg);
return i; return i;
} }
tmp = (char *) next_header_index; tmp = (char *) next_header_index;
skipping to change at line 861 skipping to change at line 829
i = msg_headers_parse (sip, tmp, &next_header_index); i = msg_headers_parse (sip, tmp, &next_header_index);
if (i != 0) { if (i != 0) {
OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "error in msg_ headers_parse()\n")); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "error in msg_ headers_parse()\n"));
osip_free (beg); osip_free (beg);
return i; return i;
} }
tmp = (char *) next_header_index; tmp = (char *) next_header_index;
if (sip->content_length != NULL && sip->content_length->value == NULL) { if (sip->content_length != NULL && sip->content_length->value == NULL) {
/* empty content_length header */ /* empty content_length header */
osip_content_length_free(sip->content_length); osip_content_length_free (sip->content_length);
sip->content_length=NULL; sip->content_length = NULL;
} }
if (sip->content_length != NULL && sip->content_length->value != NULL && atoi( sip->content_length->value) >0) { if (sip->content_length != NULL && sip->content_length->value != NULL && atoi (sip->content_length->value) > 0) {
/* body exist */ /* body exist */
} else if (sip->content_length == NULL && '\r' == next_header_index[0] && '\n' }
== next_header_index[1] && length - (tmp - beg) - (2) >0) { else if (sip->content_length == NULL && '\r' == next_header_index[0] && '\n' =
= next_header_index[1] && length - (tmp - beg) - (2) > 0) {
/* body exist */ /* body exist */
} else if (sip->content_length == NULL && '\n' == next_header_index[0] && leng }
th - (tmp - beg) - (1) >0) { else if (sip->content_length == NULL && '\n' == next_header_index[0] && length
- (tmp - beg) - (1) > 0) {
/* body exist */ /* body exist */
} else { }
else {
if (sip->content_length == NULL) if (sip->content_length == NULL)
osip_message_set_content_length (sip, "0"); osip_message_set_content_length (sip, "0");
osip_free (beg); osip_free (beg);
return OSIP_SUCCESS; /* no body found */ return OSIP_SUCCESS; /* no body found */
} }
i = msg_osip_body_parse (sip, tmp, &next_header_index, length - (tmp - beg)); i = msg_osip_body_parse (sip, tmp, &next_header_index, length - (tmp - beg));
osip_free (beg); osip_free (beg);
if (i != 0) { if (i != 0) {
OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "error in msg_ osip_body_parse()\n")); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "error in msg_ osip_body_parse()\n"));
skipping to change at line 959 skipping to change at line 930
int code; int code;
const char *reason; const char *reason;
}; };
static const struct code_to_reason reasons1xx[] = { static const struct code_to_reason reasons1xx[] = {
{100, "Trying"}, {100, "Trying"},
{180, "Ringing"}, {180, "Ringing"},
{181, "Call Is Being Forwarded"}, {181, "Call Is Being Forwarded"},
{182, "Queued"}, {182, "Queued"},
{183, "Session Progress"}, {183, "Session Progress"},
{199, "Early Dialog Terminated"},
}; };
static const struct code_to_reason reasons2xx[] = { static const struct code_to_reason reasons2xx[] = {
{200, "OK"}, {200, "OK"},
{202, "Accepted"}, {202, "Accepted"},
{204, "No Notification"},
}; };
static const struct code_to_reason reasons3xx[] = { static const struct code_to_reason reasons3xx[] = {
{300, "Multiple Choices"}, {300, "Multiple Choices"},
{301, "Moved Permanently"}, {301, "Moved Permanently"},
{302, "Moved Temporarily"}, {302, "Moved Temporarily"},
{305, "Use Proxy"}, {305, "Use Proxy"},
{380, "Alternative Service"}, {380, "Alternative Service"},
}; };
static const struct code_to_reason reasons4xx[] = { static const struct code_to_reason reasons4xx[] = {
{400, "Bad Request"}, {400, "Bad Request"},
skipping to change at line 994 skipping to change at line 967
{412, "Conditional Request Failed"}, {412, "Conditional Request Failed"},
{413, "Request Entity Too Large"}, {413, "Request Entity Too Large"},
{414, "Request-URI Too Long"}, {414, "Request-URI Too Long"},
{415, "Unsupported Media Type"}, {415, "Unsupported Media Type"},
{416, "Unsupported URI Scheme"}, {416, "Unsupported URI Scheme"},
{417, "Unknown Resource-Priority"}, {417, "Unknown Resource-Priority"},
{420, "Bad Extension"}, {420, "Bad Extension"},
{421, "Extension Required"}, {421, "Extension Required"},
{422, "Session Interval Too Small"}, {422, "Session Interval Too Small"},
{423, "Interval Too Brief"}, {423, "Interval Too Brief"},
{424, "Bad Location Information"},
{428, "Use Identity Header"},
{429, "Provide Referrer Identity"},
{430, "Flow Failed"},
{433, "Anonymity Disallowed"},
{436, "Bad Identity Info"},
{437, "Unsupported Credential"},
{438, "Invalid Identity Header"},
{439, "First Hop Lacks Outbound Support"},
{440, "Max-Breadth Exceeded"},
{469, "Bad Info Package"}, {469, "Bad Info Package"},
{470, "Consent Needed"},
{480, "Temporarily Unavailable"}, {480, "Temporarily Unavailable"},
{481, "Call/Transaction Does Not Exist"}, {481, "Call/Transaction Does Not Exist"},
{482, "Loop Detected"}, {482, "Loop Detected"},
{483, "Too Many Hops"}, {483, "Too Many Hops"},
{484, "Address Incomplete"}, {484, "Address Incomplete"},
{485, "Ambiguous"}, {485, "Ambiguous"},
{486, "Busy Here"}, {486, "Busy Here"},
{487, "Request Terminated"}, {487, "Request Terminated"},
{488, "Not Acceptable Here"}, {488, "Not Acceptable Here"},
{489, "Bad Event"}, {489, "Bad Event"},
{491, "Request Pending"}, {491, "Request Pending"},
{493, "Undecipherable"}, {493, "Undecipherable"},
{494, "Security Agreement Required"},
}; };
static const struct code_to_reason reasons5xx[] = { static const struct code_to_reason reasons5xx[] = {
{500, "Server Internal Error"}, {500, "Server Internal Error"},
{501, "Not Implemented"}, {501, "Not Implemented"},
{502, "Bad Gateway"}, {502, "Bad Gateway"},
{503, "Service Unavailable"}, {503, "Service Unavailable"},
{504, "Server Time-out"}, {504, "Server Time-out"},
{505, "Version Not Supported"}, {505, "Version Not Supported"},
{513, "Message Too Large"}, {513, "Message Too Large"},
{580, "Precondition Failure"},
}; };
static const struct code_to_reason reasons6xx[] = { static const struct code_to_reason reasons6xx[] = {
{600, "Busy Everywhere"}, {600, "Busy Everywhere"},
{603, "Decline"}, {603, "Decline"},
{604, "Does Not Exist Anywhere"}, {604, "Does Not Exist Anywhere"},
{606, "Not Acceptable"}, {606, "Not Acceptable"},
{607, "Unwanted"},
{687, "Dialog Terminated"} {687, "Dialog Terminated"}
}; };
const struct code_to_reason *reasons; const struct code_to_reason *reasons;
int len, i; int len, i;
switch (replycode / 100) { switch (replycode / 100) {
case 1: case 1:
reasons = reasons1xx; reasons = reasons1xx;
len = sizeof (reasons1xx) / sizeof (*reasons); len = sizeof (reasons1xx) / sizeof (*reasons);
break; break;
 End of changes. 30 change blocks. 
83 lines changed or deleted 76 lines changed or added

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