Module: LibSSH2::Native

Defined in:
lib/libssh2/native.rb,
lib/libssh2/native/error.rb,
lib/libssh2/native/error_codes.rb,
ext/libssh2_ruby_c/libssh2_ruby_c.c

Overview

This module is almost completely implemented in pure C. Additional methods are defined here to make things easier to implement.

Defined Under Namespace

Modules: Error Classes: Channel, Session

Class Method Summary collapse

Class Method Details

.channel_open_session(session) ⇒ Object


Channel Methods




46
47
48
# File 'lib/libssh2/native.rb', line 46

def self.channel_open_session(session)
  Native::Channel.new(session)
end

.LibSSH2::Native.initInteger

Initializes libssh2 to run and returns the error code (0 if no error). Note that this is not threadsafe and must be called before any other libssh2 method. libssh2-ruby will automatically call this for you, usually, but if you're only using the methods on Native, then you must call this yourself.

Returns:

  • (Integer)


14
15
16
17
18
19
20
21
22
23
# File 'ext/libssh2_ruby_c/global.c', line 14

static VALUE
init(VALUE module) {
    int result = libssh2_init(0);
    if (result != 0) {
        rb_exc_raise(libssh2_ruby_wrap_error(result));
        return Qnil;
    }

    return Qtrue;
}

.proxy_method(*args) ⇒ Object

This is a helper to define proxy methods on this module. Many methods are proxied to their respective objects, and this lets us do it really easily, concisely.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/libssh2/native.rb', line 8

def self.proxy_method(*args)
  if args.length != 2 && args.length != 3
    raise ArgumentError, "2 or 3 arguments required."
  end

  prefix = nil
  prefix = args.shift if args.length == 3
  name   = args.shift
  klass  = args.shift
  method_name = name
  method_name = "#{prefix}_#{name}" if prefix

  metaclass = class << self; self; end
  metaclass.send(:define_method, method_name) do |object, *args|
    if !object.kind_of?(klass)
      raise ArgumentError, "Receiving object must be a: #{klass}"
    end

    object.send(name, *args)
  end
end

.session_initObject


Session Methods




33
34
35
# File 'lib/libssh2/native.rb', line 33

def self.session_init
  Native::Session.new
end

.LibSSH2::Native.versionString

Returns the version of libssh2 that is running.

Returns:

  • (String)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'ext/libssh2_ruby_c/global.c', line 46

static VALUE
version(VALUE module) {
    VALUE result = rb_cNilClass;
    const char *version_string = libssh2_version(0);

    // Technically `libssh2_version` can return NULL if the runtime
    // version is not new enough, but the "0" parameter above should
    // force this to always be true. Still, better safe than segfault.
    if (version_string != NULL) {
        result = rb_str_new_cstr(version_string);
    }

    return result;
}