Skip to content

Commit

Permalink
esl_execute distroys handle->last_ievent internally so we should dup …
Browse files Browse the repository at this point in the history
…anything for safety before esl_execute
  • Loading branch information
seven1240 committed Aug 17, 2015
1 parent 4d974bf commit 34d5522
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions icharge.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ int check_account_password(const char *account, const char *password)

void process_event(esl_handle_t *handle, esl_event_t *event)
{
const char *uuid;
const char *uuid = esl_event_get_header(event, "Caller-Unique-ID");

uuid = strdup(uuid);
if (!uuid) abort();

switch (event->event_id) {
case ESL_EVENT_CHANNEL_PARK:
{
Expand All @@ -22,7 +26,6 @@ void process_event(esl_handle_t *handle, esl_event_t *event)

if (!service || (service && strcmp(service, "icharge"))) break;

uuid = esl_event_get_header(event, "Caller-Unique-ID");
esl_log(ESL_LOG_INFO, "New Call %s\n", uuid);

esl_execute(handle, "answer", NULL, uuid);
Expand Down Expand Up @@ -50,7 +53,6 @@ void process_event(esl_handle_t *handle, esl_event_t *event)
const char *application;
const char *charge_state;

uuid = esl_event_get_header(event, "Caller-Unique-ID");
application = esl_event_get_header(event, "Application");
charge_state = esl_event_get_header(event, "variable_charge_state");

Expand All @@ -73,12 +75,13 @@ void process_event(esl_handle_t *handle, esl_event_t *event)
break;
}
case ESL_EVENT_CHANNEL_HANGUP_COMPLETE:
uuid = esl_event_get_header(event, "Caller-Unique-ID");
esl_log(ESL_LOG_INFO, "Hangup %s\n", uuid);
break;
default:
break;
}

free((void *)uuid);
}

int main(void)
Expand Down

0 comments on commit 34d5522

Please sign in to comment.