messagingappbase/smartmessaging/vrec/src/vrec.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 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:  
       
    15 *    Recognizer for vCalendar and vCard.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <apmrec.h>
       
    23 #include <apmstd.h>
       
    24 #include "vrec.h"
       
    25 #include "VRecLog.h"
       
    26 
       
    27 #include <e32std.h>
       
    28 #include <ecom/ecom.h>
       
    29 #include <ecom/implementationproxy.h>
       
    30 
       
    31 // CONSTANTS
       
    32 const TUid KUidVREC   = {0x101F4CF5};
       
    33 
       
    34 // maximum amount of buffer space we will ever use
       
    35 // Value estimated on observation of iCal userid lengths
       
    36 const TInt KMaxBufferLength        = 255;
       
    37 
       
    38 const TText8* const mimeTypes[] =
       
    39     {
       
    40 	_S8("text/X-vCard"),
       
    41     _S8("text/calendar"),   // iCalendar MIME type (RFC 2445)
       
    42     _S8("text/x-vCalendar") // vCalendar v1.0 MIME type
       
    43     };
       
    44 
       
    45 _LIT8(KDataTypeVCard,      "text/X-vCard");
       
    46 _LIT8(KDataTypeVCalendar2, "text/x-vCalendar"); // vCalendar v1.0 MIME type
       
    47 _LIT8(KDataTypeVCalendar3, "text/calendar"); // vCalendar v2.0 MIME type
       
    48 
       
    49 _LIT8(KBegin,          "BEGIN");
       
    50 _LIT8(KVCalendar,      "VCALENDAR");
       
    51 _LIT8(KBeginVCard,      "BEGIN:VCARD");
       
    52 _LIT8(KVersionICal,		"VERSION:2.0");
       
    53 
       
    54 /**
       
    55 * VCalendar definition from vCalendar spec v1.0
       
    56 * ws = 1*(SPACE / HTAB)
       
    57 * wsls = 1*(SPACE / HTAB / CRLF)
       
    58 * vcal_file = [wsls] vcal [wsls]
       
    59 * vcal = "BEGIN"[ws]":"[ws] "VCALENDAR" [ws] 1*CRLF
       
    60 *        calprop calenties [ws] *CRLF
       
    61 *       "END" [ws] ":" [ws] "VCALENDAR" [ws] 1*CRLF
       
    62 */
       
    63 // ============================ MEMBER FUNCTIONS ===============================
       
    64 CVRec::CVRec()
       
    65     :CApaDataRecognizerType(KUidVREC, CApaDataRecognizerType::ELow)
       
    66     {
       
    67     iCountDataTypes = sizeof(mimeTypes)/sizeof(TText*);
       
    68     LOG1("CVRec::iCountDataTypes: %d", iCountDataTypes);
       
    69     }
       
    70 
       
    71 TUint CVRec::PreferredBufSize()
       
    72     {
       
    73     return KMaxBufferLength;
       
    74     }
       
    75 
       
    76 TDataType CVRec::SupportedDataTypeL(TInt aIndex) const
       
    77     {
       
    78     __ASSERT_DEBUG(aIndex>=0 && aIndex<iCountDataTypes, User::Invariant());
       
    79     TPtrC8 ptr;
       
    80     ptr.Set(mimeTypes[aIndex]);
       
    81 	return TDataType(ptr);
       
    82     }
       
    83 
       
    84 void CVRec::DoRecognizeL(const TDesC& /*aName*/, const TDesC8& aBuffer)
       
    85     {
       
    86     LOG1("CVRec::DoRecognizeL: %S", &aBuffer);
       
    87     TInt length = aBuffer.Length();
       
    88     
       
    89     // The vCalendar header is longer than the vCard header.
       
    90     TInt lengthNeeded = KBeginVCard().Length();
       
    91     if (length < lengthNeeded)
       
    92         {
       
    93         // not enough data for it to be a vCard or vCalendar or iCalendar
       
    94         return;
       
    95         }
       
    96         
       
    97     TPtrC8 data = aBuffer.Left(KMaxBufferLength);
       
    98     
       
    99     TInt posVCard = data.FindF( KBeginVCard );
       
   100     
       
   101     //the position must be at the beginning of the file
       
   102     if (posVCard == 0)
       
   103     	{
       
   104         iDataType   = TDataType(KDataTypeVCard);
       
   105         iConfidence = ECertain;
       
   106         return;
       
   107         }
       
   108     else if (posVCard != KErrNotFound)
       
   109     	{
       
   110     	iConfidence = ENotRecognized;
       
   111     	return;
       
   112     	}
       
   113     	
       
   114     if (data.FindF(KBegin) != KErrNotFound && 
       
   115     	data.FindF(KVCalendar) != KErrNotFound && 
       
   116     	data.FindF(KVersionICal) != KErrNotFound)
       
   117 		{
       
   118 	    iDataType   = TDataType(KDataTypeVCalendar3);
       
   119 	    iConfidence = ECertain;
       
   120 	    return;
       
   121         }
       
   122     else if (data.FindF(KBegin) != KErrNotFound && 
       
   123     		 data.FindF(KVersionICal) == KErrNotFound && 
       
   124     		 data.FindF(KVCalendar) != KErrNotFound)
       
   125         {
       
   126         iDataType   = TDataType(KDataTypeVCalendar2);
       
   127         iConfidence = ECertain;
       
   128         return;
       
   129         }
       
   130     else
       
   131         {
       
   132         iConfidence = ENotRecognized;
       
   133         return;
       
   134         }
       
   135     }
       
   136     
       
   137 CApaDataRecognizerType* CVRec::CreateRecognizerL()
       
   138 	{
       
   139 	return new (ELeave) CVRec ();
       
   140 	}
       
   141 
       
   142 const TImplementationProxy ImplementationTable[] =
       
   143 	{
       
   144 #ifdef __EABI__
       
   145         IMPLEMENTATION_PROXY_ENTRY( 0x101F879A, CVRec::CreateRecognizerL )
       
   146 #else
       
   147 		{ { 0x101F879A }, CVRec::CreateRecognizerL }
       
   148 #endif
       
   149 	};
       
   150 
       
   151 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   152     {
       
   153     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   154     return ImplementationTable;
       
   155     }
       
   156 
       
   157 
       
   158 
       
   159 
       
   160 
       
   161 // end of file