/* * This OS/2 port was hacked by Harald Kipp from the * * Network News Transfer Protocol server * * Phil Lapsley * University of California, Berkeley * Stan Barber * Baylor College of Medicine * * Bug reports related to THIS modified version should be sent to * * harald@os2point.ping.de * harald@sesam.com * Fido: 2:2448/434 * */ #include #include #include #include #include #include #include #include #include "globals.h" #include "nntp.h" #include "changi.h" /* * forward declarations */ static int print_header(int s, FILE * fp, char *header, long artnum); /* * XHDR header [|articlerange] * * header is a case-insensitive header field, minus any colons. * * articlerange is one of: * an article number * an article number followed by a dash to indicate all following * an article number followed by a dash followed by another * article number. * e.g., * XHDR subject retrieve subject of current article * XHDR subject 5589-6325 retrieve subject of arts 5589 to 6325 * XHDR subject 5589- retrieve subject of arts 5589 and up * XHDR subject 5589 retrieve subject of art 5589 only * XHDR subject <123@ucbvax> retrieve subject of art <123@ucbvax> * * This command is an extension, and not included in RFC 977. */ void xhdr(PNEWSCLIENT pnc, int argc, char *argv[]) { char buf[_MAX_PATH]; register int artptr; long artnum; long low, high; register FILE *fp; if (argc < 2 || argc > 3) { so_printf(pnc -> s, "%d Usage: XHDR headerfield [artrange|]\r\n", ERR_CMDSYN); lprintf("%s: Syntax error in xhdr command", pnc->remotehost); return; } if (!pnc -> canread) { so_printf(pnc -> s, "%d You only have permission to transfer, sorry.\r\n", ERR_ACCESS); lprintf("%s: Illegal read access", pnc->remotehost); return; } /* * Handle message-id requests */ if (argc == 3 && *argv[2] == '<') { if((fp = openartbyid(argv[2])) == NULL) { so_printf(pnc -> s, "%d No article by message-id %s, sorry.\r\n", ERR_NOART, argv[2]); return; } if(so_printf(pnc -> s, "%d 0 %s header of article %s.\r\n", OK_HEAD, argv[1], argv[2]) != -1) print_header(pnc -> s, fp, argv[1], atol(argv[2])); fclose(fp); so_puts(pnc -> s, ".\r\n"); return; } /* * It must be a range of articles, which means that * we need to be in a newsgroup already. */ if (!pnc -> ingroup) { so_printf(pnc -> s, "%d You are not currently in a newsgroup.\r\n", ERR_NCING); return; } if (argc == 2) { if (pnc -> art_ptr < 0 || pnc -> art_ptr >= pnc -> num_arts) { so_printf(pnc -> s, "%d No article is currently selected.\r\n", ERR_NOCRNT); return; } high = low = pnc -> art_array[pnc -> art_ptr]; artptr = pnc -> art_ptr; } else { char *cp = strchr(argv[2], '-'); if (cp == NULL) low = high = atol(argv[2]); else { *cp++ = '\0'; low = atol(argv[2]); high = atol(cp); if (high < low) if (pnc -> num_arts > 0) high = pnc -> art_array[pnc -> num_arts - 1]; else high = low; } artptr = 0; } so_printf(pnc -> s, "%d %s fields follow\r\n", OK_HEAD, argv[1]); for (; artptr < pnc -> num_arts; artptr++) { if ((artnum = pnc -> art_array[artptr]) < low) continue; if (artnum > high) break; strcpy(buf, pnc->mydir); strcat(buf, "\\"); sprintf(strchr(buf, '\0'), "%ld", artnum); fp = xopen(buf, "rt"); if (fp == NULL) continue; if(print_header(pnc -> s, fp, argv[1], artnum)) { fclose(fp); break; } fclose(fp); } so_puts(pnc -> s, ".\r\n"); } /************************************************************************/ /* */ /* */ /************************************************************************/ int print_header(int s, FILE * fp, char *header, long artnum) { int result = 0; char *line; char *buf; register char *cp; char *cp2; line = malloc(NNTP_STRLEN); buf = malloc(NNTP_STRLEN); while (fgets(line, NNTP_STRLEN, fp) != NULL) { if (*line == '\n' || *line == '\0') break; if (!isspace(*line) && (cp = strchr(line, ':')) != NULL) { *cp = '\0'; if (!stricmp(header, line)) { sprintf(buf, "%lu ", artnum); cp += 2; for (;;) { if ((cp2 = strchr(cp, '\n')) != NULL) *cp2 = '\0'; strcat(buf, cp); if (!fgets(line, NNTP_STRLEN, fp)) break; cp = line; if (*cp != ' ' && *cp != '\t') break; while (isspace(*++cp)) ; *--cp = ' '; } strcat(buf, "\r\n"); if(so_puts(s, buf) < 0) result = -1; free(line); free(buf); return(result); } } } so_printf(s, "%lu (none)\r\n", artnum); free(line); free(buf); return(result); }