comparison src/conf.c @ 366:41958685480d

Switched to `type *name' style Andrew Koenig's ``C Traps and Pitfalls'' (Ch.2.1) convinced me that it is best to go with the way C had been designed. The ``declaration reflects use'' concept conflicts with a ``type* name'' notation. Hence I switched.
author markus schnalke <meillo@marmaro.de>
date Thu, 22 Sep 2011 15:07:40 +0200
parents 84e6b552f6ad
children b27f66555ba8
comparison
equal deleted inserted replaced
365:934a223e4ee8 366:41958685480d
47 fprintf(stderr, "group %s not found! (terminating)\n", DEF_MAIL_GROUP); 47 fprintf(stderr, "group %s not found! (terminating)\n", DEF_MAIL_GROUP);
48 exit(1); 48 exit(1);
49 } 49 }
50 } 50 }
51 51
52 static gchar* true_strings[] = { 52 static gchar *true_strings[] = {
53 "yes", "on", "true", NULL 53 "yes", "on", "true", NULL
54 }; 54 };
55 55
56 static gchar *false_strings[] = { 56 static gchar *false_strings[] = {
57 "no", "off", "false", NULL 57 "no", "off", "false", NULL
58 }; 58 };
59 59
60 static gboolean 60 static gboolean
61 parse_boolean(gchar * rval) 61 parse_boolean(gchar *rval)
62 { 62 {
63 gchar **str; 63 gchar **str;
64 64
65 DEBUG(9) fprintf(stderr, "parse_boolean: %s\n", rval); 65 DEBUG(9) fprintf(stderr, "parse_boolean: %s\n", rval);
66 66
82 exit(1); 82 exit(1);
83 } 83 }
84 84
85 /* make a list from each line in a file */ 85 /* make a list from each line in a file */
86 static GList* 86 static GList*
87 parse_list_file(gchar * fname) 87 parse_list_file(gchar *fname)
88 { 88 {
89 GList *list = NULL; 89 GList *list = NULL;
90 FILE *fptr; 90 FILE *fptr;
91 91
92 if ((fptr = fopen(fname, "rt")) == NULL) { 92 if ((fptr = fopen(fname, "rt")) == NULL) {
109 return list; 109 return list;
110 } 110 }
111 111
112 /* given a semicolon separated string, this function makes a GList out of it. */ 112 /* given a semicolon separated string, this function makes a GList out of it. */
113 GList* 113 GList*
114 parse_list(gchar * line, gboolean read_file) 114 parse_list(gchar *line, gboolean read_file)
115 { 115 {
116 GList *list = NULL; 116 GList *list = NULL;
117 gchar buf[256]; 117 gchar buf[256];
118 gchar *p, *q; 118 gchar *p, *q;
119 119
147 into a list and returned. 147 into a list and returned.
148 This funktion is used for lists of addrs containing globbing chars (* and ?). 148 This funktion is used for lists of addrs containing globbing chars (* and ?).
149 We don't need valid RFC821 addresses here, just patterns to match against. 149 We don't need valid RFC821 addresses here, just patterns to match against.
150 */ 150 */
151 static GList* 151 static GList*
152 parse_address_glob_list(gchar * line, gboolean read_file) 152 parse_address_glob_list(gchar *line, gboolean read_file)
153 { 153 {
154 GList *plain_list = parse_list(line, read_file); 154 GList *plain_list = parse_list(line, read_file);
155 GList *node; 155 GList *node;
156 GList *list = NULL; 156 GList *list = NULL;
157 157
158 foreach(plain_list, node) { 158 foreach(plain_list, node) {
159 gchar *item = (gchar *) (node->data); 159 gchar *item = (gchar *) (node->data);
160 char* at; 160 char *at;
161 char* p; 161 char *p;
162 address *addr = calloc(1, sizeof(address)); 162 address *addr = calloc(1, sizeof(address));
163 163
164 for (p=item+strlen(item)-1; isspace(*p) || *p=='>'; p--) { 164 for (p=item+strlen(item)-1; isspace(*p) || *p=='>'; p--) {
165 *p = '\0'; 165 *p = '\0';
166 } 166 }
186 g_list_free(plain_list); 186 g_list_free(plain_list);
187 return list; 187 return list;
188 } 188 }
189 189
190 static GList* 190 static GList*
191 parse_resolve_list(gchar * line) 191 parse_resolve_list(gchar *line)
192 { 192 {
193 GList *list; 193 GList *list;
194 GList *list_node; 194 GList *list_node;
195 GList *res_list = NULL; 195 GList *res_list = NULL;
196 196
218 g_list_free(list); 218 g_list_free(list);
219 return res_list; 219 return res_list;
220 } 220 }
221 221
222 static interface* 222 static interface*
223 parse_interface(gchar * line, gint def_port) 223 parse_interface(gchar *line, gint def_port)
224 { 224 {
225 gchar buf[256]; 225 gchar buf[256];
226 gchar *p, *q; 226 gchar *p, *q;
227 interface *iface; 227 interface *iface;
228 228
247 return iface; 247 return iface;
248 } 248 }
249 249
250 #ifdef ENABLE_IDENT /* so far used for that only */ 250 #ifdef ENABLE_IDENT /* so far used for that only */
251 static struct in_addr* 251 static struct in_addr*
252 parse_network(gchar * line, gint def_port) 252 parse_network(gchar *line, gint def_port)
253 { 253 {
254 gchar buf[256]; 254 gchar buf[256];
255 gchar *p, *q; 255 gchar *p, *q;
256 struct in_addr addr, mask_addr, net_addr, *p_net_addr; 256 struct in_addr addr, mask_addr, net_addr, *p_net_addr;
257 guint n; 257 guint n;
290 return p_net_addr; 290 return p_net_addr;
291 } 291 }
292 #endif 292 #endif
293 293
294 static gboolean 294 static gboolean
295 eat_comments(FILE * in) 295 eat_comments(FILE *in)
296 { 296 {
297 gint c; 297 gint c;
298 298
299 for (c = fgetc(in); (c == '#' || isspace(c)) && c != EOF; 299 for (c = fgetc(in); (c == '#' || isspace(c)) && c != EOF;
300 c = fgetc(in)) { 300 c = fgetc(in)) {
309 return TRUE; 309 return TRUE;
310 } 310 }
311 311
312 /* after parsing, eat trailing character until LF */ 312 /* after parsing, eat trailing character until LF */
313 static gboolean 313 static gboolean
314 eat_line_trailing(FILE * in) 314 eat_line_trailing(FILE *in)
315 { 315 {
316 gint c; 316 gint c;
317 317
318 for (c = fgetc(in); c != EOF && c != '\n'; c = fgetc(in)); 318 for (c = fgetc(in); c != EOF && c != '\n'; c = fgetc(in));
319 if (c == EOF) 319 if (c == EOF)
320 return FALSE; 320 return FALSE;
321 return TRUE; 321 return TRUE;
322 } 322 }
323 323
324 static gboolean 324 static gboolean
325 eat_spaces(FILE * in) 325 eat_spaces(FILE *in)
326 { 326 {
327 gint c; 327 gint c;
328 328
329 for (c = fgetc(in); c != EOF && isspace(c); c = fgetc(in)) { 329 for (c = fgetc(in); c != EOF && isspace(c); c = fgetc(in)) {
330 /* empty */ 330 /* empty */
334 ungetc(c, in); 334 ungetc(c, in);
335 return TRUE; 335 return TRUE;
336 } 336 }
337 337
338 static gboolean 338 static gboolean
339 read_lval(FILE * in, gchar * buf, gint size) 339 read_lval(FILE *in, gchar *buf, gint size)
340 { 340 {
341 gint c; 341 gint c;
342 gchar *ptr = buf; 342 gchar *ptr = buf;
343 343
344 DEBUG(9) fprintf(stderr, "read_lval()\n"); 344 DEBUG(9) fprintf(stderr, "read_lval()\n");
371 371
372 return buf[0] != '\0'; 372 return buf[0] != '\0';
373 } 373 }
374 374
375 static gboolean 375 static gboolean
376 read_rval(FILE * in, gchar * buf, gint size) 376 read_rval(FILE *in, gchar *buf, gint size)
377 { 377 {
378 gint c; 378 gint c;
379 gchar *ptr = buf; 379 gchar *ptr = buf;
380 380
381 DEBUG(9) fprintf(stderr, "read_rval()\n"); 381 DEBUG(9) fprintf(stderr, "read_rval()\n");
419 419
420 return TRUE; 420 return TRUE;
421 } 421 }
422 422
423 static gboolean 423 static gboolean
424 read_statement(FILE * in, gchar * lval, gint lsize, gchar * rval, gint rsize) 424 read_statement(FILE *in, gchar *lval, gint lsize, gchar *rval, gint rsize)
425 { 425 {
426 gint c; 426 gint c;
427 427
428 DEBUG(9) fprintf(stderr, "read_statement()\n"); 428 DEBUG(9) fprintf(stderr, "read_statement()\n");
429 429
447 } 447 }
448 return FALSE; 448 return FALSE;
449 } 449 }
450 450
451 gboolean 451 gboolean
452 read_conf(gchar * filename) 452 read_conf(gchar *filename)
453 { 453 {
454 FILE *in; 454 FILE *in;
455 455
456 conf.log_max_pri = 7; 456 conf.log_max_pri = 7;
457 conf.do_relay = TRUE; 457 conf.do_relay = TRUE;
608 608
609 if (conf.warn_intervals == NULL) 609 if (conf.warn_intervals == NULL)
610 conf.warn_intervals = parse_list("1h;4h;8h;1d;2d;3d", FALSE); 610 conf.warn_intervals = parse_list("1h;4h;8h;1d;2d;3d", FALSE);
611 611
612 if (!conf.local_hosts) { 612 if (!conf.local_hosts) {
613 char* shortname = strdup(conf.host_name); 613 char *shortname = strdup(conf.host_name);
614 char* p = strchr(shortname, '.'); 614 char *p = strchr(shortname, '.');
615 if (p) { 615 if (p) {
616 *p = '\0'; 616 *p = '\0';
617 } 617 }
618 /* we don't care if shortname and conf.host_name are the same */ 618 /* we don't care if shortname and conf.host_name are the same */
619 char* local_hosts_str = g_strdup_printf("localhost;%s;%s", shortname, conf.host_name); 619 char *local_hosts_str = g_strdup_printf("localhost;%s;%s", shortname, conf.host_name);
620 conf.local_hosts = parse_list(local_hosts_str, FALSE); 620 conf.local_hosts = parse_list(local_hosts_str, FALSE);
621 free(shortname); 621 free(shortname);
622 free(local_hosts_str); 622 free(local_hosts_str);
623 } 623 }
624 624
625 625
626 return TRUE; 626 return TRUE;
627 } 627 }
628 628
629 connect_route* 629 connect_route*
630 read_route(gchar * filename, gboolean is_perma) 630 read_route(gchar *filename, gboolean is_perma)
631 { 631 {
632 gboolean ok = FALSE; 632 gboolean ok = FALSE;
633 FILE *in; 633 FILE *in;
634 634
635 connect_route *route = g_malloc(sizeof(connect_route)); 635 connect_route *route = g_malloc(sizeof(connect_route));
797 797
798 return route; 798 return route;
799 } 799 }
800 800
801 static void 801 static void
802 _g_list_free_all(GList * list) 802 _g_list_free_all(GList *list)
803 { 803 {
804 GList *node; 804 GList *node;
805 if (list) { 805 if (list) {
806 foreach(list, node) 806 foreach(list, node)
807 g_free(node->data); 807 g_free(node->data);
808 g_list_free(list); 808 g_list_free(list);
809 } 809 }
810 } 810 }
811 811
812 void 812 void
813 destroy_route(connect_route * r) 813 destroy_route(connect_route *r)
814 { 814 {
815 if (r->filename) 815 if (r->filename)
816 g_free(r->filename); 816 g_free(r->filename);
817 if (r->mail_host) { 817 if (r->mail_host) {
818 g_free(r->mail_host->address); 818 g_free(r->mail_host->address);
848 g_free(r->pipe); 848 g_free(r->pipe);
849 g_free(r); 849 g_free(r);
850 } 850 }
851 851
852 GList* 852 GList*
853 read_route_list(GList * rf_list, gboolean is_perma) 853 read_route_list(GList *rf_list, gboolean is_perma)
854 { 854 {
855 GList *list = NULL; 855 GList *list = NULL;
856 GList *node; 856 GList *node;
857 uid_t saved_uid, saved_gid; 857 uid_t saved_uid, saved_gid;
858 858
876 876
877 return list; 877 return list;
878 } 878 }
879 879
880 void 880 void
881 destroy_route_list(GList * list) 881 destroy_route_list(GList *list)
882 { 882 {
883 GList *node; 883 GList *node;
884 884
885 foreach(list, node) { 885 foreach(list, node) {
886 connect_route *route = (connect_route *) (node->data); 886 connect_route *route = (connect_route *) (node->data);