mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 08:29:26 -05:00
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:
parent
48a9be0ccc
commit
cf1c49aa3a
@ -74,7 +74,15 @@ void ApiLocalConnectionHandler::handlePendingRequests()
|
||||
if(mLocalSocket->canReadLine())
|
||||
{
|
||||
readPath:
|
||||
reqPath = mLocalSocket->readLine().constData();
|
||||
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];
|
||||
|
||||
reqPath = rString.toStdString();
|
||||
mState = WAITING_DATA;
|
||||
|
||||
/* Because QLocalSocket is SOCK_STREAM some clients implementations
|
||||
@ -84,6 +92,8 @@ void ApiLocalConnectionHandler::handlePendingRequests()
|
||||
* 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());
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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++)
|
||||
{
|
||||
if((*sit) != '/')
|
||||
std::string::const_reverse_iterator sit;
|
||||
for( sit = reqPath.rbegin(); sit != reqPath.rend(); ++sit )
|
||||
{
|
||||
// add to front because we are traveling in reverse order
|
||||
str = *sit + str;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(str != "")
|
||||
if((*sit) != '/') str = *sit + str;
|
||||
else if(!str.empty())
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user