9 #include "cfg_parser.h"
10 #include "msg_parser.h" /* parse_hostport */
18 /* params: null terminated text line => fills cl
19 * returns 0, or on error -1. */
20 int cfg_parse_line(char* line, struct cfg_line* cl)
25 rule = SP* method_re SP* uri_re SP* ip_address comment?
31 end=line+strlen(line);
32 tmp=eat_space(line, end-line);
33 if ((tmp==end)||(is_empty(tmp, end-tmp))) {
42 tmp=eat_token(cl->method,end-cl->method);
43 if (tmp==end) goto error;
46 cl->uri=eat_space(tmp,end-tmp);
47 if (tmp==end) goto error;
48 tmp=eat_token(cl->uri,end-cl->uri);
49 if (tmp==end) goto error;
52 cl->address=eat_space(tmp,end-tmp);
53 if (tmp==end) goto error;
54 tmp=eat_token(cl->address, end-cl->address);
58 if (!is_empty(tmp+1,end-tmp-1)){
59 /* check if comment */
60 tmp=eat_space(tmp+1, end-tmp-1);
62 /* extra chars at the end of line */
69 if (parse_hostport(cl->address, &tmp, &cl->port)==0){
83 /* parses the cfg, returns 0 on success, line no otherwise */
84 int cfg_parse_stream(FILE* stream)
88 char buf[MAX_LINE_SIZE];
93 if (fgets(buf, MAX_LINE_SIZE, stream)){
94 cfg_parse_line(buf, &cl);
97 if ((ret=add_rule(&cl, &rlist))!=0){
98 DPrint("ERROR: could not compile rule at line %d\n",
100 DPrint(" ----: add_rule returned %d\n", ret);
108 DPrint("ERROR: bad config line (%d):%s\n", line, buf);
115 DPrint("ERROR: reading configuration: %s\n", strerror(errno));