- Mitglied seit
- 30 Jun 2004
- Beiträge
- 12,882
- Punkte für Reaktionen
- 0
- Punkte
- 0
Beim Kompilieren der app_ldap.c bekomme ich die Fehlermeldung:
Kann da ein C-Spezi mal bitte einen Blick drauf werden, was das sein kann ? Die Fehlerstelle Bereich 87/88 habe ich gekennzeichnet.
Meine C-Kenntnisse sind nicht wirklich die besten. Danke im voraus !
Das Ganze stammt von dieser Webseite: http://www.mezzo.net/asterisk/app_ldap.html
Code:
gcc -pipe -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -g -Iinclude -I../include -D_REENTRANT -D_GNU_SOURCE -O6 -march=i686 -DASTERISK_VERSION=\"CVS-HEAD-05/30/05-18:32:20\" -DASTERISK_VERSION_NUM=999999 -DINSTALL_PREFIX=\"\" -DASTETCDIR=\"/etc/asterisk\" -DASTLIBDIR=\"/usr/lib/asterisk\" -DASTVARLIBDIR=\"/var/lib/asterisk\" -DASTVARRUNDIR=\"/var/run\" -DASTSPOOLDIR=\"/var/spool/asterisk\" -DASTLOGDIR=\"/var/log/asterisk\" -DASTCONFPATH=\"/etc/asterisk/asterisk.conf\" -DASTMODDIR=\"/usr/lib/asterisk/modules\" -DASTAGIDIR=\"/var/lib/asterisk/agi-bin\" -DBUSYDETECT_MARTIN -fomit-frame-pointer -fPIC -c -o app_ldap.o app_ldap.c
app_ldap.c: In function `get_exec':
app_ldap.c:87: parse error before `struct'
app_ldap.c:88: `cfg' undeclared (first use in this function)
app_ldap.c:88: (Each undeclared identifier is reported only once
app_ldap.c:88: for each function it appears in.)
make[1]: *** [app_ldap.o] Error 1
make[1]: Leaving directory `/usr/src/asterisk/apps'
make: *** [subdirs] Error 1
Kann da ein C-Spezi mal bitte einen Blick drauf werden, was das sein kann ? Die Fehlerstelle Bereich 87/88 habe ich gekennzeichnet.
Meine C-Kenntnisse sind nicht wirklich die besten. Danke im voraus !
Code:
/*
* Asterisk -- A telephony toolkit for Unix.
*
* LDAP Directory lookup function
*
* Copyright (C) 2004 Sven Slezak <[email protected]>
* Version: 0.9.3
* http://www.mezzo.net/asterisk
*
*/
#include <sys/types.h>
#include <asterisk/options.h>
#include <asterisk/file.h>
#include <asterisk/logger.h>
#include <asterisk/channel.h>
#include <asterisk/pbx.h>
#include <asterisk/module.h>
#include <asterisk/astdb.h>
#include <asterisk/lock.h>
#include <asterisk/config.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <iconv.h>
#include <ldap.h>
#define LDAP_CONFIG "ldap.conf"
int ldap_lookup(char *host, int port, char *user, char *pass, char *base, char *scope, char *filter, char *attribute, char*result);
int strconvert(const char *incharset, const char *outcharset, char *in, char *out);
char *strtrim (char *string);
static char *tdesc = "LDAP directory lookup function for Asterisk extension logic.";
static char *g_descrip =
" LDAPget(varname=config-file-section/key): Retrieves a value from an LDAP\n"
"directory and stores it in the given variable. Always returns 0. If the\n"
"requested key is not found, jumps to priority n+101 if available.\n";
static char *g_app = "LDAPget";
static char *g_synopsis = "Retrieve a value from an ldap directory";
STANDARD_LOCAL_USER;
LOCAL_USER_DECL;
static int get_exec (struct ast_channel *chan, void *data)
{
int arglen;
char *argv, *varname, *config, *keys, *key, *tail;
char result[2048];
char *result_conv;
int port = LDAP_PORT;
char *temp, *host, *user, *pass, *base, *scope, *filter, *_filter, *attribute,
*convert_from = NULL, *convert_to = NULL;
arglen = strlen (data);
argv = alloca (arglen + 1);
if(!argv) {
ast_log (LOG_DEBUG, "Memory allocation failed\n");
return 0;
}
memcpy (argv, data, arglen+1);
if(strchr (argv, '=') && strchr (argv, '/')) {
varname = strsep (&argv, "=");
config = strsep (&argv, "/");
keys = strsep (&argv, "\0");
if (!varname || !config || !keys) {
ast_log (LOG_DEBUG, "Ignoring; Syntax error in argument\n");
return 0;
}
if(option_verbose > 2)
ast_verbose (VERBOSE_PREFIX_3 "LDAPget: varname=%s, config-section=%s, keys=%s\n", varname, config, keys);
} else {
ast_log (LOG_DEBUG, "Ignoring, no parameters\n");
return 0;
}
******
HIER IN DIESEM BEREICH MUSS DER FEHLER LIEGEN !
******
struct ast_config *cfg;
cfg = ast_load(LDAP_CONFIG);
if(!cfg) {
ast_log(LOG_WARNING, "No such configuration file %s\n", LDAP_CONFIG);
return -1;
}
if(!(host = ast_variable_retrieve(cfg, config, "host"))) {
host = "localhost";
}
if((temp = ast_variable_retrieve(cfg, config, "port"))) {
port = atoi(temp);;
}
user = ast_variable_retrieve(cfg, config, "user");
pass = ast_variable_retrieve(cfg, config, "pass");
base = ast_variable_retrieve(cfg, config, "base");
if (!(scope = ast_variable_retrieve(cfg, config, "scope"))) {
scope = "sub";
}
if(!(_filter = ast_variable_retrieve(cfg, config, "filter"))) {
_filter = "(&(objectClass=person)(telephoneNumber=%s))";
}
if(!(attribute = ast_variable_retrieve(cfg, config, "attribute"))) {
attribute = "cn";
}
if((temp = ast_variable_retrieve(cfg, config, "convert"))) {
//convert = ast_true(temp);
if(strchr(temp, ',')) {
convert_from = strtrim(strsep(&temp, ","));
convert_to = strtrim(strsep(&temp, "\0"));
} else {
ast_log(LOG_WARNING, "syntax error: convert = <source-charset>,<destination charset>\n");
}
}
filter = (char *)alloca((strlen(_filter)+strlen(keys))*sizeof(char));
memcpy(filter, _filter, strlen(_filter)+1);
while((key = strsep(&keys, "|")) != NULL) {
if((tail = strstr(filter, "%s")) != NULL) {
//key = strtrim(key);
memmove(tail+strlen(key), tail+2, strlen(tail+2)+1);
memcpy(tail, key, strlen(key));
}
}
if(option_verbose > 2)
ast_verbose (VERBOSE_PREFIX_3 "LDAPget: ldap://%s/%s?%s?%s?%s\n", host, base, attribute, scope, filter);
if(ldap_lookup(host, port, user, pass, base, scope, filter, attribute, result)) {
if(convert_from) {
if(option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "LDAPget: convert: %s -> %s\n", convert_from, convert_to);
result_conv = alloca(strlen(result) * 2);
strconvert(convert_from, convert_to, result, result_conv);
strcpy(result, result_conv);
}
pbx_builtin_setvar_helper(chan, varname, result);
if(option_verbose > 2)
ast_verbose (VERBOSE_PREFIX_3 "LDAPget: set variable %s to %s\n", varname, result);
} else {
if (option_verbose > 2)
ast_verbose (VERBOSE_PREFIX_3 "LDAPget: Value not found in directory.\n");
/* Send the call to n+101 priority, where n is the current priority */
#if ASTERISK_VERSION_NUM == 999999
if (ast_exists_extension (chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num))
#else
if (ast_exists_extension (chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
#endif
chan->priority += 100;
}
return 0;
}
int unload_module (void) {
int retval;
STANDARD_HANGUP_LOCALUSERS;
retval = ast_unregister_application (g_app);
return retval;
}
int load_module (void) {
int retval;
retval = ast_register_application (g_app, get_exec, g_synopsis, g_descrip);
return retval;
}
char *description (void) {
return tdesc;
}
int usecount (void) {
int res;
STANDARD_USECOUNT (res);
return res;
}
char *key () {
return ASTERISK_GPL_KEY;
}
int ldap_lookup(char *host, int port, char *user, char *pass, char *base, char *scope, char *filter, char *attribute, char*result) {
char *attrs[] = { NULL };
char **values;
LDAP *ld;
LDAPMessage *res, *entry;
int ret, ldap_scope = LDAP_SCOPE_SUBTREE;
ld = ldap_init(host, port);
if(!ld) {
ast_log (LOG_DEBUG, "LDAPget: unable to initialize ldap connection to %s\n", host);
return 0;
}
if(user) {
if (option_verbose > 2)
ast_verbose (VERBOSE_PREFIX_3 "LDAPget: bind to %s as %s\n", host, user);
ldap_simple_bind(ld, user, pass);
}
if(strncmp(scope,"sub",3)==0) {
ldap_scope = LDAP_SCOPE_SUBTREE;
} else if(strncmp(scope,"base",4)==0) {
ldap_scope = LDAP_SCOPE_BASE;
} else if(strncmp(scope,"one",3)==0) {
ldap_scope = LDAP_SCOPE_ONELEVEL;
}
ret = ldap_search_s(ld, base, ldap_scope, filter, attrs, 0, &res);
if(ret) {
ast_log (LOG_DEBUG, "LDAPget: search failed: %s\n", ldap_err2string(ret));
ldap_unbind(ld);
return 0;
}
entry = ldap_first_entry(ld, res);
if(!entry) {
ldap_unbind(ld);
return 0;
}
values = ldap_get_values(ld, entry, attribute);
if(values && values[0]) {
memset(result, 0, strlen(values[0]));
strncpy(result, values[0], strlen(values[0]));
result[strlen(values[0])] = '\0';
if (option_verbose > 2)
ast_verbose (VERBOSE_PREFIX_3 "LDAPget: %s=%s\n",attribute, result);
}
ldap_unbind(ld);
return 1;
}
int strconvert(const char *incharset, const char *outcharset, char *in, char *out) {
iconv_t cd;
size_t incount, outcount, result;
incount = outcount = strlen(in) * 2;
cd = iconv_open(outcharset, incharset);
if(cd == (iconv_t) -1) {
if(errno == EINVAL) ast_log(LOG_DEBUG, "conversion from '%s' to '%s' not available", incharset, outcharset);
*out = L'\0';
return -1;
}
result = iconv(cd, &in, &incount, &out, &outcount);
iconv_close(cd);
out[strlen(out)] = '\0';
return 1;
}
char *strtrim(char *str) {
char *p, c;
p = strchr(str, '\0');
while (--p >= str && isspace(*p));
p[1] = '\0';
while ((c = *str++) != '\0' && isspace(c));
return str - 1;
}
Das Ganze stammt von dieser Webseite: http://www.mezzo.net/asterisk/app_ldap.html