Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:48:04 2009

## Asterisk developer's documentation

# app_exec.c File Reference

Exec 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_exec.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 | exec_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_exec = "Exec"
static char * | exec_descrip
static char * | exec_synopsis = "Executes internal application"
| LOCAL_USER_DECL
| STANDARD_LOCAL_USER
static char * | tdesc = "Executes applications"

## Detailed Description

Exec application.

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

Definition in file app_exec.c.

## Define Documentation

#define MAXRESULT 1024

Definition at line 44 of file app_exec.c.

## Function Documentation

char* description | ( | void |  | ) |

Provides a description of the module.

Returns:
  a short description of your module

Definition at line 120 of file app_exec.c.

    00121 {
    00122    return tdesc;
    00123 }

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

Definition at line 63 of file app_exec.c.

References app, ast_log(), ast_strdupa, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_ERROR, LOG_WARNING, MAXRESULT, pbx_exec(), pbx_findapp(), pbx_substitute_variables_helper(), s, and strsep().

Referenced by load_module().

    00064 {
    00065    int res=0;
    00066    struct localuser *u;
    00067    char *s, *appname, *endargs, args[MAXRESULT];
    00068    struct ast_app *app;
    00069
    00070    LOCAL_USER_ADD(u);
    00071
    00072    memset(args, 0, MAXRESULT);
    00073
    00074    /* Check and parse arguments */
    00075    if (data) {
    00076       s = ast_strdupa((char *)data);
    00077       if (s) {
    00078          appname = strsep(&s, "(");
    00079          if (s) {
    00080             endargs = strrchr(s, ')');
    00081             if (endargs)
    00082                *endargs = '\0';
    00083             pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1);
    00084          }
    00085          if (appname) {
    00086             app = pbx_findapp(appname);
    00087             if (app) {
    00088                res = pbx_exec(chan, app, args, 1);
    00089             } else {
    00090                ast_log(LOG_WARNING, "Could not find application (%s)\n", appname);
    00091                res = -1;
    00092             }
    00093          }
    00094       } else {
    00095          ast_log(LOG_ERROR, "Out of memory\n");
    00096          res = -1;
    00097       }
    00098    }
    00099
    00100    LOCAL_USER_REMOVE(u);
    00101    return res;
    00102 }

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 132 of file app_exec.c.

References ASTERISK_GPL_KEY.

    00133 {
    00134    return ASTERISK_GPL_KEY;
    00135 }

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 115 of file app_exec.c.

References ast_register_application(), and exec_exec().

    00116 {
    00117    return ast_register_application(app_exec, exec_exec, exec_synopsis, exec_descrip);
    00118 }

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 104 of file app_exec.c.

References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.

    00105 {
    00106    int res;
    00107
    00108    res = ast_unregister_application(app_exec);
    00109
    00110    STANDARD_HANGUP_LOCALUSERS;
    00111
    00112    return res;
    00113 }

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 125 of file app_exec.c.

References STANDARD_USECOUNT.

    00126 {
    00127    int res;
    00128    STANDARD_USECOUNT(res);
    00129    return res;
    00130 }

## Variable Documentation

char* app_exec = "Exec"`[static]`

Definition at line 48 of file app_exec.c.

Referenced by load_module().

char* exec_descrip`[static]`

Definition at line 52 of file app_exec.c.

char* exec_synopsis = "Executes internal application"`[static]`

Definition at line 50 of file app_exec.c.

LOCAL_USER_DECL

Definition at line 61 of file app_exec.c.

STANDARD_LOCAL_USER

Definition at line 59 of file app_exec.c.

char* tdesc = "Executes applications"`[static]`

Definition at line 46 of file app_exec.c.