static int callerid_write(struct ast_channel *chan, char *cmd, char *data, const char *value) { if (!value) return -1; if (!strncasecmp("all", data, 3)) { char name[256]; char num[256]; if (!ast_callerid_split(value, name, sizeof(name), num, sizeof(num))) ast_set_callerid(chan, num, name, num); } else if (!strncasecmp("name", data, 4)) { ast_set_callerid(chan, NULL, value, NULL); } else if (!strncasecmp("num", data, 3) || !strncasecmp("number", data, 6)) { ast_set_callerid(chan, value, NULL, NULL); } else if (!strncasecmp("ani", data, 3)) { ast_set_callerid(chan, NULL, NULL, value); } else if (!strncasecmp("dnid", data, 4)) { /* do we need to lock chan here? */ if (chan->cid.cid_dnid) free(chan->cid.cid_dnid); chan->cid.cid_dnid = ast_strdup(value); } else if (!strncasecmp("rdnis", data, 5)) { /* do we need to lock chan here? */ if (chan->cid.cid_rdnis) free(chan->cid.cid_rdnis); chan->cid.cid_rdnis = ast_strdup(value); } else { ast_log(LOG_ERROR, "Unknown callerid data type.\n"); } return 0; }
static int lookupcidname_exec (struct ast_channel *chan, void *data) { char dbname[64]; struct localuser *u; LOCAL_USER_ADD (u); if (chan->cid.cid_num) { if (!ast_db_get ("cidname", chan->cid.cid_num, dbname, sizeof (dbname))) { ast_set_callerid (chan, NULL, dbname, NULL); if (option_verbose > 2) ast_verbose (VERBOSE_PREFIX_3 "Changed Caller*ID name to %s\n", dbname); } } LOCAL_USER_REMOVE (u); return 0; }
static int setcallerid_exec(struct ast_channel *chan, void *data) { int res = 0; char *tmp = NULL; char name[256]; char num[256]; struct localuser *u; char *opt; int anitoo = 0; if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "SetCallerID requires an argument!\n"); return 0; } LOCAL_USER_ADD(u); tmp = ast_strdupa(data); if (!tmp) { ast_log(LOG_ERROR, "Out of memory\n"); LOCAL_USER_REMOVE(u); return -1; } opt = strchr(tmp, '|'); if (opt) { *opt = '\0'; opt++; if (*opt == 'a') anitoo = 1; } ast_callerid_split(tmp, name, sizeof(name), num, sizeof(num)); ast_set_callerid(chan, num, name, anitoo ? num : NULL); LOCAL_USER_REMOVE(u); return res; }
static int lookupcidname_exec (struct ast_channel *chan, void *data) { char dbname[64]; struct localuser *u; static int dep_warning = 0; LOCAL_USER_ADD (u); if (!dep_warning) { dep_warning = 1; ast_log(LOG_WARNING, "LookupCIDName is deprecated. Please use ${DB(cidname/${CALLERID(num)})} instead.\n"); } if (chan->cid.cid_num) { if (!ast_db_get ("cidname", chan->cid.cid_num, dbname, sizeof (dbname))) { ast_set_callerid (chan, NULL, dbname, NULL); if (option_verbose > 2) ast_verbose (VERBOSE_PREFIX_3 "Changed Caller*ID name to %s\n", dbname); } } LOCAL_USER_REMOVE (u); return 0; }
static int callerid_write(struct ast_channel *chan, const char *cmd, char *data, const char *value) { if (!value || !chan) return -1; if (!strncasecmp("all", data, 3)) { char name[256]; char num[256]; if (!ast_callerid_split(value, name, sizeof(name), num, sizeof(num))) ast_set_callerid(chan, num, name, num); } else if (!strncasecmp("name", data, 4)) { ast_set_callerid(chan, NULL, value, NULL); } else if (!strncasecmp("num", data, 3)) { ast_set_callerid(chan, value, NULL, NULL); } else if (!strncasecmp("ani", data, 3)) { if (!strncasecmp(data + 3, "2", 1)) { int i = atoi(value); chan->cid.cid_ani2 = i; } else ast_set_callerid(chan, NULL, NULL, value); } else if (!strncasecmp("dnid", data, 4)) { ast_channel_lock(chan); if (chan->cid.cid_dnid) ast_free(chan->cid.cid_dnid); chan->cid.cid_dnid = ast_strdup(value); ast_channel_unlock(chan); } else if (!strncasecmp("rdnis", data, 5)) { ast_channel_lock(chan); if (chan->cid.cid_rdnis) ast_free(chan->cid.cid_rdnis); chan->cid.cid_rdnis = ast_strdup(value); ast_channel_unlock(chan); } else if (!strncasecmp("pres", data, 4)) { int i; char *s, *val; /* Strip leading spaces */ while ((value[0] == '\t') || (value[0] == ' ')) ++value; val = ast_strdupa(value); /* Strip trailing spaces */ s = val + strlen(val); while ((s != val) && ((s[-1] == '\t') || (s[-1] == ' '))) --s; *s = '\0'; if ((val[0] >= '0') && (val[0] <= '9')) i = atoi(val); else i = ast_parse_caller_presentation(val); if (i < 0) ast_log(LOG_ERROR, "Unknown calling number presentation '%s', value unchanged\n", val); else chan->cid.cid_pres = i; } else if (!strncasecmp("ton", data, 3)) { int i = atoi(value); chan->cid.cid_ton = i; } else { ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data); } return 0; }