Ejemplo n.º 1
0
void conference_loop_energy_dn(conference_member_t *member, caller_control_action_t *action)
{
	char msg[512], str[30] = "", *p;
	switch_event_t *event;

	if (member == NULL)
		return;

	member->energy_level -= 200;
	if (member->energy_level < 0) {
		member->energy_level = 0;
	}

	if (test_eflag(member->conference, EFLAG_ENERGY_LEVEL) &&
		switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
		conference_member_add_event_data(member, event);
		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action", "energy-level");
		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->energy_level);
		switch_event_fire(&event);
	}

	//switch_snprintf(msg, sizeof(msg), "Energy level %d", member->energy_level);
	//conference_member_say(member, msg, 0);

	switch_snprintf(str, sizeof(str), "%d", abs(member->energy_level) / 200);
	for (p = str; p && *p; p++) {
		switch_snprintf(msg, sizeof(msg), "digits/%c.wav", *p);
		conference_member_play_file(member, msg, 0, SWITCH_TRUE);
	}

}
Ejemplo n.º 2
0
void conference_loop_volume_listen_dn(conference_member_t *member, caller_control_action_t *action)
{
	char msg[512];
	switch_event_t *event;

	if (member == NULL)
		return;

	member->volume_in_level--;
	switch_normalize_volume(member->volume_in_level);

	if (test_eflag(member->conference, EFLAG_GAIN_LEVEL) &&
		switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
		conference_member_add_event_data(member, event);
		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action", "gain-level");
		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->volume_in_level);
		switch_event_fire(&event);
	}

	//switch_snprintf(msg, sizeof(msg), "Gain level %d", member->volume_in_level);
	//conference_member_say(member, msg, 0);

	if (member->volume_in_level < 0) {
		switch_snprintf(msg, sizeof(msg), "currency/negative.wav", member->volume_in_level);
		conference_member_play_file(member, msg, 0, SWITCH_TRUE);
	}

	switch_snprintf(msg, sizeof(msg), "digits/%d.wav", abs(member->volume_in_level));
	conference_member_play_file(member, msg, 0, SWITCH_TRUE);
}
Ejemplo n.º 3
0
static valet_token_t *next_id(switch_core_session_t *session, valet_lot_t *lot, int min, int max, int in)
{
	int i, r = 0;
	char buf[256] = "";
	valet_token_t *token;

	if (!min) {
		min = 1;
	}

	switch_mutex_lock(globals.mutex);

	if (!in) {
		int longest = find_longest(lot, min, max);
		if (longest > 0) {
			switch_snprintf(buf, sizeof(buf), "%d", longest);
			switch_mutex_lock(lot->mutex);
			token = (valet_token_t *) switch_core_hash_find(lot->hash, buf);
			switch_mutex_unlock(lot->mutex);
			if (token) {
				goto end;
			}
		}
	}

	for (i = min; (i < max || max == 0); i++) {
		switch_snprintf(buf, sizeof(buf), "%d", i);
		switch_mutex_lock(lot->mutex);
		token = (valet_token_t *) switch_core_hash_find(lot->hash, buf);
		switch_mutex_unlock(lot->mutex);

		if ((!in && token && !token->timeout)) {
			goto end;
		}

		if (in && !token) {
			r = i;
			break;
		}
	}

	token = NULL;

	if (r) {
		switch_snprintf(buf, sizeof(buf), "%d", r);
		switch_zmalloc(token, sizeof(*token));
		switch_set_string(token->uuid, switch_core_session_get_uuid(session));
		switch_set_string(token->ext, buf);
		token->start_time = switch_epoch_time_now(NULL);
		switch_mutex_lock(lot->mutex);
		switch_core_hash_insert(lot->hash, buf, token);
		switch_mutex_unlock(lot->mutex);
	}

 end:

	switch_mutex_unlock(globals.mutex);

	return token;
}
Ejemplo n.º 4
0
switch_status_t utils_start_sofia_profile(char *profile_name)
{
    char cmd[128];
    char arg[128];
    switch_stream_handle_t mystream = { 0 };
    if (!zstr(profile_name)) {
        if (utils_profile_control(profile_name) != SWITCH_STATUS_SUCCESS) {
            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
                              "profile %s doesn't exist in sip_profiles directory\n",profile_name);
            return SWITCH_STATUS_FALSE;
        }
        switch_snprintf(cmd, sizeof(cmd),"sofia");
        switch_snprintf(arg, sizeof(arg), "profile %s start",profile_name);
        SWITCH_STANDARD_STREAM(mystream);
        if (switch_api_execute(cmd, arg, NULL, &mystream) != SWITCH_STATUS_SUCCESS) {
            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"cannot execute sofia api %s\n", profile_name);
            return SWITCH_STATUS_FALSE;
        }
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,"profile %s started\n", profile_name);
        switch_safe_free(mystream.data);
        return SWITCH_STATUS_SUCCESS;
    } else {
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"Invalid profile name\n");
        return SWITCH_STATUS_FALSE;
    }

}
Ejemplo n.º 5
0
static switch_status_t listen_entry(switch_core_session_t *session, dir_profile_t *profile, listing_callback_t *cbt)
{
	char buf[2] = "";
	char macro[256] = "";
	char recorded_name[256] = "";

	/* Try to use the recorded name from voicemail if it exist */
	if (switch_loadable_module_exists("mod_voicemail") == SWITCH_STATUS_SUCCESS) {
		char *cmd = NULL;
		switch_stream_handle_t stream = { 0 };
		SWITCH_STANDARD_STREAM(stream);

		cmd = switch_core_session_sprintf(session, "%s/%s@%s|name_path", cbt->params->profile, cbt->extension, cbt->params->domain);
		switch_api_execute("vm_prefs", cmd, session, &stream);
		if (strncmp("-ERR", stream.data, 4)) {
			switch_copy_string(recorded_name, (char *) stream.data, sizeof(recorded_name));
		}
		switch_safe_free(stream.data);
	}

	if (zstr_buf(buf)) {
		switch_snprintf(macro, sizeof(macro), "phrase:%s:%d", DIR_RESULT_ITEM, cbt->want + 1);
		switch_ivr_read(session, 0, 1, macro, NULL, buf, sizeof(buf), 1, profile->terminator_key, 0);
	}

	if (!zstr_buf(recorded_name) && zstr_buf(buf)) {
		switch_ivr_read(session, 0, 1, recorded_name, NULL, buf, sizeof(buf), 1, profile->terminator_key, 0);

	}
	if (zstr_buf(recorded_name) && zstr_buf(buf)) {
		switch_snprintf(macro, sizeof(macro), "phrase:%s:%s", DIR_RESULT_SAY_NAME, cbt->fullname);
		switch_ivr_read(session, 0, 1, macro, NULL, buf, sizeof(buf), 1, profile->terminator_key, 0);
	}
	if (cbt->exten_visible && zstr_buf(buf)) {
		switch_snprintf(macro, sizeof(macro), "phrase:%s:%s", DIR_RESULT_AT, cbt->extension);
		switch_ivr_read(session, 0, 1, macro, NULL, buf, sizeof(buf), 1, profile->terminator_key, 0);
	}
	if (zstr_buf(buf)) {
		switch_snprintf(macro, sizeof(macro), "phrase:%s:%c,%c,%c,%c", DIR_RESULT_MENU, *profile->select_name_key, *profile->next_key, *profile->prev_key,
						*profile->new_search_key);
		switch_ivr_read(session, 0, 1, macro, NULL, buf, sizeof(buf), profile->digit_timeout, profile->terminator_key, 0);
	}

	if (!zstr_buf(buf)) {
		if (buf[0] == *profile->select_name_key) {
			switch_copy_string(cbt->transfer_to, cbt->extension, 255);
		}
		if (buf[0] == *profile->new_search_key) {
			cbt->new_search = 1;
		}
		if (buf[0] == *profile->prev_key) {
			cbt->move = ENTRY_MOVE_PREV;
		}
	} else {
		return SWITCH_STATUS_TIMEOUT;
	}

	return SWITCH_STATUS_SUCCESS;
}
Ejemplo n.º 6
0
static switch_status_t process_node(const switch_log_node_t *node, switch_log_level_t level)
{
	switch_hash_index_t *hi;
	void *val;
	const void *var;
	logfile_profile_t *profile;

	for (hi = switch_core_hash_first(profile_hash); hi; hi = switch_core_hash_next(&hi)) {
		size_t mask = 0;
		size_t ok = 0;

		switch_core_hash_this(hi, &var, NULL, &val);
		profile = val;

		ok = switch_log_check_mask(profile->all_level, level);

		if (!ok) {
			mask = (size_t) switch_core_hash_find(profile->log_hash, node->file);
			ok = switch_log_check_mask(mask, level);
		}

		if (!ok) {
			mask = (size_t) switch_core_hash_find(profile->log_hash, node->func);
			ok = switch_log_check_mask(mask, level);
		}

		if (!ok) {
			char tmp[256] = "";
			switch_snprintf(tmp, sizeof(tmp), "%s:%s", node->file, node->func);
			mask = (size_t) switch_core_hash_find(profile->log_hash, tmp);
			ok = switch_log_check_mask(mask, level);
		}

		if (ok) {
			if (profile->log_uuid && !zstr(node->userdata)) {
				char buf[2048];
				char *dup = strdup(node->data);
				char *lines[100];
				int argc, i;
				
				argc = switch_split(dup, '\n', lines);
				for (i = 0; i < argc; i++) {
					switch_snprintf(buf, sizeof(buf), "%s %s\n", node->userdata, lines[i]);
					mod_logfile_raw_write(profile, buf);	
				}
				
				free(dup);
				
			} else {
				mod_logfile_raw_write(profile, node->data);
			}
		}

	}

	return SWITCH_STATUS_SUCCESS;
}
Ejemplo n.º 7
0
SWITCH_DECLARE(int) switch_config_open_file(switch_config_t *cfg, char *file_path)
{
	FILE *f;
	char *path = NULL;
	char path_buf[1024];

	if (switch_is_file_path(file_path)) {
		path = file_path;
	} else {
		switch_snprintf(path_buf, sizeof(path_buf), "%s%s%s", SWITCH_GLOBAL_dirs.conf_dir, SWITCH_PATH_SEPARATOR, file_path);
		path = path_buf;
	}

	if (!path) {
		return 0;
	}

	memset(cfg, 0, sizeof(*cfg));
	cfg->lockto = -1;

	if (!(f = fopen(path, "r"))) {
		if (!switch_is_file_path(file_path)) {
			int last = -1;
			char *var, *val;

			switch_snprintf(path_buf, sizeof(path_buf), "%s%sfreeswitch.conf", SWITCH_GLOBAL_dirs.conf_dir, SWITCH_PATH_SEPARATOR);
			path = path_buf;

			if ((f = fopen(path, "r")) == 0) {
				return 0;
			}

			cfg->file = f;
			switch_set_string(cfg->path, path);

			while (switch_config_next_pair(cfg, &var, &val)) {
				if (file_path && (cfg->sectno != last) && !strcmp(cfg->section, file_path)) {
					cfg->lockto = cfg->sectno;
					return 1;
				}
			}

			switch_config_close_file(cfg);
			memset(cfg, 0, sizeof(*cfg));
			return 0;
		}

		return 0;
	} else {
		cfg->file = f;
		switch_set_string(cfg->path, path);
		return 1;
	}
}
Ejemplo n.º 8
0
static xmlrpc_value *freeswitch_man(xmlrpc_env * const envP, xmlrpc_value * const paramArrayP, void *const userData)
{
	char *oid = NULL, *relative_oid, *s_action = NULL, *data = NULL;
	char buf[SWITCH_MAX_MANAGEMENT_BUFFER_LEN] = "";
	switch_management_action_t action = SMA_NONE;
	xmlrpc_value *val = NULL;

	/* Parse our argument array. */
	xmlrpc_decompose_value(envP, paramArrayP, "(sss)", &oid, &s_action, &data);
	if (envP->fault_occurred) {
		return NULL;
	}

	if (!strncasecmp(oid, FREESWITCH_OID_PREFIX, strlen(FREESWITCH_OID_PREFIX))) {
		relative_oid = oid + strlen(FREESWITCH_OID_PREFIX);
	} else {
		relative_oid = oid;
	}

	if (!zstr(data)) {
		switch_copy_string(buf, data, sizeof(buf));
	}

	if (!strcasecmp(s_action, "get")) {
		action = SMA_GET;
	} else if (!strcasecmp(s_action, "set")) {
		action = SMA_SET;
	}

	if (action) {
		if (switch_core_management_exec(relative_oid, action, buf, sizeof(buf)) == SWITCH_STATUS_SUCCESS) {
			if (action == SMA_SET) {
				if (*buf != '\0') {
					switch_snprintf(buf, sizeof(buf), "OK\n");
				}
			}
		} else {
			if (*buf != '\0') {
				switch_snprintf(buf, sizeof(buf), "ERROR\n");
			}
		}
	} else {
		switch_snprintf(buf, sizeof(buf), "Invalid Action %s\n", s_action);
	}

	/* Return our result. */
	val = xmlrpc_build_value(envP, "s", buf);

	/* xmlrpc-c requires us to free memory it malloced from xmlrpc_decompose_value */
	switch_safe_free(oid);
	switch_safe_free(s_action);
	switch_safe_free(data);
	return val;
}
Ejemplo n.º 9
0
cc_status_t cc_agent_get(const char *key, const char *agent, char *ret_result, size_t ret_result_size)
{
	cc_status_t result = CC_STATUS_SUCCESS;
	char *sql;
	switch_event_t *event;
	char res[256];

	/* Check to see if agent already exists */
	sql = switch_mprintf("SELECT count(*) FROM agents WHERE name = '%q'", agent);
	cc_execute_sql2str(NULL, NULL, sql, res, sizeof(res));
	switch_safe_free(sql);

	if (atoi(res) == 0) {
		result = CC_STATUS_AGENT_NOT_FOUND;
		goto done;
	}

	if (!strcasecmp(key, "status") || !strcasecmp(key, "state") || !strcasecmp(key, "uuid") ) { 
		/* Check to see if agent already exists */
		sql = switch_mprintf("SELECT %q FROM agents WHERE name = '%q'", key, agent);
		cc_execute_sql2str(NULL, NULL, sql, res, sizeof(res));
		switch_safe_free(sql);
		switch_snprintf(ret_result, ret_result_size, "%s", res);
		result = CC_STATUS_SUCCESS;

		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CALLCENTER_EVENT) == SWITCH_STATUS_SUCCESS) {
			char tmpname[256];
			if (!strcasecmp(key, "uuid")) {
				switch_snprintf(tmpname, sizeof(tmpname), "CC-Agent-UUID");	
			} else {
				switch_snprintf(tmpname, sizeof(tmpname), "CC-Agent-%c%s", (char) switch_toupper(key[0]), key+1);
			}
			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "CC-Agent", agent);
			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "CC-Action", "agent-%s-get", key);
			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, tmpname, res);
			switch_event_fire(&event);
		}

	} else {
		result = CC_STATUS_INVALID_KEY;
		goto done;

	}

done:   
	if (result == CC_STATUS_SUCCESS) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Get Info Agent %s %s = %s\n", agent, key, res);
	}

	return result;
}
Ejemplo n.º 10
0
int eventpipe_check_count(switch_core_session_t *session) {
	const char *check_str = NULL;
	int check_count = 0;
	char vbuf[10] = "";

	switch_channel_t *channel = switch_core_session_get_channel(session);
	check_str = switch_channel_get_variable(channel, "eventpipe_run_count");

	if (!zstr(check_str)) {
		/* check if reach max count */
		check_count = atoi(check_str);
		if (check_count >= PLIVO_MAX_RUN) {
			switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), 
				SWITCH_LOG_ERROR, "Abort, Max eventpipe applications reached for a call (%d)!\n", PLIVO_MAX_RUN);
			return 0;
		/* increment redirect count */
		} else {
			check_count++;
			switch_snprintf(vbuf, sizeof(vbuf), "%d", check_count);
			switch_channel_set_variable(channel, "eventpipe_run_count", vbuf);
			switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "eventpipe_run_count %d\n", check_count);
			return 1;
		}
	}
	/* Hu ?! must never be here */
	switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Hu ?! must never be here !\n");
	return 0;
}
Ejemplo n.º 11
0
SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_write_codec(switch_core_session_t *session, switch_codec_t *codec)
{
	switch_event_t *event;
	switch_channel_t *channel = switch_core_session_get_channel(session);
	char tmp[30];
	switch_status_t status = SWITCH_STATUS_SUCCESS;
	if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) {
		if (session->video_write_codec) {
			session->video_write_codec = NULL;
			status = SWITCH_STATUS_SUCCESS;
			goto end;
		}
		switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot set NULL codec!\n");
		status = SWITCH_STATUS_FALSE;
		goto end;
	}

	if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) {
		switch_channel_event_set_data(session->channel, event);
		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-video-write-codec-name", codec->implementation->iananame);
		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-video-write-codec-rate", "%d", codec->implementation->actual_samples_per_second);
		switch_event_fire(&event);
	}

	switch_channel_set_variable(channel, "video_write_codec", codec->implementation->iananame);
	switch_snprintf(tmp, sizeof(tmp), "%d", codec->implementation->actual_samples_per_second);
	switch_channel_set_variable(channel, "video_write_rate", tmp);

	session->video_write_codec = codec;
	session->video_write_impl = *codec->implementation;

  end:

	return status;
}
Ejemplo n.º 12
0
switch_status_t utils_profile_control(char *profile_name)
{
    /*TODO trovare un altro modo per controllare che il profilo sofia sia definito. Probabilmente il controllo sul file è una idiozia.*/
    char pathname[128];
    switch_snprintf(pathname,sizeof(pathname),"%s/sip_profiles/%s.xml",SWITCH_GLOBAL_dirs.conf_dir,profile_name);
    return switch_file_exists(pathname,globals.pool);
}
Ejemplo n.º 13
0
static int group_callback(void *pArg, int argc, char **argv, char **columnNames)
{
	callback_t *cbt = (callback_t *) pArg;
	switch_snprintf(cbt->buf + strlen(cbt->buf), cbt->len - strlen(cbt->buf), "%s%c", argv[0], *argv[1]);
	cbt->matches++;
	return 0;
}
Ejemplo n.º 14
0
static switch_status_t process_event(switch_event_t *event)
{
	switch_core_session_t *session = NULL;
	switch_channel_t *channel;
	char *username[3] = { 0 };
	char *domain[3] = { 0 };
	char key[512];
	char *uuid = NULL, *my_uuid = NULL;
	int i;


	switch_thread_rwlock_rdlock(globals.spy_hash_lock);

	if (!globals.spy_count) {
		goto done;
	}

	username[0] = switch_event_get_header(event, "Caller-Username");
	domain[0] = switch_event_get_header(event, "variable_domain_name");

	domain[1] = switch_event_get_header(event, "variable_dialed_domain");
	username[1] = switch_event_get_header(event, "variable_dialed_user");

	username[2] = switch_event_get_header(event, "variable_user_name");
	domain[2] = switch_event_get_header(event, "variable_domain_name");

	for (i = 0; i < 3; i++) {

		if (username[i] && domain[i]) {
			switch_snprintf(key, sizeof(key), "%s@%s", username[i], domain[i]);

			if ((uuid = switch_core_hash_find(globals.spy_hash, key))) {
				break;
			}
		}
	}

 done:
	switch_thread_rwlock_unlock(globals.spy_hash_lock);

	if (!uuid) {
		return SWITCH_STATUS_FALSE;
	}

	session = switch_core_session_locate(uuid);
	channel = switch_core_session_get_channel(session);

	switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "UserSpy retrieved uuid %s for key %s, activating eavesdrop \n", uuid, key);
	my_uuid = switch_event_get_header(event, "Unique-ID");

	switch_channel_set_variable(channel, "spy_uuid", my_uuid);

	switch_channel_set_state(channel, CS_EXCHANGE_MEDIA);
	switch_channel_set_flag(channel, CF_BREAK);

	switch_core_session_rwunlock(session);
	return SWITCH_STATUS_SUCCESS;

}
Ejemplo n.º 15
0
static switch_status_t switch_sangoma_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
{
	uint32_t encoding, decoding;
	struct sangoma_transcoding_session *sess = NULL;
	vocallo_codec_t *vcodec;
	
	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sangoma init called.\n");

	encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
	decoding = (flags & SWITCH_CODEC_FLAG_DECODE);

	if (!(encoding || decoding)) {
		return SWITCH_STATUS_FALSE;
	}

	if (!(sess = switch_core_alloc(codec->memory_pool, sizeof(*sess)))) {
		return SWITCH_STATUS_FALSE;
	}
	memset(sess, 0, sizeof(*sess));

	sess->encoder.lastrxseqno = -1;
	sess->decoder.lastrxseqno = -1;

	sess->pool = codec->memory_pool;
	sess->impl = codec->implementation;

	vcodec = get_codec_from_iana(codec->implementation->ianacode);
	
	switch_mutex_lock(g_sessions_lock);

	if (encoding) {
		sess->encoder.request.usr_priv = sess;
		sess->encoder.request.a.codec_id = SNGTC_CODEC_PCMU;
		sess->encoder.request.a.ms = 0; /*codec->implementation->microseconds_per_packet/1000;*/

		sess->encoder.request.b.codec_id = vcodec->codec_id;
		sess->encoder.request.b.ms = 0; /*codec->implementation->microseconds_per_packet/1000;*/
	}

	if (decoding) {
		sess->decoder.request.usr_priv = sess;
		sess->decoder.request.a.codec_id = vcodec->codec_id;
		sess->decoder.request.a.ms = 0; /*codec->implementation->microseconds_per_packet/1000;*/

		sess->decoder.request.b.codec_id = SNGTC_CODEC_PCMU;
		sess->decoder.request.b.ms = 0; /*codec->implementation->microseconds_per_packet/1000;*/

	}

	sess->sessid = g_next_session_id++;
	switch_snprintf(sess->hashkey, sizeof(sess->hashkey), SANGOMA_SESS_HASH_KEY_FORMAT, sess->sessid);
	switch_core_hash_insert(g_sessions_hash, sess->hashkey, sess);

	switch_mutex_unlock(g_sessions_lock);

	codec->private_info = sess;

	return SWITCH_STATUS_SUCCESS;
}
Ejemplo n.º 16
0
void utils_hupall(char *profile_name)
{
    char cmd[128];
    char arg[128];
    switch_stream_handle_t mystream = { 0 };

    switch_snprintf(cmd, sizeof(cmd),"hupall");
    switch_snprintf(arg, sizeof(arg),"normal_clearing sofia_profile_name %s",profile_name);
    SWITCH_STANDARD_STREAM(mystream);
    if (switch_api_execute(cmd, arg, NULL, &mystream) != SWITCH_STATUS_SUCCESS) {
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"cannot hupall for %s\n",profile_name);
        return;
    }
    switch_safe_free(mystream.data);
    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,"hupall for %s done\n",profile_name);
    return;
}
Ejemplo n.º 17
0
void eventpipe_events_on_conference(switch_core_session_t *session, switch_event_t *event) {
	char args[8192];
	char record_args[8192];
	const char *action = switch_str_nil(switch_event_get_header(event, "action"));
	const char *member_id = switch_str_nil(switch_event_get_header(event, "member-id"));
	const char *conf_room = switch_str_nil(switch_event_get_header(event, "conference-name"));
	const char *calluuid = switch_core_session_get_uuid(session);
	switch_channel_t *channel = switch_core_session_get_channel(session);
	if (!channel) {
		return;
	}

	switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, 
				"Event-Name: %s, Event-Subclass: %s, Conference-Name: %s, Action: %s, Member-ID: %s, Unique-ID: %s\n", 
				switch_str_nil(switch_event_get_header(event, "event-name")), 
				switch_str_nil(switch_event_get_header(event, "event-subclass")), 
				conf_room, action, member_id, calluuid);

	if (!strcmp(action, "add-member")) {
		const char *enter_sound = switch_str_nil(switch_channel_get_variable(channel, "eventpipe_conference_enter_sound"));
		const char *record_file = switch_str_nil(switch_channel_get_variable(channel, "eventpipe_conference_record_file"));
		switch_channel_set_variable(channel, "eventpipe_conference_member_id", member_id);
		switch_channel_set_variable(channel, "eventpipe_conference_room", conf_room);
		if (!zstr(enter_sound)) {
			switch_snprintf(args, sizeof(args), "%s play %s async",
					conf_room, enter_sound);
			eventpipe_execute_api(session, "conference", args);
		}
		if (!zstr(record_file)) {
			switch_snprintf(record_args, sizeof(record_args), "%s record %s",
					conf_room, record_file);
			eventpipe_execute_api(session, "conference", record_args);
		}
	} else if (!strcmp(action, "del-member")) {
		const char *exit_sound = switch_str_nil(switch_channel_get_variable(channel, "eventpipe_conference_exit_sound"));
		switch_channel_set_variable(channel, "eventpipe_conference_member_id", "");
		switch_channel_set_variable(channel, "eventpipe_conference_room", "");
		switch_channel_set_variable(channel, "eventpipe_conference_record_file", "");
		if (!zstr(exit_sound)) {
			switch_snprintf(args, sizeof(args), "conference %s play %s async",
					conf_room, exit_sound);
			eventpipe_execute_api(session, "conference", args);
		}
	}
}
Ejemplo n.º 18
0
static void db_pick_path(const char *dbname, char *buf, switch_size_t size)
{
	memset(buf, 0, size);
	if (switch_is_file_path(dbname)) {
		strncpy(buf, dbname, size);
	} else {
		switch_snprintf(buf, size, "%s%s%s.db", SWITCH_GLOBAL_dirs.db_dir, SWITCH_PATH_SEPARATOR, dbname);
	}
}
Ejemplo n.º 19
0
/* kill a freeswitch process running in background mode */
static int freeswitch_kill_background()
{
	FILE *f;					/* FILE handle to open the pid file */
	char path[PATH_MAX] = "";		/* full path of the PID file */
	pid_t pid = 0;				/* pid from the pid file */

	/* set the globals so we can use the global paths. */
	switch_core_set_globals();

	/* get the full path of the pid file. */
	switch_snprintf(path, sizeof(path), "%s%s%s", SWITCH_GLOBAL_dirs.run_dir, SWITCH_PATH_SEPARATOR, pfile);

	/* open the pid file */
	if ((f = fopen(path, "r")) == 0) {
		/* pid file does not exist */
		fprintf(stderr, "Cannot open pid file %s.\n", path);
		return 255;
	}

	/* pull the pid from the file */
	if (fscanf(f, "%d", (int *) (intptr_t) & pid) != 1) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to get the pid!\n");
	}

	/* if we have a valid pid */
	if (pid > 0) {

		/* kill the freeswitch running at the pid we found */
		fprintf(stderr, "Killing: %d\n", (int) pid);
#ifdef WIN32
		/* for windows we need the event to signal for shutting down a background FreeSWITCH */
		snprintf(path, sizeof(path), "Global\\Freeswitch.%d", pid);

		/* open the event so we can signal it */
		shutdown_event = OpenEvent(EVENT_MODIFY_STATE, FALSE, path);

		/* did we successfully open the event */
		if (!shutdown_event) {
			/* we can't get the event, so we can't signal the process to shutdown */
			fprintf(stderr, "ERROR: Can't Shutdown: %d\n", (int) pid);
		} else {
			/* signal the event to shutdown */
			SetEvent(shutdown_event);
			/* cleanup */
			CloseHandle(shutdown_event);
		}
#else
		/* for unix, send the signal to kill. */
		kill(pid, SIGTERM);
#endif
	}

	/* be nice and close the file handle to the pid file */
	fclose(f);

	return 0;
}
Ejemplo n.º 20
0
static switch_status_t load_profile(switch_xml_t xml)
{
	switch_xml_t param, settings;
	char *name = (char *) switch_xml_attr_soft(xml, "name");
	logfile_profile_t *new_profile;

	new_profile = switch_core_alloc(module_pool, sizeof(*new_profile));
	memset(new_profile, 0, sizeof(*new_profile));
	switch_core_hash_init(&(new_profile->log_hash));
	new_profile->name = switch_core_strdup(module_pool, switch_str_nil(name));

	new_profile->suffix = 1;
	new_profile->log_uuid = SWITCH_TRUE;

	if ((settings = switch_xml_child(xml, "settings"))) {
		for (param = switch_xml_child(settings, "param"); param; param = param->next) {
			char *var = (char *) switch_xml_attr_soft(param, "name");
			char *val = (char *) switch_xml_attr_soft(param, "value");
			if (!strcmp(var, "logfile")) {
				new_profile->logfile = strdup(val);
			} else if (!strcmp(var, "rollover")) {
				new_profile->roll_size = switch_atoui(val);
			} else if (!strcmp(var, "maximum-rotate")) {
				new_profile->max_rot = switch_atoui(val);
				if (new_profile->max_rot == 0) {
					new_profile->max_rot = MAX_ROT;
				}
			} else if (!strcmp(var, "uuid")) {
				new_profile->log_uuid = switch_true(val);
			}
		}
	}

	if ((settings = switch_xml_child(xml, "mappings"))) {
		for (param = switch_xml_child(settings, "map"); param; param = param->next) {
			char *var = (char *) switch_xml_attr_soft(param, "name");
			char *val = (char *) switch_xml_attr_soft(param, "value");

			add_mapping(new_profile, var, val);
		}
	}

	if (zstr(new_profile->logfile)) {
		char logfile[512];
		switch_snprintf(logfile, sizeof(logfile), "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, "freeswitch.log");
		new_profile->logfile = strdup(logfile);
	}

	if (mod_logfile_openlogfile(new_profile, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) {
		return SWITCH_STATUS_GENERR;
	}

	switch_core_hash_insert_destructor(profile_hash, new_profile->name, (void *) new_profile, cleanup_profile);
	return SWITCH_STATUS_SUCCESS;
}
Ejemplo n.º 21
0
SWITCH_DECLARE_NONSTD(switch_status_t) switch_console_stream_write(switch_stream_handle_t *handle, const char *fmt, ...)
{
	va_list ap;
	char *buf = handle->data;
	char *end = handle->end;
	int ret = 0;
	char *data = NULL;

	if (handle->data_len >= handle->data_size) {
		return SWITCH_STATUS_FALSE;
	}

	va_start(ap, fmt);
	//ret = switch_vasprintf(&data, fmt, ap);
	if (!(data = switch_vmprintf(fmt, ap))) {
		ret = -1;
	}
	va_end(ap);

	if (data) {
		switch_size_t remaining = handle->data_size - handle->data_len;
		switch_size_t need = strlen(data) + 1;

		if ((remaining < need) && handle->alloc_len) {
			switch_size_t new_len;
			void *new_data;

			new_len = handle->data_size + need + handle->alloc_chunk;
			if ((new_data = realloc(handle->data, new_len))) {
				handle->data_size = handle->alloc_len = new_len;
				handle->data = new_data;
				buf = handle->data;
				remaining = handle->data_size - handle->data_len;
				handle->end = (uint8_t *) (handle->data) + handle->data_len;
				end = handle->end;
			} else {
				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
				free(data);
				return SWITCH_STATUS_FALSE;
			}
		}

		if (remaining < need) {
			ret = -1;
		} else {
			ret = 0;
			switch_snprintf(end, remaining, "%s", data);
			handle->data_len = strlen(buf);
			handle->end = (uint8_t *) (handle->data) + handle->data_len;
		}
		free(data);
	}

	return ret ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
}
Ejemplo n.º 22
0
SWITCH_DECLARE(switch_status_t) switch_md5_string(char digest_str[SWITCH_MD5_DIGEST_STRING_SIZE], const void *input, switch_size_t inputLen)
{
	unsigned char digest[SWITCH_MD5_DIGESTSIZE];
	apr_status_t status = apr_md5(digest, input, inputLen);
	int x;

	digest_str[SWITCH_MD5_DIGEST_STRING_SIZE - 1] = '\0';

	for (x = 0; x < SWITCH_MD5_DIGESTSIZE; x++) {
		switch_snprintf(digest_str + (x * 2), 3, "%02x", digest[x]);
	}

	return status;
}
Ejemplo n.º 23
0
static uint32_t match_count(char *str, uint32_t max)
{
	char tstr[80] = "";
	uint32_t matches = 0, x = 0;
	uint32_t len = (uint32_t) strlen(str);

	for (x = 0; x < max; x++) {
		switch_snprintf(tstr, sizeof(tstr), "%u", x);
		if (!strncasecmp(str, tstr, len)) {
			matches++;
		}
	}
	return matches;
}
Ejemplo n.º 24
0
switch_status_t gather_name_digit(switch_core_session_t *session, dir_profile_t *profile, search_params_t *params)
{
	switch_channel_t *channel = switch_core_session_get_channel(session);
	switch_status_t status = SWITCH_STATUS_SUCCESS;
	cbr_t cbr;
	int loop = 1;

	switch_input_args_t args = { 0 };
	args.input_callback = on_dtmf;
	args.buf = &cbr;

	while (switch_channel_ready(channel) && loop) {
		char macro[255];
		loop = 0;
		memset(&cbr, 0, sizeof(cbr));
		cbr.profile = profile;
		params->timeout = 0;

		/* Gather the user Name */

		switch_snprintf(macro, sizeof(macro), "%s:%c", (params->search_by == SEARCH_BY_LAST_NAME ? "last_name" : "first_name"), *profile->switch_order_key);
		switch_ivr_phrase_macro(session, DIR_INTRO, macro, NULL, &args);

		while (switch_channel_ready(channel)) {
			if (cbr.digit == *profile->terminator_key) {
				status = SWITCH_STATUS_BREAK;
				break;
			}
			if (cbr.digit == *profile->switch_order_key) {
				if (params->search_by == SEARCH_BY_LAST_NAME) {
					params->search_by = SEARCH_BY_FIRST_NAME;
				} else {
					params->search_by = SEARCH_BY_LAST_NAME;
				}
				loop = 1;
				break;
			}

			if (switch_ivr_collect_digits_callback(session, &args, profile->digit_timeout, 0) == SWITCH_STATUS_TIMEOUT) {
				params->timeout = 1;
				break;
			}

		}
	}
	switch_copy_string(params->digits, cbr.digits, 255);

	return status;
}
Ejemplo n.º 25
0
static void perl_function(switch_core_session_t *session, char *data)
{
	char *uuid = switch_core_session_get_uuid(session);
	PerlInterpreter *my_perl = clone_perl();
	char code[1024] = "";

	perl_parse(my_perl, xs_init, 3, embedding, NULL);

	switch_snprintf(code, sizeof(code),
					"use lib '%s/perl';\n"
					"use freeswitch;\n"
					"$SWITCH_ENV{UUID} = \"%s\";\n" "$session = new freeswitch::Session(\"%s\")", SWITCH_GLOBAL_dirs.base_dir, uuid, uuid);

	perl_parse_and_execute(my_perl, data, code);
	destroy_perl(&my_perl);
}
Ejemplo n.º 26
0
void eventpipe_events_on_dtmf(switch_core_session_t *session, switch_event_t *event) {
	char args[8192];
	const char *dtmf_digit = switch_str_nil(switch_event_get_header(event, "dtmf-digit"));
	switch_channel_t *channel = switch_core_session_get_channel(session);
	const char *hangup_on_star = switch_str_nil(switch_channel_get_variable(channel, "eventpipe_conference_hangup_on_star"));
	const char *conf_room = switch_str_nil(switch_channel_get_variable(channel, "eventpipe_conference_room"));
	const char *conf_member_id = switch_str_nil(switch_channel_get_variable(channel, "eventpipe_conference_member_id"));

	/* handle conference kick if channel is in conference and digit '*' was pressed */
	if ((!strcmp(hangup_on_star, "true")) && (!strcmp(dtmf_digit, "*")) && (!zstr(conf_room)) && (!zstr(conf_member_id))) {
		switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, 
				"Conference, dtmf '*' pressed, kick member %s from room %s\n",
				conf_member_id, conf_room);
		switch_snprintf(args, sizeof(args), "%s kick %s", conf_room, conf_member_id);
		eventpipe_execute_api(session, "conference", args);
	}
}
Ejemplo n.º 27
0
static switch_status_t process_node(const switch_log_node_t *node, switch_log_level_t level)
{
	switch_hash_index_t *hi;
	void *val;
	const void *var;
	logfile_profile_t *profile;

	for (hi = switch_hash_first(NULL, profile_hash); hi; hi = switch_hash_next(hi)) {
		size_t mask = 0;
		size_t ok = 0;

		switch_hash_this(hi, &var, NULL, &val);
		profile = val;

		ok = switch_log_check_mask(profile->all_level, level);

		if (!ok) {
			mask = (size_t) switch_core_hash_find(profile->log_hash, node->file);
			ok = switch_log_check_mask(mask, level);
		}

		if (!ok) {
			mask = (size_t) switch_core_hash_find(profile->log_hash, node->func);
			ok = switch_log_check_mask(mask, level);
		}

		if (ok) {
			if (profile->log_uuid && !zstr(node->userdata)) {
				char buf[2048];
				switch_snprintf(buf, sizeof(buf), "%s %s", node->userdata, node->data);
				mod_logfile_raw_write(profile, buf);
			} else {
				mod_logfile_raw_write(profile, node->data);
			}
		}

	}

	return SWITCH_STATUS_SUCCESS;
}
Ejemplo n.º 28
0
static int next_id(valet_lot_t *lot, int min, int max, int in)
{
    int i, r = 0, m;
    char buf[128] = "";

    if (!min)
        min = 1;

    switch_mutex_lock(globals.mutex);
    for (i = min; (i < max || max == 0); i++) {
        switch_snprintf(buf, sizeof(buf), "%d", i);
        m = !!switch_core_hash_find(lot->hash, buf);

        if ((in && !m) || (!in && m)) {
            r = i;
            break;
        }
    }
    switch_mutex_unlock(globals.mutex);

    return r;
}
Ejemplo n.º 29
0
switch_status_t utils_recover(char *profile_name)
{
    char arg[128];
    switch_stream_handle_t mystream = { 0 };

    if (!zstr(profile_name)) {
        switch_snprintf(arg, sizeof(arg),"profile %s recover",profile_name);
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"sofia %s\n", arg);
        SWITCH_STANDARD_STREAM(mystream);

        if (switch_api_execute("sofia", arg, NULL, &mystream) != SWITCH_STATUS_SUCCESS) {
            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"cannot recover profile %s\n", profile_name);
            return SWITCH_STATUS_FALSE;
        }
        switch_safe_free(mystream.data);
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,"profile %s recovered\n", profile_name);
        return SWITCH_STATUS_SUCCESS;
    } else {
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"Invalid profile name\n");
        return SWITCH_STATUS_FALSE;
    }
    return SWITCH_STATUS_FALSE;
}
Ejemplo n.º 30
0
static switch_status_t tts_commandline_speech_open(switch_speech_handle_t *sh, const char *voice_name, int rate, switch_speech_flag_t *flags)
{
	switch_uuid_t uuid;
	char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
	char outfile[512] = "";

	tts_commandline_t *info = switch_core_alloc(sh->memory_pool, sizeof(*info));

	info->voice_name = switch_core_strdup(sh->memory_pool, voice_name);
	info->rate = rate;

	/* Construct temporary file name with a new UUID */
	switch_uuid_get(&uuid);
	switch_uuid_format(uuid_str, &uuid);
	switch_snprintf(outfile, sizeof(outfile), "%s%s%s.tmp.wav", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR, uuid_str);
	info->file = switch_core_strdup(sh->memory_pool, outfile);

	info->fh = (switch_file_handle_t *) switch_core_alloc(sh->memory_pool, sizeof(switch_file_handle_t));

	sh->private_info = info;

	return SWITCH_STATUS_SUCCESS;
}