00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00031
00032
00033
00034
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <malloc.h>
00038 #include <string.h>
00039
00040 #include "lcas_vo_data.h"
00041 #include "lcas_log.h"
00042
00043
00044
00045
00046 #define VO_DATA_WHITESPACE_CHARS " \t\n"
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00084 lcas_vo_data_t *
00085 lcas_createVoData(
00086 const char * vo,
00087 const char * group,
00088 const char * subgroup,
00089 const char * role,
00090 const char * capability
00091 )
00092 {
00093 lcas_vo_data_t * newVoData=NULL;
00094
00095 newVoData = (lcas_vo_data_t *)malloc(sizeof(lcas_vo_data_t));
00096 if (!newVoData)
00097 {
00098 lcas_log(0,"lcas_createVoData(): error in malloc for new VoData structure\n");
00099 return NULL;
00100 }
00101
00102 newVoData->vo = NULL;
00103 newVoData->group = NULL;
00104 newVoData->subgroup = NULL;
00105 newVoData->role = NULL;
00106 newVoData->capability = NULL;
00107
00108 if (vo) newVoData->vo = strdup(vo);
00109 if (group) newVoData->group = strdup(group);
00110 if (subgroup) newVoData->subgroup = strdup(subgroup);
00111 if (role) newVoData->role = strdup(role);
00112 if (capability) newVoData->capability = strdup(capability);
00113
00114 return newVoData;
00115 }
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00144 int
00145 lcas_deleteVoData(
00146 lcas_vo_data_t ** vo_data
00147 )
00148 {
00149 if (!vo_data) {
00150 lcas_log(0, "lcas_deleteVoData(): empty pointer as input !\n");
00151 return -1;
00152 }
00153
00154 if ( (*vo_data) )
00155 {
00156 if ( (*vo_data)->vo) free( (*vo_data)->vo );
00157 if ( (*vo_data)->group) free( (*vo_data)->group );
00158 if ( (*vo_data)->subgroup) free( (*vo_data)->subgroup );
00159 if ( (*vo_data)->role) free( (*vo_data)->role );
00160 if ( (*vo_data)->capability) free( (*vo_data)->capability );
00161 free( (*vo_data) );
00162 }
00163 else
00164 {
00165 lcas_log_debug(2,"lcas_deleteVoData(): no lcas_vo_data_t found\n");
00166 }
00167 *vo_data=NULL;
00168 return 0;
00169 }
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00198 int
00199 lcas_cleanVoData(
00200 lcas_vo_data_t * vo_data
00201 )
00202 {
00203 if (!vo_data) {
00204 lcas_log(0, "lcas_cleanVoData():: no lcas_vo_data_t found\n");
00205 return -1;
00206 }
00207 else
00208 {
00209 if ( (vo_data)->vo)
00210 {
00211 free( (vo_data)->vo );
00212 vo_data->vo = NULL;
00213 }
00214 if ( (vo_data)->group)
00215 {
00216 free( (vo_data)->group );
00217 vo_data->group = NULL;
00218 }
00219 if ( (vo_data)->subgroup)
00220 {
00221 free( (vo_data)->subgroup );
00222 vo_data->subgroup = NULL;
00223 }
00224 if ( (vo_data)->role)
00225 {
00226 free( (vo_data)->role );
00227 vo_data->role = NULL;
00228 }
00229 if ( (vo_data)->capability)
00230 {
00231 free( (vo_data)->capability );
00232 vo_data->capability = NULL;
00233 }
00234 }
00235 return 0;
00236 }
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00266 int
00267 lcas_copyVoData(
00268 lcas_vo_data_t * dst_vo_data,
00269 const lcas_vo_data_t * src_vo_data
00270 )
00271 {
00272 if ( (dst_vo_data) && (src_vo_data) )
00273 {
00274 if (src_vo_data->vo)
00275 dst_vo_data->vo = strdup(src_vo_data->vo);
00276 else
00277 dst_vo_data->vo = NULL;
00278 if (src_vo_data->group)
00279 dst_vo_data->group = strdup(src_vo_data->group);
00280 else
00281 dst_vo_data->group = NULL;
00282 if (src_vo_data->subgroup)
00283 dst_vo_data->subgroup = strdup(src_vo_data->subgroup);
00284 else
00285 dst_vo_data->subgroup = NULL;
00286 if (src_vo_data->role)
00287 dst_vo_data->role = strdup(src_vo_data->role);
00288 else
00289 dst_vo_data->role = NULL;
00290 if (src_vo_data->capability)
00291 dst_vo_data->capability = strdup(src_vo_data->capability);
00292 else
00293 dst_vo_data->capability = NULL;
00294
00295 return 0;
00296 }
00297 else
00298 {
00299 return -1;
00300 }
00301 }
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00327 int
00328 lcas_printVoData(
00329 int debug_level,
00330 const lcas_vo_data_t * vo_data
00331 )
00332 {
00333 if (vo_data)
00334 {
00335 lcas_log_debug(debug_level,"lcas_printVoData(): address of vo data struct: %p\n", vo_data);
00336 lcas_log_debug(debug_level,"lcas_printVoData(): VO: %s\n", vo_data->vo);
00337 lcas_log_debug(debug_level,"lcas_printVoData(): GROUP: %s\n", vo_data->group);
00338 lcas_log_debug(debug_level,"lcas_printVoData(): SUBGROUP: %s\n", vo_data->subgroup);
00339 lcas_log_debug(debug_level,"lcas_printVoData(): ROLE: %s\n", vo_data->role);
00340 lcas_log_debug(debug_level,"lcas_printVoData(): CAPABILITY: %s\n", vo_data->capability);
00341 }
00342 else
00343 {
00344 lcas_log_debug(debug_level,"lcas_printVoData(): empty pointer to vo data struct\n");
00345 }
00346 return 0;
00347 }
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00395 int
00396 lcas_stringVoData(
00397 const lcas_vo_data_t * vo_data,
00398 char * buffer,
00399 int nchars
00400 )
00401 {
00402 int totalchars;
00403 char * strptr=NULL;
00404 char * bufptr=NULL;
00405 int buflen=0;
00406
00407 bufptr=buffer;
00408 buflen=nchars;
00409
00410
00411
00412 if ( (strptr=lcas_parseVostring(vo_data->vo)) )
00413 {
00414
00415
00416
00417
00418
00419 totalchars=snprintf(bufptr,(size_t)buflen,"/VO=%s",strptr);
00420 if ( (totalchars+1) > buflen )
00421 {
00422 lcas_log(0,"lcas_stringVoData(): could not write all characters into buffer for VO\n");
00423 lcas_log(0,"lcas_stringVoData(): excess of characters: %d\n",totalchars+1-buflen);
00424 return -1;
00425 }
00426 else if ( totalchars < 0 )
00427 {
00428 lcas_log(0,"lcas_stringVoData(): error in snprintf()\n");
00429 return -1;
00430 }
00431 else
00432 {
00433 bufptr+=totalchars;
00434 buflen-=totalchars;
00435 }
00436 }
00437 else
00438 {
00439 lcas_log(0,"lcas_stringVoData(): error no VO found\n");
00440 return -1;
00441 }
00442
00443
00444
00445 if ( (strptr=lcas_parseVostring(vo_data->group)) )
00446 {
00447 totalchars=snprintf(bufptr,(size_t)buflen,"/GROUP=%s",strptr);
00448 if ( (totalchars+1) > buflen )
00449 {
00450 lcas_log(0,"lcas_stringVoData(): could not write all characters into buffer for GROUP\n");
00451 lcas_log(0,"lcas_stringVoData(): excess of characters: %d\n",totalchars+1-buflen);
00452 return -1;
00453 }
00454 else if ( totalchars < 0 )
00455 {
00456 lcas_log(0,"lcas_stringVoData(): error in snprintf()\n");
00457 return -1;
00458 }
00459 else
00460 {
00461 bufptr+=totalchars;
00462 buflen-=totalchars;
00463 }
00464 }
00465 else
00466 {
00467 lcas_log(0,"lcas_stringVoData(): error no VO-group found\n");
00468 return -1;
00469 }
00470
00471
00472
00473
00474
00475 if ( (strptr=lcas_parseVostring(vo_data->role)) )
00476 {
00477 {
00478 totalchars=snprintf(bufptr,(size_t)buflen,"/ROLE=%s",strptr);
00479 if ( (totalchars+1) > buflen )
00480 {
00481 lcas_log(0,"lcas_stringVoData(): could not write all characters into buffer for ROLE\n");
00482 lcas_log(0,"lcas_stringVoData(): excess of characters: %d\n",totalchars+1-buflen);
00483 return -1;
00484 }
00485 else if ( totalchars < 0 )
00486 {
00487 lcas_log(0,"lcas_stringVoData(): error in snprintf()\n");
00488 return -1;
00489 }
00490 else
00491 {
00492 bufptr+=totalchars;
00493 buflen-=totalchars;
00494 }
00495 }
00496 }
00497
00498
00499
00500 if ( (strptr=lcas_parseVostring(vo_data->capability)) )
00501 {
00502 {
00503 totalchars=snprintf(bufptr,(size_t)buflen,"/CAPABILITY=%s",strptr);
00504 if ( (totalchars+1) > buflen )
00505 {
00506 lcas_log(0,"lcas_stringVoData(): could not write all characters into buffer for CAPABILITY\n");
00507 lcas_log(0,"lcas_stringVoData(): excess of characters: %d\n",totalchars+1-buflen);
00508 return -1;
00509 }
00510 else if ( totalchars < 0 )
00511 {
00512 lcas_log(0,"lcas_stringVoData(): error in snprintf()\n");
00513 return -1;
00514 }
00515 else
00516 {
00517 bufptr+=totalchars;
00518 buflen-=totalchars;
00519 }
00520 }
00521 }
00522 return 0;
00523 }
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00554 char *
00555 lcas_parseVostring(
00556 char * vo_string
00557 )
00558 {
00559 char * strptr = NULL;
00560
00561 if (vo_string == NULL) return NULL;
00562
00563 strptr=vo_string;
00564 strptr += strspn(strptr, VO_DATA_WHITESPACE_CHARS);
00565 if ( (*strptr!='\0') && (strncmp(strptr,"NULL",4)) )
00566 {
00567 return strptr;
00568 }
00569 else
00570 {
00571 return NULL;
00572 }
00573 }
00574
00575
00576
00577
00578
00579
00580
00581
00582