00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <stdlib.h>
00024 #include <stdio.h>
00025 #include <string.h>
00026 #include <sys/types.h>
00027
00028 #include "asterisk.h"
00029
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $")
00031
00032 #ifndef BUILTIN_FUNC
00033 #include "asterisk/module.h"
00034 #endif
00035 #include "asterisk/channel.h"
00036 #include "asterisk/pbx.h"
00037 #include "asterisk/logger.h"
00038 #include "asterisk/utils.h"
00039 #include "asterisk/app.h"
00040 #include "asterisk/options.h"
00041 #include "asterisk/callerid.h"
00042
00043 static char *callerid_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
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 }
00073
00074 static void callerid_write(struct ast_channel *chan, char *cmd, char *data, const char *value)
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
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
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 }
00104
00105 #ifndef BUILTIN_FUNC
00106 static
00107 #endif
00108 struct ast_custom_function callerid_function = {
00109 .name = "CALLERID",
00110 .synopsis = "Gets or sets Caller*ID data on the channel.",
00111 .syntax = "CALLERID(datatype)",
00112 .desc = "Gets or sets Caller*ID data on the channel. The allowable datatypes\n"
00113 "are \"all\", \"name\", \"num\", \"ANI\", \"DNID\", \"RDNIS\".\n",
00114 .read = callerid_read,
00115 .write = callerid_write,
00116 };
00117
00118 #ifndef BUILTIN_FUNC
00119 static char *tdesc = "Caller ID related dialplan function";
00120
00121 int unload_module(void)
00122 {
00123 return ast_custom_function_unregister(&callerid_function);
00124 }
00125
00126 int load_module(void)
00127 {
00128 return ast_custom_function_register(&callerid_function);
00129 }
00130
00131 char *description(void)
00132 {
00133 return tdesc;
00134 }
00135
00136 int usecount(void)
00137 {
00138 return 0;
00139 }
00140
00141 char *key()
00142 {
00143 return ASTERISK_GPL_KEY;
00144 }
00145 #endif
00146
00147
00148
00149
00150
00151
00152
00153