~ubuntu-branches/ubuntu/natty/globus-gridftp-server/natty-updates

« back to all changes in this revision

Viewing changes to globus_i_gfs_ipc.h

  • Committer: Bazaar Package Importer
  • Author(s): Mattias Ellert
  • Date: 2009-08-07 07:24:28 UTC
  • Revision ID: james.westby@ubuntu.com-20090807072428-0bb06irrkoi81fu1
Tags: upstream-3.17
ImportĀ upstreamĀ versionĀ 3.17

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#define GFSEncodeUInt32(_start, _len, _buf, _w)                         \
 
27
do                                                                      \
 
28
{                                                                       \
 
29
    globus_size_t                       _ndx;                           \
 
30
    uint32_t                            _cw;                            \
 
31
    _ndx = (globus_byte_t *)_buf - (globus_byte_t *)_start;             \
 
32
    /* verify buffer size */                                            \
 
33
    if(_ndx + 4 > _len)                                                 \
 
34
    {                                                                   \
 
35
        _len *= 2;                                                      \
 
36
        _start = globus_libc_realloc(_start, _len);                     \
 
37
        _buf = _start + _ndx;                                           \
 
38
    }                                                                   \
 
39
    _cw = htonl((uint32_t)_w);                                          \
 
40
    memcpy(_buf, &_cw, 4);                                              \
 
41
    _buf += 4;                                                          \
 
42
} while(0)
 
43
 
 
44
#define GFSDecodeUInt32P(_buf, _len, _w)                                \
 
45
do                                                                      \
 
46
{                                                                       \
 
47
    uint32_t                            _cw;                            \
 
48
    /* verify buffer size */                                            \
 
49
    if(_len - 4 < 0)                                                    \
 
50
    {                                                                   \
 
51
        goto decode_err;                                                \
 
52
    }                                                                   \
 
53
    memcpy(&_cw, _buf, 4);                                              \
 
54
    _w = (void *) htonl((uint32_t)_cw);                                 \
 
55
    _buf += 4;                                                          \
 
56
    _len -= 4;                                                          \
 
57
} while(0)
 
58
 
 
59
#define GFSDecodeUInt32(_buf, _len, _w)                                 \
 
60
do                                                                      \
 
61
{                                                                       \
 
62
    uint32_t                            _cw;                            \
 
63
    /* verify buffer size */                                            \
 
64
    if(_len - 4 < 0)                                                    \
 
65
    {                                                                   \
 
66
        goto decode_err;                                                \
 
67
    }                                                                   \
 
68
    memcpy(&_cw, _buf, 4);                                              \
 
69
    _w = htonl((uint32_t)_cw);                                          \
 
70
    _buf += 4;                                                          \
 
71
    _len -= 4;                                                          \
 
72
} while(0)
 
73
 
 
74
 
 
75
/*
 
76
 *  if architecture is big endian already
 
77
 */
 
78
#if defined(WORDS_BIGENDIAN)
 
79
 
 
80
#define GFSEncodeUInt64(_start, _len, _buf, _w)                         \
 
81
do                                                                      \
 
82
{                                                                       \
 
83
    globus_size_t                       _ndx;                           \
 
84
    _ndx = (globus_byte_t *)_buf - (globus_byte_t *)_start;             \
 
85
    if(_ndx + 8 > _len)                                                 \
 
86
    {                                                                   \
 
87
        _len *= 2;                                                      \
 
88
        _start = globus_libc_realloc(_start, _len);                     \
 
89
        _buf = _start + _ndx;                                           \
 
90
    }                                                                   \
 
91
    memcpy(_buf, &_w, 8);                                               \
 
92
    _buf += 8;                                                          \
 
93
} while(0)
 
94
 
 
95
#define GFSDecodeUInt64(_buf, _len, _w)                                 \
 
96
do                                                                      \
 
97
{                                                                       \
 
98
    if(_len - 8 < 0)                                                    \
 
99
    {                                                                   \
 
100
        goto decode_err;                                                \
 
101
    }                                                                   \
 
102
                                                                        \
 
103
    memcpy(&_w, _buf, 8);                                               \
 
104
    _buf += 8;                                                          \
 
105
    _len -= 8;                                                          \
 
106
} while(0)
 
107
 
 
108
#else                                                                
 
109
/* not a big indian arch */
 
110
#define GFSEncodeUInt64(_start, _len, _buf, _w)                         \
 
111
do                                                                      \
 
112
{                                                                       \
 
113
    globus_size_t                       _ndx;                           \
 
114
    uint64_t                            _cw;                            \
 
115
    uint32_t                            _lo = _w & 0xffffffff;          \
 
116
    uint32_t                            _hi = _w >> 32U;                \
 
117
                                                                        \
 
118
    _ndx = (globus_byte_t *)_buf - (globus_byte_t *)_start;             \
 
119
    if(_ndx + 8 > _len)                                                 \
 
120
    {                                                                   \
 
121
        _len *= 2;                                                      \
 
122
        _start = globus_libc_realloc(_start, _len);                     \
 
123
        _buf = _start + _ndx;                                           \
 
124
    }                                                                   \
 
125
                                                                        \
 
126
    _lo = ntohl(_lo);                                                   \
 
127
    _hi = ntohl(_hi);                                                   \
 
128
    _cw = ((uint64_t) _lo) << 32U | _hi;                                \
 
129
    memcpy(_buf, &_cw, 8);                                              \
 
130
    _buf += 8;                                                          \
 
131
} while(0)
 
132
 
 
133
#define GFSDecodeUInt64(_buf, _len, _w)                                 \
 
134
do                                                                      \
 
135
{                                                                       \
 
136
    uint64_t                            _cw;                            \
 
137
    uint32_t                            _lo;                            \
 
138
    uint32_t                            _hi;                            \
 
139
                                                                        \
 
140
    if(_len - 8 < 0)                                                    \
 
141
    {                                                                   \
 
142
        goto decode_err;                                                \
 
143
    }                                                                   \
 
144
                                                                        \
 
145
    memcpy(&_cw, _buf, 8);                                              \
 
146
    _lo = _cw & 0xffffffff;                                             \
 
147
    _hi = _cw >> 32U;                                                   \
 
148
    _lo = ntohl(_lo);                                                   \
 
149
    _hi = ntohl(_hi);                                                   \
 
150
    _w = ((uint64_t) _lo) << 32U | _hi;                                 \
 
151
    _buf += 8;                                                          \
 
152
    _len -= 8;                                                          \
 
153
} while(0)
 
154
#endif                                                               
 
155
 
 
156
#define GFSEncodeChar(_start, _len, _buf, _w)                           \
 
157
do                                                                      \
 
158
{                                                                       \
 
159
    globus_size_t                       _ndx;                           \
 
160
    _ndx = (globus_byte_t *)_buf - (globus_byte_t *)_start;             \
 
161
    if(_ndx >= _len)                                                    \
 
162
    {                                                                   \
 
163
        _len *= 2;                                                      \
 
164
        _start = globus_libc_realloc(_start, _len);                     \
 
165
        _buf = _start + _ndx;                                           \
 
166
    }                                                                   \
 
167
    *_buf = (char)_w;                                                   \
 
168
    _buf++;                                                             \
 
169
} while(0)
 
170
 
 
171
#define GFSDecodeChar(_buf, _len, _w)                                   \
 
172
do                                                                      \
 
173
{                                                                       \
 
174
    if(_len - 1 < 0)                                                    \
 
175
    {                                                                   \
 
176
        goto decode_err;                                                \
 
177
    }                                                                   \
 
178
    _w = (char)*_buf;                                                   \
 
179
    _buf++;                                                             \
 
180
    _len--;                                                             \
 
181
} while(0)
 
182
 
 
183
#define GFSEncodeString(_start, _len, _buf, _w)                         \
 
184
do                                                                      \
 
185
{                                                                       \
 
186
    char *                              _str=(char*)_w;                 \
 
187
    if(_str == NULL)                                                    \
 
188
    {                                                                   \
 
189
        GFSEncodeUInt32(_start, _len, _buf, 0);                         \
 
190
    }                                                                   \
 
191
    else                                                                \
 
192
    {                                                                   \
 
193
        GFSEncodeUInt32(_start, _len, _buf, strlen(_str)+1);            \
 
194
        for(_str = (char *)_w; *_str != '\0'; _str++)                   \
 
195
        {                                                               \
 
196
            GFSEncodeChar(_start, _len, _buf, *_str);                   \
 
197
        }                                                               \
 
198
    }                                                                   \
 
199
} while(0)
 
200
 
 
201
#define GFSDecodeString(_buf, _len, _w)                                 \
 
202
do                                                                      \
 
203
{                                                                       \
 
204
    int                                 _ctr;                           \
 
205
    uint32_t                            _sz;                            \
 
206
    /* make sure that strip in terminated properly */                   \
 
207
    GFSDecodeUInt32(_buf, _len, _sz);                                   \
 
208
    if(_sz > 0)                                                         \
 
209
    {                                                                   \
 
210
        _w = malloc(_sz);                                               \
 
211
        for(_ctr = 0; _ctr < _sz - 1; _ctr++)                           \
 
212
        {                                                               \
 
213
            GFSDecodeChar(_buf, _len, _w[_ctr]);                        \
 
214
        }                                                               \
 
215
        _w[_ctr] = '\0';                                                \
 
216
    }                                                                   \
 
217
    else                                                                \
 
218
    {                                                                   \
 
219
        _w = NULL;                                                      \
 
220
    }                                                                   \
 
221
} while(0)
 
222
 
 
223
typedef struct globus_i_gfs_community_s
 
224
{
 
225
    char *                              root;
 
226
    char *                              name;
 
227
    int                                 cs_count;
 
228
    char **                             cs;
 
229
    int                                 next_ndx;
 
230
} globus_i_gfs_community_t;
 
231
 
 
232
extern globus_xio_stack_t               globus_i_gfs_ipc_xio_stack;
 
233
extern globus_i_gfs_community_t *       globus_i_gfs_ipc_community_default;
 
234
extern globus_xio_driver_t              globus_i_gfs_tcp_driver;
 
235
 
 
236
#endif