diff options
author | Reyk Floeter <reyk@esdenera.com> | 2014-07-13 16:12:59 +0200 |
---|---|---|
committer | Reyk Floeter <reyk@esdenera.com> | 2014-07-13 16:12:59 +0200 |
commit | b0a1cfbe755d14e21af5e866fc7321cf6a3c8d0b (patch) | |
tree | 948585fe33752889c039c67cc1eccd73ec5fa5c8 /httpd.c | |
parent | 660b4faa8d41d0817c59d00f8d606daab3586535 (diff) | |
download | httpd-b0a1cfbe755d14e21af5e866fc7321cf6a3c8d0b.tar.gz httpd-b0a1cfbe755d14e21af5e866fc7321cf6a3c8d0b.zip |
Implement media type support
Diffstat (limited to 'httpd.c')
-rw-r--r-- | httpd.c | 79 |
1 files changed, 77 insertions, 2 deletions
@@ -269,10 +269,16 @@ parent_configure(struct httpd *env) struct ctl_flags cf; int ret = -1; struct server *srv; + struct media_type *media; + + RB_FOREACH(media, mediatypes, env->sc_mediatypes) { + if (config_setmedia(env, media) == -1) + fatal("send media"); + } TAILQ_FOREACH(srv, env->sc_servers, srv_entry) { if (config_setserver(env, srv) == -1) - fatal("create server"); + fatal("send server"); } /* The servers need to reload their config. */ @@ -290,7 +296,7 @@ parent_configure(struct httpd *env) ret = 0; - config_purge(env, CONFIG_ALL & ~CONFIG_SERVERS); + config_purge(env, CONFIG_ALL); return (ret); } @@ -735,3 +741,72 @@ kv_cmp(struct kv *a, struct kv *b) } RB_GENERATE(kvtree, kv, kv_node, kv_cmp); + +struct media_type * +media_add(struct mediatypes *types, struct media_type *media) +{ + struct media_type *entry; + + if ((entry = RB_FIND(mediatypes, types, media)) != NULL) { + log_debug("%s: duplicated entry for \"%s\"", __func__, + media->media_name); + return (NULL); + } + + if ((entry = malloc(sizeof(*media))) == NULL) + return (NULL); + + memcpy(entry, media, sizeof(*entry)); + RB_INSERT(mediatypes, types, entry); + + return (entry); +} + +void +media_delete(struct mediatypes *types, struct media_type *media) +{ + RB_REMOVE(mediatypes, types, media); + if (media->media_encoding != NULL) + free(media->media_encoding); + free(media); +} + +void +media_purge(struct mediatypes *types) +{ + struct media_type *media; + + while ((media = RB_MIN(mediatypes, types)) != NULL) + media_delete(types, media); +} + +struct media_type * +media_find(struct mediatypes *types, char *file) +{ + struct media_type *match, media; + char *p; + + if ((p = strrchr(file, '.')) == NULL) { + p = file; + } else if (*p++ == '\0') { + return (NULL); + } + if (strlcpy(media.media_name, p, + sizeof(media.media_name)) >= + sizeof(media.media_name)) { + return (NULL); + } + + /* Find media type by extension name */ + match = RB_FIND(mediatypes, types, &media); + + return (match); +} + +int +media_cmp(struct media_type *a, struct media_type *b) +{ + return (strcasecmp(a->media_name, b->media_name)); +} + +RB_GENERATE(mediatypes, media_type, media_entry, media_cmp); |