Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:48:13 2009

## Asterisk developer's documentation

# app_setcallerid.c File Reference

App to set callerid. More...

`#include <stdlib.h>`
`#include <stdio.h>`
`#include <string.h>`
`#include "asterisk.h"`
`#include "asterisk/lock.h"`
`#include "asterisk/file.h"`
`#include "asterisk/logger.h"`
`#include "asterisk/channel.h"`
`#include "asterisk/pbx.h"`
`#include "asterisk/module.h"`
`#include "asterisk/translate.h"`
`#include "asterisk/image.h"`
`#include "asterisk/callerid.h"`

Include dependency graph for app_setcallerid.c:

Go to the source code of this file.

## Functions

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

## Variables

static char * | app = "SetCallerID"
static char * | app2 = "SetCallerPres"
static char * | descrip
static char * | descrip2
| LOCAL_USER_DECL
| STANDARD_LOCAL_USER
static char * | synopsis = "Set CallerID"
static char * | synopsis2 = "Set CallerID Presentation"
static char * | tdesc = "Set CallerID Application"

## Detailed Description

App to set callerid.

Definition in file app_setcallerid.c.

## Function Documentation

char* description | ( | void |  | ) |

Provides a description of the module.

Returns:
  a short description of your module

Definition at line 163 of file app_setcallerid.c.

    00164 {
    00165    return tdesc;
    00166 }

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 175 of file app_setcallerid.c.

References ASTERISK_GPL_KEY.

    00176 {
    00177    return ASTERISK_GPL_KEY;
    00178 }

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 153 of file app_setcallerid.c.

References ast_register_application(), setcallerid_exec(), and setcallerid_pres_exec().

    00154 {
    00155    int res;
    00156
    00157    res = ast_register_application(app2, setcallerid_pres_exec, synopsis2, descrip2);
    00158    res |= ast_register_application(app, setcallerid_exec, synopsis, descrip);
    00159
    00160    return res;
    00161 }

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

Definition at line 101 of file app_setcallerid.c.

References ast_callerid_split(), ast_log(), ast_set_callerid(), ast_strdupa, ast_strlen_zero(), LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_ERROR, LOG_WARNING, and name.

Referenced by load_module().

    00102 {
    00103    int res = 0;
    00104    char *tmp = NULL;
    00105    char name[256];
    00106    char num[256];
    00107    struct localuser *u;
    00108    char *opt;
    00109    int anitoo = 0;
    00110
    00111    if (ast_strlen_zero(data)) {
    00112       ast_log(LOG_WARNING, "SetCallerID requires an argument!\n");
    00113       return 0;
    00114    }
    00115
    00116    LOCAL_USER_ADD(u);
    00117
    00118    tmp = ast_strdupa(data);
    00119    if (!tmp) {
    00120       ast_log(LOG_ERROR, "Out of memory\n");
    00121       LOCAL_USER_REMOVE(u);
    00122       return -1;
    00123    }
    00124
    00125    opt = strchr(tmp, '|');
    00126    if (opt) {
    00127       *opt = '\0';
    00128       opt++;
    00129       if (*opt == 'a')
    00130          anitoo = 1;
    00131    }
    00132
    00133    ast_callerid_split(tmp, name, sizeof(name), num, sizeof(num));
    00134    ast_set_callerid(chan, num, name, anitoo ? num : NULL);
    00135
    00136    LOCAL_USER_REMOVE(u);
    00137
    00138    return res;
    00139 }

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

Definition at line 68 of file app_setcallerid.c.

References ast_log(), ast_parse_caller_presentation(), ast_channel::cid, ast_callerid::cid_pres, LOCAL_USER_ADD, LOCAL_USER_REMOVE, and LOG_WARNING.

Referenced by load_module().

    00069 {
    00070    struct localuser *u;
    00071    int pres = -1;
    00072
    00073    LOCAL_USER_ADD(u);
    00074
    00075    pres = ast_parse_caller_presentation(data);
    00076
    00077    if (pres < 0) {
    00078       ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show application SetCallerPres')\n",
    00079          (char *) data);
    00080       LOCAL_USER_REMOVE(u);
    00081       return 0;
    00082    }
    00083
    00084    chan->cid.cid_pres = pres;
    00085    LOCAL_USER_REMOVE(u);
    00086    return 0;
    00087 }

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 141 of file app_setcallerid.c.

References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.

    00142 {
    00143    int res;
    00144
    00145    res = ast_unregister_application(app2);
    00146    res |= ast_unregister_application(app);
    00147
    00148    STANDARD_HANGUP_LOCALUSERS;
    00149
    00150    return res;
    00151 }

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 168 of file app_setcallerid.c.

References STANDARD_USECOUNT.

    00169 {
    00170    int res;
    00171    STANDARD_USECOUNT(res);
    00172    return res;
    00173 }

## Variable Documentation

char* app = "SetCallerID"`[static]`

Definition at line 93 of file app_setcallerid.c.

char* app2 = "SetCallerPres"`[static]`

Definition at line 44 of file app_setcallerid.c.

char* descrip`[static]`

Initial value:

    "  SetCallerID(clid[|a]): Set Caller*ID on a call to a new\n"
    "value.  Sets ANI as well if a flag is used. \n"

Definition at line 97 of file app_setcallerid.c.

char* descrip2`[static]`

Definition at line 52 of file app_setcallerid.c.

LOCAL_USER_DECL

Definition at line 50 of file app_setcallerid.c.

STANDARD_LOCAL_USER

Definition at line 48 of file app_setcallerid.c.

char* synopsis = "Set CallerID"`[static]`

Definition at line 95 of file app_setcallerid.c.

char* synopsis2 = "Set CallerID Presentation"`[static]`

Definition at line 46 of file app_setcallerid.c.

char* tdesc = "Set CallerID Application"`[static]`

Definition at line 91 of file app_setcallerid.c.