Ergebnis 1 bis 3 von 3

Thema: [Gelöst] Problem beim Compilieren von app_ldap

  1. #1
    Grandstream-Guru Avatar von betateilchen
    Registriert seit
    30.06.2004
    Ort
    am Letzenberg
    Beiträge
    12.888

    [Gelöst] Problem beim Compilieren von app_ldap

    Beim Kompilieren der app_ldap.c bekomme ich die Fehlermeldung:

    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 &#40;C&#41; 2004 Sven Slezak <sunny@mezzo.net>
     * Version&#58; 0.9.3
     * http&#58;//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&#40;char *host, int port, char *user, char *pass, char *base, char *scope, char *filter, char *attribute, char*result&#41;;
    int strconvert&#40;const char *incharset, const char *outcharset, char *in, char *out&#41;;
    char *strtrim &#40;char *string&#41;;
    
    static char *tdesc = "LDAP directory lookup function for Asterisk extension logic.";
    
    static char *g_descrip =
            "  LDAPget&#40;varname=config-file-section/key&#41;&#58; 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 &#40;struct ast_channel *chan, void *data&#41;
    &#123;
            int arglen;
            char *argv, *varname, *config, *keys, *key, *tail;
            char result&#91;2048&#93;;
            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 &#40;data&#41;;
            argv = alloca &#40;arglen + 1&#41;;
            if&#40;!argv&#41; &#123;
                    ast_log &#40;LOG_DEBUG, "Memory allocation failed\n"&#41;;
                    return 0;
            &#125;
            memcpy &#40;argv, data, arglen+1&#41;;
    
            if&#40;strchr &#40;argv, '='&#41; && strchr &#40;argv, '/'&#41;&#41; &#123;
                    varname = strsep &#40;&argv, "="&#41;;
                    config = strsep &#40;&argv, "/"&#41;;
                    keys = strsep &#40;&argv, "\0"&#41;;
                    if &#40;!varname || !config || !keys&#41; &#123;
                            ast_log &#40;LOG_DEBUG, "Ignoring; Syntax error in argument\n"&#41;;
                            return 0;
                    &#125;
                    if&#40;option_verbose > 2&#41;
                            ast_verbose &#40;VERBOSE_PREFIX_3 "LDAPget&#58; varname=%s, config-section=%s, keys=%s\n", varname, config, keys&#41;;
            &#125; else &#123;
                    ast_log &#40;LOG_DEBUG, "Ignoring, no parameters\n"&#41;;
                    return 0;
            &#125;
    
    ******
    HIER IN DIESEM BEREICH MUSS DER FEHLER LIEGEN !
    ******
            struct ast_config *cfg;
            cfg = ast_load&#40;LDAP_CONFIG&#41;;
            if&#40;!cfg&#41; &#123;
                    ast_log&#40;LOG_WARNING, "No such configuration file %s\n", LDAP_CONFIG&#41;;
                    return -1;
            &#125;
            if&#40;!&#40;host = ast_variable_retrieve&#40;cfg, config, "host"&#41;&#41;&#41; &#123;
                    host = "localhost";
            &#125;
            if&#40;&#40;temp = ast_variable_retrieve&#40;cfg, config, "port"&#41;&#41;&#41; &#123;
                            port = atoi&#40;temp&#41;;;
            &#125;
            user = ast_variable_retrieve&#40;cfg, config, "user"&#41;;
            pass = ast_variable_retrieve&#40;cfg, config, "pass"&#41;;
            base = ast_variable_retrieve&#40;cfg, config, "base"&#41;;
            if &#40;!&#40;scope = ast_variable_retrieve&#40;cfg, config, "scope"&#41;&#41;&#41; &#123;
                    scope = "sub";
            &#125;
            if&#40;!&#40;_filter = ast_variable_retrieve&#40;cfg, config, "filter"&#41;&#41;&#41; &#123;
                    _filter = "&#40;&&#40;objectClass=person&#41;&#40;telephoneNumber=%s&#41;&#41;";
            &#125;
            if&#40;!&#40;attribute = ast_variable_retrieve&#40;cfg, config, "attribute"&#41;&#41;&#41; &#123;
                    attribute = "cn";
            &#125;
            if&#40;&#40;temp = ast_variable_retrieve&#40;cfg, config, "convert"&#41;&#41;&#41; &#123;
                    //convert = ast_true&#40;temp&#41;;
                    if&#40;strchr&#40;temp, ','&#41;&#41; &#123;
                            convert_from = strtrim&#40;strsep&#40;&temp, ","&#41;&#41;;
                            convert_to = strtrim&#40;strsep&#40;&temp, "\0"&#41;&#41;;
                    &#125; else &#123;
                            ast_log&#40;LOG_WARNING, "syntax error&#58; convert = <source-charset>,<destination charset>\n"&#41;;
                    &#125;
            &#125;
    
            filter = &#40;char *&#41;alloca&#40;&#40;strlen&#40;_filter&#41;+strlen&#40;keys&#41;&#41;*sizeof&#40;char&#41;&#41;;
            memcpy&#40;filter, _filter, strlen&#40;_filter&#41;+1&#41;;
    
            while&#40;&#40;key = strsep&#40;&keys, "|"&#41;&#41; != NULL&#41; &#123;
                    if&#40;&#40;tail = strstr&#40;filter, "%s"&#41;&#41; != NULL&#41; &#123;
                            //key = strtrim&#40;key&#41;;
                            memmove&#40;tail+strlen&#40;key&#41;, tail+2, strlen&#40;tail+2&#41;+1&#41;;
                            memcpy&#40;tail, key, strlen&#40;key&#41;&#41;;
                    &#125;
            &#125;
    
            if&#40;option_verbose > 2&#41;
                    ast_verbose &#40;VERBOSE_PREFIX_3 "LDAPget&#58; ldap&#58;//%s/%s?%s?%s?%s\n", host, base, attribute, scope, filter&#41;;
    
            if&#40;ldap_lookup&#40;host, port, user, pass, base, scope, filter, attribute, result&#41;&#41; &#123;
    
                    if&#40;convert_from&#41; &#123;
                            if&#40;option_verbose > 2&#41;
                                    ast_verbose&#40;VERBOSE_PREFIX_3 "LDAPget&#58; convert&#58; %s -> %s\n", convert_from, convert_to&#41;;
                            result_conv = alloca&#40;strlen&#40;result&#41; * 2&#41;;
                            strconvert&#40;convert_from, convert_to, result, result_conv&#41;;
                            strcpy&#40;result, result_conv&#41;;
                    &#125;
                    pbx_builtin_setvar_helper&#40;chan, varname, result&#41;;
                    if&#40;option_verbose > 2&#41;
                            ast_verbose &#40;VERBOSE_PREFIX_3 "LDAPget&#58; set variable %s to %s\n", varname, result&#41;;
    
            &#125; else &#123;
                    if &#40;option_verbose > 2&#41;
                            ast_verbose &#40;VERBOSE_PREFIX_3 "LDAPget&#58; Value not found in directory.\n"&#41;;
                    /* Send the call to n+101 priority, where n is the current priority */
    #if ASTERISK_VERSION_NUM == 999999
                    if &#40;ast_exists_extension &#40;chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num&#41;&#41;
    #else
                    if &#40;ast_exists_extension &#40;chan, chan->context, chan->exten, chan->priority + 101, chan->callerid&#41;&#41;
    #endif
                            chan->priority += 100;
            &#125;
    
            return 0;
    &#125;
    
    int unload_module &#40;void&#41; &#123;
            int retval;
            STANDARD_HANGUP_LOCALUSERS;
            retval = ast_unregister_application &#40;g_app&#41;;
            return retval;
    &#125;
    
    int load_module &#40;void&#41; &#123;
            int retval;
            retval = ast_register_application &#40;g_app, get_exec, g_synopsis, g_descrip&#41;;
            return retval;
    &#125;
    
    char *description &#40;void&#41; &#123;
            return tdesc;
    &#125;
    
    int usecount &#40;void&#41; &#123;
            int res;
            STANDARD_USECOUNT &#40;res&#41;;
            return res;
    &#125;
    
    char *key &#40;&#41; &#123;
            return ASTERISK_GPL_KEY;
    &#125;
    
    int ldap_lookup&#40;char *host, int port, char *user, char *pass, char *base, char *scope, char *filter, char *attribute, char*result&#41; &#123;
            char *attrs&#91;&#93; = &#123; NULL &#125;;
            char **values;
            LDAP *ld;
            LDAPMessage *res, *entry;
            int ret, ldap_scope = LDAP_SCOPE_SUBTREE;
    
            ld = ldap_init&#40;host, port&#41;;
            if&#40;!ld&#41; &#123;
                    ast_log &#40;LOG_DEBUG, "LDAPget&#58; unable to initialize ldap connection to %s\n", host&#41;;
                    return 0;
            &#125;
            if&#40;user&#41; &#123;
                    if &#40;option_verbose > 2&#41;
                            ast_verbose &#40;VERBOSE_PREFIX_3 "LDAPget&#58; bind to %s as %s\n", host, user&#41;;
                    ldap_simple_bind&#40;ld, user, pass&#41;;
            &#125;
    
            if&#40;strncmp&#40;scope,"sub",3&#41;==0&#41; &#123;
                    ldap_scope = LDAP_SCOPE_SUBTREE;
            &#125; else if&#40;strncmp&#40;scope,"base",4&#41;==0&#41; &#123;
                    ldap_scope = LDAP_SCOPE_BASE;
            &#125; else if&#40;strncmp&#40;scope,"one",3&#41;==0&#41; &#123;
                    ldap_scope = LDAP_SCOPE_ONELEVEL;
            &#125;
    
            ret = ldap_search_s&#40;ld, base, ldap_scope, filter, attrs, 0, &res&#41;;
            if&#40;ret&#41; &#123;
                    ast_log &#40;LOG_DEBUG, "LDAPget&#58; search failed&#58; %s\n", ldap_err2string&#40;ret&#41;&#41;;
                    ldap_unbind&#40;ld&#41;;
                    return 0;
            &#125;
    
            entry = ldap_first_entry&#40;ld, res&#41;;
            if&#40;!entry&#41; &#123;
                    ldap_unbind&#40;ld&#41;;
                    return 0;
            &#125;
    
            values = ldap_get_values&#40;ld, entry, attribute&#41;;
            if&#40;values && values&#91;0&#93;&#41; &#123;
                    memset&#40;result, 0, strlen&#40;values&#91;0&#93;&#41;&#41;;
                    strncpy&#40;result, values&#91;0&#93;, strlen&#40;values&#91;0&#93;&#41;&#41;;
                    result&#91;strlen&#40;values&#91;0&#93;&#41;&#93; = '\0';
                    if &#40;option_verbose > 2&#41;
                            ast_verbose &#40;VERBOSE_PREFIX_3 "LDAPget&#58; %s=%s\n",attribute, result&#41;;
            &#125;
            ldap_unbind&#40;ld&#41;;
            return 1;
    &#125;
    
    int strconvert&#40;const char *incharset, const char *outcharset, char *in, char *out&#41; &#123;
            iconv_t cd;
            size_t incount, outcount, result;
            incount = outcount = strlen&#40;in&#41; * 2;
            cd = iconv_open&#40;outcharset, incharset&#41;;
            if&#40;cd == &#40;iconv_t&#41; -1&#41; &#123;
                    if&#40;errno == EINVAL&#41; ast_log&#40;LOG_DEBUG, "conversion from '%s' to '%s' not available", incharset, outcharset&#41;;
                    *out = L'\0';
                    return -1;
            &#125;
            result = iconv&#40;cd, &in, &incount, &out, &outcount&#41;;
            iconv_close&#40;cd&#41;;
            out&#91;strlen&#40;out&#41;&#93; = '\0';
            return 1;
    &#125;
    
    char *strtrim&#40;char *str&#41; &#123;
            char *p, c;
            p = strchr&#40;str, '\0'&#41;;
            while &#40;--p >= str && isspace&#40;*p&#41;&#41;;
            p&#91;1&#93; = '\0';
            while &#40;&#40;c = *str++&#41; != '\0' && isspace&#40;c&#41;&#41;;
            return str - 1;
    &#125;
    Das Ganze stammt von dieser Webseite: http://www.mezzo.net/asterisk/app_ldap.html

    Doku lesen vor dem Posten einer Frage würde helfen, einen Großteil der hier immer wiederkehrenden Grundsatzfragen zu vermeiden!

    Alles mit ...box am Ende ist mir suspekt. Egal ob Fritz... Trix... Horst... oder was anderes am Anfang steht. Einzige Ausnahme: Match...

    Jetzt erhältlich: Das Buch zum Kurs! Betateilchen's Asterisk Baukasten

    Bitte keine unaufgeforderten Supportanfragen per PN !

  2. #2
    Admin-Team Avatar von rajo
    Registriert seit
    31.03.2004
    Beiträge
    1.961
    app_ldap.c: In function `get_exec':
    app_ldap.c:87: parse error before `struct'
    Ein Syntaxfehler -- um genau zu sein:
    struct ast_config *cfg;
    Diese Variablendeklaration gehört an den Anfang der Funktion -- es ist C, kein C++ ... also die Zeile einfach unter die Deklaration von char *temp, ... verschieben und das ganze sollte kompilieren.

  3. #3
    Grandstream-Guru Avatar von betateilchen
    Registriert seit
    30.06.2004
    Ort
    am Letzenberg
    Beiträge
    12.888
    wow - Danke !

    Funktioniert ...


    Doku lesen vor dem Posten einer Frage würde helfen, einen Großteil der hier immer wiederkehrenden Grundsatzfragen zu vermeiden!

    Alles mit ...box am Ende ist mir suspekt. Egal ob Fritz... Trix... Horst... oder was anderes am Anfang steht. Einzige Ausnahme: Match...

    Jetzt erhältlich: Das Buch zum Kurs! Betateilchen's Asterisk Baukasten

    Bitte keine unaufgeforderten Supportanfragen per PN !

Ähnliche Themen

  1. [gelöst] Fehler beim Compilieren Speedbox2fritz
    Von willithepimp im Forum Speedport2Fritz
    Antworten: 2
    Letzter Beitrag: 19.09.2009, 08:05
  2. problem beim compilieren
    Von FoCMB im Forum Freetz
    Antworten: 5
    Letzter Beitrag: 10.11.2007, 09:03
  3. [gelöst] fehler beim chan-capi 1.0.0 compilieren
    Von alex0801 im Forum Asterisk ISDN mit CAPI (chan_capi, chan_capi_cm)
    Antworten: 1
    Letzter Beitrag: 16.03.2007, 11:23
  4. Problem beim Compilieren der Toolchain
    Von Moonsurfer im Forum Freetz
    Antworten: 2
    Letzter Beitrag: 27.08.2006, 16:31
  5. [gelöst] Fehler beim Compilieren
    Von maestro im Forum Asterisk Allgemein
    Antworten: 4
    Letzter Beitrag: 29.04.2006, 12:20

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •