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_stccomm.h"
00019 #include "f_swaplw.h"
00020 #include "f_ut_compress.h"
00021 #include "portnum_def.h"
00022 #include <stdio.h>
00023 #include <errno.h>
00024 #include <ctype.h>
00025 #include <string.h>
00026 static CHARS c_gl_serv_access[64];
00027 static CHARS c_gl_serv_base[32];
00028 static INTS4 l_gl_serv_port;
00029 static INTS4 l_gl_serv_chan;
00030 static INTS4 l_gl_serv_verb;
00031 struct s_tcpcomm *ps_tcpserv;
00032 s_his_comm s_his_comm_serv;
00033
00034
00035
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 INTS4 f_his_getbas(CHARS *pc_server, INTS4 l_port, CHARS *pc_base, CHARS *pc_access,INTS4 **p_buffer)
00082 {
00083 s_his_comm s_his_comm_cli;
00084 s_his_head *ps_his_head;
00085 INTS4 i_j,i_l,l_status,l_chan,l_swap,l_buffer,l_histos,l_size;
00086 INTS4 *pl_all,*pl_l;
00087 s_compress *ps_compress;
00088 struct s_tcpcomm *ps_tcpcli;
00089
00090 ps_tcpcli = (struct s_tcpcomm *) malloc (sizeof( struct s_tcpcomm));
00091
00092
00093 s_his_comm_cli.lu_endian=1;
00094 s_his_comm_cli.lu_size=0;
00095 s_his_comm_cli.lu_histos=0;
00096 s_his_comm_cli.lu_action=COMM__GETBASE;
00097 s_his_comm_cli.l_status=COMM__SUCCESS;
00098 strcpy(s_his_comm_cli.c_histo,"*");
00099 strcpy(s_his_comm_cli.c_access,pc_access);
00100 strcpy(s_his_comm_cli.c_base,pc_base);
00101 l_status = f_stc_connectserver (pc_server,l_port, &l_chan, ps_tcpcli);
00102 if(l_status != STC__SUCCESS) {l_status=COMM__NOSERVER;goto g_return;}
00103 l_status = f_stc_write(&s_his_comm_cli,sizeof(s_his_comm),l_chan);
00104 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00105 l_status = f_stc_read (&s_his_comm_cli,sizeof(s_his_comm),l_chan,-1);
00106 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00107 l_swap = (s_his_comm_cli.lu_endian > 1);
00108 if(l_swap) l_status = f_swaplw((INTS4 *)&s_his_comm_cli,5,NULL);
00109 if(s_his_comm_cli.l_status != COMM__SUCCESS) {l_status=s_his_comm_cli.l_status;goto g_return;}
00110
00111
00112 pl_all = (INTS4 *)malloc(s_his_comm_cli.lu_size);
00113 l_buffer = s_his_comm_cli.lu_size;
00114
00115 pl_l=pl_all;
00116 i_l=l_buffer/16384;
00117 l_buffer=l_buffer%16384;
00118 for(i_j=0;i_j<i_l;i_j++){l_status = f_stc_read (pl_l,16384,l_chan,-1);pl_l+=4096;}
00119 if(l_buffer > 0) l_status = f_stc_read (pl_l,l_buffer,l_chan,-1);
00120 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00121
00122 ps_compress = (s_compress *) pl_all;
00123 if(l_swap == 1)
00124 {
00125 f_swaplw((INTS4 *)pl_all,sizeof(s_compress)/4,NULL);
00126 pl_l=pl_all+(sizeof(s_compress)/4);
00127 f_swaplw((INTS4 *)pl_l,ps_compress->l_masks,NULL);
00128 }
00129 *p_buffer = (INTS4 *)malloc(ps_compress->l_full_bytes);
00130 f_ut_compr_unpack((INTU1 *)pl_all,(INTU1 *) *p_buffer,ps_compress->l_full_bytes);
00131 if(l_swap == 1) l_status = f_his_swpbas(*p_buffer);
00132
00133 l_status=COMM__SUCCESS;
00134 g_return:
00135 f_stc_discclient (l_chan);
00136 f_stc_close (ps_tcpcli);
00137 free(pl_all);
00138 free(ps_tcpcli);
00139 return(l_status);
00140 }
00141
00142
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 INTS4 f_his_getdir(CHARS *pc_server, INTS4 l_port, CHARS *pc_base, CHARS *pc_access, CHARS *pc_histo
00189 ,INTS4 **p_buffer, INTS4 *pl_histos)
00190 {
00191 s_his_comm s_his_comm_cli;
00192 s_his_head *ps_his_head;
00193 INTS4 i_j,i_l,l_status,l_chan,l_swap,l_buffer,l_histos,l_size;
00194 INTS4 *pl_all,*pl_l;
00195 struct s_tcpcomm *ps_tcpcli;
00196
00197 ps_tcpcli = (struct s_tcpcomm *) malloc (sizeof( struct s_tcpcomm));
00198
00199
00200 s_his_comm_cli.lu_endian=1;
00201 s_his_comm_cli.lu_size=0;
00202 s_his_comm_cli.lu_histos=0;
00203 s_his_comm_cli.lu_action=COMM__GETDIR;
00204 s_his_comm_cli.l_status=COMM__SUCCESS;
00205 strcpy(s_his_comm_cli.c_histo,pc_histo);
00206 strcpy(s_his_comm_cli.c_access,pc_access);
00207 strcpy(s_his_comm_cli.c_base,pc_base);
00208 l_status = f_stc_connectserver (pc_server,l_port, &l_chan, ps_tcpcli);
00209 if(l_status != STC__SUCCESS) {l_status=COMM__NOSERVER;goto g_return;}
00210 l_status = f_stc_write(&s_his_comm_cli,sizeof(s_his_comm),l_chan);
00211 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00212 l_status = f_stc_read (&s_his_comm_cli,sizeof(s_his_comm),l_chan,-1);
00213 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00214 l_swap = (s_his_comm_cli.lu_endian > 1);
00215 if(l_swap) l_status = f_swaplw((INTS4 *)&s_his_comm_cli,5,NULL);
00216 if(s_his_comm_cli.l_status != COMM__SUCCESS) {l_status=s_his_comm_cli.l_status;goto g_return;}
00217
00218 l_histos=s_his_comm_cli.lu_histos;
00219 l_size=sizeof(s_his_head)*l_histos;
00220
00221 if(*p_buffer == 0)
00222 {
00223 pl_all = (INTS4 *)malloc(l_size);
00224 *p_buffer = pl_all;
00225 }
00226 else
00227 {
00228 if(*pl_histos < l_histos) {l_status=COMM__ERROR;goto g_return;}
00229 pl_all = *p_buffer;
00230 }
00231 *pl_histos = l_histos;
00232 l_buffer = s_his_comm_cli.lu_size;
00233
00234 pl_l=pl_all;
00235 i_l=l_buffer/16384;
00236 l_buffer=l_buffer%16384;
00237 for(i_j=0;i_j<i_l;i_j++){l_status = f_stc_read (pl_l,16384,l_chan,-1);pl_l+=4096;}
00238 if(l_buffer > 0) l_status = f_stc_read (pl_l,l_buffer,l_chan,-1);
00239 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00240
00241 ps_his_head = (s_his_head *)pl_all;
00242 for(i_j=0;i_j<s_his_comm_cli.lu_histos;i_j++)
00243 {
00244 if(l_swap) l_status = f_swaplw((INTS4 *)ps_his_head,16,NULL);
00245 ps_his_head++;
00246
00247 }
00248 l_status=COMM__SUCCESS;
00249 g_return:
00250 f_stc_discclient (l_chan);
00251 f_stc_close (ps_tcpcli);
00252 free(ps_tcpcli);
00253 return(l_status);
00254 }
00255
00256
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 INTS4 f_his_gethis(CHARS *pc_server, INTS4 l_port, CHARS *pc_base, CHARS *pc_access, CHARS *pc_histo
00311 , s_his_head **p_head, INTS4 **p_buffer, INTS4 *pl_size)
00312 {
00313 s_his_comm s_his_comm_cli;
00314 s_his_head *ps_his_head;
00315 INTS4 i_j,i_l,l_status,l_chan,l_swap,l_buffer,l_histos,l_size;
00316 INTS4 *pl_all,*pl_head,*pl_l;
00317 struct s_tcpcomm *ps_tcpcli;
00318
00319 ps_tcpcli = (struct s_tcpcomm *) malloc (sizeof( struct s_tcpcomm));
00320
00321
00322 s_his_comm_cli.lu_endian=1;
00323 s_his_comm_cli.lu_size=0;
00324 s_his_comm_cli.lu_histos=0;
00325 s_his_comm_cli.lu_action=COMM__GETHIST;
00326 s_his_comm_cli.l_status=COMM__SUCCESS;
00327 strcpy(s_his_comm_cli.c_histo,pc_histo);
00328 strcpy(s_his_comm_cli.c_access,pc_access);
00329 strcpy(s_his_comm_cli.c_base,pc_base);
00330 l_status = f_stc_connectserver (pc_server,l_port, &l_chan, ps_tcpcli);
00331 if(l_status != STC__SUCCESS) {l_status=COMM__NOSERVER;goto g_return;}
00332 l_status = f_stc_write(&s_his_comm_cli,sizeof(s_his_comm),l_chan);
00333 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00334 l_status = f_stc_read (&s_his_comm_cli,sizeof(s_his_comm),l_chan,-1);
00335 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00336 l_swap = (s_his_comm_cli.lu_endian > 1);
00337 if(l_swap) l_status = f_swaplw((INTS4 *)&s_his_comm_cli,5,NULL);
00338 if(s_his_comm_cli.l_status != COMM__SUCCESS) {l_status=s_his_comm_cli.l_status;goto g_return;}
00339
00340 l_size=s_his_comm_cli.lu_size-sizeof(s_his_head);
00341
00342 if(*p_buffer == 0)
00343 {
00344 pl_all = (INTS4 *)malloc(l_size);
00345 *p_buffer = pl_all;
00346 }
00347 else
00348 {
00349 if(*pl_size < l_size) {l_status=COMM__ERROR;goto g_return;}
00350 pl_all = *p_buffer;
00351 }
00352
00353 if(*p_head == 0)
00354 {
00355 ps_his_head = (s_his_head *)malloc(sizeof(s_his_head));
00356 *p_head = ps_his_head;
00357 }
00358 else ps_his_head = *p_head;
00359
00360 l_status = f_stc_read (ps_his_head,sizeof(s_his_head),l_chan,-1);
00361 if(l_swap) l_status = f_swaplw((INTS4 *)ps_his_head,16,NULL);
00362
00363 *pl_size = l_size;
00364 l_buffer = l_size;
00365
00366
00367 pl_l=pl_all;
00368 i_l=l_buffer/16384;
00369 l_buffer=l_buffer%16384;
00370 for(i_j=0;i_j<i_l;i_j++){l_status = f_stc_read (pl_l,16384,l_chan,-1);pl_l+=4096;}
00371 if(l_buffer > 0) l_status = f_stc_read (pl_l,l_buffer,l_chan,-1);
00372 if(l_status != STC__SUCCESS) {l_status=COMM__ERROR;goto g_return;}
00373
00374 if(l_swap) l_status = f_swaplw((INTS4 *)pl_all,l_size/4,NULL);
00375
00376 l_status=COMM__SUCCESS;
00377 g_return:
00378 f_stc_discclient (l_chan);
00379 f_stc_close (ps_tcpcli);
00380 free(ps_tcpcli);
00381 return(l_status);
00382 }
00383
00384
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 INTS4 f_his_server(CHARS *pc_base, CHARS *pc_access, INTS4 *pl_port)
00418 {
00419 INTS4 *pl_l,i_j,i_l,ll,l_buffer,l_status;
00420
00421 ps_tcpserv = (struct s_tcpcomm *) malloc (sizeof( struct s_tcpcomm));
00422 l_gl_serv_port=PORT__HIST_SERV;
00423 strcpy(c_gl_serv_access,pc_access);
00424 strcpy(c_gl_serv_base,pc_base);
00425 f_his_toupper(c_gl_serv_access,sizeof(c_gl_serv_access));
00426 f_his_toupper(c_gl_serv_base,sizeof(c_gl_serv_base));
00427
00428 while((l_status = f_stc_createserver (&l_gl_serv_port, ps_tcpserv)) != STC__SUCCESS)
00429 {
00430 l_gl_serv_port++;
00431 if(l_gl_serv_port > PORT__HIST_SERV + 20)
00432 {
00433 printf("Error creating histogram server\n");
00434 return(COMM__ERROR);
00435 }
00436 }
00437 *pl_port=l_gl_serv_port;
00438 return(0);
00439 }
00440
00441
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 INTS4 f_his_wait(INTS4 *pl_action, CHARS *pc_histo)
00478 {
00479 INTS4 *pl_l,i_j,i_l,ll,l_buffer,l_status;
00480
00481 if(l_gl_serv_verb == 1) {printf("Waiting for client on port %d [%s] \n",l_gl_serv_port,c_gl_serv_access);}
00482 l_status = f_stc_acceptclient (ps_tcpserv, &l_gl_serv_chan);
00483 if(l_status != STC__SUCCESS) { printf("error accepting client\n"); return(COMM__ERROR);}
00484 if(l_gl_serv_verb == 1) {printf("Client connected. \n");}
00485 l_status = f_stc_read (&s_his_comm_serv,sizeof(s_his_comm),l_gl_serv_chan,-1);
00486 if(l_status != STC__SUCCESS) { printf("error reading client\n"); f_stc_discclient(l_gl_serv_chan);return(COMM__ERROR); }
00487
00488 f_his_toupper(s_his_comm_serv.c_access,sizeof(s_his_comm_serv.c_access));
00489 f_his_toupper(s_his_comm_serv.c_base,sizeof(s_his_comm_serv.c_base));
00490 if((strlen(c_gl_serv_access) != 0) &
00491 (strcmp(s_his_comm_serv.c_access,c_gl_serv_access) != 0))
00492 {
00493 printf("Client connected with wrong password [%s]. \n",s_his_comm_serv.c_access);
00494 s_his_comm_serv.lu_endian=1;
00495 s_his_comm_serv.lu_size=0;
00496 s_his_comm_serv.lu_histos=0;
00497 s_his_comm_serv.l_status=COMM__NOACCESS;
00498 l_status = f_stc_write (&s_his_comm_serv,sizeof(s_his_comm), l_gl_serv_chan);
00499 f_stc_discclient (l_gl_serv_chan);
00500 return(COMM__NOACCESS);
00501 }
00502
00503 if(strcmp(s_his_comm_serv.c_base,c_gl_serv_base) != 0)
00504 {
00505 printf("Client connected for wrong base [%s]. \n",s_his_comm_serv.c_base);
00506 s_his_comm_serv.lu_endian=1;
00507 s_his_comm_serv.lu_size=0;
00508 s_his_comm_serv.lu_histos=0;
00509 s_his_comm_serv.l_status=COMM__NOBASE;
00510 l_status = f_stc_write (&s_his_comm_serv,sizeof(s_his_comm), l_gl_serv_chan);
00511 f_stc_discclient (l_gl_serv_chan);
00512 return(COMM__NOBASE);
00513 }
00514 if(s_his_comm_serv.lu_endian > 100) l_status = f_swaplw((INTS4 *)&s_his_comm_serv,5,NULL);
00515 if(l_gl_serv_verb == 1) {printf("%d: %d %d %d %d %d \"%s\" \"%s\" \"%s\"\n",l_status
00516 ,s_his_comm_serv.lu_endian
00517 ,s_his_comm_serv.lu_action
00518 ,s_his_comm_serv.lu_histos
00519 ,s_his_comm_serv.lu_size
00520 ,s_his_comm_serv.l_status
00521 ,s_his_comm_serv.c_access
00522 ,s_his_comm_serv.c_base
00523 ,s_his_comm_serv.c_histo);}
00524 *pl_action=s_his_comm_serv.lu_action;
00525 strcpy(pc_histo,s_his_comm_serv.c_histo);
00526 return(COMM__SUCCESS);
00527 }
00528
00529
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 INTS4 f_his_senddir(s_his_head *ps_head, INTS4 l_histos)
00563 {
00564 INTS4 *pl_l,i_j,i_l,ll,l_buffer,l_status;
00565
00566 if(l_gl_serv_verb == 1) {printf("Send directory %s. \n",s_his_comm_serv.c_histo);}
00567 s_his_comm_serv.lu_histos=l_histos;
00568 s_his_comm_serv.lu_endian=1;
00569 s_his_comm_serv.lu_action=COMM__PUTDIR;
00570 s_his_comm_serv.lu_size=sizeof(s_his_head)*s_his_comm_serv.lu_histos;
00571 s_his_comm_serv.l_status=COMM__SUCCESS;
00572 l_status = f_stc_write (&s_his_comm_serv,sizeof(s_his_comm), l_gl_serv_chan);
00573 if(l_status != STC__SUCCESS)
00574 { printf("error writing comm to client\n"); f_stc_discclient(l_gl_serv_chan);return(COMM__ERROR);}
00575
00576
00577 pl_l=(INTS4 *)ps_head;
00578 l_buffer = s_his_comm_serv.lu_size;
00579 i_l=l_buffer/16384;
00580 l_buffer=l_buffer%16384;
00581 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;}
00582 if(l_buffer > 0) l_status = f_stc_write (pl_l,l_buffer,l_gl_serv_chan);
00583
00584 if(l_status != STC__SUCCESS)
00585 { printf("error writing directory to client\n"); f_stc_discclient(l_gl_serv_chan);return(COMM__ERROR);}
00586 f_stc_discclient (l_gl_serv_chan);
00587 return(COMM__SUCCESS);
00588 }
00589
00590
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 INTS4 f_his_sendhis(s_his_head *ps_head, INTS4 l_histos, CHARS *pc_histo, INTS4 *pl_data)
00626 {
00627 s_his_head *ps_his_head;
00628 INTS4 *pl_l,i_j,i_l,ll,l_buffer,l_status;
00629
00630 s_his_comm_serv.lu_endian=1;
00631 s_his_comm_serv.lu_histos=0;
00632 s_his_comm_serv.lu_action=COMM__PUTHIST;
00633 ps_his_head = ps_head;
00634 for(ll=0;ll<l_histos;ll++)
00635 {
00636 pl_l = pl_data;
00637 if(strcmp(ps_his_head->c_name,pc_histo) == 0)
00638 {
00639 s_his_comm_serv.lu_histos=1;
00640 s_his_comm_serv.l_status=COMM__SUCCESS;
00641 s_his_comm_serv.lu_size=sizeof(s_his_head)+ps_his_head->l_bins_1 * ps_his_head->l_bins_2 * 4;
00642 l_status = f_stc_write (&s_his_comm_serv,sizeof(s_his_comm), l_gl_serv_chan);
00643 if(l_status != STC__SUCCESS)
00644 { printf("error writing comm to client\n"); f_stc_discclient(l_gl_serv_chan); return(COMM__ERROR);}
00645 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));}
00646 l_status = f_stc_write (ps_his_head,sizeof(s_his_head), l_gl_serv_chan);
00647 if(l_status != STC__SUCCESS)
00648 { printf("error writing header to client\n"); f_stc_discclient(l_gl_serv_chan); return(COMM__ERROR); }
00649
00650
00651 l_buffer = s_his_comm_serv.lu_size-sizeof(s_his_head);
00652 i_l=l_buffer/16384;
00653 l_buffer=l_buffer%16384;
00654 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;}
00655 if(l_buffer > 0) l_status = f_stc_write (pl_l,l_buffer,l_gl_serv_chan);
00656 if(l_status != STC__SUCCESS)
00657 { printf("error writing data to client\n"); f_stc_discclient(l_gl_serv_chan); return(COMM__ERROR); }
00658 break;
00659 }
00660 ps_his_head++;
00661 }
00662 if(s_his_comm_serv.lu_histos == 0)
00663 {
00664 if(l_gl_serv_verb == 1) {printf("Histogram %s not found\n",pc_histo);}
00665 s_his_comm_serv.l_status=COMM__NOHIST;
00666 s_his_comm_serv.lu_size=0;
00667 l_status = f_stc_write (&s_his_comm_serv,sizeof(s_his_comm), l_gl_serv_chan);
00668 if(l_status != STC__SUCCESS)
00669 { printf("error writing comm to client\n"); f_stc_discclient(l_gl_serv_chan); return(COMM__ERROR); }
00670 f_stc_discclient (l_gl_serv_chan);
00671 return(COMM__NOHIST);
00672 }
00673 f_stc_discclient (l_gl_serv_chan);
00674 return(COMM__SUCCESS);
00675 }
00676
00677
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 INTS4 f_his_close()
00706 {
00707 printf("Exit histogram server\n");
00708 f_stc_close (ps_tcpserv);
00709 free(ps_tcpserv);
00710 return(COMM__SUCCESS);
00711 }
00712
00713