home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / communic / pcmail / main / sendwork.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  4.9 KB  |  323 lines

  1. /*++
  2.  
  3. /* NAME
  4.  
  5. /*      sendwork 3
  6.  
  7. /* SUMMARY
  8.  
  9. /*      send local work to remote system
  10.  
  11. /* PROJECT
  12.  
  13. /*      pc-mail
  14.  
  15. /* PACKAGE
  16.  
  17. /*      cico
  18.  
  19. /* SYNOPSIS
  20.  
  21. /*      #include "work.h"
  22.  
  23. /*
  24.  
  25. /*      void sendwork(wrk)
  26.  
  27. /*      work *wrk;
  28.  
  29. /* DESCRIPTION
  30.  
  31. /*      sendwork converts names and contents of local work files,
  32.  
  33. /*    sends them to the remote system and deletes the files after 
  34.  
  35. /*    successfull transfer.
  36.  
  37. /*
  38.  
  39. /*    In particular, it generates appropriate "From " lines at the
  40.  
  41. /*    beginning of an outgoing mail message.
  42.  
  43. /* SEE ALSO
  44.  
  45. /*      scanwork(3)     locates work in the spool directory
  46.  
  47. /* DIAGNOSTICS
  48.  
  49. /*    sendwork() returns via longjmp(systrap,errorcode) in case
  50.  
  51. /*    of unrecoverable problems.
  52.  
  53. /*
  54.  
  55. /*    The error codes are: E_CONFUSED (unexpected work type),
  56.  
  57. /*    E_LOST (timed out), E_READERR (file read error).
  58.  
  59. /* AUTHOR(S)
  60.  
  61. /*      W.Z. Venema
  62.  
  63. /*      Eindhoven University of Technology
  64.  
  65. /*      Department of Mathematics and Computer Science
  66.  
  67. /*      Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  68.  
  69. /* CREATION DATE
  70.  
  71. /*      Thu Mar 26 11:32:23 GMT+1:00 1987
  72.  
  73. /* LAST MODIFICATION
  74.  
  75. /*    90/01/22 13:02:35
  76.  
  77. /* VERSION/RELEASE
  78.  
  79. /*    2.1
  80.  
  81. /*--*/
  82.  
  83.  
  84.  
  85. #include <stdio.h>
  86.  
  87. #include <time.h>
  88.  
  89.  
  90.  
  91. #include "defs.h"
  92.  
  93. #include "work.h"
  94.  
  95. #include "logs.h"
  96.  
  97. #include "status.h"
  98.  
  99. #include "params.h"
  100.  
  101. #include "comm.h"
  102.  
  103.  
  104.  
  105. extern struct tm *localtime();        /* std C library */
  106.  
  107.  
  108.  
  109.  /*
  110.  
  111.   * A pc-mail system can connect to the UNIX net in at least two modes:
  112.  
  113.   * 
  114.  
  115.   * 1. As a real UUCP node, with it's own node name. This node name will have to
  116.  
  117.   * appear in the "From " lines of outgoing mail. A consequence is that the
  118.  
  119.   * pc mail node name should be known in mailer routing tables. Obviously
  120.  
  121.   * this implies some administrative work when a pc mail node is added to the
  122.  
  123.   * net or taken out of operation.  This mode has not been tested by the
  124.  
  125.   * author.
  126.  
  127.   * 
  128.  
  129.   * 2. As an ordinary user. The program lets the UNIX host believe that mail
  130.  
  131.   * messages come from an ordinary user. Recipients of mail will not be able
  132.  
  133.   * to see that the mail came from the pc. Only the UNIX host knows it should
  134.  
  135.   * forward mail for unixhost!xyz to the pc-mail node. This approach has the
  136.  
  137.   * advantage that adding/deleting pc-mail nodes is simpler.
  138.  
  139.   */
  140.  
  141.  
  142.  
  143. #ifdef    UUCP_NODE            /* case 1 */
  144.  
  145. #   define UUSER    "root"        /* use current user's name */
  146.  
  147. #   define UHOST    LOGIN_NAME    /* use pc host name */
  148.  
  149. #else                    /* case 2 */
  150.  
  151. #   define UUSER    LOGIN_NAME    /* use remote login name */
  152.  
  153. #   define UHOST    rmthost        /* use remote host name */
  154.  
  155. #endif
  156.  
  157.  
  158.  
  159. /* sendwork - adapt file contents for remote host */
  160.  
  161.  
  162.  
  163. public  sendwork(wrk)
  164.  
  165. work   *wrk;
  166.  
  167. {
  168.  
  169.     long    secs;
  170.  
  171.     char    buf[MAXLINE];        /* recipient addresses */
  172.  
  173.  
  174.  
  175.     switch (wrk->type) {
  176.  
  177.  
  178.  
  179.     /*
  180.  
  181.      * Local D files contain the mail message. Except for the addition of
  182.  
  183.      * a UUCP-style "From " line (with originator/date/system), D files
  184.  
  185.      * are sent without modification.
  186.  
  187.      */
  188.  
  189.  
  190.  
  191.     case 'd':
  192.  
  193.     case 'D':
  194.  
  195.     secs = time((long *) 0);
  196.  
  197.     say(strcons("From %s %.24s remote from %s\n",
  198.  
  199.             UUSER, asctime(localtime(&secs)), UHOST));
  200.  
  201.     send_file(wrk->fp);
  202.  
  203.     break;
  204.  
  205.  
  206.  
  207.     /*
  208.  
  209.      * The first line of local X files contains the destination address.
  210.  
  211.          * Real UUCP expects something entirely different.
  212.  
  213.          *
  214.  
  215.      * We make up some extra info to make the remote uuxqt program happy.
  216.  
  217.      */
  218.  
  219.  
  220.  
  221.     case 'x':
  222.  
  223.     case 'X':
  224.  
  225.     say(strcons("U %s %s\n", UUSER, UHOST));/* U user system */
  226.  
  227.     say(strcons("F %s\n",
  228.  
  229.             rmtname('D', wrk->seqno)));    /* F D.rmtsysGnumber */
  230.  
  231.     say(strcons("I %s\n",
  232.  
  233.             rmtname('D', wrk->seqno)));    /* I D.rmtsysGnumber */
  234.  
  235.     say("C rmail ");            /* C rmail */
  236.  
  237.     (void) fgets(buf, sizeof(buf), wrk->fp);/* read destinations */
  238.  
  239.     say(buf);                /* send destinations */
  240.  
  241.     say("");                /* send EOF */
  242.  
  243.     break;
  244.  
  245.  
  246.  
  247.     default:
  248.  
  249.     trap(E_CONFUSED, "INTERNAL ERROR (unexpected work type: %c)", wrk->type);
  250.  
  251.     }
  252.  
  253. }
  254.  
  255.  
  256.  
  257. /* say - write string to host */
  258.  
  259.  
  260.  
  261. hidden  say(str)
  262.  
  263. char   *str;
  264.  
  265. {
  266.  
  267.     if (CALL(Write) (ttfd, str, strlen(str)) < 0)
  268.  
  269.     trap(E_LOST, "FAILED (link lost)");
  270.  
  271. }
  272.  
  273.  
  274.  
  275. /* send_file - do the nitty-gritty of file transfer; traps on all errors */
  276.  
  277.  
  278.  
  279. hidden  send_file(fp)
  280.  
  281. register FILE *fp;
  282.  
  283. {
  284.  
  285.     register int nread;
  286.  
  287.     register int nwrite = 0;
  288.  
  289.     char    buf[BUFSIZ];
  290.  
  291.     register int rerror;
  292.  
  293.  
  294.  
  295.     while ((nread = fread(buf, sizeof(*buf), sizeof(buf), fp)) > 0
  296.  
  297.        && (nwrite = CALL(Write) (ttfd, buf, nread)) == nread)
  298.  
  299.      /* void */ ;
  300.  
  301.     rerror = ferror(fp);
  302.  
  303.     fclose(fp);
  304.  
  305.  
  306.  
  307.     if (rerror) {
  308.  
  309.     trap(E_READERR, "FILE READ ERROR (%s)", sys_errlist[errno]);
  310.  
  311.     /* NOTREACHED */
  312.  
  313.     } else if (nwrite < 0 || CALL(Write) (ttfd, buf, 0) != 0) {
  314.  
  315.     trap(E_LOST, "FAILED (link lost)");
  316.  
  317.     /* NOTREACHED */
  318.  
  319.     }
  320.  
  321. }
  322.  
  323.