#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.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 | |
AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Caller ID related dialplan function") | |
static int | callerid_read (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) |
static int | callerid_write (struct ast_channel *chan, char *cmd, char *data, const char *value) |
static int | load_module (void) |
static int | unload_module (void) |
Variables | |
static struct ast_custom_function | callerid_function |
Definition in file func_callerid.c.
AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
"Caller ID related dialplan function" | ||||
) |
static int callerid_read | ( | struct ast_channel * | chan, | |
char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 41 of file func_callerid.c.
References ast_callerid_split(), ast_channel_lock, ast_channel_unlock, 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, LOG_ERROR, name, S_OR, and strsep().
00043 { 00044 char *opt = data; 00045 00046 if (!chan) 00047 return -1; 00048 00049 if (strchr(opt, '|')) { 00050 char name[80], num[80]; 00051 00052 data = strsep(&opt, "|"); 00053 ast_callerid_split(opt, name, sizeof(name), num, sizeof(num)); 00054 00055 if (!strncasecmp("all", data, 3)) { 00056 snprintf(buf, len, "\"%s\" <%s>", name, num); 00057 } else if (!strncasecmp("name", data, 4)) { 00058 ast_copy_string(buf, name, len); 00059 } else if (!strncasecmp("num", data, 3) || 00060 !strncasecmp("number", data, 6)) { 00061 00062 ast_copy_string(buf, num, len); 00063 } else { 00064 ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data); 00065 } 00066 } else { 00067 ast_channel_lock(chan); 00068 00069 if (!strncasecmp("all", data, 3)) { 00070 snprintf(buf, len, "\"%s\" <%s>", 00071 S_OR(chan->cid.cid_name, ""), 00072 S_OR(chan->cid.cid_num, "")); 00073 } else if (!strncasecmp("name", data, 4)) { 00074 if (chan->cid.cid_name) { 00075 ast_copy_string(buf, chan->cid.cid_name, len); 00076 } 00077 } else if (!strncasecmp("num", data, 3) 00078 || !strncasecmp("number", data, 6)) { 00079 if (chan->cid.cid_num) { 00080 ast_copy_string(buf, chan->cid.cid_num, len); 00081 } 00082 } else if (!strncasecmp("ani", data, 3)) { 00083 if (chan->cid.cid_ani) { 00084 ast_copy_string(buf, chan->cid.cid_ani, len); 00085 } 00086 } else if (!strncasecmp("dnid", data, 4)) { 00087 if (chan->cid.cid_dnid) { 00088 ast_copy_string(buf, chan->cid.cid_dnid, len); 00089 } 00090 } else if (!strncasecmp("rdnis", data, 5)) { 00091 if (chan->cid.cid_rdnis) { 00092 ast_copy_string(buf, chan->cid.cid_rdnis, len); 00093 } 00094 } else { 00095 ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data); 00096 } 00097 00098 ast_channel_unlock(chan); 00099 } 00100 00101 return 0; 00102 }
static int callerid_write | ( | struct ast_channel * | chan, | |
char * | cmd, | |||
char * | data, | |||
const char * | value | |||
) | [static] |
Definition at line 104 of file func_callerid.c.
References ast_callerid_split(), ast_channel_lock, ast_channel_unlock, ast_log(), ast_set_callerid(), ast_strdup, ast_channel::cid, ast_callerid::cid_dnid, ast_callerid::cid_rdnis, free, LOG_ERROR, and name.
00106 { 00107 if (!value || !chan) 00108 return -1; 00109 00110 if (!strncasecmp("all", data, 3)) { 00111 char name[256]; 00112 char num[256]; 00113 00114 if (!ast_callerid_split(value, name, sizeof(name), num, sizeof(num))) 00115 ast_set_callerid(chan, num, name, num); 00116 } else if (!strncasecmp("name", data, 4)) { 00117 ast_set_callerid(chan, NULL, value, NULL); 00118 } else if (!strncasecmp("num", data, 3) || 00119 !strncasecmp("number", data, 6)) { 00120 ast_set_callerid(chan, value, NULL, NULL); 00121 } else if (!strncasecmp("ani", data, 3)) { 00122 ast_set_callerid(chan, NULL, NULL, value); 00123 } else if (!strncasecmp("dnid", data, 4)) { 00124 ast_channel_lock(chan); 00125 if (chan->cid.cid_dnid) 00126 free(chan->cid.cid_dnid); 00127 chan->cid.cid_dnid = ast_strdup(value); 00128 ast_channel_unlock(chan); 00129 } else if (!strncasecmp("rdnis", data, 5)) { 00130 ast_channel_lock(chan); 00131 if (chan->cid.cid_rdnis) 00132 free(chan->cid.cid_rdnis); 00133 chan->cid.cid_rdnis = ast_strdup(value); 00134 ast_channel_unlock(chan); 00135 } else { 00136 ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data); 00137 } 00138 00139 return 0; 00140 }
static int load_module | ( | void | ) | [static] |
Definition at line 159 of file func_callerid.c.
References ast_custom_function_register(), and callerid_function.
00160 { 00161 return ast_custom_function_register(&callerid_function); 00162 }
static int unload_module | ( | void | ) | [static] |
Definition at line 154 of file func_callerid.c.
References ast_custom_function_unregister(), and callerid_function.
00155 { 00156 return ast_custom_function_unregister(&callerid_function); 00157 }
struct ast_custom_function callerid_function [static] |