Advances on trusted node addings

ApiServerLocal trim method/path line to avoid white spaces parsing
ApiServerLocal add support for passing METHOD in request
AddTrustedNode.qml add ability to copy and paste keys
This commit is contained in:
Gio 2016-09-22 12:48:08 +02:00
parent 48a9be0ccc
commit cf1c49aa3a
5 changed files with 76 additions and 54 deletions

View File

@ -74,15 +74,25 @@ void ApiLocalConnectionHandler::handlePendingRequests()
if(mLocalSocket->canReadLine())
{
readPath:
reqPath = mLocalSocket->readLine().constData();
mState = WAITING_DATA;
QString rString(mLocalSocket->readLine());
rString = rString.simplified();
if (!rString.isEmpty())
{
if(rString.startsWith("PUT", Qt::CaseInsensitive)) reqMeth = resource_api::Request::PUT;
else if (rString.startsWith("DELETE", Qt::CaseInsensitive)) reqMeth = resource_api::Request::DELETE_AA;
if(rString.contains(' ')) rString = rString.split(' ')[1];
/* Because QLocalSocket is SOCK_STREAM some clients implementations
* like the one based on QLocalSocket feel free to send the whole
* request (PATH + DATA) in a single write(), causing readyRead()
* signal being emitted only once, in that case we should continue
* processing without waiting for readyRead() being fired again, so
* we don't break here as there may be more lines to read */
reqPath = rString.toStdString();
mState = WAITING_DATA;
/* Because QLocalSocket is SOCK_STREAM some clients implementations
* like the one based on QLocalSocket feel free to send the whole
* request (PATH + DATA) in a single write(), causing readyRead()
* signal being emitted only once, in that case we should continue
* processing without waiting for readyRead() being fired again, so
* we don't break here as there may be more lines to read */
}
else break;
}
}
case WAITING_DATA:
@ -92,6 +102,7 @@ void ApiLocalConnectionHandler::handlePendingRequests()
resource_api::JsonStream reqJson;
reqJson.setJsonString(std::string(mLocalSocket->readLine().constData()));
resource_api::Request req(reqJson);
req.mMethod = reqMeth;
req.setPath(reqPath);
std::string resultString = mApiServer->handleRequest(req);
mLocalSocket->write(resultString.c_str(), resultString.length());

View File

@ -24,6 +24,7 @@
#include <retroshare/rsinit.h>
#include <string>
#include "ApiTypes.h"
#include "ApiServer.h"
namespace resource_api
@ -89,6 +90,7 @@ private:
QLocalSocket* mLocalSocket;
State mState;
std::string reqPath;
resource_api::Request::Method reqMeth;
};
} // namespace resource_api

View File

@ -211,30 +211,7 @@ public:
req.mMethod = resource_api::Request::DELETE_AA;
}
std::stack<std::string> stack;
std::string str;
for(std::string::reverse_iterator sit = path2.rbegin(); sit != path2.rend(); sit++)
{
if((*sit) != '/')
{
// add to front because we are traveling in reverse order
str = *sit + str;
}
else
{
if(str != "")
{
stack.push(str);
str.clear();
}
}
}
if(str != "")
{
stack.push(str);
}
req.mPath = stack;
req.mFullPath = path2;
req.setPath(path2);
std::string result = mApiServer->handleRequest(req);

View File

@ -193,29 +193,21 @@ public:
// then each handler should pop the top element
std::stack<std::string> mPath;
std::string mFullPath;
bool setPath(std::string reqPath)
bool setPath(const std::string &reqPath)
{
std::string str;
for(std::string::reverse_iterator sit = reqPath.rbegin(); sit != reqPath.rend(); sit++)
std::string::const_reverse_iterator sit;
for( sit = reqPath.rbegin(); sit != reqPath.rend(); ++sit )
{
if((*sit) != '/')
// add to front because we are traveling in reverse order
if((*sit) != '/') str = *sit + str;
else if(!str.empty())
{
// add to front because we are traveling in reverse order
str = *sit + str;
}
else
{
if(str != "")
{
mPath.push(str);
str.clear();
}
mPath.push(str);
str.clear();
}
}
if(str != "")
{
mPath.push(str);
}
if(!str.empty()) mPath.push(str);
mFullPath = reqPath;
return true;
@ -231,8 +223,7 @@ public:
// contains data for new resources
StreamBase& mStream;
// use the is*() methods to query the method type
//private:
// use the is*() methods to query the method type:
enum Method { GET, PUT, DELETE_AA, EXEC};// something is wrong with DELETE, it won't compile with it
Method mMethod;
};

View File

@ -27,13 +27,41 @@ Item
ColumnLayout
{
id: colLayout
anchors.top: parent.top
anchors.bottom: bottomButton.top
anchors.bottom: rowLayout.top
Text { id: myKeyField }
TextField { id: myKeyField }
TextField { id: otherKeyField }
}
RowLayout
{
id: rowLayout
anchors.top: colLayout.bottom
Button
{
text: "Copy"
onClicked:
{
myKeyField.selectAll()
myKeyField.copy()
}
}
Button
{
text: "Paste"
onClicked:
{
otherKeyField.selectAll()
otherKeyField.paste()
}
}
}
Button
{
id: bottomButton
@ -41,7 +69,20 @@ Item
anchors.bottom: parent.bottom
onClicked:
{
rsApi.request("/peers/examine_cert/", JSON.stringify({ cert_string: otherKeyField.text }))
console.log("retroshare addtrusted: ", otherKeyField.text)
var jsonData =
{
cert_string: otherKeyField.text,
flags:
{
allow_direct_download: true,
allow_push: false,
require_whitelist: false,
}
}
console.log("retroshare addtrusted jsonData: ", JSON.stringify(jsonData))
//rsApi.request("/peers/examine_cert/", JSON.stringify({ cert_string: otherKeyField.text }))
rsApi.request("POST /peers", JSON.stringify(jsonData))
}
}
}