📄 mod_filter.c
字号:
} } } if(!has_envelope) xmlnode_put_attrib(x=xmlnode_insert_tag(m->packet->x,"x"),"xmlns","jabber:x:envelope"); xmlnode_put_attrib(xmlnode_insert_tag(x,"forwardedby"),"jid",jid_full(m->packet->to)); xmlnode_put_attrib(xmlnode_insert_tag(x,"from"),"jid",jid_full(m->packet->from)); for(cur=j;cur!=NULL;cur=cur->next) xmlnode_put_attrib(xmlnode_insert_tag(x,"cc"),"jid",jid_full(cur)); for(;j!=NULL;j=j->next) { x=xmlnode_dup(m->packet->x); xmlnode_put_attrib(x,"to",jid_full(j)); xmlnode_put_attrib(x,"from",jid_full(m->packet->to)); deliver(dpacket_new(x),m->si->i); }}void mod_filter_action_settype(mapi m,xmlnode rule){ char *newtype=xmlnode_get_tag_data(rule,"settype"); if(newtype==NULL) xmlnode_hide_attrib(m->packet->x,"type"); else xmlnode_put_attrib(m->packet->x,"type",newtype); jpacket_reset(m->packet);}mreturn mod_filter_handler(mapi m, void *arg){ xmlnode rules,cur; xmlnode container; action cur_action; jpacket jp; pool p; jp = m->packet; if(m->packet->type == JPACKET_PRESENCE) return M_IGNORE; if(m->user == NULL) return M_PASS; p = pool_new(); cur_action = pmalloco(p,sizeof(_action)); /* look through the user's rule set for a matching cond */ container = mod_filter_get(m->user); xmlnode_insert_node(container, xmlnode_get_firstchild(mod_filter__default)); rules = xmlnode_get_firstchild(container); log_debug(ZONE,"Looking at rules: %s", xmlnode2str(container)); for(;rules!=NULL;rules=xmlnode_get_nextsibling(rules)) { log_debug(ZONE, "rule: %s", xmlnode2str(rules)); if(xmlnode_get_type(rules) != NTYPE_TAG) continue; cur=xmlnode_get_firstchild(rules); for(;cur!=NULL;) { /* iq packets may match the <ns/> condition */ if(j_strcmp(xmlnode_get_name(cur), "ns") == 0) { log_debug(ZONE, "checking ns"); if(m->packet->type != JPACKET_IQ) { /* ignore this rule, since the packet is not an IQ */ cur = NULL; continue; } if(j_strcmp(xmlnode_get_attrib(m->packet->iq, "xmlns"), xmlnode_get_data(cur)) == 0) { cur_action->is_match = 1; log_debug(ZONE, "MATCH"); } cur = xmlnode_get_nextsibling(cur); } else if(j_strcmp(xmlnode_get_name(cur), "roster") == 0) { xmlnode roster = xdb_get(m->user->si->xc, m->user->id, NS_ROSTER); jid j = jid_new(m->packet->p, jid_full(m->packet->from)); if ( j != NULL ) { jid_set(j, NULL, JID_RESOURCE); log_debug(ZONE, "checking roster"); if(jid_nodescan(j, roster) != NULL) { cur_action->is_match = 1; log_debug(ZONE, "MATCH"); } } else { log_debug(ZONE, "Bogus return address on message"); } xmlnode_free(roster); cur = xmlnode_get_nextsibling(cur); } else if(j_strcmp(xmlnode_get_name(cur), "group") == 0) { xmlnode roster = xdb_get(m->user->si->xc, m->user->id, NS_ROSTER); xmlnode item; char *group = spools(m->packet->p, "item/group=", xmlnode_get_data(cur), m->packet->p); jid j = jid_new(m->packet->p, jid_full(m->packet->from)); if ( j != NULL ) { jid_set(j, NULL, JID_RESOURCE); log_debug(ZONE, "checking for group %s in %s", group, xmlnode2str(roster)); while((item = xmlnode_get_tag(roster, group)) != NULL) { log_debug(ZONE, "found match: %s", xmlnode2str(item)); if(jid_cmpx(j, jid_new(xmlnode_pool(item), xmlnode_get_attrib(item->parent, "jid")), JID_USER | JID_SERVER) == 0) { cur_action->is_match = 1; log_debug(ZONE, "MATCH"); break; } xmlnode_hide(item); } } else { log_debug(ZONE, "Bogus Return address on message."); } xmlnode_free(roster); cur = xmlnode_get_nextsibling(cur); } else if(j_strcmp(xmlnode_get_name(cur),"unavailable")==0) { log_debug(ZONE,"checking unavailalbe"); if(js_session_primary(m->user)==NULL) cur_action->is_match=1; else break; log_debug(ZONE,"MATCH!"); cur=xmlnode_get_nextsibling(cur); } else if(j_strcmp(xmlnode_get_name(cur),"from")==0) { xmlnode f=cur; log_debug(ZONE,"checking from"); cur_action->is_match=0; for(;f!=NULL;f=xmlnode_get_tag(rules,"from")) { char *from=xmlnode_get_data(f); log_debug(ZONE,"checking from: %s",from); if(cur_action->is_match||from==NULL||jid_cmpx(jid_new(jp->from->p,from),jp->from,JID_USER|JID_SERVER)!=0) { log_debug(ZONE,"not a match, killing node"); if(cur==f) cur=xmlnode_get_nextsibling(cur); xmlnode_hide(f); continue; } if(cur==f)cur=xmlnode_get_nextsibling(cur); xmlnode_hide(f); cur_action->is_match=1; } if(!cur_action->is_match) break; log_debug(ZONE,"MATCH!"); } else if(j_strcmp(xmlnode_get_name(cur),"resource")==0) { xmlnode r=cur; log_debug(ZONE,"checking resource"); cur_action->is_match=0; for(;r!=NULL;r=xmlnode_get_tag(rules,"resource")) { char *res=xmlnode_get_data(r); log_debug(ZONE,"checking res: %s",res); if(cur_action->is_match||res==NULL||jp->to->resource==NULL||strcasecmp(res,jp->to->resource)!=0) { log_debug(ZONE,"not a match"); if(cur==r) cur=xmlnode_get_nextsibling(cur); xmlnode_hide(r); continue; } if(cur==r)cur=xmlnode_get_nextsibling(cur); xmlnode_hide(r); cur_action->is_match=1; } if(!cur_action->is_match) break; log_debug(ZONE,"MATCH!"); } else if(j_strcmp(xmlnode_get_name(cur),"subject")==0) { xmlnode s=cur; if(m->packet->type == JPACKET_IQ) break; log_debug(ZONE,"checking subject"); cur_action->is_match=0; for(;s!=NULL;s=xmlnode_get_tag(rules,"subject")) { char *subject=xmlnode_get_data(s); log_debug(ZONE,"checking subject: %s",subject); if(cur_action->is_match||subject==NULL||xmlnode_get_tag_data(jp->x,"subject")==NULL||strcasecmp(subject,xmlnode_get_tag_data(jp->x,"subject"))!=0) { log_debug(ZONE,"not a match"); if(cur==s)cur=xmlnode_get_nextsibling(cur); xmlnode_hide(s); continue; } if(cur==s)cur=xmlnode_get_nextsibling(cur); xmlnode_hide(s); cur_action->is_match=1; } if(!cur_action->is_match) break; log_debug(ZONE,"MATCH!"); } else if(j_strcmp(xmlnode_get_name(cur),"body")==0) { xmlnode b=cur; if(m->packet->type == JPACKET_IQ) break; log_debug(ZONE,"checking body"); cur_action->is_match=0; for(;b!=NULL;b=xmlnode_get_tag(rules,"body")) { char *body=xmlnode_get_data(b); log_debug(ZONE,"checking body: %s",body); if(cur_action->is_match||body==NULL||xmlnode_get_tag_data(jp->x,"body")==NULL||strcasecmp(body,xmlnode_get_tag_data(jp->x,"body"))!=0) { log_debug(ZONE,"not a match"); if(cur==b)cur=xmlnode_get_nextsibling(cur); xmlnode_hide(b); continue; } if(cur==b)cur=xmlnode_get_nextsibling(cur); xmlnode_hide(b); cur_action->is_match=1; } if(!cur_action->is_match) break; log_debug(ZONE,"MATCH!"); } else if(j_strcmp(xmlnode_get_name(cur),"show")==0) { xmlnode sh=cur; session s; if(m->packet->to->resource!=NULL) s=js_session_get(m->user,m->packet->to->resource); else s=js_session_primary(m->user); cur_action->is_match=0; for(;sh!=NULL;sh=xmlnode_get_tag(rules,"show")) { char *show=xmlnode_get_data(sh); log_debug(ZONE,"checking show: %s",show); if(cur_action->is_match||show==NULL||s==NULL||j_strcmp(show,xmlnode_get_tag_data(s->presence,"show"))!=0) { log_debug(ZONE,"not a match"); if(cur==sh)cur=xmlnode_get_nextsibling(cur); xmlnode_hide(sh); continue; } if(cur==sh)cur=xmlnode_get_nextsibling(cur); xmlnode_hide(sh); cur_action->is_match=1; } if(!cur_action->is_match) break; log_debug(ZONE,"MATCH!"); } else if(j_strcmp(xmlnode_get_name(cur),"type")==0) { xmlnode t=cur; char norm[7]="normal\0"; char *xtype=xmlnode_get_attrib(jp->x,"type"); if(m->packet->type == JPACKET_IQ) break; log_debug(ZONE,"checking type"); if(xtype==NULL) xtype=norm; cur_action->is_match=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -