whois.c
来自「ftam等标准协议服务器和客户端的源代码。」· C语言 代码 · 共 1,019 行 · 第 1/2 页
C
1,019 行
else w -> w_inputype = W_HANDLE, w -> w_input = w -> w_area + 1; w -> w_record = w -> w_areatype; w -> w_area = NULL, w -> w_areatype = W_NULL; } else if (*w -> w_area == '!') w -> w_area++; if (w -> w_inputype == W_NULL) { register char **ap; if (w -> w_record != W_NULL || w -> w_output != W_NULL) { advise (NULLCP, "input-field missing"); return NOTOK; }print_help: ; for (ap = whois_help; *ap; ap++) (void) fprintf (stdfp, "%s%s", *ap, EOLN); return OK; } else if (w -> w_inputype == W_NAME && w -> w_nametype == W_NULL) w -> w_nametype = nametype ? W_SURNAME : W_COMMONAME; bp = buffer; mailbox = 0; if (w -> w_areatype == W_NULL) { if (w -> w_inputype == W_MAILBOX && w -> w_area == NULL && (cp = index (w -> w_input, '@')) && !index (++cp, '*')) { (void) sprintf (bp, "fred -dm2dn %s", cp); bp += strlen (bp); mailbox = 1; goto multiple_searching; } return whois_aux (w); } (void) sprintf (bp, "search %s -norelative -singlelevel -dontdereference -sequence default -types aliasedObjectName -value -nosearchalias ", limits (-1)); bp += strlen (bp); for (ag = areas; ag -> ag_record; ag++) if (ag -> ag_record == w -> w_areatype) break; if (w -> w_geography) { (void) sprintf (bp, "\"%s\" ", w -> w_geography); bp += strlen (bp); w -> w_geography = NULL; } else if (ag -> ag_area) { (void) sprintf (bp, "\"%s\" ", ag -> ag_area); bp += strlen (bp); } (void) sprintf (bp, "-filter \"objectClass=%s & %s%s\"", ag -> ag_class, ag -> ag_rdn, eqstr (w -> w_area, 0)); bp += strlen (bp);multiple_searching: ; if ((fp = capture (buffer)) == NULL) return NOTOK; if (interrupted) {you_lose: ; (void) fclose (fp); return NOTOK; } w -> w_area = orgname, w -> w_areatype = W_NULL; multiple = 0; while (fgets (buffer, sizeof buffer, fp) && !interrupted) { if ((cp = index (buffer, '\n')) == NULL) { advise (NULLCP, "internal error(1)"); goto you_lose; } *cp = NULL; if (!isdigit (*buffer)) { (void) fprintf (stderr, "%s\n", buffer); continue; } if ((cp = index (buffer, ' ')) == NULL) { advise (NULLCP, "internal error(2)"); goto you_lose; } *cp++ = NULL; while (*cp == ' ') cp++; if (multiple == 0 && (c = getc (fp)) != EOF) { (void) ungetc (c, fp); multiple = 1; } if (mailbox && !index (cp, '@')) { advise (NULLCP, "Unable to resolve domain beyond national level."); continue; } if (multiple && query && !network) switch (ask ("try %s [y/n] ? ", cp)) { case NOTOK: continue; case OK: default: break; case DONE: goto out; } else if (verbose) { (void) fprintf (stdfp, "Trying @%s ...\n", cp); (void) fflush (stdfp); } (void) sprintf (orgname, "@%s", cp); (void) whois_aux (w); (void) fprintf (stdfp, EOLN); (void) fflush (stdfp); }out: ; (void) fclose (fp); return OK;} /* */static whois_aux (w)register struct whois *w;{ register char *bp, *cp; char *handle, buffer[BUFSIZ]; register struct area_guide *ag; for (ag = areas; ag -> ag_record; ag++) if (ag -> ag_record == w -> w_record) break; bp = buffer; switch (w -> w_inputype) { case W_NULL: default: advise (NULLCP, "internal error(8)"); return NOTOK; case W_HANDLE: (void) sprintf (bp, "showentry \"%s\" %s -fred -dontdereference", w -> w_input, limits (0)); bp += strlen (bp); goto options; case W_MAILBOX: (void) sprintf (bp, "search %s -fred ", limits (1)); bp += strlen (bp); if (w -> w_area) { (void) sprintf (bp, "\"%s\" ", w -> w_area); bp += strlen (bp); } (void) sprintf (bp, "-subtree -filter \""); bp += strlen (bp); cp = w -> w_input; if (*cp == '@') (void) sprintf (bp, "mail=*%s", cp); else if (*(cp + strlen (cp) - 1) == '@' || !index (cp, '@')) (void) sprintf (bp, "mail=%s*", cp); else if (index (cp, '*')) (void) sprintf (bp, "mail=%s", cp); else (void) sprintf (bp, "(mail=%s | otherMailbox=internet$%s)", cp, cp); bp += strlen (bp); break; case W_NAME: if (cp = w -> w_input) { cp += strlen (cp) - 1; if (*cp == '.') *cp = '*'; } (void) sprintf (bp, "search %s -%s ", limits (1), kflag ? "show" : "fred"); bp += strlen (bp); if (w -> w_area) { (void) sprintf (bp, "\"%s\" -subtree ", w -> w_area); bp += strlen (bp); } else if (w -> w_geography) { (void) sprintf (bp, "\"%s\" ", w -> w_geography); bp += strlen (bp); } else if (ag -> ag_area) { (void) sprintf (bp, "\"%s\" %s ", ag -> ag_area, ag -> ag_search); bp += strlen (bp); } else { (void) sprintf (bp, "-subtree "); bp += strlen (bp); } (void) sprintf (bp, "-filter \""); bp += strlen (bp); handle = eqstr (w -> w_input, 0); switch (w -> w_record) { case W_NULL: case W_PERSON: if (handle) { if (w -> w_title && (w -> w_record == W_NULL || w -> w_nametype == W_SURNAME)) { (void) sprintf (bp, "( "); bp += strlen (bp); } if (w -> w_record == W_NULL) { (void) sprintf (bp, "o%s | ou%s | l%s | ", handle, handle, handle, handle); bp += strlen (bp); } if (w -> w_nametype == W_SURNAME) { if (w -> w_record == W_PERSON && !w -> w_title) { (void) sprintf (bp, "( "); bp += strlen (bp); } (void) sprintf (bp, "surname%s | mail=%s@* ", eqstr (w -> w_input, 1), w -> w_input); bp += strlen (bp); if (w -> w_record == W_PERSON && !w -> w_title) { (void) sprintf (bp, ") "); bp += strlen (bp); } } else { (void) sprintf (bp, "cn%s ", handle); bp += strlen (bp); } if (w -> w_title && (w -> w_record == W_NULL || w -> w_nametype == W_SURNAME)) { (void) sprintf (bp, ") "); bp += strlen (bp); } } if (w -> w_title) { (void) sprintf (bp, "%stitle%s", handle ? "& " : "", eqstr (w -> w_title, 1)); bp += strlen (bp); } break; default: if (strcmp (handle, "=*")) { (void) sprintf (bp, "%s%s", ag -> ag_rdn, handle); bp += strlen (bp); } break; } break; } if (w -> w_record == W_PERSON || (w -> w_record != W_NULL && strcmp (handle, "=*"))) { (void) sprintf (bp, " & "); bp += strlen (bp); } if (w -> w_record != W_NULL) { (void) sprintf (bp, "objectClass=%s", ag -> ag_class); bp += strlen (bp); } (void) sprintf (bp, "\""); bp += strlen (bp); options: ; if (w -> w_output & W_EXPAND) { (void) sprintf (bp, " -expand"); bp += strlen (bp); } if (w -> w_output & W_FULL) { (void) sprintf (bp, " -full"); bp += strlen (bp); } if (w -> w_output & W_SUMMARY) { (void) sprintf (bp, " -summary"); bp += strlen (bp); } if (w -> w_output & W_SUBDISPLAY) { (void) sprintf (bp, " -subdisplay"); bp += strlen (bp); } (void) sprintf (bp, " -sequence %s", "default"); bp += strlen (bp); return dish (buffer, 0);}/* */static int test_arg (user, full, minlen)char *user, *full;int minlen;{ int i; if ((i = strlen (user)) < minlen || i > (int)strlen (full) || strncmp (user, full, i)) return 0; return 1;}/* */static char *eqstr (s, exact)char *s;int exact;{ static char buffer[BUFSIZ]; if (s == NULL) return NULL; if (index (s, '*')) (void) sprintf (buffer, "=%s", s); else if (soundex) (void) sprintf (buffer, "~=%s", s); else if (exact) (void) sprintf (buffer, "=%s", s); else (void) sprintf (buffer, "=*%s*", s); return buffer;}/* */static char *limits (isearch)int isearch;{ register char *bp; static char buffer[100]; bp = buffer; if (phone) { (void) strcpy (bp, "-phone "); bp += strlen (bp); }#ifdef notdef /* don't do this! */ if (isearch) { (void) strcpy (bp, "-searchalias "); bp += strlen (bp); }#endif (void) strcpy (bp, "-nosizelimit "); bp += strlen (bp); if (timelimit > 0) (void) sprintf (bp, "-timelimit %d", timelimit); else (void) strcpy (bp, "-notimelimit"); bp += strlen (bp); if (isearch >= 0 && (network || oneshot)) { (void) strcpy (bp, " -nofredseq"); bp += strlen (bp); } return buffer;}/* */static FILE *capture (command)char *command;{ int savnet, savpage; char tmpfil[BUFSIZ]; FILE *fp, *savfp; (void) strcpy (tmpfil, "/tmp/fredXXXXXX"); (void) unlink (mktemp (tmpfil)); if ((fp = fopen (tmpfil, "w+")) == NULL) { advise (tmpfil, "unable to create"); return NULL; } (void) unlink (tmpfil); savfp = stdfp, stdfp = fp; savnet = network, network = 0; savpage = dontpage, dontpage = 1; (void) dish (command, 0); dontpage = savpage; network = savnet; stdfp = savfp; rewind (fp); return fp;}/* */static int f_ufn (vec)char **vec;{ char *cp, buffer[BUFSIZ]; static int lastq = -1; if ((cp = vec[0]) == NULL || strcmp (cp, "-help") == 0) { (void) fprintf (stdfp, "whois name...\n"); (void) fprintf (stdfp, " find something in the white pages\n"); return OK; } if (!test_ufn (cp)) { (void) strcpy (buffer, cp); (void) str2vec (buffer, vec); return f_whois_aux (vec); } (void) sprintf (buffer, "fred -ufn %s-options %x,%s", phone ? "-phone," : "", ufn_options, cp); if (lastq != area_quantum) { (void) sync_ufnrc (); lastq = area_quantum; } return dish (buffer, 0);}/* */int test_ufn (cp)char *cp;{ register char *dp; if (*(dp = cp) == '!') dp++; for (; *dp; dp++) if (!isdigit (*dp)) break; if (!*dp || *dp == '-') /* a handle, or oldstyle */ return 0; if (!index (dp = cp, ',')) { while (dp = index (dp, ' ')) if (*++dp == '-') return 0; if (index (cp, '@')) return 0; } if (strcmp (cp, "!me") == 0) return 0; return 1;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?