• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • Directories
  • File List
  • Globals

cfg_parser.h

Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  * Standalone Configuration File Parser
00004  *
00005  * Copyright (C) 2008 iptelorg GmbH
00006  * Written by Jan Janak <jan@iptel.org>
00007  *
00008  * This file is part of SER, a free SIP server.
00009  *
00010  * SER is free software; you can redistribute it and/or modify it under the
00011  * terms of the GNU General Public License as published by the Free Software
00012  * Foundation; either version 2 of the License, or (at your option) any later
00013  * version.
00014  *
00015  * SER is distributed in the hope that it will be useful, but WITHOUT ANY
00016  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00018  * details.
00019  *
00020  * You should have received a copy of the GNU General Public License along
00021  * with this program; if not, write to the Free Software Foundation, Inc., 
00022  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00023  */
00024 
00035 #ifndef _CFG_PARSER_H
00036 #define _CFG_PARSER_H
00037 
00038 #include "str.h"
00039 #include <stdio.h>
00040 
00041 #define MAX_TOKEN_LEN 512 
00045 typedef enum cfg_flags {
00046 
00050         CFG_EXTENDED_ALPHA = (1 << 0),
00051 
00056         CFG_CASE_SENSITIVE = (1 << 1), 
00057 
00063         CFG_DEFAULT = (1 << 2),
00064 
00065 
00069         CFG_PREFIX = (1 << 3),
00070 
00075         CFG_STR_PKGMEM = (1 << 4),
00076 
00081         CFG_STR_SHMMEM = (1 << 5),
00082 
00087         CFG_STR_MALLOC = (1 << 6),
00088 
00093         CFG_STR_STATIC = (1 << 7),
00094 
00095 } cfg_flags_t;
00096 
00097 
00098 enum cfg_token_type {
00099         CFG_TOKEN_EOF    = -1,
00100         CFG_TOKEN_ALPHA  = -2,
00101         CFG_TOKEN_STRING = -3
00102 };
00103 
00104 
00106 typedef struct cfg_token {
00107         char buf [MAX_TOKEN_LEN];
00108         int type;  
00109         str val;   
00110         struct {   
00111                 int line; 
00112                 int col;  
00113         } start, end;
00114 } cfg_token_t;
00115 
00116 
00117 struct cfg_parser;
00118 
00119 typedef int (*cfg_func_f)(void* param, struct cfg_parser* st,
00120                                                   unsigned int flags);
00121 
00122 
00128 typedef struct cfg_option {
00129         char* name;    
00130         unsigned int flags;
00131         void* param;   
00132         int val;       
00133         cfg_func_f f;  
00134 } cfg_option_t;
00135 
00136 
00138 typedef struct cfg_parser {
00139         FILE* f;                 
00140         char* file;              
00141         int line;                
00142         int col;                 
00143         struct cfg_option* options; 
00144         struct {
00145                 cfg_func_f parser;   
00146                 void* param;         
00147         } section;
00148         struct cfg_token* cur_opt; 
00149 } cfg_parser_t;
00150 
00151 
00152 extern struct cfg_option cfg_bool_values[];
00153 
00154 struct cfg_parser* cfg_parser_init(str* basedir, str* filename);
00155 
00156 void cfg_section_parser(struct cfg_parser* st, cfg_func_f parser, void* param);
00157 
00158 void cfg_set_options(struct cfg_parser* st, struct cfg_option* options);
00159 
00160 int sr_cfg_parse(struct cfg_parser* st);
00161 
00162 void cfg_parser_close(struct cfg_parser* st);
00163 
00164 struct cfg_option* cfg_lookup_token(struct cfg_option* options, str* token);
00165 
00167 int cfg_get_token(struct cfg_token* token, struct cfg_parser* st, unsigned int flags);
00168 
00169 /* Commonly needed parser functions */
00170 
00171 int cfg_eat_equal(struct cfg_parser* st, unsigned int flags);
00172 
00173 int cfg_eat_eol(struct cfg_parser* st, unsigned int flags);
00174 
00179 int cfg_parse_section(void* param, struct cfg_parser* st, unsigned int flags);
00180 
00182 int cfg_parse_str_opt(void* param, struct cfg_parser* st, unsigned int flags);
00183 
00184 int cfg_parse_str(void* param, struct cfg_parser* st, unsigned int flags);
00185 
00186 int cfg_parse_enum_opt(void* param, struct cfg_parser* st, unsigned int flags);
00187 
00188 int cfg_parse_enum(void* param, struct cfg_parser* st, unsigned int flags);
00189 
00191 int cfg_parse_int_opt(void* param, struct cfg_parser* st, unsigned int flags);
00192 
00193 int cfg_parse_int(void* param, struct cfg_parser* st, unsigned int flags);
00194 
00196 int cfg_parse_bool_opt(void* param, struct cfg_parser* st, unsigned int flags);
00197 
00198 int cfg_parse_bool(void* param, struct cfg_parser* st, unsigned int flags);
00199 
00200 #endif /* _CFG_PARSER_H */

Generated on Tue May 22 2012 13:10:04 for SIP Router by  doxygen 1.7.1