added a dummy (yet) SyncController for testing sync info from iOS

This commit is contained in:
Luis Ángel San Martín 2015-03-26 22:10:51 +01:00
parent a4230699b1
commit e00d76b81a
4 changed files with 128 additions and 76 deletions

View File

@ -0,0 +1,25 @@
#include "synccontroller.h"
#include "QsLog.h"
#include <QUrl>
SyncController::SyncController()
{
}
void SyncController::service(HttpRequest &request, HttpResponse &response)
{
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
QStringList pathElements = path.split('/');
qulonglong libraryId = pathElements.at(2).toULongLong();
QString postData = QString::fromUtf8(request.getBody());
QLOG_INFO() << "POST DATA: " << postData;
//TODO Process postData and update the comics
response.write("OK",true);
}

View File

@ -0,0 +1,21 @@
#ifndef SYNCCONTROLLER_H
#define SYNCCONTROLLER_H
#include <QObject>
#include "httprequest.h"
#include "httpresponse.h"
#include "httprequesthandler.h"
class SyncController : public HttpRequestHandler {
Q_OBJECT
Q_DISABLE_COPY(SyncController);
public:
/** Constructor */
SyncController();
/** Generates the response */
void service(HttpRequest& request, HttpResponse& response);
};
#endif // SYNCCONTROLLER_H

View File

@ -21,6 +21,7 @@
#include "controllers/updatecomiccontroller.h"
#include "controllers/errorcontroller.h"
#include "controllers/comicdownloadinfocontroller.h"
#include "controllers/synccontroller.h"
#include "db_helper.h"
#include "yacreader_libraries.h"
@ -91,81 +92,84 @@ void RequestMapper::loadSession(HttpRequest & request, HttpResponse& response)
}
void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
QByteArray path=request.getPath();
qDebug("RequestMapper: path=%s",path.data());
QByteArray path=request.getPath();
qDebug("RequestMapper: path=%s",path.data());
QRegExp folder("/library/.+/folder/[0-9]+/?");//get comic content
QRegExp folderInfo("/library/.+/folder/[0-9]+/info/?"); //get folder info
QRegExp folder("/library/.+/folder/[0-9]+/?");//get comic content
QRegExp folderInfo("/library/.+/folder/[0-9]+/info/?"); //get folder info
QRegExp comicDownloadInfo("/library/.+/comic/[0-9]+/?"); //get comic info (basic/download info)
QRegExp comicFullInfo("/library/.+/comic/[0-9]+/info/?"); //get comic info (full info)
QRegExp comicOpen("/library/.+/comic/[0-9]+/remote/?"); //the server will open for reading the comic
QRegExp comicUpdate("/library/.+/comic/[0-9]+/update/?"); //get comic info
QRegExp comicClose("/library/.+/comic/[0-9]+/close/?"); //the server will close the comic and free memory
QRegExp cover("/library/.+/cover/[0-9a-f]+.jpg"); //get comic cover (navigation)
QRegExp comicPage("/library/.+/comic/[0-9]+/page/[0-9]+/?"); //get comic page
QRegExp comicClose("/library/.+/comic/[0-9]+/close/?"); //the server will close the comic and free memory
QRegExp cover("/library/.+/cover/[0-9a-f]+.jpg"); //get comic cover (navigation)
QRegExp comicPage("/library/.+/comic/[0-9]+/page/[0-9]+/?"); //get comic page
QRegExp comicPageRemote("/library/.+/comic/[0-9]+/page/[0-9]+/remote?"); //get comic page (remote reading)
QRegExp sync("/library/.+/sync");
QRegExp library("/library/([0-9]+)/.+"); //permite verificar que la biblioteca solicitada existe
path = QUrl::fromPercentEncoding(path).toUtf8();
loadSession(request, response);
//primera petición, se ha hecho un post, se sirven las bibliotecas si la seguridad mediante login no está habilitada
//primera petición, se ha hecho un post, se sirven las bibliotecas si la seguridad mediante login no está habilitada
if(path == "/") //Don't send data to the server using '/' !!!!
{
LibrariesController().service(request, response);
}
else
{
//se comprueba que la sesión sea la correcta con el fin de evitar accesos no autorizados
HttpSession session=Static::sessionStore->getSession(request,response,false);
if(!session.isNull() && session.contains("ySession"))
LibrariesController().service(request, response);
}
else
{
if(sync.exactMatch(path))
SyncController().service(request, response);
{
if(library.indexIn(path)!=-1 && DBHelper::getLibraries().contains(library.cap(1).toInt()) )
{
//listar el contenido del folder
if(folder.exactMatch(path))
{
FolderController().service(request, response);
}
else if (folderInfo.exactMatch(path))
{
FolderInfoController().service(request, response);
}
else if(cover.exactMatch(path))
{
CoverController().service(request, response);
}
else if(comicDownloadInfo.exactMatch(path))
//se comprueba que la sesión sea la correcta con el fin de evitar accesos no autorizados
HttpSession session=Static::sessionStore->getSession(request,response,false);
if(!session.isNull() && session.contains("ySession"))
{
if(library.indexIn(path)!=-1 && DBHelper::getLibraries().contains(library.cap(1).toInt()) )
{
ComicDownloadInfoController().service(request, response);
//listar el contenido del folder
if(folder.exactMatch(path))
{
FolderController().service(request, response);
}
else if (folderInfo.exactMatch(path))
{
FolderInfoController().service(request, response);
}
else if(cover.exactMatch(path))
{
CoverController().service(request, response);
}
else if(comicDownloadInfo.exactMatch(path))
{
ComicDownloadInfoController().service(request, response);
}
else if(comicFullInfo.exactMatch(path) || comicOpen.exactMatch(path))//start download or start remote reading
{
ComicController().service(request, response);
}
else if(comicPage.exactMatch(path) || comicPageRemote.exactMatch(path))
{
PageController().service(request,response);
}
else if(comicUpdate.exactMatch(path))
{
UpdateComicController().service(request, response);
}
}
else if(comicFullInfo.exactMatch(path) || comicOpen.exactMatch(path))//start download or start remote reading
{
ComicController().service(request, response);
}
else if(comicPage.exactMatch(path) || comicPageRemote.exactMatch(path))
{
PageController().service(request,response);
}
else if(comicUpdate.exactMatch(path))
else
{
UpdateComicController().service(request, response);
//response.writeText(library.cap(1));
Static::staticFileController->service(request, response);
}
}
else
{
//response.writeText(library.cap(1));
Static::staticFileController->service(request, response);
}
}
else //acceso no autorizado, redirección
{
ErrorController(300).service(request,response);
}
}
else //acceso no autorizado, redirección
{
ErrorController(300).service(request,response);
}
}
}
}

View File

@ -5,31 +5,33 @@ HEADERS += \
$$PWD/static.h \
$$PWD/startup.h \
$$PWD/requestmapper.h \
$$PWD/controllers/comiccontroller.h \
$$PWD/controllers/errorcontroller.h \
$$PWD/controllers/foldercontroller.h \
$$PWD/controllers/folderinfocontroller.h \
$$PWD/controllers/librariescontroller.h \
$$PWD/controllers/pagecontroller.h \
$$PWD/controllers/sessionmanager.h \
$$PWD/controllers/covercontroller.h \
server/controllers/updatecomiccontroller.h \
server/controllers/comicdownloadinfocontroller.h
$$PWD/controllers/comiccontroller.h \
$$PWD/controllers/errorcontroller.h \
$$PWD/controllers/foldercontroller.h \
$$PWD/controllers/folderinfocontroller.h \
$$PWD/controllers/librariescontroller.h \
$$PWD/controllers/pagecontroller.h \
$$PWD/controllers/sessionmanager.h \
$$PWD/controllers/covercontroller.h \
$$PWD/controllers/updatecomiccontroller.h \
$$PWD/controllers/comicdownloadinfocontroller.h \
$$PWD/controllers/synccontroller.h
SOURCES += \
$$PWD/static.cpp \
$$PWD/startup.cpp \
$$PWD/requestmapper.cpp \
$$PWD/controllers/comiccontroller.cpp \
$$PWD/controllers/errorcontroller.cpp \
$$PWD/controllers/foldercontroller.cpp \
$$PWD/controllers/folderinfocontroller.cpp \
$$PWD/controllers/librariescontroller.cpp \
$$PWD/controllers/pagecontroller.cpp \
$$PWD/controllers/sessionmanager.cpp \
$$PWD/controllers/covercontroller.cpp \
server/controllers/updatecomiccontroller.cpp \
server/controllers/comicdownloadinfocontroller.cpp
$$PWD/controllers/comiccontroller.cpp \
$$PWD/controllers/errorcontroller.cpp \
$$PWD/controllers/foldercontroller.cpp \
$$PWD/controllers/folderinfocontroller.cpp \
$$PWD/controllers/librariescontroller.cpp \
$$PWD/controllers/pagecontroller.cpp \
$$PWD/controllers/sessionmanager.cpp \
$$PWD/controllers/covercontroller.cpp \
$$PWD/controllers/updatecomiccontroller.cpp \
$$PWD/controllers/comicdownloadinfocontroller.cpp \
$$PWD/controllers/synccontroller.cpp
include(lib/bfLogging/bfLogging.pri)
include(lib/bfHttpServer/bfHttpServer.pri)