head 1.4; access; symbols; locks; strict; comment @ * @; 1.4 date 92.07.27.22.26.31; author paul; state Exp; branches; next 1.3; 1.3 date 89.05.13.13.02.44; author dorner; state Exp; branches; next 1.2; 1.2 date 89.05.08.22.43.54; author dorner; state Exp; branches; next 1.1; 1.1 date 89.04.07.11.52.25; author dorner; state Exp; branches; next ; desc @@ 1.4 log @Re-formatted for clarity. @ text @/* * this program implements a really limited version of the whois protocol * using qi. No doubt people who really like whois will hate this program, * but it is useful due to the fact that we have a whois client for some * systems (macs and pcs) that are difficult to write qi clients for */ /* * the basic idea is simple; we read a line from stdin. * if the line is a single "?", we give a usage message and exit * otherwise, we run a qi, prepend a "query" to the line, send the * line to the qi, and pass the response back. When we are done * responding, we die (kind of like salmon) */ #include #define LINESIZE 2048 main() { char line[LINESIZE]; if (GetLine(line, sizeof (line), stdin)) { if (*line == '?') { puts("This is a whois frontend for the CSO Nameserver.\r"); puts("Send a name, and you'll get the ph entry back.\r"); } else { int whoiToqi[2]; int qiTowhoi[2]; if (pipe(whoiToqi)) { perror("pipe whoiToqi"); exit(1); } if (pipe(qiTowhoi)) { perror("pipe qiTowhoi"); exit(1); } if (!fork()) { /* will become qi */ close(whoiToqi[1]); close(qiTowhoi[0]); /* set our stdin, stdout, and stderr properly */ if (dup2(qiTowhoi[1], 1) < 0) { perror("dup2 stdout"); exit(1); } if (dup2(qiTowhoi[1], 2) < 0) { perror("dup2 stderr"); exit(1); } if (dup2(whoiToqi[0], 0) < 0) { perror("dup2 stdin"); exit(1); } /* dew it */ execl("/nameserv/bin/qi", "qi", "-d", 0); /* uh-oh */ perror("qi"); exit(1); } else { FILE *toQI, *fromQI; /* this is really boring... */ close(whoiToqi[0]); close(qiTowhoi[1]); if (!(toQI = fdopen(whoiToqi[1], "w"))) { perror("toQI"); exit(1); } if (!(fromQI = fdopen(qiTowhoi[0], "r"))) { perror("fromQI"); exit(1); } /* now for the good stuff... */ fprintf(toQI, "query %s\n quit\n", line); fflush(toQI); /* print the response */ while (fgets(line, sizeof (line), fromQI)) { PutLine(line, stdout); if (atoi(line) >= 200) break; } /* trash the response from the quit */ while (fgets(line, sizeof (line), fromQI)) ; /* hooray! */ exit(0); } } } /* sob */ exit(1); } /*********************************************************************** * get a line of input, including newline ***********************************************************************/ GetLine(line, size, fp) char *line; int size; FILE *fp; { int c; char *lp = line; while ((c = getc(fp)) != EOF) switch (c) { case '\r': case '\0':; case '\n': *lp++ = c; *lp = '\0'; return (lp - line); break; default: if (lp - line < size - 2) *lp++ = c; break; } *lp = '\0'; return (lp - line); } PutLine(line, fp) char *line; FILE *fp; { for (; *line; line++) switch (*line) { case '\r': putc('\r', fp); putc('\0', fp); break; case '\n': putc('\r', fp); putc('\n', fp); break; default: putc(*line, fp); break; } } @ 1.3 log @No help here. @ text @a15 1 static char *rcsid = "$Source: /nameserv/src/whoi/RCS/whoi.c,v $$Date: 89/05/08 22:43:54 $$Revision: 1.2 $"; d18 3 a20 50 char line[LINESIZE]; if (GetLine(line,sizeof(line),stdin)) { if (*line=='?') { puts("This is a whois frontend for the CSO Nameserver.\r"); puts("Send a name, and you'll get the ph entry back.\r"); } else { int whoiToqi[2]; int qiTowhoi[2]; if (pipe(whoiToqi)) {perror("pipe whoiToqi"); exit(1);} if (pipe(qiTowhoi)) {perror("pipe qiTowhoi"); exit(1);} if (!fork()) { /* will become qi */ close(whoiToqi[1]); close(qiTowhoi[0]); /* set our stdin, stdout, and stderr properly */ if (dup2(qiTowhoi[1],1)<0) {perror("dup2 stdout"); exit(1);} if (dup2(qiTowhoi[1],2)<0) {perror("dup2 stderr"); exit(1);} if (dup2(whoiToqi[0],0)<0) {perror("dup2 stdin"); exit(1);} /* dew it */ execl("/nameserv/bin/qi","qi","-d",0); /* uh-oh */ perror("qi"); exit(1); } else { FILE *toQI, *fromQI; /* this is really boring... */ close(whoiToqi[0]); close(qiTowhoi[1]); if (!(toQI=fdopen(whoiToqi[1],"w"))) {perror("toQI"); exit(1);} if (!(fromQI=fdopen(qiTowhoi[0],"r"))) {perror("fromQI"); exit(1);} /* now for the good stuff... */ fprintf(toQI,"query %s\n quit\n",line); fflush(toQI); /* print the response */ while (fgets(line,sizeof(line),fromQI)) d22 83 a104 2 PutLine(line,stdout); if (atoi(line) >= 200) break; d106 2 a107 11 /* trash the response from the quit */ while (fgets(line,sizeof(line),fromQI)); /* hooray! */ exit(0); } } } /* sob */ exit(1); d113 4 a116 4 GetLine(line,size,fp) char *line; int size; FILE *fp; d118 2 a119 2 int c; char *lp=line; d121 17 a137 8 while ((c=getc(fp))!=EOF) switch (c) { case '\r': case '\0':; case '\n': *lp++ = c; d139 1 a139 10 return(lp-line); break; default: if (lp-line < size-2) *lp++ = c; break; } *lp = '\0'; return(lp-line); d142 3 a144 3 PutLine(line,fp) char *line; FILE *fp; d146 15 a160 15 for (; *line; line++) switch (*line) { case '\r': putc('\r',fp); putc('\0',fp); break; case '\n': putc('\r',fp); putc('\n',fp); break; default: putc(*line,fp); break; } a161 1 @ 1.2 log @No help here. @ text @d16 1 a16 1 static char *rcsid = "$Source:$$Date:$$Revision:$"; d23 1 a23 1 if (*line='?') @ 1.1 log @No help here. @ text @d23 1 a23 1 if (!strcmp(line,"?\n")) d25 2 a26 2 puts("This is a whois frontend for the CSO Nameserver."); puts("Send a name, and you'll get the ph entry back."); d70 1 a70 1 fputs(line,stdout); d116 21 @