Ejemplo n.º 1
0
static struct cw_config *realtime_directory(char *context)
{
	struct cw_config *cfg;
	struct cw_config *rtdata;
	struct cw_category *cat;
	struct cw_variable *var;
	char *mailbox;
	char *fullname;
	char *hidefromdir;
	char tmp[100];

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

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

	/* Get realtime entries, categorized by their mailbox number
	   and present in the requested context */
	rtdata = cw_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 = cw_category_get(cfg, context);
	if (!cat) {
		cat = cw_category_new(context);
		if (!cat) {
			cw_log(LOG_WARNING, "Out of memory\n");
			cw_config_destroy(cfg);
			return NULL;
		}
		cw_category_append(cfg, cat);
	}

	mailbox = cw_category_browse(rtdata, NULL);
	while (mailbox) {
		fullname = cw_variable_retrieve(rtdata, mailbox, "fullname");
		hidefromdir = cw_variable_retrieve(rtdata, mailbox, "hidefromdir");
		snprintf(tmp, sizeof(tmp), "no-password,%s,hidefromdir=%s",
			 fullname ? fullname : "",
			 hidefromdir ? hidefromdir : "no");
		var = cw_variable_new(mailbox, tmp);
		if (var)
			cw_variable_append(cat, var);
		else
			cw_log(LOG_WARNING, "Out of memory adding mailbox '%s'\n", mailbox);
		mailbox = cw_category_browse(rtdata, mailbox);
	}
	cw_config_destroy(rtdata);

	return cfg;
}
Ejemplo n.º 2
0
static int apply_outgoing(struct outgoing *o, char *fn, FILE *f)
{
	char buf[256];
	char *c, *c2;
	int lineno = 0;
	struct cw_variable *var;

	while(fgets(buf, sizeof(buf), f)) {
		lineno++;
		/* Trim comments */
		c = buf;
		while ((c = strchr(c, '#'))) {
			if ((c == buf) || (*(c-1) == ' ') || (*(c-1) == '\t'))
				*c = '\0';
			else
				c++;
		}

		c = buf;
		while ((c = strchr(c, ';'))) {
			if ((c > buf) && (c[-1] == '\\')) {
				memmove(c - 1, c, strlen(c) + 1);
				c++;
			} else {
				*c = '\0';
				break;
			}
		}

		cw_trim_blanks(buf);
		if (!cw_strlen_zero(buf)) {
			c = strchr(buf, ':');
			if (c) {
				*c = '\0';
				c = cw_skip_blanks(c + 1);
#if 0
				printf("'%s' is '%s' at line %d\n", buf, c, lineno);
#endif
				if (!strcasecmp(buf, "channel")) {
					strncpy(o->tech, c, sizeof(o->tech) - 1);
					if ((c2 = strchr(o->tech, '/'))) {
						*c2 = '\0';
						c2++;
						strncpy(o->dest, c2, sizeof(o->dest) - 1);
					} else {
						cw_log(LOG_NOTICE, "Channel should be in form Tech/Dest at line %d of %s\n", lineno, fn);
						o->tech[0] = '\0';
					}
				} else if (!strcasecmp(buf, "callerid")) {
					cw_callerid_split(c, o->cid_name, sizeof(o->cid_name), o->cid_num, sizeof(o->cid_num));
				} else if (!strcasecmp(buf, "application")) {
					strncpy(o->app, c, sizeof(o->app) - 1);
				} else if (!strcasecmp(buf, "data")) {
					strncpy(o->data, c, sizeof(o->data) - 1);
				} else if (!strcasecmp(buf, "maxretries")) {
					if (sscanf(c, "%d", &o->maxretries) != 1) {
						cw_log(LOG_WARNING, "Invalid max retries at line %d of %s\n", lineno, fn);
						o->maxretries = 0;
					}
				} else if (!strcasecmp(buf, "context")) {
					strncpy(o->context, c, sizeof(o->context) - 1);
				} else if (!strcasecmp(buf, "extension")) {
					strncpy(o->exten, c, sizeof(o->exten) - 1);
				} else if (!strcasecmp(buf, "priority")) {
					if ((sscanf(c, "%d", &o->priority) != 1) || (o->priority < 1)) {
						cw_log(LOG_WARNING, "Invalid priority at line %d of %s\n", lineno, fn);
						o->priority = 1;
					}
				} else if (!strcasecmp(buf, "retrytime")) {
					if ((sscanf(c, "%d", &o->retrytime) != 1) || (o->retrytime < 1)) {
						cw_log(LOG_WARNING, "Invalid retrytime at line %d of %s\n", lineno, fn);
						o->retrytime = 300;
					}
				} else if (!strcasecmp(buf, "waittime")) {
					if ((sscanf(c, "%d", &o->waittime) != 1) || (o->waittime < 1)) {
						cw_log(LOG_WARNING, "Invalid retrytime at line %d of %s\n", lineno, fn);
						o->waittime = 45;
					}
				} else if (!strcasecmp(buf, "retry")) {
					o->retries++;
				} else if (!strcasecmp(buf, "startretry")) {
					if (sscanf(c, "%d", &o->callingpid) != 1) {
						cw_log(LOG_WARNING, "Unable to retrieve calling PID!\n");
						o->callingpid = 0;
					}
				} else if (!strcasecmp(buf, "endretry") || !strcasecmp(buf, "abortretry")) {
					o->callingpid = 0;
					o->retries++;
				} else if (!strcasecmp(buf, "delayedretry")) {
				} else if (!strcasecmp(buf, "setvar") || !strcasecmp(buf, "set")) {
					c2 = c;
					strsep(&c2, "=");
					/* This is naughty. We silently ignore bad lines */
					if (c2) {
						var = cw_variable_new(c, c2);
						if (var) {
							var->next = o->vars;
							o->vars = var;
						}
					}
				} else if (!strcasecmp(buf, "account")) {
					var = cw_variable_new("CDR(accountcode|r)", c);
					if (var) {	
						var->next = o->vars;
						o->vars = var;
					}
				} else {
					cw_log(LOG_WARNING, "Unknown keyword '%s' at line %d of %s\n", buf, lineno, fn);
				}
			} else
				cw_log(LOG_NOTICE, "Syntax error at line %d of %s\n", lineno, fn);
		}
	}
	strncpy(o->fn, fn, sizeof(o->fn) - 1);
	if (cw_strlen_zero(o->tech) || cw_strlen_zero(o->dest) || (cw_strlen_zero(o->app) && cw_strlen_zero(o->exten))) {
		cw_log(LOG_WARNING, "At least one of app or extension must be specified, along with tech and dest in file %s\n", fn);
		return -1;
	}
	return 0;
}