mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-14 08:59:50 -05:00
libresapi: added identity/create_identity
This commit is contained in:
parent
284e5a9ed0
commit
94b02943e6
@ -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):
|
IdentityHandler::IdentityHandler(RsIdentity *identity):
|
||||||
mRsIdentity(identity)
|
mRsIdentity(identity)
|
||||||
{
|
{
|
||||||
addResourceHandler("*", this, &IdentityHandler::handleWildcard);
|
addResourceHandler("*", this, &IdentityHandler::handleWildcard);
|
||||||
addResourceHandler("own", this, &IdentityHandler::handleOwn);
|
addResourceHandler("own", this, &IdentityHandler::handleOwn);
|
||||||
|
addResourceHandler("create_identity", this, &IdentityHandler::handleCreateIdentity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IdentityHandler::handleWildcard(Request &req, Response &resp)
|
void IdentityHandler::handleWildcard(Request &req, Response &resp)
|
||||||
@ -134,4 +187,9 @@ ResponseTask* IdentityHandler::handleOwn(Request &req, Response &resp)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResponseTask* IdentityHandler::handleCreateIdentity(Request &req, Response &resp)
|
||||||
|
{
|
||||||
|
return new CreateIdentityTask(mRsIdentity);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace resource_api
|
} // namespace resource_api
|
||||||
|
@ -15,5 +15,6 @@ private:
|
|||||||
RsIdentity* mRsIdentity;
|
RsIdentity* mRsIdentity;
|
||||||
void handleWildcard(Request& req, Response& resp);
|
void handleWildcard(Request& req, Response& resp);
|
||||||
ResponseTask *handleOwn(Request& req, Response& resp);
|
ResponseTask *handleOwn(Request& req, Response& resp);
|
||||||
|
ResponseTask *handleCreateIdentity(Request& req, Response& resp);
|
||||||
};
|
};
|
||||||
} // namespace resource_api
|
} // namespace resource_api
|
||||||
|
Loading…
Reference in New Issue
Block a user