Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:48:14 2009

## Asterisk developer's documentation

# app_setcidname.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 "asterisk/utils.h"`

Include dependency graph for app_setcidname.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)
int | unload_module (void)
| Cleanup all module structures, sockets, etc.
int | usecount (void)
| Provides a usecount.

## Variables

static char * | app = "SetCIDName"
static char * | descrip
| LOCAL_USER_DECL
| STANDARD_LOCAL_USER
static char * | synopsis = "Set CallerID Name"
static char * | tdesc = "Set CallerID Name"

## Detailed Description

App to set callerid.

Definition in file app_setcidname.c.

## Function Documentation

char* description | ( | void |  | ) |

Provides a description of the module.

Returns:
  a short description of your module

Definition at line 117 of file app_setcidname.c.

    00118 {
    00119    return tdesc;
    00120 }

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 129 of file app_setcidname.c.

References ASTERISK_GPL_KEY.

    00130 {
    00131    return ASTERISK_GPL_KEY;
    00132 }

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 112 of file app_setcidname.c.

References ast_register_application(), and setcallerid_exec().

    00113 {
    00114    return ast_register_application(app, setcallerid_exec, synopsis, descrip);
    00115 }

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

Definition at line 63 of file app_setcidname.c.

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

    00064 {
    00065    char *tmp = NULL;
    00066    struct localuser *u;
    00067    char *opt;
    00068    static int deprecation_warning = 0;
    00069
    00070    if (!deprecation_warning) {
    00071       ast_log(LOG_WARNING, "SetCIDName is deprecated, please use Set(CALLERID(name)=value) instead.\n");
    00072       deprecation_warning = 1;
    00073    }
    00074
    00075    if (ast_strlen_zero(data)) {
    00076       ast_log(LOG_ERROR, "SetCIDName requires an argument!\n");
    00077       return 0;
    00078    }
    00079
    00080    LOCAL_USER_ADD(u);
    00081
    00082    tmp = ast_strdupa(data);
    00083    if (!tmp) {
    00084       ast_log(LOG_ERROR, "Out of memory\n");
    00085       LOCAL_USER_REMOVE(u);
    00086       return -1;
    00087    }
    00088
    00089    opt = strchr(tmp, '|');
    00090    if (opt) {
    00091       *opt = '\0';
    00092    }
    00093
    00094    ast_set_callerid(chan, NULL, tmp, NULL);
    00095
    00096    LOCAL_USER_REMOVE(u);
    00097
    00098    return 0;
    00099 }

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 101 of file app_setcidname.c.

References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.

    00102 {
    00103    int res;
    00104
    00105    res = ast_unregister_application(app);
    00106
    00107    STANDARD_HANGUP_LOCALUSERS;
    00108
    00109    return res;
    00110 }

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 122 of file app_setcidname.c.

References STANDARD_USECOUNT.

    00123 {
    00124    int res;
    00125    STANDARD_USECOUNT(res);
    00126    return res;
    00127 }

## Variable Documentation

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

Definition at line 47 of file app_setcidname.c.

char* descrip`[static]`

Definition at line 51 of file app_setcidname.c.

LOCAL_USER_DECL

Definition at line 61 of file app_setcidname.c.

STANDARD_LOCAL_USER

Definition at line 59 of file app_setcidname.c.

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

Definition at line 49 of file app_setcidname.c.

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

Definition at line 45 of file app_setcidname.c.