static VALUE _create_request_hash(struct conn *c, RouteRef route, const char* body, int bodylen) { const char *method, *uri, *query; VALUE hash_headers; struct parsed_header* h; int i; VALUE hash = createHash(); addStrToHash(hash, "application", route->_application, strlen(route->_application)); addStrToHash(hash, "model", route->_model, strlen(route->_model)); if (route->_action!=NULL) { const char* actionName = route->_action; addStrToHash(hash, "action", actionName, strlen(actionName)); } if (route->_id!=NULL) { const char* _id = route->_id; addStrToHash(hash, "id", _id, strlen(_id)); } method = _shttpd_known_http_methods[c->method].ptr; addStrToHash(hash, "request-method", method, strlen(method)); uri = c->uri; addStrToHash(hash, "request-uri", uri, strlen(uri)); query = c->query == NULL ? "" : c->query; addStrToHash(hash, "request-query", query, strlen(query)); hash_headers = createHash(); h = &c->ch.cl; for (i = 0; i < sizeof(struct headers)/sizeof(struct parsed_header); i++) { if (h->_name) { char* name = trim(_shttpd_strdup(h->_name)); if (h->_type == HDR_STRING) { addStrToHash(hash_headers,name,h->_v.v_vec.ptr,h->_v.v_vec.len); } else if (h->_type == HDR_INT) { addIntToHash(hash_headers, name, h->_v.v_big_int); } else if (h->_type == HDR_DATE) { addTimeToHash(hash_headers, name, h->_v.v_time); } free(name); } h++; } addHashToHash(hash,"headers",hash_headers); if (bodylen > 0) { addStrToHash(hash, "request-body", body, bodylen); } return hash; }
static VALUE _CreateRequestHash(HttpContextRef context, RouteRef route) { DBG(("Creating Req Hash\n")); VALUE hash = createHash(); const char* applicationName = route->_application; addStrToHash(hash, "application", applicationName, strlen(applicationName)); const char* modelName = route->_model; addStrToHash(hash, "model", modelName, strlen(modelName)); if (route->_action!=NULL) { const char* actionName = route->_action; addStrToHash(hash, "action", actionName, strlen(actionName)); } if (route->_id!=NULL) { const char* _id = route->_id; addStrToHash(hash, "id", _id, strlen(_id)); } const char* method = HTTPGetMethod(context->_request->_method); addStrToHash(hash, "request-method", method, strlen(method)); const char* uri = context->_request->_uri; addStrToHash(hash, "request-uri", uri, strlen(uri)); const char* query = context->_request->_query == NULL ? "" : context->_request->_query; addStrToHash(hash, "request-query", query, strlen(query)); VALUE hash_headers = createHash(); struct parsed_header* h = &context->_request->_cheaders.cl; for (int i = 0; i < sizeof(struct headers)/sizeof(struct parsed_header); i++) { if (h->_name) { char* name = trim(strdup(h->_name)); if (h->_type == HDR_STRING) { addStrToHash(hash_headers,name,h->_v.v_vec.ptr,h->_v.v_vec.len); } else if (h->_type == HDR_INT) { addIntToHash(hash_headers, name, h->_v.v_big_int); } else if (h->_type == HDR_DATE) { addTimeToHash(hash_headers, name, h->_v.v_time); } free(name); } h++; } addHashToHash(hash,"headers",hash_headers); int buflen = CFDataGetLength(context->_rcvdBytes); if (buflen > 0) { addStrToHash(hash, "request-body", (char*)CFDataGetBytePtr(context->_rcvdBytes), buflen); } return hash; }
static VALUE createHashFromContact(jobject contactObj) { if (logging_enable) RAWLOG_INFO("createHashFromContact() START"); JNIEnv *env = jnienv(); jclass contactCls = getJNIClass(RHODES_JAVA_CLASS_CONTACT); if (!contactCls) return Qnil; jclass fieldCls = getJNIClass(RHODES_JAVA_CLASS_CONTACT_FIELD); if (!fieldCls) return Qnil; jmethodID contactGetFieldMID = getJNIClassMethod(env, contactCls, "getField", "(I)Ljava/lang/String;"); if (!contactGetFieldMID) return Qnil; CHoldRubyValue contactHash(rho_ruby_createHash()); // contact.moveToBegin(); int i; for (i = 0; i < PB_FIELDS_COUNT; i++) { jstring value = (jstring)env->CallObjectMethod(contactObj, contactGetFieldMID, i); if (value != NULL) { addStrToHash(contactHash, field_names[i], rho_cast<std::string>(value).c_str()); } env->DeleteLocalRef(value); } if (logging_enable) RAWLOG_INFO("createHashFromContact() FINISH"); return contactHash; }
VALUE convertJavaMapToRubyHash(jobject objMap) { jclass clsMap = getJNIClass(RHODES_JAVA_CLASS_MAP); if (!clsMap) return Qnil; jclass clsSet = getJNIClass(RHODES_JAVA_CLASS_SET); if (!clsSet) return Qnil; jclass clsIterator = getJNIClass(RHODES_JAVA_CLASS_ITERATOR); if (!clsIterator) return Qnil; JNIEnv *env = jnienv(); jmethodID midGet = getJNIClassMethod(env, clsMap, "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); if (!midGet) return Qnil; jmethodID midKeySet = getJNIClassMethod(env, clsMap, "keySet", "()Ljava/util/Set;"); if (!midKeySet) return Qnil; jmethodID midIterator = getJNIClassMethod(env, clsSet, "iterator", "()Ljava/util/Iterator;"); if (!midIterator) return Qnil; jmethodID midHasNext = getJNIClassMethod(env, clsIterator, "hasNext", "()Z"); if (!midHasNext) return Qnil; jmethodID midNext = getJNIClassMethod(env, clsIterator, "next", "()Ljava/lang/Object;"); if (!midNext) return Qnil; jobject objSet = env->CallObjectMethod(objMap, midKeySet); if (!objSet) return Qnil; jobject objIterator = env->CallObjectMethod(objSet, midIterator); if (!objIterator) return Qnil; VALUE retval = createHash(); while(env->CallBooleanMethod(objIterator, midHasNext)) { jstring objKey = (jstring)env->CallObjectMethod(objIterator, midNext); if (!objKey) return Qnil; jstring objValue = (jstring)env->CallObjectMethod(objMap, midGet, objKey); if (!objValue) return Qnil; std::string const &strKey = rho_cast<std::string>(objKey); std::string const &strValue = rho_cast<std::string>(objValue); addStrToHash(retval, strKey.c_str(), strValue.c_str()); env->DeleteLocalRef(objKey); env->DeleteLocalRef(objValue); } return retval; }
VALUE rho_ringtone_manager_get_all() { LOG(INFO) + __FUNCTION__; CHoldRubyValue retval(rho_ruby_createHash()); #if _WIN32_WCE > 0x501 Hashtable<String, String> ringtones; CRingtoneManager::getCRingtoneManager().getAllRingtones(ringtones); for (Hashtable<String, String>::iterator itr = ringtones.begin(); itr != ringtones.end(); ++itr) { addStrToHash( retval, itr->first.c_str(), itr->second.c_str() ); } #endif return retval; }
VALUE rho_cast_helper<VALUE, jobject>::convertJavaMapToRubyHash(JNIEnv *env, jobject objMap) { jhobject objSet = env->CallObjectMethod(objMap, midMapKeySet); if (!objSet) return Qnil; jhobject objIterator = env->CallObjectMethod(objSet.get(), midSetIterator); if (!objIterator) return Qnil; CHoldRubyValue retval(rho_ruby_createHash()); while(env->CallBooleanMethod(objIterator.get(), midIteratorHasNext)) { jhstring objKey = (jstring)env->CallObjectMethod(objIterator.get(), midIteratorNext); if (!objKey) return Qnil; jhstring objValue = (jstring)env->CallObjectMethod(objMap, midMapGet, objKey.get()); if (!objValue) return Qnil; std::string const &strKey = rho_cast<std::string>(objKey); std::string const &strValue = rho_cast<std::string>(objValue); addStrToHash(retval, strKey.c_str(), strValue.c_str()); } return retval; }
void _addRecordValue(const char* key, const char* value, void* hash) { addStrToHash(*((unsigned long*)hash), key, value); }
RHO_GLOBAL VALUE getallPhonebookRecords(void* pb) { if (logging_enable) RAWLOG_INFO("getallPhonebookRecords() START"); jobject phonebookObj = (jobject)pb; JNIEnv *env = jnienv(); jclass phonebookCls = getJNIClass(RHODES_JAVA_CLASS_PHONEBOOK); if (!phonebookCls) return Qnil; jclass contactCls = getJNIClass(RHODES_JAVA_CLASS_CONTACT); if (!contactCls) return Qnil; jmethodID phonebookPrepareFullListMID = getJNIClassMethod(env, phonebookCls, "prepareFullList", "()V"); if (!phonebookPrepareFullListMID) return Qnil; jmethodID phonebookMoveToBeginMID = getJNIClassMethod(env, phonebookCls, "moveToBegin", "()V"); if (!phonebookMoveToBeginMID) return Qnil; jmethodID hasNextMID = getJNIClassMethod(env, phonebookCls, "hasNext", "()Z"); if (!hasNextMID) return Qnil; jmethodID nextMID = getJNIClassMethod(env, phonebookCls, "next", "()Ljava/lang/Object;"); if (!nextMID) return Qnil; jmethodID contactIdMID = getJNIClassMethod(env, contactCls, "id", "()Ljava/lang/String;"); if (!contactIdMID) return Qnil; jmethodID contactGetFieldMID = getJNIClassMethod(env, contactCls, "getField", "(I)Ljava/lang/String;"); if (!contactGetFieldMID) return Qnil; env->CallVoidMethod(phonebookObj, phonebookPrepareFullListMID); // pb.moveToBegin(); env->CallVoidMethod(phonebookObj, phonebookMoveToBeginMID); VALUE valGc = rho_ruby_disable_gc(); CHoldRubyValue hash(rho_ruby_createHash()); // while(pb.hasNext()) while(env->CallBooleanMethod(phonebookObj, hasNextMID)) { // Contact contact = (Contact)pb.next(); jobject contactObj = env->CallObjectMethod(phonebookObj, nextMID); if (!contactObj) return Qnil; // String id = contact.id(); jstring idObj = (jstring)env->CallObjectMethod(contactObj, contactIdMID); if (!idObj) return Qnil; //addHashToHash(hash, rho_cast<std::string>(idObj).c_str(), createHashFromContact(contactObj)); CHoldRubyValue contactHash(rho_ruby_createHash()); // contact.moveToBegin(); int i; for (i = 0; i < PB_FIELDS_COUNT; i++) { jstring value = (jstring)env->CallObjectMethod(contactObj, contactGetFieldMID, i); if (value != NULL) { addStrToHash(contactHash, field_names[i], rho_cast<std::string>(value).c_str()); env->DeleteLocalRef(value); } } addHashToHash(hash, rho_cast<std::string>(idObj).c_str(), contactHash); env->DeleteLocalRef(idObj); env->DeleteLocalRef(contactObj); } rho_ruby_enable_gc(valGc); if (logging_enable) RAWLOG_INFO("getallPhonebookRecords() FINISH"); return hash; }