<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][15260] </title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=15260">15260</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2009-10-28 11:55:29 -0500 (Wed, 28 Oct 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>use nonce count with registration</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiamod_sofiah">freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiasofia_gluec">freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiasofia_regc">freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcmodendpointsmod_sofiamod_sofiah"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (15259 => 15260)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h        2009-10-28 14:55:33 UTC (rev 15259)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h        2009-10-28 16:55:29 UTC (rev 15260)
</span><span class="lines">@@ -37,7 +37,7 @@
</span><span class="cx"> /*Defines etc..*/
</span><span class="cx"> /*************************************************************************************************************************************************************/
</span><span class="cx"> #define MANUAL_BYE
</span><del>-
</del><ins>+#define DEFAULT_NONCE_TTL 60
</ins><span class="cx"> #define IREG_SECONDS 30
</span><span class="cx"> #define GATEWAY_SECONDS 1
</span><span class="cx"> #define SOFIA_QUEUE_SIZE 50000
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofia_gluec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (15259 => 15260)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c        2009-10-28 14:55:33 UTC (rev 15259)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c        2009-10-28 16:55:29 UTC (rev 15260)
</span><span class="lines">@@ -3685,7 +3685,8 @@
</span><span class="cx">                 " nonce VARCHAR(255),\n"
</span><span class="cx">                 " expires INTEGER,"
</span><span class="cx">                 " profile_name VARCHAR(255),\n"
</span><del>-                " hostname VARCHAR(255)\n"
</del><ins>+                " hostname VARCHAR(255),\n"
+                " last_nc INTEGER\n"
</ins><span class="cx">                 ");\n";
</span><span class="cx">
</span><span class="cx">         /* should we move this glue to sofia_sla or keep it here where all db init happens? XXX MTK */
</span><span class="lines">@@ -3799,7 +3800,7 @@
</span><span class="cx">                 }
</span><span class="cx">
</span><span class="cx">                 free(test_sql);
</span><del>-                test_sql = switch_mprintf("delete from sip_authentication where hostname='%q'", mod_sofia_globals.hostname);
</del><ins>+                test_sql = switch_mprintf("delete from sip_authentication where hostname='%q' and last_nc >= 0", mod_sofia_globals.hostname);
</ins><span class="cx">
</span><span class="cx">                 if (switch_odbc_handle_exec(profile->master_odbc, test_sql, NULL) != SWITCH_ODBC_SUCCESS) {
</span><span class="cx">                         switch_odbc_handle_exec(profile->master_odbc, "DROP TABLE sip_authentication", NULL);
</span><span class="lines">@@ -3857,7 +3858,7 @@
</span><span class="cx">                 switch_core_db_test_reactive(profile->master_db, test_sql, "DROP TABLE sip_presence", pres_sql);
</span><span class="cx">                 free(test_sql);
</span><span class="cx">
</span><del>-                test_sql = switch_mprintf("delete from sip_authentication where hostname='%q'", mod_sofia_globals.hostname);
</del><ins>+                test_sql = switch_mprintf("delete from sip_authentication where hostname='%q' and last_nc >= 0", mod_sofia_globals.hostname);
</ins><span class="cx">                 switch_core_db_test_reactive(profile->master_db, test_sql, "DROP TABLE sip_authentication", auth_sql);
</span><span class="cx">                 free(test_sql);
</span><span class="cx">
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofia_regc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (15259 => 15260)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c        2009-10-28 14:55:33 UTC (rev 15259)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c        2009-10-28 16:55:29 UTC (rev 15260)
</span><span class="lines">@@ -681,8 +681,10 @@
</span><span class="cx">         switch_uuid_get(&uuid);
</span><span class="cx">         switch_uuid_format(uuid_str, &uuid);
</span><span class="cx">
</span><del>-        sql = switch_mprintf("insert into sip_authentication (nonce,expires,profile_name,hostname) "
-                                                 "values('%q', %ld, '%q', '%q')", uuid_str, switch_epoch_time_now(NULL) + profile->nonce_ttl, profile->name, mod_sofia_globals.hostname);
</del><ins>+        sql = switch_mprintf("insert into sip_authentication (nonce,expires,profile_name,hostname, last_nc) "
+                                                 "values('%q', %ld, '%q', '%q', 0)", uuid_str,
+                                                 switch_epoch_time_now(NULL) + (profile->nonce_ttl ? profile->nonce_ttl : DEFAULT_NONCE_TTL),
+                                                 profile->name, mod_sofia_globals.hostname);
</ins><span class="cx">         switch_assert(sql != NULL);
</span><span class="cx">         sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
</span><span class="cx">         switch_safe_free(sql);
</span><span class="lines">@@ -1567,6 +1569,25 @@
</span><span class="cx">
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static unsigned long get_nc(const char *nc, sip_t const *sip)
+{
+        unsigned long x;
+        const char *ua = NULL;
+
+        if (sip->sip_user_agent) {
+                ua = sip->sip_user_agent->g_string;
+        }
+
+        /* sigh, polycom sends nc in base-10 rather than spec which says base-16*/
+        if (ua && switch_stristr("polycom", ua)) {
+                x = strtoul(nc, 0, 10);
+        } else {
+                x = strtoul(nc, 0, 16);
+        }
+
+        return x;
+}
+
</ins><span class="cx"> auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
</span><span class="cx">                                                                 sip_authorization_t const *authorization,
</span><span class="cx">                                                                 sip_t const *sip,
</span><span class="lines">@@ -1658,7 +1679,15 @@
</span><span class="cx">
</span><span class="cx">         if (zstr(np)) {
</span><span class="cx">                 first = 1;
</span><del>-                sql = switch_mprintf("select nonce from sip_authentication where nonce='%q'", nonce);
</del><ins>+                if (nc) {
+                        unsigned long x;
+
+                        x = get_nc(nc, sip);
+                        sql = switch_mprintf("select nonce from sip_authentication where nonce='%q' and last_nc + 1 >= %lu", nonce, x);
+                } else {
+                        sql = switch_mprintf("select nonce from sip_authentication where nonce='%q'", nonce);
+                }
+
</ins><span class="cx">                 switch_assert(sql != NULL);
</span><span class="cx">                 if (!sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, np, nplen)) {
</span><span class="cx">                         free(sql);
</span><span class="lines">@@ -1885,15 +1914,15 @@
</span><span class="cx">                 input2 = switch_mprintf("%s:%s:%s", a1_hash, nonce, uridigest);
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        switch_assert(input2);
</del><ins>+        if (input2) {
+                memset(&ctx, 0, sizeof(ctx));
+                su_md5_init(&ctx);
+                su_md5_strupdate(&ctx, input2);
+                su_md5_hexdigest(&ctx, bigdigest);
+                su_md5_deinit(&ctx);
+        }
</ins><span class="cx">
</span><del>-        memset(&ctx, 0, sizeof(ctx));
-        su_md5_init(&ctx);
-        su_md5_strupdate(&ctx, input2);
-        su_md5_hexdigest(&ctx, bigdigest);
-        su_md5_deinit(&ctx);
-
-        if (!strcasecmp(bigdigest, response)) {
</del><ins>+        if (input2 && !strcasecmp(bigdigest, response)) {
</ins><span class="cx">                 ret = AUTH_OK;
</span><span class="cx">         } else {
</span><span class="cx">                 if ((profile->ndlb & PFLAG_NDLB_BROKEN_AUTH_HASH) && strcasecmp(regstr, "REGISTER") && strcasecmp(regstr, "INVITE")) {
</span><span class="lines">@@ -2047,6 +2076,22 @@
</span><span class="cx">         }
</span><span class="cx"> end:
</span><span class="cx">
</span><ins>+
+        if (nc && cnonce && qop) {
+                unsigned long x;
+                char *sql;
+
+                x = get_nc(nc, sip);
+                input2 = switch_mprintf("%s:%s:%s:%s:%s:%s", a1_hash, nonce, nc, cnonce, qop, uridigest);
+
+                sql = switch_mprintf("update sip_authentication set expires='%ld',last_nc=%lu where nonce='%s'",
+                                                         switch_epoch_time_now(NULL) + (profile->nonce_ttl ? profile->nonce_ttl : exptime + 10), x, nonce);
+
+                switch_assert(sql != NULL);
+                sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
+                switch_safe_free(sql);
+        }
+
</ins><span class="cx">         switch_event_destroy(&params);
</span><span class="cx">
</span><span class="cx">         if (xml) {
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>