18
|
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 |
#include <smfpluginutil.h>
|
|
22 |
|
|
23 |
|
|
24 |
/**
|
|
25 |
* Constructor
|
|
26 |
*/
|
|
27 |
SmfPluginUtil::SmfPluginUtil ( )
|
|
28 |
{
|
|
29 |
m_jsonParser = new QJson::Parser;
|
|
30 |
}
|
|
31 |
|
|
32 |
/**
|
|
33 |
* Destructor
|
|
34 |
*/
|
|
35 |
SmfPluginUtil::~SmfPluginUtil ( )
|
|
36 |
{
|
|
37 |
if(m_jsonParser)
|
|
38 |
delete m_jsonParser;
|
|
39 |
}
|
|
40 |
|
|
41 |
|
|
42 |
/**
|
|
43 |
* Read JSON string from the I/O Device and converts it to a QVariant object
|
|
44 |
* @param io Input output device
|
|
45 |
* @param ok if a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
|
|
46 |
* @returns a QVariant object generated from the JSON string
|
|
47 |
*/
|
|
48 |
QVariant SmfPluginUtil::parse ( QIODevice* io, bool* ok )
|
|
49 |
{
|
|
50 |
return m_jsonParser->parse(io, ok);
|
|
51 |
}
|
|
52 |
|
|
53 |
/**
|
|
54 |
* This is a method provided for convenience.
|
|
55 |
* @param jsonData data containing the JSON object representation
|
|
56 |
* @param ok if a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
|
|
57 |
* @returns a QVariant object generated from the JSON string
|
|
58 |
* @sa errorString
|
|
59 |
* @sa errorLine
|
|
60 |
*/
|
|
61 |
QVariant SmfPluginUtil::parse ( const QByteArray& jsonData, bool* ok )
|
|
62 |
{
|
|
63 |
return m_jsonParser->parse(jsonData, ok);
|
|
64 |
}
|
|
65 |
|
|
66 |
/**
|
|
67 |
* This method returns the error message tha ocuured during last parsing
|
|
68 |
* @returns a QString object containing the error message of the last parse operation
|
|
69 |
*/
|
|
70 |
QString SmfPluginUtil::errorString ( ) const
|
|
71 |
{
|
|
72 |
return m_jsonParser->errorString();
|
|
73 |
}
|
|
74 |
|
|
75 |
/**
|
|
76 |
* This method returns line number where the last QJson parsing error occurred
|
|
77 |
* @returns the line number where the error occurred
|
|
78 |
*/
|
|
79 |
int SmfPluginUtil::errorLine ( ) const
|
|
80 |
{
|
|
81 |
return m_jsonParser->errorLine();
|
|
82 |
}
|
|
83 |
|
|
84 |
/**
|
|
85 |
* Method called by plugins to get the OAuth Keys.
|
|
86 |
* @param aKeys [out] The OAuth keys
|
|
87 |
* @param aRegToken The plugin's registration token
|
|
88 |
* @param aValidity The validity of the keys
|
|
89 |
* @param aPluginID The ID of the plugin that requests for
|
|
90 |
* the OAuth keys
|
|
91 |
*/
|
|
92 |
void SmfPluginUtil::getAuthKeys( SmfAuthParams &aKeys,
|
|
93 |
const QString aRegToken,
|
|
94 |
const QDateTime& aValidity,
|
|
95 |
const QString aPluginID )
|
|
96 |
{
|
|
97 |
aKeys.clear();
|
|
98 |
|
|
99 |
// Invalid arguments
|
|
100 |
if( (0 == aRegToken.size()) ||
|
|
101 |
(0 == aPluginID.size()) ||
|
|
102 |
(aValidity.isNull()) )
|
|
103 |
return;
|
|
104 |
|
|
105 |
// Call Credential manager function to get the keys passing the registration token and the plugin
|
|
106 |
SmfCredMgrClient csmClient;
|
|
107 |
csmClient.AuthDataSet(aRegToken,aValidity,aKeys);
|
|
108 |
}
|
|
109 |
|
|
110 |
/**
|
|
111 |
* Method called by plugins to get the Nonce value
|
|
112 |
* @param aNonceString [out] The Nonce string
|
|
113 |
* @param aLength Lenth of the NONCE tobe generated
|
|
114 |
*/
|
|
115 |
void SmfPluginUtil::getNonce( QString &aNonceString, const qint64 aLength )
|
|
116 |
{
|
|
117 |
aNonceString.clear();
|
|
118 |
|
|
119 |
// Invalid argument
|
|
120 |
if(aLength < 0)
|
|
121 |
return;
|
|
122 |
|
|
123 |
// Call Credential manager function to get the nonce string
|
|
124 |
SmfCredMgrClient csmClient;
|
|
125 |
aNonceString = csmClient.GenerateNONCE(aLength);
|
|
126 |
}
|
|
127 |
|
|
128 |
/**
|
|
129 |
* Method called by plugins to generate a parameters string required to
|
|
130 |
* access Protected Resources using OAuth authorization.
|
|
131 |
* @param aRequestUrl The request URL
|
|
132 |
* @param aOperation The type of http operation
|
|
133 |
* @param aToken The access token
|
|
134 |
* @param aTokenSecret The token secret
|
|
135 |
* @param aSignatureMethod The signature method to be used
|
|
136 |
* @param aParams A map of parameters to its values
|
|
137 |
* @param aMode The mode of creation of the request
|
|
138 |
* @return The cretd parameter string
|
|
139 |
*/
|
|
140 |
QByteArray SmfPluginUtil::createParameterString( const QString &aRequestUrl,
|
|
141 |
QNetworkAccessManager::Operation aOperation,
|
|
142 |
const QByteArray &aToken,
|
|
143 |
const QByteArray &aTokenSecret,
|
|
144 |
const SmfSignatureMethod aSignatureMethod,
|
|
145 |
const QMultiMap<QByteArray, QByteArray> &aParams,
|
|
146 |
const SmfParsingMode aMode)
|
|
147 |
{
|
|
148 |
Q_UNUSED(aRequestUrl)
|
|
149 |
Q_UNUSED(aOperation)
|
|
150 |
Q_UNUSED(aToken)
|
|
151 |
Q_UNUSED(aTokenSecret)
|
|
152 |
Q_UNUSED(aSignatureMethod)
|
|
153 |
Q_UNUSED(aParams)
|
|
154 |
Q_UNUSED(aMode)
|
|
155 |
return QByteArray();
|
|
156 |
//// Call Credential manager function to create and sign the parameter string
|
|
157 |
}
|
|
158 |
|