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".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "services/p3wikiservice.h"
|
|
|
|
|
|
|
|
#include "util/rsrandom.h"
|
|
|
|
|
|
|
|
/****
|
|
|
|
* #define WIKI_DEBUG 1
|
|
|
|
****/
|
|
|
|
|
|
|
|
RsWiki *rsWiki = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
/******************* Startup / Tick ******************************************/
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
p3WikiService::p3WikiService(uint16_t type)
|
2012-06-13 20:27:28 -04:00
|
|
|
:p3GxsDataService(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int p3WikiService::tick()
|
|
|
|
{
|
2012-09-09 10:40:21 -04:00
|
|
|
//std::cerr << "p3WikiService::tick()";
|
|
|
|
//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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3WikiService::updated()
|
|
|
|
{
|
|
|
|
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-06-13 20:27:28 -04:00
|
|
|
bool p3WikiService::requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptions &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);
|
|
|
|
std::cerr << "p3WikiService::requestGroupInfo() gets Token: " << token << std::endl;
|
|
|
|
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-06-13 20:27:28 -04:00
|
|
|
bool p3WikiService::requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds)
|
|
|
|
{
|
|
|
|
generateToken(token);
|
|
|
|
std::cerr << "p3WikiService::requestMsgInfo() gets Token: " << token << std::endl;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3WikiService::requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &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);
|
|
|
|
std::cerr << "p3WikiService::requestMsgRelatedInfo() gets Token: " << token << std::endl;
|
|
|
|
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 */
|
|
|
|
bool p3WikiService::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-06-13 20:27:28 -04:00
|
|
|
std::cerr << "p3WikiService::getGroupList() ERROR AnsType Wrong" << std::endl;
|
|
|
|
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-06-13 20:27:28 -04:00
|
|
|
std::cerr << "p3WikiService::getGroupList() ERROR ReqType Wrong" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != GXS_REQUEST_STATUS_COMPLETE)
|
|
|
|
{
|
|
|
|
std::cerr << "p3WikiService::getGroupList() ERROR Status Incomplete" << std::endl;
|
|
|
|
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-06-13 20:27:28 -04:00
|
|
|
bool p3WikiService::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)
|
|
|
|
{
|
|
|
|
std::cerr << "p3WikiService::getMsgList() ERROR AnsType Wrong" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED))
|
|
|
|
{
|
|
|
|
std::cerr << "p3WikiService::getMsgList() ERROR ReqType Wrong" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != GXS_REQUEST_STATUS_COMPLETE)
|
|
|
|
{
|
|
|
|
std::cerr << "p3WikiService::getMsgList() ERROR Status Incomplete" << std::endl;
|
|
|
|
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 */
|
|
|
|
bool p3WikiService::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)
|
|
|
|
{
|
|
|
|
std::cerr << "p3WikiService::getGroupSummary() ERROR AnsType Wrong" << std::endl;
|
|
|
|
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-06-13 20:27:28 -04:00
|
|
|
std::cerr << "p3WikiService::getGroupSummary() ERROR ReqType Wrong" << std::endl;
|
2012-06-08 18:03:09 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != GXS_REQUEST_STATUS_COMPLETE)
|
|
|
|
{
|
2012-06-13 20:27:28 -04:00
|
|
|
std::cerr << "p3WikiService::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
|
|
|
|
|
|
|
bool p3WikiService::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-06-13 20:27:28 -04:00
|
|
|
std::cerr << "p3WikiService::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-06-13 20:27:28 -04:00
|
|
|
std::cerr << "p3WikiService::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-06-13 20:27:28 -04:00
|
|
|
std::cerr << "p3WikiService::getMsgSummary() ERROR Status Incomplete" << std::endl;
|
|
|
|
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-06-08 18:03:09 -04:00
|
|
|
bool p3WikiService::getGroupData(const uint32_t &token, RsWikiGroup &group)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
std::cerr << "p3WikiService::getGroupData() ERROR AnsType Wrong" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
|
2012-06-08 18:03:09 -04:00
|
|
|
{
|
2012-06-13 20:27:28 -04:00
|
|
|
std::cerr << "p3WikiService::getGroupData() ERROR ReqType Wrong" << std::endl;
|
2012-06-08 18:03:09 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != GXS_REQUEST_STATUS_COMPLETE)
|
|
|
|
{
|
|
|
|
std::cerr << "p3WikiService::getGroupData() ERROR Status Incomplete" << std::endl;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool p3WikiService::getMsgData(const uint32_t &token, RsWikiPage &page)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
std::cerr << "p3WikiService::getMsgData() ERROR AnsType Wrong" << std::endl;
|
|
|
|
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-06-13 20:27:28 -04:00
|
|
|
std::cerr << "p3WikiService::getMsgData() ERROR ReqType Wrong" << std::endl;
|
2012-06-08 18:03:09 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != GXS_REQUEST_STATUS_COMPLETE)
|
|
|
|
{
|
|
|
|
std::cerr << "p3WikiService::getMsgData() ERROR Status Incomplete" << std::endl;
|
|
|
|
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 */
|
|
|
|
uint32_t p3WikiService::requestStatus(const uint32_t token)
|
|
|
|
{
|
|
|
|
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 */
|
|
|
|
bool p3WikiService::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-07-06 19:14:18 -04:00
|
|
|
bool p3WikiService::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-07-06 19:14:18 -04:00
|
|
|
bool p3WikiService::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-07-06 19:14:18 -04:00
|
|
|
bool p3WikiService::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask)
|
|
|
|
{
|
|
|
|
return mWikiProxy->setGroupSubscribeFlags(groupId, subscribeFlags, subscribeMask);
|
|
|
|
}
|
2012-02-04 09:16:39 -05:00
|
|
|
|
2012-07-06 19:14:18 -04:00
|
|
|
bool p3WikiService::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);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3WikiService::setGroupServiceString(const std::string &grpId, const std::string &str)
|
|
|
|
{
|
|
|
|
return mWikiProxy->setGroupServiceString(grpId, str);
|
2012-02-04 09:16:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-13 20:27:28 -04:00
|
|
|
bool p3WikiService::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-06-13 20:27:28 -04:00
|
|
|
bool p3WikiService::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
|
|
|
|
|
|
|
std::string p3WikiService::genRandomId()
|
|
|
|
{
|
|
|
|
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-07-06 19:14:18 -04:00
|
|
|
bool p3WikiService::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
|
|
|
|
{
|
|
|
|
std::cerr << "p3WikiService::createGroup() Group with existing Id... dropping";
|
|
|
|
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;
|
|
|
|
RsTokReqOptions opts; // NULL is good.
|
|
|
|
std::list<std::string> groupIds;
|
|
|
|
groupIds.push_back(group.mMeta.mGroupId); // It will just return this one.
|
|
|
|
|
|
|
|
std::cerr << "p3WikiService::createGroup() Generating Request Token: " << token << std::endl;
|
|
|
|
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds);
|
2012-02-04 09:16:39 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-06 19:14:18 -04:00
|
|
|
bool p3WikiService::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 */
|
|
|
|
std::cerr << "p3WikiService::createPage() Missing PageID";
|
|
|
|
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
|
|
|
{
|
|
|
|
std::cerr << "p3WikiService::createPage() New Page";
|
|
|
|
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
|
|
|
|
{
|
|
|
|
std::cerr << "p3WikiService::createPage() Modified Page";
|
|
|
|
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-06-13 20:27:28 -04:00
|
|
|
std::cerr << "p3WikiService::createPage() GroupId: " << page.mMeta.mGroupId;
|
2012-02-04 09:16:39 -05:00
|
|
|
std::cerr << std::endl;
|
2012-06-13 20:27:28 -04:00
|
|
|
std::cerr << "p3WikiService::createPage() PageId: " << page.mMeta.mMsgId;
|
2012-02-04 09:16:39 -05:00
|
|
|
std::cerr << std::endl;
|
2012-06-13 20:27:28 -04:00
|
|
|
std::cerr << "p3WikiService::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;
|
|
|
|
RsTokReqOptions opts; // NULL is good.
|
|
|
|
std::list<std::string> msgIds;
|
|
|
|
msgIds.push_back(page.mMeta.mMsgId); // It will just return this one.
|
|
|
|
|
|
|
|
std::cerr << "p3WikiService::createPage() Generating Request Token: " << token << std::endl;
|
|
|
|
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;
|
|
|
|
}
|