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 /**
20 * Remove an entry from a service group
21 * @ingroup wssg
22 * Destroys a service group entry resource which is a member of the service
23 * group named by @a service_group_epr. If the entry exists and is a member
24 * of the group, it is destroyed and the service group removal callback is
25 * invoked.
26 *
27 * @param service_group_epr
28 * Reference to the service group which owns the entry to be removed.
29 * @param entry_epr
30 * Reference to the entry to removed.
31 *
32 * @retval GLOBUS_SUCCESS
33 * @retval #GLOBUS_SERVICE_GROUP_ERROR_TYPE_NULL_PARAMETER
34 * @retval #GLOBUS_SERVICE_GROUP_ERROR_TYPE_OUT_OF_MEMORY
35 * @retval #GLOBUS_SERVICE_GROUP_ERROR_TYPE_UNKNOWN
36 *
37 * @note
38 * Calling globus_resource_destroy() on the resource associated with
39 * @a entry_epr is quite similar to this function, but doesn't check that
40 * the entry is associated with the service group.
41 */
42 globus_result_t
43 globus_service_group_remove(
44 const wsa_EndpointReferenceType * service_group_epr,
45 const wsa_EndpointReferenceType * entry_epr)
46 147 {
47 globus_resource_t resource;
48 147 globus_result_t result = GLOBUS_SUCCESS;
49 globus_wsrf_service_group_t sg;
50 globus_wsrf_service_group_entry_t entry;
51 char * service_group_id;
52 char * entry_id;
53 GlobusFuncName(globus_service_group_remove);
54
55 147 GlobusServiceGroupDebugEnter();
56
57 147 result = globus_wsrf_core_get_resource_id_from_epr(
58 service_group_epr,
59 &service_group_id);
60
61 147 if (result != GLOBUS_SUCCESS)
62 {
63 0 result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY();
64
65 0 goto out;
66 }
67
68 147 result = globus_wsrf_core_get_resource_id_from_epr(
69 entry_epr,
70 &entry_id);
71
72 147 if (result != GLOBUS_SUCCESS)
73 {
74 0 result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY();
75
76 0 goto free_service_group_id_out;
77 }
78 147 GlobusServiceGroupGlobalLock();
79 147 sg = globus_hashtable_lookup(
80 &globus_i_service_groups,
81 service_group_id);
82 147 if (sg == NULL)
83 {
84 75 result = GLOBUS_SERVICE_GROUP_UNKNOWN();
85 75 GlobusServiceGroupGlobalUnlock();
86
87 75 goto free_entry_id_out;
88 }
89
90 72 GlobusServiceGroupLock(sg);
91 72 GlobusServiceGroupGlobalUnlock();
92
93 72 entry = globus_hashtable_remove(&sg->entries, entry_id);
94
95 72 if (entry != NULL && sg->remove_callback != NULL)
96 {
97 0 sg->remove_callback(sg->callback_arg, entry->entry);
98 }
99
100 72 if (entry == NULL)
101 {
102 33 result = GLOBUS_SERVICE_GROUP_UNKNOWN();
103
104 33 goto unlock_out;
105 }
106
107 39 globus_i_service_group_entry_destroy(entry);
108
109 39 result = globus_resource_find(entry_id, &resource);
110
111 39 if (result == GLOBUS_SUCCESS)
112 {
113 33 GlobusServiceGroupUnlock(sg);
114 33 globus_resource_destroy(resource);
115 }
116 else
117 {
118 39 unlock_out:
119 39 GlobusServiceGroupUnlock(sg);
120 }
121 147 free_entry_id_out:
122 147 free(entry_id);
123 147 free_service_group_id_out:
124 147 free(service_group_id);
125 147 out:
126 147 GlobusServiceGroupDebugExit();
127 147 return result;
128 }