jabberd2  2.7.0
db.c
Go to the documentation of this file.
1 /*
2  * jabberd - Jabber Open Source Server
3  * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney,
4  * Ryan Eatmon, Robert Norris
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
19  */
20 
21 /*
22  * this is a minimal sx plugin that hacks the "jabber:server:dialback"
23  * onto outgoing connections and adds "urn:xmpp:features:dialback" feature
24  */
25 
26 #include "s2s.h"
27 
28 #define S2S_DB_NS_DECL " xmlns:db='" uri_DIALBACK "'"
29 #define S2S_DB_NS_DECL_LEN (uri_DIALBACK_L + 12)
30 
31 static void _s2s_db_header(sx_t s, sx_plugin_t p, sx_buf_t buf) {
32 
33  if(!(s->flags & S2S_DB_HEADER))
34  return;
35 
36  log_debug(ZONE, "hacking dialback namespace decl onto stream header");
37 
38  /* get enough space */
40 
41  /* overwrite the trailing ">" with a decl followed by a new ">" */
42  memcpy(&buf->data[buf->len - 1], S2S_DB_NS_DECL ">", S2S_DB_NS_DECL_LEN+1);
43  buf->len += S2S_DB_NS_DECL_LEN;
44 }
45 
47 static void _s2s_db_features(sx_t s, sx_plugin_t p, nad_t nad) {
48  int ns;
49 
50  ns = nad_add_namespace(nad, uri_URN_DIALBACK, NULL);
51  nad_append_elem(nad, ns, "dialback", 1);
52  nad_append_elem(nad, -1, "required", 2);
53 }
54 
55 int s2s_db_init(sx_env_t env, sx_plugin_t p, va_list args) {
56  log_debug(ZONE, "initialising dialback sx plugin");
57 
60 
61  return 0;
62 }
Definition: nad.h:93
Definition: sx.h:113
unsigned int flags
Definition: sx.h:276
int s2s_db_init(sx_env_t env, sx_plugin_t p, va_list args)
Definition: db.c:55
void(* features)(sx_t s, sx_plugin_t p, nad_t nad)
Definition: sx.h:373
an environment
Definition: sx.h:382
#define S2S_DB_NS_DECL
Definition: db.c:28
a plugin
Definition: sx.h:347
int nad_add_namespace(nad_t nad, const char *uri, const char *prefix)
bring a new namespace into scope
Definition: nad.c:778
int nad_append_elem(nad_t nad, int ns, const char *name, int depth)
create a new elem on the list
Definition: nad.c:711
#define S2S_DB_HEADER
Definition: s2s.h:388
void _sx_buffer_alloc_margin(sx_buf_t buf, int before, int after)
utility: ensure a certain amount of allocated space adjacent to buf->data
Definition: sx.c:262
holds the state for a single stream
Definition: sx.h:253
char * data
Definition: sx.h:114
#define S2S_DB_NS_DECL_LEN
Definition: db.c:29
#define log_debug(...)
Definition: log.h:65
static void _s2s_db_header(sx_t s, sx_plugin_t p, sx_buf_t buf)
Definition: db.c:31
unsigned int len
Definition: sx.h:115
#define uri_URN_DIALBACK
Definition: uri.h:39
static void _s2s_db_features(sx_t s, sx_plugin_t p, nad_t nad)
sx features callback
Definition: db.c:47
#define ZONE
Definition: mio_impl.h:76
void(* header)(sx_t s, sx_plugin_t p, sx_buf_t buf)
Definition: sx.h:370