smf/smfservermodule/smfcommon/smfpluginutil.h
changeset 18 013a02bf2bb0
equal deleted inserted replaced
17:106a4bfcb866 18:013a02bf2bb0
       
     1 /**
       
     2  * Copyright (c) 2010 Sasken Communication Technologies Ltd.
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the "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  * Chandradeep Gandhi, Sasken Communication Technologies Ltd - Initial contribution
       
    11  *
       
    12  * Contributors:
       
    13  * Manasij Roy, Nalina Hariharan
       
    14  * 
       
    15  * Description:
       
    16  * The Plugin util class provides the information required for the 
       
    17  * plugins from Smf framework 
       
    18  *
       
    19  */
       
    20 
       
    21 #ifndef SMFPLUGINUTIL_H_
       
    22 #define SMFPLUGINUTIL_H_
       
    23 
       
    24 #include <QNetworkAccessManager>
       
    25 #include <QMap>
       
    26 #include <QVariant>
       
    27 #include <parser.h>
       
    28 #include <smfclientglobal.h>
       
    29 #include <smfcredmgrclient.h>
       
    30 
       
    31 enum SmfParsingMode
       
    32 	{
       
    33 	ParseForRequestContent, //Inline query format (foo=bar&bar=baz&baz=foo ...), suitable for POST requests.
       
    34 	ParseForInlineQuery, // Same as ParseForRequestContent, but prepends the string with a question mark - 
       
    35 						// suitable for GET requests (appending parameters to the request URL) 
       
    36 	ParseForHeaderArguments // HTTP request header format (parameters to be put inside a request header). 
       
    37 	};
       
    38 
       
    39 /**
       
    40  * The Plugin util class provides the information required for the 
       
    41  * plugins from Smf framework
       
    42  */
       
    43 class SMFCOMMON_EXPORT SmfPluginUtil
       
    44 	{
       
    45 public:
       
    46 	/**
       
    47 	 * Constructor
       
    48 	 */
       
    49 	SmfPluginUtil();
       
    50 	
       
    51 	/**
       
    52 	 * Destructor
       
    53 	 */
       
    54 	~SmfPluginUtil ( );
       
    55 	
       
    56 	/**
       
    57     * Read JSON string from the I/O Device and converts it to a QVariant object
       
    58     * @param io Input output device
       
    59     * @param ok if a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
       
    60     * @returns a QVariant object generated from the JSON string
       
    61 	 */
       
    62     QVariant parse ( QIODevice* io, bool* ok = 0 );
       
    63 
       
    64     /**
       
    65     * This is a method provided for convenience.
       
    66     * @param jsonData data containing the JSON object representation
       
    67     * @param ok if a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
       
    68     * @returns a QVariant object generated from the JSON string
       
    69     * @sa errorString
       
    70     * @sa errorLine
       
    71     */
       
    72     QVariant parse ( const QByteArray& jsonData, bool* ok = 0 );
       
    73     
       
    74     /**
       
    75     * This method returns the error message tha ocuured during last parsing
       
    76     * @returns a QString object containing the error message of the last parse operation
       
    77     */
       
    78     QString errorString ( ) const;
       
    79 
       
    80     /**
       
    81     * This method returns line number where the last QJson parsing error occurred
       
    82     * @returns the line number where the error occurred
       
    83     */
       
    84     int errorLine ( ) const;
       
    85 	
       
    86     /**
       
    87      * Method called by plugins to get the OAuth Keys.
       
    88      * @param aKeys [out] The OAuth keys
       
    89      * @param aRegToken The plugin's registration token
       
    90      * @param aValidity The validity of the keys
       
    91      * @param aPluginID The ID of the plugin that requests for 
       
    92      * the OAuth keys
       
    93      */
       
    94     void getAuthKeys( SmfAuthParams &aKeys, 
       
    95     		const QString aRegToken, 
       
    96     		const QDateTime& aValidity,
       
    97     		const QString aPluginID );
       
    98 	
       
    99 	/**
       
   100 	 * Method called by plugins to get the Nonce value
       
   101 	 * @param aNonceString [out] The Nonce string
       
   102 	 * @param aLength Lenth of the NONCE tobe generated
       
   103 	 */
       
   104     void getNonce( QString &aNonceString, const qint64 aLength );
       
   105 	
       
   106 	/**
       
   107 	 * Method called by plugins to generate a parameters string required to 
       
   108 	 * access Protected Resources using OAuth authorization.
       
   109 	 * @param aRequestUrl The request URL
       
   110 	 * @param aOperation The type of http operation
       
   111 	 * @param aToken The access token
       
   112 	 * @param aTokenSecret The token secret
       
   113 	 * @param aSignatureMethod The signature method to be used
       
   114 	 * @param aParams A map of parameters to its values
       
   115 	 * @param aMode The mode of creation of the request
       
   116 	 * @return The cretd parameter string
       
   117 	 */
       
   118 	QByteArray createParameterString( const QString &aRequestUrl, 
       
   119 			QNetworkAccessManager::Operation aOperation, 
       
   120 			const QByteArray &aToken, 
       
   121 			const QByteArray &aTokenSecret, 
       
   122 			const SmfSignatureMethod aSignatureMethod, 
       
   123 			const QMultiMap<QByteArray, QByteArray> &aParams, 
       
   124 			const SmfParsingMode aMode);
       
   125 	
       
   126 private:
       
   127 	/**
       
   128 	 * The instance of QJson::Parser
       
   129 	 */
       
   130 	QJson::Parser *m_jsonParser;
       
   131 	
       
   132 	};
       
   133 
       
   134 #endif /* SMFPLUGINUTIL_H_ */