openwsman 2.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/openwsman.c ADDED
@@ -0,0 +1,52 @@
1
+ #include <u/libu.h>
2
+ #include <wsman-debug.h>
3
+ #include "openwsman.h"
4
+ /*-----------------------------------------------------------------*/
5
+ /* Rbwsman */
6
+ /* debug (mostly stolen from src/server/wsmand.c) */
7
+
8
+ void
9
+ debug_message_handler (const char *str,
10
+ debug_level_e level,
11
+ void *user_data)
12
+ {
13
+ static int log_pid = 0;
14
+
15
+ if (log_pid == 0)
16
+ log_pid = getpid ();
17
+ #if 0
18
+ if (level <= wsmand_options_get_debug_level ()
19
+ || wsmand_options_get_foreground_debug() > 0 )
20
+ #endif
21
+ {
22
+ struct tm *tm;
23
+ time_t now;
24
+ char timestr[128];
25
+ char *log_msg;
26
+ int p;
27
+
28
+ time (&now);
29
+ tm = localtime (&now);
30
+ strftime (timestr, 128, "%b %e %T", tm);
31
+
32
+ log_msg = u_strdup_printf ("%s [%d] %s\n",
33
+ timestr, log_pid, str);
34
+ if ( (p = write (STDERR_FILENO, log_msg, strlen (log_msg)) ) < 0 )
35
+ fprintf(stderr, "Failed writing to log file\n");
36
+ fsync (STDERR_FILENO);
37
+
38
+ u_free (log_msg);
39
+ }
40
+ #if 0
41
+ if ( level <= wsmand_options_get_syslog_level ())
42
+ {
43
+ char *log_name = u_strdup_printf( "wsmand[%d]", log_pid );
44
+
45
+ openlog( log_name, 0, LOG_DAEMON );
46
+ syslog( LOG_INFO, "%s", str );
47
+ closelog();
48
+ u_free( log_name );
49
+ }
50
+ #endif
51
+ }
52
+
@@ -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 */
@@ -0,0 +1,27 @@
1
+ # This is openwsman/openwsman
2
+ # do NOT require this file, but do a simple
3
+ # require 'openwsman'
4
+ # instead
5
+ #
6
+
7
+ require 'openwsman/version'
8
+
9
+ # this loads the binary .so file
10
+ require '_openwsman'
11
+
12
+ # this extends Openwsman::XmlNode with method_missing
13
+ require 'openwsman/xmlnode'
14
+
15
+ # this extends Openwsman::XmlDoc with method_missing
16
+ require 'openwsman/xmldoc'
17
+
18
+ module Openwsman
19
+ class Transport
20
+ # called when authentication credentials missing or wrong
21
+ def Transport.auth_request_callback client, auth_type
22
+ # override in client code
23
+ # return Array of [ username, password ]
24
+ # return nil to abort authentication
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ #
2
+ # Assume XmlDoc.foo means XmlDoc.body.foo
3
+ #
4
+
5
+ module Openwsman
6
+ class XmlDoc
7
+ def method_missing method, *args
8
+ self.body.send method,*args
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Openwsman
2
+ class XmlNode
3
+ def method_missing method, *args
4
+ find(nil, method.to_s)
5
+ end
6
+ end
7
+ end
data/lib/openwsman.rb ADDED
@@ -0,0 +1,4 @@
1
+ # This is openwsman.rb
2
+ #
3
+
4
+ require 'openwsman/openwsman'
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openwsman
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.2.7
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Klaus Kämpf
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake-compiler
16
+ requirement: &7069220 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *7069220
25
+ - !ruby/object:Gem::Dependency
26
+ name: mocha
27
+ requirement: &7068740 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0.9'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *7068740
36
+ - !ruby/object:Gem::Dependency
37
+ name: yard
38
+ requirement: &7068260 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0.5'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *7068260
47
+ description: ! 'The openwsman gem provides a Ruby API to manage
48
+
49
+ systems using the WS-Management protocol.'
50
+ email:
51
+ - kkaempf@suse.de
52
+ executables: []
53
+ extensions:
54
+ - ext/openwsman/extconf.rb
55
+ extra_rdoc_files: []
56
+ files:
57
+ - lib/openwsman/xmlnode.rb
58
+ - lib/openwsman/xmldoc.rb
59
+ - lib/openwsman/openwsman.rb
60
+ - lib/openwsman.rb
61
+ - ext/openwsman/openwsman.h
62
+ - ext/openwsman/helpers.h
63
+ - ext/ruby/helpers.h
64
+ - ext/openwsman/openwsman_wrap.c
65
+ - ext/openwsman.c
66
+ - ext/openwsman/extconf.rb
67
+ homepage: http://www.github.com/openwsman/openwsman
68
+ licenses: []
69
+ post_install_message: ! " ____\n/@ ~-.\n/ __ .- | remember to have fun! \n //
70
+ // @ \n\n"
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 1.3.6
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 1.8.10
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Ruby client bindings for Openwsman
92
+ test_files: []
93
+ has_rdoc: