/** * call-seq: * uc.resolve("/someuri") -> "/someuri", "", handler * uc.resolve("/someuri/pathinfo") -> "/someuri", "/pathinfo", handler * uc.resolve("/notfound/orhere") -> nil, nil, nil * * 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. * * It expects strings. Don't try other string-line 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; unsigned char *script_name_str = NULL; DATA_GET(self, struct tst, tst); uri_str = (unsigned char *)StringValueCStr(uri); handler = tst_search(uri_str, tst, &pref_len); // setup for multiple return values result = rb_ary_new(); if(handler) { rb_ary_push(result, rb_str_substr (uri, 0, pref_len)); rb_ary_push(result, rb_str_substr(uri, pref_len, RSTRING(uri)->len)); rb_ary_push(result, (VALUE)handler); } else { // not found so push back nothing rb_ary_push(result, Qnil); rb_ary_push(result, Qnil); rb_ary_push(result, Qnil); } return result; }