jabberd2
2.2.16
|
00001 /* 00002 * jabberd - Jabber Open Source Server 00003 * Copyright (c) 2009 Tomasz Sterna 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 00018 */ 00019 00020 #include "sm.h" 00021 00022 /* 00023 * XEP-0163 is some lunatic nightmare... 00024 * 00025 * If you want it - YOU implement it! 00026 */ 00027 00033 #define uri_PUBSUB "http://jabber.org/protocol/pubsub" 00034 static int ns_PUBSUB = 0; 00035 00036 static mod_ret_t _pep_in_sess(mod_instance_t mi, sess_t sess, pkt_t pkt) { 00037 int ns, elem; 00038 00039 /* only handle private sets and gets */ 00040 if((pkt->type != pkt_IQ && pkt->type != pkt_IQ_SET) || pkt->ns != ns_PUBSUB) 00041 return mod_PASS; 00042 00043 /* we're only interested in no to, to our host, or to us */ 00044 if(pkt->to != NULL && jid_compare_user(sess->jid, pkt->to) != 0 && strcmp(sess->jid->domain, jid_user(pkt->to)) != 0) 00045 return mod_PASS; 00046 00047 ns = nad_find_scoped_namespace(pkt->nad, uri_PUBSUB, NULL); 00048 elem = nad_find_elem(pkt->nad, 1, ns, "pubsub", 1); 00049 00050 log_debug(ZONE, "_pep_in_sess() %d %d", ns, elem); 00051 return mod_PASS; 00052 } 00053 00054 static mod_ret_t _pep_out_sess(mod_instance_t mi, sess_t sess, pkt_t pkt) { 00055 /* add pep identity to disco results from bare JID */ 00056 if(!(pkt->type & pkt_IQ) || pkt->ns != ns_DISCO_INFO || (pkt->from != NULL && strcmp(jid_user(sess->jid), jid_full(pkt->from)))) 00057 return mod_PASS; 00058 00059 /* add PEP identity */ 00060 nad_append_elem(pkt->nad, -1, "identity", 3); 00061 nad_append_attr(pkt->nad, -1, "category", "pubsub"); 00062 nad_append_attr(pkt->nad, -1, "type", "pep"); 00063 00064 nad_append_elem(pkt->nad, -1, "feature", 3); 00065 nad_append_attr(pkt->nad, -1, "var", uri_PUBSUB "#access-presence"); 00066 nad_append_elem(pkt->nad, -1, "feature", 3); 00067 nad_append_attr(pkt->nad, -1, "var", uri_PUBSUB "#auto-create"); 00068 nad_append_elem(pkt->nad, -1, "feature", 3); 00069 nad_append_attr(pkt->nad, -1, "var", uri_PUBSUB "#auto-subscribe"); 00070 nad_append_elem(pkt->nad, -1, "feature", 3); 00071 nad_append_attr(pkt->nad, -1, "var", uri_PUBSUB "#filtered-notifications"); 00072 nad_append_elem(pkt->nad, -1, "feature", 3); 00073 nad_append_attr(pkt->nad, -1, "var", uri_PUBSUB "#publish"); 00074 00075 return mod_PASS; 00076 } 00077 00078 DLLEXPORT int module_init(mod_instance_t mi, char *arg) { 00079 module_t mod = mi->mod; 00080 00081 if(mod->init) return 0; 00082 00083 mod->in_sess = _pep_in_sess; 00084 mod->out_sess = _pep_out_sess; 00085 00086 ns_PUBSUB = sm_register_ns(mod->mm->sm, uri_PUBSUB); 00087 feature_register(mod->mm->sm, uri_PUBSUB); 00088 00089 return 0; 00090 }