Logo ROOT  
Reference Guide
XProofProtUtils.cxx
Go to the documentation of this file.
1// @(#)root/proofd:$Id$
2// Author: Gerardo Ganis 12/12/2005
3
4/*************************************************************************
5 * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//////////////////////////////////////////////////////////////////////////
13// //
14// XProofProtUtils.cxx //
15// //
16// Authors: G. Ganis, CERN 2005 //
17// //
18// Utility functions prototypes for client-to-server //
19// //
20//////////////////////////////////////////////////////////////////////////
21
22#ifdef __APPLE__
23# ifndef __macos__
24# define __macos__
25# endif
26#endif
27#ifdef __sun
28# ifndef __solaris__
29# define __solaris__
30# endif
31#endif
32#ifndef WIN32
33# include <sys/types.h>
34# ifndef ROOT_XrdFour
35# include <netinet/in.h>
36# endif
37#endif
38#include "XrdSys/XrdSysPlatform.hh"
39#include "XProofProtocol.h"
40#include "XProofProtUtils.h"
41#include "Bytes.h"
42
43#include <cstdio>
44
45namespace XPD {
46
47////////////////////////////////////////////////////////////////////////////////
48/// This function applies the network byte order on those
49/// parts of the 16-bytes buffer, only if it is composed
50/// by some binary part
51/// Return 0 if OK, -1 in case the ID is unknown
52
54{
55 switch(str->header.requestid) {
56
57 case kXP_login:
58 str->login.pid = htonl(str->login.pid);
59 break;
60 case kXP_auth:
61 // no swap on ASCII fields
62 break;
63 case kXP_create:
64 // no swap on ASCII fields
65 str->proof.int1 = htonl(str->proof.int1);
66 break;
67 case kXP_destroy:
68 str->proof.sid = htonl(str->proof.sid);
69 break;
70 case kXP_attach:
71 str->proof.sid = htonl(str->proof.sid);
72 break;
73 case kXP_detach:
74 str->proof.sid = htonl(str->proof.sid);
75 break;
76 case kXP_cleanup:
77 str->proof.sid = htonl(str->proof.sid);
78 str->proof.int1 = htonl(str->proof.int1);
79 str->proof.int2 = htonl(str->proof.int2);
80 break;
81 case kXP_sendmsg:
82 str->sendrcv.sid = htonl(str->sendrcv.sid);
83 str->sendrcv.opt = htonl(str->sendrcv.opt);
84 str->sendrcv.cid = htonl(str->sendrcv.cid);
85 break;
86 case kXP_admin:
87 str->proof.sid = htonl(str->proof.sid);
88 str->proof.int1 = htonl(str->proof.int1);
89 str->proof.int2 = htonl(str->proof.int2);
90 str->proof.int3 = htonl(str->proof.int3);
91 break;
92 case kXP_readbuf:
93 str->readbuf.ofs = htonll(str->readbuf.ofs);
94 str->readbuf.len = htonl(str->readbuf.len);
95 str->readbuf.int1 = htonl(str->readbuf.int1);
96 break;
97 case kXP_interrupt:
98 str->interrupt.sid = htonl(str->interrupt.sid);
99 str->interrupt.type = htonl(str->interrupt.type);
100 break;
101 case kXP_ping:
102 str->sendrcv.sid = htonl(str->sendrcv.sid);
103 str->sendrcv.opt = htonl(str->sendrcv.opt);
104 break;
105 case kXP_urgent:
106 str->proof.sid = htonl(str->proof.sid);
107 str->proof.int1 = htonl(str->proof.int1);
108 str->proof.int2 = htonl(str->proof.int2);
109 str->proof.int3 = htonl(str->proof.int3);
110 break;
111 case kXP_touch:
112 str->sendrcv.sid = htonl(str->sendrcv.sid);
113 break;
114 case kXP_ctrlc:
115 str->proof.sid = htonl(str->sendrcv.sid);
116 break;
117 default:
118 fprintf(stderr,"clientMarshall: unknown req ID: %d (0x%x)\n",
119 str->header.requestid, str->header.requestid);
120 return -1;
121 break;
122 }
123
124 str->header.requestid = htons(str->header.requestid);
125 str->header.dlen = htonl(str->header.dlen);
126
127 return 0;
128}
129
130////////////////////////////////////////////////////////////////////////////////
131
132void clientUnmarshall(struct ServerResponseHeader* str)
133{
134 str->status = ntohs(str->status);
135 str->dlen = ntohl(str->dlen);
136}
137
138////////////////////////////////////////////////////////////////////////////////
139
140void ServerResponseHeader2NetFmt(struct ServerResponseHeader *srh)
141{
142 srh->status = htons(srh->status);
143 srh->dlen = htonl(srh->dlen);
144}
145
146////////////////////////////////////////////////////////////////////////////////
147
148void ServerInitHandShake2HostFmt(struct ServerInitHandShake *srh)
149{
150 srh->msglen = ntohl(srh->msglen);
151 srh->protover = ntohl(srh->protover);
152 srh->msgval = ntohl(srh->msgval);
153}
154
155////////////////////////////////////////////////////////////////////////////////
156/// This procedure convert the request code id (an integer defined in
157/// XProtocol.hh) in the ascii label (human readable)
158
159char *convertRequestIdToChar(kXR_int16 requestid)
160{
161 switch(requestid) {
162
163 case kXP_login:
164 return (char *)"kXP_login";
165 case kXP_auth:
166 return (char *)"kXP_auth";
167 case kXP_create:
168 return (char *)"kXP_create";
169 case kXP_destroy:
170 return (char *)"kXP_destroy";
171 case kXP_attach:
172 return (char *)"kXP_attach";
173 case kXP_detach:
174 return (char *)"kXP_detach";
175 case kXP_sendmsg:
176 return (char *)"kXP_sendmsg";
177 case kXP_admin:
178 return (char *)"kXP_admin";
179 case kXP_readbuf:
180 return (char *)"kXP_readbuf";
181 case kXP_interrupt:
182 return (char *)"kXP_interrupt";
183 case kXP_ping:
184 return (char *)"kXP_ping";
185 case kXP_cleanup:
186 return (char *)"kXP_cleanup";
187 case kXP_urgent:
188 return (char *)"kXP_urgent";
189 case kXP_touch:
190 return (char *)"kXP_touch";
191 case kXP_ctrlc:
192 return (char *)"kXP_ctrlc";
193 default:
194 return (char *)"kXP_UNKNOWN";
195 }
196}
197
198////////////////////////////////////////////////////////////////////////////////
199
200char *convertRespStatusToChar(kXR_int16 status)
201{
202 switch( status) {
203 case kXP_ok:
204 return (char *)"kXP_ok";
205 break;
206 case kXP_oksofar:
207 return (char *)"kXP_oksofar";
208 break;
209 case kXP_attn:
210 return (char *)"kXP_attn";
211 break;
212 case kXP_authmore:
213 return (char *)"kXP_authmore";
214 break;
215 case kXP_error:
216 return (char *)"kXP_error";
217 break;
218 case kXP_wait:
219 return (char *)"kXP_wait";
220 break;
221 default:
222 return (char *)"kXP_UNKNOWN";
223 break;
224 }
225}
226
227////////////////////////////////////////////////////////////////////////////////
228
230{
231 printf("\n\n================= DUMPING CLIENT REQUEST HEADER =================\n");
232
233 printf("%40s0x%.2x 0x%.2x\n", "ClientHeader.streamid = ",
234 hdr->header.streamid[0], hdr->header.streamid[1]);
235
236 printf("%40s%s (%d)\n", "ClientHeader.requestid = ",
237 convertRequestIdToChar(hdr->header.requestid), hdr->header.requestid);
238
239 void *tmp;
240 switch(hdr->header.requestid) {
241
242 case kXP_login:
243 printf("%40s%d \n", "ClientHeader.login.pid = ", hdr->login.pid);
244 printf("%40s%s\n", "ClientHeader.login_body.username = ", hdr->login.username);
245 tmp = &hdr->login.reserved[0];
246 printf("%40s0 repeated %d times\n", "ClientHeader.login.reserved = ",
247 *((kXR_int16 *)tmp)); // use tmp to avoid type punned warning
248 printf("%40s%d\n", "ClientHeader.login.role = ", (kXR_int32)hdr->login.role[0]);
249 break;
250 case kXP_auth:
251 printf("%40s0 repeated %d times\n", "ClientHeader.auth.reserved = ",
252 (kXR_int32)sizeof(hdr->auth.reserved));
253 printf(" ClientHeader.auth.credtype= 0x%.2x 0x%.2x 0x%.2x 0x%.2x \n",
254 hdr->auth.credtype[0], hdr->auth.credtype[1],
255 hdr->auth.credtype[2], hdr->auth.credtype[3]);
256 break;
257 case kXP_create:
258 break;
259 case kXP_destroy:
260 printf("%40s%d \n", "ClientHeader.proof.sid = ", hdr->proof.sid);
261 break;
262 case kXP_attach:
263 printf("%40s%d \n", "ClientHeader.proof.sid = ", hdr->proof.sid);
264 break;
265 case kXP_detach:
266 printf("%40s%d \n", "ClientHeader.proof.sid = ", hdr->proof.sid);
267 break;
268 case kXP_ctrlc:
269 printf("%40s%d \n", "ClientHeader.proof.sid = ", hdr->proof.sid);
270 break;
271 case kXP_cleanup:
272 printf("%40s%d \n", "ClientHeader.proof.sid = ", hdr->proof.sid);
273 printf("%40s%d \n", "ClientHeader.proof.int1 = ", hdr->proof.int1);
274 printf("%40s%d \n", "ClientHeader.proof.int2 = ", hdr->proof.int2);
275 break;
276 case kXP_sendmsg:
277 printf("%40s%d \n", "ClientHeader.sendrcv.sid = ", hdr->sendrcv.sid);
278 printf("%40s%d \n", "ClientHeader.sendrcv.opt = ", hdr->sendrcv.opt);
279 printf("%40s%d \n", "ClientHeader.sendrcv.cid = ", hdr->sendrcv.cid);
280 break;
281 case kXP_interrupt:
282 printf("%40s%d \n", "ClientHeader.interrupt.sid = ", hdr->interrupt.sid);
283 printf("%40s%d \n", "ClientHeader.interrupt.type = ", hdr->interrupt.type);
284 break;
285 case kXP_ping:
286 printf("%40s%d \n", "ClientHeader.sendrcv.sid = ", hdr->sendrcv.sid);
287 printf("%40s%d \n", "ClientHeader.sendrcv.opt = ", hdr->sendrcv.opt);
288 break;
289 case kXP_touch:
290 printf("%40s%d \n", "ClientHeader.sendrcv.sid = ", hdr->sendrcv.sid);
291 break;
292 case kXP_admin:
293 case kXP_urgent:
294 printf("%40s%d \n", "ClientHeader.proof.sid = ", hdr->proof.sid);
295 printf("%40s%d \n", "ClientHeader.proof.int1 = ", hdr->proof.int1);
296 printf("%40s%d \n", "ClientHeader.proof.int2 = ", hdr->proof.int2);
297 printf("%40s%d \n", "ClientHeader.proof.int3 = ", hdr->proof.int3);
298 break;
299 case kXP_readbuf:
300 printf("%40s%lld \n", "ClientHeader.readbuf.ofs = ", hdr->readbuf.ofs);
301 printf("%40s%d \n", "ClientHeader.readbuf.len = ", hdr->readbuf.len);
302 break;
303 default:
304 printf("Unknown request ID: %d ! \n", hdr->header.requestid);
305 }
306
307 printf("%40s%d", "ClientHeader.header.dlen = ", hdr->header.dlen);
308 printf("\n=================== END CLIENT HEADER DUMPING ===================\n\n");
309}
310
311////////////////////////////////////////////////////////////////////////////////
312
313void smartPrintServerHeader(struct ServerResponseHeader* hdr)
314{
315 printf("\n\n======== DUMPING SERVER RESPONSE HEADER ========\n");
316 printf("%30s0x%.2x 0x%.2x\n", "ServerHeader.streamid = ",
317 hdr->streamid[0], hdr->streamid[1]);
318 switch(hdr->status) {
319 case kXP_ok:
320 printf("%30skXP_ok", "ServerHeader.status = ");
321 break;
322 case kXP_attn:
323 printf("%30skXP_attn", "ServerHeader.status = ");
324 break;
325 case kXP_authmore:
326 printf("%30skXP_authmore", "ServerHeader.status = ");
327 break;
328 case kXP_error:
329 printf("%30skXP_error", "ServerHeader.status = ");
330 break;
331 case kXP_oksofar:
332 printf("%30skXP_oksofar", "ServerHeader.status = ");
333 break;
334 case kXP_wait:
335 printf("%30skXP_wait", "ServerHeader.status = ");
336 break;
337 }
338 printf(" (%d)\n", hdr->status);
339 printf("%30s%d", "ServerHeader.dlen = ", hdr->dlen);
340 printf("\n========== END DUMPING SERVER HEADER ===========\n\n");
341}
342
343} // namespace ROOT
@ kXP_create
@ kXP_destroy
@ kXP_cleanup
@ kXP_sendmsg
@ kXP_ping
@ kXP_urgent
@ kXP_touch
@ kXP_detach
@ kXP_attach
@ kXP_interrupt
@ kXP_readbuf
@ kXP_auth
@ kXP_login
@ kXP_admin
@ kXP_ctrlc
@ kXP_wait
@ kXP_ok
@ kXP_authmore
@ kXP_error
@ kXP_oksofar
@ kXP_attn
void smartPrintClientHeader(XPClientRequest *hdr)
char * convertRespStatusToChar(kXR_int16 status)
void ServerResponseHeader2NetFmt(struct ServerResponseHeader *srh)
void ServerInitHandShake2HostFmt(struct ServerInitHandShake *srh)
void clientUnmarshall(struct ServerResponseHeader *str)
char * convertRequestIdToChar(kXR_int16 requestid)
This procedure convert the request code id (an integer defined in XProtocol.hh) in the ascii label (h...
void smartPrintServerHeader(struct ServerResponseHeader *hdr)
int clientMarshall(XPClientRequest *str)
This function applies the network byte order on those parts of the 16-bytes buffer,...
struct XPClientLoginRequest login
struct ClientRequestHdr header
struct XPClientProofRequest proof
struct XPClientInterruptRequest interrupt
struct ClientAuthRequest auth
struct XPClientSendRcvRequest sendrcv
struct XPClientReadbufRequest readbuf