static int tableident(Dssfile_t* file, void* buf, size_t n, Dssdisc_t* disc) { register char* s; register char* e; register char* f; register int c; unsigned char prefix[IP6PREFIX]; Bgpnum_t addr; unsigned char bits; s = (char*)buf; e = s + n; for (;;) { for (;;) { if (s >= e) return 0; c = *s++; if (!isascii(c)) return 0; if (!isspace(c)) break; } f = s - 1; for (;;) { if (s >= e) return 0; c = *s++; if (!isascii(c)) return 0; if (c == '\n') break; } if (isdigit(*f) && !strtoip4(f, NiL, &addr, &bits) || !strtoip6(f, NiL, prefix, prefix + IP6BITS) && (file->caller = file)) break; } return 1; }
static int tableread(Dssfile_t* file, Dssrecord_t* record, Dssdisc_t* disc) { register Tablestate_t* state = (Tablestate_t*)file->data; register Bgproute_t* rp; register char* s; char* p; char* e; Bgproute_t* op; for (;;) { op = &state->route[state->index]; rp = &state->route[state->index = !state->index]; if (!(s = sfgetr(file->io, '\n', 1))) return 0; while (*s == ' ' || *s == '\t' || *s == '\r') s++; if (*s == 0 || *s == '#' || *s == '\n') continue; rp->set = 0; rp->type = BGP_TYPE_withdraw; rp->attr = BGP_valid; rp->origin = BGP_ORIGIN_incomplete; if (state->v6) { rp->addr.v4 = 0; rp->bits = 0; if (strtoip6(s, &p, rp->prefixv6, rp->prefixv6 + IP6BITS)) break; rp->set |= BGP_SET_prefixv6; for (s = p; *s == ' ' || *s == '\t'; s++); rp->hop.v4 = strtoul(s, &p, 0); switch (*p) { case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case ':': rp->hop.v4 = 0; if (!strtoip6(s, &e, rp->hop.v6, NiL) && e > p) { rp->type = BGP_TYPE_announce; rp->attr |= BGP_slot; rp->set |= BGP_SET_hopv6; } break; case '.': if (strtoip4(s, &e, &rp->hop.v4, NiL) || e <= p) break; /*FALLTHROUGH*/ default: if (rp->hop.v4) { rp->type = BGP_TYPE_announce; rp->attr |= BGP_slot; } break; } if ((rp->set & BGP_SET_prefixv6) && memcmp(rp->prefixv6, op->prefixv6, sizeof(rp->prefixv6))) rp->attr |= BGP_best; else if ((rp->set & BGP_SET_hopv6) && !memcmp(rp->hop.v6, op->hop.v6, sizeof(rp->hop.v6))) continue; else if (rp->hop.v4 && op->hop.v4 && rp->hop.v4 == op->hop.v4) continue; } else { if (strtoip4(s, &p, &rp->addr.v4, &rp->bits)) break; for (s = p; *s == ' ' || *s == '\t'; s++); rp->hop.v4 = strtoul(s, &p, 0); if (p > s && (*p != '.' || !strtoip4(s, NiL, &rp->hop.v4, NiL)) && rp->hop.v4) { rp->type = BGP_TYPE_announce; rp->attr |= BGP_slot; } if (rp->addr.v4 != op->addr.v4 || rp->bits != op->bits) rp->attr |= BGP_best; else if (rp->hop.v4 == op->hop.v4) continue; } record->data = rp; record->size = BGP_FIXED; return 1; } return 0; }
static int textread(register Dssfile_t* file, Dssrecord_t* record, Dssdisc_t* disc) { register Cxvalue_t* data = (Cxvalue_t*)file->data; register Text_t* text = (Text_t*)file->dss->meth->data; register char* s; register char* f; register int c; char* t; int num; int q; Ipaddr_t a; if (!(s = sfgetr(file->io, '\n', 1))) return 0; num = 0; f = text->format; for (;;) { switch (c = *f++) { case 0: break; case ' ': while (*s == ' ' || *s == '\t') s++; break; case '%': switch (c = *f++) { case 'h': case 'l': q = c; c = *f++; break; default: q = 0; break; } switch (c) { case 0: f--; continue; case '%': if (*s++ != c) s = null; continue; case 'c': if (data[num].number = *s) s++; num++; break; case 'd': c = 10; goto number; case 'i': if (!*s) data[num].number = 0; else { strtoip4(s, &t, &a, NiL); data[num].number = a; s = t; } num++; break; case 'n': case 'u': c = 0; goto number; case 'o': c = 8; goto number; case 'x': c = 16; number: if (!*s) data[num].number = 0; else { data[num].number = strtol(s, &t, c); s = t; } num++; break; case 'f': case 'g': if (!*s) data[num].number = 0; else { data[num].number = strtod(s, &t); s = t; } num++; break; case 's': if (q = *f) f++; if (!*s) { data[num].string.data = null; data[num].string.size = 0; } else s = lextok(s, q, &data[num].string); num++; break; case 't': if (!*s) data[num].number = 0; else { data[num].number = tmdate(s, &t, NiL); if (*t && *t != *f && *t != '\n') data[num].number = strtol(s, &t, 0); s = t; } num++; break; } continue; case '\n': break; default: if (*s++ != c) s = null; continue; } break; } record->data = data; return 1; }