[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[certi-cvs] certi RTIA/Communications.cc RTIA/Communication...
From: |
certi-cvs |
Subject: |
[certi-cvs] certi RTIA/Communications.cc RTIA/Communication... |
Date: |
Sun, 12 Oct 2008 11:46:42 +0000 |
CVSROOT: /sources/certi
Module name: certi
Changes by: Petr Gotthard <gotthardp> 08/10/12 11:46:42
Modified files:
RTIA : Communications.cc Communications.hh
libCERTI : CMakeLists.txt Socket.hh SocketTCP.cc
SocketTCP.hh SocketUDP.cc SocketUDP.hh
Added files:
libCERTI : SocketHTTPProxy.cc SocketHTTPProxy.hh
Log message:
Patch #6561: Implemented support for RTIA-->RTIG connections via a HTTP
proxy
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/RTIA/Communications.cc?cvsroot=certi&r1=3.32&r2=3.33
http://cvs.savannah.gnu.org/viewcvs/certi/RTIA/Communications.hh?cvsroot=certi&r1=3.16&r2=3.17
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/CMakeLists.txt?cvsroot=certi&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/Socket.hh?cvsroot=certi&r1=3.13&r2=3.14
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketTCP.cc?cvsroot=certi&r1=3.25&r2=3.26
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketTCP.hh?cvsroot=certi&r1=3.21&r2=3.22
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketUDP.cc?cvsroot=certi&r1=3.22&r2=3.23
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketUDP.hh?cvsroot=certi&r1=3.11&r2=3.12
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketHTTPProxy.cc?cvsroot=certi&rev=3.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketHTTPProxy.hh?cvsroot=certi&rev=3.1
Patches:
Index: RTIA/Communications.cc
===================================================================
RCS file: /sources/certi/certi/RTIA/Communications.cc,v
retrieving revision 3.32
retrieving revision 3.33
diff -u -b -r3.32 -r3.33
--- RTIA/Communications.cc 11 Oct 2008 12:53:52 -0000 3.32
+++ RTIA/Communications.cc 12 Oct 2008 11:46:39 -0000 3.33
@@ -18,7 +18,7 @@
// along with this program ; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// $Id: Communications.cc,v 3.32 2008/10/11 12:53:52 gotthardp Exp $
+// $Id: Communications.cc,v 3.33 2008/10/12 11:46:39 gotthardp Exp $
// ----------------------------------------------------------------------------
#include <config.h>
@@ -27,6 +27,9 @@
#include "PrettyDebug.hh"
#include "NM_Classes.hh"
+#include "SocketHTTPProxy.hh"
+#include "SecureTCPSocket.hh"
+
#ifdef _WIN32
#include <windows.h>
#ifdef max
@@ -99,7 +102,14 @@
#ifdef FEDERATION_USES_MULTICAST
socketMC = new SocketMC();
#endif
+ if(getenv("CERTI_HTTP_PROXY") != NULL || getenv("http_proxy") != NULL)
+ socketTCP = new SocketHTTPProxy();
+ else
+#ifdef WITH_GSSAPI
socketTCP = new SecureTCPSocket();
+#else
+ socketTCP = new SocketTCP();
+#endif
socketUDP = new SocketUDP();
// Federate/RTIA link creation.
@@ -126,8 +136,8 @@
if (tcp_port==NULL) tcp_port = PORT_TCP_RTIG ;
if (udp_port==NULL) udp_port = PORT_UDP_RTIG ;
- socketTCP->createTCPClient(atoi(tcp_port), certihost);
- socketUDP->createUDPClient(atoi(udp_port), certihost);
+ socketTCP->createConnection(certihost, atoi(tcp_port));
+ socketUDP->createConnection(certihost, atoi(udp_port));
}
// ----------------------------------------------------------------------------
@@ -352,4 +362,4 @@
}} // namespace certi/rtia
-// $Id: Communications.cc,v 3.32 2008/10/11 12:53:52 gotthardp Exp $
+// $Id: Communications.cc,v 3.33 2008/10/12 11:46:39 gotthardp Exp $
Index: RTIA/Communications.hh
===================================================================
RCS file: /sources/certi/certi/RTIA/Communications.hh,v
retrieving revision 3.16
retrieving revision 3.17
diff -u -b -r3.16 -r3.17
--- RTIA/Communications.hh 11 Oct 2008 12:53:52 -0000 3.16
+++ RTIA/Communications.hh 12 Oct 2008 11:46:39 -0000 3.17
@@ -18,7 +18,7 @@
// along with this program ; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// $Id: Communications.hh,v 3.16 2008/10/11 12:53:52 gotthardp Exp $
+// $Id: Communications.hh,v 3.17 2008/10/12 11:46:39 gotthardp Exp $
// ----------------------------------------------------------------------------
#ifndef _CERTI_COMMUNICATIONS_HH
@@ -28,7 +28,7 @@
#include "NetworkMessage.hh"
#include "Message.hh"
#include "SocketUN.hh"
-#include "SecureTCPSocket.hh"
+#include "SocketTCP.hh"
#include "SocketUDP.hh"
#ifdef FEDERATION_USES_MULTICAST
#include "SocketMC.hh"
@@ -91,4 +91,4 @@
#endif // _CERTI_COMMUNICATIONS_HH
-// $Id: Communications.hh,v 3.16 2008/10/11 12:53:52 gotthardp Exp $
+// $Id: Communications.hh,v 3.17 2008/10/12 11:46:39 gotthardp Exp $
Index: libCERTI/CMakeLists.txt
===================================================================
RCS file: /sources/certi/certi/libCERTI/CMakeLists.txt,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- libCERTI/CMakeLists.txt 10 Oct 2008 11:29:06 -0000 1.16
+++ libCERTI/CMakeLists.txt 12 Oct 2008 11:46:40 -0000 1.17
@@ -102,6 +102,7 @@
SocketTCP.cc
SecureTCPSocket.cc
SecurityServer.cc
+SocketHTTPProxy.cc SocketHTTPProxy.hh
GSSAPIHandler.cc
SocketServer.hh
SocketTCP.hh
Index: libCERTI/Socket.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Socket.hh,v
retrieving revision 3.13
retrieving revision 3.14
diff -u -b -r3.13 -r3.14
--- libCERTI/Socket.hh 20 Nov 2007 09:04:54 -0000 3.13
+++ libCERTI/Socket.hh 12 Oct 2008 11:46:40 -0000 3.14
@@ -45,7 +45,9 @@
typedef unsigned long ByteCount_t;
virtual ~Socket() {};
- virtual void send(const unsigned char *, size_t) = 0 ;
+ virtual void createConnection(const char *server_name, unsigned int port)
+ throw (NetworkError) = 0;
+ virtual void send(const unsigned char *, size_t) = 0;
virtual void receive(void *Buffer, unsigned long Size) = 0 ;
virtual void close() = 0 ;
Index: libCERTI/SocketTCP.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/SocketTCP.cc,v
retrieving revision 3.25
retrieving revision 3.26
diff -u -b -r3.25 -r3.26
--- libCERTI/SocketTCP.cc 24 Jun 2008 09:09:14 -0000 3.25
+++ libCERTI/SocketTCP.cc 12 Oct 2008 11:46:41 -0000 3.26
@@ -17,7 +17,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: SocketTCP.cc,v 3.25 2008/06/24 09:09:14 erk Exp $
+// $Id: SocketTCP.cc,v 3.26 2008/10/12 11:46:41 gotthardp Exp $
// ----------------------------------------------------------------------------
#ifdef _WIN32
@@ -262,17 +262,17 @@
// ----------------------------------------------------------------------------
void
-SocketTCP::createTCPClient(in_port_t port, const char *nom_serveur)
-throw (NetworkError)
+SocketTCP::createConnection(const char *server_name, unsigned int port)
+ throw (NetworkError)
{
std::stringstream msg;
// get host information from server name
// this may perform DNS query
- struct hostent *hptr = gethostbyname(nom_serveur);
+ struct hostent *hptr = gethostbyname(server_name);
if (NULL == hptr)
{
msg << "gethostbyname gave NULL answer for hostname <"
- << nom_serveur
+ << server_name
<< "> with error <"
<< strerror(errno)
<< ">";
@@ -597,4 +597,4 @@
} // namespace
-// $Id: SocketTCP.cc,v 3.25 2008/06/24 09:09:14 erk Exp $
+// $Id: SocketTCP.cc,v 3.26 2008/10/12 11:46:41 gotthardp Exp $
Index: libCERTI/SocketTCP.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/SocketTCP.hh,v
retrieving revision 3.21
retrieving revision 3.22
diff -u -b -r3.21 -r3.22
--- libCERTI/SocketTCP.hh 24 Jun 2008 08:56:49 -0000 3.21
+++ libCERTI/SocketTCP.hh 12 Oct 2008 11:46:41 -0000 3.22
@@ -52,7 +52,8 @@
virtual ~SocketTCP();
virtual void close();
- void createTCPClient(in_port_t port, const char *nom_serveur) throw
(NetworkError);
+ virtual void createConnection(const char *server_name, unsigned int port)
+ throw (NetworkError);
void createTCPClient(in_port_t port, in_addr_t addr) throw
(NetworkError);
void createTCPServer(in_port_t port = 0, in_addr_t addr = INADDR_ANY)
throw (NetworkError);
@@ -76,6 +77,12 @@
virtual int returnSocket() ;
#endif
+protected:
+ int timeoutTCP(int, int);
+
+ ByteCount_t SentBytesCount;
+ ByteCount_t RcvdBytesCount;
+
private:
int open();
int connect(in_port_t port, in_addr_t addr);
@@ -84,7 +91,6 @@
void setPort(in_port_t port);
in_port_t getPort() const ;
in_addr_t getAddr() const ;
- int timeoutTCP(int, int);
#ifdef _WIN32
SOCKET _socket_tcp;
@@ -92,8 +98,6 @@
#else
long _socket_tcp;
#endif
- ByteCount_t SentBytesCount;
- ByteCount_t RcvdBytesCount;
bool _est_init_tcp;
struct sockaddr_in _sockIn;
Index: libCERTI/SocketUDP.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/SocketUDP.cc,v
retrieving revision 3.22
retrieving revision 3.23
diff -u -b -r3.22 -r3.23
--- libCERTI/SocketUDP.cc 21 Sep 2008 16:46:25 -0000 3.22
+++ libCERTI/SocketUDP.cc 12 Oct 2008 11:46:41 -0000 3.23
@@ -85,9 +85,8 @@
// ----------------------------------------------------------------------------
//! Create an UDP client.
void
-SocketUDP::createUDPClient(unsigned int, // port
- const char *) // nom serveur
- throw (NetworkError, NetworkSignal)
+SocketUDP::createConnection(const char *server_name, unsigned int port)
+ throw (NetworkError)
{
// unsigned long addr = 0 ;
struct sockaddr_in sock_temp ;
Index: libCERTI/SocketUDP.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/SocketUDP.hh,v
retrieving revision 3.11
retrieving revision 3.12
diff -u -b -r3.11 -r3.12
--- libCERTI/SocketUDP.hh 29 Apr 2008 09:38:33 -0000 3.11
+++ libCERTI/SocketUDP.hh 12 Oct 2008 11:46:41 -0000 3.12
@@ -63,8 +63,8 @@
virtual void close();
// SocketUDP
- void createUDPClient(unsigned int port, const char *nom_serveur)
- throw (NetworkError, NetworkSignal);
+ virtual void createConnection(const char *server_name, unsigned int port)
+ throw (NetworkError);
void createUDPServer(unsigned int port)
throw (NetworkError, NetworkSignal);
Index: libCERTI/SocketHTTPProxy.cc
===================================================================
RCS file: libCERTI/SocketHTTPProxy.cc
diff -N libCERTI/SocketHTTPProxy.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SocketHTTPProxy.cc 12 Oct 2008 11:46:40 -0000 3.1
@@ -0,0 +1,186 @@
+// ----------------------------------------------------------------------------
+// CERTI - HLA RunTime Infrastructure
+// Copyright (C) 2002-2005 ONERA
+//
+// This program is free software ; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation ; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY ; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program ; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA
+//
+// $Id: SocketHTTPProxy.cc,v 3.1 2008/10/12 11:46:40 gotthardp Exp $
+// ----------------------------------------------------------------------------
+
+#include "SocketHTTPProxy.hh"
+#include "PrettyDebug.hh"
+
+#include <cstdlib>
+#include <cstring>
+#include <cerrno>
+
+namespace certi {
+
+static PrettyDebug D("SOCKHTTP", "(SocketHTTPProxy) - ");
+static PrettyDebug G("GENDOC",__FILE__);
+
+// ----------------------------------------------------------------------------
+SocketHTTPProxy::SocketHTTPProxy() : SocketTCP()
+{
+}
+
+// ----------------------------------------------------------------------------
+SocketHTTPProxy::~SocketHTTPProxy()
+{
+}
+
+// ----------------------------------------------------------------------------
+void
+SocketHTTPProxy::createConnection(const char *server_name, unsigned int port)
+ throw (NetworkError)
+{
+ const char *http_proxy;
+ // check if proxy is requested
+ http_proxy = getenv("CERTI_HTTP_PROXY");
+ if (http_proxy == NULL)
+ http_proxy = getenv("http_proxy"); // global settings
+
+ if (http_proxy != NULL) {
+ std::string proxy_address;
+ in_port_t proxy_port;
+
+ const char *strpport = strchr(http_proxy, ':');
+ if (strpport) {
+ proxy_address.assign(http_proxy, strpport-http_proxy);
+ proxy_port = atoi(strpport+1);
+ }
+ else {
+ proxy_address.assign(http_proxy);
+ proxy_port = 3128;
+ }
+
+ D.Out(pdTrace, "Connect to '%s:%d' via 'http://%s:%d'.",
+ server_name, port, proxy_address.c_str(), proxy_port);
+ SocketTCP::createConnection(proxy_address.c_str(), proxy_port);
+ sendHTTPConnect(server_name, port);
+ }
+ else {
+ D.Out(pdTrace, "Connect to '%s:%d'.", server_name, port);
+ SocketTCP::createConnection(server_name, port);
+ }
+}
+
+// ----------------------------------------------------------------------------
+int SocketHTTPProxy::sendHTTPConnect(const char* addr, in_port_t port)
+{
+ std::stringstream request;
+ // build the HTTP request
+ request
+ << "CONNECT " << addr << ":" << port << " HTTP/1.0\x0D\x0A"
+ << "Host: " << addr << ":" << port << "\x0D\x0A"
+ << "\x0D\x0A";
+
+ D.Out(pdTrace, "HTTP proxy connection request\n%s<",
+ request.str().c_str());
+ // send the HTTP reuqest
+ send((const unsigned char*)request.str().c_str(), request.str().length());
+
+ size_t received;
+ static const size_t maxLineLength = 1024;
+ char response[maxLineLength];
+
+ // wait for the HTTP response
+ timeoutTCP(5,0);
+ // receive the HTTP response line
+ received = receiveLine(response, maxLineLength);
+ D.Out(pdTrace, "<HTTP PROXY> %s", response);
+
+ char* sCode;
+ // the response line must be "HTTP/<version> <code> <reason>"
+ if (received < 5 || strncmp(response,"HTTP/",5) != 0 ||
+ (sCode = strchr(response, ' ')) == NULL) {
+ D.Out(pdDebug, "Unexpected HTTP response.");
+ throw NetworkError("Unexpected HTTP response.");
+ }
+
+ int iCode = atoi(sCode);
+ // the response code must be 2xx
+ if (iCode < 200 || iCode >= 300) {
+ std::stringstream msg;
+ msg << "Proxy connection refused: " << response;
+ D.Out(pdDebug, "%s", msg.str().c_str());
+ throw NetworkError(msg.str().c_str());
+ }
+
+ // receive the rest of the HTTP response
+ // we wait for an empty line
+ do {
+ timeoutTCP(5,0);
+ // receive the HTTP header
+ received = receiveLine(response, maxLineLength);
+ D.Out(pdTrace, "<HTTP PROXY> %s", response);
+ }
+ while (received > 0);
+
+ return 1;
+}
+
+// ----------------------------------------------------------------------------
+size_t
+SocketHTTPProxy::receiveLine(char *buffer, size_t max_size)
+ throw (NetworkError, NetworkSignal)
+{
+ size_t nReceived = 0;
+ while (nReceived < max_size-1)
+ {
+ int result = ::recv(SocketTCP::returnSocket(), buffer+nReceived, 1, 0);
+ if (result < 0)
+ {
+ D.Out(pdExcept, "Error while receiving on TCP socket.");
+#ifdef _WIN32
+ if (WSAGetLastError() == WSAEINTR)
+#else
+ if (errno == EINTR)
+#endif
+ throw NetworkSignal("");
+ else {
+ perror("TCP Socket(RecevoirTCP) ");
+ throw NetworkError("Error while receiving TCP message.");
+ }
+ }
+ else if (result == 0) {
+ D.Out(pdExcept, "TCP connection has been closed by peer.");
+ throw NetworkError("Connection closed by client.");
+ }
+
+ nReceived += result;
+ // update statistics
+ RcvdBytesCount += result;
+
+ if (buffer[nReceived-1] == '\x0A') {
+ // strip trailing CRLF and terminate the received string
+ if(nReceived > 1 && buffer[nReceived-2] == '\x0D') {
+ buffer[nReceived-2] = 0;
+ return nReceived-2;
+ }
+ else {
+ buffer[nReceived-1] = 0;
+ return nReceived-1;
+ }
+ }
+ }
+
+ throw NetworkError("Too large HTTP response received.");
+}
+
+} // namespace
+
+// $Id: SocketHTTPProxy.cc,v 3.1 2008/10/12 11:46:40 gotthardp Exp $
Index: libCERTI/SocketHTTPProxy.hh
===================================================================
RCS file: libCERTI/SocketHTTPProxy.hh
diff -N libCERTI/SocketHTTPProxy.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SocketHTTPProxy.hh 12 Oct 2008 11:46:41 -0000 3.1
@@ -0,0 +1,44 @@
+// ----------------------------------------------------------------------------
+// CERTI - HLA RunTime Infrastructure
+// Copyright (C) 2002-2005 ONERA
+//
+// This program is free software ; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation ; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY ; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program ; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// ----------------------------------------------------------------------------
+
+#ifndef CERTI_SOCKET_HTTP_PROXY_HH
+#define CERTI_SOCKET_HTTP_PROXY_HH
+
+#include "SocketTCP.hh"
+
+namespace certi {
+
+class CERTI_EXPORT SocketHTTPProxy : public SocketTCP
+{
+public :
+ SocketHTTPProxy();
+ virtual ~SocketHTTPProxy();
+
+ virtual void createConnection(const char *server_name, unsigned int port)
+ throw (NetworkError);
+
+protected:
+ int sendHTTPConnect(const char* addr, in_port_t port);
+ size_t receiveLine(char *Buffer, size_t maxSize) throw (NetworkError,
NetworkSignal);
+};
+
+} // namespace certi
+
+#endif // CERTI_SOCKET_HTTP_PROXY_HH
+