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
18 #include "globus_i_soap_client.h"
19
20 /**
21  * Initialize a SOAP client handle.
22  * @ingroup globus_soap_client
23  *
24  * Creates a new instance of a SOAP client handle. This must be called
25  * before calling any other functions in this API with a handle.
26  *
27  * @param handle
28  *     SOAP client handle to initialize.
29  * @param attrs
30  *     Default message attributes.
31  * @param chain
32  *     Default handler chain.
33  *
34  * @retval GLOBUS_SUCCESS
35  *     Handle initialized successfully.
36  * @retval GLOBUS_SOAP_MESSAGE_ERROR_TYPE_OUT_OF_MEMORY
37  *     Insufficient memory to allocate the handle.
38  */
39 globus_result_t
40 globus_soap_client_handle_init(
41     globus_soap_client_handle_t *       handle,
42     globus_soap_message_attr_t          attrs,
43     globus_handler_chain_t              chain)
44 123 {
45 123     globus_soap_client_handle_t         client_handle;
46 123     globus_result_t                     result = GLOBUS_SUCCESS;
47 123     GlobusFuncName(globus_soap_client_init);
48 123     GlobusSoapMessageDebugEnter();
49         
50 123     client_handle = calloc(1, sizeof(struct globus_i_soap_client_handle_s));
51 123     globus_assert_string(client_handle, "Memory allocation failed");
52
53 123     if(chain)
54     {
55 123         result = globus_handler_chain_copy(
56             &client_handle->handler_chain, chain);
57 123         if(result != GLOBUS_SUCCESS)
58         {
59 0             goto error;
60         }
61     }
62
63 123     if(attrs)
64     {
65 55         globus_soap_message_attr_copy(
66             &client_handle->attrs, attrs);
67     }
68     else
69     {
70 68         globus_soap_message_attr_init(&client_handle->attrs);
71     }
72
73 123     globus_mutex_init(&client_handle->mutex, NULL);
74 123     globus_cond_init(&client_handle->cond, NULL);
75
76 123     client_handle->request.client_handle = client_handle;
77 123     client_handle->response.client_handle = client_handle;
78
79 123     *handle = client_handle;
80
81 123     GlobusSoapMessageDebugExit();
82 123     return result;
83     
84 error:
85 0     globus_free(client_handle);
86 0     GlobusSoapMessageDebugExit();
87 0     return result;
88 }
89 /* globus_soap_client_handle_init() */
90
91 /**
92  * Destroy a SOAP client handle.
93  * @ingroup globus_soap_client
94  *
95  * Destroys an instance of a SOAP client handle. After calling this
96  * function, no further API functions can be used with this handle.
97  * This function should not be called until all request and response
98  * operations for this handle are complete.
99  *
100  * @param handle
101  *     SOAP client handle to destroy.
102  */
103 void
104 globus_soap_client_handle_destroy(
105     globus_soap_client_handle_t         handle)
106 107 {
107 107     if(handle)
108     {
109 107         if(handle->handler_chain)
110         {
111 107             globus_handler_chain_destroy(handle->handler_chain);
112         }
113
114 107         if(handle->attrs)
115         {
116 107             globus_soap_message_attr_destroy(handle->attrs);
117         }
118
119 107         if(handle->message)
120         {
121 20             globus_soap_message_handle_destroy(handle->message);
122         }
123
124 107         globus_i_soap_client_request_handle_destroy(&handle->request);
125
126 107         globus_mutex_destroy(&handle->mutex);
127 107         globus_cond_destroy(&handle->cond);
128
129 107         free(handle);
130     }
131 }
132 /* globus_soap_client_handle_destroy() */
133
134 /**
135  * Cancel a SOAP client operation
136  * @ingroup globus_soap_client
137  *
138  * Attempts to cancel a SOAP client operation. This will cause any
139  * in-progress request or response operations to be cancelled as soon
140  * as possible. The callback for the operation will be called once the
141  * cancel has been completely handled.
142  *
143  * @param handle
144  *     Active SOAP client handle to cancel the current operation on.
145  */
146 globus_result_t
147 globus_soap_client_operation_cancel(
148     globus_soap_client_handle_t         handle)
149 0 {
150 0     globus_result_t result = GLOBUS_SUCCESS;
151 0     GlobusFuncName(globus_soap_client_message_cancel);
152 0     GlobusSoapMessageDebugEnter();
153
154 0     if(handle->message)
155     {
156 0         result = globus_soap_message_cancel_message(handle->message);
157     }
158
159 0     return result;
160 }
161 /* globus_soap_client_operation_cancel() */
162     
163 /**
164  * Obtain the current handler chain for a SOAP client handle.
165  * @ingroup globus_soap_client
166  *
167  * Returns the current handler chain value for a SOAP client handle.
168  * The caller may then push additional handlers onto the chain. The
169  * chain must not be modified in this way while any operations (request or
170  * response) are active on this SOAP handle.
171  *
172  * @param handle
173  *     SOAP client handle to query.
174  * @param handlers
175  *     Pointer to be set to the current value of the handler chain. This
176  *     may be set to NULL if the default chain is not initialized.
177  */
178 globus_result_t
179 globus_soap_client_handle_get_handler_chain(
180     globus_soap_client_handle_t         handle,
181     globus_handler_chain_t *            handlers)
182 0 {
183 0     globus_result_t                     result = GLOBUS_SUCCESS;
184 0     GlobusFuncName(globus_soap_client_get_handle_chain);
185 0     GlobusSoapMessageDebugEnter();
186
187 0     *handlers = handle->handler_chain;
188     
189 0     GlobusSoapMessageDebugExit();
190 0     return result;
191 }
192 /* globus_soap_client_handle_get_handler_chain() */
193
194 /**
195  * Set the value of a SOAP message attribute on a client handle.
196  * @ingroup globus_soap_client
197  *
198  * Sets the value of the named SOAP message attribute. The old value
199  * (if any) will be destroyed if the attribute previously had a destroy
200  * function associated with it.
201  * This function must not be called while any operations (request
202  * or response) are active on this SOAP handle.
203  *
204  * @param handle
205  *     SOAP client handle to query.
206  * @param prop_name
207  *     Name of the attribute to set.
208  * @param copy
209  *     Function to copy the value of the property. If this is NULL, then 
210  *     the attribute will be set to the value of the @a value parameter
211  *     and the caller may not modify @a value until the handle is destroyed.
212  *     Otherwise, this function will be called during this function call
213  *     and @a value may be modified once this function returns.
214  * @param destroy
215  *     Function to destroy the value of the property. 
216  *     If this is non-NULL, this function will be called when the attribute
217  *     is set to a new value or when the attribute is destroyed. This must
218  *     be non-NULL if @a copy is non-NULL.
219  * @param value
220  *     New value of the attribute named by @a prop_name.
221  *
222  * @retval GLOBUS_SUCCESS
223  *     Attribute set successfully.
224  * @retval GLOBUS_SOAP_MESSAGE_ERROR_TYPE_OUT_OF_MEMORY
225  *     Insufficient memory to set the attribute.
226  */
227 globus_result_t
228 globus_soap_client_handle_attr_set(
229     globus_soap_client_handle_t         handle,
230     const char *                        prop_name,
231     globus_soap_message_attr_copy_func_t
232                                         copy,
233     globus_soap_message_attr_destroy_func_t
234                                         destroy,
235     void *                              value)
236 3619 {
237 3619     return globus_soap_message_attr_set(
238         handle->attrs,
239         prop_name,
240         copy,
241         destroy,
242         value);
243 }
244 /* globus_soap_client_handle_attr_set() */
245
246 /**
247  * Remove a SOAP message attribute from a client handle.
248  * @ingroup globus_soap_client
249  *
250  * Removes an attribute from the SOAP client handle. Its previous value
251  * (if it is defined) will be returned from this function.  This function must
252  * not be called while any operations (request or response) are active on this
253  * SOAP handle.
254  *
255  * @param handle
256  *     SOAP client handle to modify.
257  * @param prop_name
258  *     Name of the attribute to remove.
259  *
260  * @return
261  *     This function returns the value of the attribute if it was set, or
262  *     NULL otherwise.
263  */
264 void *
265 globus_soap_client_handle_attr_remove(
266     globus_soap_client_handle_t         handle,
267     const char *                        prop_name)
268 0 {
269 0     return globus_soap_message_attr_remove(
270         handle->attrs,
271         prop_name);
272 }
273 /* globus_soap_client_handle_attr_remove() */
274
275 /**
276  * Get the value of a SOAP message attribute from a client handle.
277  * @ingroup globus_soap_client
278  *
279  * Returns the value of the named SOAP attribute associated with the client
280  * handle. This value must not be modified by the caller.
281  *
282  * @param handle
283  *     SOAP client handle to query.
284  * @param prop_name
285  *     Name of the attribute to query.
286  *
287  * @return
288  *     This function returns the value of the attribute if it was set, or
289  *     NULL otherwise.
290  */
291 void *
292 globus_soap_client_handle_attr_get(
293     globus_soap_client_handle_t         handle,
294     const char *                        prop_name)
295 0 {
296 0     return globus_soap_message_attr_get(
297         handle->attrs,
298         prop_name);
299 }