/* This file is in the public domain. */ #include #include #include #include "repo.h" #include "structs.h" #include "data.h" void data_record(LISTEN *l, char *name, char *stamp, char *data, void (*err)(const char *, ...)) { MAP *m; int maxpri; int errpri; unsigned long long int ts; char *ep; char *mapped; char *mstr; REPO *r; printf("data_record: name=%s stamp=%s data=%s\n",name,stamp,data); // debugging ts = strtoull(stamp,&ep,10); if ((ep == stamp) || *ep) { printf("bad timestamp\n"); // debugging (*err)("invalid timestamp value"); } maxpri = -1; errpri = -1; for (m=l->mappings;m;m=m->link) { if (m->pri < maxpri) continue; switch ((*m->ops->match)(m->priv,name)) { case MATCH_NOMATCH: m->flags &= ~MF_MATCHED; break; case MATCH_MATCH: m->flags |= MF_MATCHED; maxpri = m->pri; break; case MATCH_ERROR: errpri = m->pri; break; default: abort(); break; } } if ((errpri >= 0) && (maxpri <= errpri)) { printf("error match\n"); // debugging (*err)("bad repository name"); } if (maxpri < 0) { printf("no matching mapping\n"); // debugging (*err)("unmatched repository name"); } mapped = 0; for (m=l->mappings;m;m=m->link) { if ((m->pri != maxpri) || !(m->flags & MF_MATCHED)) continue; mstr = (*m->ops->map)(m->priv,name); printf("mapped to %s\n",mstr); // debugging if (mapped && strcmp(mstr,mapped)) { printf("mapping conflict\n"); free(mapped); free(mstr); (*err)("ambiguous repository name"); } free(mapped); mapped = mstr; } if (! mapped) abort(); for (r=l->conf->repos;r;r=r->link) { if (! strcmp(mapped,r->name)) { printf("recording\n"); // debugging free(mapped); repo_record(r,ts,data,err); return; } } printf("no repo found\n"); // debugging free(mapped); (*err)("unknown repository name"); }