|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T s
Length: 8371 (0x20b3) Types: TextFile Names: »submit_txt.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0 └─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z« └─⟦e5a54fb17⟧ └─⟦this⟧ »pp-5.0/Src/submit/submit_txt.c«
/* submit_txt.c: handles the bodies of the messages */ # ifndef lint static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Src/submit/RCS/submit_txt.c,v 5.0 90/09/20 16:23:29 pp Exp Locker: pp $"; # endif /* * $Header: /cs/research/pp/hubris/pp-beta/Src/submit/RCS/submit_txt.c,v 5.0 90/09/20 16:23:29 pp Exp Locker: pp $ * * $Log: submit_txt.c,v $ * Revision 5.0 90/09/20 16:23:29 pp * rcsforce : 5.0 public release * */ #include "head.h" #include "list_bpt.h" #include "q.h" #include "chan.h" #include <sys/socket.h> #include <sys/un.h> #include <sys/file.h> #include <sys/stat.h> extern Q_struct Qstruct; extern LIST_BPT *bodies_all; extern CHAN *ch_inbound; extern int privileged; extern char *loc_dom_mta; extern char *mgt_inhost; extern char *msg_basedir; extern char *ad_unique; extern char *cont_p2; extern char *cont_p22; extern char *msg_fullpath[]; /* -- globals -- */ char io_fpart[LINESIZE]; long msg_size; /* -- static variables -- */ static FILE *io_ofp; /* -- output -- */ static int io_linkpart; /* -- linked part so no txt copy -- */ static char *io_ostrend; static char io_tfname[FILNSIZE]; /* -- local routines -- */ int txt_tend(); void txt_input(); static int txt_bptfind(); static int txt_init(); static int txt_pend(); static int txt_pinit(); static int txt_read(); static void txt_bp_check(); static void txt_copy(); static void txt_in(); static void txt_via(); /* --------------------- Begin Routines -------------------------------- */ void txt_input (addvia) /* -- control the text -- */ int addvia; { int retval, nparts = 0, first = TRUE; PP_TRACE (("txt_input()")); /* -- set up to recieve text -- */ if ((retval = txt_init()) != RP_OK) err_abrt (retval, "Text initialisation"); while ((retval = txt_pinit()) == RP_OK) { PP_TRACE (("text loop")); /* -- add 822 trace -- */ if (first && !io_linkpart && addvia) txt_via (io_ofp); first = FALSE; nparts++; if (io_linkpart) continue; txt_in(); if ((retval = txt_pend()) != RP_OK) err_abrt (retval, "Text ending"); } if (rp_isbad (txt_tend())) retval = RP_MECH; if (retval != RP_DONE) err_abrt (RP_MECH, "Unknown error in txt_input"); if (nparts == 0) err_abrt (RP_USER, "Null message"); txt_mgt(); } int txt_tend() /* -- finally finish -- */ { PP_TRACE (("txt_tend()")); if (io_ofp != NULLFILE) { if(fclose (io_ofp) == EOF) return RP_MECH; io_ofp = NULLFILE; } if (isstr (io_ostrend)) * (io_ostrend - 1) = '\0'; return RP_OK; } /* ---------------------- Static Routines -------------------------------- */ static int txt_init() { char lbuf[LINESIZE]; int retval; PP_TRACE (("txt_init ('%s', '%s')", msg_fullpath, msg_basedir)); io_linkpart = FALSE; *io_fpart = '\0'; msg_size = 0; if (rp_isbad (retval = txt_read (lbuf))) return (retval); if (mkdir (msg_basedir, 0777) < 0) err_abrt (RP_FIO, "Cannot create base dir %s", msg_basedir); (void) strcpy (&io_tfname[0], msg_basedir); (void) strcat (&io_tfname[0], "/"); /* -- make io_ostrend point to the end of the string. -- */ io_ostrend = io_tfname + strlen (io_tfname); io_ofp = NULLFILE; pro_reply (RP_OK, "base %s", io_tfname); return (RP_OK); } static int txt_pinit() /* -- initialise for reading a single part of a msg -- */ { struct stat statbuf; char lbuf[LINESIZE], *p, *splt; int fd, retval; PP_DBG (("txt_pinit (%s)", io_tfname)); io_linkpart = FALSE; /* -- reset -- */ if (rp_isbad (retval = txt_read (lbuf))) return (retval); if (lbuf[0] == '\0') return (RP_DONE); if ((splt = index (lbuf, ' ')) != NULL) { *splt++ = '\0'; io_linkpart = TRUE; if (!privileged) err_abrt (RP_USER, "Mortals cannot link"); } txt_bp_check (lbuf); (void) strcpy (io_ostrend, lbuf); for (p = io_ostrend; (p = index (p, '/')) != NULL; p++) { *p = '\0'; (void) mkdir (io_tfname, 0777); *p = '/'; } if (io_linkpart) { if (link (splt, io_tfname) < 0) err_abrt (RP_FIO, "Cannot link file '%s' to '%s'", splt, io_tfname); if (*io_fpart == '\0') (void) strcpy (io_fpart, io_tfname); /* -- check message size -- */ if (stat (io_tfname, &statbuf) >= 0) msg_size += statbuf.st_size; pro_reply (RP_OK, "linked the files"); return (RP_OK); } if ((fd = open (io_tfname, O_CREAT | O_WRONLY | O_EXCL, 0644)) < 0) err_abrt (RP_FIO, "Can't create file '%s'", io_tfname); if ((io_ofp = fdopen (fd, "w")) == NULLFILE) { (void) close (fd); (void) unlink (io_tfname); *io_tfname = '\0'; err_abrt (RP_FIO, "cannot open io_tfname"); } if (*io_fpart == '\0') (void) strcpy (io_fpart, io_tfname); pro_reply (RP_OK, "file is '%s'", io_tfname); return (RP_OK); } static int txt_pend() /* -- end of the text input part -- */ { int retval = RP_OK; PP_TRACE (("txt_pend()")); (void) fflush (io_ofp); if (ferror (io_ofp)) retval = RP_FIO; if (fclose (io_ofp) == EOF) retval = RP_FIO; io_ofp = NULLFILE; if (retval == RP_OK) pro_reply (retval, "got this text part"); else pro_reply (retval, "text copy failure"); return (retval); } static void txt_in() /* -- input the text -- */ { long datalen; PP_TRACE (("txt_in()")); while (fread ((char *)&datalen, sizeof (datalen), 1, stdin) > 0) { datalen = ntohl (datalen); if (datalen == 0) return; txt_copy (stdin, io_ofp, datalen); PP_DBG (("submit/txt_in copied %d bytes",datalen)); } } static void txt_copy (ifp, ofp, len) FILE *ifp, *ofp; long len; { char buf[BUFSIZ]; int dlen, nc; PP_TRACE (("submit/txt_copy (ifp, ofp, %d)", len)); while (len > 0) { dlen = len < sizeof (buf) ? len : sizeof (buf); nc = fread (buf, sizeof (buf[0]), dlen, ifp); if (nc <= 0) err_abrt (RP_FIO, "Read error"); msg_size += nc; if (fwrite (buf, sizeof (buf[0]), nc, ofp) != nc) err_abrt (RP_FIO, "Write error"); len -= nc; } } static int txt_read (buf) /* -- read the control flow -- */ char *buf; { register int c; register char *p; PP_TRACE (("txt_read()")); for (p = buf; (c = getc (stdin)) != EOF && c != '\n'; *p++ = c); *p = '\0'; PP_DBG (("text_read - read '%.10s'", buf)); return ((c == EOF) ? RP_EOF : RP_OK); } static void txt_via (fp) FILE *fp; { char buf[BUFSIZ]; char thedate[LINESIZE]; char showstr[BUFSIZ]; UTC ut, lt; extern UTC utclocalise(); ut = utcnow(); lt = utclocalise(ut); UTC2rfc(lt, thedate); free ((char *)ut); free ((char *)lt); if (ch_inbound -> ch_ad_subtype == AD_JNT) (void) sprintf (buf, "Via: %s; %s\n", loc_dom_mta, thedate); else { if ( ch_inbound -> ch_show && (strncmp (ch_inbound -> ch_show, "via", 3) == 0 || strncmp (ch_inbound -> ch_show, "with", 4) == 0)) { strcpy (showstr, " "); strcat (showstr, ch_inbound -> ch_show); } else showstr[0] = '\0'; (void) sprintf (buf, "Received: from %s by %s%s id <%s@%s>; %s\n", mgt_inhost, loc_dom_mta, showstr, ad_unique + 4, loc_dom_mta, thedate); } fputs (buf, fp); } static void txt_bp_check (file) char *file; { char *p; if (*file == '/') err_abrt (RP_PARM, "File has full pathname %s", file); if (p = index (file, '/')) { if (!isdigit (*file) || strncmp (p - 4, ".ipm", 4) != 0) err_abrt (RP_PARM, "Not a forwarded message %s", file); txt_bp_check (++p); return; } /* -- check against content types -- */ if (strcmp (file, cont_p2) == 0 || strcmp (file, cont_p22) == 0) return; if (isdigit (*file)) { for (p = file + 1; isdigit (*p); p++) continue; if (*p != '.') err_abrt (RP_PARM, "Bad filename syntax %s", file); p++; } else p = file; /* -- check if this body part is allowed -- */ if (!txt_bptfind (bodies_all, p)) err_abrt (RP_PARM, "Unknown body part '%s'", file); /* -- check the file against the list of eits in Q -- */ if (!txt_bptfind (Qstruct.encodedinfo.eit_types, p)) err_abrt (RP_PARM, "'%s' is not specified in the orig encoded info", file); return; } static int txt_bptfind (list, item) LIST_BPT *list; char *item; { if (list_bpt_find (list, item)) return TRUE; return FALSE; }