40 _server->removeConnection(
this );
68 "XmlRpcServerConnection::readHeader: error while reading header (%s).",
74 char* hp = (
char*)
_header.c_str();
80 for (
char* cp = hp; ( bp == 0 ) && ( cp <
ep ); ++cp )
82 if ( (
ep - cp > 16 ) && ( strncasecmp( cp,
"Content-length: ", 16 ) == 0 ) ) lp = cp + 16;
83 else if ( (
ep - cp > 12 ) && ( strncasecmp( cp,
"Connection: ", 12 ) == 0 ) )
85 else if ( (
ep - cp > 4 ) && ( strncmp( cp,
"\r\n\r\n", 4 ) == 0 ) ) bp = cp + 4;
86 else if ( (
ep - cp > 2 ) && ( strncmp( cp,
"\n\n", 2 ) == 0 ) ) bp = cp + 2;
97 XmlRpcUtil::error(
"XmlRpcServerConnection::readHeader: EOF while reading header" );
107 XmlRpcUtil::error(
"XmlRpcServerConnection::readHeader: No Content-length specified" );
115 "XmlRpcServerConnection::readHeader: Invalid Content-length specified (%d).",
120 XmlRpcUtil::log( 3,
"XmlRpcServerConnection::readHeader: specified content length is %d.",
128 if (
_header.find(
"HTTP/1.0" ) != std::string::npos )
130 if ( kp == 0 || strncasecmp( kp,
"keep-alive", 10 ) != 0 )
135 if ( kp != 0 && strncasecmp( kp,
"close", 5 ) == 0 )
_keepAlive =
false;
161 XmlRpcUtil::error(
"XmlRpcServerConnection::readRequest: EOF while reading request" );
169 XmlRpcUtil::log( 3,
"XmlRpcServerConnection::readRequest read %d bytes.",
197 XmlRpcUtil::log( 3,
"XmlRpcServerConnection::writeResponse: wrote %d of %d bytes.",
216 XmlRpcUtil::log( 2,
"XmlRpcServerConnection::executeRequest: server calling method '%s'",
217 methodName.c_str() );
229 XmlRpcUtil::log( 2,
"XmlRpcServerConnection::executeRequest: fault %s.",
261 if ( !method )
return false;
263 method->
execute( params, result );
266 if ( !result.
valid() ) result = std::string();
280 int nc = params[0].
size();
283 for (
int i = 0; i < nc; ++i )
286 if ( !params[0][i].hasMember(
METHODNAME ) || !params[0][i].hasMember(
PARAMS ) )
291 ": Invalid argument (expected a struct with members methodName and params)";
295 const std::string& methodName = params[0][i][
METHODNAME];
302 if ( !
executeMethod( methodName, methodParams, resultValue[0] ) &&
306 result[i][
FAULTSTRING] = methodName +
": unknown method name";
308 else result[i] = resultValue;
322 const char RESPONSE_1[] =
"<?xml version=\"1.0\"?>\r\n"
323 "<methodResponse><params><param>\r\n\t";
324 const char RESPONSE_2[] =
"\r\n</param></params></methodResponse>\r\n";
326 std::string body = RESPONSE_1 + resultXml + RESPONSE_2;
335 std::string header =
"HTTP/1.1 200 OK\r\n"
339 "Content-Type: text/xml\r\n"
343 sprintf( buffLen,
"%d\r\n\r\n", body.size() );
345 return header + buffLen;
350 const char RESPONSE_1[] =
"<?xml version=\"1.0\"?>\r\n"
351 "<methodResponse><fault>\r\n\t";
352 const char RESPONSE_2[] =
"\r\n</fault></methodResponse>\r\n";
357 std::string body = RESPONSE_1 + faultStruct.
toXml() + RESPONSE_2;
sprintf(cut, "kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_" "pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
@ ReadableEvent
data available to read
@ WritableEvent
connected/data can be written without blocking
int getCode() const
Return the error code.
const std::string & getMessage() const
Return the error message.
ServerConnectionState _connectionState
bool executeMethod(const std::string &methodName, XmlRpcValue ¶ms, XmlRpcValue &result)
std::string parseRequest(XmlRpcValue ¶ms)
void generateFaultResponse(std::string const &msg, int errorCode=-1)
void generateResponse(std::string const &resultXml)
static const std::string METHODNAME
std::string generateHeader(std::string const &body)
static const std::string PARAMS
static const char PARAMS_TAG[]
static const std::string FAULTSTRING
virtual ~XmlRpcServerConnection()
Destructor.
static const char PARAMS_ETAG[]
static const std::string FAULTCODE
virtual void executeRequest()
XmlRpcServerConnection(int fd, XmlRpcServer *server, bool deleteOnClose=false)
Constructor.
bool executeMulticall(const std::string &methodName, XmlRpcValue ¶ms, XmlRpcValue &result)
static const char METHODNAME_TAG[]
static const char PARAM_TAG[]
virtual unsigned handleEvent(unsigned eventType)
static const std::string SYSTEM_MULTICALL
static const char PARAM_ETAG[]
Abstract class representing a single RPC method.
virtual void execute(XmlRpcValue ¶ms, XmlRpcValue &result)=0
Execute the method. Subclasses must provide a definition for this method.
A class to handle XML RPC requests.
static bool nbWrite(int socket, std::string &s, int *bytesSoFar)
Write text to the specified socket. Returns false on error.
static bool nbRead(int socket, std::string &s, bool *eof)
Read text from the specified socket. Returns false on error.
static std::string getErrorMsg()
Returns message corresponding to last error.
int getfd() const
Return the file descriptor being monitored.
XmlRpcSource(int fd=-1, bool deleteOnClose=false)
static bool nextTagIs(const char *tag, std::string const &xml, int *offset)
static std::string parseTag(const char *tag, std::string const &xml, int *offset)
Returns contents between <tag> and </tag>, updates offset to char after </tag>.
static void error(const char *fmt,...)
Dump error messages somewhere.
static bool findTag(const char *tag, std::string const &xml, int *offset)
Returns true if the tag is found and updates offset to the char after the tag.
static void log(int level, const char *fmt,...)
Dump messages somewhere.
RPC method arguments and results are represented by Values.
int size() const
Return the size for string, base64, array, and struct values.
bool valid() const
Return true if the value has been set to something.
std::string toXml() const
Encode the Value in xml.
void setSize(int size)
Specify the size for array values. Array values will grow beyond this size if needed.
Type const & getType() const
Return the type of the value stored.
const char XMLRPC_VERSION[]
Version identifier.