Debian Codegraph @

libsrc/os/vms/osr.c

raw
1 /* @(#)osr.c 19.1 (ES0-DMD) 02/25/03 13:56:14 */
2 /*===========================================================================
3 Copyright (C) 1995 European Southern Observatory (ESO)
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with this program; if not, write to the Free
17 Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
18 MA 02139, USA.
19
20 Corresponding concerning ESO-MIDAS should be addressed as follows:
21 Internet e-mail: [email protected]
22 Postal address: European Southern Observatory
23 Data Management Division
24 Karl-Schwarzschild-Strasse 2
25 D 85748 Garching bei Muenchen
26 GERMANY
27 ===========================================================================*/
28
29 /*+++++++++++
30 .TYPE Module
31 .LANGUAGE C
32 .IDENTIFICATION osr
33 .AUTHOR Francois Ochsenbein [ESO-IPG], Philippe Defert [ST-ECF]
34 .KEYWORDS X25 communication management
35 .ENVIRONMENT VAX/VMS, PSI
36 .COMMENTS Functions in this module allow to connect, clear,
37 read and write messages over X25.
38 The connection number is a number starting with 200.
39 \begin{TeX}
40
41 \end{TeX}
42
43 .VERSION 1.0 17-Nov-1986: Creation
44 .VERSION 1.1 16-Dec-1986: Some functions are defined as ``static"
45 .VERSION 1.2 28-Jan-1987: New X25 structure; acquire time at
46 each echange of message.
47 .VERSION 2.0 03-Feb-1988: Transformed into osr routines
48 .VERSION 2.1 30-Mar-1989: Transformed input to ASCII...
49 (IBM computers don't)
50 Force userdata!
51 .VERSION 2.2 11-May-1989: Added osrwait.
52 .VERSION 2.3 05-Sep-1989: Changed some `unclever' macros...
53 ---------------------------------*/
54
55 #define DEBUG 0 /* Debugging option */
56
57 #define MAX_IPCC 8 /* Maximal Number of Connections */
58
59 #include <osdefos.h>
60 #include <osremote.h>
61 #include <macrogen.h>
62 #include <errno.h> /* System */
63
64 #define X25_BUFSIZE 256 /* Size of input buffer */
65 #define X25_START 200 /* Starting x25 number */
66
67 MID_EXTERN int oserror;
68 MID_EXTERN char *oserrmsg;
69 MID_EXTERN int vmserror;
70
71 char *oshenv();
72
73 struct X25_struct { /* X25 packet for communication */
74 char *dte; /* Destination name */
75 char *net; /* Network name */
76 char *mbxname; /* Mailbox name */
77 char *mbxbuf; /* Mailbox buffer */
78 char *inbuf; /* Read over X25 buffer */
79 int inbytes; /* Bytes in inbuf */
80 int nw_unit; /* Number of NW device */
81 short int nw_chan; /* Channel to NW device */
82 short int mbx_chan; /* Channel to Mailbox */
83 /* unsigned long int efn; /* Event flag */
84 };
85
86 # include <descrip.h> /* System */
87 # include <psidef.h> /* Not in system... */
88 # include <dvidef.h> /* System */
89 # include <ssdef.h> /* System */
90 # include <iodef.h> /* System */
91 # include <nfbdef.h> /* System */
92 # include <msgdef.h> /* System */
93 # define MBX_BUFSIZE 256 /* Mailbox size */
94 # define MBX_NAME "X25S_MBA" /* Mail box logical name */
95 # define L dsc$w_length
96 # define S dsc$a_pointer
97
98 typedef struct dsc$descriptor descript;
99 # define void_string {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL_PTR(char)}
100 # define InitDescript(text) \
101 {sizeof(text)-1, DSC$K_DTYPE_T, DSC$K_CLASS_S,text}
102
103 # define SET_STRING(dsc,str,l) dsc.S = str, dsc.L = l \
104 /* Set address & length of a string */
105
106 typedef struct { /* Quad structure for descriptor */
107 long int len;
108 char *s; } QUAD;
109 struct item {
110 unsigned short int len;
111 unsigned short int item_code;
112 void * addr;
113 long * return_len;
114 };
115
116 static unsigned short int io_status [4]; /* status quadword for qio */
117 static long returned_length;
118
119 static descript nw_name = InitDescript("_NWA0:");
120 /* NW device name */
121 static descript mbx = void_string; /* Mail box name descriptor */
122 static QUAD ncb = /* ncb descriptor */
123 {0, 0};
124
125 static struct { /* Used with the GETDVI system service */
126 struct item item_1;
127 long int end;
128 } getdvi= {
129 {sizeof(int),DVI$_UNIT,0,&returned_length},
130 0 };
131
132 # define CheckVMS if (!(vmserror&1)) {oserror = EINTR; FINISH;}
133 # define ioCheckVMS if (iotest()) FINISH
134
135 typedef struct X25_struct X25;
136 #define NULL_X25 NULL_PTR(X25)
137
138 static X25 *Connections[MAX_IPCC] = {0,0,0,0}, *x25 = NULL_X25;
139 static int nx25 = X25_START; /* Number of used connections */
140
141 #define FINISH goto FIN
142
143 /*=====================================================================
144 VMS-specific Routines
145 *=====================================================================*/
146
147 /*=====================================================================*/
148 static int iotest()
149 /*+++
150 .PURPOSE Test the status and the i/o control block
151 .RETURNS 0 (OK) / -1 (Bad)
152 .REMARKS *** For internal use ***
153 ---*/
154 {
155 if (vmserror & 1)
156 if ((vmserror = io_status[0]) == SS$_CLEARED)
157 oserrmsg = "Connection Cleared by remote DTE.";
158
159 if (!(vmserror&1))
160 oserror = (oserrmsg ? -1 : EINTR);
161
162 return(oserror);
163 }
164
165 /*=====================================================================*/
166 static int rncb(ptr,dte,subdte,user,net)
167 /*+++
168 .PURPOSE Create the NCB (Network Control Block)
169 .RETURNS Length used in NCB
170 .REMARKS ***No check on the length of ncb buffer is performed!***
171 ---*/
172 unsigned char *ptr; /* OUT: resulting NCB */
173 unsigned char *dte; /* IN: The Destination address */
174 unsigned char *subdte; /* IN: Subdestination */
175 unsigned char *user; /* IN: User data */
176 unsigned char *net; /* IN: Network name */
177 {
178 MID_RSTATIC unsigned char user_x29[] = {1,0,0,0};
179 MID_REGISTER unsigned char *p;
180 MID_REGISTER struct header {
181 unsigned short int len;
182 unsigned short int item;
183 unsigned char count;
184 } *ps;
185
186 p = ptr;
187
188 /* remote DTE address */
189 ps = (struct header *)p, p = (unsigned char *)(ps+1);
190 ps->count = strlen(dte);
191 ps->item = PSI$C_NCB_REMDTE;
192 p += oscopy(p, dte, ps->count);
193 ps->len = p - (unsigned char *)ps;
194
195 if (subdte != NULL_PTR(unsigned char)) /* remote subaddress */
196 { ps = (struct header *)p, p = (unsigned char *)(ps+1);
197 ps->count = strlen(subdte);
198 ps->item = PSI$C_NCB_REMSUBADR;
199 p += oscopy(p, subdte, ps->count);
200 ps->len = p - (unsigned char *)ps;
201 }
202
203 if_not(user) user = (unsigned char *)""; /***** Force User Data ****/
204 { ps = (struct header *)p, p = (unsigned char *)(ps+1);
205 ps->count = strlen(user) + sizeof(user_x29);
206 ps->item = PSI$C_NCB_USERDATA;
207 p += oscopy(p, user_x29, sizeof(user_x29));
208 p += oscopy(p, user, ps->count - sizeof(user_x29));
209 ps->len = p - (unsigned char *)ps;
210 }
211
212 if (net != NULL_PTR(unsigned char)) /* Local Network name */
213 { ps = (struct header *)p, p = (unsigned char *)(ps+1);
214 ps->count = strlen(net);
215 ps->item = PSI$C_NCB_LOCNET;
216 p += oscopy(p, net, ps->count);
217 ps->len = p - (unsigned char *)ps;
218 }
219
220 return(p - ptr);
221 }
222
223 /*=====================================================================
224 Internal Routines
225 *=====================================================================*/
226
227 static int getx25(xid)
228 /*+++
229 .PURPOSE Retrieve the X25 packet.
230 .RETURNS 0 / -1 (error)
231 .REMARKS
232 ------*/
233 int xid; /* IN: Circuit Number */
234 {
235 oserrmsg = NULL_PTR(char);
236 oserror = 0;
237 x25 = NULL_X25;
238
239 if ((xid < X25_START) || (xid > nx25)) FINISH;
240 x25 = Connections[xid-X25_START];
241
242 FIN: if (x25 == NULL_X25)
243 { oserror = -1;
244 oserrmsg = "Bad X25-circuit Number";
245 }
246 return(oserror);
247 }
248
249 /*=====================================================================
250 osr Routines
251 *=====================================================================*/
252
253 /*=====================================================================*/
254 int osrinfo(xid, buf)
255 /*+++
256 .PURPOSE Get info about a connection
257 .RETURNS 0 / -1 (error). However, the net name is always filled.
258 .REMARKS
259 ------*/
260 int xid; /* IN: The Circuit Number */
261 struct remstat *buf; /* OUT: The info */
262 {
263
264 getx25(xid);
265
266 if(x25)
267 buf->dte = x25->dte, buf->net = x25->net,
268 buf->device = x25->mbxname, buf->unit= x25->nw_unit;
269 else
270 buf->dte = "",
271 buf->net = oshenv("PSI$NETWORK", "LNM$SYSTEM_TABLE"),
272 buf->device = MBX_NAME, buf->unit = 0;
273
274 return(x25 ? 0 : -1);
275 }
276
277 /*=====================================================================*/
278 int osropen(dte,subdte,user,net)
279 /*+++
280 .PURPOSE Connect to specified remote address.
281 \begin{TeX}
282 The operations are as follows:
283 \begin{enumerate}
284 \item Create the MailBox, logical name `{\tt X25S\_MB}$x$'.
285 \item Connect the Mailbox to NWA0 channel;
286 \item Retrieve the {\tt NW}$x$ unit, via a {\tt GETDVI}
287 \item Build up the NCB (Network Control Block)
288 \item Set up the virtual circuit, using {\tt IO\$\_ACCESS}
289 \end{enumerate}
290 \end{TeX}
291 .RETURNS Connection facility as a positive number / -1 on error
292 (oserror explains)
293 .REMARKS The destination may be found
294 using oshenv(symbolic_destination, "PSI$DTE_TABLE"),
295 and the user data via oshenv(dest_U, "PSI$DTE_TABLE").
296 ------*/
297 char *dte; /* IN: The Destination address */
298 char *subdte; /* IN: Subdestination (or NULL) */
299 char *user; /* IN: User data (or NULL) */
300 char *net; /* IN: Network name (or NULL) */
301 {
302 register int i;
303
304 oserrmsg = NULL_PTR(char); /* Error Indicator */
305 oserror = 0;
306 x25 = NULL_X25;
307
308 /* Check if there are not too many connections */
309
310 for (i = 0; i < ITEMS(Connections); i++)
311 if (!Connections[i]) break;
312 if (i >= ITEMS(Connections))
313 { oserrmsg = "Too many Connections";
314 FINISH;
315 }
316
317 if (!dte) /* No address */
318 { oserrmsg = "No DTE address";
319 FINISH;
320 }
321
322 /* Get Network Name if not specified */
323 if (!net) net = oshenv("PSI$NETWORK", "LNM$SYSTEM_TABLE");
324 if (!net) /* No network */
325 { oserrmsg = "No Network Available";
326 FINISH;
327 }
328
329 /* Allocate the X25 structure */
330
331 x25 = (X25 *) osmmget(sizeof(X25) + X25_BUFSIZE + MBX_BUFSIZE + 2 +
332 sizeof(MBX_NAME) + strlen(net) + strlen(dte));
333 if (oserror) FINISH;
334 x25->inbuf = (char *)(x25+1);
335 x25->mbxbuf = x25->inbuf + X25_BUFSIZE;
336 x25->dte = x25->mbxbuf + MBX_BUFSIZE;
337 x25->net = x25->dte + oscopuc(x25->dte, dte, 1000, EOS) + 1;
338 x25->mbxname = x25->net + oscopuc(x25->net, net, 1000, EOS) + 1;
339 x25->inbytes = 0;
340 oscopy(x25->mbxname, MBX_NAME, sizeof(MBX_NAME)); /* Copy Mailbox name */
341 x25->mbx_chan = 0;
342 x25->nw_chan = 0;
343
344 /* 2) Create a MailBox */
345
346 /* Create a new mailbox name */
347 *(x25->mbxname + sizeof(MBX_NAME) - 2) = 'A' + i;
348 SET_STRING(mbx, x25->mbxname, sizeof(MBX_NAME)-1);
349 vmserror = SYS$CREMBX(0,&x25->mbx_chan,0,0,0,0,&mbx);
350 CheckVMS;
351
352 /* 3) Assign channel to NW (associated with mailbox) */
353
354 vmserror = SYS$ASSIGN(&nw_name,&x25->nw_chan,0,&mbx);
355 CheckVMS;
356
357 /* 4) Retrieve the actual NW number (not required, but... */
358
359 getdvi.item_1.addr = &(x25->nw_unit);
360 vmserror = sys$getdviw(0,x25->nw_chan,0,&getdvi,io_status,0,0,0);
361 ioCheckVMS;
362
363 /* 5) Construct the NCB */
364
365 ncb.s = x25->inbuf;
366 ncb.len = rncb(ncb.s, dte, subdte, user, net);
367
368 /* 6) Ask for setup virtual circuit : send the initial packet */
369
370 vmserror = SYS$QIOW(0,x25->nw_chan,IO$_ACCESS,io_status,0,0,
371 0,&ncb,0,0,0,0);
372 CheckVMS;
373
374 /* If request correctly queued, decode the result from io_status */
375
376 vmserror = io_status[0];
377 switch(vmserror)
378 { case SS$_NORMAL:
379 switch(io_status[2])
380 { case PSI$M_STS_REMDTELNG:
381 oserrmsg = ("Remote DTE address too long"); FINISH;
382 case PSI$M_STS_USERLNG:
383 oserrmsg = ("Too much user data supplied"); FINISH;
384 } break;
385 case SS$_ABORT: case SS$_IVDEVNAM:
386 oserror = EINTR;
387 switch(io_status[2])
388 { case PSI$C_ERR_UNKNOWN:
389 oserrmsg = ("PSN Unknown error."); break;
390 case PSI$C_ERR_FACLNG:
391 oserrmsg = ("PSN Facilities too long."); break;
392 case PSI$C_ERR_INVITEM:
393 oserrmsg = ("PSN Invalid item code"); break;
394 case PSI$C_ERR_CONFLICT:
395 oserrmsg = ("PSN Conflicting items"); break;
396 case PSI$C_ERR_BADPARM:
397 oserrmsg = ("PSN Bad parameters specified"); break;
398 case PSI$C_ERR_NOTRANS:
399 oserrmsg = ("PSN No translation for name"); break;
400 case PSI$C_ERR_RECURLMT:
401 oserrmsg = ("Recursion limit reached"); break;
402 case PSI$C_ERR_INVNUM:
403 oserrmsg = ("Invalid ASCII number"); break;
404 case PSI$C_ERR_NOICI:
405 oserrmsg = ("No internal identifier specified"); break;
406 case PSI$C_ERR_MANYICI:
407 oserrmsg = ("More than one internal call identifier"); break;
408 case PSI$C_ERR_NOTIMP:
409 oserrmsg = ("Non implemented feature"); break;
410 case PSI$C_ERR_NOLINES:
411 oserrmsg = ("No lines available for the call"); break;
412 case PSI$C_ERR_NOSUCHLINE:
413 oserrmsg = ("No such line"); break;
414 case PSI$C_ERR_NOSUCHPVC:
415 oserrmsg = ("Specified PVC unknown"); break;
416 case PSI$C_ERR_NOSUCHNET:
417 oserrmsg = ("Specified PSN unknown"); break;
418 case PSI$C_ERR_NOLOCAL:
419 oserrmsg = ("ACP is out of local workspace"); break;
420 case PSI$C_ERR_NONONPAG:
421 oserrmsg = ("Insufficient free non-paged pool"); break;
422 case PSI$C_ERR_NOL3:
423 oserrmsg = ("Internal error"); break;
424 case PSI$C_ERR_BADNAME:
425 oserrmsg = ("Bad counted string"); break;
426 case PSI$C_ERR_L3ERR:
427 oserrmsg = ("Error returned from level 3"); break;
428 } FINISH;
429 case SS$_CLEARED:
430 oserrmsg = ("Remote DTE rejects the call...");
431 default:
432 oserror = EINTR;
433 FINISH;
434 }
435
436 /* WAIT FOR ANSWER FROM REMOTE */
437 /* =========================== */
438
439 vmserror = SYS$QIOW(0,x25->mbx_chan,IO$_READVBLK|IO$M_TIMED,io_status,0,0,
440 x25->mbxbuf, MBX_BUFSIZE,4,0,0,0);
441 ioCheckVMS;
442
443 if ((*(x25->mbxbuf) == MSG$_CONNECT) || (*(x25->mbxbuf) == MSG$_INCDAT))
444 /* OK TRACE_ED_STRING("Connected to ",x25->name) */ ;
445 else
446 { oserrmsg = "Connection rejected.";
447 FINISH;
448 }
449
450 Connections[i] = x25;
451 i += X25_START; /* Actual connection number */
452 if (i > nx25) nx25 = i;
453
454
455 FIN: /* If connection failed, clear */
456 if (oserrmsg) oserror = -1;
457 if (oserror) /* Failed */
458 { if (x25){
459 if(x25->nw_chan) SYS$DASSGN(x25->nw_chan);
460 if(x25->mbx_chan) SYS$DASSGN(x25->mbx_chan);
461 osmmfree(x25);
462 }
463 i = -1;
464 }
465 #if DEBUG
466 printf("Connection Summary: dte=%s, net=%s, mailbox=%s, nw#%d\n",
467 x25->dte, x25->net, x25->mbxname, x25->nw_unit);
468 #endif
469 return(i);
470 }
471
472 /*=====================================================================*/
473 int osrclose(xid)
474 /*+++
475 .PURPOSE Clear a virtual circuit
476 .RETURNS 0 / -1 (use osmsg for explanation)
477 .REMARKS
478 ---*/
479 int xid; /* IN: The circuit to clear */
480 {
481 if (getx25(xid)) FINISH;
482
483 vmserror = SYS$QIOW(0,x25->nw_chan,IO$_DEACCESS,&io_status,0,0,0,0,0,0,0,0);
484 iotest();
485
486 SYS$DASSGN(x25->nw_chan);
487 SYS$DASSGN(x25->mbx_chan);
488
489 FIN:
490 if(x25) osmmfree(x25), Connections[xid-X25_START] = NULL_X25;
491 if(oserrmsg) oserror = -1;
492
493 return (oserror ? -1 : 0);
494 }
495
496 /*=====================================================================*/
497 int osrend()
498 /*+++
499 .PURPOSE Clear all virtual circuits
500 .RETURNS 0 / -1 (use osmsg for explanation)
501 .REMARKS
502 ---*/
503 {
504 register int i;
505
506 for (i = nx25; --i >= X25_START; )
507 osrclose(i);
508
509 return (oserror ? -1 : 0);
510 }
511
512 /*=====================================================================*/
513 static int rin()
514 /*+++
515 .PURPOSE Check if something is to be read over X25
516 .RETURNS Length of input / -1 (line cleared)
517 .REMARKS Reading is performed via the internal buffer associated
518 to the x25 packet.
519 ---*/
520 {
521 register int len;
522 register char *p;
523
524 /* Look first if there is something in the internal buffer */
525
526 len = x25->inbytes;
527 if (len > 0) FINISH;
528
529 /* Read without wait */
530
531 /* vmserror = SYS$QIOW(0, x25->nw_chan, IO$_READVBLK|IO$M_NOW, */
532 vmserror = SYS$QIO(0, x25->nw_chan, IO$_READVBLK|IO$M_NOW,
533 io_status, 0,0, x25->inbuf, X25_BUFSIZE, 0,0,0,0);
534 CheckVMS;
535
536 len = io_status[1];
537
538 switch(io_status[0])
539 { case SS$_NODATA: len = 0; break;
540 case SS$_NORMAL: break;
541 default: ioCheckVMS;
542 }
543 x25->inbytes = len;
544
545 for (p = x25->inbuf + len; p > x25->inbuf; ) /* Transform to ASCII */
546 *(--p) &= 0x7f;
547
548 FIN:
549 if (oserrmsg) oserror = -1;
550 return(oserror ? -1 : len);
551 }
552
553 /*=====================================================================*/
554 int osrin(xid)
555 /*+++
556 .PURPOSE Check if something is to be read over X25
557 .RETURNS Length of input / -1 (error, see osmsg)
558 .REMARKS
559 ---*/
560 int xid; /* IN: The circuit to clear */
561 {
562 register int s;
563
564 if (getx25(xid)) FINISH;
565 s = rin();
566
567 FIN: return(oserror ? -1 : s);
568 }
569
570 /*=====================================================================*/
571 int osrwait(xid, timeout)
572 /*+++
573 .PURPOSE Wait for a message over the connection opened with osropen
574 .RETURNS Length of message (0 if none) / -1 if error (osmsg explains)
575 .REMARKS The message is not returned. osrread can be used for it.
576 ---*/
577 int xid; /* IN: The connection number */
578 int timeout; /* IN: Max time to wait (s) */
579 {
580 register int i, len;
581
582 /* Look first if data are coming ---
583 * Wait for a maximum of timeout seconds until the answer */
584
585 len = osrin(xid);
586 if (len) FINISH; /* Done ... or error ! */
587
588 for (i=timeout*4; (--i >= 0) && (len == 0); len = rin() )
589 ospwms(250);
590
591 FIN:
592 return(oserror ? -1 : len);
593 }
594
595 /*=====================================================================*/
596 int osrread(xid, buf, lbuf, timeout)
597 /*+++
598 .PURPOSE Read a message over the connection opened with osropen
599 .RETURNS Length of message / -1 if error (osmsg explains)
600 .REMARKS Return error if timeout!
601 ---*/
602 int xid; /* IN: The connection number */
603 char *buf; /* OUT: Read text */
604 int lbuf; /* IN: Size of buffer */
605 int timeout; /* IN: Max time to wait (s) */
606 {
607 register int i, len;
608
609 /* Check first of the buffer is at least one character! */
610
611 if (lbuf < 1)
612 { oserrmsg = "osrread Buffer is of negative or zero size!";
613 oserror = -1, len = -1;
614 FINISH;
615 }
616
617 /* Use osrwait which terminates as soon as somethinf arrives */
618
619 len = osrwait(xid, timeout);
620
621 /* Copy from internal buffer to user-supplied one */
622
623 FIN:
624 if (len > 0)
625 { len = MIN(x25->inbytes, lbuf);
626 oscopy(buf, x25->inbuf, len);
627 if ((len == 1) && (*buf == '\01')) /* Line Cleared */
628 { oserrmsg = "Connection Cleared by remote DTE.";
629 oserror = -1;
630 }
631 i = x25->inbytes - len; /* Bytes still in buffer */
632 if (i > 0 ) /* There are remaining bytes */
633 oscopy(x25->inbuf, x25->inbuf + len, i);
634 x25->inbytes = i;
635 }
636 return(oserror ? -1 : len);
637 }
638
639 /*=====================================================================*/
640 int osrgets(xid, buf, lbuf, timeout)
641 /*+++
642 .PURPOSE Read a message over the connection opened with osropen,
643 and reformats (suppress NUL characters and carriage-return,
644 terminate the string with the EOS)
645 .RETURNS Length of message / -1 if error (osmsg explains)
646 .REMARKS
647 ---*/
648 int xid; /* IN: The connection number */
649 char *buf; /* OUT: text to read */
650 int lbuf; /* IN: Size of buffer */
651 int timeout; /* IN: Max time to wait (s) */
652 {
653 register int lr;
654 register char *p, *q;
655
656 /* p is used as the running pointer in buffer. */
657
658 p = buf, *p = EOS;
659
660 lr = osrread(xid, p, lbuf-1, timeout);
661 if (lr <= 0) FINISH; /* Error, or nothing */
662
663 /* Suppress NUL and useless
664 * control characters */
665 for (q = p; --lr >=0; q++)
666 { if (*q == EOS) continue;
667 if (*q == '\r') continue;
668 *(p++) = *q;
669 }
670 *p = EOS;
671 lr = p - buf;
672
673 FIN:
674 return(oserror ? -1 : lr);
675 }
676
677 /*=====================================================================*/
678 int osrwrite(xid, buf, lbuf)
679 /*+++
680 .PURPOSE Write a message over X25
681 .RETURNS Size of written message / -1 (osmsg explains)
682 .REMARKS
683 ---*/
684 int xid; /* IN: The connection number */
685 char *buf; /* IN: Text to write */
686 int lbuf; /* IN: Size of buffer */
687 {
688 if (getx25(xid)) FINISH;
689
690 vmserror = SYS$QIOW(0, x25->nw_chan, IO$_WRITEVBLK, io_status, 0,0,
691 buf, lbuf, 0, 0,0,0,0);
692 iotest();
693
694 FIN:
695 return(oserror ? -1 : lbuf);
696 }
697
698 /*=====================================================================*/
699 int osrputs(xid, buf)
700 /*+++
701 .PURPOSE Write an EOS-terminated message over the network,
702 adding the Carriage Return
703 .RETURNS length of written message / -1 (osmsg explains)
704 .REMARKS
705 ---*/
706 int xid; /* IN: The connection number */
707 char *buf; /* IN: EOS-terminated Text to write */
708 {
709 register char *p;
710 register int l;
711
712 l = strlen(buf);
713 p = buf + l;
714 *p = '\r';
715
716 l = osrwrite(xid, buf, l+1);
717
718 *p = EOS; /* Reset the EOS */
719
720 return(l);
721 }
722