/** * call-seq: * uc.resolve("/someuri") -> "/someuri", "", handler * uc.resolve("/someuri/pathinfo") -> "/someuri", "/pathinfo", handler * uc.resolve("/notfound/orhere") -> nil, nil, nil * uc.resolve("/") -> "/", "/", handler # if uc.register("/", handler) * uc.resolve("/path/from/root") -> "/", "/path/from/root", handler # if uc.register("/", handler) * * Attempts to resolve either the whole URI or at the longest prefix, returning * the prefix (as script_info), path (as path_info), and registered handler * (usually an HttpHandler). If it doesn't find a handler registered at the longest * match then it returns nil,nil,nil. * * Because the resolver uses a trie you are able to register a handler at *any* character * in the URI and it will be handled as long as it's the longest prefix. So, if you * registered handler #1 at "/something/lik", and #2 at "/something/like/that", then a * a search for "/something/like" would give you #1. A search for "/something/like/that/too" * would give you #2. * * This is very powerful since it means you can also attach handlers to parts of the ; * (semi-colon) separated path params, any part of the path, use off chars, anything really. * It also means that it's very efficient to do this only taking as long as the URI has * characters. * * A slight modification to the CGI 1.2 standard is given for handlers registered to "/". * CGI expects all CGI scripts to be at some script path, so it doesn't really say anything * about a script that handles the root. To make this work, the resolver will detect that * the requested handler is at "/", and return that for script_name, and then simply return * the full URI back as path_info. * * It expects strings with no embedded '\0' characters. Don't try other string-like stuff yet. */ VALUE URIClassifier_resolve(VALUE self, VALUE uri) { void *handler = NULL; int pref_len = 0; struct tst *tst = NULL; VALUE result; unsigned char *uri_str = NULL; DATA_GET(self, struct tst, tst); uri_str = (unsigned char *)StringValueCStr(uri); handler = tst_search(uri_str, tst, &pref_len); result = rb_ary_new(); if(handler) { rb_ary_push(result, rb_str_substr (uri, 0, pref_len)); if(pref_len == 1 && uri_str[0] == '/') { rb_ary_push(result, uri); } else { rb_ary_push(result, rb_str_substr(uri, pref_len, RSTRING(uri)->len)); } rb_ary_push(result, (VALUE)handler); } else { rb_ary_push(result, Qnil); rb_ary_push(result, Qnil); rb_ary_push(result, Qnil); } return result; }
extern "C" VALUE signer_sign(VALUE self, VALUE szIn) { VALUE ret; ret = rb_str_new2(""); Signer *pSign; Data_Get_Struct(self, Signer, pSign); if(NIL_P(szIn)) rb_raise(rb_eArgError, "nil for sign"); if (pSign) { szptr szSign; if (pSign->Sign(RSTRING(szIn)->ptr, szSign)) { ret = rb_str_new2((char *)(const char *)szSign); } } int err_no = pSign->ErrorCode(); if (err_no){ char err[20]; sprintf(err, "Signer error: %d", err_no); rb_raise(rb_eStandardError, err); } return ret; }
VALUE string_spec_RSTRING_ptr_assign_call(VALUE self, VALUE str) { char *ptr = RSTRING(str)->ptr; ptr[1] = 'x'; rb_str_concat(str, rb_str_new2("d")); return str; }
// ---------------------------------------------------------------------------- VALUE RubyClassHandler::SendKeyMacro(VALUE self, VALUE rMacroString) // ---------------------------------------------------------------------------- {//static called from Ruby // send a Ruby macro string to our macro processor // eg., "SendKeyMacro("{LSHIFT DOWN}{MBUTTON DOWN}" This->m_macroProcessIsBusy = true; VALUE str = StringValue(rMacroString); char* p = RSTRING(str)->ptr; wxString macroKeys(p); #if defined(LOGGING) //LOGIT( _T("RubyClassHandler:SendKeyMacro[%s]"), macroKeys.c_str()); #endif // Make sure keys go to main window (not Ruby console or other foreground) HWND hRubyConsole = ::FindWindow(_T("#32770"), _T("Ruby Console")); if (hRubyConsole) {;} ::EnableWindow(g_hWndSketchUp,TRUE); ::SetFocus(g_hWndSketchUp); ::SetForegroundWindow(g_hWndSketchUp); This->m_pMacroRunner->SendMacroString( macroKeys, wxTheApp->GetTopWindow() ); ::SetFocus(g_hWndSketchUp); This->m_macroProcessIsBusy = false; return true; }
static VALUE bug_str_s_cstr_noembed(VALUE self, VALUE str) { VALUE str2 = rb_str_new(NULL, 0); long capacity = RSTRING_LEN(str) + TERM_LEN(str); char *buf = ALLOC_N(char, capacity); Check_Type(str, T_STRING); FL_SET((str2), STR_NOEMBED); memcpy(buf, RSTRING_PTR(str), capacity); RBASIC(str2)->flags &= ~RSTRING_EMBED_LEN_MASK; RSTRING(str2)->as.heap.aux.capa = capacity; RSTRING(str2)->as.heap.ptr = buf; RSTRING(str2)->as.heap.len = RSTRING_LEN(str); TERM_FILL(RSTRING_END(str2), TERM_LEN(str)); return str2; }
static VALUE method_create(VALUE self, VALUE path, VALUE value, VALUE flags) { char realpath[10240]; Check_Type(path, T_STRING); Check_Type(value, T_STRING); Check_Type(flags, T_FIXNUM); FETCH_DATA_PTR(self, zk); check_errors(zoo_create(zk->zh, RSTRING(path)->ptr, RSTRING(value)->ptr, RSTRING(value)->len, &ZOO_OPEN_ACL_UNSAFE, FIX2INT(flags), realpath, sizeof(realpath))); return rb_str_new2(realpath); }
VALUE rb_yp_update(VALUE self, VALUE domain, VALUE map, VALUE ypop, VALUE inkey, VALUE inval) { int res; if( domain == Qnil ) { domain = rb_yp_get_default_domain(self); }; res = yp_update(STR2CSTR(domain), STR2CSTR(map), FIX2INT(ypop), STR2CSTR(inkey), RSTRING(inkey)->len, STR2CSTR(inval), RSTRING(inval)->len); rb_yp_check_yperr(res); return INT2NUM(res); };
VALUE rb_yp_next(VALUE self, VALUE domain, VALUE map, VALUE inkey) { char *key, *val; int keylen, vallen; int res; VALUE vkey, vval; if( domain == Qnil ) { domain = rb_yp_get_default_domain(self); }; res = yp_next(STR2CSTR(domain), STR2CSTR(map), STR2CSTR(inkey), RSTRING(inkey)->len, &key, &keylen, &val, &vallen); rb_yp_check_yperr(res); if( keylen > 0 ) { vkey = rb_tainted_str_new(key, keylen); } else { vkey = Qnil; }; if( vallen > 0 ) { vval = rb_tainted_str_new(val, vallen); } else { vval = Qnil; }; return rb_assoc_new(vkey, vval); };
void rb_invalid_str(const char *str, const char *type) { VALUE s = rb_str_inspect(rb_str_new2(str)); rb_raise(rb_eArgError, "invalid value for %s: %s", type, RSTRING(s)->ptr); }
static VALUE rbreg_get(VALUE, VALUE rname) { lwc::Registry *reg = lwc::Registry::Instance(); if (!reg) { rb_raise(rb_eRuntimeError, "lwc::Registry has not yet been initialized"); } VALUE sname = rb_check_string_type(rname); if (NIL_P(sname)) { rb_raise(rb_eTypeError, "RLWC::Registry.get expects a string as argument"); } char *name = RSTRING(sname)->ptr; lwc::Object *obj = reg->get(name); if (!obj) { return Qnil; } else { VALUE rv = Qnil; //if (!strcmp(obj->getLoaderName(), "rbloader")) { // rv = ((Object*)obj)->self(); // //} else { rv = rb_funcall2(cLWCObject, rb_intern("new"), 0, NULL); SetObjectPointer(rv, obj); //} return rv; } }
// Create a new destination endpoint static VALUE t_create_destination(VALUE self, VALUE client_instance, VALUE destination_name) { MIDIEndpointRef destination; RbMIDIClient* client; Data_Get_Struct(client_instance, RbMIDIClient, client); CFStringRef destination_str = CFStringCreateWithCString(kCFAllocatorDefault, RSTRING(destination_name)->ptr, kCFStringEncodingASCII); MIDIDestinationCreate(client->client, destination_str, RbMIDIReadProc, NULL, &destination); VALUE destination_instance = rb_class_new_instance(0, 0, cEndpoint); if( destination_instance == Qnil ) { free_objects(); rb_fatal("Couldn't create an instance of Endpoint!"); } RbEndpoint* endpoint_struct; Data_Get_Struct(destination_instance, RbEndpoint, endpoint_struct); endpoint_struct->endpoint = destination; return destination_instance; }
// Create a new source endpoint static VALUE t_create_source(VALUE self, VALUE client_instance, VALUE source_name) { MIDIEndpointRef source; RbMIDIClient* client; Data_Get_Struct(client_instance, RbMIDIClient, client); CFStringRef source_str = CFStringCreateWithCString(kCFAllocatorDefault, RSTRING(source_name)->ptr, kCFStringEncodingASCII); MIDISourceCreate(client->client, source_str, &source); VALUE source_instance = rb_class_new_instance(0, 0, cEndpoint); if( source_instance == Qnil ) { free_objects(); rb_fatal("Couldn't create an instance of Endpoint!"); } RbEndpoint* endpoint_struct; Data_Get_Struct(source_instance, RbEndpoint, endpoint_struct); endpoint_struct->endpoint = source; return source_instance; }
void mrb_irep_free(mrb_state *mrb, mrb_irep *irep) { size_t i; if (!(irep->flags & MRB_ISEQ_NO_FREE)) mrb_free(mrb, irep->iseq); for (i=0; i<irep->plen; i++) { if (mrb_type(irep->pool[i]) == MRB_TT_STRING) { mrb_gc_free_str(mrb, RSTRING(irep->pool[i])); mrb_free(mrb, mrb_obj_ptr(irep->pool[i])); } #ifdef MRB_WORD_BOXING else if (mrb_type(irep->pool[i]) == MRB_TT_FLOAT) { mrb_free(mrb, mrb_obj_ptr(irep->pool[i])); } #endif } mrb_free(mrb, irep->pool); mrb_free(mrb, irep->syms); for (i=0; i<irep->rlen; i++) { mrb_irep_decref(mrb, irep->reps[i]); } mrb_free(mrb, irep->reps); mrb_free(mrb, irep->lv); mrb_free(mrb, (void *)irep->filename); mrb_free(mrb, irep->lines); mrb_debug_info_free(mrb, irep->debug_info); mrb_free(mrb, irep); }
VALUE rCORBA_Request_add_inout_arg(int _argc, VALUE *_argv, VALUE self) { VALUE arg_name = Qnil; VALUE arg_rtc = Qnil; VALUE arg_rval = Qnil; // extract and check arguments rb_scan_args(_argc, _argv, "21", &arg_rtc, &arg_rval, &arg_name); r2tao_check_type(arg_rtc, r2tao_cTypecode); if (arg_name!=Qnil) Check_Type(arg_name, T_STRING); CORBA::Request_ptr _req = r2tao_Request_r2t(self); R2TAO_TRY { CORBA::ORB_var _orb = _req->target ()->_get_orb (); CORBA::TypeCode_var _arg_tc = r2tao_Typecode_r2t (arg_rtc, _orb. in()); char *_arg_name = (arg_name!=Qnil) ? RSTRING (arg_name)->ptr : 0; // add INOUT arg CORBA::Any& _arg = (arg_name!=Qnil) ? _req->add_inout_arg (_arg_name) : _req->add_inout_arg (); // assign value to Any if (arg_rval!=Qnil) r2tao_Typecode_Ruby2Any(_arg, _arg_tc.in (), arg_rval, _orb.in ()); } R2TAO_CATCH; return ULONG2NUM (_req->arguments ()->count ()); }
VALUE string_spec_RSTRING_ptr_assign_funcall(VALUE self, VALUE str) { char *ptr = RSTRING(str)->ptr; ptr[1] = 'x'; rb_funcall(str, rb_intern("<<"), 1, rb_str_new2("e")); return str; }
static VALUE rb_sp_connect (VALUE self, VALUE eid, VALUE sockaddr) { int _eid = FIX2INT (eid); const char *_sockaddr = RSTRING (sockaddr)->ptr; return INT2FIX (sp_connect (_eid, _sockaddr) ); }
VALUE rCORBA_Request_add_out_arg(int _argc, VALUE *_argv, VALUE self) { VALUE arg_name = Qnil; VALUE arg_rtc = Qnil; // extract and check arguments rb_scan_args(_argc, _argv, "11", &arg_rtc, &arg_name); r2tao_check_type(arg_rtc, r2tao_cTypecode); if (arg_name!=Qnil) Check_Type(arg_name, T_STRING); CORBA::Request_ptr _req = r2tao_Request_r2t(self); R2TAO_TRY { CORBA::ORB_var _orb = _req->target ()->_get_orb (); CORBA::TypeCode_var _arg_tc = r2tao_Typecode_r2t (arg_rtc, _orb. in()); char *_arg_name = (arg_name!=Qnil) ? RSTRING (arg_name)->ptr : 0; // add OUT arg if (arg_name!=Qnil) _req->add_out_arg (_arg_name); else _req->add_out_arg (); } R2TAO_CATCH; return ULONG2NUM (_req->arguments ()->count ()); }
VALUE erlix_atom_init(VALUE self,VALUE string){ ErlixTerm* atom; VALUE str=StringValue(string); Data_Get_Struct(self,ErlixTerm,atom); atom->term=erl_mk_atom(RSTRING(str)->ptr); return self; }
static VALUE rb_load_file(VALUE self, VALUE rbfstr) { char buf[65535] = { '\0'; } FILE *f; VALUE listary, rmobj; Check_Type(rbfstr, T_STRING); listary = rb_iv_get(c_map, "list"); f = fopen(RSTRING(rbfstr)->ptr, "r"); if (!f) rb_raise(rb_eStdError, "file not found: %s", RSTRING(rbfstr)->ptr); while (fgets(buf, sizeof(buf), f)) load_string(buf, listary); }
VALUE rb_thrift_memory_buffer_read(VALUE self, VALUE length_value) { int length = FIX2INT(length_value); VALUE index_value = rb_ivar_get(self, index_ivar_id); int index = FIX2INT(index_value); VALUE buf = GET_BUF(self); VALUE data = rb_funcall(buf, slice_method_id, 2, index_value, length_value); index += length; if (index > RSTRING_LEN(buf)) { index = RSTRING_LEN(buf); } if (index >= GARBAGE_BUFFER_SIZE) { rb_ivar_set(self, buf_ivar_id, rb_funcall(buf, slice_method_id, 2, INT2FIX(index), INT2FIX(RSTRING_LEN(buf) - 1))); index = 0; } if (RSTRING(data)->len < length) { rb_raise(rb_eEOFError, "Not enough bytes remain in memory buffer"); } rb_ivar_set(self, index_ivar_id, INT2FIX(index)); return data; }
static VALUE syserr_initialize(int argc, VALUE *argv, VALUE self) { #if !defined(_WIN32) && !defined(__VMS) char *strerror(int); #endif const char *err; VALUE mesg, error; VALUE klass = rb_obj_class(self); if (klass == rb_eSystemCallError) { rb_scan_args(argc, argv, "11", &mesg, &error); if (argc == 1 && FIXNUM_P(mesg)) { error = mesg; mesg = Qnil; } if (!NIL_P(error) && st_lookup(syserr_tbl, NUM2LONG(error), &klass)) { /* change class */ if (TYPE(self) != T_OBJECT) { /* insurance to avoid type crash */ rb_raise(rb_eTypeError, "invalid instance type"); } RBASIC(self)->klass = klass; } } else { rb_scan_args(argc, argv, "01", &mesg); error = rb_const_get(klass, rb_intern("Errno")); } if (!NIL_P(error)) err = strerror(NUM2LONG(error)); else err = "unknown error"; if (!NIL_P(mesg)) { VALUE str = mesg; size_t len; StringValue(str); len = strlen(err)+RSTRING(str)->len+3; mesg = rb_str_new(0, len); snprintf(RSTRING(mesg)->ptr, len+1, "%s - %.*s", err, (int)RSTRING(str)->len, RSTRING(str)->ptr); rb_str_resize(mesg, strlen(RSTRING(mesg)->ptr)); } else { mesg = rb_str_new2(err); } rb_call_super(1, &mesg); rb_iv_set(self, "errno", error); return self; }
/** * call-seq: * index.get_id_by_uri(id) * * Returns just the id of the document with the given uri. */ VALUE Index_get_id_by_uri(VALUE self, VALUE uri) { ODEUM *odeum = NULL; DATA_GET(self, ODEUM, odeum); REQUIRE_TYPE(uri, T_STRING); int res = odgetidbyuri(odeum, RSTRING(uri)->ptr); return INT2FIX(res); }
/** * call-seq: * Odeum::normalizeword(asis) -> normal * * Given a word from breaktext (which is considered "as-is") * it will "normalize" it in a consistent way which is suitable * for searching. The normalization effectively strips puntuation * and spacing, and then lowercases the word. If there is nothing * but "removed" chars in the asis string then the return is empty. * Check for this so you don't try to search for nothing. */ VALUE Odeum_normalizeword(VALUE self, VALUE asis) { REQUIRE_TYPE(asis, T_STRING); char *result = odnormalizeword(RSTRING(asis)->ptr); VALUE res_str = rb_str_new2(result); free(result); return res_str; }
static VALUE ossl_cipher_final(VALUE self) { EVP_CIPHER_CTX *ctx; int out_len; VALUE str; GetCipher(self, ctx); str = rb_str_new(0, EVP_CIPHER_CTX_block_size(ctx)); if (!EVP_CipherFinal_ex(ctx, RSTRING(str)->ptr, &out_len)) ossl_raise(eCipherError, NULL); assert(out_len <= RSTRING(str)->len); RSTRING(str)->len = out_len; RSTRING(str)->ptr[out_len] = 0; return str; }
/** * call-seq: * Odeum::breaktext(test) -> [word1, word2, word3] * * Breaks a string into an array of words that are separated by * space characters and such delimiters as period, comma, etc. * You should also check out StringScanner as a more flexible * alternative. This function must do a lot of data copying and * other things in order to convert from Odeum internal types to Ruby * types. */ VALUE Odeum_breaktext(VALUE self, VALUE text) { REQUIRE_TYPE(text, T_STRING); CBLIST *result = odbreaktext(RSTRING(text)->ptr); VALUE list = CBLIST_2_array(result); cblistclose(result); return list; }
// // ShMemutex::read(timeout=-1) // VALUE rb_ShMemutex_read(int argc,VALUE *argv,VALUE self) { VALUE timeout,buf; ShMemutex *ptr; long to=-1,len; if(rb_scan_args(argc,argv,"01",&timeout)==1) to=NUM2LONG(timeout); Data_Get_Struct(self,ShMemutex,ptr); len=ptr->size(); buf=rb_str_new(NULL,len); ptr->read(RSTRING(buf)->ptr,RSTRING(buf)->len,to); return buf; }
/** * call-seq: * Document.new uri -> Document * * The uri should be specified if you're calling this. Internally the * Ruby/Odeum library kind of "cheats" and passes a Qnil for the uri * so that the ODDOC can be assigned externally. You should not * (and probably cannot) do this from Ruby. */ VALUE Document_initialize(VALUE self, VALUE uri) { if(!NIL_P(uri)) { REQUIRE_TYPE(uri, T_STRING); DATA_PTR(self) = oddocopen(RSTRING(uri)->ptr); } return self; }
static VALUE OpenVX_load(VALUE self, VALUE name) { vx_status status = VX_FAILURE; Check_Type(name, T_STRING); status = vxLoadModule(context, RSTRING(name)->ptr); REXT_PRINT("status = %d\n", status); return Qnil; }
/** * call-seq: * index.search_doc_count(word) -> Fixnum * * Returns the number of documents matching the given word. If the word * does not match anything then it returns -1. */ VALUE Index_search_doc_count(VALUE self, VALUE word) { ODEUM *odeum = NULL; DATA_GET(self, ODEUM, odeum); REQUIRE_TYPE(word, T_STRING); int res = odsearchdnum(odeum, RSTRING(word)->ptr); return INT2FIX(res); }
static enum evhook_status script_hook_goto_url(va_list ap, void *data) { unsigned char **url = va_arg(ap, unsigned char **); struct session *ses = va_arg(ap, struct session *); int error; VALUE args[2]; VALUE result; if (*url == NULL) return EVENT_HOOK_STATUS_NEXT; args[0] = rb_str_new(*url, strlen((const char *)*url)); if (!ses || !have_location(ses)) { args[1] = Qnil; } else { args[1] = rb_str_new(struri(cur_loc(ses)->vs.uri), strlen((const char *)struri(cur_loc(ses)->vs.uri))); } result = erb_protected_method_call("goto_url_hook", 2, args, &error); if (error) { erb_report_error(ses, error); return EVENT_HOOK_STATUS_NEXT; } switch (rb_type(result)) { case T_STRING: { unsigned char *new_url; new_url = memacpy(RSTRING(result)->ptr, RSTRING(result)->len); if (new_url) { mem_free_set(url, new_url); } break; } case T_NIL: break; default: alert_ruby_error(ses, "goto_url_hook must return a string or nil"); } return EVENT_HOOK_STATUS_NEXT; }