bool is_collection(res::Class cls) { auto const name = cls.name(); return name->isame(s_Vector.get()) || name->isame(s_Map.get()) || name->isame(s_Set.get()) || name->isame(s_FrozenVector.get()) || name->isame(s_FrozenSet.get()) || name->isame(s_FrozenMap.get()); }
bool is_collection(res::Class cls) { auto const name = cls.name(); return name->isame(s_Vector.get()) || name->isame(s_Map.get()) || name->isame(s_Set.get()) || name->isame(s_Pair.get()) || name->isame(s_ImmVector.get()) || name->isame(s_ImmSet.get()) || name->isame(s_ImmMap.get()); }
//对比地址是否相等 int isame_both(struct iport *iport1, struct iport *iport2,int both){ //两者单向数据流 struct iport ipt = { 0 }; if (!both){ return isame(iport1, iport2); } //第二个参数双向 if (both == 2){ ipt.sip = iport2->dip; ipt.sport = iport2->dport; ipt.dip = iport2->sip; ipt.dport = iport2->sport; return isame(iport1, iport2) || isame(iport1, &ipt)+2; } //第一个参数双向 if (both == 1){ ipt.sip = iport1->dip; ipt.sport = iport1->dport; ipt.dip = iport1->sip; ipt.dport = iport1->sport; return isame(iport1, iport2) || isame(&ipt, iport2)+1; } return 0; }
int linetorules(struct ruledata *rd){ struct rulelink *current=NULL; struct rulelink *prev=NULL; struct iport cip; int first=1; cip.sip=rd->sip; cip.dip=rd->dip; cip.sport=rd->sport; cip.dport=rd->dport; if(!rks){ rks=(struct rulelink*)calloc(1,sizeof(struct rulelink));//申请内存,第一个rulelink first=0; } current=rks; while(current && first){ if(rd->both){ if(isame_both(&cip,(struct iport *)current,1)){ //判断地址是否相同 current->both=1; break; } }else{ if(isame(&cip,(struct iport *)current)){ //判断地址是否相同 break; } } prev=current; current=current->next; } if(current==NULL){ current=(struct rulelink*)calloc(1,sizeof(struct rulelink));//新增一个rulelink结构 prev->next=current; } current->sip = rd->sip; current->dip = rd->dip; current->sport = rd->sport; current->dport = rd->dport; current->both=rd->both; linetorule(current,rd); return 0; }