home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume3 / pcmail / part05 / sendwork.c < prev    next >
C/C++ Source or Header  |  1989-02-03  |  4KB  |  155 lines

  1. /*++
  2. /* NAME
  3. /*      sendwork 3
  4. /* SUMMARY
  5. /*      send local work to remote system
  6. /* PROJECT
  7. /*      pc-mail
  8. /* PACKAGE
  9. /*      cico
  10. /* SYNOPSIS
  11. /*      #include "work.h"
  12. /*
  13. /*      void sendwork(wrk)
  14. /*      work *wrk;
  15. /* DESCRIPTION
  16. /*      sendwork converts names and contents of local work files,
  17. /*    sends them to the remote system and deletes the files after 
  18. /*    successfull transfer.
  19. /*
  20. /*    In particular, it generates appropriate "From " lines at the
  21. /*    beginning of an outgoing mail message.
  22. /* FUNCTIONS AND MACROS
  23. /*      rmtname()
  24. /* SEE ALSO
  25. /*      scanwork(3)     locates work in the spool directory
  26. /*      rmtname(3)      rules for remote file name construction
  27. /* DIAGNOSTICS
  28. /*    sendwork() returns via longjmp(systrap,errorcode) in case
  29. /*    of unrecoverable problems.
  30. /*
  31. /*    The error codes are: E_CONFUSED (unexpected work type),
  32. /*    E_LOST (timed out), E_READERR (file read error).
  33. /* AUTHOR(S)
  34. /*      W.Z. Venema
  35. /*      Eindhoven University of Technology
  36. /*      Department of Mathematics and Computer Science
  37. /*      Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  38. /* CREATION DATE
  39. /*      Thu Mar 26 11:32:23 GMT+1:00 1987
  40. /* LAST MODIFICATION
  41. /*    Wed Apr  6 00:22:23 MET 1988
  42. /* VERSION/RELEASE
  43. /*    1.4
  44. /*--*/
  45.  
  46. #include <time.h>
  47. #include "defs.h"
  48. #include "work.h"
  49. #include "logs.h"
  50. #include "status.h"
  51. #include "params.h"
  52. #include "comm.h"
  53.  
  54. extern struct tm *localtime();            /* std C library */
  55.  
  56. /*
  57. * A pc-mail system can connect to the UNIX net in at least two modes:
  58. *
  59. * 1. As a real UUCP node, with it's own node name. This node name will
  60. * have to appear in the "From " lines of outgoing mail. A consequence 
  61. * is that the pc mail node name should be known in mailer routing tables.
  62. * Obviously this implies some administrative work when a pc mail node 
  63. * is added to the net or taken out of operation. 
  64. *
  65. * 2. As an ordinary user. The program lets the UNIX host believe that
  66. * mail messages come from an ordinary user. Recipients of mail will
  67. * not be able to see that the mail came from the pc. Only the UNIX host 
  68. * knows it should forward mail for unixhost!xyz to the pc-mail node.
  69. * This approach has the advantage that adding/deleting pc-mail nodes 
  70. * is simpler.
  71. */
  72.  
  73. #ifdef    UUCP_NODE                /* case 1 */
  74. #   define U_USER    "root"            /* use current user's name */
  75. #   define U_HOST    LOGIN_NAME        /* use pc host name */
  76. #else                        /* case 2 */
  77. #   define U_USER    LOGIN_NAME        /* use remote login name */
  78. #   define U_HOST    rmthost            /* use remote host name */
  79. #endif
  80.  
  81. /* sendwork - adapt file contents for remote host */
  82.  
  83. public sendwork(wrk)
  84. work *wrk;
  85. {
  86.     register char *date;
  87.     long secs;
  88.  
  89.     switch (wrk->type) {
  90.  
  91.     /* 
  92.     * Local D files contain the mail message, nothing more, nothing less.
  93.     * We add a "From " line with originator/date/system.
  94.     * Otherwise, D files can be sent as is.
  95.     */
  96.  
  97.     case 'D':
  98.     secs = time((long *)0);
  99.     (date = asctime(localtime(&secs)))[24] = '\0';
  100.     say(strcons("From %s %s remote from %s\n",U_USER,date,U_HOST));
  101.     send_file(wrk->fp);
  102.     break;
  103.  
  104.     /* 
  105.     * Local X files contain the destination network address only.
  106.     * Therefore we must mock up some extra info to make the 
  107.     * remote uuxqt program happy.
  108.     */
  109.  
  110.     case 'X':
  111.     say(strcons("U %s %s\n",U_USER,U_HOST));    /* U user system */
  112.     say(strcons("F %s\n",rmtname('D',wrk->tail)));    /* F D.rmtsysGnumber */
  113.     say(strcons("I %s\n",rmtname('D',wrk->tail)));    /* I D.rmtsysGnumber */
  114.     say("C rmail ");                /* C rmail */
  115.     send_file(wrk->fp);                /* send destination */
  116.     break;
  117.  
  118.     default:
  119.     trap(E_CONFUSED,"INTERNAL ERROR (unexpected work type: %c)",wrk->type);
  120.     }
  121. }
  122.  
  123. /* say - write string to host */
  124.  
  125. hidden say(str)
  126. char *str;
  127. {
  128.     if (CALL(Write)(ttfd,str,strlen(str)) < 0)
  129.     trap(E_LOST,"FAILED (link lost)");
  130. }
  131.  
  132. /* send_file - do the nitty-gritty of file transfer; traps on all errors */
  133.  
  134. hidden send_file(fp)
  135. register FILE *fp;
  136. {
  137.     register int nread,nwrite = 0;
  138.     char buf[BUFSIZ];
  139.     register int rerror;
  140.  
  141.     while ((nread = fread(buf,sizeof(*buf),sizeof(buf),fp)) > 0 &&
  142.     (nwrite = CALL(Write)(ttfd,buf,nread)) == nread)
  143.     /* empty */;
  144.     rerror = ferror(fp);
  145.     fclose(fp);
  146.  
  147.     if (rerror) {
  148.     trap(E_READERR,"FILE READ ERROR (%s)",sys_errlist[errno]);
  149.     /* NOTREACHED */
  150.     } else if (nwrite < 0 || CALL(Write)(ttfd,buf,0) != 0) {
  151.     trap(E_LOST,"FAILED (link lost)");
  152.     /* NOTREACHED */
  153.     }
  154. }
  155.