2008-03-05 11:32:18 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/rsserver: p3notify.cc
|
|
|
|
*
|
|
|
|
* RetroShare C++ Interface.
|
|
|
|
*
|
|
|
|
* Copyright 2007-2008 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".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2008-03-06 07:07:54 -05:00
|
|
|
#include "pqi/p3notify.h"
|
2009-05-27 16:59:48 -04:00
|
|
|
#include <stdint.h>
|
2014-08-25 17:07:07 -04:00
|
|
|
#include <algorithm>
|
2008-03-05 11:32:18 -05:00
|
|
|
|
2014-01-07 17:51:22 -05:00
|
|
|
RsNotify *rsNotify = NULL ;
|
2008-03-05 11:32:18 -05:00
|
|
|
|
2014-01-07 17:51:22 -05:00
|
|
|
/* Output for retroshare-gui */
|
2008-03-05 11:32:18 -05:00
|
|
|
bool p3Notify::NotifySysMessage(uint32_t &sysid, uint32_t &type,
|
|
|
|
std::string &title, std::string &msg)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(noteMtx); /************* LOCK MUTEX ************/
|
|
|
|
if (pendingSysMsgs.size() > 0)
|
|
|
|
{
|
|
|
|
p3NotifySysMsg smsg = pendingSysMsgs.front();
|
|
|
|
pendingSysMsgs.pop_front();
|
|
|
|
|
|
|
|
sysid = smsg.sysid;
|
|
|
|
type = smsg.type;
|
|
|
|
title = smsg.title;
|
|
|
|
msg = smsg.msg;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-05-05 09:35:36 -04:00
|
|
|
/* Output for retroshare-gui */
|
|
|
|
bool p3Notify::NotifyLogMessage(uint32_t &sysid, uint32_t &type,
|
|
|
|
std::string &title, std::string &msg)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(noteMtx); /************* LOCK MUTEX ************/
|
|
|
|
if (pendingLogMsgs.size() > 0)
|
|
|
|
{
|
|
|
|
p3NotifyLogMsg smsg = pendingLogMsgs.front();
|
|
|
|
pendingLogMsgs.pop_front();
|
|
|
|
|
|
|
|
sysid = smsg.sysid;
|
|
|
|
type = smsg.type;
|
|
|
|
title = smsg.title;
|
|
|
|
msg = smsg.msg;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-03-05 11:32:18 -05:00
|
|
|
|
2010-06-13 06:12:56 -04:00
|
|
|
bool p3Notify::NotifyPopupMessage(uint32_t &ptype, std::string &name, std::string &title, std::string &msg)
|
2008-03-05 11:32:18 -05:00
|
|
|
{
|
|
|
|
RsStackMutex stack(noteMtx); /************* LOCK MUTEX ************/
|
|
|
|
if (pendingPopupMsgs.size() > 0)
|
|
|
|
{
|
|
|
|
p3NotifyPopupMsg pmsg = pendingPopupMsgs.front();
|
|
|
|
pendingPopupMsgs.pop_front();
|
|
|
|
|
|
|
|
ptype = pmsg.type;
|
|
|
|
name = pmsg.name;
|
2010-06-13 06:12:56 -04:00
|
|
|
title = pmsg.title;
|
2008-03-05 11:32:18 -05:00
|
|
|
msg = pmsg.msg;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Control over Messages */
|
|
|
|
bool p3Notify::GetSysMessageList(std::map<uint32_t, std::string> &list)
|
|
|
|
{
|
2010-06-26 08:31:24 -04:00
|
|
|
(void) list; /* suppress unused parameter warning */
|
2008-03-05 11:32:18 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Notify::GetPopupMessageList(std::map<uint32_t, std::string> &list)
|
|
|
|
{
|
2010-06-26 08:31:24 -04:00
|
|
|
(void) list; /* suppress unused parameter warning */
|
2008-03-05 11:32:18 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool p3Notify::SetSysMessageMode(uint32_t sysid, uint32_t mode)
|
|
|
|
{
|
2010-06-26 08:31:24 -04:00
|
|
|
(void) sysid; /* suppress unused parameter warning */
|
|
|
|
(void) mode; /* suppress unused parameter warning */
|
2008-03-05 11:32:18 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3Notify::SetPopupMessageMode(uint32_t ptype, uint32_t mode)
|
|
|
|
{
|
2010-06-26 08:31:24 -04:00
|
|
|
(void) ptype; /* suppress unused parameter warning */
|
|
|
|
(void) mode; /* suppress unused parameter warning */
|
2008-03-05 11:32:18 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Input from libretroshare */
|
2011-06-29 18:54:44 -04:00
|
|
|
bool p3Notify::AddPopupMessage(uint32_t ptype, const std::string& name, const std::string& title, const std::string& msg)
|
2008-03-05 11:32:18 -05:00
|
|
|
{
|
|
|
|
RsStackMutex stack(noteMtx); /************* LOCK MUTEX ************/
|
|
|
|
|
|
|
|
p3NotifyPopupMsg pmsg;
|
|
|
|
|
|
|
|
pmsg.type = ptype;
|
|
|
|
pmsg.name = name;
|
2011-06-29 18:54:44 -04:00
|
|
|
pmsg.title = title;
|
2008-03-05 11:32:18 -05:00
|
|
|
pmsg.msg = msg;
|
|
|
|
|
|
|
|
pendingPopupMsgs.push_back(pmsg);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-29 18:54:44 -04:00
|
|
|
bool p3Notify::AddSysMessage(uint32_t sysid, uint32_t type, const std::string& title, const std::string& msg)
|
2008-03-05 11:32:18 -05:00
|
|
|
{
|
|
|
|
RsStackMutex stack(noteMtx); /************* LOCK MUTEX ************/
|
|
|
|
|
|
|
|
p3NotifySysMsg smsg;
|
|
|
|
|
|
|
|
smsg.sysid = sysid;
|
|
|
|
smsg.type = type;
|
|
|
|
smsg.title = title;
|
|
|
|
smsg.msg = msg;
|
|
|
|
|
|
|
|
pendingSysMsgs.push_back(smsg);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-06-29 18:54:44 -04:00
|
|
|
bool p3Notify::AddLogMessage(uint32_t sysid, uint32_t type, const std::string& title, const std::string& msg)
|
2009-05-05 09:35:36 -04:00
|
|
|
{
|
|
|
|
RsStackMutex stack(noteMtx); /************* LOCK MUTEX ************/
|
|
|
|
|
|
|
|
p3NotifyLogMsg smsg;
|
|
|
|
|
|
|
|
smsg.sysid = sysid;
|
|
|
|
smsg.type = type;
|
|
|
|
smsg.title = title;
|
|
|
|
smsg.msg = msg;
|
|
|
|
|
|
|
|
pendingLogMsgs.push_back(smsg);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-06-20 08:38:11 -04:00
|
|
|
|
|
|
|
bool p3Notify::GetFeedItem(RsFeedItem &item)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(noteMtx); /************* LOCK MUTEX ************/
|
|
|
|
if (pendingNewsFeed.size() > 0)
|
|
|
|
{
|
|
|
|
item = pendingNewsFeed.front();
|
|
|
|
pendingNewsFeed.pop_front();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-09 16:25:39 -04:00
|
|
|
bool p3Notify::AddFeedItem(uint32_t type, const std::string& id1, const std::string& id2, const std::string& id3, const std::string& id4)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(noteMtx); /************* LOCK MUTEX ************/
|
|
|
|
pendingNewsFeed.push_back(RsFeedItem(type, id1, id2, id3, id4));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-06-29 18:54:44 -04:00
|
|
|
bool p3Notify::AddFeedItem(uint32_t type, const std::string& id1, const std::string& id2, const std::string& id3)
|
2008-06-20 08:38:11 -04:00
|
|
|
{
|
|
|
|
RsStackMutex stack(noteMtx); /************* LOCK MUTEX ************/
|
|
|
|
pendingNewsFeed.push_back(RsFeedItem(type, id1, id2, id3));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-23 12:35:42 -04:00
|
|
|
|
|
|
|
bool p3Notify::ClearFeedItems(uint32_t type)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(noteMtx); /************* LOCK MUTEX ************/
|
|
|
|
|
|
|
|
std::list<RsFeedItem>::iterator it;
|
|
|
|
for(it = pendingNewsFeed.begin(); it != pendingNewsFeed.end(); )
|
|
|
|
{
|
|
|
|
if (it->mType == type)
|
|
|
|
{
|
|
|
|
it = pendingNewsFeed.erase(it);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2014-01-07 17:51:22 -05:00
|
|
|
|
|
|
|
#define FOR_ALL_NOTIFY_CLIENTS for(std::list<NotifyClient*>::const_iterator it(notifyClients.begin());it!=notifyClients.end();++it)
|
|
|
|
|
|
|
|
void p3Notify::notifyChatLobbyEvent(uint64_t lobby_id, uint32_t event_type,const std::string& nickname,const std::string& any_string) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatLobbyEvent(lobby_id,event_type,nickname,any_string) ; }
|
|
|
|
|
|
|
|
void p3Notify::notifyListPreChange(int list, int type) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyListPreChange(list,type) ; }
|
|
|
|
void p3Notify::notifyListChange (int list, int type) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyListChange (list,type) ; }
|
|
|
|
|
|
|
|
void p3Notify::notifyErrorMsg (int list, int sev, std::string msg) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyErrorMsg(list,sev,msg) ; }
|
|
|
|
void p3Notify::notifyChatStatus (const std::string& peer_id , const std::string& status_string ,bool is_private) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatStatus(peer_id,status_string,is_private) ; }
|
2014-06-12 18:06:43 -04:00
|
|
|
void p3Notify::notifyChatShow (const std::string& peer_id) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatShow(peer_id) ; }
|
2014-01-07 17:51:22 -05:00
|
|
|
|
|
|
|
void p3Notify::notifyChatLobbyTimeShift (int time_shift) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatLobbyTimeShift(time_shift) ; }
|
|
|
|
void p3Notify::notifyCustomState (const std::string& peer_id , const std::string& status_string ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyCustomState (peer_id,status_string) ; }
|
|
|
|
void p3Notify::notifyHashingInfo (uint32_t type , const std::string& fileinfo ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyHashingInfo (type,fileinfo) ; }
|
|
|
|
void p3Notify::notifyTurtleSearchResult (uint32_t search_id , const std::list<TurtleFileInfo>& files ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyTurtleSearchResult(search_id,files) ; }
|
|
|
|
void p3Notify::notifyPeerHasNewAvatar (std::string peer_id ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerHasNewAvatar(peer_id) ; }
|
|
|
|
void p3Notify::notifyOwnAvatarChanged () { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyOwnAvatarChanged() ; }
|
|
|
|
void p3Notify::notifyOwnStatusMessageChanged() { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyOwnStatusMessageChanged() ; }
|
|
|
|
void p3Notify::notifyDiskFull (uint32_t location , uint32_t size_limit_in_MB ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDiskFull (location,size_limit_in_MB) ; }
|
|
|
|
void p3Notify::notifyPeerStatusChanged (const std::string& peer_id , uint32_t status ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerStatusChanged (peer_id,status) ; }
|
|
|
|
|
|
|
|
void p3Notify::notifyPeerStatusChangedSummary () { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerStatusChangedSummary() ; }
|
|
|
|
void p3Notify::notifyDiscInfoChanged () { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDiscInfoChanged () ; }
|
|
|
|
|
|
|
|
void p3Notify::notifyForumMsgReadSatusChanged (const std::string& channelId, const std::string& msgId, uint32_t status) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyForumMsgReadSatusChanged (channelId,msgId,status) ; }
|
|
|
|
void p3Notify::notifyChannelMsgReadSatusChanged (const std::string& channelId, const std::string& msgId, uint32_t status) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChannelMsgReadSatusChanged (channelId,msgId,status) ; }
|
|
|
|
|
|
|
|
void p3Notify::notifyDownloadComplete (const std::string& fileHash ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDownloadComplete (fileHash) ; }
|
|
|
|
void p3Notify::notifyDownloadCompleteCount (uint32_t count ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDownloadCompleteCount (count) ; }
|
|
|
|
void p3Notify::notifyHistoryChanged (uint32_t msgId , int type) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyHistoryChanged (msgId,type) ; }
|
|
|
|
|
|
|
|
bool p3Notify::askForPassword (const std::string& key_details , bool prev_is_bad , std::string& password)
|
|
|
|
{
|
|
|
|
FOR_ALL_NOTIFY_CLIENTS
|
|
|
|
if( (*it)->askForPassword(key_details,prev_is_bad,password))
|
|
|
|
return true ;
|
|
|
|
|
|
|
|
return false ;
|
|
|
|
}
|
|
|
|
bool p3Notify::askForPluginConfirmation (const std::string& plugin_filename, const std::string& plugin_file_hash)
|
|
|
|
{
|
|
|
|
FOR_ALL_NOTIFY_CLIENTS
|
|
|
|
if( (*it)->askForPluginConfirmation(plugin_filename,plugin_file_hash))
|
|
|
|
return true ;
|
|
|
|
|
|
|
|
return false ;
|
|
|
|
}
|
|
|
|
bool p3Notify::askForDeferredSelfSignature (const void * data , const uint32_t len , unsigned char *sign, unsigned int *signlen,int& signature_result )
|
|
|
|
{
|
|
|
|
FOR_ALL_NOTIFY_CLIENTS
|
|
|
|
if( (*it)->askForDeferredSelfSignature(data,len,sign,signlen,signature_result))
|
|
|
|
return true ;
|
|
|
|
|
|
|
|
return false ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void p3Notify::registerNotifyClient(NotifyClient *cl)
|
|
|
|
{
|
|
|
|
notifyClients.push_back(cl) ;
|
|
|
|
}
|
|
|
|
|
2014-08-25 17:07:07 -04:00
|
|
|
bool p3Notify::unregisterNotifyClient(NotifyClient *nc)
|
|
|
|
{
|
|
|
|
std::list<NotifyClient*>::iterator it = std::find(notifyClients.begin(), notifyClients.end(), nc);
|
|
|
|
if(it != notifyClients.end())
|
|
|
|
{
|
|
|
|
notifyClients.erase(it);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|