Thread View: de.comp.sources.os9
1 messages
1 total messages
Started by Frank Kaefer
Wed, 23 Dec 1992 19:41
MNews Prerelease Part05/09
Author: Frank Kaefer
Date: Wed, 23 Dec 1992 19:41
Date: Wed, 23 Dec 1992 19:41
2007 lines
47510 bytes
47510 bytes
Submitted-by: Ulrich Dessauer <ud@Nightmare.ddt.sub.org>
Archive-name: mnews/part05
: ----- Cut here ----- Cut here ----- Cut here ----- Cut here -----
: Use sh filename to extract shell archive
: This shell archive contains following files:
: 'INEWS/psys.c 882 bytes'
: 'INEWS/ract.c 2810 bytes'
: 'INEWS/retr.c 981 bytes'
: 'INEWS/rhead.c 4336 bytes'
: 'INEWS/rsat.c 1309 bytes'
: 'INEWS/rsys.c 5149 bytes'
: 'INEWS/sect.c 4541 bytes'
: 'INEWS/shead.c 1409 bytes'
: 'INEWS/sinfo.c 4889 bytes'
: 'INEWS/sit.c 1351 bytes'
: 'INEWS/spch.c 4632 bytes'
: 'INEWS/store.c 3458 bytes'
: 'INEWS/tsys.c 3084 bytes'
:
if test -f 'INEWS/psys.c' ; then
echo 'File INEWS/psys.c already exists, overwriting it'
del 'INEWS/psys.c'
fi
echo Extracting \"'INEWS/psys.c'\"
sed "s/^X//" >'INEWS/psys.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log: psys.c_v $
X * Revision 1.1 90/08/31 15:35:09 cs
X * Initial revision
X *
X */
X# ifndef LINT
Xstatic char rcsid[] = "$Id: psys.c_v 1.1 90/08/31 15:35:09 cs Exp $";
X# endif LINT
X# include "inews.h"
X
Xint
Xprocess_sys ()
X{
X register sys *stmp, *la;
X
X if (block_forward)
X do_log ("Article blocked to be forwarded\n");
X stmp = hsys;
X while (stmp) {
X if (stmp->fwd) {
X switch (stmp->cmd ? stmp->cmd[0] : '\0') {
X case '-':
X case '\0':
X if (! block_forward)
X write_it (stmp);
X break;
X case '+':
X save_it (stmp);
X break;
X default:
X pipe_it (stmp->cmd);
X break;
X }
X for (la = stmp->next; la; la = la->next)
X if (la->fwd && (! strcmp (stmp->site, la->site)))
X if (((! stmp->cmd) && (! stmp->cmd)) || (stmp->cmd && la->cmd && (! strcmp (stmp->cmd, la->cmd))))
X la->fwd = FALSE;
X }
X stmp = stmp->next;
X }
X return (0);
X}
__END__OF__THIS__FILE__
if test -f 'INEWS/ract.c' ; then
echo 'File INEWS/ract.c already exists, overwriting it'
del 'INEWS/ract.c'
fi
echo Extracting \"'INEWS/ract.c'\"
sed "s/^X//" >'INEWS/ract.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log: ract.c_v $
X * Revision 1.2 91/12/06 14:46:55 ud
X * Changed format of active file to be compatible to BNews/CNews
X *
X * Revision 1.1 90/08/31 15:35:12 cs
X * Initial revision
X *
X */
X# ifndef LINT
Xstatic char rcsid[] = "$Id: ract.c_v 1.2 91/12/06 14:46:55 ud Exp $";
X# endif LINT
X# include <c8type.h>
X# include <modes.h>
X# include "inews.h"
X
Xextern char *malloc ();
Xextern char *strdup ();
X
Xint
Xread_active ()
X{
X register char *ptr;
X register int t;
X register active *act, *tmp;
X register int fd;
X int n;
X char *buf, *sav;
X char **arg;
X int pos;
X
X hact = NULL;
X# ifdef HASH_SEARCH
X if (! (hashact = (active **) malloc ((HASH_ACTIVE + 2) * sizeof (active *)))) {
X do_log ("Can't alloc for active hashtable\n");
X return (-1);
X }
X memset (hashact, '\0', HASH_ACTIVE * sizeof (active *));
X# endif /* HASH_SEARCH */
X act = NULL;
X if ((fd = open (ACTIVE_FILE, S_IREAD)) < 0) {
X do_log ("Can't open %s\n", ACTIVE_FILE);
X return (-1);
X }
X pos = 0;
X catlines = TRUE;
X while (buf = readbuf (fd, & n)) {
X buf[n-1] = '\0';
X if ((n == 1) || (buf[0] == '#')) {
X pos += n;
X continue;
X }
X if (!(tmp = (active *) malloc (sizeof (active)))) {
X close (fd);
X do_log ("Can't alloc memory in read_active()\n");
X return (-1);
X }
X sav = buf;
X ptr = skipc (sav, '\0');
X tmp->changed = FALSE;
X tmp->pos = pos + strlen (sav) + 1;
X pos += n;
X if (!(tmp->grp = strdup (sav))) {
X close (fd);
X do_log ("Can't alloc memory in read_active()\n");
X return (-1);
X }
X sav = ptr;
X ptr = skipc (sav, '\0');
X tmp->high = atoi (sav);
X sav = ptr;
X ptr = skipc (sav, '\0');
X tmp->low = atoi (sav);
X sav = ptr;
X ptr = skipc (sav, '\0');
X tmp->aflag[0] = sav[0];
X tmp->aflag[1] = (sav[0] && sav[1]) ? sav[1] : M_USE;
X
X if (is8digit (*ptr)) {
X sav = ptr;
X ptr = skipc (sav, '\0');
X tmp -> kblimit = atoi (sav);
X } else
X tmp -> kblimit = -1;
X
X if (tmp->aflag[0] == M_MOD) {
X if ((n = getargs (ptr, &arg)) >= 0) {
X if (tmp->moderator = (char **) malloc (sizeof (char *) * (n + 2))) {
X for (t=0;t<n;++t)
X if (!(tmp->moderator[t] = strdup (arg[t]))) {
X close (fd);
X do_log ("Can't alloc memory in read_active()\n");
X return (-1);
X }
X tmp->moderator[t] = NULL;
X } else {
X close (fd);
X do_log ("Can't alloc memory in read_active()\n");
X return (-1);
X }
X free ((char *) arg);
X } else {
X close (fd);
X do_log ("Can't alloc memory in read_active()\n");
X return (-1);
X }
X } else
X tmp->moderator = NULL;
X# ifdef HASH_SEARCH
X tmp -> id = calc_hash (tmp -> grp, TRUE);
X t = tmp -> id % HASH_ACTIVE;
X tmp -> hnext = hashact[t];
X hashact[t] = tmp;
X# endif /* HASH_SEARCH */
X tmp->next = NULL;
X if (!act)
X hact = tmp;
X else
X act->next = tmp;
X act = tmp;
X }
X catlines = FALSE;
X close (fd);
X return (0);
X}
__END__OF__THIS__FILE__
if test -f 'INEWS/retr.c' ; then
echo 'File INEWS/retr.c already exists, overwriting it'
del 'INEWS/retr.c'
fi
echo Extracting \"'INEWS/retr.c'\"
sed "s/^X//" >'INEWS/retr.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log: retr.c_v $
X * Revision 1.1 91/02/03 15:34:13 ud
X * Initial revision
X *
X */
X# ifndef LINT
Xstatic char rcsid[] = "$Id: retr.c_v 1.1 91/02/03 15:34:13 ud Exp $";
X# endif LINT
X# include <time.h>
X# include "inews.h"
X
Xextern char *index ();
X
Xvoid
Xretreive_message_id (msgid)
Xcharc *msgid;
X{
X charc *cur, *tmp;
X char *fn, *ptr;
X time_t tim;
X struct tm *tt;
X
X if (do_init (FALSE) < 0)
X exit (_errmsg (1, "Can't setup system.\n"));
X tmp = msgid;
X while (tmp) {
X if (fn = exists_message_id (tmp->text, &tim)) {
X if (ptr = index (fn, ' '))
X *ptr = '\0';
X printf ("+%s\t%s/%s\t%ld", tmp->text, newsdir, fn, tim);
X if (tt = gmtime (&tim))
X printf ("\t%04d/%02d/%02d %02d:%02d\n",
X tt->tm_year + 1900,
X tt->tm_mon + 1,
X tt->tm_mday,
X tt->tm_hour,
X tt->tm_min);
X else
X printf ("\t0000/00/00 00:00\n");
X free (fn);
X } else
X printf ("-%s\n", tmp->text);
X cur = tmp->next;
X free (tmp->text);
X free ((char *) tmp);
X tmp = cur;
X }
X}
__END__OF__THIS__FILE__
if test -f 'INEWS/rhead.c' ; then
echo 'File INEWS/rhead.c already exists, overwriting it'
del 'INEWS/rhead.c'
fi
echo Extracting \"'INEWS/rhead.c'\"
sed "s/^X//" >'INEWS/rhead.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log: rhead.c_v $
X * Revision 1.3 91/09/11 18:13:43 ud
X * Moved del_obsolete_header to wgrp.c
X *
X * Revision 1.2 91/05/22 13:05:15 ud
X * - Added 8 bit support
X * - Added in memory features
X * - Added Supersedes: header
X *
X * Revision 1.1 90/08/31 15:35:17 cs
X * Initial revision
X *
X */
X# ifndef LINT
Xstatic char rcsid[] = "$Id: rhead.c_v 1.3 91/09/11 18:13:43 ud Exp $";
X# endif LINT
X# include <c8type.h>
X# include <time.h>
X# include <modes.h>
X# include "inews.h"
X
Xextern char *index ();
Xextern char *malloc ();
Xextern char *rindex ();
Xextern char *strdup ();
X
Xint
Xread_in_body (fd, fill, firstline, readon)
Xregister int fd;
Xregister char *fill;
Xchar *firstline;
Xint readon;
X{
X int fillen;
X register char *buf;
X int n;
X register int fdo;
X
X if (fill)
X fillen = strlen (fill);
X lines = 0;
X
X# ifndef IN_MEMORY
X if ((fdo = create (newstmp, S_IWRITE, 03)) < 0) {
X do_log ("Can't create %s\n", newstmp);
X return (-1);
X }
X# endif /* IN_MEMORY */
X
X if (readon) {
X if (firstline && *firstline) {
X# ifndef IN_MEMORY
X write (fdo, firstline, strlen (firstline));
X# else /* IN_MEMORY */
X add_list (&newstmp, firstline, strlen (firstline));
X# endif /* IN_MEMORY */
X ++lines;
X artsize += strlen (firstline);
X }
X conv_it = TRUE;
X while (buf = readbuf (fd, & n)) {
X ++lines;
X artsize += n + 1;
X# ifndef IN_MEMORY
X if (fill)
X write (fdo, fill, fillen);
X write (fdo, buf, n);
X# else /* IN_MEMORY */
X if (fill)
X add_list (&newstmp, fill, fillen);
X add_list (&newstmp, buf, n);
X# endif /* IN_MEMORY */
X }
X conv_it = FALSE;
X }
X# ifndef IN_MEMORY
X close (fdo);
X# endif /* IN_MEMORY */
X return (0);
X}
X
Xint
Xread_in_header (fd, fill, read_body)
Xint fd;
Xchar *fill;
Xint read_body;
X{
X register int t;
X charc *act;
X register charc *tmp;
X register char *buf;
X register char *ptr;
X int n;
X
X head = NULL;
X act = NULL;
X conv_it = TRUE;
X while (buf = readbuf (fd, & n)) {
X if (n == 1)
X break;
X buf[n - 1] = '\0';
X if (is8space (buf[0]) && act) {
X if (ptr = malloc (strlen (act->text) + strlen (buf) + 6)) {
X strcpy (ptr, act->text);
X# ifdef CAT_LINES
X strcat (ptr, " ");
X p = buf;
X while (is8space (*p))
X ++p;
X strcat (ptr, p);
X# else CAT_LINES
X strcat (ptr, "\n");
X strcat (ptr, buf);
X# endif CAT_LINES
X free (act->text);
X act->text = ptr;
X }
X continue;
X }
X if (!fill) {
X for (t=0;hlines[t];++t)
X if (Strnieql (buf, hlines[t] + 2, strlen (hlines[t] + 2)))
X break;
X ptr= skip_field (buf);
X if ((!ptr) || (!*ptr))
X continue;
X }
X if (!(tmp = (charc *) malloc (sizeof (charc)))) {
X do_log ("Can't alloc in read_header\n");
X return (-1);
X }
X if (!(tmp->text = strdup (buf))) {
X do_log ("Can't alloc in read_header\n");
X return (-1);
X }
X tmp->next = NULL;
X if (!head)
X head = tmp;
X else
X act->next = tmp;
X act = tmp;
X }
X conv_it = FALSE;
X if (fill) {
X handle_special (S_SUBJECT);
X handle_special (S_REFERENCES);
X handle_special (S_FOLLOWUP_TO);
X handle_special (S_TO);
X if (buf = malloc (512)) {
X if (tmp = get_header_line (H_MESSAGE_ID)) {
X ptr = skip_field (tmp->text);
X strcpy (buf, "In ");
X strcat (buf, ptr);
X strcat (buf, ", ");
X } else
X strcpy (buf, "");
X if (ptr = find_from (FALSE))
X strcat (buf, ptr);
X else
X strcat (buf, "Someone");
X strcat (buf, " wrote:\n");
X }
X delete_header (H_MESSAGE_ID);
X clear_msgid ();
X } else
X buf = NULL;
X
X for (tmp = head; tmp; tmp = tmp -> next)
X artsize += strlen (tmp -> text);
X
X if (read_body)
X if (read_in_body (fd, fill, buf, n > 0) < 0) {
X close (fd);
X return (-1);
X }
X if (buf)
X free (buf);
X close (fd);
X return (0);
X}
X
Xint
Xread_header (fd)
Xint fd;
X{
X char *tmp;
X
X if (read_in_header (fd, NULL, TRUE) < 0)
X return (-1);
X if (crthd) {
X delete_header (H_PATH);
X delete_header (H_SENDER);
X delete_header (H_APPROVED);
X create_header (TRUE, FALSE);
X }
X handle_special (S_NEWSGROUPS);
X handle_special (S_DISTRIBUTION);
X handle_special (S_SUPERSEDES);
X if (crthd && ngs && (!get_header_line (H_FOLLOWUP_TO)))
X if (tmp = find_followup_to (ngs)) {
X insert_header (H_FOLLOWUP_TO, tmp, FALSE);
X free (tmp);
X }
X test_systems ();
X handle_special (S_PATH);
X handle_special (S_MESSAGE_ID);
X if (sort_header (TRUE) < 0) {
X do_log ("Failed in sort_header()\n");
X return (-1);
X }
X check_approved ();
X check_control ();
X return (0);
X}
__END__OF__THIS__FILE__
if test -f 'INEWS/rsat.c' ; then
echo 'File INEWS/rsat.c already exists, overwriting it'
del 'INEWS/rsat.c'
fi
echo Extracting \"'INEWS/rsat.c'\"
sed "s/^X//" >'INEWS/rsat.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log: rsat.c_v $
X * Revision 1.1 90/08/31 15:36:00 cs
X * Initial revision
X *
X */
X# ifndef LINT
Xstatic char rcsid[] = "$Id: rsat.c_v 1.1 90/08/31 15:36:00 cs Exp $";
X# endif LINT
X# include <modes.h>
X# include "inews.h"
X
Xextern int os9forkc ();
X
Xextern char **environ;
X
Xvoid
Xdo_send_article (fdi, is_ctrl)
Xint fdi;
Xint is_ctrl;
X{
X char buf[256];
X char fn[64 + sizeof (TEMPDIR)];
X char *arg[6];
X int old0;
X int pid, st;
X int n;
X charc *tmp;
X int fd;
X
X sprintf (fn, "%s/inewscXXXXXX", TEMPDIR);
X mktemp (fn);
X if ((fd = create (fn, S_IREAD | S_IWRITE, 03)) < 0) {
X do_log ("Can't create tempfile, aborted\n");
X return;
X }
X tmp = head;
X while (tmp) {
X write (fd, tmp->text, strlen (tmp->text));
X write (fd, "\n", 1);
X tmp = tmp->next;
X }
X write (fd, "\n", 1);
X while ((n = readln (fdi, buf, 250)) > 0)
X write (fd, buf, n);
X old0 = dup (0);
X close (0);
X lseek (fd, 0 ,0);
X dup (fd);
X close (fd);
X n = 0;
X arg[n++] = "inews";
X if (is_ctrl)
X arg[n++] = "-a";
X if (verbose)
X arg[n++] = "-v";
X arg[n] = NULL;
X pid = os9exec (os9forkc, arg[0], arg, environ, 0, 0, 3);
X close (0);
X dup (old0);
X close (old0);
X if (pid < 0) {
X do_log ("Can't fork inews\n");
X unlink (fn);
X return;
X }
X while (((n = wait (&st)) != pid) && (n != -1))
X ;
X unlink (fn);
X if (st)
X do_log ("`inews' returns %d\n", st);
X}
__END__OF__THIS__FILE__
if test -f 'INEWS/rsys.c' ; then
echo 'File INEWS/rsys.c already exists, overwriting it'
del 'INEWS/rsys.c'
fi
echo Extracting \"'INEWS/rsys.c'\"
sed "s/^X//" >'INEWS/rsys.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log: rsys.c_v $
X * Revision 1.3 91/12/26 13:40:07 ud
X * Added sizelimit in activefile
X *
X * Revision 1.2 91/05/22 13:19:11 ud
X * Allows now to include other sys file style files; so you can keep
X * a seperate sys file for each site
X *
X * Revision 1.1 90/08/31 15:36:03 cs
X * Initial revision
X *
X */
X# ifndef LINT
Xstatic char rcsid[] = "$Id: rsys.c_v 1.3 91/12/26 13:40:07 ud Exp $";
X# endif LINT
X# include <c8type.h>
X# include <modes.h>
X# include "inews.h"
X
X/*
X * Maximum of indent levels for Sys-File
X */
X# define MAX_FDS 10
X
Xextern char *index ();
Xextern char *malloc ();
Xextern char *strdup ();
X
Xint
Xread_sys ()
X{
X register char *ptr;
X register char *p;
X register int t;
X sys *act, *tmp;
X int fds[MAX_FDS + 2];
X int fdp;
X int n;
X int siz;
X char *fflags;
X char *buf, *sav;
X char *store;
X char *rbuf;
X char **arg;
X
X hsys = NULL;
X act = NULL;
X if (! (rbuf = malloc (512))) {
X do_log ("Failed alloc memory in read_sys\n");
X return (-1);
X }
X if ((fds[0] = open (SYS_FILE, S_IREAD)) < 0) {
X do_log ("Can't open %s\n", SYS_FILE);
X return (-1);
X }
X fdp = 0;
X catlines = TRUE;
X while (fdp >= 0) {
X while (buf = readbuf (fds[fdp], & n)) {
X buf[n-1] = '\0';
X if ((n == 1) || (buf[0] == '#'))
X continue;
X if (buf[0] == ':') {
X if (fdp < MAX_FDS)
X if ((fds[fdp + 1] = open (buf + 1, S_IREAD)) != -1)
X ++fdp;
X continue;
X }
X if (!(tmp = (sys *) malloc (sizeof (sys)))) {
X while (fdp >= 0)
X close (fds[fdp--]);
X do_log ("Failed alloc memory in read_sys\n");
X return (-1);
X }
X tmp->fwd = FALSE;
X sav = buf;
X ptr = skipc (sav, ':');
X if (fflags = index (sav, '>')) {
X *fflags++ = '\0';
X while (is8space (*fflags))
X ++fflags;
X tmp -> fflags = strdup (fflags);
X } else
X tmp -> fflags = NULL;
X if (p = index (sav, '/')) {
X *p++ = '\0';
X store = p;
X siz = 4;
X while (p = index (p, ',')) {
X ++p;
X ++siz;
X }
X if (tmp->wsites = (char **) malloc (siz * (sizeof (char *)))) {
X p = store;
X n = 0;
X while (p) {
X store = p;
X if (p = index (p, ','))
X *p++ = '\0';
X if (!(tmp->wsites[n++] = strdup (store)))
X break;
X }
X tmp->wsites[n] = NULL;
X }
X } else
X tmp->wsites = NULL;
X if (!(tmp->site = strdup (sav))) {
X while (fdp >= 0)
X close (fds[fdp--]);
X do_log ("Failed alloc memory in read_sys\n");
X return (-1);
X }
X sav = ptr;
X ptr = skipc (sav, ':');
X if ((n = getargs (sav, &arg)) < 0) {
X while (fdp >= 0)
X close (fds[fdp--]);
X do_log ("Failed alloc memory in read_sys\n");
X return (-1);
X }
X if (!(tmp->grps = (regexp **) malloc (sizeof (regexp *) * (n + 3)))) {
X while (fdp >= 0)
X close (fds[fdp--]);
X do_log ("Failed alloc memory in read_sys\n");
X return (-1);
X }
X if (!(tmp->inv = (int *) malloc (sizeof (int) * (n + 3)))) {
X while (fdp >= 0)
X close (fds[fdp--]);
X do_log ("Failed alloc memory in read_sys\n");
X return (-1);
X }
X if (n > 0) {
X for (t=0;t<n;++t) {
X p = arg[t];
X while (*p) {
X *p = to8lower (*p);
X ++p;
X }
X p = arg[t];
X if (*p == '!') {
X ++p;
X tmp->inv[t] = TRUE;
X } else
X tmp->inv[t] = FALSE;
X if (p[0] == '^')
X strcpy (rbuf, p);
X else {
X strcpy (rbuf + 1, p);
X rbuf[0] = '^';
X }
X if (rbuf[strlen (rbuf) - 1] != '$')
X strcat (rbuf, "$");
X if (!(tmp->grps[t] = regcomp (rbuf))) {
X while (fdp >= 0)
X close (fds[fdp--]);
X do_log ("Failed alloc memory in read_sys\n");
X return (-1);
X }
X }
X tmp->grps[t] = NULL;
X free ((char *) arg);
X } else
X n = 0;
X# ifdef DEFAULT_CTRL
X tmp->grps[n] = regcomp (NG_CONTROL);
X tmp->inv[n] = FALSE;
X tmp->grps[n+1] = NULL;
X# else DEFAULT_CTRL
X tmp->grps[n] = NULL;
X# endif DEFAULT_CTRL
X sav = ptr;
X ptr = skipc (sav, ':');
X if (!*sav)
X tmp->dist = NULL;
X if (*sav) {
X if ((n = getargs (sav, &arg)) < 0) {
X while (fdp >= 0)
X close (fds[fdp--]);
X do_log ("Failed alloc memory in read_sys\n");
X return (-1);
X }
X } else
X n = 0;
X if (!(tmp->dist = (char **) malloc (sizeof (char *) * (n + 3)))) {
X while (fdp >= 0)
X close (fds[fdp--]);
X do_log ("Failed alloc memory in read_sys\n");
X return (-1);
X }
X if (n > 0) {
X for (t=0;t<n;++t) {
X p = arg[t];
X while (*p) {
X *p = to8lower (*p);
X ++p;
X }
X if (!(tmp->dist[t] = strdup (arg[t]))) {
X while (fdp >= 0)
X close (fds[fdp--]);
X do_log ("Failed alloc memory in read_sys\n");
X return (-1);
X }
X }
X tmp->dist[t] = NULL;
X free ((char *) arg);
X }
X# ifdef ADD_SITENAME_AS_DISTRIBUTION
X tmp->dist[n++] = strdup (tmp->site);
X# endif /* ADD_SITENAME_AS_DISTRIBUTION */
X tmp->dist[n] = NULL;
X if (*ptr) {
X if (!(tmp->cmd = strdup (ptr))) {
X while (fdp >= 0)
X close (fds[fdp--]);
X do_log ("Failed alloc memory in read_sys\n");
X return (-1);
X }
X } else
X tmp->cmd = NULL;
X tmp->next = NULL;
X if (!act)
X hsys = tmp;
X else
X act->next = tmp;
X act = tmp;
X }
X close (fds[fdp--]);
X }
X catlines = FALSE;
X free (rbuf);
X return (0);
X}
__END__OF__THIS__FILE__
if test -f 'INEWS/sect.c' ; then
echo 'File INEWS/sect.c already exists, overwriting it'
del 'INEWS/sect.c'
fi
echo Extracting \"'INEWS/sect.c'\"
sed "s/^X//" >'INEWS/sect.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log: sect.c_v $
X * Revision 1.2 91/05/22 13:06:16 ud
X * Abstracted news owner (from static to variable)
X *
X * Revision 1.1 90/08/31 15:36:08 cs
X * Initial revision
X *
X */
X# ifndef LINT
Xstatic char rcsid[] = "$Id: sect.c_v 1.2 91/05/22 13:06:16 ud Exp $";
X# endif LINT
X# include <time.h>
X# include <pwd.h>
X# include "inews.h"
X
Xextern char *getenv ();
Xextern char *malloc ();
Xextern char *strdup ();
X
Xvoid
Xsend_control (msg, opts, pars)
Xchar *msg;
Xchar *opts;
Xchar *pars;
X{
X register int t;
X time_t tim;
X char *line;
X char *cont;
X charc *act;
X charc *tmp;
X charc *htmp, *t2;
X int siz;
X char *ptr;
X char *sender, *fullname;
X char *ffname;
X struct passwd *pwd;
X struct gecos *gc;
X
X sender = news_owner;
X fullname = NULL;
X setpwent ();
X if (pwd = getpwuid (getuid () & 0xffff))
X if ((gc = getgecos (pwd->pw_gecos)) && gc->fullname && *gc->fullname)
X fullname = strdup (gc->fullname);
X ffname = NULL;
X setpwent ();
X if (pwd = getpwnam (user))
X if ((gc = getgecos (pwd->pw_gecos)) && gc->fullname && *gc->fullname)
X ffname = strdup (gc->fullname);
X endpwent ();
X act = NULL;
X cont = NULL;
X for (t=0;hlines[t];++t) {
X line = hlines[t] + 2;
X switch (t) {
X case H_PATH:
X cont = strdup (news_owner);
X break;
X case H_FROM:
X if (cont = malloc (strlen (fhost) + strlen (user) + (ffname ? strlen (ffname) + 6 : 0) + 10)) {
X sprintf (cont, "%s@%s", user, fhost);
X if (ffname) {
X strcat (cont, " (");
X strcat (cont, ffname);
X strcat (cont, ")");
X }
X }
X break;
X case H_SENDER:
X case H_APPROVED:
X if ((!isadm) && (t == H_SENDER)) {
X if (cont = malloc (strlen (fhost) + strlen (user) + 6))
X sprintf (cont, "%s@%s", user, fhost);
X break;
X }
X if (cont = malloc (strlen (fhost) + strlen (sender) + (fullname ? strlen (fullname) + 6 : 0) + 10)) {
X sprintf (cont, "%s@%s", sender, fhost);
X if (fullname) {
X strcat (cont, " (");
X strcat (cont, fullname);
X strcat (cont, ")");
X }
X }
X break;
X case H_NEWSGROUPS:
X case H_DISTRIBUTION:
X if (t == H_NEWSGROUPS) {
X# ifdef ALWAYS_CONTROL
X cont = strdup (NG_CONTROL);
X# endif /* ALWAYS_CONTROL */
X if (! (htmp = ngs)) {
X# ifndef ALWAYS_CONTROL
X cont = strdup (NG_CONTROL);
X# endif /* ALWAYS_CONTROL */
X break;
X }
X } else if (dists)
X htmp = dists;
X else
X break;
X siz = 0;
X t2 = htmp;
X while (t2) {
X siz += strlen (t2->text) + 4;
X if (cont && Streql (t2->text, cont)) {
X siz = 0;
X break;
X }
X t2 = t2->next;
X }
X if ((t == H_NEWSGROUPS) && (siz > 0) && cont)
X if (tmp = (charc *) malloc (sizeof (charc)))
X if (tmp->text = strdup (cont)) {
X tmp->next = ngs;
X ngs = tmp;
X htmp = ngs;
X siz += strlen (cont) + 4;
X } else
X free ((char *) tmp);
X if (cont) {
X free (cont);
X cont = NULL;
X }
X if ((siz > 0) && (cont = malloc (siz + 10))) {
X t2 = htmp;
X strcpy (cont, "");
X while (t2) {
X if (t2 != htmp)
X strcat (cont, ",");
X strcat (cont, t2->text);
X t2 = t2->next;
X }
X }
X break;
X case H_SUBJECT:
X case H_CONTROL:
X if (cont = malloc (strlen (msg) + strlen (opts) + 4 + ((pars && *pars) ? strlen (pars) + 4 : 0))) {
X strcpy (cont, msg);
X if (*opts) {
X strcat (cont, " ");
X strcat (cont, opts);
X if (pars && *pars) {
X strcat (cont, " ");
X strcat (cont, pars);
X }
X }
X }
X break;
X case H_MESSAGE_ID:
X cont = strdup (get_msgid ());
X break;
X case H_DATE:
X time (&tim);
X cont = strdup (ntime (&tim));
X break;
X case H_ORGANIZATION:
X if (ptr = getenv ("ORGANIZATION"))
X cont = strdup (ptr);
X else
X cont = NULL;
X break;
X case H_REFERENCES:
X if ((!isadm) && opts && *opts)
X cont = strdup (opts);
X break;
X case H_FOLLOWUP_TO:
X case H_KEYWORDS:
X case H_SUMMARY:
X case H_EXPIRES:
X case H_LINES:
X case H_XREF:
X default:
X cont = NULL;
X }
X if (cont) {
X if (!(tmp = (charc *) malloc (sizeof (charc))))
X do_exit (_errmsg (1, "Can't alloc in send_control\n"));
X if (!(tmp->text = malloc (strlen (cont) + strlen (line) + 6)))
X do_exit (_errmsg (1, "Can't alloc in send_control\n"));
X strcpy (tmp->text, line);
X strcat (tmp->text, " ");
X strcat (tmp->text, cont);
X free (cont);
X cont = NULL;
X tmp->next = NULL;
X if (act)
X act->next = tmp;
X else
X head = tmp;
X act = tmp;
X }
X }
X do_send_article (0, TRUE);
X if (fullname)
X free (fullname);
X if (ffname)
X free (ffname);
X}
__END__OF__THIS__FILE__
if test -f 'INEWS/shead.c' ; then
echo 'File INEWS/shead.c already exists, overwriting it'
del 'INEWS/shead.c'
fi
echo Extracting \"'INEWS/shead.c'\"
sed "s/^X//" >'INEWS/shead.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log: shead.c_v $
X * Revision 1.1 90/08/31 15:36:13 cs
X * Initial revision
X *
X */
X# ifndef LINT
Xstatic char rcsid[] = "$Id: shead.c_v 1.1 90/08/31 15:36:13 cs Exp $";
X# endif LINT
X# include "inews.h"
X
Xint
Xsort_header (make_missing)
Xregister int make_missing;
X{
X register int t;
X register charc *act, *tmp, *t2;
X
X act = head;
X for (t=0;hlines[t];++t) {
X tmp = act;
X while (tmp)
X if (Strnieql (tmp->text, hlines[t] + 2, strlen (hlines[t] + 2))) {
X if (tmp != act) {
X t2 = act;
X while (t2->next)
X if (t2->next == tmp)
X break;
X else
X t2 = t2->next;
X if (t2->next == tmp) {
X t2->next = tmp->next;
X tmp->next = act;
X if (head == act)
X head = tmp;
X else {
X t2 = head;
X while (t2->next)
X if (t2->next == act)
X break;
X else
X t2 = t2->next;
X if (t2->next == act) {
X t2->next = tmp;
X tmp->next = act;
X }
X }
X }
X } else
X act = act->next;
X break;
X } else
X tmp = tmp->next;
X if ((!tmp) && (hlines[t][0] == '0') && make_missing) {
X if (tmp = make_head (t))
X if (act == head) {
X head = tmp;
X tmp->next = act;
X } else {
X t2 = head;
X while (t2->next)
X if (t2->next == act)
X break;
X else
X t2 = t2->next;
X if (t2->next == act) {
X tmp->next = act;
X t2->next = tmp;
X }
X }
X }
X }
X return (0);
X}
__END__OF__THIS__FILE__
if test -f 'INEWS/sinfo.c' ; then
echo 'File INEWS/sinfo.c already exists, overwriting it'
del 'INEWS/sinfo.c'
fi
echo Extracting \"'INEWS/sinfo.c'\"
sed "s/^X//" >'INEWS/sinfo.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log: sinfo.c_v $
X * Revision 1.2 91/05/22 13:25:33 ud
X * Get news owner from password file
X * Determinate full host name from an own sysinfo entry (if available)
X * Do better locking/unlocking for lck.inews
X *
X * Revision 1.1 90/08/31 15:36:17 cs
X * Initial revision
X *
X */
X# ifndef LINT
Xstatic char rcsid[] = "$Id: sinfo.c_v 1.2 91/05/22 13:25:33 ud Exp $";
X# endif LINT
X# include <stdio.h>
X# include <pwd.h>
X# include <time.h>
X# include "inews.h"
X
Xextern char *cuserid ();
Xextern char *getenv ();
Xextern char *getlogin ();
Xextern char *malloc ();
Xextern char *strdup ();
X
Xstatic int islocked = FALSE;
Xstatic FILE *logp = NULL;
Xstatic time_t starttim, endtim;
X
Xvoid
Xzero_out ()
X{
X struct passwd *pw;
X
X ngs = NULL;
X dists = NULL;
X head = NULL;
X hsys = NULL;
X hact = NULL;
X# ifdef HASH_SEARCH
X hashact = NULL;
X# endif /* HASH_SEARCH */
X artsize = 0;
X act_rewrite = FALSE;
X
X block_forward = FALSE;
X
X recv = NULL;
X
X batchdir = NULL;
X newsdir = NULL;
X newslib = NULL;
X newstspool = NULL;
X
X hostname = NULL;
X fhost = NULL;
X
X isctrl = NULL;
X
X catlines = FALSE;
X verbose = FALSE;
X logp = NULL;
X if (!(user = getlogin ()))
X if (!(user = getenv ("USER")))
X if (!(user = cuserid ()))
X user = "*unknown*";
X user = strdup (user);
X setpwent ();
X if (!(home = getenv ("HOME"))) {
X if (!(pw = getpwnam (user)))
X home = TEMPDIR;
X else
X home = pw->pw_dir;
X }
X if (pw = getpwuid (getmuid () & 0xffff))
X news_owner = strdup (pw->pw_name);
X else
X news_owner = strdup (NEWS_OWNER);
X if (! news_owner)
X news_owner = NEWS_OWNER;
X endpwent ();
X home = strdup (home);
X local_term = NULL;
X}
X
Xstatic void
Xopen_log ()
X{
X if (access (LOG_FILE, 0) != -1)
X logp = fopen (LOG_FILE, "a");
X}
X
Xstatic void
Xclose_log ()
X{
X if (logp) {
X fclose (logp);
X logp = NULL;
X }
X}
X
Xint
Xdo_init (lockit)
Xint lockit;
X{
X char *buf;
X int t;
X int slp;
X
X if (!(buf = malloc (512)))
X return (-1);
X if (!info_str (BATCHDIR, buf, 500))
X batchdir = strdup (NEWS_BATCH);
X else
X batchdir = strdup (buf);
X if (!info_str (NEWSDIR, buf, 500))
X newsdir = strdup (NEWS_DIR);
X else
X newsdir = strdup (buf);
X if (!info_str (LIBDIR, buf, 500))
X newslib = strdup (NEWS_LIB);
X else
X newslib = strdup (buf);
X
X if (! info_str (TSPOOLDIR, buf, 500))
X newstspool = strdup (MNEWS_TSPOOLDIR);
X else
X newstspool = strdup (buf);
X
X if (!gethostname (buf, 500))
X return (-1);
X else
X if (!(hostname = strdup (buf)))
X return (-1);
X
X if (! getfullhostname (buf, 500)) {
X if (info_str ("hostdomain", buf, 500)) {
X if (fhost = malloc (strlen (hostname) + strlen (buf) + 3))
X sprintf (fhost, "%s.%s", hostname, buf);
X } else
X fhost = strdup (hostname);
X } else
X fhost = strdup (buf);
X
X /*
X * Test, if an allocation failed
X */
X if (!(batchdir && newsdir && newslib && fhost))
X return (-1);
X
X# ifndef IN_MEMORY
X /*
X * Make Filename for news body
X */
X sprintf (newstmp, "%s/inewsXXXXXX", TEMPDIR);
X mktemp (newstmp);
X# else /* IN_MEMORY */
X newstmp = NULL;
X# endif /* IN_MEMORY */
X
X if (chdir (newslib) < 0)
X return (-1);
X
X /*
X * Try to lock
X */
X if (lockit) {
X# ifndef EVENT_LOCK
X if (LOCK_TIMEOUT > 0) {
X t = LOCK_TIMEOUT;
X while (t-- > 0)
X if (info_is_locked (NEWS_LOCK))
X sleep (1);
X else
X break;
X } else
X t = info_is_locked (NEWS_LOCK) ? -1 : 1;
X if ((t <= 0) || (info_lock (NEWS_LOCK, -1) < 0))
X return (-2);
X# else /* EVENT_LOCK */
X if (do_lock (NEWS_LOCK, LOCK_TIMEOUT) < 0)
X return (-2);
X# endif /* EVENT_LOCK */
X islocked = TRUE;
X open_log ();
X }
X time (&starttim);
X return (0);
X}
X
Xint
Xnlock ()
X{
X int err;
X
X if (! islocked) {
X# ifndef EVENT_LOCK
X err = info_lock (NEWS_LOCK, -1);
X# else /* EVENT_LOCK */
X err = do_lock (NEWS_LOCK, LOCK_TIMEOUT);
X# endif /* EVENT_LOCK */
X if (err != -1) {
X islocked = TRUE;
X open_log ();
X }
X }
X return (islocked ? 0 : -1);
X}
X
Xvoid
Xnunlock ()
X{
X if (islocked) {
X# ifndef EVENT_LOCK
X info_unlock (NEWS_LOCK);
X# else /* EVENT_LOCK */
X do_unlock (NEWS_LOCK);
X# endif /* EVENT_LOCK */
X islocked = FALSE;
X close_log ();
X respool (TRUE);
X }
X}
X
Xvoid
Xdo_term ()
X{
X charc *tmp;
X struct tm *tt;
X
X if (local_term)
X (*local_term) ();
X# ifndef IN_MEMORY
X unlink (newstmp);
X# else /* IN_MEMORY */
X free_list (newstmp);
X newstmp = NULL;
X# endif /* IN_MEMORY */
X time (&endtim);
X if (tt = localtime (&starttim))
X do_log ("%02d.%02d %02d:%02d ",
X tt->tm_mday,
X tt->tm_mon + 1,
X tt->tm_hour,
X tt->tm_min);
X do_log ("[%d]", endtim - starttim);
X for (tmp = ngs; tmp; tmp = tmp->next)
X do_log (" %s", tmp->text);
X do_log ("\n");
X close_log ();
X if (islocked)
X nunlock ();
X else
X close_log ();
X# ifdef EVENT_LOCK
X /* Sure is sure ... */
X do_unlock ("*");
X# endif /* EVENT_LOCK */
X}
X
Xvoid
Xdo_exit (n)
Xint n;
X{
X do_term ();
X exit (n);
X}
X
Xvoid
Xdo_log (fmt, a, b, c, d, e, f)
Xchar *fmt, *a, *b, *c, *d, *e, *f;
X{
X if (logp)
X fprintf (logp, fmt, a, b, c, d, e, f);
X if (verbose)
X fprintf (stderr, fmt, a, b, c, d, e, f);
X}
__END__OF__THIS__FILE__
if test -f 'INEWS/sit.c' ; then
echo 'File INEWS/sit.c already exists, overwriting it'
del 'INEWS/sit.c'
fi
echo Extracting \"'INEWS/sit.c'\"
sed "s/^X//" >'INEWS/sit.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log: sit.c_v $
X * Revision 1.1 90/08/31 15:36:22 cs
X * Initial revision
X *
X */
X# ifndef LINT
Xstatic char rcsid[] = "$Id: sit.c_v 1.1 90/08/31 15:36:22 cs Exp $";
X# endif LINT
X# include <stdio.h>
X# include <modes.h>
X# include "inews.h"
X
Xextern char *malloc ();
X
Xvoid
Xsave_it (st)
Xsys *st;
X{
X char *dir;
X char *buf;
X char *fn;
X FILE *fp, *fpi;
X int fd;
X int id;
X
X dir = st->cmd + 1;
X if (access (dir, S_IFDIR) < 0) {
X do_log ("FATAL: %s is no directory in save_it().\n", dir);
X return;
X }
X if (!(fn = malloc (strlen (dir) + 64))) {
X do_log ("FATAL: can't alloc in save_it()\n");
X return;
X }
X sprintf (fn, "%s/.seq", dir);
X if ((fd = open (fn, S_IREAD | S_IWRITE)) < 0) {
X fd = create (fn, S_IWRITE, 03);
X id = 1;
X } else {
X if (read (fd, &id, sizeof (int)) == sizeof (int))
X ++id;
X lseek (fd, 0, 0);
X }
X if (fd != -1) {
X write (fd, &id, sizeof (int));
X close (fd);
X }
X sprintf (fn, "%s/%06d", dir, id);
X if (fp = fopen (fn, "w")) {
X if (buf = malloc (520)) {
X sprintf (buf, "%s/%s", newsdir, realfile);
X if (fpi = fopen (buf, "r")) {
X while (fgets (buf, 512, fpi))
X fputs (buf, fp);
X fclose (fpi);
X } else
X do_log ("Can't open %s for reading.\n", buf);
X free (buf);
X } else
X do_log ("Can't alloc copy-buffer.\n");
X fclose (fp);
X } else
X do_log ("Can't open output-file %s.\n", fn);
X free (fn);
X}
__END__OF__THIS__FILE__
if test -f 'INEWS/spch.c' ; then
echo 'File INEWS/spch.c already exists, overwriting it'
del 'INEWS/spch.c'
fi
echo Extracting \"'INEWS/spch.c'\"
sed "s/^X//" >'INEWS/spch.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log: spch.c_v $
X * Revision 1.2 91/05/22 13:24:52 ud
X * Added Supersedes: support
X *
X * Revision 1.1 90/08/31 15:36:25 cs
X * Initial revision
X *
X */
X# ifndef LINT
Xstatic char rcsid[] = "$Id: spch.c_v 1.2 91/05/22 13:24:52 ud Exp $";
X# endif LINT
X# include <c8type.h>
X# include "inews.h"
X
Xextern char *index ();
Xextern char *malloc ();
X
Xvoid
Xspecial_header (hd, ind)
Xcharc *hd;
Xint ind;
X{
X register char *p1, *p2;
X char *tp;
X char *buf;
X charc *tmp;
X int n;
X
X switch (ind) {
X case S_PATH:
X p1 = skip_field (hd->text);
X# ifdef USE_FULLHOST
X n = strlen (fhost);
X if ((n <= strlen (p1)) && Strneql (p1, fhost, n) && (! isalnum (p1[n])) && (p1[n] != '.'))
X break;
X# endif /* USE_FULLHOST */
X# ifndef USE_ONLY_FULLHOST
X n = strlen (hostname);
X if ((n <= strlen (p1)) && Strneql (p1, hostname, n) && (! isalnum (p1[n])) && (p1[n] != '.'))
X break;
X# endif /* USE_ONLY_FULLHOST */
X if (!(buf = malloc (strlen (hd->text) + strlen (hostname) + strlen (fhost) + 32)))
X do_exit (_errmsg (1, "Can't alloc memory when expanding Path: field.\n"));
X p2 = buf;
X p1 = hd->text;
X while (*p1 && (*p1 != ':'))
X *p2++ = *p1++;
X if (*p1) {
X *p2++ = *p1++;
X *p2++ = ' ';
X while (is8space (*p1))
X ++p1;
X# ifndef USE_ONLY_FULLHOST
X tp = hostname;
X while (*tp)
X *p2++ = *tp++;
X *p2++ = '!';
X# endif USE_ONLY_FULLHOST
X# ifdef USE_FULLHOST
X tp = fhost;
X while (*tp)
X *p2++ = *tp++;
X *p2++ = '!';
X# endif USE_FULLHOST
X while (*p1)
X *p2++ = *p1++;
X *p2 = '\0';
X free (hd->text);
X hd->text = buf;
X } else {
X do_log ("Internal error when expanding Path: field\n");
X do_exit (1);
X }
X break;
X case S_NEWSGROUPS:
X p1 = skip_field (hd->text);
X ngs = split_fields (p1, TRUE);
X if (alias_newsgroups ()) {
X if (!ngs) {
X do_log ("No more Newsgroups: after alias, aborted.\n");
X do_exit (0);
X }
X if (p1 = catcharc (ngs, ",")) {
X insert_header (H_NEWSGROUPS, p1, TRUE);
X free (p1);
X }
X }
X break;
X case S_SUBJECT:
X p1 = skip_field (hd->text);
X if (Strnicmp (p1, "re: ", 4))
X if (p2 = malloc (strlen (hd->text) + 10)) {
X sprintf (p2, "%s Re: %s", hlines[H_SUBJECT] + 2, p1);
X free (hd->text);
X hd->text = p2;
X }
X break;
X case S_FOLLOWUP_TO:
X p1 = skip_field (hd->text);
X if (*p1) {
X free_field (ngs);
X ngs = NULL;
X ngs = split_fields (p1, TRUE);
X insert_header (H_NEWSGROUPS, p1, TRUE);
X delete_header (H_FOLLOWUP_TO);
X }
X break;
X case S_MESSAGE_ID:
X p1 = skip_field (hd->text);
X set_msgid (p1);
X check_message_id (p1);
X break;
X case S_DISTRIBUTION:
X p1 = skip_field (hd->text);
X dists = split_fields (p1, TRUE);
X# ifdef NO_DOT_IN_DIST
X tmp = dists;
X while (tmp) {
X if (p1 = index (tmp->text, '.'))
X *p1 = '\0';
X tmp = tmp->next;
X }
X# endif NO_DOT_IN_DIST
X break;
X case S_REFERENCES:
X if (tmp = get_header_line (H_MESSAGE_ID)) {
X p1 = skip_field (tmp->text);
X if (p2 = malloc (strlen (p1) + strlen (hd->text) + 6)) {
X sprintf (p2, "%s %s", hd->text, p1);
X free (hd->text);
X hd->text = p2;
X }
X }
X break;
X case S_SUPERSEDES:
X if (tmp = get_header_line (H_SUPERSEDES)) {
X p1 = skip_field (tmp->text);
X delete_msg (p1);
X }
X break;
X }
X}
X
Xvoid
Xhandle_special (id)
Xregister int id;
X{
X register charc *tmp;
X register int found;
X register charc *htmp;
X register char *ptr;
X
X if ((id < 0) || (id > SPECIAL_MAX))
X return;
X tmp = head;
X found = FALSE;
X while (tmp) {
X if (Strnieql (tmp->text, slines[id], strlen (slines[id]))) {
X special_header (tmp, id);
X found = TRUE;
X }
X tmp = tmp->next;
X }
X if (!found)
X switch (id) {
X case S_TO:
X if (!recv) {
X if (!(ptr = find_address ()))
X break;
X if (recv = (charc *) malloc (sizeof (charc)))
X if (recv->text = malloc (strlen (ptr) + strlen (hlines[H_TO] + 2) + 6)) {
X sprintf (recv->text, "%s %s", hlines[H_TO] + 2, ptr);
X recv->next = NULL;
X } else {
X free ((char *) recv);
X recv = NULL;
X }
X free (ptr);
X }
X break;
X case S_REFERENCES:
X if (!(tmp = (charc *) malloc (sizeof (charc))))
X break;
X if (!(htmp = get_header_line (H_MESSAGE_ID))) {
X free ((char *) tmp);
X break;
X }
X ptr = skip_field (htmp->text);
X insert_header (H_REFERENCES, ptr, TRUE);
X break;
X case S_DISTRIBUTION:
X if ((! dists) && (crthd || ins_dist))
X make_default_dists ();
X if (dists && (dists->next || Stricmp (dists->text, DST_WORLD)))
X if (ptr = catcharc (dists, ",")) {
X insert_header (H_DISTRIBUTION, ptr, TRUE);
X free (ptr);
X }
X break;
X }
X}
__END__OF__THIS__FILE__
if test -f 'INEWS/store.c' ; then
echo 'File INEWS/store.c already exists, overwriting it'
del 'INEWS/store.c'
fi
echo Extracting \"'INEWS/store.c'\"
sed "s/^X//" >'INEWS/store.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log: store.c_v $
X * Revision 1.1 91/05/22 13:36:49 ud
X * Initial revision
X *
X *
X */
X# ifndef LINT
Xstatic char rcsid[] = "$Id: store.c_v 1.1 91/05/22 13:36:49 ud Exp $";
X# endif LINT
X# include <stdio.h>
X# include <ctype.h>
X# include <errno.h>
X# include <modes.h>
X# include <dir.h>
X# include "inews.h"
X
X# define SEQ ".seq"
X# define TNEWS_AVAIL "/dd/SYS/.TNews_Available"
X
Xextern char *_prgname ();
Xextern char *malloc ();
Xextern char *strdup ();
Xextern FILE *xpopen ();
X
Xstatic int
Xenter_tspool ()
X{
X if (! newstspool) {
X do_log ("No TSPOOL found.\n");
X return (-1);
X }
X if (chdir (newstspool) < 0) {
X do_log ("Can't chdir to %s.\n", newstspool);
X return (-1);
X }
X return (0);
X}
X
Xint
Xdo_store ()
X{
X char *buf;
X int n;
X int fd;
X int tout;
X
X if (enter_tspool () < 0)
X return (-1);
X if (! (buf = malloc (256))) {
X do_log ("Can't alloc in do_store()\n");
X return (-1);
X }
X tout = 10;
X do {
X if (((fd = open (SEQ, S_IREAD | S_IWRITE | S_ISHARE)) < 0) && (errno == E_PNNF)) {
X if ((fd = create (SEQ, S_IWRITE | S_ISHARE, 03 | S_ISHARE)) != -1)
X n = 0;
X } else {
X read (fd, &n, sizeof (int));
X lseek (fd, 0, 0);
X }
X if (fd == -1)
X sleep (1);
X } while ((fd == -1) && (tout-- > 0));
X if (fd == -1) {
X do_log ("Can't open/create %s\n", SEQ);
X free (buf);
X return (-1);
X }
X if (++n < 0)
X n = 0;
X write (fd, &n, sizeof (int));
X close (fd);
X sprintf (buf, "%06d", n);
X if ((fd = create (buf, S_IWRITE | S_ISIZE, 03, 4096)) != -1) {
X if (crthd)
X writeln (fd, " -h\n", 4);
X else
X writeln (fd, "\n", 1);
X while ((n = read (0, buf, 256)) > 0)
X if (write (fd, buf, n) != n) {
X do_log ("Can't write to temp.file\n");
X break;
X }
X close (fd);
X if (n > 0)
X fd = -1;
X }
X if (fd != -1) {
X if ((fd = create (TNEWS_AVAIL, S_IWRITE, 03)) != -1)
X close (fd);
X return (0);
X } else
X return (-1);
X}
X
Xint
Xrespool (check)
Xint check;
X{
X FILE *pp;
X DIR *dp;
X struct direct *ent;
X charc *root, *cur, *prev, *tmp;
X register char *ptr;
X char *pgm;
X char *cmd;
X char *buf;
X int n;
X int fd;
X
X if (check) {
X if (access (TNEWS_AVAIL, 0) == -1)
X return (0);
X unlink (TNEWS_AVAIL);
X }
X if (enter_tspool () < 0)
X return (-1);
X if (! (dp = opendir ("."))) {
X do_log ("Can't open %s\n", newstspool);
X return (-1);
X }
X root = NULL;
X prev = NULL;
X while (ent = readdir (dp)) {
X ptr = ent->d_name;
X while (isdigit (*ptr))
X ++ptr;
X if (*ptr)
X continue;
X if (cur = (charc *) malloc (sizeof (charc)))
X if (cur->text = strdup (ent->d_name)) {
X cur->nr = 0;
X cur->next = NULL;
X if (! prev)
X root = cur;
X else
X prev->next = cur;
X prev = cur;
X } else
X free ((char *) cur);
X }
X closedir (dp);
X if (! root)
X return (-1);
X if (! (buf = malloc (256))) {
X do_log ("Can't alloc in respool()\n");
X return (-1);
X }
X if (! (pgm = _prgname ()))
X pgm = "inews";
X if (! (cmd = malloc (256 + strlen (pgm) + 8)))
X return (-1);
X for (cur = root; cur;) {
X if ((fd = open (cur->text, S_IREAD)) < 0)
X continue;
X if ((n = readln (fd, buf, 256)) <= 0) {
X close (fd);
X continue;
X }
X buf[n - 1] = '\0';
X sprintf (cmd, "%s%s", pgm, buf);
X if (! (pp = xpopen (cmd, "w"))) {
X close (fd);
X continue;
X }
X while ((n = read (fd, buf, 256)) > 0)
X if (fwrite (buf, sizeof (char), n, pp) != n)
X break;
X close (fd);
X if (pclose (pp))
X n = 1;
X if (! n)
X unlink (cur->text);
X tmp = cur;
X cur = cur->next;
X free (tmp -> text);
X free ((char *) tmp);
X }
X free (buf);
X free (cmd);
X return (0);
X}
__END__OF__THIS__FILE__
if test -f 'INEWS/tsys.c' ; then
echo 'File INEWS/tsys.c already exists, overwriting it'
del 'INEWS/tsys.c'
fi
echo Extracting \"'INEWS/tsys.c'\"
sed "s/^X//" >'INEWS/tsys.c' <<'__END__OF__THIS__FILE__'
X/*
X * $Log: tsys.c_v $
X * Revision 1.2 91/09/11 18:16:52 ud
X * Moved macro is_part_of_hostname to inews.h
X *
X * Revision 1.1 90/08/31 15:36:30 cs
X * Initial revision
X *
X */
X# ifndef LINT
Xstatic char rcsid[] = "$Id: tsys.c_v 1.2 91/09/11 18:16:52 ud Exp $";
X# endif LINT
X# include <c8type.h>
X# include <string.h>
X# include "inews.h"
X
Xextern char *malloc ();
Xextern char *rindex ();
X
Xint
Xis_system_in_path (path, system)
Xregister char *path;
Xregister char *system;
X{
X register char *ptr;
X register int is_in;
X
X is_in = FALSE;
X if ((ptr = strstr (path, system)) && (strlen (ptr) >= strlen (system)))
X if ((ptr == path) || ((ptr > path) && (!is_part_of_hostname (*(ptr-1))))) {
X ptr += strlen (system);
X if (!is_part_of_hostname (*ptr))
X is_in = TRUE;
X }
X return (is_in);
X}
X
Xvoid
Xtest_systems ()
X{
X register sys *stmp;
X register int t;
X int found, isok;
X charc *ntmp;
X charc *htmp;
X char *path;
X int inv;
X charc *dtmp;
X char *buf, *ptr;
X int size;
X
X if (!(htmp = get_header_line (H_PATH))) {
X do_log ("FATAL: Can't get Path: field!\n");
X return;
X }
X path = skip_field (htmp->text);
X for (ntmp = ngs, size = 0; ntmp; ntmp = ntmp->next)
X if ((t = strlen (ntmp->text)) > size)
X size = t;
X if (!(buf = malloc (size + 10))) {
X do_log ("FATAL: Can't alloc for control-check\n");
X return;
X }
X stmp = hsys;
X while (stmp) {
X /*
X * Test if System is in Path:
X */
X isok = TRUE;
X if (is_system_in_path (path, stmp->site))
X isok = FALSE;
X else if (stmp->wsites)
X for (t=0;stmp->wsites[t];++t)
X if (is_system_in_path (path, stmp->wsites[t])) {
X isok = FALSE;
X break;
X }
X if (!isok) {
X stmp = stmp->next;
X continue;
X }
X
X /*
X * Test newsgroups-part
X */
X found = FALSE;
X ntmp = ngs;
X while (ntmp) {
X if (buf) {
X strcpy (buf, ntmp->text);
X if ((ptr = rindex (buf, '.')) && (Strieql (ptr, CTRL_POSTFIX)))
X *ptr = '\0';
X }
X for (t=0;stmp->grps[t];++t)
X if (regexec (stmp->grps[t], ntmp->text) ||
X (buf && regexec (stmp->grps[t], buf))) {
X found = TRUE;
X inv = stmp->inv[t];
X break;
X }
X if (found)
X break;
X ntmp = ntmp->next;
X }
X if ((!found) || inv) {
X stmp = stmp->next;
X continue;
X }
X
X /*
X * Now check distribution at least
X */
X inv = FALSE;
X if (stmp->dist && dists) {
X found = FALSE;
X dtmp = dists;
X while (dtmp) {
X for (t=0;stmp->dist[t];++t)
X if (stmp->dist[t][0] == '!') {
X if (_cmpnam (dtmp->text, stmp->dist[t] + 1, strlen (stmp->dist[t] + 1)) == 0) {
X found = TRUE;
X inv = TRUE;
X }
X } else if (_cmpnam (dtmp->text, stmp->dist[t], strlen (stmp->dist[t])) == 0) {
X found = TRUE;
X break;
X }
X if (found)
X break;
X dtmp = dtmp->next;
X }
X# ifndef ALWAYS_DIST_WORLD
X } else if (stmp->dist) {
X found = FALSE;
X for (t=0;stmp->dist[t];++t)
X if (_cmpnam (DST_WORLD, stmp->dist[t], strlen (stmp->dist[t])) == 0) {
X found = TRUE;
X break;
X }
X# endif /* ALWAYS_DIST_WORLD */
X } else
X found = TRUE;
X if (found && (!inv))
X stmp->fwd = TRUE;
X stmp = stmp->next;
X }
X if (buf)
X free (buf);
X}
X
__END__OF__THIS__FILE__
exit 0
: end of shell archive
--
Frank Kaefer # fkk@stasys.sta.sub.org # Starnberg, Germany
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads