/* This file is in the public domain. */ #include #include #include #include "ctype.h" #include "config.h" #include "structs.h" extern LEP_OPS lep_ops_local; extern LEP_OPS lep_ops_ip; static LEP_OPS *leps[] = { &lep_ops_local, &lep_ops_ip }; extern MAP_OPS map_ops_trivial; extern MAP_OPS map_ops_error; extern MAP_OPS map_ops_simple; extern MAP_OPS map_ops_regex; static MAP_OPS *maps[] = { &map_ops_trivial, &map_ops_error, &map_ops_simple, &map_ops_regex }; typedef struct sect_listen_priv SECT_LISTEN_PRIV; struct sect_listen_priv { LISTEN *l; CONFIG *cfg; } ; static void *sect_listen_start(const char *line, CONFIG *cfg) { int i; SECT_LISTEN_PRIV *p; i = 0; while (line[i] && UCisspace(line[i])) i ++; if (strncmp(line+i,"listen",6) || (line[i+6] && !UCisspace(line[i+6]))) return(0); i += 6; while (line[i] && UCisspace(line[i])) i ++; if (line[i]) config_err(cfg,"junk on listen line"); p = malloc(sizeof(SECT_LISTEN_PRIV)); p->l = malloc(sizeof(LISTEN)); p->l->refs = 1; p->l->permit = 0; p->l->endpoints = 0; p->l->mappings = 0; p->cfg = cfg; return(p); } static SPRV sect_listen_parse(void *pv, const char *line) { int i; int j; int k; SECT_LISTEN_PRIV *p; int x; p = pv; i = 0; while (line[i] && UCisspace(line[i])) i ++; j = i; while (line[i] && !UCisspace(line[i])) i ++; k = i; while (line[i] && UCisspace(line[i])) i ++; if ((k-j == 6) && !bcmp(line+j,"permit",6)) { while (line[i]) { j = i; while (line[i] && !UCisspace(line[i])) i ++; k = i; while (line[i] && UCisspace(line[i])) i ++; if ((k-j == 8) && !bcmp(line+j,"new-data",8)) { p->l->permit |= OP_NEW; } else if ((k-j == 5) && !bcmp(line+j,"fetch",5)) { p->l->permit |= OP_FETCH; } else if ((k-j == 1) && (line[j] == '*')) { p->l->permit |= OP_NEW | OP_FETCH; } else { config_err(p->cfg,"invalid operation `%.*s' on `permit' line",k-j,line+j); } } return(SPRV_GOOD); } else if ((k-j == 3) && !bcmp(line+j,"map",3)) { j = i; while (line[i] && !UCisspace(line[i])) i ++; k = i; while (line[i] && UCisspace(line[i])) i ++; for (x=(sizeof(maps)/sizeof(maps[0]))-1;x>=0;x--) { if ((*maps[x]->add)(p->cfg,p->l,line+j,k-j,line+i)) { return(SPRV_GOOD); } } } else { for (x=(sizeof(leps)/sizeof(leps[0]))-1;x>=0;x--) { if ((*leps[x]->add)(p->cfg,p->l,line+j,k-j,line+i)) { return(SPRV_GOOD); } } } return(SPRV_UNKNOWN); } static void sect_listen_done(void *pv) { SECT_LISTEN_PRIV *p; p = pv; if (p->l->permit == 0) config_warn(p->cfg,"`listen' section does not permit any operations"); if (p->l->endpoints == 0) config_warn(p->cfg,"`listen' section has no listening endpoints"); if (p->l->mappings == 0) config_warn(p->cfg,"`listen' section has no mappings"); p->l->link = p->cfg->listens; p->cfg->listens = p->l; free(p); } SECT_OPS sectops_listen = SECT_OPS_INIT(listen);