/* * 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 #include #include #include "globals.h" #include "nntp.h" #include "changi.h" char *over_field[] = { "ARTICLE #", "subject", "from", "date", "message-id", "references", "bytes", "lines", "xref" }; #define OVER_LAST_FIELD 8 static void over_fake(int s, char *path, long artnum); /************************************************************************/ /* */ /************************************************************************/ void doxover(PNEWSCLIENT pnc, int argc, char *argv[]) { long low, high, artnum; int artptr; /* * Check permission */ 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; } /* * Check syntax */ if (argc != 1 && argc != 2) { so_printf(pnc->s, "%d Usage: XOVER [artrange]\r\n", ERR_CMDSYN); lprintf("%s: Syntax error in xover command", pnc->remotehost); return; } /* * Already must be in a group */ if (!pnc->ingroup) { so_printf(pnc->s, "%d You are not currently in a newsgroup.\r\n", ERR_NCING); return; } if (argc == 1) { /* * No argument, use current article */ 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 { /* * Parse argument */ char *cp = strchr(argv[1], '-'); if (cp == NULL) /* * Argument is a single number */ low = high = atoi(argv[1]); else { /* * Argument is a range */ *cp++ = '\0'; low = atoi(argv[1]); high = atoi(cp); if (high < low) { if (pnc->num_arts > 0) high = pnc->art_array[pnc->num_arts - 1]; else high = low; } } artptr = 0; } /* * Return the desired data. */ so_printf(pnc->s, "%d overview data follows\r\n", OK_OVER); for (; artptr < pnc->num_arts; artptr++) { /* * Skip pre-low articles */ if ((artnum = pnc->art_array[artptr]) >= low) { /* * Last article in range reached */ if (artnum > high) break; /* * For now we fake it, later we may dynamically * create/update the overview file */ over_fake(pnc->s, pnc->mydir, artnum); } } so_printf(pnc->s, ".\r\n"); } /************************************************************************/ /* */ /************************************************************************/ int over_header(char *s) { register int i; register char ch = (char)tolower(*s); for (i = 1; i <= OVER_LAST_FIELD; i++) { if (ch == over_field[i][0]) { if (stricmp(s, over_field[i]) == 0) return i; break; } } return -1; } /************************************************************************/ /* */ /************************************************************************/ void over_fake(int s, char *path, long artnum) { char *array[OVER_LAST_FIELD + 1]; char line[NNTP_STRLEN]; FILE *fp; char *cp; int hdr = 0; sprintf(line, "%s\\%ld", path, artnum); if((fp = xopen(line, "rt")) == NULL) { lperror(line); return; } for (hdr = OVER_LAST_FIELD; hdr > 0; hdr--) array[hdr] = NULL; while (fgets(line, sizeof(line), fp)) { if((cp = strchr(line, '\n')) != NULL) *cp = '\0'; if (*line == '\0') break; if (*line == ' ' || *line == '\t') { if (hdr > 0 && array[hdr]) { char *cp2 = array[hdr]; for (cp = line + 1; *cp == ' ' || *cp == '\t'; cp++) ; *--cp = ' '; array[hdr] = malloc(strlen(cp2) + strlen(cp) + 1); strcpy(array[hdr], cp2); strcat(array[hdr], cp); free(cp2); } else hdr = 0; } else if ((cp = strchr(line, ':')) != NULL) { *cp++ = '\0'; if ((hdr = over_header(line)) > 0) { if (strlen(cp) > 1 && array[hdr] == NULL) array[hdr] = strdup(cp + 1); else hdr = 0; } } else hdr = 0; /* reset to avoid line break add above */ } so_printf(s, "%ld", artnum); for (hdr = 1; hdr <= OVER_LAST_FIELD; hdr++) { so_printf(s, "\t"); if (array[hdr]) { #if defined(OVER_XREF_PREFIX) if (hdr == 8) so_printf(s, "xref: "); #endif so_printf(s, "%s", array[hdr]); free(array[hdr]); } } so_printf(s, "\r\n"); fclose(fp); }