19#define RESIPROCATE_SUBSYSTEM Subsystem::REPRO
21std::atomic<unsigned int> XmlRpcConnectionBase::NextConnectionId(1);
24 mXmlRcpServer(server),
25 mConnectionId(NextConnectionId++),
57 if (!mTxBuffer.
empty())
71 int errNumSize =
sizeof(errNum);
72 getsockopt(mSock,SOL_SOCKET,SO_ERROR,(
char *)&errNum,(socklen_t *)&errNumSize);
73 InfoLog (<<
"XmlRpcSocketConnection::process: Exception reading from socket "
74 << (
int)mSock <<
" code: " << errNum <<
"; closing connection");
80 bool ok = processSomeReads();
88 bool ok = processSomeWrites();
99XmlRpcSocketConnection::processSomeReads()
101 const int bufSize = 8000;
106 int bytesRead = ::recv(mSock, buf, bufSize, 0);
108 int bytesRead = ::read(mSock, buf, bufSize);
115 InfoLog (<<
"XmlRpcSocketConnection::processSomeReads: Failed read on " << (
int)mSock);
118 else if(bytesRead == 0)
120 DebugLog (<<
"XmlRpcSocketConnection::processSomeReads: Connection closed by remote");
126 mRxBuffer +=
Data( buf, bytesRead );
135XmlRpcSocketConnection::tryParse()
139 const char* start = pb.position();
145 const char* anchor = pb.position();
149 initialTag = pb.
data(anchor);
151 pb.skipToChars(
"</" + initialTag +
">");
154 pb.skipN(initialTag.
size() + 3);
163 anchor = pb.position();
165 mRxBuffer = pb.
data(anchor);
179XmlRpcSocketConnection::processSomeWrites()
181 if (mTxBuffer.
empty())
189 int bytesWritten = ::send(mSock, mTxBuffer.
data(), (
int)mTxBuffer.
size(), 0);
191 int bytesWritten = ::write(mSock, mTxBuffer.
data(), mTxBuffer.
size() );
198 InfoLog (<<
"XmlRpcSocketConnection::processSomeWrites - failed write on " << mSock <<
" " <<
strError(e));
203 if (bytesWritten == (
int)mTxBuffer.
size())
205 DebugLog (<<
"XmlRpcSocketConnection::processSomeWrites - Wrote it all" );
215 DebugLog( <<
"XmlRpcSocketConnection::processSomeWrites - Wrote " << bytesWritten <<
" bytes - still need to do " << mTxBuffer );
224 RequestMap::iterator it =
mRequests.find(requestId);
227 Data& request = it->second;
241 response = pb.
data(start);
245 response +=
" <Response>" + responseData +
" </Response>";
251 response += pb.
data(start);
256 response =
"<Response>" + responseData +
"</Response>";
271 mTxBuffer += response;
277 mTxBuffer += eventData;
280#ifdef BUILD_QPID_PROTON
282XmlRpcProtonConnection::XmlRpcProtonConnection(XmlRpcProtonServer& server,
const resip::Data& replyTo,
283 std::shared_ptr<ProtonThreadBase::ProtonSenderBase> sender) :
290XmlRpcProtonConnection::~XmlRpcProtonConnection()
295XmlRpcProtonConnection::onRequest(
unsigned int requestId,
const resip::Data& request)
297 mRequests[requestId] = request;
315XmlRpcProtonConnection::sendResponse(
const resip::Data& responseData)
317 StackLog(<<
"sending via Proton: " << responseData);
318 mSender->sendMessage(responseData);
322XmlRpcProtonConnection::sendEvent(
const resip::Data& eventData)
324 StackLog(<<
"sending via Proton: " << eventData);
325 mSender->sendMessage(eventData);
#define resip_assert(x)
This file needs to work for both C and C++ code.
Handles cross-platform sockets compatibility.
virtual bool sendResponse(unsigned int requestId, const resip::Data &responseData, bool isFinal)
unsigned int getConnectionId() const
unsigned int getNextRequestId()
XmlRpcConnectionBase(XmlRpcServerBase &server)
XmlRpcServerBase & mXmlRcpServer
virtual ~XmlRpcConnectionBase()
virtual void handleRequest(unsigned int connectionId, unsigned int requestId, const resip::Data &request)
virtual void sendResponse(const resip::Data &response)
virtual ~XmlRpcSocketConnection()
virtual bool process(resip::FdSet &fdset)
virtual void buildFdSet(resip::FdSet &fdset)
XmlRpcSocketConnection(XmlRpcSocketServer &server, resip::Socket sock)
virtual void sendEvent(const resip::Data &eventData)
static void logSocketError(int e)
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
static const Data Empty
Constant that represents a zero-length data.
static const PreallocateType Preallocate
used only to disambiguate constructors
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.
Data & clear()
Clears the contents of this Data.
const char * data() const noexcept
Returns a pointer to the contents of this Data.
Object-oriented wrapper for your platform's file-descriptor set.
bool readyToWrite(Socket fd)
bool readyToRead(Socket fd)
bool hasException(Socket fd)
Provides string-parsing functionality with protection from buffer overflow.
CurrentPosition skipToEnd()
CurrentPosition skipWhitespace()
CurrentPosition skipToChars(const char *cs)
CurrentPosition position() const
CurrentPosition skipN(size_t count)
void data(Data &data, const char *start) const
make the passed in data share memory with the buffer (uses Data::Share)
This Class is used to implement a primitive form of RPC using loose XML formatting.
dcm! – add UnusedChecking(_enum) below;
std::string strError(int err)