Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:48:14 2009

## Asterisk developer's documentation

# app_setcdruserfield.c File Reference

Applictions connected with CDR engine. More...

`#include <sys/types.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include "asterisk.h"`
`#include "asterisk/channel.h"`
`#include "asterisk/cdr.h"`
`#include "asterisk/module.h"`
`#include "asterisk/pbx.h"`
`#include "asterisk/logger.h"`
`#include "asterisk/config.h"`
`#include "asterisk/manager.h"`
`#include "asterisk/utils.h"`

Include dependency graph for app_setcdruserfield.c:

Go to the source code of this file.

## Functions

static int | action_setcdruserfield (struct mansession *s, struct message *m)
static int | appendcdruserfield_exec (struct ast_channel *chan, void *data)
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 | setcdruserfield_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 * | appendcdruserfield_app = "AppendCDRUserField"
static char * | appendcdruserfield_descrip
static char * | appendcdruserfield_synopsis = "Append to the CDR user field"
| LOCAL_USER_DECL
static char * | setcdruserfield_app = "SetCDRUserField"
static char * | setcdruserfield_descrip
static char * | setcdruserfield_synopsis = "Set the CDR user field"
| STANDARD_LOCAL_USER
static char * | tdesc = "CDR user field apps"

## Detailed Description

Applictions connected with CDR engine.

Definition in file app_setcdruserfield.c.

## Function Documentation

static int action_setcdruserfield | ( | struct mansession * | s,
|  | struct message * | m |
| ) |  |  | `[static]`

Definition at line 79 of file app_setcdruserfield.c.

References ast_cdr_appenduserfield(), ast_cdr_setuserfield(), ast_get_channel_by_name_locked(), ast_mutex_unlock(), ast_strlen_zero(), ast_true(), astman_get_header(), astman_send_ack(), astman_send_error(), and ast_channel::lock.

Referenced by load_module().

    00080 {
    00081    struct ast_channel *c = NULL;
    00082    char *userfield = astman_get_header(m, "UserField");
    00083    char *channel = astman_get_header(m, "Channel");
    00084    char *append = astman_get_header(m, "Append");
    00085
    00086    if (ast_strlen_zero(channel)) {
    00087       astman_send_error(s, m, "No Channel specified");
    00088       return 0;
    00089    }
    00090    if (ast_strlen_zero(userfield)) {
    00091       astman_send_error(s, m, "No UserField specified");
    00092       return 0;
    00093    }
    00094    c = ast_get_channel_by_name_locked(channel);
    00095    if (!c) {
    00096       astman_send_error(s, m, "No such channel");
    00097       return 0;
    00098    }
    00099    if (ast_true(append))
    00100       ast_cdr_appenduserfield(c, userfield);
    00101    else
    00102       ast_cdr_setuserfield(c, userfield);
    00103    ast_mutex_unlock(&c->lock);
    00104    astman_send_ack(s, m, "CDR Userfield Set");
    00105    return 0;
    00106 }

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

Definition at line 124 of file app_setcdruserfield.c.

References ast_cdr_appenduserfield(), ast_channel::cdr, LOCAL_USER_ADD, and LOCAL_USER_REMOVE.

Referenced by load_module().

    00125 {
    00126    struct localuser *u;
    00127    int res = 0;
    00128
    00129    LOCAL_USER_ADD(u);
    00130
    00131    if (chan->cdr && data) {
    00132       ast_cdr_appenduserfield(chan, (char*)data);
    00133    }
    00134
    00135    LOCAL_USER_REMOVE(u);
    00136
    00137    return res;
    00138 }

char* description | ( | void |  | ) |

Provides a description of the module.

Returns:
  a short description of your module

Definition at line 164 of file app_setcdruserfield.c.

    00165 {
    00166    return tdesc;
    00167 }

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 176 of file app_setcdruserfield.c.

References ASTERISK_GPL_KEY.

    00177 {
    00178    return ASTERISK_GPL_KEY;
    00179 }

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_setcdruserfield.c.

References action_setcdruserfield(), appendcdruserfield_exec(), ast_manager_register, ast_register_application(), EVENT_FLAG_CALL, and setcdruserfield_exec().

    00154 {
    00155    int res;
    00156
    00157    res = ast_register_application(setcdruserfield_app, setcdruserfield_exec, setcdruserfield_synopsis, setcdruserfield_descrip);
    00158    res |= ast_register_application(appendcdruserfield_app, appendcdruserfield_exec, appendcdruserfield_synopsis, appendcdruserfield_descrip);
    00159    res |= ast_manager_register("SetCDRUserField", EVENT_FLAG_CALL, action_setcdruserfield, "Set the CDR UserField");
    00160
    00161    return res;
    00162 }

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

Definition at line 108 of file app_setcdruserfield.c.

References ast_cdr_setuserfield(), ast_channel::cdr, LOCAL_USER_ADD, and LOCAL_USER_REMOVE.

Referenced by load_module().

    00109 {
    00110    struct localuser *u;
    00111    int res = 0;
    00112
    00113    LOCAL_USER_ADD(u);
    00114
    00115    if (chan->cdr && data) {
    00116       ast_cdr_setuserfield(chan, (char*)data);
    00117    }
    00118
    00119    LOCAL_USER_REMOVE(u);
    00120
    00121    return res;
    00122 }

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 140 of file app_setcdruserfield.c.

References ast_manager_unregister(), ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.

    00141 {
    00142    int res;
    00143
    00144    res = ast_unregister_application(setcdruserfield_app);
    00145    res |= ast_unregister_application(appendcdruserfield_app);
    00146    res |= ast_manager_unregister("SetCDRUserField");
    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 169 of file app_setcdruserfield.c.

References STANDARD_USECOUNT.

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

## Variable Documentation

char* appendcdruserfield_app = "AppendCDRUserField"`[static]`

Definition at line 72 of file app_setcdruserfield.c.

char* appendcdruserfield_descrip`[static]`

Definition at line 61 of file app_setcdruserfield.c.

char* appendcdruserfield_synopsis = "Append to the CDR user field"`[static]`

Definition at line 73 of file app_setcdruserfield.c.

LOCAL_USER_DECL

Definition at line 77 of file app_setcdruserfield.c.

char* setcdruserfield_app = "SetCDRUserField"`[static]`

Definition at line 58 of file app_setcdruserfield.c.

char* setcdruserfield_descrip`[static]`

Definition at line 46 of file app_setcdruserfield.c.

char* setcdruserfield_synopsis = "Set the CDR user field"`[static]`

Definition at line 59 of file app_setcdruserfield.c.

STANDARD_LOCAL_USER

Definition at line 75 of file app_setcdruserfield.c.

char* tdesc = "CDR user field apps"`[static]`

Definition at line 44 of file app_setcdruserfield.c.