mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-16 00:41:41 +00:00
fix event_socket
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4141 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
d1d1c73390
commit
5bb82ebbf8
@ -523,6 +523,8 @@ static void *SWITCH_THREAD_FUNC api_exec(switch_thread_t *thread, void *obj)
|
|||||||
|
|
||||||
struct api_command_struct *acs = (struct api_command_struct *) obj;
|
struct api_command_struct *acs = (struct api_command_struct *) obj;
|
||||||
switch_stream_handle_t stream = {0};
|
switch_stream_handle_t stream = {0};
|
||||||
|
char *reply, *freply = NULL;
|
||||||
|
switch_status_t status;
|
||||||
|
|
||||||
if (switch_thread_rwlock_tryrdlock(acs->listener->rwlock) != SWITCH_STATUS_SUCCESS) {
|
if (switch_thread_rwlock_tryrdlock(acs->listener->rwlock) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error! cannot get read lock.\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error! cannot get read lock.\n");
|
||||||
@ -532,34 +534,38 @@ static void *SWITCH_THREAD_FUNC api_exec(switch_thread_t *thread, void *obj)
|
|||||||
|
|
||||||
SWITCH_STANDARD_STREAM(stream);
|
SWITCH_STANDARD_STREAM(stream);
|
||||||
|
|
||||||
if (stream.data) {
|
if ((status = switch_api_execute(acs->api_cmd, acs->arg, NULL, &stream)) == SWITCH_STATUS_SUCCESS) {
|
||||||
if (switch_api_execute(acs->api_cmd, acs->arg, NULL, &stream) == SWITCH_STATUS_SUCCESS) {
|
reply = stream.data;
|
||||||
if (!stream.data) {
|
} else {
|
||||||
stream.write_function(&stream, "Command returned no output!\n");
|
freply = switch_mprintf("%s: Command not found!", acs->api_cmd);
|
||||||
}
|
reply = freply;
|
||||||
if (acs->bg) {
|
}
|
||||||
switch_event_t *event;
|
|
||||||
|
if (!reply) {
|
||||||
if (switch_event_create(&event, SWITCH_EVENT_BACKGROUND_JOB) == SWITCH_STATUS_SUCCESS) {
|
reply = "Command returned no output!";
|
||||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Job-UUID", acs->uuid_str);
|
}
|
||||||
switch_event_add_body(event, stream.data);
|
|
||||||
switch_event_fire(&event);
|
if (acs->bg) {
|
||||||
}
|
switch_event_t *event;
|
||||||
} else {
|
|
||||||
switch_size_t len;
|
if (switch_event_create(&event, SWITCH_EVENT_BACKGROUND_JOB) == SWITCH_STATUS_SUCCESS) {
|
||||||
char buf[1024];
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Job-UUID", acs->uuid_str);
|
||||||
len = strlen(stream.data);
|
switch_event_add_body(event, reply);
|
||||||
snprintf(buf, sizeof(buf), "Content-Type: api/response\nContent-Length: %"APR_SSIZE_T_FMT"\n\n", len);
|
switch_event_fire(&event);
|
||||||
len = strlen(buf);
|
}
|
||||||
switch_socket_send(acs->listener->sock, buf, &len);
|
} else {
|
||||||
len = strlen(stream.data);
|
switch_size_t len;
|
||||||
switch_socket_send(acs->listener->sock, stream.data, &len);
|
char buf[1024];
|
||||||
}
|
len = strlen(reply);
|
||||||
}
|
snprintf(buf, sizeof(buf), "Content-Type: api/response\nContent-Length: %"APR_SSIZE_T_FMT"\n\n", len);
|
||||||
free(stream.data);
|
len = strlen(buf);
|
||||||
} else {
|
switch_socket_send(acs->listener->sock, buf, &len);
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
|
len = strlen(reply);
|
||||||
}
|
switch_socket_send(acs->listener->sock, reply, &len);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch_safe_free(stream.data);
|
||||||
|
switch_safe_free(freply);
|
||||||
|
|
||||||
switch_thread_rwlock_unlock(acs->listener->rwlock);
|
switch_thread_rwlock_unlock(acs->listener->rwlock);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user