From 07fb1d0cdaf2347b83a708a50eafa3d4ca02df04 Mon Sep 17 00:00:00 2001 From: Liang Hou Date: Mon, 28 Jan 2008 06:25:25 +0000 Subject: add initial wseventmgr.c --- src/Makefile.am | 10 +- src/wseventmgr.c | 586 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 592 insertions(+), 4 deletions(-) create mode 100644 src/wseventmgr.c diff --git a/src/Makefile.am b/src/Makefile.am index 8b50b88..c34591c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,11 +6,13 @@ CFLAGS = \ wsman_LDADD = \ $(OPENWSMAN_LIBS) \ -lwsman_curl_client_transport +wseventmgr_LDADD = \ + $(wsman_LDADD) -wsman_SOURCES = wsman.c +wsman_SOURCES = wsman.c +wseventmgr_SOURCES = wseventmgr.c bin_PROGRAMS = \ - wsman - - + wsman \ + wseventmgr diff --git a/src/wseventmgr.c b/src/wseventmgr.c new file mode 100644 index 0000000..3822b91 --- /dev/null +++ b/src/wseventmgr.c @@ -0,0 +1,586 @@ +/******************************************************************************* + * Copyright (C) 2004-2006 Intel Corp. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * - Neither the name of Intel Corp. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Intel Corp. OR THE CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + *******************************************************************************/ + +/** + * @author Anas Nashif + * @author Vadim Revyakin + * @author Liang Hou + */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#ifdef HAVE_UNISTD_H +#include +#endif + +#include +#include + +#include +#include +#include + + +#if __linux__ +extern char *getpass (const char *__prompt); +#endif + +static int server_port = 0; +static char *cainfo = NULL; +static char *cert = NULL; +static char *sslkey = NULL; +static char *endpoint = NULL; +static char *username = NULL; +static char *password = NULL; +static char *server = "localhost"; +static char *url_path = NULL; +static char *authentication_method = NULL; +static char noverify_peer = 0; +static char noverify_host = 0; + +static int transport_timeout = 0; +static char *proxy = NULL; +static char *proxy_upwd = NULL; + + +static int debug_level = -1; +static char *encoding = NULL; +char dump_request = 0; +char request_only = 0; + +static char *wsm_filter = NULL; +static char *wsm_dialect = NULL; +static char *event_delivery_mode = NULL; +static char *event_delivery_sec_mode = NULL; +static char *event_delivery_uri = NULL; +static int event_subscription_expire = 0; +static int event_heartbeat = 0; +static int event_sendbookmark =0; +static char *event_subscription_id = NULL; +static char *event_reference_properties = NULL; +static char *event_username = NULL; +static char *event_password = NULL; +static char *event_thumbprint = NULL; +static char *enum_context = NULL; +static int eventsink_enabled = 0; + +static char *cim_namespace = NULL; + +static char *_action = NULL; +static char *config_file = NULL; +static char *output_file = NULL; +static char *resource_uri_opt = NULL; + +struct _WsActions { + char *action; + int value; +}; +typedef struct _WsActions WsActions; + +WsActions action_data[] = { + {"pull", WSMAN_ACTION_PULL}, + {"subscribe", WSMAN_ACTION_SUBSCRIBE}, + {"unsubscribe", WSMAN_ACTION_UNSUBSCRIBE}, + {"renew", WSMAN_ACTION_RENEW}, + {"test", WSMAN_ACTION_TEST}, + {NULL, 0}, +}; + +WsActions delivery_mode[] = { + {"push", WSMAN_DELIVERY_PUSH}, + {"pushwithack", WSMAN_DELIVERY_PUSHWITHACK}, + {"events", WSMAN_DELIVERY_EVENTS}, + {"pull", WSMAN_DELIVERY_PULL}, + {NULL, 0} +}; + +WsActions delivery_sec_mode[] = { + {"httpbasic", WSMAN_DELIVERY_SEC_HTTP_BASIC}, + {"httpdigest", WSMAN_DELIVERY_SEC_HTTP_DIGEST}, + {"httpsbasic", WSMAN_DELIVERY_SEC_HTTPS_BASIC}, + {"httpsdigest", WSMAN_DELIVERY_SEC_HTTPS_DIGEST}, + {"httpsmutual", WSMAN_DELIVERY_SEC_HTTPS_MUTUAL}, + {"httpsmutualbasic", WSMAN_DELIVERY_SEC_HTTPS_MUTUAL_BASIC}, + {"httpsmutualdigest", WSMAN_DELIVERY_SEC_HTTPS_MUTUAL_DIGEST}, + {NULL, 0} +}; + +static int wsman_options_get_action(void) +{ + int op = 0; + int i; + for (i = 0; action_data[i].action != NULL; i++) { + if (strcmp(action_data[i].action, _action) == 0) { + op = action_data[i].value; + break; + } + } + return op; +} + +static char wsman_parse_options(int argc, char **argv) +{ + char retval = 0; + u_error_t *error = NULL; + + u_option_entry_t options[] = { + {"debug", 'd', U_OPTION_ARG_INT, &debug_level, + "Set the verbosity of debugging output.", "1-6"}, + {"print-request", 'R', U_OPTION_ARG_NONE, &dump_request, + "print request on stdout", NULL}, + {"encoding", 'j', U_OPTION_ARG_STRING, &encoding, + "Set request message encoding"}, + {"cacert", 'c', U_OPTION_ARG_STRING, &cainfo, + "Certificate file to verify the peer", ""}, + {"cert", 'A', U_OPTION_ARG_STRING, &cert, + "Certificate file. The certificate must be in PEM format.", ""}, + {"sslkey", 'K', U_OPTION_ARG_STRING, &sslkey, + "SSL Key.", ""}, + {"username", 'u', U_OPTION_ARG_STRING, &username, + "User name", ""}, + {"path", 'g', U_OPTION_ARG_STRING, &url_path, + "Path", ""}, + {"password", 'p', U_OPTION_ARG_STRING, &password, + "Password", ""}, + {"hostname", 'h', U_OPTION_ARG_STRING, &server, + "Host name", ""}, + {"endpoint", 'b', U_OPTION_ARG_STRING, &endpoint, + "End point", ""}, + {"port", 'P', U_OPTION_ARG_INT, &server_port, + "Server Port", ""}, + {"proxy", 'X', U_OPTION_ARG_STRING, &proxy, + "Proxy name", ""}, + {"proxyauth", 'Y', U_OPTION_ARG_STRING, &proxy_upwd, + "Proxy user:pwd", ""}, + {"auth", 'y', U_OPTION_ARG_STRING, &authentication_method, + "Authentication Method", ""}, + {"config-file", 'C', U_OPTION_ARG_STRING, &config_file, + "Alternate configuration file", ""}, + {"out-file", 'O', U_OPTION_ARG_STRING, &output_file, + "Write output to file", ""}, + {"noverifypeer", 'V', U_OPTION_ARG_NONE, &noverify_peer, + "Not to verify peer certificate", NULL}, + {"noverifyhost", 'v', U_OPTION_ARG_NONE, &noverify_host, + "Not to verify hostname", NULL}, + {"transport-timeout", 'I', U_OPTION_ARG_INT, &transport_timeout, + "Transport timeout in seconds", "