smf/smfservermodule/smfclient/common/smfpluginutil.h
changeset 18 013a02bf2bb0
parent 17 106a4bfcb866
child 19 c412f0526c34
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 
       
    30 enum SmfSignatureMethod
       
    31 	{
       
    32 	HMAC_SHA1,
       
    33 	RSA_SHA1,
       
    34 	PLAINTEXT
       
    35 	};
       
    36 
       
    37 enum SmfParsingMode
       
    38 	{
       
    39 	ParseForRequestContent, //Inline query format (foo=bar&bar=baz&baz=foo ...), suitable for POST requests.
       
    40 	ParseForInlineQuery, // Same as ParseForRequestContent, but prepends the string with a question mark - 
       
    41 						// suitable for GET requests (appending parameters to the request URL) 
       
    42 	ParseForHeaderArguments // HTTP request header format (parameters to be put inside a request header). 
       
    43 	};
       
    44 
       
    45 /**
       
    46  * The Plugin util class provides the information required for the 
       
    47  * plugins from Smf framework
       
    48  */
       
    49 class SMFCLIENT_EXPORT SmfPluginUtil
       
    50 	{
       
    51 public:
       
    52 	/**
       
    53 	 * Method to get the instance of SmfPluginUtil class
       
    54 	 * @return The instance of SmfPluginUtil class
       
    55 	 */
       
    56 	static SmfPluginUtil* getInstance ( );
       
    57 	
       
    58 	/**
       
    59 	 * Destructor
       
    60 	 */
       
    61 	~SmfPluginUtil ( );
       
    62 	
       
    63 	/**
       
    64     * Read JSON string from the I/O Device and converts it to a QVariant object
       
    65     * @param io Input output device
       
    66     * @param ok if a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
       
    67     * @returns a QVariant object generated from the JSON string
       
    68 	 */
       
    69     QVariant parse ( QIODevice* io, bool* ok = 0 );
       
    70 
       
    71     /**
       
    72     * This is a method provided for convenience.
       
    73     * @param jsonData data containing the JSON object representation
       
    74     * @param ok if a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
       
    75     * @returns a QVariant object generated from the JSON string
       
    76     * @sa errorString
       
    77     * @sa errorLine
       
    78     */
       
    79     QVariant parse ( const QByteArray& jsonData, bool* ok = 0 );
       
    80     
       
    81     /**
       
    82     * This method returns the error message tha ocuured during last parsing
       
    83     * @returns a QString object containing the error message of the last parse operation
       
    84     */
       
    85     QString errorString ( ) const;
       
    86 
       
    87     /**
       
    88     * This method returns line number where the last QJson parsing error occurred
       
    89     * @returns the line number where the error occurred
       
    90     */
       
    91     int errorLine ( ) const;
       
    92 	
       
    93 	/**
       
    94 	 * Method called by plugins to get the OAuth Keys. The PM sends the 
       
    95 	 * keys only if the pluginID is that of a currently loaded plugin
       
    96 	 * @param aKeys [out] The OAuth keys
       
    97 	 * @param aRegToken The plugin's registration token
       
    98 	 * @param aPluginID The ID of the plugin that requests for 
       
    99 	 * the OAuth keys
       
   100 	 */
       
   101 	void getAuthKeys( QMap<QString, QString> &aKeys, 
       
   102 			const QString aRegToken, 
       
   103 			const QString aPluginID );
       
   104 	
       
   105 	/**
       
   106 	 * Method called by plugins to get the Nonce value
       
   107 	 * @param aNonceString [out] The Nonce string
       
   108 	 */
       
   109 	void getNonce( QString &aNonceString );
       
   110 	
       
   111 	/**
       
   112 	 * Method called by plugins to generate a parameters string required to 
       
   113 	 * access Protected Resources using OAuth authorization.
       
   114 	 * @param aRequestUrl The request URL
       
   115 	 * @param aOperation The type of http operation
       
   116 	 * @param aToken The access token
       
   117 	 * @param aTokenSecret The token secret
       
   118 	 * @param aSignatureMethod The signature method to be used
       
   119 	 * @param aParams A map of parameters to its values
       
   120 	 * @param aMode The mode of creation of the request
       
   121 	 * @return The cretd parameter string
       
   122 	 */
       
   123 	QByteArray createParameterString( const QString &aRequestUrl, 
       
   124 			QNetworkAccessManager::Operation aOperation, 
       
   125 			const QByteArray &aToken, 
       
   126 			const QByteArray &aTokenSecret, 
       
   127 			const SmfSignatureMethod aSignatureMethod, 
       
   128 			const QMultiMap<QByteArray, QByteArray> &aParams, 
       
   129 			const SmfParsingMode aMode);
       
   130 	
       
   131 private:
       
   132 	/**
       
   133 	 * Constructor with default argument
       
   134 	 */
       
   135 	SmfPluginUtil ( );
       
   136 
       
   137 	
       
   138 private:
       
   139 	/**
       
   140 	 * The single instance of SmfPluginUtil
       
   141 	 */
       
   142 	static SmfPluginUtil* m_myInstance;
       
   143 	
       
   144 	/**
       
   145 	 * The instance of QJson::Parser
       
   146 	 */
       
   147 	QJson::Parser *m_jsonParser;
       
   148 	
       
   149 	};
       
   150 
       
   151 #endif /* SMFPLUGINUTIL_H_ */