static int del_exec(struct ast_channel *chan, const char *data) { char *argv, *family, *key; static int deprecation_warning = 0; if (!deprecation_warning) { deprecation_warning = 1; ast_log(LOG_WARNING, "The DBdel application has been deprecated in favor of the DB_DELETE dialplan function!\n"); } argv = ast_strdupa(data); if (strchr(argv, '/')) { family = strsep(&argv, "/"); key = strsep(&argv, "\0"); if (!family || !key) { ast_debug(1, "Ignoring; Syntax error in argument\n"); return 0; } ast_verb(3, "DBdel: family=%s, key=%s\n", family, key); if (ast_db_del(family, key)) ast_verb(3, "DBdel: Error deleting key from database.\n"); } else { ast_debug(1, "Ignoring, no parameters\n"); } return 0; }
static char *handle_cli_database_del(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { int res; switch (cmd) { case CLI_INIT: e->command = "database del"; e->usage = "Usage: database del <family> <key>\n" " Deletes an entry in the Asterisk database for a given\n" " family and key.\n"; return NULL; case CLI_GENERATE: return NULL; } if (a->argc != 4) return CLI_SHOWUSAGE; res = ast_db_del(a->argv[2], a->argv[3]); if (res) { ast_cli(a->fd, "Database entry does not exist.\n"); } else { ast_cli(a->fd, "Database entry removed.\n"); } return CLI_SUCCESS; }
static int database_del(int fd, int argc, char *argv[]) { int res; if (argc != 4) return RESULT_SHOWUSAGE; res = ast_db_del(argv[2], argv[3]); if (res) { ast_cli(fd, "Database entry does not exist.\n"); } else { ast_cli(fd, "Database entry removed.\n"); } return RESULT_SUCCESS; }
static int sorcery_astdb_delete(const struct ast_sorcery *sorcery, void *data, void *object) { const char *prefix = data; char family[strlen(prefix) + strlen(ast_sorcery_object_get_type(object)) + 2]; char value[2]; snprintf(family, sizeof(family), "%s/%s", prefix, ast_sorcery_object_get_type(object)); if (ast_db_get(family, ast_sorcery_object_get_id(object), value, sizeof(value))) { return -1; } return ast_db_del(family, ast_sorcery_object_get_id(object)); }
static int del_exec(struct ast_channel *chan, void *data) { char *argv, *family, *key; struct ast_module_user *u; static int deprecation_warning = 0; u = ast_module_user_add(chan); if (!deprecation_warning) { deprecation_warning = 1; ast_log(LOG_WARNING, "The DBdel application has been deprecated in favor of the DB_DELETE dialplan function!\n"); } argv = ast_strdupa(data); if (strchr(argv, '/')) { family = strsep(&argv, "/"); key = strsep(&argv, "\0"); if (!family || !key) { ast_log(LOG_DEBUG, "Ignoring; Syntax error in argument\n"); ast_module_user_remove(u); return 0; } if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "DBdel: family=%s, key=%s\n", family, key); if (ast_db_del(family, key)) { if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "DBdel: Error deleting key from database.\n"); } } else { ast_log(LOG_DEBUG, "Ignoring, no parameters\n"); } ast_module_user_remove(u); return 0; }
static int dialgroup_refreshdb(struct ast_channel *chan, const char *cdialgroup) { int len = 500, res = 0; char *buf = NULL; char *dialgroup = ast_strdupa(cdialgroup); do { len *= 2; buf = ast_realloc(buf, len); if ((res = dialgroup_read(chan, "", dialgroup, buf, len)) < 0) { ast_free(buf); return -1; } } while (res == 1); if (ast_strlen_zero(buf)) { ast_db_del("dialgroup", cdialgroup); } else { ast_db_put("dialgroup", cdialgroup, buf); } ast_free(buf); return 0; }
static int manager_dbdel(struct mansession *s, const struct message *m) { const char *family = astman_get_header(m, "Family"); const char *key = astman_get_header(m, "Key"); int res; if (ast_strlen_zero(family)) { astman_send_error(s, m, "No family specified."); return 0; } if (ast_strlen_zero(key)) { astman_send_error(s, m, "No key specified."); return 0; } res = ast_db_del(family, key); if (res) astman_send_error(s, m, "Database entry not found"); else astman_send_ack(s, m, "Key deleted successfully"); return 0; }
static int auth_exec(struct ast_channel *chan, void *data) { int res=0; int retries; struct localuser *u; char password[256]=""; char passwd[256]; char *opts; char *prompt; if (!data || ast_strlen_zero(data)) { ast_log(LOG_WARNING, "Authenticate requires an argument(password)\n"); return -1; } LOCAL_USER_ADD(u); if (chan->_state != AST_STATE_UP) { res = ast_answer(chan); if (res) { LOCAL_USER_REMOVE(u); return -1; } } strncpy(password, data, sizeof(password) - 1); opts=strchr(password, '|'); if (opts) { *opts = 0; opts++; } else opts = ""; /* Start asking for password */ prompt = "agent-pass"; for (retries = 0; retries < 3; retries++) { res = ast_app_getdata(chan, prompt, passwd, sizeof(passwd) - 2, 0); if (res < 0) break; res = 0; if (password[0] == '/') { if (strchr(opts, 'd')) { char tmp[256]; /* Compare against a database key */ if (!ast_db_get(password + 1, passwd, tmp, sizeof(tmp))) { /* It's a good password */ if (strchr(opts, 'r')) { ast_db_del(password + 1, passwd); } break; } } else { /* Compare against a file */ FILE *f; f = fopen(password, "r"); if (f) { char buf[256] = ""; while(!feof(f)) { fgets(buf, sizeof(buf), f); if (!feof(f) && !ast_strlen_zero(buf)) { buf[strlen(buf) - 1] = '\0'; if (!ast_strlen_zero(buf) && !strcmp(passwd, buf)) break; } } fclose(f); if (!ast_strlen_zero(buf) && !strcmp(passwd, buf)) break; } else ast_log(LOG_WARNING, "Unable to open file '%s' for authentication: %s\n", password, strerror(errno)); } } else { /* Compare against a fixed password */ if (!strcmp(passwd, password)) break; } prompt="auth-incorrect"; } if ((retries < 3) && !res) { if (strchr(opts, 'a')) ast_cdr_setaccount(chan, passwd); res = ast_streamfile(chan, "auth-thankyou", chan->language); if (!res) res = ast_waitstream(chan, ""); } else { if (!res) res = ast_streamfile(chan, "vm-goodbye", chan->language); if (!res) res = ast_waitstream(chan, ""); res = -1; } LOCAL_USER_REMOVE(u); return res; }