/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <axis2_http_sender.h>
#include <axutil_string.h>
#include <axis2_http_transport.h>
#include <string.h>
#include <axiom_output.h>
#include <axis2_op_ctx.h>
#include <axis2_ctx.h>
#include <axis2_conf_ctx.h>
#include <axis2_http_client.h>
#include <axiom_xml_writer.h>
#include <axutil_property.h>
#include <axutil_param.h>
#include <axutil_types.h>
#include <axutil_generic_obj.h>
#include <axutil_uuid_gen.h>
#include <axutil_digest_calc.h>
#include <axis2_const.h>
#include <axis2_util.h>
#include <axiom_soap.h>
#include <axutil_version.h>
#ifdef AXIS2_LIBCURL_ENABLED
#include "libcurl/axis2_libcurl.h"
#else
#define CLIENT_NONCE_LENGTH 8
#endif
struct axis2_http_sender
{
axis2_char_t *http_version;
axis2_bool_t chunked;
int so_timeout;
axiom_output_t *om_output;
axis2_http_client_t *client;
axis2_bool_t is_soap;
};
#ifndef AXIS2_LIBCURL_ENABLED
static void axis2_http_sender_add_header_list (axis2_http_simple_request_t *
request,
const axutil_env_t * env,
axutil_array_list_t *
array_list);
static axis2_status_t axis2_http_sender_configure_proxy (axis2_http_sender_t *
sender,
const axutil_env_t *
env,
axis2_msg_ctx_t *
msg_ctx);
static axis2_status_t
axis2_http_sender_configure_server_cert (axis2_http_sender_t * sender,
const axutil_env_t * env,
axis2_msg_ctx_t * msg_ctx);
static axis2_status_t
axis2_http_sender_configure_key_file (axis2_http_sender_t * sender,
const axutil_env_t * env,
axis2_msg_ctx_t * msg_ctx);
static axis2_status_t
axis2_http_sender_configure_http_auth (axis2_http_sender_t * sender,
const axutil_env_t * env,
axis2_msg_ctx_t * msg_ctx,
axis2_http_simple_request_t * request);
static axis2_status_t
axis2_http_sender_configure_proxy_auth (axis2_http_sender_t * sender,
const axutil_env_t * env,
axis2_msg_ctx_t * msg_ctx,
axis2_http_simple_request_t * request);
static axis2_status_t
axis2_http_sender_set_http_auth_type (axis2_http_sender_t * sender,
const axutil_env_t * env,
axis2_msg_ctx_t * msg_ctx,
axis2_http_simple_request_t * request);
static axis2_status_t
axis2_http_sender_set_proxy_auth_type (axis2_http_sender_t * sender,
const axutil_env_t * env,
axis2_msg_ctx_t * msg_ctx,
axis2_http_simple_request_t * request);
static axis2_status_t
axis2_http_sender_configure_http_basic_auth (axis2_http_sender_t * sender,
const axutil_env_t * env,
axis2_msg_ctx_t * msg_ctx,
axis2_http_simple_request_t *
request);
static axis2_status_t
axis2_http_sender_configure_proxy_basic_auth (axis2_http_sender_t * sender,
const axutil_env_t * env,
axis2_msg_ctx_t * msg_ctx,
axis2_http_simple_request_t *
request);
static axis2_status_t
axis2_http_sender_configure_http_digest_auth (axis2_http_sender_t * sender,
const axutil_env_t * env,
axis2_msg_ctx_t * msg_ctx,
axis2_http_simple_request_t * request,
axis2_char_t * header_data);
static axis2_status_t
axis2_http_sender_configure_proxy_digest_auth (axis2_http_sender_t * sender,
const axutil_env_t * env,
axis2_msg_ctx_t * msg_ctx,
axis2_http_simple_request_t * request,
axis2_char_t * header_data);
#endif
AXIS2_EXTERN axis2_http_sender_t *AXIS2_CALL
axis2_http_sender_create (const axutil_env_t * env)
{
axis2_http_sender_t *sender = NULL;
sender = (axis2_http_sender_t *) AXIS2_MALLOC
(env->allocator, sizeof (axis2_http_sender_t));
if (!sender)
{
AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
return NULL;
}
memset (sender, 0, sizeof (axis2_http_sender_t));
sender->http_version = (axis2_char_t *) AXIS2_HTTP_HEADER_PROTOCOL_11;
sender->so_timeout = AXIS2_HTTP_DEFAULT_SO_TIMEOUT;
/* unlike the java impl we don't have a default om output
* it should be explicitly set and it's a MUST
*/
sender->om_output = NULL;
sender->chunked = AXIS2_FALSE;
sender->client = NULL;
return sender;
}
AXIS2_EXTERN void AXIS2_CALL
axis2_http_sender_free (axis2_http_sender_t * sender,
const axutil_env_t * env)
{
if (sender->http_version)
{
AXIS2_FREE (env->allocator, sender->http_version);
}
/* Do not free this here since it will be required in later processing
* of the response soap message
*/
sender->client = NULL;
AXIS2_FREE (env->allocator, sender);
return;
}
#ifndef AXIS2_LIBCURL_ENABLED
AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_http_sender_send (axis2_http_sender_t * sender,
const axutil_env_t * env,
axis2_msg_ctx_t * msg_ctx,
axiom_soap_envelope_t * out,
const axis2_char_t * str_url,
const axis2_char_t * soap_action)
{
axis2_http_simple_request_t *request = NULL;
axis2_http_request_line_t *request_line = NULL;
/* url is to hold url given in str_url */
axutil_url_t *url = NULL;
axiom_xml_writer_t *xml_writer = NULL;
axis2_char_t *buffer = NULL;
unsigned int buffer_size = 0;
const axis2_char_t *char_set_enc = NULL;
axutil_string_t *char_set_enc_str = NULL;
int status_code = -1;
axis2_http_simple_response_t *response = NULL;
axis2_char_t *content_type = NULL;
axis2_bool_t content_type_deepl_copy = AXIS2_TRUE;
axis2_byte_t *output_stream = NULL;
int output_stream_size = 0;
axis2_bool_t doing_mtom = AXIS2_FALSE;
axutil_property_t *dump_prop