00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00021 #include <stdlib.h>
00022 #include <strings.h>
00023
00024 #ifndef _V2L_JABBER2
00025 #include <jabberd.h>
00026 #else
00027 #include "../util/util.h"
00028
00029 #define log_warn log_debug
00030 #define log_error log_debug
00031 typedef pool_t pool;
00032 #endif
00033
00034 #include <v2l_config.h>
00035 #include <v2l_conn.h>
00036
00040 static char *_v2l_config_get_tag (T_CONF conn_base, const char *tag);
00041
00042
00043
00044 int
00045 v2l_config_init (v2l_Config *self, T_CONF cfgroot)
00046 {
00047 T_CONF conn_base;
00048 const char *portstr;
00049
00050 if (!cfgroot)
00051 {
00052 log_error (ZONE, "xdb_v2l configuration not present");
00053 return 0;
00054 }
00055
00056 #ifndef _V2L_JABBER2
00057
00058 conn_base = xmlnode_get_tag (cfgroot, "connection");
00059
00060 if (conn_base == NULL)
00061 {
00062 log_error (ZONE,"<connection> tag is not present");
00063 return 0;
00064 }
00065 #else
00066 conn_base = cfgroot;
00067 #endif
00068
00069 self->host = _v2l_config_get_tag (conn_base, "host");
00070
00071 if (self->host == NULL)
00072 {
00073 log_error (ZONE, "LDAP server is not specified");
00074 return 0;
00075 }
00076
00077 portstr = _v2l_config_get_tag (conn_base, "port");
00078 self->port = portstr != NULL ? atoi (portstr) : LDAP_PORT;
00079
00080 self->suffix = _v2l_config_get_tag (conn_base, "suffix");
00081
00082 if (self->suffix == NULL)
00083 {
00084 log_error (ZONE, "LDAP suffix is not specified");
00085 return 0;
00086 }
00087
00088 self->filter = _v2l_config_get_tag (conn_base, "filter");
00089
00090 if (self->filter == NULL)
00091 {
00092 log_error (ZONE, "LDAP search filter is not specified");
00093 return 0;
00094 }
00095
00096 self->binddn = _v2l_config_get_tag (conn_base, "binddn");
00097
00098 if (self->binddn == NULL)
00099 {
00100 log_error (ZONE, "LDAP jabber admin dn is not specified");
00101 return 0;
00102 }
00103
00104 self->bindpw = _v2l_config_get_tag (conn_base, "bindpw");
00105
00106 if (self->bindpw == NULL)
00107 {
00108 log_error (ZONE,
00109 "LDAP jabber admin password is not specified");
00110 return 0;
00111 }
00112
00113 self->confpath = _v2l_config_get_tag (conn_base, "tpl");
00114
00115 if (self->confpath == NULL)
00116 {
00117 log_error (ZONE,
00118 "Path to vCard <->LDAP is not specified");
00119 return 0;
00120 }
00121
00122 self->irishack = _v2l_config_get_tag (conn_base, "irishack") != NULL;
00123
00124 self->poolref = pool_new ();
00125
00126 if (self->poolref == NULL)
00127 {
00128 log_error (ZONE, "Cannot create pool");
00129 return 0;
00130 }
00131
00132
00133 log_debug (ZONE, "LDAP server: %s / port : %d", self->host, self->port);
00134
00135 self->master_conn = v2l_get_master_conn (self);
00136
00137 if (self->master_conn == NULL)
00138 {
00139 log_error (ZONE,
00140 "Unable to create the LDAP main connection");
00141 return 0;
00142 }
00143
00144 return 1;
00145 }
00146
00147 void
00148 v2l_config_shutdown (v2l_Config *self)
00149 {
00150 if (self != NULL && self->master_conn != NULL)
00151 {
00152 v2l_free_allconn ();
00153 ldap_unbind_s (self->master_conn->ld);
00154 pool_free (self->master_conn->poolref);
00155 pool_free (self->poolref);
00156 }
00157 }
00158
00159
00160
00161 static char *
00162 _v2l_config_get_tag (T_CONF conn_base, const char *tag)
00163 {
00164 #ifndef _V2L_JABBER2
00165 xmlnode tmp;
00166
00167 tmp = xmlnode_get_tag (conn_base, tag);
00168
00169 if (tmp == NULL)
00170 {
00171 return NULL;
00172 }
00173
00174 return (char *) xmlnode_get_data (xmlnode_get_firstchild (tmp));
00175 #else
00176 char str[32] = "v2l.";
00177
00178 return config_get_one (conn_base, strncat (str, tag, 27), 0);
00179 #endif
00180 }