コード例 #1
0
static void database_increment( char *key )
{
	int res = 0;
	unsigned v;
	char value[16];
	
	
	if (ast_strlen_zero(db_family))
		return; /* If not defined, don't do anything */
	
	res = ast_db_get(db_family, key, value, sizeof(value) - 1);
	
	if(res){
		if(option_verbose >= 4)
			ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: Creating database entry %s and setting to 1\n", key);
		/* Guess we have to create it */
		res = ast_db_put(db_family, key, "1");
		return;
	}
	
	sscanf(value, "%u", &v);
	v++;
	
	if(option_verbose >= 4)
		ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: New value for %s: %u\n", key, v);
		
	snprintf(value, sizeof(value), "%u", v);
	
	res = ast_db_put(db_family, key, value);
	
	if((res)&&(option_verbose >= 4))
		ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: database_increment write error");
	
	return;	
}
コード例 #2
0
ファイル: app_alarmreceiver.c プロジェクト: litnimax/asterisk
/*!
 * \brief Attempt to access a database variable and increment it
 *
 * \note Only if the user defined db-family in alarmreceiver.conf
 *
 * The alarmreceiver app will write statistics to a few variables
 * in this family if it is defined. If the new key doesn't exist in the
 * family, then create it and set its value to 1.
 *
 * \param key A database key to increment
 * \return Nothing
 */
static void database_increment(char *key)
{
	unsigned v;
	char value[16];

	if (ast_strlen_zero(db_family)) {
		return;	/* If not defined, don't do anything */
	}

	if (ast_db_get(db_family, key, value, sizeof(value) - 1)) {
		ast_verb(4, "AlarmReceiver: Creating database entry %s and setting to 1\n", key);
		/* Guess we have to create it */
		ast_db_put(db_family, key, "1");
		return;
	}

	sscanf(value, "%30u", &v);
	v++;

	ast_verb(4, "AlarmReceiver: New value for %s: %u\n", key, v);
	snprintf(value, sizeof(value), "%u", v);

	if (ast_db_put(db_family, key, value)) {
		ast_verb(4, "AlarmReceiver: database_increment write error\n");
	}

	return;
}
コード例 #3
0
static int devstate_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
{
	size_t len = strlen("Custom:");
	enum ast_device_state state_val;

	if (strncasecmp(data, "Custom:", len)) {
		ast_log(LOG_WARNING, "The DEVICE_STATE function can only be used to set 'Custom:' device state!\n");
		return -1;
	}
	data += len;
	if (ast_strlen_zero(data)) {
		ast_log(LOG_WARNING, "DEVICE_STATE function called with no custom device name!\n");
		return -1;
	}

	state_val = ast_devstate_val(value);

	if (state_val == AST_DEVICE_UNKNOWN) {
		ast_log(LOG_ERROR, "DEVICE_STATE function given invalid state value '%s'\n", value);
		return -1;
	}

	ast_db_put(astdb_family, data, value);

	ast_devstate_changed(state_val, AST_DEVSTATE_CACHABLE, "Custom:%s", data);

	return 0;
}
コード例 #4
0
ファイル: db.c プロジェクト: aderbas/asterisk
static char *handle_cli_database_put(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
	int res;

	switch (cmd) {
	case CLI_INIT:
		e->command = "database put";
		e->usage =
			"Usage: database put <family> <key> <value>\n"
			"       Adds or updates an entry in the Asterisk database for\n"
			"       a given family, key, and value.\n";
		return NULL;
	case CLI_GENERATE:
		return NULL;
	}

	if (a->argc != 5)
		return CLI_SHOWUSAGE;
	res = ast_db_put(a->argv[2], a->argv[3], a->argv[4]);
	if (res)  {
		ast_cli(a->fd, "Failed to update entry\n");
	} else {
		ast_cli(a->fd, "Updated database successfully\n");
	}
	return CLI_SUCCESS;
}
コード例 #5
0
ファイル: db.c プロジェクト: BackupTheBerlios/solid-pbx-svn
static int manager_dbput(struct mansession *s, struct message *m)
{
	char *family = astman_get_header(m, "Family");
	char *key = astman_get_header(m, "Key");
	char *val = astman_get_header(m, "Val");
	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;
	}
	if (ast_strlen_zero(val)) {
		astman_send_error(s, m, "No val specified");
		return 0;
	}

	res = ast_db_put(family, key, val);
	if (res) {
		astman_send_error(s, m, "Failed to update entry");
	} else {
		astman_send_ack(s, m, "Updated database successfully");
	}
	return 0;
}
コード例 #6
0
ファイル: db.c プロジェクト: BackupTheBerlios/solid-pbx-svn
static int database_put(int fd, int argc, char *argv[])
{
	int res;
	if (argc != 5)
		return RESULT_SHOWUSAGE;
	res = ast_db_put(argv[2], argv[3], argv[4]);
	if (res)  {
		ast_cli(fd, "Failed to update entry\n");
	} else {
		ast_cli(fd, "Updated database successfully\n");
	}
	return RESULT_SUCCESS;
}
コード例 #7
0
static int sorcery_astdb_create(const struct ast_sorcery *sorcery, void *data, void *object)
{
	RAII_VAR(struct ast_json *, objset, ast_sorcery_objectset_json_create(sorcery, object), ast_json_unref);
	RAII_VAR(char *, value, NULL, ast_json_free);
	const char *prefix = data;
	char family[strlen(prefix) + strlen(ast_sorcery_object_get_type(object)) + 2];

	if (!objset || !(value = ast_json_dump_string(objset))) {
		return -1;
	}

	snprintf(family, sizeof(family), "%s/%s", prefix, ast_sorcery_object_get_type(object));

	return ast_db_put(family, ast_sorcery_object_get_id(object), value);
}
コード例 #8
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;
}