void * find_key_info(void * key_info) { struct trust_demo_keyinfo * in_keyinfo=key_info; struct trust_demo_keyinfo * db_keyinfo; DB_RECORD * record; void * comp_template; int ret; comp_template=memdb_get_template(DTYPE_TRUST_DEMO,SUBTYPE_KEY_INFO); ret=struct_set_flag(comp_template,CUBE_ELEM_FLAG_TEMP,"vtpm_uuid,owner,peer,usage,key_type"); if(ret<0) return NULL; record=memdb_get_first(DTYPE_TRUST_DEMO,SUBTYPE_KEY_INFO); while(record!=NULL) { db_keyinfo=record->record; if(db_keyinfo==NULL) return NULL; if(struct_part_compare(db_keyinfo,in_keyinfo,comp_template,CUBE_ELEM_FLAG_TEMP)) break; record=memdb_get_next(DTYPE_TRUST_DEMO,SUBTYPE_KEY_INFO); } return record; }
int main() { static unsigned char alloc_buffer[4096*(1+1+4+1+16+1+256)]; char json_buffer[4096]; char print_buffer[4096]; BYTE bin_buffer[4096]; int ret; int readlen; int json_offset; void * root_node; void * findlist; void * memdb_template ; BYTE uuid[DIGEST_SIZE]; int i; MSG_HEAD * msg_head; char * baseconfig[] = { "namelist.json", "typelist.json", "subtypelist.json", "msghead.json", "base_msg.json", "expandrecord.json", NULL }; // alloc_init(alloc_buffer); struct_deal_init(); memdb_init(); // test namelist reading start for(i=0;baseconfig[i]!=NULL;i++) { ret=read_json_file(baseconfig[i]); if(ret<0) return ret; printf("read %d elem from file %s!\n",ret,baseconfig[i]); } void * record; // test struct desc reading start int msg_type = memdb_get_typeno("MESSAGE"); if(msg_type<=0) return -EINVAL; int subtype=memdb_get_subtypeno(msg_type,"HEAD"); if(subtype<=0) return -EINVAL; record=memdb_get_first(msg_type,subtype); while(record!=NULL) { ret=memdb_print(record,print_buffer); if(ret<0) return -EINVAL; printf("%s\n",print_buffer); record=memdb_get_next(msg_type,subtype); } msgfunc_init(); void * message; struct basic_message base_msg; struct expand_flow_trace flow_trace; message=message_create(DTYPE_MESSAGE,SUBTYPE_BASE_MSG,NULL); base_msg.message=dup_str("Hello,World!",0); flow_trace.record_num=1; flow_trace.trace_record=Talloc0(DIGEST_SIZE*flow_trace.record_num); Strncpy(flow_trace.trace_record,"test_port",DIGEST_SIZE/4*3); ret=message_add_record(message,&base_msg); if(ret<0) { printf("add message record failed!\n"); return ret; } ret=message_add_expand_data(message,DTYPE_MSG_EXPAND,SUBTYPE_FLOW_TRACE,&flow_trace); if(ret<0) { printf("add message expand failed!\n"); return ret; } ret=message_record_struct2blob(message); if(ret<0) { printf("message struct2blob failed!\n"); return ret; } BYTE * blob; ret=message_output_json(message,json_buffer); if(ret<0) { printf("message output json failed!\n"); return ret; } printf("%s\n",json_buffer); ret=message_output_blob(message,&blob); if(ret<0) return ret; printf ("output %d data to bin_buffer\n",ret); void * new_msg; ret=message_read_from_blob(&new_msg,blob,ret); printf ("read %d from bin_buffer\n",ret); ret=message_load_record(new_msg); if(ret<0) { printf("load record failed!\n"); return ret; } ret=message_load_expand(new_msg); if(ret<0) { printf("load expand failed!\n"); return ret; } printf("%s\n",json_buffer); ret=json_2_message(json_buffer,&new_msg); if(ret<0) return ret; printf ("read %d from json_buffer\n",ret); ret=message_output_json(new_msg,json_buffer); if(ret<0) { printf("message output json failed!\n"); return ret; } printf("%s\n",json_buffer); ret=message_output_blob(message,bin_buffer); return 0; }
int main() { static unsigned char alloc_buffer[4096*(1+1+4+1+16+1+256)]; char json_buffer[4096]; char print_buffer[4096]; int ret; int readlen; int json_offset; void * root_node; void * findlist; void * memdb_template ; BYTE uuid[DIGEST_SIZE]; int i; MSG_HEAD * msg_head; char * baseconfig[] = { "typelist.json", "subtypelist.json", "msghead.json", "headrecord.json", NULL }; alloc_init(alloc_buffer); struct_deal_init(); memdb_init(); // test namelist reading start for(i=0;baseconfig[i]!=NULL;i++) { ret=read_json_file(baseconfig[i]); if(ret<0) return ret; printf("read %d elem from file %s!\n",ret,baseconfig[i]); } void * record; // test struct desc reading start int msg_type = memdb_get_typeno("MESSAGE"); if(msg_type<=0) return -EINVAL; int subtype=memdb_get_subtypeno(msg_type,"HEAD"); if(subtype<=0) return -EINVAL; record=memdb_get_first(msg_type,subtype); while(record!=NULL) { ret=memdb_print(record,print_buffer); if(ret<0) return -EINVAL; printf("%s\n",print_buffer); record=memdb_get_next(msg_type,subtype); } msgfunc_init(); void * message; message=message_create(512,1,NULL); ret=Galloc0(&msg_head,sizeof(MSG_HEAD)); if(msg_head==NULL) return -EINVAL; Strcpy(msg_head->sender_uuid,"Test sender"); Strcpy(msg_head->receiver_uuid,"Test receiver"); ret=message_add_record(message,msg_head); if(ret<0) { printf("add message head record failed!\n"); return ret; } ret=message_record_struct2blob(message); if(ret<0) { printf("message struct2blob failed!\n"); return ret; } BYTE * blob; message_output_blob(message,&blob); ret=message_output_json(message,json_buffer); if(ret<0) { printf("message output json failed!\n"); return ret; } printf("%s\n",json_buffer); void * new_msg; ret=json_2_message(json_buffer,&new_msg); if(ret<0) return ret; printf ("read % from json_buffer\n",ret); ret=message_output_json(message,json_buffer); if(ret<0) { printf("message output json failed!\n"); return ret; } printf("%s\n",json_buffer); return 0; }