[xmlrpc-c] / trunk / examples / xmlrpc_loop_server.c
(logo)
View of /trunk/examples/xmlrpc_loop_server.c
Parent Directory Parent Directory | Revision Log Revision Log
Revision 1037 - (download) (annotate)
Sat Sep 22 02:33:49 2007 UTC (23 hours, 26 minutes ago) by giraffedata
File size: 4557 byte(s)
xxx
1 /* A simple standalone XML-RPC server based on Abyss that contains a
2 simple one-thread request processing loop.
3
4 xmlrpc_sample_add_server.c is a server that does the same thing, but
5 does it by running a full Abyss daemon in the background, so it has
6 less control over how the requests are served.
7 */
8
9 #include
10 #include
11 #include
12 #include
13 #include
14
15 #include
16 #include
17 #include
18 #include
19
20 #include "config.h" /* information about this build environment */
21
22
23 static void
24 setupSignalHandlers(void) {
25
26 /* In UNIX, when you try to write to a socket that has been closed
27 from the other end, your write fails, but you also get a SIGPIPE
28 signal. That signal will kill you before you even have a chance
29 to see the write fail unless you catch, block, or ignore it.
30 If a client should connect to us and then disconnect before we've
31 sent our response, we see this socket-closed behavior. We
32 obviously don't want to die just because a client didn't complete
33 an RPC, so we ignore SIGPIPE.
34 */
35 #ifndef WIN32
36 struct sigaction mysigaction;
37
38 sigemptyset(&mysigaction.sa_mask);
39 mysigaction.sa_flags = 0;
40 mysigaction.sa_handler = SIG_IGN;
41 sigaction(SIGPIPE, &mysigaction, NULL);
42 #endif
43 }
44
45
46
47 static void
48 printPeerIpAddr(TSession * const abyssSessionP) {
49
50 struct abyss_unix_chaninfo * channelInfoP;
51 struct sockaddr_in * sockAddrInP;
52 unsigned char * ipAddr; /* 4 byte array */
53
54 SessionGetChannelInfo(abyssSessionP, (void*)&channelInfoP);
55
56 sockAddrInP = (struct sockaddr_in *) &channelInfoP->peerAddr;
57
58 ipAddr = (unsigned char *)&sockAddrInP->sin_addr.s_addr;
59
60 printf("RPC is from IP address %u.%u.%u.%u\n",
61 ipAddr[0], ipAddr[1], ipAddr[2], ipAddr[3]);
62 }
63
64
65
66 static xmlrpc_value *
67 sample_add(xmlrpc_env * const envP,
68 xmlrpc_value * const paramArrayP,
69 void * const serverInfo ATTR_UNUSED,
70 void * const channelInfo) {
71
72 xmlrpc_int x, y, z;
73
74 printPeerIpAddr(channelInfo);
75
76 /* Parse our argument array. */
77 xmlrpc_decompose_value(envP, paramArrayP, "(ii)", &x, &y);
78 if (envP->fault_occurred)
79 return NULL;
80
81 /* Add our two numbers. */
82 z = x + y;
83
84 /* Return our result. */
85 return xmlrpc_build_value(envP, "i", z);
86 }
87
88
89
90 static xmlrpc_server_shutdown_fn requestShutdown;
91
92 static void
93 requestShutdown(xmlrpc_env * const envP,
94 void * const context,
95 const char * const comment,
96 void * const callInfo) {
97
98 /* You make this run by executing the system method
99 'system.shutdown'. This function is registered in the method
100 registry as the thing to call for that.
101 */
102 int * const terminationRequestedP = context;
103 TSession * const abyssSessionP = callInfo;
104
105 xmlrpc_env_init(envP);
106
107 fprintf(stderr, "Termination requested: %s\n", comment);
108
109 printPeerIpAddr(abyssSessionP);
110
111 *terminationRequestedP = 1;
112 }
113
114
115
116 int
117 main(int const argc,
118 const char ** const argv) {
119
120 TServer abyssServer;
121 xmlrpc_registry * registryP;
122 xmlrpc_env env;
123 int terminationRequested; /* A boolean value */
124 const char * error;
125
126 if (argc-1 != 1) {
127 fprintf(stderr, "You must specify 1 argument: The TCP port number "
128 "on which to listen for XML-RPC calls. "
129 "You specified %d.\n", argc-1);
130 exit(1);
131 }
132
133 AbyssInit(&error);
134
135 xmlrpc_env_init(&env);
136
137 registryP = xmlrpc_registry_new(&env);
138
139 xmlrpc_registry_add_method2(
140 &env, registryP, "sample.add", &sample_add, NULL, NULL, NULL);
141
142 xmlrpc_registry_set_shutdown(registryP,
143 &requestShutdown, &terminationRequested);
144
145 ServerCreate(&abyssServer, "XmlRpcServer", atoi(argv[1]), NULL, NULL);
146
147 xmlrpc_server_abyss_set_handlers2(&abyssServer, "/RPC2", registryP);
148
149 ServerInit(&abyssServer);
150
151 setupSignalHandlers();
152
153 terminationRequested = 0;
154
155 while (!terminationRequested) {
156 printf("Waiting for next RPC...\n");
157
158 ServerRunOnce(&abyssServer);
159 /* This waits for the next connection, accepts it, reads the
160 HTTP POST request, executes the indicated RPC, and closes
161 the connection.
162 */
163 }
164
165 ServerFree(&abyssServer);
166
167 AbyssTerm();
168
169 return 0;
170 }
Back to SourceForge.net
Powered by ViewVC 1.0.3
ViewVC and Help
http://xmlrpc-c.svn.sourceforge.net/viewvc/xmlrpc-c/trunk/examples/xmlrpc_loop_server.c?view=markup
and so on:
1 # Since the programs in this directories are examples for the user, this
2 # make file should be as ordinary as possible. It should not rely heavily
3 # on included make files or configuration parameters. It should not use
4 # libtool. Also, we don't try to build or rebuild the libraries on which
5 # these programs depend.
6
7
8 ifeq ($(SRCDIR)x,x)
9 SRCDIR = $(CURDIR)/..
10 BUILDDIR = $(SRCDIR)
11 endif
12
13 default: all
14
15 include $(BUILDDIR)/Makefile.config
16
17 CXXFLAGS =
18
19 CFLAGS = $(CFLAGS_COMMON) $(CFLAGS_PERSONAL) $(CADD)
20 LDFLAGS = $(LADD)
21
22 # If this were a real application, working from an installed copy of
23 # Xmlrpc-c, XMLRPC_C_CONFIG would just be 'xmlrpc-c-config'. It would be
24 # found in the user's PATH.
25 XMLRPC_C_CONFIG = $(BUILDDIR)/xmlrpc-c-config.test
26
27 CLIENTPROGS_C = \
28 auth_client \
29 query-meerkat \
30 synch_client \
31 xmlrpc_sample_add_client \
32 xmlrpc_asynch_client \
33
34 SERVERPROGS_CGI = \
35 xmlrpc_sample_add_server.cgi
36
37 SERVERPROGS_ABYSS = \
38 xmlrpc_loop_server \
39 xmlrpc_sample_add_server \
40 xmlrpc_server_validatee \
41
42 PROGS = $(CLIENTPROGS_C) $(SERVERPROGS_ABYSS) \
43 gen_sample_add_xml
44
45 ifeq ($(ENABLE_CGI_SERVER),yes)
46 PROGS += $(SERVERPROGS_CGI)
47 endif
48
49 INCLUDES = $(shell $(XMLRPC_C_CONFIG) c++ client abyss-server --cflags)
50
51 LDADD_CLIENT = \
52 $(shell $(XMLRPC_C_CONFIG) client --ldadd)
53
54 LDADD_SERVER_ABYSS = \
55 $(shell $(XMLRPC_C_CONFIG) abyss-server --ldadd)
56
57 LDADD_SERVER_CGI = \
58 $(shell $(XMLRPC_C_CONFIG) cgi-server --ldadd)
59
60 LDADD_BASE = \
61 $(shell $(XMLRPC_C_CONFIG) --ldadd)
62
63 all: $(PROGS)
64
65 ifeq ($(ENABLE_CPLUSPLUS),yes)
66 all: cpp/all
67 endif
68
69 .PHONY: cpp/all
70 cpp/all:
71 $(MAKE) -C $(dir $@) $(notdir $@)
72
73 $(CLIENTPROGS_C):%:%.o
74 $(CCLD) -o $@ $(LDFLAGS) $^ $(LDADD_CLIENT)
75
76 $(SERVERPROGS_CGI):%.cgi:%_cgi.o
77 $(CCLD) -o $@ $(LDFLAGS) $^ $(LDADD_SERVER_CGI)
78
79 $(SERVERPROGS_ABYSS):%:%.o
80 $(CCLD) -o $@ $(LDFLAGS) $^ $(LDADD_SERVER_ABYSS)
81
82 gen_sample_add_xml:%:%.o
83 $(CCLD) -o $@ $(LDFLAGS) $^ $(LDADD_BASE)
84
85 %.o:%.c
86 $(CC) -c $(INCLUDES) $(CFLAGS) $<
87
88 *.c: config.h xmlrpc_amconfig.h
89
90 config.h:
91 $(LN_S) $(BUILDDIR)/xmlrpc_config.h $@
92 xmlrpc_amconfig.h:
93 $(LN_S) $(BUILDDIR)/$@ .
94
95 include $(SRCDIR)/Makefile.common
96
97 .PHONY: clean
98 clean: clean-common
99 rm -f $(PROGS) config.h xmlrpc_amconfig.h
100
101 .PHONY: distclean
102 distclean: clean
103
104 BINDIR=$(DESTDIR)$(bindir)
105
106 FILENAME_GENERATOR = "echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'"
107
108 INSTCMD = "$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p \
109 $(BINDIR)/`$(FILENAME_GENERATOR)`"
110
111 .PHONY: install
112 install: $(PROGS)
113 @$(NORMAL_INSTALL)
114 $(MKINSTALLDIRS) $(BINDIR)
115 @list='$(bin_PROGRAMS)'; for p in $$list; do \
116 if test -f $$p; then \
117 echo "$(INSTCMD)"; $(INSTCMD); \
118 else :; \
119 fi; \
120 done
Those are sections, I included the original server data and URL.
Not complicated at all, to over complicate is to obscure from reason. Just look at any Windows XP registry after SP1.
http://xmlrpc-c.svn.sourceforge.net/viewvc/xmlrpc-c/trunk/examples/Makefile?revision=355&view=markup
an SVN is basically :
http://svn.uni-koblenz.de/svn-manual/svn-design.html
or:
http://svn.uni-koblenz.de/svn-manual/svn-design.html#Working%20Directories%20and%20Repositories
and stuff,,Linux is Open Source and GPL so that a copy is not nor cannot be 'owned' by any one, rather it can be used by any or all.
Boot up any Linux and that is C in action.