/* This file is in the public domain. */ /* * MAP implementation for `error' map lines. */ #include #include #include "repo.h" #include "config.h" #include "structs.h" /* * Forward declaration of our MAP_OPS. */ extern const MAP_OPS map_ops_trivial; /* * We actually have no internal data structure per se. We need the * LISTEN pointer, but rather than wrap it in another struct, we just * stuff it directly in the priv field of the MAP. */ /* * Our add method. See if the line is a `trivial' line; if so, create * the MAP. (As mentioned above, we don't have a private data * structure to create.) */ static int map_trivial_add(CONFIG *cfg, LISTEN *l, int pri, const char *key, int keylen, const char *rest) { MAP *map; if ((keylen != 7) || bcmp(key,"trivial",7)) return(0); if (*rest) config_err(cfg,"trailing junk on `map trivial' listen line"); map = malloc(sizeof(MAP)); map->pri = pri; map->ops = &map_ops_trivial; map->priv = l; map->link = l->mappings; l->mappings = map; return(1); } /* * Our match method. We are defined to match any defined repository * name (which is why we need the LISTEN - to get hold of its conf's * list of repositories). * * We need to be careful, though, because a LISTEN can out-survive its * CONFIG. In this case, the list of repositories no longer exists, * so we match nothing (there's not much else to do). */ static MAPMATCH map_trivial_match(void *pv, const char *name) { REPO *r; if (! ((LISTEN *)pv)->conf) return(MATCH_NOMATCH); for (r=((LISTEN *)pv)->conf->repos;r;r=r->link) if (!strcmp(name,r->name)) return(MATCH_MATCH); return(MATCH_NOMATCH); } /* * Our map method. We are defined to map any string we match to that * same string, so we don't need to even look at the LISTEN here; we * are called only on a match, and we're passed the external string * that matched. */ static char *map_trivial_map(void *pv __attribute__((__unused__)), const char *name) { return(strdup(name)); } /* * Our free method. Since we have no internal data structure per se, * we have nothing to do here. */ static void map_trivial_free(void *pv __attribute__((__unused__))) { } /* * Our MAP_OPS. */ const MAP_OPS map_ops_trivial = MAP_OPS_INIT(trivial);