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(85-12-26,Flegel), approve(87-07-13,MCR7580),
 11      audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 12      Created.
 13   2) change(86-06-06,Westcott), approve(87-07-13,MCR7580),
 14      audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 15      remove puttdata support.
 16   3) change(86-10-21,ASmith), approve(87-07-13,MCR7580),
 17      audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 18      connect request support.
 19   4) change(86-10-22,ASmith), approve(87-07-13,MCR7580),
 20      audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 21      handle invalid requests.
 22   5) change(86-11-14,Flegel), approve(87-07-13,MCR7580),
 23      audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
 24      handle set/reset sleep bit
 25                                                    END HISTORY COMMENTS */
 26 /* : PROCEDURE FUNCTION (internal_mowse)
 27 
 28 Determine the destination of the internal mowse message depending on the
 29 minor capability number and direct control appropriately.
 30 */
 31 
 32 #include <dos.h>
 33 #include <stdio.h>
 34 #include <ws.h>
 35 #include <ws_msg.h>
 36 #include <ws_error.h>
 37 #include <wsmincap.h>
 38 #include <cat.h>
 39 
 40 #define HEADER_LENGTH 5                /* Length of message header */
 41 
 42 extern remote_cat r_CAT[];
 43 extern local_cat l_CAT[];
 44 
 45 internal_mowse(length,mowse_msgp)
 46 
 47 int     length;                        /* Length of message */
 48 struct input_msg *mowse_msgp;          /* message */
 49 {
 50 int  err_code;
 51 int  i;
 52 int  cap_index;
 53 char return_status;
 54 char capname[33];
 55 int  capname_length;
 56 int  cap_num;
 57 int  connect_request_len;
 58 char connect_request_string[WSPAKSIZ];
 59 
 60 struct alter_cat_msg *acp;
 61 struct null_msg connect_response_msg;
 62 struct null_msg mowse_message;
 63 
 64 /* : switch(minor_capability) */
 65 
 66    switch(mowse_msgp -> minor)
 67    {
 68 
 69 /* : - case EXECUTE_COMMAND   */
 70 
 71       case WS_EXECUTE_COMMAND :
 72 
 73          EXECUTE_COMMAND(length,mowse_msgp);
 74          break;
 75 
 76 /* : - case ADD_TO_REMOTE_CAT           */
 77 
 78       case WS_ADD_TO_RAT:
 79 
 80          acp = (struct alter_cat_msg *) mowse_msgp;
 81          return (add_to_remote_cat(acp -> source_system,acp -> rat_major,&acp -> major_name[0]));
 82 
 83 /* : DELETE_FROM_REMOTE_CAT */
 84 
 85       case WS_DELETE_FROM_RAT:
 86 
 87          acp = (struct alter_cat_msg *) mowse_msgp;
 88          if (acp -> source_system == WSIBMPC)
 89             return(WSINVSYS);
 90          cap_index = acp -> rat_major - MIN_CAPABILITY_NUMBER;
 91          if ((cap_index < 0) || (cap_index > NUMBER_OF_CAT_ENTRIES))
 92             return(WSINVNUM);
 93          r_CAT[cap_index].major_capability = 0;
 94          r_CAT[cap_index].system_id = 0;
 95          r_CAT[cap_index].flags = 0;
 96          i = 0;
 97          while (r_CAT[cap_index].capability_name[i] != 0)
 98             r_CAT[cap_index].capability_name[i++] = 0;
 99          return(0);
100 
101 /* : - case WS_SET_SLEEP_FLAG
102      -- set the sleep flag on the appropriate remote appllcation */
103 
104       case WS_SET_SLEEP_FLAG:
105 
106          cap_index = (int)mowse_msgp -> source_major - MIN_CAPABILITY_NUMBER;
107          if ((cap_index < 0) || (cap_index > NUMBER_OF_CAT_ENTRIES))
108             return (0);
109          r_CAT[cap_index].flags |= SLEEPING_BIT;
110          return (0);
111 
112 /* : - case WS_RESET_SLEEP_FLAG
113      -- set the sleep flag on the appropriate remote appllcation */
114 
115       case WS_RESET_SLEEP_FLAG:
116 
117          cap_index = (int)mowse_msgp -> source_major - MIN_CAPABILITY_NUMBER;
118          if ((cap_index < 0) || (cap_index > NUMBER_OF_CAT_ENTRIES))
119             return (0);
120          r_CAT[cap_index].flags &= ~SLEEPING_BIT;
121          return (0);
122 
123 /* : - case RESET_REPLY
124      -- clear the flag on the source capability (message always comes
125         from remote) */
126 
127       case RESET_REPLY:
128 
129          cap_index = mowse_msgp -> source_major - MIN_CAPABILITY_NUMBER;
130          if ((cap_index < 0) || (cap_index > NUMBER_OF_CAT_ENTRIES))
131             return (0);
132          r_CAT[cap_index].flags &= ~RESET_BIT;
133          return (0);
134 
135 /* : - case REQUEST_CONNECT
136      -- get the name of the capability to send connect request to */
137 
138       case REQUEST_CONNECT:
139 
140          capname_length = min(length - HEADER_LENGTH, CAPABILITY_NAME_LENGTH);
141          for (i=0; i < capname_length && mowse_msgp -> msg_data[i] != ' '; i++)
142             capname[i] = mowse_msgp -> msg_data[i];
143          capname[i] = '\0';
144 
145          connect_request_len = min(length-HEADER_LENGTH,WSPAKSIZ);
146 
147          for (i=0; i < connect_request_len; i++)
148             connect_request_string[i] = mowse_msgp -> msg_data[i];
149          connect_request_string[i] = '\0';
150 
151 /* : - try to find the capability
152      - If it is not found then create it */
153 
154          cap_num = find_local_capability(capname);
155          err_code = 0;
156          if (cap_num == 0) {
157             set_dta();
158             set_trap();
159             err_code = system(connect_request_string);
160             rst_trap();
161             rst_dta();
162             cap_num = find_local_capability(capname);
163          }
164 
165 /* : - If the capability still can't be found then send a message
166        back to the capability requesting the connection indicating
167        that the connect request has failed */
168 
169          if ((cap_num == 0) || (err_code != 0)) {
170             connect_response_msg.system = mowse_msgp -> source_system;
171             connect_response_msg.major = mowse_msgp -> source_major;
172             connect_response_msg.minor = RESPONSE_CONNECT;
173             connect_response_msg.source_system = WSIBMPC;
174             connect_response_msg.source_major = WSMAJCAP;
175             return_status = WSREJECT;
176             return (send_i_mess(&connect_response_msg,HEADER_LENGTH,&return_status,1));
177          }
178 
179 /* : otherwise send the connect request message onto the capability
180      found locally */
181 
182          mowse_message.system = WSIBMPC;
183          mowse_message.major = cap_num & 0xff;
184          mowse_message.minor = REQUEST_CONNECT;
185          mowse_message.source_system = mowse_msgp -> source_system;
186          mowse_message.source_major = mowse_msgp -> source_major;
187          return (send_i_mess(&mowse_message,HEADER_LENGTH,NULL,0));
188 
189 /* : case SET_SUSPEND
190      - set the suspend flag in the remote cat for the sepcified cap */
191 
192       case SET_SUSPEND:
193 
194          cap_index = mowse_msgp -> source_major - MIN_CAPABILITY_NUMBER;
195          if ((cap_index < 0) || (cap_index > NUMBER_OF_CAT_ENTRIES))
196             return (0);
197          r_CAT[cap_index].flags |= SUSPENDED_BIT;
198          return (0);
199 
200 /* : case RESET_SUSPEND
201      - reset the suspend flag in the remote cat for the sepcified cap */
202 
203       case RESET_SUSPEND:
204 
205          cap_index = mowse_msgp -> source_major - MIN_CAPABILITY_NUMBER;
206          if ((cap_index < 0) || (cap_index > NUMBER_OF_CAT_ENTRIES))
207             return (0);
208          r_CAT[cap_index].flags &= ~SUSPENDED_BIT;
209          return (0);
210 
211 /* : case FAIL CAPABILITY:
212      - ignore the message */
213 
214       case FAIL_CAPABILITY:
215 
216          return (0);
217 
218 /* : default: Return (invalid minor capability) only if source was not internal */
219 
220       default:
221 
222          if (mowse_msgp -> source_major == WSMAJCAP)
223             return (0);
224          mowse_message.system = mowse_msgp -> source_system;
225          mowse_message.major = mowse_msgp -> source_major;
226          mowse_message.minor = FAIL_CAPABILITY;
227          mowse_message.source_system = WSIBMPC;
228          mowse_message.source_major = WSMAJCAP;
229          return (send_i_mess(&mowse_message,HEADER_LENGTH,NULL,0));
230    }
231    return(0);
232 }
233 ^Z