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 "lcmaps_vo_data.h"
00034 #include "lcmaps_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 lcmaps_vo_data_t *
00078 lcmaps_createVoData(
00079 const char * vo,
00080 const char * group,
00081 const char * subgroup,
00082 const char * role,
00083 const char * capability
00084 )
00085 {
00086 lcmaps_vo_data_t * newVoData=NULL;
00087
00088 newVoData = (lcmaps_vo_data_t *)malloc(sizeof(lcmaps_vo_data_t));
00089 if (!newVoData)
00090 {
00091 lcmaps_log(0,"lcmaps_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 lcmaps_deleteVoData(
00139 lcmaps_vo_data_t ** vo_data
00140 )
00141 {
00142 if (!vo_data) {
00143 lcmaps_log(0, "lcmaps_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 lcmaps_log_debug(2,"lcmaps_deleteVoData(): no lcmaps_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 lcmaps_cleanVoData(
00193 lcmaps_vo_data_t * vo_data
00194 )
00195 {
00196 if (!vo_data) {
00197 lcmaps_log(0, "lcmaps_cleanVoData():: no lcmaps_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 lcmaps_copyVoData(
00261 lcmaps_vo_data_t * dst_vo_data,
00262 const lcmaps_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 lcmaps_printVoData(
00322 int debug_level,
00323 const lcmaps_vo_data_t * vo_data
00324 )
00325 {
00326 if (vo_data)
00327 {
00328 lcmaps_log_debug(debug_level,"lcmaps_printVoData(): address of vo data struct: %p\n", vo_data);
00329 lcmaps_log_debug(debug_level,"lcmaps_printVoData(): VO: %s\n", vo_data->vo);
00330 lcmaps_log_debug(debug_level,"lcmaps_printVoData(): GROUP: %s\n", vo_data->group);
00331 lcmaps_log_debug(debug_level,"lcmaps_printVoData(): SUBGROUP: %s\n", vo_data->subgroup);
00332 lcmaps_log_debug(debug_level,"lcmaps_printVoData(): ROLE: %s\n", vo_data->role);
00333 lcmaps_log_debug(debug_level,"lcmaps_printVoData(): CAPABILITY: %s\n", vo_data->capability);
00334 }
00335 else
00336 {
00337 lcmaps_log_debug(debug_level,"lcmaps_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 lcmaps_stringVoData(
00390 const lcmaps_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 if ( vo_data->vo == NULL )
00405 {
00406 lcmaps_log(0,"lcmaps_stringVoData(): error no VO found\n");
00407 return -1;
00408 }
00409
00410 strptr=vo_data->vo;
00411 strptr += strspn(strptr, VO_DATA_WHITESPACE_CHARS);
00412 if ( (*strptr!='\0') && (strncmp(strptr,"NULL",4)) )
00413 {
00414
00415
00416
00417
00418
00419 totalchars=snprintf(bufptr,(size_t)buflen,"/VO=%s",strptr);
00420 if ( (totalchars+1) > buflen )
00421 {
00422 lcmaps_log(0,"lcmaps_stringVoData(): could not write all characters into buffer for VO\n");
00423 lcmaps_log(0,"lcmaps_stringVoData(): excess of characters: %d\n",totalchars+1-buflen);
00424 return -1;
00425 }
00426 else if ( totalchars < 0 )
00427 {
00428 lcmaps_log(0,"lcmaps_stringVoData(): error in snprintf()\n");
00429 return -1;
00430 }
00431 else
00432 {
00433 bufptr+=totalchars;
00434 buflen-=totalchars;
00435 }
00436 }
00437 else
00438 {
00439 lcmaps_log(0,"lcmaps_stringVoData(): error no VO found\n");
00440 return -1;
00441 }
00442
00443
00444 if ( vo_data->group == NULL )
00445 {
00446 lcmaps_log(0,"lcmaps_stringVoData(): error no VO-group found\n");
00447 return -1;
00448 }
00449
00450 strptr=vo_data->group;
00451 strptr += strspn(strptr, VO_DATA_WHITESPACE_CHARS);
00452 if ( (*strptr!='\0') && (strncmp(strptr,"NULL",4)) )
00453 {
00454 totalchars=snprintf(bufptr,(size_t)buflen,"/GROUP=%s",strptr);
00455 if ( (totalchars+1) > buflen )
00456 {
00457 lcmaps_log(0,"lcmaps_stringVoData(): could not write all characters into buffer for GROUP\n");
00458 lcmaps_log(0,"lcmaps_stringVoData(): excess of characters: %d\n",totalchars+1-buflen);
00459 return -1;
00460 }
00461 else if ( totalchars < 0 )
00462 {
00463 lcmaps_log(0,"lcmaps_stringVoData(): error in snprintf()\n");
00464 return -1;
00465 }
00466 else
00467 {
00468 bufptr+=totalchars;
00469 buflen-=totalchars;
00470 }
00471 }
00472 else
00473 {
00474 lcmaps_log(0,"lcmaps_stringVoData(): error no VO-group found\n");
00475 return -1;
00476 }
00477
00478
00479
00480
00481 if ( vo_data->role != NULL )
00482 {
00483
00484 strptr=vo_data->role;
00485 strptr += strspn(strptr, VO_DATA_WHITESPACE_CHARS);
00486 if ( (*strptr!='\0') && (strncmp(strptr,"NULL",4)) )
00487 {
00488 totalchars=snprintf(bufptr,(size_t)buflen,"/ROLE=%s",strptr);
00489 if ( (totalchars+1) > buflen )
00490 {
00491 lcmaps_log(0,"lcmaps_stringVoData(): could not write all characters into buffer for ROLE\n");
00492 lcmaps_log(0,"lcmaps_stringVoData(): excess of characters: %d\n",totalchars+1-buflen);
00493 return -1;
00494 }
00495 else if ( totalchars < 0 )
00496 {
00497 lcmaps_log(0,"lcmaps_stringVoData(): error in snprintf()\n");
00498 return -1;
00499 }
00500 else
00501 {
00502 bufptr+=totalchars;
00503 buflen-=totalchars;
00504 }
00505 }
00506 }
00507
00508
00509 if ( vo_data->capability != NULL )
00510 {
00511
00512 strptr=vo_data->capability;
00513 strptr += strspn(strptr, VO_DATA_WHITESPACE_CHARS);
00514 if ( (*strptr!='\0') && (strncmp(strptr,"NULL",4)) )
00515 {
00516 totalchars=snprintf(bufptr,(size_t)buflen,"/CAPABILITY=%s",strptr);
00517 if ( (totalchars+1) > buflen )
00518 {
00519 lcmaps_log(0,"lcmaps_stringVoData(): could not write all characters into buffer for CAPABILITY\n");
00520 lcmaps_log(0,"lcmaps_stringVoData(): excess of characters: %d\n",totalchars+1-buflen);
00521 return -1;
00522 }
00523 else if ( totalchars < 0 )
00524 {
00525 lcmaps_log(0,"lcmaps_stringVoData(): error in snprintf()\n");
00526 return -1;
00527 }
00528 else
00529 {
00530 bufptr+=totalchars;
00531 buflen-=totalchars;
00532 }
00533 }
00534 }
00535 return 0;
00536 }
00537
00538
00539
00540
00541
00542
00543
00544