networkingtestandutils/networkingintegrationtest/NTRas/RASDB.CPP
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "rasdef.h"
       
    17 
       
    18 _LIT(RAS_DB_FILE,"Ras.ini");
       
    19 _LIT(RAS_DB_SECTION,"RAS");
       
    20 
       
    21 CRasDatabase::CRasDatabase(CNtRas* aNtRas)
       
    22 	: iNtRas(aNtRas)
       
    23 	{
       
    24 	__DECLARE_NAME(_S("CRasDatabase"));
       
    25 	}
       
    26 
       
    27 CRasDatabase::~CRasDatabase()
       
    28 	{
       
    29 	delete iIniFile;
       
    30 	}
       
    31 
       
    32 CRasDatabase* CRasDatabase::NewL(CNtRas* aNtRas)
       
    33 	{
       
    34 	
       
    35 	CRasDatabase* p = new (ELeave) CRasDatabase(aNtRas);
       
    36 	CleanupStack::PushL(p);
       
    37 	p->ConstructL();
       
    38 	CleanupStack::Pop();
       
    39 	return p;
       
    40 	}
       
    41 
       
    42 void CRasDatabase::ConstructL()
       
    43 	{
       
    44 	iIniFile = CESockIniData::NewL(RAS_DB_FILE);
       
    45 	}
       
    46 
       
    47 TInt CRasDatabase::ReadField(const TDesC& aField, TUint32& aValue)
       
    48 	{
       
    49 
       
    50 	TInt temp;
       
    51 	if(!aField.CompareF(NIF_IFSERVERMODE))
       
    52 		{
       
    53 		if(!iIniFile->FindVar(RAS_DB_SECTION, aField, temp))
       
    54 			temp=0;
       
    55 		aValue=(TUint32)temp;
       
    56 		return KErrNone;
       
    57 		}
       
    58 	else if(!aField.CompareF(RAS_YESTOCONNECT))
       
    59 		{
       
    60 		if(!iIniFile->FindVar(RAS_DB_SECTION, aField, temp))
       
    61 			temp=0;
       
    62 		aValue=(TUint32)temp;
       
    63 		return KErrNone;
       
    64 		}
       
    65 	else if(!aField.CompareF(RAS_YESTORECONNECT))
       
    66 		{
       
    67 		if(!iIniFile->FindVar(RAS_DB_SECTION, aField, temp))
       
    68 			temp=0;
       
    69 		aValue=(TUint32)temp;
       
    70 		return KErrNone;
       
    71 		}
       
    72 
       
    73 	if(!iIniFile->FindVar(RAS_DB_SECTION, aField, temp))
       
    74 		{
       
    75 		return KErrNotFound;
       
    76 		}
       
    77 	else
       
    78 		{
       
    79 		aValue=(TUint32)temp;
       
    80 		return KErrNone;
       
    81 		}
       
    82 	}
       
    83 
       
    84 TInt CRasDatabase::ReadField(const TDesC& aField, TDes8& aValue)
       
    85 	{
       
    86 	TPtrC des;
       
    87 	if (!iIniFile->FindVar(RAS_DB_SECTION, aField, des))
       
    88 		return KErrNotFound;
       
    89 
       
    90 	if (des.Length()>aValue.MaxLength())
       
    91 		return KErrTooBig;
       
    92 
       
    93 #ifndef UNICODE
       
    94 	aValue = des;
       
    95 #else
       
    96 	TInt i;
       
    97 	TInt len;
       
    98 	TUint8* Dest;
       
    99 	TUint16* Source;
       
   100 	len = des.Length();
       
   101 	Source = CONST_CAST(TUint16*, des.Ptr());
       
   102 	Dest = CONST_CAST(TUint8*, aValue.Ptr());
       
   103 	for(i=0;i<len;i++)
       
   104 		{
       
   105 		*(Dest+i) = (TUint8)(*(Source+i) & 0xFF);
       
   106 		}
       
   107 
       
   108 	aValue.SetLength(len);
       
   109 #endif
       
   110 	return KErrNone;
       
   111 	}
       
   112