Class WsMan::Client
In: rwsman_xmlattr.c
Parent: Object

The Client is the core class for openwsman Ruby bindings. All WS-Man operations are targeted towards a client, represented by an instance of the Client class. The client instance initiates and represents the http connection, and is instantiated by providing the protocol scheme (http or https), host, port, path and username and password for authentication:

  client = Client.new( "http", "wsman.host.net", 80, "/wsman", "username", "password" )

The class provides accessor (read-only) functions for the connection parameters and keeps track of the current connection and command status.

Enclosing-namespace: WsMan Document-class: XmlDoc

Methods

create   delete   dumpfile   dumpfile=   enumerate   fault_string   get   host   invoke   new   parse   password   path   port   pull   put   reconnect   release   response_code   scheme   timeout   timeout=   username  

Public Class methods

[Source]

/*
 * call-seq:
 *   Client.new( host, port, path, scheme, user, password ) -> Client
 *
 */

static VALUE
client_initialize( VALUE self, VALUE scheme, VALUE host, VALUE port, VALUE path, VALUE username, VALUE password )
{
    client_wrapper_t *wrapper = client_unwrap( self );

    char *scheme_s = StringValuePtr( scheme );
    char *host_s = StringValuePtr( host );
    int port_i = FIX2INT( port );
    char *path_s = StringValuePtr( path );
    char *username_s = StringValuePtr( username );
    char *password_s = StringValuePtr( password );

    wrapper->client = wsmc_create( host_s, port_i, path_s, scheme_s, username_s, password_s );
    wsmc_transport_init( wrapper->client, NULL );

    if (!wrapper->client) {
        rb_raise( rb_eRuntimeError, "wsman_create_client failed" );
    }

    return self;
}

Public Instance methods

Create a resource addressed by uri and defined by resource.

[Source]

/*
 * call-seq:
 *   client.create( uri, options, resource ) -> XmlDoc
 *
 * Create a resource addressed by +uri+ and defined by +resource+.
 */

static VALUE
client_create( VALUE self, VALUE resource_uri, VALUE client_options, VALUE xml )
{
    WsManClient *client = rwsman_client_unpack( self );
    client_opt_t *options = rwsman_clientoption_unpack( client_options );
    WsXmlDocH doc = rwsman_xmldoc_unpack( xml );

    WsXmlDocH result = wsmc_action_create( client, StringValuePtr( resource_uri ), options, doc );
#if 0  // alternative 
    WsXmlDocH       wsmc_action_create_fromtext(WsManClient * cl,
                          const char *resourceUri, client_opt_t options,
                          const char *data, size_t size, const char *encoding);
#endif
    return rwsman_xmldoc_new( result );
}

Delete a resource addressed by uri and options

[Source]

/*
 * call-seq:
 *   client.delete( uri, options ) -> XmlDoc
 *
 * Delete a resource addressed by +uri+ and +options+
 */

static VALUE
client_delete( VALUE self, VALUE resource_uri, VALUE client_options )
{
    WsManClient *client = rwsman_client_unpack( self );
    client_opt_t *options = rwsman_clientoption_unpack( client_options );

    WsXmlDocH result = wsmc_action_delete( client, StringValuePtr( resource_uri ), options );

    return rwsman_xmldoc_new( result );
}

Returns the current filename for request debug dumps. Useful to debug the XML request sent to the client. One must enable debugging to make dumps active. The dumpfile gets overwritten with each new client request.

[Source]

/*
 * call-seq:
 *   client.dumpfile -> string
 *
 * Returns the current filename for request debug dumps. Useful to debug
 * the XML request sent to the client.
 * One must enable debugging to make dumps active.
 * The dumpfile gets overwritten with each new client request.
 *
 */

static VALUE
client_dumpfile_get( VALUE self )
{
    client_wrapper_t *wrapper = client_unwrap( self );
    FILE *f = wsmc_get_dumpfile( wrapper->client );
    if (f == stdout)
        return Qfalse;
    else if (f == NULL)
        return Qnil;
    else
        return Qtrue;
}

Set the current filename for request debug dumps. Useful to debug the XML request sent to the client. One must enable debugging to make dumps active. The dumpfile gets overwritten with each new client request.

[Source]

/*
 * call-seq:
 *   client.dumpfile = "/tmp/my_dumpfile.xml"
 *
 * Set the current filename for request debug dumps. Useful to debug
 * the XML request sent to the client.
 * One must enable debugging to make dumps active.
 * The dumpfile gets overwritten with each new client request.
 *
 */

static VALUE
client_dumpfile_set( VALUE self, VALUE name )
{
    char *fname = StringValuePtr( name );

    client_wrapper_t *wrapper = client_unwrap( self );
    FILE *f = wsmc_get_dumpfile( wrapper->client );
    if (f && f != stdout) fclose( f );

    if (*fname == 0)
        f = stdout;                    // empty name sets 'stdout'
    else
        f = fopen( fname, "w" );

    if (f == NULL)
        rb_raise( rb_eRuntimeError, "Can't open dumpfile" );

    wsmc_set_dumpfile( wrapper->client, f );

    return Qtrue;
}

Start enumeration of all resource instances addressed by uri and options.

[Source]

/*
 * 
 * call-seq:
 *   client.enumerate( uri, options ) -> XmlDoc
 *
 * Start enumeration of all resource instances addressed by +uri+ and +options+.
 */

VALUE
client_enumerate( VALUE self, VALUE resource_uri, VALUE client_options )
{
    WsManClient *client = rwsman_client_unpack( self );
    client_opt_t *options = rwsman_clientoption_unpack( client_options );

    /* call wsman_enumerate() */
    WsXmlDocH result = wsmc_action_enumerate( client, StringValuePtr( resource_uri ), options );

    return rwsman_xmldoc_new( result );
}

Returns a string representation of the most recent WS-Man fault.

[Source]

/*
 * call-seq:
 *   client.fault_string -> string
 *
 * Returns a string representation of the most recent
 * WS-Man fault.
 *
 */

static VALUE
client_fault_string( VALUE self )
{
    client_wrapper_t *wrapper = client_unwrap( self );
    return makestring( wsmc_get_fault_string( wrapper->client ) );
}

Get a resource addressed by uri and options

[Source]

/*
 * call-seq:
 *   client.get( uri, options ) -> XmlDoc
 *
 * Get a resource addressed by +uri+ and +options+
 */

static VALUE
client_get( VALUE self, VALUE resource_uri, VALUE client_options )
{
    WsManClient *client = rwsman_client_unpack( self );
    client_opt_t *options = rwsman_clientoption_unpack( client_options );

    WsXmlDocH result = wsmc_action_get( client, StringValuePtr( resource_uri ), options );

    return rwsman_xmldoc_new( result );
}

Returns the host representation of the current client connection.

[Source]

/*
 * call-seq:
 *   client.host -> string
 *
 * Returns the host representation of the current client connection.
 *
 */

static VALUE
client_host( VALUE self )
{
    client_wrapper_t *wrapper = client_unwrap( self );
    return makestring( wsmc_get_hostname( wrapper->client ) );
}

Invoke a client method addressed by uri and options.

[Source]

/*
 * call-seq:
 *   client.invoke( uri, method ) -> XmlDoc
 *   client.invoke( uri, method, options ) -> XmlDoc
 *   client.invoke( uri, method, options, xml ) -> XmlDoc
 *
 * Invoke a client method addressed by +uri+ and +options+.
 */

static VALUE
client_invoke( int argc, VALUE *argv, VALUE self )
{
    WsManClient *client = rwsman_client_unpack( self );

    if (argc < 2)
        rb_raise( rb_eArgError, "Client.invoke needs URI and Method at least" );

    client_opt_t *options;
    if (argc > 2)
        options = rwsman_clientoption_unpack( argv[2] );
    else
        options = wsmc_options_init();

    WsXmlDocH doc;
    if (argc > 3)
        doc = rwsman_xmldoc_unpack( argv[3] );
    else
        doc = NULL;

    /* call wsman_invoke() */

    WsXmlDocH result = wsmc_action_invoke( client, StringValuePtr( argv[0] ), options, StringValuePtr( argv[1] ), doc );

    return rwsman_xmldoc_new( result );
}

Parse a XML representation (passed as string) to an XmlDoc object while using the client context.

[Source]

/*
 * call-seq:
 *   client.parse( xml, encoding, options ) -> XmlDoc
 *
 * Parse a XML representation (passed as string) to an XmlDoc object
 * while using the client context.
 *
 */

static VALUE
client_parse( VALUE self, VALUE xml, VALUE enc, VALUE opts )
{
    char *buf = StringValuePtr( xml );
    char *encoding = StringValuePtr( enc );
    int options = FIX2INT( opts );
    client_wrapper_t *wrapper = client_unwrap( self );
    // FIXME: ruby keeps string length, no need to call strlen()
    WsXmlDocH doc = wsmc_read_memory( wrapper->client, buf, strlen( buf ), encoding, options );

    return rwsman_xmldoc_new( doc );
}

Returns the password of the current client connection.

[Source]

/*
 * call-seq:
 *   client.password -> string
 *
 * Returns the password of the current client connection.
 *
 */

static VALUE
client_password( VALUE self )
{
    client_wrapper_t *wrapper = client_unwrap( self );
    return makestring( wsmc_get_password( wrapper->client ) );
}

Returns the path representation of the current client connection.

[Source]

/*
 * call-seq:
 *   client.path -> string
 *
 * Returns the path representation of the current client connection.
 *
 */

static VALUE
client_path( VALUE self )
{
    client_wrapper_t *wrapper = client_unwrap( self );
    return makestring( wsmc_get_path( wrapper->client ) );
}

Returns the port number of the current client connection.

[Source]

/*
 * call-seq:
 *   client.port -> integer
 *
 * Returns the port number of the current client connection.
 *
 */

static VALUE
client_port( VALUE self )
{
    client_wrapper_t *wrapper = client_unwrap( self );
    return INT2FIX( wsmc_get_port( wrapper->client ) );
}

Pull next enumeration instance from given context.

[Source]

/*
 * call-seq:
 *   client.pull( uri, context, options ) -> XmlDoc
 *
 * Pull next enumeration instance from given context.
 */

VALUE
client_pull( VALUE self, VALUE resource_uri, VALUE context, VALUE client_options )
{
    WsManClient *client = rwsman_client_unpack( self );
    client_opt_t *options = rwsman_clientoption_unpack( client_options );

    WsXmlDocH result = wsmc_action_pull( client, StringValuePtr( resource_uri ), options, StringValuePtr( context ) );

    return rwsman_xmldoc_new( result );
}

Put (change) a resource addressed by uri and options and change the attributes as listed in resource.

[Source]

/*
 * call-seq:
 *   client.put( uri, options, resource ) -> XmlDoc
 *
 * Put (change) a resource addressed by +uri+ and +options+ and change
 * the attributes as listed in +resource+.
 */

static VALUE
client_put( VALUE self, VALUE resource_uri, VALUE client_options, VALUE xml )
{
    WsManClient *client = rwsman_client_unpack( self );
    client_opt_t *options = rwsman_clientoption_unpack( client_options );
    WsXmlDocH doc = rwsman_xmldoc_unpack( xml );

    WsXmlDocH result = wsmc_action_put( client, StringValuePtr( resource_uri ), options, doc );

    return rwsman_xmldoc_new( result );
}

Tries to re-initialize the client connection without changing any of its parameters. Useful e.g. after losing network connection or switching networks. (?)

[Source]

/*
 * call-seq:
 *   client.reconnect -> nil
 *
 * Tries to re-initialize the client connection without
 * changing any of its parameters.
 * Useful e.g. after losing network connection or switching
 * networks. (?)
 *
 */

static VALUE
client_reconnect( VALUE self )
{
    client_wrapper_t *wrapper = client_unwrap( self );
    wsmc_reinit_conn( wrapper->client );
    return Qnil;
}

Release an enumeration context.

[Source]

/*
 * call-seq:
 *   client.release( uri, context, options ) -> XmlDoc
 *
 * Release an enumeration context.
 */

static VALUE
client_release( VALUE self, VALUE resource_uri, VALUE context, VALUE client_options )
{
    WsManClient *client = rwsman_client_unpack( self );
    client_opt_t *options = rwsman_clientoption_unpack( client_options );

    WsXmlDocH result = wsmc_action_release( client, StringValuePtr( resource_uri ), options, StringValuePtr( context ) );

    return rwsman_xmldoc_new( result );
}

Returns the response code of the most recent WS-Man command.

[Source]

/*
 * call-seq:
 *   client.response_code -> integer
 *
 * Returns the response code of the most recent WS-Man command.
 *
 */

static VALUE
client_response_code( VALUE self )
{
    client_wrapper_t *wrapper = client_unwrap( self );
    return INT2FIX( wsmc_get_response_code( wrapper->client ) );
}

Returns the scheme representation of the current client connection.

[Source]

/*
 * call-seq:
 *   client.scheme -> string
 *
 * Returns the scheme representation of the current client connection.
 *
 */
static VALUE
client_scheme( VALUE self )
{
    client_wrapper_t *wrapper = client_unwrap( self );
    return makestring( wsmc_get_scheme( wrapper->client ) );
}

Returns the current transport level timeout This is different from the request level timeout which is set in the ClientOptions

[Source]

/*
 * call-seq:
 *   client.timeout -> integer
 *
 * Returns the current transport level timeout
 * This is different from the request level timeout which is set
 * in the <code>ClientOptions</code>
 */

static VALUE
client_timeout_get( VALUE self )
{
    client_wrapper_t *wrapper = client_unwrap( self );
    unsigned long transport_level_timeout = wsman_transport_get_timeout( wrapper->client );
    return LONG2FIX( transport_level_timeout );
}

Sets the current transport level timeout This is different from the request level timeout which is set in the ClientOptions

[Source]

/*
 * call-seq:
 *   client.timeout = 3600
 *
 * Sets the current transport level timeout
 * This is different from the request level timeout which is set
 * in the <code>ClientOptions</code>
 *
 */

static VALUE
client_timeout_set( VALUE self, VALUE t )
{
    client_wrapper_t *wrapper = client_unwrap( self );
    long transport_level_timeout = FIX2LONG( t );

    if (transport_level_timeout >= 0L) {
        wsman_transport_set_timeout( wrapper->client, transport_level_timeout );
    }

    return Qnil;
}

Returns the username of the current client connection.

[Source]

/*
 * call-seq:
 *   client.username -> string
 *
 * Returns the username of the current client connection.
 *
 */

static VALUE
client_username( VALUE self )
{
    client_wrapper_t *wrapper = client_unwrap( self );
    return makestring( wsmc_get_user( wrapper->client ) );
}

[Validate]