Exemple #1
0
int router_pop_aspect_site(void * message, char * proc)
{
	MSG_EXPAND * expand;
	struct expand_aspect_point * aspect_point;
	int ret;
	int len;

	MSG_HEAD * msg_head =message_get_head(message);

	ret=message_get_define_expand(message,&expand,DTYPE_MSG_EXPAND,SUBTYPE_ASPECT_POINT);
	if(ret<0)
		return -EINVAL;
	if(expand==NULL)
		return 0;
	aspect_point=expand->expand;
	if(aspect_point->record_num<1)
		return 0;

	int curr_offset=(--(aspect_point->record_num))*DIGEST_SIZE;
	Memcpy(msg_head->receiver_uuid,aspect_point->aspect_point+curr_offset,DIGEST_SIZE);
	Memcpy(proc,aspect_point->aspect_proc+curr_offset,DIGEST_SIZE);

	if(aspect_point->record_num==0)
	{
		message_remove_expand(message,DTYPE_MSG_EXPAND,SUBTYPE_ASPECT_POINT,&expand);
		Free(expand);
		Free(aspect_point->aspect_proc);
		Free(aspect_point->aspect_point);
	}
	return 1;
}
Exemple #2
0
int router_set_dup_flow(void * message,void * policy)
{
	int ret;
    	MSG_HEAD * msg_head;	
   	DISPATCH_POLICY * msg_policy=(DISPATCH_POLICY *)policy;
	ROUTE_RULE * rule;
	char * target;

    	if(policy==NULL)
        	return -EINVAL;
    	if(message==NULL)
        	return -EINVAL;
    	msg_head=message_get_head(message);
		
	Memset(msg_head->route,0,DIGEST_SIZE);
	if(msg_policy->newname!=NULL)
		Strncpy(msg_head->route,msg_policy->newname,DIGEST_SIZE);
	msg_head->ljump=1;
	msg_head->rjump=0;
	msg_head->flow=MSG_FLOW_DELIVER;
//	msg_head->flag=msg_policy->flag;
	Memset(msg_head->receiver_uuid,0,DIGEST_SIZE);
	message_set_policy(message,policy);
	return 1;
}
Exemple #3
0
/*
int match_message_record(void * match_rule,void * message)
{
    int ret;
    MSG_HEAD * msg_head=get_message_head(message);
    if(msg_head==NULL)
        return -EINVAL;
    void * record_template = load_record_template(msg_head->record_type);
    if(record_template==NULL)
        return -EINVAL;
    MATCH_RULE * rule=(MATCH_RULE *)match_rule;
    char buffer[1024];
    void * record;
    ret=message_comp_elem_text(message,rule->seg,0,rule->value);
	
    return ret;
}

*/
int router_set_aspect_flow(void * message,void * policy)
{
	int ret;
    	MSG_HEAD * msg_head;	
   	DISPATCH_POLICY * msg_policy=(DISPATCH_POLICY *)policy;
	ROUTE_RULE * rule;
	char * target;

    	if(policy==NULL)
        	return -EINVAL;
    	if(message==NULL)
        	return -EINVAL;
    	msg_head=message_get_head(message);
		
	if(!(msg_head->flow&MSG_FLOW_ASPECT))
	{
		Memset(msg_head->route,0,DIGEST_SIZE);
		Strncpy(msg_head->route,msg_policy->newname,DIGEST_SIZE);
		msg_head->ljump=1;
		msg_head->rjump=1;
		msg_head->flow=msg_policy->type;
	}
	Memset(msg_head->receiver_uuid,0,DIGEST_SIZE);
	message_set_policy(message,policy);

	return 1;	
}
Exemple #4
0
int dispatch_match_message_jump(void * policy, void * message)
{
	int ret;
	MSG_HEAD * msg_head;
	DISPATCH_POLICY * dispatch_policy=(DISPATCH_POLICY *)policy;
	if(policy==NULL)
		return 0;
	msg_head=message_get_head(message);
	if((dispatch_policy->rjump==0)||(dispatch_policy->rjump==msg_head->rjump))
		if((dispatch_policy->ljump==0)||(dispatch_policy->ljump==msg_head->ljump))
		{
			return 1;
		}
	return 0;
}
Exemple #5
0
int router_set_query_end(void * message,void * policy)
{
	int ret;
    	MSG_HEAD * msg_head;	
   	DISPATCH_POLICY * msg_policy=(DISPATCH_POLICY *)policy;
	ROUTE_RULE * rule;
	char * target;
	int jumpcount=1;

    	if(policy==NULL)
        	return -EINVAL;
    	if(message==NULL)
        	return -EINVAL;
    	msg_head=message_get_head(message);
	message_set_policy(message,policy);
	ret=dispatch_policy_getfirstrouterule(policy,&rule);
	if(ret<0)
		return ret;
	while(rule!=NULL)
	{
		jumpcount++;
		if((rule->target_type==ROUTE_TARGET_CONN)||(rule->target_type==ROUTE_TARGET_NAME))	
			break;
		ret=dispatch_policy_getnextrouterule(policy,&rule);
	}

	if(rule==NULL)
		return -EINVAL;
	ret=dispatch_policy_getnextrouterule(policy,&rule);

	if(rule==NULL)
		msg_head->flow=MSG_FLOW_FINISH;
	else
	{
		// if next target is a remote target, change flow to DELIVER
		message_set_receiver(message,rule->target_name);
		if(rule->target_type!=ROUTE_TARGET_LOCAL)
		{
			msg_head->flow=MSG_FLOW_DELIVER;
			msg_head->flag &=~MSG_FLAG_RESPONSE;
		}
	}
	msg_head->ljump=jumpcount++;
	return 1;	
}
Exemple #6
0
int dispatch_match_message(void * policy,void * message)
{
	int ret;
	DISPATCH_POLICY * dispatch_policy=(DISPATCH_POLICY *)policy;
	MATCH_RULE * match_rule;
	MSG_HEAD * msg_head;
	void * msg_record;
	void * record_template;
	
	msg_head=message_get_head(message);
	if(msg_head==NULL)
		return -EINVAL;
	ret=dispatch_policy_getfirstmatchrule(policy,&match_rule);
	if(ret<0)
		return ret;
	while(match_rule!=NULL)
	{
		if(match_rule->area==MATCH_AREA_RECORD)
		{	
			if(match_rule->type==0)
				return 1;
			if((match_rule->type!=msg_head->record_type)||
				(match_rule->subtype!=msg_head->record_subtype))
				return 0;
			if(match_rule->match_template==NULL)
				return 1;
			ret=message_get_record(message,&msg_record,0);
			if(ret<0)
				return ret;
			if(msg_record==NULL)
				return 0;
	
			return struct_part_compare(match_rule->value,msg_record,match_rule->match_template,match_flag);
		}
		else
		{
			return 0;
		}
		
	}	
	
	
}
Exemple #7
0
int router_set_local_route(void * message,void * policy)
{
	int ret;
    	MSG_HEAD * msg_head;	
   	DISPATCH_POLICY * msg_policy=(DISPATCH_POLICY *)policy;
	ROUTE_RULE * rule;
	char * target;

    	if(policy==NULL)
        	return -EINVAL;
    	if(message==NULL)
        	return -EINVAL;
    	msg_head=message_get_head(message);
		
	Memset(msg_head->route,0,DIGEST_SIZE);
	Strncpy(msg_head->route,msg_policy->name,DIGEST_SIZE);
	msg_head->ljump=1;
	msg_head->flow=msg_policy->type;
	message_set_policy(message,policy);
	return 1;	
}
Exemple #8
0
int route_recover_route(void * message)
{
	int ret;
	MSG_HEAD * msg_head;
	MSG_EXPAND * expand;
	struct expand_route_record * route_record=NULL;
	if(message==NULL)
		return  -EINVAL;
	ret=message_get_define_expand(message,&expand,DTYPE_MSG_EXPAND,SUBTYPE_ROUTE_RECORD);
	if(ret<0)
		return ret;
	if(expand==NULL)
		return -EINVAL;
	route_record=expand->expand;
	if(route_record==NULL)
		return -EINVAL;	

	int temp_flag=0;
	msg_head=(MSG_HEAD *)message_get_head(message);	

	Memcpy(msg_head->sender_uuid,route_record->sender_uuid,DIGEST_SIZE);
	Memcpy(msg_head->receiver_uuid,route_record->receiver_uuid,DIGEST_SIZE);
	Memcpy(msg_head->route,route_record->route,DIGEST_SIZE);
	msg_head->flow=route_record->flow;
	msg_head->state=route_record->state;
	msg_head->ljump=route_record->ljump;
	msg_head->rjump=route_record->rjump;

	int temp_mask=MSG_FLAG_CRYPT|MSG_FLAG_SIGN|MSG_FLAG_ZIP|MSG_FLAG_VERIFY;

	msg_head->flag = (msg_head->flag &temp_mask) | (route_record->flag & (~temp_mask));

	message_remove_expand(message,DTYPE_MSG_EXPAND,SUBTYPE_ROUTE_RECORD,&route_record);
	Free(route_record);
	return 1;
}
Exemple #9
0
int router_store_route(void * message)
{
	int ret;
	MSG_HEAD * msg_head;
	struct expand_route_record * route_record;
	if(message==NULL)
		return  -EINVAL;
	msg_head=(MSG_HEAD *)message_get_head(message);	
	route_record=Dalloc0(sizeof(*route_record),message);
	if(route_record==NULL)
		return -ENOMEM;	

	Memcpy(route_record->sender_uuid,msg_head->sender_uuid,DIGEST_SIZE);
	Memcpy(route_record->receiver_uuid,msg_head->receiver_uuid,DIGEST_SIZE);
	Memcpy(route_record->route,msg_head->route,DIGEST_SIZE);
	route_record->flow=msg_head->flow;
	route_record->state=msg_head->state;
	route_record->flag=msg_head->flag;
	route_record->ljump=msg_head->ljump;
	route_record->rjump=msg_head->rjump;
		
	ret=message_add_expand_data(message,DTYPE_MSG_EXPAND,SUBTYPE_ROUTE_RECORD,route_record);
	return ret;
}
Exemple #10
0
int router_pop_site(void * message)
{
	MSG_EXPAND * expand;
	struct expand_flow_trace * flow_trace;
	int ret;
	int len;

	MSG_HEAD * msg_head =message_get_head(message);

	ret=message_get_define_expand(message,&expand,DTYPE_MSG_EXPAND,SUBTYPE_FLOW_TRACE);
	if(ret<0)
		return -EINVAL;
	if(expand==NULL)
		return 0;
	flow_trace=expand->expand;
	if(flow_trace->record_num<1)
		return 0;

	int curr_offset=(--(flow_trace->record_num))*DIGEST_SIZE;
	Memcpy(msg_head->receiver_uuid,flow_trace->trace_record+curr_offset,DIGEST_SIZE);

	if(flow_trace->record_num==0)
	{
		Free(flow_trace->trace_record);
		flow_trace->trace_record=NULL;
		message_remove_expand(message,DTYPE_MSG_EXPAND,SUBTYPE_FLOW_TRACE,&expand);
		Free(expand);
	}
		
//	{
//		msg_head->state=MSG_FLOW_DELIVER;
//		msg_head->flag |= MSG_FLAG_LOCAL;
//	}

	return 1;
}
Exemple #11
0
int json_2_message(char * json_str,void ** message)
{

    void * root_node;
    void * head_node;
    void * tag_node;
    void * record_node;
    void * curr_record;
    void * expand_node;
    void * curr_expand;

    void * record_value;
    void * expand_value;

    struct message_box * msg_box;
    MSG_HEAD * msg_head;
    MSG_EXPAND * msg_expand;
    int record_no;
    int expand_no;
    void * precord;
    void * pexpand;
    int i;
    int ret;
    char buffer[DIGEST_SIZE];

    int offset;
    int type;
    int subtype;

    offset=json_solve_str(&root_node,json_str);
    if(offset<0)
        return offset;

    // get json node's head
    head_node=json_find_elem("HEAD",root_node);
    if(head_node==NULL)
    	head_node=json_find_elem("head",root_node);
    if(head_node==NULL)
        return -EINVAL;
    tag_node=json_find_elem("tag",head_node);
    if(tag_node!=NULL)   // default tag value is "MESG"
    {
    	ret=json_node_getvalue(tag_node,buffer,10);
    	if(ret!=4)
        	return -EINVAL;
	if(Memcmp(buffer,"MESG",ret)!=0)
		return -EINVAL;
    }	
    msg_box=message_init();
    msg_head=message_get_head(msg_box);
    json_2_struct(head_node,msg_head,msg_box->head_template);


    // get json node's record
    // init message box
    ret=message_record_init(msg_box);
    if(ret<0)
        return ret;

    record_node=json_find_elem("RECORD",root_node);
    if(record_node==NULL)
    	record_node=json_find_elem("record",root_node);
    if(record_node==NULL)
        return -EINVAL;

    curr_record=json_get_first_child(record_node);
    if(curr_record==NULL)
         return -EINVAL;
    char node_name[DIGEST_SIZE*2];
    ret=json_node_getname(curr_record,node_name);
    if(!strcmp(node_name,"BIN_FORMAT"))
    {
	BYTE * radix64_string;
	radix64_string=malloc(4096);
	if(radix64_string==NULL)
		return -ENOMEM;
	ret=json_node_getvalue(curr_record,radix64_string,4096);
	if(ret<0)
		return -EINVAL;
	int radix64_len=strnlen(radix64_string,4096);
	msg_head->record_size=radix_to_bin_len(radix64_len);
	msg_box->blob=malloc(msg_head->record_size);
	if(msg_box->blob==NULL)
		return -ENOMEM;
	ret=radix64_to_bin(msg_box->blob,radix64_len,radix64_string);
   }
    else
   {
    	for(i=0;i<msg_head->record_num;i++)
    	{
        	if(curr_record==NULL)
            		return -EINVAL;
        	ret=Galloc0(&precord,struct_size(msg_box->record_template));
        	if(ret<=0)
            		return -EINVAL;
       		json_2_struct(curr_record,precord,msg_box->record_template);
        	message_add_record(msg_box,precord);
        	curr_record=json_get_next_child(record_node);
	}
    }

    // get json_node's expand
    expand_no=msg_head->expand_num;
    msg_head->expand_num=0;
    expand_node=json_find_elem("EXPAND",root_node); 
    if(expand_node==NULL)
    	expand_node=json_find_elem("expand",root_node);
    if(expand_node!=NULL)
    {
	char buf[20];
	void * curr_expand_template;
	curr_expand=json_get_first_child(expand_node);
   	for(i=0;i<expand_no;i++)
    	{
        	if(curr_expand==NULL)
            		return -EINVAL;
		ret=Galloc0(&msg_expand,struct_size(message_get_expand_template()));
		if(ret<0)
			return -ENOMEM;

		ret=json_2_struct(curr_expand,&msg_expand,message_get_expand_template());
		if(ret<0)
			return ret;

		void * tempnode;
		if((tempnode=json_find_elem(curr_expand,"BIN_DATA"))==NULL)
		{

				
			curr_expand_template=memdb_get_template(msg_expand->type,msg_expand->subtype);
			if(curr_expand_template==NULL)
				return -EINVAL;
			struct_free(msg_expand,message_get_expand_template());			
			ret=Galloc(&msg_expand,struct_size(curr_expand_template));
			if(ret<0)
				return -ENOMEM;
			ret=json_2_struct(curr_expand,msg_expand,curr_expand_template);
			if(ret<0)
				return ret;
		}
		

	
        	message_add_expand(msg_box,msg_expand);
        	curr_expand=json_get_next_child(expand_node);

	}
    }


    *message=msg_box;
    msg_box->box_state = MSG_BOX_RECOVER;
    return offset;
}
Exemple #12
0
int router_dup_activemsg_info (void * message)
{
	int ret;
	struct message_box * msg_box=message;
	MSG_HEAD * msg_head;
	MSG_HEAD * new_msg_head;
	if(message==NULL)
		return -EINVAL;

	void * active_msg=message_get_activemsg(message);
	if(active_msg==NULL)
		return 0;
	if(active_msg==message)
	{
		msg_head=message_get_head(message);
	//	msg_head->ljump++;
		return 0;
	}
	
	msg_head=message_get_head(active_msg);
	new_msg_head=message_get_head(message);
	message_set_flow(msg_box,msg_head->flow);
	message_set_state(msg_box,msg_head->state);
//	message_set_flag(msg_box,msg_head->flag);
	message_set_route(msg_box,msg_head->route);
	new_msg_head->ljump=msg_head->ljump;	
	new_msg_head->rjump=msg_head->rjump;	

	MSG_EXPAND * old_expand;
	MSG_EXPAND * new_expand;
	void * flow_expand;
	ret=message_get_define_expand(active_msg,&old_expand,DTYPE_MSG_EXPAND,SUBTYPE_FLOW_TRACE);
	if(old_expand!=NULL) 
	{
		new_expand=Calloc0(sizeof(MSG_EXPAND));
		if(new_expand==NULL)
			return -ENOMEM;
		Memcpy(new_expand,old_expand,sizeof(MSG_EXPAND_HEAD));
		void * struct_template =memdb_get_template(DTYPE_MSG_EXPAND,SUBTYPE_FLOW_TRACE);
		new_expand->expand = clone_struct(old_expand->expand,struct_template);
		message_add_expand(message,new_expand);
	}
	ret=message_get_define_expand(active_msg,&old_expand,DTYPE_MSG_EXPAND,SUBTYPE_ASPECT_POINT);
	if(old_expand!=NULL) 

	{
		new_expand=Calloc0(sizeof(MSG_EXPAND));
		if(new_expand==NULL)
			return -ENOMEM;
		Memcpy(new_expand,old_expand,sizeof(MSG_EXPAND_HEAD));
		void * struct_template =memdb_get_template(DTYPE_MSG_EXPAND,SUBTYPE_ASPECT_POINT);
		new_expand->expand = clone_struct(old_expand->expand,struct_template);
		message_add_expand(message,new_expand);
	}
	ret=message_get_define_expand(active_msg,&old_expand,DTYPE_MSG_EXPAND,SUBTYPE_ROUTE_RECORD);
	if(old_expand!=NULL) 
	{
		new_expand=Calloc0(sizeof(MSG_EXPAND));
		if(new_expand==NULL)
			return -ENOMEM;
		Memcpy(new_expand,old_expand,sizeof(MSG_EXPAND_HEAD));
		void * struct_template =memdb_get_template(DTYPE_MSG_EXPAND,SUBTYPE_ROUTE_RECORD);
		new_expand->expand = clone_struct(old_expand->expand,struct_template);
		message_add_expand(message,new_expand);
	}
	message_set_policy(message,message_get_policy(active_msg));

	return 1;
}
Exemple #13
0
int dispatch_match_message(void * policy,void * message)
{
	int ret;
	int result=0;
	int prev_result=0;
	int match_rule_num=0;
	DISPATCH_POLICY * dispatch_policy=(DISPATCH_POLICY *)policy;
	MATCH_RULE * match_rule;
	MSG_HEAD * msg_head;
	void * msg_record;
	void * record_template;
	
	msg_head=message_get_head(message);
	if(msg_head==NULL)
		return -EINVAL;

	if(dispatch_policy->name!=NULL)
	{
		if(msg_head->route[0]!=0)
			if(Strncmp(dispatch_policy->name,msg_head->route,DIGEST_SIZE)!=0)
				return 0;	
	}

	ret=dispatch_policy_getfirstmatchrule(policy,&match_rule);
	if(ret<0)
		return ret;
	while(match_rule!=NULL)
	{
		if((match_rule->area==0)||(match_rule->area==MATCH_AREA_HEAD))
		{
			if(match_rule->type==0)
				result=1;
			else if(match_rule->type ==msg_head->record_type)
			{
				if(match_rule->subtype==0)
					result= 1;
				else if(match_rule->subtype==msg_head->record_subtype)
					result = 1;
			}
			else
			{
				result = 0;
			}
		}
		else if(match_rule->area==MATCH_AREA_RECORD)
		{	
			if(match_rule->type==0)
				result = 1;
			else if((match_rule->type!=msg_head->record_type)||
				(match_rule->subtype!=msg_head->record_subtype))
				result = 0;
			else if(match_rule->match_template==NULL)
				result = 1;
			else
			{
				ret=message_get_record(message,&msg_record,0);
				if(ret<0)
					result =ret;
				else if(msg_record==NULL)
					result = 0;
	
				else if(!struct_part_compare(match_rule->value,msg_record,match_rule->match_template,match_flag))
					result = 1;
				else
					result = 0;
			}
		}
		else if(match_rule->area==MATCH_AREA_EXPAND)
		{
			MSG_EXPAND * msg_expand;			
			void * expand_template;
			ret=message_get_define_expand(message,&msg_expand,match_rule->type,match_rule->subtype);
			if(msg_expand==NULL)
				result=0;
			else if(match_rule->value==NULL)
				result=1;
			else
			{
			//	expand_template=memdb_get_template(match_rule->type,match_rule->subtype);
				if(match_rule->match_template==NULL)
					result=0;
				else
				{
					if(!struct_part_compare(match_rule->value,msg_expand->expand,
							match_rule->match_template,match_flag))
						result = 1;
					else
						result = 0;
				}
			}	
		}
		else
		{
			result = 0;
		}
		
		if(result<0)
			return result;
		switch(match_rule->op)
		{
			case DISPATCH_MATCH_AND:
				if(result==0)
					return result;	
				prev_result=1;
				break;				
			case DISPATCH_MATCH_OR:
				if(result>0)
					return result;	
				break;				

			case DISPATCH_MATCH_NOT:
				if(result>0)
					return 0;	
				prev_result=1;
				break;
			case DISPATCH_MATCH_ORNOT:
				if(result==0)
					return 1;
				break;	
			
			default:
				return -EINVAL;	
		}
		match_rule_num++;
		ret=dispatch_policy_getnextmatchrule(policy,&match_rule);
		if(ret<0)
			return ret;
	}	
	if(match_rule_num==0)
		return 0;
	return prev_result;
}
Exemple #14
0
int router_set_next_jump(void * message)
{
	int ret;
    	MSG_HEAD * msg_head;	
   	DISPATCH_POLICY * msg_policy;
	ROUTE_RULE * rule;
	char * target;
	int i;

    	if(message==NULL)
        	return -EINVAL;
    	msg_head=message_get_head(message);
		
	msg_policy=message_get_policy(message);
	if(msg_policy==NULL)
		return 0;	

	ret=dispatch_policy_getfirstrouterule(msg_policy,&rule);
	if(rule==NULL)
		return 0;
	for(i=1;i<msg_head->ljump;i++)
	{
		ret=dispatch_policy_getnextrouterule(msg_policy,&rule);		
		if(rule==NULL)
			return 0;
	}

	Memset(msg_head->receiver_uuid,0,DIGEST_SIZE);

	switch(rule->target_type)
	{
		case ROUTE_TARGET_LOCAL:
		case ROUTE_TARGET_PORT:
			ret=rule_get_target(rule,message,&target);
			if(ret<0)
				return ret;		
			Strncpy(msg_head->receiver_uuid,target,DIGEST_SIZE);
			msg_head->flag |=MSG_FLAG_LOCAL;
			Free(target);
			//message_set_state(message,MSG_FLOW_LOCAL);
			break;
		case ROUTE_TARGET_NAME:
		case ROUTE_TARGET_RECORD:
		case ROUTE_TARGET_EXPAND:
			ret=rule_get_target(rule,message,&target);
			if(ret<0)
				return ret;		
			if(Isstrinuuid(target))
			{
//				msg_head->receiver_uuid[0]='@';
				Strncpy(msg_head->receiver_uuid,target,DIGEST_SIZE/4*3);
			}
			else
			{
				Memcpy(msg_head->receiver_uuid,target,DIGEST_SIZE);
			}	
			Free(target);
			message_set_state(message,MSG_FLOW_DELIVER);
			msg_head->flag&=~MSG_FLAG_LOCAL;
//			msg_head->rjump++;
			break;
		case ROUTE_TARGET_CONN:
			ret=rule_get_target(rule,message,&target);
			if(ret<0)
				return ret;		
			Strncpy(msg_head->receiver_uuid,target,DIGEST_SIZE-1);
			Free(target);
			message_set_state(message,MSG_FLOW_DELIVER);
			msg_head->flag&=~MSG_FLAG_LOCAL;
//			msg_head->rjump++;
			break;
		default:
			return -EINVAL;
	}
	return 1;	
}