aboutsummaryrefslogtreecommitdiff
path: root/src/supplemental/http/http_msg.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/supplemental/http/http_msg.c')
-rw-r--r--src/supplemental/http/http_msg.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/src/supplemental/http/http_msg.c b/src/supplemental/http/http_msg.c
index ff9764bf..d6ab862e 100644
--- a/src/supplemental/http/http_msg.c
+++ b/src/supplemental/http/http_msg.c
@@ -77,12 +77,8 @@ http_headers_reset(nni_list *hdrs)
http_header *h;
while ((h = nni_list_first(hdrs)) != NULL) {
nni_list_remove(hdrs, h);
- if (h->name != NULL) {
- nni_strfree(h->name);
- }
- if (h->value != NULL) {
- nni_free(h->value, strlen(h->value) + 1);
- }
+ nni_strfree(h->name);
+ nni_strfree(h->value);
NNI_FREE_STRUCT(h);
}
}
@@ -181,13 +177,11 @@ http_set_header(nni_list *hdrs, const char *key, const char *val)
http_header *h;
NNI_LIST_FOREACH (hdrs, h) {
if (nni_strcasecmp(key, h->name) == 0) {
- char * news;
- size_t len = strlen(val) + 1;
- if ((news = nni_alloc(len)) == NULL) {
+ char *news;
+ if ((news = nni_strdup(val)) == NULL) {
return (NNG_ENOMEM);
}
- snprintf(news, len, "%s", val);
- nni_free(h->value, strlen(h->value) + 1);
+ nni_strfree(h->value);
h->value = news;
return (0);
}
@@ -200,12 +194,11 @@ http_set_header(nni_list *hdrs, const char *key, const char *val)
NNI_FREE_STRUCT(h);
return (NNG_ENOMEM);
}
- if ((h->value = nni_alloc(strlen(val) + 1)) == NULL) {
+ if ((h->value = nni_strdup(val)) == NULL) {
nni_strfree(h->name);
NNI_FREE_STRUCT(h);
return (NNG_ENOMEM);
}
- strncpy(h->value, val, strlen(val) + 1);
nni_list_append(hdrs, h);
return (0);
}
@@ -228,13 +221,13 @@ http_add_header(nni_list *hdrs, const char *key, const char *val)
http_header *h;
NNI_LIST_FOREACH (hdrs, h) {
if (nni_strcasecmp(key, h->name) == 0) {
- char * news;
- size_t len = strlen(h->value) + strlen(val) + 3;
- if ((news = nni_alloc(len)) == NULL) {
- return (NNG_ENOMEM);
+ char *news;
+ int rv;
+ rv = nni_asprintf(&news, "%s, %s", h->value, val);
+ if (rv != 0) {
+ return (rv);
}
- snprintf(news, len, "%s, %s", h->value, val);
- nni_free(h->value, strlen(h->value) + 1);
+ nni_strfree(h->value);
h->value = news;
return (0);
}
@@ -247,12 +240,11 @@ http_add_header(nni_list *hdrs, const char *key, const char *val)
NNI_FREE_STRUCT(h);
return (NNG_ENOMEM);
}
- if ((h->value = nni_alloc(strlen(val) + 1)) == NULL) {
+ if ((h->value = nni_strdup(val)) == NULL) {
nni_strfree(h->name);
NNI_FREE_STRUCT(h);
return (NNG_ENOMEM);
}
- strncpy(h->value, val, strlen(val) + 1);
nni_list_append(hdrs, h);
return (0);
}
@@ -310,7 +302,7 @@ static int
http_entity_alloc_data(nni_http_entity *entity, size_t size)
{
void *newdata;
- if ((newdata = nni_alloc(size)) == NULL) {
+ if ((newdata = nni_zalloc(size)) == NULL) {
return (NNG_ENOMEM);
}
http_entity_set_data(entity, newdata, size);