home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c004 / 3.ddi / VAX / CTSMSG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-18  |  5.2 KB  |  219 lines

  1. /*
  2.  *      System Dependent Server Message Handler
  3.  *      VMS MailBox Implementation
  4.  *
  5.  *    This program is the CONFIDENTIAL and PROPRIETARY property 
  6.  *    of FairCom(R) Corporation. Any unauthorized use, reproduction or
  7.  *    transfer of this program is strictly prohibited.
  8.  *
  9.  *      Copyright (c) 1988, 1989 FairCom Corporation
  10.  *    (Subject to limited distribution and
  11.  *     restricted disclosure only.)
  12.  *    *** ALL RIGHTS RESERVED ***
  13.  *
  14.  *      4006 West Broadway
  15.  *      Columbia, MO 65203
  16.  *
  17.  *
  18.  *      c-tree(R)      Version 4.3
  19.  *                      Release C
  20.  *                      February 7, 1989 17:30
  21.  *
  22.  */
  23.  
  24. #include "ctstdr.h"
  25. #include "ctoptn.h"
  26. #include "ctstrc.h"
  27. #include "cterrc.h"
  28. #include "ctcomm.h"
  29. #include "ctmssg.h"
  30.  
  31. LOCAL UCOUNT msgsiz;
  32. LOCAL LONG  *ausrmid;
  33.  
  34. extern COUNT uerr_cod;
  35.  
  36. /* elapsed time before unread user queue declared inactive */
  37. #define INDEFINITE 5    /* seconds */
  38.  
  39. /* LTYPE is defined in ctmsgg.h */
  40.  
  41. TEXT *getmid(sizmsg,maxusr)
  42. UCOUNT       sizmsg;
  43. COUNT               maxusr;
  44. {
  45.         TEXT *retval;
  46.  
  47.     long status;
  48.         TEXT *mballc();
  49.  
  50.         /* allocate an array for message ids: assumes long is OK */
  51.         if ((ausrmid = (LONG *) mballc(maxusr + 1,sizeof(LONG))) == NULL) {
  52.                 uerr_cod = SSCB_ERR;
  53.                 return(NULL);
  54.         }
  55.  
  56.         /* get message id for server */
  57.         uerr_cod = 0;
  58.  
  59.     /* open permanent mailbox to server */
  60.  
  61.     if ((status = SYS$CREMBX(1,&srvid,sizmsg,
  62.         sizmsg*MXMSG,0,PSL$C_USER,&SERVER)) != SS$_NORMAL)
  63.             uerr_cod = ASID_ERR;
  64.  
  65.         if (uerr_cod)
  66.                 return(NULL);
  67.  
  68.  
  69.         /* get space for server message */
  70.         if ((retval = mballc(1,sizmsg + LTYPE)) == NULL) {
  71.                 uerr_cod = SSPC_ERR;
  72.                 return(NULL);
  73.         }
  74.  
  75.         return(retval + LTYPE);
  76. }
  77.  
  78. LONG getumsg(pmsg,usrn,msgptr) /* assumes that mpntr member contains msg id */
  79. MESSAGE     *pmsg;
  80. COUNT             usrn;
  81. TEXT                  *msgptr;
  82. {
  83.         /* save message id of application: assumes that a long is sufficient */
  84.         if (usrn >= 0)
  85.                 ausrmid[usrn] = pmsg->mpntr;
  86.  
  87.         return(pmsg->mpntr);
  88. }
  89.  
  90. COUNT ridmid()
  91. {
  92.  
  93.         /* remove application message handling */
  94.     long status;
  95.                          
  96.     if ((status = SYS$DELMBX(srvid)) != SS$_NORMAL)
  97.                 return(uerr_cod = SMRD_ERR);
  98.         else
  99.                 return(NO_ERROR);
  100. }
  101.  
  102. COUNT dedusr(msgid)
  103. LONG         msgid;
  104. {
  105.     return(-1);
  106. }
  107.  
  108. COUNT ctrqst(msgadr,pmsg)
  109. PFAST TEXT **msgadr;
  110. MESSAGE            *pmsg;
  111. {
  112.         /* read input message */
  113.     long status;                 
  114.  
  115.     if((status = sys$qiow(1,srvid,IO$_READVBLK,&iosb,0,0,
  116.                *msgadr,CTS_MAXSMSG,0,0,0,0)) != SS$_NORMAL)
  117.                 return(uerr_cod = SRQS_ERR);
  118.  
  119.         /* copy message header */
  120.         cpybuf(pmsg,*msgadr,sizeof(MESSAGE));
  121.  
  122.         return(NO_ERROR);
  123. }
  124.  
  125. COUNT ctrspn(msgadr,pmsg,sizmsg,usrn)
  126. PFAST TEXT  *msgadr;
  127. MESSAGE            *pmsg;
  128. UCOUNT                   sizmsg;
  129. COUNT                           usrn;
  130. {
  131.         /* local copy of message id with correct type */
  132.         int locmid;
  133.     long status;
  134.  
  135.     if (usrn < 0)
  136.         usrn = - (usrn + 1);
  137.         locmid = ausrmid[usrn];
  138.  
  139.         /* copy message header */
  140.         cpybuf(msgadr,pmsg,sizeof(MESSAGE));
  141.  
  142.         /* send response */
  143.     sprintf(usrstr,"USER%04X\0",locmid);
  144.  
  145.     user.dsc$b_class = DSC$K_CLASS_D;    /* dynamic descriptor */
  146.     user.dsc$b_dtype = DSC$K_DTYPE_T;    /* character type */
  147.     user.dsc$a_pointer = usrstr;
  148.     user.dsc$w_length = strlen(usrstr);
  149.  
  150.     status = sys$assign(&user,&dummy,0,0);    /* get channel */    
  151.                      
  152.     status = sys$qiow(1,dummy,IO$_WRITEVBLK|IO$M_NOW,
  153.                 &iosb,0,0,msgadr,sizmsg,0,0,0,0);
  154.  
  155.     sys$dassgn(dummy);    /* get rid of channel */
  156.  
  157.         if (status != SS$_NORMAL)
  158.                 return(uerr_cod = SRSP_ERR);
  159.  
  160.         return(NO_ERROR);
  161.  
  162. }
  163.  
  164. COUNT norspn(usrn)
  165. COUNT        usrn;
  166. {
  167.         /* a non-zero response from norspn() indicates inactive user */
  168.  
  169.         /* current time measure */
  170.         long time();
  171.     long status;
  172.  
  173.         /* local copy of message id with correct type */
  174.         int locmid;
  175.  
  176.         locmid = ausrmid[usrn];
  177.  
  178.         /* get status of user queue  and see if it has unread messages */
  179.  
  180.     /* make attempt at getting mailbox information */
  181.                          
  182.     sprintf(usrstr,"USER%04X\0",locmid);
  183.  
  184.     user.dsc$b_class = DSC$K_CLASS_D;    /* dynamic descriptor */
  185.     user.dsc$b_dtype = DSC$K_DTYPE_T;    /* character type */
  186.     user.dsc$a_pointer = usrstr;
  187.     user.dsc$w_length = strlen(usrstr);
  188.  
  189.     status = sys$assign(&user,&dummy,0,0);    /* get channel */    
  190.                
  191.  
  192.     if (status != SS$_NORMAL)
  193.                return(YES);
  194.  
  195.         sys$dassgn(dummy);
  196.  
  197.     if (iosb.status != SS$_NORMAL)
  198.         return(YES);
  199.     else
  200.         return(NO);
  201.  
  202.         /* successful status check with no unread messages left with user */
  203.         return(NO);
  204. }
  205.  
  206. chkusrtim(usrtim,usrmap,usrtrn)
  207. LONG     *usrtim;
  208. COUNT        *usrmap;
  209. LONG               *usrtrn;
  210. {
  211.     /*
  212.      * This function can interrogate the usrtim[] array to
  213.      * determine if any active user slot is in fact dead.
  214.      */
  215.     return(NO_ERROR);
  216. }
  217.  
  218. /* end of ctsmsg.vms */
  219.