20#define RESIPROCATE_SUBSYSTEM AppSubsystem::MOHPARKSERVER
22int HttpConnection::nextPageNumber=1;
27 mPageNumber(nextPageNumber++),
39 closesocket(mSock); mSock=0;
41 close(mSock); mSock=0;
49 if ( !mTxBuffer.
empty() )
63 int errNumSize =
sizeof(errNum);
64 getsockopt(mSock,SOL_SOCKET,SO_ERROR,(
char *)&errNum,(socklen_t *)&errNumSize);
65 InfoLog (<<
"Exception reading from socket "
66 << (
int)mSock <<
" code: " << errNum <<
"; closing connection");
72 bool ok = processSomeReads();
80 bool ok = processSomeWrites();
100 mTxBuffer +=
"HTTP/1.0 401 Unauthorized"; mTxBuffer +=
Symbols::CRLF;
102 page = (
"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">"
104 "<title>401 Unauthorized</title>"
106 "<h1>Unauthorized</h1>"
113 mTxBuffer +=
"HTTP/1.0 404 Not Found"; mTxBuffer +=
Symbols::CRLF;
115 page = (
"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">"
117 "<title>404 Not Found</title>"
119 "<h1>Unauthorized</h1>"
126 mTxBuffer +=
"HTTP/1.0 301 Moved Permanently"; mTxBuffer +=
Symbols::CRLF;
127 mTxBuffer +=
"Location: http:/activecalls.html"; mTxBuffer +=
Symbols::CRLF;
129 page = (
"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">"
131 "<title>301 Moved Permanently</title>"
155 mTxBuffer +=
"HTTP/1.0 ";
169 mTxBuffer +=
"WWW-Authenticate: Basic realm=\"";
176 mTxBuffer += mHttpBase.
mRealm;
181 mTxBuffer +=
"Server: Console RFSS " ;
184 mTxBuffer +=
"Mime-version: 1.0 " ; mTxBuffer +=
Symbols::CRLF;
185 mTxBuffer +=
"Pragma: no-cache " ; mTxBuffer +=
Symbols::CRLF;
186 mTxBuffer +=
"Content-Length: "; mTxBuffer += len; mTxBuffer +=
Symbols::CRLF;
188 mTxBuffer +=
"Content-Type: " ;
189 mTxBuffer += pType.
type() ;
200HttpConnection::processSomeReads()
202 const int bufSize = 8000;
207 int bytesRead = ::recv(mSock, buf, bufSize, 0);
209 int bytesRead = ::read(mSock, buf, bufSize);
218 InfoLog (<<
"No data ready to read");
221 InfoLog (<<
"The call was interrupted by a signal before any data was read.");
227 InfoLog (<<
"fd is not a valid file descriptor or is not open for reading.");
230 InfoLog (<<
"fd is attached to an object which is unsuitable for reading.");
233 InfoLog (<<
"buf is outside your accessible address space.");
236 InfoLog (<<
"Some other error");
239 InfoLog (<<
"Failed read on " << (
int)mSock <<
" " << strerror(e));
242 else if (bytesRead == 0)
244 InfoLog (<<
"Connection closed by remote " );
251 mRxBuffer +=
Data( buf, bytesRead );
260HttpConnection::tryParse()
267 const char* start = pb.skipWhitespace();
277 pb.
data( uri, start );
279 DebugLog (<<
"parse found URI " << uri );
280 mParsedRequest =
true;
288 pb.skipToChars(
"Authorization" );
291 if ( pb.eof() )
DebugLog( <<
"Did not find Authorization header" );
292 pb.skipToChars(
"Basic" ); pb.skipN(6);
293 if ( pb.eof() )
DebugLog( <<
"Did not find Authorization basic " );
295 if ( pb.eof() )
DebugLog( <<
"Something weird in Auhtorization header " );
298 const char* a = pb.position();
299 pb.skipNonWhitespace();
302 DebugLog (<<
"parse found basic base64 auth data of " << buf );
308 const char* a1 = p.position();
311 const char* a2 = p.skipChar(
':');
313 password = p.
data(a2);
322 ErrLog (<<
"Some problem finding Authorization header in HTTP request" );
325 mHttpBase.
buildPage(uri,mPageNumber,user,password);
330HttpConnection::processSomeWrites()
332 if ( mTxBuffer.
empty() )
340 int bytesWritten = ::send( mSock, mTxBuffer.
data(), (
int)mTxBuffer.
size(), 0);
342 int bytesWritten = ::write(mSock, mTxBuffer.
data(), mTxBuffer.
size() );
348 InfoLog (<<
"HttpConnection failed write on " << mSock <<
" " << strerror(e));
353 if (bytesWritten == (
int)mTxBuffer.
size() )
364 DebugLog( <<
"Wrote " << bytesWritten <<
" bytes - still need to do " << mTxBuffer );
#define resip_assert(x)
This file needs to work for both C and C++ code.
Handles cross-platform sockets compatibility.
virtual void buildPage(const resip::Data &uri, int pageNumber, const resip::Data &user, const resip::Data &password)=0
bool process(resip::FdSet &fdset)
void buildFdSet(resip::FdSet &fdset)
HttpConnection(HttpBase &webAdmin, resip::Socket pSock)
void setPage(const resip::Data &page, int response, const resip::Mime &pType)
An iostream that operates on an existing Data.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Data base64decode() const
Performs RFC 3548 Base 64 decoding of the contents of this data.
static const Data Empty
Constant that represents a zero-length data.
Data substr(size_type first, size_type count=Data::npos) const
Copies a portion of this Data into a new Data.
bool empty() const noexcept
Checks whether the Data is empty.
size_type size() const noexcept
Returns the number of bytes in this Data.
const char * data() const noexcept
Returns a pointer to the contents of this Data.
static const Data & getLocalHostName()
Object-oriented wrapper for your platform's file-descriptor set.
bool readyToWrite(Socket fd)
bool readyToRead(Socket fd)
bool hasException(Socket fd)
Represents the "media-type" element in the RFC 3261 grammar.
const Data & subType() const
const Data & type() const
Provides string-parsing functionality with protection from buffer overflow.
static const char * SPACE
dcm! – add UnusedChecking(_enum) below;