home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume36 / slurp / part02 < prev    next >
Encoding:
Text File  |  1993-03-11  |  50.2 KB  |  1,970 lines

  1. Newsgroups: comp.sources.misc
  2. From: steveh@orbital.demon.co.uk (Stephen Hebditch)
  3. Subject: v36i014:  slurp - A passive NNTP transfer client, v1.05, Part02/02
  4. Message-ID: <1993Mar12.165935.17236@sparky.imd.sterling.com>
  5. X-Md4-Signature: 9cae5cd14d34cf1a8a3213ae14b7b376
  6. Date: Fri, 12 Mar 1993 16:59:35 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: steveh@orbital.demon.co.uk (Stephen Hebditch)
  10. Posting-number: Volume 36, Issue 14
  11. Archive-name: slurp/part02
  12. Environment: ANSI-C, UNIX, !SCO
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then feed it
  16. # into a shell via "sh file" or similar.  To overwrite existing files,
  17. # type "sh file -c".
  18. # Contents:  Makefile conf.h fakesyslog.c fakesyslog.h history.c misc.c
  19. #   nntp.h slurp.1 slurp.h slurp.sys sockets.c space.c time.c
  20. # Wrapped by kent@sparky on Fri Mar 12 10:55:34 1993
  21. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  22. echo If this archive is complete, you will see the following message:
  23. echo '          "shar: End of archive 2 (of 2)."'
  24. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'Makefile'\"
  26. else
  27.   echo shar: Extracting \"'Makefile'\" \(1343 characters\)
  28.   sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  29. X#
  30. X# Makefile for slurp
  31. X#
  32. X
  33. X# C compiler
  34. XCC=cc
  35. X
  36. X# C compilation flags
  37. XCFLAGS= -O -Xa -I/usr/local/src/cnews/dbz
  38. X
  39. X# Loader flags
  40. XLDFLAGS=
  41. X
  42. X# Libraries needed
  43. XLIBS= /usr/local/src/cnews/dbz/dbz.o -lnsl -lsocket
  44. X
  45. X# If you don't have syslog then uncomment these two lines
  46. X#FAKESRC=fakesyslog.c
  47. X#FAKEOBJ=fakesyslog.o
  48. X
  49. X
  50. X# Everything else probably doesn't need changing
  51. X
  52. XSOURCE = slurp.c newnews.c articles.c history.c time.c sockets.c misc.c \
  53. X     space.c ${FAKESRC}
  54. X
  55. XOBJECT = slurp.o newnews.o articles.o history.o time.o sockets.o misc.o \
  56. X     space.o ${FAKEOBJ}
  57. X
  58. XMANIFEST = README slurp.c newnews.c articles.c history.c time.c sockets.c \
  59. X       misc.c space.c fakesyslog.c conf.h slurp.h nntp.h fakesyslog.h \
  60. X       Makefile slurp.sys slurp.1 HISTORY
  61. X
  62. X
  63. Xslurp: ${OBJECT}
  64. X    ${CC} ${LDFLAGS} ${OBJECT} -o slurp ${LIBS}
  65. X
  66. Xslurp.o: slurp.c slurp.h conf.h nntp.h
  67. Xnewnews.o: newnews.c slurp.h conf.h nntp.h
  68. Xarticles.o: articles.c slurp.h conf.h nntp.h
  69. Xhistory.o: history.c slurp.h conf.h nntp.h
  70. Xtime.o: time.c slurp.h conf.h
  71. Xsockets.o: sockets.c slurp.h conf.h nntp.h
  72. Xmisc.o: misc.c slurp.h conf.h
  73. Xspace.o: space.c slurp.h conf.h
  74. Xfakesyslog.o: fakesyslog.c slurp.h conf.h
  75. X
  76. Xlint:
  77. X    lint -p ${CFLAGS} ${SOURCE} > slurp.lint
  78. X
  79. Xclean:
  80. X    -rm -f *.o slurp
  81. X
  82. Xshar:
  83. X    shar -v -s -l60 -oslurp.shar ${MANIFEST}
  84. X
  85. Xtaz:
  86. X    tar -cf - ${MANIFEST} | compress > slurp.tar.Z
  87. X
  88. X# END-OF-FILE
  89. END_OF_FILE
  90.   if test 1343 -ne `wc -c <'Makefile'`; then
  91.     echo shar: \"'Makefile'\" unpacked with wrong size!
  92.   fi
  93.   # end of 'Makefile'
  94. fi
  95. if test -f 'conf.h' -a "${1}" != "-c" ; then 
  96.   echo shar: Will not clobber existing file \"'conf.h'\"
  97. else
  98.   echo shar: Extracting \"'conf.h'\" \(5297 characters\)
  99.   sed "s/^X//" >'conf.h' <<'END_OF_FILE'
  100. X/*
  101. X * conf.h - compilation options for slurp
  102. X *
  103. X * Copyright (C) 1992/93 Stephen Hebditch. All rights reserved.
  104. X * TQM Communications, BCM Box 225, London, WC1N 3XX.
  105. X * steveh@orbital.demon.co.uk  +44 836 825962
  106. X *
  107. X * See README for more information and disclaimers
  108. X *
  109. X * $Id: conf.h,v 1.5 1993/03/01 17:41:09 root Exp $
  110. X *
  111. X * $Log: conf.h,v $
  112. X * Revision 1.5  1993/03/01  17:41:09  root
  113. X * Changed USG definition to SYSV, now used solely in slurp.h.
  114. X * Added explanation of defines for space.c.
  115. X *
  116. X * Revision 1.4  1993/02/14  14:36:16  root
  117. X * Removed BATCHARTSMAX, MSGIDMAX.
  118. X * Added INDIR, BATCHNAME.
  119. X * Modified TIMFILE, RNEWS.
  120. X *
  121. X * Revision 1.0  1992/10/29
  122. X * Initial coding.
  123. X *
  124. X */
  125. X
  126. X
  127. X/* SLURP CONFIGURATION
  128. X   =================== */
  129. X
  130. X/* Set these to the location of the slurp configuration files - NEWSLIB is
  131. X   usually a good place for them. The hostname will be added to the end of
  132. X   TIMFILE. */
  133. X
  134. X#define SYSFILE            "/usr/lib/news/slurp.sys"
  135. X#define TIMFILE            "/usr/lib/news/slurp."
  136. X
  137. X
  138. X/* If SPEEDUP is defined then there will always be one ARTICLE request
  139. X   stacked up at the NNTP server before the current article has finished
  140. X   being received. Although not strictly conforming to the standard this
  141. X   allows a much greater article throughput. */
  142. X
  143. X#define SPEEDUP
  144. X
  145. X
  146. X/* If defined then the number of characters per second transferred during
  147. X   the article request phase will be logged. */
  148. X
  149. X#define SPEEDSTATS
  150. X
  151. X
  152. X/* MAXCACHE sets the maximum number of articles that may be requested in
  153. X   any one session. If this is exceeded then this is noted to the log and
  154. X   the new time for the next NEWNEWS will not be written. */
  155. X
  156. X#define MAXCACHE        4096
  157. X
  158. X
  159. X/* NEWS CONFIGURATION
  160. X   ================== */
  161. X
  162. X/* The location of the news history file. */
  163. X
  164. X#define HISTORY_FILE    "/usr/lib/news/history"
  165. X
  166. X
  167. X/* The database format used by the news history file. For modern C News
  168. X   and INN this will almost certainly be DBZ. */
  169. X
  170. X#define DBZ
  171. X#undef    DBM
  172. X#undef    NDBM
  173. X
  174. X
  175. X/* The location of the rnews program. If defined, slurp will pipe batches
  176. X   of articles to rnews rather than creating batch files in INDIR */
  177. X
  178. X/* #define RNEWS           "/usr/bin/rnews" /* */
  179. X
  180. X
  181. X/* The place where incoming batches will be placed if RNEWS is not
  182. X   defined. This is usually /usr/spool/news/in.coming for C News and
  183. X   /var/spool/rnews for INN. */
  184. X
  185. X#define INDIR            "/var/spool/news/in.coming"
  186. X
  187. X
  188. X/* The optimum size of a news batch. Normally this can be left at 300000L.
  189. X   If you are using INN and have RNEWS defined, then set this to 0 so the
  190. X   pipe to rnews (and the socket to innd) is kept open throughout the
  191. X   session. */
  192. X
  193. X#define BATCHSIZEMAX    300000L
  194. X
  195. X
  196. X/* The location of the spool directory holding news articles. This is
  197. X   needed so we can check if there is enough space before starting to
  198. X   build up another batch of articles. */
  199. X
  200. X#define SPOOLDIR        "/var/spool/news"
  201. X
  202. X
  203. X/* If less then MINFREE blocks are available on the disk containing SPOOLDIR
  204. X   or less than MINFILES inodes are available then slurp will be aborted. If
  205. X   MINFREE is not defined then a space check is not carried out. */
  206. X
  207. X#define MINFREE 4000
  208. X/* #define MINFILES 1000 /* */
  209. X                        
  210. X
  211. X/* UNIX VERSION CONFIGURATION
  212. X   ========================== */
  213. X
  214. X/* Define SYSV if you are running a System V derivative and need
  215. X   <string.h>, <time.h> & <fcntl.h> and don't have bcopy() and bzero(). 
  216. X   If it is undefined, then you're BSDish and need <strings.h> &
  217. X   <sys/time.h> and have bcopy() and bzero(). */
  218. X
  219. X#define SYSV
  220. X
  221. X
  222. X/* You may need additional defines to use the correct method of
  223. X   determining how much disk space there is on the file system
  224. X   containing your news spool. space.c understands defines for SVR4,
  225. X   SVR3, sun, hpux, pyr, hp300, NeXT, linux, apollo, ultrix, __bsdi__
  226. X   and CMU_MACH. For other systems you may need to amend space.c. */
  227. X
  228. X#define SVR4
  229. X
  230. X
  231. X/* Change to int if your signal() is old and returns int instead of void */
  232. X
  233. X#define SIGRET            void
  234. X
  235. X
  236. X/* Define if your system has extern char sys_errlist[], but no strerror() */
  237. X
  238. X#undef SYS_ERRLIST
  239. X
  240. X
  241. X/* The facility name which syslog reports errors and stats under. If you
  242. X   don't want to use syslog for reporting then undefine and the information
  243. X   will be written to stderr instead. */
  244. X
  245. X#define SYSLOG            LOG_NEWS
  246. X
  247. X
  248. X/* If you don't have syslog then you can use the supplied fakesyslog
  249. X   instead. Define FAKESYSLOG to be the name of the file to contain the
  250. X   log. If your host supports the BSD fdopen() function and the O_APPEND
  251. X   flag to open(), you should define FAKEAPPEND with FAKESYSLOG so that
  252. X   multiple copies of nntpd don't trash the log with buffered fprintfs. */
  253. X   
  254. X/* #define FAKESYSLOG      "/usr/lib/news/nntplog" /* */
  255. X/* #define FAKEAPPEND /* */
  256. X
  257. X
  258. X/* STUFF BELOW PROBABLY DOESN'T NEED ALTERING
  259. X   ========================================== */
  260. X
  261. X#define COPYSIZE        16384    /* Articles bigger than this size will
  262. X                                   be written to a temporary file while
  263. X                                   they are being retrieved, rather than
  264. X                                   stored in memory */
  265. X
  266. X#define TIMEOUT            60 * 10    /* Max time to wait for a line from the
  267. X                                   server. */
  268. X
  269. X#define BATCHNAME        "nntp.XXXXXX"    /* Temporary filename for NNTP
  270. X                                           batch */
  271. X
  272. X/* END-OF-FILE */
  273. END_OF_FILE
  274.   if test 5297 -ne `wc -c <'conf.h'`; then
  275.     echo shar: \"'conf.h'\" unpacked with wrong size!
  276.   fi
  277.   # end of 'conf.h'
  278. fi
  279. if test -f 'fakesyslog.c' -a "${1}" != "-c" ; then 
  280.   echo shar: Will not clobber existing file \"'fakesyslog.c'\"
  281. else
  282.   echo shar: Extracting \"'fakesyslog.c'\" \(3155 characters\)
  283.   sed "s/^X//" >'fakesyslog.c' <<'END_OF_FILE'
  284. X/*
  285. X * $Id: fakesyslog.c,v 1.4 1993/02/14 14:51:30 root Exp $
  286. X *
  287. X * Fake syslog routines for systems that don't have syslog.
  288. X * Taken from an idea by Paul McKenny, <mckenny@sri-unix.arpa>.
  289. X * (Unfortunately, Paul, I can't distribute the real syslog code
  290. X * as you suggested ... sigh.)
  291. X *
  292. X * Warning: this file contains joe code that may offend you.
  293. X *
  294. X * $Log: fakesyslog.c,v $
  295. X * Revision 1.4  1993/02/14  14:51:30  root
  296. X * No changes.
  297. X *
  298. X * Revision 1.4  1993/02/14  14:50:11  root
  299. X * *** empty log message ***
  300. X *
  301. X */
  302. X
  303. X#include "slurp.h"
  304. X
  305. X#ifdef FAKESYSLOG
  306. X
  307. X#include "fakesyslog.h"
  308. X
  309. X#include <stdio.h>
  310. X#include <sys/signal.h>
  311. X#include <sys/types.h>
  312. X
  313. X#ifdef FAKEAPPEND
  314. X#include <sys/file.h>
  315. X#endif
  316. X
  317. X#ifdef FCNTL
  318. X#include <fcntl.h>
  319. X#endif
  320. X
  321. Xextern    int    errno;
  322. Xextern    int    sys_nerr;
  323. Xextern    char    *sys_errlist[];
  324. X
  325. Xstatic FILE    *logfp;
  326. Xstatic int    failed = 0;
  327. Xstatic char    *ident = "syslog";
  328. Xstatic int     opt = 0;
  329. X#ifndef BSD_42
  330. Xstatic int    fac = 0;
  331. X#endif
  332. X
  333. Xextern char    *strcpy(), *strcat(), *ctime();
  334. Xextern time_t    time();
  335. X
  336. Xresetlog()
  337. X{
  338. X    closelog();
  339. X    failed = 0;
  340. X    if (logfp == NULL) {
  341. X#ifdef BSD_42
  342. X        openlog(ident, opt);
  343. X#else
  344. X        openlog(ident, opt, fac);
  345. X#endif
  346. X        if (logfp == NULL) {
  347. X            failed = 1;
  348. X            return;
  349. X        }
  350. X    }
  351. X}
  352. X
  353. X#ifdef BSD_42
  354. Xopenlog(newident,logopt)
  355. X    char *newident;
  356. X    int logopt;
  357. X#else
  358. Xopenlog(newident,logopt,facility)
  359. X    char *newident;
  360. X    int logopt, facility;
  361. X#endif
  362. X{
  363. X#ifdef FAKEAPPEND
  364. X/*
  365. X * why can't stdio give us the capability of O_APPEND?
  366. X */
  367. X    int fd;
  368. X
  369. X    fd = open(FAKESYSLOG, O_WRONLY|O_APPEND, 0664);
  370. X    if (fd < 0)
  371. X        logfp = NULL;
  372. X    else
  373. X        logfp = fdopen(fd, "a");
  374. X#else
  375. X    logfp = fopen(FAKESYSLOG, "a");
  376. X#endif
  377. X
  378. X    (void)signal(SIGHUP, resetlog);
  379. X
  380. X    if (newident && *newident)
  381. X        ident = newident;
  382. X    opt = logopt;
  383. X#ifndef BSD_42
  384. X    fac = facility;
  385. X#endif
  386. X}
  387. X
  388. Xcloselog()
  389. X{
  390. X    if (logfp) {
  391. X        (void)fclose(logfp);
  392. X        failed = 0;
  393. X        logfp = NULL;
  394. X    }
  395. X}
  396. X
  397. X/*ARGSUSED*/
  398. Xsetlogmask(maskpri)
  399. X    int maskpri;
  400. X{
  401. X}
  402. X
  403. Xsyslog(pri, msg, x1, x2, x3, x4, x5, x6)
  404. X    int    pri;
  405. X    char    *msg, *x1, *x2, *x3, *x4, *x5, *x6;
  406. X{
  407. X    char        buf[1024];
  408. X    char        *cp, *bp;
  409. X    time_t        clock;
  410. X
  411. X    if (failed)
  412. X        return;
  413. X
  414. X    if (logfp == NULL) {
  415. X#ifdef BSD_42
  416. X        openlog(ident, opt);
  417. X#else
  418. X        openlog(ident, opt, fac);
  419. X#endif
  420. X        if (logfp == NULL) {
  421. X            failed = 1;
  422. X            return;
  423. X        }
  424. X    }
  425. X
  426. X    (void) time(&clock);
  427. X    (void) strcpy(buf, ctime(&clock)+4);
  428. X    *(bp = buf + 16) = '\0';
  429. X
  430. X    (void) sprintf(bp, "localhost %s", ident ? ident : "");
  431. X    bp += strlen(bp);
  432. X
  433. X    if (opt&LOG_PID) {
  434. X        /* don't cache getpid() - who knows when we'll fork() */
  435. X        (void) sprintf(bp, "[%d]", getpid());
  436. X        bp += strlen(bp);
  437. X    }
  438. X
  439. X    if (ident) {
  440. X        (void) strcat(bp, ": ");
  441. X        bp += 2;
  442. X    } else {
  443. X        (void) strcat(bp, " ");
  444. X        bp ++;
  445. X    }
  446. X
  447. X    for (cp = msg; *cp; cp++) {
  448. X        if (*cp == '%' && cp[1] == 'm') {
  449. X            *bp = '\0';
  450. X            if (errno >= sys_nerr || errno < 0) {
  451. X                char    work[32];
  452. X                (void)sprintf(work, "unknown error #%d", errno);
  453. X                (void)strcat(bp, work);
  454. X            } else
  455. X                (void)strcat(bp, sys_errlist[errno]);
  456. X            bp = buf + strlen(buf);
  457. X            cp++;
  458. X        } else {
  459. X            *bp++ = *cp;
  460. X        }
  461. X    }
  462. X    *bp = '\0';
  463. X    /* Ah, the semantic security of C ... */
  464. X    if (bp[-1] != '\n')
  465. X        (void) strcat(bp, "\n");
  466. X
  467. X    fprintf(logfp, buf, x1, x2, x3, x4, x5, x6);
  468. X    (void) fflush(logfp);
  469. X}
  470. X
  471. X#endif
  472. END_OF_FILE
  473.   if test 3155 -ne `wc -c <'fakesyslog.c'`; then
  474.     echo shar: \"'fakesyslog.c'\" unpacked with wrong size!
  475.   fi
  476.   # end of 'fakesyslog.c'
  477. fi
  478. if test -f 'fakesyslog.h' -a "${1}" != "-c" ; then 
  479.   echo shar: Will not clobber existing file \"'fakesyslog.h'\"
  480. else
  481.   echo shar: Extracting \"'fakesyslog.h'\" \(953 characters\)
  482.   sed "s/^X//" >'fakesyslog.h' <<'END_OF_FILE'
  483. X/*
  484. X * Fake syslog definitions.
  485. X *
  486. X * @(#)fakesyslog.h    1.1    (Berkeley) 12/18/87
  487. X */
  488. X
  489. X#ifdef FAKESYSLOG
  490. X
  491. X/*
  492. X *  Facility codes
  493. X */
  494. X
  495. X#define LOG_KERN    0
  496. X#define LOG_USER    0
  497. X#define LOG_MAIL    0
  498. X#define LOG_DAEMON    0
  499. X#define LOG_AUTH    0
  500. X#define LOG_SYSLOG    0
  501. X#define LOG_LPR        0
  502. X#define LOG_NEWS    0
  503. X#define LOG_LOCAL0    0
  504. X#define LOG_LOCAL1    0
  505. X#define LOG_LOCAL2    0
  506. X#define LOG_LOCAL3    0
  507. X#define LOG_LOCAL4    0
  508. X#define LOG_LOCAL5    0
  509. X#define LOG_LOCAL6    0
  510. X#define LOG_LOCAL7    0
  511. X
  512. X#define LOG_NFACILITIES    0
  513. X#define LOG_FACMASK    0
  514. X
  515. X/*
  516. X *  Priorities
  517. X */
  518. X
  519. X#define LOG_EMERG    0
  520. X#define LOG_ALERT    0
  521. X#define LOG_CRIT    0
  522. X#define LOG_ERR        0
  523. X#define LOG_WARNING    0
  524. X#define LOG_NOTICE    0
  525. X#define LOG_INFO    0
  526. X#define LOG_DEBUG    0
  527. X
  528. X#define LOG_PRIMASK    0
  529. X
  530. X/*
  531. X * arguments to setlogmask.
  532. X */
  533. X
  534. X#define    LOG_MASK(pri)    0
  535. X#define    LOG_UPTO(pri)    0
  536. X
  537. X/*
  538. X *  Option flags for openlog.
  539. X */
  540. X
  541. X#define    LOG_PID        1
  542. X#define    LOG_CONS    0
  543. X#define    LOG_ODELAY    0
  544. X#define LOG_NDELAY    0
  545. X#define LOG_NOWAIT    0
  546. X
  547. X#endif FAKESYSLOG
  548. END_OF_FILE
  549.   if test 953 -ne `wc -c <'fakesyslog.h'`; then
  550.     echo shar: \"'fakesyslog.h'\" unpacked with wrong size!
  551.   fi
  552.   # end of 'fakesyslog.h'
  553. fi
  554. if test -f 'history.c' -a "${1}" != "-c" ; then 
  555.   echo shar: Will not clobber existing file \"'history.c'\"
  556. else
  557.   echo shar: Extracting \"'history.c'\" \(1588 characters\)
  558.   sed "s/^X//" >'history.c' <<'END_OF_FILE'
  559. X/*
  560. X * history - handle a news history file
  561. X *
  562. X * Copyright (C) 1992/93 Stephen Hebditch. All rights reserved.
  563. X * TQM Communications, BCM Box 225, London, WC1N 3XX.
  564. X * steveh@orbital.demon.co.uk  +44 836 825962
  565. X *
  566. X * See README for more information and disclaimers
  567. X *
  568. X * Routines to open and close a C-News style history file and determine
  569. X * whether or not a particular message id exists in the history file.
  570. X *
  571. X * $Id: history.c,v 1.4 1993/02/14 14:51:59 root Exp $
  572. X *
  573. X * $Log: history.c,v $
  574. X * Revision 1.4  1993/02/14  14:51:59  root
  575. X * No changes.
  576. X *
  577. X * Revision 1.0  1992/09/92
  578. X * Initial coding.
  579. X *
  580. X */
  581. X
  582. X#include "slurp.h"
  583. X
  584. X#ifdef DBM
  585. X  #undef NULL
  586. X  #include <dbm.h>
  587. X  #undef NULL
  588. X  #define NULL 0
  589. X#endif
  590. X
  591. X#ifdef DBZ
  592. X  #include <dbz.h>
  593. X  #define DBM
  594. X#endif
  595. X
  596. X#ifdef NDBM
  597. X  #include <ndbm.h>
  598. X  #include <fcntl.h>
  599. X  static DBM *db = NULL;
  600. X#endif
  601. X
  602. X
  603. X/*
  604. X * open_history - Open history file
  605. X */
  606. X
  607. X    int
  608. Xopen_history ()
  609. X    {
  610. X#ifdef DBM
  611. X    if (dbminit (HISTORY_FILE) < 0)
  612. X        return (1);
  613. X#endif
  614. X
  615. X#ifdef NDBM
  616. X     if ((db = dbm_open (HISTORY_FILE, O_RDONLY, 0)) == NULL)
  617. X        return (1);
  618. X#endif
  619. X
  620. X    return (0);
  621. X    }
  622. X
  623. X
  624. X/*
  625. X * close_history - Close history file
  626. X */
  627. X
  628. X    void
  629. Xclose_history ()
  630. X    {
  631. X#ifdef DBM
  632. X    (void) dbmclose ();
  633. X#endif
  634. X
  635. X#ifdef NDBM
  636. X     dbm_close (db);
  637. X#endif
  638. X    }
  639. X
  640. X
  641. X/*
  642. X * Determine if message id already exists in the history file
  643. X */
  644. X
  645. X    int
  646. Xcheck_id (char *message_id)
  647. X    {
  648. X    datum k, d;
  649. X
  650. X/* Now check for presence with dbm/ndbm */
  651. X
  652. X    k.dptr = message_id;
  653. X    k.dsize = strlen (message_id) + 1;
  654. X
  655. X#ifdef DBM
  656. X    d = fetch (k);
  657. X#else
  658. X     d = dbm_fetch (db, k);
  659. X#endif
  660. X
  661. X    return (d.dptr == NULL);
  662. X    }
  663. X
  664. X/* END-OF-FILE */
  665. END_OF_FILE
  666.   if test 1588 -ne `wc -c <'history.c'`; then
  667.     echo shar: \"'history.c'\" unpacked with wrong size!
  668.   fi
  669.   # end of 'history.c'
  670. fi
  671. if test -f 'misc.c' -a "${1}" != "-c" ; then 
  672.   echo shar: Will not clobber existing file \"'misc.c'\"
  673. else
  674.   echo shar: Extracting \"'misc.c'\" \(2406 characters\)
  675.   sed "s/^X//" >'misc.c' <<'END_OF_FILE'
  676. X/*
  677. X * misc - general miscellaneous routines
  678. X *
  679. X * Copyright (C) 1992/93 Stephen Hebditch. All rights reserved.
  680. X * TQM Communications, BCM Box 225, London, WC1N 3XX.
  681. X * steveh@orbital.demon.co.uk  +44 836 825962
  682. X *
  683. X * See README for more information and disclaimers
  684. X *
  685. X * Assorted miscellaneous routines.
  686. X *
  687. X * $Id: misc.c,v 1.4 1993/02/14 14:53:27 root Exp $
  688. X *
  689. X * $Log: misc.c,v $
  690. X * Revision 1.4  1993/02/14  14:53:27  root
  691. X * In log_sys if any message ids are present, then submit the
  692. X * currently open batch and write out the unretrieved message
  693. X * ids to slurp.<hostname> along with the new time.
  694. X *
  695. X * Revision 1.0  1992/11/27
  696. X * Initial coding.
  697. X *
  698. X */
  699. X
  700. X#include "slurp.h"
  701. X#include <stdarg.h>
  702. X
  703. Xstatic int in_log_sys = FALSE;
  704. X
  705. Xstatic void log_doit (int sysflag, const char *fmt, va_list ap);
  706. X
  707. X
  708. X/*
  709. X * log_ret - Log a message to stderr or syslog related to a system call
  710. X * containing the appropriate system error message and return.
  711. X */
  712. X
  713. X    void
  714. Xlog_ret (const char *fmt, ...)
  715. X    {
  716. X    va_list ap;
  717. X
  718. X    va_start (ap, fmt);
  719. X    log_doit (TRUE, fmt, ap);
  720. X    va_end (ap);
  721. X    return;
  722. X    }
  723. X
  724. X
  725. X/*
  726. X * log_sys - Log a message to stderr or syslog related to a system call.
  727. X * containing the appropriate system error message and exit program.
  728. X * If any message ids in the tree then write out slurp.<hostname> file
  729. X * and close the batch if open.
  730. X */
  731. X
  732. X    void
  733. Xlog_sys (const char *fmt, ...)
  734. X    {
  735. X    va_list ap;
  736. X
  737. X    va_start (ap, fmt);
  738. X    log_doit (TRUE, fmt, ap);
  739. X    va_end (ap);
  740. X    if ((!in_log_sys) && (root != NULL))
  741. X        {
  742. X        in_log_sys = TRUE;
  743. X        enqueue_batch ();
  744. X        if ((!no_time_flag) && (!no_id_load_flag))
  745. X            set_ntime ();
  746. X        }
  747. X    exit (1);
  748. X    }
  749. X
  750. X
  751. X/*
  752. X * log_msg - Log a message to stderr or syslog unrelated to a system call.
  753. X */
  754. X
  755. X    void
  756. Xlog_msg (const char *fmt, ...)
  757. X    {
  758. X    va_list ap;
  759. X
  760. X    va_start (ap, fmt);
  761. X    log_doit (FALSE, fmt, ap);
  762. X    va_end (ap);
  763. X    return;
  764. X    }
  765. X
  766. X
  767. X/*
  768. X * log_doit - Write an error message to stderr if debug_flag is set or
  769. X * syslog if not set. If sysflag is true then the last system error
  770. X * message is appended.
  771. X */
  772. X
  773. X    static void
  774. Xlog_doit (int sysflag, const char *fmt, va_list ap)
  775. X    {
  776. X    int errnosave;
  777. X    char buf [BUFSIZ];
  778. X
  779. X    errnosave = errno;
  780. X    (void) vsprintf (buf, fmt, ap);
  781. X    if (sysflag)
  782. X        (void) sprintf (buf + strlen (buf), ": %s", strerror (errnosave));
  783. X    (void) strcat (buf, "\n");
  784. X#ifdef SYSLOG
  785. X        if (!debug_flag)
  786. X            syslog (LOG_ERR, buf);
  787. X        else
  788. X#endif
  789. X            (void) fprintf (stderr, "%s: %s", pname, buf);
  790. X    }
  791. X
  792. X
  793. X/* END-OF-FILE */
  794. END_OF_FILE
  795.   if test 2406 -ne `wc -c <'misc.c'`; then
  796.     echo shar: \"'misc.c'\" unpacked with wrong size!
  797.   fi
  798.   # end of 'misc.c'
  799. fi
  800. if test -f 'nntp.h' -a "${1}" != "-c" ; then 
  801.   echo shar: Will not clobber existing file \"'nntp.h'\"
  802. else
  803.   echo shar: Extracting \"'nntp.h'\" \(3070 characters\)
  804.   sed "s/^X//" >'nntp.h' <<'END_OF_FILE'
  805. X/*
  806. X * Response codes for NNTP server
  807. X *
  808. X * @(#)Header: nntp.h,v 1.8 90/07/05 02:08:31 sob Exp $
  809. X *
  810. X * First digit:
  811. X *
  812. X *    1xx    Informative message
  813. X *    2xx    Command ok
  814. X *    3xx    Command ok so far, continue
  815. X *    4xx    Command was correct, but couldn't be performed
  816. X *        for some specified reason.
  817. X *    5xx    Command unimplemented, incorrect, or a
  818. X *        program error has occurred.
  819. X *
  820. X * Second digit:
  821. X *
  822. X *    x0x    Connection, setup, miscellaneous
  823. X *    x1x    Newsgroup selection
  824. X *    x2x    Article selection
  825. X *    x3x    Distribution
  826. X *    x4x    Posting
  827. X */
  828. X
  829. X#define    CHAR_INF    '1'
  830. X#define    CHAR_OK        '2'
  831. X#define    CHAR_CONT    '3'
  832. X#define    CHAR_ERR    '4'
  833. X#define    CHAR_FATAL    '5'
  834. X
  835. X#define    INF_HELP    100    /* Help text on way */
  836. X#define    INF_AUTH    180    /* Authorization capabilities */
  837. X#define    INF_DEBUG    199    /* Debug output */
  838. X
  839. X#define    OK_CANPOST    200    /* Hello; you can post */
  840. X#define    OK_NOPOST    201    /* Hello; you can't post */
  841. X#define    OK_SLAVE    202    /* Slave status noted */
  842. X#define    OK_GOODBYE    205    /* Closing connection */
  843. X#define    OK_GROUP    211    /* Group selected */
  844. X#define    OK_GROUPS    215    /* Newsgroups follow */
  845. X#define    OK_ARTICLE    220    /* Article (head & body) follows */
  846. X#define    OK_HEAD        221    /* Head follows */
  847. X#define    OK_BODY        222    /* Body follows */
  848. X#define    OK_NOTEXT    223    /* No text sent -- stat, next, last */
  849. X#define    OK_NEWNEWS    230    /* New articles by message-id follow */
  850. X#define    OK_NEWGROUPS    231    /* New newsgroups follow */
  851. X#define    OK_XFERED    235    /* Article transferred successfully */
  852. X#define    OK_POSTED    240    /* Article posted successfully */
  853. X#define    OK_AUTHSYS    280    /* Authorization system ok */
  854. X#define    OK_AUTH        281    /* Authorization (user/pass) ok */
  855. X
  856. X#define    CONT_XFER    335    /* Continue to send article */
  857. X#define    CONT_POST    340    /* Continue to post article */
  858. X#define    NEED_AUTHINFO    380    /* authorization is required */
  859. X#define    NEED_AUTHDATA    381    /* <type> authorization data required */
  860. X
  861. X#define    ERR_GOODBYE    400    /* Have to hang up for some reason */
  862. X#define    ERR_NOGROUP    411    /* No such newsgroup */
  863. X#define    ERR_NCING    412    /* Not currently in newsgroup */
  864. X#define    ERR_NOCRNT    420    /* No current article selected */
  865. X#define    ERR_NONEXT    421    /* No next article in this group */
  866. X#define    ERR_NOPREV    422    /* No previous article in this group */
  867. X#define    ERR_NOARTIG    423    /* No such article in this group */
  868. X#define    ERR_NOART    430    /* No such article at all */
  869. X#define    ERR_GOTIT    435    /* Already got that article, don't send */
  870. X#define    ERR_XFERFAIL    436    /* Transfer failed */
  871. X#define    ERR_XFERRJCT    437    /* Article rejected, don't resend */
  872. X#define    ERR_NOPOST    440    /* Posting not allowed */
  873. X#define    ERR_POSTFAIL    441    /* Posting failed */
  874. X#define    ERR_NOAUTH    480    /* authorization required for command */
  875. X#define    ERR_AUTHSYS    481    /* Authorization system invalid */
  876. X#define    ERR_AUTHREJ    482    /* Authorization data rejected */
  877. X
  878. X#define    ERR_COMMAND    500    /* Command not recognized */
  879. X#define    ERR_CMDSYN    501    /* Command syntax error */
  880. X#define    ERR_ACCESS    502    /* Access to server denied */
  881. X#define    ERR_FAULT    503    /* Program fault, command not performed */
  882. X#define    ERR_AUTHBAD    580    /* Authorization Failed */
  883. X
  884. X/* RFC 977 defines this; don't change it. */
  885. X
  886. X#define    NNTP_STRLEN    512
  887. END_OF_FILE
  888.   if test 3070 -ne `wc -c <'nntp.h'`; then
  889.     echo shar: \"'nntp.h'\" unpacked with wrong size!
  890.   fi
  891.   # end of 'nntp.h'
  892. fi
  893. if test -f 'slurp.1' -a "${1}" != "-c" ; then 
  894.   echo shar: Will not clobber existing file \"'slurp.1'\"
  895. else
  896.   echo shar: Extracting \"'slurp.1'\" \(8296 characters\)
  897.   sed "s/^X//" >'slurp.1' <<'END_OF_FILE'
  898. X.TH SLURP 1 "1 March 1993" "V1.04"
  899. X
  900. X.SH NAME
  901. X.I slurp
  902. X\- retrieve netnews articles from a remote NNTP server
  903. X
  904. X.SH SYNOPSIS
  905. X.I slurp
  906. X[
  907. X.B \-g
  908. X.I newsgroups/distributions
  909. X]
  910. X[
  911. X.B \-t
  912. X.I time
  913. X]
  914. X[
  915. X.B \-a
  916. X.I username/password
  917. X]
  918. X[
  919. X.B \-d
  920. X]
  921. X[
  922. X.B \-i
  923. X]
  924. X[
  925. X.B \-l
  926. X]
  927. X[
  928. X.B \-r
  929. X]
  930. X[
  931. X.B \-w
  932. X]
  933. X.I hostname[/sublist]
  934. X
  935. X.SH DESCRIPTION
  936. X.PP
  937. X.I Slurp
  938. Xis an advanced passive NNTP client for UNIX. It will connect to a
  939. Xremote NNTP server and retrieve articles in a specified set of Usenet
  940. Xnewsgroups that have arrived after a particular time (typically the
  941. Xlast time it was invoked) for processing by your local news system.
  942. X
  943. X.SH OPTIONS
  944. X.TP
  945. X.BI -g " newsgroups/distributions"
  946. XIf specified then overrides any newsgroups and distributions specification
  947. Xfor
  948. X.I hostname
  949. Xin the 
  950. X.B slurp.sys
  951. Xfile.
  952. X.TP
  953. X.BI -t " time"
  954. XRetrieve articles that have arrived at the server after
  955. X.I time
  956. Xrather than using the time taken from
  957. X.BR slurp.<hostname> .
  958. XThis is in the standard NNTP time format of 'YYMMDD HHMMSS' GMT. For
  959. Xexample, midnight GMT on the 1st of December 1992 will be '921201
  960. X000000'. Note that you will need to use quotes around the time and
  961. Xremember that the time is in GMT, not the local or server time.
  962. X.TP
  963. X.BI -a " username/password"
  964. XIf specified then the username and password combination will be sent to
  965. Xthe server as part of the simple authorisation protocol when the
  966. Xconnection is first made.
  967. X.TP
  968. X.B -d
  969. XEnable debugging. This diverts reporting to stderr instead of syslog
  970. Xand turns on extra debugging output.
  971. X.TP
  972. X.B -i
  973. XNormally if an error occurs while fetching articles from the server,
  974. Xthe remaining message IDs to be fetched are written to
  975. X.B slurp.<hostname>
  976. Xso that they may be retrieved in the next session without having to
  977. Xrestart the NEWNEWS at the same point. With this option selected, no
  978. Xmessage IDs will be read from
  979. X.B slurp.<hostname>
  980. Xand in the event of an error occurring,
  981. X.B slurp.<hostname>
  982. Xwill not be updated.
  983. X.TP
  984. X.B -l
  985. XLocal time is used to set the start time in
  986. X.B slurp.<hostname>
  987. Xfor the next news retrieval, rather than setting the start time through
  988. Xa call to the tcp time service at the remote server.
  989. X.TP
  990. X.B -r
  991. XA 'MODE READER' command is sent to the remote server. This is used when
  992. Xconnecting with an INN site which needs to be switched from innd to
  993. Xnnrpd so the NEWNEWS command can be issued.
  994. X.TP
  995. X.B -w
  996. XThe time for the next news retrieval is not written to
  997. X.BR slurp.<hostname> \.
  998. X.TP
  999. X.I hostname
  1000. XThe hostname of the remote NNTP server to connect to. This must be
  1001. Xspecified.
  1002. X.TP
  1003. X.I [/sublist]
  1004. XIf this is specified, then the entry in
  1005. X.B slurp.sys
  1006. Xwhich contains
  1007. X.I /sublist
  1008. Xafter the hostname will be used. This lets you take different groups
  1009. Xfrom the same server at different times.
  1010. X
  1011. X.SH "CONFIGURATION FILES"
  1012. X.PP
  1013. XThere are two configuration files used by
  1014. X.IR slurp .
  1015. X.SS slurp.sys
  1016. X.PP
  1017. XEntries in
  1018. X.B slurp.sys
  1019. Xtake the form
  1020. X.IP
  1021. Xhostname/sublist:groups/distributions:flags:username/password
  1022. X.PP
  1023. XThis format should be familar to people who have used the C News
  1024. X.B sys
  1025. Xfile. Entries for a particular host can be continued on more than one
  1026. Xline by using a '\\' at the end of the line. e.g.
  1027. X.IP
  1028. Xhostname:group1,group2,\\
  1029. X.br
  1030. Xgroup3,group4,group5
  1031. X.PP
  1032. X.I Slurp
  1033. Xis even more picky about the presence of whitespace than C News. It can
  1034. Xonly appear in comments. Comments begin with a '#' and continue to the
  1035. Xend of the line.
  1036. X.PP
  1037. XUsing distributions is
  1038. X.B not
  1039. Xrecommended - they're only really included for completeness. Under
  1040. Xcurrent NNTP implementations, setting distributions requires the server
  1041. Xto open each article, search through for the distributions line and
  1042. Xcheck it against the supplied list. This will not only increase the
  1043. Xload on the server substantially, but increase the amount of time for
  1044. Xthe connection.
  1045. X.PP
  1046. XThere are 3 possible flags: i, l and r which have the same meaning as
  1047. Xthe command line options. If present, username and password will be
  1048. Xsent to the server as part of the simple authorisation protocol when
  1049. Xthe connection is first made.
  1050. X.SS slurp.<hostname>[.<sublist>]
  1051. X.PP
  1052. XThe file
  1053. X.B slurp.<hostname>
  1054. Xcontains the time when
  1055. X.I slurp
  1056. Xlast connected to the NNTP server at <hostname>. If a sublist has been
  1057. Xspecified with the
  1058. X.B -s
  1059. Xoption then this will be appended with a period to the name.
  1060. X.I slurp
  1061. Xcan then use this time to pick up all the articles that have arrived at
  1062. Xthe server since the last session. It may be followed on subsequent
  1063. Xlines by a list of message IDs of articles that are to be retrieved
  1064. Xfrom the server in the next session.
  1065. X.PP
  1066. XEach time
  1067. X.I slurp
  1068. Xis run and
  1069. X.B slurp.<hostname>
  1070. Xupdated, the current
  1071. X.B slurp.<hostname>
  1072. Xwill be backed up in the file
  1073. X.BR slurp.<hostname>.o \.
  1074. X
  1075. X.SH OPERATION
  1076. X.PP
  1077. XWhen run,
  1078. X.I slurp
  1079. Xwill first retrieve the appropriate newsgroup list, distribution list
  1080. Xand start time for the specified server, either from the configuration
  1081. Xfiles or overriding those settings with the command line options.
  1082. X.PP
  1083. XIf the
  1084. X.B -w
  1085. Xoption is not set, then the current time will be obtained to use as the
  1086. Xstart time for the next session. If the
  1087. X.B -l
  1088. Xoption is specified, this will be taken from the local machine,
  1089. Xotherwise it will be retrieved from the remote server through a call to
  1090. Xthe tcp time service there. If
  1091. X.B -i
  1092. Xis not specified, then the message IDs of any articles which were not
  1093. Xretrieved in the last session will be loaded from
  1094. X.BR slurp.<hostname> \.
  1095. X.PP
  1096. X.I Slurp
  1097. Xwill now connect to the NNTP server at the remote host. If a username
  1098. Xand password for use with the simple authorisation protocol have been
  1099. Xsupplied then they will be sent to the server. If the
  1100. X.B -r
  1101. Xoption is specified, then a 'MODE READER' command will be sent, to
  1102. Xensure at INN sites that
  1103. X.I slurp
  1104. Xis talking to nnrpd.
  1105. X.PP
  1106. XA NEWNEWS request will now be issued, asking for all the articles that
  1107. Xhave arrived in the specified list of newsgroups since the specified
  1108. Xtime. The server will respond with a list of message IDs. If a message
  1109. XID is not already present in the local history file, then it will be
  1110. Xstored in memory. If the list of newsgroups is too large to fit on
  1111. Xone line (NNTP has a maximum line length of 512 characters) then a
  1112. Xseries of NEWNEWS requests will be carried out, adding further message
  1113. XIDs to the memory list if they are not already present.
  1114. X.PP
  1115. XOnce this has been completed,
  1116. X.I slurp
  1117. Xmoves into an article retrieval stage. It will go through the list of
  1118. Xmessage IDs in memory and request them in turn from the server, adding
  1119. Xeach article to the batch of articles being either stored in the
  1120. Xincoming news directory or piped to
  1121. X.I rnews.
  1122. XWhen a batch is found to be larger than the maximum size, it will be
  1123. Xsubmitted to the news system.
  1124. X.PP
  1125. XOnce all the articles have been retrieved, the final batch of articles
  1126. Xwill be submitted. If the
  1127. X.B -w
  1128. Xoption has not been set, then the previously obtained time to use for
  1129. Xthe next NEWNEWS will be written to
  1130. X.BR slurp.<hostname> .
  1131. XIf an error has occurred, then the message IDs of any unretrieved
  1132. Xarticles are also written to this file, for retrieval in the next
  1133. Xsession.
  1134. X.PP
  1135. XStatistics on the connection will be logged to syslog (or stderr if
  1136. Xsyslog is not available). The new article count is the total number of
  1137. Xarticles that have been submitted to the new system. The duplicate
  1138. Xcount is how many message IDs were found to already exist on the local
  1139. Xsystem. If two NEWNEWS requests are necessary and a message ID was
  1140. Xreturned by both requests, then it will be included twice in the
  1141. Xduplicate count. The missing count is those articles which were in the
  1142. Xserver's history file but didn't exist as actual article files, usually
  1143. Xbecause they have been cancelled. If configured, the speed of transfer
  1144. Xof the article retrieval stage will also be logged.
  1145. X
  1146. X.SH "RETURN CODES"
  1147. X.PP
  1148. XSlurp returns a series of return codes which may be useful to
  1149. Xcontrolling programs:-
  1150. X.RS
  1151. X0 - Successful completion
  1152. X.br
  1153. X1 - General system error
  1154. X.br
  1155. X2 - Incorrect arguments supplied or incorrect configuration files.
  1156. X.br
  1157. X3 - Error occurred during attempt to connect to remote host
  1158. X.br
  1159. X4 - NNTP Protocol error
  1160. X.br
  1161. X5 - Insufficient disk space available for news batch.
  1162. X.RE
  1163. X
  1164. X.SH FILES
  1165. X/usr/lib/news/slurp.sys
  1166. X.br
  1167. X/usr/lib/news/slurp.<hostname>
  1168. X.SH AUTHOR
  1169. XStephen Hebditch <steveh@orbital.demon.co.uk>
  1170. X.SH "SEE ALSO"
  1171. Xrnews(8)
  1172. X.br
  1173. XRFC977 \- Network News Transfer Protocol (NNTP),
  1174. X.br
  1175. XRFC1036 \- Usenet Article Format standard.
  1176. END_OF_FILE
  1177.   if test 8296 -ne `wc -c <'slurp.1'`; then
  1178.     echo shar: \"'slurp.1'\" unpacked with wrong size!
  1179.   fi
  1180.   # end of 'slurp.1'
  1181. fi
  1182. if test -f 'slurp.h' -a "${1}" != "-c" ; then 
  1183.   echo shar: Will not clobber existing file \"'slurp.h'\"
  1184. else
  1185.   echo shar: Extracting \"'slurp.h'\" \(3522 characters\)
  1186.   sed "s/^X//" >'slurp.h' <<'END_OF_FILE'
  1187. X/*
  1188. X * slurp.h - common definitions for slurp
  1189. X *
  1190. X * Copyright (C) 1992/93 Stephen Hebditch. All rights reserved.
  1191. X * TQM Communications, BCM Box 225, London, WC1N 3XX.
  1192. X * steveh@orbital.demon.co.uk  +44 836 825962
  1193. X *
  1194. X * See README for more information and disclaimers
  1195. X *
  1196. X * $Id: slurp.h,v 1.5 1993/03/01 17:57:44 root Exp $
  1197. X *
  1198. X * $Log: slurp.h,v $
  1199. X * Revision 1.5  1993/03/01  17:57:44  root
  1200. X * Minor reshuffle, plus USG definition now SYSV.
  1201. X *
  1202. X * Revision 1.4  1993/02/14  14:40:55  root
  1203. X * Added no_id_load_flag.
  1204. X * Modified struct mnode to include used flag and remove msgid.
  1205. X * New process_id and set_ntime definitions.
  1206. X *
  1207. X * Revision 1.3  1992/12/15
  1208. X * Added SYS_ERRLIST definitions.
  1209. X *
  1210. X * Revision 1.1  1992/12/06
  1211. X * Added no_time flag.
  1212. X *
  1213. X * Revision 1.0  1992/10/29
  1214. X * Initial coding.
  1215. X *
  1216. X */
  1217. X
  1218. X/* Local header files */
  1219. X
  1220. X#include "conf.h"
  1221. X#include "nntp.h"
  1222. X
  1223. X
  1224. X/* Standard header files */
  1225. X
  1226. X#include <sys/types.h>
  1227. X#include <stdio.h>
  1228. X#include <stdlib.h>
  1229. X#include <unistd.h>
  1230. X#include <limits.h>
  1231. X#include <ctype.h>
  1232. X#include <errno.h>
  1233. X
  1234. X#ifdef SYSLOG
  1235. X  #ifdef FAKESYSLOG
  1236. X    #include "fakesyslog.h"
  1237. X  #else
  1238. X    #include <syslog.h>
  1239. X  #endif
  1240. X#endif
  1241. X
  1242. X#ifdef SYSV
  1243. X  #define FCNTL
  1244. X  #include <string.h>
  1245. X  #include <time.h>
  1246. X  #ifndef bcopy
  1247. X    #define bcopy(a,b,c) (void) memcpy ((char*) b, (char*) a, (int) c)
  1248. X  #endif
  1249. X  #ifndef bzero
  1250. X    #define bzero(a,b) (void) memset ((char*) a, 0, (int) b)
  1251. X  #endif
  1252. X#else
  1253. X  #include <strings.h>
  1254. X  #include <sys/time.h>
  1255. X#endif
  1256. X
  1257. X#ifdef SYS_ERRLIST
  1258. X  extern const char *sys_errlist[];
  1259. X  #define strerror(x) (sys_errlist[x])
  1260. X#endif
  1261. X
  1262. X
  1263. X/* Important variables */
  1264. X
  1265. Xextern char *hostname;        /* Name of current NNTP server host */
  1266. Xextern char *pname;            /* Name of this program */
  1267. Xextern int  debug_flag;        /* Write extra debugging output to screen */
  1268. Xextern int  no_time_flag;    /* Don't update slurp.<hostname> */
  1269. Xextern int  no_id_load_flag;/* Don't dump / load message ids */
  1270. X
  1271. X/* Article counters */
  1272. X
  1273. Xextern int  dupart;            /* Number of duplicate articles */
  1274. Xextern int  misart;            /* Number of missing articles */
  1275. Xextern int  newart;            /* Number of new articles */
  1276. X
  1277. Xextern long totalsize;        /* Total size of articles tranferred */
  1278. X
  1279. X/* Details for NEWNEWS */
  1280. X
  1281. Xextern char *nn_newsgroups;
  1282. Xextern char *nn_time;
  1283. Xextern char *nn_distributions;
  1284. X
  1285. X/* Binary tree holding message ids */
  1286. X
  1287. Xstruct mnode
  1288. X    {
  1289. X    struct mnode *left;
  1290. X    struct mnode *right;
  1291. X    char *msgid;
  1292. X    int used;
  1293. X    };
  1294. X                          
  1295. Xextern struct mnode *root;
  1296. Xextern int entries;
  1297. X
  1298. X
  1299. X/* Slurp function prototypes */
  1300. X
  1301. Xextern void get_articles ();                        /* articles.c */
  1302. Xextern void enqueue_batch ();
  1303. X
  1304. Xextern int  open_history ();                        /* history.c */
  1305. Xextern void close_history ();
  1306. Xextern int  check_id (char *message_id);
  1307. X
  1308. Xextern void log_ret (const char *fmt, ...);            /* misc.c */
  1309. Xextern void log_sys (const char *fmt, ...);
  1310. Xextern void log_msg (const char *fmt, ...);
  1311. X
  1312. Xextern void get_ids ();                                /* newnews.c */
  1313. Xextern void process_id (char *msgid);
  1314. X
  1315. Xextern void set_ntime ();                            /* slurp.c */
  1316. X
  1317. Xextern int  tcp_open (char *host, char *service);    /* sockets.c */
  1318. Xextern int  server_init (char *hostname);
  1319. Xextern void close_server ();
  1320. Xextern void get_server (char *buf, int size);
  1321. Xextern void put_server (char *buf);
  1322. X
  1323. Xextern int  space (int min_free);                    /* space.c */
  1324. X
  1325. Xextern long server_time ();                            /* time.c */
  1326. X
  1327. X
  1328. X/* The inevitable... */
  1329. X
  1330. X#if !defined(TRUE) || ((TRUE) != 1)
  1331. X  #define TRUE (1)
  1332. X#endif
  1333. X
  1334. X#if !defined(FALSE) || ((FALSE) != 0)
  1335. X  #define FALSE (0)
  1336. X#endif
  1337. X
  1338. X#ifndef PATH_MAX
  1339. X  #define PATH_MAX 1024
  1340. X#endif
  1341. X
  1342. X/* END-OF-FILE */
  1343. END_OF_FILE
  1344.   if test 3522 -ne `wc -c <'slurp.h'`; then
  1345.     echo shar: \"'slurp.h'\" unpacked with wrong size!
  1346.   fi
  1347.   # end of 'slurp.h'
  1348. fi
  1349. if test -f 'slurp.sys' -a "${1}" != "-c" ; then 
  1350.   echo shar: Will not clobber existing file \"'slurp.sys'\"
  1351. else
  1352.   echo shar: Extracting \"'slurp.sys'\" \(1205 characters\)
  1353.   sed "s/^X//" >'slurp.sys' <<'END_OF_FILE'
  1354. X# slurp.sys - which newsgroups we wish to take from each NNTP server
  1355. X#
  1356. X# Format is
  1357. X#   hostname/sublist:groups/distributions:flags:username/password
  1358. X#
  1359. X# * Entries for a particular host can be continued on more than one
  1360. X#   line by using a '\' at the end of the line.
  1361. X# * There is no limit on the length of each line.
  1362. X# * Whitespace is only allowed in comments - nowhere else!
  1363. X# * Comments begin with a '#'.
  1364. X# * Distributions are *not* recommended if you want a reasonable
  1365. X#   throughput and don't want to increase the server load too much...
  1366. X# * Possible flags are
  1367. X#      i  don't load /save unretrieved messsage IDs
  1368. X#      l  use local time, not that at the server
  1369. X#      r  do a 'mode reader' command
  1370. X# * If username/password are supplied then they will be used with the
  1371. X#   NNTP simple authorisation protocol.
  1372. X#      
  1373. X
  1374. X# Demon feed
  1375. Xnews.demon.co.uk:demon*,!demon.msdos.announce,alt.fan.chicken.wrestling,\
  1376. Xuk.*,!uk.net.maps,rec.video.satellite,comp.unix.sys5.r4,\
  1377. Xrec.arts.tv.uk,ba.broadcast
  1378. X
  1379. X# Orbital feed #1
  1380. Xorbital.demon.co.uk/1:cix.*,alt.bbs.*,!alt.bbs.lists*
  1381. X
  1382. X# Orbital feed #2
  1383. Xorbital.demon.co.uk/2:rec.radio.*,alt.bbs,alt.bbs.internet,alt.irc,\
  1384. Xnews.software.*:il:newserv/lick21
  1385. X
  1386. X# END OF FILE
  1387. END_OF_FILE
  1388.   if test 1205 -ne `wc -c <'slurp.sys'`; then
  1389.     echo shar: \"'slurp.sys'\" unpacked with wrong size!
  1390.   fi
  1391.   # end of 'slurp.sys'
  1392. fi
  1393. if test -f 'sockets.c' -a "${1}" != "-c" ; then 
  1394.   echo shar: Will not clobber existing file \"'sockets.c'\"
  1395. else
  1396.   echo shar: Extracting \"'sockets.c'\" \(5905 characters\)
  1397.   sed "s/^X//" >'sockets.c' <<'END_OF_FILE'
  1398. X/*
  1399. X * sockets - open a socket connection and read/write to nntp server
  1400. X *
  1401. X * Copyright (C) 1992/93 Stephen Hebditch. All rights reserved.
  1402. X * TQM Communications, BCM Box 225, London, WC1N 3XX.
  1403. X * steveh@orbital.demon.co.uk  +44 836 825962
  1404. X *
  1405. X * See README for more information and disclaimers
  1406. X *
  1407. X * Obtain the current time from the remote server in standard unix time
  1408. X * format for use with the next NEWNEWS. If the client is unable to
  1409. X * connect to the time server, then local time is used instead.
  1410. X *
  1411. X * $Id: sockets.c,v 1.5 1993/03/01 18:00:18 root Exp $
  1412. X *
  1413. X * $Log: sockets.c,v $
  1414. X * Revision 1.5  1993/03/01  18:00:18  root
  1415. X * Use ferror to detect erros, not return code.
  1416. X *
  1417. X * Revision 1.4  1993/02/14  16:22:42  root
  1418. X * No longer have get_server return a return code. Makes this module
  1419. X * no longer compatible with nntp 1.6 client library, but there ya go...
  1420. X * Changed error detection in put_server for no other reason than to
  1421. X * be consistent with elsewhere.
  1422. X *
  1423. X * Revision 1.3  1992/12/15
  1424. X * Removed unnecessary close() in close_server.
  1425. X * Syslog log level for connected message changed to LOG_INFO.
  1426. X *
  1427. X * Revision 1.1  1992/12/04
  1428. X * Print line before it is sent to server when debugging is on.
  1429. X *
  1430. X * Revision 1.0  1992/11/29
  1431. X * Adapted from nntpxfer-e code.
  1432. X * Incorporate code to set up a tcp connection, plus cleaned up the
  1433. X * existing code.
  1434. X *
  1435. X */
  1436. X
  1437. X#include "slurp.h"
  1438. X
  1439. X#include <signal.h>
  1440. X#include <setjmp.h>
  1441. X#include <unistd.h>
  1442. X#include <netdb.h>
  1443. X#include <sys/socket.h>
  1444. X#include <netinet/in.h>
  1445. X#include <arpa/inet.h>
  1446. X
  1447. X#ifndef INADDR_NONE
  1448. X  #define INADDR_NONE 0xffffffff
  1449. X#endif
  1450. X
  1451. Xstruct sockaddr_in serv_addr;
  1452. Xstruct servent serv_info;
  1453. Xstruct hostent host_info;
  1454. X
  1455. Xstatic int server;
  1456. Xstatic FILE *server_rd_fp;
  1457. Xstatic FILE *server_wr_fp;
  1458. X
  1459. X
  1460. X/*
  1461. X * tcp_open - Open a tcp connection to 'host' for service 'service',
  1462. X * returning a file descriptor for the socket.
  1463. X */
  1464. X
  1465. X    int
  1466. Xtcp_open (char *host, char *service)
  1467. X    {
  1468. X    int sockfd, on;
  1469. X    unsigned long inaddr;
  1470. X    struct servent *sp;
  1471. X    struct hostent *hp;
  1472. X
  1473. X    bzero ((char *) &serv_addr, sizeof (serv_addr));
  1474. X    serv_addr.sin_family = AF_INET;
  1475. X
  1476. X    /* Get service information */
  1477. X    if ((sp = getservbyname (service, "tcp")) == NULL)
  1478. X        {
  1479. X        log_ret ("tcp_open: Unknown service %s/tcp", service);
  1480. X        return (-1);
  1481. X        }
  1482. X    serv_info = *sp;
  1483. X    serv_addr.sin_port = sp->s_port;
  1484. X
  1485. X    /* Try to convert host name as dotted decimal */
  1486. X    if ((inaddr = inet_addr (host)) != INADDR_NONE)
  1487. X        {
  1488. X        bcopy ((char *) &inaddr, (char *) &serv_addr.sin_addr,
  1489. X               sizeof (inaddr));
  1490. X        host_info.h_name = NULL;
  1491. X        }
  1492. X    /* If that failed, then look up the host name */
  1493. X    else
  1494. X        {
  1495. X        if ((hp = gethostbyname (host)) == NULL)
  1496. X            {
  1497. X            log_ret ("tcp_open: Host name error: %s", host);
  1498. X            return (-1);
  1499. X            }
  1500. X        host_info = *hp;
  1501. X        bcopy (hp->h_addr, (char *) &serv_addr.sin_addr, hp->h_length);
  1502. X        }
  1503. X
  1504. X    if ((sockfd = socket (AF_INET, SOCK_STREAM, 0)) < 0)
  1505. X        {
  1506. X        log_ret ("tcp_open: Can't create TCP socket");
  1507. X        return (-1);
  1508. X        }
  1509. X
  1510. X    if (connect (sockfd, (struct sockaddr *) &serv_addr,
  1511. X        sizeof (serv_addr)) < 0)
  1512. X        {
  1513. X        log_ret ("tcp_open: Can't connect to server %s", host);
  1514. X        (void) close (sockfd);
  1515. X        return (-1);
  1516. X        }
  1517. X
  1518. X    on = 1;
  1519. X    if (setsockopt (sockfd, SOL_SOCKET, SO_KEEPALIVE, 
  1520. X                    (char *) &on, sizeof (on)) < 0)
  1521. X        log_ret ("tcp_open: Can't set KEEPALIVE on socket");
  1522. X
  1523. X    return (sockfd);
  1524. X    }
  1525. X
  1526. X/*
  1527. X * server_init - Open a connection to the NNTP server. Returns -1 if an
  1528. X * error occurs, otherwise the server's initial response code.
  1529. X */
  1530. X
  1531. X    int
  1532. Xserver_init (char *hostname)
  1533. X    {
  1534. X    char line [NNTP_STRLEN];
  1535. X
  1536. X    /* First try and make the connection */
  1537. X    if ((server = tcp_open (hostname,"nntp")) < 0)
  1538. X        return (-1);
  1539. X
  1540. X    /* Now fdopen to enable buffering of incoming data */
  1541. X    if ((server_rd_fp = fdopen (server, "r")) == NULL)
  1542. X        {
  1543. X        log_ret ("server_init: Can't fdopen socket for reading");
  1544. X        return (-1);
  1545. X        }
  1546. X    if ((server_wr_fp = fdopen (server, "w")) == NULL)
  1547. X        {
  1548. X        log_ret ("server_init: Can't fdopen socket for writing");
  1549. X        return (-1);
  1550. X        }
  1551. X
  1552. X    /* Inform everyone that we're there */
  1553. X#ifdef SYSLOG
  1554. X    if (!debug_flag)
  1555. X        syslog(LOG_INFO, "Connected to nntp server at %s", hostname);
  1556. X    else
  1557. X#endif
  1558. X        (void) fprintf (stderr, "Connected to nntp server at %s\n", hostname);
  1559. X
  1560. X    /* Get the greeting herald */
  1561. X    get_server (line, sizeof (line));
  1562. X    if (debug_flag)
  1563. X        (void) fprintf (stderr, "-> %s\n", line);
  1564. X
  1565. X    /* Return the banner code */
  1566. X    return (atoi (line));
  1567. X    }
  1568. X
  1569. X
  1570. X/*
  1571. X * close_server - Close down the NNTP server connection
  1572. X */
  1573. X
  1574. X    void
  1575. Xclose_server ()
  1576. X    {
  1577. X    char line [NNTP_STRLEN];
  1578. X
  1579. X    if (debug_flag)
  1580. X        (void) fprintf (stderr, "<- QUIT\n");
  1581. X    put_server ("QUIT");
  1582. X    get_server (line, sizeof (line));
  1583. X    if (debug_flag)
  1584. X        (void) fprintf (stderr, "-> %s\n", line);
  1585. X
  1586. X    (void) fclose (server_rd_fp);
  1587. X    (void) fclose (server_wr_fp);
  1588. X    }
  1589. X
  1590. X
  1591. Xstatic jmp_buf env_alrm;
  1592. X
  1593. X    static void
  1594. Xsig_alrm (int signo)
  1595. X    {
  1596. X    longjmp (env_alrm, 1);
  1597. X    }
  1598. X
  1599. X/*
  1600. X * get_server - Read a line up to CRLF from the socket into a buffer.
  1601. X */
  1602. X
  1603. X    void
  1604. Xget_server (char *line, int size)
  1605. X    {
  1606. X    int esave;
  1607. X    char *pos;
  1608. X
  1609. X    /* Set up an alarm to handle socket timeout */
  1610. X    if (setjmp (env_alrm))
  1611. X        {
  1612. X        (void) alarm (0);                    /* Reset alarm clock */
  1613. X        (void) signal (SIGALRM, SIG_DFL);
  1614. X        errno = EPIPE;
  1615. X        log_sys ("get_server: Read error on server socket");
  1616. X        }
  1617. X
  1618. X    (void) signal (SIGALRM, sig_alrm);
  1619. X    (void) alarm (TIMEOUT);
  1620. X
  1621. X    /* Read line */
  1622. X    (void) fgets (line, size, server_rd_fp);
  1623. X
  1624. X    /* Reset the alarm */
  1625. X    esave = errno;
  1626. X    (void) alarm (0);
  1627. X    (void) signal (SIGALRM, SIG_DFL);
  1628. X    errno = esave;
  1629. X
  1630. X    /* Report any error */
  1631. X    if (ferror (server_rd_fp))
  1632. X        log_sys ("get_server: Read error on server socket");
  1633. X
  1634. X    /* Kill the CRLF */
  1635. X    if (pos = strchr (line, '\r'))
  1636. X        *pos = '\0';
  1637. X    if (pos = strchr (line, '\n'))
  1638. X        *pos = '\0';
  1639. X    }
  1640. X
  1641. X/*
  1642. X * put_server - write a line from a linefer to a socket
  1643. X */
  1644. X
  1645. X    void
  1646. Xput_server (char *line)
  1647. X    {
  1648. X
  1649. X    (void) fprintf (server_wr_fp, "%s\r\n", line);
  1650. X    if (ferror (server_wr_fp))
  1651. X        log_sys ("put_server: Write error on server socket");
  1652. X    (void) fflush (server_wr_fp);
  1653. X    }
  1654. X
  1655. X/* END-OF-FILE */
  1656. END_OF_FILE
  1657.   if test 5905 -ne `wc -c <'sockets.c'`; then
  1658.     echo shar: \"'sockets.c'\" unpacked with wrong size!
  1659.   fi
  1660.   # end of 'sockets.c'
  1661. fi
  1662. if test -f 'space.c' -a "${1}" != "-c" ; then 
  1663.   echo shar: Will not clobber existing file \"'space.c'\"
  1664. else
  1665.   echo shar: Extracting \"'space.c'\" \(5227 characters\)
  1666.   sed "s/^X//" >'space.c' <<'END_OF_FILE'
  1667. X/*
  1668. X * space - determine free space on a filesystem
  1669. X *
  1670. X * Copyright (C) 1992/93 Stephen Hebditch and others.
  1671. X * TQM Communications, BCM Box 225, London, WC1N 3XX.
  1672. X * steveh@orbital.demon.co.uk  +44 836 825962
  1673. X *
  1674. X * See README for more information and disclaimers
  1675. X *
  1676. X * This routine determines if there is enough space on the filesystem
  1677. X * holding the news spool for a new batch of incoming articles.
  1678. X * It is based on space.c in the NNTP reference implementation which
  1679. X * credits Stan Barber <sob@bcm.tmc.edu>, Tad Guy <tadguy@cs.odu.edu>,
  1680. X * Chris Jepeway <jepeway@utkcs2.cs.utk.edu> and Tom Lane <tgl@cs.cmu.edu>
  1681. X * but has been heavily cleaned up and support for SVR4, Linux and
  1682. X * BSDI added.
  1683. X *
  1684. X * $Id: space.c,v 1.5 1993/03/01 18:08:20 root Exp $
  1685. X *
  1686. X * $Log: space.c,v $
  1687. X * Revision 1.5  1993/03/01  18:08:20  root
  1688. X * Completely reworked from the original and heavily tidied up.
  1689. X * Support added for SVR4 and Linux.
  1690. X *
  1691. X * Revision 1.4  1993/02/14  16:12:20  root
  1692. X * Added support for BSDI.
  1693. X *
  1694. X */
  1695. X
  1696. X#include "slurp.h"
  1697. X
  1698. X#ifdef MINFREE
  1699. X
  1700. X#include <sys/types.h>
  1701. X#include <sys/stat.h>
  1702. X
  1703. X#define DFREE_OK        0
  1704. X#define DFREE_INODES    1
  1705. X#define DFREE_BLOCKS    2
  1706. X#define DFREE_ERR        3
  1707. X
  1708. X/*
  1709. X * Definitions for use with dfree() for various UNIX families.
  1710. X *
  1711. X * statfilesys        Routine to call when trying to stat a file system
  1712. X *                    to get the number of free blocks available.
  1713. X * statfs_type        The data type into which statfs() wants to return
  1714. X *                    useful information.
  1715. X * bombed            Boolean expression returning 1 if a call to statfs()
  1716. X *                    fails.
  1717. X * blkavail            Given a statfs_type called fs, return number of free
  1718. X *                    blocks available to a non-superuser.
  1719. X * filavail            Given a statfs_type called fs, return number of free
  1720. X *                    inodes available to a non-superuser.
  1721. X */
  1722. X
  1723. X  #if defined(SVR4)
  1724. X    #include <sys/statvfs.h>
  1725. X    #define statfilesys        statvfs
  1726. X    typedef struct statvfs     statfs_type;
  1727. X    #define bombed(call)    ((call) == -1)
  1728. X    #define blkavail(fs)    ((fs).f_bavail)
  1729. X    #define filavail(fs)    ((fs).f_favail)
  1730. X
  1731. X  #elif defined(sun) || defined(hpux) || defined(pyr) || defined(hp300) || defined(NeXT) || defined(linux)
  1732. X    #include <sys/vfs.h>
  1733. X    #define statfilesys        statfs
  1734. X    typedef struct statfs     statfs_type;
  1735. X    #define bombed(call)    ((call) == -1)
  1736. X    #define blkavail(fs)    ((fs).f_bavail)
  1737. X    #define filavail(fs)    ((fs).f_ffree)
  1738. X
  1739. X  #elif defined(apollo)
  1740. X    #include <sys/types.h>
  1741. X    #include <sys/statfs.h>
  1742. X    #define statfilesys(a,b) statfs (a, b, sizeof (struct statfs), 0)
  1743. X    typedef struct statfs     statfs_type;
  1744. X    #define bombed(call)    ((call) == -1)
  1745. X    #define blkavail(fs)    ((fs).f_bfree)
  1746. X    #define filavail(fs)    ((fs).f_ffree)
  1747. X
  1748. X  #elif defined(ultrix)
  1749. X    #include <sys/mount.h>
  1750. X    typedef struct fs_data    statfs_type;
  1751. X    #define statfilesys        statfs
  1752. X    #define bombed(call)    ((call) <= 0)
  1753. X    #define blkavail(fs)    ((int)((fs).fd_req.bfreen))
  1754. X    #define filavail(fs)    ((int)((fs).fd_req.gfree))
  1755. X
  1756. X  #elif defined(__bsdi__)
  1757. X    #include <sys/mount.h>
  1758. X    typedef struct statfs    statfs_type;
  1759. X    #define statfilesys        statfs
  1760. X    #define bombed(call)    ((call) < 0)
  1761. X    #define blkavail(fs)    ((int)((fs).f_bfree))
  1762. X    #define filavail(fs)    ((int)((fs).f_ffree))
  1763. X
  1764. X  #elif defined(SVR3)
  1765. X    #include <ustat.h>
  1766. X    typedef struct ustat statfs_type;
  1767. X        int
  1768. X    statfilesys (char *dir, statfs_type *fs)
  1769. X        {
  1770. X        struct stat file;
  1771. X        if (stat (dir, &file))
  1772. X            return (-1);
  1773. X        if (ustat (file.st_dev, fs))
  1774. X            return (-2);
  1775. X        return (0);
  1776. X        }
  1777. X    #define bombed(call)    (call != 0)
  1778. X    #define blkavail(fs)    ((fs).f_tfree)
  1779. X    #define filavail(fs)    ((fs).f_tinode)    
  1780. X
  1781. X  #elif defined(CMU_MACH)
  1782. X    #include <sys/ioctl.h>
  1783. X    typedef struct fsparam statfs_type;
  1784. X        int
  1785. X    statfilesys (char *dir, statfs_type *fs)
  1786. X        {
  1787. X        int fd;
  1788. X        fd = open (dir, O_RDONLY);
  1789. X        if (fd < 0)
  1790. X            return (-1);
  1791. X        if (ioctl (fd, FIOCFSPARAM, fs) < 0)
  1792. X            {
  1793. X            close (fd);
  1794. X            return(-2);
  1795. X            }
  1796. X        close (fd);
  1797. X        return (0);
  1798. X        }
  1799. X    #define bombed (call)    ((call) < 0)
  1800. X    #define blkavail (fs)    ((fs).fsp_free-((fs).fsp_size*(fs).fsp_minfree+99)/100)
  1801. X
  1802. X  #else
  1803. X    SPACE DEFINITIONS NOT AVAILABLE FOR THIS MACHINE OR NOT SET CORRECTLY
  1804. X  #endif
  1805. X
  1806. X
  1807. X/*
  1808. X * dfree - Return the free space available on the file system containing
  1809. X * the specified directory. Space is measured in kilobytes. A negative
  1810. X * value is returned if there is an error.
  1811. X */
  1812. X
  1813. X    static int
  1814. Xdfree (char *location, int free_space)
  1815. X    {
  1816. X    statfs_type fsys;
  1817. X
  1818. X    /* Return error if can't get file system info */
  1819. X    if (bombed (statfilesys (location, &fsys)))
  1820. X        return (DFREE_ERR);
  1821. X
  1822. X    /* If able to test if free inodes then do so */
  1823. X#if defined(filfree) && defined(MINFILES)
  1824. X    if (filfree (fsys) < MINFILES )
  1825. X         return (DFREE_INODES);
  1826. X#endif
  1827. X
  1828. X    /* Test if blocks are available */
  1829. X    if (blkavail (fsys) < free_space)
  1830. X        return (DFREE_BLOCKS);
  1831. X
  1832. X    return (DFREE_OK);
  1833. X    }
  1834. X
  1835. X
  1836. X/*
  1837. X * space - Returns 1 if there are a sufficient number of free blocks
  1838. X * and inodes on the filesystem containing the news spool, or 0 if
  1839. X * there are only a small number of blocks / inodes remaining.
  1840. X */
  1841. X
  1842. X    int
  1843. Xspace (int min_free)
  1844. X    {
  1845. X    switch (dfree (SPOOLDIR, min_free))
  1846. X        {
  1847. X        case DFREE_OK:
  1848. X            return (1);
  1849. X        case DFREE_ERR:
  1850. X            log_ret ("dfree failed due to system call error");
  1851. X            break;
  1852. X        case DFREE_INODES:
  1853. X            log_msg ("no inodes on %s", SPOOLDIR);
  1854. X            break;
  1855. X        case DFREE_BLOCKS:
  1856. X            log_msg ("no space on %s", SPOOLDIR);
  1857. X            break;
  1858. X        }
  1859. X    return (0);
  1860. X    }
  1861. X
  1862. X#endif /* MINFREE */
  1863. X
  1864. X/* END-OF-FILE */
  1865. END_OF_FILE
  1866.   if test 5227 -ne `wc -c <'space.c'`; then
  1867.     echo shar: \"'space.c'\" unpacked with wrong size!
  1868.   fi
  1869.   # end of 'space.c'
  1870. fi
  1871. if test -f 'time.c' -a "${1}" != "-c" ; then 
  1872.   echo shar: Will not clobber existing file \"'time.c'\"
  1873. else
  1874.   echo shar: Extracting \"'time.c'\" \(1582 characters\)
  1875.   sed "s/^X//" >'time.c' <<'END_OF_FILE'
  1876. X/*
  1877. X * time - obtain the time from the remote server
  1878. X *
  1879. X * Copyright (C) 1992/93 Stephen Hebditch. All rights reserved.
  1880. X * TQM Communications, BCM Box 225, London, WC1N 3XX.
  1881. X * steveh@orbital.demon.co.uk  +44 836 825962
  1882. X *
  1883. X * See README for more information and disclaimers
  1884. X *
  1885. X * Obtain the current time from the remote server in standard unix time
  1886. X * format for use with the next NEWNEWS. If the client is unable to
  1887. X * connect to the time server or the read fails then the error is
  1888. X * reported and the program is exited.
  1889. X *
  1890. X * $Id: time.c,v 1.5 1993/03/01 18:09:12 root Exp $
  1891. X *
  1892. X * $Log: time.c,v $
  1893. X * Revision 1.5  1993/03/01  18:09:12  root
  1894. X * Made the epoch constant an unsigned long.
  1895. X *
  1896. X * Revision 1.4  1993/02/14  15:10:01  root
  1897. X * No changes.
  1898. X *
  1899. X * Revision 1.0  1992/08/92
  1900. X * Initial coding.
  1901. X *
  1902. X */
  1903. X
  1904. X#include "slurp.h"
  1905. X
  1906. X#include <unistd.h>
  1907. X#include <netinet/in.h>
  1908. X
  1909. X
  1910. X    time_t
  1911. Xserver_time (char *hostname)
  1912. X    {
  1913. X    int server, ret;
  1914. X    u_long timebuf;
  1915. X
  1916. X/* First open the socket */
  1917. X
  1918. X    if ((server = tcp_open (hostname, "time")) < 0)
  1919. X        return ((time_t) 0);
  1920. X
  1921. X    ret = read (server, &timebuf, 4);
  1922. X
  1923. X/* Close the socket and check we got 4 bytes */
  1924. X
  1925. X    (void) close (server);
  1926. X
  1927. X    if (ret != 4)
  1928. X        {
  1929. X        log_ret ("server_time: Read error on time server socket");
  1930. X        return ((time_t) 0);
  1931. X        }
  1932. X
  1933. X/* Convert byte order if needed */
  1934. X
  1935. X    timebuf = ntohl (timebuf);
  1936. X
  1937. X    if (debug_flag)
  1938. X        (void) fprintf (stderr, "time is currently %ld at server %s\n",
  1939. X                        timebuf, hostname);
  1940. X
  1941. X/* Convert the time from seconds since 1900 to seconds since 1970 */
  1942. X
  1943. X    return ((time_t) (timebuf - 2208988800UL));
  1944. X    }
  1945. X
  1946. X/* END-OF-FILE */
  1947. END_OF_FILE
  1948.   if test 1582 -ne `wc -c <'time.c'`; then
  1949.     echo shar: \"'time.c'\" unpacked with wrong size!
  1950.   fi
  1951.   # end of 'time.c'
  1952. fi
  1953. echo shar: End of archive 2 \(of 2\).
  1954. cp /dev/null ark2isdone
  1955. MISSING=""
  1956. for I in 1 2 ; do
  1957.     if test ! -f ark${I}isdone ; then
  1958.     MISSING="${MISSING} ${I}"
  1959.     fi
  1960. done
  1961. if test "${MISSING}" = "" ; then
  1962.     echo You have unpacked both archives.
  1963.     rm -f ark[1-9]isdone
  1964. else
  1965.     echo You still must unpack the following archives:
  1966.     echo "        " ${MISSING}
  1967. fi
  1968. exit 0
  1969. exit 0 # Just in case...
  1970.