mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-13 01:26:58 +00:00
add xmlrpc-c 1.03.14 to in tree libs
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3772 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
4
libs/xmlrpc-c/examples/cpp/.cvsignore
Normal file
4
libs/xmlrpc-c/examples/cpp/.cvsignore
Normal file
@@ -0,0 +1,4 @@
|
||||
meerkat-app-list
|
||||
xmlrpc_sample_add_server
|
||||
xmlrpc_sample_add_client
|
||||
sample_add_client_complex
|
96
libs/xmlrpc-c/examples/cpp/Makefile
Normal file
96
libs/xmlrpc-c/examples/cpp/Makefile
Normal file
@@ -0,0 +1,96 @@
|
||||
# Since the programs in this directories are examples for the user, this
|
||||
# make file should be as ordinary as possible. It should not rely heavily
|
||||
# on included make files or configuration parameters. It should not use
|
||||
# libtool. Also, we don't try to build or rebuild the libraries on which
|
||||
# these programs depend.
|
||||
|
||||
|
||||
ifeq ($(SRCDIR)x,x)
|
||||
SRCDIR = $(CURDIR)/../..
|
||||
BUILDDIR = $(SRCDIR)
|
||||
endif
|
||||
|
||||
default: all
|
||||
|
||||
include $(BUILDDIR)/Makefile.config
|
||||
|
||||
CXXFLAGS = $(CXXFLAGS_COMMON) $(CFLAGS_PERSONAL) $(CADD)
|
||||
LDFLAGS = $(LADD)
|
||||
|
||||
# If this were a real application, working from an installed copy of
|
||||
# Xmlrpc-c, XMLRPC_C_CONFIG would just be 'xmlrpc-c-config'. It would be
|
||||
# found in the user's PATH.
|
||||
XMLRPC_C_CONFIG = $(BUILDDIR)/xmlrpc-c-config.test
|
||||
|
||||
|
||||
SERVERPROGS_ABYSS = \
|
||||
xmlrpc_sample_add_server \
|
||||
|
||||
LEGACY_CLIENTPROGS = \
|
||||
meerkat-app-list
|
||||
|
||||
CLIENTPROGS = \
|
||||
xmlrpc_sample_add_client \
|
||||
sample_add_client_complex \
|
||||
|
||||
# Build up PROGS:
|
||||
PROGS =
|
||||
|
||||
ifeq ($(ENABLE_ABYSS_SERVER),yes)
|
||||
PROGS += $(SERVERPROGS_ABYSS)
|
||||
endif
|
||||
|
||||
ifeq ($(MUST_BUILD_CLIENT),yes)
|
||||
PROGS += $(CLIENTPROGS) $(LEGACY_CLIENTPROGS)
|
||||
endif
|
||||
|
||||
INCLUDES = $(shell $(XMLRPC_C_CONFIG) c++2 client abyss-server --cflags)
|
||||
|
||||
LDADD_SERVER_ABYSS = \
|
||||
$(shell $(XMLRPC_C_CONFIG) c++2 abyss-server --ldadd)
|
||||
|
||||
LDADD_CLIENT = \
|
||||
$(shell $(XMLRPC_C_CONFIG) c++2 client --ldadd)
|
||||
|
||||
LDADD_BASE = \
|
||||
$(shell $(XMLRPC_C_CONFIG) c++2 --ldadd)
|
||||
|
||||
LDADD_LEGACY_CLIENT = \
|
||||
$(shell $(XMLRPC_C_CONFIG) c++ client --ldadd)
|
||||
|
||||
all: $(PROGS)
|
||||
|
||||
$(SERVERPROGS_ABYSS):%:%.o
|
||||
$(CXXLD) -o $@ $(LDFLAGS) $^ $(LDADD_SERVER_ABYSS)
|
||||
|
||||
$(LEGACY_CLIENTPROGS):%:%.o
|
||||
$(CXXLD) -o $@ $(LDFLAGS) $^ $(LDADD_LEGACY_CLIENT)
|
||||
|
||||
$(CLIENTPROGS):%:%.o
|
||||
$(CXXLD) -o $@ $(LDFLAGS) $^ $(LDADD_CLIENT)
|
||||
|
||||
%.o:%.cpp
|
||||
$(CXX) -c $(INCLUDES) $(CXXFLAGS) $<
|
||||
|
||||
*.c: config.h xmlrpc_amconfig.h
|
||||
|
||||
config.h:
|
||||
$(LN_S) $(BUILDDIR)/xmlrpc_config.h $@
|
||||
xmlrpc_amconfig.h:
|
||||
$(LN_S) $(BUILDDIR)/$@ .
|
||||
|
||||
include $(SRCDIR)/Makefile.common
|
||||
|
||||
.PHONY: clean
|
||||
clean: clean-common
|
||||
rm -f $(PROGS) config.h xmlrpc_amconfig.h
|
||||
|
||||
.PHONY: distclean
|
||||
distclean: clean
|
||||
|
||||
.PHONY: dep depend
|
||||
dep depend:
|
||||
# We don't do dependencies in this directory, because it's supposed to be
|
||||
# an example of what a program outside this package would do, so we can't
|
||||
# go weaving it into the rest of the package. Ergo, a developer must
|
||||
# carefully clean and remake examples as he updates other parts of the tree.
|
108
libs/xmlrpc-c/examples/cpp/meerkat-app-list.cpp
Normal file
108
libs/xmlrpc-c/examples/cpp/meerkat-app-list.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
// List recently-released Linux applications. (Written in C++.)
|
||||
// For more details about O'Reilly's excellent Meerkat news service, see:
|
||||
// http://www.oreillynet.com/pub/a/rss/2000/11/14/meerkat_xmlrpc.html */
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include <xmlrpc-c/oldcppwrapper.hpp>
|
||||
|
||||
#define NAME "XML-RPC C++ Meerkat Query Demo"
|
||||
#define VERSION "0.1"
|
||||
#define MEERKAT_URL "http://www.oreillynet.com/meerkat/xml-rpc/server.php"
|
||||
#define SOFTWARE_LINUX (6)
|
||||
|
||||
static void list_apps (int hours) {
|
||||
|
||||
// Build our time_period parameter.
|
||||
ostringstream time_period_stream;
|
||||
time_period_stream << hours << "HOUR";
|
||||
string time_period = time_period_stream.str();
|
||||
|
||||
// Assemble our meerkat query recipe.
|
||||
XmlRpcValue recipe = XmlRpcValue::makeStruct();
|
||||
recipe.structSetValue("category", XmlRpcValue::makeInt(SOFTWARE_LINUX));
|
||||
recipe.structSetValue("time_period", XmlRpcValue::makeString(time_period));
|
||||
recipe.structSetValue("descriptions", XmlRpcValue::makeInt(76));
|
||||
|
||||
// Build our parameter array.
|
||||
XmlRpcValue param_array = XmlRpcValue::makeArray();
|
||||
param_array.arrayAppendItem(recipe);
|
||||
|
||||
// Create a client pointing to Meerkat.
|
||||
XmlRpcClient meerkat (MEERKAT_URL);
|
||||
|
||||
// Perform the query.
|
||||
XmlRpcValue apps = meerkat.call("meerkat.getItems", param_array);
|
||||
|
||||
// Print our results.
|
||||
int first = 1;
|
||||
size_t app_count = apps.arraySize();
|
||||
for (size_t i = 0; i < app_count; i++) {
|
||||
XmlRpcValue app = apps.arrayGetItem(i);
|
||||
|
||||
// Get some information about our application.
|
||||
string title = app.structGetValue("title").getString();
|
||||
string link = app.structGetValue("link").getString();
|
||||
string description = app.structGetValue("description").getString();
|
||||
|
||||
// Print a separator line if necessary.
|
||||
if (first)
|
||||
first = 0;
|
||||
else
|
||||
cout << endl;
|
||||
|
||||
// Print this application entry.
|
||||
if (description.size() > 0) {
|
||||
cout << title << endl << description << endl << link << endl;
|
||||
} else {
|
||||
cout << title << endl << description << endl << link << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Print out a usage message.
|
||||
static void usage (void)
|
||||
{
|
||||
cerr << "Usage: meekat-app-list [hours]" << endl;
|
||||
cerr << "Data from <http://www.oreillynet.com/meerkat/>." << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
int status = 0;
|
||||
int hours = 25;
|
||||
|
||||
// Parse our command-line arguments.
|
||||
if (argc == 1) {
|
||||
// Use default value for hours.
|
||||
} else if (argc == 2) {
|
||||
hours = atoi(argv[1]);
|
||||
}
|
||||
if (hours == 0)
|
||||
usage();
|
||||
if (hours > 49) {
|
||||
cerr << "It's not nice to ask for > 49 hours at once." << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Start up our client library.
|
||||
XmlRpcClient::Initialize(NAME, VERSION);
|
||||
|
||||
// Call our implementation, and watch out for faults.
|
||||
try {
|
||||
list_apps(hours);
|
||||
} catch (XmlRpcFault& fault) {
|
||||
cerr << argv[0] << ": XML-RPC fault #" << fault.getFaultCode()
|
||||
<< ": " << fault.getFaultString() << endl;
|
||||
status = 1;
|
||||
}
|
||||
|
||||
// Shut down our client library.
|
||||
XmlRpcClient::Terminate();
|
||||
|
||||
return status;
|
||||
}
|
68
libs/xmlrpc-c/examples/cpp/sample_add_client_complex.cpp
Normal file
68
libs/xmlrpc-c/examples/cpp/sample_add_client_complex.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
/*=============================================================================
|
||||
sample_add_client_complex.cpp
|
||||
===============================================================================
|
||||
This is an example of an XML-RPC client that uses XML-RPC for C/C++
|
||||
(Xmlrpc-c).
|
||||
|
||||
In particular, it uses the complex lower-level interface that gives you
|
||||
lots of flexibility but requires lots of code. Also see
|
||||
xmlrpc_sample_add_server, which does the same thing as this program,
|
||||
but with much simpler code because it uses a simpler facility of
|
||||
Xmlrpc-c.
|
||||
|
||||
This program actually gains nothing from using the more difficult
|
||||
facility. It is for demonstration purposes.
|
||||
=============================================================================*/
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <xmlrpc-c/girerr.hpp>
|
||||
#include <xmlrpc-c/base.hpp>
|
||||
#include <xmlrpc-c/client.hpp>
|
||||
#include <cassert>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main(int argc, char **) {
|
||||
|
||||
if (argc-1 > 0) {
|
||||
cerr << "This program has no arguments" << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
xmlrpc_c::clientXmlTransport_curl myTransport;
|
||||
xmlrpc_c::client_xml myClient(&myTransport);
|
||||
|
||||
string const methodName("sample.add");
|
||||
|
||||
xmlrpc_c::paramList sampleAddParms;
|
||||
sampleAddParms.add(xmlrpc_c::value_int(5));
|
||||
sampleAddParms.add(xmlrpc_c::value_int(7));
|
||||
|
||||
xmlrpc_c::rpcPtr myRpcP(methodName, sampleAddParms);
|
||||
|
||||
string const serverUrl("http://localhost:8080/RPC2");
|
||||
|
||||
xmlrpc_c::carriageParm_curl0 myCarriageParm(serverUrl);
|
||||
|
||||
xmlrpc_c::value result;
|
||||
|
||||
myRpcP->call(&myClient, &myCarriageParm);
|
||||
|
||||
assert(myRpcP->isFinished());
|
||||
|
||||
int const sum(xmlrpc_c::value_int(myRpcP->getResult()));
|
||||
// Assume the method returned an integer; throws error if not
|
||||
|
||||
cout << "Result of RPC (sum of 5 and 7): " << sum << endl;
|
||||
|
||||
} catch (girerr::error const error) {
|
||||
cerr << "Client threw error: " << error.what() << endl;
|
||||
} catch (...) {
|
||||
cerr << "Client threw unexpected error." << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
38
libs/xmlrpc-c/examples/cpp/xmlrpc_sample_add_client.cpp
Normal file
38
libs/xmlrpc-c/examples/cpp/xmlrpc_sample_add_client.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <xmlrpc-c/girerr.hpp>
|
||||
#include <xmlrpc-c/base.hpp>
|
||||
#include <xmlrpc-c/client_simple.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main(int argc, char **) {
|
||||
|
||||
if (argc-1 > 0) {
|
||||
cerr << "This program has no arguments" << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
string const serverUrl("http://localhost:8080/RPC2");
|
||||
string const methodName("sample.add");
|
||||
|
||||
xmlrpc_c::clientSimple myClient;
|
||||
xmlrpc_c::value result;
|
||||
|
||||
myClient.call(serverUrl, methodName, "ii", &result, 5, 7);
|
||||
|
||||
int const sum = xmlrpc_c::value_int(result);
|
||||
// Assume the method returned an integer; throws error if not
|
||||
|
||||
cout << "Result of RPC (sum of 5 and 7): " << sum << endl;
|
||||
|
||||
} catch (girerr::error const error) {
|
||||
cerr << "Client threw error: " << error.what() << endl;
|
||||
} catch (...) {
|
||||
cerr << "Client threw unexpected error." << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
55
libs/xmlrpc-c/examples/cpp/xmlrpc_sample_add_server.cpp
Normal file
55
libs/xmlrpc-c/examples/cpp/xmlrpc_sample_add_server.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <cassert>
|
||||
|
||||
#include <xmlrpc-c/base.hpp>
|
||||
#include <xmlrpc-c/registry.hpp>
|
||||
#include <xmlrpc-c/server_abyss.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class sampleAddMethod : public xmlrpc_c::method {
|
||||
public:
|
||||
sampleAddMethod() {
|
||||
// signature and help strings are documentation -- the client
|
||||
// can query this information with a system.methodSignature and
|
||||
// system.methodHelp RPC.
|
||||
this->_signature = "i:ii";
|
||||
// method's result and two arguments are integers
|
||||
this->_help = "This method adds two integers together";
|
||||
}
|
||||
void
|
||||
execute(xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retvalP) {
|
||||
|
||||
int const addend(paramList.getInt(0));
|
||||
int const adder(paramList.getInt(1));
|
||||
|
||||
paramList.verifyEnd(2);
|
||||
|
||||
*retvalP = xmlrpc_c::value_int(addend + adder);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
int
|
||||
main(int const,
|
||||
const char ** const) {
|
||||
|
||||
xmlrpc_c::registry myRegistry;
|
||||
|
||||
xmlrpc_c::methodPtr const sampleAddMethodP(new sampleAddMethod);
|
||||
|
||||
myRegistry.addMethod("sample.add", sampleAddMethodP);
|
||||
|
||||
xmlrpc_c::serverAbyss myAbyssServer(
|
||||
myRegistry,
|
||||
8080, // TCP port on which to listen
|
||||
"/tmp/xmlrpc_log" // Log file
|
||||
);
|
||||
|
||||
myAbyssServer.run();
|
||||
// xmlrpc_c::serverAbyss.run() never returns
|
||||
assert(false);
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user