提交 3c72e9f1 authored 作者: Anthony Minessale's avatar Anthony Minessale

add username and realm to sip db

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12785 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 bce5187d
...@@ -57,6 +57,7 @@ SWITCH_DECLARE(int) switch_isupper(int c); ...@@ -57,6 +57,7 @@ SWITCH_DECLARE(int) switch_isupper(int c);
SWITCH_DECLARE(int) switch_isxdigit(int c); SWITCH_DECLARE(int) switch_isxdigit(int c);
#define switch_goto_status(_status, _label) status = _status; goto _label #define switch_goto_status(_status, _label) status = _status; goto _label
#define switch_goto_int(_n, _i, _label) _n = _i; goto _label
#define switch_samples_per_packet(rate, interval) ((uint32_t)((float)rate / (1000.0f / (float)interval))) #define switch_samples_per_packet(rate, interval) ((uint32_t)((float)rate / (1000.0f / (float)interval)))
#define SWITCH_SMAX 32767 #define SWITCH_SMAX 32767
#define SWITCH_SMIN -32768 #define SWITCH_SMIN -32768
......
...@@ -677,8 +677,10 @@ void sofia_presence_mwi_event_handler(switch_event_t *event); ...@@ -677,8 +677,10 @@ void sofia_presence_mwi_event_handler(switch_event_t *event);
void sofia_presence_cancel(void); void sofia_presence_cancel(void);
switch_status_t config_sofia(int reload, char *profile_name); switch_status_t config_sofia(int reload, char *profile_name);
void sofia_reg_auth_challenge(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_regtype_t regtype, const char *realm, int stale); void sofia_reg_auth_challenge(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_regtype_t regtype, const char *realm, int stale);
auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization, sip_t const *sip, const char *regstr, auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization,
char *np, size_t nplen, char *ip, switch_event_t **v_event, long exptime, sofia_regtype_t regtype, const char *to_user); sip_t const *sip, const char *regstr, char *np, size_t nplen, char *ip, switch_event_t **v_event,
long exptime, sofia_regtype_t regtype, const char *to_user, switch_event_t **auth_params);
void sofia_reg_handle_sip_r_challenge(int status, void sofia_reg_handle_sip_r_challenge(int status,
char const *phrase, char const *phrase,
......
...@@ -406,7 +406,7 @@ void sofia_event_callback(nua_event_t event, ...@@ -406,7 +406,7 @@ void sofia_event_callback(nua_event_t event,
get_addr(network_ip, sizeof(network_ip), addrinfo->ai_addr, addrinfo->ai_addrlen); get_addr(network_ip, sizeof(network_ip), addrinfo->ai_addr, addrinfo->ai_addrlen);
auth_res = sofia_reg_parse_auth(profile, authorization, sip, auth_res = sofia_reg_parse_auth(profile, authorization, sip,
(char *) sip->sip_request->rq_method_name, tech_pvt->key, strlen(tech_pvt->key), network_ip, NULL, 0, (char *) sip->sip_request->rq_method_name, tech_pvt->key, strlen(tech_pvt->key), network_ip, NULL, 0,
REG_INVITE, NULL); REG_INVITE, NULL, NULL);
} }
if (auth_res != AUTH_OK) { if (auth_res != AUTH_OK) {
...@@ -579,6 +579,12 @@ void event_handler(switch_event_t *event) ...@@ -579,6 +579,12 @@ void event_handler(switch_event_t *event)
char *profile_name = switch_event_get_header(event, "orig-profile-name"); char *profile_name = switch_event_get_header(event, "orig-profile-name");
char *to_user = switch_event_get_header(event, "orig-to-user"); char *to_user = switch_event_get_header(event, "orig-to-user");
char *presence_hosts = switch_event_get_header(event, "presence-hosts"); char *presence_hosts = switch_event_get_header(event, "presence-hosts");
char *network_ip = switch_event_get_header(event, "network-ip");
char *network_port = switch_event_get_header(event, "network-port");
char *username = switch_event_get_header(event, "username");
char *realm = switch_event_get_header(event, "realm");
sofia_profile_t *profile = NULL; sofia_profile_t *profile = NULL;
char guess_ip4[256]; char guess_ip4[256];
...@@ -606,10 +612,11 @@ void event_handler(switch_event_t *event) ...@@ -606,10 +612,11 @@ void event_handler(switch_event_t *event)
switch_find_local_ip(guess_ip4, sizeof(guess_ip4), AF_INET); switch_find_local_ip(guess_ip4, sizeof(guess_ip4), AF_INET);
sql = switch_mprintf("insert into sip_registrations " sql = switch_mprintf("insert into sip_registrations "
"(call_id,sip_user,sip_host,presence_hosts,contact,status,rpid,expires,user_agent,server_user,server_host,profile_name,hostname) " "(call_id,sip_user,sip_host,presence_hosts,contact,status,rpid,expires,"
"values ('%q', '%q','%q','%q','Registered', '%q', %ld, '%q', '%q', '%q','%q','%q')", "user_agent,server_user,server_host,profile_name,hostname,network_ip,network_port,sip_username,sip_realm) "
"values ('%q', '%q','%q','%q','Registered', '%q', %ld, '%q', '%q', '%q','%q','%q','%q','%q','%q','%q')",
call_id, from_user, from_host, presence_hosts, contact_str, rpid, expires, user_agent, to_user, guess_ip4, call_id, from_user, from_host, presence_hosts, contact_str, rpid, expires, user_agent, to_user, guess_ip4,
profile_name,mod_sofia_globals.hostname); profile_name,mod_sofia_globals.hostname, network_ip, network_port, username, realm);
if (sql) { if (sql) {
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE); sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
......
...@@ -3191,7 +3191,9 @@ int sofia_glue_init_sql(sofia_profile_t *profile) ...@@ -3191,7 +3191,9 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
" profile_name VARCHAR(255),\n" " profile_name VARCHAR(255),\n"
" hostname VARCHAR(255),\n" " hostname VARCHAR(255),\n"
" network_ip VARCHAR(255),\n" " network_ip VARCHAR(255),\n"
" network_port VARCHAR(6)\n" " network_port VARCHAR(6),\n"
" sip_username VARCHAR(255),\n"
" sip_realm VARCHAR(255)\n"
");\n"; ");\n";
...@@ -3289,6 +3291,8 @@ int sofia_glue_init_sql(sofia_profile_t *profile) ...@@ -3289,6 +3291,8 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
"create index sr_status on sip_registrations (status)", "create index sr_status on sip_registrations (status)",
"create index sr_network_ip on sip_registrations (network_ip)", "create index sr_network_ip on sip_registrations (network_ip)",
"create index sr_network_port on sip_registrations (network_port)", "create index sr_network_port on sip_registrations (network_port)",
"create index sr_sip_username on sip_registrations (sip_username)",
"create index sr_sip_realm on sip_registrations (sip_realm)",
"create index ss_call_id on sip_subscriptions (call_id)", "create index ss_call_id on sip_subscriptions (call_id)",
"create index ss_hostname on sip_subscriptions (hostname)", "create index ss_hostname on sip_subscriptions (hostname)",
"create index ss_sip_user on sip_subscriptions (sip_user)", "create index ss_sip_user on sip_subscriptions (sip_user)",
...@@ -3329,7 +3333,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile) ...@@ -3329,7 +3333,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
test_sql = switch_mprintf("delete from sip_registrations where (contact like '%%TCP%%' " test_sql = switch_mprintf("delete from sip_registrations where (contact like '%%TCP%%' "
"or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q' " "or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q' "
"and network_ip!='-1' and network_port!='-1'", "and network_ip!='-1' and network_port!='-1' and sip_username != '-1'",
mod_sofia_globals.hostname); mod_sofia_globals.hostname);
if (switch_odbc_handle_exec(profile->master_odbc, test_sql, NULL) != SWITCH_ODBC_SUCCESS) { if (switch_odbc_handle_exec(profile->master_odbc, test_sql, NULL) != SWITCH_ODBC_SUCCESS) {
...@@ -3401,7 +3405,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile) ...@@ -3401,7 +3405,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
test_sql = switch_mprintf("delete from sip_registrations where (contact like '%%TCP%%' " test_sql = switch_mprintf("delete from sip_registrations where (contact like '%%TCP%%' "
"or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q' " "or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q' "
"and network_ip!='-1' and network_port!='-1'", "and network_ip!='-1' and network_port!='-1' and sip_username != '-1'",
mod_sofia_globals.hostname); mod_sofia_globals.hostname);
switch_core_db_test_reactive(profile->master_db, test_sql, "DROP TABLE sip_registrations", reg_sql); switch_core_db_test_reactive(profile->master_db, test_sql, "DROP TABLE sip_registrations", reg_sql);
...@@ -3465,6 +3469,9 @@ int sofia_glue_init_sql(sofia_profile_t *profile) ...@@ -3465,6 +3469,9 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
switch_core_db_exec(profile->master_db, "create index if not exists sr_status on sip_registrations (status)", NULL, NULL, NULL); switch_core_db_exec(profile->master_db, "create index if not exists sr_status on sip_registrations (status)", NULL, NULL, NULL);
switch_core_db_exec(profile->master_db, "create index if not exists sr_network_ip on sip_registrations (network_ip)", NULL, NULL, NULL); switch_core_db_exec(profile->master_db, "create index if not exists sr_network_ip on sip_registrations (network_ip)", NULL, NULL, NULL);
switch_core_db_exec(profile->master_db, "create index if not exists sr_network_port on sip_registrations (network_port)", NULL, NULL, NULL); switch_core_db_exec(profile->master_db, "create index if not exists sr_network_port on sip_registrations (network_port)", NULL, NULL, NULL);
switch_core_db_exec(profile->master_db, "create index if not exists sr_sip_username on sip_registrations (sip_username)", NULL, NULL, NULL);
switch_core_db_exec(profile->master_db, "create index if not exists sr_sip_realm on sip_registrations (sip_realm)", NULL, NULL, NULL);
switch_core_db_exec(profile->master_db, "create index if not exists ss_call_id on sip_subscriptions (call_id)", NULL, NULL, NULL); switch_core_db_exec(profile->master_db, "create index if not exists ss_call_id on sip_subscriptions (call_id)", NULL, NULL, NULL);
switch_core_db_exec(profile->master_db, "create index if not exists ss_hostname on sip_subscriptions (hostname)", NULL, NULL, NULL); switch_core_db_exec(profile->master_db, "create index if not exists ss_hostname on sip_subscriptions (hostname)", NULL, NULL, NULL);
......
...@@ -699,6 +699,8 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand ...@@ -699,6 +699,8 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
char received_data[128] = ""; char received_data[128] = "";
char *path_val = NULL; char *path_val = NULL;
su_addrinfo_t *my_addrinfo = msg_addrinfo(nua_current_request(nua)); su_addrinfo_t *my_addrinfo = msg_addrinfo(nua_current_request(nua));
switch_event_t *auth_params = NULL;
int r = 0;
/* all callers must confirm that sip, sip->sip_request and sip->sip_contact are not NULL */ /* all callers must confirm that sip, sip->sip_request and sip->sip_contact are not NULL */
switch_assert(sip != NULL && sip->sip_contact != NULL && sip->sip_request != NULL); switch_assert(sip != NULL && sip->sip_contact != NULL && sip->sip_request != NULL);
...@@ -723,7 +725,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand ...@@ -723,7 +725,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
if (!to_user || !to_host) { if (!to_user || !to_host) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can not do authorization without a complete from header\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can not do authorization without a complete from header\n");
nua_respond(nh, SIP_401_UNAUTHORIZED, NUTAG_WITH_THIS(nua), TAG_END()); nua_respond(nh, SIP_401_UNAUTHORIZED, NUTAG_WITH_THIS(nua), TAG_END());
return 1; switch_goto_int(r, 1, end);
} }
if (!reg_host) { if (!reg_host) {
...@@ -840,7 +842,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand ...@@ -840,7 +842,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
if (authorization) { if (authorization) {
char *v_contact_str; char *v_contact_str;
if ((auth_res = sofia_reg_parse_auth(profile, authorization, sip, sip->sip_request->rq_method_name, 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_STALE) { key, keylen, network_ip, v_event, exptime, regtype, to_user, &auth_params)) == AUTH_STALE) {
stale = 1; stale = 1;
} }
...@@ -913,7 +915,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand ...@@ -913,7 +915,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
} else { } else {
nua_respond(nh, SIP_401_UNAUTHORIZED, NUTAG_WITH_THIS(nua), TAG_END()); nua_respond(nh, SIP_401_UNAUTHORIZED, NUTAG_WITH_THIS(nua), TAG_END());
} }
return 1; switch_goto_int(r, 1, end);
} }
} }
...@@ -934,12 +936,12 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand ...@@ -934,12 +936,12 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
} else { } else {
sofia_reg_auth_challenge(nua, profile, nh, regtype, realm, stale); sofia_reg_auth_challenge(nua, profile, nh, regtype, realm, stale);
} }
return 1; switch_goto_int(r, 1, end);
} }
reg: reg:
if (regtype != REG_REGISTER) { if (regtype != REG_REGISTER) {
return 0; switch_goto_int(r, 0, end);
} }
call_id = sip->sip_call_id->i_id; call_id = sip->sip_call_id->i_id;
...@@ -959,6 +961,13 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand ...@@ -959,6 +961,13 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
if (exptime) { if (exptime) {
const char *agent = "dunno"; const char *agent = "dunno";
char guess_ip4[256]; char guess_ip4[256];
const char *username = "unknown";
const char *realm = reg_host;
if (auth_params) {
username = switch_event_get_header(auth_params, "sip_auth_username");
realm = switch_event_get_header(auth_params, "sip_auth_realm");
}
if (sip->sip_user_agent) { if (sip->sip_user_agent) {
agent = sip->sip_user_agent->g_string; agent = sip->sip_user_agent->g_string;
...@@ -979,11 +988,12 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand ...@@ -979,11 +988,12 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
switch_find_local_ip(guess_ip4, sizeof(guess_ip4), AF_INET); switch_find_local_ip(guess_ip4, sizeof(guess_ip4), AF_INET);
sql = switch_mprintf("insert into sip_registrations " sql = switch_mprintf("insert into sip_registrations "
"(call_id,sip_user,sip_host,presence_hosts,contact,status,rpid,expires,user_agent,server_user,server_host,profile_name,hostname,network_ip,network_port) " "(call_id,sip_user,sip_host,presence_hosts,contact,status,rpid,expires,"
"values ('%q','%q', '%q','%q','%q','%q', '%q', %ld, '%q', '%q', '%q', '%q', '%q', '%q', '%q')", "user_agent,server_user,server_host,profile_name,hostname,network_ip,network_port,sip_username,sip_realm) "
"values ('%q','%q', '%q','%q','%q','%q', '%q', %ld, '%q', '%q', '%q', '%q', '%q', '%q', '%q','%q','%q')",
call_id, to_user, reg_host, profile->presence_hosts ? profile->presence_hosts : reg_host, call_id, to_user, reg_host, profile->presence_hosts ? profile->presence_hosts : reg_host,
contact_str, reg_desc, rpid, (long) switch_epoch_time_now(NULL) + (long) exptime * 2, contact_str, reg_desc, rpid, (long) switch_epoch_time_now(NULL) + (long) exptime * 2,
agent, from_user, guess_ip4, profile->name, mod_sofia_globals.hostname, network_ip, network_port_c); agent, from_user, guess_ip4, profile->name, mod_sofia_globals.hostname, network_ip, network_port_c, username, realm);
if (sql) { if (sql) {
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE); sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
...@@ -1006,6 +1016,8 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand ...@@ -1006,6 +1016,8 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "to-host", from_host); 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-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, "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_fire(&s_event); switch_event_fire(&s_event);
} }
...@@ -1154,10 +1166,17 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand ...@@ -1154,10 +1166,17 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
} }
} }
return 1; switch_goto_int(r, 1, end);
} }
return 0;
end:
if (auth_params) {
switch_event_destroy(&auth_params);
}
return r;
} }
...@@ -1458,8 +1477,19 @@ void sofia_reg_handle_sip_r_challenge(int status, ...@@ -1458,8 +1477,19 @@ void sofia_reg_handle_sip_r_challenge(int status,
} }
auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization, sip_t const *sip, const char *regstr, auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
char *np, size_t nplen, char *ip, switch_event_t **v_event, long exptime, sofia_regtype_t regtype, const char *to_user) sip_authorization_t const *authorization,
sip_t const *sip,
const char *regstr,
char *np,
size_t nplen,
char *ip,
switch_event_t **v_event,
long exptime,
sofia_regtype_t
regtype,
const char *to_user,
switch_event_t **auth_params)
{ {
int indexnum; int indexnum;
const char *cur; const char *cur;
...@@ -1600,6 +1630,10 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co ...@@ -1600,6 +1630,10 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_method", (sip && sip->sip_request) ? sip->sip_request->rq_method_name : NULL); switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_method", (sip && sip->sip_request) ? sip->sip_request->rq_method_name : NULL);
if (auth_params) {
switch_event_dup(auth_params, params);
}
if (!switch_strlen_zero(profile->reg_domain)) { if (!switch_strlen_zero(profile->reg_domain)) {
domain_name = profile->reg_domain; domain_name = profile->reg_domain;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论