| 1 | /* | |
| 2 | * Copyright 1999-2006 University of Chicago | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | ||
| 17 | #include "globus_i_wsrf_service_group.h" | |
| 18 | ||
| 19 | #include "globus_xml_buffer.h" | |
| 20 | ||
| 21 | #include "wssg_EntryType.h" | |
| 22 | #include "wssg_Entry.h" | |
| 23 | ||
| 24 | #include "wssg_ServiceGroupEPR.h" | |
| 25 | #include "wssg_MemberEPR.h" | |
| 26 | #include "wssg_Content.h" | |
| 27 | ||
| 28 | #ifndef GLOBUS_DONT_DOCUMENT_INTERNAL | |
| 29 | /** | |
| 30 | * Structure containing information about how to access a service group | |
| 31 | * entry and its containing group. | |
| 32 | * | |
| 33 | */ | |
| 34 | typedef struct | |
| 35 | { | |
| 36 | wsa_EndpointReferenceType service_group_epr; | |
| 37 | wsa_EndpointReferenceType entry_epr; | |
| 38 | char * service_path; | |
| 39 | } | |
| 40 | globus_service_group_entry_info_t; | |
| 41 | ||
| 42 | static | |
| 43 | globus_result_t | |
| 44 | globus_l_service_group_entry_create_epr( | |
| 45 | const wsa_AttributedURIType * entry_uri, | |
| 46 | const char * resource_id, | |
| 47 | wsa_EndpointReferenceType ** sge_epr_res); | |
| 48 | ||
| 49 | static | |
| 50 | globus_result_t | |
| 51 | globus_l_service_group_create_entry( | |
| 52 | globus_wsrf_service_group_entry_t * entry, | |
| 53 | const char * resource_id, | |
| 54 | const wsa_EndpointReferenceType * entry_epr, | |
| 55 | const wsa_EndpointReferenceType * service_epr, | |
| 56 | const wssg_ContentType * content); | |
| 57 | ||
| 58 | static | |
| 59 | globus_result_t | |
| 60 | globus_l_service_group_entry_create_resource( | |
| 61 | const char * resource_id, | |
| 62 | const wsa_EndpointReferenceType * group_epr, | |
| 63 | const wsa_EndpointReferenceType * member_epr, | |
| 64 | const wsa_EndpointReferenceType * entry_epr, | |
| 65 | const wssg_ContentType * content, | |
| 66 | const xsd_dateTime * initial_termination_time); | |
| 67 | ||
| 68 | static | |
| 69 | char * | |
| 70 | globus_l_epr_to_path( | |
| 71 | const wsa_EndpointReferenceType * epr); | |
| 72 | ||
| 73 | static | |
| 74 | time_t | |
| 75 | globus_l_timegm( | |
| 76 | const struct tm * tm); | |
| 77 | ||
| 78 | static | |
| 79 | void | |
| 80 | globus_l_service_group_entry_destructor( | |
| 81 | void * p); | |
| 82 | ||
| 83 | static | |
| 84 | globus_result_t | |
| 85 | globus_l_service_group_check_membership( | |
| 86 | globus_wsrf_service_group_t sg, | |
| 87 | const wsa_EndpointReferenceType * service_epr, | |
| 88 | const wssg_ContentType * content); | |
| 89 | ||
| 90 | #define WSSG_NAMESPACE \ | |
| 91 | "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ServiceGroup-1.2-draft-01.xsd" | |
| 92 | ||
| 93 | #endif | |
| 94 | ||
| 95 | /** | |
| 96 | * Add a service entry to a service group | |
| 97 | * @ingroup wssg | |
| 98 | * | |
| 99 | * Creates a new entry in a service group. This new entry will be created if the | |
| 100 | * @a content element matches the membership content rule used to create the | |
| 101 | * service group. The EPR to contact the new entry will be returned in the | |
| 102 | * @a new_service_group_entry_epr parameter. The providers associated with the | |
| 103 | * entry service (selected at service group creation time) will be initialized | |
| 104 | * when the entry is created. | |
| 105 | * | |
| 106 | * @param service_group_epr | |
| 107 | * EPR of the service group to add the new entry to. | |
| 108 | * @param service_epr | |
| 109 | * EPR of the service to add to the group. | |
| 110 | * @param content | |
| 111 | * Content value to be associated with @a service_epr in the service group | |
| 112 | * entry resource. The element used for the content must match the | |
| 113 | * membership content rule of the service. | |
| 114 | * @param initial_termination_time | |
| 115 | * Optional initial termination time of the entry. If this is NULL, then | |
| 116 | * the entry will last until either explicitly destroyed or until the group | |
| 117 | * is destroyed. | |
| 118 | * @param new_service_group_entry_epr | |
| 119 | * Pointer to be set to contain EPR of the new service group entry. This | |
| 120 | * EPR must be freed by the caller by calling | |
| 121 | * wsa_EndpointReferenceType_destroy(). | |
| 122 | * | |
| 123 | * @retval GLOBUS_SUCCESS | |
| 124 | * @retval #GLOBUS_SERVICE_GROUP_ERROR_TYPE_NULL_PARAMETER | |
| 125 | * @retval #GLOBUS_SERVICE_GROUP_ERROR_TYPE_OUT_OF_MEMORY | |
| 126 | * @retval #GLOBUS_SERVICE_GROUP_ERROR_TYPE_UNKNOWN | |
| 127 | * @retval #GLOBUS_SERVICE_GROUP_ERROR_TYPE_INVALID_CONTENT | |
| 128 | */ | |
| 129 | globus_result_t | |
| 130 | globus_service_group_add( | |
| 131 | const wsa_EndpointReferenceType * service_group_epr, | |
| 132 | const wsa_EndpointReferenceType * service_epr, | |
| 133 | const wssg_ContentType * content, | |
| 134 | const xsd_dateTime * initial_termination_time, | |
| 135 | wsa_EndpointReferenceType ** new_service_group_entry_epr) | |
| 136 | 141 | { |
| 137 | globus_wsrf_service_group_t sg; | |
| 138 | globus_wsrf_service_group_entry_t sge; | |
| 139 | wsa_EndpointReferenceType * sge_epr; | |
| 140 | globus_result_t result; | |
| 141 | int rc; | |
| 142 | globus_uuid_t uuid; | |
| 143 | GlobusFuncName(globus_service_group_add); | |
| 144 | ||
| 145 | 141 | GlobusServiceGroupDebugEnter(); |
| 146 | ||
| 147 | 141 | if (service_group_epr == NULL || |
| 148 | new_service_group_entry_epr == NULL || | |
| 149 | service_epr == NULL) | |
| 150 | { | |
| 151 | 9 | result = GLOBUS_SERVICE_GROUP_NULL_PARAMETER(); |
| 152 | ||
| 153 | 9 | goto out; |
| 154 | } | |
| 155 | ||
| 156 | 132 | *new_service_group_entry_epr = NULL; |
| 157 | ||
| 158 | /* If successful, sg is locked */ | |
| 159 | 132 | result = globus_i_service_group_lookup( |
| 160 | service_group_epr, | |
| 161 | &sg); | |
| 162 | ||
| 163 | 132 | if (result != GLOBUS_SUCCESS) |
| 164 | { | |
| 165 | 3 | goto out; |
| 166 | } | |
| 167 | ||
| 168 | 129 | result = globus_l_service_group_check_membership( |
| 169 | sg, | |
| 170 | service_epr, | |
| 171 | content); | |
| 172 | 129 | if (result != GLOBUS_SUCCESS) |
| 173 | { | |
| 174 | 6 | goto unlock_sg_out; |
| 175 | } | |
| 176 | ||
| 177 | /* Create UUID to be used for the Reference Properties of the EPR | |
| 178 | * and the resource_id used by core | |
| 179 | */ | |
| 180 | 123 | rc = globus_uuid_create(&uuid); |
| 181 | 123 | if (rc != GLOBUS_SUCCESS) |
| 182 | { | |
| 183 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 184 | 0 | goto unlock_sg_out; |
| 185 | } | |
| 186 | ||
| 187 | /* Create an EPR to the ServiceGroupEntry resource we will create below */ | |
| 188 | 123 | result = globus_l_service_group_entry_create_epr( |
| 189 | &sg->service_group_entry_uri, | |
| 190 | &uuid.text[0], | |
| 191 | &sge_epr); | |
| 192 | ||
| 193 | 123 | if (result != GLOBUS_SUCCESS) |
| 194 | { | |
| 195 | 0 | goto unlock_sg_out; |
| 196 | } | |
| 197 | ||
| 198 | /* Create entry which we will stick into the entries hash for the group | |
| 199 | * This will contain the information needed for the wssg:Entry property | |
| 200 | * of the ServiceGroup resource. | |
| 201 | */ | |
| 202 | 123 | result = globus_l_service_group_create_entry( |
| 203 | &sge, | |
| 204 | &uuid.text[0], | |
| 205 | sge_epr, | |
| 206 | service_epr, | |
| 207 | content); | |
| 208 | 123 | if (result != GLOBUS_SUCCESS) |
| 209 | { | |
| 210 | 0 | goto destroy_sge_epr_out; |
| 211 | } | |
| 212 | ||
| 213 | 123 | rc = globus_hashtable_insert( |
| 214 | &sg->entries, | |
| 215 | sge->resource_id, | |
| 216 | sge); | |
| 217 | ||
| 218 | 123 | if (rc != GLOBUS_SUCCESS) |
| 219 | { | |
| 220 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 221 | ||
| 222 | 0 | goto destroy_sge_out; |
| 223 | } | |
| 224 | ||
| 225 | /* Now create the resource associated with the ServiceGroupEntry. | |
| 226 | */ | |
| 227 | 123 | result = globus_l_service_group_entry_create_resource( |
| 228 | &uuid.text[0], | |
| 229 | &sg->service_group_epr, | |
| 230 | sge->entry->MemberServiceEPR, | |
| 231 | sge_epr, | |
| 232 | content, | |
| 233 | initial_termination_time); | |
| 234 | ||
| 235 | 123 | if (sge->entry && sg->add_callback != NULL) |
| 236 | { | |
| 237 | 9 | sg->add_callback(sg->callback_arg, sge->entry); |
| 238 | } | |
| 239 | ||
| 240 | 123 | if (result == GLOBUS_SUCCESS) |
| 241 | { | |
| 242 | 123 | *new_service_group_entry_epr = sge_epr; |
| 243 | } | |
| 244 | ||
| 245 | /* cleanup if an error occurred */ | |
| 246 | 123 | if (result != GLOBUS_SUCCESS) |
| 247 | { | |
| 248 | 0 | globus_hashtable_remove( |
| 249 | &sg->entries, | |
| 250 | sge->resource_id); | |
| 251 | ||
| 252 | 0 | destroy_sge_out: |
| 253 | 0 | free(sge->resource_id); |
| 254 | 0 | wssg_EntryType_destroy(sge->entry); |
| 255 | 0 | free(sge); |
| 256 | ||
| 257 | 0 | destroy_sge_epr_out: |
| 258 | 0 | wsa_EndpointReferenceType_destroy(sge_epr); |
| 259 | } | |
| 260 | ||
| 261 | 129 | unlock_sg_out: |
| 262 | 129 | GlobusServiceGroupUnlock(sg); |
| 263 | ||
| 264 | 141 | out: |
| 265 | 141 | GlobusServiceGroupDebugExit(); |
| 266 | 141 | return result; |
| 267 | } | |
| 268 | /* globus_service_group_add() */ | |
| 269 | ||
| 270 | #ifndef GLOBUS_DONT_DOCUMENT_INTERNAL | |
| 271 | /** | |
| 272 | * Create an endpoint reference to a new service group entry. | |
| 273 | * | |
| 274 | * @param entry_uri | |
| 275 | * @param resource_id | |
| 276 | * @param sge_epr_res | |
| 277 | */ | |
| 278 | static | |
| 279 | globus_result_t | |
| 280 | globus_l_service_group_entry_create_epr( | |
| 281 | const wsa_AttributedURIType * entry_uri, | |
| 282 | const char * resource_id, | |
| 283 | wsa_EndpointReferenceType ** sge_epr_res) | |
| 284 | 123 | { |
| 285 | 123 | wsa_EndpointReferenceType * sge_epr = NULL; |
| 286 | 123 | xsd_any * refprop = NULL; |
| 287 | globus_result_t result; | |
| 288 | GlobusFuncName(globus_l_service_group_entry_create_epr); | |
| 289 | ||
| 290 | 123 | GlobusServiceGroupDebugEnter(); |
| 291 | 123 | *sge_epr_res = NULL; |
| 292 | ||
| 293 | 123 | result = wsa_EndpointReferenceType_init(&sge_epr); |
| 294 | 123 | if (result != GLOBUS_SUCCESS) |
| 295 | { | |
| 296 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 297 | ||
| 298 | 0 | goto out; |
| 299 | } | |
| 300 | 123 | sge_epr->Address.base_value = globus_libc_strdup( |
| 301 | entry_uri->base_value); | |
| 302 | 123 | if (sge_epr->Address.base_value == NULL) |
| 303 | { | |
| 304 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 305 | ||
| 306 | 0 | goto destroy_sge_epr_out; |
| 307 | } | |
| 308 | ||
| 309 | 123 | result = wsa_ReferenceParametersType_init( |
| 310 | &sge_epr->ReferenceParameters); | |
| 311 | 123 | if (result != GLOBUS_SUCCESS) |
| 312 | { | |
| 313 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 314 | ||
| 315 | 0 | goto destroy_sge_epr_out; |
| 316 | } | |
| 317 | ||
| 318 | 123 | refprop = xsd_any_array_push(&sge_epr->ReferenceParameters->any); |
| 319 | ||
| 320 | 123 | if (refprop == NULL) |
| 321 | { | |
| 322 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 323 | ||
| 324 | 0 | goto destroy_sge_epr_out; |
| 325 | } | |
| 326 | 123 | refprop->any_info = &xsd_string_info; |
| 327 | 123 | result = xsd_string_init_cstr( |
| 328 | (xsd_string **) &refprop->value, | |
| 329 | globus_libc_strdup(resource_id)); | |
| 330 | 123 | if (result != GLOBUS_SUCCESS) |
| 331 | { | |
| 332 | 0 | goto destroy_sge_epr_out; |
| 333 | } | |
| 334 | 123 | result = xsd_QName_init(&refprop->element); |
| 335 | ||
| 336 | 123 | if (result != GLOBUS_SUCCESS) |
| 337 | { | |
| 338 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 339 | ||
| 340 | 0 | goto destroy_sge_epr_out; |
| 341 | } | |
| 342 | 123 | refprop->element->Namespace = globus_libc_strdup(WSSG_NAMESPACE); |
| 343 | 123 | if (refprop->element->Namespace == GLOBUS_NULL) |
| 344 | { | |
| 345 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 346 | ||
| 347 | 0 | goto destroy_sge_epr_out; |
| 348 | } | |
| 349 | 123 | refprop->element->local = globus_libc_strdup("EntryID"); |
| 350 | 123 | if (refprop->element->local == GLOBUS_NULL) |
| 351 | { | |
| 352 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 353 | ||
| 354 | 0 | goto destroy_sge_epr_out; |
| 355 | } | |
| 356 | ||
| 357 | 123 | *sge_epr_res = sge_epr; |
| 358 | ||
| 359 | 123 | destroy_sge_epr_out: |
| 360 | 123 | if (result != GLOBUS_SUCCESS) |
| 361 | { | |
| 362 | 0 | wsa_EndpointReferenceType_destroy(sge_epr); |
| 363 | } | |
| 364 | 123 | out: |
| 365 | ||
| 366 | 123 | GlobusServiceGroupDebugExit(); |
| 367 | 123 | return result; |
| 368 | } | |
| 369 | /* globus_l_service_group_entry_create_epr() */ | |
| 370 | ||
| 371 | ||
| 372 | static | |
| 373 | globus_result_t | |
| 374 | globus_l_service_group_create_entry( | |
| 375 | globus_wsrf_service_group_entry_t * entry, | |
| 376 | const char * resource_id, | |
| 377 | const wsa_EndpointReferenceType * entry_epr, | |
| 378 | const wsa_EndpointReferenceType * service_epr, | |
| 379 | const wssg_ContentType * content) | |
| 380 | 123 | { |
| 381 | globus_wsrf_service_group_entry_t sge; | |
| 382 | globus_result_t result; | |
| 383 | GlobusFuncName(globus_l_service_group_create_entry); | |
| 384 | ||
| 385 | 123 | GlobusServiceGroupDebugEnter(); |
| 386 | 123 | *entry = NULL; |
| 387 | ||
| 388 | /* Create the entry struct we will put in the hash for the service group */ | |
| 389 | 123 | sge = malloc(sizeof(globus_i_wsrf_service_group_entry_t)); |
| 390 | ||
| 391 | 123 | if (sge == NULL) |
| 392 | { | |
| 393 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 394 | ||
| 395 | 0 | goto out; |
| 396 | } | |
| 397 | 123 | result = wssg_EntryType_init(&sge->entry); |
| 398 | ||
| 399 | 123 | if (result != GLOBUS_SUCCESS) |
| 400 | { | |
| 401 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 402 | ||
| 403 | 0 | goto free_sge_out; |
| 404 | } | |
| 405 | ||
| 406 | 123 | sge->entry->ServiceGroupEntryEPR = NULL; |
| 407 | 123 | result = wsa_EndpointReferenceType_copy( |
| 408 | &sge->entry->ServiceGroupEntryEPR, | |
| 409 | entry_epr); | |
| 410 | ||
| 411 | 123 | if (result != GLOBUS_SUCCESS) |
| 412 | { | |
| 413 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 414 | ||
| 415 | 0 | goto destroy_entry_out; |
| 416 | } | |
| 417 | 123 | result = wsa_EndpointReferenceType_copy( |
| 418 | &sge->entry->MemberServiceEPR, | |
| 419 | service_epr); | |
| 420 | 123 | if (result != GLOBUS_SUCCESS) |
| 421 | { | |
| 422 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 423 | ||
| 424 | 0 | goto destroy_entry_out; |
| 425 | } | |
| 426 | ||
| 427 | /* Instead of copying the Content element here, we'll do it when | |
| 428 | * the entries list is requested via | |
| 429 | * globus_wsrf_service_group_get_entries(). The only version of the | |
| 430 | * data in memory will be in the service group entry's resource list | |
| 431 | */ | |
| 432 | ||
| 433 | 123 | sge->resource_id = globus_libc_strdup(resource_id); |
| 434 | 123 | if (sge->resource_id == NULL) |
| 435 | { | |
| 436 | 0 | goto destroy_entry_out; |
| 437 | } | |
| 438 | ||
| 439 | 123 | *entry = sge; |
| 440 | ||
| 441 | 123 | if (result != GLOBUS_SUCCESS) |
| 442 | { | |
| 443 | 0 | destroy_entry_out: |
| 444 | 0 | wssg_EntryType_destroy((*entry)->entry); |
| 445 | 0 | free_sge_out: |
| 446 | 0 | free(sge); |
| 447 | } | |
| 448 | 123 | out: |
| 449 | 123 | GlobusServiceGroupDebugExit(); |
| 450 | 123 | return result; |
| 451 | } | |
| 452 | /* globus_l_service_group_create_entry() */ | |
| 453 | ||
| 454 | static | |
| 455 | globus_result_t | |
| 456 | globus_l_service_group_entry_create_resource( | |
| 457 | const char * resource_id, | |
| 458 | const wsa_EndpointReferenceType * group_epr, | |
| 459 | const wsa_EndpointReferenceType * member_epr, | |
| 460 | const wsa_EndpointReferenceType * entry_epr, | |
| 461 | const wssg_ContentType * content, | |
| 462 | const xsd_dateTime * initial_termination_time) | |
| 463 | 123 | { |
| 464 | globus_resource_t resource; | |
| 465 | globus_result_t result; | |
| 466 | wsa_EndpointReferenceType * tmp_epr; | |
| 467 | wssg_ContentType * tmp_content; | |
| 468 | globus_extension_handle_t ext; | |
| 469 | globus_service_descriptor_t * service_desc; | |
| 470 | globus_service_group_entry_info_t * info; | |
| 471 | int rc; | |
| 472 | GlobusFuncName(globus_l_service_group_entry_create_resource); | |
| 473 | ||
| 474 | 123 | GlobusServiceGroupDebugEnter(); |
| 475 | 123 | result = globus_resource_create(resource_id, &resource); |
| 476 | 123 | if (result != GLOBUS_SUCCESS) |
| 477 | { | |
| 478 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 479 | ||
| 480 | 0 | goto out; |
| 481 | } | |
| 482 | ||
| 483 | 123 | info = calloc(1, sizeof(globus_service_group_entry_info_t)); |
| 484 | 123 | if (info == NULL) |
| 485 | { | |
| 486 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 487 | ||
| 488 | 0 | goto destroy_resource_out; |
| 489 | } | |
| 490 | ||
| 491 | /* This is a little bit of a hack. What this key is used for is to | |
| 492 | * have a function called when the SGE resource is destroyed. When that | |
| 493 | * occurs, the function will try to remove the entry from the containing | |
| 494 | * group if possible. | |
| 495 | */ | |
| 496 | 123 | result = globus_resource_set_resource_specific_by_key( |
| 497 | resource, | |
| 498 | "wssg:DestructionInfo", | |
| 499 | info, | |
| 500 | globus_l_service_group_entry_destructor); | |
| 501 | ||
| 502 | 123 | if (result != GLOBUS_SUCCESS) |
| 503 | { | |
| 504 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 505 | ||
| 506 | 0 | free(info); |
| 507 | ||
| 508 | 0 | goto destroy_resource_out; |
| 509 | } | |
| 510 | ||
| 511 | 123 | result = wsa_EndpointReferenceType_copy_contents( |
| 512 | &info->entry_epr, | |
| 513 | entry_epr); | |
| 514 | 123 | if (result != GLOBUS_SUCCESS) |
| 515 | { | |
| 516 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 517 | ||
| 518 | 0 | goto destroy_resource_out; |
| 519 | } | |
| 520 | ||
| 521 | 123 | result = wsa_EndpointReferenceType_copy_contents( |
| 522 | &info->service_group_epr, | |
| 523 | group_epr); | |
| 524 | 123 | if (result != GLOBUS_SUCCESS) |
| 525 | { | |
| 526 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 527 | ||
| 528 | 0 | goto destroy_resource_out; |
| 529 | } | |
| 530 | ||
| 531 | /* InitialTerminationTime maps to resource lifetime. The wsrl provider | |
| 532 | * will create appropriate RPs when we initialize it below. | |
| 533 | */ | |
| 534 | 123 | if (initial_termination_time != NULL) |
| 535 | { | |
| 536 | globus_abstime_t timeout; | |
| 537 | ||
| 538 | 6 | timeout.tv_sec = globus_l_timegm(initial_termination_time); |
| 539 | 6 | timeout.tv_nsec = 0; |
| 540 | ||
| 541 | 6 | result = globus_resource_set_destroy_time( |
| 542 | resource, | |
| 543 | &timeout); | |
| 544 | ||
| 545 | 6 | if (result != GLOBUS_SUCCESS) |
| 546 | { | |
| 547 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 548 | ||
| 549 | 0 | goto destroy_resource_out; |
| 550 | } | |
| 551 | } | |
| 552 | ||
| 553 | /* Initialize ResourceProperties with values passed to us */ | |
| 554 | /* ServiceGroupEPR: Contains a reference to the ServiceGroup this | |
| 555 | * entry is a member of. | |
| 556 | */ | |
| 557 | 123 | result = wsa_EndpointReferenceType_copy( |
| 558 | &tmp_epr, | |
| 559 | group_epr); | |
| 560 | ||
| 561 | 123 | if (result != GLOBUS_SUCCESS) |
| 562 | { | |
| 563 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 564 | ||
| 565 | 0 | goto destroy_resource_out; |
| 566 | } | |
| 567 | ||
| 568 | 123 | result = globus_resource_create_property( |
| 569 | resource, | |
| 570 | &wssg_ServiceGroupEPR_qname, | |
| 571 | &wsa_EndpointReferenceType_info, | |
| 572 | tmp_epr); | |
| 573 | ||
| 574 | 123 | if (result != GLOBUS_SUCCESS) |
| 575 | { | |
| 576 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 577 | ||
| 578 | 0 | wsa_EndpointReferenceType_destroy(tmp_epr); |
| 579 | ||
| 580 | 0 | goto destroy_resource_out; |
| 581 | } | |
| 582 | ||
| 583 | /* | |
| 584 | * MemberEPR: Contains a reference to the member to which this entry | |
| 585 | * pertains. | |
| 586 | */ | |
| 587 | 123 | result = wsa_EndpointReferenceType_copy( |
| 588 | &tmp_epr, | |
| 589 | member_epr); | |
| 590 | ||
| 591 | 123 | if (result != GLOBUS_SUCCESS) |
| 592 | { | |
| 593 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 594 | ||
| 595 | 0 | goto destroy_resource_out; |
| 596 | } | |
| 597 | 123 | result = globus_resource_create_property( |
| 598 | resource, | |
| 599 | &wssg_MemberEPR_qname, | |
| 600 | &wsa_EndpointReferenceType_info, | |
| 601 | tmp_epr); | |
| 602 | 123 | if (result != GLOBUS_SUCCESS) |
| 603 | { | |
| 604 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 605 | ||
| 606 | 0 | wsa_EndpointReferenceType_destroy(tmp_epr); |
| 607 | ||
| 608 | 0 | goto destroy_resource_out; |
| 609 | } | |
| 610 | ||
| 611 | /* | |
| 612 | * Content: information pertaining to the group membership. | |
| 613 | */ | |
| 614 | 123 | result = wssg_ContentType_copy( |
| 615 | &tmp_content, | |
| 616 | content); | |
| 617 | ||
| 618 | 123 | if (result != GLOBUS_SUCCESS) |
| 619 | { | |
| 620 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 621 | ||
| 622 | 0 | goto destroy_resource_out; |
| 623 | } | |
| 624 | ||
| 625 | 123 | result = globus_resource_create_property( |
| 626 | resource, | |
| 627 | &wssg_Content_qname, | |
| 628 | &wssg_ContentType_info, | |
| 629 | tmp_content); | |
| 630 | 123 | if (result != GLOBUS_SUCCESS) |
| 631 | { | |
| 632 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 633 | ||
| 634 | 0 | wssg_ContentType_destroy(tmp_content); |
| 635 | } | |
| 636 | 123 | info->service_path = globus_l_epr_to_path(entry_epr); |
| 637 | ||
| 638 | 123 | if (info->service_path == NULL) |
| 639 | { | |
| 640 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 641 | ||
| 642 | 0 | goto destroy_resource_out; |
| 643 | } | |
| 644 | ||
| 645 | 123 | rc = globus_extension_activate(info->service_path); |
| 646 | 123 | if (rc != GLOBUS_SUCCESS) |
| 647 | { | |
| 648 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 649 | ||
| 650 | 0 | goto free_service_path_out; |
| 651 | } | |
| 652 | ||
| 653 | /* Initialize resource providers for the service group entry */ | |
| 654 | 123 | service_desc = globus_extension_lookup( |
| 655 | &ext, | |
| 656 | GLOBUS_SERVICE_REGISTRY, | |
| 657 | info->service_path); | |
| 658 | ||
| 659 | 123 | if (service_desc == NULL) |
| 660 | { | |
| 661 | 0 | result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 662 | ||
| 663 | 0 | goto deactivate_extension_out; |
| 664 | } | |
| 665 | ||
| 666 | 123 | result = globus_operation_table_init_resource( |
| 667 | service_desc->operations, | |
| 668 | entry_epr); | |
| 669 | ||
| 670 | if (result != GLOBUS_SUCCESS) | |
| 671 | { | |
| 672 | 123 | goto release_service_desc_out; |
| 673 | } | |
| 674 | ||
| 675 | 123 | release_service_desc_out: |
| 676 | 123 | globus_extension_release(ext); |
| 677 | ||
| 678 | 123 | if (result != GLOBUS_SUCCESS) |
| 679 | { | |
| 680 | 0 | deactivate_extension_out: |
| 681 | 0 | globus_extension_deactivate(info->service_path); |
| 682 | 0 | free_service_path_out: |
| 683 | 0 | free(info->service_path); |
| 684 | 0 | info->service_path = NULL; |
| 685 | } | |
| 686 | ||
| 687 | 123 | destroy_resource_out: |
| 688 | 123 | if (result == GLOBUS_SUCCESS) |
| 689 | { | |
| 690 | 123 | globus_resource_finish(resource); |
| 691 | } | |
| 692 | else | |
| 693 | { | |
| 694 | 0 | globus_resource_destroy(resource); |
| 695 | } | |
| 696 | ||
| 697 | 123 | out: |
| 698 | 123 | GlobusServiceGroupDebugExit(); |
| 699 | 123 | return result; |
| 700 | } | |
| 701 | /* globus_l_service_group_entry_create_resource() */ | |
| 702 | ||
| 703 | /** | |
| 704 | * Determine the path to the local service module from an EPR. | |
| 705 | * | |
| 706 | * @param epr | |
| 707 | * Endpoint Reference to a service deployed in this container. | |
| 708 | * | |
| 709 | * @return | |
| 710 | * This function returns the local path to the service module for | |
| 711 | * the service named by the EPR. This will be NULL if the EPR does | |
| 712 | * not contain a path. | |
| 713 | * | |
| 714 | * @note There is no checking that the path is valid. | |
| 715 | */ | |
| 716 | static | |
| 717 | char * | |
| 718 | globus_l_epr_to_path( | |
| 719 | const wsa_EndpointReferenceType * epr) | |
| 720 | 123 | { |
| 721 | const char * tmp; | |
| 722 | globus_url_t url; | |
| 723 | char * path; | |
| 724 | int rc; | |
| 725 | GlobusFuncName(globus_l_epr_to_path); | |
| 726 | ||
| 727 | 123 | GlobusServiceGroupDebugEnter(); |
| 728 | 123 | rc = globus_url_parse(epr->Address.base_value, &url); |
| 729 | ||
| 730 | 123 | if (rc != GLOBUS_SUCCESS) |
| 731 | { | |
| 732 | 0 | return NULL; |
| 733 | } | |
| 734 | ||
| 735 | 123 | tmp = url.url_path; |
| 736 | 369 | while(*tmp == '/') |
| 737 | { | |
| 738 | 123 | tmp++; |
| 739 | } | |
| 740 | ||
| 741 | 123 | path = globus_common_create_string( |
| 742 | "%s/%s", | |
| 743 | GLOBUS_SERVICE_ENGINE_MODULE_PATH_PREFIX, | |
| 744 | tmp); | |
| 745 | ||
| 746 | 123 | globus_url_destroy(&url); |
| 747 | ||
| 748 | 123 | GlobusServiceGroupDebugExit(); |
| 749 | 123 | return path; |
| 750 | } | |
| 751 | /* globus_l_epr_to_path() */ | |
| 752 | ||
| 753 | static | |
| 754 | time_t | |
| 755 | globus_l_timegm( | |
| 756 | const struct tm * tm) | |
| 757 | 6 | { |
| 758 | time_t ret; | |
| 759 | char *tz; | |
| 760 | GlobusFuncName(globus_l_timegm); | |
| 761 | ||
| 762 | 6 | GlobusServiceGroupDebugEnter(); |
| 763 | 6 | tz = getenv("TZ"); |
| 764 | 6 | globus_libc_setenv("TZ", "", 1); |
| 765 | 6 | tzset(); |
| 766 | 6 | ret = mktime((struct tm *) tm); |
| 767 | 6 | if (tz) |
| 768 | 6 | globus_libc_setenv("TZ", tz, 1); |
| 769 | else | |
| 770 | 0 | globus_libc_unsetenv("TZ"); |
| 771 | 6 | tzset(); |
| 772 | ||
| 773 | 6 | GlobusServiceGroupDebugExit(); |
| 774 | 6 | return ret; |
| 775 | } | |
| 776 | /* globus_l_timegm() */ | |
| 777 | ||
| 778 | /* | |
| 779 | * This function is called when the resource associated with the service group | |
| 780 | * entry is destroyed. This can happen either when the service group is | |
| 781 | * destroyed, the entry is explicitly removed, the entry dies because of | |
| 782 | * scheduled termination, or the service group module is destroyed. | |
| 783 | */ | |
| 784 | static | |
| 785 | void | |
| 786 | globus_l_service_group_entry_destructor( | |
| 787 | void * p) | |
| 788 | 114 | { |
| 789 | 114 | globus_service_group_entry_info_t * info = p; |
| 790 | ||
| 791 | GlobusFuncName(globus_l_service_group_entry_destructor); | |
| 792 | ||
| 793 | 114 | GlobusServiceGroupDebugEnter(); |
| 794 | 114 | GlobusServiceGroupDebugPrintf(GLOBUS_L_SERVICE_GROUP_DEBUG_DEBUG, |
| 795 | ("Destroying sge %p\n", p)); | |
| 796 | ||
| 797 | 114 | if (info->service_group_epr.Address.base_value != NULL && |
| 798 | info->entry_epr.Address.base_value != NULL) | |
| 799 | { | |
| 800 | 114 | globus_service_group_remove( |
| 801 | &info->service_group_epr, | |
| 802 | &info->entry_epr); | |
| 803 | } | |
| 804 | ||
| 805 | 114 | GlobusServiceGroupDebugPrintf(GLOBUS_L_SERVICE_GROUP_DEBUG_DEBUG, |
| 806 | ("Freeing sge data %p\n", p)); | |
| 807 | 114 | wsa_EndpointReferenceType_destroy_contents(&info->service_group_epr); |
| 808 | 114 | wsa_EndpointReferenceType_destroy_contents(&info->entry_epr); |
| 809 | 114 | globus_extension_deactivate(info->service_path); |
| 810 | 114 | free(info->service_path); |
| 811 | 114 | free(info); |
| 812 | ||
| 813 | 114 | GlobusServiceGroupDebugExit(); |
| 814 | 114 | } |
| 815 | /* globus_l_service_group_entry_destructor() */ | |
| 816 | ||
| 817 | static | |
| 818 | globus_result_t | |
| 819 | globus_l_service_group_check_membership( | |
| 820 | globus_wsrf_service_group_t sg, | |
| 821 | const wsa_EndpointReferenceType * service_epr, | |
| 822 | const wssg_ContentType * content) | |
| 823 | 129 | { |
| 824 | int i, j; | |
| 825 | xsd_QName_array * elements; | |
| 826 | xsd_any tmp; | |
| 827 | globus_result_t result; | |
| 828 | GlobusFuncName(globus_l_service_group_check_membership); | |
| 829 | ||
| 830 | 129 | GlobusServiceGroupDebugEnter(); |
| 831 | ||
| 832 | 129 | result = xsd_any_init_contents(&tmp); |
| 833 | ||
| 834 | 129 | elements = &sg->membership_content_rule->_ContentElements; |
| 835 | ||
| 836 | 129 | if (result != GLOBUS_SUCCESS) |
| 837 | { | |
| 838 | 0 | return GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY(); |
| 839 | } | |
| 840 | ||
| 841 | 129 | if (sg->membership_content_rule == NULL) |
| 842 | { | |
| 843 | 0 | GlobusServiceGroupDebugExit(); |
| 844 | 0 | return GLOBUS_SUCCESS; |
| 845 | } | |
| 846 | 129 | else if (content == NULL) |
| 847 | { | |
| 848 | 3 | GlobusServiceGroupDebugExit(); |
| 849 | 3 | return GLOBUS_SERVICE_GROUP_NULL_PARAMETER(); |
| 850 | } | |
| 851 | ||
| 852 | 129 | for (i = 0; i < content->any.length; i++) |
| 853 | { | |
| 854 | 129 | for (j = 0; j < elements->length; j++) |
| 855 | { | |
| 856 | 126 | if (xsd_QName_keyeq(content->any.elements[i].element, |
| 857 | &elements->elements[j])) | |
| 858 | { | |
| 859 | 123 | GlobusServiceGroupDebugExit(); |
| 860 | 123 | return GLOBUS_SUCCESS; |
| 861 | } | |
| 862 | } | |
| 863 | } | |
| 864 | ||
| 865 | 3 | xsd_any_destroy_contents(&tmp); |
| 866 | ||
| 867 | 3 | GlobusServiceGroupDebugExit(); |
| 868 | 3 | return GLOBUS_SERVICE_GROUP_INVALID_CONTENT(); |
| 869 | } | |
| 870 | /* globus_l_service_group_check_membership() */ |