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

  1. /*++
  2. /* NAME
  3. /*      protomsg 3
  4. /* SUMMARY
  5. /*      high-level protocol message exchange 
  6. /* PROJECT
  7. /*      pc-mail
  8. /* PACKAGE
  9. /*      cico
  10. /* SYNOPSIS
  11. /*      int isok(str)
  12. /*      char *str;
  13. /*
  14. /*      char *talk(str)
  15. /*      char *str;
  16. /*
  17. /*      char *hear()
  18. /* DESCRIPTION
  19. /*      All routines in this module exchange messages via the line
  20. /*    protocol agreed upon during communications startup.
  21. /*
  22. /*      All messages are sent including a null-byte terminator.
  23. /*
  24. /*      isok() send a request to the remote system and 
  25. /*      returns YES or NO according to the Y or N response.
  26. /*
  27. /*      talk() send a message to the remote system and returns a 
  28. /*    pointer to that message.
  29. /*
  30. /*      hear() reads the next message from the remote system and 
  31. /*      returns a pointer to the result.
  32. /* FUNCTIONS AND MACROS
  33. /*      trap(), debug()
  34. /* DIAGNOSTICS
  35. /*      isok() and hear() return via longjmp(systrap,E_LOST) in case
  36. /*    of timeout or protocol errors.
  37. /* BUGS
  38. /*      Message storage is in static buffers whose contents are overwritten
  39. /*      with each call.
  40. /* AUTHOR(S)
  41. /*      W.Z. Venema
  42. /*      Eindhoven University of Technology
  43. /*      Department of Mathematics and Computer Science
  44. /*      Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  45. /* CREATION DATE
  46. /*      Thu Mar 26 16:14:57 GMT+1:00 1987
  47. /* LAST MODIFICATION
  48. /*    Wed Apr  6 00:21:41 MET 1988
  49. /* VERSION/RELEASE
  50. /*    1.4
  51. /*--*/
  52.  
  53. #include "defs.h"
  54. #include "params.h"
  55. #include "comm.h"
  56. #include "logs.h"
  57. #include "status.h"
  58.  
  59. /* isok - send message and get yes/no response */
  60.  
  61. public int isok(msg)
  62. char *msg;
  63. {
  64.     register char *s = talk(msg);
  65.     register char *r = hear();
  66.  
  67.     if (s[0] == r[0]) {
  68.     if (r[1] == 'Y')
  69.         return(YES);
  70.     if (r[1] == 'N')
  71.         return(NO);
  72.     }
  73.     trap(E_LOST,"PROTOCOL ERROR (expected %cY or %cN, got %s)",s[0],s[0],r);
  74.     /* NOTREACHED */
  75. }
  76.  
  77. /* talk - send message to other side */
  78.  
  79. public char *talk(str)
  80. char *str;
  81. {
  82.     debug(4)("sent \"%s\"\n",str);
  83.     if (CALL(Write)(ttfd,str,strlen(str)+1) == -1)
  84.     trap(E_LOST,"FAILED (link lost)");
  85.     return(str);
  86. }
  87.  
  88. /* listen - get message from other side */
  89.  
  90. public char *hear()
  91. {
  92.     register int nread;
  93.  
  94.     if ((nread = CALL(Read)(ttfd,msgin,MSGBUF)) < 0)
  95.     trap(E_LOST,"FAILED (link lost)");
  96.     msgin[nread] = '\0';
  97.     debug(4)("got \"%s\"\n",msgin);
  98.     return(msgin);
  99. }
  100.