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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <errno.h>
#include <time.h>
#include "u/libu.h"
#include "wsman-client-api.h"
#include "wsman-client-transport.h"
#define DESC "Description"
static char *file = NULL;
static char *endpoint = NULL;
typedef enum {
INTEROP_IDENTIFY = 0
} InteropTest;
static set_props(actionOptions *op, char *k, char *v)
{
hash_t *h = hash_create(HASHCOUNT_T_MAX, 0, 0);
if ( !hash_alloc_insert(h, k, v)) {
fprintf(stderr, "hash_alloc_insert failed");
}
op->properties = h;
}
static void
wsman_add_selectors_list_from_node( WsXmlNodeH input, actionOptions *options)
{
hash_t *h = hash_create(HASHCOUNT_T_MAX, 0, 0);
WsXmlNodeH node = ws_xml_get_child(input, 0, NULL, WSM_SELECTOR_SET);
if ( node )
{
WsXmlNodeH selector;
int index = 0;
while( (selector = ws_xml_get_child(node, index++, NULL, WSM_SELECTOR)) )
{
char* attrVal = ws_xml_find_attr_value(selector, NULL, WSM_NAME);
if ( attrVal == NULL )
attrVal = ws_xml_find_attr_value(selector, NULL, WSM_NAME);
if ( attrVal )
{
if (!hash_alloc_insert(h, attrVal, ws_xml_get_node_text(selector))) {
error("hash_alloc_insert failed");
}
}
}
}
if (!hash_isempty(h))
options->selectors = h;
}
static int pull_items(WsManClient *cl, WsXmlDocH doc, void *data)
{
if (!doc) {
return 0;
}
xml_parser_doc_dump(stdout, doc);
return 1;
}
static int run_interop_test (WsManClient *cl, WsXmlNodeH scenario, InteropTest id)
{
WsXmlDocH response;
actionOptions options;
initialize_action_options(&options);
wsman_set_action_option(&options,FLAG_DUMP_REQUEST );
if (id == 0) { // 6.1 Identify
response = wsman_identify(cl, options);
xml_parser_doc_dump(stdout, response);
}else if (id == 2) { // 6.2 Get
WsXmlNodeH input = ws_xml_get_child(scenario, 0, NULL, "Input");
WsXmlNodeH r = ws_xml_get_child(input, 0, NULL, "ResourceURI");
wsman_add_selectors_list_from_node(input, &options);
char *resource_uri = ws_xml_get_node_text(r);
response = ws_transfer_get(cl, resource_uri, options);
xml_parser_doc_dump(stdout, response);
}else if (id == 3) { // 6.3 Get failure - invalid resoure URI
WsXmlNodeH input = ws_xml_get_child(scenario, 0, NULL, "Input");
WsXmlNodeH r = ws_xml_get_child(input, 0, NULL, "ResourceURI");
wsman_add_selectors_list_from_node(input, &options);
char *resource_uri = ws_xml_get_node_text(r);
response = ws_transfer_get(cl, resource_uri, options);
xml_parser_doc_dump(stdout, response);
}else if (id == 4) { // 6.4 Get failure (MaxEnvelop exceeded)
WsXmlNodeH input = ws_xml_get_child(scenario, 0, NULL, "Input");
WsXmlNodeH r = ws_xml_get_child(input, 0, NULL, "ResourceURI");
wsman_add_selectors_list_from_node(input, &options);
char *resource_uri = ws_xml_get_node_text(r);
response = ws_transfer_get(cl, resource_uri, options);
xml_parser_doc_dump(stdout, response);
}else if (id == 5) { // 6.5 Get failure - invalid selectors
WsXmlNodeH input = ws_xml_get_child(scenario, 0, NULL, "Input");
WsXmlNodeH r = ws_xml_get_child(input, 0, NULL, "ResourceURI");
wsman_add_selectors_list_from_node(input, &options);
char *resource_uri = ws_xml_get_node_text(r);
response = ws_transfer_get(cl, resource_uri, options);
xml_parser_doc_dump(stdout, response);
}else if (id == 8) { // 7.1 Enumerate"
WsXmlNodeH input = ws_xml_get_child(scenario, 0, NULL, "Input");
WsXmlNodeH r = ws_xml_get_child(input, 0, NULL, "ResourceURI");
char *resource_uri = ws_xml_get_node_text(r);
wsenum_enumerate_and_pull(cl, resource_uri , options, pull_items, NULL );
}else if (id == 9) { // 7.2 Optimized Enumerate
wsman_set_action_option(&options, FLAG_ENUMERATION_OPTIMIZATION);
WsXmlNodeH input = ws_xml_get_child(scenario, 0, NULL, "Input");
WsXmlNodeH r = ws_xml_get_child(input, 0, NULL, "ResourceURI");
char *resource_uri = ws_xml_get_node_text(r);
wsenum_enumerate_and_pull(cl, resource_uri , options, pull_items, NULL );
}else if (id == 10) { // 7.3 Enumerate failure
WsXmlNodeH input = ws_xml_get_child(scenario, 0, NULL, "Input");
WsXmlNodeH r = ws_xml_get_child(input, 0, NULL, "ResourceURI");
char *resource_uri = ws_xml_get_node_text(r);
WsXmlDocH e = wsenum_enumerate(cl, resource_uri , options );
char *enumContext = wsenum_get_enum_context(e);
if (enumContext) {
response = wsenum_pull(cl, resource_uri, enumContext, options);
xml_parser_doc_dump(stdout, response);
WsXmlDocH response2 = wsenum_pull(cl, resource_uri, "xxxx", options);
if (response2)
xml_parser_doc_dump(stdout, response2);
}
}else if (id == 11) { // 7.4 Enumerate ObjectAndEPR
wsman_set_action_option(&options, FLAG_ENUMERATION_ENUM_EPR);
WsXmlNodeH input = ws_xml_get_child(scenario, 0, NULL, "Input");
WsXmlNodeH r = ws_xml_get_child(input, 0, NULL, "ResourceURI");
char *resource_uri = ws_xml_get_node_text(r);
wsenum_enumerate_and_pull(cl, resource_uri , options, pull_items, NULL );
}else if (id == 16) { // 7.9 Enumerate Polymorphism
wsman_set_action_option(&options, FLAG_POLYMORPHISM_NONE);
WsXmlNodeH input = ws_xml_get_child(scenario, 0, NULL, "Input");
WsXmlNodeH r = ws_xml_get_child(input, 0, NULL, "ResourceURI");
char *resource_uri = ws_xml_get_node_text(r);
wsenum_enumerate_and_pull(cl, resource_uri , options, pull_items, NULL );
}else if (id == 17) { // 8.1 Invoke
WsXmlNodeH input = ws_xml_get_child(scenario, 0, NULL, "Input");
WsXmlNodeH r = ws_xml_get_child(input, 0, NULL, "ResourceURI");
WsXmlNodeH m = ws_xml_get_child(input, 0, NULL, "MethodName");
char *resource_uri = ws_xml_get_node_text(r);
char *method = ws_xml_get_node_text(m);
wsman_add_selectors_list_from_node(input, &options);
response = wsman_invoke(cl, resource_uri, method, options);
xml_parser_doc_dump(stdout, response);
}else if (id == 18) { // 9.1 Put
WsXmlNodeH input = ws_xml_get_child(scenario, 0, NULL, "Input");
WsXmlNodeH r = ws_xml_get_child(input, 0, NULL, "ResourceURI");
WsXmlNodeH k = ws_xml_get_child(input, 0, NULL, "PropertyName");
WsXmlNodeH v = ws_xml_get_child(input, 0, NULL, "NewValue");
char *resource_uri = ws_xml_get_node_text(r);
wsman_add_selectors_list_from_node(input, &options);
set_props(&options, ws_xml_get_node_text(k), ws_xml_get_node_text(v) );
response = ws_transfer_put(cl, resource_uri, options);
xml_parser_doc_dump(stdout, response);
}
return 0;
}
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[] = {
{ "interop-file", 'f', U_OPTION_ARG_STRING, &file,
"Interop file", "<file>" },
{ "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, "interop");
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( uri->host,
uri->port,
uri->path,
uri->scheme,
uri->user,
uri->pwd);
initialize_action_options(&options);
doc = wsman_client_read_file(cl, file, "UTF-8", 0);
//xml_parser_doc_dump(stdout, doc);
//WsXmlNodeH node = ws_xml_get_soap_element(doc, "WSManInteropScenarios");
WsXmlNodeH node;
if (doc != NULL)
node = xml_parser_get_root(doc);
WsXmlNodeH scenario;
int index = 0;
int test_id = 0;
while( (scenario = ws_xml_get_child(node, index++, NULL, "Scenario")) ) {
WsXmlAttrH desc = ws_xml_get_node_attr(scenario, 0);
char *attr_val = ws_xml_get_attr_value(desc);
WsXmlAttrH supported = ws_xml_get_node_attr(scenario, 1);
if (strcmp(ws_xml_get_attr_value(supported), "true") == 0 ) {
if (desc) {
if (attr_val)
printf("%s (%d)\n\n", attr_val, test_id );
}
run_interop_test(cl, scenario, test_id);
} else {
if (desc) {
if (attr_val)
printf("%s: Not Supported (%d)\n\n", attr_val, test_id );
}
}
test_id++;
}
return 0;
}
|