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

  1. From: iverson@xstor.com (Tim Iverson)
  2. Newsgroups: alt.sources
  3. Subject: Patches to TRN 1.0.2 for remote threads via NNTP
  4. Message-ID: <1991Jun26.002311.7657@xstor.com>
  5. Date: 26 Jun 91 00:23:11 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.  You will also need a virgin copy of trn 1.0.2.
  11.  
  12. What it does:    Adds support for the nntp XTHREAD command when compiled for
  13.         use with an nntp server that supports XTHREAD.  This causes
  14.         trn to get active2, db.init, and the thread files from the
  15.         server, so you no longer need to run mthreads on the client
  16.         machines.
  17.  
  18. To apply:    Build nntp with the XTHREAD command.  This patch uses some
  19.         new functions in clientlib.c.  Then do
  20.         patch -p < this_file
  21.  
  22. To compile:    sh ./Configure
  23.         make depend
  24.         make trn
  25.  
  26. The configure step is not optional.  It is needed to build the new server.h
  27.  
  28. You might also want to edit your client makefile/installation so that
  29. mthreads and friends are neither compiled nor installed.
  30.  
  31. - Tim Iverson
  32.   iverson@xstor.com -/- uunet!xstor!iverson
  33.  
  34. #
  35. ################ patch starts here
  36. ##
  37. Prereq: v1.0.2
  38. Index: patchlevel
  39. @@ -1 +1 @@
  40. -Trn v1.0.2
  41. +Trn v1.0.2nntp
  42. Index: Configure
  43. @@ -2055,4 +2055,14 @@
  44. =
  45. =#include "$NNTPSRC/common/nntp.h"
  46. +
  47. +# if defined(OK_BIN) && defined(USETHREADS)
  48. +#  define XTHREAD
  49. +EXT    char    *nntp_thread_name;
  50. +EXT    FILE    *nntp_active2(void);
  51. +EXT    int    nntp_dbinit(void *buf, int size);
  52. +EXT    void    nntp_thread(void);
  53. +EXT    void    nntp_unlink(void);
  54. +# endif
  55. +
  56. =#endif
  57. =EOF_SERVE
  58. Index: common.h
  59. @@ -798,9 +798,17 @@
  60. =/* how to cancel an article, continued */
  61. =#ifndef CANCELHEADER
  62. -#ifdef INTERNET
  63. +# ifndef CMSG_HACK
  64. +#  ifdef INTERNET
  65. +#   define CANCELHEADER "From: %L@%H (%N)\nNewsgroups: %n\nSubject: cancel %i\nControl: cancel %i\nReferences: %R\nDistribution: %D\nOrganization: %o\n\nThis message was cancelled from within trn.\n"
  66. +#  else
  67. +#   define CANCELHEADER "From:%L@%H.UUCP (%N)\nNewsgroups: %n\nSubject: cancel %i\nControl: cancel %i\nReferences: %R\nDistribution: %D\nOrganization: %o\n"
  68. +#  endif
  69. +# else
  70. +#  ifdef INTERNET
  71. =#   define CANCELHEADER "From: %L@%H (%N)\nNewsgroups: %n\nSubject: cmsg cancel %i\nReferences: %R\nDistribution: %D\nOrganization: %o\n\nThis message was cancelled from within trn.\n"
  72. -#else
  73. +#  else
  74. =#   define CANCELHEADER "From:%L@%H.UUCP (%N)\nNewsgroups: %n\nSubject: cmsg cancel %i\nReferences: %R\nDistribution: %D\nOrganization: %o\n"
  75. -#endif
  76. +#  endif
  77. +# endif
  78. =#endif
  79. =
  80. Index: final.c
  81. @@ -56,4 +56,8 @@
  82. =#include "final.h"
  83. =
  84. +#ifdef    SERVER
  85. +# include "server.h"
  86. +#endif
  87. +
  88. =void
  89. =final_init()
  90. @@ -112,4 +116,7 @@
  91. =     UNLINK(lockname);
  92. =#ifdef SERVER
  93. +# ifdef XTHREAD
  94. +    nntp_unlink();
  95. +# endif
  96. =    if (*active_name)
  97. =    UNLINK(active_name);
  98. Index: ng.c
  99. @@ -250,4 +250,9 @@
  100. =    }
  101. =
  102. +#ifdef XTHREAD    /* use remote thread file? */
  103. +# define thread_name(g)    nntp_thread_name
  104. +    nntp_thread();
  105. +#endif
  106. +
  107. =    /* FROM HERE ON, RETURN THRU CLEANUP OR WE ARE SCREWED */
  108. =
  109. @@ -651,4 +656,8 @@
  110. =    mode = oldmode;
  111. =    return exit_code;
  112. +
  113. +#ifdef    thread_name    /* undo the thread name patch (if active) */
  114. +# undef thread_name
  115. +#endif
  116. =}                    /* Whew! */
  117. =
  118. Index: ngdata.c
  119. @@ -90,6 +90,11 @@
  120. =#ifdef USETHREADS
  121. =    if (use_threads) {
  122. +# ifdef XTHREAD
  123. +    cp = "server's active2";
  124. +    actfp = nntp_active2();
  125. +# else /* !XTHREADS */
  126. =    cp = filexp(ACTIVE2);
  127. =    actfp = fopen(cp,"r");
  128. +# endif    /* XTHREAD */
  129. =    if (actfp == Nullfp) {
  130. =        printf(cantopen,cp) FLUSH;
  131. Index: nntp.c
  132. @@ -0,0 +1,192 @@
  133. +/* This file (and only this file - not the entire trn distribution) is
  134. + * hereby placed in the public domain.  Use it as you see fit, but if you
  135. + * manage to find some wonderful use for this code elsewhere, it would be
  136. + * nice to receive mention for it.
  137. + *
  138. + * - Tim Iverson
  139. + *   iverson@xstor.com -/- uunet!xstor!iverson
  140. + *   3/29/91
  141. + */
  142. +
  143. +#include "EXTERN.h"
  144. +#include "common.h"
  145. +#include "server.h"
  146. +
  147. +#ifdef XTHREAD
  148. +
  149. +# ifdef __GNUC__
  150. +#  define alloca __builtin_alloca
  151. +# endif
  152. +
  153. +static    char        /* tmp file names */
  154. +    tmp_active2[]    = "/tmp/12345678901234",
  155. +    tmp_thread[]    = "/tmp/12345678901234";
  156. +
  157. +static    int        /* !0 indicates tmp file has been created */
  158. +    got_active2    = 0,
  159. +    got_thread    = 0;
  160. +
  161. +char    *nntp_thread_name = NULL;
  162. +
  163. +
  164. +/* This function returns a pointer to an open file containing a copy of the
  165. + * current active2 file on the server.
  166. + *
  167. + * entry:    it is assumed the server is already open and accessible via
  168. + *        the put_server() and get_server() functions.
  169. + *
  170. + * exit:    on success, tmp file to hold server's active2 has been created
  171. + *
  172. + * return:    file pointer opened for reading on success, NULL on failure.
  173. + */
  174. +FILE *
  175. +nntp_active2()
  176. +{
  177. +    char    ser_line[512];
  178. +    FILE    *fp;
  179. +
  180. +    /* check to see if the server will even give us the active2 file */
  181. +    put_server("LIST ACTIVE2");
  182. +    if (get_server(ser_line, sizeof(ser_line)) || (*ser_line != CHAR_OK))
  183. +        return NULL;        /* server won't/can't give it to us */
  184. +
  185. +    /* first try to create the tmp file */
  186. +    if (!got_active2)
  187. +    {
  188. +        sprintf(tmp_active2, "/tmp/rrnact2.%u", getpid());
  189. +        if (!(fp = fopen(tmp_active2, "w")))
  190. +            return NULL;
  191. +        got_active2 = 1;
  192. +    }
  193. +
  194. +    /* data is now waiting to be picked up - try to create the tmp file */
  195. +    while (!get_server(ser_line, sizeof(ser_line)))
  196. +    {
  197. +        if (ser_line[0] == '.' && !ser_line[1])
  198. +            break;
  199. +        fprintf(fp, "%s\n", ser_line);
  200. +    }
  201. +
  202. +    /* reopen the file for reading */
  203. +    return fp = freopen(tmp_active2, "r", fp);
  204. +}
  205. +
  206. +
  207. +
  208. +/* Load buf with the ouput of XTHREAD DBINIT.  Don't exceed size bytes and
  209. + * return the actual number of bytes sent.
  210. + */
  211. +int
  212. +nntp_dbinit(buf, size)
  213. +void    *buf;
  214. +int    size;
  215. +{
  216. +    int    rsize;
  217. +    char    *rbuf;
  218. +
  219. +    /* first try to do the command */
  220. +    if (!(rsize = xthread("DBINIT")))
  221. +        return rsize;
  222. +
  223. +    /* get space for the all of the bytes */
  224. +    if (!(rbuf = alloca(rsize)))
  225. +        return 0;
  226. +
  227. +    xthread_read(rbuf, rsize);
  228. +    memcpy(buf, rbuf, rsize > size ? size : rsize);
  229. +    return rsize;
  230. +}
  231. +
  232. +
  233. +
  234. +/* Get the thread for the current GROUP and put it in a tmp file.  The
  235. + * tmp file name is then placed in nntp_thread_name.
  236. + *
  237. + * entry:    the nntp GROUP command has been used to select the
  238. + *        desired newsgroup.  ser_rd_fp and ser_wr_fp (the server
  239. + *        read and write file pointers) are open; i.e. server_init()
  240. + *        has been performed successfully.
  241. + *
  242. + * exit:    a tmp file to hold the thread file from the server is
  243. + *        created and nntp_thread_name is set to point at the
  244. + *        name of that file.  On failure, nntp_thread_name is
  245. + *        set to point at the name of an empty file (/dev/null).
  246. + */
  247. +void
  248. +nntp_thread()
  249. +{
  250. +    int    size;
  251. +    char    *buf;
  252. +    FILE    *fp;
  253. +
  254. +    /* start out as a pessimist */
  255. +    nntp_thread_name = "/dev/null";
  256. +
  257. +    /* first try to do the command */
  258. +    if (!(size = xthread(NULL)))
  259. +        return;
  260. +
  261. +    /* get space for the all of the bytes */
  262. +    if (!(buf = alloca(size)))
  263. +        return;
  264. +
  265. +    /* read it in in one big gulp */
  266. +    xthread_read(buf, size);
  267. +
  268. +    /* make sure we've got a place for the thread file */
  269. +    if (!got_thread)
  270. +    {
  271. +        sprintf(tmp_thread, "/tmp/rrnthd.%u", getpid());
  272. +        got_thread = 1;
  273. +    }
  274. +
  275. +    /* try to create/open the tmp file */
  276. +    if (!(fp = fopen(tmp_thread, "w")))
  277. +        return;
  278. +
  279. +    /* write it out unbuffered */
  280. +    write(fileno(fp), buf, size);
  281. +    fclose(fp);
  282. +    nntp_thread_name = tmp_thread;
  283. +}
  284. +
  285. +
  286. +
  287. +/* Remove all temporary files used so far by the nntp support module.
  288. + * This routine could be much more general (and should if tmp files start
  289. + * proliferating).
  290. + */
  291. +void
  292. +nntp_unlink()
  293. +{
  294. +    if (got_active2)
  295. +        UNLINK(tmp_active2);
  296. +    if (got_thread)
  297. +        UNLINK(tmp_thread);
  298. +    got_active2 = got_thread = 0;
  299. +}
  300. +
  301. +
  302. +# if defined(M_XENIX) && !defined(M_UNIX)    /* sco xenix lacks memmove */
  303. +
  304. +/* ansi memmove function for non-ansi compilers
  305. + */
  306. +void *
  307. +memmove(d, s, n)
  308. +char    *d,
  309. +    *s;
  310. +size_t    n;
  311. +{
  312. +    void    *r = d;
  313. +
  314. +    if (d < s) while (n--)
  315. +        *d++ = *s++;
  316. +    else for (d += n, s += n; n; --n)
  317. +        *--d = *--s;
  318. +
  319. +    return r;
  320. +}
  321. +
  322. +# endif /* M_XENIX */
  323. +
  324. +#endif /* not XTHREAD */
  325. Index: rn.c
  326. @@ -11,5 +11,5 @@
  327. =
  328. =static char rnid[] = "@(#)$Header: rn.c,v 4.3.3.3 91/01/16 03:28:42 davison Trn $";
  329. -static char patchlevel[] = "Trn v1.0.2 based on Rn patchlevel 54";
  330. +static char patchlevel[] = "Trn v1.0.2 (with nntp threads) based on Rn patchlevel 54";
  331. =
  332. =/* $Log:    rn.c,v $
  333. Index: rthreads.c
  334. @@ -21,4 +21,8 @@
  335. =#include "rthreads.h"
  336. =
  337. +#ifdef    SERVER
  338. +# include "server.h"
  339. +#endif
  340. +
  341. =static FILE *fp_in;
  342. =
  343. @@ -40,7 +44,11 @@
  344. =
  345. =    word_same = long_same = TRUE;
  346. +#ifdef    XTHREAD
  347. +    if (nntp_dbinit(&mt_bmap, sizeof mt_bmap) >= sizeof mt_bmap - 1) {
  348. +#else    /* !XTHREAD */
  349. =    filename = filexp( "%X/db.init" );
  350. =    if( (fp_in = fopen( filename, FOPEN_RB )) != Nullfp ) {
  351. =    if( fread( &mt_bmap, 1, sizeof (BMAP), fp_in ) >= sizeof (BMAP)-1 ) {
  352. +#endif    /* XTHREAD */
  353. =        if( mt_bmap.version != DB_VERSION ) {
  354. =        printf( "\nThread database is the wrong version -- ignoring it.\n" ) FLUSH;
  355. @@ -58,4 +66,5 @@
  356. =        }
  357. =        }
  358. +#ifndef    XTHREAD
  359. =    } else {
  360. =        goto no_db_init;
  361. @@ -62,4 +71,5 @@
  362. =    }
  363. =    fclose( fp_in );
  364. +#endif    /* XTHREAD */
  365. =    } else {
  366. =      no_db_init:
  367. ##
  368. ################ patch ends here
  369. #
  370.