webservices/wsnotifierplugins/src/sennotplugindlg.cpp
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 // INCLUDE FILES
       
    26 #include "sennotplugindlg.h"
       
    27 
       
    28 // Epoc DLL entry point, return that everything is ok
       
    29 #ifndef EKA2
       
    30 GLDEF_C TInt E32Dll(TDllReason)
       
    31     {
       
    32     return(KErrNone);
       
    33     }
       
    34 #endif
       
    35     
       
    36 
       
    37 /******************************************************************************
       
    38  *              TSenNotPluginMessage implementation
       
    39  *****************************************************************************/
       
    40 
       
    41 // Serialize 16-bit buffer in the format <E16BitDescriptor><length><data>
       
    42 void TSenNotPluginMessage::AppendBuf16(const TDesC& aBuf)
       
    43     {
       
    44     TObjectType descType(E16BitDescriptor);
       
    45     TInt32 length = aBuf.Length();
       
    46     iData.Append((const TUint8*)&descType, sizeof(TObjectType));
       
    47     iData.Append((const TUint8*)&length, sizeof(TInt32));
       
    48     iData.Append((const TUint8*)aBuf.Ptr(), aBuf.Size());
       
    49     }
       
    50 
       
    51 // Serialize 32 bit integer in the format <EInt32><value>
       
    52 void TSenNotPluginMessage::AppendInt32(TInt32 aInt32)
       
    53     {
       
    54     TObjectType intType(EInt32); //
       
    55     iData.Append((const TUint8*)&intType, sizeof(TObjectType));
       
    56     iData.Append((const TUint8*)&aInt32, sizeof(TInt32));
       
    57     }
       
    58 
       
    59 TPtrC16 TSenNotPluginMessage::GetBuf16(TInt aIndex) const
       
    60     {
       
    61     TPtr16 result(NULL, 0);
       
    62     TUint8* ptr = (TUint8*)iData.Ptr();
       
    63     for(TInt i=0; i<aIndex; i++)
       
    64         {
       
    65         ptr = NavigatePointerToNextObjext(ptr);
       
    66         }
       
    67     ptr += sizeof(TObjectType);
       
    68     TInt32 length = *((TInt32*)ptr);
       
    69     ptr += sizeof(TInt32);
       
    70     result.Set((TUint16*)ptr, length, length); // Note: length == max length
       
    71     return result;
       
    72     }
       
    73 
       
    74 TInt32 TSenNotPluginMessage::GetInt32(TInt aIndex) const
       
    75     {
       
    76     TUint8* ptr = (TUint8*)iData.Ptr();
       
    77     for(TInt i=0; i<aIndex; i++)
       
    78         {
       
    79         ptr = NavigatePointerToNextObjext(ptr);
       
    80         }
       
    81     ptr += sizeof(TObjectType);
       
    82     TInt32 result = *((TInt32*)ptr);
       
    83     return result;
       
    84     }
       
    85 
       
    86 TInt TSenNotPluginMessage::Int32ObjectSize() const
       
    87     {
       
    88     return sizeof(TObjectType) + sizeof(TInt32);
       
    89     }
       
    90 
       
    91 TInt TSenNotPluginMessage::Buf16ObjectSize(TUint8 *aObjectStart) const
       
    92     {
       
    93     TUint8 *ptr = aObjectStart;
       
    94     ptr += sizeof(TObjectType);
       
    95     TInt32 length = *((TInt32*)ptr);
       
    96     return sizeof(TObjectType) + sizeof(TInt32) + length * 2; // 2x : 16 bytes per one character
       
    97     }
       
    98 
       
    99 TUint8* TSenNotPluginMessage::NavigatePointerToNextObjext(TUint8* aObjectStart) const
       
   100     {
       
   101     TUint8* ptr = aObjectStart;
       
   102     TObjectType objectType = *((TObjectType*)ptr);
       
   103     if(objectType == E16BitDescriptor)
       
   104         ptr += Buf16ObjectSize(ptr);
       
   105     else if(objectType == EInt32)
       
   106         ptr += Int32ObjectSize();
       
   107     // else this should panic
       
   108     return ptr;
       
   109     }
       
   110 
       
   111 /******************************************************************************
       
   112  *              TSenNotPluginRequest implementation
       
   113  *****************************************************************************/
       
   114 
       
   115 EXPORT_C TSenNotPluginRequest::TSenNotPluginRequest()
       
   116 : iMethod(ENoMethod)
       
   117     {
       
   118     }
       
   119 
       
   120 EXPORT_C TInt TSenNotPluginRequest::Method()
       
   121     {
       
   122     return iMethod;
       
   123     }
       
   124 
       
   125 EXPORT_C TSenNotPluginRequest::TSenNotPluginRequest(TInt aMethod)
       
   126 : iMethod(aMethod)
       
   127     {
       
   128     }
       
   129 
       
   130 /******************************************************************************
       
   131  *              TAuthenticationDlgRequest implementation
       
   132  *****************************************************************************/
       
   133 
       
   134 
       
   135 EXPORT_C TAuthenticationDlgRequest::TAuthenticationDlgRequest()
       
   136     : TSenNotPluginRequest(EAuthenticationDlg)
       
   137     {
       
   138     SetData(KNullDesC, KNullDesC);
       
   139     }
       
   140 
       
   141 EXPORT_C TInt TAuthenticationDlgRequest::SetData(const TDesC& aUsername,
       
   142                                                     const TDesC& aPassword)
       
   143     {
       
   144     iData.Zero();
       
   145     if(aUsername.Length() > KSenMaxUsernameLength ||
       
   146        aPassword.Length() > KSenMaxPasswordLength)
       
   147         return KErrBadDescriptor;
       
   148     AppendBuf16(aUsername);
       
   149     AppendBuf16(aPassword);
       
   150     return KErrNone;
       
   151     }
       
   152 
       
   153 EXPORT_C TPtrC16 TAuthenticationDlgRequest::Username() const
       
   154     {
       
   155     return GetBuf16(0);
       
   156     }
       
   157 
       
   158 EXPORT_C TPtrC16 TAuthenticationDlgRequest::Password() const
       
   159     {
       
   160     return GetBuf16(1);
       
   161     }
       
   162 
       
   163 /******************************************************************************
       
   164  *              TAuthenticationDlgResponse implementation
       
   165  *****************************************************************************/
       
   166 
       
   167 EXPORT_C TAuthenticationDlgResponse::TAuthenticationDlgResponse()
       
   168     {
       
   169     SetData(KNullDesC, KNullDesC, EFalse);
       
   170     }
       
   171 
       
   172 EXPORT_C TInt TAuthenticationDlgResponse::SetData(const TDesC& aUsername, 
       
   173     const TDesC& aPassword, TBool aOkButtonPressed) 
       
   174     { 
       
   175     iData.Zero(); 
       
   176     if(aUsername.Length() > KSenMaxUsernameLength || 
       
   177        aPassword.Length() > KSenMaxPasswordLength) 
       
   178         return KErrBadDescriptor; 
       
   179 
       
   180     //TUint8* ptr = (TUint8*)iData.Ptr();  // ptr not used atm
       
   181 
       
   182     TUint16 value16; 
       
   183     if (aOkButtonPressed) value16 = 1; 
       
   184     else value16 = 0; 
       
   185     iData.Append((const TUint8*)&value16, sizeof(TUint16)); 
       
   186     iData.Append((const TUint8*)aUsername.Ptr(), aUsername.Size()); 
       
   187     if (aUsername.Size() < KSenMaxUsernameLength*2) 
       
   188             { 
       
   189                 iData.AppendFill(0,KSenMaxUsernameLength*2-aUsername.Size()); 
       
   190             } 
       
   191     iData.Append((const TUint8*)aPassword.Ptr(), aPassword.Size()); 
       
   192     if (aPassword.Size() < KSenMaxPasswordLength*2) 
       
   193             { 
       
   194                 iData.AppendFill(0,KSenMaxPasswordLength*2-aPassword.Size()); 
       
   195             } 
       
   196     return KErrNone; 
       
   197     } 
       
   198 
       
   199 EXPORT_C TPtrC16 TAuthenticationDlgResponse::Username() const 
       
   200     { 
       
   201     TUint16* ptr = (TUint16*)iData.Ptr(); 
       
   202     TInt size = sizeof(TUint16)/2; 
       
   203     ptr += size; 
       
   204     TUint16* start = ptr; 
       
   205     while (*ptr != 0) 
       
   206             { 
       
   207             ptr += size; 
       
   208             } 
       
   209         TInt length = (ptr-start)/size; 
       
   210     TPtr16 result(NULL, 0); 
       
   211     result.Set((TUint16*)start, length, length); // Note: length == max length 
       
   212     return result; 
       
   213     } 
       
   214 
       
   215 EXPORT_C TPtrC16 TAuthenticationDlgResponse::Password() const 
       
   216     { 
       
   217     TUint16* ptr = (TUint16*)iData.Ptr(); 
       
   218     TInt size = sizeof(TUint16)/2; 
       
   219     ptr += size*(1+KSenMaxUsernameLength); 
       
   220     TUint16* start = ptr; 
       
   221     while (*ptr != 0) 
       
   222             { 
       
   223             ptr += size; 
       
   224             } 
       
   225         TInt length = (ptr-start)/size; 
       
   226     TPtr16 result(NULL, 0); 
       
   227     result.Set((TUint16*)start, length, length); // Note: length == max length 
       
   228     return result; 
       
   229     } 
       
   230 
       
   231 EXPORT_C TBool TAuthenticationDlgResponse::OkButtonPressed() const 
       
   232     { 
       
   233     if (*(TUint16*)iData.Ptr() == 1) return ETrue; 
       
   234     else return EFalse; 
       
   235     }
       
   236 
       
   237 /******************************************************************************
       
   238  *              TAllowRegisterDlgRequest implementation
       
   239  *****************************************************************************/
       
   240 
       
   241 EXPORT_C TAllowRegisterDlgRequest::TAllowRegisterDlgRequest()
       
   242     : TSenNotPluginRequest(EAllowRegisterDlg)
       
   243     {
       
   244     }
       
   245 
       
   246 
       
   247 /******************************************************************************
       
   248  *              TAllowRegisterDlgResponse implementation
       
   249  *****************************************************************************/
       
   250 
       
   251 EXPORT_C TAllowRegisterDlgResponse::TAllowRegisterDlgResponse()
       
   252     {
       
   253     SetOkButton(EFalse);
       
   254     }
       
   255 
       
   256 EXPORT_C void TAllowRegisterDlgResponse::SetOkButton(TBool aValue)
       
   257     {
       
   258     AppendInt32((TInt32)aValue);
       
   259     }
       
   260 
       
   261 EXPORT_C TBool TAllowRegisterDlgResponse::OkButtonPressed() const
       
   262     {
       
   263     return (TBool)GetInt32(0);
       
   264     }
       
   265 
       
   266 /******************************************************************************
       
   267  *              TAllowUnRegisterDlgRequest implementation
       
   268  *****************************************************************************/
       
   269 
       
   270 EXPORT_C TAllowUnRegisterDlgRequest::TAllowUnRegisterDlgRequest()
       
   271     : TSenNotPluginRequest(EAllowUnRegisterDlg)
       
   272     {
       
   273     }
       
   274 
       
   275 
       
   276 /******************************************************************************
       
   277  *              TAllowUnRegisterDlgResponse implementation
       
   278  *****************************************************************************/
       
   279 
       
   280 EXPORT_C TAllowUnRegisterDlgResponse::TAllowUnRegisterDlgResponse()
       
   281     {
       
   282     SetOkButton(EFalse); // False by default
       
   283     }
       
   284 
       
   285 EXPORT_C void TAllowUnRegisterDlgResponse::SetOkButton(TBool aValue)
       
   286     {
       
   287     AppendInt32((TInt32)aValue);
       
   288     }
       
   289 
       
   290 EXPORT_C TBool TAllowUnRegisterDlgResponse::OkButtonPressed() const
       
   291     {
       
   292     return (TBool)GetInt32(0);
       
   293     }
       
   294 
       
   295 /******************************************************************************
       
   296  *              TAskSaveDlgRequest implementation
       
   297  *****************************************************************************/
       
   298 
       
   299 EXPORT_C TAskSaveDlgRequest::TAskSaveDlgRequest()
       
   300     : TSenNotPluginRequest(EAskSaveDlg)
       
   301     {
       
   302     }
       
   303 
       
   304 /******************************************************************************
       
   305  *              TAskSaveDlgResponse implementation
       
   306  *****************************************************************************/
       
   307 
       
   308 EXPORT_C TAskSaveDlgResponse::TAskSaveDlgResponse()
       
   309     {
       
   310     SetOkButton(EFalse); // False by default
       
   311     }
       
   312 
       
   313 EXPORT_C void TAskSaveDlgResponse::SetOkButton(TBool aValue)
       
   314     {
       
   315     AppendInt32((TInt32)aValue);
       
   316     }
       
   317 
       
   318 EXPORT_C TBool TAskSaveDlgResponse::OkButtonPressed() const
       
   319     {
       
   320     return (TBool)GetInt32(0);
       
   321     }
       
   322 
       
   323 // End of File
       
   324 
       
   325 
       
   326