/* This file is in the public domain. */ #include #include #include "util.h" #include "ctype.h" #include "config.h" #include "structs.h" extern const MAP_OPS map_ops_simple; typedef struct map_simple_priv MAP_SIMPLE_PRIV; struct map_simple_priv { char *extname; char *intname; } ; static int map_simple_add(CONFIG *cfg, LISTEN *l, int pri, const char *key, int keylen, const char *rest) { MAP *map; MAP_SIMPLE_PRIV *p; int e1; int b2; int e2; int i; if ((keylen != 6) || bcmp(key,"simple",6)) return(0); if (! *rest) config_err(cfg,"missing name on `map simple' listen line"); i = 0; while (rest[i] && !UCisspace(rest[i])) i ++; e1 = i; while (rest[i] && UCisspace(rest[i])) i ++; if (! rest[i]) config_err(cfg,"too few names on `map simple' listen line"); b2 = i; while (rest[i] && !UCisspace(rest[i])) i ++; e2 = i; while (rest[i] && UCisspace(rest[i])) i ++; if (rest[i]) config_err(cfg,"trailing junk on `map simple' listen line"); p = malloc(sizeof(MAP_SIMPLE_PRIV)); p->extname = blk_to_nulterm(rest,e1); p->intname = blk_to_nulterm(rest+b2,e2-b2); map = malloc(sizeof(MAP)); map->pri = pri; map->ops = &map_ops_simple; map->priv = p; map->link = l->mappings; l->mappings = map; return(1); } static MAPMATCH map_simple_match(void *pv, const char *name) { return(strcmp(name,((MAP_SIMPLE_PRIV *)pv)->extname)?MATCH_NOMATCH:MATCH_MATCH); } static char *map_simple_map(void *pv, const char *name __attribute__((__unused__))) { return(strdup(((MAP_SIMPLE_PRIV *)pv)->intname)); } static void map_simple_free(void *pv) { MAP_SIMPLE_PRIV *p; p = pv; free(p->extname); free(p->intname); free(p); } const MAP_OPS map_ops_simple = MAP_OPS_INIT(simple);