Ejemplo n.º 1
0
static void mycallback(esl_socket_t server_sock, esl_socket_t client_sock, struct sockaddr_in *addr, void *user_data)
{
	esl_handle_t handle = {{0}};
	const char *path;
	char path_buffer[1024] = { 0 };

	if (esl_attach_handle(&handle, client_sock, addr) != ESL_SUCCESS || !handle.info_event) {
		close(client_sock);
		esl_log(ESL_LOG_ERROR, "Socket Error\n");
		return;
	}

	if (!(path = esl_event_get_header(handle.info_event, "variable_ivr_path"))) {
		esl_disconnect(&handle);
		esl_log(ESL_LOG_ERROR, "Missing ivr_path param!\n");
		return;
	}

	snprintf(path_buffer, sizeof(path_buffer), "%s %d", path, client_sock);


	if (system(path_buffer)) {
		 esl_log(ESL_LOG_ERROR, "System Call Failed! [%s]\n", strerror(errno));
	}

	esl_disconnect(&handle);
	
}
Ejemplo n.º 2
0
static void mycallback(esl_socket_t server_sock, esl_socket_t client_sock, struct sockaddr_in *addr)
{
	esl_handle_t handle = {{0}};
	char path_buffer[1024] = { 0 };
	const char *path;
	
	if (esl_attach_handle(&handle, client_sock, addr) != ESL_SUCCESS || !handle.info_event) {
		esl_log(ESL_LOG_ERROR, "Socket Error\n");
		exit(0);
	}

	if (!(path = esl_event_get_header(handle.info_event, "variable_ivr_path"))) {
		esl_disconnect(&handle);
		esl_log(ESL_LOG_ERROR, "Missing ivr_path param!\n");
		exit(0);
	}

	strncpy(path_buffer, path, sizeof(path_buffer) - 1);
	
	/* hotwire the socket to STDIN/STDOUT */
	dup2(client_sock, STDIN_FILENO);
	dup2(client_sock, STDOUT_FILENO);

	/* close the handle but leak the socket on purpose cos the child will need it open */
	handle.sock = -1;
	esl_disconnect(&handle);
	
	execl(path_buffer, path_buffer, (char *)NULL);
	//system(path_buffer);
	close(client_sock);
	exit(0);
}
Ejemplo n.º 3
0
static void mycallback(esl_socket_t server_sock, esl_socket_t client_sock, struct sockaddr_in *addr, void *user_data)
{
	esl_handle_t handle = {{0}};
	int done = 0;
	esl_status_t status;
	time_t exp = 0;

	if (fork()) {
		return;
	}

	if (esl_attach_handle(&handle, client_sock, addr) != ESL_SUCCESS) {
		return;
	}


	esl_log(ESL_LOG_INFO, "Connected! %d\n", handle.sock);

	esl_filter(&handle, "unique-id", esl_event_get_header(handle.info_event, "caller-unique-id"));
	esl_events(&handle, ESL_EVENT_TYPE_PLAIN, "SESSION_HEARTBEAT CHANNEL_ANSWER CHANNEL_ORIGINATE CHANNEL_PROGRESS CHANNEL_HANGUP "
			   "CHANNEL_BRIDGE CHANNEL_UNBRIDGE CHANNEL_OUTGOING CHANNEL_EXECUTE CHANNEL_EXECUTE_COMPLETE DTMF CUSTOM conference::maintenance");

	esl_send_recv(&handle, "linger");

	esl_execute(&handle, "answer", NULL, NULL);
	esl_execute(&handle, "conference", "3000@default", NULL);
	
	while((status = esl_recv_timed(&handle, 1000)) != ESL_FAIL) {
		if (done) {
			if (time(NULL) >= exp) {
				break;
			}
		} else if (status == ESL_SUCCESS) {
			const char *type = esl_event_get_header(handle.last_event, "content-type");
			if (type && !strcasecmp(type, "text/disconnect-notice")) {
				const char *dispo = esl_event_get_header(handle.last_event, "content-disposition");
				esl_log(ESL_LOG_INFO, "Got a disconnection notice dispostion: [%s]\n", dispo ? dispo : "");
				if (dispo && !strcmp(dispo, "linger")) {
					done = 1;
					esl_log(ESL_LOG_INFO, "Waiting 5 seconds for any remaining events.\n");
					exp = time(NULL) + 5;
				}
			}
		}
	}
	
	esl_log(ESL_LOG_INFO, "Disconnected! %d\n", handle.sock);
	esl_disconnect(&handle);
}
Ejemplo n.º 4
0
static void my_forking_callback(esl_socket_t server_sock, esl_socket_t client_sock, struct sockaddr_in *addr, void *user_data)
{
	esl_handle_t handle = {{0}};
	char path_buffer[1024] = { 0 };
	const char *path;
	char arg[64] = { 0 };

	signal(SIGCHLD, handle_SIGCHLD);

	if (fork()) {
		close(client_sock);
		return;
	}
	
	if (esl_attach_handle(&handle, client_sock, addr) != ESL_SUCCESS || !handle.info_event) {
		esl_log(ESL_LOG_ERROR, "Socket Error\n");
		exit(0);
	}

	if (!(path = esl_event_get_header(handle.info_event, "variable_ivr_path"))) {
		esl_disconnect(&handle);
		esl_log(ESL_LOG_ERROR, "Missing ivr_path param!\n");
		exit(0);
	}

	snprintf(arg, sizeof(arg), "%d", client_sock);

	strncpy(path_buffer, path, sizeof(path_buffer) - 1);
	
	/* hotwire the socket to STDIN/STDOUT */
	/* hotwire the socket to STDIN/STDOUT */
	if (!(dup2(client_sock, STDIN_FILENO)) && !(dup2(client_sock, STDOUT_FILENO))){
		esl_disconnect(&handle);
		esl_log(ESL_LOG_ERROR, "Socket Error hotwiring socket to STDIN/STDOUT!\n");
		return;
	}

	/* close the handle but leak the socket on purpose cos the child will need it open */
	handle.sock = -1;
	esl_disconnect(&handle);
	
	execl(path_buffer, path_buffer, arg, (char *)NULL);
	close(client_sock);
	exit(0);
}
Ejemplo n.º 5
0
ESLconnection::ESLconnection(int socket)
{
	connection_construct_common();
	memset(&handle, 0, sizeof(handle));
	esl_attach_handle(&handle, (esl_socket_t)socket, NULL);
}