
alo at alobbs
Jan 13, 2006, 3:11 PM
Post #1 of 1
(252 views)
Permalink
|
Author: alo Date: 2006-01-13 23:11:56 +0100 (Fri, 13 Jan 2006) New Revision: 137 Added: cherokee/cherokee/mime_entry.c cherokee/cherokee/mime_entry.h Removed: cherokee/cherokee/mime_grammar.y cherokee/cherokee/mime_scanner.l Modified: cherokee/cherokee/Makefile.am cherokee/cherokee/cherokee.h cherokee/cherokee/handler_file.c cherokee/cherokee/http.c cherokee/cherokee/mime.c cherokee/cherokee/mime.h cherokee/cherokee/module_read_config.c cherokee/cherokee/read_config_grammar.y cherokee/cherokee/read_config_scanner.l cherokee/cherokee/server-protected.h cherokee/cherokee/server.c Log: Modified: cherokee/cherokee/Makefile.am =================================================================== --- cherokee/cherokee/Makefile.am 2006-01-12 20:29:39 UTC (rev 136) +++ cherokee/cherokee/Makefile.am 2006-01-13 22:11:56 UTC (rev 137) @@ -611,6 +611,7 @@ mime.h \ mime-protected.h \ mime.c \ +mime_entry.c \ matching_list.h \ matching_list.c \ iocache.h \ @@ -637,11 +638,8 @@ resolv_cache.h \ resolv_cache.c \ typed_table.h \ -typed_table.c \ -mime_grammar.y \ -mime_scanner.l +typed_table.c - libcherokee_client_la_SOURCES = \ url.h \ url.c \ @@ -759,6 +757,7 @@ table.h \ http.h \ mime.h \ +mime_entry.h \ list.h \ list_merge_sort.h \ url.h \ @@ -790,15 +789,7 @@ icons_grammar.c : icons_grammar.y $(YACC) -dv -p yy_icons_ -o $@ $< -# Mime: -mime_scanner.c : mime_scanner.l - $(LEX) -Pyy_mime_ -i -o$@ $< -mime_grammar.h : mime_grammar.c -mime_grammar.c : mime_grammar.y - $(YACC) -dv -p yy_mime_ -o $@ $< - - # # Cherokee plugins # @@ -894,9 +885,6 @@ icons_grammar.h \ icons_grammar.c \ icons_scanner.c \ -mime_grammar.h \ -mime_grammar.c \ -mime_scanner.c \ config.h WINDOWS_PORT_FILES = \ Modified: cherokee/cherokee/cherokee.h =================================================================== --- cherokee/cherokee/cherokee.h 2006-01-12 20:29:39 UTC (rev 136) +++ cherokee/cherokee/cherokee.h 2006-01-13 22:11:56 UTC (rev 137) @@ -37,6 +37,7 @@ #include <cherokee/table.h> #include <cherokee/http.h> #include <cherokee/list.h> +#include <cherokee/mime_entry.h> #include <cherokee/mime.h> #include <cherokee/list.h> #include <cherokee/list_merge_sort.h> Modified: cherokee/cherokee/handler_file.c =================================================================== --- cherokee/cherokee/handler_file.c 2006-01-12 20:29:39 UTC (rev 136) +++ cherokee/cherokee/handler_file.c 2006-01-13 22:11:56 UTC (rev 137) @@ -430,13 +430,11 @@ /* Look for the mime type */ #ifndef CHEROKEE_EMBEDDED - ext = strrchr (conn->request.buf, '.'); - if (ext != NULL) { - cherokee_mime_t *m; - - ret = cherokee_mime_get_default (&m); - if (ret == ret_ok) { - ret = cherokee_mime_get (m, ext+1, &n->mime); + if (srv->mime != NULL) { + ext = strrchr (conn->request.buf, '.'); + if (ext != NULL) { + ret = cherokee_mime_get_by_suffix (srv->mime, ext+1, &n->mime); + printf ("cherokee_mime_get_by_suffix ret=%d\n", ret); } } #endif @@ -548,6 +546,7 @@ cherokee_handler_file_add_headers (cherokee_handler_file_t *fhdl, cherokee_buffer_t *buffer) { + ret_t ret; off_t length; struct tm modified_tm; @@ -580,13 +579,17 @@ * "Content-Type:" and "Cache-Control: max-age=" */ if (fhdl->mime != NULL) { + cherokee_buffer_t *mime; + cuint_t maxage; + + cherokee_mime_entry_get_type (fhdl->mime, &mime); cherokee_buffer_add (buffer, "Content-Type: ", 14); - cherokee_buffer_add_buffer (buffer, MIME_ENTRY_NAME(fhdl->mime)); + cherokee_buffer_add_buffer (buffer, mime); cherokee_buffer_add (buffer, CRLF, 2); - if (MIME_ENTRY_AGE(fhdl->mime) != -1) { - cherokee_buffer_add_va (buffer, "Cache-Control: max-age=%d"CRLF, - MIME_ENTRY_AGE(fhdl->mime)); + ret = cherokee_mime_entry_get_maxage (fhdl->mime, &maxage); + if (ret == ret_ok) { + cherokee_buffer_add_va (buffer, "Cache-Control: max-age=%d"CRLF, maxage); } } @@ -621,9 +624,6 @@ void MODULE_INIT(file) (cherokee_module_loader_t *loader) { - ret_t ret; - cherokee_mime_t *mime; - /* Init flag */ if (_file_is_init == true) { @@ -631,14 +631,6 @@ } _file_is_init = true; - - /* Library dependences: mime + /* Init something more.. */ -#ifndef CHEROKEE_EMBEDDED - ret = cherokee_mime_init (&mime); - if (ret < ret_ok) { - PRINT_ERROR_S ("Can not init MIME module\n"); - return; - } -#endif } Modified: cherokee/cherokee/http.c =================================================================== --- cherokee/cherokee/http.c 2006-01-12 20:29:39 UTC (rev 136) +++ cherokee/cherokee/http.c 2006-01-13 22:11:56 UTC (rev 137) @@ -27,10 +27,10 @@ #include <stdio.h> -#define entry(name,name_str) \ - case name: \ - if (len) *len = sizeof(name_str); \ - *str = name_str; \ +#define entry(name,name_str) \ + case name: \ + if (len) *len = sizeof(name_str) - 1; \ + *str = name_str; \ return ret_ok; ret_t @@ -124,7 +124,7 @@ { #define entry_code(c) \ case http_ ## c: \ - return cherokee_buffer_add (buf, http_ ## c ## _string, sizeof(http_ ## c ## _string)) + return cherokee_buffer_add (buf, http_ ## c ## _string, sizeof(http_ ## c ## _string)-1) switch (code) { entry_code (continue); Modified: cherokee/cherokee/mime.c =================================================================== --- cherokee/cherokee/mime.c 2006-01-12 20:29:39 UTC (rev 136) +++ cherokee/cherokee/mime.c 2006-01-13 22:11:56 UTC (rev 137) @@ -26,15 +26,10 @@ #include "mime.h" #include "mime-protected.h" +#include "util.h" -extern int yy_mime_restart (FILE *); -extern int yy_mime__create_buffer (FILE *, int size); -extern void yy_mime__switch_to_buffer (void *); -extern void yy_mime__delete_buffer (void *); - - -static ret_t +ret_t cherokee_mime_new (cherokee_mime_t **mime) { CHEROKEE_NEW_STRUCT(n, mime); @@ -50,6 +45,7 @@ return ret_ok; } + ret_t cherokee_mime_free (cherokee_mime_t *mime) { @@ -67,111 +63,151 @@ } -ret_t -cherokee_mime_load (cherokee_mime_t *mime, char *filename) +ret_t +cherokee_mime_set_by_suffix (cherokee_mime_t *mime, char *suffix, cherokee_mime_entry_t *entry) { - int error; - char *file; - void *bufstate; + return cherokee_table_add (&mime->mime_table, suffix, (void *)entry); +} - extern FILE *yy_mime_in; - extern int yy_mime_parse (void *); +ret_t +cherokee_mime_get_by_suffix (cherokee_mime_t *mime, char *suffix, cherokee_mime_entry_t **entry) +{ + return cherokee_table_get (&mime->mime_table, suffix, (void **)entry); +} - file = (filename) ? filename : CHEROKEE_CONFDIR"/mime.conf"; - yy_mime_in = fopen (file, "r"); - if (yy_mime_in == NULL) { - PRINT_ERROR("Can't read the mime spec file: '%s'\n", file); - return ret_error; - } +ret_t +cherokee_mime_get_by_type (cherokee_mime_t *mime, char *type, cherokee_mime_entry_t **entry) +{ + ret_t ret; + list_t *i; - yy_mime_restart(yy_mime_in); + list_for_each (i, &mime->mime_list) { + cherokee_buffer_t *itype; - bufstate = (void *) yy_mime__create_buffer (yy_mime_in, 65535); - yy_mime__switch_to_buffer (bufstate); - error = yy_mime_parse (mime); - yy_mime__delete_buffer (bufstate); + ret = cherokee_mime_entry_get_type (MIME_ENTRY(i), &itype); + if (ret != ret_ok) continue; - fclose (yy_mime_in); + if (strcmp (type, itype->buf) == 0) { + *entry = MIME_ENTRY(i); + return ret_ok; + } + } - return (error)? ret_error : ret_ok; + return ret_not_found; } - ret_t -cherokee_mime_get (cherokee_mime_t *mime, char *suffix, cherokee_mime_entry_t **entry) +cherokee_mime_add_entry (cherokee_mime_t *mime, cherokee_mime_entry_t *entry) { - return cherokee_table_get (MIME_TABLE(mime), suffix, (void **)entry); + list_add ((list_t *)entry, &mime->mime_list); + return ret_ok; } ret_t -cherokee_mime_add (cherokee_mime_t *mime, cherokee_mime_entry_t *entry) +cherokee_mime_load_mime_types (cherokee_mime_t *mime, char *filename) { - list_add ((list_t *)entry, MIME_LIST(mime)); - return ret_ok; -} + ret_t ret; + char *p; + char *end; + cherokee_buffer_t file = CHEROKEE_BUF_INIT; + cherokee_buffer_t ext = CHEROKEE_BUF_INIT; + cherokee_buffer_t type = CHEROKEE_BUF_INIT; + ret = cherokee_buffer_read_file (&file, filename); + if (ret != ret_ok) goto error; + + p = file.buf; + end = file.buf + file.len; -/* Mime global - */ + while (p < end) { + char *nl, *c1, *c2, *tmp; + cuint_t len; + cherokee_mime_entry_t *entry; -static cherokee_mime_t *_mime_global = NULL; + cherokee_buffer_clean (&ext); + cherokee_buffer_clean (&type); -ret_t -cherokee_mime_init (cherokee_mime_t **mime) -{ - ret_t ret; + /* Look for the EOL + */ + c1 = strchr (p, '\r'); + c2 = strchr (p, '\n'); - if (_mime_global == NULL) { - ret = cherokee_mime_new (&_mime_global); - if (unlikely(ret < ret_ok)) return ret; - } + nl = cherokee_min_str (c1, c2); + if (nl == NULL) break; - *mime = _mime_global; - return ret_ok; -} + /* Skip comments and empty lines + */ + *nl = '\0'; + if (*p == '#') + goto next_line; + + len = strlen (p); + if (len < 3) + goto next_line; -ret_t -cherokee_mime_get_default (cherokee_mime_t **mime) -{ - if (_mime_global == NULL) { - return ret_not_found; - } - - *mime = _mime_global; - return ret_ok; -} + /* Parse the mime type + */ + c1 = strchr (p, ' '); + c2 = strchr (p, '\t'); + tmp = cherokee_min_str (c1, c2); + if (tmp == NULL) goto next_line; + /* Create the new MIME entry obj + */ + cherokee_buffer_add (&type, p, tmp-p); -/* Mime entry methods - */ + ret = cherokee_mime_get_by_type (mime, type.buf, &entry); + if (ret != ret_ok) { + cherokee_mime_entry_new (&entry); + cherokee_mime_add_entry (MIME(mime), entry); + } -ret_t -cherokee_mime_entry_new (cherokee_mime_entry_t **mentry) -{ - CHEROKEE_NEW_STRUCT(n, mime_entry); + cherokee_mime_entry_set_type (entry, type.buf); + + /* Adds its extensions + */ + p = tmp; + while (p < nl) { + cherokee_buffer_clean (&ext); + + /* Look for the next extension + */ + while ((*p == ' ') || (*p == '\t')) p++; + if (p >= nl) break; - INIT_LIST_HEAD(&n->base); - n->max_age = -1; - cherokee_buffer_new (&n->mime_name); + c1 = strchr (p, ' '); + c2 = strchr (p, '\t'); - *mentry = n; - return ret_ok; -} + tmp = cherokee_min_str (c1, c2); + if (tmp == NULL) tmp = nl; + /* Add it to the table + */ + cherokee_buffer_add (&ext, p, tmp-p); + cherokee_table_add (&mime->mime_table, ext.buf, entry); -ret_t -cherokee_mime_entry_free (cherokee_mime_entry_t *mentry) -{ - if (mentry->mime_name != NULL) { - cherokee_buffer_free (mentry->mime_name); - mentry->mime_name = NULL; + p = tmp; + } + + next_line: + p = nl + 1; + while ((*p == '\r') || (*p == '\n')) p++; } - free (mentry); + cherokee_buffer_mrproper (&ext); + cherokee_buffer_mrproper (&type); + cherokee_buffer_mrproper (&file); return ret_ok; + +error: + cherokee_buffer_mrproper (&ext); + cherokee_buffer_mrproper (&type); + cherokee_buffer_mrproper (&file); + return ret_error; } + Modified: cherokee/cherokee/mime.h =================================================================== --- cherokee/cherokee/mime.h 2006-01-12 20:29:39 UTC (rev 136) +++ cherokee/cherokee/mime.h 2006-01-13 22:11:56 UTC (rev 137) @@ -33,39 +33,26 @@ #include <cherokee/table.h> #include <cherokee/buffer.h> #include <cherokee/list.h> +#include <cherokee/mime_entry.h> + CHEROKEE_BEGIN_DECLS typedef struct cherokee_mime cherokee_mime_t; +#define MIME(m) ((cherokee_mime_t *)(m)) -typedef struct { - struct list_head base; - int max_age; - cherokee_buffer_t *mime_name; -} cherokee_mime_entry_t; +ret_t cherokee_mime_new (cherokee_mime_t **mime); +ret_t cherokee_mime_free (cherokee_mime_t *mime); -#define MIME(m) ((cherokee_mime_t *)(m)) -#define MIME_ENTRY(m) ((cherokee_mime_entry_t *)(m)) -#define MIME_ENTRY_AGE(m) (MIME_ENTRY(m)->max_age) -#define MIME_ENTRY_NAME(m) (MIME_ENTRY(m)->mime_name) +ret_t cherokee_mime_add_entry (cherokee_mime_t *mime, cherokee_mime_entry_t *entry); +ret_t cherokee_mime_load_mime_types (cherokee_mime_t *mime, char *filename); -/* Mime methods - */ -ret_t cherokee_mime_init (cherokee_mime_t **mime); -ret_t cherokee_mime_free (cherokee_mime_t *mime); -ret_t cherokee_mime_get_default (cherokee_mime_t **mime); +ret_t cherokee_mime_get_by_type (cherokee_mime_t *mime, char *type, cherokee_mime_entry_t **entry); -ret_t cherokee_mime_load (cherokee_mime_t *mime, char *filename); -ret_t cherokee_mime_get (cherokee_mime_t *mime, char *suffix, cherokee_mime_entry_t **entry); -ret_t cherokee_mime_add (cherokee_mime_t *mime, cherokee_mime_entry_t *entry); +ret_t cherokee_mime_set_by_suffix (cherokee_mime_t *mime, char *suffix, cherokee_mime_entry_t *entry); +ret_t cherokee_mime_get_by_suffix (cherokee_mime_t *mime, char *suffix, cherokee_mime_entry_t **entry); -/* Mime entry methods - */ -ret_t cherokee_mime_entry_new (cherokee_mime_entry_t **mentry); -ret_t cherokee_mime_entry_free (cherokee_mime_entry_t *mentry); - - CHEROKEE_END_DECLS #endif /* CHEROKEE_MIME_H */ Added: cherokee/cherokee/mime_entry.c =================================================================== --- cherokee/cherokee/mime_entry.c 2006-01-12 20:29:39 UTC (rev 136) +++ cherokee/cherokee/mime_entry.c 2006-01-13 22:11:56 UTC (rev 137) @@ -0,0 +1,101 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +/* Cherokee + * + * Authors: + * Alvaro Lopez Ortega <alvaro at alobbs.com> + * + * Copyright (C) 2001-2006 Alvaro Lopez Ortega + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + */ + +#include "common-internal.h" +#include "mime_entry.h" + +struct cherokee_mime_entry { + struct list_head base; + + cuint_t maxage; + cherokee_boolean_t maxage_set; + + cherokee_buffer_t *mime_name; +}; + +ret_t +cherokee_mime_entry_new (cherokee_mime_entry_t **mentry) +{ + CHEROKEE_NEW_STRUCT(n, mime_entry); + + INIT_LIST_HEAD(&n->base); + + n->maxage = -1; + n->maxage_set = false; + + cherokee_buffer_new (&n->mime_name); + + *mentry = n; + return ret_ok; +} + + +ret_t +cherokee_mime_entry_free (cherokee_mime_entry_t *mentry) +{ + if (mentry->mime_name != NULL) { + cherokee_buffer_free (mentry->mime_name); + mentry->mime_name = NULL; + } + + free (mentry); + return ret_ok; +} + + +ret_t +cherokee_mime_entry_set_type (cherokee_mime_entry_t *mentry, char *type) +{ + cherokee_buffer_clean (mentry->mime_name); + return cherokee_buffer_add (mentry->mime_name, type, strlen(type)); +} + + +ret_t +cherokee_mime_entry_get_type (cherokee_mime_entry_t *mentry, cherokee_buffer_t **name) +{ + *name = mentry->mime_name; + return ret_ok; +} + + +ret_t +cherokee_mime_entry_set_maxage (cherokee_mime_entry_t *mentry, cuint_t maxage) +{ + mentry->maxage_set = true; + + mentry->maxage = maxage; + return ret_ok; +} + + +ret_t +cherokee_mime_entry_get_maxage (cherokee_mime_entry_t *mentry, cuint_t *maxage) +{ + if (mentry->maxage_set == false) + return ret_not_found; + + *maxage = mentry->maxage; + return ret_ok; +} Added: cherokee/cherokee/mime_entry.h =================================================================== --- cherokee/cherokee/mime_entry.h 2006-01-12 20:29:39 UTC (rev 136) +++ cherokee/cherokee/mime_entry.h 2006-01-13 22:11:56 UTC (rev 137) @@ -0,0 +1,54 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +/* Cherokee + * + * Authors: + * Alvaro Lopez Ortega <alvaro at alobbs.com> + * + * Copyright (C) 2001-2006 Alvaro Lopez Ortega + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + */ + +#if !defined (CHEROKEE_INSIDE_CHEROKEE_H) && !defined (CHEROKEE_COMPILATION) +# error "Only <cherokee/cherokee.h> can be included directly, this file may disappear or change contents." +#endif + +#ifndef CHEROKEE_MIME_ENTRY_H +#define CHEROKEE_MIME_ENTRY_H + +#include <cherokee/common.h> +#include <cherokee/table.h> +#include <cherokee/buffer.h> +#include <cherokee/list.h> + + +CHEROKEE_BEGIN_DECLS + +typedef struct cherokee_mime_entry cherokee_mime_entry_t; +#define MIME_ENTRY(m) ((cherokee_mime_entry_t *)(m)) + +ret_t cherokee_mime_entry_new (cherokee_mime_entry_t **mentry); +ret_t cherokee_mime_entry_free (cherokee_mime_entry_t *mentry); + +ret_t cherokee_mime_entry_set_type (cherokee_mime_entry_t *mentry, char *type); +ret_t cherokee_mime_entry_get_type (cherokee_mime_entry_t *mentry, cherokee_buffer_t **name); + +ret_t cherokee_mime_entry_set_maxage (cherokee_mime_entry_t *mentry, cuint_t maxage); +ret_t cherokee_mime_entry_get_maxage (cherokee_mime_entry_t *mentry, cuint_t *maxage); + +CHEROKEE_END_DECLS + +#endif /* CHEROKEE_MIME_ENTRY_H */ Deleted: cherokee/cherokee/mime_grammar.y =================================================================== --- cherokee/cherokee/mime_grammar.y 2006-01-12 20:29:39 UTC (rev 136) +++ cherokee/cherokee/mime_grammar.y 2006-01-13 22:11:56 UTC (rev 137) @@ -1,144 +0,0 @@ -%{ -/* Cherokee - * - * Authors: - * Alvaro Lopez Ortega <alvaro at alobbs.com> - * - * Copyright (C) 2001-2006 Alvaro Lopez Ortega - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#include "common-internal.h" -#include "list_ext.h" -#include "mime.h" -#include "mime-protected.h" - - -/* Define the parameter name of the yyparse() argument - */ -#define YYPARSE_PARAM mime - -%} - -%union { - unsigned int number; - char *string; - struct list_head *list; -} - -%{ - -/* What is the right way to import these prototipes? - * There's the same problem in read_config_grammar.y - */ -extern int yy_mime_lex (void); -extern char *yy_mime_text; -extern int yy_mime_lineno; - -list_t current_list; -cherokee_mime_entry_t *current_mime_entry; - - - -void -yy_mime_error(char* msg) -{ - PRINT_ERROR ("Error parsing configuration: '%s', line %d, symbol '%s' (0x%x)\n", - msg, yy_mime_lineno, yy_mime_text, yy_mime_text[0]); -} - -%} - - -%token T_MAXAGE T_SUFFIXES -%token <string> T_SUFFIX T_MIME -%token <number> T_AGE - -%type <list> list_ids -%type <string> id - -%% - -mime_file : lines; - -lines : line - | lines line; - -line : mime - ; - - -mime : T_MIME '{' -{ - /* Create a new mime_entry object - */ - cherokee_mime_entry_new (¤t_mime_entry); - cherokee_mime_add (MIME(mime), current_mime_entry); - - /* Add the mime string to the mime_name buffer - */ - cherokee_buffer_add (MIME_ENTRY_NAME(current_mime_entry), $1, strlen($1)); - free ($1); -} -internal_mimes '}' -{ - current_mime_entry = NULL; -}; - - -internal_mimes : internal_mime - | internal_mimes internal_mime; - -internal_mime : maxage - | suffixes; - -maxage : T_MAXAGE T_AGE -{ - MIME_ENTRY_AGE(current_mime_entry) = $2; -}; - -suffixes : T_SUFFIXES list_ids -{ - ret_t ret; - list_t *i; - - list_for_each (i, $2) { - ret = cherokee_table_add (MIME_TABLE(mime), LIST_ITEM(i)->info, current_mime_entry); - if (ret < ret_ok) { - PRINT_ERROR ("Error adding MIME suffix %s\n", (char *)LIST_ITEM(i)->info); - } - } - - cherokee_list_free ($2, free); -}; - - -/* List - */ -id : T_SUFFIX; - -list_ids : id -{ - INIT_LIST_HEAD(¤t_list); - cherokee_list_add (¤t_list, $1); - $$ = ¤t_list; -}; - -list_ids : id ',' list_ids -{ - cherokee_list_add (¤t_list, $1); - $$ = ¤t_list; -}; Deleted: cherokee/cherokee/mime_scanner.l =================================================================== --- cherokee/cherokee/mime_scanner.l 2006-01-12 20:29:39 UTC (rev 136) +++ cherokee/cherokee/mime_scanner.l 2006-01-13 22:11:56 UTC (rev 137) @@ -1,68 +0,0 @@ -%{ -/* Cherokee - * - * Authors: - * Alvaro Lopez Ortega <alvaro at alobbs.com> - * - * Copyright (C) 2001-2006 Alvaro Lopez Ortega - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#include "mime_grammar.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -%} - -%option yylineno -%option nounput - -ws [ \t]+ -nl [\n\r]+ - -comment #.*$ - -mime [\+\.\-_a-zA-Z0-9\/\\]+ -suffix [a-zA-Z0-9]+ -age [0-9]+ -%% - -{ws} ; -{nl} ; -{comment} ; - -"max-age" { return T_MAXAGE; } -"maxage" { return T_MAXAGE; } -"suffixes" { return T_SUFFIXES; } - -{age} { yy_mime_lval.number = atoi (yy_mime_text); return T_AGE; } -{suffix} { yy_mime_lval.string = strdup (yy_mime_text); return T_SUFFIX; } -{mime} { yy_mime_lval.string = strdup (yy_mime_text); return T_MIME; } - -<<EOF>> { yyterminate(); } - -. { return yy_mime_text[0]; } - - -%% - -int -yy_mime_wrap() -{ - return 1; -} - Modified: cherokee/cherokee/module_read_config.c =================================================================== --- cherokee/cherokee/module_read_config.c 2006-01-12 20:29:39 UTC (rev 136) +++ cherokee/cherokee/module_read_config.c 2006-01-13 22:11:56 UTC (rev 137) @@ -258,26 +258,20 @@ /* Maybe read the MIME file */ if (srv->mime_file != NULL) { - do { - cherokee_mime_t *mime = NULL; - - ret = cherokee_mime_get_default (&mime); - - if (ret == ret_not_found) { - ret = cherokee_mime_init (&mime); - } - + if (srv->mime == NULL) { + ret = cherokee_mime_new (&srv->mime); if (ret < ret_ok) { PRINT_ERROR_S ("Can not get default MIME configuration file\n"); - break; + return ret; } - - ret = cherokee_mime_load (mime, srv->mime_file); - if (ret < ret_ok) { - PRINT_ERROR ("Can not load MIME configuration file %s\n", srv->mime_file); - } - } while (0); - } + } + + ret = cherokee_mime_load_mime_types (srv->mime, srv->mime_file); + if (ret < ret_ok) { + PRINT_ERROR ("Can not load MIME configuration file %s\n", srv->mime_file); + return ret; + } + } #endif return ret; Modified: cherokee/cherokee/read_config_grammar.y =================================================================== --- cherokee/cherokee/read_config_grammar.y 2006-01-12 20:29:39 UTC (rev 136) +++ cherokee/cherokee/read_config_grammar.y 2006-01-13 22:11:56 UTC (rev 137) @@ -94,6 +94,7 @@ static cherokee_encoder_table_entry_t *current_encoder_entry = NULL; static cherokee_module_info_t *current_module_info = NULL; static cherokee_fcgi_server_t *current_fastcgi_server = NULL; +static cherokee_mime_entry_t *current_mime_entry = NULL; static cuint_t priority_counter = 1; typedef struct { @@ -331,10 +332,10 @@ %token T_ICONS T_AUTH T_NAME T_METHOD T_PASSWDFILE T_SSL_CA_LIST_FILE T_FROM T_SOCKET T_LOG_FLUSH_INTERVAL %token T_HEADERFILE T_PANIC_ACTION T_JUST_ABOUT T_LISTEN_QUEUE_SIZE T_SENDFILE T_MINSIZE T_MAXSIZE T_MAX_FDS %token T_SHOW T_CHROOT T_ONLY_SECURE T_MAX_CONNECTION_REUSE T_REWRITE T_POLL_METHOD T_EXTENSION T_IPV6 T_ENV -%token T_REQUEST +%token T_REQUEST T_MIMETYPE T_MAX_AGE %token <number> T_NUMBER T_PORT T_PORT_TLS -%token <string> T_QSTRING T_FULLDIR T_ID T_HTTP_URL T_HTTPS_URL T_HOSTNAME T_IP T_DOMAIN_NAME T_ADDRESS_PORT +%token <string> T_QSTRING T_FULLDIR T_ID T_HTTP_URL T_HTTPS_URL T_HOSTNAME T_IP T_DOMAIN_NAME T_ADDRESS_PORT T_MIMETYPE_ID %type <name_ptr> directory_option handler %type <string> host_name http_generic id_or_path ip_or_domain str_type address_or_path @@ -365,6 +366,7 @@ | listen | server_tokens | mime + | mime_entry | icons | timeout | keepalive @@ -638,6 +640,49 @@ SRV(server)->mime_file = $2; }; +mime_entry : T_MIMETYPE T_MIMETYPE_ID '{' +{ + ret_t ret; + cherokee_mime_entry_t *entry; + + if (SRV(server)->mime == NULL) { + ret = cherokee_mime_new (&SRV(server)->mime); + if (ret != ret_ok) return 1; + } + + ret = cherokee_mime_get_by_type (SRV(server)->mime, $2, &entry); + if (ret != ret_ok) { + cherokee_mime_entry_new (&entry); + cherokee_mime_add_entry (SRV(server)->mime, entry); + } + + current_mime_entry = entry; +} +mimetype_options '}' +{ + current_mime_entry = NULL; +} + +mimetype_options : T_MAX_AGE T_NUMBER +{ + cherokee_mime_entry_set_maxage (current_mime_entry, $2); +}; + +mimetype_options : T_EXTENSION id_list +{ + ret_t ret; + linked_list_t *i; + + i = $2; + while (i != NULL) { + ret = cherokee_mime_set_by_suffix (SRV(server)->mime, i->string, current_mime_entry); + if (ret != ret_ok) return ret; + + free (i->string); + i = i->next; + } +}; + icons : T_ICONS T_FULLDIR { SRV(server)->icons_file = $2; Modified: cherokee/cherokee/read_config_scanner.l =================================================================== --- cherokee/cherokee/read_config_scanner.l 2006-01-12 20:29:39 UTC (rev 136) +++ cherokee/cherokee/read_config_scanner.l 2006-01-13 22:11:56 UTC (rev 137) @@ -44,6 +44,7 @@ ip4_mask [\/\\]({ip4_dir}|[0-9]{1,2}) ip4 {ip4_dir}{ip4_mask}{0,1} domain_name [\.\-_a-zA-Z0-9]* +mime_type [a-z0-9\-]+\/[a-z0-9\-]+ hex_255 [0-9a-fA-F]{1,4} ip6_part {hex_255}":"? @@ -71,6 +72,7 @@ "Directory" { return T_DIRECTORY; } "Extension" { return T_EXTENSION; } "Request" { return T_REQUEST; } +"MimeType" { return T_MIMETYPE; } "KeepAlive" { return T_KEEPALIVE; } "MaxKeepAliveRequests" { return T_KEEPALIVE_MAX_REQUESTS; } "ErrorHandler" { return T_ERROR_HANDLER; } @@ -111,6 +113,7 @@ "policy" { return T_POLICY; } "OnlySecure" { return T_ONLY_SECURE; } "MaxConnectionReuse" { return T_MAX_CONNECTION_REUSE; } +"MaxAge" { return T_MAX_AGE; } "Env" { return T_ENV; } "HeaderFile" { return T_HEADERFILE; } "On" { yylval.number = 1; return T_NUMBER; } @@ -120,6 +123,7 @@ {http} { yylval.string = strdup(yytext); return T_HTTP_URL; } {https} { yylval.string = strdup(yytext); return T_HTTPS_URL; } {id} { yylval.string = strdup(yytext); return T_ID; } +{mime_type} { yylval.string = strdup(yytext); return T_MIMETYPE_ID; } {ip} { yylval.string = strdup(yytext); return T_IP; } {qstring} { int len = strlen(yytext); yylval.string = (char *) malloc (len-1); Modified: cherokee/cherokee/server-protected.h =================================================================== --- cherokee/cherokee/server-protected.h 2006-01-12 20:29:39 UTC (rev 136) +++ cherokee/cherokee/server-protected.h 2006-01-13 22:11:56 UTC (rev 137) @@ -54,6 +54,7 @@ #include "iocache.h" #include "regex.h" #include "nonce.h" +#include "mime.h" struct cherokee_server { @@ -150,6 +151,11 @@ char *chroot; int chrooted; + /* Mime + */ + char *mime_file; + cherokee_mime_t *mime; + /* Time */ int timeout; @@ -166,7 +172,6 @@ /* Another config files */ char *config_file; - char *mime_file; char *icons_file; /* Performance Modified: cherokee/cherokee/server.c =================================================================== --- cherokee/cherokee/server.c 2006-01-12 20:29:39 UTC (rev 136) +++ cherokee/cherokee/server.c 2006-01-13 22:11:56 UTC (rev 137) @@ -111,7 +111,11 @@ */ n->config_file = NULL; n->icons_file = NULL; + + /* Mime types + */ n->mime_file = NULL; + n->mime = NULL; /* Exit related */ @@ -313,6 +317,11 @@ srv->mime_file = NULL; } + if (srv->mime != NULL) { + cherokee_mime_free (srv->mime); + srv->mime = NULL; + } + cherokee_iocache_free_default (srv->iocache); cherokee_regex_table_free (srv->regexs);
|