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_service_engine.h"
18
19 /**
20 * Get a list of contacts for all engines running in this process.
21 * @ingroup globus_service_engine
22 *
23 * Allocates an array of xsd_anyURIs which will be set to contain the
24 * contact strings for all service engines running in this process. The
25 * variable pointed to by @a contacts_length will be set to the length of
26 * this array. It is the responsibility of the caller to free the @a contacts
27 * array. If there are no engines running in this process, @a contacts
28 * will be set to NULL and @a contacts_length will be set to 0.
29 *
30 *
31 * @param contacts
32 * Pointer to an array which will be allocated to contain the list of
33 * contacts.
34 * @param contacts_length
35 * Pointer to a variable which will hold the length of the @a contacts
36 * array.
37 *
38 * @retval GLOBUS_SUCCESS
39 * Contacts list successfully created.
40 * @retval GLOBUS_SOAP_MESSAGE_ERROR_TYPE_NULL_PARAM
41 * One of @a contacts or @a contacts_length is NULL.
42 * @retval GLOBUS_SERVICE_ENGINE_ERROR_TYPE_OUT_OF_MEMORY
43 * Insufficient memory to copy contacts list.
44 */
45 globus_result_t
46 globus_service_get_engine_contacts(
47 xsd_anyURI ** contacts,
48 globus_size_t * contacts_length)
49 0 {
50 0 globus_result_t result = GLOBUS_SUCCESS;
51 globus_size_t num_engines;
52 globus_list_t * tmp;
53 globus_service_engine_t tmp_engine;
54 0 xsd_anyURI * contact_array = NULL;
55 0 int i = 0;
56
57 0 if (contacts == NULL || contacts_length == NULL)
58 {
59 0 result = GlobusSoapMessageErrorNullParam;
60
61 0 goto out;
62 }
63 0 GlobusServiceEngineExtensionLock();
64
65 0 num_engines = globus_list_size(globus_i_service_engine_instances);
66 0 if (num_engines == 0)
67 {
68 0 goto unlock_out;
69 }
70 0 contact_array = calloc(num_engines, sizeof(xsd_anyURI));
71
72 0 if (contact_array == NULL)
73 {
74 0 result = GlobusServiceEngineErrorOutOfMemory;
75
76 0 goto unlock_out;
77 }
78
79 0 tmp = globus_i_service_engine_instances;
80 0 while (!globus_list_empty(tmp))
81 {
82 0 tmp_engine = globus_list_first(tmp);
83
84 0 contact_array[i] = globus_libc_strdup(tmp_engine->contact);
85
86 0 if (contact_array[i] == NULL)
87 {
88 0 result = GlobusServiceEngineErrorOutOfMemory;
89
90 0 for (i--; i >= 0; i--)
91 {
92 0 free(contact_array[i]);
93 }
94
95 0 free(contact_array);
96
97 0 contact_array = NULL;
98 0 i = 0;
99
100 0 goto unlock_out;
101 }
102
103 0 i++;
104
105 0 tmp = globus_list_rest(tmp);
106 }
107
108 0 unlock_out:
109 0 GlobusServiceEngineExtensionUnlock();
110
111 0 *contacts = contact_array;
112 0 *contacts_length = i;
113
114 0 out:
115 0 return GLOBUS_SUCCESS;
116 }