src/server/config/mimeconf.c

changeset 415
d938228c382e
parent 392
0aef555055ee
child 453
4586d534f9b5
--- a/src/server/config/mimeconf.c	Wed Nov 02 19:19:01 2022 +0100
+++ b/src/server/config/mimeconf.c	Sun Nov 06 15:53:32 2022 +0100
@@ -30,13 +30,10 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <ucx/mempool.h>
+#include <cx/mempool.h>
 #include "mimeconf.h"
 
-typedef struct {
-    ucx_destructor destructor;
-    void           *ptr;
-} ucx_regdestr;
+#define MIMECONFIG_MAX_TOKENS 4096
 
 MimeConfig *load_mime_config(const char *file) {
     FILE *in = fopen(file, "r");
@@ -47,7 +44,8 @@
     
     MimeConfig *conf = malloc(sizeof(MimeConfig));
     conf->parser.parse = mimeconf_parse;
-    conf->directives = NULL;
+    conf->directives_begin = NULL;
+    conf->directives_end = NULL;
     conf->ntypes = 0;
     int r = cfg_parse_basic_file((ConfigParser*)conf, in);
     if(r != 0) {
@@ -64,38 +62,29 @@
 }
 
 void free_mime_config(MimeConfig *conf) {
-    ucx_mempool_destroy(conf->parser.mp->pool);
+    //ucx_mempool_destroy(conf->parser.mp->pool);
     free(conf);
 }
 
-int mimeconf_parse(void *p, ConfigLine *begin, ConfigLine *end, sstr_t line) {
+int mimeconf_parse(void *p, ConfigLine *begin, ConfigLine *end, cxmutstr line) {
     MimeConfig *conf = p;
-    UcxAllocator *mp = conf->parser.mp;
+    CxAllocator *mp = conf->parser.mp;
     
     // parse mime directive
     MimeDirective *dir = OBJ_NEW_N(mp, MimeDirective);
     
-    UcxList *params = cfg_param_list(line, mp);
-    UCX_FOREACH(pl, params) {
-        ConfigParam *param = pl->data;
-        
-        if(!sstrcmp(param->name, sstr("type"))) {
+    ConfigParam *params = cfg_param_list(line, mp);
+    for(ConfigParam *param=params;param;param=param->next) { 
+        if(!cx_strcmp(cx_strcast(param->name), cx_str("type"))) {
             dir->type = param->value;
-        } else if(!sstrcmp(param->name, sstr("exts"))) {
+        } else if(!cx_strcmp(cx_strcast(param->name), cx_str("exts"))) {
             // comma-separated file extensions
-            
-            ssize_t nx = 0;
-            sstr_t *exts = sstrsplit(param->value, sstrn(",", 1), &nx);
-            for(int i=0;i<nx;i++) {
-                sstr_t extstr = sstrdup_a(mp, exts[i]);
-                dir->exts = ucx_list_append_a(mp, dir->exts, extstr.ptr);
-                free(exts[i].ptr);
-            }
-            free(exts);
+            dir->nextensions = cx_strsplit_a(mp, cx_strcast(param->value), cx_strn(",", 1), MIMECONFIG_MAX_TOKENS, &dir->extensions);
         }
     }
     
-    conf->directives = ucx_list_append_a(mp, conf->directives, dir);
+    CFG_MIME_ADD(&conf->directives_begin, &conf->directives_end, dir);
+    
     conf->ntypes++;
 
     return 0;

mercurial