globus_connect_gridftp_server 16.16~rc1
Loading...
Searching...
No Matches
/build/globus-connect-gridftp-server-16.16~rc1/globus_i_gfs_ipc.h
1/*
2 * Copyright The University of Chicago
3 *
4 * All Rights Reserved.
5 */
6
7#ifndef GLOBUS_I_GFS_IPC_H
8#define GLOBUS_I_GFS_IPC_H
9
10#include "globus_i_gridftp_server.h"
11
12/************************************************************************
13 * packing macros
14 * --------------
15 ***********************************************************************/
16
17#define GFSEncodeUInt32(_start, _len, _buf, _w) \
18do \
19{ \
20 globus_size_t _ndx; \
21 uint32_t _cw; \
22 _ndx = (globus_byte_t *)_buf - (globus_byte_t *)_start; \
23 /* verify buffer size */ \
24 while(_ndx + 4 > _len) \
25 { \
26 _len *= 2; \
27 _start = globus_libc_realloc(_start, _len); \
28 _buf = _start + _ndx; \
29 } \
30 _cw = (uint32_t) htonl((uint32_t)_w); \
31 memcpy(_buf, &_cw, 4); \
32 _buf += 4; \
33} while(0)
34
35#define GFSDecodeUInt32P(_buf, _len, _w) \
36do \
37{ \
38 uint32_t _cw; \
39 /* verify buffer size */ \
40 if(_len - 4 < 0) \
41 { \
42 goto decode_err; \
43 } \
44 memcpy(&_cw, _buf, 4); \
45 _w = (void *) (intptr_t) htonl((uint32_t)_cw); \
46 _buf += 4; \
47 _len -= 4; \
48} while(0)
49
50#define GFSDecodeUInt32(_buf, _len, _w) \
51do \
52{ \
53 uint32_t _cw; \
54 /* verify buffer size */ \
55 if(_len - 4 < 0) \
56 { \
57 goto decode_err; \
58 } \
59 memcpy(&_cw, _buf, 4); \
60 _w = htonl((uint32_t)_cw); \
61 _buf += 4; \
62 _len -= 4; \
63} while(0)
64
65
66/*
67 * if architecture is big endian already
68 */
69#if defined(WORDS_BIGENDIAN)
70
71#define GFSEncodeUInt64(_start, _len, _buf, _w) \
72do \
73{ \
74 globus_size_t _ndx; \
75 _ndx = (globus_byte_t *)_buf - (globus_byte_t *)_start; \
76 while(_ndx + 8 > _len) \
77 { \
78 _len *= 2; \
79 _start = globus_libc_realloc(_start, _len); \
80 _buf = _start + _ndx; \
81 } \
82 memcpy(_buf, &_w, 8); \
83 _buf += 8; \
84} while(0)
85
86#define GFSDecodeUInt64(_buf, _len, _w) \
87do \
88{ \
89 if(_len - 8 < 0) \
90 { \
91 goto decode_err; \
92 } \
93 \
94 memcpy(&_w, _buf, 8); \
95 _buf += 8; \
96 _len -= 8; \
97} while(0)
98
99#else
100/* not a big indian arch */
101#define GFSEncodeUInt64(_start, _len, _buf, _w) \
102do \
103{ \
104 globus_size_t _ndx; \
105 uint64_t _cw; \
106 uint32_t _lo = _w & 0xffffffff; \
107 uint32_t _hi = _w >> 32U; \
108 \
109 _ndx = (globus_byte_t *)_buf - (globus_byte_t *)_start; \
110 while(_ndx + 8 > _len) \
111 { \
112 _len *= 2; \
113 _start = globus_libc_realloc(_start, _len); \
114 _buf = _start + _ndx; \
115 } \
116 \
117 _lo = ntohl(_lo); \
118 _hi = ntohl(_hi); \
119 _cw = ((uint64_t) _lo) << 32U | _hi; \
120 memcpy(_buf, &_cw, 8); \
121 _buf += 8; \
122} while(0)
123
124#define GFSDecodeUInt64(_buf, _len, _w) \
125do \
126{ \
127 uint64_t _cw; \
128 uint32_t _lo; \
129 uint32_t _hi; \
130 \
131 if(_len - 8 < 0) \
132 { \
133 goto decode_err; \
134 } \
135 \
136 memcpy(&_cw, _buf, 8); \
137 _lo = _cw & 0xffffffff; \
138 _hi = _cw >> 32U; \
139 _lo = ntohl(_lo); \
140 _hi = ntohl(_hi); \
141 _w = ((uint64_t) _lo) << 32U | _hi; \
142 _buf += 8; \
143 _len -= 8; \
144} while(0)
145#endif
146
147#define GFSEncodeChar(_start, _len, _buf, _w) \
148do \
149{ \
150 globus_size_t _ndx; \
151 _ndx = (globus_byte_t *)_buf - (globus_byte_t *)_start; \
152 while(_ndx >= _len) \
153 { \
154 _len *= 2; \
155 _start = globus_libc_realloc(_start, _len); \
156 _buf = _start + _ndx; \
157 } \
158 *_buf = (char)_w; \
159 _buf++; \
160} while(0)
161
162#define GFSDecodeChar(_buf, _len, _w) \
163do \
164{ \
165 if(_len - 1 < 0) \
166 { \
167 goto decode_err; \
168 } \
169 _w = (char)*_buf; \
170 _buf++; \
171 _len--; \
172} while(0)
173
174#define GFSEncodeString(_start, _len, _buf, _w) \
175do \
176{ \
177 char * _str=(char*)_w; \
178 if(_str == NULL) \
179 { \
180 GFSEncodeUInt32(_start, _len, _buf, 0); \
181 } \
182 else \
183 { \
184 GFSEncodeUInt32(_start, _len, _buf, strlen(_str)+1); \
185 for(_str = (char *)_w; *_str != '\0'; _str++) \
186 { \
187 GFSEncodeChar(_start, _len, _buf, *_str); \
188 } \
189 } \
190} while(0)
191
192#define GFSDecodeString(_buf, _len, _w) \
193do \
194{ \
195 int _ctr; \
196 uint32_t _sz; \
197 /* make sure that strip in terminated properly */ \
198 GFSDecodeUInt32(_buf, _len, _sz); \
199 if(_sz > 0) \
200 { \
201 _w = malloc(_sz); \
202 for(_ctr = 0; _ctr < _sz - 1; _ctr++) \
203 { \
204 GFSDecodeChar(_buf, _len, _w[_ctr]); \
205 } \
206 _w[_ctr] = '\0'; \
207 } \
208 else \
209 { \
210 _w = NULL; \
211 } \
212} while(0)
213
214void *
215globus_i_gfs_ipc_query_op_info(
216 int op_info_id);
217
218extern globus_xio_stack_t globus_i_gfs_ipc_xio_stack;
219extern globus_xio_driver_t globus_i_gfs_tcp_driver;
220
221#endif