Beispiel #1
0
int check_event(esl_handle_t * handle, int timer)
{
    int done = 0, c = 0;
    esl_status_t status;
    time_t exp = 0;
    char dtmf[128];
    int res = 0;
    int  channel_execute = 0;
    dtmf[0] = 0;
    printf("%s,%d check_event\n", __FILE__, __LINE__);
    while ((status = esl_recv_timed(handle, 1000)) != ESL_FAIL)
    {
        c++;
        //disp_msg("Waiting 1 seconds events.\n");
        if (timer>0 && c >= timer) {
            res = 100;
            break;
        }

        if (status == ESL_SUCCESS)
        {
            const char *type = esl_event_get_header(handle->last_event, "content-type");

            if (type)
            {
                if (strcasecmp(type, "text/disconnect-notice") == 0)
                {
                    const char *dispo = esl_event_get_header(handle->last_event, "content-disposition");
                    //disp_msg("Got a disconnection notice dispostion: [%s]", dispo ? dispo : "");
                    if (dispo && strcmp(dispo, "linger") == 0)
                    {
                        res = -99;
                        break;
                    }
                }
                if (strcasecmp(type, "text/event-plain") == 0)
                {
                    const char *eventbody = esl_event_get_body(handle->last_event);
                    if ((res = check_event_body(eventbody, dtmf, 1, "#", &channel_execute)))
                    {
                        //disp_msg("check_event_body res=%d.",res);
                        if (res<0)	break;
                    }
                }

            }
        }
    }
    //disp_msg("check_event res=%d",res);
    return res;
}
Beispiel #2
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);
}