Browse Source

cleanup dead keyvalue code

From: Stefan Bühler <stbuehler@web.de>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3073 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/heads/lighttpd-1.4.x
Stefan Bühler 6 years ago
parent
commit
107f40545c
  1. 158
      src/keyvalue.c
  2. 41
      src/keyvalue.h

158
src/keyvalue.c

@ -140,159 +140,6 @@ int keyvalue_get_key(keyvalue *kv, const char *s) {
return -1;
}
keyvalue_buffer *keyvalue_buffer_init(void) {
keyvalue_buffer *kvb;
kvb = calloc(1, sizeof(*kvb));
return kvb;
}
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;
}
int s_keyvalue_buffer_append(s_keyvalue_buffer *kvb, const char *key, const char *value) {
size_t i;
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;
}
int httpauth_keyvalue_buffer_append(httpauth_keyvalue_buffer *kvb, const char *key, const char *realm, httpauth_type type) {
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);
}
const char *get_http_version_name(int i) {
return keyvalue_get_value(http_versions, i);
@ -325,6 +172,7 @@ pcre_keyvalue_buffer *pcre_keyvalue_buffer_init(void) {
pcre_keyvalue_buffer *kvb;
kvb = calloc(1, sizeof(*kvb));
force_assert(NULL != kvb);
return kvb;
}
@ -345,17 +193,21 @@ int pcre_keyvalue_buffer_append(server *srv, pcre_keyvalue_buffer *kvb, const ch
kvb->used = 0;
kvb->kv = malloc(kvb->size * sizeof(*kvb->kv));
force_assert(NULL != kvb->kv);
for(i = 0; i < kvb->size; i++) {
kvb->kv[i] = calloc(1, sizeof(**kvb->kv));
force_assert(NULL != kvb->kv[i]);
}
} else if (kvb->used == kvb->size) {
kvb->size += 4;
kvb->kv = realloc(kvb->kv, kvb->size * sizeof(*kvb->kv));
force_assert(NULL != kvb->kv);
for(i = kvb->used; i < kvb->size; i++) {
kvb->kv[i] = calloc(1, sizeof(**kvb->kv));
force_assert(NULL != kvb->kv[i]);
}
}

41
src/keyvalue.h

@ -71,12 +71,6 @@ typedef struct {
char *value;
} keyvalue;
typedef struct {
char *key;
char *value;
} s_keyvalue;
typedef struct {
#ifdef HAVE_PCRE_H
pcre *key;
@ -86,26 +80,11 @@ typedef struct {
buffer *value;
} pcre_keyvalue;
typedef enum { HTTP_AUTH_BASIC, HTTP_AUTH_DIGEST } httpauth_type;
typedef struct {
char *key;
char *realm;
httpauth_type type;
} httpauth_keyvalue;
#define KVB(x) \
typedef struct {\
x **kv; \
size_t used;\
size_t size;\
} x ## _buffer
KVB(keyvalue);
KVB(s_keyvalue);
KVB(httpauth_keyvalue);
KVB(pcre_keyvalue);
pcre_keyvalue **kv;
size_t used;
size_t size;
} pcre_keyvalue_buffer;
const char *get_http_status_name(int i);
const char *get_http_version_name(int i);
@ -117,18 +96,6 @@ http_method_t get_http_method_key(const char *s);
const char *keyvalue_get_value(keyvalue *kv, int k);
int keyvalue_get_key(keyvalue *kv, const char *s);
keyvalue_buffer *keyvalue_buffer_init(void);
int keyvalue_buffer_append(keyvalue_buffer *kvb, int k, const char *value);
void keyvalue_buffer_free(keyvalue_buffer *kvb);
s_keyvalue_buffer *s_keyvalue_buffer_init(void);
int s_keyvalue_buffer_append(s_keyvalue_buffer *kvb, const char *key, const char *value);
void s_keyvalue_buffer_free(s_keyvalue_buffer *kvb);
httpauth_keyvalue_buffer *httpauth_keyvalue_buffer_init(void);
int httpauth_keyvalue_buffer_append(httpauth_keyvalue_buffer *kvb, const char *key, const char *realm, httpauth_type type);
void httpauth_keyvalue_buffer_free(httpauth_keyvalue_buffer *kvb);
pcre_keyvalue_buffer *pcre_keyvalue_buffer_init(void);
int pcre_keyvalue_buffer_append(struct server *srv, pcre_keyvalue_buffer *kvb, const char *key, const char *value);
void pcre_keyvalue_buffer_free(pcre_keyvalue_buffer *kvb);

Loading…
Cancel
Save