#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" |
Definition in file func_callerid.c.
| 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 (!chan) 00046 return ""; 00047 00048 if (!strncasecmp("all", data, 3)) { 00049 snprintf(buf, len, "\"%s\" <%s>", chan->cid.cid_name ? chan->cid.cid_name : "", chan->cid.cid_num ? chan->cid.cid_num : ""); 00050 } else if (!strncasecmp("name", data, 4)) { 00051 if (chan->cid.cid_name) { 00052 ast_copy_string(buf, chan->cid.cid_name, len); 00053 } 00054 } else if (!strncasecmp("num", data, 3) || !strncasecmp("number", data, 6)) { 00055 if (chan->cid.cid_num) { 00056 ast_copy_string(buf, chan->cid.cid_num, len); 00057 } 00058 } else if (!strncasecmp("ani", data, 3)) { 00059 if (chan->cid.cid_ani) { 00060 ast_copy_string(buf, chan->cid.cid_ani, len); 00061 } 00062 } else if (!strncasecmp("dnid", data, 4)) { 00063 if (chan->cid.cid_dnid) { 00064 ast_copy_string(buf, chan->cid.cid_dnid, len); 00065 } 00066 } else if (!strncasecmp("rdnis", data, 5)) { 00067 if (chan->cid.cid_rdnis) { 00068 ast_copy_string(buf, chan->cid.cid_rdnis, len); 00069 } 00070 } else { 00071 ast_log(LOG_ERROR, "Unknown callerid data type.\n"); 00072 } 00073 00074 return buf; 00075 }
| static void callerid_write | ( | struct ast_channel * | chan, | |
| char * | cmd, | |||
| char * | data, | |||
| const char * | value | |||
| ) | [static] |
Definition at line 77 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.
00078 { 00079 if (!value || !chan) 00080 return; 00081 00082 if (!strncasecmp("all", data, 3)) { 00083 char name[256]; 00084 char num[256]; 00085 if (!ast_callerid_split(value, name, sizeof(name), num, sizeof(num))) 00086 ast_set_callerid(chan, num, name, num); 00087 } else if (!strncasecmp("name", data, 4)) { 00088 ast_set_callerid(chan, NULL, value, NULL); 00089 } else if (!strncasecmp("num", data, 3) || !strncasecmp("number", data, 6)) { 00090 ast_set_callerid(chan, value, NULL, NULL); 00091 } else if (!strncasecmp("ani", data, 3)) { 00092 ast_set_callerid(chan, NULL, NULL, value); 00093 } else if (!strncasecmp("dnid", data, 4)) { 00094 /* do we need to lock chan here? */ 00095 if (chan->cid.cid_dnid) 00096 free(chan->cid.cid_dnid); 00097 chan->cid.cid_dnid = ast_strlen_zero(value) ? NULL : strdup(value); 00098 } else if (!strncasecmp("rdnis", data, 5)) { 00099 /* do we need to lock chan here? */ 00100 if (chan->cid.cid_rdnis) 00101 free(chan->cid.cid_rdnis); 00102 chan->cid.cid_rdnis = ast_strlen_zero(value) ? NULL : strdup(value); 00103 } else { 00104 ast_log(LOG_ERROR, "Unknown callerid data type.\n"); 00105 } 00106 }
| char* description | ( | void | ) |
Provides a description of the module.
Definition at line 134 of file func_callerid.c.
00135 { 00136 return tdesc; 00137 }
| 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; }
Definition at line 144 of file func_callerid.c.
References ASTERISK_GPL_KEY.
00145 { 00146 return ASTERISK_GPL_KEY; 00147 }
| 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.
Definition at line 129 of file func_callerid.c.
References ast_custom_function_register().
00130 { 00131 return ast_custom_function_register(&callerid_function); 00132 }
| 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).
Definition at line 124 of file func_callerid.c.
References ast_custom_function_unregister().
00125 { 00126 return ast_custom_function_unregister(&callerid_function); 00127 }
| 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.
Definition at line 139 of file func_callerid.c.
struct ast_custom_function callerid_function [static] |
Definition at line 111 of file func_callerid.c.
char* tdesc = "Caller ID related dialplan function" [static] |
Definition at line 122 of file func_callerid.c.
1.5.6