00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATAdvertService.c,v 1.12 2004/04/29 14:18:49 hartmutkaiser Exp $";
00018
00019
00020 #include <stdlib.h>
00021 #include <string.h>
00022 #include <assert.h>
00023 #include <time.h>
00024 #include <errno.h>
00025 #include <sys/utsname.h>
00026
00027
00028 #include "GAT.h"
00029 #include "GATUtil.h"
00030 #include "GATInternal.h"
00031 #include "GATRegistry.h"
00032 #include "GATAdvertServiceCPI.h"
00033 #include "GATMetricEvent.h"
00034 #include "GATMonitorable.h"
00035
00036
00037 GATOBJECT_DEFINE_VTABLE(GATAdvertService);
00038 GATMONITORABLE_DEFINE_VTABLE(GATAdvertService);
00039
00040
00041 GATOBJECT_DEFINE_CONVERTERS(GATAdvertService)
00042
00043
00044
00045
00046 struct GATAdvertService_S {
00047
00048 GATAdvertService_vtable *GATObject__vtable;
00049 GATAdvertService_IMonitorable_vtable *GATMonitorable__vtable;
00050
00051
00052 GATAdvertServiceCPI_Instance data;
00053 GATAdvertServiceCPI cpi;
00054 GATAdvertServiceCPIList cpilist;
00055 };
00056
00057
00058
00059 static GATResult
00060 GATAdvertService_GetCPIInstanceData(GATAdvertService object, void **data);
00061
00062 static GATResult
00063 GATAdvertService_EnsureMetaDataItem(GATContext context, char const *item,
00064 GATTable metadata, char const *defaultvalue);
00065
00066 static char *
00067 GATAdvertService_ExtractName(GATString_const path);
00068
00069 static GATResult
00070 GATAdvertService_ResolvePath(
00071 GATString_const cwd, GATString_const path, char **absolute_path);
00072
00073
00074 GATAdvertService_vtable GATAdvertService__vtable = {
00075 GATAdvertService_GetType,
00076 GATAdvertService_Destroy,
00077 GATAdvertService_Equals,
00078 GATAdvertService_Clone,
00079 GATAdvertService_GetInterface,
00080 GATAdvertService_GetCPIInstanceData
00081 };
00082
00083 static GATAdvertService_IMonitorable_vtable
00084 GATAdvertService_IMonitorable__vtable =
00085 {
00086 GATAdvertService_AddMetricListener,
00087 GATAdvertService_RegisterPolling,
00088 GATAdvertService_RemoveRegisteredMetric,
00089 GATAdvertService_GetMetrics
00090 };
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 GATAdvertService
00109 GATAdvertService_Create(GATContext context, GATPreferences_const preferences)
00110 {
00111 GAT_STATUS_APIENTRY(context, "GATAdvertService_Create");
00112
00113 GATAdvertService new_advertservice = (GATAdvertService) malloc(
00114 sizeof(struct GATAdvertService_S));
00115 if (NULL != new_advertservice)
00116 {
00117 memset(new_advertservice, 0, sizeof(struct GATAdvertService_S));
00118 new_advertservice->GATObject__vtable = &GATAdvertService__vtable;
00119 new_advertservice->GATMonitorable__vtable =
00120 &GATAdvertService_IMonitorable__vtable;
00121
00122 new_advertservice->data.context = context;
00123 new_advertservice->data.source =
00124 GATAdvertService_ToGATObject_const(new_advertservice);
00125 new_advertservice->data.pwd = GATString_Create("/", 2, "ASCII");
00126
00127 GAT_CREATE_STATUS_IF(NULL == new_advertservice->data.pwd, GAT_MEMORYFAILURE);
00128
00129
00130 {
00131 GATRegistry_const registry = GATContext_internal_GetRegistry(context);
00132
00133
00134 if (NULL == preferences)
00135 {
00136 preferences = GATContext_GetPreferences(context);
00137 }
00138 new_advertservice->cpilist = GATRegistry_FindGATAdvertServiceCPI(registry, preferences);
00139
00140 if (NULL == new_advertservice->cpilist)
00141 {
00142 GAT_CREATE_STATUS(GAT_NO_REGISTERED_CPI);
00143 }
00144 else if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00145 {
00146
00147 GATBool found_cpi = GATFalse;
00148 GATAdvertServiceCPIList current = NULL;
00149 for(current = new_advertservice->cpilist; NULL != current; current = current->next)
00150 {
00151 GAT_CREATE_STATUS(GATAdvertServiceCPI_CreateInstance(current->cpi,
00152 &new_advertservice->data));
00153 if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00154 {
00155 new_advertservice->cpi = current->cpi;
00156 found_cpi = GATTrue;
00157 break;
00158 }
00159 }
00160
00161
00162 if (GATFalse == found_cpi)
00163 {
00164 GAT_CREATE_STATUS(GAT_NO_REGISTERED_CPI);
00165 }
00166 else
00167 {
00168
00169
00170 GATList_GATMetric metrics = NULL;
00171 GATResult retval = GATAdvertServiceCPI_GetMetrics(new_advertservice->cpi,
00172 &new_advertservice->data, &metrics);
00173
00174 if (GAT_SUCCEEDED(retval))
00175 {
00176 new_advertservice->data.monitorable = GATMonitorable_Impl_Create(metrics);
00177 if (NULL == new_advertservice->data.monitorable)
00178 {
00179 GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00180 }
00181 GATList_GATMetric_Destroy(&metrics);
00182 }
00183 else if (GAT_NOTIMPL == retval)
00184 {
00185 retval = GAT_SUCCESS;
00186 }
00187 else
00188 {
00189 GAT_CREATE_STATUS(retval);
00190 }
00191
00192
00193 GAT_CREATE_STATUS(GATRegistry_AddGATAdvertServiceToCPIList(context,
00194 new_advertservice->cpi, new_advertservice));
00195 }
00196 }
00197 }
00198 }
00199 else
00200 {
00201 GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00202 }
00203
00204
00205 if (GAT_FAILED(GAT_CURRENT_STATUS()))
00206 {
00207 GATAdvertService_Destroy(&new_advertservice);
00208 }
00209 GAT_STORE_STATUS();
00210 return new_advertservice;
00211 }
00212
00213
00214
00215
00216
00217
00218
00219
00220 void
00221 GATAdvertService_Destroy(GATAdvertService *object)
00222 {
00223 if (NULL != object && NULL != *object)
00224 {
00225 GATString_Destroy(&(*object)->data.pwd);
00226 GATMonitorable_Impl_Destroy(&(*object)->data.monitorable);
00227 if (NULL != (*object)->cpi)
00228 {
00229 GATRegistry_RemoveGATAdvertServiceFromCPIList((*object)->data.context,
00230 (*object)->cpi, *object);
00231 GATAdvertServiceCPI_DestroyInstance((*object)->cpi, &(*object)->data);
00232 }
00233 GATAdvertServiceCPIList_Destroy((*object)->cpilist);
00234 free(*object);
00235 *object = NULL;
00236 }
00237 }
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252 GATResult
00253 GATAdvertService_Equals(GATAdvertService_const lhs,
00254 GATAdvertService_const rhs, GATBool *isequal)
00255 {
00256 if (NULL != lhs && NULL != rhs)
00257 {
00258 GAT_STATUS_APIENTRY(lhs->data.context, "GATAdvertService_Equals");
00259 if (NULL != isequal)
00260 {
00261 GAT_CREATE_STATUS(GATString_Equals(lhs->data.pwd, rhs->data.pwd, isequal));
00262 if (GATTrue == *isequal)
00263 {
00264 GAT_CREATE_STATUS(GATAdvertServiceCPI_EqualsInstance(lhs->cpi,
00265 &lhs->data, &rhs->data, isequal));
00266 }
00267 }
00268 else
00269 {
00270 GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00271 }
00272 return GAT_RETURN_STATUS();
00273 }
00274 return GAT_INVALID_HANDLE;
00275 }
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 GATResult
00290 GATAdvertService_Clone(GATAdvertService_const handle,
00291 GATAdvertService *new_handle)
00292 {
00293 if (NULL != handle)
00294 {
00295 GAT_STATUS_APIENTRY(handle->data.context, "GATAdvertService_Clone");
00296
00297 if (NULL == new_handle)
00298 {
00299 GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00300 }
00301 else
00302 {
00303 struct GATAdvertService_S const *object = handle;
00304 GATAdvertService new_object =
00305 (GATAdvertService)malloc(sizeof(struct GATAdvertService_S));
00306
00307 *new_handle = NULL;
00308 if (NULL == new_object)
00309 {
00310 GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00311 }
00312 else
00313 {
00314 memset(new_object, 0, sizeof(struct GATAdvertService_S));
00315 new_object->GATObject__vtable = &GATAdvertService__vtable;
00316 new_object->GATMonitorable__vtable = &GATAdvertService_IMonitorable__vtable;
00317
00318 new_object->data.context = object->data.context;
00319 new_object->data.source = GATAdvertService_ToGATObject_const(new_object);
00320
00321 new_object->cpilist = GATRegistry_CloneGATAdvertServiceCPIList(
00322 object->cpilist);
00323 if (NULL == new_object->cpilist)
00324 {
00325 GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00326 }
00327 GAT_CREATE_STATUS(GATString_Clone(object->data.pwd,
00328 &new_object->data.pwd));
00329
00330 if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00331 {
00332
00333 GATAdvertServiceCPIList current = object->cpilist;
00334 GATAdvertServiceCPIList new_current = new_object->cpilist;
00335
00336 for (; NULL != current;
00337 current = current->next, new_current = new_current->next)
00338 {
00339 if (current->cpi == object->cpi)
00340 {
00341 new_object->cpi = new_current->cpi;
00342 break;
00343 }
00344 }
00345 assert(NULL != new_object->cpi);
00346
00347
00348 GAT_CREATE_STATUS(GATAdvertServiceCPI_CloneInstance(object->cpi,
00349 &object->data, &new_object->data));
00350
00351
00352 if (NULL != object->data.monitorable)
00353 {
00354 GAT_CREATE_STATUS(GATMonitorable_Impl_Clone(object->data.monitorable,
00355 &new_object->data.monitorable));
00356 }
00357
00358 GAT_CREATE_STATUS(GATRegistry_AddGATAdvertServiceToCPIList(
00359 new_object->data.context, new_object->cpi, new_object));
00360 }
00361
00362
00363 if (GAT_FAILED(GAT_CURRENT_STATUS()))
00364 {
00365 GATAdvertService_Destroy(&new_object);
00366 }
00367 else
00368 {
00369
00370 *new_handle = new_object;
00371 }
00372 }
00373 }
00374 return GAT_RETURN_STATUS();
00375 }
00376 return GAT_INVALID_HANDLE;
00377 }
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389 GATType
00390 GATAdvertService_GetType(GATAdvertService_const object)
00391 {
00392 GAT_UNUSED_PARAMETER(object);
00393 return GATType_GATAdvertService;
00394 }
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408 GATResult
00409 GATAdvertService_GetInterface(GATAdvertService_const object, GATInterface iftype,
00410 void const **ifp)
00411 {
00412 if (NULL != object)
00413 {
00414 GAT_STATUS_APIENTRY(object->data.context, "GATAdvertService_GetInterface");
00415
00416 if (NULL != ifp)
00417 {
00418 if (GATInterface_IMonitorable == iftype && NULL != object->data.monitorable)
00419 {
00420 *ifp = (void const *) &object->GATMonitorable__vtable;
00421 }
00422 else
00423 {
00424 ifp = NULL;
00425 GAT_CREATE_STATUS(GAT_NO_INTERFACE);
00426 }
00427 }
00428 else
00429 {
00430 GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00431 }
00432
00433 return GAT_RETURN_STATUS();
00434 }
00435 return GAT_INVALID_HANDLE;
00436 }
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460 GATResult
00461 GATAdvertService_AddMetricListener(GATAdvertService object,
00462 GATMetricListener listener, void *listener_data, GATMetric metric,
00463 GATuint32 *cookie)
00464 {
00465 if (NULL != object)
00466 {
00467 GAT_STATUS_APIENTRY(object->data.context, "GATAdvertService_AddMetricListener");
00468
00469 if (NULL != object->data.monitorable)
00470 {
00471 GAT_CREATE_STATUS(GATMonitorable_Impl_AddMetricListener(
00472 object->data.monitorable, listener, listener_data, metric, cookie));
00473 }
00474 else
00475 {
00476
00477 GAT_CREATE_STATUS(GAT_NO_INTERFACE);
00478 }
00479
00480 return GAT_RETURN_STATUS();
00481 }
00482 return GAT_INVALID_HANDLE;
00483 }
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502 GATResult
00503 GATAdvertService_RegisterPolling(GATAdvertService object, GATMetric metric,
00504 GATMetricEvent *event, GATuint32 *cookie)
00505 {
00506 GATResult retval = GAT_INVALID_HANDLE;
00507 if (NULL != object)
00508 {
00509 GAT_STATUS_APIENTRY(object->data.context, "GATAdvertService_RegisterPolling");
00510
00511 if (NULL != object->data.monitorable)
00512 {
00513 GAT_CREATE_STATUS(GATMonitorable_Impl_RegisterPolling(
00514 object->data.monitorable, metric, 0, cookie));
00515
00516
00517 GAT_CREATE_STATUS(GATAdvertServiceCPI_GetMetricEvent(object->cpi,
00518 &object->data, metric, event));
00519
00520 if (GAT_FAILED(GAT_CURRENT_STATUS()) && NULL != cookie && 0 != *cookie)
00521 {
00522 GATMonitorable_Impl_RemoveRegisteredMetric(object->data.monitorable,
00523 metric, *cookie);
00524 *cookie = 0;
00525 }
00526 }
00527 else
00528 {
00529
00530 GAT_CREATE_STATUS(GAT_NO_INTERFACE);
00531 }
00532
00533 return GAT_RETURN_STATUS();
00534 }
00535 return GAT_INVALID_HANDLE;
00536 }
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554 GATResult
00555 GATAdvertService_RemoveRegisteredMetric(GATAdvertService object,
00556 GATMetric metric, GATuint32 cookie)
00557 {
00558 if (NULL != object)
00559 {
00560 GAT_STATUS_APIENTRY(object->data.context, "GATAdvertService_RemoveRegisteredMetric");
00561
00562 if (NULL != object->data.monitorable)
00563 {
00564 GAT_CREATE_STATUS(GATMonitorable_Impl_RemoveRegisteredMetric(
00565 object->data.monitorable, metric, cookie));
00566 }
00567 else
00568 {
00569
00570 GAT_CREATE_STATUS(GAT_NO_INTERFACE);
00571 }
00572
00573 return GAT_RETURN_STATUS();
00574 }
00575 return GAT_INVALID_HANDLE;
00576 }
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590 GATResult
00591 GATAdvertService_GetMetrics(GATAdvertService_const object,
00592 GATList_GATMetric *metrics)
00593 {
00594 if (NULL != object)
00595 {
00596 GAT_STATUS_APIENTRY(object->data.context, "GATAdvertService_GetMetrics");
00597
00598 if (NULL != object->data.monitorable)
00599 {
00600 GAT_CREATE_STATUS(GATMonitorable_Impl_GetMetrics(
00601 object->data.monitorable, metrics));
00602 }
00603 else
00604 {
00605
00606 GAT_CREATE_STATUS(GAT_NO_INTERFACE);
00607 }
00608
00609 return GAT_RETURN_STATUS();
00610 }
00611 return GAT_INVALID_HANDLE;
00612 }
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634 GATResult
00635 GATAdvertService_Add(GATAdvertService object, GATObject_const advertisable,
00636 GATTable metadata, GATString_const path)
00637 {
00638 if (NULL != object)
00639 {
00640 GAT_STATUS_APIENTRY(object->data.context, "GATAdvertService_Add");
00641
00642 if (NULL != path)
00643 {
00644
00645
00646 char *name = GATAdvertService_ExtractName(path);
00647 char *resolved_path = NULL;
00648 struct utsname sysinfo;
00649 time_t curr_time = 0;
00650 char buffer[64];
00651 char *newline = NULL;
00652
00653 GAT_CREATE_STATUS_IF(NULL == name, GAT_MEMORYFAILURE);
00654 GAT_CREATE_STATUS(GATAdvertService_ResolvePath(object->data.pwd, path,
00655 &resolved_path));
00656
00657 GAT_CREATE_STATUS(GATAdvertService_EnsureMetaDataItem(object->data.context,
00658 "GAT_NAME", metadata, name));
00659 GAT_CREATE_STATUS(GATAdvertService_EnsureMetaDataItem(object->data.context,
00660 "GAT_PATH", metadata, resolved_path));
00661 GAT_CREATE_STATUS(GATAdvertService_EnsureMetaDataItem(object->data.context,
00662 "GAT_TYPE", metadata, GATType_GetName(GATObject_GetType(advertisable))));
00663
00664 GAT_CREATE_STATUS_IF(uname (&sysinfo) < 0, POSIX_TO_GAT(errno));
00665 GAT_CREATE_STATUS(GATAdvertService_EnsureMetaDataItem(object->data.context,
00666 "GAT_HOSTNAME", metadata, sysinfo.nodename));
00667
00668 curr_time = time(NULL);
00669 strcpy(buffer, asctime(gmtime(&curr_time)));
00670 newline = strchr(buffer, '\n');
00671
00672 if (NULL != newline)
00673 {
00674 *newline = '\0';
00675 }
00676 strcat(buffer, " GMT");
00677 GAT_CREATE_STATUS(GATAdvertService_EnsureMetaDataItem(object->data.context,
00678 "GAT_CREATIONTIME", metadata, buffer));
00679
00680 free(name);
00681 free(resolved_path);
00682
00683
00684 GAT_CREATE_STATUS(GATAdvertServiceCPI_Add(object->cpi, &object->data,
00685 advertisable, metadata, path));
00686 }
00687 else
00688 {
00689 GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00690 }
00691 return GAT_RETURN_STATUS();
00692 }
00693 return GAT_INVALID_HANDLE;
00694 }
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707 GATResult
00708 GATAdvertService_Delete(GATAdvertService object, GATString_const path)
00709 {
00710 if (NULL != object)
00711 {
00712 GAT_STATUS_APIENTRY(object->data.context, "");
00713
00714 GAT_CREATE_STATUS(GATAdvertServiceCPI_Delete(object->cpi, &object->data,
00715 path));
00716 return GAT_RETURN_STATUS();
00717 }
00718 return GAT_INVALID_HANDLE;
00719 }
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736 GATResult
00737 GATAdvertService_GetMetaData(GATAdvertService_const object,
00738 GATString_const path, GATTable *metadata)
00739 {
00740 if (NULL != object)
00741 {
00742 GAT_STATUS_APIENTRY(object->data.context, "GATAdvertService_GetMetaData");
00743 GAT_CREATE_STATUS(GATAdvertServiceCPI_GetMetaData(object->cpi,
00744 &object->data, path, metadata));
00745 return GAT_RETURN_STATUS();
00746 }
00747 return GAT_INVALID_HANDLE;
00748 }
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765 GATResult
00766 GATAdvertService_GetAdvertisable(GATAdvertService_const object,
00767 GATString_const path, GATObject *advertisable)
00768 {
00769 if (NULL != object)
00770 {
00771 GAT_STATUS_APIENTRY(object->data.context, "GATAdvertService_GetAdvertisable");
00772 GAT_CREATE_STATUS(GATAdvertServiceCPI_GetAdvertisable(object->cpi,
00773 &object->data, path, advertisable));
00774 return GAT_RETURN_STATUS();
00775 }
00776 return GAT_INVALID_HANDLE;
00777 }
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794 GATResult
00795 GATAdvertService_Find(GATAdvertService_const object, GATTable_const metadata,
00796 GATList_String *paths)
00797 {
00798 if (NULL != object)
00799 {
00800 GAT_STATUS_APIENTRY(object->data.context, "GATAdvertService_Find");
00801 GAT_CREATE_STATUS(GATAdvertServiceCPI_Find(object->cpi, &object->data,
00802 metadata, paths));
00803 return GAT_RETURN_STATUS();
00804 }
00805 return GAT_INVALID_HANDLE;
00806 }
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820 GATResult
00821 GATAdvertService_SetPWD(GATAdvertService object, GATString_const path)
00822 {
00823 if (NULL != object)
00824 {
00825 GAT_STATUS_APIENTRY(object->data.context, "GATAdvertService_SetPWD");
00826
00827 char const *pathstr = GATString_GetBuffer(path);
00828
00829 if (NULL != pathstr && '/' == pathstr[0])
00830 {
00831 GATString_Destroy(&object->data.pwd);
00832 GAT_CREATE_STATUS(GATString_Clone(path, &object->data.pwd));
00833 }
00834 else
00835 {
00836
00837 GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00838 }
00839
00840 return GAT_RETURN_STATUS();
00841 }
00842 return GAT_INVALID_HANDLE;
00843 }
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858 GATResult
00859 GATAdvertService_GetPWD(GATAdvertService object, GATString *path)
00860 {
00861 if (NULL != object)
00862 {
00863 GAT_STATUS_APIENTRY(object->data.context, "GATAdvertService_SetPWD");
00864 GAT_CREATE_STATUS(GATString_Clone(object->data.pwd, path));
00865 return GAT_RETURN_STATUS();
00866 }
00867 return GAT_INVALID_HANDLE;
00868 }
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883 static GATResult
00884 GATAdvertService_GetCPIInstanceData(GATAdvertService object, void **data)
00885 {
00886 if (NULL != object)
00887 {
00888 GAT_USES_STATUS(object->data.context, "GATAdvertService_GetCPIInstanceData");
00889
00890 if (NULL != data)
00891 {
00892 *data = (void *)&object->data;
00893 }
00894 else
00895 {
00896 GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00897 }
00898
00899 return GAT_RETURN_STATUS();
00900 }
00901 return GAT_INVALID_HANDLE;
00902 }
00903
00904
00905
00906
00907
00908
00909 static GATResult
00910 GATAdvertService_EnsureMetaDataItem(GATContext context, char const *item,
00911 GATTable metadata, char const *defaultvalue)
00912 {
00913 GAT_USES_STATUS(context, "GATAdvertService_EnsureMetaDataItem");
00914
00915 if (GAT_FAILED(GATTable_Get_String(metadata, item, 0, 0)))
00916 {
00917 GAT_CREATE_STATUS(GATTable_Add_String(metadata, item, defaultvalue));
00918 }
00919 return GAT_RETURN_STATUS();
00920 }
00921
00922
00923
00924
00925
00926 static char *
00927 GATAdvertService_ExtractName(GATString_const path)
00928 {
00929 char const *pathstr = GATString_GetBuffer(path);
00930 char *last_delim = strrchr(pathstr, '/');
00931 char *result = NULL;
00932
00933 if (NULL == last_delim)
00934 {
00935 result = GATUtil_strdup(pathstr);
00936 }
00937 else
00938 {
00939 result = GATUtil_strdup(last_delim+1);
00940 }
00941 return result;
00942 }
00943
00944
00945
00946
00947 static GATResult
00948 GATAdvertService_ResolvePath(
00949 GATString_const cwd, GATString_const path, char **absolute_path)
00950 {
00951 GATResult retval = GAT_INVALID_PARAMETER;
00952 char *new_path = NULL;
00953 char const *pwd = GATString_GetBuffer(cwd);
00954 char const *pathstr = GATString_GetBuffer(path);
00955
00956 if (NULL != pwd && NULL != pathstr)
00957 {
00958 int len = strlen(pwd);
00959 if (0 == len)
00960 {
00961 retval = GAT_INVALID_PARAMETER;
00962 }
00963 else if ('/' != pathstr[0])
00964 {
00965
00966 retval = GATUtil_appendstring(&new_path, pwd);
00967 if (GAT_SUCCEEDED(retval) && '/' != new_path[len-1])
00968 {
00969
00970 retval = GATUtil_appendstring(&new_path, "/");
00971 }
00972
00973 if (GAT_SUCCEEDED(retval))
00974 {
00975
00976 retval = GATUtil_appendstring(&new_path, pathstr);
00977 }
00978 }
00979 else
00980 {
00981
00982 new_path = GATUtil_strdup(pathstr);
00983 if (NULL == new_path)
00984 {
00985 retval = GAT_MEMORYFAILURE;
00986 }
00987 else
00988 {
00989 retval = GAT_SUCCESS;
00990 }
00991 }
00992
00993
00994 if (GAT_SUCCEEDED(retval))
00995 {
00996 if (NULL != absolute_path)
00997 {
00998 *absolute_path = new_path;
00999 }
01000 else
01001 {
01002 retval = GAT_INVALID_PARAMETER;
01003 }
01004 }
01005 if (GAT_FAILED(retval))
01006 {
01007 free(new_path);
01008 }
01009 }
01010 return retval;
01011 }