/* This file is in the public domain. */ /* * MAP implementation for `error' map lines. */ #include #include #include "util.h" #include "ctype.h" #include "config.h" #include "structs.h" /* * Forward declaration of our MAP_OPS. */ extern const MAP_OPS map_ops_error; /* * Our private data contains only the name we're supposed to match; * nothing more is needed. */ typedef struct map_error_priv MAP_ERROR_PRIV; struct map_error_priv { char *name; } ; /* * Our add method. See if a map line is an `error' line; if so, save * the name, set up the MAP_ERROR_PRIV, and create the MAP. */ static int map_error_add(CONFIG *cfg, LISTEN *l, int pri, const char *key, int keylen, const char *rest) { MAP *map; MAP_ERROR_PRIV *p; int e; int i; if ((keylen != 5) || bcmp(key,"error",5)) return(0); if (! *rest) config_err(cfg,"missing name on `map error' listen line"); i = 0; while (rest[i] && !UCisspace(rest[i])) i ++; e = i; while (rest[i] && UCisspace(rest[i])) i ++; if (rest[i]) config_err(cfg,"trailing junk on `map error' listen line"); p = malloc(sizeof(MAP_ERROR_PRIV)); p->name = blk_to_nulterm(rest,e); map = malloc(sizeof(MAP)); map->pri = pri; map->ops = &map_ops_error; map->priv = p; map->link = l->mappings; l->mappings = map; return(1); } /* * See if an incoming line matches this MAP. We are defined to match a * fixed string, so this is easy. */ static MAPMATCH map_error_match(void *pv, const char *name) { return(strcmp(name,((MAP_ERROR_PRIV *)pv)->name)?MATCH_NOMATCH:MATCH_ERROR); } /* * Map an incoming line to a repository name. Because our match method * never returns MATCH, this should never be called. */ static char *map_error_map(void *pv __attribute__((__unused__)), const char *name __attribute__((__unused__))) { abort(); } /* * Free up our internal data. */ static void map_error_free(void *pv) { MAP_ERROR_PRIV *p; p = pv; free(p->name); free(p); } /* * Our MAP_OPS. */ const MAP_OPS map_ops_error = MAP_OPS_INIT(error);