Sat Sep 16 05:48:02 2006

Asterisk developer's documentation


func_callerid.c File Reference

Caller ID related dialplan functions. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/logger.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/options.h"
#include "asterisk/callerid.h"

Go to the source code of this file.

Functions

static char * callerid_read (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static void callerid_write (struct ast_channel *chan, char *cmd, char *data, const char *value)
char * description (void)
 Provides a description of the module.
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 struct ast_custom_function callerid_function
static char * tdesc = "Caller ID related dialplan function"


Detailed Description

Caller ID related dialplan functions.

Definition in file func_callerid.c.


Function Documentation

static char* callerid_read ( struct ast_channel chan,
char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 43 of file func_callerid.c.

References ast_log(), ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_dnid, ast_callerid::cid_name, ast_callerid::cid_num, ast_callerid::cid_rdnis, and LOG_ERROR.

00044 {
00045    if (!strncasecmp("all", data, 3)) {
00046       snprintf(buf, len, "\"%s\" <%s>", chan->cid.cid_name ? chan->cid.cid_name : "", chan->cid.cid_num ? chan->cid.cid_num : "");  
00047    } else if (!strncasecmp("name", data, 4)) {
00048       if (chan->cid.cid_name) {
00049          ast_copy_string(buf, chan->cid.cid_name, len);
00050       }
00051    } else if (!strncasecmp("num", data, 3) || !strncasecmp("number", data, 6)) {
00052       if (chan->cid.cid_num) {
00053          ast_copy_string(buf, chan->cid.cid_num, len);
00054       }
00055    } else if (!strncasecmp("ani", data, 3)) {
00056       if (chan->cid.cid_ani) {
00057          ast_copy_string(buf, chan->cid.cid_ani, len);
00058       }
00059    } else if (!strncasecmp("dnid", data, 4)) {
00060       if (chan->cid.cid_dnid) {
00061          ast_copy_string(buf, chan->cid.cid_dnid, len);
00062       }
00063    } else if (!strncasecmp("rdnis", data, 5)) {
00064       if (chan->cid.cid_rdnis) {
00065          ast_copy_string(buf, chan->cid.cid_rdnis, len);
00066       }
00067    } else {
00068       ast_log(LOG_ERROR, "Unknown callerid data type.\n");
00069    }
00070 
00071    return buf;
00072 }

static void callerid_write ( struct ast_channel chan,
char *  cmd,
char *  data,
const char *  value 
) [static]

Definition at line 74 of file func_callerid.c.

References ast_callerid_split(), ast_log(), ast_set_callerid(), ast_strlen_zero(), ast_channel::cid, ast_callerid::cid_dnid, ast_callerid::cid_rdnis, free, LOG_ERROR, name, and strdup.

00075 {
00076    if (!value)
00077                 return;
00078    
00079    if (!strncasecmp("all", data, 3)) {
00080       char name[256];
00081       char num[256];
00082       if (!ast_callerid_split(value, name, sizeof(name), num, sizeof(num)))
00083          ast_set_callerid(chan, num, name, num);   
00084         } else if (!strncasecmp("name", data, 4)) {
00085                 ast_set_callerid(chan, NULL, value, NULL);
00086         } else if (!strncasecmp("num", data, 3) || !strncasecmp("number", data, 6)) {
00087                 ast_set_callerid(chan, value, NULL, NULL);
00088         } else if (!strncasecmp("ani", data, 3)) {
00089                 ast_set_callerid(chan, NULL, NULL, value);
00090         } else if (!strncasecmp("dnid", data, 4)) {
00091                 /* do we need to lock chan here? */
00092                 if (chan->cid.cid_dnid)
00093                         free(chan->cid.cid_dnid);
00094                 chan->cid.cid_dnid = ast_strlen_zero(value) ? NULL : strdup(value);
00095         } else if (!strncasecmp("rdnis", data, 5)) {
00096                 /* do we need to lock chan here? */
00097                 if (chan->cid.cid_rdnis)
00098                         free(chan->cid.cid_rdnis);
00099                 chan->cid.cid_rdnis = ast_strlen_zero(value) ? NULL : strdup(value);
00100         } else {
00101                 ast_log(LOG_ERROR, "Unknown callerid data type.\n");
00102         }
00103 }

char* description ( void   ) 

Provides a description of the module.

Returns:
a short description of your module

Definition at line 131 of file func_callerid.c.

00132 {
00133    return tdesc;
00134 }

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

References ASTERISK_GPL_KEY.

00142 {
00143    return ASTERISK_GPL_KEY;
00144 }

int load_module ( void   ) 

Initialize the module.

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.

Definition at line 126 of file func_callerid.c.

References ast_custom_function_register(), and callerid_function.

00127 {
00128         return ast_custom_function_register(&callerid_function);
00129 }

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 121 of file func_callerid.c.

References ast_custom_function_unregister(), and callerid_function.

00122 {
00123         return ast_custom_function_unregister(&callerid_function);
00124 }

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 136 of file func_callerid.c.

00137 {
00138    return 0;
00139 }


Variable Documentation

struct ast_custom_function callerid_function [static]

Definition at line 108 of file func_callerid.c.

Referenced by load_module(), and unload_module().

char* tdesc = "Caller ID related dialplan function" [static]

Definition at line 119 of file func_callerid.c.


Generated on Sat Sep 16 05:48:02 2006 for Asterisk - the Open Source PBX by  doxygen 1.4.7