Exemplo n.º 1
0
int read_recordtype_json_desc(void * root,void * record)
{

	int ret;
	void * data;
	void * struct_template;

	DB_RECORD * db_record=record;
	DB_RECORD * struct_record;
	struct struct_desc_record * struct_desc;
	struct struct_recordtype * recordtype;
	
	void * temp_node;

	if(db_record->head.type <=0)
		return -EINVAL;

	struct_template=memdb_get_template(db_record->head.type,db_record->head.subtype);
	if(struct_template==NULL)
		return -EINVAL;

	ret=Galloc0(&recordtype,sizeof(struct struct_recordtype));
	if(ret<0)
		return ret;

	temp_node=json_find_elem("uuid",root);
	if(temp_node==NULL)
		return -EINVAL;
	char * uuid_str=json_get_valuestr(temp_node);
	
	if(!Isvaliduuid(uuid_str))
	{
		struct_record=memdb_find_byname(uuid_str,DB_STRUCT_DESC,0);
		if(struct_record==NULL)
			return -EINVAL;		
		Memcpy(recordtype->uuid,struct_record->head.uuid,DIGEST_SIZE);
		ret=json_remove_node(temp_node);
	}

	ret=json_2_struct(root,recordtype,struct_template);
//	namelist->elem_no=json_get_elemno(temp_node);
	db_record->record=recordtype;

	ret=memdb_comp_uuid(db_record);
	if(ret<0)
		return ret;	
	ret=memdb_store_record(db_record);
	if(ret<0)
		return ret;
	ret=memdb_register_dynamicdb(recordtype->type,recordtype->subtype);

	return ret;	
}
Exemplo n.º 2
0
int user_addr_store(void * sub_proc,void * message)
{
	
	int ret;
	struct user_address * user_addr;
	MSG_EXPAND * expand;
	struct expand_flow_trace * flow_trace;
	struct login_info * login_data;
	DB_RECORD * db_record;
	int trace_offset;
	
	ret=message_get_record(message,&login_data,0);
	if(ret<0)
		return ret;
	ret=message_get_define_expand(message,&expand,DTYPE_MSG_EXPAND,SUBTYPE_FLOW_TRACE);
	if(ret<0)
		return ret;
	if(expand==NULL)
		return -EINVAL;
	flow_trace=expand->expand;

	if(flow_trace->record_num<=0)
		return -EINVAL;
	trace_offset=DIGEST_SIZE*(flow_trace->record_num-1);
	db_record=memdb_find_byname(login_data->user,DTYPE_CRYPTO_DEMO,SUBTYPE_USER_ADDR);
	if(db_record!=NULL)
	{
		user_addr=(struct user_address *)db_record->record;
		if(Memcmp(user_addr->addr,flow_trace->trace_record+trace_offset,DIGEST_SIZE)==0)
			return 0;	
		memdb_remove_record(db_record);
	}
	user_addr=Talloc0(sizeof(struct user_address));
	if(user_addr==NULL)
		return -ENOMEM;
	Strncpy(user_addr->user,login_data->user,DIGEST_SIZE);
	Memcpy(user_addr->addr,flow_trace->trace_record+trace_offset,DIGEST_SIZE);
	memdb_store(user_addr,DTYPE_CRYPTO_DEMO,SUBTYPE_USER_ADDR,login_data->user);
	return 1;
}
Exemplo n.º 3
0
int read_typelist_json_desc(void * root,void * record)
{
	int ret;
	struct struct_namelist * namelist;
	struct struct_namelist * baselist;
	struct struct_typelist * typelist;
	struct struct_typelist * basetypelist;

	int * temp_node;
	void * namelist_template;
	void * typelist_template;
	DB_RECORD * db_record=record;
	DB_RECORD * namelist_record;


	ret=Galloc0(&typelist,sizeof(struct struct_typelist));
	if(ret<0)
		return ret;
	if(db_record->head.type!=DB_TYPELIST)
		return -EINVAL;
	
//      store the namelist (if exists) and compute the uuid

	temp_node=json_find_elem("uuid",root);
	if(temp_node == NULL)
	{
		// this typelist use namelist describe, 
		// we should finish namelist store first	
		ret=Galloc0(&namelist_record,sizeof(DB_RECORD));
		if(ret<0)
			return ret;
		namelist_record->head.type=DB_NAMELIST;
		ret=read_namelist_json_desc(root,namelist_record);
		if(ret<0)
			return ret;
		Memcpy(typelist->uuid,namelist_record->head.uuid,DIGEST_SIZE);
		namelist=namelist_record->record;
		typelist->elem_no=namelist->elem_no;			
	}
	else
	{
		typelist_template=memdb_get_template(DB_TYPELIST,0);
		if(typelist_template==NULL)
			return -EINVAL;

		ret=json_2_struct(root,typelist,typelist_template);
		namelist_record=memdb_find(typelist->uuid,DB_NAMELIST,0);
		if(namelist_record==NULL)
			return -EINVAL;
		namelist=namelist_record->record;
		if(typelist->elem_no==0)
			typelist->elem_no=namelist->elem_no;
	}

	db_record->record=typelist;
	ret=memdb_store_record(db_record);

	// merge the typelist 

	namelist_record=memdb_find_byname("typeenumlist",DB_NAMELIST,0);
	
	if(namelist_record==NULL)
		return -EINVAL;

	baselist=_merge_namelist(namelist_record->record,db_record->tail);
	if(baselist==NULL)
		return -EINVAL;

	ret=memdb_remove_byname("typeenumlist",DB_NAMELIST,0);
	if(ret<0)
		return -EINVAL;
	
	memdb_store(baselist,DB_NAMELIST,0,"typeenumlist");
	typeenumlist=baselist;

	return ret;	
}