@@ -0,0 +1,84 @@
/*
* Copyright 2010 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/
/*!
* \file Session.cpp
* \brief Implementation of the class Session
*
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */

#include "Session.h"

Session::Session(const QString &sessionToken, const QDateTime &lastAccessTime, const QSharedPointer<common::User> &user)
: m_sessionToken(sessionToken),
m_lastAccessTime(lastAccessTime),
m_user(user)
{
}

void Session::setSessionToken(const QString &sessionToken)
{
m_sessionToken = sessionToken;
}

void Session::setLastAccessTime(const QDateTime lastAccessTime)
{
m_lastAccessTime = lastAccessTime;
}

void Session::setUser(const QSharedPointer<common::User> &user)
{
m_user = user;
}

const QString& Session::getSessionToken() const
{
return m_sessionToken;
}

const QDateTime& Session::getLastAccessTime() const
{
return m_lastAccessTime;
}

const QSharedPointer<common::User>& Session::getUser() const
{
return m_user;
}

qlonglong Session::getId() const
{
return 0;
}

Session::~Session()
{
}
@@ -11,6 +11,7 @@ SOURCES += \
../../http_requests/src/VersionQuery.cpp \
../../http_requests/src/DeleteUserQuery.cpp \
../../json/src/JsonUser.cpp \
../../json/src/JsonSession.cpp \
../../json/src/JsonSerializer.cpp \
../../json/src/LoginRequestJSON.cpp \
../../json/src/LoginResponseJSON.cpp \
@@ -19,6 +20,7 @@ SOURCES += \
../../json/src/DefaultResponseJSON.cpp \
../../json/src/VersionResponseJSON.cpp \
../../common/src/signals.cpp \
../../common/src/session.cpp \
Test_RegisterUserQuery.cpp

HEADERS += \
@@ -28,6 +30,7 @@ HEADERS += \
../../http_requests/inc/VersionQuery.h \
../../http_requests/inc/DeleteUserQuery.h \
../../json/inc/JsonUser.h \
../../json/inc/JsonSession.h \
../../json/inc/JsonSerializer.h \
../../json/inc/LoginRequestJSON.h \
../../json/inc/LoginResponseJSON.h \
@@ -36,6 +39,7 @@ HEADERS += \
../../json/inc/VersionResponseJSON.h \
../../json/inc/DefaultResponseJSON.h \
../../common/inc/signals.h \
../../common/inc/session.h \
VersionQuery_Test.h \
DeleteUserQuery_Test.h \
Test_RegisterUserQuery.h
@@ -41,6 +41,7 @@
#include "DataMarks.h"
#include "Channel.h"
#include "User.h"
#include "Session.h"
#include "TimeSlot.h"

class JsonSerializer:public QObject
@@ -50,6 +51,7 @@ class JsonSerializer:public QObject
QSharedPointer<Channels> m_channelsContainer;
QSharedPointer<DataMarks> m_tagsContainer;
QSharedPointer<common::Users> m_usersContainer;
QSharedPointer<Sessions> m_sessionsContainer;

QVariantMap m_jsonTree;

@@ -65,6 +67,7 @@ class JsonSerializer:public QObject
void addChannel(const QSharedPointer<Channel>&);
void addTag(const QSharedPointer<DataMark>&);
void addUser(const QSharedPointer<common::User>&);
void addSession(const QSharedPointer<Session>&);

virtual QByteArray getJson() const = 0;

@@ -73,6 +76,7 @@ class JsonSerializer:public QObject
QSharedPointer<DataMarks> getTags() const;
QSharedPointer<common::Users> getUsers() const;
QSharedPointer<Channels> getChannels() const;
QSharedPointer<Sessions> getSessions() const;

const QString& getStatus() const;
void setStatus(const QString&);
@@ -0,0 +1,59 @@
/*
* Copyright 2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/
/*!
* \file JsonSession.h
* \brief Header of JsonSession
*
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */

#ifndef JSONSESSION_H
#define JSONSESSION_H

#include "Session.h"

class JsonSession: public Session
{
static qlonglong globalSessionId;
qlonglong m_id;

public:
JsonSession(const QString& sessionToken,
const QDateTime& lastAccessTime,
const QSharedPointer<common::User>& user);

qlonglong getId() const;
void setId(qlonglong);

~JsonSession();
};

#endif // JSONSESSION_H
@@ -53,7 +53,7 @@ class LoadTagsRequestJSON: public JsonSerializer
double getLatitude() const;
double getLongitude() const;
double getRadius() const;
QString getAuthToken() const;
QString getSessionToken() const;

void setLatitude(double latitude);
void setLongitude(double longitude);
@@ -0,0 +1,60 @@
/*
* Copyright 2010-2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/
/*----------------------------------------------------------------- !
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */

#ifndef QUITSESSIONREQUESTJSON_H
#define QUITSESSIONREQUESTJSON_H

#include "JsonSerializer.h"

#include <QString>

class QuitSessionRequestJSON: public JsonSerializer
{
private:
QString m_sessionToken;

public:
QuitSessionRequestJSON(QString sessionToken, QObject *parent = 0);
QuitSessionRequestJSON(QObject *parent = 0);

void setSessionToken(QString sessionToken);
QString getSessionToken() const;

QByteArray getJson() const;
bool parseJson(const QByteArray&);

~QuitSessionRequestJSON();
};

#endif // QUITSESSIONREQUESTJSON_H
@@ -0,0 +1,56 @@
/*
* Copyright 2010-2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/
/*----------------------------------------------------------------- !
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */

#ifndef QUITSESSIONRESPONSEJSON_H
#define QUITSESSIONRESPONSEJSON_H

#include "JsonSerializer.h"

#include <QString>

class QuitSessionResponseJSON: public JsonSerializer
{
private:
QString m_sessionToken;

public:
QuitSessionResponseJSON(QObject *parent = 0);

QByteArray getJson() const;
bool parseJson(const QByteArray&);

~QuitSessionResponseJSON();
};

#endif // QUITSESSIONRESPONSEJSON_H
@@ -51,7 +51,10 @@ HEADERS += \
inc/FilterChannelResponseJSON.h \
inc/DeleteUserRequestJSON.h \
inc/DeleteUserResponseJSON.h \
inc/BuildResponseJSON.h
inc/BuildResponseJSON.h \
inc/QuitSessionRequestJSON.h \
inc/QuitSessionResponseJSON.h \
inc/JsonSession.h

SOURCES += \
src/AvailableChannelsResponseJSON.cpp \
@@ -83,7 +86,10 @@ SOURCES += \
src/VersionResponseJSON.cpp \
src/AddUserRequestJSON.cpp \
src/FilterChannelRequestJSON.cpp \
src/FilterChannelResponseJSON.cpp
src/FilterChannelResponseJSON.cpp \
src/QuitSessionRequestJSON.cpp \
src/QuitSessionResponseJSON.cpp \
src/JsonSession.cpp


LIBS += -lcommon -lqjson
@@ -33,7 +33,7 @@
* ---------------------------------------------------------------- */

#include "AddChannelRequestJSON.h"
#include "JsonUser.h"
#include "JsonSession.h"
#include "JsonChannel.h"

#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_SIMULATOR)
@@ -53,7 +53,7 @@ QByteArray AddChannelRequestJSON::getJson() const
{
QJson::Serializer serializer;
QVariantMap obj;
obj.insert("auth_token", m_usersContainer->at(0)->getToken());
obj.insert("auth_token", m_sessionsContainer->at(0)->getSessionToken());
obj.insert("name", m_channelsContainer->at(0)->getName());
obj.insert("description",m_channelsContainer->at(0)->getDescription());
obj.insert("url",m_channelsContainer->at(0)->getUrl());
@@ -74,7 +74,7 @@ bool AddChannelRequestJSON::parseJson(const QByteArray&data)
QString name = result["name"].toString();
QString description = result["description"].toString();
QString url = result["url"].toString();
m_usersContainer->push_back(QSharedPointer<common::User>(new JsonUser("unknown","unknown",auth_token)));
m_sessionsContainer->push_back(QSharedPointer<Session>(new JsonSession(auth_token, QDateTime::currentDateTime(), QSharedPointer<common::User>(NULL))));
m_channelsContainer->push_back(QSharedPointer<Channel>(new JsonChannel(name,description,url)));
return true;
}
@@ -41,7 +41,7 @@

#include "FilterChannelRequestJSON.h"

#include "JsonUser.h"
#include "JsonSession.h"

#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_SIMULATOR)
#include <qjson/parser.h>
@@ -72,8 +72,8 @@ bool FilterChannelRequestJSON::parseJson(const QByteArray&data)
QVariantMap result = parser.parse(data, &ok).toMap();
if (!ok) return false;

QString authToken = result["auth_token"].toString();
m_usersContainer->push_back(QSharedPointer<common::User>(new JsonUser("none", "none", authToken)));
QString auth_token = result["auth_token"].toString();
m_sessionsContainer->push_back(QSharedPointer<Session>(new JsonSession(auth_token, QDateTime::currentDateTime(), QSharedPointer<common::User>(NULL))));

m_channel = result["channel"].toString();
m_amount = result["amount"].toInt(&ok);
@@ -40,7 +40,7 @@
* ---------------------------------------------------------------- */

#include "FilterCircleRequestJSON.h"
#include "JsonUser.h"
#include "JsonSession.h"

#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_SIMULATOR)
#include <qjson/parser.h>
@@ -59,7 +59,7 @@ QByteArray FilterCircleRequestJSON::getJson() const
{
QJson::Serializer serializer;
QVariantMap obj;
obj.insert("auth_token",m_usersContainer->at(0)->getToken());
obj.insert("auth_token",m_sessionsContainer->at(0)->getSessionToken());
obj.insert("latitude", m_latitude);
obj.insert("longitude", m_longitude);
obj.insert("radius", m_radius);
@@ -83,7 +83,7 @@ bool FilterCircleRequestJSON::parseJson(const QByteArray&data)
{
return false;
}
QString authToken = result["auth_token"].toString();
QString auth_token = result["auth_token"].toString();
setTimeFrom(QDateTime::fromString(result["time_from"].toString(), "dd MM yyyy HH:mm:ss.zzz"));
setTimeTo(QDateTime::fromString(result["time_to"].toString(), "dd MM yyyy HH:mm:ss.zzz"));
double latitude = result["latitude"].toDouble(&ok);
@@ -96,7 +96,7 @@ bool FilterCircleRequestJSON::parseJson(const QByteArray&data)
if (!ok) return false;

FilterRequestJSON::setShape(QSharedPointer<FShape>(new FShapeCircle(latitude, longitude, radius)));
m_usersContainer->push_back(QSharedPointer<common::User>(new JsonUser("null", "null", authToken)));
m_sessionsContainer->push_back(QSharedPointer<Session>(new JsonSession(auth_token, QDateTime::currentDateTime(), QSharedPointer<common::User>(NULL))));
return true;
}

@@ -40,7 +40,7 @@
* ---------------------------------------------------------------- */

#include "FilterPolygonRequestJSON.h"
#include "JsonUser.h"
#include "JsonSession.h"
#include "FShape.h"
#include "FShapePolygon.h"

@@ -62,7 +62,7 @@ QByteArray FilterPolygonRequestJSON::getJson() const
// TODO it's necessary for symbian client
QJson::Serializer serializer;
QVariantMap obj;
obj.insert("auth_token", m_usersContainer->at(0)->getToken());
obj.insert("auth_token", m_sessionsContainer->at(0)->getSessionToken());
return serializer.serialize(obj);
}

@@ -77,7 +77,7 @@ bool FilterPolygonRequestJSON::parseJson(const QByteArray&data)
QVariantMap result = parser.parse(data, &ok).toMap();
if (!ok) return false;

QString authToken = result["auth_token"].toString();
QString auth_token = result["auth_token"].toString();
setTimeFrom(QDateTime::fromString(result["time_from"].toString(), "dd MM yyyy HH:mm:ss.zzz"));
setTimeTo(QDateTime::fromString(result["time_to"].toString(), "dd MM yyyy HH:mm:ss.zzz"));

@@ -98,6 +98,6 @@ bool FilterPolygonRequestJSON::parseJson(const QByteArray&data)
shape->addPoint(number, lat, lon);
}
setShape(QSharedPointer<FShape>(shape));
m_usersContainer->push_back(QSharedPointer<common::User>(new JsonUser("null", "null", authToken)));
m_sessionsContainer->push_back(QSharedPointer<Session>(new JsonSession(auth_token, QDateTime::currentDateTime(), QSharedPointer<common::User>(NULL))));
return true;
}
@@ -42,7 +42,7 @@
#include <syslog.h>
#include "FilterRectangleRequestJSON.h"

#include "JsonUser.h"
#include "JsonSession.h"
#include "FShape.h"
#include "FShapeRectangle.h"

@@ -64,7 +64,7 @@ QByteArray FilterRectangleRequestJSON::getJson() const
// TODO it's necessary for symbian client
QJson::Serializer serializer;
QVariantMap obj;
obj.insert("auth_token", m_usersContainer->at(0)->getToken());
obj.insert("auth_token", m_sessionsContainer->at(0)->getSessionToken());
return serializer.serialize(obj);
}

@@ -78,7 +78,7 @@ bool FilterRectangleRequestJSON::parseJson(const QByteArray&data)
bool ok;
QVariantMap result = parser.parse(data, &ok).toMap();
if (!ok) return false;
QString authToken = result["auth_token"].toString();
QString auth_token = result["auth_token"].toString();
setTimeFrom(QDateTime::fromString(result["time_from"].toString(), "dd MM yyyy HH:mm:ss.zzz"));
setTimeTo(QDateTime::fromString(result["time_to"].toString(), "dd MM yyyy HH:mm:ss.zzz"));

@@ -101,6 +101,6 @@ bool FilterRectangleRequestJSON::parseJson(const QByteArray&data)

FShapeRectangle * shape = new FShapeRectangle(lat1, lon1, lat2, lon2);
setShape(QSharedPointer<FShape>(shape));
m_usersContainer->push_back(QSharedPointer<common::User>(new JsonUser("null", "null", authToken)));
m_sessionsContainer->push_back(QSharedPointer<Session>(new JsonSession(auth_token, QDateTime::currentDateTime(), QSharedPointer<common::User>(NULL))));
return true;
}
@@ -34,10 +34,12 @@

#include "JsonSerializer.h"

JsonSerializer::JsonSerializer(QObject * parent):QObject(parent),
m_channelsContainer(new Channels),
m_tagsContainer(new DataMarks),
m_usersContainer(new common::Users)
JsonSerializer::JsonSerializer(QObject * parent)
: QObject(parent),
m_channelsContainer(new Channels),
m_tagsContainer(new DataMarks),
m_usersContainer(new common::Users),
m_sessionsContainer(new Sessions)
{
}

@@ -65,6 +67,11 @@ QSharedPointer<DataMarks> JsonSerializer::getTags() const
return m_tagsContainer;
}

QSharedPointer<Sessions> JsonSerializer::getSessions() const
{
return m_sessionsContainer;
}


void JsonSerializer::addChannel(const QSharedPointer<Channel> &channel)
{
@@ -78,9 +85,14 @@ void JsonSerializer::addTag(const QSharedPointer<DataMark> &tag)
}


void JsonSerializer::addUser(const QSharedPointer<common::User> &tag)
void JsonSerializer::addUser(const QSharedPointer<common::User> &user)
{
m_usersContainer->push_back(user);
}

void JsonSerializer::addSession(const QSharedPointer<Session> &session)
{
m_usersContainer->push_back(tag);
m_sessionsContainer->push_back(session);
}


@@ -0,0 +1,63 @@
/*
* Copyright 2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/
/*! ---------------------------------------------------------------
* \file JsonSession.cpp
* \brief JsonSession implementation
*
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */

#include "JsonSession.h"

qlonglong JsonSession::globalSessionId = 0;

JsonSession::JsonSession(const QString &sessionToken, const QDateTime &lastAccessTime, const QSharedPointer<common::User> &user)
: Session(sessionToken, lastAccessTime, user),
m_id(globalSessionId++)
{
}


qlonglong JsonSession::getId() const
{
return m_id;
}


void JsonSession::setId(qlonglong id)
{
m_id = id;
}


JsonSession::~JsonSession()
{
}
@@ -33,7 +33,7 @@
#include <QDebug>
#include "LoadTagsRequestJSON.h"

#include "JsonUser.h"
#include "JsonSession.h"
#include "JsonChannel.h"
#include "JsonDataMark.h"

@@ -66,8 +66,8 @@ bool LoadTagsRequestJSON::parseJson(const QByteArray &data)

if (!ok) return false;

QString authToken = result["auth_token"].toString();
m_usersContainer->push_back(QSharedPointer<common::User>(new JsonUser("dummyUser[LoadTagsRequest]","dummyPassword",authToken)));
QString auth_token = result["auth_token"].toString();
m_sessionsContainer->push_back(QSharedPointer<Session>(new JsonSession(auth_token, QDateTime::currentDateTime(), QSharedPointer<common::User>(NULL))));

result["latitude"].toDouble(&ok);
if (!ok) return false;
@@ -93,17 +93,17 @@ QByteArray LoadTagsRequestJSON::getJson() const
{
QJson::Serializer serializer;
QVariantMap obj;
obj.insert("auth_token", getAuthToken());
obj.insert("auth_token", getSessionToken());
obj.insert("latitude", getLatitude());
obj.insert("longitude", getLongitude());
obj.insert("radius", getRadius());
return serializer.serialize(obj);
}


QString LoadTagsRequestJSON::getAuthToken() const
QString LoadTagsRequestJSON::getSessionToken() const
{
return m_usersContainer->at(0)->getToken();
return m_sessionsContainer->at(0)->getSessionToken();
}


@@ -44,6 +44,7 @@

#include "LoginResponseJSON.h"
#include "JsonUser.h"
#include "JsonSession.h"

LoginResponseJSON::LoginResponseJSON(QObject *parent) : JsonSerializer(parent)
{
@@ -54,8 +55,8 @@ QByteArray LoginResponseJSON::getJson() const
{
QJson::Serializer serializer;
QVariantMap obj;
if(m_usersContainer->size()>0)
obj.insert("auth_token", m_usersContainer->at(0)->getToken());
if(m_sessionsContainer->size()>0)
obj.insert("auth_token", m_sessionsContainer->at(0)->getSessionToken());
obj.insert("errno", m_errno);
return serializer.serialize(obj);
}
@@ -75,8 +76,8 @@ bool LoginResponseJSON::parseJson(const QByteArray &data)
if (!ok) return false;
m_errno = result["errno"].toInt(&ok);

QString auth_token = result["auth_token"].toString();
QSharedPointer<common::User> user(new JsonUser("unknown", "unknown", auth_token));
m_usersContainer->push_back(user);
QString session_token = result["auth_token"].toString();
QSharedPointer<Session> session(new JsonSession(session_token, QDateTime::currentDateTime(), QSharedPointer<common::User>(NULL)));
m_sessionsContainer->push_back(session);
return true;
}
@@ -0,0 +1,90 @@
/*
* Copyright 2010-2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/
/*----------------------------------------------------------------- !
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */

#include "QuitSessionRequestJSON.h"
#include "JsonUser.h"

#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_SIMULATOR)
#include <qjson/parser.h>
#include <qjson/serializer.h>
#else
#include "parser.h"
#include "serializer.h"
#endif

QuitSessionRequestJSON::QuitSessionRequestJSON(QString sessionToken, QObject *parent)
: JsonSerializer(parent),
m_sessionToken(sessionToken)

{
}

QuitSessionRequestJSON::QuitSessionRequestJSON(QObject *parent)
: JsonSerializer(parent)
{
}

void QuitSessionRequestJSON::setSessionToken(QString sessionToken)
{
m_sessionToken = sessionToken;
}

QString QuitSessionRequestJSON::getSessionToken() const
{
return m_sessionToken;
}

QByteArray QuitSessionRequestJSON::getJson() const
{
QJson::Serializer serializer;
QVariantMap obj;
obj.insert("auth_token", m_sessionToken);
return serializer.serialize(obj);
}

bool QuitSessionRequestJSON::parseJson(const QByteArray&data)
{
QJson::Parser parser;
bool ok;
QVariantMap result = parser.parse(data, &ok).toMap();
if (!ok) return false;

m_sessionToken = result["auth_token"].toString();

return true;
}

QuitSessionRequestJSON::~QuitSessionRequestJSON()
{
}
@@ -0,0 +1,73 @@
/*
* Copyright 2010-2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/
/*----------------------------------------------------------------- !
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */

#include "QuitSessionResponseJSON.h"
#include "JsonUser.h"

#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_SIMULATOR)
#include <qjson/parser.h>
#include <qjson/serializer.h>
#else
#include "parser.h"
#include "serializer.h"
#endif

QuitSessionResponseJSON::QuitSessionResponseJSON(QObject *parent)
: JsonSerializer(parent)
{
}

QByteArray QuitSessionResponseJSON::getJson() const
{
QJson::Serializer serializer;
QVariantMap obj;
obj.insert("errno", m_errno);
return serializer.serialize(obj);
}

bool QuitSessionResponseJSON::parseJson(const QByteArray&data)
{
QJson::Parser parser;
bool ok;
QVariantMap result = parser.parse(data, &ok).toMap();
if (!ok) return false;

m_errno = result["errno"].toInt();

return true;
}

QuitSessionResponseJSON::~QuitSessionResponseJSON()
{
}
@@ -55,7 +55,7 @@

#include "JsonChannel.h"
#include "JsonDataMark.h"
#include "JsonUser.h"
#include "JsonSession.h"

#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_SIMULATOR)
#include <syslog.h>
@@ -93,12 +93,13 @@ bool SubscribeChannelRequestJSON::parseJson(const QByteArray &data)
if (!ok) return false;

QString channelLabel = result["channel"].toString();
QString authToken = result["auth_token"].toString();
QString auth_token = result["auth_token"].toString();

QSharedPointer<Channel> dummyChannel(new JsonChannel(channelLabel, "from SubscribeChannelReques"));
m_channelsContainer->push_back(dummyChannel);
QSharedPointer<common::User> dummyUser(new JsonUser("unknown", "unknown", authToken));
m_usersContainer->push_back(dummyUser);

QSharedPointer<Session> dummySession(new JsonSession(auth_token, QDateTime::currentDateTime(), QSharedPointer<common::User>(NULL)));
m_sessionsContainer->push_back(dummySession);

return true;
}
@@ -109,7 +110,7 @@ QByteArray SubscribeChannelRequestJSON::getJson() const
QJson::Serializer serializer;
QVariantMap request;

request.insert("auth_token", m_usersContainer->at(0)->getToken());
request.insert("auth_token", m_sessionsContainer->at(0)->getSessionToken());
request.insert("channel", m_channelsContainer->at(0)->getName());

return serializer.serialize(request);
@@ -56,7 +56,7 @@
#include "SubscribedChannelsRequestJSON.h"
#include "JsonChannel.h"
#include "JsonDataMark.h"
#include "JsonUser.h"
#include "JsonSession.h"
//#include <syslog.h>
SubscribedChannelsRequestJSON::SubscribedChannelsRequestJSON()
{
@@ -80,9 +80,10 @@ bool SubscribedChannelsRequestJSON::parseJson(const QByteArray &data)

if (!ok) return false;

QString authToken = result["auth_token"].toString();
QSharedPointer<common::User> dummyUser(new JsonUser("unknown", "unknown", authToken));
m_usersContainer->push_back(dummyUser);
QString auth_token = result["auth_token"].toString();
QSharedPointer<Session> dummySession(new JsonSession(auth_token, QDateTime::currentDateTime(), QSharedPointer<common::User>(NULL)));

m_sessionsContainer->push_back(dummySession);

return true;
}
@@ -93,7 +94,7 @@ QByteArray SubscribedChannelsRequestJSON::getJson() const
QJson::Serializer serializer;
QVariantMap request;

request.insert("auth_token", m_usersContainer->at(0)->getToken());
request.insert("auth_token", m_sessionsContainer->at(0)->getSessionToken());

return serializer.serialize(request);
}
@@ -36,7 +36,7 @@
#include "DataMarks.h"
#include "JsonChannel.h"
#include "JsonDataMark.h"
#include "JsonUser.h"
#include "JsonSession.h"

#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_SIMULATOR)
#include <qjson/parser.h>
@@ -59,7 +59,7 @@ bool WriteTagRequestJSON::parseJson(const QByteArray &data)
QVariantMap result = parser.parse(data, &ok).toMap();
if (!ok) return false;

QString token = result["auth_token"].toString();
QString auth_token = result["auth_token"].toString();
QString channel_name = result["channel"].toString();
QString title = result["title"].toString();
QString link = result["link"].toString();
@@ -74,12 +74,12 @@ bool WriteTagRequestJSON::parseJson(const QByteArray &data)

QDateTime time = QDateTime::fromString(result["time"].toString(), "dd MM yyyy HH:mm:ss.zzz");

QSharedPointer<common::User> user(new JsonUser("unknown", "unknown", token));
QSharedPointer<Session> session(new JsonSession(auth_token, QDateTime::currentDateTime(), QSharedPointer<common::User>(NULL)));
QSharedPointer<Channel> channel(new JsonChannel(channel_name, "unknown"));

QSharedPointer<DataMark> tag(new JsonDataMark(altitude, latitude, longitude, title, description, link, time));
tag->setChannel(channel);
tag->setUser(user);
tag->setSession(session);
m_tagsContainer->push_back(tag);

return true;
@@ -91,7 +91,7 @@ QByteArray WriteTagRequestJSON::getJson() const
QJson::Serializer serializer;
QVariantMap request;
QSharedPointer<DataMark> mark = m_tagsContainer->at(0);
request.insert("auth_token", mark->getUser()->getToken());
request.insert("auth_token", mark->getSession()->getSessionToken());
request.insert("channel", mark->getChannel()->getName());
request.insert("title", mark->getLabel().isEmpty()? "New mark":mark->getLabel());
request.insert("link", mark->getUrl());
@@ -1,7 +1,33 @@
/*
* Copyright <C> 2012 Edward Ryabikov <edward.ryabikov@gmail.com
* Copyright 2010-2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/

/*!
* \file Test_AvailableChannelsResponseJSON.cpp
* \brief Test suite for AvailableChannelsResponseJSON class
@@ -1,7 +1,33 @@
/*
* Copyright <C> 2012 Edward Ryabikov <edward.ryabikov@gmail.com
* Copyright 2010-2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/

/*!
* \file Test_AvailableChannelsResponseJSON.h
* \brief Test suite for AvailableChannelsResponseJSON class
@@ -0,0 +1,71 @@
/*
* Copyright 2010-2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/
/*!
* \file Test_QuitSessionRequestJSON_Test.cpp
* \brief Test suite for QuitSessionRequestJSON class
*
* PROJ: OSLL/geo2tag
* ----------------------------------------------------------- */

#include "Test_QuitSessionRequestJSON.h"
#include <qjson/parser.h>
#include <qjson/serializer.h>


namespace Test
{
void Test_QuitSessionRequestJSON::getJson()
{
QuitSessionRequestJSON request;
QByteArray data;
QJson::Serializer serializer;
QVariantMap obj;

data = QString("{\"auth_token\":\"MMMMMMMMMM\"}").toAscii();
obj.insert("auth_token", QString("MMMMMMMMMM"));

QByteArray true_json = serializer.serialize(obj);

request.parseJson(data);
QCOMPARE(request.getJson(), true_json);
}

void Test_QuitSessionRequestJSON::parseJson()
{
QuitSessionRequestJSON request;
QByteArray data;

data = QString("{\"auth_token\":\"MMMMMMMMMM\"}").toAscii();
QCOMPARE(request.parseJson(data), true);
QCOMPARE(request.getSessionToken(), QString("MMMMMMMMMM"));
}

} // end of namespace Test
@@ -0,0 +1,57 @@
/*
* Copyright 2010-2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/
/*!
* \file QuitSessionRequestJSON_Test.h
* \brief Test suite for QuitSessionRequestJSON class
*
* PROJ: OSLL/geo2tag
* ----------------------------------------------------------- */

#ifndef TEST_QUITSESSIONREQUESTJSON_H
#define TEST_QUITSESSIONREQUESTJSON_H

#include <QObject>
#include <QtTest>
#include "../inc/QuitSessionRequestJSON.h"

namespace Test
{
class Test_QuitSessionRequestJSON : public QObject
{
Q_OBJECT

private slots:
void getJson();
void parseJson();
};
}

#endif // TEST_QUITSESSIONREQUESTJSON_H
@@ -0,0 +1,70 @@
/*
* Copyright 2010-2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/
/*!
* \file Test_QuitSessionResponseJSON.cpp
* \brief Test suite for QuitSessionResponseJSON class
*
* PROJ: OSLL/geo2tag
* ----------------------------------------------------------- */

#include "Test_QuitSessionResponseJSON.h"
#include <qjson/parser.h>
#include <qjson/serializer.h>

namespace Test
{
void Test_QuitSessionResponseJSON::getJson()
{
QuitSessionResponseJSON response;
QByteArray data;
QJson::Serializer serializer;
QVariantMap obj;

data = QString("{\"errno\":\"0\"}").toAscii();
obj.insert("errno", 0);

QByteArray true_json = serializer.serialize(obj);

response.parseJson(data);
QCOMPARE(response.getJson(), true_json);
}

void Test_QuitSessionResponseJSON::parseJson()
{
QuitSessionResponseJSON response;
QByteArray data;

data = QString("{\"errno\":\"0\"}").toAscii();
QCOMPARE(response.parseJson(data), true);
QCOMPARE(response.getErrno(), 0);
}

} // end of namespace Test
@@ -0,0 +1,57 @@
/*
* Copyright 2010-2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/
/*!
* \file Test_QuitSessionResponseJSON.h
* \brief Test suite for QuitSessionResponseJSON class
*
* PROJ: OSLL/geo2tag
* ----------------------------------------------------------- */

#ifndef TEST_QUITSESSIONRESPONSEJSON_H
#define TEST_QUITSESSIONRESPONSEJSON_H

#include <QObject>
#include <QtTest>
#include "../inc/QuitSessionResponseJSON.h"

namespace Test
{
class Test_QuitSessionResponseJSON : public QObject
{
Q_OBJECT

private slots:
void getJson();
void parseJson();
};
}

#endif // TEST_QUITSESSIONRESPONSEJSON_H
@@ -1,7 +1,33 @@
/*
* Copyright <C> 2012 Edward Ryabikov <edward.ryabikov@gmail.com
* Copyright 2010-2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/

/*!
* \file RegisterUserRequestJSON_Test.cpp
* \brief Test suite for RegisterUserRequestJSON class
@@ -1,7 +1,33 @@
/*
* Copyright <C> 2012 Edward Ryabikov <edward.ryabikov@gmail.com
* Copyright 2010-2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/

/*!
* \file RegisterUserRequestJSON_Test.h
* \brief Test suite for RegisterUserRequestJSON class
@@ -1,7 +1,33 @@
/*
* Copyright <C> 2012 Edward Ryabikov <edward.ryabikov@gmail.com
* Copyright 2010-2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/

/*!
* \file RegisterUserResponseJSON_Test.cpp
* \brief Test suite for RegisterUserResponseJSON class
@@ -1,7 +1,33 @@
/*
* Copyright <C> 2012 Edward Ryabikov <edward.ryabikov@gmail.com
* Copyright 2010-2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/

/*!
* \file RegisterUserResponseJSON_Test.h
* \brief Test suite for RegisterUserResponseJSON class
@@ -1,5 +1,5 @@
/*
* Copyright 2011 Kirill Krinkin kirill.krinkin@gmail.com
* Copyright 2010-2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -11,7 +11,7 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AS IS'' AND ANY EXPRESS OR
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
@@ -28,7 +28,6 @@
*
* The advertising clause requiring mention in adverts must never be included.
*/

/*!
* \file main.cpp
* \brief Test suite for json
@@ -45,6 +44,8 @@
#include "Test_RegisterUserRequestJSON.h"
#include "Test_RegisterUserResponseJSON.h"
#include "Test_AvailableChannelsResponseJSON.h"
#include "Test_QuitSessionRequestJSON.h"
#include "Test_QuitSessionResponseJSON.h"

int main(int argc, char **argv)
{
@@ -55,9 +56,12 @@ int main(int argc, char **argv)
new Test::JsonUser_Test(),
new Test::Test_RegisterUserRequestJSON(),
new Test::Test_RegisterUserResponseJSON(),
// new Test::Test_AvailableChannelsResponseJSON()
new Test::Test_AvailableChannelsResponseJSON(),
new Test::Test_QuitSessionRequestJSON(),
new Test::Test_QuitSessionResponseJSON()
};

QTest::qExec(tests[4]);
for (unsigned int i = 0; i < sizeof(tests)/sizeof(QObject*); i++) {
QTest::qExec(tests[i]);
}
@@ -11,9 +11,13 @@ SOURCES += main.cpp \
../../json/src/RegisterUserRequestJSON.cpp \
../../json/src/RegisterUserResponseJSON.cpp \
../../json/src/AvailableChannelsResponseJSON.cpp \
../../json/src/QuitSessionRequestJSON.cpp \
../../json/src/QuitSessionResponseJSON.cpp \
Test_RegisterUserResponseJSON.cpp \
Test_RegisterUserRequestJSON.cpp \
Test_AvailableChannelsResponseJSON.cpp
Test_AvailableChannelsResponseJSON.cpp \
Test_QuitSessionRequestJSON.cpp \
Test_QuitSessionResponseJSON.cpp
HEADERS += JsonUser_Test.h \
../inc/JsonUser.h \
../../common/inc/User.h \
@@ -22,9 +26,13 @@ HEADERS += JsonUser_Test.h \
../../json/inc/RegisterUserRequestJSON.h \
../../json/inc/RegisterUserResponseJSON.h \
../../json/inc/AvailableChannelsResponseJSON.h \
../../json/inc/QuitSessionRequestJSON.h \
../../json/inc/QuitSessionResponseJSON.h \
Test_RegisterUserResponseJSON.h \
Test_RegisterUserRequestJSON.h \
Test_AvailableChannelsResponseJSON.h
Test_AvailableChannelsResponseJSON.h \
Test_QuitSessionResponseJSON.h \
Test_QuitSessionRequestJSON.h

CONFIG += qtestlib

@@ -55,6 +55,7 @@
#include "UpdateThread.h"
#include "QueryExecutor.h"
#include "FilterRequestJSON.h"
#include "Session.h"

namespace common
{
@@ -69,6 +70,7 @@ namespace common
QSharedPointer<Users> m_usersContainer;
QSharedPointer<TimeSlots> m_timeSlotsContainer;
QSharedPointer<DataChannels> m_dataChannelsMap;
QSharedPointer<Sessions> m_sessionsContainer;

UpdateThread * m_updateThread;

@@ -85,10 +87,13 @@ namespace common
DbObjectsCollection();

QSharedPointer<User> findUser(const QSharedPointer<User>&) const;
QSharedPointer<Session> findSession(const QSharedPointer<Session>&) const;
QSharedPointer<Session> findSessionForUser(const QSharedPointer<User>&) const;

QByteArray processRegisterUserQuery(const QByteArray&);
QByteArray processConfirmRegistrationQuery(const QString&);
QByteArray processLoginQuery(const QByteArray&);
QByteArray processQuitSessionQuery(const QByteArray&);
QByteArray processSubscribedChannelsQuery(const QByteArray&);
QByteArray processAvailableChannelsQuery(const QByteArray&);
QByteArray processWriteTagQuery(const QByteArray&);
@@ -41,6 +41,7 @@
#include "User.h"
#include "Channel.h"
#include "DataMarks.h"
#include "Session.h"

class QueryExecutor : public QObject
{
@@ -60,9 +61,11 @@ class QueryExecutor : public QObject
qlonglong nextChannelKey() const;
qlonglong nextTagKey() const;
qlonglong nextTimeSlotKey() const;
qlonglong nextSessionKey() const;

const QString generateNewToken(const QString& login,const QString& password) const;
const QString generateNewToken(const QString& email, const QString& login,const QString& password) const;
const QString generateNewToken(const QString& accessTime, const QString& email, const QString& login,const QString& password) const;

bool subscribeChannel(const QSharedPointer<common::User>& user,const QSharedPointer<Channel>& channel);
bool unsubscribeChannel(const QSharedPointer<common::User>& user,const QSharedPointer<Channel>& channel);
@@ -84,8 +87,11 @@ class QueryExecutor : public QObject
bool deleteChannelTimeSlot(const QSharedPointer<Channel>&);
bool deleteMarkTimeSlot(const QSharedPointer<DataMark>&);
bool isChannelSubscribed(QSharedPointer<Channel>&, QSharedPointer<common::User>&);
bool deleteUser(const QSharedPointer<common::User> &user);

bool deleteUser(const QSharedPointer<common::User> &user);
// Sessions
QSharedPointer<Session> insertNewSession(const QSharedPointer<Session>& session);
bool updateSession(const QSharedPointer<Session>& session);
bool deleteSession(const QSharedPointer<Session>& session);

signals:

@@ -0,0 +1,56 @@
/*
* Copyright 2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/
/*!
* \file SessionInternal.h
* \brief Header of SessionInternal
*
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */

#ifndef SESSIONINTERNAL_H
#define SESSIONINTERNAL_H

#include "Session.h"

class DbSession: public Session
{
qlonglong m_id;

public:
DbSession(qlonglong id, const QString& sessionToken, const QDateTime& lastAccessTime, const QSharedPointer<common::User>& user);

qlonglong getId() const;
void setId(qlonglong);

~DbSession();
};

#endif // SESSIONINTERNAL_H
@@ -44,6 +44,7 @@
#include "ChannelInternal.h"
#include "DataChannel.h"
#include "TimeSlotInternal.h"
#include "SessionInternal.h"

class UpdateThread: public QThread
{
@@ -54,6 +55,7 @@ class UpdateThread: public QThread
QSharedPointer<common::Users> m_usersContainer;
QSharedPointer<TimeSlots> m_timeSlotsContainer;
QSharedPointer<DataChannels> m_dataChannelsMap;
QSharedPointer<Sessions> m_sessionsContainer;

QSqlDatabase m_database;

@@ -68,9 +70,11 @@ class UpdateThread: public QThread
void loadTags(DataMarks &);
void loadChannels(Channels &);
void loadTimeSlots(TimeSlots &);
void updateReflections(DataMarks&, common::Users&, Channels&, TimeSlots&);
void loadSessions(Sessions &);
void updateReflections(DataMarks&, common::Users&, Channels&, TimeSlots&, Sessions&);

void checkTmpUsers();
void checkSessions();

void sendConfirmationLetter(const QString &, const QString &);

@@ -86,6 +90,7 @@ class UpdateThread: public QThread
const QSharedPointer<Channels>& channels,
const QSharedPointer<TimeSlots>& timeSlots,
const QSharedPointer<DataChannels>& dataChannelsMap,
const QSharedPointer<Sessions>& sessions,
QObject *parent = 0);

void incrementTransactionCount(int i = 1);
@@ -53,7 +53,8 @@ HEADERS += \
inc/DbSession.h \
inc/UpdateThread.h \
inc/QueryExecutor.h \
inc/TimeSlotInternal.h
inc/TimeSlotInternal.h \
inc/SessionInternal.h


SOURCES += src/main.cpp \
@@ -65,7 +66,8 @@ SOURCES += src/main.cpp \
src/DbSession.cpp \
src/UpdateThread.cpp \
src/QueryExecutor.cpp \
src/TimeSlotInternal.cpp
src/TimeSlotInternal.cpp \
src/SessionInternal.cpp

LIBS += -lcommon -lfcgi -lwikigpsJson -lpq
OBJECTS_DIR = .obj

Large diffs are not rendered by default.

@@ -46,6 +46,7 @@
#include "UserInternal.h"
#include "ChannelInternal.h"
#include "TimeSlotInternal.h"
#include "SessionInternal.h"
#include "PerformanceCounter.h"


@@ -101,6 +102,10 @@ qlonglong QueryExecutor::nextTimeSlotKey() const
return nextKey("timeSlots_seq");
}

qlonglong QueryExecutor::nextSessionKey() const
{
return nextKey("sessions_seq");
}

const QString QueryExecutor::generateNewToken(const QString& login,const QString& password) const
{
@@ -122,6 +127,16 @@ const QString QueryExecutor::generateNewToken(const QString& email, const QStrin
return result;
}

const QString QueryExecutor::generateNewToken(const QString& accessTime, const QString& email, const QString& login,const QString& password) const
{
QString log=login+password+email+accessTime;
QByteArray toHash(log.toUtf8());
toHash=QCryptographicHash::hash(log.toUtf8(),QCryptographicHash::Md5);
QString result(toHash.toHex());
syslog(LOG_INFO,"TOken = %s",result.toStdString().c_str());
return result;
}


QSharedPointer<DataMark> QueryExecutor::insertNewTag(const QSharedPointer<DataMark>& tag)
{
@@ -682,3 +697,80 @@ bool QueryExecutor::deleteUser(const QSharedPointer<common::User> &user)
}
return result;
}

QSharedPointer<Session> QueryExecutor::insertNewSession(const QSharedPointer<Session>& session)
{
QSqlQuery query(m_database);
qlonglong newId = nextSessionKey();
QString newSessionToken = generateNewToken(session->getLastAccessTime().toUTC().toString(),
session->getUser()->getEmail(),
session->getUser()->getLogin(),
session->getUser()->getPassword());

syslog(LOG_INFO, "NewId ready, now preparing sql query for adding new session");
query.prepare("insert into sessions (id, user_id, session_token, last_access_time) values (:id, :user_id, :token, :time);");
query.bindValue(":id", newId);
query.bindValue(":user_id", session->getUser()->getId());
query.bindValue(":token", newSessionToken);
query.bindValue(":time", session->getLastAccessTime().toUTC());

m_database.transaction();

bool result = query.exec();
if (!result) {
syslog(LOG_INFO,"Rollback for NewSession sql query");
m_database.rollback();
return QSharedPointer<Session>(NULL);
} else {
syslog(LOG_INFO,"Commit for NewSession sql query - insert in table sessions");
m_database.commit();
}
return QSharedPointer<Session>(new DbSession(newId, newSessionToken, session->getLastAccessTime(), session->getUser()));
}

bool QueryExecutor::updateSession(const QSharedPointer<Session>& session)
{
QSqlQuery query(m_database);
QDateTime currentTime = QDateTime::currentDateTime().toUTC();
syslog(LOG_INFO, "Updating session with token: %s", session->getSessionToken().toStdString().c_str());

query.prepare("update sessions set last_access_time = :time where session_token = :token;");
query.bindValue(":time", currentTime);
query.bindValue(":token", session->getSessionToken());

m_database.transaction();

bool result = query.exec();
if (!result) {
syslog(LOG_INFO,"Rollback for updateSession sql query");
m_database.rollback();
return false;
} else {
syslog(LOG_INFO,"Commit for updateSession sql query");
m_database.commit();
session->setLastAccessTime(currentTime);
return true;
}
}

bool QueryExecutor::deleteSession(const QSharedPointer<Session> &session)
{
QSqlQuery query(m_database);
syslog(LOG_INFO, "Deleting session with token: %s", session->getSessionToken().toStdString().c_str());

query.prepare("delete from sessions where id = :id;");
query.bindValue(":id", session->getId());

m_database.transaction();

bool result = query.exec();
if (!result) {
syslog(LOG_INFO, "Rollback for deleteSession sql query");
m_database.rollback();
return false;
} else {
syslog(LOG_INFO, "Commit for deleteSession sql query");
m_database.commit();
return true;
}
}
@@ -0,0 +1,64 @@
/*
* Copyright 2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/
/*! ---------------------------------------------------------------
* \file SessionInternal.cpp
* \brief SessionInternal implementation
*
* PROJ: OSLL/geoblog
* ---------------------------------------------------------------- */

#include "SessionInternal.h"

DbSession::DbSession(qlonglong id,
const QString &sessionToken,
const QDateTime &lastAccessTime,
const QSharedPointer<common::User> &user)
: Session(sessionToken, lastAccessTime, user),
m_id(id)
{
}


qlonglong DbSession::getId() const
{
return m_id;
}


void DbSession::setId(qlonglong id)
{
m_id = id;
}


DbSession::~DbSession()
{
}
@@ -41,20 +41,22 @@
#include "PerformanceCounter.h"

UpdateThread::UpdateThread(const QSqlDatabase &db,
const QSharedPointer<DataMarks> &tags,
const QSharedPointer<common::Users> &users,
const QSharedPointer<Channels> &channels,
const QSharedPointer<TimeSlots> &timeSlots,
const QSharedPointer<DataChannels>& dataChannelsMap,
QObject *parent):
QThread(parent),
m_channelsContainer(channels),
m_tagsContainer(tags),
m_usersContainer(users),
m_timeSlotsContainer(timeSlots),
m_dataChannelsMap(dataChannelsMap),
m_database(db),
m_transactionCount(0)
const QSharedPointer<DataMarks> &tags,
const QSharedPointer<common::Users> &users,
const QSharedPointer<Channels> &channels,
const QSharedPointer<TimeSlots> &timeSlots,
const QSharedPointer<DataChannels>& dataChannelsMap,
const QSharedPointer<Sessions>& sessions,
QObject *parent)
: QThread(parent),
m_channelsContainer(channels),
m_tagsContainer(tags),
m_usersContainer(users),
m_timeSlotsContainer(timeSlots),
m_dataChannelsMap(dataChannelsMap),
m_sessionsContainer(sessions),
m_database(db),
m_transactionCount(0)
{
}

@@ -117,6 +119,7 @@ void UpdateThread::run()
// Check if DB contain new changes

checkTmpUsers();
checkSessions();
if (!compareTransactionNumber())
{
QThread::msleep(10000);
@@ -128,20 +131,23 @@ void UpdateThread::run()
DataMarks tagsContainer(*m_tagsContainer);
Channels channelsContainer(*m_channelsContainer);
TimeSlots timeSlotsContainer(*m_timeSlotsContainer);
Sessions sessionsContainer(*m_sessionsContainer);

loadUsers(usersContainer);
loadTags(tagsContainer);
loadChannels(channelsContainer);
loadTimeSlots(timeSlotsContainer);
loadSessions(sessionsContainer);

lockWriting();
syslog(LOG_INFO,"Containers locked for db_update");
m_usersContainer->merge(usersContainer);
m_tagsContainer->merge(tagsContainer);
m_channelsContainer->merge(channelsContainer);
m_timeSlotsContainer->merge(timeSlotsContainer);
m_sessionsContainer->merge(sessionsContainer);

updateReflections(*m_tagsContainer,*m_usersContainer, *m_channelsContainer, *m_timeSlotsContainer);
updateReflections(*m_tagsContainer,*m_usersContainer, *m_channelsContainer, *m_timeSlotsContainer, *m_sessionsContainer);

syslog(LOG_INFO, "tags added. trying to unlock");
unlockWriting();
@@ -161,9 +167,11 @@ void UpdateThread::run()
}
}


syslog(LOG_INFO, "current users' size = %d",m_usersContainer->size());
syslog(LOG_INFO, "current tags' size = %d",m_tagsContainer->size());
syslog(LOG_INFO, "current channels' size = %d", m_channelsContainer->size());
syslog(LOG_INFO, "current sessions' size = %d", m_sessionsContainer->size());
m_database.close();
}
QThread::msleep(10000);
@@ -277,8 +285,27 @@ void UpdateThread::loadTags(DataMarks &container)
}
}

void UpdateThread::loadSessions(Sessions &container)
{
syslog(LOG_INFO, "Sessions size = %d", m_usersContainer->size());
QSqlQuery query(m_database);
query.exec("select id, user_id, session_token, last_access_time from sessions;");
while (query.next()) {
qlonglong id = query.record().value("id").toLongLong();
if (container.exist(id))
continue;
qlonglong userId = query.record().value("user_id").toLongLong();
QSharedPointer<common::User> user(new DbUser("", "", userId, ""));

QString sessionToken = query.record().value("session_token").toString();
QDateTime lastAccessTime = query.record().value("last_access_time").toDateTime();//.toTimeSpec(Qt::LocalTime);

QSharedPointer<Session> newSession(new DbSession(id, sessionToken, lastAccessTime, user));
container.push_back(newSession);
}
}

void UpdateThread::updateReflections(DataMarks &tags, common::Users &users, Channels &channels, TimeSlots & timeSlots)
void UpdateThread::updateReflections(DataMarks &tags, common::Users &users, Channels &channels, TimeSlots & timeSlots, Sessions &sessions)
{
{
QSqlQuery query(m_database);
@@ -356,6 +383,10 @@ void UpdateThread::updateReflections(DataMarks &tags, common::Users &users, Chan
}
}

for(int i=0; i<sessions.size(); i++)
{
sessions[i]->setUser(users.item(sessions[i]->getUser()->getId()));
}
}

void UpdateThread::checkTmpUsers()
@@ -380,7 +411,9 @@ void UpdateThread::checkTmpUsers()
syslog(LOG_INFO,"Commit for CheckTmpUser sql query");
m_database.commit();
}
lockWriting();
incrementTransactionCount();
unlockWriting();
}

// Deleting old signups
@@ -407,7 +440,41 @@ void UpdateThread::checkTmpUsers()
syslog(LOG_INFO,"Commit for DeleteTmpUser sql query");
m_database.commit();
}
lockWriting();
incrementTransactionCount();
unlockWriting();
}
}

void UpdateThread::checkSessions()
{
syslog(LOG_INFO,"checkSessions query is running now...");
SettingsStorage storage(SETTINGS_STORAGE_FILENAME);
int timelife = storage.getValue("General_Settings/session_timelife", QVariant(DEFAULT_SESSION_TIMELIFE)).toInt();
for (int i = 0; i < m_sessionsContainer->size(); i++) {
QDateTime currentTime = QDateTime::currentDateTime().toUTC();
//syslog(LOG_INFO, "Current time: %s", currentTime.toString().toStdString().c_str());
QDateTime lastAccessTime = m_sessionsContainer->at(i)->getLastAccessTime();
//syslog(LOG_INFO, "Last access time: %s", lastAccessTime.toString().toStdString().c_str());
if (lastAccessTime.addDays(timelife) <= currentTime) {
QSqlQuery query(m_database);
query.prepare("delete from sessions where id = :id;");
query.bindValue(":id", m_sessionsContainer->at(i)->getId());
syslog(LOG_INFO,"Deleting: %s", query.lastQuery().toStdString().c_str());
m_database.transaction();
bool result = query.exec();
if (!result) {
syslog(LOG_INFO, "Rollback for DeleteSession sql query");
m_database.rollback();
} else {
syslog(LOG_INFO, "Commit for DeleteSession sql query");
m_database.commit();
}
lockWriting();
incrementTransactionCount();
m_sessionsContainer->erase(m_sessionsContainer->at(i));
unlockWriting();
}
}
}