connectivitymodules/SeCon/wbxml/conmlhandler/src/sconconmlhandler.cpp
changeset 40 b63e67867dcd
parent 19 2691f6aa1921
equal deleted inserted replaced
39:9905f7d46607 40:b63e67867dcd
   167 // Returns the generated WBXML -document
   167 // Returns the generated WBXML -document
   168 // -----------------------------------------------------------------------------
   168 // -----------------------------------------------------------------------------
   169 //  
   169 //  
   170 TPtrC8 CSConConMLHandler::WBXMLDocument()
   170 TPtrC8 CSConConMLHandler::WBXMLDocument()
   171     {
   171     {
   172     LOGGER_ENTERFN( "CSConConMLHandler::WBXMLDocument()" );
       
   173     LOGGER_LEAVEFN( "CSConConMLHandler::WBXMLDocument()" );
       
   174     return iGenerator->WBXMLDocument();
   172     return iGenerator->WBXMLDocument();
   175     }
   173     }
   176     
   174     
   177 // -----------------------------------------------------------------------------
   175 // -----------------------------------------------------------------------------
   178 // CSConConMLHandler::XMLDocument()
   176 // CSConConMLHandler::XMLDocument()
   179 // Returns the generated XML -document
   177 // Returns the generated XML -document
   180 // -----------------------------------------------------------------------------
   178 // -----------------------------------------------------------------------------
   181 //  
   179 //  
   182 TPtrC8 CSConConMLHandler::XMLDocument()
   180 TPtrC8 CSConConMLHandler::XMLDocument()
   183     {
   181     {
   184     LOGGER_ENTERFN( "CSConConMLHandler::XMLDocument()" );
       
   185     LOGGER_LEAVEFN( "CSConConMLHandler::XMLDocument()" );
       
   186     return iGenerator->XMLDocument();
   182     return iGenerator->XMLDocument();
   187     }
   183     }
   188 
   184 
   189 // -----------------------------------------------------------------------------
   185 // -----------------------------------------------------------------------------
   190 // CSConConMLHandler::ParseL()
   186 // CSConConMLHandler::ParseL()
   316 // Reads one byte from the document
   312 // Reads one byte from the document
   317 // -----------------------------------------------------------------------------
   313 // -----------------------------------------------------------------------------
   318 //  
   314 //  
   319 TUint8 CSConConMLHandler::ReadUint8L()
   315 TUint8 CSConConMLHandler::ReadUint8L()
   320     {
   316     {
   321     LOGGER_ENTERFN( "CSConConMLHandler::ReadUint8L()" );
       
   322     if ( iPos == iParseBuffer->Size()) 
   317     if ( iPos == iParseBuffer->Size()) 
   323         {
   318         {
   324         User::Leave ( KErrEof );
   319         User::Leave ( KErrEof );
   325         }
   320         }
   326     TUint8 value;
   321     TUint8 value;
   328     TPtr8 ptr = data->Des();
   323     TPtr8 ptr = data->Des();
   329     iParseBuffer->Read(iPos, ptr, sizeof(TUint8));
   324     iParseBuffer->Read(iPos, ptr, sizeof(TUint8));
   330     iPos+= sizeof(TUint8);
   325     iPos+= sizeof(TUint8);
   331     value = ptr[0];
   326     value = ptr[0];
   332     CleanupStack::PopAndDestroy(1); //data 
   327     CleanupStack::PopAndDestroy(1); //data 
   333     LOGGER_WRITE_1( "CSConConMLHandler::ReadUint8L()\
       
   334      : returned %d ", value );
       
   335     return value;
   328     return value;
   336     }
   329     }
   337     
   330     
   338 // -----------------------------------------------------------------------------
   331 // -----------------------------------------------------------------------------
   339 // CSConConMLHandler::ReadMUint32L()
   332 // CSConConMLHandler::ReadMUint32L()
   340 // Reads multibyte coding from the document
   333 // Reads multibyte coding from the document
   341 // -----------------------------------------------------------------------------
   334 // -----------------------------------------------------------------------------
   342 //  
   335 //  
   343 TUint32 CSConConMLHandler::ReadMUint32L()
   336 TUint32 CSConConMLHandler::ReadMUint32L()
   344     {
   337     {
   345     LOGGER_ENTERFN( "CSConConMLHandler::ReadMUint32L()" );
       
   346     TUint32 result = 0;
   338     TUint32 result = 0;
   347     TUint8 c;
   339     TUint8 c;
   348     
   340     
   349     do  {
   341     do  {
   350         c = ReadUint8L();
   342         c = ReadUint8L();
   351         result = (result << 7) | (c & 0x7f);
   343         result = (result << 7) | (c & 0x7f);
   352         } while ( c & 0x80 );
   344         } while ( c & 0x80 );
   353     
   345     
   354     LOGGER_WRITE_1( "CSConConMLHandler::ReadMUint32L()\
       
   355      : returned %d ", result );
       
   356     return result;
   346     return result;
   357     }
   347     }
   358 
   348 
   359 // -----------------------------------------------------------------------------
   349 // -----------------------------------------------------------------------------
   360 // CSConConMLHandler::ReadStrIL()
   350 // CSConConMLHandler::ReadStrIL()
   361 // Reads string data from the document
   351 // Reads string data from the document
   362 // -----------------------------------------------------------------------------
   352 // -----------------------------------------------------------------------------
   363 //  
   353 //  
   364 TPtrC8 CSConConMLHandler::ReadStrIL()
   354 TPtrC8 CSConConMLHandler::ReadStrIL()
   365     {
   355     {
   366     LOGGER_ENTERFN( "CSConConMLHandler::ReadStrIL()" );
       
   367     iBuffer->Reset();
   356     iBuffer->Reset();
   368     RBufWriteStream bws(*iBuffer);
   357     RBufWriteStream bws(*iBuffer);
   369     TUint8 c;
   358     TUint8 c;
   370     while( (c = ReadUint8L()) != 0 )
   359     while( (c = ReadUint8L()) != 0 )
   371         {
   360         {
   372         bws.WriteUint8L(c);
   361         bws.WriteUint8L(c);
   373         }
   362         }
   374     bws.CommitL();
   363     bws.CommitL();
   375     LOGGER_LEAVEFN( "CSConConMLParser::ReadStrIL()" );
       
   376     return iBuffer->Ptr(0);
   364     return iBuffer->Ptr(0);
   377     }
   365     }
   378     
   366     
   379 // -----------------------------------------------------------------------------
   367 // -----------------------------------------------------------------------------
   380 // CSConConMLHandler::ReadStringTableL()
   368 // CSConConMLHandler::ReadStringTableL()
   381 // Handles the document's string table
   369 // Handles the document's string table
   382 // -----------------------------------------------------------------------------
   370 // -----------------------------------------------------------------------------
   383 //  
   371 //  
   384 void CSConConMLHandler::ReadStringTableL()
   372 void CSConConMLHandler::ReadStringTableL()
   385     {
   373     {
   386     LOGGER_ENTERFN( "CSConConMLHandler::ReadStringTableL()" );
       
   387     delete iStringTable;
   374     delete iStringTable;
   388     iStringTable = NULL;
   375     iStringTable = NULL;
   389     TUint32 strTblLen = ReadMUint32L();
   376     TUint32 strTblLen = ReadMUint32L();
   390 
   377 
   391     if( strTblLen > 0 )
   378     if( strTblLen > 0 )
   398         iStringTable = HBufC8::NewL(strTblLen);
   385         iStringTable = HBufC8::NewL(strTblLen);
   399         TPtr8 ptr = iStringTable->Des();
   386         TPtr8 ptr = iStringTable->Des();
   400         iParseBuffer->Read(iPos, ptr, strTblLen);
   387         iParseBuffer->Read(iPos, ptr, strTblLen);
   401         iPos+=strTblLen;
   388         iPos+=strTblLen;
   402         }
   389         }
   403     LOGGER_LEAVEFN( "CSConConMLHandler::ReadStringTableL()" );
       
   404     }
   390     }
   405     
   391     
   406 // -----------------------------------------------------------------------------
   392 // -----------------------------------------------------------------------------
   407 // CSConConMLHandler::StringTableString()
   393 // CSConConMLHandler::StringTableString()
   408 // Returns a value from the string table according to the given index
   394 // Returns a value from the string table according to the given index
   409 // -----------------------------------------------------------------------------
   395 // -----------------------------------------------------------------------------
   410 //  
   396 //  
   411 TPtrC8 CSConConMLHandler::StringTableString( TUint32 aIndex )
   397 TPtrC8 CSConConMLHandler::StringTableString( TUint32 aIndex )
   412     {
   398     {
   413     LOGGER_ENTERFN( "CSConConMLHandler::StringTableString()" );
       
   414     TPtrC8 temp(iStringTable->Mid(aIndex));
   399     TPtrC8 temp(iStringTable->Mid(aIndex));
   415     TInt pos = temp.Find(KWBXMLNull());
   400     TInt pos = temp.Find(KWBXMLNull());
   416     if( pos != KErrNotFound )
   401     if( pos != KErrNotFound )
   417         {
   402         {
   418         temp.Set(temp.Left(pos));
   403         temp.Set(temp.Left(pos));
   419         }
   404         }
   420     LOGGER_LEAVEFN( "CSConConMLHandler::StringTableString()" );
       
   421     return temp;
   405     return temp;
   422     }
   406     }
   423 
   407 
   424 // -----------------------------------------------------------------------------
   408 // -----------------------------------------------------------------------------
   425 // CSConConMLHandler::HandleElementL()
   409 // CSConConMLHandler::HandleElementL()
   426 // Starts a new element in the document
   410 // Starts a new element in the document
   427 // -----------------------------------------------------------------------------
   411 // -----------------------------------------------------------------------------
   428 //  
   412 //  
   429 void CSConConMLHandler::HandleElementL( TUint8 aId )
   413 void CSConConMLHandler::HandleElementL( TUint8 aId )
   430     {
   414     {
   431     LOGGER_ENTERFN( "CSConConMLHandler::HandleElementL()" );
       
   432     TUint8 tag(TUint8(aId & 0x3f));
   415     TUint8 tag(TUint8(aId & 0x3f));
   433         
   416         
   434     iGenerator->StartElementL( tag );
   417     iGenerator->StartElementL( tag );
   435 
   418 
   436     if( aId & 0x40 ) 
   419     if( aId & 0x40 ) 
   439         }
   422         }
   440     else 
   423     else 
   441         {
   424         {
   442         iGenerator->EndElementL(tag);
   425         iGenerator->EndElementL(tag);
   443         }
   426         }
   444     LOGGER_LEAVEFN( "CSConConMLHandler::HandleElementL()" );
       
   445     }
   427     }
   446 
   428 
   447 // -----------------------------------------------------------------------------
   429 // -----------------------------------------------------------------------------
   448 // CSConConMLHandler::ReadOpaqueL()
   430 // CSConConMLHandler::ReadOpaqueL()
   449 // Reads opaque data from the document
   431 // Reads opaque data from the document
   450 // -----------------------------------------------------------------------------
   432 // -----------------------------------------------------------------------------
   451 //  
   433 //  
   452 TPtrC8 CSConConMLHandler::ReadOpaqueL()
   434 TPtrC8 CSConConMLHandler::ReadOpaqueL()
   453     {
   435     {
   454     LOGGER_ENTERFN( "CSConConMLHandler::ReadOpaqueL()" );
       
   455     iBuffer->Reset();
   436     iBuffer->Reset();
   456     RBufWriteStream bws(*iBuffer);
   437     RBufWriteStream bws(*iBuffer);
   457     TUint32 length = ReadMUint32L();
   438     TUint32 length = ReadMUint32L();
   458     if( iPos+length > iParseBuffer->Size()) 
   439     if( iPos+length > iParseBuffer->Size()) 
   459         {
   440         {
   466     iPos+= length;
   447     iPos+= length;
   467     bws.WriteL(ptr, length);
   448     bws.WriteL(ptr, length);
   468     bws.CommitL();
   449     bws.CommitL();
   469     CleanupStack::PopAndDestroy(1); // data
   450     CleanupStack::PopAndDestroy(1); // data
   470     
   451     
   471     LOGGER_LEAVEFN( "CSConConMLHandler::ReadOpaqueL()" );
       
   472     return iBuffer->Ptr(0);
   452     return iBuffer->Ptr(0);
   473     }
   453     }
   474 
   454