Debian Codegraph @

test/TestBase64Server.cpp

raw
1 // TestBase64Server.cpp : Simple XMLRPC server example. Usage: TestBase64Server serverPort
2 //
3 #if defined(_MSC_VER)
4 # pragma warning(disable:4786) // identifier was truncated in debug info
5 #endif
6
7
8 #include <iostream>
9 #include <fstream>
10 #include <algorithm>
11 #include <stdlib.h>
12
13
14 #include "XmlRpc.h"
15 using namespace XmlRpc;
16
17
18 // The server
19 XmlRpcServer s;
20
21 // No arguments, result is Base64-encoded pngnow.png data.
22 class TestBase64 : public XmlRpcServerMethod
23 {
24 public:
25 TestBase64(XmlRpcServer* s) : XmlRpcServerMethod("TestBase64", s) {}
26
27 void execute(XmlRpcValue& params, XmlRpcValue& result)
28 {
29 std::ifstream infile("pngnow.png", std::ios::binary);
30 if (infile.fail())
31 infile.open("../pngnow.png", std::ios::binary);
32 if (infile.fail())
33 result = "Could not open file pngnow.png";
34 else {
35
36 XmlRpcValue::BinaryData& data = result;
37 int n = 0;
38 for (;; ++n) {
39 char c = infile.get();
40 if (infile.eof()) break;
41 data.push_back(c);
42 }
43 std::cerr << "Read " << n << " bytes from pngnow.png\n";
44 }
45 }
46 } TestBase64(&s); // This constructor registers the method with the server
47
48
49
50 int main(int argc, char* argv[])
51 {
52 if (argc != 2) {
53 std::cerr << "Usage: TestBase64Server serverPort\n";
54 return -1;
55 }
56 int port = atoi(argv[1]);
57
58 //XmlRpc::setVerbosity(5);
59
60 // Create the server socket on the specified port
61 s.bindAndListen(port);
62
63 // Wait for requests indefinitely
64 s.work(-1.0);
65
66 return 0;
67 }
68