17
|
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 "{License}"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "{LicenseUrl}".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Narasimhulu Kavadapu, Sasken Communication Technologies Ltd - Initial contribution
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
* class to maintian session & all credential keys.
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "sessionSP.h"
|
|
19 |
#include "requestSP.h"
|
|
20 |
#include <qfile.h>
|
|
21 |
#include <QTimer>
|
|
22 |
#include <qdebug.h>
|
|
23 |
|
|
24 |
#include "keys.h"
|
|
25 |
|
|
26 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
27 |
// global
|
|
28 |
|
|
29 |
static const QString kAPIRestURL = "http://api.flickr.com/services/rest/";
|
|
30 |
|
|
31 |
static const int kMaxBurstRequests = 3;
|
|
32 |
static const int kBurstDuration = 2;
|
|
33 |
|
|
34 |
static FBSession* sharedSession = NULL;
|
|
35 |
|
|
36 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
37 |
// Static class functions
|
|
38 |
FBSession* FBSession::session()
|
|
39 |
{
|
|
40 |
return sharedSession;
|
|
41 |
}
|
|
42 |
|
|
43 |
void FBSession::setSession(FBSession* aSession)
|
|
44 |
{
|
|
45 |
sharedSession = aSession;
|
|
46 |
}
|
|
47 |
|
|
48 |
|
|
49 |
FBSession* FBSession::sessionForApplication ( const QString& aAppKey, const QString& aAppSecret, const QString& aSessionProxy)
|
|
50 |
{
|
|
51 |
FBSession* session = new FBSession ( aAppKey, aAppSecret, aSessionProxy );
|
|
52 |
return session;
|
|
53 |
}
|
|
54 |
|
|
55 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
56 |
// instance public functions
|
|
57 |
FBSession::FBSession( const QString& aAppKey, const QString& aAppSecret, const QString& aGetSessionProxy ) :
|
|
58 |
iApiKey (aAppKey),
|
|
59 |
iApiSecret ( aAppSecret ),
|
|
60 |
m_Client(new SmfCredMgrClient(this))
|
|
61 |
{
|
|
62 |
if (!sharedSession)
|
|
63 |
{
|
|
64 |
sharedSession = this;
|
|
65 |
}
|
|
66 |
}
|
|
67 |
|
|
68 |
FBSession::~FBSession()
|
|
69 |
{
|
|
70 |
if(m_Client){
|
|
71 |
delete m_Client;
|
|
72 |
m_Client = NULL;
|
|
73 |
}
|
|
74 |
}
|
|
75 |
|
|
76 |
const QString& FBSession::apiURL() const
|
|
77 |
{
|
|
78 |
return kAPIRestURL;
|
|
79 |
}
|
|
80 |
void FBSession::SaveFrobKey (const QString& frob )
|
|
81 |
{
|
|
82 |
iFrobKey = frob;
|
|
83 |
//save();
|
|
84 |
}
|
|
85 |
void FBSession::Savetoken (const QString& token )
|
|
86 |
{
|
|
87 |
qDebug()<<"Inside FBSession::Savetoken";
|
|
88 |
qDebug()<<"token argument = "<<token;
|
|
89 |
iToken = token;
|
|
90 |
save();
|
|
91 |
emit sessionDidLogin(token);
|
|
92 |
}
|
|
93 |
bool FBSession::resume()
|
|
94 |
{
|
|
95 |
QString CMRegToken = iSettings.value("CMFlickrRegToken", "NA" ).toString();
|
|
96 |
QDateTime ExpiryTime = iSettings.value("FlckrExpiryTime","NA").toDateTime();
|
|
97 |
|
|
98 |
qDebug() << "CMRegToken = :" << CMRegToken;
|
|
99 |
qDebug() << "ExpiryTime = :" << ExpiryTime;
|
|
100 |
|
|
101 |
SmfAuthParams Params;
|
|
102 |
if(m_Client->AuthDataSet(CMRegToken,ExpiryTime,Params))
|
|
103 |
{
|
|
104 |
QByteArray accessToken = Params.value("finalToken");
|
|
105 |
emit sessionDidLogin( accessToken );
|
|
106 |
return true;
|
|
107 |
}
|
|
108 |
return false;
|
|
109 |
}
|
|
110 |
void FBSession::logout() {
|
|
111 |
|
|
112 |
iToken.clear();
|
|
113 |
iFrobKey.clear();
|
|
114 |
|
|
115 |
unsave();
|
|
116 |
|
|
117 |
emit sessionDidLogout();
|
|
118 |
}
|
|
119 |
|
|
120 |
void FBSession::send (FBRequest* aRequest) {
|
|
121 |
qDebug()<<"Inside FBSession::send";
|
|
122 |
performRequest (aRequest, true);
|
|
123 |
}
|
|
124 |
|
|
125 |
|
|
126 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
127 |
// instance private functions
|
|
128 |
void FBSession::save()
|
|
129 |
{
|
|
130 |
qDebug()<<"Inside FBSession::save()";
|
|
131 |
qDebug()<<"Auth token = "<<iToken;
|
|
132 |
/* if (iFrobKey.length()) {
|
|
133 |
iSettings.setValue("FrobKey", iFrobKey);
|
|
134 |
} else {
|
|
135 |
iSettings.remove("FrobKey");
|
|
136 |
}
|
|
137 |
if (iToken.length()) {
|
|
138 |
iSettings.setValue("FullToken", iToken);
|
|
139 |
} else {
|
|
140 |
iSettings.remove("FullToken");
|
|
141 |
}
|
|
142 |
|
|
143 |
iSettings.sync();*/
|
|
144 |
|
|
145 |
|
|
146 |
SmfAuthParams Params;
|
|
147 |
Params.insert("ApiKey",kApiKey.toAscii());
|
|
148 |
Params.insert("ApiSecret",kApiSecret.toAscii());
|
|
149 |
Params.insert("AuthToken",iToken.toAscii());
|
|
150 |
|
|
151 |
QList<QUrl> UrlList;
|
|
152 |
UrlList.append(QUrl("http://api.flickr.com"));
|
|
153 |
|
|
154 |
QStringList PluginList;
|
|
155 |
PluginList.append(QString("flickrcontactfetcherplugin.qtplugin"));
|
|
156 |
PluginList.append(QString("flickrgalleryplugin.qtplugin"));
|
|
157 |
|
|
158 |
QString UID("0xE1D8C7D7");
|
|
159 |
|
|
160 |
//Currently Hardcoded with current time bcoz CM is not handling expiry time as '0' value
|
|
161 |
QDateTime ExpirationDate = QDateTime::currentDateTime();
|
|
162 |
ExpirationDate.addYears(1);
|
|
163 |
|
|
164 |
QString CMRegToken = m_Client->StoreAuthData(Params,ExpirationDate,UrlList,PluginList,UID,true);
|
|
165 |
|
|
166 |
qDebug()<<"Reg token from CSM = "<<CMRegToken;
|
|
167 |
qDebug()<<"Reg token size = "<<CMRegToken.count();
|
|
168 |
qDebug()<<"Exp date from CSM = "<<ExpirationDate;
|
|
169 |
|
|
170 |
iSettings.remove("CMFlickrRegToken");
|
|
171 |
iSettings.remove("FlckrExpiryTime");
|
|
172 |
|
|
173 |
if(CMRegToken.size())
|
|
174 |
{
|
|
175 |
iSettings.setValue("CMFlickrRegToken", CMRegToken);
|
|
176 |
iSettings.setValue("FlckrExpiryTime", ExpirationDate);
|
|
177 |
}
|
|
178 |
}
|
|
179 |
|
|
180 |
void FBSession::unsave()
|
|
181 |
{
|
|
182 |
|
|
183 |
}
|
|
184 |
bool FBSession::performRequest(FBRequest* aRequest, bool aEnqueue) {
|
|
185 |
// Stagger requests that happen in short bursts to prevent the server from rejecting
|
|
186 |
// them for making too many requests in a short time
|
|
187 |
qDebug()<<"Inside FBSession::performRequest";
|
|
188 |
aRequest->connect();
|
|
189 |
return true;
|
|
190 |
}
|