SEXP mongo_get_databases(SEXP mongo_conn) { mongo* conn = _checkMongo(mongo_conn); bson out; if (mongo_simple_int_command(conn, "admin", "listDatabases", 1, &out) != MONGO_OK) { bson_destroy(&out); return R_NilValue; } bson_iterator it, databases, database; bson_iterator_init(&it, &out); bson_iterator_next(&it); bson_iterator_subiterator(&it, &databases); int count = 0; while (bson_iterator_next(&databases)) { bson_iterator_subiterator(&databases, &database); bson_iterator_next(&database); const char* name = bson_iterator_string(&database); if (strcmp(name, "admin") != 0 && strcmp(name, "local") != 0) count++; } SEXP ret; PROTECT(ret = allocVector(STRSXP, count)); bson_iterator_subiterator(&it, &databases); int i = 0; while (bson_iterator_next(&databases)) { bson_iterator_subiterator(&databases, &database); bson_iterator_next(&database); const char* name = bson_iterator_string(&database); if (strcmp(name, "admin") != 0 && strcmp(name, "local") != 0) SET_STRING_ELT(ret, i++, mkChar(name)); } bson_destroy(&out); UNPROTECT(1); return ret; }
int read_inode(const bson * doc, struct inode * out) { bson_iterator i, sub; bson_type bt; const char * key; bson_iterator_init(&i, doc); while((bt = bson_iterator_next(&i)) > 0) { key = bson_iterator_key(&i); if(strcmp(key, "_id") == 0) memcpy(&out->oid, bson_iterator_oid(&i), sizeof(bson_oid_t)); else if(strcmp(key, "mode") == 0) out->mode = bson_iterator_int(&i); else if(strcmp(key, "owner") == 0) out->owner = bson_iterator_long(&i); else if(strcmp(key, "group") == 0) out->group = bson_iterator_long(&i); else if(strcmp(key, "size") == 0) out->size = bson_iterator_long(&i); else if(strcmp(key, "created") == 0) out->created = bson_iterator_time_t(&i); else if(strcmp(key, "modified") == 0) out->modified = bson_iterator_time_t(&i); else if(strcmp(key, "data") == 0) { out->datalen = bson_iterator_string_len(&i); out->data = malloc(out->datalen + 1); strcpy(out->data, bson_iterator_string(&i)); } else if(strcmp(key, "dirents") == 0) { while(out->dirents) { struct dirent * next = out->dirents->next; free(out->dirents); out->dirents = next; } bson_iterator_subiterator(&i, &sub); while((bt = bson_iterator_next(&sub)) > 0) { int len = bson_iterator_string_len(&sub); struct dirent * cde = malloc(sizeof(struct dirent) + len); if(!cde) return -ENOMEM; strcpy(cde->path, bson_iterator_string(&sub)); cde->len = bson_iterator_string_len(&sub); cde->next = out->dirents; out->dirents = cde; out->direntcount++; } } } return 0; }
void testCheckDuplicates2(void) { bson b, b2; bson_iterator it, sit; bson_type bt; bson_init(&b); bson_append_start_array(&b, "array"); bson_append_int(&b, "0", 1); bson_append_finish_array(&b); bson_append_start_array(&b, "array"); bson_append_int(&b, "0", 3); bson_append_int(&b, "1", 4); bson_append_finish_array(&b); bson_finish(&b); CU_ASSERT_FALSE_FATAL(b.err); CU_ASSERT_TRUE_FATAL(bson_check_duplicate_keys(&b)); bson_init(&b2); bson_fix_duplicate_keys(&b, &b2); bson_finish(&b2); CU_ASSERT_FALSE_FATAL(b2.err); CU_ASSERT_FALSE_FATAL(bson_check_duplicate_keys(&b2)); BSON_ITERATOR_INIT(&it, &b2); bt = bson_iterator_next(&it); CU_ASSERT_EQUAL_FATAL(bt, BSON_ARRAY); CU_ASSERT_STRING_EQUAL_FATAL(BSON_ITERATOR_KEY(&it), "array"); BSON_ITERATOR_SUBITERATOR(&it, &sit); bt = bson_iterator_next(&sit); CU_ASSERT_STRING_EQUAL_FATAL(BSON_ITERATOR_KEY(&sit), "0"); CU_ASSERT_TRUE_FATAL(BSON_IS_NUM_TYPE(bt)); CU_ASSERT_EQUAL_FATAL(bson_iterator_int(&sit), 1); bt = bson_iterator_next(&sit); CU_ASSERT_STRING_EQUAL_FATAL(BSON_ITERATOR_KEY(&sit), "1"); CU_ASSERT_TRUE_FATAL(BSON_IS_NUM_TYPE(bt)); CU_ASSERT_EQUAL_FATAL(bson_iterator_int(&sit), 3); bt = bson_iterator_next(&sit); CU_ASSERT_STRING_EQUAL_FATAL(BSON_ITERATOR_KEY(&sit), "2"); CU_ASSERT_TRUE_FATAL(BSON_IS_NUM_TYPE(bt)); CU_ASSERT_EQUAL_FATAL(bson_iterator_int(&sit), 4); bt = bson_iterator_next(&sit); CU_ASSERT_EQUAL_FATAL(bt, BSON_EOO); bson_destroy(&b2); bson_destroy(&b); }
int _iterator_getComplex(bson_iterator* iter, struct Rcomplex* z) { bson_iterator sub; if (bson_iterator_type(iter) != BSON_OBJECT) return 0; bson_iterator_subiterator(iter, &sub); if (bson_iterator_next(&sub) != BSON_DOUBLE || strcmp(bson_iterator_key(&sub), "r") != 0) return 0; z->r = bson_iterator_double(&sub); if (bson_iterator_next(&sub) != BSON_DOUBLE || strcmp(bson_iterator_key(&sub), "i") != 0) return 0; z->i = bson_iterator_double(&sub); if (bson_iterator_next(&sub) != BSON_EOO) return 0; return 1; }
int ComputeOperator(BSONElem* val,BSONElem* query){ bson_iterator q,o; bson_type qType,tType; bson_iterator_from_buffer(&q, query->value); bson_iterator_from_buffer(&o, val->value); bson qBson,oBson; bson_init_finished_data(&qBson,(char*)query->value); bson_init_finished_data(&oBson,(char*)val->value); while((qType = bson_iterator_next(&q))) { const char* key = bson_iterator_key(&q); BSONElem qVal; BSONElemInitFromItr(&qVal,&q); int cVal = 0,r; uint8_t cont = False; int error; QueryOpDesc* desc = HTFind(opTable,key,strlen(key)+1); if (desc) { cont = desc->fn(val,&qVal,&error); if (!cont) { return False; } } else { // no such operator return False; } } //printf("Returning true\n"); return True; }
void bson_print_raw( const char * data , int depth ){ bson_iterator i; const char * key; int temp; char oidhex[25]; bson_iterator_init( &i , data ); while ( bson_iterator_next( &i ) ){ bson_type t = bson_iterator_type( &i ); if ( t == 0 ) break; key = bson_iterator_key( &i ); for ( temp=0; temp<=depth; temp++ ) printf( "\t" ); printf( "%s : %d \t " , key , t ); switch ( t ){ case bson_int: printf( "%d" , bson_iterator_int( &i ) ); break; case bson_double: printf( "%f" , bson_iterator_double( &i ) ); break; case bson_bool: printf( "%s" , bson_iterator_bool( &i ) ? "true" : "false" ); break; case bson_string: printf( "%s" , bson_iterator_string( &i ) ); break; case bson_null: printf( "null" ); break; case bson_oid: bson_oid_to_string(bson_iterator_oid(&i), oidhex); printf( "%s" , oidhex ); break; case bson_object: case bson_array: printf( "\n" ); bson_print_raw( bson_iterator_value( &i ) , depth + 1 ); break; default: fprintf( stderr , "can't print type : %d\n" , t ); } printf( "\n" ); } }
int MCPContentPersonAward::set_basic_info_from_bson_result(bson* bson_out, const char* aggregate_name) { LOGD("[GWJ] %s: start", __FUNCTION__); const char* key; bson_iterator it[1]; stringstream ss; MCPContentPersonAwardRecord* detail = ObjectPoolFactory<MCPContentPersonAwardRecord>::instance().fetch_object(); bson_iterator_init(it, bson_out); while(bson_iterator_next(it)) { ss.clear(); key = bson_iterator_key(it); if(0 == strcmp(key, "priority")) { detail->priority = bson_iterator_string(it); LOGG("[GWJ] %s: set MCPContentPersonAwardRecord.priority[%s]", __FUNCTION__, detail->priority.c_str()); } else if(0 == strcmp(key, "kudou")) { detail->kudou = bson_iterator_int(it); LOGG("[GWJ] %s: set MCPContentPersonAwardRecord.kudou[%d]", __FUNCTION__, detail->kudou; } else if(0 == strcmp(key, "commodity_id"))
uint8_t XTDBRemoveFromIndex(XTDBHandle* handle,BinaryStr* key,BinaryStr* data) { bson_oid_t oid; bson_iterator q; bson_type qType; uint8_t ret = True; _S_FN(indexRemove); bson_iterator_from_buffer(&q, data->data); while((qType = bson_iterator_next(&q))) { const char* keyVal = bson_iterator_key(&q); //printf("%s\n",keyVal); DataBaseBE* db; BSONElem qVal; BSONElemInitFromItr(&qVal,&q); db = XTDBGetIndex(handle,keyVal); if (db) { bson outBson; BinaryStr out; ConvertToBStr(&qVal,&outBson); BsonToBStr(&outBson,&out); ret = DBDeleteKeyVal(db,&out,key); if (!ret) { handle->error = XTDB_NO_ENTRY; bson_destroy(&outBson); break; } bson_destroy(&outBson); } } _E_FN(indexRemove); return ret; //return DBSet(handle->mainDB,&key,&val,False); }
void find_in_array(bson_iterator *it, char *key_ref, char *value_ref, char *key_needed, char *value_needed) { char value_ref_found[MONGO_STRING_LENGTH]; char value_needed_found[MONGO_STRING_LENGTH]; bson_iterator i; while(bson_iterator_next(it)) { switch(bson_iterator_type(it)){ case bson_string: if (strcmp(bson_iterator_key(it), key_ref) == 0) strcpy(value_ref_found, bson_iterator_string(it)); if (strcmp(bson_iterator_key(it), key_needed) == 0) strcpy(value_needed_found, bson_iterator_string(it)); break; case bson_object: case bson_array: bson_iterator_init(&i, bson_iterator_value(it)); find_in_array(&i, key_ref, value_ref, key_needed, value_needed); break; default: break; } } if (strcmp(value_ref_found, value_ref) == 0) strcpy(value_needed, value_needed_found); }
int main(int argc, char *argv[]) { const char * test_server = (argc > 1 ? argv[1] : TEST_SERVER); bson_iterator it[1], it2[1]; bson b[1]; bson sub[1]; bson copy[1]; bson_type type; bson_init( b ); bson_append_string( b, "foo", "hello" ); { bson_append_start_object( b, "o" ); bson_append_string( b, "bar", "goodbye" ); bson_append_finish_object( b ); } bson_iterator_init( it, b ); bson_iterator_next( it ); type = bson_iterator_next( it ); ASSERT( BSON_OBJECT == type ); bson_iterator_subobject_init( it, sub, 0 ); ASSERT( sub->finished == 1 ); bson_iterator_init( it2, sub ); type = bson_iterator_next( it2 ); ASSERT( BSON_STRING == type ); type = bson_iterator_next( it2 ); ASSERT( BSON_EOO == type ); bson_copy( copy, sub ); ASSERT( 1 == copy->finished ); ASSERT( 0 == copy->stackPos ); ASSERT( 0 == copy->err ); bson_destroy( copy ); bson_destroy( b ); return 0; }
bson_type bson_find( bson_iterator *it, const bson *obj, const char *name ) { bson_iterator_init( it, (bson *)obj ); while( bson_iterator_next( it ) ) { if ( strcmp( name, bson_iterator_key( it ) ) == 0 ) break; } return bson_iterator_type( it ); }
void MongodbClient::ReadData(KeyedArchive* archive, void* bsonObj) { if((!archive) || (!bsonObj)) return; bson_iterator it; bson_iterator_init(&it, (bson*)bsonObj); while (bson_iterator_next(&it)) { String key = String(bson_iterator_key(&it)); bson_type type = bson_iterator_type(&it); if(key == "_id") continue; // ignore _id switch (type) { case BSON_STRING: archive->SetString(key, String(bson_iterator_string(&it))); break; case BSON_INT: archive->SetInt32(key, bson_iterator_int(&it)); break; case BSON_LONG: archive->SetInt32(key, (int32)bson_iterator_long(&it)); break; case BSON_DOUBLE: archive->SetFloat(key, (float32)bson_iterator_double(&it)); break; case BSON_OBJECT: { bson sub; bson_iterator_subobject(&it, &sub); KeyedArchive* subArchive = new KeyedArchive(); ReadData(subArchive, &sub); archive->SetArchive(key, subArchive); SafeRelease(subArchive); break; } case BSON_OID: //TODO: add 12-bytes array //bson_append_oid(object, key, bson_iterator_oid(&it)); break; default: DVASSERT(false); Logger::Error("[MongodbUpdateObject::ReadData] Not implemented type: %d", type); break; } } }
void lua_push_bson_array(lua_State *L, bson_iterator *it) { bson_type bt; lua_push_bsontype_table(L, BSON_ARRAY); int i; for (i = 1; (bt = bson_iterator_next(it)) != BSON_EOO; ++i) { lua_push_bson_value(L, it); lua_rawseti(L, -2, i); } }
INLINE int sizeof_bson P1(const char *, data){ int size = 0; bson_iterator i; bson_iterator_from_buffer( &i, data ); while(bson_iterator_next( &i )){ size++; } return size; }
void lua_push_bson_table(lua_State *L, bson_iterator *it) { bson_type bt; lua_push_bsontype_table(L, BSON_OBJECT); while ((bt = bson_iterator_next(it)) != BSON_EOO) { lua_pushstring(L, bson_iterator_key(it)); lua_push_bson_value(L, it); lua_rawset(L, -3); } }
MONGO_EXPORT bson_type bson_find( bson_iterator *it, const bson *obj, const char *name ) { check_mongo_object( (void*)obj ); check_mongo_object( it ); bson_iterator_init( it, (bson *)obj ); while( bson_iterator_next( it ) ) { if ( strcmp( name, bson_iterator_key( it ) ) == 0 ) break; } return bson_iterator_type( it ); }
static void bson_decode_tree(lua_State* L, bson_iterator* b,int set_t){ const char *key; while(bson_iterator_next(b)) { bson_type t = bson_iterator_type(b); if(t == 0) { lua_pushnil(L); break; } key = bson_iterator_key(b); if(set_t) { lua_pushstring(L,key); } LOG_MSG("type %d,key %s",t,key); switch(t) { case BSON_DOUBLE: lua_pushnumber(L,bson_iterator_double(b)); break; case BSON_STRING: lua_pushstring(L,bson_iterator_string(b)); break; case BSON_BOOL: lua_pushboolean(L,bson_iterator_bool( b ) ? true : false ); break; case BSON_NULL: lua_pushnil(L); break; case BSON_INT: lua_pushinteger(L,bson_iterator_int(b)); break; case BSON_OBJECT: bson_iterator t; bson_iterator_subiterator(b,&t); bson_decode_tree(L,&t); lua_settable(L,-3); break; case BSON_ARRAY: lua_newtable(L); bson_iterator s; bson_iterator_subiterator(b,&s); bson_decode_tree(L,&s,1); break; default: break; } if(set_t) { lua_settable(L,-3); } } }
//------------------------------------------------------------------------------ int main( int argc, char * argv[] ){ mongo conn; if( mongo_client( &conn , TEST_SERVER, TEST_PORT ) != MONGO_OK ) { std::cout << "failed to connect\n"; return EXIT_FAILURE; } mongo_cursor cursor; mongo_cursor_init( &cursor, &conn, "test.test" ); char hex_oid[25]; while( mongo_cursor_next( &cursor ) == MONGO_OK ) { std::cout << "row:\n"; bson_iterator it; bson_iterator_init( &it, mongo_cursor_bson( &cursor ) ); while( bson_iterator_next( &it ) ) { std::cout << " " << bson_iterator_key( &it ) << " = "; switch( bson_iterator_type( &it ) ) { case BSON_DOUBLE: std::cout << "(double) " << bson_iterator_double( &it ) << std::endl; break; case BSON_INT: std::cout << "(int) " << bson_iterator_int( &it ) << std::endl; break; case BSON_STRING: std::cout << "(string) \"" << bson_iterator_string( &it ) << "\"\n"; break; case BSON_OID: bson_oid_to_string( bson_iterator_oid( &it ), hex_oid ); std::cout << "(oid) \"" << hex_oid << "\"\n"; break; case BSON_OBJECT: std::cout << "(subobject) {...}\n"; break; case BSON_ARRAY: std::cout << "(array) [...]\n"; break; case BSON_TIMESTAMP: std::cout << "(timestamp) [...]\n"; break; default: std::cout << "(type " << bson_iterator_type( &it ) << std::endl; break; } } std::cout << std::endl; } mongo_disconnect( &conn ); return EXIT_SUCCESS; }
int test_bson_iterator( void ) { bson b[1]; bson_iterator i[1]; bson_iterator_init( i, bson_empty( b ) ); bson_iterator_next( i ); bson_iterator_type( i ); bson_find( i, bson_empty( b ), "foo" ); return 0; }
void MongodbObject::EnableForEdit() { bson *newObject = new bson(); bson_init(newObject); bson_iterator it; bson_iterator_init(&it, objectData->object); while (bson_iterator_next(&it)) { const char * key = bson_iterator_key(&it); bson_type type = bson_iterator_type(&it); switch (type) { case BSON_STRING: bson_append_string(newObject, key, bson_iterator_string(&it)); break; case BSON_INT: bson_append_int(newObject, key, bson_iterator_int(&it)); break; case BSON_LONG: bson_append_long(newObject, key, bson_iterator_long(&it)); break; case BSON_DOUBLE: bson_append_double(newObject, key, bson_iterator_double(&it)); break; case BSON_OBJECT: bson sub; bson_iterator_subobject(&it, &sub); bson_append_bson(newObject, key, &sub); break; case BSON_OID: bson_append_oid(newObject, key, bson_iterator_oid(&it)); break; default: break; } } bson_destroy(objectData->object); SafeDelete(objectData->object); objectData->object = newObject; }
void json_from_bson_array(yajl_gen *g, bson_iterator *it) { yajl_gen_array_open( *g ); while( bson_iterator_next( it ) ) { bson_type t = bson_iterator_type( it ); json_from_bson_type( t, g, it ); } yajl_gen_array_close( *g ); }
v8::Local<v8::Object> decodeObject(bson_iterator *it, bool bArray) { v8::Local<v8::Object> obj; if (bArray) obj = v8::Array::New(isolate); else obj = v8::Object::New(isolate); while (bson_iterator_next(it)) decodeValue(obj, it); return obj; }
INT32 bson2csv( CHAR delChar, CHAR delField, CHAR *pbson, CHAR **ppBuffer, INT32 *pCSVSize, BOOLEAN includeBinary, BOOLEAN includeRegex ) { INT32 rc = SDB_OK ; BOOLEAN isFirst = TRUE ; bson_type fieldType ; bson_iterator it ; bson_iterator_from_buffer( &it, pbson ) ; while ( bson_iterator_next( &it ) ) { fieldType = bson_iterator_type( &it ) ; if ( BSON_EOO == fieldType ) { break ; } if ( isFirst ) { isFirst = FALSE ; } else { rc = _appendString( delChar, &delField, 1, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } if ( BSON_UNDEFINED == fieldType ) { continue ; } rc = _appendValue( delChar, &it, ppBuffer, pCSVSize, includeBinary, includeRegex ) ; if ( rc ) { goto error ; } } done: return rc ; error: goto done ; }
void InitWith(bson *obj) { bson_iterator it; bson_iterator_init(&it, obj); while (bson_iterator_next(&it)) { const char * key = bson_iterator_key(&it); bson_type type = bson_iterator_type(&it); switch (type) { case BSON_STRING: bson_append_string(object, key, bson_iterator_string(&it)); break; case BSON_INT: bson_append_int(object, key, bson_iterator_int(&it)); break; case BSON_LONG: bson_append_long(object, key, bson_iterator_long(&it)); break; case BSON_DOUBLE: bson_append_double(object, key, bson_iterator_double(&it)); break; case BSON_OBJECT: { bson sub; bson_iterator_subobject(&it, &sub); bson_append_bson(object, key, &sub); break; } case BSON_OID: bson_append_oid(object, key, bson_iterator_oid(&it)); break; default: DVASSERT(false); Logger::Error("[MongodbObjectInternalData::InitWith] Not implemented type: %d", type); break; } } }
size_t bson_keypars_count( const bson *a ) { assert( a ); size_t i; bson_iterator *a_it; a_it = malloc( sizeof( bson_iterator ) ); bson_iterator_init( a_it, a ); for( i = 0; bson_iterator_next( a_it ); i++ ); free( a_it ); return i; }
void testSaveLoad() { CU_ASSERT_PTR_NOT_NULL_FATAL(jb); bson_oid_t oid; EJCOLL *ccoll = ejdbcreatecoll(jb, "contacts", NULL); CU_ASSERT_PTR_NOT_NULL(ccoll); //Save record bson a1; bson_init(&a1); bson_append_string(&a1, "name", "Петров Петр"); bson_append_string(&a1, "phone", "333-222-333"); bson_append_int(&a1, "age", 33); bson_append_long(&a1, "longage", 0xFFFFFFFFFF01LL); bson_append_double(&a1, "doubleage", 0.333333); bson_finish(&a1); ejdbsavebson(ccoll, &a1, &oid); bson_destroy(&a1); bson *lbson = ejdbloadbson(ccoll, &oid); CU_ASSERT_PTR_NOT_NULL(lbson); bson_iterator it1; bson_iterator_init(&it1, lbson); int btype = bson_iterator_next(&it1); CU_ASSERT(btype == BSON_OID); btype = bson_iterator_next(&it1); CU_ASSERT(btype == BSON_STRING); CU_ASSERT(!strcmp("name", bson_iterator_key(&it1))); CU_ASSERT(!strcmp("Петров Петр", bson_iterator_string(&it1))); btype = bson_iterator_next(&it1); CU_ASSERT(btype == BSON_STRING); CU_ASSERT(!strcmp("phone", bson_iterator_key(&it1))); CU_ASSERT(!strcmp("333-222-333", bson_iterator_string(&it1))); btype = bson_iterator_next(&it1); CU_ASSERT(btype == BSON_INT); CU_ASSERT(!strcmp("age", bson_iterator_key(&it1))); CU_ASSERT(33 == bson_iterator_int(&it1)); btype = bson_iterator_next(&it1); CU_ASSERT(btype == BSON_LONG); CU_ASSERT(!strcmp("longage", bson_iterator_key(&it1))); CU_ASSERT(0xFFFFFFFFFF01LL == bson_iterator_long(&it1)); btype = bson_iterator_next(&it1); CU_ASSERT(btype == BSON_DOUBLE); CU_ASSERT(!strcmp("doubleage", bson_iterator_key(&it1))); CU_ASSERT_DOUBLE_EQUAL(bson_iterator_double(&it1), 0.3, 0.1); btype = bson_iterator_next(&it1); CU_ASSERT(btype == BSON_EOO); bson_del(lbson); }
bool bson_cmp_array( const bson_iterator *it1, const bson_iterator *it2 ) { assert( it1 ); assert( it2 ); bool equal = true; bson_iterator *it1_d, *it2_d; it1_d = malloc( sizeof( bson_iterator ) ); it2_d = malloc( sizeof( bson_iterator ) ); memcpy( it1_d, it1, sizeof( bson_iterator ) ); memcpy( it2_d, it2, sizeof( bson_iterator ) ); assert( it1_d ); assert( it2_d ); while( true ) { bson_type t1 = bson_iterator_next( it1_d ); bson_type t2 = bson_iterator_next( it2_d ); if( t1 == BSON_EOO && t2 == BSON_EOO ) break; else if( t1 != t2 || !bson_values_are_equal( t1, it1_d, it2_d ) ) { equal = false; break; } } free( it1_d ); free( it2_d ); return equal; }
int srld_find(bson_iterator *i, int keyc, char **keyv, char *data, int depth) { bson_iterator_init(i, data); while(bson_iterator_next(i)){ if (strcmp(keyv[depth], bson_iterator_key(i)) == 0) { //printf("%s == %s, depth %d\n", keyv[depth], bson_iterator_key(i), depth); if (depth == keyc-1) { return 1; } else { return srld_find(i, keyc, keyv, (char *)bson_iterator_value(i), depth+1); } } } return 0; }
/** * \brief This function tries to load tag group data from MongoDB */ static void vs_mongo_taggroup_load_data(struct VSTagGroup *tg, bson *bson_version) { bson_iterator version_data_iter; /* Try to get tags of tag group */ if( bson_find(&version_data_iter, bson_version, "tags") == BSON_OBJECT ) { struct VSTag *tag; bson bson_tag; bson_iterator tags_iter, tag_iter; const char *key; int tag_id, data_type = -1, count = -1, tag_custom_type = -1; bson_iterator_subiterator(&version_data_iter, &tags_iter); while( bson_iterator_next(&tags_iter) == BSON_OBJECT ) { key = bson_iterator_key(&tags_iter); sscanf(key, "%d", &tag_id); bson_iterator_subobject_init(&tags_iter, &bson_tag, 0); if( bson_find(&tag_iter, &bson_tag, "data_type") == BSON_INT) { data_type = bson_iterator_int(&tag_iter); } if( bson_find(&tag_iter, &bson_tag, "count") == BSON_INT) { count = bson_iterator_int(&tag_iter); } if( bson_find(&tag_iter, &bson_tag, "custom_type") == BSON_INT) { tag_custom_type = bson_iterator_int(&tag_iter); } if(data_type != -1 && count != -1 && tag_custom_type != -1) { /* Create tag with specific ID */ tag = vs_tag_create(tg, tag_id, data_type, count, tag_custom_type); if(tag != NULL) { tag->state = ENTITY_CREATED; vs_mongo_tag_load_data(tag, &bson_tag); tag->flag = TAG_INITIALIZED; } } } } }
void json_from_bson_object(yajl_gen *g, bson_iterator *it) { yajl_gen_map_open( *g ); while( bson_iterator_next( it ) ) { bson_type t = bson_iterator_type( it ); const char* key = bson_iterator_key( it ); yajl_gen_string( *g, (const unsigned char*)key, strlen(key) ); json_from_bson_type( t, g, it ); } yajl_gen_map_close( *g ); }