jabberd2  2.2.16
s2s/db.c
Go to the documentation of this file.
00001 /*
00002  * jabberd - Jabber Open Source Server
00003  * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney,
00004  *                    Ryan Eatmon, Robert Norris
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
00019  */
00020 
00021 /*
00022  * this is a minimal sx plugin that hacks the "jabber:server:dialback"
00023  * onto outgoing connections and adds "urn:xmpp:features:dialback" feature
00024  */
00025 
00026 #include "s2s.h"
00027 
00028 #define S2S_DB_NS_DECL      " xmlns:db='" uri_DIALBACK "'"
00029 #define S2S_DB_NS_DECL_LEN  (uri_DIALBACK_L + 12)
00030 
00031 static void _s2s_db_header(sx_t s, sx_plugin_t p, sx_buf_t buf) {
00032 
00033     if(!(s->flags & S2S_DB_HEADER))
00034         return;
00035 
00036     log_debug(ZONE, "hacking dialback namespace decl onto stream header");
00037 
00038     /* get enough space */
00039     _sx_buffer_alloc_margin(buf, 0, S2S_DB_NS_DECL_LEN + 2);
00040 
00041     /* overwrite the trailing ">" with a decl followed by a new ">" */
00042     memcpy(&buf->data[buf->len - 1], S2S_DB_NS_DECL ">", S2S_DB_NS_DECL_LEN+1);
00043     buf->len += S2S_DB_NS_DECL_LEN;
00044 }
00045 
00047 static void _s2s_db_features(sx_t s, sx_plugin_t p, nad_t nad) {
00048     int ns;
00049 
00050     ns = nad_add_namespace(nad, uri_URN_DIALBACK, NULL);
00051     nad_append_elem(nad, ns, "dialback", 1);
00052     nad_append_elem(nad, -1, "required", 2);
00053 }
00054 
00055 int s2s_db_init(sx_env_t env, sx_plugin_t p, va_list args) {
00056     log_debug(ZONE, "initialising dialback sx plugin");
00057 
00058     p->header = _s2s_db_header;
00059     p->features = _s2s_db_features;
00060 
00061     return 0;
00062 }