summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorDenis Sadykov <sadden@intel.com>2007-01-24 15:42:55 +0000
committerDenis Sadykov <sadden@intel.com>2007-01-24 15:42:55 +0000
commit7dab0154975928ff1fe171761e81f4ffbf13f3e2 (patch)
treec323a431cf0a666bdf06307efa076c98a0da38c8 /examples
parent5bfddd295747f14535ee7775301238e34c7deafb (diff)
downloadwsmancli-7dab0154975928ff1fe171761e81f4ffbf13f3e2.tar.gz
wsmancli-7dab0154975928ff1fe171761e81f4ffbf13f3e2.tar.xz
wsmancli-7dab0154975928ff1fe171761e81f4ffbf13f3e2.zip
new api example
Diffstat (limited to 'examples')
-rw-r--r--examples/new_api_example.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/examples/new_api_example.c b/examples/new_api_example.c
new file mode 100644
index 0000000..00ff787
--- /dev/null
+++ b/examples/new_api_example.c
@@ -0,0 +1,101 @@
+
+
+#include "wsman-client-api.h"
+
+static char *endpoint = NULL;
+
+int main(int argc, char** argv)
+{
+ int sid, sid1;
+ wsman_data_t *data;
+ char *buf;
+ int size;
+ char retval = 0;
+ u_error_t *error = NULL;
+ u_uri_t *uri;
+
+
+ u_option_entry_t opt[] = {
+ { "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, "adv api example");
+ 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);
+
+ if (endpoint) {
+ u_uri_parse((const char *)endpoint, &uri);
+ }
+ if (!endpoint || !uri) {
+ fprintf(stderr, "endpoint option required\n");
+ return 1;
+ }
+
+ sid = wsman_session_open(uri->host, uri->port, uri->path, uri->scheme,
+ uri->user, uri->pwd);
+
+ if (sid < 0) {
+ printf("Open session failed\n");
+ return 0;
+ }
+
+ sid1 = wsman_session_open(uri->host, uri->port, uri->path, uri->scheme,
+ uri->user, uri->pwd);
+
+ if (sid < 0) {
+ printf("Open session failed\n");
+ wsman_session_close(sid);
+ return 0;
+ }
+
+ printf("\n******** Opened session id %d ********\n\n", sid);
+ printf("******** Opened session id %d ********\n\n", sid1);
+
+ data = wsman_session_do_action(sid, WSMAN_ACTION_IDENTIFY);
+
+ if (!data->response) {
+ printf("******** Identify failed - %s ********\n",
+ data->fault_message);
+ return 0;
+ }
+ ws_xml_dump_memory_node_tree(ws_xml_get_doc_root(data->response),
+ &buf, &size);
+
+ printf ("******** Identify response (id %d) ********\n%s\n", sid, buf);
+
+ wsman_session_close(sid);
+
+ printf("******** Closed session id %d ********\n\n", sid);
+
+ data = wsman_session_do_action(sid1, WSMAN_ACTION_ENUMERATION);
+
+ if (!data->response) {
+ printf("******** Enumeration failed - %s ********\n",
+ data->fault_message);
+ return 0;
+ }
+ ws_xml_dump_memory_node_tree(ws_xml_get_doc_root(data->response),
+ &buf, &size);
+ printf("******** Enumeration response (id %d) ********\n%s\n", sid1,buf);
+
+ wsman_session_close(sid1);
+
+ printf("******** Closed session id %d ********\n\n", sid1);
+
+ return 1;
+}
+