2012-02-04 09:16:39 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/services p3wikiservice.cc
|
|
|
|
*
|
|
|
|
* Wiki interface for RetroShare.
|
|
|
|
*
|
|
|
|
* Copyright 2012-2012 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
#include "services/p3wikiserviceVEG.h"
|
2012-02-04 09:16:39 -05:00
|
|
|
|
|
|
|
#include "util/rsrandom.h"
|
|
|
|
|
|
|
|
/****
|
|
|
|
* #define WIKI_DEBUG 1
|
|
|
|
****/
|
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
RsWikiVEG *rsWikiVEG = NULL;
|
2012-02-04 09:16:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
/******************* Startup / Tick ******************************************/
|
|
|
|
/********************************************************************************/
|
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
p3WikiServiceVEG::p3WikiServiceVEG(uint16_t type)
|
|
|
|
:p3GxsDataServiceVEG(type, new WikiDataProxy()), mWikiMtx("p3WikiService"), mUpdated(true)
|
2012-02-04 09:16:39 -05:00
|
|
|
{
|
|
|
|
RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/
|
2012-06-13 20:27:28 -04:00
|
|
|
|
|
|
|
mWikiProxy = (WikiDataProxy *) mProxy;
|
2012-02-04 09:16:39 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
int p3WikiServiceVEG::tick()
|
2012-02-04 09:16:39 -05:00
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
//std::cerr << "p3WikiServiceVEG::tick()";
|
2012-09-09 10:40:21 -04:00
|
|
|
//std::cerr << std::endl;
|
2012-06-08 18:03:09 -04:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
fakeprocessrequests();
|
|
|
|
|
2012-02-04 09:16:39 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::updated()
|
2012-02-04 09:16:39 -05:00
|
|
|
{
|
|
|
|
RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
if (mUpdated)
|
|
|
|
{
|
|
|
|
mUpdated = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-08 18:03:09 -04:00
|
|
|
|
|
|
|
|
|
|
|
/* Data Requests */
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds)
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
2012-06-13 20:27:28 -04:00
|
|
|
generateToken(token);
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::requestGroupInfo() gets Token: " << token << std::endl;
|
2012-06-13 20:27:28 -04:00
|
|
|
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds);
|
2012-06-08 18:03:09 -04:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
return true;
|
2012-06-08 18:03:09 -04:00
|
|
|
}
|
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds)
|
2012-06-13 20:27:28 -04:00
|
|
|
{
|
|
|
|
generateToken(token);
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::requestMsgInfo() gets Token: " << token << std::endl;
|
2012-06-13 20:27:28 -04:00
|
|
|
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGS, groupIds);
|
2012-06-08 18:03:09 -04:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &msgIds)
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
2012-06-13 20:27:28 -04:00
|
|
|
generateToken(token);
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::requestMsgRelatedInfo() gets Token: " << token << std::endl;
|
2012-06-13 20:27:28 -04:00
|
|
|
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds);
|
2012-06-08 18:03:09 -04:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
return true;
|
2012-06-08 18:03:09 -04:00
|
|
|
}
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
/* Generic Lists */
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::getGroupList( const uint32_t &token, std::list<std::string> &groupIds)
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
2012-06-13 20:27:28 -04:00
|
|
|
uint32_t status;
|
|
|
|
uint32_t reqtype;
|
|
|
|
uint32_t anstype;
|
|
|
|
time_t ts;
|
|
|
|
checkRequestStatus(token, status, reqtype, anstype, ts);
|
2012-06-08 18:03:09 -04:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
if (anstype != RS_TOKREQ_ANSTYPE_LIST)
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::getGroupList() ERROR AnsType Wrong" << std::endl;
|
2012-06-13 20:27:28 -04:00
|
|
|
return false;
|
2012-06-08 18:03:09 -04:00
|
|
|
}
|
2012-06-13 20:27:28 -04:00
|
|
|
|
|
|
|
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::getGroupList() ERROR ReqType Wrong" << std::endl;
|
2012-06-13 20:27:28 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != GXS_REQUEST_STATUS_COMPLETE)
|
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::getGroupList() ERROR Status Incomplete" << std::endl;
|
2012-06-13 20:27:28 -04:00
|
|
|
return false;
|
2012-06-08 18:03:09 -04:00
|
|
|
}
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
bool ans = loadRequestOutList(token, groupIds);
|
|
|
|
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
2012-06-08 18:03:09 -04:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
return ans;
|
2012-06-08 18:03:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::getMsgList( const uint32_t &token, std::list<std::string> &msgIds)
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
2012-06-13 20:27:28 -04:00
|
|
|
uint32_t status;
|
|
|
|
uint32_t reqtype;
|
|
|
|
uint32_t anstype;
|
|
|
|
time_t ts;
|
|
|
|
checkRequestStatus(token, status, reqtype, anstype, ts);
|
|
|
|
|
|
|
|
if (anstype != RS_TOKREQ_ANSTYPE_LIST)
|
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::getMsgList() ERROR AnsType Wrong" << std::endl;
|
2012-06-13 20:27:28 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED))
|
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::getMsgList() ERROR ReqType Wrong" << std::endl;
|
2012-06-13 20:27:28 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != GXS_REQUEST_STATUS_COMPLETE)
|
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::getMsgList() ERROR Status Incomplete" << std::endl;
|
2012-06-13 20:27:28 -04:00
|
|
|
return false;
|
|
|
|
}
|
2012-06-08 18:03:09 -04:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
bool ans = loadRequestOutList(token, msgIds);
|
|
|
|
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
|
|
|
|
|
|
|
return ans;
|
2012-06-08 18:03:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
/* Generic Summary */
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::getGroupSummary( const uint32_t &token, std::list<RsGroupMetaData> &groupInfo)
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
|
|
|
uint32_t status;
|
|
|
|
uint32_t reqtype;
|
2012-06-13 20:27:28 -04:00
|
|
|
uint32_t anstype;
|
2012-06-08 18:03:09 -04:00
|
|
|
time_t ts;
|
2012-06-13 20:27:28 -04:00
|
|
|
checkRequestStatus(token, status, reqtype, anstype, ts);
|
|
|
|
|
|
|
|
if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY)
|
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::getGroupSummary() ERROR AnsType Wrong" << std::endl;
|
2012-06-13 20:27:28 -04:00
|
|
|
return false;
|
|
|
|
}
|
2012-06-08 18:03:09 -04:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::getGroupSummary() ERROR ReqType Wrong" << std::endl;
|
2012-06-08 18:03:09 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != GXS_REQUEST_STATUS_COMPLETE)
|
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::getGroupSummary() ERROR Status Incomplete" << std::endl;
|
2012-06-08 18:03:09 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
std::list<std::string> groupIds;
|
|
|
|
bool ans = loadRequestOutList(token, groupIds);
|
2012-06-08 18:03:09 -04:00
|
|
|
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
/* convert to RsGroupMetaData */
|
|
|
|
mProxy->getGroupSummary(groupIds, groupInfo);
|
|
|
|
|
2012-06-08 18:03:09 -04:00
|
|
|
return ans;
|
|
|
|
}
|
2012-06-13 20:27:28 -04:00
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::getMsgSummary( const uint32_t &token, std::list<RsMsgMetaData> &msgInfo)
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
|
|
|
uint32_t status;
|
|
|
|
uint32_t reqtype;
|
2012-06-13 20:27:28 -04:00
|
|
|
uint32_t anstype;
|
2012-06-08 18:03:09 -04:00
|
|
|
time_t ts;
|
2012-06-13 20:27:28 -04:00
|
|
|
checkRequestStatus(token, status, reqtype, anstype, ts);
|
2012-06-08 18:03:09 -04:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY)
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::getMsgSummary() ERROR AnsType Wrong" << std::endl;
|
2012-06-08 18:03:09 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED))
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::getMsgSummary() ERROR ReqType Wrong" << std::endl;
|
2012-06-08 18:03:09 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
if (status != GXS_REQUEST_STATUS_COMPLETE)
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::getMsgSummary() ERROR Status Incomplete" << std::endl;
|
2012-06-13 20:27:28 -04:00
|
|
|
return false;
|
2012-06-08 18:03:09 -04:00
|
|
|
}
|
2012-06-13 20:27:28 -04:00
|
|
|
|
|
|
|
std::list<std::string> msgIds;
|
|
|
|
bool ans = loadRequestOutList(token, msgIds);
|
2012-06-08 18:03:09 -04:00
|
|
|
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
2012-06-13 20:27:28 -04:00
|
|
|
|
|
|
|
/* convert to RsMsgMetaData */
|
|
|
|
mProxy->getMsgSummary(msgIds, msgInfo);
|
|
|
|
|
2012-06-08 18:03:09 -04:00
|
|
|
return ans;
|
|
|
|
}
|
2012-06-13 20:27:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
/* Specific Service Data */
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::getGroupData(const uint32_t &token, RsWikiGroup &group)
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
|
|
|
uint32_t status;
|
|
|
|
uint32_t reqtype;
|
2012-06-13 20:27:28 -04:00
|
|
|
uint32_t anstype;
|
2012-06-08 18:03:09 -04:00
|
|
|
time_t ts;
|
2012-06-13 20:27:28 -04:00
|
|
|
checkRequestStatus(token, status, reqtype, anstype, ts);
|
2012-06-08 18:03:09 -04:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
|
|
|
|
if (anstype != RS_TOKREQ_ANSTYPE_DATA)
|
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::getGroupData() ERROR AnsType Wrong" << std::endl;
|
2012-06-13 20:27:28 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::getGroupData() ERROR ReqType Wrong" << std::endl;
|
2012-06-08 18:03:09 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != GXS_REQUEST_STATUS_COMPLETE)
|
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::getGroupData() ERROR Status Incomplete" << std::endl;
|
2012-06-08 18:03:09 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string id;
|
2012-06-13 20:27:28 -04:00
|
|
|
if (!popRequestOutList(token, id))
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
|
|
|
/* finished */
|
|
|
|
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
/* convert to RsWikiAlbum */
|
|
|
|
bool ans = mWikiProxy->getGroup(id, group);
|
2012-06-08 18:03:09 -04:00
|
|
|
return ans;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::getMsgData(const uint32_t &token, RsWikiPage &page)
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
|
|
|
uint32_t status;
|
|
|
|
uint32_t reqtype;
|
2012-06-13 20:27:28 -04:00
|
|
|
uint32_t anstype;
|
2012-06-08 18:03:09 -04:00
|
|
|
time_t ts;
|
2012-06-13 20:27:28 -04:00
|
|
|
checkRequestStatus(token, status, reqtype, anstype, ts);
|
|
|
|
|
|
|
|
|
|
|
|
if (anstype != RS_TOKREQ_ANSTYPE_DATA)
|
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::getMsgData() ERROR AnsType Wrong" << std::endl;
|
2012-06-13 20:27:28 -04:00
|
|
|
return false;
|
|
|
|
}
|
2012-06-08 18:03:09 -04:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED))
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::getMsgData() ERROR ReqType Wrong" << std::endl;
|
2012-06-08 18:03:09 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != GXS_REQUEST_STATUS_COMPLETE)
|
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::getMsgData() ERROR Status Incomplete" << std::endl;
|
2012-06-08 18:03:09 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string id;
|
2012-06-13 20:27:28 -04:00
|
|
|
if (!popRequestOutList(token, id))
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
|
|
|
/* finished */
|
|
|
|
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
/* convert to RsWikiAlbum */
|
|
|
|
bool ans = mWikiProxy->getPage(id, page);
|
2012-06-08 18:03:09 -04:00
|
|
|
return ans;
|
|
|
|
}
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
|
|
|
|
|
2012-06-08 18:03:09 -04:00
|
|
|
/* Poll */
|
2012-09-14 20:16:06 -04:00
|
|
|
uint32_t p3WikiServiceVEG::requestStatus(const uint32_t token)
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
|
|
|
uint32_t status;
|
|
|
|
uint32_t reqtype;
|
2012-06-13 20:27:28 -04:00
|
|
|
uint32_t anstype;
|
2012-06-08 18:03:09 -04:00
|
|
|
time_t ts;
|
2012-06-13 20:27:28 -04:00
|
|
|
checkRequestStatus(token, status, reqtype, anstype, ts);
|
2012-06-08 18:03:09 -04:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
/* Cancel Request */
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::cancelRequest(const uint32_t &token)
|
2012-02-04 09:16:39 -05:00
|
|
|
{
|
2012-06-13 20:27:28 -04:00
|
|
|
return clearRequest(token);
|
|
|
|
}
|
2012-02-04 09:16:39 -05:00
|
|
|
|
2012-07-06 19:14:18 -04:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask)
|
2012-06-13 20:27:28 -04:00
|
|
|
{
|
2012-07-06 19:14:18 -04:00
|
|
|
return mWikiProxy->setMessageStatus(msgId, status, statusMask);
|
2012-02-04 09:16:39 -05:00
|
|
|
}
|
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask)
|
2012-02-04 09:16:39 -05:00
|
|
|
{
|
2012-07-06 19:14:18 -04:00
|
|
|
return mWikiProxy->setGroupStatus(groupId, status, statusMask);
|
2012-02-04 09:16:39 -05:00
|
|
|
}
|
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask)
|
2012-07-06 19:14:18 -04:00
|
|
|
{
|
|
|
|
return mWikiProxy->setGroupSubscribeFlags(groupId, subscribeFlags, subscribeMask);
|
|
|
|
}
|
2012-02-04 09:16:39 -05:00
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::setMessageServiceString(const std::string &msgId, const std::string &str)
|
2012-02-04 09:16:39 -05:00
|
|
|
{
|
2012-07-06 19:14:18 -04:00
|
|
|
return mWikiProxy->setMessageServiceString(msgId, str);
|
|
|
|
}
|
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::setGroupServiceString(const std::string &grpId, const std::string &str)
|
2012-07-06 19:14:18 -04:00
|
|
|
{
|
|
|
|
return mWikiProxy->setGroupServiceString(grpId, str);
|
2012-02-04 09:16:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::groupRestoreKeys(const std::string &groupId)
|
2012-02-04 09:16:39 -05:00
|
|
|
{
|
2012-06-13 20:27:28 -04:00
|
|
|
return false;
|
2012-02-04 09:16:39 -05:00
|
|
|
}
|
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::groupShareKeys(const std::string &groupId, std::list<std::string>& peers)
|
2012-02-04 09:16:39 -05:00
|
|
|
{
|
2012-06-13 20:27:28 -04:00
|
|
|
return false;
|
2012-02-04 09:16:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
/********************************************************************************************/
|
2012-02-04 09:16:39 -05:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
std::string p3WikiServiceVEG::genRandomId()
|
2012-06-13 20:27:28 -04:00
|
|
|
{
|
|
|
|
std::string randomId;
|
|
|
|
for(int i = 0; i < 20; i++)
|
2012-02-04 09:16:39 -05:00
|
|
|
{
|
2012-06-13 20:27:28 -04:00
|
|
|
randomId += (char) ('a' + (RSRandom::random_u32() % 26));
|
2012-02-04 09:16:39 -05:00
|
|
|
}
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
return randomId;
|
2012-02-04 09:16:39 -05:00
|
|
|
}
|
2012-06-13 20:27:28 -04:00
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::createGroup(uint32_t &token, RsWikiGroup &group, bool isNew)
|
2012-02-04 09:16:39 -05:00
|
|
|
{
|
2012-06-13 20:27:28 -04:00
|
|
|
if (group.mMeta.mGroupId.empty())
|
2012-02-04 09:16:39 -05:00
|
|
|
{
|
|
|
|
/* new photo */
|
|
|
|
|
|
|
|
/* generate a temp id */
|
2012-06-13 20:27:28 -04:00
|
|
|
group.mMeta.mGroupId = genRandomId();
|
2012-02-04 09:16:39 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::createGroup() Group with existing Id... dropping";
|
2012-02-04 09:16:39 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-06 19:14:18 -04:00
|
|
|
{
|
|
|
|
RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/
|
2012-02-04 09:16:39 -05:00
|
|
|
|
2012-07-06 19:14:18 -04:00
|
|
|
mUpdated = true;
|
|
|
|
mWikiProxy->addGroup(group);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fake a request to return the GroupMetaData.
|
|
|
|
generateToken(token);
|
|
|
|
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
|
2012-09-14 20:16:06 -04:00
|
|
|
RsTokReqOptionsVEG opts; // NULL is good.
|
2012-07-06 19:14:18 -04:00
|
|
|
std::list<std::string> groupIds;
|
|
|
|
groupIds.push_back(group.mMeta.mGroupId); // It will just return this one.
|
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::createGroup() Generating Request Token: " << token << std::endl;
|
2012-07-06 19:14:18 -04:00
|
|
|
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds);
|
2012-02-04 09:16:39 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
bool p3WikiServiceVEG::createPage(uint32_t &token, RsWikiPage &page, bool isNew)
|
2012-02-04 09:16:39 -05:00
|
|
|
{
|
2012-06-13 20:27:28 -04:00
|
|
|
if (page.mMeta.mGroupId.empty())
|
2012-02-04 09:16:39 -05:00
|
|
|
{
|
|
|
|
/* new photo */
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::createPage() Missing PageID";
|
2012-02-04 09:16:39 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if its a mod or new page */
|
2012-06-13 20:27:28 -04:00
|
|
|
if (page.mMeta.mOrigMsgId.empty())
|
2012-02-04 09:16:39 -05:00
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::createPage() New Page";
|
2012-02-04 09:16:39 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
/* new page, generate a new OrigPageId */
|
2012-06-13 20:27:28 -04:00
|
|
|
page.mMeta.mOrigMsgId = genRandomId();
|
|
|
|
page.mMeta.mMsgId = page.mMeta.mOrigMsgId;
|
2012-02-04 09:16:39 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::createPage() Modified Page";
|
2012-02-04 09:16:39 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
/* mod page, keep orig page id, generate a new PageId */
|
2012-06-13 20:27:28 -04:00
|
|
|
page.mMeta.mMsgId = genRandomId();
|
2012-02-04 09:16:39 -05:00
|
|
|
}
|
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::createPage() GroupId: " << page.mMeta.mGroupId;
|
2012-02-04 09:16:39 -05:00
|
|
|
std::cerr << std::endl;
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::createPage() PageId: " << page.mMeta.mMsgId;
|
2012-02-04 09:16:39 -05:00
|
|
|
std::cerr << std::endl;
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::createPage() OrigPageId: " << page.mMeta.mOrigMsgId;
|
2012-02-04 09:16:39 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
|
2012-07-06 19:14:18 -04:00
|
|
|
{
|
|
|
|
RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/
|
2012-02-04 09:16:39 -05:00
|
|
|
|
2012-07-06 19:14:18 -04:00
|
|
|
mUpdated = true;
|
|
|
|
mWikiProxy->addPage(page);
|
|
|
|
}
|
2012-06-13 20:27:28 -04:00
|
|
|
|
2012-07-06 19:14:18 -04:00
|
|
|
// Fake a request to return the MsgMetaData.
|
|
|
|
generateToken(token);
|
|
|
|
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
|
2012-09-14 20:16:06 -04:00
|
|
|
RsTokReqOptionsVEG opts; // NULL is good.
|
2012-07-06 19:14:18 -04:00
|
|
|
std::list<std::string> msgIds;
|
|
|
|
msgIds.push_back(page.mMeta.mMsgId); // It will just return this one.
|
|
|
|
|
2012-09-14 20:16:06 -04:00
|
|
|
std::cerr << "p3WikiServiceVEG::createPage() Generating Request Token: " << token << std::endl;
|
2012-07-06 19:14:18 -04:00
|
|
|
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds);
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
return true;
|
|
|
|
}
|
2012-02-04 09:16:39 -05:00
|
|
|
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
|
|
|
|
/********************************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool WikiDataProxy::getGroup(const std::string &id, RsWikiGroup &group)
|
|
|
|
{
|
|
|
|
void *groupData = NULL;
|
|
|
|
RsGroupMetaData meta;
|
|
|
|
if (getGroupData(id, groupData) && getGroupSummary(id, meta))
|
2012-02-04 09:16:39 -05:00
|
|
|
{
|
2012-06-13 20:27:28 -04:00
|
|
|
RsWikiGroup *pG = (RsWikiGroup *) groupData;
|
|
|
|
group = *pG;
|
2012-02-04 09:16:39 -05:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
// update definitive version of the metadata.
|
|
|
|
group.mMeta = meta;
|
2012-02-04 09:16:39 -05:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
std::cerr << "WikiDataProxy::getGroup() Id: " << id;
|
|
|
|
std::cerr << " MetaData: " << meta << " DataPointer: " << groupData;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return true;
|
2012-02-04 09:16:39 -05:00
|
|
|
}
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
std::cerr << "WikiDataProxy::getGroup() FAILED Id: " << id;
|
|
|
|
std::cerr << std::endl;
|
2012-02-04 09:16:39 -05:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
return false;
|
2012-02-04 09:16:39 -05:00
|
|
|
}
|
2012-06-13 20:27:28 -04:00
|
|
|
|
|
|
|
bool WikiDataProxy::getPage(const std::string &id, RsWikiPage &page)
|
2012-02-04 09:16:39 -05:00
|
|
|
{
|
2012-06-13 20:27:28 -04:00
|
|
|
void *msgData = NULL;
|
|
|
|
RsMsgMetaData meta;
|
|
|
|
if (getMsgData(id, msgData) && getMsgSummary(id, meta))
|
2012-02-04 09:16:39 -05:00
|
|
|
{
|
2012-06-13 20:27:28 -04:00
|
|
|
RsWikiPage *pP = (RsWikiPage *) msgData;
|
|
|
|
// Shallow copy of thumbnail.
|
|
|
|
page = *pP;
|
2012-02-04 09:16:39 -05:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
// update definitive version of the metadata.
|
|
|
|
page.mMeta = meta;
|
|
|
|
|
|
|
|
std::cerr << "WikiDataProxy::getPage() Id: " << id;
|
|
|
|
std::cerr << " MetaData: " << meta << " DataPointer: " << msgData;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "WikiDataProxy::getPage() FAILED Id: " << id;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
return false;
|
2012-02-04 09:16:39 -05:00
|
|
|
}
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
bool WikiDataProxy::addGroup(const RsWikiGroup &group)
|
|
|
|
{
|
|
|
|
// Make duplicate.
|
|
|
|
RsWikiGroup *pG = new RsWikiGroup();
|
|
|
|
*pG = group;
|
|
|
|
|
|
|
|
std::cerr << "WikiDataProxy::addGroup()";
|
|
|
|
std::cerr << " MetaData: " << pG->mMeta << " DataPointer: " << pG;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
return createGroup(pG);
|
|
|
|
}
|
2012-02-04 09:16:39 -05:00
|
|
|
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
bool WikiDataProxy::addPage(const RsWikiPage &page)
|
|
|
|
{
|
|
|
|
// Make duplicate.
|
|
|
|
RsWikiPage *pP = new RsWikiPage();
|
|
|
|
*pP = page;
|
2012-02-04 09:16:39 -05:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
std::cerr << "WikiDataProxy::addPage()";
|
|
|
|
std::cerr << " MetaData: " << pP->mMeta << " DataPointer: " << pP;
|
|
|
|
std::cerr << std::endl;
|
2012-02-04 09:16:39 -05:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
return createMsg(pP);
|
|
|
|
}
|
2012-02-04 09:16:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
/* These Functions must be overloaded to complete the service */
|
|
|
|
bool WikiDataProxy::convertGroupToMetaData(void *groupData, RsGroupMetaData &meta)
|
|
|
|
{
|
|
|
|
RsWikiGroup *group = (RsWikiGroup *) groupData;
|
|
|
|
meta = group->mMeta;
|
2012-02-04 09:16:39 -05:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
return true;
|
|
|
|
}
|
2012-02-04 09:16:39 -05:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
bool WikiDataProxy::convertMsgToMetaData(void *msgData, RsMsgMetaData &meta)
|
|
|
|
{
|
|
|
|
RsWikiPage *page = (RsWikiPage *) msgData;
|
|
|
|
meta = page->mMeta;
|
2012-02-04 09:16:39 -05:00
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
return true;
|
|
|
|
}
|