2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 \brief Module skeleton.
22 node [shape = plaintext, fontname = Helvetica, fontsize = 12]
23 server [shape = egg, label = jabberd ]
25 label =<<table href="v2l__vcard_8h.html">
26 <tr><td bgcolor="gray">v2l_vcard</td></tr>
27 <tr><td>XML vCard Handling</td></tr>
31 label =<<table href="v2l__config_8h.html">
32 <tr><td bgcolor="gray">v2l_config</td></tr>
33 <tr><td>Config handling package</td></tr>
37 label =<<table href="v2l__conn_8h.html">
38 <tr><td bgcolor="gray">v2l_conn</td></tr>
39 <tr><td>LDAP-level package</td></tr>
53 #include <v2l_config.h>
55 #include <v2l_vcard.h>
57 #define LOG_ERROR_MEM log_error (ZONE, "Unable to allocate memory")
59 static result
_v2l_packets_handler (instance i
, dpacket p
, void *args
);
60 static int _v2l_check_attr_value (xmlnode node
, char *attr_name
,
62 static void _v2l_shutdown (void *arg
);
64 /*! \brief Module entry point.
65 See jabberd14 API docs for details.
71 xdb_v2l (instance i
, xmlnode x
)
73 xdbcache xc
= NULL
; /* for config request */
74 v2l_Config
*self
= NULL
;
76 log_debug (ZONE
, "Loading xdb_v2l");
78 self
= (v2l_Config
*) pmalloco (i
->p
, sizeof (*self
));
87 /* Load config from xdb */
89 self
->config
= xdb_get (xc
, jid_new (xmlnode_pool (x
), "config@-internal"),
90 "jabberd:xdb_v2l:config");
93 if (!v2l_config_init (self
, self
->config
))
95 /* do no try to go on with a badly configured ldap component */
99 register_phandler (i
, o_DELIVER
, _v2l_packets_handler
, (void *) self
);
100 register_shutdown (_v2l_shutdown
, (void *) self
);
102 log_debug (ZONE
, "xdb_v2l has been successfully initialized");
105 /*! \brief shutdown and cleanup callback
106 See jabberd14 API docs for details.
109 _v2l_shutdown (void *arg
)
111 v2l_config_shutdown ((v2l_Config
*) arg
);
114 /*! \brief Main callback. Handle xdb packets
115 See jabberd14 API docs for details.
118 _v2l_packets_handler (instance i
, dpacket p
, void *args
)
120 v2l_Config
*self
= (v2l_Config
*) args
;
121 v2l_LdapConn
*user_conn
;
124 if ((p
== NULL
) || (p
->x
== NULL
) || (p
->id
== NULL
))
126 log_error (ZONE
, "malformed xdb packet");
130 if (_v2l_check_attr_value (p
->x
, "type", "error"))
133 log_warn (ZONE
, "xdb_v2l received an error packet");
137 if (!_v2l_check_attr_value (p
->x
, "ns", NS_VCARD
))
140 "xdb_v2l received a packet for other namespace than NS_VCARD");
144 user_conn
= v2l_get_conn (self
, p
->id
->user
);
146 if (user_conn
== NULL
)
148 log_error (ZONE
, "Unable to create connection for \"%s\" user",
153 if (_v2l_check_attr_value (p
->x
, "type", "set"))
155 xmlnode child
= xmlnode_get_firstchild (p
->x
);
157 if (v2l_vcard_set (self
, user_conn
, child
) != 1)
164 xmlnode data
= v2l_vcard_get (self
, user_conn
);
168 xmlnode_insert_tag_node (p
->x
, data
);
173 /* making XML reply */
174 xmlnode_put_attrib (p
->x
, "type", "result");
175 xmlnode_put_attrib (p
->x
, "to", xmlnode_get_attrib (p
->x
, "from"));
176 xmlnode_put_attrib (p
->x
, "from", jid_full (p
->id
));
178 dp
= dpacket_new (p
->x
);
192 _v2l_check_attr_value (xmlnode node
, char *attr_name
, char *value
)
194 if ((node
== NULL
) || (attr_name
== NULL
) || (value
== NULL
))
196 log_debug (ZONE
, "_v2l_check_attr_value () parameters are not valid");
200 return strncmp (xmlnode_get_attrib (node
, attr_name
), value
,
201 strlen (value
)) == 0;