本文整理汇总了C++中XmlRpcValue::toXml方法的典型用法代码示例。如果您正苦于以下问题:C++ XmlRpcValue::toXml方法的具体用法?C++ XmlRpcValue::toXml怎么用?C++ XmlRpcValue::toXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlRpcValue
的用法示例。
在下文中一共展示了XmlRpcValue::toXml方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
// Encode the request to call the specified method with the specified parameters into xml
bool
XmlRpcCurlClient::generateRequest(const char* methodName, XmlRpcValue const& params)
{
std::string body = REQUEST_BEGIN;
body += methodName;
body += REQUEST_END_METHODNAME;
// If params is an array, each element is a separate parameter
if (params.valid()) {
body += PARAMS_TAG;
if (params.getType() == XmlRpcValue::TypeArray)
{
for (int i=0; i<params.size(); ++i) {
body += PARAM_TAG;
body += params[i].toXml();
body += PARAM_ETAG;
}
}
else
{
body += PARAM_TAG;
body += params.toXml();
body += PARAM_ETAG;
}
body += PARAMS_ETAG;
}
body += REQUEST_END;
_request = body;
return true;
}
示例2: generateRequest
// Encode the request to call the specified method with the specified parameters into xml
bool XmlRpcClient::generateRequest(const char* methodName, XmlRpcValue const& params)
{
std::string body = REQUEST_BEGIN;
body += methodName;
body += REQUEST_END_METHODNAME;
// If params is an array, each element is a separate parameter
if (params.valid())
{
body += PARAMS_TAG;
if (params.getType() == XmlRpcValue::TypeArray)
{
for (int i=0; i<params.size(); ++i)
{
body += PARAM_TAG;
body += params[i].toXml();
body += PARAM_ETAG;
}
}
else
{
body += PARAM_TAG;
body += params.toXml();
body += PARAM_ETAG;
}
body += PARAMS_ETAG;
}
body += REQUEST_END;
std::string header = generateHeader(body);
XmlRpcUtil::log(4, "XmlRpcClient::generateRequest: header is %d bytes, content-length is %d.",
header.length(), body.length());
_request = header + body;
return true;
}
示例3: generateFaultResponse
void XmlRpcServerConnection::generateFaultResponse(std::string const& errorMsg, int errorCode)
{
const char RESPONSE_1[] =
"<?xml version=\"1.0\"?>\r\n"
"<methodResponse><fault>\r\n\t";
const char RESPONSE_2[] =
"\r\n</fault></methodResponse>\r\n";
XmlRpcValue faultStruct;
faultStruct[FAULTCODE] = errorCode;
faultStruct[FAULTSTRING] = errorMsg;
std::string body = RESPONSE_1 + faultStruct.toXml() + RESPONSE_2;
std::string header = generateHeader(body);
_response = header + body;
}
示例4: write
bool XmlRpcCarrier::write(Protocol& proto, SizedWriter& writer) {
//XmlRpc::setVerbosity(10);
StringOutputStream sos;
StringInputStream sis;
writer.write(sos);
sis.reset(sos.toString());
String header;
if (sender) {
header = NetType::readLine(sis);
}
String body = NetType::readLine(sis);
//printf("Asked to write: hdr %s body %s\n",
// header.c_str(), body.c_str());
Value v;
//printf("HEADER %s\n", header.c_str());
if (header[0]=='q') {
body = "yarp.quit";
// XMLRPC does not need a quit message, this should get stripped
return false;
}
Bottle *bot = v.asList();
//Bottle aux;
bot->fromString(body.c_str());
ConstString methodName;
if (sender) {
methodName = bot->get(0).toString();
*bot = bot->tail();
}
XmlRpcValue args;
if (bot->size()==1) {
toXmlRpcValue(bot->get(0),args);
} else {
toXmlRpcValue(v,args);
}
//printf("xmlrpc block to write is %s\n", args.toXml().c_str());
std::string req;
if (sender) {
const Address& addr = host.isValid()?host:proto.getStreams().getRemoteAddress();
XmlRpcClient c(addr.getName().c_str(),(addr.getPort()>0)?addr.getPort():80);
c.generateRequest(methodName.c_str(),args);
req = c.getRequest();
} else {
XmlRpcServerConnection c(0,NULL);
c.generateResponse(args.toXml());
req = c.getResponse();
}
int start = 0;
//printf("converts to %s\n", req.c_str());
if (sender) {
if (req.length()<8) {
fprintf(stderr, "XmlRpcCarrier fail, %s:%d\n", __FILE__, __LINE__);
return false;
}
for (int i=0; i<(int)req.length(); i++) {
if (req[i] == '\n') {
start++;
break;
}
start++;
}
if (!firstRound) {
Bytes b((char*)http.c_str(),http.length());
proto.os().write(b);
}
firstRound = false;
}
Bytes b((char*)req.c_str()+start,req.length()-start);
//printf("WRITING [%s]\n", req.c_str()+start);
proto.os().write(b);
return proto.os().isOk();
}
示例5: write
bool XmlRpcCarrier::write(ConnectionState& proto, SizedWriter& writer) {
StringOutputStream sos;
StringInputStream sis;
writer.write(sos);
sis.reset(sos.toString());
ConstString header;
if (sender) {
header = sis.readLine();
}
ConstString body = sis.readLine();
Value v;
if (header.length()>0 && header[0]=='q') {
body = "yarp.quit";
// XMLRPC does not need a quit message, this should get stripped
return false;
}
Bottle *bot = v.asList();
bot->fromString(body.c_str());
ConstString methodName;
if (sender) {
methodName = bot->get(0).toString();
*bot = bot->tail();
}
XmlRpcValue args;
if (bot->size()==1) {
toXmlRpcValue(bot->get(0),args);
} else {
toXmlRpcValue(v,args);
}
std::string req;
if (sender) {
const Contact& addr = host.isValid()?host:proto.getStreams().getRemoteAddress();
XmlRpcClient c(addr.getHost().c_str(),(addr.getPort()>0)?addr.getPort():80);
c.generateRequest(methodName.c_str(),args);
req = c.getRequest();
} else {
XmlRpcServerConnection c(0,NULL);
c.generateResponse(args.toXml());
req = c.getResponse();
}
int start = 0;
if (sender) {
if (req.length()<8) {
fprintf(stderr, "XmlRpcCarrier fail, %s:%d\n", __FILE__, __LINE__);
return false;
}
for (int i=0; i<(int)req.length(); i++) {
if (req[i] == '\n') {
start++;
break;
}
start++;
}
if (!firstRound) {
Bytes b((char*)http.c_str(),http.length());
proto.os().write(b);
}
firstRound = false;
}
Bytes b((char*)req.c_str()+start,req.length()-start);
proto.os().write(b);
return proto.os().isOk();
}