Skip to content

Commit c5cd981

Browse files
committedAug 1, 2014
FS-6690 #resolve
1 parent fb27451 commit c5cd981

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
 

‎src/mod/endpoints/mod_verto/mod_verto.c

+37-1
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,23 @@ static void check_permissions(jsock_t *jsock, switch_xml_t x_user, cJSON *params
805805

806806
}
807807

808+
static void login_fire_custom_event(jsock_t *jsock, cJSON *params, int success, const char *result_txt)
809+
{
810+
switch_event_t *s_event;
811+
812+
if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_LOGIN) == SWITCH_STATUS_SUCCESS) {
813+
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "verto_profile_name", jsock->profile->name);
814+
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "verto_client_address", jsock->name);
815+
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "verto_login", cJSON_GetObjectCstr(params, "login"));
816+
if (success) {
817+
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "verto_sessid", cJSON_GetObjectCstr(params, "sessid"));
818+
}
819+
switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "verto_success", "%d", success);
820+
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "verto_result_txt", result_txt);
821+
switch_event_fire(&s_event);
822+
}
823+
}
824+
808825
static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *message, switch_size_t mlen)
809826
{
810827
switch_bool_t r = SWITCH_FALSE;
@@ -827,6 +844,7 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
827844
if (zstr(passwd)) {
828845
*code = CODE_AUTH_FAILED;
829846
switch_snprintf(message, mlen, "Missing passwd");
847+
login_fire_custom_event(jsock, params, 0, "Missing passwd");
830848
goto end;
831849
}
832850

@@ -835,6 +853,7 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
835853
if (!(r = !strcmp(passwd, jsock->profile->root_passwd))) {
836854
*code = CODE_AUTH_FAILED;
837855
switch_snprintf(message, mlen, "Authentication Failure");
856+
login_fire_custom_event(jsock, params, 0, "Authentication Failure");
838857
}
839858

840859
} else if (!zstr(jsock->profile->userauth)) {
@@ -868,6 +887,7 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
868887
if (switch_xml_locate_user_merged("id", id, domain, NULL, &x_user, req_params) != SWITCH_STATUS_SUCCESS && !jsock->profile->blind_reg) {
869888
*code = CODE_AUTH_FAILED;
870889
switch_snprintf(message, mlen, "Login Incorrect");
890+
login_fire_custom_event(jsock, params, 0, "Login Incorrect");
871891
} else {
872892
switch_xml_t x_param, x_params;
873893
const char *use_passwd = NULL, *verto_context = NULL, *verto_dialplan = NULL;
@@ -924,6 +944,7 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
924944
*code = CODE_AUTH_FAILED;
925945
switch_snprintf(message, mlen, "Authentication Failure");
926946
jsock->uid = NULL;
947+
login_fire_custom_event(jsock, params, 0, "Authentication Failure");
927948
} else {
928949
r = SWITCH_TRUE;
929950
check_permissions(jsock, x_user, params);
@@ -1345,6 +1366,8 @@ static void jsock_flush(jsock_t *jsock)
13451366

13461367
static void *SWITCH_THREAD_FUNC client_thread(switch_thread_t *thread, void *obj)
13471368
{
1369+
switch_event_t *s_event;
1370+
13481371
jsock_t *jsock = (jsock_t *) obj;
13491372

13501373
switch_event_create(&jsock->params, SWITCH_EVENT_CHANNEL_DATA);
@@ -1380,6 +1403,11 @@ static void *SWITCH_THREAD_FUNC client_thread(switch_thread_t *thread, void *obj
13801403
jsock_flush(jsock);
13811404

13821405
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s Ending client thread.\n", jsock->name);
1406+
if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_CLIENT_DISCONNECT) == SWITCH_STATUS_SUCCESS) {
1407+
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "verto_profile_name", jsock->profile->name);
1408+
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "verto_client_address", jsock->name);
1409+
switch_event_fire(&s_event);
1410+
}
13831411
switch_thread_rwlock_wrlock(jsock->rwlock);
13841412
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s Thread ended\n", jsock->name);
13851413
switch_thread_rwlock_unlock(jsock->rwlock);
@@ -3028,6 +3056,8 @@ static switch_bool_t login_func(const char *method, cJSON *params, jsock_t *jsoc
30283056
*response = cJSON_CreateObject();
30293057
cJSON_AddItemToObject(*response, "message", cJSON_CreateString("logged in"));
30303058

3059+
login_fire_custom_event(jsock, params, 1, "Logged in");
3060+
30313061
return SWITCH_TRUE;
30323062
}
30333063

@@ -3142,6 +3172,7 @@ static int start_jsock(verto_profile_t *profile, int sock)
31423172
jsock_type_t ptype = PTYPE_CLIENT;
31433173
switch_thread_data_t *td;
31443174
switch_memory_pool_t *pool;
3175+
switch_event_t *s_event;
31453176

31463177
switch_core_new_memory_pool(&pool);
31473178

@@ -3173,7 +3204,12 @@ static int start_jsock(verto_profile_t *profile, int sock)
31733204

31743205
jsock->ptype = ptype;
31753206

3176-
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s Client Connect.\n", jsock->name);
3207+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s Client Connect.\n", jsock->name);
3208+
if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_CLIENT_CONNECT) == SWITCH_STATUS_SUCCESS) {
3209+
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "verto_profile_name", profile->name);
3210+
switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "verto_client_address", "%s:%d", inet_ntoa(jsock->remote_addr.sin_addr), ntohs(jsock->remote_addr.sin_port));
3211+
switch_event_fire(&s_event);
3212+
}
31773213

31783214
/* no nagle please */
31793215
setsockopt(jsock->client_socket, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag));

‎src/mod/endpoints/mod_verto/mod_verto.h

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
#define CODE_AUTH_FAILED -32001
6868
#define CODE_SESSION_ERROR -32002
6969

70+
#define MY_EVENT_CLIENT_CONNECT "verto::client_connect"
71+
#define MY_EVENT_CLIENT_DISCONNECT "verto::client_disconnect"
72+
#define MY_EVENT_LOGIN "verto::login"
7073

7174
typedef enum {
7275
PTYPE_CLIENT = (1 << 0),

0 commit comments

Comments
 (0)
Please sign in to comment.