implemented support for multiple proxies
This commit is contained in:
parent
82514f2b52
commit
71d7f96944
35 changed files with 156 additions and 111 deletions
19
proxy/Makefile
Normal file
19
proxy/Makefile
Normal file
|
@ -0,0 +1,19 @@
|
|||
PROGRAM=wanproxy
|
||||
|
||||
SRCS+= wanproxy.cc
|
||||
SRCS+= wanproxy_config.cc
|
||||
SRCS+= wanproxy_config_class_codec.cc
|
||||
SRCS+= wanproxy_config_class_interface.cc
|
||||
SRCS+= wanproxy_config_class_peer.cc
|
||||
SRCS+= wanproxy_config_class_proxy.cc
|
||||
SRCS+= wanproxy_config_type_codec.cc
|
||||
SRCS+= wanproxy_config_type_compressor.cc
|
||||
SRCS+= wanproxy_config_type_proxy_type.cc
|
||||
SRCS+= wanproxy_config_type_proxy_role.cc
|
||||
SRCS+= proxy_listener.cc
|
||||
SRCS+= proxy_connector.cc
|
||||
|
||||
TOPDIR=..
|
||||
USE_LIBS=common common/thread common/time common/uuid config crypto event http io io/net io/socket ssh xcodec xcodec/cache/coss zlib
|
||||
include ${TOPDIR}/common/program.mk
|
||||
|
272
proxy/proxy_connector.cc
Normal file
272
proxy/proxy_connector.cc
Normal file
|
@ -0,0 +1,272 @@
|
|||
/*
|
||||
* Copyright (c) 2008-2011 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <event/event_system.h>
|
||||
#include <io/socket/socket.h>
|
||||
#include <io/sink_filter.h>
|
||||
#include <ssh/ssh_filter.h>
|
||||
#include <xcodec/xcodec_filter.h>
|
||||
#include <zlib/zlib_filter.h>
|
||||
#include <common/count_filter.h>
|
||||
#include "proxy_connector.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: proxy_connector.cc //
|
||||
// Description: carries data between endpoints through a filter chain //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2016-02-28 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ProxyConnector::ProxyConnector (const std::string& name,
|
||||
WANProxyCodec* local_codec,
|
||||
WANProxyCodec* remote_codec,
|
||||
Socket* local_socket,
|
||||
SocketAddressFamily family,
|
||||
const std::string& remote_name,
|
||||
bool cln, bool ssh)
|
||||
: log_("/wanproxy/" + name + "/connector"),
|
||||
local_codec_(local_codec),
|
||||
remote_codec_(remote_codec),
|
||||
local_socket_(local_socket),
|
||||
remote_socket_(0),
|
||||
is_cln_(cln),
|
||||
is_ssh_(ssh),
|
||||
request_chain_(this),
|
||||
response_chain_(this),
|
||||
connect_action_(0),
|
||||
stop_action_(0),
|
||||
request_action_(0),
|
||||
response_action_(0),
|
||||
close_action_(0),
|
||||
flushing_(0)
|
||||
{
|
||||
if (local_socket_ && (remote_socket_ = Socket::create (family, SocketTypeStream, "tcp", remote_name)))
|
||||
{
|
||||
connect_action_ = remote_socket_->connect (remote_name, callback (this, &ProxyConnector::connect_complete));
|
||||
stop_action_ = event_system.register_interest (EventInterestStop, callback (this, &ProxyConnector::conclude));
|
||||
}
|
||||
else
|
||||
{
|
||||
close_action_ = event_system.track (0, StreamModeWait, callback (this, &ProxyConnector::conclude));
|
||||
}
|
||||
}
|
||||
|
||||
ProxyConnector::~ProxyConnector ()
|
||||
{
|
||||
if (connect_action_)
|
||||
connect_action_->cancel ();
|
||||
if (stop_action_)
|
||||
stop_action_->cancel ();
|
||||
if (request_action_)
|
||||
request_action_->cancel ();
|
||||
if (response_action_)
|
||||
response_action_->cancel ();
|
||||
if (close_action_)
|
||||
close_action_->cancel ();
|
||||
if (local_socket_)
|
||||
local_socket_->close ();
|
||||
if (remote_socket_)
|
||||
remote_socket_->close ();
|
||||
delete local_socket_;
|
||||
delete remote_socket_;
|
||||
}
|
||||
|
||||
void ProxyConnector::connect_complete (Event e)
|
||||
{
|
||||
if (connect_action_)
|
||||
connect_action_->cancel (), connect_action_ = 0;
|
||||
|
||||
switch (e.type_)
|
||||
{
|
||||
case Event::Done:
|
||||
break;
|
||||
case Event::Error:
|
||||
INFO(log_) << "Connect failed: " << e;
|
||||
conclude (e);
|
||||
return;
|
||||
default:
|
||||
ERROR(log_) << "Unexpected event: " << e;
|
||||
conclude (e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (build_chains (local_codec_, remote_codec_, local_socket_, remote_socket_))
|
||||
{
|
||||
request_action_ = local_socket_->read (callback (this, &ProxyConnector::on_request_data));
|
||||
response_action_ = remote_socket_->read (callback (this, &ProxyConnector::on_response_data));
|
||||
}
|
||||
}
|
||||
|
||||
bool ProxyConnector::build_chains (WANProxyCodec* cdc1, WANProxyCodec* cdc2, Socket* sck1, Socket* sck2)
|
||||
{
|
||||
if (! sck1 || ! sck2)
|
||||
return false;
|
||||
|
||||
response_chain_.prepend (new SinkFilter ("/wanproxy/response", sck1, is_cln_));
|
||||
|
||||
if (is_ssh_)
|
||||
{
|
||||
SSH::EncryptFilter* enc; SSH::DecryptFilter* dec;
|
||||
request_chain_.append ((dec = new SSH::DecryptFilter ((cdc1 ? SSH::SOURCE_ENCODED : 0))));
|
||||
response_chain_.prepend ((enc = new SSH::EncryptFilter (SSH::ServerRole, (cdc1 ? SSH::SOURCE_ENCODED : 0))));
|
||||
dec->set_encrypter (enc);
|
||||
}
|
||||
|
||||
if (cdc1)
|
||||
{
|
||||
if (cdc1->counting_)
|
||||
{
|
||||
request_chain_.append (new CountFilter (cdc1->request_input_bytes_));
|
||||
response_chain_.prepend (new CountFilter (cdc1->response_output_bytes_));
|
||||
}
|
||||
|
||||
if (cdc1->compressor_)
|
||||
{
|
||||
request_chain_.append (new InflateFilter ());
|
||||
response_chain_.prepend (new DeflateFilter (cdc1->compressor_level_));
|
||||
}
|
||||
|
||||
if (cdc1->xcache_)
|
||||
{
|
||||
EncodeFilter* enc; DecodeFilter* dec;
|
||||
request_chain_.append ((dec = new DecodeFilter ("/wanproxy/" + cdc1->name_ + "/dec", cdc1)));
|
||||
response_chain_.prepend ((enc = new EncodeFilter ("/wanproxy/" + cdc1->name_ + "/enc", cdc1, 1)));
|
||||
dec->set_upstream (enc);
|
||||
}
|
||||
|
||||
if (cdc1->counting_)
|
||||
{
|
||||
request_chain_.append (new CountFilter (cdc1->request_output_bytes_));
|
||||
response_chain_.prepend (new CountFilter (cdc1->response_input_bytes_, 1));
|
||||
}
|
||||
}
|
||||
|
||||
if (cdc2)
|
||||
{
|
||||
if (cdc2->counting_)
|
||||
{
|
||||
request_chain_.append (new CountFilter (cdc2->request_input_bytes_));
|
||||
response_chain_.prepend (new CountFilter (cdc2->response_output_bytes_));
|
||||
}
|
||||
|
||||
if (cdc2->xcache_)
|
||||
{
|
||||
EncodeFilter* enc; DecodeFilter* dec;
|
||||
request_chain_.append ((enc = new EncodeFilter ("/wanproxy/" + cdc2->name_ + "/enc", cdc2)));
|
||||
response_chain_.prepend ((dec = new DecodeFilter ("/wanproxy/" + cdc2->name_ + "/dec", cdc2)));
|
||||
dec->set_upstream (enc);
|
||||
}
|
||||
|
||||
if (cdc2->compressor_)
|
||||
{
|
||||
request_chain_.append (new DeflateFilter (cdc2->compressor_level_));
|
||||
response_chain_.prepend (new InflateFilter ());
|
||||
}
|
||||
|
||||
if (cdc2->counting_)
|
||||
{
|
||||
request_chain_.append (new CountFilter (cdc2->request_output_bytes_));
|
||||
response_chain_.prepend (new CountFilter (cdc2->response_input_bytes_));
|
||||
}
|
||||
}
|
||||
|
||||
if (is_ssh_)
|
||||
{
|
||||
SSH::EncryptFilter* enc; SSH::DecryptFilter* dec;
|
||||
request_chain_.append ((enc = new SSH::EncryptFilter (SSH::ClientRole, (cdc2 ? SSH::SOURCE_ENCODED : 0))));
|
||||
response_chain_.prepend ((dec = new SSH::DecryptFilter ((cdc2 ? SSH::SOURCE_ENCODED : 0))));
|
||||
dec->set_encrypter (enc);
|
||||
}
|
||||
|
||||
request_chain_.append (new SinkFilter ("/wanproxy/request", sck2));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ProxyConnector::on_request_data (Event e)
|
||||
{
|
||||
if (request_action_)
|
||||
request_action_->cancel (), request_action_ = 0;
|
||||
if (flushing_ & REQUEST_CHAIN_FLUSHING)
|
||||
return;
|
||||
|
||||
switch (e.type_)
|
||||
{
|
||||
case Event::Done:
|
||||
request_action_ = local_socket_->read (callback (this, &ProxyConnector::on_request_data));
|
||||
if (request_chain_.consume (e.buffer_))
|
||||
break;
|
||||
case Event::EOS:
|
||||
DEBUG(log_) << "Flushing request";
|
||||
flushing_ |= REQUEST_CHAIN_FLUSHING;
|
||||
request_chain_.flush (REQUEST_CHAIN_READY);
|
||||
break;
|
||||
default:
|
||||
DEBUG(log_) << "Unexpected event: " << e;
|
||||
conclude (e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ProxyConnector::on_response_data (Event e)
|
||||
{
|
||||
if (response_action_)
|
||||
response_action_->cancel (), response_action_ = 0;
|
||||
if (flushing_ & RESPONSE_CHAIN_FLUSHING)
|
||||
return;
|
||||
|
||||
switch (e.type_)
|
||||
{
|
||||
case Event::Done:
|
||||
response_action_ = remote_socket_->read (callback (this, &ProxyConnector::on_response_data));
|
||||
if (response_chain_.consume (e.buffer_))
|
||||
break;
|
||||
case Event::EOS:
|
||||
DEBUG(log_) << "Flushing response";
|
||||
flushing_ |= RESPONSE_CHAIN_FLUSHING;
|
||||
response_chain_.flush (RESPONSE_CHAIN_READY);
|
||||
break;
|
||||
default:
|
||||
DEBUG(log_) << "Unexpected event: " << e;
|
||||
conclude (e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ProxyConnector::flush (int flg)
|
||||
{
|
||||
flushing_ |= flg;
|
||||
if ((flushing_ & (REQUEST_CHAIN_READY | RESPONSE_CHAIN_READY)) == (REQUEST_CHAIN_READY | RESPONSE_CHAIN_READY))
|
||||
if (! close_action_)
|
||||
close_action_ = event_system.track (0, StreamModeWait, callback (this, &ProxyConnector::conclude));
|
||||
}
|
||||
|
||||
void ProxyConnector::conclude (Event e)
|
||||
{
|
||||
delete this;
|
||||
}
|
80
proxy/proxy_connector.h
Normal file
80
proxy/proxy_connector.h
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) 2008-2011 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef PROGRAMS_WANPROXY_PROXY_CONNECTOR_H
|
||||
#define PROGRAMS_WANPROXY_PROXY_CONNECTOR_H
|
||||
|
||||
#define REQUEST_CHAIN_FLUSHING 0x10000
|
||||
#define RESPONSE_CHAIN_FLUSHING 0x20000
|
||||
#define REQUEST_CHAIN_READY 0x40000
|
||||
#define RESPONSE_CHAIN_READY 0x80000
|
||||
|
||||
#include <common/filter.h>
|
||||
#include <event/action.h>
|
||||
#include <event/event.h>
|
||||
#include <io/socket/socket_types.h>
|
||||
#include "wanproxy_codec.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: proxy_connector.h //
|
||||
// Description: carries data between endpoints through a filter chain //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2016-02-28 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ProxyConnector : public Filter
|
||||
{
|
||||
LogHandle log_;
|
||||
WANProxyCodec* local_codec_;
|
||||
WANProxyCodec* remote_codec_;
|
||||
Socket* local_socket_;
|
||||
Socket* remote_socket_;
|
||||
bool is_cln_, is_ssh_;
|
||||
FilterChain request_chain_;
|
||||
FilterChain response_chain_;
|
||||
Action* connect_action_;
|
||||
Action* stop_action_;
|
||||
Action* request_action_;
|
||||
Action* response_action_;
|
||||
Action* close_action_;
|
||||
int flushing_;
|
||||
|
||||
public:
|
||||
ProxyConnector (const std::string&, WANProxyCodec*, WANProxyCodec*,
|
||||
Socket*, SocketAddressFamily, const std::string&, bool cln, bool ssh);
|
||||
virtual ~ProxyConnector ();
|
||||
|
||||
void connect_complete (Event e);
|
||||
bool build_chains (WANProxyCodec* cdc1, WANProxyCodec* cdc2, Socket* sck1, Socket* sck2);
|
||||
void on_request_data (Event e);
|
||||
void on_response_data (Event e);
|
||||
virtual void flush (int flg);
|
||||
void conclude (Event e);
|
||||
};
|
||||
|
||||
#endif /* !PROGRAMS_WANPROXY_PROXY_CONNECTOR_H */
|
137
proxy/proxy_listener.cc
Normal file
137
proxy/proxy_listener.cc
Normal file
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* Copyright (c) 2008-2011 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <event/event_system.h>
|
||||
#include "proxy_connector.h"
|
||||
#include "proxy_listener.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: proxy_listener.cc //
|
||||
// Description: listens on a port spawning a connector for each client //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2016-02-28 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ProxyListener::ProxyListener (const std::string& name,
|
||||
WANProxyCodec* local_codec,
|
||||
WANProxyCodec* remote_codec,
|
||||
SocketAddressFamily local_family,
|
||||
const std::string& local_address,
|
||||
SocketAddressFamily remote_family,
|
||||
const std::string& remote_address,
|
||||
bool cln, bool ssh)
|
||||
: log_("/wanproxy/" + name + "/listener"),
|
||||
name_(name),
|
||||
local_codec_(local_codec),
|
||||
remote_codec_(remote_codec),
|
||||
local_family_(local_family),
|
||||
local_address_(local_address),
|
||||
remote_family_(remote_family),
|
||||
remote_address_(remote_address),
|
||||
is_cln_(cln),
|
||||
is_ssh_(ssh),
|
||||
accept_action_(0),
|
||||
stop_action_(0)
|
||||
{
|
||||
launch_service ();
|
||||
}
|
||||
|
||||
ProxyListener::~ProxyListener ()
|
||||
{
|
||||
if (accept_action_)
|
||||
accept_action_->cancel ();
|
||||
if (stop_action_)
|
||||
stop_action_->cancel ();
|
||||
close ();
|
||||
}
|
||||
|
||||
void ProxyListener::launch_service ()
|
||||
{
|
||||
if (listen (local_family_, local_address_))
|
||||
{
|
||||
accept_action_ = accept (callback (this, &ProxyListener::accept_complete));
|
||||
INFO(log_) << "Listening on: " << getsockname ();
|
||||
}
|
||||
else
|
||||
{
|
||||
HALT(log_) << "Unable to create listener.";
|
||||
}
|
||||
}
|
||||
|
||||
void ProxyListener::refresh (const std::string& name,
|
||||
WANProxyCodec* local_codec,
|
||||
WANProxyCodec* remote_codec,
|
||||
SocketAddressFamily local_family,
|
||||
const std::string& local_address,
|
||||
SocketAddressFamily remote_family,
|
||||
const std::string& remote_address,
|
||||
bool cln, bool ssh)
|
||||
{
|
||||
bool relaunch = (local_address != local_address_);
|
||||
bool redirect = (remote_address != remote_address_);
|
||||
|
||||
name_ = name;
|
||||
local_codec_ = local_codec;
|
||||
remote_codec_ = remote_codec;
|
||||
local_family_ = local_family;
|
||||
local_address_ = local_address;
|
||||
remote_family_ = remote_family;
|
||||
remote_address_ = remote_address;
|
||||
is_cln_ = cln;
|
||||
is_ssh_ = ssh;
|
||||
|
||||
if (relaunch)
|
||||
{
|
||||
if (accept_action_)
|
||||
accept_action_->cancel (), accept_action_ = 0;
|
||||
launch_service ();
|
||||
}
|
||||
|
||||
if (redirect)
|
||||
{
|
||||
INFO(log_) << "Peer address: " << remote_address_;
|
||||
}
|
||||
}
|
||||
|
||||
void ProxyListener::accept_complete (Event e, Socket* sck)
|
||||
{
|
||||
switch (e.type_)
|
||||
{
|
||||
case Event::Done:
|
||||
DEBUG(log_) << "Accepted client: " << sck->getpeername ();
|
||||
new ProxyConnector (name_, local_codec_, remote_codec_, sck, remote_family_, remote_address_, is_cln_, is_ssh_);
|
||||
break;
|
||||
case Event::Error:
|
||||
ERROR(log_) << "Accept error: " << e;
|
||||
break;
|
||||
default:
|
||||
ERROR(log_) << "Unexpected event: " << e;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
69
proxy/proxy_listener.h
Normal file
69
proxy/proxy_listener.h
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2008-2011 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef PROGRAMS_WANPROXY_PROXY_LISTENER_H
|
||||
#define PROGRAMS_WANPROXY_PROXY_LISTENER_H
|
||||
|
||||
#include <event/action.h>
|
||||
#include <event/event.h>
|
||||
#include <io/net/tcp_server.h>
|
||||
#include "wanproxy_codec.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: proxy_listener.h //
|
||||
// Description: listens on a port spawning a connector for each client //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-08-31 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ProxyListener : public TCPServer
|
||||
{
|
||||
LogHandle log_;
|
||||
std::string name_;
|
||||
WANProxyCodec* local_codec_;
|
||||
WANProxyCodec* remote_codec_;
|
||||
SocketAddressFamily local_family_;
|
||||
std::string local_address_;
|
||||
SocketAddressFamily remote_family_;
|
||||
std::string remote_address_;
|
||||
bool is_cln_, is_ssh_;
|
||||
Action* accept_action_;
|
||||
Action* stop_action_;
|
||||
|
||||
public:
|
||||
ProxyListener (const std::string&, WANProxyCodec*, WANProxyCodec*, SocketAddressFamily, const std::string&,
|
||||
SocketAddressFamily, const std::string&, bool cln, bool ssh);
|
||||
~ProxyListener ();
|
||||
|
||||
void launch_service ();
|
||||
void refresh (const std::string&, WANProxyCodec*, WANProxyCodec*, SocketAddressFamily, const std::string&,
|
||||
SocketAddressFamily, const std::string&, bool cln, bool ssh);
|
||||
void accept_complete (Event e, Socket* client);
|
||||
};
|
||||
|
||||
#endif /* !PROGRAMS_WANPROXY_PROXY_LISTENER_H */
|
111
proxy/wanproxy.cc
Normal file
111
proxy/wanproxy.cc
Normal file
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright (c) 2008-2012 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <common/log.h>
|
||||
#include <event/event_system.h>
|
||||
#include "wanproxy.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: wanproxy.cc //
|
||||
// Description: session start and global application management //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2016-02-28 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define PROGRAM_VERSION "3.0.5"
|
||||
|
||||
WanProxyCore wanproxy;
|
||||
|
||||
static void usage(void);
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
std::string configfile;
|
||||
bool quiet, verbose;
|
||||
int ch;
|
||||
|
||||
quiet = verbose = false;
|
||||
|
||||
INFO("/wanproxy") << "WANProxy MT " << PROGRAM_VERSION;
|
||||
INFO("/wanproxy") << "Copyright (c) 2008-2013 WANProxy.org";
|
||||
INFO("/wanproxy") << "Copyright (c) 2013-2018 Bramfeld-Software";
|
||||
INFO("/wanproxy") << "All rights reserved.";
|
||||
|
||||
while ((ch = getopt(argc, argv, "c:qv")) != -1)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case 'c':
|
||||
configfile = optarg;
|
||||
break;
|
||||
case 'q':
|
||||
quiet = true;
|
||||
break;
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (configfile.empty ())
|
||||
usage();
|
||||
|
||||
if (quiet && verbose)
|
||||
usage();
|
||||
|
||||
if (verbose)
|
||||
Log::mask (".?", Log::Debug);
|
||||
else if (quiet)
|
||||
Log::mask (".?", Log::Error);
|
||||
else
|
||||
Log::mask (".?", Log::Info);
|
||||
|
||||
if (! wanproxy.configure (configfile))
|
||||
{
|
||||
ERROR("/wanproxy") << "Could not configure proxies.";
|
||||
wanproxy.terminate ();
|
||||
return 1;
|
||||
}
|
||||
|
||||
event_system.run ();
|
||||
|
||||
wanproxy.terminate ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
INFO("/wanproxy/usage") << "wanproxy [-q | -v] -c configfile";
|
||||
exit(1);
|
||||
}
|
||||
|
85
proxy/wanproxy.conf
Normal file
85
proxy/wanproxy.conf
Normal file
|
@ -0,0 +1,85 @@
|
|||
# Set log-mask before doing anything else so that there isn't a lot of noise.
|
||||
# Uses an informative mask in non-release builds. Errors-only in release builds.
|
||||
create log-mask catch-all
|
||||
set catch-all.regex "^/"
|
||||
set catch-all.mask INFO
|
||||
activate catch-all
|
||||
|
||||
# Set up codec instances.
|
||||
create codec codec0
|
||||
set codec0.codec XCodec
|
||||
set codec0.compressor zlib
|
||||
set codec0.compressor_level 6
|
||||
activate codec0
|
||||
|
||||
create codec codec1
|
||||
set codec1.codec XCodec
|
||||
set codec1.compressor zlib
|
||||
set codec1.compressor_level 6
|
||||
activate codec1
|
||||
|
||||
# Set up interfaces.
|
||||
create interface if0
|
||||
set if0.family IP
|
||||
set if0.host "localhost"
|
||||
set if0.port "3300"
|
||||
activate if0
|
||||
|
||||
create interface if1
|
||||
set if1.family $if0.family
|
||||
set if1.host $if0.host
|
||||
set if1.port "3301"
|
||||
activate if1
|
||||
|
||||
create interface if2
|
||||
set if2.family $if0.family
|
||||
set if2.host $if0.host
|
||||
set if2.port "3302"
|
||||
activate if2
|
||||
|
||||
# And peers to connect to them.
|
||||
create peer peer0
|
||||
set peer0.family $if1.family
|
||||
set peer0.host $if1.host
|
||||
set peer0.port $if1.port
|
||||
activate peer0
|
||||
|
||||
create peer peer1
|
||||
set peer1.family $if2.family
|
||||
set peer1.host $if2.host
|
||||
set peer1.port $if2.port
|
||||
activate peer1
|
||||
|
||||
# Set up proxy from the client that encodes.
|
||||
create proxy proxy0
|
||||
set proxy0.type TCP-TCP
|
||||
set proxy0.interface if0
|
||||
set proxy0.interface_codec None
|
||||
set proxy0.peer peer0
|
||||
set proxy0.peer_codec codec0
|
||||
activate proxy0
|
||||
|
||||
# Which feeds into this, which decodes.
|
||||
create proxy proxy1
|
||||
set proxy1.type TCP-TCP
|
||||
set proxy1.interface if1
|
||||
set proxy1.interface_codec codec1
|
||||
set proxy1.peer peer1
|
||||
set proxy1.peer_codec None
|
||||
activate proxy1
|
||||
|
||||
# Which feeds into this, which spawns connections from SOCKS.
|
||||
create proxy-socks proxy-socks0
|
||||
set proxy-socks0.interface if2
|
||||
activate proxy-socks0
|
||||
|
||||
# And set up a monitoring interface on port 9900.
|
||||
create interface if3
|
||||
set if3.family $if0.family
|
||||
set if3.host $if0.host
|
||||
set if3.port "9900"
|
||||
activate if3
|
||||
|
||||
create monitor monitor0
|
||||
set monitor0.interface if3
|
||||
activate monitor0
|
173
proxy/wanproxy.h
Normal file
173
proxy/wanproxy.h
Normal file
|
@ -0,0 +1,173 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: wanproxy.h //
|
||||
// Description: global data for the wanproxy application //
|
||||
// Project: WANProxy XTech //
|
||||
// Author: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2016-02-28 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef PROGRAMS_WANPROXY_WANPROXY_CORE_H
|
||||
#define PROGRAMS_WANPROXY_WANPROXY_CORE_H
|
||||
|
||||
#include <event/event_system.h>
|
||||
#include <common/uuid/uuid.h>
|
||||
#include <xcodec/xcodec.h>
|
||||
#include <xcodec/xcodec_cache.h>
|
||||
#include <xcodec/cache/coss/xcodec_cache_coss.h>
|
||||
#include "wanproxy_codec.h"
|
||||
#include "wanproxy_config.h"
|
||||
#include "wanproxy_config_type_codec.h"
|
||||
#include "proxy_listener.h"
|
||||
|
||||
struct WanProxyInstance
|
||||
{
|
||||
std::string proxy_name_;
|
||||
bool proxy_client_;
|
||||
bool proxy_secure_;
|
||||
SocketAddressFamily local_protocol_;
|
||||
std::string local_address_;
|
||||
WANProxyCodec local_codec_;
|
||||
SocketAddressFamily remote_protocol_;
|
||||
std::string remote_address_;
|
||||
WANProxyCodec remote_codec_;
|
||||
ProxyListener* listener_;
|
||||
|
||||
WanProxyInstance ()
|
||||
{
|
||||
proxy_client_ = proxy_secure_ = false;
|
||||
local_protocol_ = remote_protocol_ = SocketAddressFamilyIP;
|
||||
listener_ = 0;
|
||||
}
|
||||
|
||||
~WanProxyInstance ()
|
||||
{
|
||||
delete listener_;
|
||||
}
|
||||
};
|
||||
|
||||
struct WanProxyCore
|
||||
{
|
||||
private:
|
||||
std::string config_file_;
|
||||
Action* reload_action_;
|
||||
std::map<UUID, XCodecCache*> caches_;
|
||||
std::map<std::string, WanProxyInstance> proxies_;
|
||||
|
||||
public:
|
||||
WanProxyCore ()
|
||||
{
|
||||
reload_action_ = 0;
|
||||
}
|
||||
|
||||
bool configure (const std::string& file)
|
||||
{
|
||||
WANProxyConfig config;
|
||||
config_file_ = file;
|
||||
if (reload_action_)
|
||||
reload_action_->cancel ();
|
||||
reload_action_ = event_system.register_interest (EventInterestReload, callback (this, &WanProxyCore::reload));
|
||||
return config.read_file (config_file_);
|
||||
}
|
||||
|
||||
void reload ()
|
||||
{
|
||||
if (configure (config_file_))
|
||||
INFO("wanproxy/core") << "Reloaded proxy configuration.";
|
||||
else
|
||||
INFO("wanproxy/core") << "Could not reconfigure proxies.";
|
||||
}
|
||||
|
||||
void add_proxy (std::string& name, WanProxyInstance& data)
|
||||
{
|
||||
WanProxyInstance& prx = proxies_[name];
|
||||
|
||||
prx.proxy_name_ = data.proxy_name_;
|
||||
prx.proxy_client_ = data.proxy_client_;
|
||||
prx.proxy_secure_ = data.proxy_secure_;
|
||||
prx.local_protocol_ = data.local_protocol_;
|
||||
prx.local_address_ = data.local_address_;
|
||||
prx.local_codec_ = data.local_codec_;
|
||||
prx.remote_protocol_ = data.remote_protocol_;
|
||||
prx.remote_address_ = data.remote_address_;
|
||||
prx.remote_codec_ = data.remote_codec_;
|
||||
|
||||
if (! prx.listener_)
|
||||
prx.listener_ = new ProxyListener (prx.proxy_name_, &prx.local_codec_, &prx.remote_codec_,
|
||||
prx.local_protocol_, prx.local_address_, prx.remote_protocol_, prx.remote_address_,
|
||||
prx.proxy_client_, prx.proxy_secure_);
|
||||
else
|
||||
prx.listener_->refresh (prx.proxy_name_, &prx.local_codec_, &prx.remote_codec_,
|
||||
prx.local_protocol_, prx.local_address_, prx.remote_protocol_, prx.remote_address_,
|
||||
prx.proxy_client_, prx.proxy_secure_);
|
||||
}
|
||||
|
||||
XCodecCache* add_cache (WANProxyConfigCache type, std::string& path, size_t size, UUID& uuid)
|
||||
{
|
||||
XCodecCache* cache = 0;
|
||||
switch (type)
|
||||
{
|
||||
case WANProxyConfigCacheMemory:
|
||||
cache = new XCodecMemoryCache (uuid, size);
|
||||
break;
|
||||
case WANProxyConfigCacheCOSS:
|
||||
cache = new XCodecCacheCOSS (uuid, path, size);
|
||||
break;
|
||||
}
|
||||
ASSERT("/xcodec/cache", caches_.find(uuid) == caches_.end());
|
||||
if (cache)
|
||||
caches_[uuid] = cache;
|
||||
return cache;
|
||||
}
|
||||
|
||||
XCodecCache* find_cache (UUID uuid)
|
||||
{
|
||||
std::map<UUID, XCodecCache*>::const_iterator it = caches_.find (uuid);
|
||||
if (it != caches_.end ())
|
||||
return it->second;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void terminate ()
|
||||
{
|
||||
if (reload_action_)
|
||||
reload_action_->cancel (), reload_action_ = 0;
|
||||
|
||||
std::map<std::string, WanProxyInstance>::iterator prx;
|
||||
for (prx = proxies_.begin(); prx != proxies_.end(); prx++)
|
||||
print_stream_counts (prx->second);
|
||||
proxies_.clear ();
|
||||
|
||||
std::map<UUID, XCodecCache*>::iterator it;
|
||||
for (it = caches_.begin(); it != caches_.end(); it++)
|
||||
delete it->second;
|
||||
caches_.clear ();
|
||||
}
|
||||
|
||||
void print_stream_counts (WanProxyInstance& prx)
|
||||
{
|
||||
if (prx.local_codec_.counting_ || prx.remote_codec_.counting_)
|
||||
INFO("wanproxy/core") << "Stream counts for proxy: " << prx.proxy_name_;
|
||||
|
||||
if (prx.local_codec_.counting_)
|
||||
{
|
||||
INFO("wanproxy/core") << "Local codec request input bytes: " << prx.local_codec_.request_input_bytes_;
|
||||
INFO("wanproxy/core") << "Local codec request output bytes: " << prx.local_codec_.request_output_bytes_;
|
||||
INFO("wanproxy/core") << "Local codec response input bytes: " << prx.local_codec_.response_input_bytes_;
|
||||
INFO("wanproxy/core") << "Local codec response output bytes: " << prx.local_codec_.response_output_bytes_;
|
||||
}
|
||||
|
||||
if (prx.remote_codec_.counting_)
|
||||
{
|
||||
INFO("wanproxy/core") << "Remote codec request input bytes: " << prx.remote_codec_.request_input_bytes_;
|
||||
INFO("wanproxy/core") << "Remote codec request output bytes: " << prx.remote_codec_.request_output_bytes_;
|
||||
INFO("wanproxy/core") << "Remote codec response input bytes: " << prx.remote_codec_.response_input_bytes_;
|
||||
INFO("wanproxy/core") << "Remote codec response output bytes: " << prx.remote_codec_.response_output_bytes_;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
extern WanProxyCore wanproxy;
|
||||
|
||||
#endif /* !PROGRAMS_WANPROXY_WANPROXY_CORE_H */
|
73
proxy/wanproxy_codec.h
Normal file
73
proxy/wanproxy_codec.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef PROGRAMS_WANPROXY_WANPROXY_CODEC_H
|
||||
#define PROGRAMS_WANPROXY_WANPROXY_CODEC_H
|
||||
|
||||
#include "wanproxy_config_type_codec.h"
|
||||
#include "wanproxy_config_type_compressor.h"
|
||||
#include <xcodec/xcodec_cache.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: wanproxy_codec.h //
|
||||
// Description: control parameters for each connection endpoint //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-08-31 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct WANProxyCodec {
|
||||
std::string name_;
|
||||
WANProxyConfigCache cache_type_;
|
||||
std::string cache_path_;
|
||||
size_t cache_size_;
|
||||
UUID cache_uuid_;
|
||||
XCodecCache* xcache_;
|
||||
bool compressor_;
|
||||
char compressor_level_;
|
||||
bool counting_;
|
||||
intmax_t request_input_bytes_;
|
||||
intmax_t request_output_bytes_;
|
||||
intmax_t response_input_bytes_;
|
||||
intmax_t response_output_bytes_;
|
||||
|
||||
WANProxyCodec(void)
|
||||
: name_(""),
|
||||
cache_type_(WANProxyConfigCacheMemory),
|
||||
cache_size_(0),
|
||||
xcache_(NULL),
|
||||
compressor_(false),
|
||||
compressor_level_(0),
|
||||
counting_(false),
|
||||
request_input_bytes_(0),
|
||||
request_output_bytes_(0),
|
||||
response_input_bytes_(0),
|
||||
response_output_bytes_(0)
|
||||
{ }
|
||||
};
|
||||
|
||||
#endif /* !PROGRAMS_WANPROXY_WANPROXY_CODEC_H */
|
204
proxy/wanproxy_config.cc
Normal file
204
proxy/wanproxy_config.cc
Normal file
|
@ -0,0 +1,204 @@
|
|||
/*
|
||||
* Copyright (c) 2008-2012 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <deque>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include <config/config.h>
|
||||
#include <config/config_class.h>
|
||||
#include <config/config_class_log_mask.h>
|
||||
|
||||
#include <event/event_callback.h>
|
||||
|
||||
#include "wanproxy_config.h"
|
||||
#include "wanproxy_config_class_codec.h"
|
||||
#include "wanproxy_config_class_interface.h"
|
||||
//#include "wanproxy_config_class_monitor.h"
|
||||
#include "wanproxy_config_class_peer.h"
|
||||
#include "wanproxy_config_class_proxy.h"
|
||||
//#include "wanproxy_config_class_proxy_socks.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: wanproxy_config.cc //
|
||||
// Description: high-level configuration parser //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-04-01 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
WANProxyConfig::WANProxyConfig(void)
|
||||
: log_("/wanproxy/config"),
|
||||
config_(NULL)
|
||||
{ }
|
||||
|
||||
WANProxyConfig::~WANProxyConfig()
|
||||
{
|
||||
delete config_;
|
||||
}
|
||||
|
||||
bool
|
||||
WANProxyConfig::parse(std::deque<std::string>& tokens)
|
||||
{
|
||||
std::string command = tokens.front();
|
||||
tokens.pop_front();
|
||||
|
||||
if (command == "activate") {
|
||||
parse_activate(tokens);
|
||||
} else if (command == "create") {
|
||||
parse_create(tokens);
|
||||
} else if (command == "set") {
|
||||
parse_set(tokens);
|
||||
} else {
|
||||
tokens.clear();
|
||||
ERROR(log_) << "Unrecognized configuration command: " << command;
|
||||
}
|
||||
|
||||
return tokens.empty();
|
||||
}
|
||||
|
||||
void
|
||||
WANProxyConfig::parse_activate(std::deque<std::string>& tokens)
|
||||
{
|
||||
if (tokens.size() != 1) {
|
||||
ERROR(log_) << "Wrong number of words in activate (" << tokens.size() << ")";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!config_->activate(tokens[0])) {
|
||||
ERROR(log_) << "Object (" << tokens[0] << ") activation failed.";
|
||||
return;
|
||||
}
|
||||
tokens.clear();
|
||||
}
|
||||
|
||||
void
|
||||
WANProxyConfig::parse_create(std::deque<std::string>& tokens)
|
||||
{
|
||||
if (tokens.size() != 2) {
|
||||
ERROR(log_) << "Wrong number of words in create (" << tokens.size() << ")";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!config_->create(tokens[0], tokens[1])) {
|
||||
ERROR(log_) << "Object (" << tokens[1] << ") could not be created.";
|
||||
return;
|
||||
}
|
||||
tokens.clear();
|
||||
}
|
||||
|
||||
void
|
||||
WANProxyConfig::parse_set(std::deque<std::string>& tokens)
|
||||
{
|
||||
if (tokens.size() != 2) {
|
||||
ERROR(log_) << "Wrong number of words in set (" << tokens.size() << ")";
|
||||
return;
|
||||
}
|
||||
|
||||
std::string::iterator dot = std::find(tokens[0].begin(), tokens[0].end(), '.');
|
||||
if (dot == tokens[0].end()) {
|
||||
ERROR(log_) << "Identifier (" << tokens[0] << ") is not an object member identifier.";
|
||||
return;
|
||||
}
|
||||
|
||||
std::string object(tokens[0].begin(), dot);
|
||||
std::string member(dot + 1, tokens[0].end());
|
||||
if (object == "" || member == "") {
|
||||
ERROR(log_) << "Object (" << object << ") or member name (" << member << ") is empty.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!config_->set(object, member, tokens[1])) {
|
||||
ERROR(log_) << "Set of object member (" << tokens[0] << ") failed.";
|
||||
return;
|
||||
}
|
||||
tokens.clear();
|
||||
}
|
||||
|
||||
bool
|
||||
WANProxyConfig::read_file(const std::string& path)
|
||||
{
|
||||
delete config_;
|
||||
config_ = NULL;
|
||||
|
||||
INFO(log_) << "Configuring WANProxy.";
|
||||
|
||||
if (path.empty()) {
|
||||
ERROR(log_) << "No file name specified";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::fstream in;
|
||||
in.open(path.c_str(), std::ios::in);
|
||||
|
||||
if (!in.good()) {
|
||||
ERROR(log_) << "Could not open file: " << path;
|
||||
return false;
|
||||
}
|
||||
|
||||
config_ = new Config();
|
||||
config_->import(&config_class_log_mask);
|
||||
config_->import(&wanproxy_config_class_codec);
|
||||
config_->import(&wanproxy_config_class_interface);
|
||||
//config_->import(&wanproxy_config_class_monitor);
|
||||
config_->import(&wanproxy_config_class_peer);
|
||||
config_->import(&wanproxy_config_class_proxy);
|
||||
//config_->import(&wanproxy_config_class_proxy_socks);
|
||||
|
||||
std::deque<std::string> tokens;
|
||||
|
||||
while (in.good()) {
|
||||
std::string line;
|
||||
std::getline(in, line);
|
||||
|
||||
if (line[0] == '#' || line.empty())
|
||||
continue;
|
||||
|
||||
std::istringstream is(line);
|
||||
while (is.good()) {
|
||||
std::string word;
|
||||
is >> word;
|
||||
if (word.empty())
|
||||
continue;
|
||||
if (word[0] == '#')
|
||||
break;
|
||||
tokens.push_back(word);
|
||||
}
|
||||
if (tokens.empty())
|
||||
continue;
|
||||
if (!parse(tokens)) {
|
||||
ERROR(log_) << "Error in configuration directive: " << line;
|
||||
delete config_;
|
||||
config_ = NULL;
|
||||
return false;
|
||||
}
|
||||
ASSERT(log_, tokens.empty());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
59
proxy/wanproxy_config.h
Normal file
59
proxy/wanproxy_config.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2008-2011 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef PROGRAMS_WANPROXY_WANPROXY_CONFIG_H
|
||||
#define PROGRAMS_WANPROXY_WANPROXY_CONFIG_H
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: wanproxy_config.h //
|
||||
// Description: high-level configuration parser //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-04-01 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Config;
|
||||
|
||||
class WANProxyConfig {
|
||||
LogHandle log_;
|
||||
Config *config_;
|
||||
public:
|
||||
WANProxyConfig(void);
|
||||
~WANProxyConfig();
|
||||
|
||||
private:
|
||||
bool parse(std::deque<std::string>&);
|
||||
|
||||
void parse_activate(std::deque<std::string>&);
|
||||
void parse_create(std::deque<std::string>&);
|
||||
void parse_set(std::deque<std::string>&);
|
||||
|
||||
public:
|
||||
bool read_file(const std::string&);
|
||||
};
|
||||
|
||||
#endif /* !PROGRAMS_WANPROXY_WANPROXY_CONFIG_H */
|
125
proxy/wanproxy_config_class_codec.cc
Normal file
125
proxy/wanproxy_config_class_codec.cc
Normal file
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <common/buffer.h>
|
||||
#include <common/uuid/uuid.h>
|
||||
#include <config/config_class.h>
|
||||
#include <config/config_object.h>
|
||||
#include <xcodec/xcodec.h>
|
||||
#include <xcodec/xcodec_cache.h>
|
||||
#include <xcodec/cache/coss/xcodec_cache_coss.h>
|
||||
#include "wanproxy_config_class_codec.h"
|
||||
#include "wanproxy.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: wanproxy_config_class_codec.cc //
|
||||
// Description: high-level parser for xcodec-related options //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-08-31 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
WANProxyConfigClassCodec wanproxy_config_class_codec;
|
||||
|
||||
bool
|
||||
WANProxyConfigClassCodec::Instance::activate(const ConfigObject *co)
|
||||
{
|
||||
UUID uuid;
|
||||
XCodecCache* cache;
|
||||
|
||||
codec_.name_ = co->name_;
|
||||
|
||||
switch (codec_type_)
|
||||
{
|
||||
case WANProxyConfigCodecXCodec:
|
||||
/*
|
||||
* Fetch UUID from permanent storage if there is any.
|
||||
*/
|
||||
if (cache_path_.empty())
|
||||
{
|
||||
uuid.generate();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string uuid_path = cache_path_ + "/UUID";
|
||||
if (! uuid.from_file (uuid_path))
|
||||
{
|
||||
uuid.generate();
|
||||
uuid.to_file (uuid_path);
|
||||
}
|
||||
}
|
||||
|
||||
codec_.cache_type_ = cache_type_;
|
||||
codec_.cache_path_ = cache_path_;
|
||||
codec_.cache_size_ = local_size_;
|
||||
codec_.cache_uuid_ = uuid;
|
||||
|
||||
if (! (cache = wanproxy.find_cache (uuid)))
|
||||
cache = wanproxy.add_cache (cache_type_, cache_path_, local_size_, uuid);
|
||||
codec_.xcache_ = cache;
|
||||
break;
|
||||
case WANProxyConfigCodecNone:
|
||||
codec_.xcache_ = 0;
|
||||
break;
|
||||
default:
|
||||
ERROR("/wanproxy/config/codec") << "Invalid codec type.";
|
||||
return (false);
|
||||
}
|
||||
|
||||
INFO("/wanproxy/config/cache/type") << cache_type_;
|
||||
INFO("/wanproxy/config/cache/path") << cache_path_;
|
||||
INFO("/wanproxy/config/cache/size") << local_size_;
|
||||
INFO("/wanproxy/config/cache/uuid") << uuid;
|
||||
|
||||
switch (compressor_) {
|
||||
case WANProxyConfigCompressorZlib:
|
||||
if (compressor_level_ < 0 || compressor_level_ > 9) {
|
||||
ERROR("/wanproxy/config/codec") << "Compressor level must be in range 0..9 (inclusive.)";
|
||||
return (false);
|
||||
}
|
||||
|
||||
codec_.compressor_ = true;
|
||||
codec_.compressor_level_ = (char) compressor_level_;
|
||||
break;
|
||||
case WANProxyConfigCompressorNone:
|
||||
if (compressor_level_ > 0) {
|
||||
ERROR("/wanproxy/config/codec") << "Compressor level set but no compressor.";
|
||||
return (false);
|
||||
}
|
||||
|
||||
codec_.compressor_ = false;
|
||||
codec_.compressor_level_ = 0;
|
||||
break;
|
||||
default:
|
||||
ERROR("/wanproxy/config/codec") << "Invalid compressor type.";
|
||||
return (false);
|
||||
}
|
||||
|
||||
codec_.counting_ = (byte_counts_ != 0);
|
||||
|
||||
return (true);
|
||||
}
|
94
proxy/wanproxy_config_class_codec.h
Normal file
94
proxy/wanproxy_config_class_codec.h
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef PROGRAMS_WANPROXY_WANPROXY_CONFIG_CLASS_CODEC_H
|
||||
#define PROGRAMS_WANPROXY_WANPROXY_CONFIG_CLASS_CODEC_H
|
||||
|
||||
#include <config/config_type_int.h>
|
||||
#include <config/config_type_string.h>
|
||||
#include "wanproxy_codec.h"
|
||||
#include "wanproxy_config_type_codec.h"
|
||||
#include "wanproxy_config_type_compressor.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: wanproxy_config_class_codec.h //
|
||||
// Description: high-level parser for xcodec-related options //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-08-31 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class WANProxyConfigClassCodec : public ConfigClass {
|
||||
|
||||
public:
|
||||
struct Instance : public ConfigClassInstance {
|
||||
|
||||
WANProxyCodec codec_;
|
||||
WANProxyConfigCodec codec_type_;
|
||||
WANProxyConfigCompressor compressor_;
|
||||
intmax_t compressor_level_;
|
||||
intmax_t byte_counts_;
|
||||
WANProxyConfigCache cache_type_;
|
||||
std::string cache_path_;
|
||||
intmax_t local_size_;
|
||||
intmax_t remote_size_;
|
||||
|
||||
Instance(void)
|
||||
: codec_type_(WANProxyConfigCodecNone),
|
||||
compressor_(WANProxyConfigCompressorNone),
|
||||
compressor_level_(0),
|
||||
byte_counts_(0),
|
||||
cache_type_(WANProxyConfigCacheMemory),
|
||||
local_size_(0),
|
||||
remote_size_(0)
|
||||
{
|
||||
}
|
||||
|
||||
bool activate(const ConfigObject *);
|
||||
};
|
||||
|
||||
WANProxyConfigClassCodec(void)
|
||||
: ConfigClass("codec", new ConstructorFactory<ConfigClassInstance, Instance>)
|
||||
{
|
||||
add_member("codec", &wanproxy_config_type_codec, &Instance::codec_type_);
|
||||
add_member("compressor", &wanproxy_config_type_compressor, &Instance::compressor_);
|
||||
add_member("compressor_level", &config_type_int, &Instance::compressor_level_);
|
||||
add_member("byte_counts", &config_type_int, &Instance::byte_counts_);
|
||||
|
||||
add_member("cache", &wanproxy_config_type_cache, &Instance::cache_type_);
|
||||
add_member("cache_path", &config_type_string, &Instance::cache_path_);
|
||||
add_member("local_size", &config_type_int, &Instance::local_size_);
|
||||
add_member("remote_size", &config_type_int, &Instance::remote_size_);
|
||||
}
|
||||
|
||||
~WANProxyConfigClassCodec()
|
||||
{ }
|
||||
};
|
||||
|
||||
extern WANProxyConfigClassCodec wanproxy_config_class_codec;
|
||||
|
||||
#endif /* !PROGRAMS_WANPROXY_WANPROXY_CONFIG_CLASS_CODEC_H */
|
31
proxy/wanproxy_config_class_interface.cc
Normal file
31
proxy/wanproxy_config_class_interface.cc
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <config/config_class.h>
|
||||
#include <config/config_object.h>
|
||||
|
||||
#include "wanproxy_config_class_interface.h"
|
||||
|
||||
WANProxyConfigClassInterface wanproxy_config_class_interface;
|
43
proxy/wanproxy_config_class_interface.h
Normal file
43
proxy/wanproxy_config_class_interface.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef PROGRAMS_WANPROXY_WANPROXY_CONFIG_CLASS_INTERFACE_H
|
||||
#define PROGRAMS_WANPROXY_WANPROXY_CONFIG_CLASS_INTERFACE_H
|
||||
|
||||
#include <config/config_class_address.h>
|
||||
|
||||
class WANProxyConfigClassInterface : public ConfigClassAddress {
|
||||
public:
|
||||
WANProxyConfigClassInterface(void)
|
||||
: ConfigClassAddress("interface")
|
||||
{ }
|
||||
|
||||
~WANProxyConfigClassInterface()
|
||||
{ }
|
||||
};
|
||||
|
||||
extern WANProxyConfigClassInterface wanproxy_config_class_interface;
|
||||
|
||||
#endif /* !PROGRAMS_WANPROXY_WANPROXY_CONFIG_CLASS_INTERFACE_H */
|
31
proxy/wanproxy_config_class_peer.cc
Normal file
31
proxy/wanproxy_config_class_peer.cc
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <config/config_class.h>
|
||||
#include <config/config_object.h>
|
||||
|
||||
#include "wanproxy_config_class_peer.h"
|
||||
|
||||
WANProxyConfigClassPeer wanproxy_config_class_peer;
|
43
proxy/wanproxy_config_class_peer.h
Normal file
43
proxy/wanproxy_config_class_peer.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2011 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef PROGRAMS_WANPROXY_WANPROXY_CONFIG_CLASS_PEER_H
|
||||
#define PROGRAMS_WANPROXY_WANPROXY_CONFIG_CLASS_PEER_H
|
||||
|
||||
#include <config/config_class_address.h>
|
||||
|
||||
class WANProxyConfigClassPeer : public ConfigClassAddress {
|
||||
public:
|
||||
WANProxyConfigClassPeer(void)
|
||||
: ConfigClassAddress("peer")
|
||||
{ }
|
||||
|
||||
~WANProxyConfigClassPeer()
|
||||
{ }
|
||||
};
|
||||
|
||||
extern WANProxyConfigClassPeer wanproxy_config_class_peer;
|
||||
|
||||
#endif /* !PROGRAMS_WANPROXY_WANPROXY_CONFIG_CLASS_PEER_H */
|
111
proxy/wanproxy_config_class_proxy.cc
Normal file
111
proxy/wanproxy_config_class_proxy.cc
Normal file
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <common/buffer.h>
|
||||
|
||||
#include <config/config_class.h>
|
||||
#include <config/config_object.h>
|
||||
|
||||
#include <event/event_callback.h>
|
||||
#include <event/event_system.h>
|
||||
|
||||
#include <io/socket/socket_types.h>
|
||||
|
||||
#include "wanproxy_config_class_codec.h"
|
||||
#include "wanproxy_config_class_interface.h"
|
||||
#include "wanproxy_config_class_peer.h"
|
||||
#include "wanproxy_config_class_proxy.h"
|
||||
#include "wanproxy.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: wanproxy_config_class_proxy.cc //
|
||||
// Description: high-level parser for the global proxy object //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-08-31 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
WANProxyConfigClassProxy wanproxy_config_class_proxy;
|
||||
|
||||
bool
|
||||
WANProxyConfigClassProxy::Instance::activate(const ConfigObject *co)
|
||||
{
|
||||
WANProxyConfigClassInterface::Instance *interface =
|
||||
dynamic_cast<WANProxyConfigClassInterface::Instance *>(interface_->instance_);
|
||||
if (interface == NULL)
|
||||
return (false);
|
||||
|
||||
if (interface->host_ == "" || interface->port_ == "")
|
||||
return (false);
|
||||
|
||||
WANProxyCodec *interface_codec;
|
||||
if (interface_codec_ != NULL) {
|
||||
WANProxyConfigClassCodec::Instance *codec =
|
||||
dynamic_cast<WANProxyConfigClassCodec::Instance *>(interface_codec_->instance_);
|
||||
if (codec == NULL)
|
||||
return (false);
|
||||
interface_codec = &codec->codec_;
|
||||
} else {
|
||||
interface_codec = NULL;
|
||||
}
|
||||
|
||||
WANProxyConfigClassPeer::Instance *peer =
|
||||
dynamic_cast<WANProxyConfigClassPeer::Instance *>(peer_->instance_);
|
||||
if (peer == NULL)
|
||||
return (false);
|
||||
|
||||
if (peer->host_ == "" || peer->port_ == "")
|
||||
return (false);
|
||||
|
||||
WANProxyCodec *peer_codec;
|
||||
if (peer_codec_ != NULL) {
|
||||
WANProxyConfigClassCodec::Instance *codec =
|
||||
dynamic_cast<WANProxyConfigClassCodec::Instance *>(peer_codec_->instance_);
|
||||
if (codec == NULL)
|
||||
return (false);
|
||||
peer_codec = &codec->codec_;
|
||||
} else {
|
||||
peer_codec = NULL;
|
||||
}
|
||||
|
||||
if (role_ == WANProxyConfigProxyRoleUndefined && ! interface_codec && peer_codec)
|
||||
role_ = WANProxyConfigProxyRoleClient;
|
||||
|
||||
WanProxyInstance ins;
|
||||
ins.proxy_name_ = co->name_;
|
||||
ins.proxy_client_ = (role_ == WANProxyConfigProxyRoleClient);
|
||||
ins.proxy_secure_ = (type_ == WANProxyConfigProxyTypeSSHSSH);
|
||||
ins.local_protocol_ = interface->family_;
|
||||
ins.local_address_ = '[' + interface->host_ + ']' + ':' + interface->port_;
|
||||
ins.local_codec_ = (interface_codec ? *interface_codec : WANProxyCodec ());
|
||||
ins.remote_protocol_ = peer->family_;
|
||||
ins.remote_address_ = '[' + peer->host_ + ']' + ':' + peer->port_;
|
||||
ins.remote_codec_ = (peer_codec ? *peer_codec : WANProxyCodec ());
|
||||
wanproxy.add_proxy (ins.proxy_name_, ins);
|
||||
|
||||
return (true);
|
||||
}
|
83
proxy/wanproxy_config_class_proxy.h
Normal file
83
proxy/wanproxy_config_class_proxy.h
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef PROGRAMS_WANPROXY_WANPROXY_CONFIG_CLASS_PROXY_H
|
||||
#define PROGRAMS_WANPROXY_WANPROXY_CONFIG_CLASS_PROXY_H
|
||||
|
||||
#include <config/config_type_pointer.h>
|
||||
|
||||
#include "wanproxy_config_type_proxy_type.h"
|
||||
#include "wanproxy_config_type_proxy_role.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: wanproxy_config_class_proxy.h //
|
||||
// Description: high-level parser for the global proxy object //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-08-31 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class WANProxyConfigClassProxy : public ConfigClass {
|
||||
struct Instance : public ConfigClassInstance {
|
||||
WANProxyConfigProxyType type_;
|
||||
WANProxyConfigProxyRole role_;
|
||||
ConfigObject *interface_;
|
||||
ConfigObject *interface_codec_;
|
||||
ConfigObject *peer_;
|
||||
ConfigObject *peer_codec_;
|
||||
|
||||
Instance(void)
|
||||
: type_(WANProxyConfigProxyTypeTCPTCP),
|
||||
role_(WANProxyConfigProxyRoleUndefined),
|
||||
interface_(NULL),
|
||||
interface_codec_(NULL),
|
||||
peer_(NULL),
|
||||
peer_codec_(NULL)
|
||||
{ }
|
||||
|
||||
bool activate(const ConfigObject *);
|
||||
};
|
||||
public:
|
||||
WANProxyConfigClassProxy(void)
|
||||
: ConfigClass("proxy", new ConstructorFactory<ConfigClassInstance, Instance>)
|
||||
{
|
||||
add_member("type", &wanproxy_config_type_proxy_type, &Instance::type_);
|
||||
add_member("role", &wanproxy_config_type_proxy_role, &Instance::role_);
|
||||
add_member("interface", &config_type_pointer, &Instance::interface_);
|
||||
add_member("interface_codec", &config_type_pointer, &Instance::interface_codec_);
|
||||
add_member("peer", &config_type_pointer, &Instance::peer_);
|
||||
add_member("peer_codec", &config_type_pointer, &Instance::peer_codec_);
|
||||
}
|
||||
|
||||
/* XXX So wrong. */
|
||||
~WANProxyConfigClassProxy()
|
||||
{ }
|
||||
};
|
||||
|
||||
extern WANProxyConfigClassProxy wanproxy_config_class_proxy;
|
||||
|
||||
#endif /* !PROGRAMS_WANPROXY_WANPROXY_CONFIG_CLASS_PROXY_H */
|
44
proxy/wanproxy_config_type_codec.cc
Normal file
44
proxy/wanproxy_config_type_codec.cc
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2009 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "wanproxy_config_type_codec.h"
|
||||
|
||||
static struct WANProxyConfigTypeCodec::Mapping wanproxy_config_type_codec_map[] = {
|
||||
{ "XCodec", WANProxyConfigCodecXCodec },
|
||||
{ "None", WANProxyConfigCodecNone },
|
||||
{ NULL, WANProxyConfigCodecNone }
|
||||
};
|
||||
|
||||
WANProxyConfigTypeCodec
|
||||
wanproxy_config_type_codec("codec", wanproxy_config_type_codec_map);
|
||||
|
||||
static struct WANProxyConfigTypeCache::Mapping wanproxy_config_type_cache_map[] = {
|
||||
{ "Memory", WANProxyConfigCacheMemory },
|
||||
{ "COSS", WANProxyConfigCacheCOSS },
|
||||
{ NULL, WANProxyConfigCacheMemory }
|
||||
};
|
||||
|
||||
WANProxyConfigTypeCache
|
||||
wanproxy_config_type_cache("cache", wanproxy_config_type_cache_map);
|
50
proxy/wanproxy_config_type_codec.h
Normal file
50
proxy/wanproxy_config_type_codec.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2011 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef PROGRAMS_WANPROXY_WANPROXY_CONFIG_TYPE_CODEC_H
|
||||
#define PROGRAMS_WANPROXY_WANPROXY_CONFIG_TYPE_CODEC_H
|
||||
|
||||
#include <config/config_type_enum.h>
|
||||
|
||||
enum WANProxyConfigCodec {
|
||||
WANProxyConfigCodecNone,
|
||||
WANProxyConfigCodecXCodec
|
||||
};
|
||||
|
||||
typedef ConfigTypeEnum<WANProxyConfigCodec> WANProxyConfigTypeCodec;
|
||||
|
||||
extern WANProxyConfigTypeCodec wanproxy_config_type_codec;
|
||||
|
||||
enum WANProxyConfigCache {
|
||||
WANProxyConfigCacheMemory,
|
||||
WANProxyConfigCacheCOSS
|
||||
};
|
||||
|
||||
typedef ConfigTypeEnum<WANProxyConfigCache> WANProxyConfigTypeCache;
|
||||
|
||||
extern WANProxyConfigTypeCache wanproxy_config_type_cache;
|
||||
|
||||
#endif /* !PROGRAMS_WANPROXY_WANPROXY_CONFIG_TYPE_CODEC_H */
|
||||
|
35
proxy/wanproxy_config_type_compressor.cc
Normal file
35
proxy/wanproxy_config_type_compressor.cc
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2010 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "wanproxy_config_type_compressor.h"
|
||||
|
||||
static struct WANProxyConfigTypeCompressor::Mapping wanproxy_config_type_compressor_map[] = {
|
||||
{ "zlib", WANProxyConfigCompressorZlib },
|
||||
{ "None", WANProxyConfigCompressorNone },
|
||||
{ NULL, WANProxyConfigCompressorNone }
|
||||
};
|
||||
|
||||
WANProxyConfigTypeCompressor
|
||||
wanproxy_config_type_compressor("compressor", wanproxy_config_type_compressor_map);
|
40
proxy/wanproxy_config_type_compressor.h
Normal file
40
proxy/wanproxy_config_type_compressor.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2011 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef PROGRAMS_WANPROXY_WANPROXY_CONFIG_TYPE_COMPRESSOR_H
|
||||
#define PROGRAMS_WANPROXY_WANPROXY_CONFIG_TYPE_COMPRESSOR_H
|
||||
|
||||
#include <config/config_type_enum.h>
|
||||
|
||||
enum WANProxyConfigCompressor {
|
||||
WANProxyConfigCompressorNone,
|
||||
WANProxyConfigCompressorZlib
|
||||
};
|
||||
|
||||
typedef ConfigTypeEnum<WANProxyConfigCompressor> WANProxyConfigTypeCompressor;
|
||||
|
||||
extern WANProxyConfigTypeCompressor wanproxy_config_type_compressor;
|
||||
|
||||
#endif /* !PROGRAMS_WANPROXY_WANPROXY_CONFIG_TYPE_COMPRESSOR_H */
|
35
proxy/wanproxy_config_type_proxy_role.cc
Normal file
35
proxy/wanproxy_config_type_proxy_role.cc
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2012 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "wanproxy_config_type_proxy_role.h"
|
||||
|
||||
static struct WANProxyConfigTypeProxyRole::Mapping wanproxy_config_type_proxy_role_map[] = {
|
||||
{ "Client", WANProxyConfigProxyRoleClient },
|
||||
{ "Server", WANProxyConfigProxyRoleServer },
|
||||
{ NULL, WANProxyConfigProxyRoleUndefined }
|
||||
};
|
||||
|
||||
WANProxyConfigTypeProxyRole
|
||||
wanproxy_config_type_proxy_role ("proxy_role", wanproxy_config_type_proxy_role_map);
|
51
proxy/wanproxy_config_type_proxy_role.h
Normal file
51
proxy/wanproxy_config_type_proxy_role.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2012 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef PROGRAMS_WANPROXY_WANPROXY_CONFIG_TYPE_PROXY_ROLE_H
|
||||
#define PROGRAMS_WANPROXY_WANPROXY_CONFIG_TYPE_PROXY_ROLE_H
|
||||
|
||||
#include <config/config_type_enum.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: wanproxy_config_type_proxy_role.h //
|
||||
// Description: a type to signal if the proxy is acting as a client //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-04-01 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum WANProxyConfigProxyRole {
|
||||
WANProxyConfigProxyRoleUndefined,
|
||||
WANProxyConfigProxyRoleClient,
|
||||
WANProxyConfigProxyRoleServer
|
||||
};
|
||||
|
||||
typedef ConfigTypeEnum<WANProxyConfigProxyRole> WANProxyConfigTypeProxyRole;
|
||||
|
||||
extern WANProxyConfigTypeProxyRole wanproxy_config_type_proxy_role;
|
||||
|
||||
#endif /* !PROGRAMS_WANPROXY_WANPROXY_CONFIG_TYPE_PROXY_ROLE_H */
|
37
proxy/wanproxy_config_type_proxy_type.cc
Normal file
37
proxy/wanproxy_config_type_proxy_type.cc
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2012 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "wanproxy_config_type_proxy_type.h"
|
||||
|
||||
static struct WANProxyConfigTypeProxyType::Mapping wanproxy_config_type_proxy_type_map[] = {
|
||||
{ "TCP", WANProxyConfigProxyTypeTCPTCP },
|
||||
{ "TCP-TCP", WANProxyConfigProxyTypeTCPTCP },
|
||||
{ "SSH", WANProxyConfigProxyTypeSSHSSH },
|
||||
{ "SSH-SSH", WANProxyConfigProxyTypeSSHSSH },
|
||||
{ NULL, WANProxyConfigProxyTypeTCPTCP }
|
||||
};
|
||||
|
||||
WANProxyConfigTypeProxyType
|
||||
wanproxy_config_type_proxy_type("proxy_type", wanproxy_config_type_proxy_type_map);
|
40
proxy/wanproxy_config_type_proxy_type.h
Normal file
40
proxy/wanproxy_config_type_proxy_type.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2012 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef PROGRAMS_WANPROXY_WANPROXY_CONFIG_TYPE_PROXY_TYPE_H
|
||||
#define PROGRAMS_WANPROXY_WANPROXY_CONFIG_TYPE_PROXY_TYPE_H
|
||||
|
||||
#include <config/config_type_enum.h>
|
||||
|
||||
enum WANProxyConfigProxyType {
|
||||
WANProxyConfigProxyTypeTCPTCP,
|
||||
WANProxyConfigProxyTypeSSHSSH,
|
||||
};
|
||||
|
||||
typedef ConfigTypeEnum<WANProxyConfigProxyType> WANProxyConfigTypeProxyType;
|
||||
|
||||
extern WANProxyConfigTypeProxyType wanproxy_config_type_proxy_type;
|
||||
|
||||
#endif /* !PROGRAMS_WANPROXY_WANPROXY_CONFIG_TYPE_PROXY_TYPE_H */
|
Loading…
Add table
Add a link
Reference in a new issue