-
-
Save Oliveiras/02243fa4ea72d51407c892373fd1212a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "SoapEndpoint.h" | |
// don't let Axis define int types because we already included <cstdint> | |
#define AXIS2_SKIP_INT_TYPEDEFS | |
extern "C" { | |
#include <axiom.h> | |
#include <axis2_util.h> | |
#include <axiom_soap.h> | |
#include <axis2_client.h> | |
#include "generated/axis2_stub_SignatureService.h" | |
} // extern "C" | |
#include <boost/format.hpp> | |
#include "log/log.h" | |
namespace cad { | |
struct SoapEndpoint::Impl { | |
adb_SimpleSignatureReqTypeV2_t* | |
build_simple_signature_request( | |
const axutil_env_t* env, | |
long ap_id, | |
char* target_user, | |
char* data_to_be_signed); | |
int64_t | |
parse_simple_signature_response( | |
const axutil_env_t* env, | |
adb_SimpleSignatureRespTypeV2_t* response); | |
}; | |
SoapEndpoint::SoapEndpoint() | |
: impl_(new Impl) { | |
} | |
SoapEndpoint::~SoapEndpoint() { | |
} | |
int64_t | |
SoapEndpoint::send_simple_signature( | |
long ap_id, | |
char* target_user, | |
char* data_to_be_signed) { | |
// alloc axis environment & cia | |
axutil_env_t* env = axutil_env_create_all("cad.log", AXIS2_LOG_LEVEL_DEBUG); | |
axis2_char_t* client_home = AXIS2_GETENV("AXIS2C_HOME"); | |
// create the endpoint | |
axis2_char_t* endpoint_address = | |
axis2_stub_get_endpoint_uri_of_SignatureService(env); | |
axis2_stub_t* endpoint = | |
axis2_stub_create_SignatureService(env, client_home, endpoint_address); | |
// mount the request | |
adb_SimpleSignatureReqTypeV2_t* request_type = | |
impl_->build_simple_signature_request(env, ap_id, target_user, data_to_be_signed); | |
adb_SimpleSignatureV2_t* request_message = | |
adb_SimpleSignatureV2_create_with_values(env, request_type); | |
// get and parse the response | |
adb_SimpleSignatureV2Response_t* response_message = | |
axis2_stub_op_SignatureService_SimpleSignatureV2(endpoint, env, request_message, nullptr); | |
adb_SimpleSignatureRespTypeV2_t* response_type = | |
adb_SimpleSignatureV2Response_get_SimpleSignatureRespTypeV2(response_message, env); | |
int64_t transaction_id = impl_->parse_simple_signature_response(env, response_type); | |
// free axis vars | |
axis2_stub_free(endpoint, env); | |
axutil_env_free(env); | |
return transaction_id; | |
} | |
adb_SimpleSignatureReqTypeV2_t* | |
SoapEndpoint::Impl::build_simple_signature_request( | |
const axutil_env_t* env, | |
long ap_id, | |
char* target_user, | |
char* data_to_be_signed) { | |
adb_SimpleSignatureReqTypeV2_t* request = adb_SimpleSignatureReqTypeV2_create(env); | |
adb_SimpleSignatureReqTypeV2_set_ApId(request, env, ap_id); | |
adb_SimpleSignatureReqTypeV2_set_DataToBeSigned(request, env, data_to_be_signed); | |
adb_SimpleSignatureReqTypeV2_set_MessagingMode(request, env, | |
adb_MessagingModeType_create_with_values(env, "asynchClientServer")); | |
adb_SimpleSignatureReqTypeV2_set_MobileUser(request, env, | |
adb_MobileUserType_create_with_values(env, target_user)); | |
adb_SimpleSignatureReqTypeV2_set_TestMode(request, env, true); | |
return request; | |
} | |
int64_t | |
SoapEndpoint::Impl::parse_simple_signature_response( | |
const axutil_env_t* env, | |
adb_SimpleSignatureRespTypeV2_t* response) { | |
adb_StatusType_t* status_type = adb_SimpleSignatureRespTypeV2_get_Status(response, env); | |
int status_code = adb_StatusType_get_StatusCode(status_type, env); | |
axis2_char_t* status_message = adb_StatusType_get_StatusMessage(status_type, env); | |
if (status_code >= 200) { | |
LOG.error((boost::format("Server returned an error [code: %1%; message: %2%]") | |
% status_code % status_message).str()); | |
return 0; | |
} | |
int64_t transaction_id = adb_SimpleSignatureRespTypeV2_get_TransactionId(response, env); | |
return transaction_id; | |
} | |
} // cad |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef SOAP_ENDPOINT_H_ | |
#define SOAP_ENDPOINT_H_ | |
#include <cstdint> | |
#include <memory> | |
namespace cad { | |
// TODO document it | |
class SoapEndpoint { | |
struct Impl; | |
std::unique_ptr<cad::SoapEndpoint::Impl> impl_; | |
public: | |
SoapEndpoint(); | |
~SoapEndpoint(); | |
int64_t | |
send_simple_signature( | |
long ap_id, | |
char* target_user, | |
char* data_to_be_signed); | |
}; | |
} // cad | |
#endif // SOAP_ENDPOINT_H_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment