@@ -805,6 +805,23 @@ static void check_permissions(jsock_t *jsock, switch_xml_t x_user, cJSON *params
805
805
806
806
}
807
807
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
+
808
825
static switch_bool_t check_auth (jsock_t * jsock , cJSON * params , int * code , char * message , switch_size_t mlen )
809
826
{
810
827
switch_bool_t r = SWITCH_FALSE ;
@@ -827,6 +844,7 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
827
844
if (zstr (passwd )) {
828
845
* code = CODE_AUTH_FAILED ;
829
846
switch_snprintf (message , mlen , "Missing passwd" );
847
+ login_fire_custom_event (jsock , params , 0 , "Missing passwd" );
830
848
goto end ;
831
849
}
832
850
@@ -835,6 +853,7 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
835
853
if (!(r = !strcmp (passwd , jsock -> profile -> root_passwd ))) {
836
854
* code = CODE_AUTH_FAILED ;
837
855
switch_snprintf (message , mlen , "Authentication Failure" );
856
+ login_fire_custom_event (jsock , params , 0 , "Authentication Failure" );
838
857
}
839
858
840
859
} else if (!zstr (jsock -> profile -> userauth )) {
@@ -868,6 +887,7 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
868
887
if (switch_xml_locate_user_merged ("id" , id , domain , NULL , & x_user , req_params ) != SWITCH_STATUS_SUCCESS && !jsock -> profile -> blind_reg ) {
869
888
* code = CODE_AUTH_FAILED ;
870
889
switch_snprintf (message , mlen , "Login Incorrect" );
890
+ login_fire_custom_event (jsock , params , 0 , "Login Incorrect" );
871
891
} else {
872
892
switch_xml_t x_param , x_params ;
873
893
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 *
924
944
* code = CODE_AUTH_FAILED ;
925
945
switch_snprintf (message , mlen , "Authentication Failure" );
926
946
jsock -> uid = NULL ;
947
+ login_fire_custom_event (jsock , params , 0 , "Authentication Failure" );
927
948
} else {
928
949
r = SWITCH_TRUE ;
929
950
check_permissions (jsock , x_user , params );
@@ -1345,6 +1366,8 @@ static void jsock_flush(jsock_t *jsock)
1345
1366
1346
1367
static void * SWITCH_THREAD_FUNC client_thread (switch_thread_t * thread , void * obj )
1347
1368
{
1369
+ switch_event_t * s_event ;
1370
+
1348
1371
jsock_t * jsock = (jsock_t * ) obj ;
1349
1372
1350
1373
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
1380
1403
jsock_flush (jsock );
1381
1404
1382
1405
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
+ }
1383
1411
switch_thread_rwlock_wrlock (jsock -> rwlock );
1384
1412
switch_log_printf (SWITCH_CHANNEL_LOG , SWITCH_LOG_INFO , "%s Thread ended\n" , jsock -> name );
1385
1413
switch_thread_rwlock_unlock (jsock -> rwlock );
@@ -3028,6 +3056,8 @@ static switch_bool_t login_func(const char *method, cJSON *params, jsock_t *jsoc
3028
3056
* response = cJSON_CreateObject ();
3029
3057
cJSON_AddItemToObject (* response , "message" , cJSON_CreateString ("logged in" ));
3030
3058
3059
+ login_fire_custom_event (jsock , params , 1 , "Logged in" );
3060
+
3031
3061
return SWITCH_TRUE ;
3032
3062
}
3033
3063
@@ -3142,6 +3172,7 @@ static int start_jsock(verto_profile_t *profile, int sock)
3142
3172
jsock_type_t ptype = PTYPE_CLIENT ;
3143
3173
switch_thread_data_t * td ;
3144
3174
switch_memory_pool_t * pool ;
3175
+ switch_event_t * s_event ;
3145
3176
3146
3177
switch_core_new_memory_pool (& pool );
3147
3178
@@ -3173,7 +3204,12 @@ static int start_jsock(verto_profile_t *profile, int sock)
3173
3204
3174
3205
jsock -> ptype = ptype ;
3175
3206
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
+ }
3177
3213
3178
3214
/* no nagle please */
3179
3215
setsockopt (jsock -> client_socket , IPPROTO_TCP , TCP_NODELAY , (char * )& flag , sizeof (flag ));
0 commit comments