openwsman 2.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/openwsman/extconf.rb +33 -0
- data/ext/openwsman/helpers.h +170 -0
- data/ext/openwsman/openwsman.h +8 -0
- data/ext/openwsman/openwsman_wrap.c +16107 -0
- data/ext/openwsman.c +52 -0
- data/ext/ruby/helpers.h +170 -0
- data/lib/openwsman/openwsman.rb +27 -0
- data/lib/openwsman/xmldoc.rb +11 -0
- data/lib/openwsman/xmlnode.rb +7 -0
- data/lib/openwsman.rb +4 -0
- metadata +93 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
#
|
2
|
+
# extconf.rb for openwsman Gem
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'mkmf'
|
6
|
+
# $CFLAGS = "#{$CFLAGS} -Werror"
|
7
|
+
|
8
|
+
# requires wsman, wsman_client, and libxml2
|
9
|
+
|
10
|
+
unless have_library('wsman', 'wsman_create_doc')
|
11
|
+
STDERR.puts "Cannot find wsman_create_doc() in libwsman"
|
12
|
+
STDERR.puts "Is openwsman-devel installed ?"
|
13
|
+
exit 1
|
14
|
+
end
|
15
|
+
find_header 'wsman-xml-api.h', '/usr/include/openwsman'
|
16
|
+
|
17
|
+
unless have_library('wsman_client', 'wsmc_create')
|
18
|
+
STDERR.puts "Cannot find wsmc_create() in libwsman_client"
|
19
|
+
STDERR.puts "Is openwsman-devel installed ?"
|
20
|
+
exit 1
|
21
|
+
end
|
22
|
+
find_header 'wsman-client-api.h', '/usr/include/openwsman'
|
23
|
+
|
24
|
+
unless have_library('xml2', 'xmlNewDoc')
|
25
|
+
STDERR.puts "Cannot find xmlNewDoc() in libxml2"
|
26
|
+
STDERR.puts "Is libxml2-devel installed ?"
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
find_header 'libxml/parser.h', '/usr/include/libxml2'
|
30
|
+
|
31
|
+
$CPPFLAGS = "-I/usr/include/openwsman -I.."
|
32
|
+
|
33
|
+
create_makefile('openwsman')
|
@@ -0,0 +1,170 @@
|
|
1
|
+
#ifndef RUBY_HELPERS_H
|
2
|
+
#define RUBY_HELPERS_H
|
3
|
+
|
4
|
+
/*
|
5
|
+
* openwsman-ruby.c
|
6
|
+
*
|
7
|
+
* helper functions to convert between ruby and openwsman values
|
8
|
+
*
|
9
|
+
* Author: Klaus Kaempf <kkaempf@suse.de>
|
10
|
+
*
|
11
|
+
*/
|
12
|
+
|
13
|
+
/*****************************************************************************
|
14
|
+
* Copyright (C) 2008 Novell Inc. All rights reserved.
|
15
|
+
* Copyright (C) 2008 SUSE Linux Products GmbH. All rights reserved.
|
16
|
+
*
|
17
|
+
* Redistribution and use in source and binary forms, with or without
|
18
|
+
* modification, are permitted provided that the following conditions are met:
|
19
|
+
*
|
20
|
+
* - Redistributions of source code must retain the above copyright notice,
|
21
|
+
* this list of conditions and the following disclaimer.
|
22
|
+
*
|
23
|
+
* - Redistributions in binary form must reproduce the above copyright notice,
|
24
|
+
* this list of conditions and the following disclaimer in the documentation
|
25
|
+
* and/or other materials provided with the distribution.
|
26
|
+
*
|
27
|
+
* - Neither the name of Novell Inc. nor of SUSE Linux Products GmbH nor the
|
28
|
+
* names of its contributors may be used to endorse or promote products
|
29
|
+
* derived from this software without specific prior written permission.
|
30
|
+
*
|
31
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
|
32
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
33
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
34
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL Novell Inc. OR SUSE Linux Products GmbH OR
|
35
|
+
* THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
36
|
+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
37
|
+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
38
|
+
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
39
|
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
40
|
+
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
41
|
+
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
42
|
+
*****************************************************************************/
|
43
|
+
|
44
|
+
/* convert char* to string VALUE */
|
45
|
+
static VALUE
|
46
|
+
makestring( const char *s )
|
47
|
+
{
|
48
|
+
if (s) return rb_str_new2( s );
|
49
|
+
return Qnil;
|
50
|
+
}
|
51
|
+
|
52
|
+
|
53
|
+
/* convert VALUE to char* */
|
54
|
+
static const char *
|
55
|
+
as_string( VALUE v )
|
56
|
+
{
|
57
|
+
const char *str;
|
58
|
+
if (SYMBOL_P(v)) {
|
59
|
+
str = rb_id2name(SYM2ID(v));
|
60
|
+
}
|
61
|
+
else if (TYPE(v) == T_STRING) {
|
62
|
+
str = StringValuePtr(v);
|
63
|
+
}
|
64
|
+
else if (v == Qnil) {
|
65
|
+
str = NULL;
|
66
|
+
}
|
67
|
+
else {
|
68
|
+
VALUE v_s = rb_funcall(v, rb_intern("to_s"), 0 );
|
69
|
+
str = StringValuePtr(v_s);
|
70
|
+
}
|
71
|
+
return str;
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
/* convert openwsman hash_t* to hash VALUE (string pairs) */
|
76
|
+
static VALUE
|
77
|
+
hash2value( hash_t *hash )
|
78
|
+
{
|
79
|
+
VALUE v;
|
80
|
+
hnode_t *node;
|
81
|
+
hscan_t ptr;
|
82
|
+
|
83
|
+
if (!hash) return Qnil;
|
84
|
+
|
85
|
+
hash_scan_begin( &ptr, hash );
|
86
|
+
|
87
|
+
v = rb_hash_new();
|
88
|
+
while ((node = hash_scan_next( &ptr )) ) {
|
89
|
+
rb_hash_aset( v, makestring( hnode_getkey( node ) ), makestring( hnode_get( node ) ) );
|
90
|
+
}
|
91
|
+
return v;
|
92
|
+
}
|
93
|
+
|
94
|
+
|
95
|
+
/* add key,value VALUE pair to hash_t*
|
96
|
+
* (used as callback for value2hash)
|
97
|
+
*/
|
98
|
+
static int
|
99
|
+
add_i( VALUE key, VALUE value, hash_t *h )
|
100
|
+
{
|
101
|
+
if (key != Qundef) {
|
102
|
+
const char *k = as_string( key );
|
103
|
+
const char *v = as_string( value );
|
104
|
+
|
105
|
+
if (!hash_lookup( h, k ) ) {
|
106
|
+
if ( !hash_alloc_insert( h, k, v ) ) {
|
107
|
+
rb_raise( rb_eException, "hash_alloc_insert failed" );
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}
|
111
|
+
return 0;
|
112
|
+
}
|
113
|
+
|
114
|
+
|
115
|
+
/* create hash (h == NULL) or add to hash (h != NULL) from hash VALUE */
|
116
|
+
static hash_t *
|
117
|
+
value2hash( hash_t *h, VALUE v )
|
118
|
+
{
|
119
|
+
if (NIL_P(v)) return NULL;
|
120
|
+
|
121
|
+
Check_Type( v, T_HASH );
|
122
|
+
|
123
|
+
if (!h) h = hash_create(HASHCOUNT_T_MAX, 0, 0);
|
124
|
+
|
125
|
+
rb_hash_foreach( v, add_i, (unsigned long)h );
|
126
|
+
|
127
|
+
return h;
|
128
|
+
}
|
129
|
+
|
130
|
+
|
131
|
+
/*
|
132
|
+
* callback function if client authentication fails
|
133
|
+
*
|
134
|
+
*/
|
135
|
+
static void
|
136
|
+
auth_request_callback( WsManClient *client, wsman_auth_type_t t, char **username, char **password )
|
137
|
+
{
|
138
|
+
|
139
|
+
/*
|
140
|
+
* Uhm, swig 1.3.40 (or earlier) renamed its internal class variables from
|
141
|
+
* cFoo to SwigClassFoo
|
142
|
+
* 1.3.36 certainly used cFoo
|
143
|
+
*
|
144
|
+
*/
|
145
|
+
|
146
|
+
#if SWIG_VERSION < 0x010340
|
147
|
+
#define TRANSPORT_CLASS cTransport
|
148
|
+
#else
|
149
|
+
#define TRANSPORT_CLASS SwigClassTransport
|
150
|
+
#endif
|
151
|
+
|
152
|
+
extern swig_class TRANSPORT_CLASS;
|
153
|
+
VALUE c = SWIG_NewPointerObj((void*) client, SWIGTYPE_p__WsManClient, 0);
|
154
|
+
|
155
|
+
/* ruby callback */
|
156
|
+
VALUE result = rb_funcall( TRANSPORT_CLASS.klass, rb_intern( "auth_request_callback" ), 2, c, INT2NUM( t ) );
|
157
|
+
|
158
|
+
if (CLASS_OF( result ) == rb_cArray) {
|
159
|
+
if (RARRAY_LEN(result) == 2 ) {
|
160
|
+
*username = strdup(as_string( rb_ary_entry( result, 0 ) ));
|
161
|
+
*password= strdup(as_string( rb_ary_entry( result, 1 ) ));
|
162
|
+
return;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
*username = NULL; /* abort authentication */
|
167
|
+
return;
|
168
|
+
}
|
169
|
+
|
170
|
+
#endif /* RUBY_HELPERS_H */
|