diff options
author | Anas Nashif <nashif@intel.com> | 2007-03-27 22:54:34 +0000 |
---|---|---|
committer | Anas Nashif <nashif@intel.com> | 2007-03-27 22:54:34 +0000 |
commit | 23e187b9a2225f4bd64c7088c2504432a6f477a1 (patch) | |
tree | 5b8694094e1d1fa78ebfe0eb1305139543a6f98b /src | |
parent | 6845642a1173fc16bdb2a4974e2e655109510609 (diff) | |
download | wsmancli-23e187b9a2225f4bd64c7088c2504432a6f477a1.tar.gz wsmancli-23e187b9a2225f4bd64c7088c2504432a6f477a1.tar.xz wsmancli-23e187b9a2225f4bd64c7088c2504432a6f477a1.zip |
add cim extensions option
Diffstat (limited to 'src')
-rw-r--r-- | src/wsman-client-options.c | 752 | ||||
-rw-r--r-- | src/wsman-client-options.h | 62 | ||||
-rw-r--r-- | src/wsman.c | 170 |
3 files changed, 522 insertions, 462 deletions
diff --git a/src/wsman-client-options.c b/src/wsman-client-options.c index 5e5ca76..a2e0226 100644 --- a/src/wsman-client-options.c +++ b/src/wsman-client-options.c @@ -52,17 +52,17 @@ #if 0 static char *auth_methods[] = { - "basic", - "digest", - "ntlm", - NULL, + "basic", + "digest", + "ntlm", + NULL, }; #endif static const char **wsman_argv = NULL; -static int server_port = 0; +static int server_port = 0; static char *cafile = NULL; static char *username = NULL; static char *password = NULL; @@ -78,11 +78,12 @@ static char *proxy_upwd = NULL; static int debug_level = -1; static char *test_case = NULL; static int enum_max_elements = 0; -char enum_optimize = 0; -char enum_estimate = 0; -char dump_request = 0; -char step = 0; -char request_only = 0; +char enum_optimize = 0; +char enum_estimate = 0; +char dump_request = 0; +char step = 0; +char request_only = 0; +char cim_extensions = 0; static char *enum_mode = NULL; static char *binding_enum_mode = NULL; static char *enum_context = NULL; @@ -105,367 +106,386 @@ static char *invoke_method = NULL; static char **properties = NULL; -WsActions action_data[] = - { - { "get", WSMAN_ACTION_TRANSFER_GET}, - { "put", WSMAN_ACTION_TRANSFER_PUT}, - { "create", WSMAN_ACTION_TRANSFER_CREATE}, - { "delete", WSMAN_ACTION_TRANSFER_DELETE}, - { "enumerate", WSMAN_ACTION_ENUMERATION}, - { "pull", WSMAN_ACTION_PULL}, - { "release", WSMAN_ACTION_RELEASE}, - { "invoke", WSMAN_ACTION_CUSTOM }, - { "identify", WSMAN_ACTION_IDENTIFY}, - { "test", WSMAN_ACTION_TEST}, - { NULL, 0}, - }; - -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" }, - { "cafile", 'c', U_OPTION_ARG_STRING, &cafile, - "Certificate file", "<filename>" }, - { "username", 'u', U_OPTION_ARG_STRING, &username, - "User name", "<username>" }, - { "path", 'g', U_OPTION_ARG_STRING, &url_path, - "Path", "<path>" }, - { "input", 'J', U_OPTION_ARG_STRING, &input, - "File with resource for Create and Put operations in XML, can be a SOAP envelope", "<filename>" }, - { "password", 'p', U_OPTION_ARG_STRING, &password, - "Password", "<password>" }, - { "hostname", 'h', U_OPTION_ARG_STRING, &server, - "Host name", "<hostname>" }, - { "port", 'P', U_OPTION_ARG_INT, &server_port, - "Server Port", "<port>"}, - { "proxy", 'X', U_OPTION_ARG_STRING, &proxy, - "Proxy name", "<proxy>" }, - { "proxyauth", 'Y', U_OPTION_ARG_STRING, &proxy_upwd, - "Proxy user:pwd", "<proxyauth>" }, - { "auth", 'y', U_OPTION_ARG_STRING, &authentication_method, - "Authentication Method", "<basic|digest|gss>" }, - { "method", 'a', U_OPTION_ARG_STRING, &invoke_method, - "Method (Works only with 'invoke')", "<custom method>" }, - { "prop", 'k', U_OPTION_ARG_STRING_ARRAY, &properties, - "Properties with key value pairs (For 'put', 'invoke' and 'create')", - "<key=val>" }, - { "config-file",'C', U_OPTION_ARG_STRING, &config_file, - "Alternate configuration file", "<file>" }, - { "out-file", 'O', U_OPTION_ARG_STRING, &output_file, - "Write output to file", "<file>" }, - { "noverifypeer",'V', U_OPTION_ARG_NONE, &no_verify_peer, - "Not to verify peer certificate", NULL }, - { NULL } - }; - - - - u_option_entry_t request_options[] = { - { "filter", 'x', U_OPTION_ARG_STRING, &wsm_filter, - "Filter" , "<filter>" }, - { "dialect", 'D', U_OPTION_ARG_STRING, &wsm_dialect, - "Filter Dialect" , "<dialect>" }, - { "timeout", 't', U_OPTION_ARG_INT, &operation_timeout, - "Operation timeout in seconds", "<time in sec>" }, - { "max-envelope-size", 'e', U_OPTION_ARG_INT, &max_envelope_size, - "maximal envelope size" , "<size>" }, - { "fragment", 'F', U_OPTION_ARG_STRING, &fragment, - "Fragment (Supported Dialects: XPATH)" , "<fragment>" }, - { NULL } - }; - - u_option_entry_t enum_options[] = { - - { "max-elements", 'm', U_OPTION_ARG_INT, &enum_max_elements, - "Max Elements Per Pull/Optimized Enumeration", - "<max number of elements>" }, - { "optimize", 'o', U_OPTION_ARG_NONE, &enum_optimize, - "Optimize enumeration results", NULL }, - { "estimate-count", 'E', U_OPTION_ARG_NONE, &enum_estimate, - "Return estimation of total items", NULL }, - { "enum-mode", 'M', U_OPTION_ARG_STRING, &enum_mode, - "Enumeration Mode", "epr|objepr" }, - { "enum-context", 'U', U_OPTION_ARG_STRING, &enum_context, - "Enumeration Context (For use with Pull and Release)", "<enum context>" }, - { NULL } - }; - - u_option_entry_t cim_options[] = { - - { "namespace", 'N', U_OPTION_ARG_STRING, &cim_namespace, - "CIM Namespace (default is root/cimv2)", "<namespace>" }, - { "binding-enum-mode", 'B', U_OPTION_ARG_STRING, &binding_enum_mode, - "CIM binding Enumeration Mode", "none|include|exclude"}, - - { NULL } - }; - - u_option_entry_t test_options[] = { - { "from-file", 'f', U_OPTION_ARG_STRING, &test_case, - "Send request from file", "<file name>"}, - { "print-request", 'R', U_OPTION_ARG_NONE, &dump_request, - "print request on stdout", NULL}, - { "request",'Q', U_OPTION_ARG_NONE, &request_only, - "Only output reqest. Not send it.", NULL }, - { "step",'S', U_OPTION_ARG_NONE, &step, - "Do not perform multiple operations (do not pull data when enumerating)", NULL }, - //{ "print-response", 'N', 0, G_OPTION_ARG_NONE, &dump_response, "print all responses to stdout", NULL}, - { NULL } - }; - - u_option_group_t *enum_group; - u_option_group_t *test_group; - u_option_group_t *cim_group; - u_option_group_t *req_flag_group; - - u_option_context_t *opt_ctx; - opt_ctx = u_option_context_new("<action> <Resource Uri>"); - enum_group = u_option_group_new("enumeration", "Enumeration", - "Enumeration Options"); - test_group = u_option_group_new("tests", "Tests", "Test Cases"); - cim_group = u_option_group_new("cim", "CIM", "CIM Options"); - req_flag_group = u_option_group_new("flags", "Flags", "Request Flags"); - - u_option_group_add_entries(enum_group, enum_options); - u_option_group_add_entries(test_group, test_options); - u_option_group_add_entries(cim_group, cim_options); - u_option_group_add_entries(req_flag_group, request_options); - - u_option_context_set_ignore_unknown_options(opt_ctx, FALSE); - u_option_context_add_main_entries(opt_ctx, options, "wsman"); - u_option_context_add_group(opt_ctx, enum_group); - u_option_context_add_group(opt_ctx, test_group); - u_option_context_add_group(opt_ctx, cim_group); - u_option_context_add_group(opt_ctx, req_flag_group); - - retval = u_option_context_parse(opt_ctx, &argc, &argv, &error); - u_option_context_free(opt_ctx); - - if (error) { - if (error->message) - printf ("%s\n", error->message); - u_error_free(error); - return FALSE; - } - - if (argc > 2 ) { - _action = argv[1]; - resource_uri = argv[2]; - } else { - if (argv[1] && ( strcmp(argv[1], "identify") == 0 || - strcmp(argv[1], "test") == 0 )) { - _action = argv[1]; - } else { - fprintf(stderr, "Error: operation can not be completed." - " Action or/and Resource Uri missing.\n"); - return FALSE; - } - } - u_error_free(error); - - // set default options - if (server_port == 0) { - server_port = cafile ? 8888 : 8889; - } - if (url_path == NULL) { - url_path = "/wsman"; - } - return TRUE; -} - -const char * wsman_options_get_output_file (void) -{ - return output_file; -} -const char * wsman_options_get_config_file (void) { - return config_file; -} - -int wsman_read_client_config (dictionary *ini) -{ - if (iniparser_find_entry(ini, "client")) { - agent = iniparser_getstr(ini, "client:agent"); - server_port = server_port ? - server_port : iniparser_getint(ini, "client:port", 80); - authentication_method = authentication_method? - authentication_method: - iniparser_getstr(ini, "client:authentication_method"); - } else { - return 0; - } - return 1; +WsActions action_data[] = { + {"get", WSMAN_ACTION_TRANSFER_GET}, + {"put", WSMAN_ACTION_TRANSFER_PUT}, + {"create", WSMAN_ACTION_TRANSFER_CREATE}, + {"delete", WSMAN_ACTION_TRANSFER_DELETE}, + {"enumerate", WSMAN_ACTION_ENUMERATION}, + {"pull", WSMAN_ACTION_PULL}, + {"release", WSMAN_ACTION_RELEASE}, + {"invoke", WSMAN_ACTION_CUSTOM}, + {"identify", WSMAN_ACTION_IDENTIFY}, + {"test", WSMAN_ACTION_TEST}, + {NULL, 0}, +}; + +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"}, + {"cafile", 'c', U_OPTION_ARG_STRING, &cafile, + "Certificate file", "<filename>"}, + {"username", 'u', U_OPTION_ARG_STRING, &username, + "User name", "<username>"}, + {"path", 'g', U_OPTION_ARG_STRING, &url_path, + "Path", "<path>"}, + {"input", 'J', U_OPTION_ARG_STRING, &input, + "File with resource for Create and Put operations in XML, can be a SOAP envelope", + "<filename>"}, + {"password", 'p', U_OPTION_ARG_STRING, &password, + "Password", "<password>"}, + {"hostname", 'h', U_OPTION_ARG_STRING, &server, + "Host name", "<hostname>"}, + {"port", 'P', U_OPTION_ARG_INT, &server_port, + "Server Port", "<port>"}, + {"proxy", 'X', U_OPTION_ARG_STRING, &proxy, + "Proxy name", "<proxy>"}, + {"proxyauth", 'Y', U_OPTION_ARG_STRING, &proxy_upwd, + "Proxy user:pwd", "<proxyauth>"}, + {"auth", 'y', U_OPTION_ARG_STRING, &authentication_method, + "Authentication Method", "<basic|digest|gss>"}, + {"method", 'a', U_OPTION_ARG_STRING, &invoke_method, + "Method (Works only with 'invoke')", "<custom method>"}, + {"prop", 'k', U_OPTION_ARG_STRING_ARRAY, &properties, + "Properties with key value pairs (For 'put', 'invoke' and 'create')", + "<key=val>"}, + {"config-file", 'C', U_OPTION_ARG_STRING, &config_file, + "Alternate configuration file", "<file>"}, + {"out-file", 'O', U_OPTION_ARG_STRING, &output_file, + "Write output to file", "<file>"}, + {"noverifypeer", 'V', U_OPTION_ARG_NONE, &no_verify_peer, + "Not to verify peer certificate", NULL}, + {NULL} + }; + + + + u_option_entry_t request_options[] = { + {"filter", 'x', U_OPTION_ARG_STRING, &wsm_filter, + "Filter", "<filter>"}, + {"dialect", 'D', U_OPTION_ARG_STRING, &wsm_dialect, + "Filter Dialect", "<dialect>"}, + {"timeout", 't', U_OPTION_ARG_INT, &operation_timeout, + "Operation timeout in seconds", "<time in sec>"}, + {"max-envelope-size", 'e', U_OPTION_ARG_INT, + &max_envelope_size, + "maximal envelope size", "<size>"}, + {"fragment", 'F', U_OPTION_ARG_STRING, &fragment, + "Fragment (Supported Dialects: XPATH)", "<fragment>"}, + {NULL} + }; + + u_option_entry_t enum_options[] = { + + {"max-elements", 'm', U_OPTION_ARG_INT, &enum_max_elements, + "Max Elements Per Pull/Optimized Enumeration", + "<max number of elements>"}, + {"optimize", 'o', U_OPTION_ARG_NONE, &enum_optimize, + "Optimize enumeration results", NULL}, + {"estimate-count", 'E', U_OPTION_ARG_NONE, &enum_estimate, + "Return estimation of total items", NULL}, + {"enum-mode", 'M', U_OPTION_ARG_STRING, &enum_mode, + "Enumeration Mode", "epr|objepr"}, + {"enum-context", 'U', U_OPTION_ARG_STRING, &enum_context, + "Enumeration Context (For use with Pull and Release)", + "<enum context>"}, + {NULL} + }; + + u_option_entry_t cim_options[] = { + + {"namespace", 'N', U_OPTION_ARG_STRING, &cim_namespace, + "CIM Namespace (default is root/cimv2)", "<namespace>"}, + {"binding-enum-mode", 'B', U_OPTION_ARG_STRING, + &binding_enum_mode, + "CIM binding Enumeration Mode", "none|include|exclude"}, + {"cim-extensions", 'T', U_OPTION_ARG_NONE, &cim_extensions, + "Show CIM Extensions", NULL}, + + {NULL} + }; + + u_option_entry_t test_options[] = { + {"from-file", 'f', U_OPTION_ARG_STRING, &test_case, + "Send request from file", "<file name>"}, + {"print-request", 'R', U_OPTION_ARG_NONE, &dump_request, + "print request on stdout", NULL}, + {"request", 'Q', U_OPTION_ARG_NONE, &request_only, + "Only output reqest. Not send it.", NULL}, + {"step", 'S', U_OPTION_ARG_NONE, &step, + "Do not perform multiple operations (do not pull data when enumerating)", + NULL}, + //{ "print-response", 'N', 0, G_OPTION_ARG_NONE, &dump_response, "print all responses to stdout", NULL}, + {NULL} + }; + + u_option_group_t *enum_group; + u_option_group_t *test_group; + u_option_group_t *cim_group; + u_option_group_t *req_flag_group; + + u_option_context_t *opt_ctx; + opt_ctx = u_option_context_new("<action> <Resource Uri>"); + enum_group = u_option_group_new("enumeration", "Enumeration", + "Enumeration Options"); + test_group = u_option_group_new("tests", "Tests", "Test Cases"); + cim_group = u_option_group_new("cim", "CIM", "CIM Options"); + req_flag_group = + u_option_group_new("flags", "Flags", "Request Flags"); + + u_option_group_add_entries(enum_group, enum_options); + u_option_group_add_entries(test_group, test_options); + u_option_group_add_entries(cim_group, cim_options); + u_option_group_add_entries(req_flag_group, request_options); + + u_option_context_set_ignore_unknown_options(opt_ctx, FALSE); + u_option_context_add_main_entries(opt_ctx, options, "wsman"); + u_option_context_add_group(opt_ctx, enum_group); + u_option_context_add_group(opt_ctx, test_group); + u_option_context_add_group(opt_ctx, cim_group); + u_option_context_add_group(opt_ctx, req_flag_group); + + retval = u_option_context_parse(opt_ctx, &argc, &argv, &error); + u_option_context_free(opt_ctx); + + if (error) { + if (error->message) + printf("%s\n", error->message); + u_error_free(error); + return FALSE; + } + + if (argc > 2) { + _action = argv[1]; + resource_uri = argv[2]; + } else { + if (argv[1] && (strcmp(argv[1], "identify") == 0 || + strcmp(argv[1], "test") == 0)) { + _action = argv[1]; + } else { + fprintf(stderr, + "Error: operation can not be completed." + " Action or/and Resource Uri missing.\n"); + return FALSE; + } + } + u_error_free(error); + + // set default options + if (server_port == 0) { + server_port = cafile ? 8888 : 8889; + } + if (url_path == NULL) { + url_path = "/wsman"; + } + return TRUE; +} + +const char *wsman_options_get_output_file(void) +{ + return output_file; +} +const char *wsman_options_get_config_file(void) +{ + return config_file; +} + +int wsman_read_client_config(dictionary * ini) +{ + if (iniparser_find_entry(ini, "client")) { + agent = iniparser_getstr(ini, "client:agent"); + server_port = server_port ? + server_port : iniparser_getint(ini, "client:port", 80); + authentication_method = authentication_method ? + authentication_method : + iniparser_getstr(ini, "client:authentication_method"); + } else { + return 0; + } + return 1; } void wsman_setup_transport_and_library_options() { - // transport options - wsman_transport_set_auth_method(authentication_method); - if (proxy) { - wsman_transport_set_proxy(proxy); - if (proxy_upwd) { - wsman_transport_set_proxyauth(proxy_upwd); - } - } - if (cafile) { - wsman_transport_set_cafile(cafile); - } - wsman_transport_set_no_verify_peer(no_verify_peer); - - // library options - wsman_debug_set_level(debug_level); -} - - -const char ** wsman_options_get_argv (void) { - return wsman_argv; -} - + // transport options + wsman_transport_set_auth_method(authentication_method); + if (proxy) { + wsman_transport_set_proxy(proxy); + if (proxy_upwd) { + wsman_transport_set_proxyauth(proxy_upwd); + } + } + if (cafile) { + wsman_transport_set_cafile(cafile); + } + wsman_transport_set_no_verify_peer(no_verify_peer); + + // library options + wsman_debug_set_level(debug_level); +} + + +const char **wsman_options_get_argv(void) +{ + return wsman_argv; +} + + + +int wsman_options_get_server_port(void) +{ + return server_port; +} + +unsigned long wsman_options_get_max_envelope_size(void) +{ + return max_envelope_size; +} +unsigned long wsman_options_get_operation_timeout(void) +{ + return operation_timeout; +} + +char *wsman_options_get_cafile(void) +{ + return cafile; +} +char *wsman_options_get_server(void) +{ + if (server) + return server; + else + return "localhost"; +} -int wsman_options_get_server_port (void) { - return server_port; -} - -unsigned long -wsman_options_get_max_envelope_size (void) -{ - return max_envelope_size; -} -unsigned long wsman_options_get_operation_timeout (void) { - return operation_timeout; -} - -char* wsman_options_get_cafile (void) { - return cafile; -} - -char* wsman_options_get_server (void) { - if (server) - return server; - else - return "localhost"; -} - -char* wsman_options_get_invoke_method (void) { - return invoke_method; -} - -char* wsman_options_get_username (void) { - return username; -} - -char* wsman_options_get_password (void) { - return password; -} - - - -hash_t * wsman_options_get_properties (void) -{ - int c = 0; - hash_t *h = hash_create(HASHCOUNT_T_MAX, 0, 0); - - while(properties != NULL && properties[c] != NULL) - { - char *cc[3]; - u_tokenize1(cc, 2, properties[c], '='); - if (!hash_alloc_insert(h, cc[0], cc[1])) { - debug("hash_alloc_insert failed"); - } - c++; - } - return h; -} - -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; -} - -char* wsman_options_get_resource_uri (void) -{ - return resource_uri; -} - -int wsman_options_get_max_elements (void) -{ - return enum_max_elements; -} -char wsman_options_get_optimize_enum (void) -{ - return enum_optimize; -} -char wsman_options_get_estimate_enum (void) -{ - return enum_estimate; -} -char wsman_options_get_dump_request (void) -{ - return dump_request; -} -char wsman_options_get_step_request (void) -{ - return step; -} - -char * wsman_options_get_enum_context (void) -{ - return enum_context; -} - -char * wsman_options_get_test_file (void) -{ - return test_case; -} - -char * wsman_options_get_input_file (void) -{ - return input; -} - -char * wsman_options_get_enum_mode (void) -{ - return enum_mode; -} -char* -wsman_options_get_binding_enum_mode (void) -{ - return binding_enum_mode; -} -char* -wsman_options_get_cim_namespace (void) -{ - return cim_namespace; -} -char * wsman_options_get_fragment (void) -{ - return fragment; -} -char * wsman_options_get_filter (void) -{ - return wsm_filter; -} - -char * wsman_options_get_dialect (void) -{ - return wsm_dialect; -} -char * wsman_options_get_path (void) -{ - return url_path; +char *wsman_options_get_invoke_method(void) +{ + return invoke_method; } +char *wsman_options_get_username(void) +{ + return username; +} + +char *wsman_options_get_password(void) +{ + return password; +} + + + +hash_t *wsman_options_get_properties(void) +{ + int c = 0; + hash_t *h = hash_create(HASHCOUNT_T_MAX, 0, 0); + + while (properties != NULL && properties[c] != NULL) { + char *cc[3]; + u_tokenize1(cc, 2, properties[c], '='); + if (!hash_alloc_insert(h, cc[0], cc[1])) { + debug("hash_alloc_insert failed"); + } + c++; + } + return h; +} + +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; +} + +char *wsman_options_get_resource_uri(void) +{ + return resource_uri; +} + +int wsman_options_get_max_elements(void) +{ + return enum_max_elements; +} +char wsman_options_get_optimize_enum(void) +{ + return enum_optimize; +} + + +char wsman_options_get_cim_ext(void) +{ + return cim_extensions; +} + +char wsman_options_get_estimate_enum(void) +{ + return enum_estimate; +} +char wsman_options_get_dump_request(void) +{ + return dump_request; +} +char wsman_options_get_step_request(void) +{ + return step; +} + +char *wsman_options_get_enum_context(void) +{ + return enum_context; +} + +char *wsman_options_get_test_file(void) +{ + return test_case; +} + +char *wsman_options_get_input_file(void) +{ + return input; +} + +char *wsman_options_get_enum_mode(void) +{ + return enum_mode; +} + +char *wsman_options_get_binding_enum_mode(void) +{ + return binding_enum_mode; +} +char *wsman_options_get_cim_namespace(void) +{ + return cim_namespace; +} +char *wsman_options_get_fragment(void) +{ + return fragment; +} +char *wsman_options_get_filter(void) +{ + return wsm_filter; +} + +char *wsman_options_get_dialect(void) +{ + return wsm_dialect; +} +char *wsman_options_get_path(void) +{ + return url_path; +} diff --git a/src/wsman-client-options.h b/src/wsman-client-options.h index 8f9374d..d14fedd 100644 --- a/src/wsman-client-options.h +++ b/src/wsman-client-options.h @@ -2,51 +2,51 @@ #ifndef WSMANCLIENTOPTIONS_H_ #define WSMANCLIENTOPTIONS_H_ -struct _WsActions -{ - char* action; - int value; +struct _WsActions { + char *action; + int value; }; typedef struct _WsActions WsActions; -extern int wsman_read_client_config (dictionary *ini); +extern int wsman_read_client_config(dictionary * ini); extern char wsman_parse_options(int argc, char **argv); extern void wsman_setup_transport_and_library_options(void); extern char *wsman_options_get_server(void); extern int wsman_options_get_server_port(void); -extern char * wsman_options_get_path (void); +extern char *wsman_options_get_path(void); extern char *wsman_options_get_username(void); extern char *wsman_options_get_password(void); extern char *wsman_options_get_cafile(void); extern int wsman_options_get_max_elements(void); -extern char * wsman_options_get_test_file(void); -extern char * wsman_options_get_input_file(void); +extern char *wsman_options_get_test_file(void); +extern char *wsman_options_get_input_file(void); extern int wsman_options_get_action(void); extern char *wsman_options_get_resource_uri(void); -extern hash_t *wsman_options_get_properties (void); -extern char *wsman_options_get_invoke_method (void); -extern char *wsman_options_get_enum_mode (void); -extern char *wsman_options_get_binding_enum_mode (void); -extern char *wsman_options_get_cim_namespace (void); -extern char wsman_options_get_optimize_enum (void); -extern char wsman_options_get_dump_request (void); -extern char wsman_options_get_step_request (void); -extern char wsman_options_get_estimate_enum (void); -extern char * wsman_options_get_fragment (void); -extern char * wsman_options_get_filter (void); - -extern char * wsman_options_get_dialect (void); -extern const char * wsman_options_get_config_file (void); -extern unsigned long wsman_options_get_max_envelope_size (void); -extern unsigned long wsman_options_get_operation_timeout (void); - -extern char * wsman_options_get_enum_context (void); - -extern const char ** wsman_options_get_argv (void); -extern const char * wsman_options_get_output_file (void); - -#endif /*WSMANCLIENTOPTIONS_H_*/ +extern hash_t *wsman_options_get_properties(void); +extern char *wsman_options_get_invoke_method(void); +extern char *wsman_options_get_enum_mode(void); +extern char *wsman_options_get_binding_enum_mode(void); +extern char *wsman_options_get_cim_namespace(void); +extern char wsman_options_get_optimize_enum(void); +extern char wsman_options_get_cim_ext(void); +extern char wsman_options_get_dump_request(void); +extern char wsman_options_get_step_request(void); +extern char wsman_options_get_estimate_enum(void); +extern char *wsman_options_get_fragment(void); +extern char *wsman_options_get_filter(void); + +extern char *wsman_options_get_dialect(void); +extern const char *wsman_options_get_config_file(void); +extern unsigned long wsman_options_get_max_envelope_size(void); +extern unsigned long wsman_options_get_operation_timeout(void); + +extern char *wsman_options_get_enum_context(void); + +extern const char **wsman_options_get_argv(void); +extern const char *wsman_options_get_output_file(void); + +#endif /*WSMANCLIENTOPTIONS_H_ */ diff --git a/src/wsman.c b/src/wsman.c index 3387a78..7d38ebd 100644 --- a/src/wsman.c +++ b/src/wsman.c @@ -54,11 +54,10 @@ #include "wsman-client-options.h" -static void -wsman_output(WsManClient *cl, WsXmlDocH doc) +static void wsman_output(WsManClient * cl, WsXmlDocH doc) { - FILE *f = stdout; - const char *filename = wsman_options_get_output_file(); + FILE *f = stdout; + const char *filename = wsman_options_get_output_file(); WS_LASTERR_Code err; err = wsman_client_get_last_error(cl); @@ -84,30 +83,30 @@ wsman_output(WsManClient *cl, WsXmlDocH doc) } -static void -initialize_logging(void) +static void initialize_logging(void) { - debug_add_handler(wsman_debug_message_handler, DEBUG_LEVEL_ALWAYS, NULL); + debug_add_handler(wsman_debug_message_handler, DEBUG_LEVEL_ALWAYS, + NULL); } -int -main(int argc, char **argv) +int main(int argc, char **argv) { - int retVal = 0; - int op; - char *filename; - dictionary *ini = NULL; - WsManClient *cl; - WsXmlDocH doc; - char *enumContext; - WsXmlDocH rqstDoc; - actionOptions options; - WsXmlDocH enum_response; - WsXmlDocH resource; - char *enumeration_mode, *binding_enumeration_mode, *resource_uri_with_selectors; - char *resource_uri = NULL; + int retVal = 0; + int op; + char *filename; + dictionary *ini = NULL; + WsManClient *cl; + WsXmlDocH doc; + char *enumContext; + WsXmlDocH rqstDoc; + actionOptions options; + WsXmlDocH enum_response; + WsXmlDocH resource; + char *enumeration_mode, *binding_enumeration_mode, + *resource_uri_with_selectors; + char *resource_uri = NULL; @@ -115,7 +114,8 @@ main(int argc, char **argv) if (filename) { ini = iniparser_load(filename); if (ini == NULL) { - fprintf(stderr, "cannot parse file [%s]", filename); + fprintf(stderr, "cannot parse file [%s]", + filename); exit(EXIT_FAILURE); } else if (!wsman_read_client_config(ini)) { fprintf(stderr, "Configuration file not found\n"); @@ -128,17 +128,17 @@ main(int argc, char **argv) wsman_setup_transport_and_library_options(); initialize_logging(); - // wsman_client_transport_init(NULL); + // wsman_client_transport_init(NULL); initialize_action_options(&options); debug("Certificate: %s", wsman_options_get_cafile()); cl = wsman_create_client(wsman_options_get_server(), - wsman_options_get_server_port(), - wsman_options_get_path(), - wsman_options_get_cafile() ? "https" : "http", - wsman_options_get_username(), - wsman_options_get_password()); + wsman_options_get_server_port(), + wsman_options_get_path(), + wsman_options_get_cafile()? "https" : + "http", wsman_options_get_username(), + wsman_options_get_password()); @@ -151,8 +151,10 @@ main(int argc, char **argv) */ resource_uri_with_selectors = wsman_options_get_resource_uri(); if (resource_uri_with_selectors) { - wsman_set_options_from_uri(resource_uri_with_selectors, &options); - wsman_remove_query_string(resource_uri_with_selectors, &resource_uri); + wsman_set_options_from_uri(resource_uri_with_selectors, + &options); + wsman_remove_query_string(resource_uri_with_selectors, + &resource_uri); } op = wsman_options_get_action(); @@ -160,7 +162,8 @@ main(int argc, char **argv) wsman_set_action_option(&options, FLAG_DUMP_REQUEST); } if (wsman_options_get_max_envelope_size()) { - options.max_envelope_size = wsman_options_get_max_envelope_size(); + options.max_envelope_size = + wsman_options_get_max_envelope_size(); } if (wsman_options_get_operation_timeout()) { options.timeout = wsman_options_get_operation_timeout(); @@ -176,12 +179,16 @@ main(int argc, char **argv) } options.properties = wsman_options_get_properties(); options.cim_ns = wsman_options_get_cim_namespace(); + if (wsman_options_get_cim_ext()) { + wsman_set_action_option(&options, FLAG_CIM_EXTENSIONS); + } switch (op) { case WSMAN_ACTION_TEST: rqstDoc = wsman_client_read_file(cl, - wsman_options_get_input_file(), "UTF-8", 0); + wsman_options_get_input_file + (), "UTF-8", 0); wsman_send_request(cl, rqstDoc); doc = wsman_build_envelope_from_response(cl); wsman_output(cl, doc); @@ -199,7 +206,8 @@ main(int argc, char **argv) case WSMAN_ACTION_CUSTOM: doc = wsman_invoke(cl, resource_uri, options, - wsman_options_get_invoke_method(), NULL); + wsman_options_get_invoke_method(), + NULL); wsman_output(cl, doc); if (doc) { ws_xml_destroy_doc(doc); @@ -211,17 +219,20 @@ main(int argc, char **argv) if (doc) { ws_xml_destroy_doc(doc); } - break; + break; case WSMAN_ACTION_TRANSFER_CREATE: if (wsman_options_get_input_file()) { resource = wsman_client_read_file(cl, - wsman_options_get_input_file(), "UTF-8", 0); - doc = ws_transfer_create(cl, resource_uri, options, resource); + wsman_options_get_input_file + (), "UTF-8", 0); + doc = + ws_transfer_create(cl, resource_uri, options, + resource); ws_xml_destroy_doc(resource); wsman_output(cl, doc); if (doc) { ws_xml_destroy_doc(doc); - } + } } else { fprintf(stderr, "Missing resource data\n"); } @@ -230,11 +241,16 @@ main(int argc, char **argv) if (wsman_options_get_input_file()) { printf("input file provided\n"); resource = wsman_client_read_file(cl, - wsman_options_get_input_file(), "UTF-8", 0); - doc = ws_transfer_put(cl, resource_uri, options, resource); + wsman_options_get_input_file + (), "UTF-8", 0); + doc = + ws_transfer_put(cl, resource_uri, options, + resource); ws_xml_destroy_doc(resource); } else { - doc = ws_transfer_get_and_put(cl, resource_uri, options); + doc = + ws_transfer_get_and_put(cl, resource_uri, + options); } wsman_output(cl, doc); if (doc) { @@ -249,14 +265,18 @@ main(int argc, char **argv) } break; case WSMAN_ACTION_PULL: - doc = wsenum_pull(cl, resource_uri, options, wsman_options_get_enum_context()); + doc = + wsenum_pull(cl, resource_uri, options, + wsman_options_get_enum_context()); wsman_output(cl, doc); if (doc) { ws_xml_destroy_doc(doc); } break; case WSMAN_ACTION_RELEASE: - doc = wsenum_release(cl, resource_uri, options, wsman_options_get_enum_context()); + doc = + wsenum_release(cl, resource_uri, options, + wsman_options_get_enum_context()); wsman_output(cl, doc); if (doc) { ws_xml_destroy_doc(doc); @@ -265,40 +285,53 @@ main(int argc, char **argv) case WSMAN_ACTION_ENUMERATION: enumeration_mode = wsman_options_get_enum_mode(); - binding_enumeration_mode = wsman_options_get_binding_enum_mode(); + binding_enumeration_mode = + wsman_options_get_binding_enum_mode(); if (enumeration_mode) { if (strcmp(enumeration_mode, "epr") == 0) - wsman_set_action_option(&options, FLAG_ENUMERATION_ENUM_EPR); + wsman_set_action_option(&options, + FLAG_ENUMERATION_ENUM_EPR); else - wsman_set_action_option(&options, FLAG_ENUMERATION_ENUM_OBJ_AND_EPR); + wsman_set_action_option(&options, + FLAG_ENUMERATION_ENUM_OBJ_AND_EPR); } if (binding_enumeration_mode) { - if (strcmp(binding_enumeration_mode, "include") == 0) - wsman_set_action_option(&options, FLAG_IncludeSubClassProperties); - else if (strcmp(binding_enumeration_mode, "exclude") == 0) - wsman_set_action_option(&options, FLAG_ExcludeSubClassProperties); - else if (strcmp(binding_enumeration_mode, "none") == 0) - wsman_set_action_option(&options, FLAG_POLYMORPHISM_NONE); + if (strcmp(binding_enumeration_mode, "include") == + 0) + wsman_set_action_option(&options, + FLAG_IncludeSubClassProperties); + else if (strcmp + (binding_enumeration_mode, + "exclude") == 0) + wsman_set_action_option(&options, + FLAG_ExcludeSubClassProperties); + else if (strcmp(binding_enumeration_mode, "none") + == 0) + wsman_set_action_option(&options, + FLAG_POLYMORPHISM_NONE); } if (wsman_options_get_optimize_enum()) { - wsman_set_action_option(&options, FLAG_ENUMERATION_OPTIMIZATION); + wsman_set_action_option(&options, + FLAG_ENUMERATION_OPTIMIZATION); } options.max_elements = wsman_options_get_max_elements(); if (wsman_options_get_estimate_enum()) { - wsman_set_action_option(&options, FLAG_ENUMERATION_COUNT_ESTIMATION); + wsman_set_action_option(&options, + FLAG_ENUMERATION_COUNT_ESTIMATION); } enum_response = wsenum_enumerate(cl, - resource_uri, options); + resource_uri, options); wsman_output(cl, enum_response); if (enum_response) { if (!(wsman_client_get_response_code(cl) == 200 || - wsman_client_get_response_code(cl) == 400 || - wsman_client_get_response_code(cl) == 500)) { + wsman_client_get_response_code(cl) == 400 || + wsman_client_get_response_code(cl) == 500)) { break; } - enumContext = wsenum_get_enum_context(enum_response); + enumContext = + wsenum_get_enum_context(enum_response); ws_xml_destroy_doc(enum_response); } else { break; @@ -307,12 +340,17 @@ main(int argc, char **argv) if (!wsman_options_get_step_request()) { while (enumContext != NULL && enumContext[0] != 0) { - doc = wsenum_pull(cl, resource_uri, options, enumContext); + doc = + wsenum_pull(cl, resource_uri, options, + enumContext); wsman_output(cl, doc); - if (wsman_client_get_response_code(cl) != 200 && - wsman_client_get_response_code(cl) != 400 && - wsman_client_get_response_code(cl) != 500) { + if (wsman_client_get_response_code(cl) != + 200 + && wsman_client_get_response_code(cl) + != 400 + && wsman_client_get_response_code(cl) + != 500) { break; } enumContext = wsenum_get_enum_context(doc); @@ -330,9 +368,10 @@ main(int argc, char **argv) if (wsman_client_get_response_code(cl) != 200) { fprintf(stderr, "Connection failed. response code = %ld\n", - wsman_client_get_response_code(cl)); + wsman_client_get_response_code(cl)); if (wsman_client_get_fault_string(cl)) { - fprintf(stderr, "%s\n", wsman_client_get_fault_string(cl)); + fprintf(stderr, "%s\n", + wsman_client_get_fault_string(cl)); } } destroy_action_options(&options); @@ -343,7 +382,8 @@ main(int argc, char **argv) iniparser_freedict(ini); } #ifdef DEBUG_VERBOSE - printf(" ****** Transfer Time = %ull usecs ******\n", get_transfer_time()); + printf(" ****** Transfer Time = %ull usecs ******\n", + get_transfer_time()); #endif return retVal; |