Esempio n. 1
0
static void loadconfigurationfile(void)
{
	char *cat;
	struct ast_config *cfg;
	struct ast_variable *v;
	
	cfg = ast_load(CONF_FILE);
	if (!cfg) {
		/* Standard configuration */
		enablecdr = 0;
		return;
	}
	
	cat = ast_category_browse(cfg, NULL);
	while (cat) {
		if (!strcasecmp(cat, "general")) {
			v = ast_variable_browse(cfg, cat);
			while (v) {
				if (!strcasecmp(v->name, "enabled")) {
					enablecdr = ast_true(v->value);
				}
				
				v = v->next;
			}
		}
	
		/* Next category */
		cat = ast_category_browse(cfg, cat);
	}
	
	ast_destroy(cfg);
}
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;
}
Esempio n. 3
0
/*!
 * \brief Load res_snmp.conf config file
 * \return 1 on load, 0 file does not exist
*/
static int load_config(void)
{
    struct ast_variable *var;
    struct ast_config *cfg;
    struct ast_flags config_flags = { 0 };
    char *cat;

    res_snmp_enabled = 0;
    res_snmp_agentx_subagent = 1;
    cfg = ast_config_load("res_snmp.conf", config_flags);
    if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
        ast_log(LOG_WARNING, "Could not load res_snmp.conf\n");
        return 0;
    }
    cat = ast_category_browse(cfg, NULL);
    while (cat) {
        var = ast_variable_browse(cfg, cat);

        if (strcasecmp(cat, "general") == 0) {
            while (var) {
                if (strcasecmp(var->name, "subagent") == 0) {
                    if (ast_true(var->value))
                        res_snmp_agentx_subagent = 1;
                    else if (ast_false(var->value))
                        res_snmp_agentx_subagent = 0;
                    else {
                        ast_log(LOG_ERROR, "Value '%s' does not evaluate to true or false.\n", var->value);
                        ast_config_destroy(cfg);
                        return 1;
                    }
                } else if (strcasecmp(var->name, "enabled") == 0) {
                    res_snmp_enabled = ast_true(var->value);
                } else {
                    ast_log(LOG_ERROR, "Unrecognized variable '%s' in category '%s'\n", var->name, cat);
                    ast_config_destroy(cfg);
                    return 1;
                }
                var = var->next;
            }
        } else {
            ast_log(LOG_ERROR, "Unrecognized category '%s'\n", cat);
            ast_config_destroy(cfg);
            return 1;
        }

        cat = ast_category_browse(cfg, cat);
    }
    ast_config_destroy(cfg);
    return 1;
}
static struct ast_config *realtime_sorcery_multi(const char *database, const char *table, const struct ast_variable *fields)
{
	struct ast_config *objects;
	char *object_id = NULL;

	if (!(objects = ast_config_new())) {
		return NULL;
	}

	while ((object_id = ast_category_browse(realtime_objects, object_id))) {
		struct ast_category *object;

		if (!realtime_is_object_matching(object_id, fields)) {
			continue;
		}

		if (!(object = ast_category_new("", "", 0))) {
			ast_config_destroy(objects);
			return NULL;
		}

		ast_variable_append(object, ast_variables_dup(ast_category_root(realtime_objects, object_id)));
		ast_category_append(objects, object);
	}

	return objects;
}
Esempio n. 5
0
/*!
 * \brief Tests that the contents of an ast_config is what is expected
 *
 * \param cfg Config to test
 * \retval -1 Failed to pass a test
 * \retval 0 Config passes checks
 */
static int test_config_validity(struct ast_config *cfg)
{
	int i;
	const char *cat_iter = NULL;
	/* Okay, let's see if the correct content is there */
	for (i = 0; i < ARRAY_LEN(categories); ++i) {
		struct ast_variable *var = NULL;
		size_t j;
		cat_iter = ast_category_browse(cfg, cat_iter);
		if (strcmp(cat_iter, categories[i].category)) {
			ast_log(LOG_ERROR, "Category name mismatch, %s does not match %s\n", cat_iter, categories[i].category);
			return -1;
		}
		for (j = 0; j < ARRAY_LEN(categories[i].vars); ++j) {
			var = var ? var->next : ast_variable_browse(cfg, cat_iter);
			if (strcmp(var->name, categories[i].vars[j].name)) {
				ast_log(LOG_ERROR, "Variable name mismatch, %s does not match %s\n", var->name, categories[i].vars[j].name);
				return -1;
			}
			if (strcmp(var->value, categories[i].vars[j].val)) {
				ast_log(LOG_ERROR, "Variable value mismatch, %s does not match %s\n", var->value, categories[i].vars[j].val);
				return -1;
			}
		}
	}
	return 0;
}
static int load_config(int reload)
{
	const char *cat = NULL;
	struct ast_config *cfg;
	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
	struct ast_variable *v;
	int newenablecel = CEL_AMI_ENABLED_DEFAULT;
	int new_cel_show_user_def = CEL_SHOW_USERDEF_DEFAULT;

	cfg = ast_config_load(CONF_FILE, config_flags);
	if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
		return 0;
	}

	if (cfg == CONFIG_STATUS_FILEINVALID) {
		ast_log(LOG_WARNING, "Configuration file '%s' is invalid. CEL manager Module not activated.\n",
			CONF_FILE);
		enablecel = 0;
		return -1;
	} else if (!cfg) {
		ast_log(LOG_WARNING, "Failed to load configuration file. CEL manager Module not activated.\n");
		enablecel = 0;
		return -1;
	}

	while ((cat = ast_category_browse(cfg, cat))) {
		if (strcasecmp(cat, "manager")) {
			continue;
		}

		for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
			if (!strcasecmp(v->name, "enabled")) {
				newenablecel = ast_true(v->value) ? 1 : 0;
			} else if (!strcasecmp(v->name, "show_user_defined")) {
				new_cel_show_user_def = ast_true(v->value) ? 1 : 0;
			} else {
				ast_log(LOG_NOTICE, "Unknown option '%s' specified "
						"for cel_manager.\n", v->name);
			}
		}
	}

	ast_config_destroy(cfg);

	cel_show_user_def = new_cel_show_user_def;
	if (enablecel && !newenablecel) {
		if (event_sub) {
			event_sub = ast_event_unsubscribe(event_sub);
		}
	} else if (!enablecel && newenablecel) {
		event_sub = ast_event_subscribe(AST_EVENT_CEL, manager_log, "Manager Event Logging", NULL, AST_EVENT_IE_END);
		if (!event_sub) {
			ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CEL handling\n");
		}
	}
	enablecel = newenablecel;

	return 0;
}
static struct ast_variable *realtime_sorcery(const char *database, const char *table, const struct ast_variable *fields)
{
	char *object_id = NULL;

	while ((object_id = ast_category_browse(realtime_objects, object_id))) {
		if (!realtime_is_object_matching(object_id, fields)) {
			continue;
		}

		return ast_variables_dup(ast_category_root(realtime_objects, object_id));
	}

	return NULL;
}
Esempio n. 8
0
static int do_directory(struct ast_channel *chan, struct ast_config *cfg, struct ast_config *ucfg, char *context, char *dialcontext, char digit, int last, int readext, int fromappvm)
{
	/* Read in the first three digits..  "digit" is the first digit, already read */
	char ext[NUMDIGITS + 1], *cat;
	char name[80] = "";
	struct ast_variable *v;
	int res;
	int found=0;
	int lastuserchoice = 0;
	char *start, *conv, *stringp = NULL;
	const char *pos;
	int breakout = 0;

	if (ast_strlen_zero(context)) {
		ast_log(LOG_WARNING,
			"Directory must be called with an argument "
			"(context in which to interpret extensions)\n");
		return -1;
	}
	if (digit == '0') {
		if (!ast_goto_if_exists(chan, dialcontext, "o", 1) ||
		    (!ast_strlen_zero(chan->macrocontext) &&
		     !ast_goto_if_exists(chan, chan->macrocontext, "o", 1))) {
			return 0;
		} else {
			ast_log(LOG_WARNING, "Can't find extension 'o' in current context.  "
				"Not Exiting the Directory!\n");
			res = 0;
		}
	}	
	if (digit == '*') {
		if (!ast_goto_if_exists(chan, dialcontext, "a", 1) ||
		    (!ast_strlen_zero(chan->macrocontext) &&
		     !ast_goto_if_exists(chan, chan->macrocontext, "a", 1))) {
			return 0;
		} else {
			ast_log(LOG_WARNING, "Can't find extension 'a' in current context.  "
				"Not Exiting the Directory!\n");
			res = 0;
		}
	}	
	memset(ext, 0, sizeof(ext));
	ext[0] = digit;
	res = 0;
	if (ast_readstring(chan, ext + 1, NUMDIGITS - 1, 3000, 3000, "#") < 0) res = -1;
	if (!res) {
		/* Search for all names which start with those digits */
		v = ast_variable_browse(cfg, context);
		while(v && !res) {
			/* Find all candidate extensions */
			while(v) {
				/* Find a candidate extension */
				start = strdup(v->value);
				if (start && !strcasestr(start, "hidefromdir=yes")) {
					stringp=start;
					strsep(&stringp, ",");
					pos = strsep(&stringp, ",");
					if (pos) {
						ast_copy_string(name, pos, sizeof(name));
						/* Grab the last name */
						if (last && strrchr(pos,' '))
							pos = strrchr(pos, ' ') + 1;
						conv = convert(pos);
						if (conv) {
							if (!strncmp(conv, ext, strlen(ext))) {
								/* Match! */
								found++;
								free(conv);
								free(start);
								break;
							}
							free(conv);
						}
					}
					free(start);
				}
				v = v->next;
			}

			if (v) {
				/* We have a match -- play a greeting if they have it */
				res = play_mailbox_owner(chan, context, dialcontext, v->name, name, readext, fromappvm);
				switch (res) {
					case -1:
						/* user pressed '1' but extension does not exist, or
						 * user hungup
						 */
						lastuserchoice = 0;
						break;
					case '1':
						/* user pressed '1' and extensions exists;
						   play_mailbox_owner will already have done
						   a goto() on the channel
						 */
						lastuserchoice = res;
						break;
					case '*':
						/* user pressed '*' to skip something found */
						lastuserchoice = res;
						res = 0;
						break;
					default:
						break;
				}
				v = v->next;
			}
		}

		if (!res && ucfg) {
			/* Search users.conf for all names which start with those digits */
			for (cat = ast_category_browse(ucfg, NULL); cat && !res ; cat = ast_category_browse(ucfg, cat)) {
				if (!strcasecmp(cat, "general"))
					continue;
				if (!ast_true(ast_config_option(ucfg, cat, "hasdirectory")))
					continue;
				
				/* Find all candidate extensions */
				if ((pos = ast_variable_retrieve(ucfg, cat, "fullname"))) {
					ast_copy_string(name, pos, sizeof(name));
					/* Grab the last name */
					if (last && strrchr(pos,' '))
						pos = strrchr(pos, ' ') + 1;
					conv = convert(pos);
					if (conv) {
						if (!strcmp(conv, ext)) {
							/* Match! */
							found++;
							/* We have a match -- play a greeting if they have it */
							res = play_mailbox_owner(chan, context, dialcontext, cat, name, readext, fromappvm);
							switch (res) {
							case -1:
								/* user pressed '1' but extension does not exist, or
								 * user hungup
								 */
								lastuserchoice = 0;
								breakout = 1;
								break;
							case '1':
								/* user pressed '1' and extensions exists;
								   play_mailbox_owner will already have done
								   a goto() on the channel
								 */
								lastuserchoice = res;
								breakout = 1;
								break;
							case '*':
								/* user pressed '*' to skip something found */
								lastuserchoice = res;
								breakout = 0;
								res = 0;
								break;
							default:
								breakout = 1;
								break;
							}
							free(conv);
							if (breakout)
								break;
						}
						else
							free(conv);
					}
				}
			}
		}
			
		if (lastuserchoice != '1') {
			res = ast_streamfile(chan, found ? "dir-nomore" : "dir-nomatch", chan->language);
			if (!res)
				res = 1;
			return res;
		}
		return 0;
	}
	return res;
}
Esempio n. 9
0
/*
 * Load module stuff
 */
static int ind_load_module(void)
{
	struct ast_config *cfg;
	struct ast_variable *v;
	char *cxt;
	char *c;
	struct ind_tone_zone *tones;
	const char *country = NULL;

	/* that the following cast is needed, is yuk! */
	/* yup, checked it out. It is NOT written to. */
	cfg = ast_config_load((char *)config);
	if (!cfg)
		return -1;

	/* Use existing config to populate the Indication table */
	cxt = ast_category_browse(cfg, NULL);
	while(cxt) {
		/* All categories but "general" are considered countries */
		if (!strcasecmp(cxt, "general")) {
			cxt = ast_category_browse(cfg, cxt);
			continue;
		}		
		if (!(tones = ast_calloc(1, sizeof(*tones)))) {
			ast_config_destroy(cfg);
			return -1;
		}
		ast_copy_string(tones->country,cxt,sizeof(tones->country));

		v = ast_variable_browse(cfg, cxt);
		while(v) {
			if (!strcasecmp(v->name, "description")) {
				ast_copy_string(tones->description, v->value, sizeof(tones->description));
			} else if ((!strcasecmp(v->name,"ringcadence"))||(!strcasecmp(v->name,"ringcadance"))) {
				char *ring,*rings = ast_strdupa(v->value);
				c = rings;
				ring = strsep(&c,",");
				while (ring) {
					int *tmp, val;
					if (!isdigit(ring[0]) || (val=atoi(ring))==-1) {
						ast_log(LOG_WARNING,"Invalid ringcadence given '%s' at line %d.\n",ring,v->lineno);
						ring = strsep(&c,",");
						continue;
					}					
					if (!(tmp = ast_realloc(tones->ringcadence, (tones->nrringcadence + 1) * sizeof(int)))) {
						ast_config_destroy(cfg);
						return -1;
					}
					tones->ringcadence = tmp;
					tmp[tones->nrringcadence] = val;
					tones->nrringcadence++;
					/* next item */
					ring = strsep(&c,",");
				}
			} else if (!strcasecmp(v->name,"alias")) {
				char *countries = ast_strdupa(v->value);
				c = countries;
				country = strsep(&c,",");
				while (country) {
					struct ind_tone_zone* azone;
					if (!(azone = ast_calloc(1, sizeof(*azone)))) {
						ast_config_destroy(cfg);
						return -1;
					}
					ast_copy_string(azone->country, country, sizeof(azone->country));
					ast_copy_string(azone->alias, cxt, sizeof(azone->alias));
					if (ast_register_indication_country(azone)) {
						ast_log(LOG_WARNING, "Unable to register indication alias at line %d.\n",v->lineno);
						free(tones);
					}
					/* next item */
					country = strsep(&c,",");
				}
			} else {
				/* add tone to country */
				struct ind_tone_zone_sound *ps,*ts;
				for (ps=NULL,ts=tones->tones; ts; ps=ts, ts=ts->next) {
					if (strcasecmp(v->name,ts->name)==0) {
						/* already there */
						ast_log(LOG_NOTICE,"Duplicate entry '%s', skipped.\n",v->name);
						goto out;
					}
				}
				/* not there, add it to the back */				
				if (!(ts = ast_malloc(sizeof(*ts)))) {
					ast_config_destroy(cfg);
					return -1;
				}
				ts->next = NULL;
				ts->name = strdup(v->name);
				ts->data = strdup(v->value);
				if (ps)
					ps->next = ts;
				else
					tones->tones = ts;
			}
out:			v = v->next;
		}
		if (tones->description[0] || tones->alias[0] || tones->tones) {
			if (ast_register_indication_country(tones)) {
				ast_log(LOG_WARNING, "Unable to register indication at line %d.\n",v->lineno);
				free(tones);
			}
		} else free(tones);

		cxt = ast_category_browse(cfg, cxt);
	}

	/* determine which country is the default */
	country = ast_variable_retrieve(cfg,"general","country");
	if (!country || !*country || ast_set_indication_country(country))
		ast_log(LOG_WARNING,"Unable to set the default country (for indication tones)\n");

	ast_config_destroy(cfg);
	return 0;
}
Esempio n. 10
0
static int load_config(int reload)
{
	char *cat = NULL;
	struct ast_config *cfg;
	struct ast_variable *v;
	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
	int newenablecdr = 0;

	cfg = ast_config_load(CONF_FILE, config_flags);
	if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
		return 0;
	}

	if (cfg == CONFIG_STATUS_FILEINVALID) {
		ast_log(LOG_ERROR, "Config file '%s' could not be parsed\n", CONF_FILE);
		return -1;
	}

	if (!cfg) {
		/* Standard configuration */
		ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n");
		if (enablecdr)
			ast_cdr_unregister(name);
		enablecdr = 0;
		return -1;
	}

	if (reload) {
		ast_rwlock_wrlock(&customfields_lock);
	}

	if (reload && customfields) {
		ast_free(customfields);
		customfields = NULL;
	}

	while ( (cat = ast_category_browse(cfg, cat)) ) {
		if (!strcasecmp(cat, "general")) {
			v = ast_variable_browse(cfg, cat);
			while (v) {
				if (!strcasecmp(v->name, "enabled"))
					newenablecdr = ast_true(v->value);

				v = v->next;
			}
		} else if (!strcasecmp(cat, "mappings")) {
			customfields = ast_str_create(CUSTOM_FIELDS_BUF_SIZE);
			v = ast_variable_browse(cfg, cat);
			while (v) {
				if (customfields && !ast_strlen_zero(v->name) && !ast_strlen_zero(v->value)) {
					if ((ast_str_strlen(customfields) + strlen(v->value) + strlen(v->name) + 14) < ast_str_size(customfields)) {
						ast_str_append(&customfields, -1, "%s: ${CDR(%s)}\r\n", v->value, v->name);
						ast_log(LOG_NOTICE, "Added mapping %s: ${CDR(%s)}\n", v->value, v->name);
					} else {
						ast_log(LOG_WARNING, "No more buffer space to add other custom fields\n");
						break;
					}

				}
				v = v->next;
			}
		}
	}

	if (reload) {
		ast_rwlock_unlock(&customfields_lock);
	}

	ast_config_destroy(cfg);

	if (enablecdr && !newenablecdr)
		ast_cdr_unregister(name);
	else if (!enablecdr && newenablecdr)
		ast_cdr_register(name, "Asterisk Manager Interface CDR Backend", manager_log);
	enablecdr = newenablecdr;

	return 0;
}
Esempio n. 11
0
int load_mrcp_config(const char *filename, const char *who_asked)
{
	const char *cat = NULL;
	struct ast_variable *var;
	const char *value = NULL;

#if AST_VERSION_AT_LEAST(1,6,0)
	struct ast_flags config_flags = { 0 };
	struct ast_config *cfg = ast_config_load2(filename, who_asked, config_flags);
#else
	struct ast_config *cfg = ast_config_load(filename);
#endif
	if (!cfg) {
		ast_log(LOG_WARNING, "No such configuration file %s\n", filename);
		return -1;
	}
#if AST_VERSION_AT_LEAST(1,6,2)
	if (cfg == CONFIG_STATUS_FILEINVALID) {
		ast_log(LOG_ERROR, "Config file %s is in an invalid format\n", filename);
		return -1;
	}
#endif

	globals_clear();
	globals_default();

	if ((value = ast_variable_retrieve(cfg, "general", "default-tts-profile")) != NULL) {
		ast_log(LOG_DEBUG, "general.default-tts-profile=%s\n",  value);
		globals.unimrcp_default_synth_profile = apr_pstrdup(globals.pool, value);
	} else {
		ast_log(LOG_ERROR, "Unable to load genreal.default-tts-profile from config file, aborting\n");
		ast_config_destroy(cfg);
		return -1;
	}
	if ((value = ast_variable_retrieve(cfg, "general", "default-asr-profile")) != NULL) {
		ast_log(LOG_DEBUG, "general.default-asr-profile=%s\n",  value);
		globals.unimrcp_default_recog_profile = apr_pstrdup(globals.pool, value);
	} else {
		ast_log(LOG_ERROR, "Unable to load genreal.default-asr-profile from config file, aborting\n");
		ast_config_destroy(cfg);
		return -1;
	}
	if ((value = ast_variable_retrieve(cfg, "general", "log-level")) != NULL) {
		ast_log(LOG_DEBUG, "general.log-level=%s\n",  value);
		globals.unimrcp_log_level = apr_pstrdup(globals.pool, value);
	}
	if ((value = ast_variable_retrieve(cfg, "general", "max-connection-count")) != NULL) {
		ast_log(LOG_DEBUG, "general.max-connection-count=%s\n",  value);
		globals.unimrcp_max_connection_count = apr_pstrdup(globals.pool, value);
	}
	if ((value = ast_variable_retrieve(cfg, "general", "offer-new-connection")) != NULL) {
		ast_log(LOG_DEBUG, "general.offer-new-connection=%s\n",  value);
		globals.unimrcp_offer_new_connection = apr_pstrdup(globals.pool, value);
	}
	if ((value = ast_variable_retrieve(cfg, "general", "rx-buffer-size")) != NULL) {
		ast_log(LOG_DEBUG, "general.rx-buffer-size=%s\n",  value);
		globals.unimrcp_rx_buffer_size = apr_pstrdup(globals.pool, value);
	}
	if ((value = ast_variable_retrieve(cfg, "general", "tx-buffer-size")) != NULL) {
		ast_log(LOG_DEBUG, "general.tx-buffer-size=%s\n",  value);
		globals.unimrcp_tx_buffer_size = apr_pstrdup(globals.pool, value);
	}
	if ((value = ast_variable_retrieve(cfg, "general", "request-timeout")) != NULL) {
		ast_log(LOG_DEBUG, "general.request-timeout=%s\n",  value);
		globals.unimrcp_request_timeout = apr_pstrdup(globals.pool, value);
	}

	while ((cat = ast_category_browse(cfg, cat)) != NULL) {
		if (strcasecmp(cat, "general") != 0) {
			if ((value = ast_variable_retrieve(cfg, cat, "version")) != NULL) {
				ast_mrcp_profile_t *mod_profile = NULL;

				if (profile_create(&mod_profile, cat, value, globals.pool) == 0) {
					apr_hash_set(globals.profiles, apr_pstrdup(globals.pool, mod_profile->name), APR_HASH_KEY_STRING, mod_profile);

					for (var = ast_variable_browse(cfg, cat); var; var = var->next) {
						ast_log(LOG_DEBUG, "%s.%s=%s\n", cat, var->name, var->value);
						apr_hash_set(mod_profile->cfg, apr_pstrdup(globals.pool, var->name), APR_HASH_KEY_STRING, apr_pstrdup(globals.pool, var->value));
					}
				} else
					ast_log(LOG_WARNING, "Unable to create a profile for %s\n", cat);
			} else
				ast_log(LOG_WARNING, "Category %s does not have a version variable defined\n", cat);
		}
	}

	ast_config_destroy(cfg);

	return 0;
}
Esempio n. 12
0
static int pbx_load_module(void)
{
	struct ast_config *cfg;
	struct ast_variable *v;
	char *cxt, *ext, *pri, *appl, *data, *tc, *cidmatch;
	struct ast_context *con;
	char *start, *end;
	char realvalue[256];

	cfg = ast_load(config);
	if (cfg) {
		/* Use existing config to populate the PBX table */
		static_config = ast_true(ast_variable_retrieve(cfg, "general",
			"static"));
		write_protect_config = ast_true(ast_variable_retrieve(cfg, "general",
			"writeprotect"));
		v = ast_variable_browse(cfg, "globals");
		while(v) {
			memset(realvalue, 0, sizeof(realvalue));
			pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
			pbx_builtin_setvar_helper(NULL, v->name, realvalue);
			v = v->next;
		}
		cxt = ast_category_browse(cfg, NULL);
		while(cxt) {
			/* All categories but "general" or "globals" are considered contexts */
			if (!strcasecmp(cxt, "general") || !strcasecmp(cxt, "globals")) {
				cxt = ast_category_browse(cfg, cxt);
				continue;
			}
			if ((con=ast_context_create(&local_contexts,cxt, registrar))) {
				v = ast_variable_browse(cfg, cxt);
				while(v) {
					if (!strcasecmp(v->name, "exten")) {
						char *stringp=NULL;
						int ipri = -2;
						char realext[256]="";
						tc = strdup(v->value);
						if(tc!=NULL){
							stringp=tc;
							ext = strsep(&stringp, ",");
							if (!ext)
								ext="";
							pri = strsep(&stringp, ",");
							if (!pri)
								pri="";
							if (!strcmp(pri,"hint"))
								ipri=PRIORITY_HINT;
							else {
								if (sscanf(pri, "%i", &ipri) != 1) {
									ast_log(LOG_WARNING, "Invalid priority '%s' at line %d\n", pri, v->lineno);
									ipri = 0;
								}
							}
							appl = stringp;
							if (!appl)
								appl="";
							if (!(start = strchr(appl, '('))) {
								if (stringp)
									appl = strsep(&stringp, ",");
								else
									appl = "";
							}
							if (start && (end = strrchr(appl, ')'))) {
								*start = *end = '\0';
								data = start + 1;
								process_quotes_and_slashes(data, ',', '|');
							} else if (stringp!=NULL && *stringp=='"') {
								stringp++;
								data = strsep(&stringp, "\"");
								stringp++;
							} else {
								if (stringp)
									data = strsep(&stringp, ",");
								else
									data = "";
							}
							cidmatch = strchr(ext, '/');
							if (cidmatch) {
								*cidmatch = '\0';
								cidmatch++;
							}
							stringp=ext;
							strsep(&stringp, "/");

							if (!data)
								data="";
							while(*appl && (*appl < 33)) appl++;
							pbx_substitute_variables_helper(NULL, ext, realext, sizeof(realext) - 1);
							if (ipri) {
								if (ast_add_extension2(con, 0, realext, ipri, cidmatch, appl, strdup(data), FREE, registrar)) {
									ast_log(LOG_WARNING, "Unable to register extension at line %d\n", v->lineno);
								}
							}
							free(tc);
						} else fprintf(stderr,"Error strdup returned NULL in %s\n",__PRETTY_FUNCTION__);
					} else if(!strcasecmp(v->name, "include")) {
						memset(realvalue, 0, sizeof(realvalue));
						pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
						if (ast_context_add_include2(con, realvalue, registrar))
							ast_log(LOG_WARNING, "Unable to include context '%s' in context '%s'\n", v->value, cxt);
					} else if(!strcasecmp(v->name, "ignorepat")) {
						memset(realvalue, 0, sizeof(realvalue));
						pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
						if (ast_context_add_ignorepat2(con, realvalue, registrar))
							ast_log(LOG_WARNING, "Unable to include ignorepat '%s' in context '%s'\n", v->value, cxt);
					} else if (!strcasecmp(v->name, "switch")) {
						char *stringp=NULL;
						memset(realvalue, 0, sizeof(realvalue));
						pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
						tc = realvalue;
						stringp=tc;
						appl = strsep(&stringp, "/");
						data = strsep(&stringp, "");
						if (!data)
							data = "";
						if (ast_context_add_switch2(con, appl, data, registrar))
							ast_log(LOG_WARNING, "Unable to include switch '%s' in context '%s'\n", v->value, cxt);
					}
					v = v->next;
				}
			}
			cxt = ast_category_browse(cfg, cxt);
		}
		ast_destroy(cfg);
	}
	ast_merge_contexts_and_delete(&local_contexts,registrar);

	for (con = ast_walk_contexts(NULL); con; con = ast_walk_contexts(con))
		ast_context_verify_includes(con);

	return 0;
}
Esempio n. 13
0
int misdn_cfg_init (int this_max_ports)
{
	char config[] = "misdn.conf";
	char *cat, *p;
	int i;
	struct ast_config *cfg;
	struct ast_variable *v;

	if (!(cfg = AST_LOAD_CFG(config))) {
		ast_log(LOG_WARNING, "missing file: misdn.conf\n");
		return -1;
	}

	ast_mutex_init(&config_mutex);

	misdn_cfg_lock();

	if (this_max_ports) {
		/* this is the first run */
		max_ports = this_max_ports;
		map = (int *)calloc(MISDN_GEN_LAST + 1, sizeof(int));
		if (_enum_array_map())
			return -1;
		p = (char *)calloc(1, (max_ports + 1) * sizeof(union misdn_cfg_pt *)
						   + (max_ports + 1) * NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt));
		port_cfg = (union misdn_cfg_pt **)p;
		p += (max_ports + 1) * sizeof(union misdn_cfg_pt *);
		for (i = 0; i <= max_ports; ++i) {
			port_cfg[i] = (union misdn_cfg_pt *)p;
			p += NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt);
		}
		general_cfg = (union misdn_cfg_pt *)calloc(1, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
		ptp = (int *)calloc(max_ports + 1, sizeof(int));
	}
	else {
		/* misdn reload */
		_free_port_cfg();
		_free_general_cfg();
		memset(port_cfg[0], 0, NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt) * (max_ports + 1));
		memset(general_cfg, 0, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
		memset(ptp, 0, sizeof(int) * (max_ports + 1));
	}

	cat = ast_category_browse(cfg, NULL);

	while(cat) {
		v = ast_variable_browse(cfg, cat);
		if (!strcasecmp(cat, "general")) {
			_build_general_config(v);
		} else {
			_build_port_config(v, cat);
		}
		cat = ast_category_browse(cfg, cat);
	}

	_fill_defaults();

	misdn_cfg_unlock();
	AST_DESTROY_CFG(cfg);

	return 0;
}
Esempio n. 14
0
static int load_config(int reload) {
	char *cat = NULL;
	struct ast_config *cfg;
	struct ast_variable *v;
	struct ast_flags config_flags = {reload ? CONFIG_FLAG_FILEUNCHANGED : 0};
	int newenablecdr = 0;

	cfg = ast_config_load(CONF_FILE, config_flags);
	if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
		return 0;
	}

	if (cfg == CONFIG_STATUS_FILEINVALID) {
		ast_log(LOG_ERROR, "Config file '%s' could not be parsed\n", CONF_FILE);
		return -1;
	}

	if (!cfg) {
		/* Standard configuration */
		ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n");
		if (enablecdr) {
			ast_cdr_backend_suspend(name);
		}
		enablecdr = 0;
		return -1;
	}

	if (reload) {
		ast_rwlock_wrlock(&config_lock);
		ast_free(bs_host);
		ast_free(bs_tube);
	}

	/* Bootstrap the default configuration */
	bs_host = ast_strdup(DEFAULT_BEANSTALK_HOST);
	bs_port = DEFAULT_BEANSTALK_PORT;
	bs_tube = ast_strdup(DEFAULT_BEANSTALK_TUBE);
	priority = BEANSTALK_JOB_PRIORITY;

	while ((cat = ast_category_browse(cfg, cat))) {
		if (!strcasecmp(cat, "general")) {
			v = ast_variable_browse(cfg, cat);
			while (v) {

				if (!strcasecmp(v->name, "enabled")) {
					newenablecdr = ast_true(v->value);
				} else if (!strcasecmp(v->name, "host")) {
					ast_free(bs_host);
					bs_host = ast_strdup(v->value);
				} else if (!strcasecmp(v->name, "port")) {
					bs_port = atoi(v->value);
				} else if (!strcasecmp(v->name, "tube")) {
					ast_free(bs_tube);
					bs_tube = ast_strdup(v->value);
				} else if (!strcasecmp(v->name, "priority")) {
					priority = atoi(v->value);
				}
				v = v->next;

			}
		}
	}

	if (reload) {
		ast_rwlock_unlock(&config_lock);
	}

	ast_config_destroy(cfg);

	if (!newenablecdr) {
		ast_cdr_backend_suspend(name);
	} else if (newenablecdr) {
		ast_cdr_backend_unsuspend(name);
		ast_log(LOG_NOTICE, "Added beanstalkd server %s at port %d with tube %s", bs_host, bs_port, bs_tube);
	}
	enablecdr = newenablecdr;

	return 0;
}
Esempio n. 15
0
int misdn_cfg_init(int this_max_ports, int reload)
{
	char config[] = "misdn.conf";
	char *cat, *p;
	int i;
	struct ast_config *cfg;
	struct ast_variable *v;
	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };

	if (!(cfg = ast_config_load2(config, "chan_misdn", config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) {
		ast_log(LOG_WARNING, "missing or invalid file: misdn.conf\n");
		return -1;
	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
		return 0;

	ast_mutex_init(&config_mutex);

	/* Copy the default jb config over global_jbconf */
	memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));

	misdn_cfg_lock();

	if (this_max_ports) {
		/* this is the first run */
		max_ports = this_max_ports;
		map = ast_calloc(MISDN_GEN_LAST + 1, sizeof(int));
		if (_enum_array_map())
			return -1;
		p = ast_calloc(1, (max_ports + 1) * sizeof(union misdn_cfg_pt *)
						   + (max_ports + 1) * NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt));
		port_cfg = (union misdn_cfg_pt **)p;
		p += (max_ports + 1) * sizeof(union misdn_cfg_pt *);
		for (i = 0; i <= max_ports; ++i) {
			port_cfg[i] = (union misdn_cfg_pt *)p;
			p += NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt);
		}
		general_cfg = ast_calloc(1, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
		ptp = ast_calloc(max_ports + 1, sizeof(int));
	}
	else {
		/* misdn reload */
		_free_port_cfg();
		_free_general_cfg();
		memset(port_cfg[0], 0, NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt) * (max_ports + 1));
		memset(general_cfg, 0, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
		memset(ptp, 0, sizeof(int) * (max_ports + 1));
	}

	cat = ast_category_browse(cfg, NULL);

	while(cat) {
		v = ast_variable_browse(cfg, cat);
		if (!strcasecmp(cat, "general")) {
			_build_general_config(v);
		} else {
			_build_port_config(v, cat);
		}
		cat = ast_category_browse(cfg, cat);
	}

	_fill_defaults();

	misdn_cfg_unlock();
	ast_config_destroy(cfg);

	return 0;
}