<!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][15331] </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=15331">15331</a></dd>
<dt>Author</dt> <dd>rupa</dd>
<dt>Date</dt> <dd>2009-11-03 11:57:44 -0600 (Tue, 03 Nov 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>fix minor bugs
make whitepages work if regular url not set (oops)
channel var set for area
ignore &quot;UNKNOWN&quot; and &quot;UNAVAILABLE&quot; from api</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcmodapplicationsmod_cidlookupmod_cidlookupc">freeswitch/trunk/src/mod/applications/mod_cidlookup/mod_cidlookup.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcmodapplicationsmod_cidlookupmod_cidlookupc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/applications/mod_cidlookup/mod_cidlookup.c (15330 => 15331)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/applications/mod_cidlookup/mod_cidlookup.c        2009-11-03 16:52:22 UTC (rev 15330)
+++ freeswitch/trunk/src/mod/applications/mod_cidlookup/mod_cidlookup.c        2009-11-03 17:57:44 UTC (rev 15331)
</span><span class="lines">@@ -151,7 +151,7 @@
</span><span class="cx">         SWITCH_CONFIG_ITEM(&quot;cache&quot;, SWITCH_CONFIG_BOOL, CONFIG_RELOAD, &amp;globals.cache, SWITCH_FALSE, NULL, &quot;true|false&quot;, &quot;whether to cache via cidlookup&quot;),
</span><span class="cx">         SWITCH_CONFIG_ITEM(&quot;cache-expire&quot;, SWITCH_CONFIG_INT, CONFIG_RELOAD, &amp;globals.cache_expire, (void *)300, NULL, &quot;expire&quot;, &quot;seconds to preserve num-&gt;name cache&quot;),
</span><span class="cx">         SWITCH_CONFIG_ITEM_STRING_STRDUP(&quot;sql&quot;, CONFIG_RELOAD, &amp;globals.sql, &quot;&quot;, &quot;sql whre number=${caller_id_number}&quot;, &quot;SQL to run if overriding CID&quot;),
</span><del>-        SWITCH_CONFIG_ITEM_STRING_STRDUP(&quot;citystate-sql&quot;, CONFIG_RELOAD, &amp;globals.citystate_sql, &quot;&quot;, &quot;sql to look up city/state info&quot;, &quot;SQL to run if overriding CID&quot;),
</del><ins>+        SWITCH_CONFIG_ITEM_STRING_STRDUP(&quot;citystate-sql&quot;, CONFIG_RELOAD, &amp;globals.citystate_sql, NULL, &quot;sql to look up city/state info&quot;, &quot;SQL to run if overriding CID&quot;),
</ins><span class="cx">         SWITCH_CONFIG_ITEM_CALLBACK(&quot;odbc-dsn&quot;, SWITCH_CONFIG_STRING, CONFIG_RELOAD, &amp;globals.odbc_dsn, &quot;&quot;, config_callback_dsn, &amp;config_opt_dsn,
</span><span class="cx">                 &quot;db:user:passwd&quot;, &quot;Database to use.&quot;),
</span><span class="cx">         SWITCH_CONFIG_ITEM_END()
</span><span class="lines">@@ -328,14 +328,18 @@
</span><span class="cx">                         !zstr((char *)http_data.stream.data) &amp;&amp;
</span><span class="cx">                         strcmp(&quot; &quot;, http_data.stream.data) ) {
</span><span class="cx">                 
</span><del>-                name = switch_core_strdup(pool, http_data.stream.data);
</del><ins>+                /* don't return UNKNOWN */
+                if (strcmp(&quot;UNKNOWN&quot;, http_data.stream.data) ||
+                        strcmp(&quot;UNAVAILABLE&quot;, http_data.stream.data)) {
+                        name = switch_core_strdup(pool, http_data.stream.data);
+                }
</ins><span class="cx">         }
</span><span class="cx">         
</span><span class="cx">         switch_safe_free(http_data.stream.data);
</span><span class="cx">         return name;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static char *do_whitepages_lookup(switch_memory_pool_t *pool, switch_event_t *event, const char *num, switch_bool_t *areaonly)
</del><ins>+static char *do_whitepages_lookup(switch_memory_pool_t *pool, switch_event_t *event, const char *num, char **area)
</ins><span class="cx"> {
</span><span class="cx">         char *xml_s = NULL;
</span><span class="cx">         char *query = NULL;
</span><span class="lines">@@ -352,6 +356,8 @@
</span><span class="cx">                 goto done;
</span><span class="cx">         }
</span><span class="cx">         
</span><ins>+        switch_assert(area);
+        
</ins><span class="cx">         switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;whitepages-cid&quot;, num);
</span><span class="cx">         switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;whitepages-api-key&quot;, globals.whitepages_apikey);
</span><span class="cx">         
</span><span class="lines">@@ -365,20 +371,19 @@
</span><span class="cx">                 goto done;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        *areaonly = SWITCH_FALSE;
-        
</del><span class="cx">         /* try for bizname first */
</span><span class="cx">         node = switch_xml_get(xml, &quot;wp:listings&quot;, 0, &quot;wp:listing&quot;, 0, &quot;wp:business&quot;, 0, &quot;wp:businessname&quot;, -1);
</span><span class="cx">         if (node) {
</span><span class="cx">                 name = switch_core_strdup(pool, switch_xml_txt(node));
</span><del>-                goto done;
</del><ins>+                goto area;
</ins><span class="cx">         }
</span><span class="cx">         
</span><span class="cx">         node = switch_xml_get(xml, &quot;wp:listings&quot;, 0, &quot;wp:listing&quot;, 0, &quot;wp:displayname&quot;, -1);
</span><span class="cx">         if (node) {
</span><span class="cx">                 name = switch_core_strdup(pool, switch_xml_txt(node));
</span><del>-                goto done;
</del><span class="cx">         }
</span><ins>+
+area:
</ins><span class="cx">         
</span><span class="cx">         node = switch_xml_get(xml, &quot;wp:listings&quot;, 0, &quot;wp:listing&quot;, 0, &quot;wp:address&quot;, 0, &quot;wp:city&quot;, -1);
</span><span class="cx">         if (node) {
</span><span class="lines">@@ -391,8 +396,7 @@
</span><span class="cx">         }
</span><span class="cx">         
</span><span class="cx">         if (city || state) {
</span><del>-                *areaonly = SWITCH_TRUE;
-                name = switch_core_sprintf(pool, &quot;%s %s&quot;, city ? city : &quot;&quot;, state ? state : &quot;&quot;);
</del><ins>+                *area = switch_core_sprintf(pool, &quot;%s %s&quot;, city ? city : &quot;&quot;, state ? state : &quot;&quot;);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx"> done:
</span><span class="lines">@@ -404,7 +408,7 @@
</span><span class="cx">                 switch_xml_free(xml);
</span><span class="cx">         }
</span><span class="cx">         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, &quot;whitepages XML: %s\n&quot;, xml_s);
</span><del>-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, &quot;whitepages name: %s\n&quot;, name ? name : &quot;(null)&quot;);
</del><ins>+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, &quot;whitepages name: %s, area: %s\n&quot;, name ? name : &quot;(null)&quot;, *area ? *area : &quot;(null)&quot;);
</ins><span class="cx">         return name;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -435,63 +439,72 @@
</span><span class="cx">         char *area = NULL;
</span><span class="cx">         char *url_query = NULL;
</span><span class="cx">         char *src = NULL;
</span><del>-        switch_bool_t areaonly = SWITCH_FALSE;
-        
</del><ins>+
</ins><span class="cx">         number = string_digitsonly(pool, num);
</span><span class="cx">         switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;caller_id_number&quot;, number);
</span><span class="cx"> 
</span><span class="cx">         /* database always wins */
</span><span class="cx">         if (switch_odbc_available() &amp;&amp; globals.master_odbc &amp;&amp; globals.sql) {
</span><span class="cx">                 name = do_db_lookup(pool, event, number, globals.sql);
</span><del>-                src = &quot;database&quot;;
</del><ins>+                if (name) {
+                        src = &quot;database&quot;;
+                }
</ins><span class="cx">         }
</span><span class="cx"> 
</span><del>-        if (!name &amp;&amp; globals.url) {
</del><ins>+        if (!name &amp;&amp; (globals.url || globals.whitepages_apikey)) {
</ins><span class="cx">                 if (globals.cache) {
</span><span class="cx">                         name = check_cache(pool, number);
</span><del>-                        src = &quot;cache&quot;;
</del><ins>+                        if (name) {
+                                src = &quot;cache&quot;;
+                        }
</ins><span class="cx">                 }
</span><del>-                if (!skipurl &amp;&amp; !name) {
-                        name = do_whitepages_lookup(pool, event, number, &amp;areaonly);
-                        src = &quot;whitepages&quot;;
-                        if (areaonly) {
-                                if (!skipcitystate) {
-                                        area = name; /* preserve if we're not skipping city/state */
</del><ins>+                if (!skipurl &amp;&amp; !name &amp;&amp; globals.whitepages_apikey) {
+                        name = do_whitepages_lookup(pool, event, number, &amp;area);
+                        if (area || name) {
+                                src = &quot;whitepages&quot;;
+                        }
+                        if (name) {
+                                if (globals.cache) {
+                                        set_cache(pool, number, name);
</ins><span class="cx">                                 }
</span><del>-                                name = NULL; /* always clear out name */
</del><span class="cx">                         }
</span><del>-                        if (globals.cache &amp;&amp; name) {
-                                set_cache(pool, number, name);
-                        }
</del><span class="cx">                 }
</span><del>-                if (!skipurl &amp;&amp; !name) {
</del><ins>+                if (!skipurl &amp;&amp; !name &amp;&amp; globals.url) {
</ins><span class="cx">                         url_query = switch_event_expand_headers(event, globals.url);
</span><span class="cx">                         name = do_lookup_url(pool, event, url_query);
</span><del>-                        src = &quot;url&quot;;
</del><ins>+                        if (name) {
+                                src = &quot;url&quot;;
+                                if (globals.cache) {
+                                        set_cache(pool, number, name);
+                                }
+                        }
</ins><span class="cx">                         if (url_query != globals.url) {
</span><span class="cx">                                 switch_safe_free(url_query);
</span><span class="cx">                         }
</span><span class="cx">                         
</span><del>-                        /* store and use preserved area info */
-                        if (!name &amp;&amp; area) {
-                                src = &quot;whitepages&quot;;
-                                name = area;
-                        }
-                        if (globals.cache &amp;&amp; name) {
-                                set_cache(pool, number, name);
-                        }
</del><span class="cx">                 }
</span><span class="cx">         }
</span><del>-        /* only do the below if it is a nanpa number */
-        if (!skipcitystate &amp;&amp; strlen(number) == 11 &amp;&amp; number[0] == '1' &amp;&amp;
-                !name &amp;&amp; switch_odbc_available() &amp;&amp; globals.master_odbc &amp;&amp; globals.citystate_sql) {
</del><ins>+        /* only do the below if we don't know anything about the # and it is a nanpa number */
+        if (!area &amp;&amp; !name &amp;&amp; 
+                !skipcitystate &amp;&amp; 
+                strlen(number) == 11 &amp;&amp; number[0] == '1' &amp;&amp;
+                switch_odbc_available() &amp;&amp; globals.master_odbc &amp;&amp; globals.citystate_sql) {
</ins><span class="cx">                 
</span><del>-                name = do_db_lookup(pool, event, number, globals.citystate_sql);
</del><ins>+                area = do_db_lookup(pool, event, number, globals.citystate_sql);
</ins><span class="cx">                 src = &quot;npanxx&quot;;
</span><span class="cx">         }
</span><ins>+        
+        if (!name &amp;&amp; area) {
+                name = area;
+        }
+        
+        if (!name) {
+                name = &quot;UNKNOWN&quot;;
+        }
</ins><span class="cx"> 
</span><del>-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, &quot;cidlookup source: %s\n&quot;, src);
-        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;cidlookup_source&quot;, src);
</del><ins>+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, &quot;cidlookup source: %s\n&quot;, src ? src : &quot;none&quot;);
+        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;cidlookup_source&quot;, src ? src : &quot;none&quot;);
+        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;cidlookup_area&quot;, area ? area : &quot;unknown&quot;);
</ins><span class="cx">         return name;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -550,6 +563,9 @@
</span><span class="cx">                 if (!zstr(switch_event_get_header(event, &quot;cidlookup_source&quot;))) {
</span><span class="cx">                         switch_channel_set_variable(channel, &quot;cidlookup_source&quot;, switch_core_strdup(pool, switch_event_get_header(event, &quot;cidlookup_source&quot;)));
</span><span class="cx">                 }
</span><ins>+                if (!zstr(switch_event_get_header(event, &quot;cidlookup_area&quot;))) {
+                        switch_channel_set_variable(channel, &quot;cidlookup_area&quot;, switch_core_strdup(pool, switch_event_get_header(event, &quot;cidlookup_area&quot;)));
+                }
</ins><span class="cx">                 profile-&gt;caller_id_name = switch_core_strdup(profile-&gt;pool, name);;
</span><span class="cx">         }
</span><span class="cx">         
</span><span class="lines">@@ -596,14 +612,14 @@
</span><span class="cx">                 
</span><span class="cx">                 if (!strcmp(&quot;status&quot;, argv[0])) {
</span><span class="cx">                         stream-&gt;write_function(stream, &quot;+OK\n url: %s\n cache: %s\n cache-expire: %d\n&quot;, 
</span><del>-                                                                        globals.url,
</del><ins>+                                                                        globals.url ? globals.url : &quot;(null)&quot;,
</ins><span class="cx">                                                                         (globals.cache) ? &quot;true&quot; : &quot;false&quot;,
</span><span class="cx">                                                                         globals.cache_expire);
</span><span class="cx">                                                                         
</span><span class="cx">                         stream-&gt;write_function(stream, &quot; odbc-dsn: %s\n sql: %s\n citystate-sql: %s\n&quot;, 
</span><del>-                                                                        globals.odbc_dsn,
-                                                                        globals.sql,
-                                                                        globals.citystate_sql);
</del><ins>+                                                                        globals.odbc_dsn ? globals.odbc_dsn : &quot;(null)&quot;,
+                                                                        globals.sql ? globals.sql : &quot;(null)&quot;,
+                                                                        globals.citystate_sql ? globals.citystate_sql : &quot;(null)&quot;);
</ins><span class="cx">                         stream-&gt;write_function(stream, &quot; ODBC Compiled: %s\n&quot;, switch_odbc_available() ? &quot;true&quot; : &quot;false&quot;);
</span><span class="cx"> 
</span><span class="cx">                         switch_goto_status(SWITCH_STATUS_SUCCESS, done);
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>