mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-13 01:26:58 +00:00
event socket / ESL improvements
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12228 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -786,12 +786,11 @@ ESL_DECLARE(esl_status_t) esl_recv_event(esl_handle_t *handle, esl_event_t **sav
|
||||
|
||||
while(handle->connected) {
|
||||
rrval = recv(handle->sock, c, 1, 0);
|
||||
|
||||
if (rrval == 0) {
|
||||
if (++zc >= 100) {
|
||||
esl_disconnect(handle);
|
||||
esl_mutex_unlock(handle->mutex);
|
||||
return ESL_FAIL;
|
||||
return ESL_DISCONNECTED;
|
||||
}
|
||||
} else if (rrval < 0) {
|
||||
strerror_r(handle->errnum, handle->err, sizeof(handle->err));
|
||||
@@ -876,21 +875,16 @@ ESL_DECLARE(esl_status_t) esl_recv_event(esl_handle_t *handle, esl_event_t **sav
|
||||
|
||||
hval = esl_event_get_header(revent, "content-type");
|
||||
|
||||
if (!esl_strlen_zero(hval) && !esl_safe_strcasecmp(hval, "text/event-plain") && revent->body) {
|
||||
const char *en;
|
||||
if (!esl_safe_strcasecmp(hval, "text/disconnect-notice") && revent->body) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!esl_safe_strcasecmp(hval, "text/event-plain") && revent->body) {
|
||||
esl_event_types_t et = ESL_EVENT_COMMAND;
|
||||
char *body = strdup(revent->body);
|
||||
|
||||
esl_event_safe_destroy(&handle->last_ievent);
|
||||
|
||||
if ((en = esl_stristr("event-name:", body))) {
|
||||
en++;
|
||||
while(*en == ' ') en++;
|
||||
if (en) {
|
||||
esl_name_event(en, &et);
|
||||
}
|
||||
}
|
||||
|
||||
esl_event_create(&handle->last_ievent, et);
|
||||
|
||||
beg = body;
|
||||
@@ -914,14 +908,18 @@ ESL_DECLARE(esl_status_t) esl_recv_event(esl_handle_t *handle, esl_event_t **sav
|
||||
if (hname && hval) {
|
||||
esl_url_decode(hval);
|
||||
esl_log(ESL_LOG_DEBUG, "RECV INNER HEADER [%s] = [%s]\n", hname, hval);
|
||||
if (!strcasecmp(hname, "event-name")) {
|
||||
esl_event_del_header(handle->last_ievent, "event-name");
|
||||
}
|
||||
esl_event_add_header_string(handle->last_ievent, ESL_STACK_BOTTOM, hname, hval);
|
||||
esl_name_event(hval, &handle->last_event->event_id);
|
||||
}
|
||||
|
||||
beg = c + 1;
|
||||
}
|
||||
|
||||
free(body);
|
||||
|
||||
|
||||
if ((cl = esl_event_get_header(handle->last_ievent, "content-length"))) {
|
||||
esl_ssize_t sofar = 0;
|
||||
|
||||
|
@@ -118,6 +118,8 @@ static const char *EVENT_NAMES[] = {
|
||||
"GENERAL",
|
||||
"COMMAND",
|
||||
"SESSION_HEARTBEAT",
|
||||
"CLIENT_DISCONNECTED",
|
||||
"SERVER_DISCONNECTED",
|
||||
"ALL"
|
||||
};
|
||||
|
||||
@@ -157,10 +159,12 @@ ESL_DECLARE(esl_status_t) esl_event_create_subclass(esl_event_t **event, esl_eve
|
||||
|
||||
(*event)->event_id = event_id;
|
||||
|
||||
esl_event_add_header_string(*event, ESL_STACK_BOTTOM, "Event-Name", esl_event_name((*event)->event_id));
|
||||
|
||||
if (subclass_name) {
|
||||
(*event)->subclass_name = DUP(subclass_name);
|
||||
esl_event_add_header_string(*event, ESL_STACK_BOTTOM, "Event-Subclass", subclass_name);
|
||||
}
|
||||
}
|
||||
|
||||
return ESL_SUCCESS;
|
||||
}
|
||||
|
@@ -163,7 +163,9 @@ ESLevent *ESLconnection::recvEvent()
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
last_event_obj = new ESLevent("server_disconnected");
|
||||
|
||||
return last_event_obj;
|
||||
}
|
||||
|
||||
ESLevent *ESLconnection::recvEventTimed(int ms)
|
||||
@@ -183,7 +185,8 @@ ESLevent *ESLconnection::recvEventTimed(int ms)
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
last_event_obj = new ESLevent("server_disconnected");
|
||||
return last_event_obj;
|
||||
}
|
||||
|
||||
int ESLconnection::filter(const char *header, const char *value)
|
||||
|
@@ -248,7 +248,8 @@ typedef int16_t esl_port_t;
|
||||
typedef enum {
|
||||
ESL_SUCCESS,
|
||||
ESL_FAIL,
|
||||
ESL_BREAK
|
||||
ESL_BREAK,
|
||||
ESL_DISCONNECTED
|
||||
} esl_status_t;
|
||||
|
||||
#include <esl_threadmutex.h>
|
||||
@@ -341,7 +342,15 @@ ESL_DECLARE(esl_status_t) esl_events(esl_handle_t *handle, esl_event_type_t etyp
|
||||
|
||||
#define esl_recv(_h) esl_recv_event(_h, NULL)
|
||||
#define esl_recv_timed(_h, _ms) esl_recv_event_timed(_h, _ms, NULL)
|
||||
#define esl_safe_strcasecmp(_s1, _s2) ((_s1) && (_s2)) ? strcasecmp((_s1), (_s2)) : 1
|
||||
|
||||
static __inline__ int esl_safe_strcasecmp(const char *s1, const char *s2)
|
||||
{
|
||||
if (!(s1 && s2)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return strcasecmp(s1, s2);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@@ -106,6 +106,8 @@ typedef enum {
|
||||
ESL_EVENT_GENERAL,
|
||||
ESL_EVENT_COMMAND,
|
||||
ESL_EVENT_SESSION_HEARTBEAT,
|
||||
ESL_EVENT_CLIENT_DISCONNECTED,
|
||||
ESL_EVENT_SERVER_DISCONNECTED,
|
||||
ESL_EVENT_ALL
|
||||
} esl_event_types_t;
|
||||
|
||||
|
Reference in New Issue
Block a user