Neil Jerram <[email protected]> writes:

> Joachim Ott <[email protected]> writes:
>
>> I've tried a bit with "mdbus2 -s org.freesmartphone.odatad
>> /org/freesmartphone/Data/World
>> org.freesmartphone.Data.World.GetCountryCodeForMccMnc 23430" (returns
>> "im"). I've tried other values like 23410, 2341, 234, they all return
>> "im". The lookup-function seems wrong (I haven't looked at the
>> source).
>
> Thanks for your reply and for the mdbus2 technique.  I think I've
> tracked the problem down now, and will provide a patch shortly.

FYI, below is the patch that I just sent to smartphones-userland.

      Neil


* fsodatad/src/plugins/world/plugin.vala: Don't return a 3 digit
  prefix match while there are still countries we haven't checked yet
  that might have a full match.
---
 fsodatad/src/plugins/world/plugin.vala |   38 +++++++++++++++++++++-----------
 1 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/fsodatad/src/plugins/world/plugin.vala 
b/fsodatad/src/plugins/world/plugin.vala
index 4e2d11a..6b726df 100644
--- a/fsodatad/src/plugins/world/plugin.vala
+++ b/fsodatad/src/plugins/world/plugin.vala
@@ -59,35 +59,47 @@ class World.Info : FreeSmartphone.Data.World, 
FsoFramework.AbstractObject
 
     public async string get_country_code_for_mcc_mnc( string mcc_mnc ) throws 
FreeSmartphone.Error, DBusError, IOError
     {
+        var mcc = "%c%c%c".printf( (int)mcc_mnc[0], (int)mcc_mnc[1], 
(int)mcc_mnc[2] );
+        var prefixccode = "";
+#if DEBUG
+       debug( @"Looking for = $(mcc_mnc)" );
+#endif
         foreach ( var country in 
FsoData.MBPI.Database.instance().allCountries().values )
         {
+#if DEBUG
+           debug( @"Country = $(country.code)" );
+#endif
             foreach ( var provider in country.providers.values )
             {
+#if DEBUG
+               debug( @"Provider = $(provider.name)" );
+#endif
                 foreach ( var code1 in provider.codes )
                 {
+#if DEBUG
+                   debug( @"Code = $(code1)" );
+#endif
                     if ( code1 == mcc_mnc )
                     {
-                        return country.code;
-                    }
-                }
 #if DEBUG
-                debug( @"Exact match not found for $mcc_mnc; trying first 
three digits..." );
+                        debug( @"Full match with country code $(country.code)" 
);
 #endif
-                var mcc = "%c%c%c".printf( (int)mcc_mnc[0], (int)mcc_mnc[1], 
(int)mcc_mnc[2] );
-
-                foreach ( var code2 in provider.codes )
-                {
-                    if ( code2.has_prefix( mcc ) )
-                    {
                         return country.code;
                     }
-                }
+                   else if ( ( prefixccode == "" ) && code1.has_prefix( mcc ) 
)  
+                   {
 #if DEBUG
-                debug( @"No provider with MCC $mcc found" );
+                        debug( @"Prefix match with country code 
$(country.code)" );
 #endif
+                       prefixccode = country.code;
+                   }
+                }
             }
         }
-        return "";
+#if DEBUG
+        debug( @"No country/provider found with MCC $mcc" );
+#endif
+        return prefixccode;
     }
 
     public async GLib.HashTable<string,string> get_timezones_for_country_code( 
string country_code ) throws FreeSmartphone.Error, DBusError, IOError
-- 
1.7.1

_______________________________________________
Shr-devel mailing list
[email protected]
http://lists.shr-project.org/mailman/listinfo/shr-devel

Reply via email to