diff options
Diffstat (limited to 'src/keyvalue.c')
-rw-r--r-- | src/keyvalue.c | 110 |
1 files changed, 55 insertions, 55 deletions
diff --git a/src/keyvalue.c b/src/keyvalue.c index 2b21d55..ae5df2f 100644 --- a/src/keyvalue.c +++ b/src/keyvalue.c @@ -87,7 +87,7 @@ static keyvalue http_status[] = { { 504, "Gateway Timeout" }, { 505, "HTTP Version Not Supported" }, { 507, "Insufficient Storage" }, /* WebDAV */ - + { -1, NULL } }; @@ -102,12 +102,12 @@ static keyvalue http_status_body[] = { { 501, "501.html" }, { 503, "503.html" }, { 505, "505.html" }, - + { -1, NULL } }; -const char *keyvalue_get_value(keyvalue *kv, int k) { +const char *keyvalue_get_value(keyvalue *kv, int k) { int i; for (i = 0; kv[i].value; i++) { if (kv[i].key == k) return kv[i].value; @@ -115,7 +115,7 @@ const char *keyvalue_get_value(keyvalue *kv, int k) { return NULL; } -int keyvalue_get_key(keyvalue *kv, const char *s) { +int keyvalue_get_key(keyvalue *kv, const char *s) { int i; for (i = 0; kv[i].value; i++) { if (0 == strcmp(kv[i].value, s)) return kv[i].key; @@ -125,9 +125,9 @@ int keyvalue_get_key(keyvalue *kv, const char *s) { keyvalue_buffer *keyvalue_buffer_init(void) { keyvalue_buffer *kvb; - + kvb = calloc(1, sizeof(*kvb)); - + return kvb; } @@ -135,49 +135,49 @@ int keyvalue_buffer_append(keyvalue_buffer *kvb, int key, const char *value) { size_t i; if (kvb->size == 0) { kvb->size = 4; - + kvb->kv = malloc(kvb->size * sizeof(*kvb->kv)); - + for(i = 0; i < kvb->size; i++) { kvb->kv[i] = calloc(1, sizeof(**kvb->kv)); } } else if (kvb->used == kvb->size) { kvb->size += 4; - + kvb->kv = realloc(kvb->kv, kvb->size * sizeof(*kvb->kv)); - + for(i = kvb->used; i < kvb->size; i++) { kvb->kv[i] = calloc(1, sizeof(**kvb->kv)); } } - + kvb->kv[kvb->used]->key = key; kvb->kv[kvb->used]->value = strdup(value); - + kvb->used++; - + return 0; } void keyvalue_buffer_free(keyvalue_buffer *kvb) { size_t i; - + for (i = 0; i < kvb->size; i++) { if (kvb->kv[i]->value) free(kvb->kv[i]->value); free(kvb->kv[i]); } - + if (kvb->kv) free(kvb->kv); - + free(kvb); } s_keyvalue_buffer *s_keyvalue_buffer_init(void) { s_keyvalue_buffer *kvb; - + kvb = calloc(1, sizeof(*kvb)); - + return kvb; } @@ -186,50 +186,50 @@ int s_keyvalue_buffer_append(s_keyvalue_buffer *kvb, const char *key, const char if (kvb->size == 0) { kvb->size = 4; kvb->used = 0; - + kvb->kv = malloc(kvb->size * sizeof(*kvb->kv)); - + for(i = 0; i < kvb->size; i++) { kvb->kv[i] = calloc(1, sizeof(**kvb->kv)); } } else if (kvb->used == kvb->size) { kvb->size += 4; - + kvb->kv = realloc(kvb->kv, kvb->size * sizeof(*kvb->kv)); - + for(i = kvb->used; i < kvb->size; i++) { kvb->kv[i] = calloc(1, sizeof(**kvb->kv)); } } - + kvb->kv[kvb->used]->key = key ? strdup(key) : NULL; kvb->kv[kvb->used]->value = strdup(value); - + kvb->used++; - + return 0; } void s_keyvalue_buffer_free(s_keyvalue_buffer *kvb) { size_t i; - + for (i = 0; i < kvb->size; i++) { if (kvb->kv[i]->key) free(kvb->kv[i]->key); if (kvb->kv[i]->value) free(kvb->kv[i]->value); free(kvb->kv[i]); } - + if (kvb->kv) free(kvb->kv); - + free(kvb); } httpauth_keyvalue_buffer *httpauth_keyvalue_buffer_init(void) { httpauth_keyvalue_buffer *kvb; - + kvb = calloc(1, sizeof(*kvb)); - + return kvb; } @@ -237,42 +237,42 @@ int httpauth_keyvalue_buffer_append(httpauth_keyvalue_buffer *kvb, const char *k size_t i; if (kvb->size == 0) { kvb->size = 4; - + kvb->kv = malloc(kvb->size * sizeof(*kvb->kv)); - + for(i = 0; i < kvb->size; i++) { kvb->kv[i] = calloc(1, sizeof(**kvb->kv)); } } else if (kvb->used == kvb->size) { kvb->size += 4; - + kvb->kv = realloc(kvb->kv, kvb->size * sizeof(*kvb->kv)); - + for(i = kvb->used; i < kvb->size; i++) { kvb->kv[i] = calloc(1, sizeof(**kvb->kv)); } } - + kvb->kv[kvb->used]->key = strdup(key); kvb->kv[kvb->used]->realm = strdup(realm); kvb->kv[kvb->used]->type = type; - + kvb->used++; - + return 0; } void httpauth_keyvalue_buffer_free(httpauth_keyvalue_buffer *kvb) { size_t i; - + for (i = 0; i < kvb->size; i++) { if (kvb->kv[i]->key) free(kvb->kv[i]->key); if (kvb->kv[i]->realm) free(kvb->kv[i]->realm); free(kvb->kv[i]); } - + if (kvb->kv) free(kvb->kv); - + free(kvb); } @@ -306,9 +306,9 @@ http_method_t get_http_method_key(const char *s) { pcre_keyvalue_buffer *pcre_keyvalue_buffer_init(void) { pcre_keyvalue_buffer *kvb; - + kvb = calloc(1, sizeof(*kvb)); - + return kvb; } @@ -319,46 +319,46 @@ int pcre_keyvalue_buffer_append(pcre_keyvalue_buffer *kvb, const char *key, cons int erroff; pcre_keyvalue *kv; #endif - + if (!key) return -1; #ifdef HAVE_PCRE_H if (kvb->size == 0) { kvb->size = 4; kvb->used = 0; - + kvb->kv = malloc(kvb->size * sizeof(*kvb->kv)); - + for(i = 0; i < kvb->size; i++) { kvb->kv[i] = calloc(1, sizeof(**kvb->kv)); } } else if (kvb->used == kvb->size) { kvb->size += 4; - + kvb->kv = realloc(kvb->kv, kvb->size * sizeof(*kvb->kv)); - + for(i = kvb->used; i < kvb->size; i++) { kvb->kv[i] = calloc(1, sizeof(**kvb->kv)); } } - + kv = kvb->kv[kvb->used]; if (NULL == (kv->key = pcre_compile(key, 0, &errptr, &erroff, NULL))) { - + fprintf(stderr, "%s.%d: rexexp compilation error at %s\n", __FILE__, __LINE__, errptr); return -1; } - if (NULL == (kv->key_extra = pcre_study(kv->key, 0, &errptr)) && + if (NULL == (kv->key_extra = pcre_study(kv->key, 0, &errptr)) && errptr != NULL) { return -1; } - + kv->value = buffer_init_string(value); - + kvb->used++; - + return 0; #else UNUSED(kvb); @@ -380,9 +380,9 @@ void pcre_keyvalue_buffer_free(pcre_keyvalue_buffer *kvb) { if (kv->value) buffer_free(kv->value); free(kv); } - + if (kvb->kv) free(kvb->kv); #endif - + free(kvb); } |