javacommons/javaenv/src.s60/javaenvinfo.cpp
changeset 78 71ad690e91f5
parent 57 59b3b4473dc8
equal deleted inserted replaced
72:1f0034e370aa 78:71ad690e91f5
    24 #include "logger.h"
    24 #include "logger.h"
    25 
    25 
    26 namespace Java
    26 namespace Java
    27 {
    27 {
    28 
    28 
    29 TInt ParseVersionL(TLex& aVersionText,TBool aLastVersionNumber);
    29 TInt ParseVersionL(TLex& aVersionText, TBool aLastVersionNumber, TUint aVersionNumMaxValue);
    30 
    30 
    31 // User-agent header substring
    31 // User-agent header substring
    32 _LIT(KUserAgentJavaString, "Configuration/CLDC-1.1 Profile/MIDP-2.1");
    32 _LIT(KUserAgentJavaString, "Configuration/CLDC-1.1 Profile/MIDP-2.1");
    33 
    33 
    34 // About application Java version text
    34 // About application Java version text
    38 _LIT(KMicroeditionJavaVersionFile, "\\resource\\versions\\java.txt");
    38 _LIT(KMicroeditionJavaVersionFile, "\\resource\\versions\\java.txt");
    39 
    39 
    40 // Length of temporary buffer for string manipulation
    40 // Length of temporary buffer for string manipulation
    41 const TUint KBufferSize = 32;
    41 const TUint KBufferSize = 32;
    42 
    42 
    43 // The min and max values for each version number
    43 // The max values for each field of version number (from TVersion)
    44 // const TUint KMajorVersionMinValue = 1;
       
    45 const TUint KMajorVersionMaxValue = 127;
    44 const TUint KMajorVersionMaxValue = 127;
    46 // const TUint KMinorVersionMaxValue = 9;
    45 const TUint KMinorVersionMaxValue = 99;
    47 // const TUint KBuildVersionMinValue = 1;
    46 const TUint KBuildVersionMaxValue = 32767;
    48 // const TUint KBuildVersionMaxValue = 32767;
       
    49 
    47 
    50 
    48 
    51 // ======== MEMBER FUNCTIONS ========
    49 // ======== MEMBER FUNCTIONS ========
    52 
    50 
    53 // ---------------------------------------------------------------------------
    51 // ---------------------------------------------------------------------------
   159     buffer16->Des().Copy(des);
   157     buffer16->Des().Copy(des);
   160 
   158 
   161     // parse the version numbers (major, minor, build) from the string
   159     // parse the version numbers (major, minor, build) from the string
   162     // leave if  error occurs in string or in its format (e.g.: missing dot char, wrong value)
   160     // leave if  error occurs in string or in its format (e.g.: missing dot char, wrong value)
   163     TLex versionText(buffer16->Des());
   161     TLex versionText(buffer16->Des());
   164     TUint32 majorVersion = ParseVersionL(versionText,EFalse);
   162     TUint32 majorVersion = ParseVersionL(versionText,EFalse, KMajorVersionMaxValue);
   165     TUint32 minorVersion = ParseVersionL(versionText,EFalse);
   163     TUint32 minorVersion = ParseVersionL(versionText,EFalse, KMinorVersionMaxValue);
   166     TUint32 buildVersion = ParseVersionL(versionText,ETrue);
   164     TUint32 buildVersion = ParseVersionL(versionText,ETrue, KBuildVersionMaxValue);
   167 
   165 
   168     TVersion version(majorVersion, minorVersion, buildVersion);
   166     TVersion version(majorVersion, minorVersion, buildVersion);
   169 
   167 
   170     CleanupStack::PopAndDestroy(buffer16);
   168     CleanupStack::PopAndDestroy(buffer16);
   171     CleanupStack::PopAndDestroy(buffer);
   169     CleanupStack::PopAndDestroy(buffer);
   176 }
   174 }
   177 
   175 
   178 //
   176 //
   179 //
   177 //
   180 //
   178 //
   181 TInt ParseVersionL(TLex& aVersionText,TBool aLastVersionNumber)
   179 TInt ParseVersionL(TLex& aVersionText, TBool aLastVersionNumber, TUint aVersionNumMaxValue)
   182 {
   180 {
   183     JELOG2(EUtils);
   181     JELOG2(EUtils);
   184 
   182 
   185     aVersionText.Mark();
   183     aVersionText.Mark();
   186     while ((aVersionText.Peek()).IsDigit())
   184     while ((aVersionText.Peek()).IsDigit())
   190     }
   188     }
   191     TLex partialVersionText(aVersionText.MarkedToken());
   189     TLex partialVersionText(aVersionText.MarkedToken());
   192     TUint32 version(0);
   190     TUint32 version(0);
   193     if (partialVersionText.BoundedVal(version,
   191     if (partialVersionText.BoundedVal(version,
   194                                       EDecimal,
   192                                       EDecimal,
   195                                       Java::KMajorVersionMaxValue) != KErrNone)
   193                                       aVersionNumMaxValue) != KErrNone)
   196     {
   194     {
   197         LOG(EUtils,EInfo, " GetJavaVersionL: format of value is corrupted (major version)");
   195         LOG(EUtils,EInfo, " GetJavaVersionL: format of value is corrupted");
   198         User::Leave(KErrCorrupt);
   196         User::Leave(KErrCorrupt);
   199     }
   197     }
   200     // check format
   198     // check format
   201     if (!aLastVersionNumber)
   199     if (!aLastVersionNumber)
   202     {
   200     {
   205             // move to the next char (should be number)
   203             // move to the next char (should be number)
   206             aVersionText.Inc();
   204             aVersionText.Inc();
   207         }
   205         }
   208         else
   206         else
   209         {
   207         {
   210             LOG(EUtils,EInfo, " GetJavaVersionL: format of value is corrupted");
   208             LOG(EUtils,EInfo, " GetJavaVersionL: format of value is corrupted2");
   211             User::Leave(KErrCorrupt);
   209             User::Leave(KErrCorrupt);
   212         }
   210         }
   213     }
   211     }
   214     return version;
   212     return version;
   215 }
   213 }