xdr_rec.c (0cc39166733d7a7eee94bd8aa573237a90d9838e) xdr_rec.c (1ad08a09e9732e9e6e44f069c55f4abe27ed392a)
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
8 *
8 *
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
12 *
12 *
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
16 *
16 *
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
20 *
20 *
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
24 *
24 *
25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California 94043
28 */
25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California 94043
28 */
29#if defined(LIBC_SCCS) && !defined(lint)
29#if defined(LIBC_SCCS) && !defined(lint)
30/*static char *sccsid = "from: @(#)xdr_rec.c 1.21 87/08/11 Copyr 1984 Sun Micro";*/
31/*static char *sccsid = "from: @(#)xdr_rec.c 2.2 88/08/01 4.0 RPCSRC";*/
30/*static char *sccsid = "from: @(#)xdr_rec.c 1.21 87/08/11 Copyr 1984 Sun Micro";*/
31/*static char *sccsid = "from: @(#)xdr_rec.c 2.2 88/08/01 4.0 RPCSRC";*/
32static char *rcsid = "$Id: xdr_rec.c,v 1.1 1993/10/27 05:41:12 paul Exp $";
32static char *rcsid = "$Id: xdr_rec.c,v 1.4 1995/10/22 14:53:56 phk Exp $";
33#endif
34
35/*
36 * xdr_rec.c, Implements TCP/IP based XDR streams with a "record marking"
37 * layer above tcp (for rpc's use).
38 *
39 * Copyright (C) 1984, Sun Microsystems, Inc.
40 *
41 * These routines interface XDRSTREAMS to a tcp/ip connection.
42 * There is a record marking layer between the xdr stream
43 * and the tcp transport level. A record is composed on one or more
44 * record fragments. A record fragment is a thirty-two bit header followed
45 * by n bytes of data, where n is contained in the header. The header
46 * is represented as a htonl(u_long). Thegh order bit encodes
47 * whether or not the fragment is the last fragment of the record
33#endif
34
35/*
36 * xdr_rec.c, Implements TCP/IP based XDR streams with a "record marking"
37 * layer above tcp (for rpc's use).
38 *
39 * Copyright (C) 1984, Sun Microsystems, Inc.
40 *
41 * These routines interface XDRSTREAMS to a tcp/ip connection.
42 * There is a record marking layer between the xdr stream
43 * and the tcp transport level. A record is composed on one or more
44 * record fragments. A record fragment is a thirty-two bit header followed
45 * by n bytes of data, where n is contained in the header. The header
46 * is represented as a htonl(u_long). Thegh order bit encodes
47 * whether or not the fragment is the last fragment of the record
48 * (1 => fragment is last, 0 => more fragments to follow.
48 * (1 => fragment is last, 0 => more fragments to follow.
49 * The other 31 bits encode the byte length of the fragment.
50 */
51
52#include <stdio.h>
53#include <stdlib.h>
49 * The other 31 bits encode the byte length of the fragment.
50 */
51
52#include <stdio.h>
53#include <stdlib.h>
54#include <string.h>
54#include <rpc/types.h>
55#include <rpc/xdr.h>
56#include <netinet/in.h>
57
55#include <rpc/types.h>
56#include <rpc/xdr.h>
57#include <netinet/in.h>
58
58extern long lseek();
59
60static u_int fix_buf_size();
61static bool_t flush_out();
62static bool_t get_input_bytes();
63static bool_t set_input_fragment();
64static bool_t skip_input_bytes();
65
66static bool_t xdrrec_getlong();
67static bool_t xdrrec_putlong();
68static bool_t xdrrec_getbytes();
69static bool_t xdrrec_putbytes();
70static u_int xdrrec_getpos();
71static bool_t xdrrec_setpos();
59static u_int fix_buf_size();
60static bool_t flush_out();
61static bool_t get_input_bytes();
62static bool_t set_input_fragment();
63static bool_t skip_input_bytes();
64
65static bool_t xdrrec_getlong();
66static bool_t xdrrec_putlong();
67static bool_t xdrrec_getbytes();
68static bool_t xdrrec_putbytes();
69static u_int xdrrec_getpos();
70static bool_t xdrrec_setpos();
72static long * xdrrec_inline();
71static int32_t *xdrrec_inline();
73static void xdrrec_destroy();
74
75static struct xdr_ops xdrrec_ops = {
76 xdrrec_getlong,
77 xdrrec_putlong,
78 xdrrec_getbytes,
79 xdrrec_putbytes,
80 xdrrec_getpos,

--- 10 unchanged lines hidden (view full) ---

91 * are a byte count of the fragment. The highest order bit is a boolean:
92 * 1 => this fragment is the last fragment of the record,
93 * 0 => this fragment is followed by more fragment(s).
94 *
95 * The fragment/record machinery is not general; it is constructed to
96 * meet the needs of xdr and rpc based on tcp.
97 */
98
72static void xdrrec_destroy();
73
74static struct xdr_ops xdrrec_ops = {
75 xdrrec_getlong,
76 xdrrec_putlong,
77 xdrrec_getbytes,
78 xdrrec_putbytes,
79 xdrrec_getpos,

--- 10 unchanged lines hidden (view full) ---

90 * are a byte count of the fragment. The highest order bit is a boolean:
91 * 1 => this fragment is the last fragment of the record,
92 * 0 => this fragment is followed by more fragment(s).
93 *
94 * The fragment/record machinery is not general; it is constructed to
95 * meet the needs of xdr and rpc based on tcp.
96 */
97
99#define LAST_FRAG ((u_long)(1 << 31))
98#define LAST_FRAG ((u_int32_t)(1 << 31))
100
101typedef struct rec_strm {
102 caddr_t tcp_handle;
103 caddr_t the_buffer;
104 /*
105 * out-goung bits
106 */
99
100typedef struct rec_strm {
101 caddr_t tcp_handle;
102 caddr_t the_buffer;
103 /*
104 * out-goung bits
105 */
107 int (*writeit)();
106 int (*writeit) __P((caddr_t, caddr_t, int));
108 caddr_t out_base; /* output buffer (points to frag header) */
109 caddr_t out_finger; /* next output position */
110 caddr_t out_boundry; /* data cannot up to this address */
107 caddr_t out_base; /* output buffer (points to frag header) */
108 caddr_t out_finger; /* next output position */
109 caddr_t out_boundry; /* data cannot up to this address */
111 u_long *frag_header; /* beginning of curren fragment */
110 u_int32_t *frag_header; /* beginning of current fragment */
112 bool_t frag_sent; /* true if buffer sent in middle of record */
113 /*
114 * in-coming bits
115 */
111 bool_t frag_sent; /* true if buffer sent in middle of record */
112 /*
113 * in-coming bits
114 */
116 int (*readit)();
115 int (*readit) __P((caddr_t, caddr_t, int));
117 u_long in_size; /* fixed size of the input buffer */
118 caddr_t in_base;
119 caddr_t in_finger; /* location of next byte to be had */
120 caddr_t in_boundry; /* can read up to this location */
121 long fbtbc; /* fragment bytes to be consumed */
122 bool_t last_frag;
123 u_int sendsize;
124 u_int recvsize;

--- 18 unchanged lines hidden (view full) ---

143 int (*readit)(); /* like read, but pass it a tcp_handle, not sock */
144 int (*writeit)(); /* like write, but pass it a tcp_handle, not sock */
145{
146 register RECSTREAM *rstrm =
147 (RECSTREAM *)mem_alloc(sizeof(RECSTREAM));
148
149 if (rstrm == NULL) {
150 (void)fprintf(stderr, "xdrrec_create: out of memory\n");
116 u_long in_size; /* fixed size of the input buffer */
117 caddr_t in_base;
118 caddr_t in_finger; /* location of next byte to be had */
119 caddr_t in_boundry; /* can read up to this location */
120 long fbtbc; /* fragment bytes to be consumed */
121 bool_t last_frag;
122 u_int sendsize;
123 u_int recvsize;

--- 18 unchanged lines hidden (view full) ---

142 int (*readit)(); /* like read, but pass it a tcp_handle, not sock */
143 int (*writeit)(); /* like write, but pass it a tcp_handle, not sock */
144{
145 register RECSTREAM *rstrm =
146 (RECSTREAM *)mem_alloc(sizeof(RECSTREAM));
147
148 if (rstrm == NULL) {
149 (void)fprintf(stderr, "xdrrec_create: out of memory\n");
151 /*
152 * This is bad. Should rework xdrrec_create to
150 /*
151 * This is bad. Should rework xdrrec_create to
153 * return a handle, and in this case return NULL
154 */
155 return;
156 }
157 /*
158 * adjust sizes and allocate buffer quad byte aligned
159 */
160 rstrm->sendsize = sendsize = fix_buf_size(sendsize);
161 rstrm->recvsize = recvsize = fix_buf_size(recvsize);
162 rstrm->the_buffer = mem_alloc(sendsize + recvsize + BYTES_PER_XDR_UNIT);
163 if (rstrm->the_buffer == NULL) {
164 (void)fprintf(stderr, "xdrrec_create: out of memory\n");
165 return;
166 }
167 for (rstrm->out_base = rstrm->the_buffer;
152 * return a handle, and in this case return NULL
153 */
154 return;
155 }
156 /*
157 * adjust sizes and allocate buffer quad byte aligned
158 */
159 rstrm->sendsize = sendsize = fix_buf_size(sendsize);
160 rstrm->recvsize = recvsize = fix_buf_size(recvsize);
161 rstrm->the_buffer = mem_alloc(sendsize + recvsize + BYTES_PER_XDR_UNIT);
162 if (rstrm->the_buffer == NULL) {
163 (void)fprintf(stderr, "xdrrec_create: out of memory\n");
164 return;
165 }
166 for (rstrm->out_base = rstrm->the_buffer;
168 (u_int)rstrm->out_base % BYTES_PER_XDR_UNIT != 0;
167 (u_long)rstrm->out_base % BYTES_PER_XDR_UNIT != 0;
169 rstrm->out_base++);
170 rstrm->in_base = rstrm->out_base + sendsize;
171 /*
172 * now the rest ...
173 */
174 xdrs->x_ops = &xdrrec_ops;
175 xdrs->x_private = (caddr_t)rstrm;
176 rstrm->tcp_handle = tcp_handle;
177 rstrm->readit = readit;
178 rstrm->writeit = writeit;
179 rstrm->out_finger = rstrm->out_boundry = rstrm->out_base;
168 rstrm->out_base++);
169 rstrm->in_base = rstrm->out_base + sendsize;
170 /*
171 * now the rest ...
172 */
173 xdrs->x_ops = &xdrrec_ops;
174 xdrs->x_private = (caddr_t)rstrm;
175 rstrm->tcp_handle = tcp_handle;
176 rstrm->readit = readit;
177 rstrm->writeit = writeit;
178 rstrm->out_finger = rstrm->out_boundry = rstrm->out_base;
180 rstrm->frag_header = (u_long *)rstrm->out_base;
181 rstrm->out_finger += sizeof(u_long);
179 rstrm->frag_header = (u_int32_t *)rstrm->out_base;
180 rstrm->out_finger += sizeof(u_int32_t);
182 rstrm->out_boundry += sendsize;
183 rstrm->frag_sent = FALSE;
184 rstrm->in_size = recvsize;
185 rstrm->in_boundry = rstrm->in_base;
186 rstrm->in_finger = (rstrm->in_boundry += recvsize);
187 rstrm->fbtbc = 0;
188 rstrm->last_frag = TRUE;
189}

--- 5 unchanged lines hidden (view full) ---

195 */
196
197static bool_t
198xdrrec_getlong(xdrs, lp)
199 XDR *xdrs;
200 long *lp;
201{
202 register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
181 rstrm->out_boundry += sendsize;
182 rstrm->frag_sent = FALSE;
183 rstrm->in_size = recvsize;
184 rstrm->in_boundry = rstrm->in_base;
185 rstrm->in_finger = (rstrm->in_boundry += recvsize);
186 rstrm->fbtbc = 0;
187 rstrm->last_frag = TRUE;
188}

--- 5 unchanged lines hidden (view full) ---

194 */
195
196static bool_t
197xdrrec_getlong(xdrs, lp)
198 XDR *xdrs;
199 long *lp;
200{
201 register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
203 register long *buflp = (long *)(rstrm->in_finger);
204 long mylong;
202 register int32_t *buflp = (int32_t *)(rstrm->in_finger);
203 int32_t mylong;
205
206 /* first try the inline, fast case */
204
205 /* first try the inline, fast case */
207 if ((rstrm->fbtbc >= sizeof(long)) &&
208 (((int)rstrm->in_boundry - (int)buflp) >= sizeof(long))) {
209 *lp = (long)ntohl((u_long)(*buflp));
210 rstrm->fbtbc -= sizeof(long);
211 rstrm->in_finger += sizeof(long);
206 if ((rstrm->fbtbc >= sizeof(int32_t)) &&
207 (((long)rstrm->in_boundry - (long)buflp) >= sizeof(int32_t))) {
208 *lp = (long)ntohl((u_int32_t)(*buflp));
209 rstrm->fbtbc -= sizeof(int32_t);
210 rstrm->in_finger += sizeof(int32_t);
212 } else {
211 } else {
213 if (! xdrrec_getbytes(xdrs, (caddr_t)&mylong, sizeof(long)))
212 if (! xdrrec_getbytes(xdrs, (caddr_t)&mylong, sizeof(int32_t)))
214 return (FALSE);
213 return (FALSE);
215 *lp = (long)ntohl((u_long)mylong);
214 *lp = (long)ntohl((u_int32_t)mylong);
216 }
217 return (TRUE);
218}
219
220static bool_t
221xdrrec_putlong(xdrs, lp)
222 XDR *xdrs;
223 long *lp;
224{
225 register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
215 }
216 return (TRUE);
217}
218
219static bool_t
220xdrrec_putlong(xdrs, lp)
221 XDR *xdrs;
222 long *lp;
223{
224 register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
226 register long *dest_lp = ((long *)(rstrm->out_finger));
225 register int32_t *dest_lp = ((int32_t *)(rstrm->out_finger));
227
226
228 if ((rstrm->out_finger += sizeof(long)) > rstrm->out_boundry) {
227 if ((rstrm->out_finger += sizeof(int32_t)) > rstrm->out_boundry) {
229 /*
230 * this case should almost never happen so the code is
231 * inefficient
232 */
228 /*
229 * this case should almost never happen so the code is
230 * inefficient
231 */
233 rstrm->out_finger -= sizeof(long);
232 rstrm->out_finger -= sizeof(int32_t);
234 rstrm->frag_sent = TRUE;
235 if (! flush_out(rstrm, FALSE))
236 return (FALSE);
233 rstrm->frag_sent = TRUE;
234 if (! flush_out(rstrm, FALSE))
235 return (FALSE);
237 dest_lp = ((long *)(rstrm->out_finger));
238 rstrm->out_finger += sizeof(long);
236 dest_lp = ((int32_t *)(rstrm->out_finger));
237 rstrm->out_finger += sizeof(int32_t);
239 }
238 }
240 *dest_lp = (long)htonl((u_long)(*lp));
239 *dest_lp = (int32_t)htonl((u_int32_t)(*lp));
241 return (TRUE);
242}
243
244static bool_t /* must manage buffers, fragments, and records */
245xdrrec_getbytes(xdrs, addr, len)
246 XDR *xdrs;
247 register caddr_t addr;
248 register u_int len;

--- 8 unchanged lines hidden (view full) ---

257 return (FALSE);
258 if (! set_input_fragment(rstrm))
259 return (FALSE);
260 continue;
261 }
262 current = (len < current) ? len : current;
263 if (! get_input_bytes(rstrm, addr, current))
264 return (FALSE);
240 return (TRUE);
241}
242
243static bool_t /* must manage buffers, fragments, and records */
244xdrrec_getbytes(xdrs, addr, len)
245 XDR *xdrs;
246 register caddr_t addr;
247 register u_int len;

--- 8 unchanged lines hidden (view full) ---

256 return (FALSE);
257 if (! set_input_fragment(rstrm))
258 return (FALSE);
259 continue;
260 }
261 current = (len < current) ? len : current;
262 if (! get_input_bytes(rstrm, addr, current))
263 return (FALSE);
265 addr += current;
264 addr += current;
266 rstrm->fbtbc -= current;
267 len -= current;
268 }
269 return (TRUE);
270}
271
272static bool_t
273xdrrec_putbytes(xdrs, addr, len)
274 XDR *xdrs;
275 register caddr_t addr;
276 register u_int len;
277{
278 register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
265 rstrm->fbtbc -= current;
266 len -= current;
267 }
268 return (TRUE);
269}
270
271static bool_t
272xdrrec_putbytes(xdrs, addr, len)
273 XDR *xdrs;
274 register caddr_t addr;
275 register u_int len;
276{
277 register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
279 register int current;
278 register long current;
280
281 while (len > 0) {
279
280 while (len > 0) {
282 current = (u_int)rstrm->out_boundry - (u_int)rstrm->out_finger;
281 current = (u_long)rstrm->out_boundry -
282 (u_long)rstrm->out_finger;
283 current = (len < current) ? len : current;
283 current = (len < current) ? len : current;
284 bcopy(addr, rstrm->out_finger, current);
284 memcpy(rstrm->out_finger, addr, current);
285 rstrm->out_finger += current;
286 addr += current;
287 len -= current;
288 if (rstrm->out_finger == rstrm->out_boundry) {
289 rstrm->frag_sent = TRUE;
290 if (! flush_out(rstrm, FALSE))
291 return (FALSE);
292 }
293 }
294 return (TRUE);
295}
296
297static u_int
298xdrrec_getpos(xdrs)
299 register XDR *xdrs;
300{
301 register RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
302 register long pos;
303
285 rstrm->out_finger += current;
286 addr += current;
287 len -= current;
288 if (rstrm->out_finger == rstrm->out_boundry) {
289 rstrm->frag_sent = TRUE;
290 if (! flush_out(rstrm, FALSE))
291 return (FALSE);
292 }
293 }
294 return (TRUE);
295}
296
297static u_int
298xdrrec_getpos(xdrs)
299 register XDR *xdrs;
300{
301 register RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
302 register long pos;
303
304 pos = lseek((int)rstrm->tcp_handle, (long) 0, 1);
304 pos = lseek((int)(long)rstrm->tcp_handle, (off_t) 0, 1);
305 if (pos != -1)
306 switch (xdrs->x_op) {
307
308 case XDR_ENCODE:
309 pos += rstrm->out_finger - rstrm->out_base;
310 break;
311
312 case XDR_DECODE:
313 pos -= rstrm->in_boundry - rstrm->in_finger;
314 break;
315
316 default:
305 if (pos != -1)
306 switch (xdrs->x_op) {
307
308 case XDR_ENCODE:
309 pos += rstrm->out_finger - rstrm->out_base;
310 break;
311
312 case XDR_DECODE:
313 pos -= rstrm->in_boundry - rstrm->in_finger;
314 break;
315
316 default:
317 pos = (u_int) -1;
317 pos = -1;
318 break;
319 }
320 return ((u_int) pos);
321}
322
323static bool_t
324xdrrec_setpos(xdrs, pos)
325 register XDR *xdrs;

--- 25 unchanged lines hidden (view full) ---

351 rstrm->fbtbc -= delta;
352 return (TRUE);
353 }
354 break;
355 }
356 return (FALSE);
357}
358
318 break;
319 }
320 return ((u_int) pos);
321}
322
323static bool_t
324xdrrec_setpos(xdrs, pos)
325 register XDR *xdrs;

--- 25 unchanged lines hidden (view full) ---

351 rstrm->fbtbc -= delta;
352 return (TRUE);
353 }
354 break;
355 }
356 return (FALSE);
357}
358
359static long *
359static int32_t *
360xdrrec_inline(xdrs, len)
361 register XDR *xdrs;
362 int len;
363{
364 register RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
360xdrrec_inline(xdrs, len)
361 register XDR *xdrs;
362 int len;
363{
364 register RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
365 long * buf = NULL;
365 int32_t * buf = NULL;
366
367 switch (xdrs->x_op) {
368
369 case XDR_ENCODE:
370 if ((rstrm->out_finger + len) <= rstrm->out_boundry) {
366
367 switch (xdrs->x_op) {
368
369 case XDR_ENCODE:
370 if ((rstrm->out_finger + len) <= rstrm->out_boundry) {
371 buf = (long *) rstrm->out_finger;
371 buf = (int32_t *) rstrm->out_finger;
372 rstrm->out_finger += len;
373 }
374 break;
375
376 case XDR_DECODE:
377 if ((len <= rstrm->fbtbc) &&
378 ((rstrm->in_finger + len) <= rstrm->in_boundry)) {
372 rstrm->out_finger += len;
373 }
374 break;
375
376 case XDR_DECODE:
377 if ((len <= rstrm->fbtbc) &&
378 ((rstrm->in_finger + len) <= rstrm->in_boundry)) {
379 buf = (long *) rstrm->in_finger;
379 buf = (int32_t *) rstrm->in_finger;
380 rstrm->fbtbc -= len;
381 rstrm->in_finger += len;
382 }
383 break;
384 }
385 return (buf);
386}
387

--- 31 unchanged lines hidden (view full) ---

419 return (FALSE);
420 }
421 rstrm->last_frag = FALSE;
422 return (TRUE);
423}
424
425/*
426 * Look ahead fuction.
380 rstrm->fbtbc -= len;
381 rstrm->in_finger += len;
382 }
383 break;
384 }
385 return (buf);
386}
387

--- 31 unchanged lines hidden (view full) ---

419 return (FALSE);
420 }
421 rstrm->last_frag = FALSE;
422 return (TRUE);
423}
424
425/*
426 * Look ahead fuction.
427 * Returns TRUE iff there is no more input in the buffer
427 * Returns TRUE iff there is no more input in the buffer
428 * after consuming the rest of the current record.
429 */
430bool_t
431xdrrec_eof(xdrs)
432 XDR *xdrs;
433{
434 register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
435

--- 19 unchanged lines hidden (view full) ---

455xdrrec_endofrecord(xdrs, sendnow)
456 XDR *xdrs;
457 bool_t sendnow;
458{
459 register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
460 register u_long len; /* fragment length */
461
462 if (sendnow || rstrm->frag_sent ||
428 * after consuming the rest of the current record.
429 */
430bool_t
431xdrrec_eof(xdrs)
432 XDR *xdrs;
433{
434 register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
435

--- 19 unchanged lines hidden (view full) ---

455xdrrec_endofrecord(xdrs, sendnow)
456 XDR *xdrs;
457 bool_t sendnow;
458{
459 register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
460 register u_long len; /* fragment length */
461
462 if (sendnow || rstrm->frag_sent ||
463 ((u_long)rstrm->out_finger + sizeof(u_long) >=
463 ((u_long)rstrm->out_finger + sizeof(u_int32_t) >=
464 (u_long)rstrm->out_boundry)) {
465 rstrm->frag_sent = FALSE;
466 return (flush_out(rstrm, TRUE));
467 }
468 len = (u_long)(rstrm->out_finger) - (u_long)(rstrm->frag_header) -
464 (u_long)rstrm->out_boundry)) {
465 rstrm->frag_sent = FALSE;
466 return (flush_out(rstrm, TRUE));
467 }
468 len = (u_long)(rstrm->out_finger) - (u_long)(rstrm->frag_header) -
469 sizeof(u_long);
469 sizeof(u_int32_t);
470 *(rstrm->frag_header) = htonl((u_long)len | LAST_FRAG);
470 *(rstrm->frag_header) = htonl((u_long)len | LAST_FRAG);
471 rstrm->frag_header = (u_long *)rstrm->out_finger;
472 rstrm->out_finger += sizeof(u_long);
471 rstrm->frag_header = (u_int32_t *)rstrm->out_finger;
472 rstrm->out_finger += sizeof(u_int32_t);
473 return (TRUE);
474}
475
476
477/*
478 * Internal useful routines
479 */
480static bool_t
481flush_out(rstrm, eor)
482 register RECSTREAM *rstrm;
483 bool_t eor;
484{
485 register u_long eormask = (eor == TRUE) ? LAST_FRAG : 0;
473 return (TRUE);
474}
475
476
477/*
478 * Internal useful routines
479 */
480static bool_t
481flush_out(rstrm, eor)
482 register RECSTREAM *rstrm;
483 bool_t eor;
484{
485 register u_long eormask = (eor == TRUE) ? LAST_FRAG : 0;
486 register u_long len = (u_long)(rstrm->out_finger) -
487 (u_long)(rstrm->frag_header) - sizeof(u_long);
486 register u_int32_t len = (u_long)(rstrm->out_finger) -
487 (u_long)(rstrm->frag_header) - sizeof(u_int32_t);
488
489 *(rstrm->frag_header) = htonl(len | eormask);
490 len = (u_long)(rstrm->out_finger) - (u_long)(rstrm->out_base);
491 if ((*(rstrm->writeit))(rstrm->tcp_handle, rstrm->out_base, (int)len)
492 != (int)len)
493 return (FALSE);
488
489 *(rstrm->frag_header) = htonl(len | eormask);
490 len = (u_long)(rstrm->out_finger) - (u_long)(rstrm->out_base);
491 if ((*(rstrm->writeit))(rstrm->tcp_handle, rstrm->out_base, (int)len)
492 != (int)len)
493 return (FALSE);
494 rstrm->frag_header = (u_long *)rstrm->out_base;
495 rstrm->out_finger = (caddr_t)rstrm->out_base + sizeof(u_long);
494 rstrm->frag_header = (u_int32_t *)rstrm->out_base;
495 rstrm->out_finger = (caddr_t)rstrm->out_base + sizeof(u_int32_t);
496 return (TRUE);
497}
498
499static bool_t /* knows nothing about records! Only about input buffers */
500fill_input_buf(rstrm)
501 register RECSTREAM *rstrm;
502{
503 register caddr_t where;
496 return (TRUE);
497}
498
499static bool_t /* knows nothing about records! Only about input buffers */
500fill_input_buf(rstrm)
501 register RECSTREAM *rstrm;
502{
503 register caddr_t where;
504 u_int i;
505 register int len;
504 u_long i;
505 register long len;
506
507 where = rstrm->in_base;
506
507 where = rstrm->in_base;
508 i = (u_int)rstrm->in_boundry % BYTES_PER_XDR_UNIT;
508 i = (u_long)rstrm->in_boundry % BYTES_PER_XDR_UNIT;
509 where += i;
510 len = rstrm->in_size - i;
511 if ((len = (*(rstrm->readit))(rstrm->tcp_handle, where, len)) == -1)
512 return (FALSE);
513 rstrm->in_finger = where;
514 where += len;
515 rstrm->in_boundry = where;
516 return (TRUE);
517}
518
519static bool_t /* knows nothing about records! Only about input buffers */
520get_input_bytes(rstrm, addr, len)
521 register RECSTREAM *rstrm;
522 register caddr_t addr;
523 register int len;
524{
509 where += i;
510 len = rstrm->in_size - i;
511 if ((len = (*(rstrm->readit))(rstrm->tcp_handle, where, len)) == -1)
512 return (FALSE);
513 rstrm->in_finger = where;
514 where += len;
515 rstrm->in_boundry = where;
516 return (TRUE);
517}
518
519static bool_t /* knows nothing about records! Only about input buffers */
520get_input_bytes(rstrm, addr, len)
521 register RECSTREAM *rstrm;
522 register caddr_t addr;
523 register int len;
524{
525 register int current;
525 register long current;
526
527 while (len > 0) {
526
527 while (len > 0) {
528 current = (int)rstrm->in_boundry - (int)rstrm->in_finger;
528 current = (long)rstrm->in_boundry - (long)rstrm->in_finger;
529 if (current == 0) {
530 if (! fill_input_buf(rstrm))
531 return (FALSE);
532 continue;
533 }
534 current = (len < current) ? len : current;
529 if (current == 0) {
530 if (! fill_input_buf(rstrm))
531 return (FALSE);
532 continue;
533 }
534 current = (len < current) ? len : current;
535 bcopy(rstrm->in_finger, addr, current);
535 memcpy(addr, rstrm->in_finger, current);
536 rstrm->in_finger += current;
537 addr += current;
538 len -= current;
539 }
540 return (TRUE);
541}
542
543static bool_t /* next two bytes of the input stream are treated as a header */
544set_input_fragment(rstrm)
545 register RECSTREAM *rstrm;
546{
536 rstrm->in_finger += current;
537 addr += current;
538 len -= current;
539 }
540 return (TRUE);
541}
542
543static bool_t /* next two bytes of the input stream are treated as a header */
544set_input_fragment(rstrm)
545 register RECSTREAM *rstrm;
546{
547 u_long header;
547 u_int32_t header;
548
549 if (! get_input_bytes(rstrm, (caddr_t)&header, sizeof(header)))
550 return (FALSE);
551 header = (long)ntohl(header);
552 rstrm->last_frag = ((header & LAST_FRAG) == 0) ? FALSE : TRUE;
553 rstrm->fbtbc = header & (~LAST_FRAG);
554 return (TRUE);
555}
556
557static bool_t /* consumes input bytes; knows nothing about records! */
558skip_input_bytes(rstrm, cnt)
559 register RECSTREAM *rstrm;
560 long cnt;
561{
548
549 if (! get_input_bytes(rstrm, (caddr_t)&header, sizeof(header)))
550 return (FALSE);
551 header = (long)ntohl(header);
552 rstrm->last_frag = ((header & LAST_FRAG) == 0) ? FALSE : TRUE;
553 rstrm->fbtbc = header & (~LAST_FRAG);
554 return (TRUE);
555}
556
557static bool_t /* consumes input bytes; knows nothing about records! */
558skip_input_bytes(rstrm, cnt)
559 register RECSTREAM *rstrm;
560 long cnt;
561{
562 register int current;
562 register long current;
563
564 while (cnt > 0) {
563
564 while (cnt > 0) {
565 current = (int)rstrm->in_boundry - (int)rstrm->in_finger;
565 current = (long)rstrm->in_boundry - (long)rstrm->in_finger;
566 if (current == 0) {
567 if (! fill_input_buf(rstrm))
568 return (FALSE);
569 continue;
570 }
571 current = (cnt < current) ? cnt : current;
572 rstrm->in_finger += current;
573 cnt -= current;

--- 13 unchanged lines hidden ---
566 if (current == 0) {
567 if (! fill_input_buf(rstrm))
568 return (FALSE);
569 continue;
570 }
571 current = (cnt < current) ? cnt : current;
572 rstrm->in_finger += current;
573 cnt -= current;

--- 13 unchanged lines hidden ---