Go to the documentation of this file.00001 
00002 
00003 #include "XmlRpc.h"
00004 using namespace XmlRpc;
00005 
00006 #include <iostream>
00007 
00008 
00009 XmlRpcServer s;
00010 
00011 
00012 
00013 
00014 
00015 class ArrayOfStructsTest : public XmlRpcServerMethod
00016 {
00017 public:
00018   ArrayOfStructsTest(XmlRpcServer* s) : XmlRpcServerMethod("validator1.arrayOfStructsTest", s) {}
00019 
00020   void execute(XmlRpcValue& params, XmlRpcValue& result)
00021   {
00022     std::cerr << "ArrayOfStructsTest\n";
00023     XmlRpcValue& arg1 = params[0];
00024     int n = arg1.size(), sum = 0;
00025     for (int i=0; i<n; ++i) 
00026       sum += int(arg1[i]["curly"]);
00027 
00028     result = sum;
00029   }
00030 } arrayOfStructsTest(&s);
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 class CountTheEntities : public XmlRpcServerMethod
00040 {
00041 public:
00042   CountTheEntities(XmlRpcServer* s) : XmlRpcServerMethod("validator1.countTheEntities", s) {}
00043 
00044   void execute(XmlRpcValue& params, XmlRpcValue& result)
00045   {
00046     std::cerr << "CountTheEntities\n";
00047     std::string& arg = params[0];
00048     int ctLeftAngleBrackets = 0;
00049     int ctRightAngleBrackets = 0;
00050     int ctAmpersands = 0;
00051     int ctApostrophes = 0;
00052     int ctQuotes = 0;
00053 
00054     int n = int(arg.length());
00055     for (int i=0; i<n; ++i)
00056       switch (arg[i])
00057       {
00058         case '<': ++ctLeftAngleBrackets; break;
00059         case '>': ++ctRightAngleBrackets; break;
00060         case '&': ++ctAmpersands; break;
00061         case '\'': ++ctApostrophes; break;
00062         case '\"': ++ctQuotes; break;
00063       }
00064 
00065     result["ctLeftAngleBrackets"] = ctLeftAngleBrackets;
00066     result["ctRightAngleBrackets"] = ctRightAngleBrackets;
00067     result["ctAmpersands"] = ctAmpersands;
00068     result["ctApostrophes"] = ctApostrophes;
00069     result["ctQuotes"] = ctQuotes;
00070   }
00071 } countTheEntities(&s);
00072 
00073 
00074 
00075 
00076 
00077 
00078 
00079 class EasyStructTest : public XmlRpcServerMethod
00080 {
00081 public:
00082   EasyStructTest(XmlRpcServer* s) : XmlRpcServerMethod("validator1.easyStructTest", s) {}
00083 
00084   void execute(XmlRpcValue& params, XmlRpcValue& result)
00085   {
00086     std::cerr << "EasyStructTest\n";
00087     XmlRpcValue& arg1 = params[0];
00088     int sum = int(arg1["moe"]) + int(arg1["larry"]) + int(arg1["curly"]);
00089     result = sum;
00090   }
00091 } easyStructTest(&s);
00092 
00093 
00094 
00095 
00096 class EchoStructTest : public XmlRpcServerMethod
00097 {
00098 public:
00099   EchoStructTest(XmlRpcServer* s) : XmlRpcServerMethod("validator1.echoStructTest", s) {}
00100 
00101   void execute(XmlRpcValue& params, XmlRpcValue& result)
00102   {
00103     std::cerr << "EchoStructTest\n";
00104     result = params[0];
00105   }
00106 } echoStructTest(&s);
00107 
00108 
00109 
00110 
00111 
00112 class ManyTypesTest : public XmlRpcServerMethod
00113 {
00114 public:
00115   ManyTypesTest(XmlRpcServer* s) : XmlRpcServerMethod("validator1.manyTypesTest", s) {}
00116 
00117   void execute(XmlRpcValue& params, XmlRpcValue& result)
00118   {
00119     std::cerr << "ManyTypesTest\n";
00120     result = params;
00121   }
00122 } manyTypesTest(&s);
00123 
00124 
00125 
00126 
00127 
00128 
00129 
00130 
00131 class ModerateSizeArrayCheck : public XmlRpcServerMethod
00132 {
00133 public:
00134   ModerateSizeArrayCheck(XmlRpcServer* s) : XmlRpcServerMethod("validator1.moderateSizeArrayCheck", s) {}
00135 
00136   void execute(XmlRpcValue& params, XmlRpcValue& result)
00137   {
00138     std::cerr << "ModerateSizeArrayCheck\n";
00139     std::string s = params[0][0];
00140     s += std::string(params[0][params[0].size()-1]);
00141     result = s;
00142   }
00143 } moderateSizeArrayCheck(&s);
00144 
00145 
00146 
00147 
00148 
00149 
00150 
00151 
00152 
00153 class NestedStructTest : public XmlRpcServerMethod
00154 {
00155 public:
00156   NestedStructTest(XmlRpcServer* s) : XmlRpcServerMethod("validator1.nestedStructTest", s) {}
00157 
00158   void execute(XmlRpcValue& params, XmlRpcValue& result)
00159   {
00160     std::cerr << "NestedStructTest\n";
00161     XmlRpcValue& dayStruct = params[0]["2000"]["04"]["01"];
00162     int sum = int(dayStruct["moe"]) + int(dayStruct["larry"]) + int(dayStruct["curly"]);
00163     result = sum;
00164   }
00165 } nestedStructTest(&s);
00166 
00167 
00168 
00169 
00170 
00171 
00172 class SimpleStructReturnTest : public XmlRpcServerMethod
00173 {
00174 public:
00175   SimpleStructReturnTest(XmlRpcServer* s) : XmlRpcServerMethod("validator1.simpleStructReturnTest", s) {}
00176 
00177   void execute(XmlRpcValue& params, XmlRpcValue& result)
00178   {
00179     std::cerr << "SimpleStructReturnTest\n";
00180     int n = params[0];
00181     result["times10"] = n * 10;
00182     result["times100"] = n * 100;
00183     result["times1000"] = n * 1000;
00184   }
00185 } simpleStructReturnTest(&s);
00186 
00187 
00188 
00189 int main(int argc, char* argv[])
00190 {
00191   if (argc != 2) {
00192     std::cerr << "Usage: Validator port\n";
00193     return -1;
00194   }
00195   int port = atoi(argv[1]);
00196 
00197   XmlRpc::setVerbosity(5);
00198 
00199   
00200   s.bindAndListen(port);
00201 
00202   
00203   s.work(-1.0);
00204 
00205   return 0;
00206 }
00207