示例#1
0
void
Init_ossl_pkcs12()
{
    mPKCS12 = rb_define_module_under(mOSSL, "PKCS12");
    cPKCS12 = rb_define_class_under(mPKCS12, "PKCS12", rb_cObject);
    ePKCS12Error = rb_define_class_under(mPKCS12, "PKCS12Error", eOSSLError);
    rb_define_module_function(mPKCS12, "create", ossl_pkcs12_s_create, -1);

    rb_define_alloc_func(cPKCS12, ossl_pkcs12_s_allocate);
    rb_attr(cPKCS12, rb_intern("key"), 1, 0, Qfalse);
    rb_attr(cPKCS12, rb_intern("certificate"), 1, 0, Qfalse);
    rb_attr(cPKCS12, rb_intern("ca_certs"), 1, 0, Qfalse);
    rb_define_method(cPKCS12, "initialize", ossl_pkcs12_initialize, -1);
    rb_define_method(cPKCS12, "to_der", ossl_pkcs12_to_der, 0);
}
示例#2
0
/*
 * Many operating systems allow signals to be sent to running
 * processes. Some signals have a defined effect on the process, while
 * others may be trapped at the code level and acted upon. For
 * example, your process may trap the USR1 signal and use it to toggle
 * debugging, and may use TERM to initiate a controlled shutdown.
 *
 *     pid = fork do
 *       Signal.trap("USR1") do
 *         $debug = !$debug
 *         puts "Debug now: #$debug"
 *       end
 *       Signal.trap("TERM") do
 *         puts "Terminating..."
 *         shutdown()
 *       end
 *       # . . . do some work . . .
 *     end
 *
 *     Process.detach(pid)
 *
 *     # Controlling program:
 *     Process.kill("USR1", pid)
 *     # ...
 *     Process.kill("USR1", pid)
 *     # ...
 *     Process.kill("TERM", pid)
 *
 * produces:
 *     Debug now: true
 *     Debug now: false
 *    Terminating...
 *
 * The list of available signal names and their interpretation is
 * system dependent. Signal delivery semantics may also vary between
 * systems; in particular signal delivery may not always be reliable.
 */
void
Init_signal(void)
{
#ifndef MACOS_UNUSE_SIGNAL
    VALUE mSignal = rb_define_module("Signal");

    rb_define_global_function("trap", sig_trap, -1);
    rb_define_module_function(mSignal, "trap", sig_trap, -1);
    rb_define_module_function(mSignal, "list", sig_list, 0);

    rb_define_method(rb_eSignal, "initialize", esignal_init, -1);
    rb_attr(rb_eSignal, rb_intern("signo"), 1, 0, 0);
    rb_alias(rb_eSignal, rb_intern("signm"), rb_intern("message"));
    rb_define_method(rb_eInterrupt, "initialize", interrupt_init, -1);

    install_sighandler(SIGINT, sighandler);
#ifdef SIGHUP
    install_sighandler(SIGHUP, sighandler);
#endif
#ifdef SIGQUIT
    install_sighandler(SIGQUIT, sighandler);
#endif
#ifdef SIGTERM
    install_sighandler(SIGTERM, sighandler);
#endif
#ifdef SIGALRM
    install_sighandler(SIGALRM, sighandler);
#endif
#ifdef SIGUSR1
    install_sighandler(SIGUSR1, sighandler);
#endif
#ifdef SIGUSR2
    install_sighandler(SIGUSR2, sighandler);
#endif

#ifdef RUBY_DEBUG_ENV
    if (!ruby_enable_coredump)
#endif
    {
#ifdef SIGBUS
    install_sighandler(SIGBUS, sigbus);
#endif
#ifdef SIGSEGV
    install_sighandler(SIGSEGV, sigsegv);
#endif
    }
#ifdef SIGPIPE
    install_sighandler(SIGPIPE, sigpipe);
#endif

#if defined(SIGCLD)
    init_sigchld(SIGCLD);
#elif defined(SIGCHLD)
    init_sigchld(SIGCHLD);
#endif

#endif /* MACOS_UNUSE_SIGNAL */
}
示例#3
0
/*
 * INIT
 */
void 
Init_ossl_x509store()
{
    VALUE x509stctx;

    eX509StoreError = rb_define_class_under(mX509, "StoreError", eOSSLError);

    cX509Store = rb_define_class_under(mX509, "Store", rb_cObject);
    rb_attr(cX509Store, rb_intern("verify_callback"), 1, 0, Qfalse);
    rb_attr(cX509Store, rb_intern("error"), 1, 0, Qfalse);
    rb_attr(cX509Store, rb_intern("error_string"), 1, 0, Qfalse);
    rb_attr(cX509Store, rb_intern("chain"), 1, 0, Qfalse);
    rb_define_alloc_func(cX509Store, ossl_x509store_alloc);
    rb_define_method(cX509Store, "initialize",   ossl_x509store_initialize, -1);
    rb_define_method(cX509Store, "verify_callback=", ossl_x509store_set_vfy_cb, 1);
    rb_define_method(cX509Store, "flags=",       ossl_x509store_set_flags, 1);
    rb_define_method(cX509Store, "purpose=",     ossl_x509store_set_purpose, 1);
    rb_define_method(cX509Store, "trust=",       ossl_x509store_set_trust, 1);
    rb_define_method(cX509Store, "time=",        ossl_x509store_set_time, 1);
    rb_define_method(cX509Store, "add_path",     ossl_x509store_add_path, 1);
    rb_define_method(cX509Store, "add_file",     ossl_x509store_add_file, 1);
    rb_define_method(cX509Store, "set_default_paths", ossl_x509store_set_default_paths, 0);
    rb_define_method(cX509Store, "add_cert",     ossl_x509store_add_cert, 1);
    rb_define_method(cX509Store, "add_crl",      ossl_x509store_add_crl, 1);
    rb_define_method(cX509Store, "verify",       ossl_x509store_verify, -1);

    cX509StoreContext = rb_define_class_under(mX509,"StoreContext",rb_cObject);
    x509stctx = cX509StoreContext;
    rb_define_alloc_func(cX509StoreContext, ossl_x509stctx_alloc);
    rb_define_method(x509stctx,"initialize",  ossl_x509stctx_initialize, -1);
    rb_define_method(x509stctx,"verify",      ossl_x509stctx_verify, 0);
    rb_define_method(x509stctx,"chain",       ossl_x509stctx_get_chain,0);
    rb_define_method(x509stctx,"error",       ossl_x509stctx_get_err, 0);
    rb_define_method(x509stctx,"error=",      ossl_x509stctx_set_error, 1);
    rb_define_method(x509stctx,"error_string",ossl_x509stctx_get_err_string,0);
    rb_define_method(x509stctx,"error_depth", ossl_x509stctx_get_err_depth, 0);
    rb_define_method(x509stctx,"current_cert",ossl_x509stctx_get_curr_cert, 0);
    rb_define_method(x509stctx,"current_crl", ossl_x509stctx_get_curr_crl, 0);
    rb_define_method(x509stctx,"cleanup",     ossl_x509stctx_cleanup, 0);
    rb_define_method(x509stctx,"flags=",      ossl_x509stctx_set_flags, 1);
    rb_define_method(x509stctx,"purpose=",    ossl_x509stctx_set_purpose, 1);
    rb_define_method(x509stctx,"trust=",      ossl_x509stctx_set_trust, 1);
    rb_define_method(x509stctx,"time=",       ossl_x509stctx_set_time, 1);

}
示例#4
0
文件: ossl_pkcs12.c 项目: fi8on/ruby
void
Init_ossl_pkcs12()
{
    /*
     * Defines a file format commonly used to store private keys with
     * accompanying public key certificates, protected with a password-based
     * symmetric key.
     */
    cPKCS12 = rb_define_class_under(mOSSL, "PKCS12", rb_cObject);
    ePKCS12Error = rb_define_class_under(cPKCS12, "PKCS12Error", eOSSLError);
    rb_define_singleton_method(cPKCS12, "create", ossl_pkcs12_s_create, -1);

    rb_define_alloc_func(cPKCS12, ossl_pkcs12_s_allocate);
    rb_attr(cPKCS12, rb_intern("key"), 1, 0, Qfalse);
    rb_attr(cPKCS12, rb_intern("certificate"), 1, 0, Qfalse);
    rb_attr(cPKCS12, rb_intern("ca_certs"), 1, 0, Qfalse);
    rb_define_method(cPKCS12, "initialize", ossl_pkcs12_initialize, -1);
    rb_define_method(cPKCS12, "to_der", ossl_pkcs12_to_der, 0);
}
示例#5
0
文件: ossl_cms.c 项目: sustr4/rCMS
void
Init_ossl_cms()
{
    cCMS = rb_define_class_under(mOSSL, "CMS", rb_cObject);
    eCMSError = rb_define_class_under(cCMS, "CMSError", rb_eStandardError);

    rb_define_singleton_method(cCMS, "read_cms", ossl_cms_s_read_cms, 1);

    rb_attr(cCMS, rb_intern("data"), 1, 0, Qfalse);
    rb_attr(cCMS, rb_intern("error_string"), 1, 1, Qfalse);

    rb_define_alloc_func(cCMS, ossl_cms_alloc);
    rb_define_copy_func(cCMS, ossl_cms_copy);

    rb_define_method(cCMS, "initialize", ossl_cms_initialize, -1);
    rb_define_method(cCMS, "verify", ossl_cms_verify, -1);
    rb_define_method(cCMS, "to_pem", ossl_cms_to_pem, 0);
    rb_define_alias(cCMS,  "to_s", "to_pem");
    rb_define_method(cCMS, "to_der", ossl_cms_to_der, 0);
}
示例#6
0
static void zkrb_define_methods(void) {
#define DEFINE_METHOD(M, ARGS) { \
    rb_define_method(CZookeeper, #M, method_ ## M, ARGS); }

#define DEFINE_CLASS_METHOD(M, ARGS) { \
    rb_define_singleton_method(CZookeeper, #M, method_ ## M, ARGS); }

// defines a method with a zkrb_ prefix, the actual C method does not have this prefix
#define DEFINE_ZKRB_METHOD(M, ARGS) { \
    rb_define_method(CZookeeper, zkrb_ ## M, method_ ## M, ARGS); }

  // the number after the method name should be actual arity of C function - 1
  DEFINE_METHOD(zkrb_init, -1);

  rb_define_method(CZookeeper, "zkrb_get_children", method_get_children,  4);
  rb_define_method(CZookeeper, "zkrb_exists",       method_exists,        4);
  rb_define_method(CZookeeper, "zkrb_create",       method_create,        6);
  rb_define_method(CZookeeper, "zkrb_delete",       method_delete,        4);
  rb_define_method(CZookeeper, "zkrb_get",          method_get,           4);
  rb_define_method(CZookeeper, "zkrb_set",          method_set,           5);
  rb_define_method(CZookeeper, "zkrb_set_acl",      method_set_acl,       5);
  rb_define_method(CZookeeper, "zkrb_get_acl",      method_get_acl,       3);
  rb_define_method(CZookeeper, "zkrb_add_auth",     method_add_auth,      3);

  rb_define_singleton_method(CZookeeper, "zoo_set_log_level", method_zoo_set_log_level, 1);

  DEFINE_METHOD(client_id, 0);
  DEFINE_METHOD(close_handle, 0);
  DEFINE_METHOD(deterministic_conn_order, 1);
  DEFINE_METHOD(is_unrecoverable, 0);
  DEFINE_METHOD(recv_timeout, 1);
  DEFINE_METHOD(zkrb_state, 0);
  DEFINE_METHOD(sync, 2);
  DEFINE_METHOD(zkrb_iterate_event_loop, 0);
  DEFINE_METHOD(zkrb_get_next_event_st, 0);

  // methods for the ruby-side event manager
  DEFINE_METHOD(zkrb_get_next_event, 1);
  DEFINE_METHOD(zkrb_get_next_event_st, 0);
  DEFINE_METHOD(has_events, 0);

  // Make these class methods?
  DEFINE_METHOD(zerror, 1);

  rb_define_singleton_method(CZookeeper, "set_zkrb_debug_level", klass_method_zkrb_set_debug_level, 1);

  rb_attr(CZookeeper, rb_intern("selectable_io"), 1, 0, Qtrue);

}
示例#7
0
static void zkrb_define_methods(void) {
#define DEFINE_METHOD(method, args) { \
    rb_define_method(Zookeeper, #method, method_ ## method, args); }
#define DEFINE_CLASS_METHOD(method, args) { \
    rb_define_singleton_method(Zookeeper, #method, method_ ## method, args); }

  // the number after the method name should be actual arity of C function - 1
  DEFINE_METHOD(zkrb_init, -1);
  DEFINE_METHOD(get_children, 4);
  DEFINE_METHOD(exists, 4);
  DEFINE_METHOD(create, 6);
  DEFINE_METHOD(delete, 4);
  DEFINE_METHOD(get, 4);
  DEFINE_METHOD(set, 5);
  DEFINE_METHOD(set_acl, 5);
  DEFINE_METHOD(get_acl, 3);
  DEFINE_METHOD(client_id, 0);
  DEFINE_METHOD(close_handle, 0);
  DEFINE_METHOD(deterministic_conn_order, 1);
  DEFINE_METHOD(is_unrecoverable, 0);
  DEFINE_METHOD(recv_timeout, 1);
  DEFINE_METHOD(zkrb_state, 0);
  DEFINE_METHOD(sync, 2);

  // TODO
  // DEFINE_METHOD(add_auth, 3);

  // methods for the ruby-side event manager
  DEFINE_METHOD(get_next_event, 1);
  DEFINE_METHOD(has_events, 0);

  // Make these class methods?
  DEFINE_METHOD(zerror, 1);

  rb_define_singleton_method(Zookeeper, "set_zkrb_debug_level", klass_method_zkrb_set_debug_level, 1);

  rb_attr(Zookeeper, rb_intern("selectable_io"), 1, 0, Qtrue);
  rb_define_method(Zookeeper, "wake_event_loop!", method_wake_event_loop_bang, 0);

}
示例#8
0
文件: class.c 项目: technohippy/oruby
void
rb_define_attr(VALUE klass, const char *name, int read, int write)
{
    rb_attr(klass, rb_intern(name), read, write, FALSE);
}
示例#9
0
文件: error.c 项目: knugie/ruby
void
Init_Exception(void)
{
    rb_eException   = rb_define_class("Exception", rb_cObject);
    rb_define_singleton_method(rb_eException, "exception", rb_class_new_instance, -1);
    rb_define_method(rb_eException, "exception", exc_exception, -1);
    rb_define_method(rb_eException, "initialize", exc_initialize, -1);
    rb_define_method(rb_eException, "==", exc_equal, 1);
    rb_define_method(rb_eException, "to_s", exc_to_s, 0);
    rb_define_method(rb_eException, "message", exc_message, 0);
    rb_define_method(rb_eException, "inspect", exc_inspect, 0);
    rb_define_method(rb_eException, "backtrace", exc_backtrace, 0);
    rb_define_method(rb_eException, "backtrace_locations", exc_backtrace_locations, 0);
    rb_define_method(rb_eException, "set_backtrace", exc_set_backtrace, 1);
    rb_define_method(rb_eException, "cause", exc_cause, 0);

    rb_eSystemExit  = rb_define_class("SystemExit", rb_eException);
    rb_define_method(rb_eSystemExit, "initialize", exit_initialize, -1);
    rb_define_method(rb_eSystemExit, "status", exit_status, 0);
    rb_define_method(rb_eSystemExit, "success?", exit_success_p, 0);

    rb_eFatal  	    = rb_define_class("fatal", rb_eException);
    rb_eSignal      = rb_define_class("SignalException", rb_eException);
    rb_eInterrupt   = rb_define_class("Interrupt", rb_eSignal);

    rb_eStandardError = rb_define_class("StandardError", rb_eException);
    rb_eTypeError     = rb_define_class("TypeError", rb_eStandardError);
    rb_eArgError      = rb_define_class("ArgumentError", rb_eStandardError);
    rb_eIndexError    = rb_define_class("IndexError", rb_eStandardError);
    rb_eKeyError      = rb_define_class("KeyError", rb_eIndexError);
    rb_eRangeError    = rb_define_class("RangeError", rb_eStandardError);

    rb_eScriptError = rb_define_class("ScriptError", rb_eException);
    rb_eSyntaxError = rb_define_class("SyntaxError", rb_eScriptError);

    rb_eLoadError   = rb_define_class("LoadError", rb_eScriptError);
    /* the path failed to load */
    rb_attr(rb_eLoadError, rb_intern_const("path"), 1, 0, Qfalse);

    rb_eNotImpError = rb_define_class("NotImplementedError", rb_eScriptError);

    rb_eNameError     = rb_define_class("NameError", rb_eStandardError);
    rb_define_method(rb_eNameError, "initialize", name_err_initialize, -1);
    rb_define_method(rb_eNameError, "name", name_err_name, 0);
    rb_cNameErrorMesg = rb_define_class_under(rb_eNameError, "message", rb_cData);
    rb_define_singleton_method(rb_cNameErrorMesg, "!", rb_name_err_mesg_new, NAME_ERR_MESG_COUNT);
    rb_define_method(rb_cNameErrorMesg, "==", name_err_mesg_equal, 1);
    rb_define_method(rb_cNameErrorMesg, "to_str", name_err_mesg_to_str, 0);
    rb_define_method(rb_cNameErrorMesg, "_dump", name_err_mesg_dump, 1);
    rb_define_singleton_method(rb_cNameErrorMesg, "_load", name_err_mesg_load, 1);
    rb_eNoMethodError = rb_define_class("NoMethodError", rb_eNameError);
    rb_define_method(rb_eNoMethodError, "initialize", nometh_err_initialize, -1);
    rb_define_method(rb_eNoMethodError, "args", nometh_err_args, 0);

    rb_eRuntimeError = rb_define_class("RuntimeError", rb_eStandardError);
    rb_eSecurityError = rb_define_class("SecurityError", rb_eException);
    rb_eNoMemError = rb_define_class("NoMemoryError", rb_eException);
    rb_eEncodingError = rb_define_class("EncodingError", rb_eStandardError);
    rb_eEncCompatError = rb_define_class_under(rb_cEncoding, "CompatibilityError", rb_eEncodingError);

    syserr_tbl = st_init_numtable();
    rb_eSystemCallError = rb_define_class("SystemCallError", rb_eStandardError);
    rb_define_method(rb_eSystemCallError, "initialize", syserr_initialize, -1);
    rb_define_method(rb_eSystemCallError, "errno", syserr_errno, 0);
    rb_define_singleton_method(rb_eSystemCallError, "===", syserr_eqq, 1);

    rb_mErrno = rb_define_module("Errno");

    rb_define_global_function("warn", rb_warn_m, -1);
}
/*
 * INIT
 */
void
Init_ossl_pkcs7()
{
    cPKCS7 = rb_define_class_under(mOSSL, "PKCS7", rb_cObject);
    ePKCS7Error = rb_define_class_under(cPKCS7, "PKCS7Error", eOSSLError);
    rb_define_singleton_method(cPKCS7, "read_smime", ossl_pkcs7_s_read_smime, 1);
    rb_define_singleton_method(cPKCS7, "write_smime", ossl_pkcs7_s_write_smime, -1);
    rb_define_singleton_method(cPKCS7, "sign",  ossl_pkcs7_s_sign, -1);
    rb_define_singleton_method(cPKCS7, "encrypt", ossl_pkcs7_s_encrypt, -1);
    rb_attr(cPKCS7, rb_intern("data"), 1, 0, Qfalse);
    rb_attr(cPKCS7, rb_intern("error_string"), 1, 1, Qfalse);
    rb_define_alloc_func(cPKCS7, ossl_pkcs7_alloc);
    rb_define_copy_func(cPKCS7, ossl_pkcs7_copy);
    rb_define_method(cPKCS7, "initialize", ossl_pkcs7_initialize, -1);
    rb_define_method(cPKCS7, "type=", ossl_pkcs7_set_type, 1);
    rb_define_method(cPKCS7, "type", ossl_pkcs7_get_type, 0);
    rb_define_method(cPKCS7, "detached=", ossl_pkcs7_set_detached, 1);
    rb_define_method(cPKCS7, "detached", ossl_pkcs7_get_detached, 0);
    rb_define_method(cPKCS7, "detached?", ossl_pkcs7_detached_p, 0);
    rb_define_method(cPKCS7, "cipher=", ossl_pkcs7_set_cipher, 1);
    rb_define_method(cPKCS7, "add_signer", ossl_pkcs7_add_signer, 1);
    rb_define_method(cPKCS7, "signers", ossl_pkcs7_get_signer, 0);
    rb_define_method(cPKCS7, "add_recipient", ossl_pkcs7_add_recipient, 1);
    rb_define_method(cPKCS7, "recipients", ossl_pkcs7_get_recipient, 0);
    rb_define_method(cPKCS7, "add_certificate", ossl_pkcs7_add_certificate, 1);
    rb_define_method(cPKCS7, "certificates=", ossl_pkcs7_set_certificates, 1);
    rb_define_method(cPKCS7, "certificates", ossl_pkcs7_get_certificates, 0);
    rb_define_method(cPKCS7, "add_crl", ossl_pkcs7_add_crl, 1);
    rb_define_method(cPKCS7, "crls=", ossl_pkcs7_set_crls, 1);
    rb_define_method(cPKCS7, "crls", ossl_pkcs7_get_crls, 0);
    rb_define_method(cPKCS7, "add_data", ossl_pkcs7_add_data, 1);
    rb_define_alias(cPKCS7,  "data=", "add_data");
    rb_define_method(cPKCS7, "verify", ossl_pkcs7_verify, -1);
    rb_define_method(cPKCS7, "decrypt", ossl_pkcs7_decrypt, -1);
    rb_define_method(cPKCS7, "to_pem", ossl_pkcs7_to_pem, 0);
    rb_define_alias(cPKCS7,  "to_s", "to_pem");
    rb_define_method(cPKCS7, "to_der", ossl_pkcs7_to_der, 0);

    cPKCS7Signer = rb_define_class_under(cPKCS7, "SignerInfo", rb_cObject);
    rb_define_const(cPKCS7, "Signer", cPKCS7Signer);
    rb_define_alloc_func(cPKCS7Signer, ossl_pkcs7si_alloc);
    rb_define_method(cPKCS7Signer, "initialize", ossl_pkcs7si_initialize,3);
    rb_define_method(cPKCS7Signer, "issuer", ossl_pkcs7si_get_issuer, 0);
    rb_define_alias(cPKCS7Signer, "name", "issuer");
    rb_define_method(cPKCS7Signer, "serial", ossl_pkcs7si_get_serial,0);
    rb_define_method(cPKCS7Signer,"signed_time",ossl_pkcs7si_get_signed_time,0);

    cPKCS7Recipient = rb_define_class_under(cPKCS7,"RecipientInfo",rb_cObject);
    rb_define_alloc_func(cPKCS7Recipient, ossl_pkcs7ri_alloc);
    rb_define_method(cPKCS7Recipient, "initialize", ossl_pkcs7ri_initialize,1);
    rb_define_method(cPKCS7Recipient, "issuer", ossl_pkcs7ri_get_issuer,0);
    rb_define_method(cPKCS7Recipient, "serial", ossl_pkcs7ri_get_serial,0);
    rb_define_method(cPKCS7Recipient, "enc_key", ossl_pkcs7ri_get_enc_key,0);

#define DefPKCS7Const(x) rb_define_const(cPKCS7, #x, INT2NUM(PKCS7_##x))

    DefPKCS7Const(TEXT);
    DefPKCS7Const(NOCERTS);
    DefPKCS7Const(NOSIGS);
    DefPKCS7Const(NOCHAIN);
    DefPKCS7Const(NOINTERN);
    DefPKCS7Const(NOVERIFY);
    DefPKCS7Const(DETACHED);
    DefPKCS7Const(BINARY);
    DefPKCS7Const(NOATTR);
    DefPKCS7Const(NOSMIMECAP);
}
示例#11
0
文件: ossl_ssl.c 项目: 2220142/ruby
void
Init_ossl_ssl()
{
    int i;
    VALUE ary;

#if 0 /* let rdoc know about mOSSL */
    mOSSL = rb_define_module("OpenSSL");
#endif

    ID_callback_state = rb_intern("@callback_state");

    ossl_ssl_ex_vcb_idx = SSL_get_ex_new_index(0,(void *)"ossl_ssl_ex_vcb_idx",0,0,0);
    ossl_ssl_ex_store_p = SSL_get_ex_new_index(0,(void *)"ossl_ssl_ex_store_p",0,0,0);
    ossl_ssl_ex_ptr_idx = SSL_get_ex_new_index(0,(void *)"ossl_ssl_ex_ptr_idx",0,0,0);
    ossl_ssl_ex_client_cert_cb_idx =
	SSL_get_ex_new_index(0,(void *)"ossl_ssl_ex_client_cert_cb_idx",0,0,0);
    ossl_ssl_ex_tmp_dh_callback_idx =
	SSL_get_ex_new_index(0,(void *)"ossl_ssl_ex_tmp_dh_callback_idx",0,0,0);

    mSSL = rb_define_module_under(mOSSL, "SSL");
    eSSLError = rb_define_class_under(mSSL, "SSLError", eOSSLError);

    Init_ossl_ssl_session();

    /* class SSLContext
     *
     * The following attributes are available but don't show up in rdoc.
     * All attributes must be set before calling SSLSocket.new(io, ctx).
     * * ssl_version, cert, key, client_ca, ca_file, ca_path, timeout,
     * * verify_mode, verify_depth client_cert_cb, tmp_dh_callback,
     * * session_id_context, session_add_cb, session_new_cb, session_remove_cb
     */
    cSSLContext = rb_define_class_under(mSSL, "SSLContext", rb_cObject);
    rb_define_alloc_func(cSSLContext, ossl_sslctx_s_alloc);
    for(i = 0; i < numberof(ossl_sslctx_attrs); i++)
        rb_attr(cSSLContext, rb_intern(ossl_sslctx_attrs[i]), 1, 1, Qfalse);
    rb_define_alias(cSSLContext, "ssl_timeout", "timeout");
    rb_define_alias(cSSLContext, "ssl_timeout=", "timeout=");
    rb_define_method(cSSLContext, "initialize",  ossl_sslctx_initialize, -1);
    rb_define_method(cSSLContext, "ssl_version=", ossl_sslctx_set_ssl_version, 1);
    rb_define_method(cSSLContext, "ciphers",     ossl_sslctx_get_ciphers, 0);
    rb_define_method(cSSLContext, "ciphers=",    ossl_sslctx_set_ciphers, 1);

    rb_define_method(cSSLContext, "setup", ossl_sslctx_setup, 0);


    rb_define_const(cSSLContext, "SESSION_CACHE_OFF", LONG2FIX(SSL_SESS_CACHE_OFF));
    rb_define_const(cSSLContext, "SESSION_CACHE_CLIENT", LONG2FIX(SSL_SESS_CACHE_CLIENT)); /* doesn't actually do anything in 0.9.8e */
    rb_define_const(cSSLContext, "SESSION_CACHE_SERVER", LONG2FIX(SSL_SESS_CACHE_SERVER));
    rb_define_const(cSSLContext, "SESSION_CACHE_BOTH", LONG2FIX(SSL_SESS_CACHE_BOTH)); /* no different than CACHE_SERVER in 0.9.8e */
    rb_define_const(cSSLContext, "SESSION_CACHE_NO_AUTO_CLEAR", LONG2FIX(SSL_SESS_CACHE_NO_AUTO_CLEAR));
    rb_define_const(cSSLContext, "SESSION_CACHE_NO_INTERNAL_LOOKUP", LONG2FIX(SSL_SESS_CACHE_NO_INTERNAL_LOOKUP));
    rb_define_const(cSSLContext, "SESSION_CACHE_NO_INTERNAL_STORE", LONG2FIX(SSL_SESS_CACHE_NO_INTERNAL_STORE));
    rb_define_const(cSSLContext, "SESSION_CACHE_NO_INTERNAL", LONG2FIX(SSL_SESS_CACHE_NO_INTERNAL));
    rb_define_method(cSSLContext, "session_add",     ossl_sslctx_session_add, 1);
    rb_define_method(cSSLContext, "session_remove",     ossl_sslctx_session_remove, 1);
    rb_define_method(cSSLContext, "session_cache_mode",     ossl_sslctx_get_session_cache_mode, 0);
    rb_define_method(cSSLContext, "session_cache_mode=",     ossl_sslctx_set_session_cache_mode, 1);
    rb_define_method(cSSLContext, "session_cache_size",     ossl_sslctx_get_session_cache_size, 0);
    rb_define_method(cSSLContext, "session_cache_size=",     ossl_sslctx_set_session_cache_size, 1);
    rb_define_method(cSSLContext, "session_cache_stats",     ossl_sslctx_get_session_cache_stats, 0);
    rb_define_method(cSSLContext, "flush_sessions",     ossl_sslctx_flush_sessions, -1);

    ary = rb_ary_new2(numberof(ossl_ssl_method_tab));
    for (i = 0; i < numberof(ossl_ssl_method_tab); i++) {
        rb_ary_push(ary, ID2SYM(rb_intern(ossl_ssl_method_tab[i].name)));
    }
    rb_obj_freeze(ary);
    /* holds a list of available SSL/TLS methods */
    rb_define_const(cSSLContext, "METHODS", ary);

    /* class SSLSocket
     *
     * The following attributes are available but don't show up in rdoc.
     * * io, context, sync_close
     *
     */
    cSSLSocket = rb_define_class_under(mSSL, "SSLSocket", rb_cObject);
    rb_define_alloc_func(cSSLSocket, ossl_ssl_s_alloc);
    for(i = 0; i < numberof(ossl_ssl_attr_readers); i++)
        rb_attr(cSSLSocket, rb_intern(ossl_ssl_attr_readers[i]), 1, 0, Qfalse);
    for(i = 0; i < numberof(ossl_ssl_attrs); i++)
        rb_attr(cSSLSocket, rb_intern(ossl_ssl_attrs[i]), 1, 1, Qfalse);
    rb_define_alias(cSSLSocket, "to_io", "io");
    rb_define_method(cSSLSocket, "initialize", ossl_ssl_initialize, -1);
    rb_define_method(cSSLSocket, "connect",    ossl_ssl_connect, 0);
    rb_define_method(cSSLSocket, "connect_nonblock",    ossl_ssl_connect_nonblock, 0);
    rb_define_method(cSSLSocket, "accept",     ossl_ssl_accept, 0);
    rb_define_method(cSSLSocket, "accept_nonblock",     ossl_ssl_accept_nonblock, 0);
    rb_define_method(cSSLSocket, "sysread",    ossl_ssl_read, -1);
    rb_define_private_method(cSSLSocket, "sysread_nonblock",    ossl_ssl_read_nonblock, -1);
    rb_define_method(cSSLSocket, "syswrite",   ossl_ssl_write, 1);
    rb_define_private_method(cSSLSocket, "syswrite_nonblock",    ossl_ssl_write_nonblock, 1);
    rb_define_method(cSSLSocket, "sysclose",   ossl_ssl_close, 0);
    rb_define_method(cSSLSocket, "cert",       ossl_ssl_get_cert, 0);
    rb_define_method(cSSLSocket, "peer_cert",  ossl_ssl_get_peer_cert, 0);
    rb_define_method(cSSLSocket, "peer_cert_chain", ossl_ssl_get_peer_cert_chain, 0);
    rb_define_method(cSSLSocket, "cipher",     ossl_ssl_get_cipher, 0);
    rb_define_method(cSSLSocket, "state",      ossl_ssl_get_state, 0);
    rb_define_method(cSSLSocket, "pending",    ossl_ssl_pending, 0);
    rb_define_method(cSSLSocket, "session_reused?",    ossl_ssl_session_reused, 0);
    rb_define_method(cSSLSocket, "session=",    ossl_ssl_set_session, 1);
    rb_define_method(cSSLSocket, "verify_result", ossl_ssl_get_verify_result, 0);

#define ossl_ssl_def_const(x) rb_define_const(mSSL, #x, INT2NUM(SSL_##x))

    ossl_ssl_def_const(VERIFY_NONE);
    ossl_ssl_def_const(VERIFY_PEER);
    ossl_ssl_def_const(VERIFY_FAIL_IF_NO_PEER_CERT);
    ossl_ssl_def_const(VERIFY_CLIENT_ONCE);
    /* Not introduce constants included in OP_ALL such as...
     * ossl_ssl_def_const(OP_MICROSOFT_SESS_ID_BUG);
     * ossl_ssl_def_const(OP_NETSCAPE_CHALLENGE_BUG);
     * ossl_ssl_def_const(OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG);
     * ossl_ssl_def_const(OP_SSLREF2_REUSE_CERT_TYPE_BUG);
     * ossl_ssl_def_const(OP_MICROSOFT_BIG_SSLV3_BUFFER);
     * ossl_ssl_def_const(OP_MSIE_SSLV2_RSA_PADDING);
     * ossl_ssl_def_const(OP_SSLEAY_080_CLIENT_DH_BUG);
     * ossl_ssl_def_const(OP_TLS_D5_BUG);
     * ossl_ssl_def_const(OP_TLS_BLOCK_PADDING_BUG);
     * ossl_ssl_def_const(OP_DONT_INSERT_EMPTY_FRAGMENTS);
     */
    ossl_ssl_def_const(OP_ALL);
#if defined(SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION)
    ossl_ssl_def_const(OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);
#endif
#if defined(SSL_OP_SINGLE_ECDH_USE)
    ossl_ssl_def_const(OP_SINGLE_ECDH_USE);
#endif
    ossl_ssl_def_const(OP_SINGLE_DH_USE);
    ossl_ssl_def_const(OP_EPHEMERAL_RSA);
#if defined(SSL_OP_CIPHER_SERVER_PREFERENCE)
    ossl_ssl_def_const(OP_CIPHER_SERVER_PREFERENCE);
#endif
    ossl_ssl_def_const(OP_TLS_ROLLBACK_BUG);
    ossl_ssl_def_const(OP_NO_SSLv2);
    ossl_ssl_def_const(OP_NO_SSLv3);
    ossl_ssl_def_const(OP_NO_TLSv1);
#if defined(SSL_OP_NO_TICKET)
    ossl_ssl_def_const(OP_NO_TICKET);
#endif
    ossl_ssl_def_const(OP_PKCS1_CHECK_1);
    ossl_ssl_def_const(OP_PKCS1_CHECK_2);
    ossl_ssl_def_const(OP_NETSCAPE_CA_DN_BUG);
    ossl_ssl_def_const(OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG);
}
示例#12
0
/*
 * INIT
 */
void
Init_ossl_x509store()
{
    VALUE x509stctx;

#if 0
    mOSSL = rb_define_module("OpenSSL"); /* let rdoc know about mOSSL */
    mX509 = rb_define_module_under(mOSSL, "X509");
#endif

    eX509StoreError = rb_define_class_under(mX509, "StoreError", eOSSLError);

    /* Document-class: OpenSSL::X509::Store
     *
     * The X509 certificate store holds trusted CA certificates used to verify
     * peer certificates.
     *
     * The easiest way to create a useful certificate store is:
     *
     *   cert_store = OpenSSL::X509::Store.new
     *   cert_store.set_default_paths
     *
     * This will use your system's built-in certificates.
     *
     * If your system does not have a default set of certificates you can
     * obtain a set from Mozilla here: http://curl.haxx.se/docs/caextract.html
     * (Note that this set does not have an HTTPS download option so you may
     * wish to use the firefox-db2pem.sh script to extract the certificates
     * from a local install to avoid man-in-the-middle attacks.)
     *
     * After downloading or generating a cacert.pem from the above link you
     * can create a certificate store from the pem file like this:
     *
     *   cert_store = OpenSSL::X509::Store.new
     *   cert_store.add_file 'cacert.pem'
     *
     * The certificate store can be used with an SSLSocket like this:
     *
     *   ssl_context = OpenSSL::SSL::SSLContext.new
     *   ssl_context.cert_store = cert_store
     *
     *   tcp_socket = TCPSocket.open 'example.com', 443
     *
     *   ssl_socket = OpenSSL::SSL::SSLSocket.new tcp_socket, ssl_context
     */

    cX509Store = rb_define_class_under(mX509, "Store", rb_cObject);
    rb_attr(cX509Store, rb_intern("verify_callback"), 1, 0, Qfalse);
    rb_attr(cX509Store, rb_intern("error"), 1, 0, Qfalse);
    rb_attr(cX509Store, rb_intern("error_string"), 1, 0, Qfalse);
    rb_attr(cX509Store, rb_intern("chain"), 1, 0, Qfalse);
    rb_define_alloc_func(cX509Store, ossl_x509store_alloc);
    rb_define_method(cX509Store, "initialize",   ossl_x509store_initialize, -1);
    rb_define_method(cX509Store, "verify_callback=", ossl_x509store_set_vfy_cb, 1);
    rb_define_method(cX509Store, "flags=",       ossl_x509store_set_flags, 1);
    rb_define_method(cX509Store, "purpose=",     ossl_x509store_set_purpose, 1);
    rb_define_method(cX509Store, "trust=",       ossl_x509store_set_trust, 1);
    rb_define_method(cX509Store, "time=",        ossl_x509store_set_time, 1);
    rb_define_method(cX509Store, "add_path",     ossl_x509store_add_path, 1);
    rb_define_method(cX509Store, "add_file",     ossl_x509store_add_file, 1);
    rb_define_method(cX509Store, "set_default_paths", ossl_x509store_set_default_paths, 0);
    rb_define_method(cX509Store, "add_cert",     ossl_x509store_add_cert, 1);
    rb_define_method(cX509Store, "add_crl",      ossl_x509store_add_crl, 1);
    rb_define_method(cX509Store, "verify",       ossl_x509store_verify, -1);

    cX509StoreContext = rb_define_class_under(mX509,"StoreContext",rb_cObject);
    x509stctx = cX509StoreContext;
    rb_define_alloc_func(cX509StoreContext, ossl_x509stctx_alloc);
    rb_define_method(x509stctx,"initialize",  ossl_x509stctx_initialize, -1);
    rb_define_method(x509stctx,"verify",      ossl_x509stctx_verify, 0);
    rb_define_method(x509stctx,"chain",       ossl_x509stctx_get_chain,0);
    rb_define_method(x509stctx,"error",       ossl_x509stctx_get_err, 0);
    rb_define_method(x509stctx,"error=",      ossl_x509stctx_set_error, 1);
    rb_define_method(x509stctx,"error_string",ossl_x509stctx_get_err_string,0);
    rb_define_method(x509stctx,"error_depth", ossl_x509stctx_get_err_depth, 0);
    rb_define_method(x509stctx,"current_cert",ossl_x509stctx_get_curr_cert, 0);
    rb_define_method(x509stctx,"current_crl", ossl_x509stctx_get_curr_crl, 0);
    rb_define_method(x509stctx,"flags=",      ossl_x509stctx_set_flags, 1);
    rb_define_method(x509stctx,"purpose=",    ossl_x509stctx_set_purpose, 1);
    rb_define_method(x509stctx,"trust=",      ossl_x509stctx_set_trust, 1);
    rb_define_method(x509stctx,"time=",       ossl_x509stctx_set_time, 1);

}
示例#13
0
static void
rb_attr2(VALUE klass, const char *attr, int read, int write)
{
	rb_attr(klass, rb_intern(attr), read, write, 0);
}
示例#14
0
void
Init_vte_terminal(VALUE mVte)
{
    VALUE cTerminal, cTerminalEraseBinding, cTerminalAntiAlias;
#if VTE_CHECK_VERSION(0, 18, 0)
    VALUE cTerminalCursorBlinkMode;
#endif
#if VTE_CHECK_VERSION(0, 19, 1)
    VALUE cTerminalCursorShape;
#endif

    id_new = rb_intern("new");
    id_call = rb_intern("call");

    id_row = rb_intern("@row");
    id_column = rb_intern("@column");
    id_fore = rb_intern("@fore");
    id_back = rb_intern("@back");
    id_underline = rb_intern("@underline");
    id_strikethrough = rb_intern("@strikethrough");

    cTerminal = G_DEF_CLASS(VTE_TYPE_TERMINAL, "Terminal", mVte);
    cTerminalEraseBinding = G_DEF_CLASS(VTE_TYPE_TERMINAL_ERASE_BINDING,
                                        "TerminalEraseBinding", mVte);
#if VTE_CHECK_VERSION(0, 18, 0)
    cTerminalCursorBlinkMode = G_DEF_CLASS(VTE_TYPE_TERMINAL_CURSOR_BLINK_MODE,
					   "TerminalCursorBlinkMode", mVte);
#endif
#if VTE_CHECK_VERSION(0, 19, 1)
    cTerminalCursorShape = G_DEF_CLASS(VTE_TYPE_TERMINAL_CURSOR_SHAPE,
				       "TerminalCursorShape", mVte);
#endif
    cTerminalAntiAlias = G_DEF_CLASS(VTE_TYPE_TERMINAL_ANTI_ALIAS,
                                     "TerminalAntiAlias", mVte);

    cCharAttributes = rb_define_class_under(mVte, "CharAttributes", rb_cObject);

    rb_define_method(cCharAttributes, "initialize", ca_initialize, 6);
    rb_attr(cCharAttributes, rb_intern("row"), TRUE, FALSE, TRUE);
    rb_attr(cCharAttributes, rb_intern("column"), TRUE, FALSE, TRUE);
    rb_attr(cCharAttributes, rb_intern("fore"), TRUE, FALSE, TRUE);
    rb_attr(cCharAttributes, rb_intern("back"), TRUE, FALSE, TRUE);
    rb_define_alias(cCharAttributes, "foreground", "fore");
    rb_define_alias(cCharAttributes, "background", "back");
    rb_define_method(cCharAttributes, "underline?", ca_get_underline, 0);
    rb_define_method(cCharAttributes, "strikethrough?",
                     ca_get_strikethrough, 0);


    rb_define_method(cTerminal, "initialize", term_initialize, 0);

    rb_define_method(cTerminal, "fork_command", term_fork_command, -1);
    rb_define_method(cTerminal, "fork_pty", term_fork_pty, -1);

    rb_define_method(cTerminal, "feed", term_feed, 1);
    rb_define_method(cTerminal, "feed_child", term_feed_child, 1);
    rb_define_method(cTerminal, "feed_child_binary", term_feed_child_binary, 1);

    rb_define_method(cTerminal, "copy_clipboard", term_copy_clipboard, 0);
    rb_define_method(cTerminal, "paste_clipboard", term_paste_clipboard, 0);
    rb_define_method(cTerminal, "copy_primary", term_copy_primary, 0);
    rb_define_method(cTerminal, "paste_primary", term_paste_primary, 0);

    rb_define_method(cTerminal, "set_size", term_set_size, 2);

    rb_define_method(cTerminal, "set_audible_bell", term_set_audible_bell, 1);
    rb_define_method(cTerminal, "audible_bell?", term_get_audible_bell, 0);
    rb_define_method(cTerminal, "set_visible_bell", term_set_visible_bell, 1);
    rb_define_method(cTerminal, "visible_bell?", term_get_visible_bell, 0);

    rb_define_method(cTerminal, "set_scroll_background",
                     term_set_scroll_background, 1);
    rb_define_method(cTerminal, "set_scroll_on_output",
                     term_set_scroll_on_output, 1);
    rb_define_method(cTerminal, "set_scroll_on_keystroke",
                     term_set_scroll_on_keystroke, 1);

    rb_define_method(cTerminal, "set_color_dim", term_set_color_dim, 1);
    rb_define_method(cTerminal, "set_color_bold", term_set_color_bold, 1);
    rb_define_method(cTerminal, "set_color_foreground",
                     term_set_color_foreground, 1);
    rb_define_method(cTerminal, "set_color_background",
                     term_set_color_background, 1);
    rb_define_method(cTerminal, "set_color_cursor", term_set_color_cursor, 1);
    rb_define_method(cTerminal, "set_color_highlight",
                     term_set_color_highlight, 1);
    rb_define_method(cTerminal, "set_colors", term_set_colors, 3);
    rb_define_method(cTerminal, "set_default_colors",
                     term_set_default_colors, 0);
    rb_define_method(cTerminal, "set_background_image",
                     term_set_background_image, 1);
    rb_define_method(cTerminal, "set_background_tint_color",
                     term_set_background_tint_color, 1);
    rb_define_method(cTerminal, "set_background_saturation",
                     term_set_background_saturation, 1);
    rb_define_method(cTerminal, "set_background_transparent",
                     term_set_background_transparent, 1);
    rb_define_method(cTerminal, "set_cursor_blinks", term_set_cursor_blinks, 1);
#if VTE_CHECK_VERSION(0, 18, 0)
    rb_define_method(cTerminal, "set_cursor_blink_mode",
		     term_set_cursor_blink_mode, 1);
    rb_define_method(cTerminal, "cursor_blink_mode",
		     term_get_cursor_blink_mode, 0);
#endif
#if VTE_CHECK_VERSION(0, 19, 1)
    rb_define_method(cTerminal, "set_cursor_shape", term_set_cursor_shape, 1);
    rb_define_method(cTerminal, "cursor_shape", term_get_cursor_shape, 0);
    rb_define_method(cTerminal, "pty", term_get_pty, 0);
    rb_define_method(cTerminal, "child_exit_status",
		     term_get_child_exit_status, 0);
#endif
    rb_define_method(cTerminal, "set_scrollback_lines",
                     term_set_scrollback_lines, 1);

    rb_define_method(cTerminal, "im_append_menuitems",
                     term_im_append_menuitems, 1);

    rb_define_method(cTerminal, "set_font", term_set_font, -1);
    rb_define_method(cTerminal, "font", term_get_font, 0);
    rb_define_method(cTerminal, "using_xft?", term_get_using_xft, 0);
    rb_define_method(cTerminal, "set_allow_bold", term_set_allow_bold, 1);
    rb_define_method(cTerminal, "allow_bold?", term_get_allow_bold, 0);
    rb_define_method(cTerminal, "has_selection?", term_get_has_selection, 0);
    rb_define_alias(cTerminal, "have_selection?", "has_selection?");
    rb_define_method(cTerminal, "set_word_chars", term_set_word_chars, 1);
    rb_define_method(cTerminal, "word_char?", term_is_word_char, 1);
    rb_define_method(cTerminal, "set_backspace_binding",
                     term_set_backspace_binding, 1);
    rb_define_method(cTerminal, "set_delete_binding",
                     term_set_delete_binding, 1);
    rb_define_method(cTerminal, "mouse_autohide?", term_get_mouse_autohide, 0);
    rb_define_method(cTerminal, "set_mouse_autohide",
                     term_set_mouse_autohide, 1);

    rb_define_method(cTerminal, "reset", term_reset, 2);

    rb_define_method(cTerminal, "get_text", term_get_text, -1);
    rb_define_method(cTerminal, "get_text_range", term_get_text_range, -1);

    rb_define_method(cTerminal, "cursor_position", term_get_cursor_position, 0);

    rb_define_method(cTerminal, "match_clear_all", term_match_clear_all, 0);
    rb_define_method(cTerminal, "match_add", term_match_add, 1);
    rb_define_method(cTerminal, "match_set_cursor",
                     term_match_set_cursor, 2);
    rb_define_method(cTerminal, "match_set_cursor_type",
                     term_match_set_cursor_type, 2);
    rb_define_method(cTerminal, "match_remove", term_match_remove, 1);
    rb_define_method(cTerminal, "match_check", term_match_check, 2);

    rb_define_method(cTerminal, "set_emulation", term_set_emulation, 1);
    rb_define_method(cTerminal, "emulation", term_get_emulation, 0);
    rb_define_method(cTerminal, "default_emulation",
                     term_get_default_emulation, 0);

    rb_define_method(cTerminal, "set_encoding", term_set_encoding, 1);
    rb_define_method(cTerminal, "encoding", term_get_encoding, 0);

    rb_define_method(cTerminal, "status_line", term_get_status_line, 0);
    rb_define_method(cTerminal, "padding", term_get_padding, 0);

    rb_define_method(cTerminal, "set_pty", term_set_pty, 1);

    rb_define_method(cTerminal, "adjustment", term_get_adjustment, 0);
    rb_define_method(cTerminal, "char_width", term_get_char_width, 0);
    rb_define_method(cTerminal, "char_height", term_get_char_height, 0);
    rb_define_method(cTerminal, "char_descent", term_get_char_descent, 0);
    rb_define_method(cTerminal, "char_ascent", term_get_char_ascent, 0);
    rb_define_method(cTerminal, "row_count", term_get_row_count, 0);
    rb_define_method(cTerminal, "column_count", term_get_column_count, 0);
    rb_define_method(cTerminal, "window_title", term_get_window_title, 0);
    rb_define_method(cTerminal, "icon_title", term_get_icon_title, 0);

    G_DEF_SETTERS(cTerminal);
}
示例#15
0
void
Init_cairo_font (void)
{
#if CAIRO_CHECK_VERSION(1, 7, 6)
  cr_id_call = rb_intern ("call");
  cr_id_new = rb_intern ("new");

  cr_id_init = rb_intern ("init");
  cr_id_render_glyph = rb_intern ("render_glyph");
  cr_id_text_to_glyphs = rb_intern ("text_to_glyphs");
  cr_id_unicode_to_glyph = rb_intern ("unicode_to_glyph");

  cr_id_at_glyphs = rb_intern ("@glyphs");
  cr_id_at_clusters = rb_intern ("@clusters");
  cr_id_at_cluster_flags = rb_intern ("@cluster_flags");
  cr_id_at_need_glyphs = rb_intern ("@need_glyphs");
  cr_id_at_need_clusters = rb_intern ("@need_clusters");
  cr_id_at_need_cluster_flags = rb_intern ("@need_cluster_flags");
#endif

  rb_cCairo_FontFace =
    rb_define_class_under (rb_mCairo, "FontFace", rb_cObject);
  rb_define_alloc_func (rb_cCairo_FontFace, cr_font_face_allocate);

  rb_define_singleton_method (rb_cCairo_FontFace, "quartz_supported?",
                              cr_font_face_quartz_supported_p, 0);
  rb_define_singleton_method (rb_cCairo_FontFace, "freetype_supported?",
                              cr_font_face_freetype_supported_p, 0);

#ifdef CAIRO_HAS_FT_FONT
  rb_cCairo_FreeTypeFontFace =
    rb_define_class_under (rb_mCairo, "FreeTypeFontFace", rb_cCairo_FontFace);

  {
    FT_Error error;

    error = FT_Init_FreeType (&cr_freetype_library);
    cr_freetype_error_check (error, "failed to initialize FreeType", Qnil);

    rb_define_finalizer (rb_cCairo_FreeTypeFontFace,
                         rb_proc_new (cr_freetype_done_library, Qnil));
  }

  rb_define_method (rb_cCairo_FreeTypeFontFace, "initialize",
                    cr_freetype_font_face_initialize, 1);
#endif

#if CAIRO_CHECK_VERSION(1, 7, 6)
  rb_cCairo_ToyFontFace =
    rb_define_class_under (rb_mCairo, "ToyFontFace", rb_cCairo_FontFace);

  rb_define_method (rb_cCairo_ToyFontFace, "initialize",
                    cr_toy_font_face_initialize, -1);

  rb_define_method (rb_cCairo_ToyFontFace, "family",
                    cr_toy_font_face_get_family, 0);
  rb_define_method (rb_cCairo_ToyFontFace, "slant",
                    cr_toy_font_face_get_slant, 0);
  rb_define_method (rb_cCairo_ToyFontFace, "weight",
                    cr_toy_font_face_get_weight, 0);


  rb_cCairo_UserFontFace =
    rb_define_class_under (rb_mCairo, "UserFontFace", rb_cCairo_FontFace);

  rb_define_method (rb_cCairo_UserFontFace, "initialize",
                    cr_user_font_face_initialize, 0);

  rb_define_method (rb_cCairo_UserFontFace, "on_init",
                    cr_user_font_face_on_init, 0);
  rb_define_method (rb_cCairo_UserFontFace, "on_render_glyph",
                    cr_user_font_face_on_render_glyph, 0);
  rb_define_method (rb_cCairo_UserFontFace, "on_text_to_glyphs",
                    cr_user_font_face_on_text_to_glyphs, 0);
  rb_define_method (rb_cCairo_UserFontFace, "on_unicode_to_glyph",
                    cr_user_font_face_on_unicode_to_glyph, 0);


  rb_cCairo_UserFontFace_TextToGlyphsData =
    rb_define_class_under (rb_cCairo_UserFontFace,
                           "TextToGlyphsData", rb_cObject);
  rb_attr (rb_cCairo_UserFontFace_TextToGlyphsData, rb_intern ("glyphs"),
           CR_TRUE, CR_TRUE, CR_TRUE);
  rb_attr (rb_cCairo_UserFontFace_TextToGlyphsData, rb_intern ("clusters"),
           CR_TRUE, CR_TRUE, CR_TRUE);

  rb_define_method (rb_cCairo_UserFontFace_TextToGlyphsData,
                    "initialize", cr_text_to_glyphs_data_initialize, 3);

  rb_define_method (rb_cCairo_UserFontFace_TextToGlyphsData,
                    "cluster_flags",
                    cr_text_to_glyphs_data_get_cluster_flags, 0);
  rb_define_method (rb_cCairo_UserFontFace_TextToGlyphsData,
                    "cluster_flags=",
                    cr_text_to_glyphs_data_set_cluster_flags, 1);
  rb_define_method (rb_cCairo_UserFontFace_TextToGlyphsData,
                    "need_glyphs?", cr_text_to_glyphs_data_need_glyphs, 0);
  rb_define_method (rb_cCairo_UserFontFace_TextToGlyphsData,
                    "need_clusters?", cr_text_to_glyphs_data_need_clusters, 0);
  rb_define_method (rb_cCairo_UserFontFace_TextToGlyphsData,
                    "need_cluster_flags?",
                    cr_text_to_glyphs_data_need_cluster_flags, 0);

  RB_CAIRO_DEF_SETTERS (rb_cCairo_UserFontFace_TextToGlyphsData);
#endif
}
示例#16
0
文件: texplay.c 项目: aanno/texplay
void
Init_texplay() {

  VALUE jm_Module = rb_define_module("TexPlay");
  VALUE TPPoint = rb_define_class_under(jm_Module, "TPPoint", rb_cObject);

  /** define basic point class TPPoint **/
  rb_attr(TPPoint, rb_intern("x"), 1, 1, Qtrue);
  rb_attr(TPPoint, rb_intern("y"), 1, 1, Qtrue);
  rb_define_method(TPPoint, "initialize", m_init_TPPoint, -1);
  /** end of TPPoint definition **/

  /* TexPlay methods */
  rb_define_method(jm_Module, "paint", m_paint, -1);
  rb_define_method(jm_Module, "get_pixel", m_getpixel, -1);
  rb_define_method(jm_Module, "circle", m_circle, -1);
  rb_define_method(jm_Module, "line", m_line, -1);
  rb_define_method(jm_Module, "rect", m_rect, -1);
  rb_define_method(jm_Module, "pixel", m_pixel, -1);
  rb_define_method(jm_Module, "fill", m_flood_fill, -1);
  rb_define_method(jm_Module, "bezier", m_bezier, -1);
  rb_define_method(jm_Module, "polyline", m_polyline, -1);
  rb_define_method(jm_Module, "ngon", m_ngon, -1);
    
  rb_define_method(jm_Module, "splice", m_splice, -1);
    
  rb_define_method(jm_Module, "color", m_color, -1);
  rb_define_method(jm_Module, "offset", m_offset, -1);
  rb_define_method(jm_Module, "method_missing", m_missing, -1);
  rb_define_method(jm_Module, "quad_cached?", m_quad_cached, 0);

  rb_define_method(jm_Module, "each", m_each, -1);
    
  /* needs to be updated, not yet done **/
  /* rb_define_method(jm_Module, "bitmask", m_bitmask, -1); */
  /* rb_define_method(jm_Module, "leftshift", m_lshift, -1); */
  /* rb_define_method(jm_Module, "rightshift", m_rshift, -1); */
  /* rb_define_method(jm_Module, "[]=", m_special_pixel, -1); */

  rb_define_method(jm_Module, "dup", m_dup_image, 0);
  rb_define_method(jm_Module, "clone", m_clone_image, 0);
  rb_define_method(jm_Module, "to_blob", m_to_blob, 0);
  rb_define_method(jm_Module, "force_sync", m_force_sync, 1);
  rb_define_method(jm_Module, "set_options", m_user_set_options, 1);
  rb_define_method(jm_Module, "get_options", m_get_options, 0);
  rb_define_method(jm_Module, "delete_options", m_user_delete_options, 0);

  rb_define_method(jm_Module, "refresh_cache", m_cache_refresh, 0);
    
  /* a constant containing the sidelength of largest allowable quad */
  rb_define_const(jm_Module, "TP_MAX_QUAD_SIZE", INT2FIX(max_quad_size() - 2));

  /* singleton method for creating & removing macros */
  rb_define_singleton_method(jm_Module, "create_macro", M_create_macro, 1);
  rb_define_singleton_method(jm_Module, "remove_macro", M_remove_macro, 1);
  rb_define_singleton_method(jm_Module, "refresh_cache_all", M_refresh_cache_all, 0);
  /* rb_define_singleton_method(jm_Module, "create_blank_image", M_create_blank, 3); */

  /** aliases; must be made on singleton class because we're using class methods **/
  rb_define_method(jm_Module, "box", m_rect, -1);
  rb_define_method(jm_Module, "colour", m_color, -1);
  rb_define_method(jm_Module, "composite", m_splice, -1);
  rb_define_method(jm_Module, "set_pixel", m_pixel, -1);
  rb_define_method(jm_Module, "[]", m_getpixel, -1);
  rb_define_method(jm_Module, "cache", m_cache_refresh, 0);
  /** end of aliases **/

  /** basic setup **/

  /* seed the random number generator */
  srand(time(NULL));

  monkey_patch_gosu();
  /** end basic setup **/
}
示例#17
0
/*
 * call-seq:
 *   column.select(options) {|record| ...} -> Groonga::Hash
 *   column.select(query, options) -> Groonga::Hash
 *   column.select(expression, options) -> Groonga::Hash
 *
 * カラムが所属するテーブルからブロックまたは文字列で指定し
 * た条件にマッチするレコードを返す。返されたテーブルには
 * +expression+という特異メソッドがあり、指定した条件を表し
 * ているGroonga::Expressionを取得できる。
 * Groonga::Expression#snippetを使うことにより、指定した条件
 * 用のスニペットを簡単に生成できる。
 *
 *   results = description_column.select do |column|
 *     column =~ "groonga"
 *   end
 *   snippet = results.expression.snippet([["<em>", "</em>"]])
 *   results.each do |record|
 *     puts "#{record['name']}の説明文の中で「groonga」が含まれる部分"
 *     snippet.execute(record["description"].each do |snippet|
 *       puts "---"
 *       puts "#{snippet}..."
 *       puts "---"
 *     end
 *   end
 *
 * 出力例
 *   Ruby/groongaの説明文の中で「groonga」が含まれる部分
 *   ---
 *   Ruby/<em>groonga</em>は<em>groonga</em>のいわゆるDB-APIの層の...
 *   ---
 *
 * _query_には「[カラム名]:[演算子][値]」という書式で条件を
 * 指定する。演算子は以下の通り。
 *
 * [なし]
 *   [カラム値] == [値]
 * [<tt>!</tt>]
 *   [カラム値] != [値]
 * [<tt><</tt>]
 *   [カラム値] < [値]
 * [<tt>></tt>]
 *   [カラム値] > [値]
 * [<tt><=</tt>]
 *   [カラム値] <= [値]
 * [<tt>>=</tt>]
 *   [カラム値] >= [値]
 * [<tt>@</tt>]
 *   [カラム値]が[値]を含んでいるかどうか
 *
 * 例:
 *   "groonga" # _column_カラムの値が"groonga"のレコードにマッチ
 *   "name:daijiro" # _column_カラムが属しているテーブルの
 *                  # "name"カラムの値が"daijiro"のレコードにマッチ
 *   "description:@groonga" # _column_カラムが属しているテーブルの
 *                          # "description"カラムが
 *                          # "groonga"を含んでいるレコードにマッチ
 *
 * _expression_には既に作成済みのGroonga::Expressionを渡す
 *
 * ブロックで条件を指定する場合は
 * Groonga::ColumnExpressionBuilderを参照。
 *
 * _options_に指定可能な値は以下の通り。
 *
 * [+:operator+]
 *   マッチしたレコードをどのように扱うか。指定可能な値は以
 *   下の通り。省略した場合はGroonga::Operation::OR。
 *
 *   [Groonga::Operation::OR]
 *     マッチしたレコードを追加。すでにレコードが追加され
 *     ている場合は何もしない。
 *   [Groonga::Operation::AND]
 *     マッチしたレコードのスコアを増加。マッチしなかった
 *     レコードを削除。
 *   [Groonga::Operation::BUT]
 *     マッチしたレコードを削除。
 *   [Groonga::Operation::ADJUST]
 *     マッチしたレコードのスコアを増加。
 *
 * [+:result+]
 *   検索結果を格納するテーブル。マッチしたレコードが追加さ
 *   れていく。省略した場合は新しくテーブルを作成して返す。
 *
 * [+:name+]
 *   条件の名前。省略した場合は名前を付けない。
 *
 * [+:syntax+]
 *   _query_の構文。省略した場合は+:query+。
 *
 *   参考: Groonga::Expression#parse.
 *
 * [+:allow_pragma+]
 *   query構文時にプラグマを利用するかどうか。省略した場合は
 *   利用する。
 *
 *   参考: Groonga::Expression#parse.
 *
 * [+:allow_column+]
 *   query構文時にカラム指定を利用するかどうか。省略した場合
 *   は利用する。
 *
 *   参考: Groonga::Expression#parse.
 *
 * [+:allow_update+]
 *   script構文時に更新操作を利用するかどうか。省略した場合
 *   は利用する。
 *
 *   参考: Groonga::Expression#parse.
 */
static VALUE
rb_grn_column_select (int argc, VALUE *argv, VALUE self)
{
    grn_ctx *context;
    grn_obj *table, *column, *result, *expression;
    grn_operator operator = GRN_OP_OR;
    VALUE options;
    VALUE rb_query, condition_or_options;
    VALUE rb_name, rb_operator, rb_result, rb_syntax;
    VALUE rb_allow_pragma, rb_allow_column, rb_allow_update;
    VALUE builder;
    VALUE rb_expression = Qnil;

    rb_query = Qnil;

    rb_scan_args(argc, argv, "02", &condition_or_options, &options);

    rb_grn_column_deconstruct(SELF(self), &column, &context,
			      NULL, NULL,
			      NULL, NULL, NULL);
    table = grn_column_table(context, column);

    if (RVAL2CBOOL(rb_obj_is_kind_of(condition_or_options, rb_cString))) {
        rb_query = condition_or_options;
    } else if (RVAL2CBOOL(rb_obj_is_kind_of(condition_or_options,
                                            rb_cGrnExpression))) {
        rb_expression = condition_or_options;
    } else {
        if (!NIL_P(options))
            rb_raise(rb_eArgError,
		     "should be [query_string, option_hash], "
		     "[expression, option_hash] "
		     "or [option_hash]: %s",
		     rb_grn_inspect(rb_ary_new4(argc, argv)));
        options = condition_or_options;
    }

    rb_grn_scan_options(options,
			"operator", &rb_operator,
			"result", &rb_result,
			"name", &rb_name,
			"syntax", &rb_syntax,
			"allow_pragma", &rb_allow_pragma,
			"allow_column", &rb_allow_column,
			"allow_update", &rb_allow_update,
			NULL);

    if (!NIL_P(rb_operator))
	operator = NUM2INT(rb_operator);

    if (NIL_P(rb_result)) {
	result = grn_table_create(context, NULL, 0, NULL,
				  GRN_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC,
				  table,
				  0);
	rb_result = GRNTABLE2RVAL(context, result, RB_GRN_TRUE);
    } else {
	result = RVAL2GRNTABLE(rb_result, &context);
    }

    if (NIL_P(rb_expression)) {
      builder = rb_grn_column_expression_builder_new(self, rb_name, rb_query);
      rb_funcall(builder, rb_intern("syntax="), 1, rb_syntax);
      rb_funcall(builder, rb_intern("allow_pragma="), 1, rb_allow_pragma);
      rb_funcall(builder, rb_intern("allow_column="), 1, rb_allow_column);
      rb_funcall(builder, rb_intern("allow_update="), 1, rb_allow_update);
      rb_expression = rb_grn_column_expression_builder_build(builder);
    }
    rb_grn_object_deconstruct(RB_GRN_OBJECT(DATA_PTR(rb_expression)),
                              &expression, NULL,
                              NULL, NULL, NULL, NULL);

    grn_table_select(context, table, expression, result, operator);
    rb_grn_context_check(context, self);

    rb_attr(rb_singleton_class(rb_result),
	    rb_intern("expression"),
	    RB_GRN_TRUE, RB_GRN_FALSE, RB_GRN_FALSE);
    rb_iv_set(rb_result, "@expression", rb_expression);

    return rb_result;
}
示例#18
0
/* This class is a node for an N-ary tree data structure
 * with a unique identifier, text value, children, features
 * (annotations) and dependencies.
 *
 * This class was partly based on the 'rubytree' gem.
 * RubyTree is licensed under the BSD license and can
 * be found at http://rubytree.rubyforge.org/rdoc/.
 */
void Init_native(void) {

	birch = rb_define_module("Birch");
	
	/* 
	 * Birch::Tree
	 */
	 birch_tree = rb_define_class_under(birch, "Tree", rb_cObject);
	
	// Mixin Enumerable.
	rb_include_module(birch_tree, rb_mEnumerable);
	
	// Attribute accessors
	rb_attr(birch_tree, rb_intern("id"), 1, 1, 1);
	rb_attr(birch_tree, rb_intern("value"), 1, 1, 1);
	rb_attr(birch_tree, rb_intern("parent"), 1, 1, 1);
	rb_attr(birch_tree, rb_intern("features"), 1, 1, 1);
	
	// Attribute readers
	rb_attr(birch_tree, rb_intern("children"), 1, 0, 0);
	rb_attr(birch_tree, rb_intern("edges"), 1, 0, 0);
	
	// Methods
	rb_define_method(birch_tree, "initialize", birch_initialize, 2);
	rb_define_method(birch_tree, "root", birch_root, 0);
	rb_define_method(birch_tree, "<<", birch_add, 1);
	rb_define_method(birch_tree, "add", birch_add, 1);
	rb_define_method(birch_tree, "[]", birch_get, 1);
	rb_define_method(birch_tree, "get", birch_get, 1);
	rb_define_method(birch_tree, "[]=", birch_set, 2);
	rb_define_method(birch_tree, "set", birch_set, 2); 
	rb_define_method(birch_tree, "unset", birch_unset, 1); 
	rb_define_method(birch_tree, "size", birch_size, 0);
	rb_define_method(birch_tree, "each", birch_each, 0);
	rb_define_method(birch_tree, "find", birch_find, 1);
	rb_define_method(birch_tree, "is_leaf?", birch_is_leaf, 0);
	rb_define_method(birch_tree, "is_root?", birch_is_root, 0);
	rb_define_method(birch_tree, "has_parent?", birch_has_parent, 0);
	rb_define_method(birch_tree, "has_children?", birch_has_children, 0);
	rb_define_method(birch_tree, "has_edges?", birch_has_edges, 0);
	rb_define_method(birch_tree, "has_feature?", birch_has_feature, 1);
	rb_define_method(birch_tree, "has_features?", birch_has_features, 0);
	rb_define_method(birch_tree, "has?", birch_has_feature, 1);
	rb_define_method(birch_tree, "link", birch_link, 1);
	rb_define_method(birch_tree, "set_as_root!", birch_set_as_root, 0);
	rb_define_method(birch_tree, "remove", birch_remove, 1);
	rb_define_method(birch_tree, "remove_all!", birch_remove_all, 0); 
	
	/* 
	 * Birch::Edge
	 */

	birch_edge = rb_define_class_under(birch, "Edge", rb_cObject);
	
	// Attribute readers
	rb_attr(birch_edge, rb_intern("node_a"), 1, 0, 0);
	rb_attr(birch_edge, rb_intern("node_b"), 1, 0, 0);
	rb_attr(birch_edge, rb_intern("directed"), 1, 0, 0);
	rb_attr(birch_edge, rb_intern("direction"), 1, 0, 0);
	
	rb_define_method(birch_edge, "initialize", birch_edge_initialize, -1);
	
}