version 1.59, 2008/12/16 18:56:47
|
version 1.60, 2015/06/10 12:36:02
|
|
|
#include <Pegasus/Common/SSLContext.h> | #include <Pegasus/Common/SSLContext.h> |
#include <Pegasus/Common/Monitor.h> | #include <Pegasus/Common/Monitor.h> |
#include <Pegasus/Common/HTTPAcceptor.h> | #include <Pegasus/Common/HTTPAcceptor.h> |
|
#include <Pegasus/Common/HostAddress.h> |
#include <Pegasus/Common/PegasusVersion.h> | #include <Pegasus/Common/PegasusVersion.h> |
#include <Pegasus/Common/MessageLoader.h> | #include <Pegasus/Common/MessageLoader.h> |
#include <Pegasus/Common/Time.h> | #include <Pegasus/Common/Time.h> |
|
|
class CIMListenerService | class CIMListenerService |
{ | { |
public: | public: |
|
CIMListenerService( |
|
const String &listenAddress, |
|
Uint32 portNumber, |
|
SSLContext * sslContext = NULL); |
CIMListenerService(Uint32 portNumber, SSLContext * sslContext = NULL); | CIMListenerService(Uint32 portNumber, SSLContext * sslContext = NULL); |
CIMListenerService(CIMListenerService & svc); | CIMListenerService(CIMListenerService & svc); |
~CIMListenerService(); | ~CIMListenerService(); |
|
|
*/ | */ |
void setIndicationDispatcher(CIMListenerIndicationDispatcher* dispatcher); | void setIndicationDispatcher(CIMListenerIndicationDispatcher* dispatcher); |
| |
|
/** Returns the bind address. |
|
*/ |
|
String getListenAddress() const; |
|
|
/** Returns the port number being used. | /** Returns the port number being used. |
*/ | */ |
Uint32 getPortNumber() const; | Uint32 getPortNumber() const; |
|
|
_listener_routine(void *param); | _listener_routine(void *param); |
| |
private: | private: |
|
String _listenAddress; |
Uint32 _portNumber; | Uint32 _portNumber; |
SSLContext *_sslContext; | SSLContext *_sslContext; |
ReadWriteSem _sslContextObjectLock; | ReadWriteSem _sslContextObjectLock; |
|
|
}; | }; |
| |
CIMListenerService::CIMListenerService( | CIMListenerService::CIMListenerService( |
|
const String &listenAddress, |
Uint32 portNumber, | Uint32 portNumber, |
SSLContext * sslContext) | SSLContext * sslContext) |
: | : |
|
_listenAddress(listenAddress), |
|
_portNumber(portNumber), |
|
_sslContext(sslContext), |
|
_monitor(NULL), |
|
_ip6Acceptor(NULL), |
|
_ip4Acceptor(NULL), |
|
_dieNow(false), |
|
_dispatcher(NULL), |
|
_responseEncoder(NULL), |
|
_requestDecoder(NULL) |
|
{ |
|
} |
|
|
|
CIMListenerService::CIMListenerService( |
|
Uint32 portNumber, |
|
SSLContext * sslContext) |
|
: |
|
_listenAddress(), |
_portNumber(portNumber), | _portNumber(portNumber), |
_sslContext(sslContext), | _sslContext(sslContext), |
_monitor(NULL), | _monitor(NULL), |
|
|
} | } |
| |
CIMListenerService::CIMListenerService(CIMListenerService & svc) : | CIMListenerService::CIMListenerService(CIMListenerService & svc) : |
|
_listenAddress(svc._listenAddress), |
_portNumber(svc._portNumber), | _portNumber(svc._portNumber), |
_sslContext(svc._sslContext), | _sslContext(svc._sslContext), |
_monitor(NULL), | _monitor(NULL), |
|
|
_requestDecoder = new CIMExportRequestDecoder( | _requestDecoder = new CIMExportRequestDecoder( |
_dispatcher, _responseEncoder->getQueueId()); | _dispatcher, _responseEncoder->getQueueId()); |
} | } |
|
|
|
HostAddress listenAddress; |
|
Boolean listenAddressEmpty = _listenAddress == String::EMPTY; |
|
if (!listenAddressEmpty) |
|
listenAddress.setHostAddress(_listenAddress); |
|
|
#ifdef PEGASUS_ENABLE_IPV6 | #ifdef PEGASUS_ENABLE_IPV6 |
if (System::isIPv6StackActive()) |
if (System::isIPv6StackActive() && |
|
(listenAddressEmpty || |
|
(listenAddress.isValid() && |
|
listenAddress.getAddressType() == HostAddress::AT_IPV6))) |
{ | { |
if (NULL == _ip6Acceptor) | if (NULL == _ip6Acceptor) |
{ | { |
|
|
_ip6Acceptor = new HTTPAcceptor( | _ip6Acceptor = new HTTPAcceptor( |
_monitor, _requestDecoder, | _monitor, _requestDecoder, |
HTTPAcceptor::IPV6_CONNECTION, | HTTPAcceptor::IPV6_CONNECTION, |
_portNumber, 0, 0); |
_portNumber, 0, 0, |
|
listenAddressEmpty ? 0 : &listenAddress); |
} | } |
else | else |
{ | { |
_ip6Acceptor = new HTTPAcceptor( | _ip6Acceptor = new HTTPAcceptor( |
_monitor, _requestDecoder, | _monitor, _requestDecoder, |
HTTPAcceptor::IPV6_CONNECTION, | HTTPAcceptor::IPV6_CONNECTION, |
_portNumber, _sslContext, &_sslContextObjectLock); |
_portNumber, _sslContext, &_sslContextObjectLock, |
|
listenAddressEmpty ? 0 : &listenAddress); |
} | } |
} | } |
} | } |
|
|
_ip4Acceptor = new HTTPAcceptor( | _ip4Acceptor = new HTTPAcceptor( |
_monitor, _requestDecoder, | _monitor, _requestDecoder, |
HTTPAcceptor::IPV4_CONNECTION, | HTTPAcceptor::IPV4_CONNECTION, |
_portNumber, 0, 0); |
_portNumber, 0, 0, |
|
listenAddressEmpty ? 0 : &listenAddress); |
} | } |
else | else |
{ | { |
_ip4Acceptor = new HTTPAcceptor( | _ip4Acceptor = new HTTPAcceptor( |
_monitor, _requestDecoder, | _monitor, _requestDecoder, |
HTTPAcceptor::IPV4_CONNECTION, | HTTPAcceptor::IPV4_CONNECTION, |
_portNumber, _sslContext, &_sslContextObjectLock); |
_portNumber, _sslContext, &_sslContextObjectLock, |
|
listenAddressEmpty ? 0 : &listenAddress); |
} | } |
} | } |
bind(); | bind(); |
|
|
_dispatcher = dispatcher; | _dispatcher = dispatcher; |
} | } |
| |
|
String CIMListenerService::getListenAddress() const |
|
{ |
|
bool listenAddressEmpty = _listenAddress == String::EMPTY; |
|
|
|
if (listenAddressEmpty && _ip6Acceptor != 0) |
|
return _ip6Acceptor->getListenAddress(); |
|
else if (listenAddressEmpty && _ip4Acceptor != 0) |
|
return _ip4Acceptor->getListenAddress(); |
|
|
|
return _listenAddress; |
|
} |
|
|
Uint32 CIMListenerService::getPortNumber() const | Uint32 CIMListenerService::getPortNumber() const |
{ | { |
Uint32 portNumber = _portNumber; | Uint32 portNumber = _portNumber; |
|
|
class CIMListenerRep | class CIMListenerRep |
{ | { |
public: | public: |
|
CIMListenerRep( |
|
const String &listenAddress, |
|
Uint32 portNumber, |
|
SSLContext* sslContext = NULL); |
CIMListenerRep(Uint32 portNumber, SSLContext * sslContext = NULL); | CIMListenerRep(Uint32 portNumber, SSLContext * sslContext = NULL); |
~CIMListenerRep(); | ~CIMListenerRep(); |
| |
|
String getListenAddress() const; |
Uint32 getPortNumber() const; | Uint32 getPortNumber() const; |
| |
SSLContext *getSSLContext() const; | SSLContext *getSSLContext() const; |
|
|
private: | private: |
Boolean waitForPendingRequests(Uint32 shutdownTimeout); | Boolean waitForPendingRequests(Uint32 shutdownTimeout); |
| |
|
String _listenAddress; |
Uint32 _portNumber; | Uint32 _portNumber; |
SSLContext *_sslContext; | SSLContext *_sslContext; |
| |
|
|
}; | }; |
| |
CIMListenerRep::CIMListenerRep( | CIMListenerRep::CIMListenerRep( |
|
const String &listenAddress, |
Uint32 portNumber, | Uint32 portNumber, |
SSLContext * sslContext) | SSLContext * sslContext) |
: | : |
|
_listenAddress(listenAddress), |
|
_portNumber(portNumber), |
|
_sslContext(sslContext), |
|
_dispatcher(new CIMListenerIndicationDispatcher()), |
|
_thread_pool(NULL), |
|
_svc(NULL), |
|
_listener_sem(NULL) |
|
{ |
|
} |
|
|
|
CIMListenerRep::CIMListenerRep( |
|
Uint32 portNumber, |
|
SSLContext * sslContext) |
|
: |
|
_listenAddress(), |
_portNumber(portNumber), | _portNumber(portNumber), |
_sslContext(sslContext), | _sslContext(sslContext), |
_dispatcher(new CIMListenerIndicationDispatcher()), | _dispatcher(new CIMListenerIndicationDispatcher()), |
|
|
// don't delete _svc, this is deleted by _listener_routine | // don't delete _svc, this is deleted by _listener_routine |
} | } |
| |
|
String CIMListenerRep::getListenAddress() const |
|
{ |
|
return !_svc ? _listenAddress : _svc->getListenAddress(); |
|
} |
|
|
Uint32 CIMListenerRep::getPortNumber() const | Uint32 CIMListenerRep::getPortNumber() const |
{ | { |
Uint32 portNumber; | Uint32 portNumber; |
|
|
if (_thread_pool == 0) | if (_thread_pool == 0) |
{ | { |
AutoPtr < CIMListenerService > | AutoPtr < CIMListenerService > |
svc(new CIMListenerService(_portNumber, _sslContext)); |
svc(new CIMListenerService(_listenAddress, _portNumber, |
|
_sslContext)); |
| |
svc->setIndicationDispatcher(_dispatcher); | svc->setIndicationDispatcher(_dispatcher); |
svc->init(); | svc->init(); |
|
|
///////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////// |
| |
CIMListener::CIMListener( | CIMListener::CIMListener( |
|
const String &listenAddress, |
|
Uint32 portNumber, |
|
SSLContext* sslContext) |
|
: |
|
_rep(new CIMListenerRep(listenAddress, portNumber, sslContext)) |
|
{ |
|
} |
|
|
|
CIMListener::CIMListener( |
Uint32 portNumber, | Uint32 portNumber, |
SSLContext * sslContext) | SSLContext * sslContext) |
: | : |
|
|
_rep = NULL; | _rep = NULL; |
} | } |
| |
|
String CIMListener::getListenAddress() const |
|
{ |
|
return static_cast < CIMListenerRep * >(_rep)->getListenAddress(); |
|
} |
|
|
Uint32 CIMListener::getPortNumber() const | Uint32 CIMListener::getPortNumber() const |
{ | { |
return static_cast < CIMListenerRep * >(_rep)->getPortNumber(); | return static_cast < CIMListenerRep * >(_rep)->getPortNumber(); |