| 1 |
// ---------------------------------------------------------------------------- |
| 2 |
// |
| 3 |
// flxmlrpc Copyright (c) 2015 by W1HKJ, Dave Freese <[email protected]> |
| 4 |
// |
| 5 |
// XmlRpc++ Copyright (c) 2002-2008 by Chris Morley |
| 6 |
// |
| 7 |
// This file is part of fldigi |
| 8 |
// |
| 9 |
// flxmlrpc is free software; you can redistribute it and/or modify |
| 10 |
// it under the terms of the GNU Lesser General Public License as published by |
| 11 |
// the Free Software Foundation; either version 3 of the License, or |
| 12 |
// (at your option) any later version. |
| 13 |
// |
| 14 |
// You should have received a copy of the GNU General Public License |
| 15 |
// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
// ---------------------------------------------------------------------------- |
| 17 |
|
| 18 |
#ifndef _XMLRPCSERVERCONNECTION_H_ |
| 19 |
#define _XMLRPCSERVERCONNECTION_H_ |
| 20 |
|
| 21 |
#if defined(_MSC_VER) |
| 22 |
# pragma warning(disable:4786) // identifier was truncated in debug info |
| 23 |
#endif |
| 24 |
|
| 25 |
#include <string> |
| 26 |
|
| 27 |
#include "XmlRpcValue.h" |
| 28 |
#include "XmlRpcSource.h" |
| 29 |
|
| 30 |
namespace XmlRpc { |
| 31 |
|
| 32 |
|
| 33 |
// The server waits for client connections and provides support for executing methods |
| 34 |
class XmlRpcServer; |
| 35 |
class XmlRpcServerMethod; |
| 36 |
|
| 37 |
//! A class to handle XML RPC requests from a particular client |
| 38 |
class XmlRpcServerConnection : public XmlRpcSource { |
| 39 |
public: |
| 40 |
|
| 41 |
//! Constructor |
| 42 |
XmlRpcServerConnection(XmlRpcSocket::Socket fd, XmlRpcServer* server, bool deleteOnClose = false); |
| 43 |
//! Destructor |
| 44 |
virtual ~XmlRpcServerConnection(); |
| 45 |
|
| 46 |
// XmlRpcSource interface implementation |
| 47 |
//! Handle IO on the client connection socket. |
| 48 |
//! @param eventType Type of IO event that occurred. @see XmlRpcDispatch::EventType. |
| 49 |
virtual unsigned handleEvent(unsigned eventType); |
| 50 |
|
| 51 |
protected: |
| 52 |
|
| 53 |
//! Reads the http header |
| 54 |
bool readHeader(); |
| 55 |
|
| 56 |
//! Reads the request (based on the content-length header value) |
| 57 |
bool readRequest(); |
| 58 |
|
| 59 |
//! Executes the request and writes the resulting response |
| 60 |
bool writeResponse(); |
| 61 |
|
| 62 |
|
| 63 |
//! Helper method to execute the client request |
| 64 |
virtual void executeRequest(); |
| 65 |
|
| 66 |
|
| 67 |
//! The XmlRpc server that accepted this connection |
| 68 |
XmlRpcServer* _server; |
| 69 |
|
| 70 |
//! Possible IO states for the connection |
| 71 |
enum ServerConnectionState { READ_HEADER, READ_REQUEST, WRITE_RESPONSE }; |
| 72 |
//! Current IO state for the connection |
| 73 |
ServerConnectionState _connectionState; |
| 74 |
|
| 75 |
//! Request headers |
| 76 |
std::string _header; |
| 77 |
|
| 78 |
//! Number of bytes expected in the request body (parsed from header) |
| 79 |
int _contentLength; |
| 80 |
|
| 81 |
//! Request body |
| 82 |
std::string _request; |
| 83 |
|
| 84 |
//! Response |
| 85 |
std::string _response; |
| 86 |
|
| 87 |
//! Number of bytes of the response written so far |
| 88 |
int _bytesWritten; |
| 89 |
|
| 90 |
//! Whether to keep the current client connection open for further requests |
| 91 |
bool _keepAlive; |
| 92 |
}; |
| 93 |
} // namespace XmlRpc |
| 94 |
|
| 95 |
#endif // _XMLRPCSERVERCONNECTION_H_ |