jabberd2  2.7.0
bind.c
Go to the documentation of this file.
1 /*
2  * jabberd - Jabber Open Source Server
3  * Copyright (c) 2002-2003 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 
28 #include "c2s.h"
29 
31 static void _bind_features(sx_t s, sx_plugin_t p, nad_t nad) {
32  int ns;
33 
34  if(s->auth_id == NULL) {
35  c2s_t c2s;
36  host_t host;
37 
38  log_debug(ZONE, "not auth'd, offering auth and register");
39 
40  ns = nad_add_namespace(nad, uri_IQAUTH, NULL);
41  nad_append_elem(nad, ns, "auth", 1);
42 
43  c2s = (c2s_t) p->private;
44  host = xhash_get(c2s->hosts, s->req_to);
45  if(! host) host = c2s->vhost;
46  if(host && host->ar_register_enable) {
47  ns = nad_add_namespace(nad, uri_IQREGISTER, NULL);
48  nad_append_elem(nad, ns, "register", 1);
49  }
50  } else {
51  log_debug(ZONE, "auth'd, offering resource bind and session");
52 
53  ns = nad_add_namespace(nad, uri_BIND, NULL);
54  nad_append_elem(nad, ns, "bind", 1);
55  nad_append_elem(nad, -1, "required", 2);
56  nad->scope = ns;
57  nad_append_elem(nad, ns, "unbind", 1);
58 #ifdef ENABLE_SUPERSEDED
59  ns = nad_add_namespace(nad, uri_XSESSION, NULL);
60  nad_append_elem(nad, ns, "session", 1);
61 #endif
62  ns = nad_add_namespace(nad, uri_ROSTERVER, NULL);
63  nad_append_elem(nad, ns, "ver", 1);
64  }
65 }
66 
69 int bind_init(sx_env_t env, sx_plugin_t p, va_list args) {
70  c2s_t c2s;
71 
72  log_debug(ZONE, "initialising resource bind sx plugin");
73 
74  c2s = va_arg(args, c2s_t);
75 
77  p->private = (void *) c2s;
78 
79  return 0;
80 }
Definition: nad.h:93
#define uri_IQREGISTER
Definition: uri.h:49
int ar_register_enable
registration
Definition: c2s.h:151
c2s_t c2s
Definition: c2s.h:338
const char * req_to
Definition: sx.h:282
void(* features)(sx_t s, sx_plugin_t p, nad_t nad)
Definition: sx.h:373
an environment
Definition: sx.h:382
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
int bind_init(sx_env_t env, sx_plugin_t p, va_list args)
plugin initialiser
Definition: bind.c:69
#define uri_BIND
Definition: uri.h:42
#define uri_IQAUTH
Definition: uri.h:48
#define uri_XSESSION
Definition: uri.h:43
holds the state for a single stream
Definition: sx.h:253
struct c2s_st * c2s_t
Definition: c2s.h:53
Definition: c2s.h:124
xht hosts
hosts mapping
Definition: c2s.h:311
const char * auth_id
Definition: sx.h:334
#define log_debug(...)
Definition: log.h:65
Definition: c2s.h:157
host_t vhost
Definition: c2s.h:312
int scope
Definition: nad.h:107
void * private
Definition: sx.h:354
void * xhash_get(xht h, const char *key)
Definition: xhash.c:184
#define ZONE
Definition: mio_impl.h:76
#define uri_ROSTERVER
Definition: uri.h:58
static void _bind_features(sx_t s, sx_plugin_t p, nad_t nad)
sx features callback
Definition: bind.c:31