src/server/config/conf.c

changeset 21
627b09ee74e4
parent 20
7b235fa88008
child 22
adb0bda54e6b
equal deleted inserted replaced
20:7b235fa88008 21:627b09ee74e4
257 * parses a line containing a directive and returns a ConfigDirective object 257 * parses a line containing a directive and returns a ConfigDirective object
258 * or NULL if an error occurs 258 * or NULL if an error occurs
259 */ 259 */
260 ConfigDirective* cfg_parse_directive(sstr_t line, UcxMempool *mp) { 260 ConfigDirective* cfg_parse_directive(sstr_t line, UcxMempool *mp) {
261 if(line.length < 6) { 261 if(line.length < 6) {
262 printf("line too short\n");
262 return NULL; // line too short 263 return NULL; // line too short
263 } 264 }
264 265
265 sstr_t name; 266 sstr_t name;
266 267
485 tag->param = ucx_list_append(tag->param, param); 486 tag->param = ucx_list_append(tag->param, param);
486 } 487 }
487 488
488 return tag; 489 return tag;
489 } 490 }
491
492
493 /* directive functions */
494
495 /*
496 * gets a ConfigDirective with a specific name from a List of directives
497 * returns a directive or NULL, if the directive cannot be found
498 */
499 ConfigDirective* cfg_directivelist_get(UcxDlist *dirs, sstr_t name) {
500 while(dirs != NULL) {
501 ConfigDirective *d = dirs->data;
502 if(d != NULL) {
503 if(!sstrcmp(d->directive_type, name)) {
504 return d;
505 }
506 }
507 dirs = dirs->next;
508 }
509 return NULL;
510 }
511
512 sstr_t cfg_directivelist_get_str(UcxDlist *dirs, sstr_t name) {
513 ConfigDirective *d = cfg_directivelist_get(dirs, name);
514 if(d == NULL) {
515 sstr_t n;
516 n.ptr = NULL;
517 n.length = 0;
518 return n;
519 }
520 return cfg_directive_pstr1(d);
521 }
522
523 /*
524 * returns the name of the first parameter of the directive
525 * useful for 'name value' directives
526 */
527 sstr_t cfg_directive_pstr1(ConfigDirective *dir) {
528 if(dir->param == NULL) {
529 fprintf(stderr, "%s", "Error: cfg_directive_pstr1: param is NULL\n");
530 sstr_t n;
531 n.ptr = NULL;
532 n.length = 0;
533 return n;
534 }
535
536 ConfigParam *p = dir->param->data;
537 return p->name;
538 }
539
540

mercurial