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; } } }
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 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; }