Commit a4a92b7ce2ef4efc211677eeda2252162c058c9d
1 parent
4c86eb95
Exists in
sqlite_test
HORRRRIBLE
Showing
2 changed files
with
230 additions
and
58 deletions
Show diff stats
src/SERVER/DD_GetData.c
... | ... | @@ -266,7 +266,7 @@ int CloseID(int ID) |
266 | 266 | int status; |
267 | 267 | int i,il, count = 0; |
268 | 268 | /* Is this ID */ |
269 | - if(Verbose) fprintf(stderr,"CloseID(%d)\n",ID); | |
269 | + //if(Verbose) fprintf(stderr,"CloseID(%d)\n",ID); | |
270 | 270 | if(ID >= MaxIDNumber) return(1); /* Everythig is OK */ |
271 | 271 | if(DD_Var[ID] != NULL) |
272 | 272 | { |
... | ... | @@ -311,7 +311,7 @@ int CloseID(int ID) |
311 | 311 | { |
312 | 312 | for(i = 0; i < DD_Var[ID]->VarData[il].VarNumber; i++) |
313 | 313 | { |
314 | - if (Verbose) fprintf(stderr,"CloseID(%d): %d, ptr %p\n",ID,i,DD_Var[ID]->VarData[il].Variables[i]); | |
314 | + //if (Verbose) fprintf(stderr,"CloseID(%d): %d, ptr %p\n",ID,i,DD_Var[ID]->VarData[il].Variables[i]); | |
315 | 315 | free(DD_Var[ID]->VarData[il].Variables[i]); |
316 | 316 | // DD_Var[ID]->VarData[il].VarNumber = 0; |
317 | 317 | } |
... | ... | @@ -341,7 +341,7 @@ int CloseID(int ID) |
341 | 341 | |
342 | 342 | free(DD_Var[ID]); |
343 | 343 | DD_Var[ID] = NULL; |
344 | - if(Verbose) fprintf(stderr,"CloseID(%d): Free DD_Var\n",ID); | |
344 | + //if(Verbose) fprintf(stderr,"CloseID(%d): Free DD_Var\n",ID); | |
345 | 345 | } |
346 | 346 | |
347 | 347 | /* Count determination */ |
... | ... | @@ -454,10 +454,15 @@ int GetAttribute(int ID, char *VarName) |
454 | 454 | if (Verbose) |
455 | 455 | fprintf(stderr,"Malloc DD_Var[%d]->AttrData.Variables[0] = %p\n",ID,DD_Var[ID]->AttrData.Variables[0]); |
456 | 456 | */ |
457 | - | |
457 | + int ooo; | |
458 | 458 | switch(type) |
459 | 459 | { |
460 | 460 | case NC_DOUBLE: status = nc_get_vara_double(DD_Var[ID]->attrID,VarID,start,DimArray,(double *)DD_Var[ID]->AttrData.Variables[0]); |
461 | + printf("Getting double data from nc dataset\n"); | |
462 | + for (ooo=0;ooo<count;ooo++) { | |
463 | + printf("oooo %f\n", &DD_Var[ID]->AttrData.Variables[ooo]); | |
464 | + printf("done\n"); | |
465 | +} | |
461 | 466 | if (status != NC_NOERR) |
462 | 467 | { |
463 | 468 | if(Verbose) fprintf(stderr,"GETATTR: %s\n",nc_strerror(status)); |
... | ... | @@ -465,6 +470,12 @@ int GetAttribute(int ID, char *VarName) |
465 | 470 | } |
466 | 471 | break; |
467 | 472 | case NC_CHAR: status = nc_get_vara_text(DD_Var[ID]->attrID,VarID,start,DimArray,(char *)DD_Var[ID]->AttrData.Variables[0]); |
473 | + printf("Getting text data from nc dataset\n"); | |
474 | + for (ooo=0;ooo<count;ooo++) { | |
475 | + printf("oooo %f\n",DimArray[ooo]); | |
476 | + printf("iiii %f\n",start[ooo]); | |
477 | + printf("done\n"); | |
478 | +} | |
468 | 479 | if (status != NC_NOERR) |
469 | 480 | { |
470 | 481 | if(Verbose) fprintf(stderr,"GETATTR: %s\n",nc_strerror(status)); |
... | ... | @@ -472,6 +483,11 @@ int GetAttribute(int ID, char *VarName) |
472 | 483 | } |
473 | 484 | break; |
474 | 485 | case NC_FLOAT: status = nc_get_vara_float(DD_Var[ID]->attrID,VarID,start,DimArray,(float *)DD_Var[ID]->AttrData.Variables[0]); |
486 | + printf("Getting float data from nc dataset\n"); | |
487 | + for (ooo=0;ooo<count;ooo++) { | |
488 | + printf("oooo %f\n", &DD_Var[ID]->AttrData.Variables[ooo]); | |
489 | + printf("done\n"); | |
490 | +} | |
475 | 491 | if (status != NC_NOERR) |
476 | 492 | { |
477 | 493 | if(Verbose) fprintf(stderr,"GETATTR: %s\n",nc_strerror(status)); |
... | ... | @@ -479,6 +495,11 @@ int GetAttribute(int ID, char *VarName) |
479 | 495 | } |
480 | 496 | break; |
481 | 497 | case NC_SHORT: status = nc_get_vara_short(DD_Var[ID]->attrID,VarID,start,DimArray,(short *)DD_Var[ID]->AttrData.Variables[0]); |
498 | + printf("Getting short data from nc dataset\n"); | |
499 | + for (ooo=0;ooo<count;ooo++) { | |
500 | + printf("oooo %f\n", &DD_Var[ID]->AttrData.Variables[ooo]); | |
501 | + printf("done\n"); | |
502 | +} | |
482 | 503 | if (status != NC_NOERR) |
483 | 504 | { |
484 | 505 | if(Verbose) fprintf(stderr,"GETATTR: %s\n",nc_strerror(status)); |
... | ... | @@ -486,6 +507,12 @@ int GetAttribute(int ID, char *VarName) |
486 | 507 | } |
487 | 508 | break; |
488 | 509 | case NC_INT: status = nc_get_vara_long(DD_Var[ID]->attrID,VarID,start,DimArray,(long *)DD_Var[ID]->AttrData.Variables[0]); |
510 | + printf("Getting long data from nc dataset\n"); | |
511 | + for (ooo=0;ooo<count;ooo++) { | |
512 | + printf("oooo %f\n", &DD_Var[ID]->AttrData.Variables[ooo]); | |
513 | + printf("done\n"); | |
514 | +} | |
515 | + | |
489 | 516 | if (status != NC_NOERR) |
490 | 517 | { |
491 | 518 | if(Verbose) fprintf(stderr,"GETATTR: %s\n",nc_strerror(status)); |
... | ... | @@ -771,6 +798,7 @@ int GetAttribute(int ID, char *VarName) |
771 | 798 | DD_Var[ID]->VarData[il].Dimensions = (int *)malloc(sizeof(int)*DimNumber); |
772 | 799 | for(i = 0; i < DD_Var[ID]->VarData[il].DimNumber; i++) |
773 | 800 | { |
801 | + printf("Filling data %i\n", (int)DimArray[i+1]); | |
774 | 802 | (DD_Var[ID]->VarData[il].Dimensions)[i] = (int)DimArray[i+1]; |
775 | 803 | //if(Verbose) fprintf(stderr,"GetMultiData(%d): Dimensions(%d): dim[%d] = %d\n",ID,il,i,(int)DimArray[i+1]); |
776 | 804 | } |
... | ... | @@ -915,19 +943,25 @@ int GetAttribute(int ID, char *VarName) |
915 | 943 | { |
916 | 944 | case DD_DOUBLE: status = nc_get_vara_double(Local.ncID, VarID[il], start, DimArray, |
917 | 945 | (double *)DD_Var[ID]->VarData[il].Variables[DD_Var[ID]->VarData[il].VarNumber]); |
946 | +printf("\tVALUE %f", *(double*)DD_Var[ID]->VarData[il].Variables[DD_Var[ID]->VarData[il].VarNumber]); | |
947 | + | |
918 | 948 | break; |
919 | 949 | case DD_INT: status = nc_get_vara_int(Local.ncID, VarID[il], start, DimArray, |
920 | 950 | (int *)DD_Var[ID]->VarData[il].Variables[DD_Var[ID]->VarData[il].VarNumber]); |
951 | +printf("\tVALUE %f", *(int*)DD_Var[ID]->VarData[il].Variables[DD_Var[ID]->VarData[il].VarNumber]); | |
921 | 952 | break; |
922 | 953 | case DD_FLOAT: status = nc_get_vara_float(Local.ncID, VarID[il], start, DimArray, |
923 | 954 | (float *)DD_Var[ID]->VarData[il].Variables[DD_Var[ID]->VarData[il].VarNumber]); |
955 | +printf("\tVALUE %f", *(float*)DD_Var[ID]->VarData[il].Variables[DD_Var[ID]->VarData[il].VarNumber]); | |
924 | 956 | // if(Verbose) fprintf(stderr,"(Variable[%d])[0] = %f\n",il,((float *)DD_Var[ID]->VarData[il].Variables[DD_Var[ID]->VarData[il].VarNumber])[0]); |
925 | 957 | break; |
926 | 958 | case DD_SHORT: status = nc_get_vara_short(Local.ncID, VarID[il], start, DimArray, |
927 | 959 | (short *)DD_Var[ID]->VarData[il].Variables[DD_Var[ID]->VarData[il].VarNumber]); |
960 | +printf("\tVALUE %f", *(short*)DD_Var[ID]->VarData[il].Variables[DD_Var[ID]->VarData[il].VarNumber]); | |
928 | 961 | break; |
929 | 962 | case DD_CHAR: status = nc_get_vara_text(Local.ncID, VarID[il], start, DimArray, |
930 | 963 | (char *)DD_Var[ID]->VarData[il].Variables[DD_Var[ID]->VarData[il].VarNumber]); |
964 | +printf("\tVALUE %f", *(double *)DD_Var[ID]->VarData[il].Variables[DD_Var[ID]->VarData[il].VarNumber]); | |
931 | 965 | } /* End of switch */ |
932 | 966 | DD_Var[ID]->VarData[il].VarNumber++; |
933 | 967 | } /* if not NOVAR */ | ... | ... |
src/SERVER/DD_Server.c
... | ... | @@ -29,6 +29,7 @@ |
29 | 29 | #include <sys/time.h> |
30 | 30 | #include <sys/types.h> |
31 | 31 | #include <unistd.h> |
32 | +#include <signal.h> | |
32 | 33 | #include "DD.h" |
33 | 34 | #include "DD_comm.h" |
34 | 35 | |
... | ... | @@ -185,9 +186,11 @@ int SendToNet(int SocketID, char *buff, int length) |
185 | 186 | */ |
186 | 187 | int PutHeader(int a1, int a2, int a3,int SocketID) |
187 | 188 | { |
189 | + printf("in PutHeader \n"); | |
188 | 190 | int cc; |
189 | 191 | XDR xdrs; |
190 | 192 | char buf[REPLYLENGTH]; |
193 | + printf("a1 %i a2 %i a3 %i", a1, a2, a3); | |
191 | 194 | |
192 | 195 | xdrmem_create(&xdrs, buf, REPLYLENGTH, XDR_ENCODE); |
193 | 196 | xdr_int(&xdrs,&a1); |
... | ... | @@ -195,6 +198,13 @@ int PutHeader(int a1, int a2, int a3,int SocketID) |
195 | 198 | xdr_int(&xdrs,&a3); |
196 | 199 | |
197 | 200 | xdr_destroy(&xdrs); |
201 | + printf("Buffer %s\n", buf); | |
202 | + printf(buf); | |
203 | + printf("aa\n"); | |
204 | + //int i; | |
205 | + //for (i=0; i<REPLYLENGTH; i++) { | |
206 | + // printf("-%s-\n", buf[i]); | |
207 | + //} | |
198 | 208 | |
199 | 209 | /* if((cc = send(SocketID,buf,REPLYLENGTH,0)) < 0) */ |
200 | 210 | if((cc = SendToNet(SocketID,buf, REPLYLENGTH)) < 0) |
... | ... | @@ -202,6 +212,7 @@ int PutHeader(int a1, int a2, int a3,int SocketID) |
202 | 212 | if(Verbose) perror("PutHeader:"); |
203 | 213 | return(REPLYRECERR); |
204 | 214 | } |
215 | + printf("out PutHeader\n"); | |
205 | 216 | return(0); |
206 | 217 | } |
207 | 218 | /*------------------------end of PutHeader ------------------------*/ |
... | ... | @@ -224,6 +235,7 @@ int SendConstantPacket(DD_Var_t *Data,int SocketID) |
224 | 235 | MaxNumber * xdrlen[Data->AttrData.type]; /* Data Array */ |
225 | 236 | |
226 | 237 | /* Sending Header */ |
238 | + printf("Sending header\n"); | |
227 | 239 | if((error = PutHeader(Data->AttrData.type, |
228 | 240 | Data->AttrData.DimNumber, |
229 | 241 | PacketSize,SocketID)) < 0) return error; |
... | ... | @@ -232,9 +244,11 @@ int SendConstantPacket(DD_Var_t *Data,int SocketID) |
232 | 244 | xdrmem_create(&xdrs, buff, (u_int)PacketSize, XDR_ENCODE); |
233 | 245 | |
234 | 246 | /* Packing Dimensions */ |
247 | + printf("packing dimensions\n"); | |
235 | 248 | if(Data->AttrData.DimNumber > 0) |
236 | 249 | { |
237 | 250 | Number = (u_int)Data->AttrData.DimNumber; |
251 | + printf("\tdim number : %i", Number); | |
238 | 252 | xdr_array(&xdrs, (caddr_t *)&(Data->AttrData.Dimensions), |
239 | 253 | &Number, |
240 | 254 | (u_int)Data->AttrData.DimNumber, |
... | ... | @@ -243,6 +257,19 @@ int SendConstantPacket(DD_Var_t *Data,int SocketID) |
243 | 257 | } |
244 | 258 | |
245 | 259 | /* Packing Variables */ |
260 | + int k; | |
261 | + for (k=0;k<MaxNumber;k++) { | |
262 | + printf("\t\tmax n %i", k); | |
263 | + printf("\t\tv "); | |
264 | + printf("%f\n",Data->AttrData.Variables[k]); | |
265 | +} | |
266 | + //printf("datatype "); | |
267 | + printf("dimnumber %i\n",Data->AttrData.DimNumber); | |
268 | + printf("type %i\n", Data->AttrData.type); | |
269 | + char vu; | |
270 | + scanf("eoij",vu); | |
271 | + int j; | |
272 | + //printf("\n"); | |
246 | 273 | xdr_array(&xdrs,(caddr_t *)&(Data->AttrData.Variables[0]), |
247 | 274 | &MaxNumber, |
248 | 275 | MaxNumber, |
... | ... | @@ -271,11 +298,14 @@ int SendDataPacket(DD_Var_t *Data, int SocketID, int LastFlag) |
271 | 298 | u_int MaxNumber,Number; |
272 | 299 | int error = OK; |
273 | 300 | |
274 | - for(il = 0; il < Data->ParamSize; il++) | |
275 | - { | |
301 | + for(il = 0; il < Data->ParamSize; il++) { | |
302 | + printf("\t\til %i\n", il); | |
303 | + char vu; | |
304 | + scanf("%s",&vu); | |
276 | 305 | MaxNumber = 1; |
277 | - for(i = 0;i < Data->VarData[il].DimNumber; i++) | |
306 | + for(i = 0;i < Data->VarData[il].DimNumber; i++) { | |
278 | 307 | MaxNumber = MaxNumber * Data->VarData[il].Dimensions[i]; |
308 | + } | |
279 | 309 | |
280 | 310 | PacketSize = xdrlen[DD_INT] + /* Flag */ |
281 | 311 | xdrlen[DD_INT] + /* arrays number */ |
... | ... | @@ -283,6 +313,7 @@ int SendDataPacket(DD_Var_t *Data, int SocketID, int LastFlag) |
283 | 313 | xdrlen[DD_INT] *(Data->VarData[il].DimNumber+1) + /* dimensions array */ |
284 | 314 | MaxNumber*xdrlen[Data->VarData[il].type]*Data->VarData[il].VarNumber + /* set if data arrays */ |
285 | 315 | xdrlen[DD_INT] * Data->VarData[il].VarNumber; /* data arrays sizes */ |
316 | + printf("MaxNumber : %i\n", MaxNumber); | |
286 | 317 | |
287 | 318 | /* Sending header */ |
288 | 319 | if((error = PutHeader(Data->VarData[il].type, |
... | ... | @@ -319,6 +350,10 @@ int SendDataPacket(DD_Var_t *Data, int SocketID, int LastFlag) |
319 | 350 | unixlen[Data->VarData[il].type], |
320 | 351 | (xdrproc_t)ConvFunc[Data->VarData[il].type]); |
321 | 352 | } |
353 | + /*Print buffer*/ | |
354 | + for(i==0;i<PacketSize;i++) { | |
355 | + printf("%c", buff[i]); | |
356 | + } | |
322 | 357 | |
323 | 358 | /* Sending Data Packet */ |
324 | 359 | if((cc = SendToNet(SocketID,buff, PacketSize)) < 0) |
... | ... | @@ -340,7 +375,98 @@ int SendDataPacket(DD_Var_t *Data, int SocketID, int LastFlag) |
340 | 375 | * return packets with information |
341 | 376 | * Start of this subroutine is the start of new communication session |
342 | 377 | */ |
378 | +int receive(int socket_id, char * buffer) { | |
379 | + int cc; | |
380 | + while((cc = recv(socket_id,buffer,REQUESTLENGTH,0)) < 0); /* Receive identification packet */ | |
381 | + if (cc == 0) { | |
382 | + printf("REQSENDERR %i\n", REQSENDERR); | |
383 | + return REQSENDERR; | |
384 | + } | |
385 | + return 0; | |
386 | +} | |
387 | + | |
388 | + | |
389 | + | |
390 | + | |
391 | +struct RequestData { | |
392 | + int type; | |
393 | + char * name; | |
394 | + char * time; | |
395 | + char * host; | |
396 | + char * ticket; | |
397 | + char * login; | |
398 | + char * st_login; //STReqLogin | |
399 | + int * uid; | |
400 | +}; | |
343 | 401 | |
402 | +void initialize_request_data(struct RequestData * r) { | |
403 | + r->name=0; | |
404 | + r->time=0; | |
405 | + r->host=0; | |
406 | + r->ticket=0; | |
407 | + r->login=0; | |
408 | + r->st_login=0; | |
409 | + r->uid=0; | |
410 | +} | |
411 | + | |
412 | +void decode_request_type(XDR * xdrs, char * buffer, struct RequestData * request) { | |
413 | + xdrmem_create(xdrs, buffer, REQUESTLENGTH, XDR_DECODE); | |
414 | + xdr_int(xdrs, &request->type); | |
415 | +} | |
416 | + | |
417 | + | |
418 | +void decode_request(XDR * xdrs, char * buffer, int * request_type) { | |
419 | + // decode the request recieved by the server, stores the request type in request_type | |
420 | + xdrmem_create(xdrs, buffer, REQUESTLENGTH, XDR_DECODE); | |
421 | + xdr_int(xdrs,request_type); | |
422 | +} | |
423 | + | |
424 | +int decode_open_instrument_request(XDR * xdrs, | |
425 | + char * buffer, | |
426 | + struct RequestData * request, | |
427 | + int socket_id) { | |
428 | + xdr_string(xdrs,request->name,MAXSETLENGTH); | |
429 | + printf("name : %s\n", request->name); | |
430 | + xdrmem_create(xdrs, buffer,REQUESTLENGTH , XDR_FREE); | |
431 | + int cc = receive(socket_id, buffer); | |
432 | + if (cc==REQSENDERR) return cc; | |
433 | + xdrmem_create(xdrs, buffer,REQUESTLENGTH, XDR_DECODE); | |
434 | + xdr_int(xdrs,request->uid); | |
435 | + xdr_string(xdrs,request->host,MAXHOSTLENGTH); | |
436 | + xdr_string(xdrs,request->login,USRLENGTH); | |
437 | + return 0; | |
438 | +} | |
439 | + | |
440 | +int decode_get_ticket_request(XDR * xdrs, char * buffer, struct RequestData * request, int socket_id) { | |
441 | + printf("get ticket request\n"); | |
442 | + xdrmem_create(xdrs, buffer,REQUESTLENGTH , XDR_FREE); | |
443 | + int cc = receive(socket_id, buffer); | |
444 | + printf("REV %i %i\n", cc, REQSENDERR); | |
445 | + if (cc == REQSENDERR) { | |
446 | + printf("opiqezhgp\n\n"); | |
447 | + return REQSENDERR; | |
448 | + } | |
449 | + printf("a"); | |
450 | + xdrmem_create(xdrs, buffer, REQUESTLENGTH, XDR_DECODE); | |
451 | + printf("b"); | |
452 | + xdr_int(xdrs,request->uid); | |
453 | + printf("c"); | |
454 | + printf("uid %s\n", request->uid); | |
455 | + xdr_string(&xdrs,request->login ,USRLENGTH); | |
456 | +printf("login %s\n", request->login); | |
457 | + xdr_string(&xdrs,request->ticket,TICKETLENGTH); | |
458 | +printf("ticket %s\n", request->ticket); | |
459 | + xdr_string(&xdrs,request->host,MAXHOSTLENGTH); | |
460 | +printf("host %s\n", request->host); | |
461 | +mypause(); | |
462 | + return 0; | |
463 | + | |
464 | +} | |
465 | +void mypause() { | |
466 | + printf("Pausing\n"); | |
467 | + char aaa; | |
468 | + scanf("%s",aaa); | |
469 | +} | |
344 | 470 | void Serv(int SocketID) |
345 | 471 | { |
346 | 472 | int cc; |
... | ... | @@ -354,6 +480,9 @@ void Serv(int SocketID) |
354 | 480 | static char *ReqTicket = NULL; |
355 | 481 | static char *ReqLogin = NULL; |
356 | 482 | static char *STReqLogin = NULL; |
483 | + // initialize the request container | |
484 | + struct RequestData request; | |
485 | + initialize_request_data(&request); | |
357 | 486 | |
358 | 487 | /*------- Variables to create new VI ---------------*/ |
359 | 488 | static char *NewVIName = NULL; /* Full name of VI (data set to generate )*/ |
... | ... | @@ -384,7 +513,7 @@ void Serv(int SocketID) |
384 | 513 | DD_Var_t *Data; |
385 | 514 | int RemainID =0; /* Number of remained ID in use */ |
386 | 515 | static int TicketID = NOPERMISSION; |
387 | - static int uid, FileAccID; | |
516 | + int uid, FileAccID; | |
388 | 517 | int GoOut = 0; /* The flag of finishing of session */ |
389 | 518 | int LastFlag; /* The flag of the end of data transmission */ |
390 | 519 | |
... | ... | @@ -423,9 +552,7 @@ void Serv(int SocketID) |
423 | 552 | { |
424 | 553 | /* Get request from client */ |
425 | 554 | while((cc = recv(SocketID,ReqBuf,REQUESTLENGTH,0)) < 0); |
426 | - | |
427 | - if (cc == 0) | |
428 | - { | |
555 | + if (cc == 0) { | |
429 | 556 | err = REQSENDERR; |
430 | 557 | GoOut = 1; |
431 | 558 | break; |
... | ... | @@ -434,29 +561,21 @@ void Serv(int SocketID) |
434 | 561 | err = 0; |
435 | 562 | |
436 | 563 | /* Decode Request */ |
437 | - xdrmem_create(&xdrs, ReqBuf, REQUESTLENGTH, XDR_DECODE); | |
438 | - xdr_int(&xdrs,&ReqType); | |
439 | - | |
440 | - switch (ReqType) | |
564 | + //xdrmem_create(&xdrs, ReqBuf, REQUESTLENGTH, XDR_DECODE); | |
565 | + //xdr_int(&xdrs,&ReqType); | |
566 | + //decode_request(&xdrs, ReqBuf, &ReqType); | |
567 | + decode_request_type(&xdrs, ReqBuf, &request); | |
568 | + printf("Request type : %i\n", request.type); | |
569 | + int rc; | |
570 | + switch (request.type) | |
441 | 571 | { |
442 | 572 | case OPENINSREQ: |
443 | - printf("Open instrument request\n"); | |
444 | - scanf("", vu); | |
445 | - xdr_string(&xdrs,&ReqName,MAXSETLENGTH); | |
446 | - | |
447 | - xdrmem_create(&xdrs, ReqBuf,REQUESTLENGTH , XDR_FREE); | |
448 | - while((cc = recv(SocketID,ReqBuf,REQUESTLENGTH,0)) < 0); /* Receive identification packet */ | |
449 | - if (cc == 0) | |
450 | - { | |
451 | - err = REQSENDERR; | |
452 | - break; | |
453 | - } | |
454 | - xdrmem_create(&xdrs, ReqBuf,REQUESTLENGTH, XDR_DECODE); | |
455 | - xdr_int(&xdrs,&uid); | |
456 | - xdr_string(&xdrs,&ReqHost,MAXHOSTLENGTH); | |
457 | - xdr_string(&xdrs,&ReqLogin,USRLENGTH); | |
458 | - if(Verbose)printf("Serv():OPENINSREQ: Client Pasport: ID = %d, Host <%s>\n",uid,ReqHost); | |
459 | - | |
573 | + rc = decode_open_instrument_request(&xdrs, ReqBuf, &request, SocketID); | |
574 | + if (rc==REQSENDERR) break; | |
575 | + printf("\tHost : %s\nLogin : %s\n", request.host, request.login); | |
576 | +//char vu; scanf("%s",vu); | |
577 | + if(Verbose)printf("Serv():OPENINSREQ: Client Pasport: ID = %d, Host <%s>\n",request.uid,request.host); | |
578 | + mypause(); | |
460 | 579 | break; |
461 | 580 | |
462 | 581 | case CLOSEINSREQ : |
... | ... | @@ -538,27 +657,30 @@ void Serv(int SocketID) |
538 | 657 | |
539 | 658 | case GETTICKETREQ: |
540 | 659 | printf("get ticket request\n"); |
541 | - scanf("",vu); | |
542 | - xdrmem_create(&xdrs, ReqBuf,REQUESTLENGTH , XDR_FREE); | |
543 | - while((cc = recv(SocketID,ReqBuf,REQUESTLENGTH,0)) < 0); | |
544 | - if (cc == 0) | |
545 | - { | |
546 | - err = REQSENDERR; | |
547 | - break; | |
548 | - } | |
549 | - xdrmem_create(&xdrs, ReqBuf, REQUESTLENGTH, XDR_DECODE); | |
550 | - | |
551 | - xdr_int(&xdrs,&uid); | |
552 | - xdr_string(&xdrs,&ReqLogin,USRLENGTH); | |
553 | - xdr_string(&xdrs,&ReqTicket,TICKETLENGTH); | |
554 | - xdr_string(&xdrs,&ReqHost,MAXHOSTLENGTH); | |
660 | + printf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); | |
661 | + rc = decode_get_ticket_request(&xdrs, ReqBuf, &request, SocketID); | |
662 | + printf("%i %i\n", rc, REQSENDERR); | |
663 | + if (rc==REQSENDERR) break; | |
664 | + //xdrmem_create(&xdrs, ReqBuf,REQUESTLENGTH , XDR_FREE); | |
665 | + //while((cc = recv(SocketID,ReqBuf,REQUESTLENGTH,0)) < 0); | |
666 | + //if (cc == 0) | |
667 | + //{ | |
668 | + // err = REQSENDERR; | |
669 | + // break; | |
670 | + //} | |
671 | + //xdrmem_create(&xdrs, ReqBuf, REQUESTLENGTH, XDR_DECODE); | |
672 | + | |
673 | + //xdr_int(&xdrs,&uid); | |
674 | + //xdr_string(&xdrs,&ReqLogin,USRLENGTH); | |
675 | + //xdr_string(&xdrs,&ReqTicket,TICKETLENGTH); | |
676 | + //xdr_string(&xdrs,&ReqHost,MAXHOSTLENGTH); | |
555 | 677 | |
556 | 678 | break; |
557 | 679 | |
558 | 680 | |
559 | 681 | case SHOWTICKETREQ: |
560 | 682 | printf("show ticket request\n"); |
561 | - scanf("",vu); | |
683 | +// scanf("",vu); | |
562 | 684 | xdr_int(&xdrs,&STid); |
563 | 685 | xdr_string(&xdrs,&STReqHost,MAXHOSTLENGTH); |
564 | 686 | xdr_string(&xdrs,&STReqLogin,USRLENGTH); |
... | ... | @@ -570,10 +692,12 @@ void Serv(int SocketID) |
570 | 692 | /*------------------------------------------------ |
571 | 693 | * Call data functions and response generation |
572 | 694 | *----------------------------------------------*/ |
695 | + printf("Now answer the request \n"); | |
573 | 696 | |
574 | 697 | switch(ReqType) |
575 | 698 | { |
576 | 699 | case OPENINSREQ: |
700 | + printf("Openinng instrument\n"); | |
577 | 701 | if(Verbose) fprintf(stderr,"Serv():OPENINSREQ:ShowTicket; Host %s\n",ReqHost); |
578 | 702 | err = ShowTicket(uid,ReqHost,ReqLogin); |
579 | 703 | if(err >= 0) |
... | ... | @@ -584,8 +708,11 @@ void Serv(int SocketID) |
584 | 708 | err = PutHeader(id,0,0,SocketID); /* return error if something is wrong */ |
585 | 709 | } |
586 | 710 | else PutHeader(err,0,0,SocketID); |
711 | + printf("opening instrument done\n"); | |
587 | 712 | break; |
588 | 713 | case CLOSEINSREQ: |
714 | + printf("closing instrument ...\n"); | |
715 | + | |
589 | 716 | if(id < 0){err = NOID;PutHeader(err,0,0,SocketID);} |
590 | 717 | if(Verbose) fprintf(stderr,"Serv():CLOSEINSREQ: ID = %d\n",id); |
591 | 718 | RemainID = CloseID(id); |
... | ... | @@ -599,23 +726,29 @@ void Serv(int SocketID) |
599 | 726 | err = PutHeader(RemainID-1,0,0,SocketID); |
600 | 727 | if(RemainID == 1) GoOut = 1; |
601 | 728 | } |
729 | + printf("closing instrument done\n"); | |
602 | 730 | break; |
603 | 731 | case TIMESETREQ: |
732 | + printf("time set request...\n"); | |
604 | 733 | if(id < 0) err = NOID; |
605 | 734 | if(err >= 0) err = SetTime(DD_Var[id],DD_Time2Double(ReqTime)); |
606 | 735 | if(err == CTIMEISSHIFTED) err = SetTime(DD_Var[id],-1.0); |
607 | 736 | if(err >= 0) PutHeader(0,0,0,SocketID); |
608 | 737 | else PutHeader(err,0,0,SocketID); |
738 | + printf("time set request done\n"); | |
609 | 739 | break; |
610 | 740 | |
611 | 741 | case DATAINFOREQ: |
742 | + printf("data info request ...\n"); | |
612 | 743 | if(id < 0) err = NOID; |
613 | 744 | else err = GetAttribute(id,ReqName); |
614 | 745 | if(err >= 0) err = SendConstantPacket(DD_Var[id],SocketID); |
615 | 746 | else PutHeader(err,0,0,SocketID); |
747 | + printf("data info request done\n"); | |
616 | 748 | break; |
617 | 749 | |
618 | 750 | case DATAGETREQ: |
751 | + printf("data get request ...\n"); | |
619 | 752 | if(id < 0) err = NOID; |
620 | 753 | /*------ Call data until LastPacket Flag (OK) returns --------*/ |
621 | 754 | else do |
... | ... | @@ -629,9 +762,11 @@ void Serv(int SocketID) |
629 | 762 | } |
630 | 763 | while((err >= 0) && (DD_Var[id]->LastPacketFlag == MOREDATA)); |
631 | 764 | if(err < 0) PutHeader(err,0,0,SocketID); |
765 | + printf("data get request done\n"); | |
632 | 766 | break; |
633 | 767 | |
634 | 768 | case ADDVIREQ: |
769 | + printf("add vi request ...\n"); | |
635 | 770 | sprintf(Command,ADDDATASETCALL,getenv("DDBASEBIN"),RemBaseName,RemSetID,NewVIName); |
636 | 771 | if(Verbose) fprintf(stderr, "Serv:ADDVIREQ: Command = %s\n", Command); |
637 | 772 | err = system(Command); |
... | ... | @@ -643,22 +778,27 @@ void Serv(int SocketID) |
643 | 778 | default: PutHeader(NOEXEC,0,0,SocketID); |
644 | 779 | } |
645 | 780 | GoOut = 1; |
781 | + printf("add vi request done \n"); | |
646 | 782 | break; |
647 | 783 | |
648 | 784 | case GETTICKETREQ: |
785 | + printf("get ticket request...\n"); | |
649 | 786 | errTick = CheckTicket(ReqLogin, ReqTicket); |
650 | 787 | Put2Log(uid,ReqHost,ReqLogin,errTick); /* Log file */ |
651 | 788 | if(errTick >= 0) TicketID = GetTicket(uid,ReqHost,errTick); |
652 | 789 | if(Verbose) printf("GETTICKETREQ: uid= %d ReqHost = %s ErrTick = %d\n",uid,ReqHost ,errTick); |
653 | 790 | PutHeader(TicketID,0,0,SocketID); |
654 | 791 | GoOut = 1; |
792 | + printf("get ticket request done \n"); | |
655 | 793 | break; |
656 | 794 | |
657 | 795 | case SHOWTICKETREQ: |
796 | + printf("show ticket request ...\n"); | |
658 | 797 | if(Verbose) printf("SHOWTICKETREQ; ShowTicket; Host %s\n",STReqHost); |
659 | 798 | err = ShowTicket(STid,STReqHost,STReqLogin); |
660 | 799 | PutHeader(err,0,0,SocketID); |
661 | 800 | GoOut = 1; |
801 | + printf("show ticket done\n"); | |
662 | 802 | break; |
663 | 803 | } /* swithch Reqtype */ |
664 | 804 | |
... | ... | @@ -667,6 +807,7 @@ void Serv(int SocketID) |
667 | 807 | |
668 | 808 | |
669 | 809 | endend: |
810 | + printf("ENDING HERE"); | |
670 | 811 | if(Verbose) |
671 | 812 | fprintf(stderr, "Serv():EndEnd:Close session %d at %s by error %d\n",SocketID,Double2DD_Time((double)time(NULL)),err); |
672 | 813 | RemainID = CloseID(FileAccID); |
... | ... | @@ -715,25 +856,22 @@ int main(int argc, char **argv) |
715 | 856 | MaxIDNumber = (size_t)(sysconf(_SC_OPEN_MAX) / 3L - 5L); |
716 | 857 | |
717 | 858 | /*-------- Endless listen ----------------------------------------------*/ |
718 | - while(1) | |
719 | - { | |
859 | + while(1) { | |
720 | 860 | NewSocketLen = sizeof(NewSocketAddr); |
721 | 861 | printf("This is my sqlite3 version of DDServer\n"); |
722 | - if((NewSocketID = accept(ListenerID,&NewSocketAddr,&NewSocketLen)) < 0) | |
723 | - { | |
862 | + if((NewSocketID = accept(ListenerID,&NewSocketAddr,&NewSocketLen)) < 0) { | |
724 | 863 | // printf(" %d %d %d \n", ListenerID, (int)NewSocketLen, NewSocketID); |
725 | 864 | if(Verbose) perror("DD_Server: Accept: "); |
726 | 865 | } |
727 | - else | |
728 | - { | |
866 | + else { | |
729 | 867 | if(Verbose) fprintf(stderr, "There is connection from ...\n"); |
730 | - if(fork() == 0) /* I am child */ | |
731 | - { | |
732 | - if(fork() == 0) | |
733 | - { | |
868 | + if(fork() == 0) /* I am child */ { | |
869 | + if(fork() == 0) { | |
734 | 870 | Serv(NewSocketID); /*Real working */ |
735 | 871 | } |
736 | - else exit(0); | |
872 | + else { | |
873 | + exit(0); | |
874 | + } | |
737 | 875 | } |
738 | 876 | else wait(&stat_loc); /* wait of finishing of child */ |
739 | 877 | close(NewSocketID); | ... | ... |