webservices/wsframework/src/senhttptransportproperties.cpp
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 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 <s32strm.h> // RWriteStream
       
    26 #include <SenXmlReader.h>
       
    27 #include "SenHttpTransportProperties.h"
       
    28 
       
    29 namespace
       
    30     {
       
    31     _LIT8(KIapIdLocalName, "IapId"); 
       
    32     _LIT8(KProxyHostLocalName, "ProxyHost"); 
       
    33     _LIT8(KProxyPortLocalName, "ProxyPort"); 
       
    34     }
       
    35 
       
    36 EXPORT_C CSenHttpTransportProperties* CSenHttpTransportProperties::NewL()
       
    37     {
       
    38     CSenHttpTransportProperties* pNew = NewLC();
       
    39     CleanupStack::Pop(); // pNew
       
    40     return pNew;
       
    41     }
       
    42 
       
    43 EXPORT_C CSenHttpTransportProperties* CSenHttpTransportProperties::NewLC()
       
    44     {
       
    45     CSenHttpTransportProperties* pNew = new (ELeave) CSenHttpTransportProperties;
       
    46     CleanupStack::PushL(pNew);
       
    47 
       
    48     // omit parsing by passing zero-length descriptor
       
    49     pNew->BaseConstructL(KSenXmlPropertiesLocalname,
       
    50                          KNullDesC8,
       
    51                          NULL);
       
    52     return pNew;
       
    53     }
       
    54 
       
    55 EXPORT_C CSenHttpTransportProperties* CSenHttpTransportProperties::NewL(const TDesC8& aXmlUtf8,
       
    56                                                                CSenXmlReader& aParser)
       
    57     {
       
    58     CSenHttpTransportProperties* pNew = NewLC(aXmlUtf8, aParser);
       
    59     CleanupStack::Pop(); // pNew
       
    60     return pNew;
       
    61     }
       
    62 
       
    63 EXPORT_C CSenHttpTransportProperties* CSenHttpTransportProperties::NewLC(const TDesC8& aXmlUtf8,
       
    64                                                                 CSenXmlReader& aParser)
       
    65     {
       
    66     CSenHttpTransportProperties* pNew = new (ELeave) CSenHttpTransportProperties;
       
    67     CleanupStack::PushL(pNew);
       
    68 
       
    69     // parse the XML document  descriptor into DOM fragment
       
    70     pNew->BaseConstructL(KSenXmlPropertiesLocalname,
       
    71                          aXmlUtf8,
       
    72                          &aParser);
       
    73     return pNew;
       
    74     }
       
    75 
       
    76 EXPORT_C CSenHttpTransportProperties* CSenHttpTransportProperties::NewL(const CSenElement& aElement)
       
    77     {
       
    78     CSenHttpTransportProperties* pNew = NewLC(aElement);
       
    79     CleanupStack::Pop(); // pNew
       
    80     return pNew;
       
    81     }
       
    82 
       
    83 EXPORT_C CSenHttpTransportProperties* CSenHttpTransportProperties::NewLC(const CSenElement& aElement)
       
    84     {
       
    85     CSenHttpTransportProperties* pNew = new (ELeave) CSenHttpTransportProperties;
       
    86     CleanupStack::PushL(pNew);
       
    87 
       
    88     // parse the XML document  descriptor into DOM fragment
       
    89     pNew->BaseConstructL(aElement);
       
    90     return pNew;
       
    91     }
       
    92 
       
    93 
       
    94 
       
    95 /**
       
    96 * Get an integer identifying properties class type.
       
    97 * All subclasses MUST return use unique integer value.
       
    98 * @return unique TInt identifying this properties class type
       
    99 */
       
   100 TInt CSenHttpTransportProperties::PropertiesClassType() 
       
   101     { 
       
   102     return KSenPropertiesClassTypeSenHttpTransportProperties; 
       
   103     }
       
   104 
       
   105 /**
       
   106 * Writes this properties object as descriptor into a stream.
       
   107 * UTF-8 charset encoding will be used.
       
   108 * @since Series60
       
   109 * @param aWriteStream The stream to write to.
       
   110 */
       
   111 void CSenHttpTransportProperties::WriteToL(RWriteStream& aWriteStream)
       
   112     {
       
   113     CSenTransportProperties::WriteAsXMLToL(aWriteStream);
       
   114     /*
       
   115     WriteAsXMLToL(aWriteStream);
       
   116     */
       
   117     }
       
   118 
       
   119 /**
       
   120 * Get these properties as UTF-8 charset encoded descriptor.
       
   121 * @since Series60
       
   122 * @return a pointer to UTF-8 encoded descriptor. 
       
   123 * Caller takes ownership.
       
   124 */
       
   125 HBufC8* CSenHttpTransportProperties::AsUtf8L()
       
   126     {
       
   127     return CSenTransportProperties::AsUtf8L();
       
   128     /*
       
   129     return AsXmlL();
       
   130     */
       
   131     }
       
   132 
       
   133 
       
   134 /**
       
   135 * Get these properties as UTF-8 charset encoded descriptor.
       
   136 * @since Series60
       
   137 * @return a pointer to UTF-8 encoded descriptor, which is
       
   138 * has been left on cleanup stack.
       
   139 * Caller takes ownership.
       
   140 */
       
   141 HBufC8* CSenHttpTransportProperties::AsUtf8LC()
       
   142     {
       
   143     return CSenTransportProperties::AsUtf8LC();
       
   144     /*
       
   145     HBufC8* pAsXml = AsXmlL();
       
   146     CleanupStack::PushL(pAsXml);
       
   147     return pAsXml;
       
   148     */
       
   149     }
       
   150 
       
   151 /**
       
   152 * Destructor.
       
   153 */
       
   154 CSenHttpTransportProperties::~CSenHttpTransportProperties()
       
   155     {
       
   156     }
       
   157 
       
   158 /**
       
   159 * Constructs this fragment. Subclasses should call this
       
   160 * function in their corresponding 2nd phase constructor.
       
   161 *
       
   162 * @param aLocalname is used as XML localname for this instance
       
   163 * @param aXml is the XML document to be parsed into this DOM tree
       
   164 * this properties instance represents.
       
   165 * Parsing is omitted iff descriptor is zero-length: KNullDesC8.
       
   166 */
       
   167 void CSenHttpTransportProperties::BaseConstructL(const TDesC8& aLocalname, 
       
   168                                                  const TDesC8& aXml,
       
   169                                                  CSenXmlReader* aParser)
       
   170     {
       
   171     CSenTransportProperties::BaseConstructL(aLocalname, aXml, aParser);
       
   172     }
       
   173 
       
   174 /**
       
   175 * Constructs this fragment. Subclasses should call this
       
   176 * function in their corresponding 2nd phase constructor.
       
   177 *
       
   178 * @param aNamespace is the XML namespace
       
   179 * @param aLocalname is the XML localname
       
   180 * @param aXml is the XML document to be parsed into this DOM tree
       
   181 * this properties instance represents.
       
   182 * Parsing is omitted iff descriptor is zero-length: KNullDesC8.
       
   183 */
       
   184 void CSenHttpTransportProperties::BaseConstructL(const TDesC8& aNamespace, 
       
   185                                                  const TDesC8& aLocalname, 
       
   186                                                  const TDesC8& aXml,
       
   187                                                  CSenXmlReader* aParser)
       
   188     {
       
   189     CSenTransportProperties::BaseConstructL(aNamespace, aLocalname, aXml, aParser);
       
   190     }
       
   191 
       
   192 /**
       
   193 * Constructs this fragment. Subclasses should call this
       
   194 * function in their corresponding 2nd phase constructor.
       
   195 *
       
   196 * @param aNamespace is the XML namespace
       
   197 * @param aLocalname is the XML localname
       
   198 * @param aLocalname is the XML qualified name
       
   199 * @param aXml is the XML document to be parsed into this DOM tree
       
   200 * this properties instance represents.
       
   201 * Parsing is omitted iff descriptor is zero-length: KNullDesC8.
       
   202 */
       
   203 void CSenHttpTransportProperties::BaseConstructL(const TDesC8& aNamespace, 
       
   204                                                  const TDesC8& aLocalname, 
       
   205                                                  const TDesC8& aQualifiedName, 
       
   206                                                  const TDesC8& aXml,
       
   207                                                  CSenXmlReader* aParser)
       
   208     {
       
   209     CSenTransportProperties::BaseConstructL(aNamespace, aLocalname, aQualifiedName, aXml, aParser);
       
   210 
       
   211     }
       
   212 
       
   213 /**
       
   214 * 2nd phase constructor:
       
   215 */
       
   216 void CSenHttpTransportProperties::BaseConstructL(const CSenElement& aElement)
       
   217     {
       
   218     CSenTransportProperties::BaseConstructL(aElement);
       
   219     }
       
   220 
       
   221 
       
   222 
       
   223 
       
   224 CSenHttpTransportProperties::CSenHttpTransportProperties()
       
   225     {
       
   226     }
       
   227 
       
   228 
       
   229 // First versions of real HTTP spesific transport methods:
       
   230 
       
   231 EXPORT_C TInt CSenHttpTransportProperties::IapId(TUint32& aCurrentIapId)
       
   232     {
       
   233     CSenElement* pIapIdElement = AsElement().Element(KIapIdLocalName);
       
   234     if(pIapIdElement && pIapIdElement->HasContent())
       
   235         {
       
   236         TPtrC8 content = pIapIdElement->Content();
       
   237         TLex8 lex(content);
       
   238 
       
   239         TInt retVal = lex.Val(aCurrentIapId, EDecimal);
       
   240         return retVal;
       
   241         }
       
   242     return KErrNotFound;
       
   243     }
       
   244 
       
   245 
       
   246 EXPORT_C void CSenHttpTransportProperties::SetIapIdL(TUint32 aIapId)
       
   247     {
       
   248     CSenElement* pIapIdElement = AsElement().Element(KIapIdLocalName);
       
   249     if(!pIapIdElement)
       
   250         {
       
   251         pIapIdElement = &(AsElement().AddElementL(KIapIdLocalName));
       
   252         }
       
   253     TBuf8<128> buf;
       
   254     buf.AppendFormat(_L8("%u"), aIapId);
       
   255     pIapIdElement->SetContentL(buf);
       
   256     }
       
   257 
       
   258 EXPORT_C TInt CSenHttpTransportProperties::ProxyPort()
       
   259     {
       
   260     CSenElement* pProxyPortElement = AsElement().Element(KProxyPortLocalName);
       
   261     if(pProxyPortElement && pProxyPortElement->HasContent())
       
   262         {
       
   263         TPtrC8 content = pProxyPortElement->Content();
       
   264         TLex8 lex(content);
       
   265 
       
   266         TUint proxyPort(0);
       
   267         TInt retVal = lex.Val(proxyPort, EDecimal);
       
   268         if(retVal==KErrNone)
       
   269             {
       
   270             return (TInt)proxyPort;
       
   271             }
       
   272         else
       
   273             {
       
   274             return retVal;
       
   275             }
       
   276         }
       
   277     return KErrNotFound;
       
   278     }
       
   279 
       
   280 EXPORT_C void CSenHttpTransportProperties::SetProxyPortL(TInt aProxyPort)
       
   281     {
       
   282     CSenElement* pProxyPortElement = AsElement().Element(KProxyPortLocalName);
       
   283     if(!pProxyPortElement)
       
   284         {
       
   285         pProxyPortElement = &(AsElement().AddElementL(KProxyPortLocalName));
       
   286         }
       
   287     TBuf8<128> buf;
       
   288     buf.AppendFormat(_L8("%u"), aProxyPort);
       
   289     pProxyPortElement->SetContentL(buf);
       
   290     }
       
   291 
       
   292 EXPORT_C TPtrC8 CSenHttpTransportProperties::ProxyHost()
       
   293     {
       
   294     CSenElement* pProxyHostElement = AsElement().Element(KProxyHostLocalName);
       
   295     if(pProxyHostElement && pProxyHostElement->HasContent())
       
   296         {
       
   297         return pProxyHostElement->Content();
       
   298         }
       
   299     else return KNullDesC8();
       
   300     }
       
   301 
       
   302 EXPORT_C void CSenHttpTransportProperties::SetProxyHostL(const TDesC8& aProxyHost)
       
   303     {
       
   304     CSenElement* pProxyHostElement = AsElement().Element(KProxyHostLocalName);
       
   305     if(!pProxyHostElement)
       
   306         {
       
   307         pProxyHostElement = &(AsElement().AddElementL(KProxyHostLocalName));
       
   308         }
       
   309     pProxyHostElement->SetContentL(aProxyHost);
       
   310     }
       
   311 
       
   312 // END OF FILEŽ
       
   313 
       
   314