1 |
1 |
2 // Include files |
2 // Include files |
3 #include "sampleplugin.h" |
3 #include "sampleplugin.h" |
4 #include <QNetworkRequest> |
4 #include <QNetworkRequest> |
5 #include <QNetworkAccessManager> |
5 #include <QNetworkAccessManager> |
|
6 #include <qfile.h> |
|
7 #include <stdio.h> |
6 |
8 |
7 /** |
9 /** |
8 * Constructor with default argument |
10 * Constructor with default argument |
9 * @param aUtil The SmfPluginUtil instance. The plugins can |
11 * @param aUtil The SmfPluginUtil instance. The plugins can |
10 * call the method getAuthKeys() of this class, with its pluginID to |
12 * call the method getAuthKeys() of this class, with its pluginID to |
84 SmfPluginError error; |
86 SmfPluginError error; |
85 QString url = m_provider->serviceUrl().toString(); |
87 QString url = m_provider->serviceUrl().toString(); |
86 |
88 |
87 // Get the oAuth keys from The Smf Server |
89 // Get the oAuth keys from The Smf Server |
88 QMap<QString, QString> keys; |
90 QMap<QString, QString> keys; |
89 m_util->getAuthKeys(keys, m_provider->pluginId()); |
91 QString registrationToken = retrievePrivateRegToken(); |
|
92 m_util->getAuthKeys(keys, registrationToken, m_provider->pluginId()); |
90 |
93 |
91 // Unable to get the tokens |
94 // Unable to get the tokens |
92 if(keys.isEmpty()) |
95 if(keys.isEmpty()) |
93 error = SmfPluginErrInvalidApplication; |
96 error = SmfPluginErrInvalidApplication; |
94 else |
97 else |
240 |
243 |
241 // Create a map of the arguments keys and their repective values |
244 // Create a map of the arguments keys and their repective values |
242 QMultiMap<QByteArray, QByteArray> params; |
245 QMultiMap<QByteArray, QByteArray> params; |
243 params.insert("method", "postComment"); |
246 params.insert("method", "postComment"); |
244 params.insert("photoId", aImage.id().toAscii()); |
247 params.insert("photoId", aImage.id().toAscii()); |
245 params.insert("comment", aImage.comments().join(" ").toAscii()); |
248 params.insert("comment", "excellent Himalaya"); |
246 |
249 |
247 QNetworkAccessManager::Operation type = QNetworkAccessManager::GetOperation; |
250 QNetworkAccessManager::Operation type = QNetworkAccessManager::GetOperation; |
248 SmfSignatureMethod signMethod = HMAC_SHA1; |
251 SmfSignatureMethod signMethod = HMAC_SHA1; |
249 SmfParsingMode mode = ParseForInlineQuery; |
252 SmfParsingMode mode = ParseForInlineQuery; |
250 |
253 |
251 error = createRequest(aRequest, type, signMethod, params, mode, NULL); |
254 error = createRequest(aRequest, type, signMethod, params, mode, NULL); |
252 return error; |
255 return error; |
253 } |
256 } |
|
257 |
|
258 /** |
|
259 * This function retrieves the registration token that was provided to Authentication App |
|
260 * while authenticatiing user with the service |
|
261 * |
|
262 * Plugin source codes are not open source - so free to use anything they like |
|
263 */ |
|
264 QString SamplePlugin::retrievePrivateRegToken() |
|
265 { |
|
266 |
|
267 /** |
|
268 * This is a private implementation - |
|
269 * implementer might choose to use registry to store/retrieve this token |
|
270 * or to write encrypted (symmetric) token to a file kept at known dir |
|
271 */ |
|
272 QFile qf("/resource/data/sampleplugindata.dat"); |
|
273 qf.open(QIODevice::ReadOnly); |
|
274 QByteArray qba = qf.read(20); |
|
275 qba.chop(5); |
|
276 QString rs(qba.toBase64()); |
|
277 return rs; |
|
278 } |
|
279 |
254 |
280 |
255 /** |
281 /** |
256 * Method to get the provider information |
282 * Method to get the provider information |
257 * @return Instance of SmfProviderBase |
283 * @return Instance of SmfProviderBase |
258 */ |
284 */ |