|
reSIProcate/repro
9694
|
#include <HttpBase.hxx>


Public Member Functions | |
| HttpBase (int port, resip::IpVersion version, const resip::Data &realm) | |
| virtual | ~HttpBase () |
| void | buildFdSet (resip::FdSet &fdset) |
| void | process (resip::FdSet &fdset) |
| bool | isSane () |
Protected Member Functions | |
| virtual void | buildPage (const resip::Data &uri, int pageNumber, const resip::Data &user, const resip::Data &password)=0 |
| void | setPage (const resip::Data &page, int pageNumber, int response=200, const resip::Mime &pType=resip::Mime("text","html")) |
Protected Attributes | |
| const resip::Data | mRealm |
Private Attributes | |
| resip::Socket | mFd |
| int | nextConnection |
| resip::Tuple | mTuple |
| bool | sane |
| HttpConnection * | mConnection [MaxConnections] |
Static Private Attributes | |
| static const int | MaxConnections = 30 |
Friends | |
| class | HttpConnection |
Definition at line 14 of file HttpBase.hxx.
| HttpBase::HttpBase | ( | int | port, |
| resip::IpVersion | version, | ||
| const resip::Data & | realm | ||
| ) |
Definition at line 48 of file HttpBase.cxx.
: mRealm(realm), nextConnection(0), mTuple(Data::Empty,port,ipVer,TCP,Data::Empty) { // !rwm! [TODO] check that this works for IPv6 //assert( ipVer == V4 ); sane = true; for ( int i=0 ; i<MaxConnections; i++) { mConnection[i]=0; } #ifdef USE_IPV6 mFd = ::socket(ipVer == V4 ? PF_INET : PF_INET6, SOCK_STREAM, 0); #else mFd = ::socket(PF_INET, SOCK_STREAM, 0); #endif if ( mFd == INVALID_SOCKET ) { int e = getErrno(); ErrLog (<< "Failed to create socket: " << strerror(e)); sane = false; return; } DebugLog (<< "Creating fd=" << (int)mFd << (ipVer == V4 ? " V4/" : " V6/") ); int on = 1; #if !defined(WIN32) if ( ::setsockopt ( mFd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) ) #else if ( ::setsockopt ( mFd, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on)) ) #endif { int e = getErrno(); ErrLog (<< "Couldn't set sockoptions SO_REUSEPORT | SO_REUSEADDR: " << strerror(e)); sane = false; return; } DebugLog (<< "Binding to " << Tuple::inet_ntop(mTuple)); if ( ::bind( mFd, &mTuple.getMutableSockaddr(), mTuple.length()) == SOCKET_ERROR ) { int e = getErrno(); if ( e == EADDRINUSE ) { ErrLog (<< mTuple << " already in use "); } else { ErrLog (<< "Could not bind to " << mTuple); } sane = false; return; } bool ok = makeSocketNonBlocking(mFd); if ( !ok ) { ErrLog (<< "Could not make HTTP socket non-blocking " << port ); sane = false; return; } // do the listen, seting the maximum queue size for compeletly established // sockets -- on linux, tcp_max_syn_backlog should be used for the incomplete // queue size(see man listen) int e = listen(mFd,5 ); if (e != 0 ) { int e = getErrno(); InfoLog (<< "Failed listen " << strerror(e)); sane = false; return; } }
| HttpBase::~HttpBase | ( | ) | [virtual] |
Definition at line 30 of file HttpBase.cxx.
{
#if defined(WIN32)
closesocket(mFd);
#else
close(mFd);
#endif
mFd=0;
for( int i=0; i<MaxConnections; i++)
{
if ( mConnection[i] )
{
delete mConnection[i] ; mConnection[i]=0;
}
}
}
| void HttpBase::buildFdSet | ( | resip::FdSet & | fdset | ) |
Definition at line 134 of file HttpBase.cxx.
{
fdset.setRead( mFd );
for( int i=0; i<MaxConnections; i++)
{
if ( mConnection[i] )
{
mConnection[i]->buildFdSet(fdset);
}
}
}
| virtual void repro::HttpBase::buildPage | ( | const resip::Data & | uri, |
| int | pageNumber, | ||
| const resip::Data & | user, | ||
| const resip::Data & | password | ||
| ) | [protected, pure virtual] |
Implemented in repro::WebAdmin.
| bool HttpBase::isSane | ( | ) |
Definition at line 216 of file HttpBase.cxx.
{
return sane;
}
| void HttpBase::process | ( | resip::FdSet & | fdset | ) |
Definition at line 149 of file HttpBase.cxx.
{
if (fdset.readyToRead(mFd))
{
Tuple tuple(mTuple);
struct sockaddr& peer = tuple.getMutableSockaddr();
socklen_t peerLen = tuple.length();
Socket sock = accept( mFd, &peer, &peerLen);
if ( sock == SOCKET_ERROR )
{
int e = getErrno();
switch (e)
{
case EWOULDBLOCK:
// !jf! this can not be ready in some cases
return;
default:
ErrLog(<< "Some error reading from socket: " << e);
// .bwc. This is almost certainly a bad assert that a nefarious
// endpoint could hit.
// assert(0); // Transport::error(e);
}
return;
}
makeSocketNonBlocking(sock);
int c = nextConnection;
nextConnection = ( nextConnection+1 ) % MaxConnections;
if ( mConnection[c] )
{
delete mConnection[c]; mConnection[c] = 0;
}
mConnection[c] = new HttpConnection(*this,sock);
DebugLog (<< "Received TCP connection as connection=" << c << " fd=" << (int)sock);
}
for( int i=0; i<MaxConnections; i++)
{
if ( mConnection[i] )
{
bool ok = mConnection[i]->process(fdset);
if ( !ok )
{
delete mConnection[i]; mConnection[i]=0;
}
}
}
}
| void HttpBase::setPage | ( | const resip::Data & | page, |
| int | pageNumber, | ||
| int | response = 200, |
||
| const resip::Mime & | pType = resip::Mime("text","html") |
||
| ) | [protected] |
Definition at line 202 of file HttpBase.cxx.
{
for ( int i=0 ; i<MaxConnections; i++)
{
if ( mConnection[i] )
{
if ( mConnection[i]->mPageNumber == pageNumber )
{
mConnection[i]->setPage( page,response,type );
}
}
}
}
friend class HttpConnection [friend] |
Definition at line 16 of file HttpBase.hxx.
const int repro::HttpBase::MaxConnections = 30 [static, private] |
Definition at line 40 of file HttpBase.hxx.
HttpConnection* repro::HttpBase::mConnection[MaxConnections] [private] |
Definition at line 48 of file HttpBase.hxx.
resip::Socket repro::HttpBase::mFd [private] |
Definition at line 42 of file HttpBase.hxx.
const resip::Data repro::HttpBase::mRealm [protected] |
Definition at line 37 of file HttpBase.hxx.
resip::Tuple repro::HttpBase::mTuple [private] |
Definition at line 44 of file HttpBase.hxx.
int repro::HttpBase::nextConnection [private] |
Definition at line 43 of file HttpBase.hxx.
bool repro::HttpBase::sane [private] |
Definition at line 46 of file HttpBase.hxx.
1.7.5.1