/**
 * Converts the CString to Descriptor
 */
HBufC* CSmsPlatformServiceS60Impl::convertToDes(const char* aData,
        const int aMsgType,
        const int aLength)
{
    HBufC* smsData = 0;
    smsData = HBufC::New(aLength+1);
    if (aData != NULL)
    {
        if (aMsgType == MESSAGE_TEXT)
        {
            TPtr ptr = smsData->Des();
            TPtr16 ptr16((TUint16 *)aData,aLength);
            ptr16.SetLength(aLength);
            ptr.Copy(ptr16);
            ptr.ZeroTerminate();
        }
        else
        {

            TPtr ptr = smsData->Des();
            TPtr8 ptr8((TUint8 *)aData,aLength);
            ptr8.SetLength(aLength);
            ptr.Copy(ptr8);
            ptr.ZeroTerminate();
        }
    }
    return smsData;
}
void ImageSource::setDataL(SharedBuffer* data, bool allDataReceived)
{
    // Make the decoder by sniffing the bytes.
    // This method will examine the data and instantiate an instance of the appropriate decoder plugin.
    // If insufficient bytes are available to determine the image type, no decoder plugin will be
    // made.
    if( !allDataReceived ) return;
    if( !m_decoder )
        // sync decoding if no observer is passed
        m_decoder = CAnimationDecoder::NewL( NULL );
    if( m_decoder ) {
        TPtrC8 ptr( (const TUint8*)data->data(), data->size() );
        TPtrC16 ptr16(m_mimeType.des());        
        m_decoder->OpenL( ptr, &ptr16, ETrue );
    }
}
/* Get certificate info from CX509Certificate.
 */
static void get_cert_info(pj_pool_t *pool, pj_ssl_cert_info *ci,
                          const CX509Certificate *x)
{
    enum { tmp_buf_len = 512 };
    char *tmp_buf;
    unsigned len;
    
    pj_assert(pool && ci && x);
    
    /* Init */
    tmp_buf = new char[tmp_buf_len];
    pj_bzero(ci, sizeof(*ci));
    
    /* Version */
    ci->version = x->Version();
    
    /* Serial number */
    len = x->SerialNumber().Length();
    if (len > sizeof(ci->serial_no)) 
	len = sizeof(ci->serial_no);
    pj_memcpy(ci->serial_no + sizeof(ci->serial_no) - len, 
              x->SerialNumber().Ptr(), len);
    
    /* Subject */
    {
	HBufC *subject = NULL;
	TRAPD(err, subject = x->SubjectL());
	if (err == KErrNone) {
	    TPtr16 ptr16(subject->Des());
	    len = ptr16.Length();
	    TPtr8 ptr8((TUint8*)pj_pool_alloc(pool, len), len);
	    ptr8.Copy(ptr16);
	    pj_strset(&ci->subject.cn, (char*)ptr8.Ptr(), ptr8.Length());
	}
	pj_str_t tmp = get_cert_name(tmp_buf, tmp_buf_len,
				     x->SubjectName());
	pj_strdup(pool, &ci->subject.info, &tmp);
    }

    /* Issuer */
    {
	HBufC *issuer = NULL;
	TRAPD(err, issuer = x->IssuerL());
	if (err == KErrNone) {
	    TPtr16 ptr16(issuer->Des());
	    len = ptr16.Length();
	    TPtr8 ptr8((TUint8*)pj_pool_alloc(pool, len), len);
	    ptr8.Copy(ptr16);
	    pj_strset(&ci->issuer.cn, (char*)ptr8.Ptr(), ptr8.Length());
	}
	pj_str_t tmp = get_cert_name(tmp_buf, tmp_buf_len,
				     x->IssuerName());
	pj_strdup(pool, &ci->issuer.info, &tmp);
    }
    
    /* Validity */
    const CValidityPeriod &valid_period = x->ValidityPeriod();
    TTime base_time(TDateTime(1970, EJanuary, 0, 0, 0, 0, 0));
    TTimeIntervalSeconds tmp_sec;
    valid_period.Start().SecondsFrom(base_time, tmp_sec);
    ci->validity.start.sec = tmp_sec.Int(); 
    valid_period.Finish().SecondsFrom(base_time, tmp_sec);
    ci->validity.end.sec = tmp_sec.Int();
    
    /* Deinit */
    delete [] tmp_buf;
}