home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3545 < prev    next >
Encoding:
Internet Message Format  |  1991-06-26  |  10.5 KB

  1. From: iverson@xstor.com (Tim Iverson)
  2. Newsgroups: alt.sources
  3. Subject: Patches to NNTP 1.5.11 to support remote threads for TRN
  4. Message-ID: <1991Jun26.001735.7615@xstor.com>
  5. Date: 26 Jun 91 00:17:35 GMT
  6.  
  7.  
  8. This patch file requires patch-2.0.2.0 patchlevel 12u4.  You might have some
  9. success with unipatch or earlier 12u* versions of patch, but you're on your
  10. own there.  Basically, it extends the nntp command set to allow trn to
  11. retrieve thread information via nntp - the need for a local threads database
  12. is eliminated.
  13.  
  14.  
  15. What it does:    modifies the LIST command to also list trn's active2 file.
  16.         adds an XTHREAD command so trn can access threads remotely.
  17.  
  18. To apply:    cd nntp-1.5.11
  19.         patch -p < this_file
  20.  
  21. To compile:    None of the installation files or Makefiles are modified,
  22.         so you will have to follow the directions included with
  23.         nntp.  For SCO Unix, you should apply the sco unix patch.
  24.  
  25. - Tim Iverson
  26.   iverson@xstor.com -/- uunet!xstor!iverson
  27.  
  28. #
  29. ################ patch starts here
  30. ##
  31. Prereq: "1.5.11
  32. Index: common/version.c
  33. @@ -3,3 +3,3 @@
  34. = */
  35. =
  36. -char    nntp_version[] = "1.5.11 (10 February 1991)";
  37. +char    nntp_version[] = "1.5.11a (1 April 1991)";
  38. Index: common/clientlib.c
  39. @@ -634,2 +634,72 @@
  40. =}
  41. =
  42. +
  43. +
  44. +static    int    bytes = 0;    /* bytes remaining to be transfered */
  45. +
  46. +/* This function issues an XTHREAD command and prepares xthread_read() for
  47. + * the data transfer by reading the status line returned by the server.
  48. + *
  49. + * entry:    server must be open and ready to accept commands.
  50. + *
  51. + * exit:    server will be transfering XTHREAD data.
  52. + *
  53. + * return:    bytes to be transfered on success, 0 for error.
  54. + */
  55. +int
  56. +xthread(cmd)
  57. +char    *cmd;
  58. +{
  59. +    char    buf[512];
  60. +
  61. +    /* send the given xthread command */
  62. +    sprintf(buf, cmd && *cmd ? "XTHREAD %s\r\n" : "XTHREAD\r\n", cmd);
  63. +    put_server(buf);
  64. +
  65. +    /* try to get the status line and the status code */
  66. +    if (get_server(buf, sizeof buf) || *buf != CHAR_OK)
  67. +        return bytes = 0;
  68. +
  69. +    /* try to get the number of bytes being transfered */
  70. +    if (sscanf(buf, "%*d%d", &bytes) != 1)
  71. +        return bytes = 0;
  72. +    return bytes;
  73. +}
  74. +
  75. +
  76. +/* This function is used to read the data sent as a result of the
  77. + * XTHREAD command.
  78. + *
  79. + * entry:    There must have been a successful call to xthread() or
  80. + *        xthread_read() preceding the current call.
  81. + *
  82. + *        No other communication to or from the server after XTHREAD is
  83. + *        issued and before this function returns EOF or error is
  84. + *        allowed - otherwise we'll block for data that'll never come.
  85. + *
  86. + * exit:    The buffer is filled with data from the XTHREAD command.
  87. + *
  88. + * return:    bytes read into the buffer, 0 for eof or error.
  89. + */
  90. +int
  91. +xthread_read(buf, n)
  92. +void    *buf;
  93. +int    n;
  94. +{
  95. +    /* if no bytes to read, then just return EOF */
  96. +    if (!bytes)
  97. +        return bytes;
  98. +
  99. +    /* try to read some data from the server */
  100. +    bytes -= (n = fread(buf, 1, n > bytes ? bytes : n, ser_rd_fp));
  101. +
  102. +    /* if no more left, then fetch the end-of-command signature */
  103. +    if (!bytes)
  104. +    {
  105. +        char buf[5];    /* "\r\n.\r\n" */
  106. +
  107. +        fread(buf, sizeof buf, 1, ser_rd_fp);
  108. +    }
  109. +
  110. +    return n;
  111. +}
  112. Index: common/clientlib.h
  113. @@ -10,2 +10,4 @@
  114. =extern    int    get_server();
  115. =extern    void    close_server();
  116. +extern    int    xthread();
  117. +extern    int    xthread_read();
  118. Index: common/conf.h.dist
  119. @@ -95,4 +95,13 @@
  120. =            /* loaded already, defining this may be a bad idea */
  121. =
  122. +#define XTHREAD        /* Optional XTHREAD command.  This allows trn to
  123. +             * keep all data on the server.
  124. +             */
  125. +
  126. +#ifdef    XTHREAD        /* locations for trn data files (on server) */
  127. +# define ACTIVE2_FILE    "/usr/local/lib/trn/active2"
  128. +# define DBINIT_FILE    "/usr/local/lib/trn/db.init"
  129. +#endif
  130. +
  131. =/* Things that vary in network implementations */
  132. =#define    SUBNET        /* If you have 4.3 subnetting */
  133. Index: common/nntp.h
  134. @@ -49,4 +49,5 @@
  135. =#define    OK_AUTHSYS    280    /* Authorization system ok */
  136. =#define    OK_AUTH        281    /* Authorization (user/pass) ok */
  137. +#define    OK_BIN        282    /* binary data follows */
  138. =
  139. =#define    CONT_XFER    335    /* Continue to send article */
  140. Index: server/Makefile
  141. @@ -7,5 +7,5 @@
  142. =    newgroups.o newnews.o nextlast.o ngmatch.o post.o parsit.o scandir.o \
  143. =    slave.o spawn.o strcasecmp.o subnet.o time.o xhdr.o fakesyslog.o \
  144. -    batch.o auth.o timer.o ../common/version.o
  145. +    batch.o auth.o timer.o xthread.o ../common/version.o
  146. =
  147. =SRVRSRC = main.c serve.c access.c access_inet.c access_dnet.c active.c \
  148. @@ -13,5 +13,5 @@
  149. =    newgroups.c newnews.c nextlast.c ngmatch.c post.c parsit.c scandir.c \
  150. =    slave.c spawn.c strcasecmp.c subnet.c time.c xhdr.c fakesyslog.c \
  151. -    batch.c auth.c timer.c ../common/version.c
  152. +    batch.c auth.c timer.c xthread.c ../common/version.c
  153. =
  154. =SRVRINC = common.h ../common/conf.h ../common/nntp.h timer.h
  155. @@ -19,4 +19,6 @@
  156. =SRCS    = ${SRVRSRC}
  157. =
  158. +THREADS    = ../../trn/threads.o
  159. +
  160. =# -ldbm here if you've #define'ed DBM in ../common/conf.h
  161. =LIBS    = -ldbm
  162. @@ -30,8 +32,12 @@
  163. =all:    nntpd
  164. =
  165. -nntpd: ${SRVROBJ} ${SRVRINC}
  166. -    ${CC} ${CFLAGS} -o nntpd ${SRVROBJ} ${LIBS}
  167. +nntpd: ${SRVROBJ} ${SRVRINC} ${THREADS}
  168. +    ${CC} ${CFLAGS} -o nntpd ${SRVROBJ} ${THREADS} ${LIBS}
  169. =
  170. =${SRVROBJ}: ${SRVRINC}
  171. +
  172. +$(THREADS) :
  173. +    @echo You must first build threads.o as used in trn.
  174. +    @false
  175. =
  176. =install: nntpd
  177. Index: server/common.h
  178. @@ -165,4 +165,10 @@
  179. =extern    char    rnews[];
  180. =
  181. +#ifdef    XTHREAD
  182. +extern    char    active2file[];
  183. +extern    char    dbinitfile[];
  184. +extern    char    *threadfile;
  185. +#endif
  186. +
  187. =extern    char    **group_array;
  188. =extern    char    *actbuf;
  189. Index: server/globals.c
  190. @@ -27,4 +27,10 @@
  191. =char    rnews[] = RNEWS;
  192. =
  193. +#ifdef    XTHREAD
  194. +char    active2file[] = ACTIVE2_FILE;
  195. +char    dbinitfile[] = DBINIT_FILE;
  196. +char    *threadfile = NULL;
  197. +#endif
  198. +
  199. =/*
  200. = * Other random externals.
  201. Index: server/group.c
  202. @@ -101,4 +101,12 @@
  203. =        *cp = '.';
  204. =
  205. +#ifdef    XTHREAD
  206. +    {
  207. +        extern char *thread_name(const char *newsgroup);
  208. +
  209. +        threadfile = thread_name(argv[1]);
  210. +    }
  211. +#endif
  212. +
  213. =    printf("%d %d %d %d %s\r\n",
  214. =        OK_GROUP,
  215. Index: server/help.c
  216. @@ -22,6 +22,13 @@
  217. =    printf("STAT        NEWGROUPS    HELP\r\n");
  218. =    printf("IHAVE       NEWNEWS      SLAVE\r\n");
  219. -    printf("\r\nAdditionally, the following extention is supported:\r\n\r\n");
  220. +#if defined(XHDR) || defined(XTHREAD)
  221. +    printf("\r\nAdditionally, the following extentions are supported:\r\n\r\n");
  222. +# ifdef    XHDR
  223. =    printf("XHDR        Retrieve a single header line from a range of articles.\r\n");
  224. +# endif    XHDR
  225. +# ifdef    XTHREAD
  226. +    printf("XTHREAD     Retrieve trn thread file for the current group.\r\n");
  227. +# endif
  228. +#endif
  229. =    printf("\r\n");
  230. =    printf("Bugs to Stan Barber (Internet: nntp@tmc.edu; UUCP: ...!bcm!nntp)\r\n");
  231. Index: server/list.c
  232. @@ -46,6 +46,27 @@
  233. =        items = "newsgroup descriptions";
  234. =        format = "Descriptions in form \"group description\".";
  235. +#ifdef    XTHREAD
  236. +    } else if (argc == 2 && !strcasecmp(argv[1],"active2")){
  237. +                num_groups = read_groups();
  238. +                if (num_groups == 0){ /* can't get a group list */
  239. +                  printf("%d Group update failed. Try later.\r\n",
  240. +                         ERR_FAULT);
  241. +                  (void) fflush(stdout);
  242. +# ifdef LOG
  243. +                  syslog(LOG_INFO, "%s group update failed in LIST", hostname);
  244. +# endif
  245. +                  exit(1);
  246. +                }
  247. +        filename = active2file;
  248. +        items = "threaded newsgroups";
  249. +        format = "Threaded groups in form \"group high low y/n/m\".";
  250. +#endif    /* XTHREAD */
  251. =    } else {
  252. -        printf("%d Usage: LIST [ACTIVE|NEWSGROUPS|DISTRIBUTIONS]\r\n",
  253. +        printf(
  254. +#ifdef    XTHREAD
  255. +        "%d Usage: LIST [ACTIVE|ACTIVE2|DISTRIBUTIONS|NEWSGROUPS]\r\n",
  256. +#else
  257. +        "%d Usage: LIST [ACTIVE|NEWSGROUPS|DISTRIBUTIONS]\r\n",
  258. +#endif    /* XTHREAD */
  259. =            ERR_CMDSYN);
  260. =        (void) fflush(stdout);
  261. Index: server/serve.c
  262. @@ -27,5 +27,5 @@
  263. =extern    int    ahbs(), group(), help(), ihave();
  264. =extern    int    list(), newgroups(), newnews(), nextlast(), post();
  265. -extern    int    slave(), stat(), xhdr();
  266. +extern    int    slave(), stat(), xhdr(), xthread();
  267. =
  268. =extern int errno;
  269. @@ -62,4 +62,7 @@
  270. =    "xhdr",        0,    xhdr,
  271. =#endif XHDR
  272. +#ifdef XTHREAD
  273. +    "xthread",    0,    xthread,
  274. +#endif
  275. =};
  276. =#define NUMCMDS (sizeof(cmdtbl) / sizeof(struct cmdent))
  277. Index: server/xthread.c
  278. @@ -0,0 +1,115 @@
  279. +/* This file (and only this file - not the entire nntp distribution) is
  280. + * hereby placed in the public domain.  Use it as you see fit, but if you
  281. + * manage to find some wonderful use for this code elsewhere, it would be
  282. + * nice to receive mention for it.
  283. + *
  284. + * - Tim Iverson
  285. + *   iverson@xstor.com -/- uunet!xstor!iverson
  286. + *   3/28/91
  287. + */
  288. +
  289. +#include "common.h"
  290. +
  291. +#ifdef XTHREAD
  292. +
  293. +# ifdef __GNUC__
  294. +#  define alloca __builtin_alloca
  295. +# else
  296. +extern    void *alloca(unsigned int bytes);
  297. +# endif
  298. +
  299. +
  300. +/* Usage: XTHREAD [DBINIT|THREAD]
  301. + *
  302. + * DBINIT    dump the contents of the db.init file to stdout
  303. + * THREAD    dump the contents of the thread file for the current
  304. + *        newsgroup to stdout (default if no argument).
  305. + *
  306. + * N.B. These two files are not ascii and no attempt is made at converting
  307. + *    native byte size to any type of standard whatsoever.  This'll have
  308. + *    to be fixed if this command is to be integrated into the protocol.
  309. + *
  310. + * This command is not documented in rfc977.
  311. + */
  312. +
  313. +void
  314. +xthread(argc, argv)
  315. +int    argc;
  316. +char    *argv[];
  317. +{
  318. +    register FILE    *fp;
  319. +    struct stat    s;
  320. +    char        *buf, *file, *what;
  321. +
  322. +    /* can't transfer threads, only read 'em */
  323. +    if (!canread)
  324. +    {
  325. +        printf("%d You only have permission to transfer, sorry.\r\n",
  326. +            ERR_ACCESS);
  327. +        (void) fflush(stdout);
  328. +        return;
  329. +    }
  330. +
  331. +    /* "parse" the argument */
  332. +    if (argc == 2 && !strcasecmp(argv[1], "dbinit"))
  333. +    {
  334. +        file = dbinitfile;
  335. +        what = "db.init";
  336. +    }
  337. +    else if (argc == 1 || argc == 2 && !strcasecmp(argv[1], "thread"))
  338. +    {
  339. +        if (!threadfile)
  340. +        {
  341. +            printf("%d You are not currently in a newsgroup.\r\n",
  342. +                ERR_NCING);
  343. +            (void) fflush(stdout);
  344. +            return;
  345. +        }
  346. +        file = threadfile;
  347. +        what = "thread";
  348. +    }
  349. +    else
  350. +    {
  351. +        printf("%d Usage: XTHREAD [DBINIT|THREAD]\r\n", ERR_CMDSYN);
  352. +        (void) fflush(stdout);
  353. +        return;
  354. +    }
  355. +
  356. +    /* try to open the file to be transfered */
  357. +    if (!(fp = fopen(file, "r")))
  358. +    {
  359. +        printf("%d %s file is not available.\r\n", ERR_FAULT, what);
  360. +        (void) fflush(stdout);
  361. +#ifdef SYSLOG
  362. +        syslog(LOG_ERR, "xthread: fopen %s: %m", file);
  363. +#endif
  364. +        return;
  365. +    }
  366. +
  367. +    /* tell 'em how much binary data is coming down the pike */
  368. +    fstat(fileno(fp), &s);
  369. +    printf("%d %u bytes of %s file follows verbatim "
  370. +        "(binary!)\r\n", OK_BIN, s.st_size, what);
  371. +
  372. +    /* copy the file verbatim to stdout */
  373. +    if (buf = alloca(s.st_size))
  374. +    {
  375. +        /* ah-so! got lotsa memoree */
  376. +        read(fileno(fp), buf, s.st_size);
  377. +        fwrite(buf, s.st_size, 1, stdout);
  378. +    }
  379. +    else
  380. +    {
  381. +        int        bytes;
  382. +        char        buf[BUFSIZ];
  383. +
  384. +        while (bytes = fread(buf, 1, sizeof buf, fp))
  385. +            fwrite(buf, bytes, 1, stdout);
  386. +    }
  387. +
  388. +    fputs("\r\n.\r\n", stdout);
  389. +    fflush(stdout);
  390. +    fclose(fp);
  391. +}
  392. +
  393. +#endif /* not XTHREAD */
  394. ##
  395. ################ patch ends here
  396. #
  397.