Esempio n. 1
0
File: otama.c Progetto: kyama/otama
static VALUE
otama_record_rb_value(VALUE self)
{
	return rb_iv_get(self, "@value");
}
Esempio n. 2
0
File: port.c Progetto: mi07/trema
/*
 * Compares two ports by substracting their unique numbers.
 *
 * @return [Number] the result of the substraction. Zero ports are equal.
 */
static VALUE
port_compare( VALUE self, VALUE other ) {
  uint16_t a = ( uint16_t ) NUM2UINT( rb_iv_get( self, "@number" ) );
  uint16_t b = ( uint16_t ) NUM2UINT( rb_iv_get( other, "@number" ) );
  return UINT2NUM( ( uint16_t ) ( a - b ) );
}
Esempio n. 3
0
File: otama.c Progetto: kyama/otama
static VALUE
otama_record_rb_id(VALUE self)
{
	return rb_iv_get(self, "@id");
}
Esempio n. 4
0
File: port.c Progetto: mi07/trema
/*
 * The port's supported features as a 32-bit bitmap.
 *
 * @return [Number] the value of supported.
 */
static VALUE 
port_supported( VALUE self ) {
  return rb_iv_get( self, "@supported" );
}
Esempio n. 5
0
File: port.c Progetto: mi07/trema
/*
 * The features advertised by the peer connected to the port as a 32-bit bitmap.
 *
 * @return [Number] the value of peer.
 */
static VALUE
port_peer( VALUE self ) {
  return rb_iv_get( self, "@peer" );
}
Esempio n. 6
0
static int is_running(VALUE self) {
  VALUE rval = rb_iv_get(self, "@_running");
  return RTEST(rval);
}
Esempio n. 7
0
File: port.c Progetto: mi07/trema
/*
 * The port's advertised features as a 32-bit bitmap.
 *
 * @return [Number] the value of advertised.
 */
static VALUE
port_advertised( VALUE self ) {
  return rb_iv_get( self, "@advertised" );
}
Esempio n. 8
0
File: port.c Progetto: mi07/trema
/*
 * The port's configuration as a 32-bit bitmap.
 *
 * @return [Number] the value of config.
 */
static VALUE
port_config( VALUE self ) {
  return rb_iv_get( self, "@config" );
}
Esempio n. 9
0
File: port.c Progetto: mi07/trema
/*
 * The port's state as a 32-bit bitmap.
 *
 * @return [Number] the value of state.
 */
static VALUE
port_state( VALUE self ) {
  return rb_iv_get( self, "@state" );
}
Esempio n. 10
0
File: port.c Progetto: mi07/trema
/*
 * The port's Ethernet address expressed as a {Mac} object.
 *
 * @return [Mac] the value of hw_addr.
 */
static VALUE
port_hw_addr( VALUE self ) {
  return rb_iv_get( self, "@hw_addr" );
}
Esempio n. 11
0
File: port.c Progetto: mi07/trema
/*
 * The port's human readable defined name.
 *
 * @return [String] the value of name.
 */
static VALUE
port_name( VALUE self ) {
  return rb_iv_get( self, "@name" );
}
Esempio n. 12
0
File: port.c Progetto: mi07/trema
/*
 * The port's unique number.
 *
 * @return [Number] the value of number.
 */
static VALUE
port_number( VALUE self ) {
  return rb_iv_get( self, "@number" );
}
Esempio n. 13
0
static int
sysexit_status(VALUE err)
{
    VALUE st = rb_iv_get(err, "status");
    return NUM2INT(st);
}
Esempio n. 14
0
static int is_closed(VALUE self) {
  VALUE rval = rb_iv_get(self, "@_closed");
  return RTEST(rval);
}
Esempio n. 15
0
VALUE board_ci( VALUE self, VALUE x, VALUE y ) {
  int w = NUM2INT(rb_iv_get( self, "@width" ));
  return INT2NUM( NUM2INT(x) + NUM2INT(y) * w );
}
Esempio n. 16
0
File: port.c Progetto: mi07/trema
/*
 * The port's current features as a 32-bit bitmap.
 *
 * @return [Number] the value of curr.
 */
static VALUE
port_curr( VALUE self ) {
  return rb_iv_get( self, "@curr" );
}
Esempio n. 17
0
/*
 * The destination TCP or UDP port number.
 *
 * @return [Number] the value of attribute tp_dst.
 */
static VALUE
action_get_tp_dst( VALUE self ) {
  return rb_iv_get( self, "@tp_dst" );
}
/*
 * call-seq:
 *    ctx.setup => Qtrue # first time
 *    ctx.setup => nil # thereafter
 *
 * This method is called automatically when a new SSLSocket is created.
 * Normally you do not need to call this method (unless you are writing an extension in C).
 */
static VALUE
ossl_sslctx_setup(VALUE self)
{
    SSL_CTX *ctx;
    X509 *cert = NULL, *client_ca = NULL;
    X509_STORE *store;
    EVP_PKEY *key = NULL;
    char *ca_path = NULL, *ca_file = NULL;
    int i, verify_mode;
    VALUE val;

    if(OBJ_FROZEN(self)) return Qnil;
    Data_Get_Struct(self, SSL_CTX, ctx);

#if !defined(OPENSSL_NO_DH)
    if (RTEST(ossl_sslctx_get_tmp_dh_cb(self))){
	SSL_CTX_set_tmp_dh_callback(ctx, ossl_tmp_dh_callback);
    }
    else{
	SSL_CTX_set_tmp_dh_callback(ctx, ossl_default_tmp_dh_callback);
    }
#endif
    SSL_CTX_set_ex_data(ctx, ossl_ssl_ex_ptr_idx, (void*)self);

    val = ossl_sslctx_get_cert_store(self);
    if(!NIL_P(val)){
	/*
         * WORKAROUND:
	 *   X509_STORE can count references, but
	 *   X509_STORE_free() doesn't care it.
	 *   So we won't increment it but mark it by ex_data.
	 */
        store = GetX509StorePtr(val); /* NO NEED TO DUP */
        SSL_CTX_set_cert_store(ctx, store);
        SSL_CTX_set_ex_data(ctx, ossl_ssl_ex_store_p, (void*)1);
    }

    val = ossl_sslctx_get_extra_cert(self);
    if(!NIL_P(val)){
	rb_block_call(val, rb_intern("each"), 0, 0, ossl_sslctx_add_extra_chain_cert_i, self);
    }

    /* private key may be bundled in certificate file. */
    val = ossl_sslctx_get_cert(self);
    cert = NIL_P(val) ? NULL : GetX509CertPtr(val); /* NO DUP NEEDED */
    val = ossl_sslctx_get_key(self);
    key = NIL_P(val) ? NULL : GetPKeyPtr(val); /* NO DUP NEEDED */
    if (cert && key) {
        if (!SSL_CTX_use_certificate(ctx, cert)) {
            /* Adds a ref => Safe to FREE */
            ossl_raise(eSSLError, "SSL_CTX_use_certificate:");
        }
        if (!SSL_CTX_use_PrivateKey(ctx, key)) {
            /* Adds a ref => Safe to FREE */
            ossl_raise(eSSLError, "SSL_CTX_use_PrivateKey:");
        }
        if (!SSL_CTX_check_private_key(ctx)) {
            ossl_raise(eSSLError, "SSL_CTX_check_private_key:");
        }
    }

    val = ossl_sslctx_get_client_ca(self);
    if(!NIL_P(val)){
	if(TYPE(val) == T_ARRAY){
	    for(i = 0; i < RARRAY_LEN(val); i++){
		client_ca = GetX509CertPtr(RARRAY_PTR(val)[i]);
        	if (!SSL_CTX_add_client_CA(ctx, client_ca)){
		    /* Copies X509_NAME => FREE it. */
        	    ossl_raise(eSSLError, "SSL_CTX_add_client_CA");
        	}
	    }
        }
	else{
	    client_ca = GetX509CertPtr(val); /* NO DUP NEEDED. */
            if (!SSL_CTX_add_client_CA(ctx, client_ca)){
		/* Copies X509_NAME => FREE it. */
        	ossl_raise(eSSLError, "SSL_CTX_add_client_CA");
            }
	}
    }

    val = ossl_sslctx_get_ca_file(self);
    ca_file = NIL_P(val) ? NULL : StringValuePtr(val);
    val = ossl_sslctx_get_ca_path(self);
    ca_path = NIL_P(val) ? NULL : StringValuePtr(val);
    if(ca_file || ca_path){
	if (!SSL_CTX_load_verify_locations(ctx, ca_file, ca_path))
	    rb_warning("can't set verify locations");
    }

    val = ossl_sslctx_get_verify_mode(self);
    verify_mode = NIL_P(val) ? SSL_VERIFY_NONE : NUM2INT(val);
    SSL_CTX_set_verify(ctx, verify_mode, ossl_ssl_verify_callback);
    if (RTEST(ossl_sslctx_get_client_cert_cb(self)))
	SSL_CTX_set_client_cert_cb(ctx, ossl_client_cert_cb);

    val = ossl_sslctx_get_timeout(self);
    if(!NIL_P(val)) SSL_CTX_set_timeout(ctx, NUM2LONG(val));

    val = ossl_sslctx_get_verify_dep(self);
    if(!NIL_P(val)) SSL_CTX_set_verify_depth(ctx, NUM2LONG(val));

    val = ossl_sslctx_get_options(self);
    if(!NIL_P(val)) {
    	SSL_CTX_set_options(ctx, NUM2LONG(val));
    } else {
	SSL_CTX_set_options(ctx, SSL_OP_ALL);
    }
    rb_obj_freeze(self);

    val = ossl_sslctx_get_sess_id_ctx(self);
    if (!NIL_P(val)){
	StringValue(val);
	if (!SSL_CTX_set_session_id_context(ctx, RSTRING_PTR(val),
					    RSTRING_LEN(val))){
	    ossl_raise(eSSLError, "SSL_CTX_set_session_id_context:");
	}
    }

    if (RTEST(rb_iv_get(self, "@session_get_cb"))) {
	SSL_CTX_sess_set_get_cb(ctx, ossl_sslctx_session_get_cb);
	OSSL_Debug("SSL SESSION get callback added");
    }
    if (RTEST(rb_iv_get(self, "@session_new_cb"))) {
	SSL_CTX_sess_set_new_cb(ctx, ossl_sslctx_session_new_cb);
	OSSL_Debug("SSL SESSION new callback added");
    }
    if (RTEST(rb_iv_get(self, "@session_remove_cb"))) {
	SSL_CTX_sess_set_remove_cb(ctx, ossl_sslctx_session_remove_cb);
	OSSL_Debug("SSL SESSION remove callback added");
    }
    return Qtrue;
}