addded cookiehander class
authorlampehe-local <henri.lampela@ixonos.com>
Fri, 14 May 2010 09:14:50 +0000 (12:14 +0300)
committerlampehe-local <henri.lampela@ixonos.com>
Fri, 14 May 2010 09:14:50 +0000 (12:14 +0300)
src/cookiehandler/cookiehandler.cpp [new file with mode: 0644]
src/cookiehandler/cookiehandler.h [new file with mode: 0644]
src/situareservice/situareservice.cpp
src/situareservice/situareservice.h
src/src.pro

diff --git a/src/cookiehandler/cookiehandler.cpp b/src/cookiehandler/cookiehandler.cpp
new file mode 100644 (file)
index 0000000..df6df19
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+      Henri Lampela - henri.lampela@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#include <QDebug>
+#include <QStringList>
+#include "cookiehandler.h"
+
+CookieHandler::CookieHandler()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+}
+
+CookieHandler::~CookieHandler()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+}
+
+QString CookieHandler::formCookie(const QString &apiKeyValue, QString expiresValue,
+                                  QString userValue, QString sessionKeyValue,
+                                  QString sessionSecretValue, const QString &signatureValue,
+                                  const QString &localeValue)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QString cookie;
+    QString apiKey;
+    QString user;
+    QString expires;
+    QString sessionKey;
+    QString sessionSecret;
+    QString locale;
+    QString variable;
+    QString signature = EQUAL_MARK;
+    QStringList variableList;
+
+    signature.append(signatureValue);
+    apiKey.append(apiKeyValue);
+    apiKey.append(UNDERLINE_MARK);
+
+    user.append(USER);
+    user.append(EQUAL_MARK);
+    expires.append(EXPIRES);
+    expires.append(EQUAL_MARK);
+    sessionKey.append(SESSION_KEY);
+    sessionKey.append(EQUAL_MARK);
+    sessionSecret.append(SESSION_SECRET);
+    sessionSecret.append(EQUAL_MARK);
+    locale.append(LOCALE);
+    locale.append(EQUAL_MARK);
+    locale.append(localeValue);
+
+    variableList.append(expires.append(expiresValue.append(BREAK_MARK)));
+    variableList.append(sessionKey.append(sessionKeyValue.append(BREAK_MARK)));
+    variableList.append(user.append(userValue).append(BREAK_MARK));
+    variableList.append(sessionSecret.append(sessionSecretValue.append(BREAK_MARK)));
+
+    cookie.append(BREAK_MARK);
+
+    foreach(variable, variableList) {
+        cookie.append(apiKey);
+        cookie.append(variable);
+    }
+    apiKey.remove(UNDERLINE_MARK);
+    cookie.append(apiKey);
+    cookie.append(signature);
+    cookie.append(BREAK_MARK);
+    cookie.append(locale);
+
+    qDebug() << cookie;
+
+    return cookie;
+}
diff --git a/src/cookiehandler/cookiehandler.h b/src/cookiehandler/cookiehandler.h
new file mode 100644 (file)
index 0000000..afc72c1
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+      Henri Lampela - henri.lampela@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#ifndef COOKIEHANDLER_H
+#define COOKIEHANDLER_H
+
+#include <QString>
+#include "../situareservice/situarecommon.h"
+
+/**
+* @brief Class for cookie cretion.
+*
+* @author Henri Lampela
+* @class CookieHandler cookiehandler.h "cookiehandler/cookiehandler.h"
+*/
+class CookieHandler
+{
+public:
+
+    /**
+    * @brief Default constructor
+    *
+    */
+    CookieHandler();
+
+    /**
+    * @brief Destructor
+    *
+    */
+    ~CookieHandler();
+
+    /**
+    * @brief Forms a http cookie
+    *
+    * @param apiKeyValue application key
+    * @param expiresValue session expire date&time from Facebook
+    * @param userValue user id from Facebook
+    * @param sessionKeyValue session key from Facebook
+    * @param sessionSecretValue session secret from Facebook
+    * @param signatureValue md5 generated signature
+    * @param localeValue used locale
+    * @return QString formed cookie
+    */
+    QString formCookie(const QString &apiKeyValue, QString expiresValue, QString userValue,
+                       QString sessionKeyValue, QString sessionSecretValue,
+                       const QString &signatureValue, const QString &localeValue);
+
+};
+
+#endif // COOKIEHANDLER_H
index c9080a8..c0c594d 100644 (file)
@@ -27,6 +27,7 @@
 #include <QNetworkReply>
 #include "situareservice.h"
 #include "situarecommon.h"
+#include "../cookiehandler/cookiehandler.h"
 #include "parser.h"
 
 SituareService::SituareService(QObject *parent)
@@ -67,9 +68,11 @@ void SituareService::fetchLocations()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QString cookie = formCookie(API_KEY, m_credentials.expires(),m_credentials.userID(),
-                                m_credentials.sessionKey(), m_credentials.sessionSecret(),
-                                m_credentials.sig(), EN_LOCALE);
+    CookieHandler cookieHandler;
+
+    QString cookie = cookieHandler.formCookie(API_KEY, m_credentials.expires(), m_credentials.userID(),
+                                              m_credentials.sessionKey(), m_credentials.sessionSecret(),
+                                              m_credentials.sig(), EN_LOCALE);
 
     QUrl url = formUrl(SITUARE_URL, GET_LOCATIONS);
     sendRequest(url, COOKIE, cookie);
@@ -79,9 +82,11 @@ void SituareService::reverseGeo(const QPointF &coordinates)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QString cookie = formCookie(API_KEY, m_credentials.expires(),m_credentials.userID(),
-                                m_credentials.sessionKey(), m_credentials.sessionSecret(),
-                                m_credentials.sig(), EN_LOCALE);
+    CookieHandler cookieHandler;
+
+    QString cookie = cookieHandler.formCookie(API_KEY, m_credentials.expires(), m_credentials.userID(),
+                                              m_credentials.sessionKey(), m_credentials.sessionSecret(),
+                                              m_credentials.sig(), EN_LOCALE);
 
     QString urlParameters = formUrlParameters(coordinates);
     QUrl url = formUrl(SITUARE_URL, REVERSE_GEO, urlParameters);
@@ -94,9 +99,11 @@ void SituareService::updateLocation(const QPointF &coordinates, const QString &s
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QString cookie = formCookie(API_KEY, m_credentials.expires(),m_credentials.userID(),
-                                m_credentials.sessionKey(), m_credentials.sessionSecret(),
-                                m_credentials.sig(), EN_LOCALE);
+    CookieHandler cookieHandler;
+
+    QString cookie = cookieHandler.formCookie(API_KEY, m_credentials.expires(), m_credentials.userID(),
+                                              m_credentials.sessionKey(), m_credentials.sessionSecret(),
+                                              m_credentials.sig(), EN_LOCALE);
 
 
     QString publishValue;
@@ -112,64 +119,7 @@ void SituareService::updateLocation(const QPointF &coordinates, const QString &s
     sendRequest(url, COOKIE, cookie);
 }
 
-QString SituareService::formCookie(const QString &apiKeyValue, QString expiresValue,
-                                   QString userValue, QString sessionKeyValue,
-                                   QString sessionSecretValue, const QString &signatureValue,
-                                   const QString &localeValue)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    QString cookie;
-    QString apiKey;
-    QString user;
-    QString expires;
-    QString sessionKey;
-    QString sessionSecret;
-    QString locale;
-    QString variable;
-    QString signature = EQUAL_MARK;
-    QStringList variableList;
-
-    signature.append(signatureValue);
-    apiKey.append(apiKeyValue);
-    apiKey.append(UNDERLINE_MARK);
-
-    user.append(USER);
-    user.append(EQUAL_MARK);
-    expires.append(EXPIRES);
-    expires.append(EQUAL_MARK);
-    sessionKey.append(SESSION_KEY);
-    sessionKey.append(EQUAL_MARK);
-    sessionSecret.append(SESSION_SECRET);
-    sessionSecret.append(EQUAL_MARK);
-    locale.append(LOCALE);
-    locale.append(EQUAL_MARK);
-    locale.append(localeValue);
-
-    variableList.append(expires.append(expiresValue.append(BREAK_MARK)));
-    variableList.append(sessionKey.append(sessionKeyValue.append(BREAK_MARK)));
-    variableList.append(user.append(userValue).append(BREAK_MARK));
-    variableList.append(sessionSecret.append(sessionSecretValue.append(BREAK_MARK)));
-
-    cookie.append(BREAK_MARK);
-
-    foreach(variable, variableList) {
-        cookie.append(apiKey);
-        cookie.append(variable);
-    }
-    apiKey.remove(UNDERLINE_MARK);
-    cookie.append(apiKey);
-    cookie.append(signature);
-    cookie.append(BREAK_MARK);
-    cookie.append(locale);
-
-    qDebug() << cookie;
-
-    return cookie;
-}
-
-QUrl SituareService::formUrl(const QString &baseUrl, const QString &phpScript,
-                             QString urlParameters)
+QUrl SituareService::formUrl(const QString &baseUrl, const QString &phpScript, QString urlParameters)
 {
     qDebug() << __PRETTY_FUNCTION__;
     QString urlString;
@@ -186,8 +136,7 @@ QUrl SituareService::formUrl(const QString &baseUrl, const QString &phpScript,
     return url;
 }
 
-QString SituareService::formUrlParameters(const QPointF &coordinates, QString status,
-                                          QString publish)
+QString SituareService::formUrlParameters(const QPointF &coordinates, QString status, QString publish)
 {
     QString parameters;
 
@@ -271,7 +220,7 @@ void SituareService::requestFinished(QNetworkReply *reply)
             parseUserData(replyArray);
         }
         else if(replyArray == "") {
-                       if(url.toString().contains(UPDATE_LOCATION.toAscii())) {
+            if(url.toString().contains(UPDATE_LOCATION.toAscii())) {
                 emit updateWasSuccessful();
             }
             else {
index 821921b..605dfe9 100644 (file)
@@ -104,22 +104,6 @@ public slots:
 private:
 
     /**
-    * @brief Forms a http cookie
-    *
-    * @param apiKeyValue application key
-    * @param expiresValue session expire date&time from Facebook
-    * @param userValue user id from Facebook
-    * @param sessionKeyValue session key from Facebook
-    * @param sessionSecretValue session secret from Facebook
-    * @param signatureValue md5 generated signature
-    * @param localeValue used locale
-    * @return QString formed cookie
-    */
-    QString formCookie(const QString &apiKeyValue, QString expiresValue, QString userValue,
-                       QString sessionKeyValue, QString sessionSecretValue,
-                       const QString &signatureValue, const QString &localeValue);
-
-    /**
     * @brief Forms a http url
     *
     * @param baseUrl Server url
index bf3e3e7..6528f45 100644 (file)
@@ -11,6 +11,7 @@ SOURCES += main.cpp \
     ui/mapviewscreen.cpp \
     situareservice/situareservice.cpp \
     situareservice/imagefetcher.cpp \
+    cookiehandler/cookiehandler.cpp \
     facebookservice/facebookcredentials.cpp \
     facebookservice/facebookauthentication.cpp \
     map/mapengine.cpp \
@@ -59,6 +60,7 @@ HEADERS += ui/mainwindow.h \
     situareservice/situareservice.h \
     situareservice/situarecommon.h \
     situareservice/imagefetcher.h \
+    cookiehandler/cookiehandler.h \
     facebookservice/facebookcredentials.h \
     facebookservice/facebookauthentication.h \
     facebookservice/facebookcommon.h \