From 99ada6bdbafda2dc1bd797041dff20c7c5e32f3e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 27 Oct 2010 12:00:30 -0500 Subject: [PATCH] add events --- src/mod/endpoints/mod_sofia/mod_sofia.h | 2 ++ src/mod/endpoints/mod_sofia/sofia_reg.c | 43 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index baff8e95e2..0cd3b38871 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -76,6 +76,8 @@ typedef struct private_object private_object_t; #define SOFIA_SESSION_TIMEOUT "sofia_session_timeout" #define MY_EVENT_REGISTER "sofia::register" +#define MY_EVENT_PRE_REGISTER "sofia::pre_register" +#define MY_EVENT_REGISTER_ATTEMPT "sofia::register_attempt" #define MY_EVENT_UNREGISTER "sofia::unregister" #define MY_EVENT_EXPIRE "sofia::expire" #define MY_EVENT_GATEWAY_STATE "sofia::gateway_state" diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 51ce56faec..e8fdcd2489 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -993,11 +993,37 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand if (authorization) { char *v_contact_str; + const char *username = "unknown"; + const char *realm = reg_host; if ((auth_res = sofia_reg_parse_auth(profile, authorization, sip, sip->sip_request->rq_method_name, key, keylen, network_ip, v_event, exptime, regtype, to_user, &auth_params, ®_count)) == AUTH_STALE) { stale = 1; } + + if (auth_params) { + username = switch_event_get_header(auth_params, "sip_auth_username"); + realm = switch_event_get_header(auth_params, "sip_auth_realm"); + } + if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_REGISTER_ATTEMPT) == SWITCH_STATUS_SUCCESS) { + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "profile-name", profile->name); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "from-user", to_user); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "from-host", reg_host); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "contact", contact_str); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "call-id", call_id); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "rpid", rpid); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "status", reg_desc); + switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "expires", "%ld", (long) exptime); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "to-user", from_user); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "to-host", from_host); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "network-ip", network_ip); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "network-port", network_port_c); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "username", username); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "realm", realm); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "user-agent", agent); + switch_event_fire(&s_event); + } + if (exptime && v_event && *v_event) { char *exp_var; char *allow_multireg = NULL; @@ -1101,6 +1127,23 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand if (!authorization || stale) { const char *realm = profile->challenge_realm; + if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_PRE_REGISTER) == SWITCH_STATUS_SUCCESS) { + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "profile-name", profile->name); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "from-user", to_user); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "from-host", reg_host); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "contact", contact_str); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "call-id", call_id); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "rpid", rpid); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "status", reg_desc); + switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "expires", "%ld", (long) exptime); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "to-user", from_user); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "to-host", from_host); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "network-ip", network_ip); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "network-port", network_port_c); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "user-agent", agent); + switch_event_fire(&s_event); + } + if (zstr(realm) || !strcasecmp(realm, "auto_to")) { realm = to_host; } else if (!strcasecmp(realm, "auto_from")) {