Eigene asterisk module schreiben

Aus metasec wiki
Wechseln zu: Navigation, Suche

Coding Guidelines

http://www.asterisk.org/developers/coding-guidelines

Grundgerüst

Configdateien


    struct ast_config   *cfg;
    struct ast_variable *var;

    /*
     *  load the configfile
     */
    cfg = ast_config_load("metasec.conf");
    if ( !cfg ) {
        ast_log(LOG_WARNING, "no metasec_stat.conf, exiting... \n");
        return RESULT_SUCCESS;
    }

    for ( var = ast_variable_browse(cfg, "general"); var; var = var->next ) {

        if (option_verbose > 8)
            ast_log(LOG_WARNING, "cfg file: %s => %s \n", var->name, var->value);

        if ( strstr(var->name, "dnd_db_family" ) )
            sprintf(dnd_db_family,"%s",var->value);

        else if ( strstr(var->name, "dnd_exec_cmd") && !ast_strlen_zero(var->value) )
            sprintf(dnd_exec_cmd,"%s",var->value);


    }
    ast_config_destroy(cfg);

ASTDB

Einen einzelnen Eintrag schreiben

ast_db_put(uml_db_family, exten, str_val);

Größere Operationen mit der AstDB


    char c[10] = "astdb_tab";
    /*
     get the structs for the database
     */
    struct ast_db_entry *db_tree;
    struct ast_db_entry *entry;

        db_tree = ast_db_gettree(c, NULL);
        for ( entry = db_tree; entry; entry = entry->next ) {

            t_key=ast_strdupa(entry->key);
            key = strsep(&t_key, "/");
            key = strsep(&t_key, "/");
            key = strsep(&t_key, "/");


            if (option_verbose > 8)
                ast_log(LOG_NOTICE, "key:%s val:%s \n", key , entry->data);
            sprintf(exten,"%s",key);

            for(j=0;j<100;j++) {

                if ( strstr(user_data[j].ext,exten) && strlen(exten) == strlen(user_data[j].ext)  ) {
                    /* ok. we found the index for the current exten */
                    break;
                } else if ( strlen(user_data[j].ext) == 0 ) {
                    /* ok. we found the next free index */
                    break;
                }

            }

            sprintf(user_data[j].ext,"%s",key);

            if ( strstr(c,"dnd") )
                sprintf(user_data[j].dnd,"%s",entry->data);
            else if ( strstr(c,"uml_target") )
                sprintf(user_data[j].uml,"%s",entry->data);
            else
                sprintf(user_data[j].dyn,"%s",entry->data);

        }

        if (db_tree)
            ast_db_freetree(db_tree);