summaryrefslogtreecommitdiffstats
path: root/examples/session_invoke.c
blob: ff7ebc1a36370fe5ebfa21d03b7ce3fd54819f7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "wsman-client-api.h"

int main(int argc, char** argv)
{
	int		sid;
	int		eid;
	char		*response;
	char 		retval = 0;
	const char	*resource_uri =
	"http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_SystemTimeService";
	u_error_t 	*error = NULL;
	char		*user = NULL;
	char		*passwd = NULL;

	u_option_entry_t opt[] = {
	{ "user",	'u',	U_OPTION_ARG_STRING,	&user,
		"user name", "<user>" },
	{ "passwd",	'p',	U_OPTION_ARG_STRING,	&passwd,
		"password", "<passwd>" },
	{ 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 0;
	}
	u_error_free(error);

	if (!user || !passwd) {
		printf("\t new_api_example: user and passwd are required\n");
		return 0;
	}

	sid = wsman_session_open("localhost", 8889, "/wsman", "http",
				user, passwd, 0);

	if (sid < 0) {
		printf("Open session failed\n");
		return 0;
	}


	printf("\n******** Opened session id %d ********\n\n", sid);

	eid = wsman_session_enumerate(sid, resource_uri, NULL, NULL,
						FLAG_ENUMERATION_ENUM_EPR);

	if (eid < 0) {
		printf("******** Enumeration failed - %s ********\n\n",
			wsman_session_error(sid));
		goto end;
	}

	response = wsman_enumerator_pull(eid);
	if (!response) {
		printf("******** Pull failed - %s ********\n\n",
			wsman_enumerator_error(eid));
	}

	wsman_enumerator_release(eid);

	wsman_session_resource_locator_set(sid, response);

	response = wsman_session_invoke(sid, "ManageSystemTime",
					"<GetRequest>TRUE</GetRequest>", 0);

	if (!response) {
		printf("******** Invoke failed - %s ********\n\n",
			wsman_session_error(sid));
		goto end;
	}
	printf("******** Invoke response *******\n%s\n", response);
	retval = 1;

 end:
	wsman_session_close(sid);
	printf("******** Closed session id %d ********\n\n", sid);

	return retval;
}