Skip to content

Instantly share code, notes, and snippets.

@seven1240
Created July 11, 2014 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seven1240/e80e1bf243588e907b39 to your computer and use it in GitHub Desktop.
Save seven1240/e80e1bf243588e907b39 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <esl.h>
static void bridge_callback(esl_socket_t server_sock, esl_socket_t client_sock, struct sockaddr_in *addr, void *user_data)
{
esl_handle_t handle = {{0}};
esl_status_t status = ESL_SUCCESS;
const char *cid_name, *cid_number;
esl_attach_handle(&handle, client_sock, addr);
cid_name = esl_event_get_header(handle.info_event, "Caller-Caller-ID-Name");
cid_number = esl_event_get_header(handle.info_event, "Caller-Caller-ID-Number");
esl_log(ESL_LOG_INFO, "New Call From \"%s\" <%s>\n", cid_name, cid_number);
esl_send_recv(&handle, "myevents");
esl_log(ESL_LOG_INFO, "%s\n", handle.last_sr_reply);
esl_send_recv(&handle, "linger 5");
esl_log(ESL_LOG_INFO, "%s\n", handle.last_sr_reply);
esl_execute(&handle, "bridge", "user/1008", NULL);
while(status == ESL_SUCCESS || status == ESL_BREAK) {
const char *type;
const char *application;
status = esl_recv_timed(&handle, 1000);
if (status == ESL_BREAK) {
continue;
}
type = esl_event_get_header(handle.last_event, "content-type");
if (type && !strcasecmp(type, "text/event-plain")) {
esl_log(ESL_LOG_INFO, "Event: %s\n", esl_event_get_header(handle.last_ievent, "Event-Name"));
}
}
end:
esl_log(ESL_LOG_INFO, "Disconnected! status = %d\n", status);
esl_disconnect(&handle);
}
int main(void)
{
esl_global_set_default_logger(ESL_LOG_LEVEL_INFO);
esl_log(ESL_LOG_INFO, "ACD Server listening at localhost:8040 ...\n");
esl_listen_threaded("localhost", 8040, bridge_callback, NULL, 100000);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment