VALUE xml_to_wbxml(VALUE self, VALUE xml_source) { WBXMLError ret = WBXML_OK; WBXMLConvXML2WBXMLParams params; WB_UTINY* xml = NULL; /* Must be null terminated */ WB_UTINY* wbxml = NULL; WB_ULONG wbxml_len = 0; VALUE value; Check_SafeStr(xml_source); if (TYPE(xml_source) != T_STRING) rb_raise(rb_eTypeError, "parameter to xml_to_wbxml must be a string"); xml = (WB_UTINY*)STR2CSTR(xml_source); params.wbxml_version = WBXML_VERSION_13; params.use_strtbl = TRUE; params.keep_ignorable_ws = FALSE; ret = wbxml_conv_xml2wbxml(xml, &wbxml, &wbxml_len, ¶ms); if (ret != WBXML_OK) rb_raise(rb_eRuntimeError, (const char*)wbxml_errors_string(ret)); value = rb_str_new((const char*)wbxml, wbxml_len); if (wbxml != NULL) wbxml_free(wbxml); return value; }
VALUE wbxml_to_xml(VALUE self, VALUE wbxml_source) { WBXMLError ret = WBXML_OK; WBXMLConvWBXML2XMLParams params; WB_UTINY* wbxml = NULL; WB_ULONG wbxml_len = 0; WB_UTINY* xml = NULL; /* Must be null terminated */ VALUE value; Check_SafeStr(wbxml_source); if (TYPE(wbxml_source) != T_STRING) rb_raise(rb_eTypeError, "parameter to wbxml_to_xml must be a string"); wbxml = (WB_UTINY*)STR2CSTR(wbxml_source); wbxml_len = RSTRING_LEN(wbxml_source); params.gen_type = WBXML_ENCODER_XML_GEN_INDENT; params.lang = WBXML_LANG_UNKNOWN; /* Don't force the language */ params.indent = 2; params.keep_ignorable_ws = FALSE; ret = wbxml_conv_wbxml2xml(wbxml, wbxml_len, &xml, ¶ms); if (ret != WBXML_OK) rb_raise(rb_eRuntimeError, (const char*)wbxml_errors_string(ret)); value = rb_str_new((const char*)xml, strlen(xml)); if (xml != NULL) wbxml_free(xml); return value; }
static VALUE rb_mod_autoload(VALUE mod, SEL sel, VALUE sym, VALUE file) { ID id = rb_to_id(sym); Check_SafeStr(file); rb_autoload(mod, id, RSTRING_PTR(file)); return Qnil; }
static VALUE wrap_ma_initialize(VALUE self, VALUE vprofname) { const char *profname; geoword::MAPtr *pService; Check_Type(vprofname, T_STRING); Check_SafeStr(vprofname); profname = STR2CSTR(vprofname); Data_Get_Struct(self, geoword::MAPtr, pService); geoword::MAPtr service = geoword::createMA(profname); *pService = service; return Qnil; }
static VALUE mSyslog_open(int argc, VALUE *argv, VALUE self) { VALUE ident, opt, fac; if (syslog_opened) { rb_raise(rb_eRuntimeError, "syslog already open"); } rb_scan_args(argc, argv, "03", &ident, &opt, &fac); if (NIL_P(ident)) { ident = rb_gv_get("$0"); } #ifdef SafeStringValue SafeStringValue(ident); #else Check_SafeStr(ident); #endif syslog_ident = strdup(RSTRING_PTR(ident)); if (NIL_P(opt)) { syslog_options = LOG_PID | LOG_CONS; } else { syslog_options = NUM2INT(opt); } if (NIL_P(fac)) { syslog_facility = LOG_USER; } else { syslog_facility = NUM2INT(fac); } openlog(syslog_ident, syslog_options, syslog_facility); syslog_opened = 1; setlogmask(syslog_mask = setlogmask(0)); /* be like File.new.open {...} */ if (rb_block_given_p()) { rb_ensure(rb_yield, self, mSyslog_close, self); } return self; }
static VALUE ossl_x509store_add_path(VALUE self, VALUE dir) { X509_STORE *store; X509_LOOKUP *lookup; char *path = NULL; if(dir != Qnil){ Check_SafeStr(dir); path = RSTRING_PTR(dir); } GetX509Store(self, store); lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir()); if(lookup == NULL) ossl_raise(eX509StoreError, NULL); if(X509_LOOKUP_add_dir(lookup, path, X509_FILETYPE_PEM) != 1){ ossl_raise(eX509StoreError, NULL); } return self; }
static VALUE fortran_file_open(int argc, VALUE *argv, VALUE klass) { VALUE vlun, vfname, vstatus, vform, vacces, vblank, vrecord; int lun, record; char *fname, *status, *form, *acces, *blank; rb_scan_args(argc, argv, "25", &vlun, &vfname, &vstatus, &vform, &vacces, &vblank, &vrecord); Check_SafeStr(vfname); fname = RSTRING(vfname)->ptr; lun = FIX2INT(vlun); if (NIL_P(vstatus)) status = "UNKNOWN"; else status = STR2CSTR(vstatus); if (NIL_P(vform)) form = "FORMATTED"; else form = STR2CSTR(vform); if (NIL_P(vacces)) acces = "SEQUENTIAL"; else acces = STR2CSTR(vacces); if (NIL_P(vblank)) blank = "NULL"; else blank = STR2CSTR(vblank); if (NIL_P(vrecord)) record = 0; else record = FIX2INT(vrecord); fortfileopen_(&lun, fname, status, form, acces, blank, &record, strlen(fname), strlen(status), strlen(form), strlen(acces), strlen(blank)); return Qnil; }
/* call-seq: SQLite3::Database.new(file, options = {}) * * Create a new Database object that opens the given file. If utf16 * is +true+, the filename is interpreted as a UTF-16 encoded string. * * By default, the new database will return result rows as arrays * (#results_as_hash) and has type translation disabled (#type_translation=). */ static VALUE initialize(int argc, VALUE *argv, VALUE self) { sqlite3RubyPtr ctx; VALUE file; VALUE opts; VALUE zvfs; #ifdef HAVE_SQLITE3_OPEN_V2 int mode = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE; #endif int status; Data_Get_Struct(self, sqlite3Ruby, ctx); rb_scan_args(argc, argv, "12", &file, &opts, &zvfs); #if defined StringValueCStr StringValuePtr(file); rb_check_safe_obj(file); #else Check_SafeStr(file); #endif if(NIL_P(opts)) opts = rb_hash_new(); else Check_Type(opts, T_HASH); #ifdef HAVE_RUBY_ENCODING_H if(UTF16_LE_P(file) || UTF16_BE_P(file)) { status = sqlite3_open16(utf16_string_value_ptr(file), &ctx->db); } else { #endif if(Qtrue == rb_hash_aref(opts, sym_utf16)) { status = sqlite3_open16(utf16_string_value_ptr(file), &ctx->db); } else { #ifdef HAVE_RUBY_ENCODING_H if(!UTF8_P(file)) { file = rb_str_export_to_enc(file, rb_utf8_encoding()); } #endif if (Qtrue == rb_hash_aref(opts, ID2SYM(rb_intern("readonly")))) { #ifdef HAVE_SQLITE3_OPEN_V2 mode = SQLITE_OPEN_READONLY; #else rb_raise(rb_eNotImpError, "sqlite3-ruby was compiled against a version of sqlite that does not support readonly databases"); #endif } #ifdef HAVE_SQLITE3_OPEN_V2 status = sqlite3_open_v2( StringValuePtr(file), &ctx->db, mode, NIL_P(zvfs) ? NULL : StringValuePtr(zvfs) ); #else status = sqlite3_open( StringValuePtr(file), &ctx->db ); #endif } #ifdef HAVE_RUBY_ENCODING_H } #endif CHECK(ctx->db, status) rb_iv_set(self, "@tracefunc", Qnil); rb_iv_set(self, "@authorizer", Qnil); rb_iv_set(self, "@encoding", Qnil); rb_iv_set(self, "@busy_handler", Qnil); rb_iv_set(self, "@collations", rb_hash_new()); rb_iv_set(self, "@functions", rb_hash_new()); rb_iv_set(self, "@results_as_hash", rb_hash_aref(opts, sym_results_as_hash)); rb_iv_set(self, "@type_translation", rb_hash_aref(opts, sym_type_translation)); #ifdef HAVE_SQLITE3_OPEN_V2 rb_iv_set(self, "@readonly", mode == SQLITE_OPEN_READONLY ? Qtrue : Qfalse); #else rb_iv_set(self, "@readonly", Qfalse); #endif if(rb_block_given_p()) { rb_ensure(rb_yield, self, sqlite3_rb_close, self); } return self; }