6 #include <QNetworkRequest>
34 VFS::WARN(
"The provided url is invalid: \""+url+
"\". Requests will fail.");
40 this, SLOT(
sslErrors(QNetworkReply*,QList<QSslError>)) );
82 QJsonObject o = r->
_data.object();
86 QString user = o[
"username"].toString();
87 QString pass = o[
"password"].toString();
90 params.addQueryItem(
"username",user);
91 params.addQueryItem(
"password",pass);
96 QNetworkRequest request(
_url);
97 request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
99 QNetworkReply *p =
_manager.post(request,params.query().toUtf8());
117 params.addQueryItem(
"mode",
"list");
120 params.addQueryItem(
"vfscurltoken",
_token);
125 QNetworkRequest request(
_url);
126 request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
128 QNetworkReply *p =
_manager.post(request,params.query().toUtf8());
149 r->
_reason = QString(
"Curlauth error: %1").arg(reply->errorString());
154 QByteArray response = reply->readAll();
157 QJsonParseError error;
158 QJsonDocument doc = QJsonDocument::fromJson(response,&error);
159 if (error.error == QJsonParseError::NoError)
164 QJsonObject o = doc.object();
165 QJsonObject d = r->
_data.object();
167 if (o[
"valid"].toBool() && o.contains(
"username"))
170 d[
"uidnumber"] = o[
"uidnumber"].toInt( 0 );
171 d[
"realname"] = o.contains(
"realname") ? o[
"realname"] : o[
"username"];
173 d[
"groups"] = o.contains(
"groups") ? o[
"groups"].toArray() : QJsonArray();
177 r->
_data.setObject(d);
180 r->
_user = o[
"username"].toString();
185 if (o.contains(
"error"))
186 r->
_reason =
"Curlauth error: "+o[
"error"].toString();
188 r->
_reason =
"Unspecified curlauth error";
191 r->
_user = d[
"username"].toString();
197 QJsonObject o = doc.object();
199 if (o[
"valid"].toBool() && o.contains(
"users"))
201 QJsonObject u = r->
_data.object();
205 r->
_data.setObject(u);
211 if (o.contains(
"error"))
212 r->
_reason = o[
"error"].toString();
214 r->
_reason =
"Unspecified curlauth error";
231 r->
_reason = QString(
"JSON parse error in respone to curl request at '%1': %2\n%3").arg(
_url.toString()).arg(error.errorString()).arg(QString(response));
239 VFS::ERROR( QString(
"Unable to find a VFS_request for network reply on \"%1\". If there was a request, it will not be deleted and will leak memory.").arg(reply->url().toString()), 0,
className() );
242 reply->deleteLater();
253 for (
int i=0;i<errors.size();i++)
The base class for authenticating users.
QNetworkAccessManager _manager
The curl connection manager.
void sslErrors(QNetworkReply *reply, QList< QSslError > errors)
An ssl error has occurred...
QMap< QNetworkReply *, VFS_request * > _requests
A map of outstanding VFS_request objects to their QNetworkReply objects.
virtual void ls(VFS_request *r)
List the users available for this auth method.
virtual void read(VFS_request *r)
Perform an authentication request by read()ing from this node, which will curl the _url via http POST...
QUrl _url
The url to curl.
Q_INVOKABLE VFS_curlauth(QString url, QString token="")
void replyFinished(QNetworkReply *reply)
A network request has completed.
QString _token
A token sent when requesting a listing from a remote url.
virtual void issueResponse(VFS_request *t)
Once a request has been completed, issue a response.
QString className()
Return the class name of a node.
void finished(bool andDelete=false)
Emitted if a thread fails to create its node, or a node is rm()'d, or any other reason a node has com...
The base class for all requests between nodes.
static const char * requestTypeStrings[]
A printable string for each request type.
@ read
read full contents (4)
@ ls
list children of a node (1)
requestType _requestType
the action this request is performing or requesting
QString _initialPath
the target path when the request was made (relative to the responder)
QString _user
who initiated this request, mostly for logging
QString _reason
if something (probably bad) happened, this is the reason
bool _isCallback
whether or not to issue a response (IE, another request is chained to this request,...
bool _success
if the request was successfully completed
QJsonDocument _data
the request payload
static void ERROR(QString message, int level=0, QString user="server")
Send a message to the VFS::_errors VFS_stream.
static void WARN(QString message, int level=0, QString user="server")
Send a message to the VFS::_warnings VFS_stream.