Grid Community Toolkit  6.2.1653033972 (tag: v6.2.20220524)
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
globus_i_gfs_ipc.h
1 /*
2  * Copyright 1999-2006 University of Chicago
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef GLOBUS_I_GFS_IPC_H
18 #define GLOBUS_I_GFS_IPC_H
19 
20 #include "globus_i_gridftp_server.h"
21 
22 /************************************************************************
23  * packing macros
24  * --------------
25  ***********************************************************************/
26 
27 #define GFSEncodeUInt32(_start, _len, _buf, _w) \
28 do \
29 { \
30  globus_size_t _ndx; \
31  uint32_t _cw; \
32  _ndx = (globus_byte_t *)_buf - (globus_byte_t *)_start; \
33  /* verify buffer size */ \
34  while(_ndx + 4 > _len) \
35  { \
36  _len *= 2; \
37  _start = globus_libc_realloc(_start, _len); \
38  _buf = _start + _ndx; \
39  } \
40  _cw = (uint32_t) htonl((uint32_t)_w); \
41  memcpy(_buf, &_cw, 4); \
42  _buf += 4; \
43 } while(0)
44 
45 #define GFSDecodeUInt32P(_buf, _len, _w) \
46 do \
47 { \
48  uint32_t _cw; \
49  /* verify buffer size */ \
50  if(_len - 4 < 0) \
51  { \
52  goto decode_err; \
53  } \
54  memcpy(&_cw, _buf, 4); \
55  _w = (void *) (intptr_t) htonl((uint32_t)_cw); \
56  _buf += 4; \
57  _len -= 4; \
58 } while(0)
59 
60 #define GFSDecodeUInt32(_buf, _len, _w) \
61 do \
62 { \
63  uint32_t _cw; \
64  /* verify buffer size */ \
65  if(_len - 4 < 0) \
66  { \
67  goto decode_err; \
68  } \
69  memcpy(&_cw, _buf, 4); \
70  _w = htonl((uint32_t)_cw); \
71  _buf += 4; \
72  _len -= 4; \
73 } while(0)
74 
75 
76 /*
77  * if architecture is big endian already
78  */
79 #if defined(WORDS_BIGENDIAN)
80 
81 #define GFSEncodeUInt64(_start, _len, _buf, _w) \
82 do \
83 { \
84  globus_size_t _ndx; \
85  _ndx = (globus_byte_t *)_buf - (globus_byte_t *)_start; \
86  while(_ndx + 8 > _len) \
87  { \
88  _len *= 2; \
89  _start = globus_libc_realloc(_start, _len); \
90  _buf = _start + _ndx; \
91  } \
92  memcpy(_buf, &_w, 8); \
93  _buf += 8; \
94 } while(0)
95 
96 #define GFSDecodeUInt64(_buf, _len, _w) \
97 do \
98 { \
99  if(_len - 8 < 0) \
100  { \
101  goto decode_err; \
102  } \
103  \
104  memcpy(&_w, _buf, 8); \
105  _buf += 8; \
106  _len -= 8; \
107 } while(0)
108 
109 #else
110 /* not a big indian arch */
111 #define GFSEncodeUInt64(_start, _len, _buf, _w) \
112 do \
113 { \
114  globus_size_t _ndx; \
115  uint64_t _cw; \
116  uint32_t _lo = _w & 0xffffffff; \
117  uint32_t _hi = _w >> 32U; \
118  \
119  _ndx = (globus_byte_t *)_buf - (globus_byte_t *)_start; \
120  while(_ndx + 8 > _len) \
121  { \
122  _len *= 2; \
123  _start = globus_libc_realloc(_start, _len); \
124  _buf = _start + _ndx; \
125  } \
126  \
127  _lo = ntohl(_lo); \
128  _hi = ntohl(_hi); \
129  _cw = ((uint64_t) _lo) << 32U | _hi; \
130  memcpy(_buf, &_cw, 8); \
131  _buf += 8; \
132 } while(0)
133 
134 #define GFSDecodeUInt64(_buf, _len, _w) \
135 do \
136 { \
137  uint64_t _cw; \
138  uint32_t _lo; \
139  uint32_t _hi; \
140  \
141  if(_len - 8 < 0) \
142  { \
143  goto decode_err; \
144  } \
145  \
146  memcpy(&_cw, _buf, 8); \
147  _lo = _cw & 0xffffffff; \
148  _hi = _cw >> 32U; \
149  _lo = ntohl(_lo); \
150  _hi = ntohl(_hi); \
151  _w = ((uint64_t) _lo) << 32U | _hi; \
152  _buf += 8; \
153  _len -= 8; \
154 } while(0)
155 #endif
156 
157 #define GFSEncodeChar(_start, _len, _buf, _w) \
158 do \
159 { \
160  globus_size_t _ndx; \
161  _ndx = (globus_byte_t *)_buf - (globus_byte_t *)_start; \
162  while(_ndx >= _len) \
163  { \
164  _len *= 2; \
165  _start = globus_libc_realloc(_start, _len); \
166  _buf = _start + _ndx; \
167  } \
168  *_buf = (char)_w; \
169  _buf++; \
170 } while(0)
171 
172 #define GFSDecodeChar(_buf, _len, _w) \
173 do \
174 { \
175  if(_len - 1 < 0) \
176  { \
177  goto decode_err; \
178  } \
179  _w = (char)*_buf; \
180  _buf++; \
181  _len--; \
182 } while(0)
183 
184 #define GFSEncodeString(_start, _len, _buf, _w) \
185 do \
186 { \
187  char * _str=(char*)_w; \
188  if(_str == NULL) \
189  { \
190  GFSEncodeUInt32(_start, _len, _buf, 0); \
191  } \
192  else \
193  { \
194  GFSEncodeUInt32(_start, _len, _buf, strlen(_str)+1); \
195  for(_str = (char *)_w; *_str != '\0'; _str++) \
196  { \
197  GFSEncodeChar(_start, _len, _buf, *_str); \
198  } \
199  } \
200 } while(0)
201 
202 #define GFSDecodeString(_buf, _len, _w) \
203 do \
204 { \
205  int _ctr; \
206  uint32_t _sz; \
207  /* make sure that strip in terminated properly */ \
208  GFSDecodeUInt32(_buf, _len, _sz); \
209  if(_sz > 0) \
210  { \
211  _w = malloc(_sz); \
212  for(_ctr = 0; _ctr < _sz - 1; _ctr++) \
213  { \
214  GFSDecodeChar(_buf, _len, _w[_ctr]); \
215  } \
216  _w[_ctr] = '\0'; \
217  } \
218  else \
219  { \
220  _w = NULL; \
221  } \
222 } while(0)
223 
224 void *
225 globus_i_gfs_ipc_query_op_info(
226  int op_info_id);
227 
228 extern globus_xio_stack_t globus_i_gfs_ipc_xio_stack;
229 extern globus_xio_driver_t globus_i_gfs_tcp_driver;
230 
231 #endif