コード例 #1
0
static struct ast_config *realtime_directory(char *context)
{
	struct ast_config *cfg;
	struct ast_config *rtdata;
	struct ast_category *cat;
	struct ast_variable *var;
	char *mailbox;
	char *fullname;
	char *hidefromdir;
	char tmp[100];

	/* Load flat file config. */
	cfg = ast_config_load(VOICEMAIL_CONFIG);

	if (!cfg) {
		/* Loading config failed. */
		ast_log(LOG_WARNING, "Loading config failed.\n");
		return NULL;
	}

	/* Get realtime entries, categorized by their mailbox number
	   and present in the requested context */
	rtdata = ast_load_realtime_multientry("voicemail", "mailbox LIKE", "%", "context", context, NULL);

	/* if there are no results, just return the entries from the config file */
	if (!rtdata)
		return cfg;

	/* Does the context exist within the config file? If not, make one */
	cat = ast_category_get(cfg, context);
	if (!cat) {
		cat = ast_category_new(context);
		if (!cat) {
			ast_log(LOG_WARNING, "Out of memory\n");
			ast_config_destroy(cfg);
			return NULL;
		}
		ast_category_append(cfg, cat);
	}

	mailbox = ast_category_browse(rtdata, NULL);
	while (mailbox) {
		fullname = ast_variable_retrieve(rtdata, mailbox, "fullname");
		hidefromdir = ast_variable_retrieve(rtdata, mailbox, "hidefromdir");
		snprintf(tmp, sizeof(tmp), "no-password,%s,hidefromdir=%s",
			 fullname ? fullname : "",
			 hidefromdir ? hidefromdir : "no");
		var = ast_variable_new(mailbox, tmp);
		if (var)
			ast_variable_append(cat, var);
		else
			ast_log(LOG_WARNING, "Out of memory adding mailbox '%s'\n", mailbox);
		mailbox = ast_category_browse(rtdata, mailbox);
	}
	ast_config_destroy(rtdata);

	return cfg;
}
コード例 #2
0
static int realtime_sorcery_destroy(const char *database, const char *table, const char *keyfield, const char *entity, const struct ast_variable *fields)
{
	struct ast_category *found;
	if (!(found = ast_category_get(realtime_objects, entity, NULL))) {
		return 0;
	}

	ast_category_delete(realtime_objects, found);

	return 1;
}
コード例 #3
0
static int realtime_sorcery_update(const char *database, const char *table, const char *keyfield, const char *entity, const struct ast_variable *fields)
{
	struct ast_category *object, *found;

	if (!(found = ast_category_get(realtime_objects, entity, NULL))) {
		return 0;
	} else if (!(object = ast_category_new(entity, "", 0))) {
		return -1;
	}

	ast_category_delete(realtime_objects, found);
	ast_variable_append(object, ast_variables_dup((struct ast_variable*)fields));
	ast_variable_append(object, ast_variable_new(keyfield, entity, ""));
	ast_category_append(realtime_objects, object);

	return 1;
}