Example #1
0
//returns >0 or CONNERR.
int Syscall::httpCreateConnectionLC(const TDesC8& parturl, CHttpConnection*& conn,
	int method, SocketType socketType)
{
	int port_m1_index = parturl.Locate(':');
	int path_index = parturl.Locate('/');
	if(path_index == KErrNotFound) {
		return CONNERR_URL;
	}
	if(port_m1_index > path_index) {
		port_m1_index = KErrNotFound;
	}
	TPtrC8 path(parturl.Mid(path_index));
	int hostname_length;
	TUint16 port;
	if(port_m1_index == KErrNotFound) {
		port = (socketType == SSL) ? 443 : 80;
		hostname_length = path_index;
	} else {
		TLex8 portLex(parturl.Mid(port_m1_index + 1, path_index - (port_m1_index + 1)));
		hostname_length = port_m1_index;
		if(portLex.Val(port, EDecimal) != KErrNone) {
			return CONNERR_URL;
		}
	}
	TPtrC8 hostname(parturl.Left(hostname_length));
	conn = new (ELeave) CHttpConnection(createSocket(socketType), method, port, gHttpStringPool);
	CleanupStack::PushL(conn);
	conn->ConstructL(hostname, path);
	return 1;
}
void CSenPropertiesElement::Set( const TDesC8& aNamespaceURI,
                                 const TDesC8& aLocalName,
                                 const TDesC8& aQName )
    {
    if ( !ipStringPool )
        {
        CSenXmlElement::Set(aNamespaceURI, aLocalName, aQName);
        }
    else
        {
        RString localName;
        TInt leaveCode(KErrNone);
        TRAP( leaveCode, localName = ipStringPool->OpenStringL(aLocalName); )
        if( !leaveCode )
            {
            iLocalName.Close();
            iLocalName = localName;
        
            TPtrC8 prefix(KNullDesC8);
    
            if(aQName != KNullDesC8)
                {
                TInt colon(KErrNotFound);
                colon = aQName.Locate(':');
                if(colon!=KErrNotFound)
                    {
                    prefix.Set(aQName.Left(colon));
                    }
                }
            TRAP( leaveCode, SetNamespaceL(prefix, aNamespaceURI); )
Example #3
0
// -----------------------------------------------------------------------------
// SdpUtil::IsValidCharSet
// Generic checker to validate that string has only valid characters
// -----------------------------------------------------------------------------
//
TBool SdpUtil::IsValidCharSet(
    const TDesC8& aIllegalChars,
    const TDesC8& aValue,
    TInt aStart,
    TInt aEnd)
	{
	TBool result = EFalse;
	
	if ( aIllegalChars.Length() > 0 && aStart >= 0 && 
         aEnd <= aValue.Length() && aStart < aEnd )
		{
		TInt comp = KErrNotFound;
		while (comp == KErrNotFound && aStart < aEnd)
			{
			comp = aIllegalChars.Locate( aValue[aStart] );
			++aStart;
			}
		result = ( comp == KErrNotFound );
		}
	else 
		{
		result = ( ( aStart < aEnd ) && 
                   ( aIllegalChars.Length() == 0 || aValue.Length() == 0 ) );
		}

	return result;
	}
// ----------------------------------------------------------
// CSimplePresenceList::ConstructL
// ----------------------------------------------------------
//
void CSimplePresenceList::ConstructL(
  const TDesC8& aData, const TDesC8& aBoundary, const TDesC8& aStart )
    {       
    _LIT(KUrl, "http://dummy.com/d1/d.html");
           
    // body part array
    RPointerArray<CBodyPart> bodyPartArray;
    // Cleanup-routine
    TCleanupItem clItem( ResetAndDestroy, &bodyPartArray  );
    CleanupStack::PushL( clItem );
    
    // remove "..." characters from boundary if needed
    TPtrC8 pUnQuoted = aBoundary;
    TInt quoted = aBoundary.Locate('"');
    if (!quoted)
        {
        pUnQuoted.Set( aBoundary.Mid( 1, aBoundary.Length() - 2 ));
        } 
        
            
    // parse
    MultipartParser::ParseL( aData, KSimpleMultipartType, pUnQuoted, KUrl, bodyPartArray  );    
    DoConstructL( bodyPartArray, aStart );
   
    CleanupStack::PopAndDestroy( ); // bodyPartArray 
    }
// ----------------------------------------------------------------------------
// CWmDrmDlaParser::ProcessLicenseResponse
// ----------------------------------------------------------------------------
//
TInt CWmDrmDlaParser::ProcessLicenseResponse(
    const TDesC8& aLicenseResponse,
    HBufC8*& aTID,
    HBufC8*& aContentURL)
    {
    TInt error = KErrNone;
    
    LOGFNR( "CWmDrmDlaParser::ProcessLicenseResponse", error );
    
    // Find beginning of XML document ('<')
    TInt pos = aLicenseResponse.Locate( '<' );
    if ( pos != KErrNotFound )
      {
      iContentUrl = &aContentURL;
      iTID = &aTID;
      iErrorCode = KErrNone;
      TPtrC8 ptrUrl = aLicenseResponse.Mid( pos );
      TRAP( error, Xml::ParseL( *iParser, ptrUrl ) );
      if ( !error )
        {
        error = iErrorCode;
        }

      iTID = NULL;
      iContentUrl = NULL;

      delete iServerUrl;
      iServerUrl = NULL;
      }
    else
      {
      error = KErrCorrupt;
      }
    return error;
    }
Example #6
0
void CPppMsChap2::ChallengeHashL(const TDesC8& aPeerChallenge,
                                 const TDesC8& aAuthenticatorChallenge,
                                 const TDesC8& aUserName,
                                 TDes8& aChallengeHash)
/**
   Computes the hash of the Peer Challenge, Authenticator Challenge
   and username using SHA-1.
   @param aPeerChallenge [in] The Peer Challenge (16 octets).
   @param aAuthenticatorChallenge [in] The Authenticator Challenge (16
   octets).
   @param aUserName [in] The Microsoft Windows NT username (0 to 256
   char).
   @param aChallengeHash [out] The hash of the peer challenge,
   authenticator challenge and username, computed using SHA-1 (8
   octets).
   @note This function implements the ChallengeHash routine specified
   in RFC 2759.
   @internalComponent
*/
{
    ASSERT(aPeerChallenge.Length() ==
           KPppMsChap2PeerChallengeSize);
    ASSERT(aAuthenticatorChallenge.Length() ==
           KPppMsChap2AuthenticatorChallengeSize);
    ASSERT(aUserName.Length() <= KPppMsChapMaxNTUserNameLength);
    ASSERT(aChallengeHash.Length()==KPppMsChap2ChallengeHashSize);

    CSHA1* sha1 = CSHA1::NewL();
    CleanupStack::PushL(sha1);

// RFC 2759: "Only the user name (as presented by the peer and
// excluding any prepended domain name)"
    TPtrC8 userName(aUserName);
    TInt i = aUserName.Locate('\\');
    if (i >= 0 && i < userName.Length() - 1)
        userName.Set(aUserName.Mid(i + 1));
    else if (i >= userName.Length() - 1)
        User::Leave(KErrGeneral);


    sha1->Update(aPeerChallenge);
    sha1->Update(aAuthenticatorChallenge);

    aChallengeHash.Copy(sha1->Final(userName).Ptr(),
                        KPppMsChap2ChallengeHashSize);


    CleanupStack::PopAndDestroy(sha1);

    ASSERT(aChallengeHash.Length()==KPppMsChap2ChallengeHashSize);
}
// -----------------------------------------------------------------------------
// TSdpRtpmapValue::DecodeL
// Decodes string and puts it into parts
// -----------------------------------------------------------------------------
//
EXPORT_C TSdpRtpmapValue TSdpRtpmapValue::DecodeL( 
    const TDesC8& aText )
    {
    __ASSERT_ALWAYS(aText.Length() > 0 && 
                    aText.Locate( KSlashChar ) != KErrNotFound, 
        User::Leave(KErrSdpCodecMediaAttributeField));

    TInt length( aText.Length() );
    if ( aText[length - 1] == KLFChar )
        {
        if ( length > 1 && aText[length - 2] == KCRChar )
            {
            length--;
            }
        length--;
        }  
    TPtrC8 restValue( aText.Left( length ) );

    __ASSERT_ALWAYS(SdpUtil::IsByteString(restValue), 
                    User::Leave(KErrSdpCodecMediaAttributeField)); 

    TInt pos = restValue.Locate( KSlashChar );
    
    // <encoding name>
    TPtrC8 encName( restValue.Left( pos ) );    
    
    restValue.Set( restValue.Right( restValue.Length() - pos - 1 ) );
    pos = restValue.Locate( KSlashChar );

    // <clock rate> <encoding parameters>
    TPtrC8 encParam( KNullDesC8 );
    TPtrC8 clockRate( KNullDesC8 );
   
    if ( pos == KErrNotFound )
        {              
        clockRate.Set( restValue );      
        
        __ASSERT_ALWAYS( clockRate.Length() > 0 && encParam.Length() == 0,
                         User::Leave( KErrSdpCodecMediaAttributeField ) );          
        }
    else
        {
        clockRate.Set( restValue.Left( pos ) );      
        encParam.Set( restValue.Right( restValue.Length() - pos - 1 ) );

        __ASSERT_ALWAYS( clockRate.Length() > 0 && encParam.Length() > 0,
                         User::Leave( KErrSdpCodecMediaAttributeField ) );
        }
   
    return TSdpRtpmapValue( encName, clockRate, encParam );
    }
Example #8
0
// -----------------------------------------------------------------------------
// SdpUtil::IsValidChars
// Checks if all the charcaters on the descriptor are from valid charset
// -----------------------------------------------------------------------------
//
TBool SdpUtil::IsValidChars( 
    const TDesC8& aValidChars, 
    const TDesC8& aDes )
    {
    TBool valid( aDes.Length() > 0 );
    for ( TInt i( 0 ); i < aDes.Length() && valid; i++ )
        {
        if ( aValidChars.Locate( aDes[i] ) == KErrNotFound )
            {
            valid = EFalse;
            }
        }

    return valid;
    }
Example #9
0
bool splitPurl(const TDesC8& parturl, TPtrC8& hostnamePtrC8, int& port, int portMax) {
	int port_m1_index = parturl.Locate(':');
	if(port_m1_index == KErrNotFound) {
		return false;
	}
	TLex8 portLex(parturl.Mid(port_m1_index + 1));

	//port = atoi(port_m1 + 1);
	int result = portLex.Val(port);
	if(result != KErrNone || port <= 0 || port >= portMax) {
		return false;
	}

	hostnamePtrC8.Set(parturl.Left(port_m1_index));
	return true;
}
Example #10
0
/**
	@internalComponent

	Parses a segment of the form name=value and returns the name and value parts
	
	@param			aSegment	the name-value segemnt to parse
	@param			aName		the name part that is returned
	@param			aValue		the value part that is returned
 */
void GetNameValuePair(const TDesC8& aSegment, TPtrC8& aName, TPtrC8& aValue)
	{
	TPtrC8 value;
	TInt sepPos = aSegment.Locate(KEqualsSeparator);
	if (sepPos != KErrNotFound)
		{
		aName.Set(aSegment.Left(sepPos));
		value.Set(aSegment.Mid(sepPos+1));
		}
	else
		{
		aName.Set(aSegment);
		}

	aValue.Set(value);
	}
void CHttpClientHeaderReader::SetCookieNameAndValueL(CHeaderFieldPart& aCookie, const TDesC8& aNameValue) const
	{

	TInt equalPos = aNameValue.Locate('=');
	if (equalPos <= 0)
		User::Leave(KErrHttpDecodeCookie);

	TPtrC8 nameVal(aNameValue.Left(equalPos));
	InetProtTextUtils::RemoveWhiteSpace(nameVal, InetProtTextUtils::ERemoveBoth);
	TPtrC8 name(iStrPool.StringF(HTTP::ECookieName,iStringTable).DesC());
	SetNewStringParamL(aCookie, name ,nameVal);

	TPtrC8 valueVal(aNameValue.Right(aNameValue.Length() - (equalPos+1)));
	InetProtTextUtils::RemoveWhiteSpace(valueVal, InetProtTextUtils::ERemoveBoth);
	TPtrC8 value(iStrPool.StringF(HTTP::ECookieValue,iStringTable).DesC());
	SetNewStringParamL(aCookie, value ,valueVal);
	}
Example #12
0
void CHttpConnection::HeaderLineHandlerL(const TDesC8& line) {
	LOGS("Handling header line \"%S\"\n", &line);
	if(line.Length() == 0) {
		CompleteReadHeaders(0, KErrNone);
		mState = FINISHED;
		return;
	}
	//format: "key: value"
	//const char* colon = strchr(baseLine, ':');
	int colonIndex = line.Locate(':');
	if(colonIndex != KErrNotFound) if(line[colonIndex + 1] != ' ')
		colonIndex = KErrNotFound;
	if(colonIndex == KErrNotFound) {
		LOG("HTTP bad header line: \"%S\"\n", &line);
		CompleteReadHeaders(CONNERR_PROTOCOL, 0);
		return;
	}
	TPtrC8 key(line.Left(colonIndex));
	TPtrC8 value(line.Mid(colonIndex + 2));
	LOGS("HTTP header %S: %S\n", &key, &value);

	//lower-case
	TCleaner<HBufC8> keyBuf(HBufC8::NewLC(key.Length()));
	keyBuf->Des().CopyLC(key);

	//if the key is already present, comma-combine the values.
	const TDesC8* oldValue = mResponseHeaders.find(*keyBuf);
	if(oldValue != NULL) {
		LOGS("Combined!\n");
		//value = itr->second + ", " + value;
		_LIT(KCommaSpace, ", ");
		TCleaner<HBufC8> combBuf(HBufC8::NewLC(oldValue->Length() + KCommaSpace().Length() +
			value.Length()));
		TPtr8 combPtr(combBuf->Des());
		combPtr.Append(*oldValue);
		combPtr.Append(KCommaSpace);
		combPtr.Append(value);
		mResponseHeaders.erase(*keyBuf);
		mResponseHeaders.insert(*keyBuf, combPtr);
	} else {
		mResponseHeaders.insert(*keyBuf, value);
	}
}
Example #13
0
// -----------------------------------------------------------------------------
// SdpUtil::IsTokenCharWithOptionalSlash
// Checks if all the possible two elements divided by slash are valid tokens
// -----------------------------------------------------------------------------
//
TBool SdpUtil::IsTokenCharWithOptionalSlash(const TDesC8& aValue)
	{
	TInt lineEndPosition = aValue.Locate('/');

	if ( lineEndPosition != KErrNotFound )
		{
		TPtrC8 firstToken( aValue.Left( lineEndPosition ) );
		if( !IsTokenChar( firstToken ) ||
		    !IsTokenChar( aValue.Mid( lineEndPosition + 1 ) ) )
			{
			return EFalse;
			}
		}
	else
		{
		return IsTokenChar( aValue );
		}
	return ETrue;
	}
void CSenPropertiesElement::BaseConstructL(const TDesC8& aNsUri,
                                           const TDesC8& aLocalName,
                                           const TDesC8& aQName,
                                           RStringPool* aStringPool)
    {
    ipStringPool = aStringPool;

    if (aLocalName == KNullDesC8)
        {
        User::Leave(KErrSenZeroLengthDescriptor);
        }
    SenXmlUtils::LeaveOnXmlEscapesL(aLocalName);

    if (aQName == KNullDesC8)
        {
        User::Leave(KErrSenZeroLengthDescriptor);
        }
    SenXmlUtils::LeaveOnXmlEscapesL(aQName);

    if ( ipStringPool )
        {
        iLocalName = ipStringPool->OpenStringL(aLocalName);
        }
    else
        {
        Set(KNullDesC8, aLocalName, aLocalName);
        }
    TPtrC8 ptrPrefix(KNullDesC8);

    if (aQName.Length() > 0 )
        {
        TInt colon = aQName.Locate(':');
        if (colon > 0) // Note: 0 also treated as no prefix
            {
            ptrPrefix.Set(aQName.Ptr(),colon);
            }
        }

    SetNamespaceL(ptrPrefix, aNsUri);    
    }
// ----------------------------------------------------------------------------
// CWmDrmDlaParser::GetLicenseServerURLFromDRMHeader
// ----------------------------------------------------------------------------
//
TInt CWmDrmDlaParser::GetLicenseServerURLFromDRMHeader(
    const TDesC8& aDrmHeader,
    HBufC8*& aServerURL )
    {
    TInt error( KErrNone );
    
    LOGFNR( "CWmDrmDlaParser::GetLicenseServerURLFromDRMHeader", error );
    
    // Find beginning of XML document ('<')
    TInt pos = aDrmHeader.Locate( '<' );
    if ( pos != KErrNotFound )
        {
        iServerUrl = &aServerURL;
        iErrorCode = KErrNone;
        TPtrC8 ptrUrl = aDrmHeader.Mid( pos );
        TRAP( error, Xml::ParseL( *iParser, ptrUrl ) );
        if ( !error )
            {
            error = iErrorCode;
            }

        iServerUrl = NULL;

        delete iTID;
        iTID = NULL;

        delete iContentUrl;
        iContentUrl = NULL;
        }
    else
        {
        error = KErrCorrupt;
        }

    return error;
    }
// ---------------------------------------------------------------------------------
// CUpnpTmFilteredAppList::ParseAppFilterStringL
// Method parses the descriptor containing the filter string
// It parses the comma-separated list of A_ARG_TYPE_AppList schema 
// elements, attributes and their values
// eg: "name="*Audio*",description="*",icon@mimetype="*svg+xml*", remotingInfo@protocolID="*",
//     appInfo@appCategory="*",audioInfo@audioType="*",resourceStatus="free",signature="*""
// @param aAppFilter Buffer containing application filter string
// @param aErr[out]  Terminal Mode error code
// ---------------------------------------------------------------------------------
//
void CUpnpTmFilteredAppList::ParseAppFilterStringL( const TDesC8& aAppFilter, 
                                                     TTerminalModeErrorCode& aErr )
    {
    OstTraceFunctionEntry0( CUPNPTMFILTEREDAPPLIST_PARSEAPPFILTERSTRINGL_ENTRY );
    // Validate the filter string
    aErr = ETerminalModeSuccess;
    TInt quotePos = aAppFilter.Locate( KQuote );
    if ( ( quotePos != 0 ) || ( aAppFilter.Find(KDoubleQuote) == KErrNotFound ))    
        {
        // corrupt filter string
        aErr = ETerminalModeInvalidArgument;
        OstTrace1( TRACE_ERROR, DUP2_CUPNPTMFILTEREDAPPLIST_PARSEAPPFILTERSTRINGL, "CUpnpTmFilteredAppList::ParseAppFilterStringL;quotePos=%d", quotePos );
        return;
        }
    RBuf8 filterBuffer;
    CleanupClosePushL(filterBuffer);
    /* Create a buffer having the content of AppFilter buffer but without 
       the leading quote(")  */ 
    filterBuffer.CreateL(aAppFilter.Mid(quotePos+1));
    TInt equalToQuoteToken;
    while( ( equalToQuoteToken = filterBuffer.Find(Keq)) != KErrNotFound )
        {
        // Fetch the full key string
        TPtrC8 key = filterBuffer.Left(equalToQuoteToken);
        // Check for the presence of sub element by checking the @ in the key string
        TInt atTokenPos = key.Find(KAtToken);
        TBool displayInfo(EFalse);
        if ( atTokenPos != KErrNotFound )
            {
            // @ is found in the key string
            // Now extract the parent element
            TPtrC8 parentKey = key.Left(atTokenPos);
            //Remove any leading and trailing whitespaces in the parent element
            const TDesC8& parentKeyWithoutSpace = RemoveWhiteSpace(parentKey);
            // Check if the parent elemet is one of desired element or not.
            // It should be one of the following :
            // <1> icon <2> remotingInfo <3> appInfo <4> displayInfo <5> audioInfo
            if ( ( parentKeyWithoutSpace.Compare(KIconElement) != KErrNone ) &&
                ( parentKeyWithoutSpace.Compare(KRemotingInfo) != KErrNone ) &&
                ( parentKeyWithoutSpace.Compare(KAppInfo) != KErrNone ) &&
                ( parentKeyWithoutSpace.Compare(KDisplayInfo) != KErrNone ) &&
                ( parentKeyWithoutSpace.Compare(KAudioInfo) != KErrNone ) )
                {
                // parent element is not proper
                aErr = ETerminalModeInvalidArgument;   
                break;
                }
            if ( parentKeyWithoutSpace.Compare(KDisplayInfo) == KErrNone )
                {
                // The parent key element is displayInfo
                displayInfo = ETrue;   
                }
            // Fetch the actual key name ( child element )
            key.Set(key.Mid(atTokenPos+1));
            }
        
        //Remove any leading and trailing whitespaces in the key 
        const TDesC8& keyWithoutSpace = RemoveWhiteSpace(key);
        if ( (filterBuffer.Mid(equalToQuoteToken) ).Locate(KQuote) != 1 )
            {
            // Missing quote(") ahead of the value
            aErr = ETerminalModeInvalidArgument;
            break;    
            }
        TPtrC8 bufPtr = filterBuffer.Mid(equalToQuoteToken+2);
        quotePos = bufPtr.Locate( KQuote );
        if ( quotePos == KErrNotFound )
            {
            // missing quote (") at the end of the value
            aErr = ETerminalModeInvalidArgument;
            break;
            }
        
        /* Add the filter info as key-value pairs.
        // Also check if the parent key is display info.
           If display info flag is true then use the method with non default parameter */
        if ( displayInfo )
            {
            iFilterInfo->SetFilterInfoL( keyWithoutSpace, bufPtr.Left(quotePos), aErr, ETrue );
            }
        else
            {
            // Use the method with default parameter
            iFilterInfo->SetFilterInfoL( keyWithoutSpace, bufPtr.Left(quotePos), aErr );   
            }
        if ( aErr != ETerminalModeSuccess )
            {
            // Return the error code in case the key element is not as per the schema
            aErr = ETerminalModeInvalidArgument;
            break;
            }
        // Skip the quote position and set the buffer
        bufPtr.Set(bufPtr.Mid(quotePos+1));
        if ( ( bufPtr.Locate(KCommaSeparator) != 0 ) && ( bufPtr.Locate(KQuote) != 0 ) )
            {
            //  missing quote (") or comma (,) following the quote.
            //  Expected to be something of this kind ( ", or "" )
            aErr = ETerminalModeInvalidArgument;
            break;      
            }
        //Copy the residual content skipping two characters(", or "" ) in the actual buffer
        filterBuffer.Copy(bufPtr.Mid(UpnpString::KLinefeedLength));
        }
    CleanupStack::PopAndDestroy(&filterBuffer);
    OstTrace1( TRACE_FLOW, CUPNPTMFILTEREDAPPLIST_PARSEAPPFILTERSTRINGL, "CUpnpTmFilteredAppList::ParseAppFilterStringL;aErr=%d", aErr );
    OstTraceFunctionExit0( CUPNPTMFILTEREDAPPLIST_PARSEAPPFILTERSTRINGL_EXIT );
    }
// ----------------------------------------------------------
// CSimplePresenceList::DoConstructL
// ----------------------------------------------------------
//    
void CSimplePresenceList::DoConstructL( 
    RPointerArray<CBodyPart>& aParts, const TDesC8& aStart )
    {
    
    _LIT8( KMyContentType, "Content-Type: multipart/related;");  
    _LIT8( KMyBoundary, "boundary="); 
    
    const TInt myBoundaryLen = 9;   // boundary=  9 characters         
       
    // Handle body parts one by one
    TInt size = aParts.Count();
    TInt i;
    CBodyPart* cp = NULL;
    TPtrC8 boundary;
    TPtrC8 start;
    
    // remove "..." quoted marks when needed
    TPtrC8 pStartUnquoted( KNullDesC8 );
    if ( aStart.Locate( '"') == 0 )
        {
        pStartUnquoted.Set( aStart.Mid( 1, aStart.Length() - 2 ));
        }
    else
        {
        pStartUnquoted.Set( aStart );        
        } 

    // remove <...> marks when needed
    if ( pStartUnquoted.Locate( '<') == 0 )
        {
        pStartUnquoted.Set( pStartUnquoted.Mid( 1, pStartUnquoted.Length() - 2 ));
        } 
    
    TPtrC8 p8;
    p8.Set( KSimpleDocumentType );
    TInt mySize = p8.Length();
    p8.Set( KSimpleMultipartType );
    TInt mySize2 = p8.Length();    
          
#ifdef _DEBUG                
    TPtrC p16b; // notice: for debug
    TPtrC8 p8b;
#endif 

// Make this handle direct content too in the RLMI list, i.e. 
// content-type: multipart/related; type="application/pidf+xml"; boundary=...;
    for (i = 0; i < size; i++)
        {
        cp = aParts[i];
        // inline const TDesC8& Headers() { return iHeaders; }
        TPtrC8 allHeaders = cp->Headers();
        HBufC8* headersBuff = allHeaders.AllocL();
        CleanupStack::PushL( headersBuff );
               
#ifdef _DEBUG        
        p16b.Set( cp->Url() ); // debug only
        p8b.Set( cp->ContentType() ); // debug only
        p8b.Set( cp->ContentID() ); // debug only
#endif                         
        if ( !pStartUnquoted.Compare( cp->ContentID()) &&
             !cp->ContentType().Left(sizeof(KSimpleListType)).CompareF( KSimpleListType ))
            {
            // Meta data is the root         
            iMeta = CSimpleMeta::NewL( cp->Body() );                               
            }
        else if ( !cp->ContentType().CompareF( KSimpleDocumentType ))
            {
            // Ordinary presence element                    
            CSimpleDocument* cd = CSimpleDocument::NewL( cp->Body() );             
            CleanupStack::PushL( cd );           
            User::LeaveIfError( iDocuments.Append( cd ) );
            CleanupStack::Pop( cd );
            }             
        else if ( (!cp->ContentType().Left(mySize2).CompareF( KSimpleMultipartType ))) 
            {
            // multipart for user's direct content data
            // get boundary from headers
            TPtrC8 pStart(KNullDesC8);
            TPtrC8 pBoundary(KNullDesC8);          
            
            TPtrC8 pHeaders = headersBuff->Des();
            TPtrC8 pContentType;
            TInt pos1 = pHeaders.Find( KMyContentType );
            if ( pos1 >= 0 )
                {
                TPtrC8 h2 = pHeaders.Mid( pos1 );
                TInt pos2 = h2.Locate( '\r');
                if ( pos2 < 0 )
                    {
                    pContentType.Set( h2 );
                    }
                else
                    {
                    pContentType.Set( h2.Left( h2.Length() - pos2 ));                    
                    }    
                                                                
                // search boundary 
                TInt posx = pContentType.Find( KMyBoundary );
                if ( posx >= 0 )
                    {                    
                    TPtrC8 h5 = pContentType.Mid( posx );
                    TInt pos5 = h5.Locate( ';');
                    if ( pos5 < 0 )
                        {
                        // There are no more parameters
                        pBoundary.Set( h5.Mid( myBoundaryLen )); 
                        }
                    else
                        {
                        // There are more in the line, has to cut off                        
                        pBoundary.Set( h5.Mid( myBoundaryLen, pos5 - myBoundaryLen ));                        
                        }    
                    }                 
                }
            
            // "..." characters are removed later from boundary in NewInMultiPartL(
            CSimpleDocument* cd = CSimpleDocument::NewInMultiPartL( cp->Body(), pBoundary, pStart );
            CleanupStack::PushL( cd );           
            User::LeaveIfError( iDocuments.Append( cd ) );
            CleanupStack::Pop( cd );            
                        
            }        
        /* notice: later nested multiparts if type = rlmi   */
        else
            {
            // This is something that should not be in the document.
            // Ignore it.
            } 
        CleanupStack::PopAndDestroy( headersBuff );                             
        }    
    }
/**
Parse the flags data and update to iFlags.
@param aFlagsData contains list of flags to be parsed.
@return The remaining portion of the aFlagsData parameter that was not parsed.
*/
TPtrC8 TMessageFlagInfo::ParseFlagsL(const TDesC8& aFlagsData)
	{
	// formal definition of the FLAGS data item of a FETCH FLAGS is
	//
	// msg-att-dynamic = "FLAGS" SP "(" [flag-fetch *(SP flag-fetch)] ")"
	//
	// flag-fetch = flag / "\Recent"
	// flag = "\Answered" / "\Flagged" / "\Deleted" / "\Seen" / "\Draft" / flag-keyword / flag-extension
	// flag-extension = "\" atom
	// flag-keyword = atom
	//
	//

	TPtrC8 parseData(aFlagsData);
	
	TInt start = aFlagsData.Locate('(');
	TInt end = aFlagsData.Locate(')');

	// Reset the flags, prior to setting them.
	iFlags = 0;

	// Now set them.
	if ((start >= 0) && (end > start))
		{
		RDesParts flags;
		CleanupClosePushL(flags);
		
		// lose the brackets
		parseData.Set(aFlagsData.Mid(start+1, end-start-1));
		
		CImapCommand::GetDelimitedPartsL(' ', parseData, flags);
		TInt flagsCount = flags.Count();
		for (TInt i = 0; i < flagsCount; ++i)
			{
			TPtrC8 flag = flags[i];

			if(flag.CompareF(KImapTxtFlagDeleted) == 0)
				{
				SetFlag(TMessageFlagInfo::EDeleted, ETrue);
				}
			else if (flag.CompareF(KImapTxtFlagSeen) == 0)
				{
				SetFlag(TMessageFlagInfo::ESeen, ETrue);
				}
			else if(flag.CompareF(KImapTxtFlagFlagged) == 0)
				{
				SetFlag(TMessageFlagInfo::EFlagged, ETrue);			
				}
			else if(flag.CompareF(KImapTxtFlagAnswered) == 0)
				{
				SetFlag(TMessageFlagInfo::EAnswered, ETrue);
				}
			else if(flag.CompareF(KImapTxtFlagDraft) == 0)
				{
				SetFlag(TMessageFlagInfo::EDraft, ETrue);
				}
			else if(flag.CompareF(KImapTxtFlagRecent) == 0)
				{
				SetFlag(TMessageFlagInfo::ERecent, ETrue);	
				}
			}

		// return the remainder.
		// if there is a space after the closing bracket, 
		// then remainder should start after the space.
		if (aFlagsData.Length() > end + 1)
			{
			if (aFlagsData[end+1] == ' ')
				{
				++end;
				}
			}		
		
		if (aFlagsData.Length() > end)
			{
			parseData.Set(aFlagsData.Mid(end + 1));
			}
		else
			{
			parseData.Set(aFlagsData.Right(0));
			}
			
		CleanupStack::PopAndDestroy(&flags);
		}

	return parseData;
	}
Example #19
0
void CHTTPSession::InitializeFiltersL(const TDesC8& aProtocol)
	{
	__START_PERFORMANCE_LOGGER();
	const TChar protocolSeparatorChar = '/';
	// Get list of ECOM plugins that match the interface UID
	REComSession::ListImplementationsL(KUidFilterPluginInterface, iEComFilterInfoArray);

	// Locate the protocol separator and return with errorcode if its not found as its invalid
	const TInt clientProtSeparator = aProtocol.Locate(protocolSeparatorChar);
	if( clientProtSeparator == KErrNotFound )
		User::Leave(KErrNotFound);

	// Store the protocol provided by the client
	TPtrC8 clientProtocol(aProtocol.Left(clientProtSeparator));

	// Loop through all the filter plugins found by ECom
	const TInt filterCount = iEComFilterInfoArray.Count();
	for(TInt ii=0; ii<filterCount; ++ii)
		{
		// Get the descriptor with the filter datatype
		TPtrC8 filterProtocol(iEComFilterInfoArray[ii]->DataType());

		// Find the protocol in the data type, if thats not found then find the TFCORE data type
		TInt protocolDataTypeStart = filterProtocol.FindF(clientProtocol);
		TInt protocolLength = clientProtocol.Length();
		if( protocolDataTypeStart == KErrNotFound )
			{
			protocolDataTypeStart = filterProtocol.FindF(KTxtCoreFilterProtocol());
			protocolLength = KTxtCoreFilterProtocol().Length();
			}

		// Build table of plugins of core and specified protocol filters
		if( protocolDataTypeStart > KErrNotFound )
			{
			// Set the offset for the beginning of the filter type and check that the seperator exists
			TInt offset = protocolDataTypeStart + protocolLength;
			if( filterProtocol[offset] != STATIC_CAST(TUint8, protocolSeparatorChar) )
				User::Leave(KErrNotFound);
			// Increment the offset for the seperator
			++offset;

			// Ensure that there is data after the seperator
			if( filterProtocol.Length() <= offset )
				User::Leave(KErrNotFound);

			// Create a TSessionFilterInfo with the filter plugin data and append to client array
			TSessionFilterInfo* filterInfo = new(ELeave) TSessionFilterInfo;
			CleanupStack::PushL(filterInfo);

			// Set the filter properties
			filterInfo->iFilterInfo = iEComFilterInfoArray[ii];
			// Get the category of the filter from the filter data type
			const TUint KTxtExplicitChar = '-';
			const TUint KTxtMandatoryChar = '+';
			TChar filterSymbol(filterProtocol[offset]);
			if( filterSymbol==KTxtExplicitChar)
				{
				filterInfo->iCategory = TSessionFilterInfo::EExplicit;
				filterInfo->iFilterPlugin = NULL;
				}
			else if( filterSymbol==KTxtMandatoryChar )
				{
				filterInfo->iCategory = TSessionFilterInfo::EMandatory;
				// Install the filter
				// This should leave as the filter is mandatory
				filterInfo->iFilterPlugin = CEComFilter::InstallFilterL(this->Handle(), iEComFilterInfoArray[ii]->ImplementationUid());
				}
			else
				{
				filterInfo->iCategory = TSessionFilterInfo::EImplicit;
				// Install the filter
				// This is trapped if it leaves as the transport framework should be able to plough on without it
				// But leave if the error is KErrNoMemory.
				TRAPD ( err, filterInfo->iFilterPlugin = CEComFilter::InstallFilterL(this->Handle(), iEComFilterInfoArray[ii]->ImplementationUid()) );
				if ( err == KErrNoMemory )
					{
					User::Leave ( err );
					}
				}

			// Add the filter information to the list
			User::LeaveIfError(iFilterInfoList.Append(filterInfo));
			CleanupStack::Pop(filterInfo);
			}
		}
	__END_PERFORMANCE_LOGGER(_L(",CHTTPSession::InitializeFiltersL()"));
	}