Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:48:03 2009

## Asterisk developer's documentation

# app_eval.c File Reference

Eval application. More...

`#include <stdio.h>`
`#include <stdlib.h>`
`#include <unistd.h>`
`#include <string.h>`
`#include "asterisk.h"`
`#include "asterisk/file.h"`
`#include "asterisk/logger.h"`
`#include "asterisk/options.h"`
`#include "asterisk/channel.h"`
`#include "asterisk/pbx.h"`
`#include "asterisk/module.h"`

Include dependency graph for app_eval.c:

Go to the source code of this file.

## Defines

#define | MAXRESULT 1024

## Functions

char * | description (void)
| Provides a description of the module.
static int | eval_exec (struct ast_channel *chan, void *data)
char * | key ()
| Returns the ASTERISK_GPL_KEY.
int | load_module (void)
| Initialize the module.
int | unload_module (void)
| Cleanup all module structures, sockets, etc.
int | usecount (void)
| Provides a usecount.

## Variables

static char * | app_eval = "Eval"
static char * | eval_descrip
static char * | eval_synopsis = "Evaluates a string"
| LOCAL_USER_DECL
| STANDARD_LOCAL_USER
static char * | tdesc = "Reevaluates strings"

## Detailed Description

Eval application.

Author:
  Tilghman Lesher <app_eval__v001@the-tilghman.com>

Definition in file app_eval.c.

## Define Documentation

#define MAXRESULT 1024

Definition at line 43 of file app_eval.c.

## Function Documentation

char* description | ( | void |  | ) |

Provides a description of the module.

Returns:
  a short description of your module

Definition at line 112 of file app_eval.c.

    00113 {
    00114    return tdesc;
    00115 }

static int eval_exec | ( | struct ast_channel * | chan,
|  | void * | data |
| ) |  |  | `[static]`

Definition at line 62 of file app_eval.c.

References ast_log(), ast_strdupa, dep_warning, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_ERROR, LOG_WARNING, MAXRESULT, pbx_builtin_setvar_helper(), pbx_substitute_variables_helper(), s, and strsep().

Referenced by load_module().

    00063 {
    00064    int res=0;
    00065    struct localuser *u;
    00066    char *s, *newvar=NULL, tmp[MAXRESULT];
    00067    static int dep_warning = 0;
    00068
    00069    LOCAL_USER_ADD(u);
    00070
    00071    if (!dep_warning) {
    00072       ast_log(LOG_WARNING, "This application has been deprecated in favor of the dialplan function, EVAL\n");
    00073       dep_warning = 1;
    00074    }
    00075
    00076    /* Check and parse arguments */
    00077    if (data) {
    00078       s = ast_strdupa((char *)data);
    00079       if (s) {
    00080          newvar = strsep(&s, "=");
    00081          if (newvar && (newvar[0] != '\0')) {
    00082             memset(tmp, 0, MAXRESULT);
    00083             pbx_substitute_variables_helper(chan, s, tmp, MAXRESULT - 1);
    00084             pbx_builtin_setvar_helper(chan, newvar, tmp);
    00085          }
    00086       } else {
    00087          ast_log(LOG_ERROR, "Out of memory\n");
    00088          res = -1;
    00089       }
    00090    }
    00091
    00092    LOCAL_USER_REMOVE(u);
    00093    return res;
    00094 }

char* key | ( | void |  | ) |

Returns the ASTERISK_GPL_KEY.

This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:

     char *key(void) {
             return ASTERISK_GPL_KEY;
     }

Returns:
  ASTERISK_GPL_KEY

Definition at line 124 of file app_eval.c.

References ASTERISK_GPL_KEY.

    00125 {
    00126    return ASTERISK_GPL_KEY;
    00127 }

int load_module | ( | void |  | ) |

Initialize the module.

This function is called at module load time. Put all code in here that needs to set up your module's hardware, software, registrations, etc.

Returns:
  This function should return 0 on success and non-zero on failure. If the module is not loaded successfully, Asterisk will call its unload_module() function.

Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.

Returns:
  int Always 0.

TE STUFF END

Definition at line 107 of file app_eval.c.

References ast_register_application(), and eval_exec().

    00108 {
    00109    return ast_register_application(app_eval, eval_exec, eval_synopsis, eval_descrip);
    00110 }

int unload_module | ( | void |  | ) |

Cleanup all module structures, sockets, etc.

This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).

Returns:
  Zero on success, or non-zero on error.

Definition at line 96 of file app_eval.c.

References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.

    00097 {
    00098    int res;
    00099
    00100    res = ast_unregister_application(app_eval);
    00101
    00102    STANDARD_HANGUP_LOCALUSERS;
    00103
    00104    return res;
    00105 }

int usecount | ( | void |  | ) |

Provides a usecount.

This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.

Returns:
  The module's usecount.

Definition at line 117 of file app_eval.c.

References STANDARD_USECOUNT.

    00118 {
    00119    int res;
    00120    STANDARD_USECOUNT(res);
    00121    return res;
    00122 }

## Variable Documentation

char* app_eval = "Eval"`[static]`

Definition at line 47 of file app_eval.c.

char* eval_descrip`[static]`

Definition at line 51 of file app_eval.c.

char* eval_synopsis = "Evaluates a string"`[static]`

Definition at line 49 of file app_eval.c.

LOCAL_USER_DECL

Definition at line 60 of file app_eval.c.

STANDARD_LOCAL_USER

Definition at line 58 of file app_eval.c.

char* tdesc = "Reevaluates strings"`[static]`

Definition at line 45 of file app_eval.c.