Commit 85724e8f authored by Rafaël Carré's avatar Rafaël Carré

httpd: simplify MsgAdd

parent f170a378
...@@ -1297,36 +1297,30 @@ const char *httpd_MsgGet( const httpd_message_t *msg, const char *name ) ...@@ -1297,36 +1297,30 @@ const char *httpd_MsgGet( const httpd_message_t *msg, const char *name )
void httpd_MsgAdd( httpd_message_t *msg, const char *name, const char *psz_value, ... ) void httpd_MsgAdd( httpd_message_t *msg, const char *name, const char *psz_value, ... )
{ {
va_list args; httpd_header *p_tmp = realloc( msg->p_headers, sizeof(httpd_header) * (msg->i_headers + 1));
char *value = NULL; if (!p_tmp)
return;
va_start( args, psz_value ); msg->p_headers = p_tmp;
if( us_vasprintf( &value, psz_value, args ) == -1 )
value = NULL;
va_end( args );
if( value == NULL ) httpd_header *h = &msg->p_headers[msg->i_headers];
h->name = strdup(name);
if (!h->name)
return; return;
name = strdup( name ); h->value = NULL;
if( name == NULL )
{ va_list args;
free( value ); va_start( args, psz_value );
int ret = us_vasprintf(&h->value, psz_value, args);
va_end( args );
if (ret == -1 ) {
free(h->name);
return; return;
} }
httpd_header * p_tmp = realloc( msg->p_headers, sizeof(httpd_header) * (msg->i_headers + 1));
if(p_tmp)
{
msg->p_headers = p_tmp;
msg->p_headers[msg->i_headers].name = name;
msg->p_headers[msg->i_headers].value = value;
msg->i_headers++; msg->i_headers++;
}
else
{
free(name);
free(value);
}
} }
static void httpd_ClientInit( httpd_client_t *cl, mtime_t now ) static void httpd_ClientInit( httpd_client_t *cl, mtime_t now )
......
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