| 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_wsrf_options.h" | |
| 18 | #include "globus_wsrf_core_tools.h" | |
| 19 | #include "globus_i_wsrf_options.h" | |
| 20 | ||
| 21 | /** | |
| 22 | * Initialize a WSRF options parsing handle | |
| 23 | * @ingroup globus_wsrf_options | |
| 24 | * | |
| 25 | * Creates a new handle which will contain state from parsing the command line | |
| 26 | * options of a program. The handle should be added to a globus_options_handle_t | |
| 27 | * table by calling globus_wsrf_options_handle_add_to_table() before calling | |
| 28 | * globus_options_command_line_process(). The a list of ptions which the handle | |
| 29 | * processes is located \ref globus_wsrf_options_options "here". | |
| 30 | * | |
| 31 | * @param handle | |
| 32 | * Handle to be initialized. | |
| 33 | * @param application_name | |
| 34 | * Name of application (for --help message) | |
| 35 | * @param application_version | |
| 36 | * Version information about the application (for --version and --versions) | |
| 37 | * @param usage | |
| 38 | * Short usage to be printed when --usage or --help are used. The application | |
| 39 | * name will be prepended to the usage string. | |
| 40 | * @param post_help_banner | |
| 41 | * Additional information to be printed after the option list when --help is | |
| 42 | * used. | |
| 43 | * | |
| 44 | * @retval GLOBUS_SUCCESS | |
| 45 | * Handle initialized | |
| 46 | * @retval GLOBUS_SOAP_MESSAGE_ERROR_TYPE_NULL_PARAM | |
| 47 | * Unable to initialize handle---null parameter. | |
| 48 | * @retval GLOBUS_SOAP_MESSAGE_ERROR_TYPE_OUT_OF_MEMORY | |
| 49 | * Unable to initialize handle---malloc failed. | |
| 50 | * | |
| 51 | * @see globus_wsrf_options_handle_destroy() | |
| 52 | */ | |
| 53 | extern | |
| 54 | globus_result_t | |
| 55 | globus_wsrf_options_handle_init( | |
| 56 | globus_wsrf_options_handle_t * handle, | |
| 57 | const char * application_name, | |
| 58 | globus_version_t * application_version, | |
| 59 | const char * usage, | |
| 60 | const char * post_help_banner) | |
| 61 | 114 | { |
| 62 | 114 | globus_result_t result = GLOBUS_SUCCESS; |
| 63 | globus_i_wsrf_options_handle_t * new_handle; | |
| 64 | GlobusFuncName(globus_wsrf_options_handle_init); | |
| 65 | ||
| 66 | 114 | if (handle == NULL) |
| 67 | { | |
| 68 | 0 | result = GlobusSoapMessageErrorNullParam; |
| 69 | ||
| 70 | 0 | goto out; |
| 71 | } | |
| 72 | ||
| 73 | 114 | new_handle = malloc(sizeof(globus_i_wsrf_options_handle_t)); |
| 74 | ||
| 75 | 114 | if (new_handle == NULL) |
| 76 | { | |
| 77 | 0 | result = GlobusSoapMessageErrorOutOfMemory; |
| 78 | 0 | goto out; |
| 79 | } | |
| 80 | 114 | new_handle->application_name = application_name; |
| 81 | 114 | new_handle->application_version = application_version; |
| 82 | 114 | new_handle->epr = NULL; |
| 83 | 114 | new_handle->debug = GLOBUS_FALSE; |
| 84 | 114 | new_handle->usage = usage; |
| 85 | 114 | new_handle->post_banner = post_help_banner; |
| 86 | ||
| 87 | 114 | result = globus_soap_message_attr_init(&new_handle->attr); |
| 88 | ||
| 89 | 114 | if (result != GLOBUS_SUCCESS) |
| 90 | { | |
| 91 | 0 | free(new_handle); |
| 92 | 0 | new_handle = NULL; |
| 93 | } | |
| 94 | 114 | *handle = new_handle; |
| 95 | 114 | out: |
| 96 | 114 | return result; |
| 97 | } | |
| 98 | /* globus_wsrf_options_handle_init() */ | |
| 99 | ||
| 100 | /** | |
| 101 | * Free a WSRF options parsing handle | |
| 102 | * @ingroup globus_wsrf_options | |
| 103 | * | |
| 104 | * Free memory associated with a globus_wsrf_options_handle_t. | |
| 105 | * | |
| 106 | * @param handle | |
| 107 | * Handle to be freed. | |
| 108 | * | |
| 109 | * @return void | |
| 110 | */ | |
| 111 | extern | |
| 112 | void | |
| 113 | globus_wsrf_options_handle_destroy( | |
| 114 | globus_wsrf_options_handle_t handle) | |
| 115 | 114 | { |
| 116 | 114 | if (handle) |
| 117 | { | |
| 118 | 114 | globus_soap_message_attr_destroy(handle->attr); |
| 119 | 114 | free(handle); |
| 120 | } | |
| 121 | 114 | } |
| 122 | /* globus_wsrf_options_handle_destroy() */ | |
| 123 | ||
| 124 | /** | |
| 125 | * Get the service EPR specified on the command line. | |
| 126 | * @ingroup globus_wsrf_options | |
| 127 | * | |
| 128 | * After processing command line options, this function will return an | |
| 129 | * EPR either constructed from the -s and -k options or read from an epr file | |
| 130 | * specified by the -e option. | |
| 131 | * | |
| 132 | * @param handle | |
| 133 | * Handle to query. | |
| 134 | * @param epr | |
| 135 | * Pointer to an EndpointReferenceType which will be set to | |
| 136 | * contain the new parsed value. Caller must free the contents of this | |
| 137 | * EPr. | |
| 138 | * | |
| 139 | * @retval GLOBUS_SUCCESS | |
| 140 | * EPR located. | |
| 141 | * @retval GLOBUS_SOAP_MESSAGE_ERROR_TYPE_NULL_PARAM | |
| 142 | * Unable to query handle---null parameter. | |
| 143 | * @retval GLOBUS_SOAP_MESSAGE_ERROR_TYPE_OUT_OF_MEMORY | |
| 144 | * Unable to query handle---malloc failed. | |
| 145 | * | |
| 146 | */ | |
| 147 | extern | |
| 148 | globus_result_t | |
| 149 | globus_wsrf_options_handle_get_epr( | |
| 150 | globus_wsrf_options_handle_t handle, | |
| 151 | wsa_EndpointReferenceType * epr) | |
| 152 | 114 | { |
| 153 | 114 | globus_result_t result = GLOBUS_SUCCESS; |
| 154 | GlobusFuncName(globus_wsrf_options_handle_get_epr); | |
| 155 | 114 | if (handle == NULL || epr == NULL || handle->epr == NULL) |
| 156 | { | |
| 157 | 0 | result = GlobusSoapMessageErrorNullParam; |
| 158 | 0 | goto out; |
| 159 | } | |
| 160 | 114 | result = wsa_EndpointReferenceType_init_contents(epr); |
| 161 | 114 | if (result != GLOBUS_SUCCESS) |
| 162 | { | |
| 163 | 0 | goto out; |
| 164 | } | |
| 165 | 114 | result = wsa_EndpointReferenceType_copy_contents(epr, handle->epr); |
| 166 | 114 | if (result != GLOBUS_SUCCESS) |
| 167 | { | |
| 168 | 0 | wsa_EndpointReferenceType_destroy_contents(epr); |
| 169 | } | |
| 170 | 114 | out: |
| 171 | 114 | return result; |
| 172 | } | |
| 173 | /* globus_wsrf_options_handle_get_epr() */ | |
| 174 | ||
| 175 | /** | |
| 176 | * Get the debug option. | |
| 177 | * @ingroup globus_wsrf_options | |
| 178 | * | |
| 179 | * After processing command line options, this function will return the | |
| 180 | * debug flag value if it was passed on the command line via -d. | |
| 181 | * | |
| 182 | * @param handle | |
| 183 | * Handle to query. | |
| 184 | * @param debug | |
| 185 | * Pointer to a globus_bool_t which will be set to GLOBUS_TRUE if the debug | |
| 186 | * option was passed on the command line, GLOBUS_FALSE otherwise. | |
| 187 | * | |
| 188 | * @retval GLOBUS_SUCCESS | |
| 189 | * EPR located. | |
| 190 | * @retval GLOBUS_SOAP_MESSAGE_ERROR_TYPE_NULL_PARAM | |
| 191 | * Unable to query handle---null parameter. | |
| 192 | * @retval GLOBUS_SOAP_MESSAGE_ERROR_TYPE_OUT_OF_MEMORY | |
| 193 | * Unable to query handle---malloc failed. | |
| 194 | */ | |
| 195 | extern | |
| 196 | globus_result_t | |
| 197 | globus_wsrf_options_handle_get_debug( | |
| 198 | globus_wsrf_options_handle_t handle, | |
| 199 | globus_bool_t * debug) | |
| 200 | 60 | { |
| 201 | 60 | globus_result_t result = GLOBUS_SUCCESS; |
| 202 | GlobusFuncName(globus_wsrf_options_handle_get_debug); | |
| 203 | ||
| 204 | 60 | if (handle == NULL || debug == NULL) |
| 205 | { | |
| 206 | 0 | result = GlobusSoapMessageErrorNullParam; |
| 207 | } | |
| 208 | else | |
| 209 | { | |
| 210 | 60 | *debug = handle->debug; |
| 211 | } | |
| 212 | ||
| 213 | 60 | return result; |
| 214 | } | |
| 215 | /* globus_wsrf_options_handle_get_debug() */ | |
| 216 | ||
| 217 | /** | |
| 218 | * Get the SOAP message attrs set by command line options. | |
| 219 | * @ingroup globus_wsrf_options | |
| 220 | * | |
| 221 | * After processing command line options, this function will return a SOAP | |
| 222 | * message attribute constructed from various command line options. This attribute | |
| 223 | * will contain security credentials, other security configuration, and | |
| 224 | * communications settings. | |
| 225 | * | |
| 226 | * @param handle | |
| 227 | * Handle to query. | |
| 228 | * @param attr | |
| 229 | * Pointer to a globus_soap_message_attr_t which will be set to a copy | |
| 230 | * of the attributes which were set by the command-line option processing. | |
| 231 | * Caller must destroy this attribute set. | |
| 232 | * | |
| 233 | * @retval GLOBUS_SUCCESS | |
| 234 | * Attr copied. | |
| 235 | * @retval GLOBUS_SOAP_MESSAGE_ERROR_TYPE_NULL_PARAM | |
| 236 | * Unable to copy attr---null parameter. | |
| 237 | * @retval GLOBUS_SOAP_MESSAGE_ERROR_TYPE_OUT_OF_MEMORY | |
| 238 | * Unable to copy attr---malloc failed. | |
| 239 | */ | |
| 240 | extern | |
| 241 | globus_result_t | |
| 242 | globus_wsrf_options_handle_get_attr( | |
| 243 | globus_wsrf_options_handle_t handle, | |
| 244 | globus_soap_message_attr_t * attr) | |
| 245 | 114 | { |
| 246 | 114 | globus_result_t result = GLOBUS_SUCCESS; |
| 247 | GlobusFuncName(globus_wsrf_options_handle_get_attr); | |
| 248 | ||
| 249 | 114 | if (handle == NULL || attr == NULL) |
| 250 | { | |
| 251 | 0 | result = GlobusSoapMessageErrorNullParam; |
| 252 | } | |
| 253 | else | |
| 254 | { | |
| 255 | 114 | result = globus_soap_message_attr_copy(attr, handle->attr); |
| 256 | } | |
| 257 | 114 | return result; |
| 258 | } | |
| 259 | /* globus_wsrf_options_handle_get_attr() */ | |
| 260 | ||
| 261 | /** | |
| 262 | * Add wsrf common arg parsing options to an options handle | |
| 263 | * @ingroup globus_wsrf_options | |
| 264 | * | |
| 265 | * Configures a globus_options handle to process the SOAP client-related | |
| 266 | * options. | |
| 267 | * | |
| 268 | * @param handle | |
| 269 | * WSRF common options handle to add to wsrf table. | |
| 270 | * @param options_handle | |
| 271 | * Options processing handle. | |
| 272 | * | |
| 273 | * @retval GLOBUS_SUCCESS | |
| 274 | * Options configured. | |
| 275 | * @retval GLOBUS_SOAP_MESSAGE_ERROR_TYPE_NULL_PARAM | |
| 276 | * Unable to set up options---null parameter. | |
| 277 | * @retval GLOBUS_SOAP_MESSAGE_ERROR_TYPE_OUT_OF_MEMORY | |
| 278 | * Unable to set up options---malloc failed. | |
| 279 | */ | |
| 280 | extern | |
| 281 | globus_result_t | |
| 282 | globus_wsrf_options_handle_add_to_table( | |
| 283 | globus_wsrf_options_handle_t handle, | |
| 284 | globus_options_handle_t options_handle) | |
| 285 | 114 | { |
| 286 | 114 | globus_result_t result = GLOBUS_SUCCESS; |
| 287 | GlobusFuncName(globus_wsrf_options_handle_add_to_table); | |
| 288 | ||
| 289 | 114 | if (handle == NULL || options_handle == NULL) |
| 290 | { | |
| 291 | 0 | result = GlobusSoapMessageErrorNullParam; |
| 292 | } | |
| 293 | else | |
| 294 | { | |
| 295 | 114 | result = globus_options_add_table( |
| 296 | options_handle, | |
| 297 | globus_i_wsrf_common_options_table, | |
| 298 | handle); | |
| 299 | } | |
| 300 | 114 | return result; |
| 301 | } |