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 49 {
47 49     globus_resource_t                   resource;
48 49     globus_result_t                     result = GLOBUS_SUCCESS;
49 49     globus_wsrf_service_group_t         sg;
50 49     globus_wsrf_service_group_entry_t   entry;
51 49     char *                              service_group_id;
52 49     char *                              entry_id;
53 49     GlobusFuncName(globus_service_group_remove);
54
55 49     GlobusServiceGroupDebugEnter();
56
57 49     result = globus_wsrf_core_get_resource_id_from_epr(
58             service_group_epr,
59             &service_group_id);
60
61 49     if (result != GLOBUS_SUCCESS)
62     {
63 0         result = GLOBUS_SERVICE_GROUP_OUT_OF_MEMORY();
64
65 0         goto out;
66     }
67
68 49     result = globus_wsrf_core_get_resource_id_from_epr(
69             entry_epr,
70             &entry_id);
71
72 49     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 49     GlobusServiceGroupGlobalLock();
79 49     sg = globus_hashtable_lookup(
80                 &globus_i_service_groups,
81                 service_group_id);
82 49     if (sg == NULL)
83     {
84 25         result = GLOBUS_SERVICE_GROUP_UNKNOWN();
85 25         GlobusServiceGroupGlobalUnlock();
86
87 25         goto free_entry_id_out;
88     }
89
90 24     GlobusServiceGroupLock(sg);
91 24     GlobusServiceGroupGlobalUnlock();
92
93 24     entry = globus_hashtable_remove(&sg->entries, entry_id);
94
95 24     if (entry != NULL && sg->remove_callback != NULL)
96     {
97 0         sg->remove_callback(sg->callback_arg, entry->entry);
98     }
99
100 24     if (entry == NULL)
101     {
102 11         result = GLOBUS_SERVICE_GROUP_UNKNOWN();
103
104 11         goto unlock_out;
105     }
106
107 13     globus_i_service_group_entry_destroy(entry);
108
109 13     result = globus_resource_find(entry_id, &resource);
110
111 13     if (result == GLOBUS_SUCCESS)
112     {
113 11         GlobusServiceGroupUnlock(sg);
114 11         globus_resource_destroy(resource);
115     }
116     else
117     {
118 unlock_out:
119 13         GlobusServiceGroupUnlock(sg);
120     }
121 free_entry_id_out:
122 49     free(entry_id);
123 free_service_group_id_out:
124 49     free(service_group_id);
125 out:
126 49     GlobusServiceGroupDebugExit();
127 49     return result;
128 }