remotestoragefw/webdavaccessplugin/src/rsfwlockqueryparser.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:  Parse WebDAV LOCK method response body
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "rsfwlockqueryparser.h"
       
    21 #include "rsfwdavfileinfo.h"
       
    22 #include "mdebug.h"
       
    23 
       
    24 // CONSTANTS
       
    25 _LIT(KTimeOutTag,"Second-");
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ==============================
       
    28 
       
    29 CRsfwLockQueryParser* CRsfwLockQueryParser::NewLC()
       
    30     {
       
    31     CRsfwLockQueryParser* self = new(ELeave) CRsfwLockQueryParser;
       
    32     CleanupStack::PushL(self);
       
    33     self->ConstructL();
       
    34     return self;
       
    35     }
       
    36 
       
    37 CRsfwLockQueryParser* CRsfwLockQueryParser::NewL()
       
    38     {
       
    39     CRsfwLockQueryParser* self = NewLC();
       
    40     CleanupStack::Pop(self);
       
    41     return self;
       
    42     }
       
    43 
       
    44 void CRsfwLockQueryParser::ConstructL()
       
    45     {
       
    46     /*
       
    47       iParseState = ELooking;
       
    48     */
       
    49     }
       
    50 
       
    51 CRsfwLockQueryParser::~CRsfwLockQueryParser()
       
    52     {
       
    53     delete iContentString;
       
    54     }
       
    55 
       
    56 // ----------------------------------------------------------------------------
       
    57 // CRsfwLockQueryParser::OnStartDocumentL
       
    58 // This method is a callback to indicate the start of the document.
       
    59 // @param aDocParam Specifies the various parameters of the document.
       
    60 // @arg aDocParam.iCharacterSetName The character encoding of the document.
       
    61 // ----------------------------------------------------------------------------
       
    62 //
       
    63 void CRsfwLockQueryParser::OnStartDocumentL(
       
    64     const Xml::RDocumentParameters& /* aDocParam */,
       
    65     TInt /* aErrCode */)
       
    66     {
       
    67     }
       
    68 
       
    69 // ----------------------------------------------------------------------------
       
    70 // CRsfwLockQueryParser::OnStartDocumentL
       
    71 // This method is a callback to indicate the end of the document.
       
    72 // ----------------------------------------------------------------------------
       
    73 //
       
    74 void CRsfwLockQueryParser::OnEndDocumentL(TInt aErrCode)
       
    75     {
       
    76     if (aErrCode)
       
    77         {
       
    78         User::Leave(aErrCode);
       
    79         }
       
    80     }
       
    81 
       
    82 // ----------------------------------------------------------------------------
       
    83 // CRsfwLockQueryParser::OnStartElementL
       
    84 // This method is a callback to indicate an element has been parsed.
       
    85 // @param aElement is a handle to the element's details.
       
    86 // @param aAttributes contains the attributes for the element.
       
    87 // @param aErrorCode is the error code.
       
    88 // If this is not KErrNone then special action may be required.
       
    89 // ----------------------------------------------------------------------------
       
    90 //
       
    91 void CRsfwLockQueryParser::OnStartElementL(
       
    92     const Xml::RTagInfo& aElement,
       
    93     const Xml::RAttributeArray& /* aAttributes */,
       
    94     TInt aErrorCode)
       
    95     {
       
    96     _LIT8(KLockType, "locktype");
       
    97     _LIT8(KLockScope, "lockscope");
       
    98     _LIT8(KDepth, "depth");
       
    99     _LIT8(KTimeout, "timeout");
       
   100     _LIT8(KLockToken, "locktoken");
       
   101 
       
   102     if (aErrorCode)
       
   103         {
       
   104         User::Leave(aErrorCode);
       
   105         }
       
   106 
       
   107     switch (iParseState)
       
   108         {
       
   109     case ELockType:
       
   110         // Currently, write is the only acquired type, might change later
       
   111         break;
       
   112 
       
   113     case ELockScope:
       
   114         // Currently, exclusive is the only acquired type, might change later
       
   115         break;
       
   116 
       
   117     case EDepth:
       
   118         break;
       
   119 
       
   120     case ETimeout:
       
   121         break;
       
   122 
       
   123     case ELockToken:
       
   124         {
       
   125         _LIT8(KHref, "href");
       
   126         if (((aElement.LocalName()).DesC()).Compare(KHref) == 0)
       
   127             {
       
   128             iParseState = EHrefToken;
       
   129             }
       
   130         }
       
   131         break;
       
   132 
       
   133     case EHrefToken:
       
   134         break;
       
   135 
       
   136     case ELooking: // we are trying to find the next interesting tag
       
   137         if (((aElement.LocalName()).DesC()).Compare(KLockType) == 0)
       
   138             {
       
   139             iParseState = ELockType;
       
   140             }
       
   141         else if (((aElement.LocalName()).DesC()).Compare(KLockScope) == 0)
       
   142             {
       
   143             iParseState = ELockScope;
       
   144             }
       
   145         else if (((aElement.LocalName()).DesC()).Compare(KDepth) == 0)
       
   146             {
       
   147             iParseState = EDepth;
       
   148             }
       
   149         else if (((aElement.LocalName()).DesC()).Compare(KTimeout) == 0)
       
   150             {
       
   151             iParseState = ETimeout;
       
   152             }
       
   153         else if (((aElement.LocalName()).DesC()).Compare(KLockToken) == 0)
       
   154             {
       
   155             iParseState = ELockToken;
       
   156             }
       
   157         else
       
   158             {
       
   159             // lint
       
   160             }
       
   161         break;
       
   162 
       
   163     default:
       
   164         break;
       
   165         }
       
   166     }
       
   167 
       
   168 // ----------------------------------------------------------------------------
       
   169 // CRsfwLockQueryParser::OnEndElementL
       
   170 // This method is a callback to indicate that end of element has been reached.
       
   171 // @param aElement is a handle to the element's details.
       
   172 // @param aErrorCode is the error code.
       
   173 // If this is not KErrNone then special action may be required.
       
   174 // ----------------------------------------------------------------------------
       
   175 //
       
   176 void CRsfwLockQueryParser::OnEndElementL(const Xml::RTagInfo& /* aElement */,
       
   177                                      TInt aErrorCode)
       
   178     {
       
   179     if (aErrorCode)
       
   180         {
       
   181         User::Leave(aErrorCode);
       
   182         }
       
   183 
       
   184     // otherwise we will continue reading
       
   185     // if we have some interesting content
       
   186     if ((iParseState != ELooking) && !iContentString)
       
   187         {
       
   188         iParseState = ELooking;
       
   189         return;
       
   190         }
       
   191 
       
   192     switch (iParseState)
       
   193         {
       
   194     case ELockType:
       
   195         break;
       
   196 
       
   197     case ELockScope:
       
   198         break;
       
   199 
       
   200     case EDepth:
       
   201         {
       
   202         /*
       
   203           TPtrC aux;
       
   204           aux.Set(aBuf);
       
   205           TLex lex(aux);
       
   206           lex.Val(iDepth);
       
   207         */
       
   208         }
       
   209         break;
       
   210 
       
   211     case ETimeout:
       
   212         {
       
   213         if (iDavFileInfo)
       
   214             {
       
   215             _LIT8(KInfinite, "Infinite");
       
   216             if (iContentString->Compare(KInfinite) == 0)
       
   217                 {
       
   218                 iDavFileInfo->SetTimeout(KMaxTUint);
       
   219                 }
       
   220             else
       
   221                 {
       
   222                 // We expect 'Second-x" where x a positive integer
       
   223                 TInt timeout = 0;
       
   224                 if (iContentString->Length() > KTimeOutTag().Length())
       
   225                     {
       
   226                     TPtrC8 aux;
       
   227                     aux.Set(*iContentString);
       
   228                     TLex8 lex(aux);
       
   229                     lex.SkipAndMark(KTimeOutTag().Length());
       
   230                     lex.Val(timeout);
       
   231                     }
       
   232                 iDavFileInfo->SetTimeout(timeout);
       
   233                 }
       
   234             }
       
   235         }
       
   236         break;
       
   237 
       
   238     case ELockToken:
       
   239         break;
       
   240 
       
   241     case EHrefToken:
       
   242         if (iDavFileInfo)
       
   243             {
       
   244             iDavFileInfo->SetLockTokenL(*iContentString);
       
   245             }
       
   246         break;
       
   247 
       
   248     case ELooking:
       
   249         break;
       
   250 
       
   251     default:
       
   252         break;
       
   253         }
       
   254 
       
   255     delete iContentString;
       
   256     iContentString = NULL;
       
   257     iParseState = ELooking;
       
   258     }
       
   259 
       
   260 // ----------------------------------------------------------------------------
       
   261 // CRsfwLockQueryParser::OnContentL
       
   262 // This method is a callback that sends the content of the element.
       
   263 // Not all the content may be returned in one go.
       
   264 // The data may be sent in chunks.
       
   265 // When an OnEndElementL is received there is no more content to be sent.
       
   266 // @param aBytes is the raw content data for the element.
       
   267 // The client is responsible for converting the data to the
       
   268 // required character set if necessary.
       
   269 // In some instances the content may be binary and must not be converted.
       
   270 // @param aErrorCode is the error code.
       
   271 // If this is not KErrNone then special action may be required.
       
   272 //
       
   273 void CRsfwLockQueryParser::OnContentL(const TDesC8& aBytes, TInt aErrorCode)
       
   274     {
       
   275     if (aErrorCode)
       
   276         {
       
   277         User::Leave(aErrorCode);
       
   278         }
       
   279 
       
   280     // We want to add to contentstring only if we are in a state
       
   281     // where the content is interesting to us
       
   282     if ((iParseState == ETimeout) || (iParseState == EHrefToken))
       
   283         {
       
   284         if (!iContentString)
       
   285             {
       
   286             iContentString = HBufC8::NewL(aBytes.Length());
       
   287             TPtr8 string = iContentString->Des();
       
   288             string.Append(aBytes);
       
   289             }
       
   290         else
       
   291             {
       
   292             iContentString =
       
   293                 iContentString->ReAllocL(iContentString->Length() +
       
   294                                          aBytes.Length());
       
   295             TPtr8 string = iContentString->Des();
       
   296             string.Append(aBytes);
       
   297             }
       
   298         }
       
   299     }
       
   300 
       
   301 // ----------------------------------------------------------------------------
       
   302 // CRsfwLockQueryParser::OnStartPrefixMappingL
       
   303 // This method is a notification of the beginning of the scope of a prefix-URI
       
   304 // Namespace mapping.
       
   305 // This method is always called before corresponding OnStartElementL method.
       
   306 // @param aPrefix is the Namespace prefix being declared.
       
   307 // @param aUri is the Namespace URI the prefix is mapped to.
       
   308 // @param aErrorCode is the error code.
       
   309 // If this is not KErrNone then special action may be required.
       
   310 // ----------------------------------------------------------------------------
       
   311 //
       
   312 void CRsfwLockQueryParser::OnStartPrefixMappingL(const RString& /* aPrefix */,
       
   313                                              const RString& /* aUri */,
       
   314                                              TInt aErrorCode)
       
   315     {
       
   316     if (aErrorCode)
       
   317         {
       
   318         User::Leave(aErrorCode);
       
   319         }
       
   320     }
       
   321 
       
   322 // ----------------------------------------------------------------------------
       
   323 // CRsfwLockQueryParser::OnEndPrefixMappingL
       
   324 // This method is a notification of end of the scope of a prefix-URI mapping.
       
   325 // This method is called after the corresponding DoEndElementL method.
       
   326 // @param aPrefix is the Namespace prefix that was mapped.
       
   327 // @param aErrorCode is the error code.
       
   328 // If this is not KErrNone then special action may be required.
       
   329 // ----------------------------------------------------------------------------
       
   330 //
       
   331 void CRsfwLockQueryParser::OnEndPrefixMappingL(const RString& /* aPrefix */,
       
   332                                            TInt aErrorCode)
       
   333     {
       
   334     if (aErrorCode)
       
   335         {
       
   336         User::Leave(aErrorCode);
       
   337         }
       
   338     }
       
   339 
       
   340 // ----------------------------------------------------------------------------
       
   341 // CRsfwLockQueryParser::OnIgnorableWhiteSpaceL
       
   342 // This method is a notification of ignorable whitespace in element content.
       
   343 // @param aBytes are the ignored bytes from the document being parsed.
       
   344 // @param aErrorCode is the error code.
       
   345 // If this is not KErrNone then special action may be required.
       
   346 // ----------------------------------------------------------------------------
       
   347 //
       
   348 void CRsfwLockQueryParser::OnIgnorableWhiteSpaceL(const TDesC8& /* aBytes */,
       
   349                                               TInt aErrorCode)
       
   350     {
       
   351     if (aErrorCode)
       
   352         {
       
   353         User::Leave(aErrorCode);
       
   354         }
       
   355     }
       
   356 
       
   357 // ----------------------------------------------------------------------------
       
   358 // CRsfwLockQueryParser::OnSkippedEntityL
       
   359 // This method is a notification of a skipped entity.
       
   360 // If the parser encounters an external entity it does not need to expand it -
       
   361 // it can return the entity as aName for the client to deal with.
       
   362 // @param aName is the name of the skipped entity.
       
   363 // @param aErrorCode is the error code.
       
   364 // If this is not KErrNone then special action may be required.
       
   365 // ----------------------------------------------------------------------------
       
   366 //
       
   367 void CRsfwLockQueryParser::OnSkippedEntityL(const RString& /* aName */,
       
   368                                         TInt aErrorCode)
       
   369     {
       
   370     if (aErrorCode)
       
   371         {
       
   372         User::Leave(aErrorCode);
       
   373         }
       
   374     }
       
   375 
       
   376 // ----------------------------------------------------------------------------
       
   377 // CRsfwLockQueryParser::OnProcessingInstructionL
       
   378 // This method is a receive notification of a processing instruction.
       
   379 // @param aTarget is the processing instruction target.
       
   380 // @param aData is the processing instruction data. If empty none was supplied.
       
   381 // @param aErrorCode is the error code.
       
   382 // If this is not KErrNone then special action may be required.
       
   383 // ----------------------------------------------------------------------------
       
   384 //
       
   385 void CRsfwLockQueryParser::OnProcessingInstructionL(const TDesC8& /* aTarget */,
       
   386                                                 const TDesC8& /* aData */,
       
   387                                                 TInt aErrorCode)
       
   388     {
       
   389     if (aErrorCode)
       
   390         {
       
   391         User::Leave(aErrorCode);
       
   392         }
       
   393     }
       
   394 
       
   395 // ----------------------------------------------------------------------------
       
   396 // CRsfwLockQueryParser::OnError
       
   397 // This method indicates an error has occurred.
       
   398 // @param aErrorCode is the error code
       
   399 // ----------------------------------------------------------------------------
       
   400 //
       
   401 
       
   402 void CRsfwLockQueryParser::OnError(TInt aErrorCode)
       
   403     {
       
   404     DEBUGSTRING(("CRsfwLockQueryParser::OnError(%d)", aErrorCode));
       
   405     iError = aErrorCode;
       
   406     }
       
   407 
       
   408 // ----------------------------------------------------------------------------
       
   409 // CRsfwLockQueryParser::GetExtendedInterface
       
   410 // This method obtains the interface matching the specified uid.
       
   411 // @return 0 if no interface matching the uid is found.
       
   412 // Otherwise, the this pointer cast to that interface.
       
   413 // @param aUid the uid identifying the required interface.
       
   414 // ----------------------------------------------------------------------------
       
   415 //
       
   416 TAny* CRsfwLockQueryParser::GetExtendedInterface(const TInt32 /* aUid */)
       
   417     {
       
   418     return NULL;
       
   419     }
       
   420 
       
   421 // ----------------------------------------------------------------------------
       
   422 // CRsfwLockQueryParser::SetFileDavInfo
       
   423 // Set a pointer to the directory information structure to be filled.
       
   424 // ----------------------------------------------------------------------------
       
   425 //
       
   426 void CRsfwLockQueryParser::SetDavFileInfo(CRsfwDavFileInfo* aDavFileInfo)
       
   427     {
       
   428     iDavFileInfo = aDavFileInfo;
       
   429     }
       
   430     
       
   431 TInt CRsfwLockQueryParser::GetLastError() 
       
   432 	{
       
   433 	return iError;
       
   434 	}
       
   435 
       
   436 //  End of File