|
|
1.1 root 1: /*
2: * This file implements client functions for the XNS courier library
3: */
4:
5: /*
6: $Log: client.c,v $
7: * Revision 3.0 87/01/14 14:40:36 ed
8: * release containing Xerox (Webster Research Center) modifications
9: *
10: * Revision 2.0 85/11/21 07:22:04 jqj
11: * 4.3BSD standard release
12: *
13: * Revision 1.3 85/03/11 16:36:46 jqj
14: * *** empty log message ***
15: *
16: * Revision 1.3 85/03/11 16:36:46 jqj
17: * Public alpha-test version, released 11 March 1985
18: *
19: * Revision 1.2 85/01/27 07:37:10 jqj
20: * finished but undebugged version
21: *
22: * Revision 1.1 84/12/30 10:14:30 jqj
23: * Initial revision -- Mogul's tcp-based version
24: */
25:
26: #ifndef lint
27: static char rcsid[] = "$Header: client.c,v 3.0 87/01/14 14:40:36 ed Exp $";
28: #endif
29:
30: #include <stdio.h>
31: #include <sys/types.h> /* for xn.h, and socket.h */
32: #include <sys/socket.h>
33: #include <netns/ns.h> /* for XNS addresses and courierconnection.h */
34: #include <netns/sp.h> /* for XNS addresses and courierconnection.h */
35: #include "courier.h"
36: #include "realcourierconnection.h"
37: #include <except.h>
38:
39: #if DEBUG
40: int CourierClientDebuggingFlag = 0;
41: #endif
42:
43:
44:
45: CourierConnection *
46: CourierOpen( addr )
47: struct ns_addr *addr;
48: {
49: extern char *malloc();
50: CourierConnection *conn;
51:
52: conn = (CourierConnection*) malloc(sizeof(CourierConnection));
53: conn->host.sns_family = AF_NS;
54: conn->host.sns_addr = *addr;
55: /* unknown socket? */
56: if (conn->host.sns_addr.x_port == 0)
57: conn->host.sns_addr.x_port = htons(IDPPORT_COURIER);
58: #if DEBUG
59: if (CourierClientDebuggingFlag)
60: fprintf(stderr,
61: "[CourierOpen: connect to %x#%x.%x.%x.%x.%x.%x#%x]\n",
62: ns_netof(conn->host.sns_addr),
63: conn->host.sns_addr.x_host.c_host[0],
64: conn->host.sns_addr.x_host.c_host[1],
65: conn->host.sns_addr.x_host.c_host[2],
66: conn->host.sns_addr.x_host.c_host[3],
67: conn->host.sns_addr.x_host.c_host[4],
68: conn->host.sns_addr.x_host.c_host[5],
69: ntohs(conn->host.sns_addr.x_port));
70: #endif
71: if ((conn->fd = openSPPConnection(&conn->host)) >= 0) {
72: conn->abortseen = FALSE;
73: conn->bdtstate = wantdata;
74: conn->state = wantversion;
75: conn->sphdrOpts.sp_dt = 0;
76: conn->sphdrOpts.sp_cc = 0;
77: return(conn);
78: }
79: else {
80: free((char*)conn);
81: return(NULL);
82: }
83: }
84:
85:
86: SendCallMessage(f, program, version, procedure, nwords, arguments)
87: CourierConnection *f; /* socket descriptor */
88: LongCardinal program; /* Courier program number */
89: Cardinal version, /* Courier program version */
90: procedure, /* Courier procedure number */
91: nwords; /* number of words in argument buffer */
92: Unspecified *arguments; /* prepacked argument buffer */
93: {
94: static Cardinal ourCVersion = COURIERVERSION;
95: static Cardinal msgtype = 0;
96: static Unspecified tid = 0;
97: #define HDRLEN 8
98: Unspecified *_bp, hdrbuf[HDRLEN];
99:
100: #if DEBUG
101: if (CourierClientDebuggingFlag)
102: fprintf(stderr, "[SendCallMessage program %D procedure %d, arglen %d]\n",
103: program, procedure, nwords);
104: #endif
105: _bp = hdrbuf;
106: if (f->state == wantversion) {
107: /* exchange version numbers */
108: _bp += externalize_Cardinal(&ourCVersion, _bp);
109: _bp += externalize_Cardinal(&ourCVersion, _bp);
110: }
111: _bp += externalize_Cardinal(&msgtype, _bp); /* call message type */
112: _bp += externalize_Unspecified(&tid, _bp); /* transaction id */
113: _bp += externalize_LongCardinal(&program, _bp);
114: _bp += externalize_Cardinal(&version, _bp);
115: _bp += externalize_Cardinal(&procedure, _bp);
116: (void) CheckEND(f);
117: CourierWrite(f, (_bp-hdrbuf), hdrbuf, nwords, arguments);
118: if (f->state == calldone)
119: f->state = inprogress;
120: }
121:
122:
123: Unspecified *
124: ReceiveReturnMessage(f, abortedFlag)
125: CourierConnection *f; /* socket descriptor */
126: Boolean *abortedFlag; /* TRUE iff abort received */
127: /* returns a pointer to a block of data to be freed after unpacking
128: * procResults or [errorValue, errorArgs]
129: */
130: {
131: #define RETHDRLEN 2
132: Unspecified *bp, *buf, hdrbuf[RETHDRLEN];
133: Cardinal msgtype, tid;
134: rejectionDetails *rdetails;
135: extern char *malloc();
136:
137: buf = ReadMessage(f, hdrbuf, RETHDRLEN);
138: bp = hdrbuf;
139: f->state = calldone;
140: bp += internalize_Cardinal(&msgtype, bp);
141: bp += internalize_Unspecified(&tid, bp);
142: #if DEBUG
143: if (CourierClientDebuggingFlag)
144: fprintf(stderr, "[ReceiveReturnMessage type %d]\n", msgtype);
145: #endif
146: switch (msgtype) {
147: case RETURN:
148: *abortedFlag = FALSE;
149: break;
150: case REJECT:
151: bp = buf;
152: rdetails = (rejectionDetails*)malloc(sizeof(rejectionDetails));
153: bp += internalize_enumeration(&(rdetails->designator), bp);
154: if (rdetails->designator == noSuchVersionNumber) {
155: bp += internalize_Cardinal( &(rdetails->noSuchVersionNumber_case.lowest), bp);
156: bp += internalize_Cardinal( &(rdetails->noSuchVersionNumber_case.highest), bp);
157: }
158: Deallocate(buf);
159: raise(REJECT_ERROR, (char*) rdetails);
160: /*NOTREACHED*/
161: case ABORT:
162: *abortedFlag = TRUE;
163: break;
164: }
165: return(buf);
166: }
167:
168:
169: MaybeCallBDTHandler(f, BDTproc)
170: /* called by RPC stub from Foo_client.c */
171: CourierConnection *f; /* socket descriptor */
172: int (*BDTproc)();
173: {
174: /* can't look ahead here, since server may be expecting us to send
175: * lots of data before he does anything
176: */
177: f->abortseen = FALSE;
178: /* ### setup interrupt handler for URGENT messages */
179: if (BDTproc != NULL)
180: (*BDTproc)(f);
181: /* ### clear interrupt handler */
182: f->bdtstate = wantdata;
183: }
184:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.