00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027
00028 #ifdef HAVE_STRING_H
00029 #include <string.h>
00030 #endif
00031
00032 #include <libxml/tree.h>
00033 #include <libxml/uri.h>
00034
00035 #include <nanohttp/nanohttp-error.h>
00036 #include <nanohttp/nanohttp-logging.h>
00037
00038 #include "soap-fault.h"
00039 #include "soap-env.h"
00040 #include "soap-ctx.h"
00041 #include "soap-addressing.h"
00042 #include "soap-service.h"
00043 #include "soap-router.h"
00044 #include "soap-transport.h"
00045 #ifdef HAVE_XMLSEC1
00046 #include "soap-xmlsec.h"
00047 #endif
00048 #include "soap-client.h"
00049
00050 #ifdef HAVE_XMLSEC1
00051 static int _soap_client_force_sign = 0;
00052 static int _soap_client_force_verify = 0;
00053 static int _soap_client_force_encrypt = 0;
00054 static int _soap_client_force_decrypt = 0;
00055
00056 static inline void
00057 _soap_client_parse_arguments(int argc, char **argv)
00058 {
00059 int i;
00060
00061 for (i=0; i<argc; i++)
00062 {
00063 if (!strcmp(CSOAP_CLIENT_FORCE_ENCRYPT, argv[i]))
00064 {
00065 _soap_client_force_encrypt = 1;
00066 }
00067 else if (!strcmp(CSOAP_CLIENT_FORCE_DECRYPT, argv[i]))
00068 {
00069 _soap_client_force_decrypt = 1;
00070 }
00071 else if (!strcmp(CSOAP_CLIENT_FORCE_VERIFY, argv[i]))
00072 {
00073 _soap_client_force_verify = 1;
00074 }
00075 else if (!strcmp(CSOAP_CLIENT_FORCE_SIGN, argv[i]))
00076 {
00077 _soap_client_force_sign = 1;
00078 }
00079 }
00080 return;
00081 }
00082 #endif
00083
00084 herror_t
00085 soap_client_init_args(int argc, char **argv)
00086 {
00087 herror_t status;
00088
00089 #ifdef HAVE_XMLSEC1
00090 _soap_client_parse_arguments(argc, argv);
00091
00092 if ((status = soap_xmlsec_client_init_args(argc, argv)) != H_OK)
00093 {
00094 log_error2("soap_xmlsec_client_init_args failed (%s)", herror_message(status));
00095 return status;
00096 }
00097 #endif
00098
00099 if ((status = soap_transport_client_init_args(argc, argv)) != H_OK)
00100 {
00101 log_error2("soap_transport_client_init_args failed (%s)", herror_message(status));
00102 return status;
00103 }
00104
00105 return H_OK;
00106 }
00107
00108 void
00109 soap_client_destroy(void)
00110 {
00111 soap_transport_client_destroy();
00112
00113 return;
00114 }
00115
00116 herror_t
00117 soap_client_invoke(struct SoapCtx *req, struct SoapCtx **res, const char *url, const char *action)
00118 {
00119 herror_t status;
00120 char *id;
00121
00122 log_verbose2("action = \"%s\"", action);
00123 soap_addressing_set_action_string(req->env, action);
00124
00125 log_verbose2("url = \"%s\"", url);
00126 soap_addressing_set_to_address_string(req->env, url);
00127
00128 log_verbose2("from = \"%s\"", soap_transport_get_name());
00129 soap_addressing_set_from_address_string(req->env, soap_transport_get_name());
00130
00131 soap_addressing_set_message_id_string(req->env, NULL);
00132 id = soap_addressing_get_message_id_string(req->env);
00133 log_verbose2("generated message id = \"%s\"", id);
00134 free(id);
00135
00136 #ifdef HAVE_XMLSEC1
00137 if ((status = soap_xmlsec_encrypt(req)) != H_OK)
00138 {
00139 log_error2("soap_xmlsec_encrypt failed (%s)", herror_message(status));
00140 if (_soap_client_force_encrypt)
00141 return status;
00142 }
00143 else
00144 {
00145 log_verbose1("soap_xmlsec_encrypt succeed");
00146 }
00147
00148 if ((status = soap_xmlsec_sign(req)) != H_OK)
00149 {
00150 log_error2("soap_xmlsec_sign failed (%s)", herror_message(status));
00151 if (_soap_client_force_sign)
00152 return status;
00153 }
00154 else
00155 {
00156 log_verbose1("soap_xmlsec_encrypt succeed");
00157 }
00158 #endif
00159
00160 if ((status = soap_transport_client_invoke(req, res)) != H_OK)
00161 {
00162 log_error2("soap_transport_client_invoke failed (%s)", herror_message(status));
00163 return status;
00164 }
00165
00166 #ifdef HAVE_XMLSEC1
00167 if ((status = soap_xmlsec_verify(*res)) != H_OK)
00168 {
00169 log_error2("soap_xmlsec_verify failed (%s)", herror_message(status));
00170 if (_soap_client_force_verify)
00171 return status;
00172 }
00173 else
00174 {
00175 log_verbose1("soap_xmlsec_verify succeed");
00176 }
00177
00178 if ((status = soap_xmlsec_decrypt(*res)) != H_OK)
00179 {
00180 log_error2("soap_xmlsec_decrypt failed (%s)", herror_message(status));
00181 if (_soap_client_force_decrypt)
00182 return status;
00183 }
00184 else
00185 {
00186 log_verbose1("soap_xmlsec_decrypt succeed");
00187 }
00188 #endif
00189
00190 return H_OK;
00191 }