1 /* ***********************************************************
  2    *                                                         *
  3    * Copyright, (C) Honeywell Bull Inc., 1987                *
  4    *                                                         *
  5    * Copyright, (C) Honeywell Information Systems Inc., 1986 *
  6    *                                                         *
  7    *********************************************************** */
  8 
  9 /* HISTORY COMMENTS:
 10   1) change(86-06-01,Westcott), approve(87-07-13,MCR7580),
 11      audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 12      Created.
 13   2) change(86-11-24,Flegel), approve(87-07-13,MCR7580),
 14      audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 15      Check to make sure that it is safe to send
 16      to the destination (is it suspended?).
 17                                                    END HISTORY COMMENTS */
 18 
 19 /* : PROCEDURE FUNCTION (sendimsg):
 20 
 21 This module is used by internal mowse programs to send an internal mowse
 22 minor capability message to another application.
 23 */
 24 
 25 #include <stdio.h>
 26 #include <dos.h>
 27 #include <ws.h>
 28 #include <alloc.h>
 29 #include <ws_error.h>
 30 #include <ws_msg.h>
 31 #include <ws_fgb.h>
 32 #include <cat.h>
 33 #include <wsmincap.h>
 34 
 35 extern struct allocstr *lcaptr;
 36 extern struct fgbstr   *lcbfptr,
 37                        *lcblptr;
 38 extern char            mysystem;
 39 extern local_cat       l_CAT[];        /* Local CAT */
 40 extern remote_cat      r_CAT[];        /* Remote CAT */
 41 
 42 send_i_mess (p_message,p_message_len,p_data,p_data_len)
 43 
 44 struct input_msg  *p_message;          /* Message header */
 45 int     p_message_len;                 /* length of header */
 46 char    *p_data;                       /* Data in message */
 47 int     p_data_len;                    /* Length of data in message */
 48 {
 49 char *flags;                           /* Flags of application */
 50 char header[6];                        /* Header string */
 51 char *data_ptrs[2];                    /* Message pieces */
 52 int  data_lens[2];                     /* Message piece lengths */
 53 int  major;                            /* Major capability index into CAT */
 54 int  error;
 55 int  total_len;                        /* Combined length of message */
 56 int  i;
 57 char *c1;                              /* Copy pointers */
 58 char *c2;
 59 struct fgbstr *bufp;                   /* Mesage buffer for local messages */
 60 struct fgbstr *lcbp1;                  /* Temp pointer for local message insertion */
 61 
 62 char *wsalloc();
 63 
 64 
 65 /* : Get the flags of the destination application, at the same time, make
 66      sure the capability exists */
 67 
 68    major = (int) (p_message -> major) - MIN_CAPABILITY_NUMBER;
 69    if ((major < 0) || (major > NUMBER_OF_CAT_ENTRIES))
 70    {  if (p_message -> major != WSMAJCAP)
 71          return (WSINVNUM);
 72       flags = NULL;
 73    }
 74    else if (p_message -> system == mysystem)
 75    {  if (!l_CAT[major].mcb_ptr)
 76          return (WSINVNUM);
 77       flags = &(l_CAT[major].flags);
 78    }
 79    else
 80    {  if (!r_CAT[major].major_capability)
 81          return (WSINVNUM);
 82       flags = &(r_CAT[major].flags);
 83    }
 84 
 85 /* : If something about the flags says that we shouldn't send, return suspended */
 86 
 87    if (flags)
 88    {  if ((*flags & (SUSPENDED_BIT | RESET_BIT))
 89          && (p_message -> minor != TERMINATE_APPLICATION)
 90          && (p_message -> minor != RESUME_APPLICATION)
 91          && (p_message -> minor != SUSPEND_APPLICATION)
 92          && (p_message -> minor != RESET_APPLICATION)
 93          && (p_message -> minor != FAIL_CAPABILITY))
 94       {
 95          return (WSSUSPND);
 96       }
 97    }
 98 
 99 /* : if message is addressed to this system  */
100 
101    if (p_message -> system == mysystem) {
102       total_len = p_message_len + p_data_len;
103       bufp = (struct fgbstr *)wsalloc (lcaptr,total_len+sizeof(struct fgbstr));
104 
105 /* : - copy to local capability buffer */
106 
107       if (bufp != NULL) {
108          c1 = (char *) p_message;
109          c2 = &bufp -> fgb_char[0];
110          for (i = 0;i < p_message_len;i++) {
111             *c2++ = *c1++;
112          }
113          c1 = p_data;
114          for (i = 0;i < p_data_len;i++) {
115             *c2++ = *c1++;
116          }
117          bufp -> fgb_length = total_len;
118 
119 /* : - link to previous local capability buffers  */
120 
121          bufp -> fgb_next = NULL;
122          if (lcbfptr == NULL) {        /* Head */
123             lcbfptr = bufp;
124             lcblptr = bufp;
125          }
126          else {                        /* Tail */
127             lcbp1 = lcblptr;
128             lcbp1 -> fgb_next = bufp;
129             lcblptr = bufp;
130          }
131          return(0);
132       }
133       return(WSBUFOVR);
134    }
135 /* : else message is addressed to remote system
136      - set up structure for snddat */
137 
138    else {
139       data_ptrs[0] = (char *) p_message;
140       data_lens[0] = p_message_len;
141       data_ptrs[1] = p_data;
142       data_lens[1] = p_data_len;
143 
144 /* : - while (message not sent because window full) try and send 2 messages */
145    while (snddat (BG, 2 ,&data_ptrs,&data_lens) == 1);
146 
147 /* : - return with error code
148      -- = 0, if message sent
149      -- = WSBUFOVR, if message too long */
150 
151    if (error == -1)
152       return (WSBUFOVR);
153    return(0);
154    }
155 }
156 ^Z