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