/*
* Write the metadata to the log file
*/
static int write_metadata( FILE *logfile, char *signalling_type, struct ast_channel *chan)
{
	int res = 0;
	struct timeval t;
	struct ast_tm now;
	char *cl;
	char *cn;
	char workstring[80];
	char timestamp[80];
	
	/* Extract the caller ID location */
	ast_copy_string(workstring,
		S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, ""),
		sizeof(workstring));
	ast_shrink_phone_number(workstring);
	if (ast_strlen_zero(workstring)) {
		cl = "<unknown>";
	} else {
		cl = workstring;
	}
	cn = S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, "<unknown>");

	/* Get the current time */
	t = ast_tvnow();
	ast_localtime(&t, &now, NULL);

	/* Format the time */
	ast_strftime(timestamp, sizeof(timestamp), time_stamp_format, &now);

	res = fprintf(logfile, "\n\n[metadata]\n\n");
	if (res >= 0) {
		res = fprintf(logfile, "PROTOCOL=%s\n", signalling_type);
	}
	if (res >= 0) {
		res = fprintf(logfile, "CALLINGFROM=%s\n", cl);
	}
	if (res >= 0) {
		res = fprintf(logfile, "CALLERNAME=%s\n", cn);
	}
	if (res >= 0) {
		res = fprintf(logfile, "TIMESTAMP=%s\n\n", timestamp);
	}
	if (res >= 0) {
		res = fprintf(logfile, "[events]\n\n");
	}
	if (res < 0) {
		ast_verb(3, "AlarmReceiver: can't write metadata\n");
		ast_debug(1,"AlarmReceiver: can't write metadata\n");
	} else {
		res = 0;
	}

	return res;
}
Example #2
0
static int global_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
{
	const char *var = pbx_builtin_getvar_helper(NULL, data);

	*buf = '\0';

	if (var)
		ast_copy_string(buf, var, len);

	return 0;
}
static int callerid_read(struct ast_channel *chan, char *cmd, char *data,
			 char *buf, size_t len)
{
	char *opt = data;

	/* XXX we are not always clearing the buffer. Is this correct ? */
	if (strchr(opt, '|')) {
		char name[80], num[80];

		data = strsep(&opt, "|");
		ast_callerid_split(opt, name, sizeof(name), num, sizeof(num));

		if (!strncasecmp("all", data, 3)) {
			snprintf(buf, len, "\"%s\" <%s>", name, num);
		} else if (!strncasecmp("name", data, 4)) {
			ast_copy_string(buf, name, len);
		} else if (!strncasecmp("num", data, 3) ||
			   !strncasecmp("number", data, 6)) {

			ast_copy_string(buf, num, len);
		} else {
			ast_log(LOG_ERROR, "Unknown callerid data type.\n");
		}
	} else {
		if (!strncasecmp("all", data, 3)) {
			snprintf(buf, len, "\"%s\" <%s>",
				 S_OR(chan->cid.cid_name, ""),
				 S_OR(chan->cid.cid_num, ""));
		} else if (!strncasecmp("name", data, 4)) {
			if (chan->cid.cid_name) {
				ast_copy_string(buf, chan->cid.cid_name, len);
			}
		} else if (!strncasecmp("num", data, 3)
				   || !strncasecmp("number", data, 6)) {
			if (chan->cid.cid_num) {
				ast_copy_string(buf, chan->cid.cid_num, len);
			}
		} else if (!strncasecmp("ani", data, 3)) {
			if (chan->cid.cid_ani) {
				ast_copy_string(buf, chan->cid.cid_ani, len);
			}
		} else if (!strncasecmp("dnid", data, 4)) {
			if (chan->cid.cid_dnid) {
				ast_copy_string(buf, chan->cid.cid_dnid, len);
			}
		} else if (!strncasecmp("rdnis", data, 5)) {
			if (chan->cid.cid_rdnis) {
				ast_copy_string(buf, chan->cid.cid_rdnis, len);
			}
		} else {
			ast_log(LOG_ERROR, "Unknown callerid data type.\n");
		}
	}

	return 0;
}
static int moh_read(struct ast_channel *chan, char *cmd, char *data,
		    char *buf, size_t len)
{
	if (!depwarning) {
		depwarning = 1;
		ast_log(LOG_WARNING, "MUSICCLASS() is deprecated; use CHANNEL(musicclass) instead.\n");
	}

	ast_copy_string(buf, chan->musicclass, len);

	return 0;
}
Example #5
0
int ast_aoc_set_association_number(struct ast_aoc_decoded *decoded, const char *num, uint8_t plan)
{
	if ((decoded->msg_type != AST_AOC_E) || ast_strlen_zero(num)) {
		return -1;
	}
	memset(&decoded->charging_association, 0, sizeof(decoded->charging_association));
	decoded->charging_association.charging_type = AST_AOC_CHARGING_ASSOCIATION_NUMBER;
	decoded->charging_association.charge.number.plan = plan;
	ast_copy_string(decoded->charging_association.charge.number.number, num, sizeof(decoded->charging_association.charge.number.number));

	return 0;
}
Example #6
0
static int func_channel_read(struct ast_channel *chan, char *function,
			     char *data, char *buf, size_t len)
{
	int ret = 0;

	if (!strcasecmp(data, "audionativeformat"))
		/* use the _multiple version when chan->nativeformats holds multiple formats */
		/* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_AUDIO_MASK); */
		ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_AUDIO_MASK), len);
	else if (!strcasecmp(data, "videonativeformat"))
		/* use the _multiple version when chan->nativeformats holds multiple formats */
		/* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_VIDEO_MASK); */
		ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_VIDEO_MASK), len);
	else if (!strcasecmp(data, "audioreadformat"))
		ast_copy_string(buf, ast_getformatname(chan->readformat), len);
	else if (!strcasecmp(data, "audiowriteformat"))
		ast_copy_string(buf, ast_getformatname(chan->writeformat), len);
	else if (!strcasecmp(data, "tonezone") && chan->zone)
		locked_copy_string(chan, buf, chan->zone->country, len);
	else if (!strcasecmp(data, "language"))
		locked_copy_string(chan, buf, chan->language, len);
	else if (!strcasecmp(data, "musicclass"))
		locked_copy_string(chan, buf, chan->musicclass, len);
	else if (!strcasecmp(data, "state"))
		locked_copy_string(chan, buf, ast_state2str(chan->_state), len);
	else if (!strcasecmp(data, "channeltype"))
		locked_copy_string(chan, buf, chan->tech->type, len);
	else if (!strcasecmp(data, "transfercapability"))
		locked_copy_string(chan, buf, transfercapability_table[chan->transfercapability & 0x1f], len);
	else if (!strcasecmp(data, "callgroup")) {
		char groupbuf[256];
		locked_copy_string(chan, buf,  ast_print_group(groupbuf, sizeof(groupbuf), chan->callgroup), len);
	} else if (!chan->tech->func_channel_read
		 || chan->tech->func_channel_read(chan, function, data, buf, len)) {
		ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data);
		ret = -1;
	}

	return ret;
}
Example #7
0
/*! \brief SPEECH() Dialplan Function */
static int speech_read(struct ast_channel *chan, const char *cmd, char *data,
			char *buf, size_t len)
{
	int results = 0;
	struct ast_speech_result *result = NULL;
	struct ast_speech *speech = find_speech(chan);
	char tmp[128] = "";

	/* Now go for the various options */
	if (!strcasecmp(data, "status")) {
		if (speech != NULL)
			ast_copy_string(buf, "1", len);
		else
			ast_copy_string(buf, "0", len);
		return 0;
	}

	/* Make sure we have a speech structure for everything else */
	if (speech == NULL) {
		return -1;
	}

	/* Check to see if they are checking for silence */
	if (!strcasecmp(data, "spoke")) {
		if (ast_test_flag(speech, AST_SPEECH_SPOKE))
			ast_copy_string(buf, "1", len);
		else
			ast_copy_string(buf, "0", len);
	} else if (!strcasecmp(data, "results")) {
		/* Count number of results */
		for (result = speech->results; result; result = AST_LIST_NEXT(result, list))
			results++;
		snprintf(tmp, sizeof(tmp), "%d", results);
		ast_copy_string(buf, tmp, len);
	} else {
		buf[0] = '\0';
	}

	return 0;
}
static int log_events(struct ast_channel *chan,  char *signalling_type, event_node_t *event)
{

	int res = 0;
	char workstring[sizeof(event_spool_dir)+sizeof(event_file)] = "";
	int fd;
	FILE *logfile;
	event_node_t *elp = event;
	
	if (!ast_strlen_zero(event_spool_dir)) {
		
		/* Make a template */
		
		ast_copy_string(workstring, event_spool_dir, sizeof(workstring));
		strncat(workstring, event_file, sizeof(workstring) - strlen(workstring) - 1);
		
		/* Make the temporary file */
		
		fd = mkstemp(workstring);
		
		if(fd == -1){
			ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: can't make temporary file\n");	
			ast_log(LOG_DEBUG,"AlarmReceiver: can't make temporary file\n");
			res = -1;
		}
		
		if(!res){
			logfile = fdopen(fd, "w");
			if(logfile){
				/* Write the file */
				res = write_metadata(logfile, signalling_type, chan);
				if(!res)
					while((!res) && (elp != NULL)){
						res = write_event(logfile, elp);
						elp = elp->next;
					}
				if(!res){
					if(fflush(logfile) == EOF)
						res = -1;
					if(!res){
						if(fclose(logfile) == EOF)
							res = -1;
					}				
				}
			}
			else
				res = -1;
		}
	}

	return res;	
}
Example #9
0
/*!\brief uridecode: Decode URI according to RFC 2396 */
static int uridecode(struct ast_channel *chan, const char *cmd, char *data,
		     char *buf, size_t len)
{
	if (ast_strlen_zero(data)) {
		buf[0] = '\0';
		return 0;
	}

	ast_copy_string(buf, data, len);
	ast_uri_decode(buf, ast_uri_http);

	return 0;
}
Example #10
0
/*!\brief uridecode: Decode URI according to RFC 2396 */
static int uridecode(struct ast_channel *chan, char *cmd, char *data,
		     char *buf, size_t len)
{
	if (ast_strlen_zero(data)) {
		ast_log(LOG_WARNING, "Syntax: URIDECODE(<data>) - missing argument!\n");
		return -1;
	}

	ast_copy_string(buf, data, len);
	ast_uri_decode(buf);

	return 0;
}
Example #11
0
int ast_get_txt(struct ast_channel *chan, const char *number, char *txt, int txtlen, char *suffix)
{
	struct txt_context context;
	char tmp[259 + 512];
	int pos = strlen(number) - 1;
	int newpos = 0;
	int ret = -1;

	ast_debug(4, "ast_get_txt: Number = '%s', suffix = '%s'\n", number, suffix);

	if (chan && ast_autoservice_start(chan) < 0) {
		return -1;
	}

	if (pos > 128) {
		pos = 128;
	}

	while (pos >= 0) {
		if (isdigit(number[pos])) {
			tmp[newpos++] = number[pos];
			tmp[newpos++] = '.';
		}
		pos--;
	}

	ast_copy_string(&tmp[newpos], suffix, sizeof(tmp) - newpos);

	if (ret < 0) {
		ast_debug(2, "No such number found in ENUM: %s (%s)\n", tmp, strerror(errno));
		ret = 0;
	} else {
		ast_copy_string(txt, context.txt, txtlen);
	}
	if (chan) {
		ret |= ast_autoservice_stop(chan);
	}
	return ret;
}
Example #12
0
char *term_prompt(char *outbuf, const char *inbuf, int maxout)
{
	if (!vt100compat) {
		ast_copy_string(outbuf, inbuf, maxout);
		return outbuf;
	}
	snprintf(outbuf, maxout, "%c[%d;%d;%dm%c%c[%d;%d;%dm%s",
		ESC, ATTR_BRIGHT, COLOR_BLUE, COLOR_BLACK + 10,
		inbuf[0],
		ESC, 0, COLOR_WHITE, COLOR_BLACK + 10,
		inbuf + 1);
	return outbuf;
}
Example #13
0
static int load_module(void)
{
	struct ast_config *cfg;
	struct ast_flags config_flags = { 0 };
	const char *tmp;

	if ((cfg = ast_config_load(cel_config, config_flags))) {
		ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME);
		if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) {
			ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg));
		}
		ast_config_destroy(cfg);
	} else {
		return AST_MODULE_LOAD_DECLINE;
	}

	/*
	 * start logging
	 *
	 * NOTE: Yes this causes a slight memory leak if the module is
	 * unloaded.  However, it is better than a crash if cdr_radius
	 * and cel_radius are both loaded.
	 */
	tmp = ast_strdup("asterisk");
	if (tmp) {
		rc_openlog((char *) tmp);
	}

	/* read radiusclient-ng config file */
	if (!(rh = rc_read_config(radiuscfg))) {
		ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg);
		return AST_MODULE_LOAD_DECLINE;
	}

	/* read radiusclient-ng dictionaries */
	if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) {
		ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n");
		rc_destroy(rh);
		rh = NULL;
		return AST_MODULE_LOAD_DECLINE;
	}

	event_sub = ast_event_subscribe(AST_EVENT_CEL, radius_log, "CEL Radius Logging", NULL, AST_EVENT_IE_END);
	if (!event_sub) {
		rc_destroy(rh);
		rh = NULL;
		return AST_MODULE_LOAD_DECLINE;
	} else {
		return AST_MODULE_LOAD_SUCCESS;
	}
}
Example #14
0
/*!
 * \brief Write metadata to log file
 *
 * \param logfile Log File Pointer
 * \param signalling_type Signaling Type
 * \param chan Asterisk Channel
 * \param no_checksum Expecting messages without checksum
 *
 * \retval 0 success
 * \retval -1 failure
 */
static int write_metadata(FILE *logfile, char *signalling_type, struct ast_channel *chan, int no_checksum)
{
	struct timeval t;
	struct ast_tm now;
	char *cl;
	char *cn;
	char workstring[80];
	char timestamp[80];

	/* Extract the caller ID location */
	ast_copy_string(workstring,
		S_COR(ast_channel_caller(chan)->id.number.valid,
		ast_channel_caller(chan)->id.number.str, ""), sizeof(workstring));
	ast_shrink_phone_number(workstring);
	if (ast_strlen_zero(workstring)) {
		cl = "<unknown>";
	} else {
		cl = workstring;
	}
	cn = S_COR(ast_channel_caller(chan)->id.name.valid,
		ast_channel_caller(chan)->id.name.str, "<unknown>");

	/* Get the current time */
	t = ast_tvnow();
	ast_localtime(&t, &now, NULL);

	/* Format the time */
	ast_strftime(timestamp, sizeof(timestamp), time_stamp_format, &now);

	if (no_group_meta && fprintf(logfile, "PROTOCOL=%s\n"
			"CHECKSUM=%s\n"
			"CALLINGFROM=%s\n"
			"CALLERNAME=%s\n"
			"TIMESTAMP=%s\n\n",
			signalling_type, (!no_checksum) ? "yes" : "no", cl, cn, timestamp) > -1) {
		return 0;
	} else if (fprintf(logfile, "\n\n[metadata]\n\n"
			"PROTOCOL=%s\n"
			"CHECKSUM=%s\n"
			"CALLINGFROM=%s\n"
			"CALLERNAME=%s\n"
			"TIMESTAMP=%s\n\n"
			"[events]\n\n",
			signalling_type, (!no_checksum) ? "yes" : "no", cl, cn, timestamp) > -1) {
		return 0;
	}

	ast_verb(3, "AlarmReceiver: can't write metadata\n");
	ast_debug(1, "AlarmReceiver: can't write metadata\n");
	return -1;
}
Example #15
0
static int group_count_function_read(struct ast_channel *chan, const char *cmd,
                                     char *data, char *buf, size_t len)
{
    int ret = -1;
    int count = -1;
    char group[80] = "", category[80] = "";

    ast_app_group_split_group(data, group, sizeof(group), category,
                              sizeof(category));

    /* If no group has been provided let's find one */
    if (ast_strlen_zero(group)) {
        struct ast_group_info *gi = NULL;

        ast_app_group_list_rdlock();
        for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
            if (gi->chan != chan)
                continue;
            if (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))
                break;
        }
        if (gi) {
            ast_copy_string(group, gi->group, sizeof(group));
            if (!ast_strlen_zero(gi->category))
                ast_copy_string(category, gi->category, sizeof(category));
        }
        ast_app_group_list_unlock();
    }

    if ((count = ast_app_group_get_count(group, category)) == -1) {
        ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", ast_channel_name(chan));
    } else {
        snprintf(buf, len, "%d", count);
        ret = 0;
    }

    return ret;
}
int load_module(void)
{
#ifdef USE_ODBC_STORAGE
	struct ast_config *cfg = ast_config_load(VOICEMAIL_CONFIG);
	char *tmp;

	if (cfg) {
		if ((tmp = ast_variable_retrieve(cfg, "general", "odbcstorage"))) {
			ast_copy_string(odbc_database, tmp, sizeof(odbc_database));
		}
		if ((tmp = ast_variable_retrieve(cfg, "general", "odbctable"))) {
			ast_copy_string(odbc_table, tmp, sizeof(odbc_table));
		}
		if ((tmp = ast_variable_retrieve(cfg, "general", "format"))) {
			ast_copy_string(vmfmts, tmp, sizeof(vmfmts));
		}
		ast_config_destroy(cfg);
	} else
		ast_log(LOG_WARNING, "Unable to load " VOICEMAIL_CONFIG " - ODBC defaults will be used\n");
#endif

	return ast_register_application(app, directory_exec, synopsis, descrip);
}
Example #17
0
/*!
 * \internal
 * \brief Implements PJSIP_HEADER 'read' by searching the for the requested header.
 *
 * Retrieve the header_datastore.
 * Search for the nth matching header.
 * Validate the pjsip_hdr found.
 * Parse pjsip_hdr into a name and value.
 * Return the value.
 */
static int read_header(void *obj)
{
	struct header_data *data = obj;
	pjsip_hdr *hdr = NULL;
	char *pj_hdr_string;
	size_t pj_hdr_string_len;
	char *p;
	size_t plen;
	RAII_VAR(struct ast_datastore *, datastore,
			 ast_sip_session_get_datastore(data->channel->session, header_datastore.type),
			 ao2_cleanup);

	if (!datastore || !datastore->data) {
		ast_debug(1, "There was no datastore from which to read headers.\n");
		return -1;
	}

	hdr = find_header((struct hdr_list *) datastore->data, data->header_name,
					  data->header_number);

	if (!hdr) {
		ast_debug(1, "There was no header named %s.\n", data->header_name);
		return -1;
	}

	pj_hdr_string = ast_alloca(data->len);
	pj_hdr_string_len = pjsip_hdr_print_on(hdr, pj_hdr_string, data->len);
	pj_hdr_string[pj_hdr_string_len] = '\0';

	p = strchr(pj_hdr_string, ':');
	if (!p) {
		ast_log(AST_LOG_ERROR,
				"A malformed header was returned from pjsip_hdr_print_on.\n");
		return -1;
	}

	++p;
	p = ast_strip(p);
	plen = strlen(p);
	if (plen + 1 > data->len) {
		ast_log(AST_LOG_ERROR,
				"Buffer isn't big enough to hold header value.  %zu > %zu\n", plen + 1,
				data->len);
		return -1;
	}

	ast_copy_string(data->buf, p, data->len);

	return 0;
}
Example #18
0
static int load_module(void)
{
	struct ast_config *cfg;
	struct ast_flags config_flags = { 0 };
	const char *tmp;

	if ((cfg = ast_config_load(cdr_config, config_flags)) && cfg != CONFIG_STATUS_FILEINVALID) {
		ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME);
		ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguniqueid")), RADIUS_FLAG_LOGUNIQUEID);
		ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguserfield")), RADIUS_FLAG_LOGUSERFIELD);
		if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg")))
			ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg));
		ast_config_destroy(cfg);
	} else
		return AST_MODULE_LOAD_DECLINE;

	/*
	 * start logging
	 *
	 * NOTE: Yes this causes a slight memory leak if the module is
	 * unloaded.  However, it is better than a crash if cdr_radius
	 * and cel_radius are both loaded.
	 */
	tmp = ast_strdup("asterisk");
	if (tmp) {
		rc_openlog((char *) tmp);
	}

	/* read radiusclient-ng config file */
	if (!(rh = rc_read_config(radiuscfg))) {
		ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg);
		return AST_MODULE_LOAD_DECLINE;
	}

	/* read radiusclient-ng dictionaries */
	if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) {
		ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n");
		rc_destroy(rh);
		rh = NULL;
		return AST_MODULE_LOAD_DECLINE;
	}

	if (ast_cdr_register(name, desc, radius_log)) {
		rc_destroy(rh);
		rh = NULL;
		return AST_MODULE_LOAD_DECLINE;
	} else {
		return AST_MODULE_LOAD_SUCCESS;
	}
}
/*
 * SHOW INDICATIONS command stuff
 */
static int handle_show_indications(int fd, int argc, char *argv[])
{
	struct tone_zone *tz;
	char buf[256];
	int found_country = 0;

	if (ast_mutex_lock(&tzlock)) {
		ast_log(LOG_WARNING, "Unable to lock tone_zones list\n");
		return 0;
	}
	if (argc == 2) {
		/* no arguments, show a list of countries */
		ast_cli(fd,"Country Alias   Description\n"
			   "===========================\n");
		for (tz=tone_zones; tz; tz=tz->next) {
			ast_cli(fd,"%-7.7s %-7.7s %s\n", tz->country, tz->alias, tz->description);
		}
		ast_mutex_unlock(&tzlock);
		return 0;
	}
	/* there was a request for specific country(ies), lets humor them */
	for (tz=tone_zones; tz; tz=tz->next) {
		int i,j;
		for (i=2; i<argc; i++) {
			if (strcasecmp(tz->country,argv[i])==0 &&
			    !tz->alias[0]) {
				struct tone_zone_sound* ts;
				if (!found_country) {
					found_country = 1;
					ast_cli(fd,"Country Indication      PlayList\n"
						   "=====================================\n");
				}
				j = snprintf(buf,sizeof(buf),"%-7.7s %-15.15s ",tz->country,"<ringcadence>");
				for (i=0; i<tz->nrringcadence; i++) {
					j += snprintf(buf+j,sizeof(buf)-j,"%d,",tz->ringcadence[i]);
				}
				if (tz->nrringcadence) j--;
				ast_copy_string(buf+j,"\n",sizeof(buf)-j);
				ast_cli(fd,buf);
				for (ts=tz->tones; ts; ts=ts->next)
					ast_cli(fd,"%-7.7s %-15.15s %s\n",tz->country,ts->name,ts->data);
				break;
			}
		}
	}
	if (!found_country)
		ast_cli(fd,"No countries matched your criteria.\n");
	ast_mutex_unlock(&tzlock);
	return -1;
}
Example #20
0
static char *builtin_function_md5(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) 
{
	char md5[33];

	if (ast_strlen_zero(data)) {
		ast_log(LOG_WARNING, "Syntax: MD5(<data>) - missing argument!\n");
		return NULL;
	}

	ast_md5_hash(md5, data);
	ast_copy_string(buf, md5, len);
	
	return buf;
}
Example #21
0
static VALUE_PAIR *get_avp(const char *file)
{
	FILE *in;
	char tmp[256];
	VALUE_PAIR *avp = NULL;
	VALUE_PAIR *avp_head = NULL;
	VALUE_PAIR *avp_tmp = NULL;
	int len = 0;

	if((in=fopen(file,"r")) != NULL) {
		while(!feof(in)){
			memset(tmp,0,sizeof(tmp));
			if(!fgets(tmp,sizeof(tmp),in))
				break;
			avp = (VALUE_PAIR *)ast_malloc(sizeof(VALUE_PAIR));
			if(avp == NULL){
				return NULL;
			}
			if(avp_head == NULL){
				avp_head = avp;
			}
			ast_copy_string(avp->name,tmp,strlen(tmp));
			memset(tmp,0,sizeof(tmp));
			fgets(tmp,sizeof(tmp),in);
			avp->attribute = atoi(tmp);
			memset(tmp,0,sizeof(tmp));
			fgets(tmp,sizeof(tmp),in);
			avp->type = atoi(tmp);
			memset(tmp,0,sizeof(tmp));
			fgets(tmp,sizeof(tmp),in);
			if(avp->type == 0) {
				len = strlen(tmp)-1;
				tmp[len] = '\0';
				memcpy(avp->strvalue,tmp,strlen(tmp));
				avp->lvalue = strlen(tmp);
			}else{
				avp->lvalue = atoi(tmp);
			}
			avp->next = NULL;
			if(avp_tmp != NULL){
				avp_tmp->next = avp;
			}
			avp_tmp = avp;
		}
		fclose(in);
	}

	return avp_head;
}
static int start_monitor_action(struct mansession *s, struct message *m)
{
	struct ast_channel *c = NULL;
	char *name = astman_get_header(m, "Channel");
	char *fname = astman_get_header(m, "File");
	char *format = astman_get_header(m, "Format");
	char *mix = astman_get_header(m, "Mix");
	char *d;
	
	if (ast_strlen_zero(name)) {
		astman_send_error(s, m, "No channel specified");
		return 0;
	}
	c = ast_get_channel_by_name_locked(name);
	if (!c) {
		astman_send_error(s, m, "No such channel");
		return 0;
	}

	if (ast_strlen_zero(fname)) {
		/* No filename base specified, default to channel name as per CLI */
		fname = malloc (FILENAME_MAX);
		if (!fname) {
			astman_send_error(s, m, "Could not start monitoring channel");
			ast_mutex_unlock(&c->lock);
			return 0;
		}
		memset(fname, 0, FILENAME_MAX);
		ast_copy_string(fname, c->name, FILENAME_MAX);
		/* Channels have the format technology/channel_name - have to replace that /  */
		if ((d=strchr(fname, '/'))) *d='-';
	}
	
	if (ast_monitor_start(c, format, fname, 1)) {
		if (ast_monitor_change_fname(c, fname, 1)) {
			astman_send_error(s, m, "Could not start monitoring channel");
			ast_mutex_unlock(&c->lock);
			return 0;
		}
	}

	if (ast_true(mix)) {
		ast_monitor_setjoinfiles(c, 1);
	}

	ast_mutex_unlock(&c->lock);
	astman_send_ack(s, m, "Started monitoring channel");
	return 0;
}
Example #23
0
static int env_read(struct ast_channel *chan, const char *cmd, char *data,
			char *buf, size_t len)
{
	char *ret = NULL;

	*buf = '\0';

	if (data)
		ret = getenv(data);

	if (ret)
		ast_copy_string(buf, ret, len);

	return 0;
}
Example #24
0
static int parse_config_general(struct ast_config *cfg, struct conf_infos *conf_info)
{
    struct ast_variable *var = NULL;

    for (var = ast_variable_browse(cfg, "general"); var != NULL; var = var->next) {

        if (!strcasecmp(var->name, "hlr_db")) {
            ast_copy_string(conf_info->hlr_db_path, var->value, sizeof(conf_info->hlr_db_path));
            continue;

        } else if (!strcasecmp(var->name, "openbsc_cfg")) {
            ast_copy_string(conf_info->openbsc_cfg_path, var->value, sizeof(conf_info->openbsc_cfg_path));
            continue;

        } else if (!strcasecmp(var->name, "log")) {
            ast_copy_string(conf_info->log_path, var->value, sizeof(conf_info->log_path));

        } else if (!strcasecmp(var->name, "context")) {
            ast_copy_string(conf_info->context, var->value, sizeof(conf_info->context));
        }
    }

    return 0;
}
Example #25
0
static int ifmodule_read(struct ast_channel *chan, const char *cmd, char *data,
		    char *buf, size_t len)
{
	char *ret = "0";

	*buf = '\0';

	if (data)
		if (ast_module_check(data))
			ret = "1";

	ast_copy_string(buf, ret, len);

	return 0;
}
Example #26
0
static int notify_option_handler(const struct aco_option *opt,
				 struct ast_variable *var, void *obj)
{
	struct notify_option *option = obj;

	int name_size = strlen(var->name) + 1;
	int value_size = strlen(var->value) + 1;

	RAII_VAR(struct notify_option_item *, item,
		 ao2_alloc(sizeof(*item) + name_size + value_size,
			   NULL), ao2_cleanup);

	item->name = item->buf;
	item->value = item->buf + name_size;

	ast_copy_string(item->buf, var->name, name_size);
	ast_copy_string(item->buf + name_size, var->value, value_size);

	if (!ao2_link(option->items, item)) {
		return -1;
	}

	return 0;
}
Example #27
0
static int pgsql_reconnect(const char *database)
{
	char my_database[50];

	ast_copy_string(my_database, S_OR(database, dbname), sizeof(my_database));

	/* mutex lock should have been locked before calling this function. */

	if (pgsqlConn && PQstatus(pgsqlConn) != CONNECTION_OK) {
		PQfinish(pgsqlConn);
		pgsqlConn = NULL;
	}

	if ((!pgsqlConn) && (dbhost || dbsock) && dbuser && dbpass && my_database) {
		char *connInfo = NULL;
		unsigned int size = 100 + strlen(dbhost)
			+ strlen(dbuser)
			+ strlen(dbpass)
			+ strlen(my_database);
		
		if (!(connInfo = ast_malloc(size)))
			return 0;
		
		sprintf(connInfo, "host=%s port=%d dbname=%s user=%s password=%s",
					dbhost, dbport, my_database, dbuser, dbpass);
		ast_log(LOG_DEBUG, "%u connInfo=%s\n", size, connInfo);
		pgsqlConn = PQconnectdb(connInfo);
		ast_log(LOG_DEBUG, "%u connInfo=%s\n", size, connInfo);
		free(connInfo);
		connInfo = NULL;
		ast_log(LOG_DEBUG, "pgsqlConn=%p\n", pgsqlConn);
		if (pgsqlConn && PQstatus(pgsqlConn) == CONNECTION_OK) {
			ast_log(LOG_DEBUG, "Postgresql RealTime: Successfully connected to database.\n");
			connect_time = time(NULL);
			return 1;
		} else {
			ast_log(LOG_ERROR,
					"Postgresql RealTime: Failed to connect database server %s on %s. Check debug for more info.\n",
					dbname, dbhost);
			ast_log(LOG_DEBUG, "Postgresql RealTime: Cannot Connect: %s\n",
					PQresultErrorMessage(NULL));
			return 0;
		}
	} else {
		ast_log(LOG_DEBUG, "Postgresql RealTime: Everything is fine.\n");
		return 1;
	}
}
Example #28
0
int ast_callerid_parse(char *instr, char **name, char **location)
{
	char *ns, *ne, *ls, *le;

	/* Try "name" <location> format or name <location> format */
	if ((ls = strrchr(instr, '<')) && (le = strrchr(ls, '>'))) {
		*ls = *le = '\0';	/* location found, trim off the brackets */
		*location = ls + 1;	/* and this is the result */
		if ((ns = strchr(instr, '"')) && (ne = strchr(ns + 1, '"'))) {
			*ns = *ne = '\0';	/* trim off the quotes */
			*name = ns + 1;		/* and this is the name */
		} else if (ns) {
			/* An opening quote was found but no closing quote was. The closing
			 * quote may actually be after the end of the bracketed number
			 */
			if (strchr(le + 1, '\"')) {
				*ns = '\0';
				*name = ns + 1;
				ast_trim_blanks(*name);
			} else {
				*name = NULL;
			}
		} else { /* no quotes, trim off leading and trailing spaces */
			*name = ast_skip_blanks(instr);
			ast_trim_blanks(*name);
		}
	} else {	/* no valid brackets */
		char tmp[256];

		ast_copy_string(tmp, instr, sizeof(tmp));
		ast_shrink_phone_number(tmp);
		if (ast_isphonenumber(tmp)) {	/* Assume it's just a location */
			*name = NULL;
			strcpy(instr, tmp); /* safe, because tmp will always be the same size or smaller than instr */
			*location = instr;
		} else { /* Assume it's just a name. */
			*location = NULL;
			if ((ns = strchr(instr, '"')) && (ne = strchr(ns + 1, '"'))) {
				*ns = *ne = '\0';	/* trim off the quotes */
				*name = ns + 1;		/* and this is the name */
			} else { /* no quotes, trim off leading and trailing spaces */
				*name = ast_skip_blanks(instr);
				ast_trim_blanks(*name);
			}
		}
	}
	return 0;
}
Example #29
0
int ast_sip_sched_task_get_name(struct ast_sip_sched_task *schtd, char *name, size_t maxlen)
{
	if (maxlen <= 0) {
		return -1;
	}

	if (!ao2_ref_and_lock(schtd)) {
		return -1;
	}

	ast_copy_string(name, schtd->name, maxlen);

	ao2_unlock_and_unref(schtd);

	return 0;
}
Example #30
0
/*! \brief SPEECH_SCORE() Dialplan Function */
static int speech_score(struct ast_channel *chan, char *cmd, char *data,
		       char *buf, size_t len)
{
	struct ast_speech_result *result = NULL;
	struct ast_speech *speech = find_speech(chan);
	char tmp[128] = "";

	if (data == NULL || speech == NULL || !(result = find_result(speech->results, data)))
		return -1;
	
	snprintf(tmp, sizeof(tmp), "%d", result->score);
	
	ast_copy_string(buf, tmp, len);

	return 0;
}