• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/ap/gpl/gsoap/source_build_platform/gsoap/samples/xml-rpc/
1/*
2	xml-rpc-currentTime.c
3
4	XML-RPC currenTime (C version)
5
6	Prints current time.
7
8	Compile:
9	soapcpp2 -c xml-rpc.h
10	cc xml-rpc-currentTime.c stdsoap2.c soapC.c
11
12--------------------------------------------------------------------------------
13gSOAP XML Web services tools
14Copyright (C) 2001-2008, Robert van Engelen, Genivia, Inc. All Rights Reserved.
15This software is released under one of the following two licenses:
16GPL or Genivia's license for commercial use.
17--------------------------------------------------------------------------------
18GPL license.
19
20This program is free software; you can redistribute it and/or modify it under
21the terms of the GNU General Public License as published by the Free Software
22Foundation; either version 2 of the License, or (at your option) any later
23version.
24
25This program is distributed in the hope that it will be useful, but WITHOUT ANY
26WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
27PARTICULAR PURPOSE. See the GNU General Public License for more details.
28
29You should have received a copy of the GNU General Public License along with
30this program; if not, write to the Free Software Foundation, Inc., 59 Temple
31Place, Suite 330, Boston, MA 02111-1307 USA
32
33Author contact information:
34engelen@genivia.com / engelen@acm.org
35--------------------------------------------------------------------------------
36A commercial use license is available from Genivia, Inc., contact@genivia.com
37--------------------------------------------------------------------------------
38*/
39
40#include "soapH.h"
41
42int methodCall(struct soap *soap, const char *URL, struct methodCall *m, struct methodResponse *r);
43
44int main()
45{ struct soap *soap = soap_new();
46  struct methodCall m;
47  struct methodResponse r;
48  /* Set up method call */
49  m.methodName = "currentTime.getCurrentTime";
50  /* no parameters */
51  m.params.__size = 0;
52  /* no namespaces */
53  soap->namespaces = NULL;
54  /* no SOAP encodingStyle */
55  soap->encodingStyle = NULL;
56  /* connect, send request, and receive response */
57  if (methodCall(soap, "http://time.xmlrpc.com/RPC2", &m, &r))
58  { soap_print_fault(soap, stderr);
59    exit(soap->error);
60  }
61  if (r.fault)
62  { /* print fault on stdout */
63    soap_begin_send(soap);
64    soap_put_fault(soap, r.fault, "fault", NULL);
65    soap_end_send(soap);
66  }
67  else if (r.params && r.params->__size == 1)
68  { /* print response parameter */
69    if (r.params->param[0].value.__type == SOAP_TYPE__dateTime_DOTiso8601)
70      printf("Time = %s\n", (char*)r.params->param[0].value.ref);
71    else
72      printf("Time not provided\n");
73  }
74  soap_end(soap);
75  soap_done(soap);
76  free(soap);
77  return 0;
78}
79
80int methodCall(struct soap *soap, const char *URL, struct methodCall *m, struct methodResponse *r)
81{ /* no namespaces */
82  soap->namespaces = NULL;
83  /* no SOAP encodingStyle */
84  soap->encodingStyle = NULL;
85  /* connect, send request, and receive response */
86  if (soap_connect(soap, URL, NULL)
87   || soap_put_methodCall(soap, m, "methodCall", NULL)
88   || soap_end_send(soap)
89   || soap_begin_recv(soap)
90   || !soap_get_methodResponse(soap, r, "methodResponse", NULL)
91   || soap_end_recv(soap))
92    return soap_closesock(soap); /* closes socket and returns soap->error */
93  soap_closesock(soap);
94  return SOAP_OK;
95}
96
97/* Don't need a namespace table. We put an empty one here to avoid link errors */
98struct Namespace namespaces[] = { {NULL, NULL} };
99