Reads LDAP<->vCard bindings in an external file.
[vcard2ldap.git] / src / v2l_config.c
blob96221eb3bf67288cf976fc99a5238e7e1df2bc87
1 /*
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.
17 #include <stdlib.h>
18 #include <strings.h>
19 #include <jabberd.h>
20 #include <v2l_config.h>
21 #include <v2l_conn.h>
23 static char *_v2l_config_get_tag(xmlnode conn_base, const char *tag);
25 int
26 v2l_config_init (v2l_Config *self, xmlnode cfgroot)
28 xmlnode conn_base;
29 const char *portstr;
31 if (!cfgroot)
33 log_error(ZONE, "xdb_v2l configuration not present");
34 return 0;
37 /* Have a look in the XML configuration data for connection information. */
38 conn_base = xmlnode_get_tag (cfgroot, "connection");
40 if (conn_base == NULL)
42 log_error(ZONE,"<connection> tag is not present");
43 return 0;
46 self->host = _v2l_config_get_tag (conn_base, "host");
48 if (self->host == NULL)
50 log_error (ZONE, "LDAP server is not specified");
51 return 0;
54 portstr = _v2l_config_get_tag (conn_base, "port");
55 self->port = portstr != NULL ? atoi (portstr) : LDAP_PORT;
57 self->suffix = _v2l_config_get_tag (conn_base, "suffix");
59 if (self->suffix == NULL)
61 log_error (ZONE, "LDAP suffix is not specified");
62 return 0;
65 self->uniqattr = _v2l_config_get_tag (conn_base, "uniqattr");
67 if (self->uniqattr == NULL)
69 log_error (ZONE, "LDAP unique attribute is not specified");
70 return 0;
73 self->binddn = _v2l_config_get_tag (conn_base, "binddn");
75 if (self->binddn == NULL)
77 log_error (ZONE, "LDAP jabber admin dn is not specified");
78 return 0;
81 self->bindpw = _v2l_config_get_tag (conn_base, "bindpw");
83 if (self->bindpw == NULL)
85 log_error (ZONE,
86 "LDAP jabber admin password is not specified");
87 return 0;
90 self->confpath = _v2l_config_get_tag (conn_base, "tpl");
92 if (self->confpath == NULL)
94 log_error (ZONE,
95 "Path to vCard <->LDAP is not specified");
96 return 0;
99 self->poolref = pool_new ();
101 if (self->poolref == NULL)
103 log_error (ZONE, "Cannot create pool");
104 return 0;
107 /* Get a handle to an LDAP connection. */
108 log_debug (ZONE, "LDAP server: %s / port : %d", self->host, self->port);
110 self->master_conn = v2l_get_master_conn (self);
112 if (self->master_conn == NULL)
114 log_error (ZONE,
115 "Unable to create the LDAP main connection");
116 return 0;
119 return 1;
122 static char *
123 _v2l_config_get_tag(xmlnode conn_base, const char *tag)
125 xmlnode tmp;
127 tmp = xmlnode_get_tag (conn_base, tag);
129 if (tmp == NULL)
131 return NULL;
134 return (char *) xmlnode_get_data (xmlnode_get_firstchild (tmp));