00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "typedefs.h"
00017 #include "f_his_hist.h"
00018 #include "f_his_toupper.h"
00019 #include "f_his_swpbas.h"
00020 #include "f_stccomm.h"
00021 #include "f_swaplw.h"
00022 #include "f_ut_compress.h"
00023 #include "portnum_def.h"
00024 #include <stdio.h>
00025 #include <errno.h>
00026 #include <ctype.h>
00027 #include <string.h>
00028 #include <stdlib.h>
00029 static CHARS c_gl_serv_access[64];
00030 static CHARS c_gl_serv_base[32];
00031 static INTS4 l_gl_serv_port;
00032 static INTS4 l_gl_serv_chan;
00033 static INTS4 l_gl_serv_verb;
00034 struct s_tcpcomm *ps_tcpserv;
00035 s_his_comm s_his_comm_serv;
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 INTS4 f_his_getbas(CHARS *pc_server, INTS4 l_port, CHARS *pc_base, CHARS *pc_access,INTS4 **p_buffer)
00085 {
00086 s_his_comm s_his_comm_cli;
00087 s_his_head *ps_his_head;
00088 INTS4 i_j,i_l,l_status,l_chan,l_swap,l_buffer,l_histos,l_size;
00089 INTS4 *pl_all,*pl_l;
00090 s_compress *ps_compress;
00091 struct s_tcpcomm *ps_tcpcli;
00092
00093 ps_tcpcli = (struct s_tcpcomm *) malloc (sizeof( struct s_tcpcomm));
00094
00095
00096 s_his_comm_cli.lu_endian=1;
00097 s_his_comm_cli.lu_size=0;
00098 s_his_comm_cli.lu_histos=0;
00099 s_his_comm_cli.lu_action=COMM__GETBASE;
00100 s_his_comm_cli.l_status=COMM__SUCCESS;
00101 strcpy(s_his_comm_cli.c_histo,"*");
00102 strcpy(s_his_comm_cli.c_access,pc_access);
00103 strcpy(s_his_comm_cli.c_base,pc_base);
00104 l_status = f_stc_connectserver (pc_server,l_port, &l_chan, ps_tcpcli);
00105 if(l_status != STC__SUCCESS) {l_status=COMM__NOSERVER;goto g_return;}
00106 l_status = f_stc_write(&s_his_comm_cli,sizeof(s_his_comm),l_chan);
00107 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00108 l_status = f_stc_read (&s_his_comm_cli,sizeof(s_his_comm),l_chan,-1);
00109 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00110 l_swap = (s_his_comm_cli.lu_endian > 1);
00111 if(l_swap) l_status = f_swaplw((INTS4 *)&s_his_comm_cli,5,NULL);
00112 if(s_his_comm_cli.l_status != COMM__SUCCESS) {l_status=s_his_comm_cli.l_status;goto g_return;}
00113
00114
00115 pl_all = (INTS4 *)malloc(s_his_comm_cli.lu_size);
00116 l_buffer = s_his_comm_cli.lu_size;
00117
00118 pl_l=pl_all;
00119 i_l=l_buffer/16384;
00120 l_buffer=l_buffer%16384;
00121 for(i_j=0;i_j<i_l;i_j++){l_status = f_stc_read (pl_l,16384,l_chan,-1);pl_l+=4096;}
00122 if(l_buffer > 0) l_status = f_stc_read (pl_l,l_buffer,l_chan,-1);
00123 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00124
00125 ps_compress = (s_compress *) pl_all;
00126 if(l_swap == 1)
00127 {
00128 f_swaplw((INTS4 *)pl_all,sizeof(s_compress)/4,NULL);
00129 pl_l=pl_all+(sizeof(s_compress)/4);
00130 f_swaplw((INTS4 *)pl_l,ps_compress->l_masks,NULL);
00131 }
00132 *p_buffer = (INTS4 *)malloc(ps_compress->l_full_bytes);
00133 f_ut_compr_unpack((INTU1 *)pl_all,(INTU1 *) *p_buffer,ps_compress->l_full_bytes);
00134 if(l_swap == 1) l_status = f_his_swpbas((s_head*) *p_buffer);
00135
00136 l_status=COMM__SUCCESS;
00137 g_return:
00138 f_stc_discclient (l_chan);
00139 f_stc_close (ps_tcpcli);
00140 free(pl_all);
00141 free(ps_tcpcli);
00142 return(l_status);
00143 }
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 INTS4 f_his_getdir(CHARS *pc_server, INTS4 l_port, CHARS *pc_base, CHARS *pc_access, CHARS *pc_histo
00192 ,INTS4 **p_buffer, INTS4 *pl_histos)
00193 {
00194 s_his_comm s_his_comm_cli;
00195 s_his_head *ps_his_head;
00196 INTS4 i_j,i_l,l_status,l_chan,l_swap,l_buffer,l_histos,l_size;
00197 INTS4 *pl_all,*pl_l;
00198 struct s_tcpcomm *ps_tcpcli;
00199
00200 ps_tcpcli = (struct s_tcpcomm *) malloc (sizeof( struct s_tcpcomm));
00201
00202
00203 s_his_comm_cli.lu_endian=1;
00204 s_his_comm_cli.lu_size=0;
00205 s_his_comm_cli.lu_histos=0;
00206 s_his_comm_cli.lu_action=COMM__GETDIR;
00207 s_his_comm_cli.l_status=COMM__SUCCESS;
00208 strcpy(s_his_comm_cli.c_histo,pc_histo);
00209 strcpy(s_his_comm_cli.c_access,pc_access);
00210 strcpy(s_his_comm_cli.c_base,pc_base);
00211 l_status = f_stc_connectserver (pc_server,l_port, &l_chan, ps_tcpcli);
00212 if(l_status != STC__SUCCESS) {l_status=COMM__NOSERVER;goto g_return;}
00213 l_status = f_stc_write(&s_his_comm_cli,sizeof(s_his_comm),l_chan);
00214 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00215 l_status = f_stc_read (&s_his_comm_cli,sizeof(s_his_comm),l_chan,-1);
00216 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00217 l_swap = (s_his_comm_cli.lu_endian > 1);
00218 if(l_swap) l_status = f_swaplw((INTS4 *)&s_his_comm_cli,5,NULL);
00219 if(s_his_comm_cli.l_status != COMM__SUCCESS) {l_status=s_his_comm_cli.l_status;goto g_return;}
00220
00221 l_histos=s_his_comm_cli.lu_histos;
00222 l_size=sizeof(s_his_head)*l_histos;
00223
00224 if(*p_buffer == 0)
00225 {
00226 pl_all = (INTS4 *)malloc(l_size);
00227 *p_buffer = pl_all;
00228 }
00229 else
00230 {
00231 if(*pl_histos < l_histos) {l_status=COMM__ERROR;goto g_return;}
00232 pl_all = *p_buffer;
00233 }
00234 *pl_histos = l_histos;
00235 l_buffer = s_his_comm_cli.lu_size;
00236
00237 pl_l=pl_all;
00238 i_l=l_buffer/16384;
00239 l_buffer=l_buffer%16384;
00240 for(i_j=0;i_j<i_l;i_j++){l_status = f_stc_read (pl_l,16384,l_chan,-1);pl_l+=4096;}
00241 if(l_buffer > 0) l_status = f_stc_read (pl_l,l_buffer,l_chan,-1);
00242 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00243
00244 ps_his_head = (s_his_head *)pl_all;
00245 for(i_j=0;i_j<s_his_comm_cli.lu_histos;i_j++)
00246 {
00247 if(l_swap) l_status = f_swaplw((INTS4 *)ps_his_head,16,NULL);
00248 ps_his_head++;
00249
00250 }
00251 l_status=COMM__SUCCESS;
00252 g_return:
00253 f_stc_discclient (l_chan);
00254 f_stc_close (ps_tcpcli);
00255 free(ps_tcpcli);
00256 return(l_status);
00257 }
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 INTS4 f_his_gethis(CHARS *pc_server, INTS4 l_port, CHARS *pc_base, CHARS *pc_access, CHARS *pc_histo
00314 , s_his_head **p_head, INTS4 **p_buffer, INTS4 *pl_size)
00315 {
00316 s_his_comm s_his_comm_cli;
00317 s_his_head *ps_his_head;
00318 INTS4 i_j,i_l,l_status,l_chan,l_swap,l_buffer,l_histos,l_size;
00319 INTS4 *pl_all,*pl_head,*pl_l;
00320 struct s_tcpcomm *ps_tcpcli;
00321
00322 ps_tcpcli = (struct s_tcpcomm *) malloc (sizeof( struct s_tcpcomm));
00323
00324
00325 s_his_comm_cli.lu_endian=1;
00326 s_his_comm_cli.lu_size=0;
00327 s_his_comm_cli.lu_histos=0;
00328 s_his_comm_cli.lu_action=COMM__GETHIST;
00329 s_his_comm_cli.l_status=COMM__SUCCESS;
00330 strcpy(s_his_comm_cli.c_histo,pc_histo);
00331 strcpy(s_his_comm_cli.c_access,pc_access);
00332 strcpy(s_his_comm_cli.c_base,pc_base);
00333 l_status = f_stc_connectserver (pc_server,l_port, &l_chan, ps_tcpcli);
00334 if(l_status != STC__SUCCESS) {l_status=COMM__NOSERVER;goto g_return;}
00335 l_status = f_stc_write(&s_his_comm_cli,sizeof(s_his_comm),l_chan);
00336 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00337 l_status = f_stc_read (&s_his_comm_cli,sizeof(s_his_comm),l_chan,-1);
00338 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00339 l_swap = (s_his_comm_cli.lu_endian > 1);
00340 if(l_swap) l_status = f_swaplw((INTS4 *)&s_his_comm_cli,5,NULL);
00341 if(s_his_comm_cli.l_status != COMM__SUCCESS) {l_status=s_his_comm_cli.l_status;goto g_return;}
00342
00343 l_size=s_his_comm_cli.lu_size-sizeof(s_his_head);
00344
00345 if(*p_buffer == 0)
00346 {
00347 pl_all = (INTS4 *)malloc(l_size);
00348 *p_buffer = pl_all;
00349 }
00350 else
00351 {
00352 if(*pl_size < l_size) {l_status=COMM__ERROR;goto g_return;}
00353 pl_all = *p_buffer;
00354 }
00355
00356 if(*p_head == 0)
00357 {
00358 ps_his_head = (s_his_head *)malloc(sizeof(s_his_head));
00359 *p_head = ps_his_head;
00360 }
00361 else ps_his_head = *p_head;
00362
00363 l_status = f_stc_read (ps_his_head,sizeof(s_his_head),l_chan,-1);
00364 if(l_swap) l_status = f_swaplw((INTS4 *)ps_his_head,16,NULL);
00365
00366 *pl_size = l_size;
00367 l_buffer = l_size;
00368
00369
00370 pl_l=pl_all;
00371 i_l=l_buffer/16384;
00372 l_buffer=l_buffer%16384;
00373 for(i_j=0;i_j<i_l;i_j++){l_status = f_stc_read (pl_l,16384,l_chan,-1);pl_l+=4096;}
00374 if(l_buffer > 0) l_status = f_stc_read (pl_l,l_buffer,l_chan,-1);
00375 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00376
00377 if(l_swap) l_status = f_swaplw((INTS4 *)pl_all,l_size/4,NULL);
00378
00379 l_status=COMM__SUCCESS;
00380 g_return:
00381 f_stc_discclient (l_chan);
00382 f_stc_close (ps_tcpcli);
00383 free(ps_tcpcli);
00384 return(l_status);
00385 }
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420 INTS4 f_his_server(CHARS *pc_base, CHARS *pc_access, INTS4 *pl_port)
00421 {
00422 INTS4 *pl_l,i_j,i_l,ll,l_buffer,l_status;
00423
00424 ps_tcpserv = (struct s_tcpcomm *) malloc (sizeof( struct s_tcpcomm));
00425 l_gl_serv_port=PORT__HIST_SERV;
00426 strcpy(c_gl_serv_access,pc_access);
00427 strcpy(c_gl_serv_base,pc_base);
00428 f_his_toupper(c_gl_serv_access,sizeof(c_gl_serv_access));
00429 f_his_toupper(c_gl_serv_base,sizeof(c_gl_serv_base));
00430
00431 while((l_status = f_stc_createserver (&l_gl_serv_port, ps_tcpserv)) != STC__SUCCESS)
00432 {
00433 l_gl_serv_port++;
00434 if(l_gl_serv_port > PORT__HIST_SERV + 20)
00435 {
00436 printf("Error creating histogram server\n");
00437 return(COMM__ERROR);
00438 }
00439 }
00440 *pl_port=l_gl_serv_port;
00441 return(0);
00442 }
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480 INTS4 f_his_wait(INTS4 *pl_action, CHARS *pc_histo)
00481 {
00482 INTS4 *pl_l,i_j,i_l,ll,l_buffer,l_status;
00483
00484 if(l_gl_serv_verb == 1) {printf("Waiting for client on port %d [%s] \n",l_gl_serv_port,c_gl_serv_access);}
00485 l_status = f_stc_acceptclient (ps_tcpserv, &l_gl_serv_chan);
00486 if(l_status != STC__SUCCESS) { printf("error accepting client\n"); return(COMM__ERROR);}
00487 if(l_gl_serv_verb == 1) {printf("Client connected. \n");}
00488 l_status = f_stc_read (&s_his_comm_serv,sizeof(s_his_comm),l_gl_serv_chan,-1);
00489 if(l_status != STC__SUCCESS) { printf("error reading client\n"); f_stc_discclient(l_gl_serv_chan);return(COMM__ERROR); }
00490
00491 f_his_toupper(s_his_comm_serv.c_access,sizeof(s_his_comm_serv.c_access));
00492 f_his_toupper(s_his_comm_serv.c_base,sizeof(s_his_comm_serv.c_base));
00493 if((strlen(c_gl_serv_access) != 0) &
00494 (strcmp(s_his_comm_serv.c_access,c_gl_serv_access) != 0))
00495 {
00496 printf("Client connected with wrong password [%s]. \n",s_his_comm_serv.c_access);
00497 s_his_comm_serv.lu_endian=1;
00498 s_his_comm_serv.lu_size=0;
00499 s_his_comm_serv.lu_histos=0;
00500 s_his_comm_serv.l_status=COMM__NOACCESS;
00501 l_status = f_stc_write (&s_his_comm_serv,sizeof(s_his_comm), l_gl_serv_chan);
00502 f_stc_discclient (l_gl_serv_chan);
00503 return(COMM__NOACCESS);
00504 }
00505
00506 if(strcmp(s_his_comm_serv.c_base,c_gl_serv_base) != 0)
00507 {
00508 printf("Client connected for wrong base [%s]. \n",s_his_comm_serv.c_base);
00509 s_his_comm_serv.lu_endian=1;
00510 s_his_comm_serv.lu_size=0;
00511 s_his_comm_serv.lu_histos=0;
00512 s_his_comm_serv.l_status=COMM__NOBASE;
00513 l_status = f_stc_write (&s_his_comm_serv,sizeof(s_his_comm), l_gl_serv_chan);
00514 f_stc_discclient (l_gl_serv_chan);
00515 return(COMM__NOBASE);
00516 }
00517 if(s_his_comm_serv.lu_endian > 100) l_status = f_swaplw((INTS4 *)&s_his_comm_serv,5,NULL);
00518 if(l_gl_serv_verb == 1) {printf("%d: %d %d %d %d %d \"%s\" \"%s\" \"%s\"\n",l_status
00519 ,s_his_comm_serv.lu_endian
00520 ,s_his_comm_serv.lu_action
00521 ,s_his_comm_serv.lu_histos
00522 ,s_his_comm_serv.lu_size
00523 ,s_his_comm_serv.l_status
00524 ,s_his_comm_serv.c_access
00525 ,s_his_comm_serv.c_base
00526 ,s_his_comm_serv.c_histo);}
00527 *pl_action=s_his_comm_serv.lu_action;
00528 strcpy(pc_histo,s_his_comm_serv.c_histo);
00529 return(COMM__SUCCESS);
00530 }
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565 INTS4 f_his_senddir(s_his_head *ps_head, INTS4 l_histos)
00566 {
00567 INTS4 *pl_l,i_j,i_l,ll,l_buffer,l_status;
00568
00569 if(l_gl_serv_verb == 1) {printf("Send directory %s. \n",s_his_comm_serv.c_histo);}
00570 s_his_comm_serv.lu_histos=l_histos;
00571 s_his_comm_serv.lu_endian=1;
00572 s_his_comm_serv.lu_action=COMM__PUTDIR;
00573 s_his_comm_serv.lu_size=sizeof(s_his_head)*s_his_comm_serv.lu_histos;
00574 s_his_comm_serv.l_status=COMM__SUCCESS;
00575 l_status = f_stc_write (&s_his_comm_serv,sizeof(s_his_comm), l_gl_serv_chan);
00576 if(l_status != STC__SUCCESS)
00577 { printf("error writing comm to client\n"); f_stc_discclient(l_gl_serv_chan);return(COMM__ERROR);}
00578
00579
00580 pl_l=(INTS4 *)ps_head;
00581 l_buffer = s_his_comm_serv.lu_size;
00582 i_l=l_buffer/16384;
00583 l_buffer=l_buffer%16384;
00584 for(i_j=0;i_j<i_l;i_j++){l_status = f_stc_write (pl_l,16384,l_gl_serv_chan);pl_l+=4096;}
00585 if(l_buffer > 0) l_status = f_stc_write (pl_l,l_buffer,l_gl_serv_chan);
00586
00587 if(l_status != STC__SUCCESS)
00588 { printf("error writing directory to client\n"); f_stc_discclient(l_gl_serv_chan);return(COMM__ERROR);}
00589 f_stc_discclient (l_gl_serv_chan);
00590 return(COMM__SUCCESS);
00591 }
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628 INTS4 f_his_sendhis(s_his_head *ps_head, INTS4 l_histos, CHARS *pc_histo, INTS4 *pl_data)
00629 {
00630 s_his_head *ps_his_head;
00631 INTS4 *pl_l,i_j,i_l,ll,l_buffer,l_status;
00632
00633 s_his_comm_serv.lu_endian=1;
00634 s_his_comm_serv.lu_histos=0;
00635 s_his_comm_serv.lu_action=COMM__PUTHIST;
00636 ps_his_head = ps_head;
00637 for(ll=0;ll<l_histos;ll++)
00638 {
00639 pl_l = pl_data;
00640 if(strcmp(ps_his_head->c_name,pc_histo) == 0)
00641 {
00642 s_his_comm_serv.lu_histos=1;
00643 s_his_comm_serv.l_status=COMM__SUCCESS;
00644 s_his_comm_serv.lu_size=sizeof(s_his_head)+ps_his_head->l_bins_1 * ps_his_head->l_bins_2 * 4;
00645 l_status = f_stc_write (&s_his_comm_serv,sizeof(s_his_comm), l_gl_serv_chan);
00646 if(l_status != STC__SUCCESS)
00647 { printf("error writing comm to client\n"); f_stc_discclient(l_gl_serv_chan); return(COMM__ERROR);}
00648 if(l_gl_serv_verb == 1) {printf("%-32s %8d\n",ps_his_head->c_name,s_his_comm_serv.lu_size-sizeof(s_his_head));}
00649 l_status = f_stc_write (ps_his_head,sizeof(s_his_head), l_gl_serv_chan);
00650 if(l_status != STC__SUCCESS)
00651 { printf("error writing header to client\n"); f_stc_discclient(l_gl_serv_chan); return(COMM__ERROR); }
00652
00653
00654 l_buffer = s_his_comm_serv.lu_size-sizeof(s_his_head);
00655 i_l=l_buffer/16384;
00656 l_buffer=l_buffer%16384;
00657 for(i_j=0;i_j<i_l;i_j++){l_status = f_stc_write (pl_l,16384,l_gl_serv_chan);pl_l+=4096;}
00658 if(l_buffer > 0) l_status = f_stc_write (pl_l,l_buffer,l_gl_serv_chan);
00659 if(l_status != STC__SUCCESS)
00660 { printf("error writing data to client\n"); f_stc_discclient(l_gl_serv_chan); return(COMM__ERROR); }
00661 break;
00662 }
00663 ps_his_head++;
00664 }
00665 if(s_his_comm_serv.lu_histos == 0)
00666 {
00667 if(l_gl_serv_verb == 1) {printf("Histogram %s not found\n",pc_histo);}
00668 s_his_comm_serv.l_status=COMM__NOHIST;
00669 s_his_comm_serv.lu_size=0;
00670 l_status = f_stc_write (&s_his_comm_serv,sizeof(s_his_comm), l_gl_serv_chan);
00671 if(l_status != STC__SUCCESS)
00672 { printf("error writing comm to client\n"); f_stc_discclient(l_gl_serv_chan); return(COMM__ERROR); }
00673 f_stc_discclient (l_gl_serv_chan);
00674 return(COMM__NOHIST);
00675 }
00676 f_stc_discclient (l_gl_serv_chan);
00677 return(COMM__SUCCESS);
00678 }
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708 INTS4 f_his_close()
00709 {
00710 printf("Exit histogram server\n");
00711 f_stc_close (ps_tcpserv);
00712 free(ps_tcpserv);
00713 return(COMM__SUCCESS);
00714 }
00715
00716