int route_push_site(void * message,BYTE * name) { MSG_EXPAND * expand; struct expand_flow_trace * flow_trace; int ret; int len; int index; index=message_get_define_expand(message,&expand,DTYPE_MSG_EXPAND,SUBTYPE_FLOW_TRACE); if(index<0) return -EINVAL; if(expand==NULL) { expand=Dalloc0(sizeof(MSG_EXPAND),message); if(expand==NULL) return -ENOMEM; expand->type=DTYPE_MSG_EXPAND; expand->subtype=SUBTYPE_FLOW_TRACE; flow_trace=Dalloc0(sizeof(*flow_trace),message); if(flow_trace==NULL) return -ENOMEM; expand->expand=flow_trace; } else { flow_trace=expand->expand; } if(flow_trace->record_num==0) { flow_trace->record_num++; flow_trace->trace_record=Dalloc0(DIGEST_SIZE,message); if(flow_trace->trace_record==NULL) return -ENOMEM; Memcpy(flow_trace->trace_record,name,DIGEST_SIZE); message_add_expand(message,expand); } else { int curr_offset=flow_trace->record_num*DIGEST_SIZE; flow_trace->record_num++; char * buffer; buffer=Dalloc0(curr_offset+DIGEST_SIZE,message); if(buffer==NULL) return -ENOMEM; Memcpy(buffer,flow_trace->trace_record,curr_offset); Free(flow_trace->trace_record); Memcpy(buffer+curr_offset,name,DIGEST_SIZE); flow_trace->trace_record=buffer; message_replace_define_expand(message,expand); } return 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; }
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; }
int route_push_aspect_site(void * message,char * proc,char * point) { MSG_EXPAND * expand; struct expand_aspect_point * aspect_point; int ret; int len; int index; index=message_get_define_expand(message,&expand,DTYPE_MSG_EXPAND,SUBTYPE_ASPECT_POINT); if(index<0) return -EINVAL; if(expand==NULL) { expand=Calloc0(sizeof(MSG_EXPAND)); if(expand==NULL) return -ENOMEM; expand->type=DTYPE_MSG_EXPAND; expand->subtype=SUBTYPE_ASPECT_POINT; aspect_point=Dalloc0(sizeof(*aspect_point),message); if(aspect_point==NULL) return -ENOMEM; expand->expand=aspect_point; } else { aspect_point=expand->expand; } if(aspect_point->record_num==0) { aspect_point->record_num++; aspect_point->aspect_proc=Dalloc0(DIGEST_SIZE,message); if(aspect_point->aspect_proc==NULL) return -ENOMEM; Memcpy(aspect_point->aspect_proc,proc,DIGEST_SIZE); aspect_point->aspect_point=Dalloc0(DIGEST_SIZE,message); if(aspect_point->aspect_point==NULL) return -ENOMEM; Memcpy(aspect_point->aspect_point,point,DIGEST_SIZE); message_add_expand(message,expand); } else { int curr_offset=aspect_point->record_num*DIGEST_SIZE; aspect_point->record_num++; char * buffer; buffer=Dalloc0(curr_offset+DIGEST_SIZE,message); if(buffer==NULL) return -ENOMEM; Memcpy(buffer,aspect_point->aspect_proc,curr_offset); Free(aspect_point->aspect_proc); Memcpy(buffer+curr_offset,proc,DIGEST_SIZE); aspect_point->aspect_proc=buffer; buffer=Dalloc0(curr_offset+DIGEST_SIZE,message); if(buffer==NULL) return -ENOMEM; Memcpy(buffer,aspect_point->aspect_point,curr_offset); Free(aspect_point->aspect_point); Memcpy(buffer+curr_offset,point,DIGEST_SIZE); aspect_point->aspect_point=buffer; message_replace_define_expand(message,expand); } return 0; }