osip_body.c (libosip2-5.0.0) | : | osip_body.c (libosip2-5.1.0) | ||
---|---|---|---|---|
skipping to change at line 50 | skipping to change at line 50 | |||
(*body)->headers = (osip_list_t *) osip_malloc (sizeof (osip_list_t)); | (*body)->headers = (osip_list_t *) osip_malloc (sizeof (osip_list_t)); | |||
if ((*body)->headers == NULL) { | if ((*body)->headers == NULL) { | |||
osip_free (*body); | osip_free (*body); | |||
*body = NULL; | *body = NULL; | |||
return OSIP_NOMEM; | return OSIP_NOMEM; | |||
} | } | |||
osip_list_init ((*body)->headers); | osip_list_init ((*body)->headers); | |||
return OSIP_SUCCESS; | return OSIP_SUCCESS; | |||
} | } | |||
/** | ||||
* Fill the body of message. | ||||
* @param sip The structure to store results. | ||||
* @param buf The pointer to the start of body. | ||||
* @param length The length of body; | ||||
*/ | ||||
int | int | |||
osip_message_set_body (osip_message_t * sip, const char *buf, size_t length) | osip_message_set_body (osip_message_t * sip, const char *buf, size_t length) | |||
{ | { | |||
osip_body_t *body; | osip_body_t *body; | |||
int i; | int i; | |||
i = osip_body_init (&body); | i = osip_body_init (&body); | |||
if (i != 0) | if (i != 0) | |||
return i; | return i; | |||
i = osip_body_parse (body, buf, length); | i = osip_body_parse (body, buf, length); | |||
skipping to change at line 267 | skipping to change at line 261 | |||
/* really store the header in the sip structure */ | /* really store the header in the sip structure */ | |||
if (osip_strncasecmp (hname, "content-type", 12) == 0) | if (osip_strncasecmp (hname, "content-type", 12) == 0) | |||
i = osip_body_set_contenttype (body, hvalue); | i = osip_body_set_contenttype (body, hvalue); | |||
else | else | |||
i = osip_body_set_header (body, hname, hvalue); | i = osip_body_set_header (body, hname, hvalue); | |||
osip_free (hname); | osip_free (hname); | |||
osip_free (hvalue); | osip_free (hvalue); | |||
if (i != 0) | if (i != 0) | |||
return i; | return i; | |||
if (strncmp (end_of_line, CRLF, 2) == 0 || strncmp (end_of_line, "\n", 1) == 0 || strncmp (end_of_line, "\r", 1) == 0) { | if (strncmp (end_of_line, OSIP_CRLF, 2) == 0 || strncmp (end_of_line, "\n", 1) == 0 || strncmp (end_of_line, "\r", 1) == 0) { | |||
*next_body = end_of_line; | *next_body = end_of_line; | |||
return OSIP_SUCCESS; | return OSIP_SUCCESS; | |||
} | } | |||
start_of_line = end_of_line; | start_of_line = end_of_line; | |||
} | } | |||
} | } | |||
int | int | |||
osip_body_parse (osip_body_t * body, const char *start_of_body, size_t length) | osip_body_parse (osip_body_t * body, const char *start_of_body, size_t length) | |||
{ | { | |||
skipping to change at line 316 | skipping to change at line 310 | |||
return OSIP_BADPARAMETER; | return OSIP_BADPARAMETER; | |||
start_of_osip_body_header = start_of_body; | start_of_osip_body_header = start_of_body; | |||
i = osip_body_parse_header (body, start_of_osip_body_header, &end_of_osip_body _header); | i = osip_body_parse_header (body, start_of_osip_body_header, &end_of_osip_body _header); | |||
if (i != 0) | if (i != 0) | |||
return i; | return i; | |||
start_of_osip_body_header = end_of_osip_body_header; | start_of_osip_body_header = end_of_osip_body_header; | |||
/* set the real start of body */ | /* set the real start of body */ | |||
if (strncmp (start_of_osip_body_header, CRLF, 2) == 0) | if (strncmp (start_of_osip_body_header, OSIP_CRLF, 2) == 0) | |||
start_of_osip_body_header = start_of_osip_body_header + 2; | start_of_osip_body_header = start_of_osip_body_header + 2; | |||
else { | else { | |||
if ((strncmp (start_of_osip_body_header, "\n", 1) == 0) | if ((strncmp (start_of_osip_body_header, "\n", 1) == 0) | |||
|| (strncmp (start_of_osip_body_header, "\r", 1) == 0)) | || (strncmp (start_of_osip_body_header, "\r", 1) == 0)) | |||
start_of_osip_body_header = start_of_osip_body_header + 1; | start_of_osip_body_header = start_of_osip_body_header + 1; | |||
else | else | |||
return OSIP_SYNTAXERROR; /* message does not end with CRLFCRLF, CRCR or L FLF */ | return OSIP_SYNTAXERROR; /* message does not end with CRLFCRLF, CRCR or L FLF */ | |||
} | } | |||
end_of_osip_body_header = start_of_body + length; | end_of_osip_body_header = start_of_body + length; | |||
skipping to change at line 390 | skipping to change at line 384 | |||
size_t len; | size_t len; | |||
len = tmp_body - ptr; | len = tmp_body - ptr; | |||
length = length + strlen (tmp) + 4; | length = length + strlen (tmp) + 4; | |||
ptr = osip_realloc (ptr, length); | ptr = osip_realloc (ptr, length); | |||
tmp_body = ptr + len; | tmp_body = ptr + len; | |||
} | } | |||
tmp_body = osip_str_append (tmp_body, tmp); | tmp_body = osip_str_append (tmp_body, tmp); | |||
osip_free (tmp); | osip_free (tmp); | |||
tmp_body = osip_strn_append (tmp_body, CRLF, 2); | tmp_body = osip_strn_append (tmp_body, OSIP_CRLF, 2); | |||
} | } | |||
{ | { | |||
osip_list_iterator_t it; | osip_list_iterator_t it; | |||
osip_header_t *header = (osip_header_t *) osip_list_get_first(body->headers, | osip_header_t *header = (osip_header_t *) osip_list_get_first (body->headers | |||
&it); | , &it); | |||
while (header != OSIP_SUCCESS) { | while (header != OSIP_SUCCESS) { | |||
i = osip_header_to_str (header, &tmp); | i = osip_header_to_str (header, &tmp); | |||
if (i != 0) { | if (i != 0) { | |||
osip_free (ptr); | osip_free (ptr); | |||
return i; | return i; | |||
} | } | |||
if (length < tmp_body - ptr + strlen (tmp) + 4) { | if (length < tmp_body - ptr + strlen (tmp) + 4) { | |||
size_t len; | size_t len; | |||
len = tmp_body - ptr; | len = tmp_body - ptr; | |||
length = length + strlen (tmp) + 4; | length = length + strlen (tmp) + 4; | |||
ptr = osip_realloc (ptr, length); | ptr = osip_realloc (ptr, length); | |||
tmp_body = ptr + len; | tmp_body = ptr + len; | |||
} | } | |||
tmp_body = osip_str_append (tmp_body, tmp); | tmp_body = osip_str_append (tmp_body, tmp); | |||
osip_free (tmp); | osip_free (tmp); | |||
tmp_body = osip_strn_append (tmp_body, CRLF, 2); | tmp_body = osip_strn_append (tmp_body, OSIP_CRLF, 2); | |||
header = (osip_header_t *) osip_list_get_next(&it); | header = (osip_header_t *) osip_list_get_next (&it); | |||
} | } | |||
} | } | |||
if ((osip_list_size (body->headers) > 0) || (body->content_type != NULL)) { | if ((osip_list_size (body->headers) > 0) || (body->content_type != NULL)) { | |||
if (length < tmp_body - ptr + 3) { | if (length < tmp_body - ptr + 3) { | |||
size_t len; | size_t len; | |||
len = tmp_body - ptr; | len = tmp_body - ptr; | |||
length = length + 3 + body->length; /* add body->length, to avoid calling realloc often */ | length = length + 3 + body->length; /* add body->length, to avoid ca lling realloc often */ | |||
ptr = osip_realloc (ptr, length); | ptr = osip_realloc (ptr, length); | |||
tmp_body = ptr + len; | tmp_body = ptr + len; | |||
} | } | |||
tmp_body = osip_strn_append (tmp_body, CRLF, 2); | tmp_body = osip_strn_append (tmp_body, OSIP_CRLF, 2); | |||
} | } | |||
if (length < tmp_body - ptr + body->length + 4) { | if (length < tmp_body - ptr + body->length + 4) { | |||
size_t len; | size_t len; | |||
len = tmp_body - ptr; | len = tmp_body - ptr; | |||
length = length + body->length + 4; | length = length + body->length + 4; | |||
ptr = osip_realloc (ptr, length); | ptr = osip_realloc (ptr, length); | |||
tmp_body = ptr + len; | tmp_body = ptr + len; | |||
} | } | |||
memcpy (tmp_body, body->body, body->length); | memcpy (tmp_body, body->body, body->length); | |||
End of changes. 11 change blocks. | ||||
22 lines changed or deleted | 17 lines changed or added |