summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnas Nashif <nashif@intel.com>2006-11-10 21:43:25 +0000
committerAnas Nashif <nashif@intel.com>2006-11-10 21:43:25 +0000
commit229f300df3229d6dd26a6b9fc931532696c16e83 (patch)
tree4e26674bdba80614a9ad262539ae34625ba835f3
parentfd7fe5fc71ee932889a1be3f21c243acb06ebff7 (diff)
downloadwsmancli-229f300df3229d6dd26a6b9fc931532696c16e83.tar.gz
wsmancli-229f300df3229d6dd26a6b9fc931532696c16e83.tar.xz
wsmancli-229f300df3229d6dd26a6b9fc931532696c16e83.zip
read endpoint data from command line
-rwxr-xr-xsrc/wsmid_identify.c104
1 files changed, 73 insertions, 31 deletions
diff --git a/src/wsmid_identify.c b/src/wsmid_identify.c
index 4426821..e50d10a 100755
--- a/src/wsmid_identify.c
+++ b/src/wsmid_identify.c
@@ -64,19 +64,11 @@ SER_STR("ProductVendor", 1, 1),
SER_STR("ProductVersion", 1, 1),
SER_END_ITEMS("IdentifyResponse", wsmid_identify);
-typedef struct {
- const char *server;
- int port;
- const char *path;
- const char *scheme;
- const char *username;
- const char *password;
-} ServerData;
-
-ServerData sd[] = {
- {"localhost", 8889, "/wsman", "http", "wsman", "secret"}
-};
+static char vendor = 0;
+static char version = 0;
+static char protocol = 0;
+static char *endpoint = NULL;
int main(int argc, char** argv)
{
@@ -84,13 +76,55 @@ int main(int argc, char** argv)
WsManClient *cl;
WsXmlDocH doc;
actionOptions options;
+ char retval = 0;
+ u_error_t *error = NULL;
+
+ u_option_entry_t opt[] = {
+ { "product", 'p', U_OPTION_ARG_NONE, &vendor,
+ "Print Product Vendor", NULL },
+ { "version", 'v', U_OPTION_ARG_NONE, &version,
+ "Print Product Version", NULL },
+ { "protocol", 'P', U_OPTION_ARG_NONE, &protocol,
+ "Print Protocol Version", NULL },
+ { "endpoint", 'u', U_OPTION_ARG_STRING, &endpoint,
+ "Endpoint in form of a URL", "<uri>" },
+ { NULL }
+ };
+
+ u_option_context_t *opt_ctx;
+ opt_ctx = u_option_context_new("");
+ u_option_context_set_ignore_unknown_options(opt_ctx, FALSE);
+ u_option_context_add_main_entries(opt_ctx, opt, "wsmid_identify");
+ 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 1;
+ }
+ u_error_free(error);
+
+
+ u_uri_t *uri;
+ if (endpoint) {
+ u_uri_parse((const char *)endpoint, &uri);
+ }
+ if (!endpoint || !uri) {
+ fprintf(stderr, "endpoint option required\n");
+ return 1;
+ }
+
+
wsman_client_transport_init(NULL);
- cl = wsman_create_client( sd[0].server,
- sd[0].port,
- sd[0].path,
- sd[0].scheme,
- sd[0].username,
- sd[0].password);
+ cl = wsman_create_client( uri->host,
+ uri->port,
+ uri->path,
+ uri->scheme,
+ uri->user,
+ uri->pwd);
initialize_action_options(&options);
@@ -98,20 +132,28 @@ int main(int argc, char** argv)
WsXmlNodeH soapBody = ws_xml_get_soap_body(doc);
if (ws_xml_get_child(soapBody, 0, XML_NS_WSMAN_ID, "IdentifyResponse")) {
- wsmid_identify *id = ws_deserialize(
- cl->wscntx,
- soapBody,
- wsmid_identify_TypeInfo,
- "IdentifyResponse",
- XML_NS_WSMAN_ID,
- XML_NS_WSMAN_ID,
- 0,
- 0);
- printf(" Vendor: %s\n", id->ProductVendor);
- printf(" Version: %s\n", id->ProductVersion);
- printf(" Protocol Version: %s\n", id->ProtocolVersion);
+ wsmid_identify *id = ws_deserialize(cl->wscntx, soapBody,
+ wsmid_identify_TypeInfo,"IdentifyResponse",
+ XML_NS_WSMAN_ID, XML_NS_WSMAN_ID,
+ 0,
+ 0);
+
+ if (vendor)
+ printf("%s\n", id->ProductVendor);
+ if (version)
+ printf("%s\n", id->ProductVersion);
+ if (protocol)
+ printf("%s\n", id->ProtocolVersion);
+
+ if (!protocol && !vendor && !version ) {
+ printf("%s %s supporting protocol %s\n", id->ProductVendor, id->ProductVersion,id->ProtocolVersion);
+ }
+
}
-
+ if (uri) {
+ u_uri_free(uri);
+ }
+
if (doc) {
ws_xml_destroy_doc(doc);
}