"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/osipparser2/osip_message_to_str.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_to_str.c  (libosip2-5.0.0):osip_message_to_str.c  (libosip2-5.1.0)
skipping to change at line 207 skipping to change at line 207
*_string = NULL; *_string = NULL;
*_message = NULL; *_message = NULL;
return OSIP_NOMEM; return OSIP_NOMEM;
} }
*_string = string; *_string = string;
message = string + size; message = string + size;
} }
message = osip_str_append (message, tmp); message = osip_str_append (message, tmp);
osip_free (tmp); osip_free (tmp);
message = osip_strn_append (message, CRLF, 2); message = osip_strn_append (message, OSIP_CRLF, 2);
} }
*_string = string; *_string = string;
*_message = message; *_message = message;
*next = message; *next = message;
return OSIP_SUCCESS; return OSIP_SUCCESS;
} }
static int static int
strcat_headers_one_per_line (char **_string, size_t * malloc_size, char **_messa ge, osip_list_t * headers, char *header, size_t size_of_header, int (*xxx_to_str ) (void *, char **), char **next) strcat_headers_one_per_line (char **_string, size_t * malloc_size, char **_messa ge, osip_list_t * headers, char *header, size_t size_of_header, int (*xxx_to_str ) (void *, char **), char **next)
{ {
char *string; char *string;
char *message; char *message;
char *tmp; char *tmp;
int i; int i;
osip_list_iterator_t it; osip_list_iterator_t it;
void *elt = osip_list_get_first(headers, &it); void *elt = osip_list_get_first (headers, &it);
string = *_string; string = *_string;
message = *_message; message = *_message;
while (elt != OSIP_SUCCESS) { while (elt != OSIP_SUCCESS) {
if (*malloc_size < message - string + 100 + size_of_header) if (*malloc_size < message - string + 100 + size_of_header)
/* take some memory avoid to osip_realloc too much often */ /* take some memory avoid to osip_realloc too much often */
{ /* should not happen often */ { /* should not happen often */
size_t size = message - string; size_t size = message - string;
skipping to change at line 272 skipping to change at line 272
osip_free (*_string); /* pointer for string */ osip_free (*_string); /* pointer for string */
*_string = NULL; *_string = NULL;
*_message = NULL; *_message = NULL;
return OSIP_NOMEM; return OSIP_NOMEM;
} }
*_string = string; *_string = string;
message = string + size; message = string + size;
} }
message = osip_str_append (message, tmp); message = osip_str_append (message, tmp);
osip_free (tmp); osip_free (tmp);
message = osip_strn_append (message, CRLF, 2); message = osip_strn_append (message, OSIP_CRLF, 2);
elt = osip_list_get_next(&it); elt = osip_list_get_next (&it);
} }
*_string = string; *_string = string;
*_message = message; *_message = message;
*next = message; *next = message;
return OSIP_SUCCESS; return OSIP_SUCCESS;
} }
/* return values: /* return values:
1: structure and buffer "message" are identical. 1: structure and buffer "message" are identical.
2: buffer "message" is not up to date with the structure info (call osip_mes sage_to_str to update it). 2: buffer "message" is not up to date with the structure info (call osip_mes sage_to_str to update it).
skipping to change at line 378 skipping to change at line 378
if (i != 0) { if (i != 0) {
if (!sipfrag) { if (!sipfrag) {
osip_free (*dest); osip_free (*dest);
*dest = NULL; *dest = NULL;
return i; return i;
} }
/* A start-line isn't required for message/sipfrag parts. */ /* A start-line isn't required for message/sipfrag parts. */
} }
else { else {
size_t message_len = strlen(tmp); size_t message_len = strlen (tmp);
if (_osip_message_realloc (&message, dest, message_len + 3, &malloc_size) < 0) { if (_osip_message_realloc (&message, dest, message_len + 3, &malloc_size) < 0) {
osip_free (tmp); osip_free (tmp);
*dest = NULL; *dest = NULL;
return OSIP_NOMEM; return OSIP_NOMEM;
} }
message = osip_str_append (message, tmp); message = osip_str_append (message, tmp);
osip_free (tmp); osip_free (tmp);
message = osip_strn_append (message, CRLF, 2); message = osip_strn_append (message, OSIP_CRLF, 2);
} }
{ {
struct to_str_table { struct to_str_table {
char header_name[30]; char header_name[30];
int header_length; int header_length;
osip_list_t *header_list; osip_list_t *header_list;
void *header_data; void *header_data;
int (*to_str) (void *, char **); int (*to_str) (void *, char **);
} }
skipping to change at line 482 skipping to change at line 483
return i; return i;
} }
message = next; message = next;
pos++; pos++;
} }
} }
{ {
osip_list_iterator_t it; osip_list_iterator_t it;
osip_header_t *header = (osip_header_t *) osip_list_get_first(&sip->headers, osip_header_t *header = (osip_header_t *) osip_list_get_first (&sip->headers
&it); , &it);
while (header != OSIP_SUCCESS) { while (header != OSIP_SUCCESS) {
size_t header_len = 0; size_t header_len = 0;
i = osip_header_to_str (header, &tmp); i = osip_header_to_str (header, &tmp);
if (i != 0) { if (i != 0) {
osip_free (*dest); osip_free (*dest);
*dest = NULL; *dest = NULL;
return i; return i;
} }
header_len = strlen (tmp); header_len = strlen (tmp);
if (_osip_message_realloc (&message, dest, header_len + 3, &malloc_size) < 0) { if (_osip_message_realloc (&message, dest, header_len + 3, &malloc_size) < 0) {
osip_free (tmp); osip_free (tmp);
*dest = NULL; *dest = NULL;
return OSIP_NOMEM; return OSIP_NOMEM;
} }
message = osip_str_append (message, tmp); message = osip_str_append (message, tmp);
osip_free (tmp); osip_free (tmp);
message = osip_strn_append (message, CRLF, 2); message = osip_strn_append (message, OSIP_CRLF, 2);
header = (osip_header_t *) osip_list_get_next(&it); header = (osip_header_t *) osip_list_get_next (&it);
} }
} }
/* we have to create the body before adding the contentlength */ /* we have to create the body before adding the contentlength */
/* add enough lenght for "Content-Length: " */ /* add enough lenght for "Content-Length: " */
if (_osip_message_realloc (&message, dest, 16, &malloc_size) < 0) if (_osip_message_realloc (&message, dest, 16, &malloc_size) < 0)
return OSIP_NOMEM; return OSIP_NOMEM;
if (sipfrag && osip_list_eol (&sip->bodies, 0)) { if (sipfrag && osip_list_eol (&sip->bodies, 0)) {
/* end of headers */ /* end of headers */
osip_strncpy (message, CRLF, 2); osip_strncpy (message, OSIP_CRLF, 2);
message = message + 2; message = message + 2;
/* same remark as at the beginning of the method */ /* same remark as at the beginning of the method */
sip->message_property = 1; sip->message_property = 1;
sip->message = osip_strdup (*dest); sip->message = osip_strdup (*dest);
sip->message_length = message - *dest; sip->message_length = message - *dest;
if (message_length != NULL) if (message_length != NULL)
*message_length = message - *dest; *message_length = message - *dest;
return OSIP_SUCCESS; /* it's all done */ return OSIP_SUCCESS; /* it's all done */
skipping to change at line 565 skipping to change at line 567
In fact, if extra spaces exist: the stack can't be used In fact, if extra spaces exist: the stack can't be used
to make user-agent that wants to make authentication... to make user-agent that wants to make authentication...
This should be changed... This should be changed...
*/ */
content_length_to_modify = message; content_length_to_modify = message;
message = osip_str_append (message, " "); message = osip_str_append (message, " ");
} }
/* } */ /* } */
message = osip_strn_append (message, CRLF, 2); message = osip_strn_append (message, OSIP_CRLF, 2);
/* end of headers */ /* end of headers */
message = osip_strn_append (message, CRLF, 2); message = osip_strn_append (message, OSIP_CRLF, 2);
start_of_bodies = message; start_of_bodies = message;
total_length = start_of_bodies - *dest; total_length = start_of_bodies - *dest;
if (osip_list_eol (&sip->bodies, 0)) { if (osip_list_eol (&sip->bodies, 0)) {
/* same remark as at the beginning of the method */ /* same remark as at the beginning of the method */
sip->message_property = 1; sip->message_property = 1;
sip->message = osip_strdup (*dest); sip->message = osip_strdup (*dest);
sip->message_length = total_length; sip->message_length = total_length;
if (message_length != NULL) if (message_length != NULL)
skipping to change at line 605 skipping to change at line 607
return OSIP_SYNTAXERROR; return OSIP_SYNTAXERROR;
} }
boundary = osip_malloc (len + 5); boundary = osip_malloc (len + 5);
if (boundary == NULL) { if (boundary == NULL) {
osip_free (*dest); osip_free (*dest);
*dest = NULL; *dest = NULL;
return OSIP_NOMEM; return OSIP_NOMEM;
} }
osip_strncpy (boundary, CRLF, 2); osip_strncpy (boundary, OSIP_CRLF, 2);
osip_strncpy (boundary + 2, "--", 2); osip_strncpy (boundary + 2, "--", 2);
if (ct_param->gvalue[0] == '"' && ct_param->gvalue[len - 1] == '"') if (ct_param->gvalue[0] == '"' && ct_param->gvalue[len - 1] == '"')
osip_strncpy (boundary + 4, ct_param->gvalue + 1, len - 2); osip_strncpy (boundary + 4, ct_param->gvalue + 1, len - 2);
else else
osip_strncpy (boundary + 4, ct_param->gvalue, len); osip_strncpy (boundary + 4, ct_param->gvalue, len);
} }
} }
{ {
osip_list_iterator_t it; osip_list_iterator_t it;
osip_body_t *body = (osip_body_t *) osip_list_get_first(&sip->bodies, &it); osip_body_t *body = (osip_body_t *) osip_list_get_first (&sip->bodies, &it);
while (body != OSIP_SUCCESS) { while (body != OSIP_SUCCESS) {
size_t body_length; size_t body_length;
if (boundary) { if (boundary) {
/* Needs at most 77 bytes, /* Needs at most 77 bytes,
last realloc allocate at least 100 bytes extra */ last realloc allocate at least 100 bytes extra */
message = osip_str_append (message, boundary); message = osip_str_append (message, boundary);
message = osip_strn_append (message, CRLF, 2); message = osip_strn_append (message, OSIP_CRLF, 2);
} }
i = osip_body_to_str (body, &tmp, &body_length); i = osip_body_to_str (body, &tmp, &body_length);
if (i != 0) { if (i != 0) {
osip_free (*dest); osip_free (*dest);
*dest = NULL; *dest = NULL;
if (boundary) if (boundary)
osip_free (boundary); osip_free (boundary);
return i; return i;
} }
if (malloc_size < message - *dest + 100 + body_length) { if (malloc_size < message - *dest + 100 + body_length) {
size_t size = message - *dest; size_t size = message - *dest;
int offset_of_body; int offset_of_body;
int offset_content_length_to_modify = 0; int offset_content_length_to_modify = 0;
offset_of_body = (int) (start_of_bodies - *dest); offset_of_body = (int) (start_of_bodies - *dest);
if (content_length_to_modify != NULL) if (content_length_to_modify != NULL)
offset_content_length_to_modify = (int) (content_length_to_modify - *de offset_content_length_to_modify = (int) (content_length_to_modify - *d
st); est);
malloc_size = message - *dest + body_length + 100; malloc_size = message - *dest + body_length + 100;
*dest = osip_realloc (*dest, malloc_size); *dest = osip_realloc (*dest, malloc_size);
if (*dest == NULL) { if (*dest == NULL) {
osip_free (tmp); /* fixed 09/Jun/2005 */ osip_free (tmp); /* fixed 09/Jun/2005 */
if (boundary) if (boundary)
osip_free (boundary); osip_free (boundary);
return OSIP_NOMEM; return OSIP_NOMEM;
} }
start_of_bodies = *dest + offset_of_body; start_of_bodies = *dest + offset_of_body;
if (content_length_to_modify != NULL) if (content_length_to_modify != NULL)
content_length_to_modify = *dest + offset_content_length_to_modify; content_length_to_modify = *dest + offset_content_length_to_modify;
message = *dest + size; message = *dest + size;
} }
memcpy (message, tmp, body_length); memcpy (message, tmp, body_length);
message[body_length] = '\0'; message[body_length] = '\0';
osip_free (tmp); osip_free (tmp);
message = message + body_length; message = message + body_length;
body = (osip_body_t *) osip_list_get_next(&it); body = (osip_body_t *) osip_list_get_next (&it);
} }
} }
if (boundary) { if (boundary) {
/* Needs at most 79 bytes, /* Needs at most 79 bytes,
last realloc allocate at least 100 bytes extra */ last realloc allocate at least 100 bytes extra */
message = osip_str_append (message, boundary); message = osip_str_append (message, boundary);
message = osip_strn_append (message, "--", 2); message = osip_strn_append (message, "--", 2);
message = osip_strn_append (message, CRLF, 2); message = osip_strn_append (message, OSIP_CRLF, 2);
osip_free (boundary); osip_free (boundary);
boundary = NULL; boundary = NULL;
} }
if (content_length_to_modify == NULL) { if (content_length_to_modify == NULL) {
osip_free (*dest); osip_free (*dest);
*dest = NULL; *dest = NULL;
return OSIP_SYNTAXERROR; return OSIP_SYNTAXERROR;
} }
/* we NOW have the length of bodies: */ /* we NOW have the length of bodies: */
{ {
size_t size = message - start_of_bodies; size_t size = message - start_of_bodies;
char tmp2[15]; char tmp2[15];
total_length += size; total_length += size;
snprintf (tmp2, 15, "%i", (int) size); snprintf (tmp2, 15, "%i", (int) size);
/* do not use osip_strncpy here! */ /* do not use osip_strncpy here! */
strncpy (content_length_to_modify + 5 - strlen (tmp2), tmp2, strlen (tmp2)); memcpy (content_length_to_modify + 5 - strlen (tmp2), tmp2, strlen (tmp2));
} }
/* same remark as at the beginning of the method */ /* same remark as at the beginning of the method */
sip->message_property = 1; sip->message_property = 1;
sip->message = osip_malloc (total_length + 1); sip->message = osip_malloc (total_length + 1);
if (sip->message != NULL) { if (sip->message != NULL) {
memcpy (sip->message, *dest, total_length); memcpy (sip->message, *dest, total_length);
sip->message[total_length] = '\0'; sip->message[total_length] = '\0';
sip->message_length = total_length; sip->message_length = total_length;
if (message_length != NULL) if (message_length != NULL)
 End of changes. 21 change blocks. 
53 lines changed or deleted 56 lines changed or added

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