Annotation of embedaddon/libpdel/structs/xmlrpc-test/main.c, revision 1.1
1.1 ! misho 1:
! 2: /*
! 3: * Copyright (c) 2001-2002 Packet Design, LLC.
! 4: * All rights reserved.
! 5: *
! 6: * Subject to the following obligations and disclaimer of warranty,
! 7: * use and redistribution of this software, in source or object code
! 8: * forms, with or without modifications are expressly permitted by
! 9: * Packet Design; provided, however, that:
! 10: *
! 11: * (i) Any and all reproductions of the source or object code
! 12: * must include the copyright notice above and the following
! 13: * disclaimer of warranties; and
! 14: * (ii) No rights are granted, in any manner or form, to use
! 15: * Packet Design trademarks, including the mark "PACKET DESIGN"
! 16: * on advertising, endorsements, or otherwise except as such
! 17: * appears in the above copyright notice or in the software.
! 18: *
! 19: * THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
! 20: * TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
! 21: * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
! 22: * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
! 23: * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
! 24: * OR NON-INFRINGEMENT. PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
! 25: * OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
! 26: * OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
! 27: * RELIABILITY OR OTHERWISE. IN NO EVENT SHALL PACKET DESIGN BE
! 28: * LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
! 29: * OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
! 30: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
! 31: * DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
! 32: * USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
! 33: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
! 34: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
! 35: * THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
! 36: * THE POSSIBILITY OF SUCH DAMAGE.
! 37: *
! 38: * Author: Archie Cobbs <archie@freebsd.org>
! 39: */
! 40:
! 41: #include "xmlrpc_test.h"
! 42:
! 43: #define XMLRPC_TEST_VERSION "libpdel/" PDEL_VERSION_STRING
! 44:
! 45: /* List of XML-RPC methods */
! 46: static const struct http_servlet_xmlrpc_method *method_list[] = {
! 47: &arrayOfStructsTest_method,
! 48: &countTheEntities_method,
! 49: &easyStructTest_method,
! 50: &echoStructTest_method,
! 51: &manyTypesTest_method,
! 52: &moderateSizeArrayCheck_method,
! 53: &nestedStructTest_method,
! 54: &simpleStructReturnTest_method,
! 55: };
! 56: #define NUM_METHODS (sizeof(method_list) / sizeof(*method_list))
! 57:
! 58: /* Global variables */
! 59: int debug_level;
! 60:
! 61: /* Internal functions */
! 62: static void usage(void);
! 63:
! 64: /*
! 65: * Implement the XML-RPC validation test suite.
! 66: */
! 67: int
! 68: main(int argc, char **argv)
! 69: {
! 70: struct http_servlet_xmlrpc_method xmlrpc_methods[NUM_METHODS + 1];
! 71: struct http_servlet_xmlrpc_info xmlrpc_info;
! 72: static const struct in_addr zero_ip;
! 73: struct http_servlet *servlet;
! 74: struct http_server *server;
! 75: struct pevent_ctx *ctx;
! 76: char versbuf[64];
! 77: sigset_t sigs;
! 78: int port = 0;
! 79: int sig;
! 80: int ch;
! 81: int i;
! 82:
! 83: /* Parse command line arguments */
! 84: while ((ch = getopt(argc, argv, "dp:")) != -1) {
! 85: switch (ch) {
! 86: case 'd':
! 87: debug_level++;
! 88: break;
! 89: case 'p':
! 90: port = atoi(optarg);
! 91: break;
! 92: default:
! 93: usage();
! 94: }
! 95: }
! 96: argc -= optind;
! 97: argv += optind;
! 98: switch (argc) {
! 99: case 0:
! 100: break;
! 101: default:
! 102: usage();
! 103: break;
! 104: }
! 105: if (port == 0)
! 106: port = 80;
! 107:
! 108: /* Enable typed memory */
! 109: if (debug_level > 0 && typed_mem_enable() == -1)
! 110: err(1, "typed_mem_enable");
! 111:
! 112: /* Get event context */
! 113: if ((ctx = pevent_ctx_create("xmlrpc_test_server.ctx", NULL)) == NULL)
! 114: err(1, "pevent_ctx_create");
! 115:
! 116: /* Start HTTP server */
! 117: snprintf(versbuf, sizeof(versbuf), "%s (%s/%s)",
! 118: XMLRPC_TEST_VERSION, host_os, host_arch);
! 119: if ((server = http_server_start(ctx,
! 120: zero_ip, port, NULL, versbuf, alog)) == NULL)
! 121: err(1, "http_server_start");
! 122: fprintf(stderr, "started XML-RPC server on port %d\n", port);
! 123:
! 124: /* Create XML-RPC servlet */
! 125: for (i = 0; i < NUM_METHODS; i++)
! 126: xmlrpc_methods[i] = *method_list[i];
! 127: memset(&xmlrpc_methods[i], 0, sizeof(xmlrpc_methods[i]));
! 128: memset(&xmlrpc_info, 0, sizeof(xmlrpc_info));
! 129: xmlrpc_info.methods = xmlrpc_methods;
! 130: xmlrpc_info.logger = alog;
! 131: if ((servlet = http_servlet_xmlrpc_create(&xmlrpc_info,
! 132: NULL, NULL)) == NULL)
! 133: err(1, "http_servlet_xmlrpc_create");
! 134:
! 135: /* Register XML-RPC servlet */
! 136: if (http_server_register_servlet(server,
! 137: servlet, NULL, "^" XML_RPC_URL "$", 0) == -1)
! 138: err(1, "http_server_register_servlet");
! 139:
! 140: /* Wait for interrupt */
! 141: sigemptyset(&sigs);
! 142: sigaddset(&sigs, SIGINT);
! 143: sigaddset(&sigs, SIGTERM);
! 144: if (sigprocmask(SIG_BLOCK, &sigs, NULL) == -1)
! 145: err(1, "sigprocmask");
! 146: if (sigwait(&sigs, &sig) == -1)
! 147: err(1, "sigwait");
! 148:
! 149: /* Shut down server */
! 150: if (debug_level > 0)
! 151: fprintf(stderr, "\nrec'd signal %d, shutting down...\n", sig);
! 152: http_server_stop(&server);
! 153:
! 154: /* Destroy event context */
! 155: pevent_ctx_destroy(&ctx);
! 156: usleep(100000);
! 157:
! 158: /* Done */
! 159: if (debug_level > 0) {
! 160: fprintf(stderr, "displaying unfreed memory...\n");
! 161: typed_mem_dump(stdout);
! 162: }
! 163: return (0);
! 164: }
! 165:
! 166: /*
! 167: * Exit after printing usage string
! 168: */
! 169: static void
! 170: usage(void)
! 171: {
! 172: fprintf(stderr, "Usage: xmlrpc_test [-d] [-p port]\n");
! 173: fprintf(stderr, "Options:\n");
! 174: fprintf(stderr, "\t-d\tIncrease debugging level\n");
! 175: fprintf(stderr, "\t-p\tSpecify HTTP server port (default 80)\n");
! 176: exit(1);
! 177: }
! 178:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>