void oci8_do_parse_connect_string(VALUE conn_str, VALUE *user, VALUE *pass, VALUE *dbname, VALUE *mode) { static VALUE re = Qnil; if (NIL_P(re)) { re = rb_eval_string(CONN_STR_REGEX); rb_global_variable(&re); } OCI8SafeStringValue(conn_str); if (RTEST(rb_reg_match(re, conn_str))) { *user = rb_reg_nth_match(1, rb_backref_get()); *pass = rb_reg_nth_match(2, rb_backref_get()); *dbname = rb_reg_nth_match(3, rb_backref_get()); *mode = rb_reg_nth_match(4, rb_backref_get()); if (RSTRING_LEN(*user) == 0 && RSTRING_LEN(*pass) == 0) { /* external credential */ *user = Qnil; *pass = Qnil; } if (!NIL_P(*mode)) { char *ptr; SafeStringValue(*mode); ptr = RSTRING_PTR(*mode); if (strcasecmp(ptr, "SYSDBA") == 0) { *mode = sym_SYSDBA; } else if (strcasecmp(ptr, "SYSOPER") == 0) { *mode = sym_SYSOPER; } } } else { rb_raise(rb_eArgError, "invalid connect string \"%s\" (expect \"username/password[@(tns_name|//host[:port]/service_name)][ as (sysdba|sysoper)]\"", RSTRING_PTR(conn_str)); } }
VALUE rb_rtype_valid(VALUE self, VALUE expected, VALUE value) { long i; VALUE e_keys; VALUE v_keys; switch(TYPE(expected)) { case T_MODULE: case T_CLASS: return rb_obj_is_kind_of(value, expected) ? Qtrue : Qfalse; case T_SYMBOL: return rb_respond_to(value, rb_to_id(expected)) ? Qtrue : Qfalse; case T_REGEXP: return rb_reg_match( expected, rb_funcall(value, id_to_s, 0) ) != Qnil ? Qtrue : Qfalse; case T_HASH: if( !RB_TYPE_P(value, T_HASH) ) { return Qfalse; } e_keys = rb_funcall(expected, id_keys, 0); v_keys = rb_funcall(value, id_keys, 0); if( !RTEST(rb_funcall(e_keys, id_eqeq, 1, v_keys)) ) { return Qfalse; } for(i = 0; i < RARRAY_LEN(e_keys); i++) { VALUE e_k = rb_ary_entry(e_keys, i); VALUE e_v = rb_hash_aref(expected, e_k); if(rb_rtype_valid(self, e_v, rb_hash_aref(value, e_k)) == Qfalse) { return Qfalse; } } return Qtrue; case T_ARRAY: for(i = 0; i < RARRAY_LEN(expected); i++) { VALUE e = rb_ary_entry(expected, i); VALUE valid = rb_rtype_valid(self, e, value); if(valid == Qtrue) { return Qtrue; } } return Qfalse; case T_TRUE: return RTEST(value) ? Qtrue : Qfalse; case T_FALSE: return !RTEST(value) ? Qtrue : Qfalse; case T_NIL: return value == Qnil; default: if(rb_obj_is_kind_of(expected, rb_cRange)) { return rb_funcall(expected, id_include, 1, value); } else if(rb_obj_is_kind_of(expected, rb_cProc)) { return RTEST(rb_funcall(expected, id_call, 1, value)) ? Qtrue : Qfalse; } else if( RTEST(rb_obj_is_kind_of(expected, rb_cRtypeBehaviorBase)) ) { return rb_funcall(expected, id_valid, 1, value); } else { VALUE str = rb_any_to_s(expected); rb_raise(rb_eRtypeTypeSignatureError, "Invalid type signature: Unknown type behavior %s", StringValueCStr(str)); return Qfalse; } } }
VALUE regexp_spec_reg_match(VALUE self, VALUE re, VALUE str) { return rb_reg_match(re, str); }