mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-15 20:42:29 -04:00
added resource_api and rs-nogui-webui (requires libmicrohttpd, Html files are not included)
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8047 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
97831d0667
commit
ad1bc7f3b8
38 changed files with 5547 additions and 2 deletions
133
libresapi/src/api/IdentityHandler.cpp
Normal file
133
libresapi/src/api/IdentityHandler.cpp
Normal file
|
@ -0,0 +1,133 @@
|
|||
#include "IdentityHandler.h"
|
||||
|
||||
#include <retroshare/rsidentity.h>
|
||||
|
||||
#include "Operators.h"
|
||||
#include "ApiTypes.h"
|
||||
#include "GxsResponseTask.h"
|
||||
#ifndef WINDOWS_SYS
|
||||
#include "unistd.h"
|
||||
#endif
|
||||
|
||||
namespace resource_api
|
||||
{
|
||||
|
||||
class SendIdentitiesListTask: public GxsResponseTask
|
||||
{
|
||||
public:
|
||||
SendIdentitiesListTask(RsIdentity* idservice, std::list<RsGxsId> ids):
|
||||
GxsResponseTask(idservice, 0)
|
||||
{
|
||||
for(std::list<RsGxsId>::iterator vit = ids.begin(); vit != ids.end(); ++vit)
|
||||
{
|
||||
requestGxsId(*vit);
|
||||
mIds.push_back(*vit);// convert fro list to vector
|
||||
}
|
||||
}
|
||||
private:
|
||||
std::vector<RsGxsId> mIds;
|
||||
protected:
|
||||
virtual void gxsDoWork(Request &req, Response &resp)
|
||||
{
|
||||
resp.mDataStream.getStreamToMember();
|
||||
for(std::vector<RsGxsId>::iterator vit = mIds.begin(); vit != mIds.end(); ++vit)
|
||||
{
|
||||
streamGxsId(*vit, resp.mDataStream.getStreamToMember());
|
||||
}
|
||||
resp.setOk();
|
||||
done();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
IdentityHandler::IdentityHandler(RsIdentity *identity):
|
||||
mRsIdentity(identity)
|
||||
{
|
||||
addResourceHandler("*", this, &IdentityHandler::handleWildcard);
|
||||
addResourceHandler("own", this, &IdentityHandler::handleOwn);
|
||||
}
|
||||
|
||||
void IdentityHandler::handleWildcard(Request &req, Response &resp)
|
||||
{
|
||||
bool ok = true;
|
||||
|
||||
if(req.isPut())
|
||||
{
|
||||
RsIdentityParameters params;
|
||||
req.mStream << makeKeyValueReference("name", params.nickname);
|
||||
if(req.mStream.isOK())
|
||||
{
|
||||
uint32_t token;
|
||||
mRsIdentity->createIdentity(token, params);
|
||||
// not sure if should acknowledge the token
|
||||
// for now go the easier way
|
||||
}
|
||||
else
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
||||
uint32_t token;
|
||||
mRsIdentity->getTokenService()->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts);
|
||||
|
||||
time_t start = time(NULL);
|
||||
while((mRsIdentity->getTokenService()->requestStatus(token) != RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
||||
&&(mRsIdentity->getTokenService()->requestStatus(token) != RsTokenService::GXS_REQUEST_V2_STATUS_FAILED)
|
||||
&&((time(NULL) < (start+10)))
|
||||
)
|
||||
{
|
||||
#ifdef WINDOWS_SYS
|
||||
Sleep(500);
|
||||
#else
|
||||
usleep(500*1000) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
if(mRsIdentity->getTokenService()->requestStatus(token) == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
||||
{
|
||||
std::vector<RsGxsIdGroup> grps;
|
||||
ok &= mRsIdentity->getGroupData(token, grps);
|
||||
for(std::vector<RsGxsIdGroup>::iterator vit = grps.begin(); vit != grps.end(); vit++)
|
||||
{
|
||||
RsGxsIdGroup& grp = *vit;
|
||||
KeyValueReference<RsGxsGroupId> id("id", grp.mMeta.mGroupId);
|
||||
KeyValueReference<RsPgpId> pgp_id("pgp_id",grp.mPgpId );
|
||||
// not very happy about this, i think the flags should stay hidden in rsidentities
|
||||
bool own = (grp.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN);
|
||||
bool pgp_linked = (grp.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID);
|
||||
resp.mDataStream.getStreamToMember()
|
||||
<< id
|
||||
<< pgp_id
|
||||
<< makeKeyValueReference("name", grp.mMeta.mGroupName)
|
||||
<< makeKeyValueReference("own", own)
|
||||
<< makeKeyValueReference("pgp_linked", pgp_linked);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(ok)
|
||||
{
|
||||
resp.setOk();
|
||||
}
|
||||
else
|
||||
{
|
||||
resp.setFail();
|
||||
}
|
||||
}
|
||||
|
||||
ResponseTask* IdentityHandler::handleOwn(Request &req, Response &resp)
|
||||
{
|
||||
std::list<RsGxsId> ids;
|
||||
mRsIdentity->getOwnIds(ids);
|
||||
return new SendIdentitiesListTask(mRsIdentity, ids);
|
||||
}
|
||||
|
||||
} // namespace resource_api
|
Loading…
Add table
Add a link
Reference in a new issue