Annotation of 43BSDTahoe/new/nntp/server/xhdr.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char    *sccsid = "@(#)xhdr.c   1.3     (Berkeley) 7/17/87";
                      3: #endif
                      4: 
                      5: #include "common.h"
                      6: 
                      7: #ifdef XHDR
                      8: 
                      9: /*
                     10:  * XHDR header [<messageid>|articlerange]
                     11:  *
                     12:  * header is a case-insensitive header field, minus any colons.
                     13:  *
                     14:  * articlerange is one of:
                     15:  *     an article number
                     16:  *     an article number followed by a dash to indicate all following
                     17:  *     an article number followed by a dash followed by another
                     18:  *             article number.
                     19:  * e.g.,
                     20:  * XHDR subject                        retrieve subject of current article
                     21:  * XHDR subject 5589-6325      retrieve subject of arts 5589 to 6325
                     22:  * XHDR subject 5589-          retrieve subject of arts 5589 and up
                     23:  * XHDR subject 5589           retrieve subject of art 5589 only
                     24:  * XHDR subject <123@ucbvax>   retrieve subject of art <123@ucbvax>
                     25:  *
                     26:  * This command is an extention, and not included in RFC 977.
                     27:  */
                     28: 
                     29: xhdr(argc, argv)
                     30:        int             argc;
                     31:        char            *argv[];
                     32: {
                     33:        char            buf[MAX_STRLEN];
                     34:        register int    artptr;
                     35:        register int    artnum;
                     36:        register int    low, high;
                     37:        register FILE   *fp;
                     38:        register char   *cp;
                     39: 
                     40:        if (argc < 2 || argc > 3) {
                     41:                printf("%d Usage: XHDR headerfield [artrange|<message-id>]\r\n",
                     42:                        ERR_CMDSYN);
                     43:                (void) fflush(stdout);
                     44:                return;
                     45:        }
                     46: 
                     47:        if (!canread) {
                     48:                printf("%d You only have permission to transfer, sorry.\r\n",
                     49:                        ERR_ACCESS);
                     50:                (void) fflush(stdout);
                     51:                return;
                     52:        }
                     53: 
                     54:        /* Handle message-id requests */
                     55: 
                     56:        if (argc == 3 && *argv[2] == '<') {     /* Message ID */
                     57:                fp = openartbyid(argv[2]);
                     58:                if (fp == NULL) {
                     59:                        printf("%d No article by message-id %s, sorry.\r\n",
                     60:                                ERR_NOART, argv[2]);
                     61:                        (void) fflush(stdout);
                     62:                        return;
                     63:                }
                     64:                printf("%d 0 %s header of article %s.\r\n",
                     65:                        OK_HEAD, argv[1], argv[2]);
                     66:                print_header(fp, argv[1], argv[2]);
                     67:                (void) fclose(fp);
                     68: 
                     69:                putchar('.');
                     70:                putchar('\r');
                     71:                putchar('\n');
                     72:                (void) fflush(stdout);
                     73:                return;
                     74:        }
                     75: 
                     76:        /*
                     77:         * It must be a range of articles, which means that we need
                     78:         * to be in a newsgroup already.
                     79:         */
                     80: 
                     81:        if (!ingroup) {
                     82:                printf("%d You are not currently in a newsgroup.\r\n",
                     83:                        ERR_NCING);
                     84:                (void) fflush(stdout);
                     85:                return;
                     86:        }
                     87: 
                     88:        artptr = 0;
                     89: 
                     90:        if (argc == 2) {
                     91:                if (art_ptr < 0 || art_ptr >= num_arts) {
                     92:                        printf("%d No article is currently selected.\r\n",
                     93:                                ERR_NOCRNT);
                     94:                        (void) fflush(stdout);
                     95:                        return;
                     96:                }
                     97:                high = low = art_array[art_ptr];
                     98:                artptr = art_ptr;
                     99:        } else {
                    100:                cp = index(argv[2], '-');
                    101:                if (cp == NULL)
                    102:                        low = high = atoi(argv[2]);
                    103:                else {
                    104:                        *cp = '\0';
                    105:                        low = atoi(argv[2]);
                    106:                        cp++;
                    107:                        high = atoi(cp);
                    108:                        if (high < low)
                    109:                                high = art_array[num_arts-1];
                    110:                }
                    111:        }
                    112: 
                    113:        printf("%d %s fields follow\r\n", OK_HEAD, argv[1]);
                    114: 
                    115:        for (;; artptr++) {
                    116:                if ((artnum = art_array[artptr]) < low)
                    117:                        continue;
                    118:                if (artnum > high)
                    119:                        break;
                    120: 
                    121:                (void) sprintf(buf, "%d", artnum);
                    122:                fp = fopen(buf, "r");
                    123:                if (fp == NULL)
                    124:                        continue;
                    125:                print_header(fp, argv[1], buf);
                    126:                (void) fclose(fp);
                    127:        }
                    128: 
                    129:        putchar('.');
                    130:        putchar('\r');
                    131:        putchar('\n');
                    132:        (void) fflush(stdout);
                    133: }
                    134: 
                    135: 
                    136: print_header(fp, header, artname)
                    137:        register FILE   *fp;
                    138:        register char   *header;
                    139:        register char   *artname;
                    140: {
                    141:        char            line[MAX_STRLEN];
                    142:        register char   *cp, *cp1;
                    143: 
                    144:        while (fgets(line, sizeof (line), fp) != NULL) {
                    145:                if (*line == '\n' || *line == '\0') {
                    146:                        printf("%s (none)\r\n", artname);
                    147:                        return;
                    148:                }
                    149:                if (cp = index(line, ':')) {
                    150:                        *cp = '\0';
                    151:                        if (streql(header, line)) {
                    152:                                if (cp1 = index(cp + 2, '\n'))
                    153:                                        *cp1 = '\0';
                    154:                                printf("%s %s\r\n", artname, cp + 2);
                    155:                                return;
                    156:                        }
                    157:                }
                    158:        }
                    159: }
                    160: 
                    161: #endif XHDR

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.