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
44namespace XPD {
45
46////////////////////////////////////////////////////////////////////////////////
47/// This function applies the network byte order on those
48/// parts of the 16-bytes buffer, only if it is composed
49/// by some binary part
50/// Return 0 if OK, -1 in case the ID is unknown
51
53{
54 switch(str->header.requestid) {
55
56 case kXP_login:
57 str->login.pid = htonl(str->login.pid);
58 break;
59 case kXP_auth:
60 // no swap on ASCII fields
61 break;
62 case kXP_create:
63 // no swap on ASCII fields
64 str->proof.int1 = htonl(str->proof.int1);
65 break;
66 case kXP_destroy:
67 str->proof.sid = htonl(str->proof.sid);
68 break;
69 case kXP_attach:
70 str->proof.sid = htonl(str->proof.sid);
71 break;
72 case kXP_detach:
73 str->proof.sid = htonl(str->proof.sid);
74 break;
75 case kXP_cleanup:
76 str->proof.sid = htonl(str->proof.sid);
77 str->proof.int1 = htonl(str->proof.int1);
78 str->proof.int2 = htonl(str->proof.int2);
79 break;
80 case kXP_sendmsg:
81 str->sendrcv.sid = htonl(str->sendrcv.sid);
82 str->sendrcv.opt = htonl(str->sendrcv.opt);
83 str->sendrcv.cid = htonl(str->sendrcv.cid);
84 break;
85 case kXP_admin:
86 str->proof.sid = htonl(str->proof.sid);
87 str->proof.int1 = htonl(str->proof.int1);
88 str->proof.int2 = htonl(str->proof.int2);
89 str->proof.int3 = htonl(str->proof.int3);
90 break;
91 case kXP_readbuf:
92 str->readbuf.ofs = htonll(str->readbuf.ofs);
93 str->readbuf.len = htonl(str->readbuf.len);
94 str->readbuf.int1 = htonl(str->readbuf.int1);
95 break;
96 case kXP_interrupt:
97 str->interrupt.sid = htonl(str->interrupt.sid);
98 str->interrupt.type = htonl(str->interrupt.type);
99 break;
100 case kXP_ping:
101 str->sendrcv.sid = htonl(str->sendrcv.sid);
102 str->sendrcv.opt = htonl(str->sendrcv.opt);
103 break;
104 case kXP_urgent:
105 str->proof.sid = htonl(str->proof.sid);
106 str->proof.int1 = htonl(str->proof.int1);
107 str->proof.int2 = htonl(str->proof.int2);
108 str->proof.int3 = htonl(str->proof.int3);
109 break;
110 case kXP_touch:
111 str->sendrcv.sid = htonl(str->sendrcv.sid);
112 break;
113 case kXP_ctrlc:
114 str->proof.sid = htonl(str->sendrcv.sid);
115 break;
116 default:
117 fprintf(stderr,"clientMarshall: unknown req ID: %d (0x%x)\n",
118 str->header.requestid, str->header.requestid);
119 return -1;
120 break;
121 }
122
123 str->header.requestid = htons(str->header.requestid);
124 str->header.dlen = htonl(str->header.dlen);
125
126 return 0;
127}
128
129////////////////////////////////////////////////////////////////////////////////
130
131void clientUnmarshall(struct ServerResponseHeader* str)
132{
133 str->status = ntohs(str->status);
134 str->dlen = ntohl(str->dlen);
135}
136
137////////////////////////////////////////////////////////////////////////////////
138
139void ServerResponseHeader2NetFmt(struct ServerResponseHeader *srh)
140{
141 srh->status = htons(srh->status);
142 srh->dlen = htonl(srh->dlen);
143}
144
145////////////////////////////////////////////////////////////////////////////////
146
147void ServerInitHandShake2HostFmt(struct ServerInitHandShake *srh)
148{
149 srh->msglen = ntohl(srh->msglen);
150 srh->protover = ntohl(srh->protover);
151 srh->msgval = ntohl(srh->msgval);
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// This procedure convert the request code id (an integer defined in
156/// XProtocol.hh) in the ascii label (human readable)
157
158char *convertRequestIdToChar(kXR_int16 requestid)
159{
160 switch(requestid) {
161
162 case kXP_login:
163 return (char *)"kXP_login";
164 case kXP_auth:
165 return (char *)"kXP_auth";
166 case kXP_create:
167 return (char *)"kXP_create";
168 case kXP_destroy:
169 return (char *)"kXP_destroy";
170 case kXP_attach:
171 return (char *)"kXP_attach";
172 case kXP_detach:
173 return (char *)"kXP_detach";
174 case kXP_sendmsg:
175 return (char *)"kXP_sendmsg";
176 case kXP_admin:
177 return (char *)"kXP_admin";
178 case kXP_readbuf:
179 return (char *)"kXP_readbuf";
180 case kXP_interrupt:
181 return (char *)"kXP_interrupt";
182 case kXP_ping:
183 return (char *)"kXP_ping";
184 case kXP_cleanup:
185 return (char *)"kXP_cleanup";
186 case kXP_urgent:
187 return (char *)"kXP_urgent";
188 case kXP_touch:
189 return (char *)"kXP_touch";
190 case kXP_ctrlc:
191 return (char *)"kXP_ctrlc";
192 default:
193 return (char *)"kXP_UNKNOWN";
194 }
195}
196
197////////////////////////////////////////////////////////////////////////////////
198
199char *convertRespStatusToChar(kXR_int16 status)
200{
201 switch( status) {
202 case kXP_ok:
203 return (char *)"kXP_ok";
204 break;
205 case kXP_oksofar:
206 return (char *)"kXP_oksofar";
207 break;
208 case kXP_attn:
209 return (char *)"kXP_attn";
210 break;
211 case kXP_authmore:
212 return (char *)"kXP_authmore";
213 break;
214 case kXP_error:
215 return (char *)"kXP_error";
216 break;
217 case kXP_wait:
218 return (char *)"kXP_wait";
219 break;
220 default:
221 return (char *)"kXP_UNKNOWN";
222 break;
223 }
224}
225
226////////////////////////////////////////////////////////////////////////////////
227
229{
230 printf("\n\n================= DUMPING CLIENT REQUEST HEADER =================\n");
231
232 printf("%40s0x%.2x 0x%.2x\n", "ClientHeader.streamid = ",
233 hdr->header.streamid[0], hdr->header.streamid[1]);
234
235 printf("%40s%s (%d)\n", "ClientHeader.requestid = ",
236 convertRequestIdToChar(hdr->header.requestid), hdr->header.requestid);
237
238 void *tmp;
239 switch(hdr->header.requestid) {
240
241 case kXP_login:
242 printf("%40s%d \n", "ClientHeader.login.pid = ", hdr->login.pid);
243 printf("%40s%s\n", "ClientHeader.login_body.username = ", hdr->login.username);
244 tmp = &hdr->login.reserved[0];
245 printf("%40s0 repeated %d times\n", "ClientHeader.login.reserved = ",
246 *((kXR_int16 *)tmp)); // use tmp to avoid type punned warning
247 printf("%40s%d\n", "ClientHeader.login.role = ", (kXR_int32)hdr->login.role[0]);
248 break;
249 case kXP_auth:
250 printf("%40s0 repeated %d times\n", "ClientHeader.auth.reserved = ",
251 (kXR_int32)sizeof(hdr->auth.reserved));
252 printf(" ClientHeader.auth.credtype= 0x%.2x 0x%.2x 0x%.2x 0x%.2x \n",
253 hdr->auth.credtype[0], hdr->auth.credtype[1],
254 hdr->auth.credtype[2], hdr->auth.credtype[3]);
255 break;
256 case kXP_create:
257 break;
258 case kXP_destroy:
259 printf("%40s%d \n", "ClientHeader.proof.sid = ", hdr->proof.sid);
260 break;
261 case kXP_attach:
262 printf("%40s%d \n", "ClientHeader.proof.sid = ", hdr->proof.sid);
263 break;
264 case kXP_detach:
265 printf("%40s%d \n", "ClientHeader.proof.sid = ", hdr->proof.sid);
266 break;
267 case kXP_ctrlc:
268 printf("%40s%d \n", "ClientHeader.proof.sid = ", hdr->proof.sid);
269 break;
270 case kXP_cleanup:
271 printf("%40s%d \n", "ClientHeader.proof.sid = ", hdr->proof.sid);
272 printf("%40s%d \n", "ClientHeader.proof.int1 = ", hdr->proof.int1);
273 printf("%40s%d \n", "ClientHeader.proof.int2 = ", hdr->proof.int2);
274 break;
275 case kXP_sendmsg:
276 printf("%40s%d \n", "ClientHeader.sendrcv.sid = ", hdr->sendrcv.sid);
277 printf("%40s%d \n", "ClientHeader.sendrcv.opt = ", hdr->sendrcv.opt);
278 printf("%40s%d \n", "ClientHeader.sendrcv.cid = ", hdr->sendrcv.cid);
279 break;
280 case kXP_interrupt:
281 printf("%40s%d \n", "ClientHeader.interrupt.sid = ", hdr->interrupt.sid);
282 printf("%40s%d \n", "ClientHeader.interrupt.type = ", hdr->interrupt.type);
283 break;
284 case kXP_ping:
285 printf("%40s%d \n", "ClientHeader.sendrcv.sid = ", hdr->sendrcv.sid);
286 printf("%40s%d \n", "ClientHeader.sendrcv.opt = ", hdr->sendrcv.opt);
287 break;
288 case kXP_touch:
289 printf("%40s%d \n", "ClientHeader.sendrcv.sid = ", hdr->sendrcv.sid);
290 break;
291 case kXP_admin:
292 case kXP_urgent:
293 printf("%40s%d \n", "ClientHeader.proof.sid = ", hdr->proof.sid);
294 printf("%40s%d \n", "ClientHeader.proof.int1 = ", hdr->proof.int1);
295 printf("%40s%d \n", "ClientHeader.proof.int2 = ", hdr->proof.int2);
296 printf("%40s%d \n", "ClientHeader.proof.int3 = ", hdr->proof.int3);
297 break;
298 case kXP_readbuf:
299 printf("%40s%lld \n", "ClientHeader.readbuf.ofs = ", hdr->readbuf.ofs);
300 printf("%40s%d \n", "ClientHeader.readbuf.len = ", hdr->readbuf.len);
301 break;
302 default:
303 printf("Unknown request ID: %d ! \n", hdr->header.requestid);
304 }
305
306 printf("%40s%d", "ClientHeader.header.dlen = ", hdr->header.dlen);
307 printf("\n=================== END CLIENT HEADER DUMPING ===================\n\n");
308}
309
310////////////////////////////////////////////////////////////////////////////////
311
312void smartPrintServerHeader(struct ServerResponseHeader* hdr)
313{
314 printf("\n\n======== DUMPING SERVER RESPONSE HEADER ========\n");
315 printf("%30s0x%.2x 0x%.2x\n", "ServerHeader.streamid = ",
316 hdr->streamid[0], hdr->streamid[1]);
317 switch(hdr->status) {
318 case kXP_ok:
319 printf("%30skXP_ok", "ServerHeader.status = ");
320 break;
321 case kXP_attn:
322 printf("%30skXP_attn", "ServerHeader.status = ");
323 break;
324 case kXP_authmore:
325 printf("%30skXP_authmore", "ServerHeader.status = ");
326 break;
327 case kXP_error:
328 printf("%30skXP_error", "ServerHeader.status = ");
329 break;
330 case kXP_oksofar:
331 printf("%30skXP_oksofar", "ServerHeader.status = ");
332 break;
333 case kXP_wait:
334 printf("%30skXP_wait", "ServerHeader.status = ");
335 break;
336 }
337 printf(" (%d)\n", hdr->status);
338 printf("%30s%d", "ServerHeader.dlen = ", hdr->dlen);
339 printf("\n========== END DUMPING SERVER HEADER ===========\n\n");
340}
341
342} // 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