1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 #include <stdio.h>
36 #include <ws.h>
37 #include <ws_msg.h>
38 #include <wsmincap.h>
39 #include <ws_mcb.h>
40 #include <ws_func.h>
41 #include <ws_error.h>
42
43 #define TRUE 1
44 #define FALSE 0
45
46 pe (p_mcb_ptr, p_minor_cap, p_bufseg, p_bufoff, p_buflen)
47
48 mcb *p_mcb_ptr;
49 char p_minor_cap;
50 int p_bufseg;
51 int p_bufoff;
52 int p_buflen;
53 {
54 int link_info_size;
55 int msg_header_size;
56 int sender_major;
57 int code;
58 struct more_msg more_message;
59 struct input_msg *message;
60
61
62
63 if (p_mcb_ptr -> mcb_flag & MCB_NULL_ROUTINE)
64 return (0);
65
66
67
68 msg_header_size = sizeof(more_message)-2;
69 link_info_size = sizeof(struct linklst)-2;
70 peek (p_bufseg,p_bufoff,&more_message, msg_header_size);
71 message = (struct input_msg *) (&more_message);
72
73
74
75 switch ((int) p_minor_cap)
76 {
77 case CONTINUE_MESSAGE:
78
79 return (handle_continue (p_mcb_ptr, &more_message));
80
81 case PARTIAL_MESSAGE:
82
83 return (handle_partial (p_mcb_ptr, p_buflen, p_bufseg, p_bufoff,
84 msg_header_size, link_info_size, &more_message));
85
86 case RESUME_APPLICATION:
87
88 if (!(p_mcb_ptr -> mcb_flag & MCB_SUSPEND))
89 return (WSNOSPND);
90 p_mcb_ptr -> mcb_flag &= ~MCB_SUSPEND;
91 code = forward (p_mcb_ptr, message -> minor, &(message -> msg_data[0]),
92 p_buflen, message -> source_system, message -> source_major);
93 return (code);
94
95 case SUSPEND_APPLICATION:
96
97 if (p_mcb_ptr -> mcb_flag & MCB_SUSPEND)
98 return (WSSUSPND);
99 code = forward (p_mcb_ptr, message -> minor, &(message -> msg_data[0]),
100 p_buflen, message -> source_system, message -> source_major);
101 p_mcb_ptr -> mcb_flag |= MCB_SUSPEND;
102 return (code);
103
104 case RESET_APPLICATION:
105
106 return (handle_reset (p_mcb_ptr, message, p_buflen));
107
108 case FAIL_CAPABILITY:
109 case SYSTEM_ERROR:
110
111 return (handle_fail (p_mcb_ptr, message, p_buflen));
112
113 case TERMINATE_APPLICATION:
114
115 code = forward (p_mcb_ptr, message -> minor, &(message -> msg_data[0]),
116 p_buflen, message -> source_system, message -> source_major);
117 return (code);
118
119 default:
120
121 return (handle_default (p_mcb_ptr, p_buflen, p_bufseg, p_bufoff, p_minor_cap,
122 msg_header_size, link_info_size, &more_message));
123 }
124 }
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145 llpfree (core,first,llp)
146
147 struct allocstr *core;
148 struct linklst **first;
149 struct linklst *llp;
150 {
151 struct linklst *llp1;
152
153
154
155
156 llp1 = *first;
157 if (llp1 == llp)
158 *first = llp1 -> nextbuf;
159 else
160 { while (llp1 != NULL)
161 { if (llp1->nextbuf == llp)
162 { llp1->nextbuf = llp->nextbuf;
163 break;
164 }
165 llp1 = llp1->nextbuf;
166 }
167 }
168
169
170
171 while (llp != NULL)
172 { llp1 = llp->nextlink;
173 wsfree(core,llp);
174 llp = llp1;
175 }
176 }
177
178
179
180
181
182
183
184
185 forward (p_mcb_ptr, p_minor, p_data, p_data_len, p_source_system, p_source_major)
186
187 mcb *p_mcb_ptr;
188 char p_minor;
189 char *p_data;
190 int p_data_len;
191 char p_source_system;
192 char p_source_major;
193 {
194 int major_sender;
195
196 major_sender = (p_source_system << 8) | p_source_major;
197
198
199
200 if ((p_mcb_ptr -> mcb_flag & MCB_SUSPEND) && (p_minor != TERMINATE_APPLICATION)
201 && (p_minor != RESUME_APPLICATION) && (p_minor != SUSPEND_APPLICATION))
202 {
203 return (execap (major_sender, FAIL_CAPABILITY, NULL, 0, p_mcb_ptr));
204 }
205
206
207
208 (*p_mcb_ptr -> application_entry)
209 ((int)p_minor, major_sender, p_data, p_data_len,
210 p_mcb_ptr -> data_block_ptr, p_mcb_ptr);
211
212 return (0);
213 }
214
215
216
217
218
219
220
221
222 BUG
223
224
225
226
227 handle_reset (p_mcb_ptr, p_message, p_message_len)
228
229 mcb *p_mcb_ptr;
230 struct input_msg *p_message;
231 int p_message_len;
232 {
233 struct linklst *msg_buffer;
234 struct linklst *next_buf;
235
236
237
238 msg_buffer = p_mcb_ptr -> inbuff;
239 while (msg_buffer != NULL)
240 { next_buf = msg_buffer -> nextbuf;
241 llpfree (p_mcb_ptr -> inalloc, &(p_mcb_ptr -> inbuff), msg_buffer);
242 msg_buffer = next_buf;
243 }
244 p_mcb_ptr -> inbuff = NULL;
245
246
247
248 msg_buffer = p_mcb_ptr -> outbuff;
249 while (msg_buffer != NULL)
250 { next_buf = msg_buffer -> nextbuf;
251 llpfree (p_mcb_ptr -> outalloc, &(p_mcb_ptr -> outbuff), msg_buffer);
252 msg_buffer = next_buf;
253 }
254 p_mcb_ptr -> outbuff = NULL;
255
256
257
258 forward (p_mcb_ptr, p_message -> minor, &(p_message -> msg_data [0]),
259 p_message_len, p_message -> source_system, p_message -> source_major);
260 }
261
262
263
264
265
266
267
268 handle_fail (p_mcb_ptr, p_message, p_message_len)
269
270 mcb *p_mcb_ptr;
271 struct input_msg *p_message;
272 int p_message_len;
273 {
274 struct linklst *msg_buffer;
275 struct linklst *next_buf;
276
277
278
279 msg_buffer = p_mcb_ptr -> outbuff;
280 while (msg_buffer != NULL)
281 { next_buf = msg_buffer -> nextbuf;
282 llpfree (p_mcb_ptr -> outalloc, &(p_mcb_ptr -> outbuff), msg_buffer);
283 msg_buffer = next_buf;
284 }
285 p_mcb_ptr -> outbuff = NULL;
286
287
288
289 forward (p_mcb_ptr, p_message -> minor, &(p_message -> msg_data [0]),
290 p_message_len, p_message -> source_system, p_message -> source_major);
291 }
292
293
294
295
296
297
298
299
300
301
302 handle_partial (p_mcb_ptr, p_buflen, p_bufseg, p_bufoff, p_msg_hdr_size, p_link_info_size, p_more_message)
303
304 mcb *p_mcb_ptr;
305 int p_bufseg;
306 int p_bufoff;
307 int p_buflen;
308 int p_msg_hdr_size;
309 int p_link_info_size;
310 struct more_msg *p_more_message;
311
312 {
313 int found;
314 int done;
315 int buffer_size;
316 int amount_to_copy;
317 int major_sender;
318 int i;
319 char *more_msg_header1;
320 char *more_msg_header2;
321 struct linklst *msg_buffer;
322 struct linklst *prev_msg_buffer;
323 struct linklst *new_msg_buffer;
324
325
326 msg_buffer = p_mcb_ptr->inbuff;
327 prev_msg_buffer = p_mcb_ptr->inbuff;
328
329
330
331 found = done = FALSE;
332 while ((found == FALSE) && (done == FALSE))
333 { if (msg_buffer == NULL)
334 done = TRUE;
335 else
336 { more_msg_header1 = (char *) msg_buffer->lldata;
337 more_msg_header2 = (char *) p_more_message;
338
339 if (!strncmp(more_msg_header1,more_msg_header2,p_msg_hdr_size))
340 found = done = TRUE;
341 else
342 { prev_msg_buffer = msg_buffer;
343 msg_buffer = msg_buffer->nextbuf;
344 }
345 }
346 }
347
348
349
350 if (found == FALSE)
351 { buffer_size = p_mcb_ptr->inbuff_length + p_link_info_size + p_msg_hdr_size;
352 new_msg_buffer = (struct linklst *) wsalloc(p_mcb_ptr->inalloc, buffer_size);
353
354
355
356 if (new_msg_buffer != NULL)
357 { new_msg_buffer->linksize = buffer_size;
358 amount_to_copy = min(buffer_size-p_link_info_size,p_buflen);
359 peek(p_bufseg,p_bufoff,new_msg_buffer->lldata,amount_to_copy);
360 new_msg_buffer->nextlink = NULL;
361 new_msg_buffer->nextbuf = NULL;
362 new_msg_buffer->linkused = amount_to_copy;
363
364 if (prev_msg_buffer == p_mcb_ptr->inbuff)
365 p_mcb_ptr->inbuff = new_msg_buffer;
366 else
367 prev_msg_buffer->nextbuf = new_msg_buffer;
368 }
369
370
371
372 else
373 { buffer_size = p_msg_hdr_size+p_link_info_size+1;
374 new_msg_buffer = (struct linklst *) wsalloc(p_mcb_ptr->inalloc,buffer_size);
375
376 if (new_msg_buffer != NULL)
377 { for (i=0; i<p_msg_hdr_size; i++)
378 new_msg_buffer->lldata[i] = *(((char *) p_more_message)+i);
379
380 new_msg_buffer->nextlink = NULL;
381 new_msg_buffer->nextbuf = NULL;
382 new_msg_buffer->linkused = buffer_size;
383 new_msg_buffer->linksize = buffer_size;
384
385 if (prev_msg_buffer == p_mcb_ptr->inbuff)
386 p_mcb_ptr->inbuff = new_msg_buffer;
387 else
388 prev_msg_buffer->nextbuf = new_msg_buffer;
389 }
390
391
392
393 else
394 { major_sender = p_more_message -> source_major;
395 major_sender = (major_sender << 8) | p_more_message -> minor;
396 return (execap(major_sender, FAIL_CAPABILITY, NULL, 0, p_mcb_ptr));
397 }
398 }
399 }
400
401
402
403 if (found == TRUE)
404 { amount_to_copy = min((p_buflen-p_msg_hdr_size),(msg_buffer->linksize-msg_buffer->linkused-p_link_info_size));
405 peek(p_bufseg,p_bufoff+p_msg_hdr_size,&(msg_buffer->lldata[msg_buffer->linkused]),
406 amount_to_copy);
407 msg_buffer->linkused += amount_to_copy;
408 }
409
410
411
412
413 major_sender = p_more_message -> source_major;
414 major_sender = (major_sender << 8) | p_more_message -> minor;
415 return (execap (major_sender, CONTINUE_MESSAGE,&(p_more_message -> source_system),1,p_mcb_ptr));
416 }
417
418
419
420
421
422
423
424
425 handle_continue (p_mcb_ptr, p_more_message)
426
427 mcb *p_mcb_ptr;
428 struct more_msg *p_more_message;
429
430 {
431 int found;
432 int done;
433 int major_sender;
434 int i;
435 int code;
436 struct linklst *msg_buffer;
437 struct linklst *prev_msg_buffer;
438 struct more_msg *message;
439
440
441 code = 0;
442 msg_buffer = p_mcb_ptr->outbuff;
443 prev_msg_buffer = p_mcb_ptr->outbuff;
444 found = FALSE;
445 done = FALSE;
446
447
448
449 while ((found == FALSE) && (done == FALSE))
450 { if (msg_buffer == NULL)
451 done = TRUE;
452 else
453 { message = (struct more_msg *) msg_buffer->lldata;
454 if ((message->system == p_more_message -> source_system)
455 && (message->major == p_more_message -> source_major)
456 && (message->source_system == p_more_message -> minor))
457 {
458 found = TRUE;
459 done = TRUE;
460 }
461 else if ((message->system == p_more_message -> source_system)
462 && (message->major == p_more_message -> source_major)
463 && (message->more_minor == p_more_message -> minor))
464 {
465 found = TRUE;
466 done = TRUE;
467 }
468 else
469 { prev_msg_buffer = msg_buffer;
470 msg_buffer = msg_buffer->nextbuf;
471 }
472 }
473 }
474
475
476
477 if (found)
478 { if (prev_msg_buffer == p_mcb_ptr->outbuff)
479 { p_mcb_ptr->outbuff = msg_buffer->nextlink;
480 if (msg_buffer->nextlink != NULL)
481 p_mcb_ptr->outbuff->nextlink->nextbuf = msg_buffer->nextbuf;
482 }
483 else
484 { prev_msg_buffer->nextbuf = msg_buffer->nextlink;
485 if (msg_buffer->nextlink != NULL)
486 msg_buffer->nextlink->nextbuf = msg_buffer->nextbuf;
487 }
488
489
490
491 code = call_mowse_int(I$EXECAP,msg_buffer->lldata, msg_buffer->linkused);
492 wsfree(p_mcb_ptr->outalloc,msg_buffer);
493
494 }
495
496
497
498
499 else
500 { code = forward (p_mcb_ptr, FAIL_CAPABILITY, NULL, 0, (char)WSIBMPC,
501 (char)WSMAJCAP);
502 }
503
504 return (code);
505 }
506
507
508
509
510
511
512 handle_default (p_mcb_ptr, p_buflen, p_bufseg, p_bufoff, p_minor_cap, p_msg_hdr_size, p_link_info_size, p_more_message)
513
514 mcb *p_mcb_ptr;
515 int p_bufseg;
516 int p_bufoff;
517 int p_buflen;
518 int p_minor_cap;
519 int p_msg_hdr_size;
520 int p_link_info_size;
521 struct more_msg *p_more_message;
522 {
523 int found;
524 int done;
525 int buffer_size;
526 int amount_to_copy;
527 int major_sender;
528 int i;
529 int all_copied;
530 int start_of_message;
531 int data_length;
532 char *more_msg_header1;
533 char *more_msg_header2;
534 struct input_msg *input_message;
535 struct linklst *msg_buffer;
536 struct linklst *prev_msg_buffer;
537 struct more_msg *message;
538
539
540
541 msg_buffer = p_mcb_ptr->inbuff;
542 prev_msg_buffer = NULL;
543
544 found = FALSE;
545 done = FALSE;
546 while ((found == FALSE) && (done == FALSE))
547 { if (msg_buffer == NULL)
548 done = TRUE;
549 else
550 { message = (struct more_msg *) msg_buffer->lldata;
551 if ((message->system == p_more_message -> system)
552 && (message->major == p_more_message -> major)
553 && (message->source_system == p_more_message -> more_minor))
554 {
555 found = TRUE;
556 done = TRUE;
557 }
558 else
559 { prev_msg_buffer = msg_buffer;
560 msg_buffer = msg_buffer->nextbuf;
561 }
562 }
563 }
564
565
566
567
568
569 if (found == TRUE)
570 { amount_to_copy = min((p_buflen-p_msg_hdr_size+1),(msg_buffer->linksize - msg_buffer->linkused-p_link_info_size));
571
572 if (amount_to_copy == (p_buflen-p_msg_hdr_size+1))
573 { peek(p_bufseg,p_bufoff+p_msg_hdr_size-1,&(msg_buffer->lldata[msg_buffer->linkused]),
574 amount_to_copy);
575 msg_buffer->linkused += amount_to_copy;
576 data_length = msg_buffer->linkused - p_msg_hdr_size;
577 start_of_message = p_msg_hdr_size;
578 all_copied = TRUE;
579 }
580 else
581 all_copied = FALSE;
582 }
583 else
584 { buffer_size = p_buflen+p_link_info_size;
585 msg_buffer = (struct linklst *) wsalloc(p_mcb_ptr->inalloc,buffer_size);
586
587 if (msg_buffer != NULL)
588 { peek(p_bufseg,p_bufoff,msg_buffer->lldata,p_buflen);
589 msg_buffer->nextlink = NULL;
590 msg_buffer->nextbuf = NULL;
591 msg_buffer->linkused = buffer_size;
592 msg_buffer->linksize = buffer_size;
593 data_length = p_buflen - (p_msg_hdr_size -1);
594 start_of_message = p_msg_hdr_size -1;
595 all_copied = TRUE;
596 }
597 else
598 all_copied = FALSE;
599 }
600
601
602
603
604
605
606 major_sender = p_more_message -> source_system;
607 major_sender = (major_sender << 8) | p_more_message -> source_major;
608
609 if (all_copied == TRUE)
610 { input_message = (struct input_msg *) msg_buffer->lldata;
611 if (input_message->system != WSIBMPC)
612 return(-1);
613
614
615
616 forward (p_mcb_ptr, p_minor_cap, (&(msg_buffer -> lldata[start_of_message])),
617 data_length, p_more_message -> source_system, p_more_message -> source_major);
618 }
619 else
620 { forward (p_mcb_ptr, WSOVRFLW, NULL, 0, (char)WSIBMPC, (char)WSMAJCAP);
621 }
622
623
624
625 if ((found == TRUE) && (msg_buffer != NULL))
626 { if ((msg_buffer == p_mcb_ptr->inbuff) ||
627 (prev_msg_buffer == p_mcb_ptr->inbuff))
628 {
629 p_mcb_ptr->inbuff = msg_buffer->nextbuf;
630 }
631 else
632 prev_msg_buffer->nextbuf = msg_buffer->nextbuf;
633
634 wsfree(p_mcb_ptr->inalloc,msg_buffer);
635 }
636 else
637 { if (msg_buffer != NULL)
638 wsfree(p_mcb_ptr->inalloc,msg_buffer);
639 }
640
641 return(0);
642 }
643 ^Z