libresapi: added identity/create_identity

This commit is contained in:
electron128 2016-01-31 16:04:34 +01:00
parent 284e5a9ed0
commit 94b02943e6
2 changed files with 59 additions and 0 deletions

View File

@ -41,11 +41,64 @@ protected:
};
class CreateIdentityTask: public GxsResponseTask
{
public:
CreateIdentityTask(RsIdentity* idservice):
GxsResponseTask(idservice, idservice->getTokenService()), mState(BEGIN), mToken(0), mRsIdentity(idservice){}
private:
enum State {BEGIN, WAIT_ACKN, WAIT_ID};
State mState;
uint32_t mToken;
RsIdentity* mRsIdentity;
RsGxsId mId;
protected:
virtual void gxsDoWork(Request &req, Response &resp)
{
switch(mState)
{
case BEGIN:{
RsIdentityParameters params;
req.mStream << makeKeyValueReference("name", params.nickname) << makeKeyValueReference("pgp_linked", params.isPgpLinked);
if(params.nickname == "")
{
resp.setFail("name can't be empty");
done();
return;
}
mRsIdentity->createIdentity(mToken, params);
addWaitingToken(mToken);
mState = WAIT_ACKN;
break;
}
case WAIT_ACKN:{
RsGxsGroupId grpId;
if(!mRsIdentity->acknowledgeGrp(mToken, grpId))
{
resp.setFail("acknowledge of group id failed");
done();
return;
}
mId = RsGxsId(grpId);
requestGxsId(mId);
mState = WAIT_ID;
break;
}
case WAIT_ID:
streamGxsId(mId, resp.mDataStream);
resp.setOk();
done();
}
}
};
IdentityHandler::IdentityHandler(RsIdentity *identity):
mRsIdentity(identity)
{
addResourceHandler("*", this, &IdentityHandler::handleWildcard);
addResourceHandler("own", this, &IdentityHandler::handleOwn);
addResourceHandler("create_identity", this, &IdentityHandler::handleCreateIdentity);
}
void IdentityHandler::handleWildcard(Request &req, Response &resp)
@ -134,4 +187,9 @@ ResponseTask* IdentityHandler::handleOwn(Request &req, Response &resp)
return 0;
}
ResponseTask* IdentityHandler::handleCreateIdentity(Request &req, Response &resp)
{
return new CreateIdentityTask(mRsIdentity);
}
} // namespace resource_api

View File

@ -15,5 +15,6 @@ private:
RsIdentity* mRsIdentity;
void handleWildcard(Request& req, Response& resp);
ResponseTask *handleOwn(Request& req, Response& resp);
ResponseTask *handleCreateIdentity(Request& req, Response& resp);
};
} // namespace resource_api