remotestoragefw/mountmanager/src/rsfwmountentry.cpp
branchRCL_3
changeset 19 88ee4cf65e19
parent 16 87c71b25c937
child 20 1aa8c82cb4cb
equal deleted inserted replaced
16:87c71b25c937 19:88ee4cf65e19
     1 /*
       
     2 * Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Mount configuration entry
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <uri16.h>
       
    21 #include <rsfwmountentry.h>
       
    22 #include "rsfwmountutils.h"
       
    23 
       
    24 // ============================ MEMBER FUNCTIONS ==============================
       
    25 
       
    26 // ----------------------------------------------------------------------------
       
    27 // CRsfwMountEntry::NewLC
       
    28 // ----------------------------------------------------------------------------
       
    29 //
       
    30 EXPORT_C CRsfwMountEntry* CRsfwMountEntry::NewLC()
       
    31     {
       
    32     CRsfwMountEntry* self = new (ELeave) CRsfwMountEntry();
       
    33     CleanupStack::PushL(self);
       
    34     self->ConstructL();
       
    35     return self;
       
    36     }
       
    37 
       
    38 // ----------------------------------------------------------------------------
       
    39 // CRsfwMountEntry::NewL
       
    40 // ----------------------------------------------------------------------------
       
    41 //
       
    42 EXPORT_C CRsfwMountEntry* CRsfwMountEntry::NewL()
       
    43     {
       
    44     CRsfwMountEntry* self = NewLC();
       
    45     CleanupStack::Pop(self);
       
    46     return self;
       
    47     }
       
    48 
       
    49 // ----------------------------------------------------------------------------
       
    50 // CRsfwMountEntry::CRsfwMountEntry
       
    51 // ----------------------------------------------------------------------------
       
    52 //
       
    53 CRsfwMountEntry::CRsfwMountEntry()
       
    54     {
       
    55     }
       
    56 
       
    57 // ----------------------------------------------------------------------------
       
    58 // CRsfwMountEntry::~CRsfwMountEntry
       
    59 // ----------------------------------------------------------------------------
       
    60 //
       
    61 EXPORT_C CRsfwMountEntry::~CRsfwMountEntry()
       
    62     {
       
    63     Clear();
       
    64     iFs.Close();
       
    65     }
       
    66 
       
    67 // ----------------------------------------------------------------------------
       
    68 // CRsfwMountEntry::SetItemL
       
    69 // ----------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C void CRsfwMountEntry::SetItemL(TInt aIndex, const TDesC& aValue)
       
    72     {
       
    73     TChar driveChar;
       
    74      
       
    75     if ((aIndex < EMountEntryItemIndex) || (aIndex >= EMountEntryItemCount))
       
    76         {
       
    77         User::Leave(KErrArgument);
       
    78         }
       
    79 
       
    80     switch (aIndex) 
       
    81         {
       
    82         case EMountEntryItemName:
       
    83             if (aValue.Length() > KMaxMountNameLength) 
       
    84                 {
       
    85                 User::Leave(KErrArgument);
       
    86                 }      
       
    87             // name must not contain chars not allowed in Symbian file names
       
    88             // as the name will be stored as drive friendly name
       
    89             // (rules for allowed chars are the same)
       
    90             if (!(RsfwMountUtils::IsFriendlyNameValid(aValue))) 
       
    91                 {
       
    92                 User::Leave(KErrArgument);
       
    93                 }
       
    94             break;
       
    95         case EMountEntryItemUri:
       
    96             if (aValue.Length() > KMaxMountUriLength)
       
    97                 {
       
    98                 User::Leave(KErrArgument);
       
    99                 }
       
   100             break;
       
   101         case EMountEntryItemUserName:
       
   102             if (aValue.Length() > KMaxMountUserNameLength)
       
   103                 {
       
   104                 User::Leave(KErrArgument);
       
   105                 }
       
   106             break;   
       
   107         case EMountEntryItemPassword:
       
   108              if (aValue.Length() > KMaxMountPasswordLength)
       
   109                 {
       
   110                 User::Leave(KErrArgument);
       
   111                 } 
       
   112             break;
       
   113         case EMountEntryItemDrive:
       
   114             // remote drives can take drive letters from  J through Y
       
   115             // (see documentation for RFs::DriveList())
       
   116             driveChar = aValue[0];
       
   117             TInt driveNumber;
       
   118             User::LeaveIfError(iFs.CharToDrive(driveChar, driveNumber));
       
   119             if (!((driveNumber >= EDriveJ) && (driveNumber < EDriveZ)))
       
   120                 {
       
   121                 User::Leave(KErrArgument);
       
   122                 }
       
   123             break;
       
   124         default:
       
   125             // check that the value is not too long
       
   126             if (aValue.Length() > KMaxMountConfItemLength) 
       
   127                 {
       
   128                 User::Leave(KErrArgument);
       
   129                 }
       
   130             break;            
       
   131         }
       
   132         
       
   133     HBufC*& p = iMountEntryItems[aIndex];
       
   134     if (p)
       
   135         {
       
   136         delete p;
       
   137         p = NULL;
       
   138         }
       
   139     p = aValue.AllocL();
       
   140     }
       
   141 
       
   142 // ----------------------------------------------------------------------------
       
   143 // CRsfwMountEntry::SetItemL
       
   144 // ----------------------------------------------------------------------------
       
   145 //
       
   146 EXPORT_C void CRsfwMountEntry::SetItemL(TInt aIndex, const TDesC8& aValue)
       
   147     {
       
   148     HBufC* p = HBufC::NewLC(aValue.Length());
       
   149     TPtr pPtr = p->Des();
       
   150     pPtr.Copy(aValue);
       
   151     SetItemL(aIndex, pPtr);
       
   152     CleanupStack::PopAndDestroy(p);
       
   153     }
       
   154 
       
   155 // ----------------------------------------------------------------------------
       
   156 // CRsfwMountEntry::SetEntryL
       
   157 // ----------------------------------------------------------------------------
       
   158 //
       
   159 EXPORT_C void CRsfwMountEntry::SetEntryL(TInt aIndex,
       
   160                                      const TDesC& aName,
       
   161                                      TChar aDriveLetter,
       
   162                                      const TDesC& aUri,
       
   163                                      const TDesC& aUserName,
       
   164                                      const TDesC& aPassword,
       
   165                                      const TDesC& aIap)
       
   166     {
       
   167     TBuf<KIndexAsStringLength> index;
       
   168     index.Num(aIndex);
       
   169     SetItemL(EMountEntryItemIndex, index);
       
   170     SetItemL(EMountEntryItemName, aName);
       
   171     TBuf<KIndexAsStringLength> drive;
       
   172     drive.Append(aDriveLetter);
       
   173     SetItemL(EMountEntryItemDrive, drive);
       
   174     SetItemL(EMountEntryItemUri, aUri);
       
   175     SetItemL(EMountEntryItemUserName, aUserName);
       
   176     SetItemL(EMountEntryItemPassword, aPassword);
       
   177     SetItemL(EMountEntryItemIap, aIap);
       
   178     }
       
   179 
       
   180 // ----------------------------------------------------------------------------
       
   181 // CRsfwMountEntry::Item
       
   182 // ----------------------------------------------------------------------------
       
   183 //
       
   184 EXPORT_C const HBufC* CRsfwMountEntry::Item(TInt aIndex) const
       
   185     {
       
   186     if ((aIndex >= EMountEntryItemIndex) && (aIndex < EMountEntryItemCount))
       
   187         {
       
   188         return iMountEntryItems[aIndex];
       
   189         }
       
   190     return NULL;
       
   191     }
       
   192 
       
   193 // ----------------------------------------------------------------------------
       
   194 // CRsfwMountEntry::Clear
       
   195 // ----------------------------------------------------------------------------
       
   196 //
       
   197 EXPORT_C void CRsfwMountEntry::Clear()
       
   198     {
       
   199     TInt i;
       
   200     for (i = EMountEntryItemIndex;  i < EMountEntryItemCount;  i++)
       
   201         {
       
   202         if (iMountEntryItems[i])
       
   203             {
       
   204             delete iMountEntryItems[i];
       
   205             iMountEntryItems[i] = NULL;
       
   206             }
       
   207         }
       
   208     }
       
   209 
       
   210 // ----------------------------------------------------------------------------
       
   211 // CRsfwMountEntry::CloneL
       
   212 // ----------------------------------------------------------------------------
       
   213 //
       
   214 EXPORT_C CRsfwMountEntry* CRsfwMountEntry::CloneL() const
       
   215     {
       
   216     CRsfwMountEntry* entry = CRsfwMountEntry::NewLC();
       
   217     TInt i;
       
   218     for (i = EMountEntryItemIndex;  i < EMountEntryItemCount;  i++)
       
   219         {
       
   220         HBufC* item = iMountEntryItems[i];
       
   221         if (item)
       
   222             {
       
   223             entry->iMountEntryItems[i] = (*item).AllocL();
       
   224             }
       
   225         }
       
   226     CleanupStack::Pop(entry);
       
   227     return entry;
       
   228     }
       
   229 
       
   230 // ----------------------------------------------------------------------------
       
   231 // CRsfwMountEntry::ConstructL
       
   232 // ----------------------------------------------------------------------------
       
   233 //
       
   234 void CRsfwMountEntry::ConstructL()
       
   235     {
       
   236     User::LeaveIfError(iFs.Connect());
       
   237     }
       
   238 
       
   239 //  End of File