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