59 |
59 |
60 return conf; |
60 return conf; |
61 } |
61 } |
62 |
62 |
63 void free_mime_config(MimeConfig *conf) { |
63 void free_mime_config(MimeConfig *conf) { |
64 ucx_mempool_destroy(conf->parser.mp); |
64 ucx_mempool_destroy(conf->parser.mp->pool); |
65 free(conf); |
65 free(conf); |
66 } |
66 } |
67 |
67 |
68 int mimeconf_parse(void *p, ConfigLine *begin, ConfigLine *end, sstr_t line) { |
68 int mimeconf_parse(void *p, ConfigLine *begin, ConfigLine *end, sstr_t line) { |
69 MimeConfig *conf = p; |
69 MimeConfig *conf = p; |
70 UcxMempool *mp = conf->parser.mp; |
70 UcxAllocator *mp = conf->parser.mp; |
71 |
71 |
72 // parse mime directive |
72 // parse mime directive |
73 MimeDirective *dir = ucx_mempool_calloc(mp, 1, sizeof(MimeDirective)); |
73 MimeDirective *dir = OBJ_NEW_N(mp, MimeDirective); |
74 |
74 |
75 UcxList *params = cfg_param_list(line, mp); |
75 UcxList *params = cfg_param_list(line, mp); |
76 UCX_FOREACH(UcxList*, params, pl) { |
76 UCX_FOREACH(pl, params) { |
77 ConfigParam *param = pl->data; |
77 ConfigParam *param = pl->data; |
78 |
78 |
79 if(!sstrcmp(param->name, sstr("type"))) { |
79 if(!sstrcmp(param->name, sstr("type"))) { |
80 dir->type = param->value; |
80 dir->type = param->value; |
81 } else if(!sstrcmp(param->name, sstr("exts"))) { |
81 } else if(!sstrcmp(param->name, sstr("exts"))) { |
82 // comma-separated file extensions |
82 // comma-separated file extensions |
83 |
83 |
84 size_t nx = 0; |
84 size_t nx = 0; |
85 sstr_t *exts = sstrsplit(param->value, sstrn(",", 1), &nx); |
85 sstr_t *exts = sstrsplit(param->value, sstrn(",", 1), &nx); |
86 for(int i=0;i<nx;i++) { |
86 for(int i=0;i<nx;i++) { |
87 sstr_t extstr = sstrdup_mp(mp, exts[i]); |
87 sstr_t extstr = sstrdup_a(mp, exts[i]); |
88 dir->exts = ucx_list_append(dir->exts, extstr.ptr); |
88 dir->exts = ucx_list_append_a(mp, dir->exts, extstr.ptr); |
89 free(exts[i].ptr); |
89 free(exts[i].ptr); |
90 } |
90 } |
91 free(exts); |
91 free(exts); |
92 } |
92 } |
93 } |
93 } |
94 |
94 |
95 cfg_list_destr(mp, dir->exts); |
95 conf->directives = ucx_list_append_a(mp, conf->directives, dir); |
96 conf->directives = ucx_list_append(conf->directives, dir); |
|
97 conf->ntypes++; |
96 conf->ntypes++; |
98 |
97 |
99 return 0; |
98 return 0; |
100 } |
99 } |