1 /****************************************************************************
3 ** Copyright (C) Qxt Foundation. Some rights reserved.
5 ** This file is part of the QxtWeb module of the Qt eXTension library
7 ** This library is free software; you can redistribute it and/or modify it
8 ** under the terms of th Common Public License, version 1.0, as published by
11 ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
12 ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
13 ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
14 ** FITNESS FOR A PARTICULAR PURPOSE.
16 ** You should have received a copy of the CPL along with this file.
17 ** See the LICENSE file and the cpl1.0.txt file included with the source
18 ** distribution for more information. If you did not receive a copy of the
19 ** license, contact the Qxt Foundation.
21 ** <http://libqxt.org> <foundation@libqxt.org>
23 ****************************************************************************/
24 #include "qxtwebcontroller.h"
25 #include "qxtwebcore.h"
26 #include <QStringList>
28 #include <QCoreApplication>
30 static QTextStream nullstream;
32 QString QxtWebController::WebRoot()
35 return QCoreApplication::applicationDirPath()+"/../";
39 QxtWebController::QxtWebController(QString name):QObject(QCoreApplication::instance())
46 QTextStream & QxtWebController::echo()
50 qDebug("QxtWebController::echo() no stream open");
57 QString QxtWebController::self()
59 return "/"+objectName();
63 int QxtWebController::invoke(server_t & SERVER_i)
66 QList<QByteArray> args_d = SERVER["REQUEST_URI"].split('/');
68 ///--------------find action ------------------
69 QByteArray action="index";
73 if (action.trimmed().isEmpty())action="index";
75 else if (args_d.count()>1)
89 foreach(QByteArray arg,args_d)
90 args<<QUrl::fromPercentEncoding(arg);
93 QTextStream strm (&buffer);
99 if (!QMetaObject::invokeMethod(this, action,Q_RETURN_ARG(int, retVal) ,
100 Q_ARG(QString, args.at(0)),Q_ARG(QString, args.at(1)),Q_ARG(QString, args.at(2)),Q_ARG(QString, args.at(3))
101 ,Q_ARG(QString, args.at(4)),Q_ARG(QString, args.at(5)),Q_ARG(QString, args.at(6)),Q_ARG(QString, args.at(8))))
103 retVal=4042; ///FIXME: the return value of the invoke has a meaning, handle it!
106 else if (args.count()>7)
108 if (!QMetaObject::invokeMethod(this, (action),Q_RETURN_ARG(int, retVal) ,
109 Q_ARG(QString, args.at(0)),Q_ARG(QString, args.at(1)),Q_ARG(QString, args.at(2)),Q_ARG(QString, args.at(3))
110 ,Q_ARG(QString, args.at(4)),Q_ARG(QString, args.at(5)),Q_ARG(QString, args.at(6)),Q_ARG(QString, args.at(7))
117 else if (args.count()>6)
119 if ( !QMetaObject::invokeMethod(this, (action),Q_RETURN_ARG(int, retVal) ,
120 Q_ARG(QString, args.at(0)),Q_ARG(QString, args.at(1)),Q_ARG(QString, args.at(2)),Q_ARG(QString, args.at(3))
121 ,Q_ARG(QString, args.at(4)),Q_ARG(QString, args.at(5)),Q_ARG(QString, args.at(6))
127 else if (args.count()>5)
129 if (!QMetaObject::invokeMethod(this, (action),Q_RETURN_ARG(int, retVal) ,
130 Q_ARG(QString, args.at(0)),Q_ARG(QString, args.at(1)),Q_ARG(QString, args.at(2)),Q_ARG(QString, args.at(3))
131 ,Q_ARG(QString, args.at(4)),Q_ARG(QString, args.at(5))
137 else if ( args.count()>4)
139 if ( !QMetaObject::invokeMethod(this, (action),Q_RETURN_ARG(int, retVal) ,
140 Q_ARG(QString, args.at(0)),Q_ARG(QString, args.at(1)),Q_ARG(QString, args.at(2)),Q_ARG(QString, args.at(3))
141 ,Q_ARG(QString, args.at(4))
147 else if (args.count()>3)
149 if ( !QMetaObject::invokeMethod(this, (action),Q_RETURN_ARG(int, retVal) ,
150 Q_ARG(QString, args.at(0)),Q_ARG(QString, args.at(1)),Q_ARG(QString, args.at(2)),Q_ARG(QString, args.at(3))
156 else if (args.count()>2)
158 if ( !QMetaObject::invokeMethod(this, (action),Q_RETURN_ARG(int, retVal) ,
159 Q_ARG(QString, args.at(0)),Q_ARG(QString, args.at(1)),Q_ARG(QString, args.at(2))
163 else if (args.count()>1)
165 if ( !QMetaObject::invokeMethod(this, (action),Q_RETURN_ARG(int, retVal) ,
166 Q_ARG(QString, args.at(0)),Q_ARG(QString, args.at(1))
170 else if (args.count()>0)
172 if ( !QMetaObject::invokeMethod(this, (action),Q_RETURN_ARG(int, retVal) ,Q_ARG(QString, args.at(0))))
177 if ( !QMetaObject::invokeMethod(this, (action),Q_RETURN_ARG(int, retVal) ))
186 QxtWebCore::send(buffer);