Created V0.3.x branch and moved the head into the trunk directory.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@246 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2007-11-15 03:18:48 +00:00
commit 935745a08e
1318 changed files with 348809 additions and 0 deletions

View file

@ -0,0 +1,24 @@
RS_TOP_DIR = ..
include ../make.opt
OBJ = notifytxt.o retroshare.o
TESTS =
all : $(OBJ) retroshare-nogui
retroshare-nogui: $(OBJ)
$(CC) $(RSCFLAGS) -o retroshare-nogui $(OBJ) $(RSLIBS)
.cc.o:
$(CC) $(RSCFLAGS) -c $<
clean:
-/bin/rm $(OBJ)
clobber: clean
-/bin/rm retroshare-nogui

View file

@ -0,0 +1,189 @@
/*
* "$Id: notifytxt.cc,v 1.1 2007-02-19 20:08:30 rmf24 Exp $"
*
* RetroShare C++ Interface.
*
* Copyright 2004-2006 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 "rsiface/notifytxt.h"
#include <iostream>
#include <sstream>
void NotifyTxt::notifyErrorMsg(int list, int type, std::string msg)
{
return;
}
void NotifyTxt::notifyChat()
{
return;
}
void NotifyTxt::notifyListChange(int list, int type)
{
std::cerr << "NotifyTxt::notifyListChange()" << std::endl;
switch(list)
{
case NOTIFY_LIST_NEIGHBOURS:
displayNeighbours();
break;
case NOTIFY_LIST_FRIENDS:
displayFriends();
break;
case NOTIFY_LIST_DIRLIST:
displayDirectories();
break;
case NOTIFY_LIST_SEARCHLIST:
displaySearch();
break;
case NOTIFY_LIST_MESSAGELIST:
displayMessages();
break;
case NOTIFY_LIST_CHANNELLIST:
displayChannels();
break;
case NOTIFY_LIST_TRANSFERLIST:
displayTransfers();
break;
default:
break;
}
return;
}
void NotifyTxt::displayNeighbours()
{
iface->lockData(); /* Lock Interface */
std::map<RsCertId,NeighbourInfo>::const_iterator it;
const std::map<RsCertId,NeighbourInfo> &neighs = iface->getNeighbourMap();
std::ostringstream out;
for(it = neighs.begin(); it != neighs.end(); it++)
{
out << "Neighbour: ";
out << it ->second.name << " ";
out << it ->second.status << " ";
out << it ->second.trustLvl << " ";
out << std::endl;
}
std::cerr << out.str();
iface->unlockData(); /* UnLock Interface */
}
void NotifyTxt::displayFriends()
{
iface->lockData(); /* Lock Interface */
std::map<RsCertId,NeighbourInfo>::const_iterator it;
const std::map<RsCertId,NeighbourInfo> &friends = iface->getFriendMap();
std::ostringstream out;
for(it = friends.begin(); it != friends.end(); it++)
{
out << "Friend: ";
out << it->second.name << " ";
out << it->second.status << " ";
out << it->second.trustLvl << " ";
out << std::endl;
}
std::cerr << out.str();
iface->unlockData(); /* UnLock Interface */
}
void NotifyTxt::displayDirectories()
{
iface->lockData(); /* Lock Interface */
std::ostringstream out;
std::cerr << out.str();
iface->unlockData(); /* UnLock Interface */
}
void NotifyTxt::displaySearch()
{
iface->lockData(); /* Lock Interface */
std::ostringstream out;
std::cerr << out.str();
iface->unlockData(); /* UnLock Interface */
}
void NotifyTxt::displayMessages()
{
iface->lockData(); /* Lock Interface */
std::ostringstream out;
std::cerr << out.str();
std::list<MessageInfo>::const_iterator it;
const std::list<MessageInfo> &msgs = iface->getMessages();
std::list<FileInfo>::const_iterator fit;
int i;
for(it = msgs.begin(); it != msgs.end(); it++)
{
out << "Message: ";
out << it->title << std::endl;
out << "\t" << it->msg << std::endl;
const std::list<FileInfo> &files = it -> files;
for(fit = files.begin(), i = 1; fit != files.end(); fit++, i++)
{
out << "\t\tFile(" << i << ") " << fit->fname << std::endl;
}
out << std::endl;
}
iface->unlockData(); /* UnLock Interface */
}
void NotifyTxt::displayChannels()
{
iface->lockData(); /* Lock Interface */
std::ostringstream out;
std::cerr << out.str();
iface->unlockData(); /* UnLock Interface */
}
void NotifyTxt::displayTransfers()
{
iface->lockData(); /* Lock Interface */
std::ostringstream out;
std::cerr << out.str();
iface->unlockData(); /* UnLock Interface */
}

View file

@ -0,0 +1,57 @@
#ifndef RSIFACE_NOTIFY_TXT_H
#define RSIFACE_NOTIFY_TXT_H
/*
* "$Id: notifytxt.h,v 1.1 2007-02-19 20:08:30 rmf24 Exp $"
*
* RetroShare C++ Interface.
*
* Copyright 2004-2006 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 "rsiface/rsiface.h"
#include <string>
class NotifyTxt: public NotifyBase
{
public:
NotifyTxt() { return; }
virtual ~NotifyTxt() { return; }
void setRsIface(RsIface *i) { iface = i; }
virtual void notifyListChange(int list, int type);
virtual void notifyErrorMsg(int list, int sev, std::string msg);
virtual void notifyChat();
private:
void displayNeighbours();
void displayFriends();
void displayDirectories();
void displaySearch();
void displayMessages();
void displayChannels();
void displayTransfers();
RsIface *iface; /* so we can get the data */
};
#endif

View file

@ -0,0 +1,70 @@
/*
* "$Id: retroshare.cc,v 1.4 2007-04-21 19:08:51 rmf24 Exp $"
*
* RetroShare C++ Interface.
*
* Copyright 2004-2006 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 "rsiface/rsiface.h" /* definition of iface */
#include "rsiface/notifytxt.h"
#include <iostream>
#ifdef WINDOWS_SYS
#include <winsock2.h>
#endif
int main(int argc, char **argv)
{
/* Objects */
RsInit *config = InitRsConfig();
InitRetroShare(argc, argv, config);
LoadCertificates(config, false);
//NotifyBase *notify = new NotifyBase();
NotifyTxt *notify = new NotifyTxt();
RsIface *iface = createRsIface(*notify);
RsControl *rsServer = createRsControl(*iface, *notify);
notify->setRsIface(iface);
rsServer -> StartupRetroShare(config);
CleanupRsConfig(config);
/* pass control to the GUI */
while(1)
{
std::cerr << "GUI Tick()" << std::endl;
#ifndef WINDOWS_SYS
sleep(1);
#else
Sleep(1000);
#endif
}
return 1;
}

View file

@ -0,0 +1,241 @@
#ifndef RS_EXPRESSIONS_H
#define RS_EXPRESSIONS_H
/*
* rs-core/src/rsiface: rsexpr.h
*
* RetroShare C++ Interface.
*
* Copyright 2007-2008 by Kashif Kaleem.
*
* 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 <string>
#include <list>
/******************************************************************************************
Enumerations defining the Operators usable in the Boolean search expressions
******************************************************************************************/
enum LogicalOperator{
AndOp=0, /* exp AND exp */
OrOp, /* exp OR exp */
XorOp /* exp XOR exp */
};
/*Operators for String Queries*/
enum StringOperator{
ContainsAnyStrings = 0, /* e.g. name contains any of 'conference' 'meeting' 'presentation' */
ContainsAllStrings, /* same as above except that it contains ALL of the strings */
EqualsString /* exactly equal*/
};
/*Relational operators ( >, <, >=, <=, == and InRange )*/
enum RelOperator{
Equals = 0,
GreaterEquals,
Greater,
SmallerEquals,
Smaller,
InRange /* lower limit <= value <= upper limit*/
};
/******************************************************************************************
Boolean Search Expression
classes:
Expression: The base class of all expression typest
CompoundExpression: The expression which uses a logical operator to combine
the results of two expressions
StringExpression: An expression which uses some sort of string comparison.
RelExpression: A Relational Expression where > < >= <= == make sense.
e.g. size date etc
******************************************************************************************/
class FileEntry;
class Expression{
public:
virtual bool eval (FileEntry *file) = 0;
virtual ~Expression() {};
};
class CompoundExpression : public Expression {
public:
CompoundExpression( enum LogicalOperator op, Expression * exp1, Expression *exp2)
: Lexp(exp1), Rexp(exp2), Op(op){ }
bool eval (FileEntry *file) {
if (Lexp == NULL or Rexp == NULL) {
return false;
}
switch (Op){
case AndOp:
return Lexp->eval(file) && Rexp->eval(file);
case OrOp:
return Lexp->eval(file) || Rexp->eval(file);
case XorOp:
return Lexp->eval(file) ^ Rexp->eval(file);
default:
return false;
}
}
virtual ~CompoundExpression(){
delete Lexp;
delete Rexp;
}
private:
Expression *Lexp;
Expression *Rexp;
enum LogicalOperator Op;
};
class StringExpression: public Expression {
public:
StringExpression(enum StringOperator op, std::list<std::string> &t,
bool ic): Op(op),terms(t), IgnoreCase(ic){}
protected:
bool evalStr(std::string &str);
private:
enum StringOperator Op;
std::list<std::string> terms;
bool IgnoreCase;
};
template <class T>
class RelExpression: public Expression {
public:
RelExpression(enum RelOperator op, T lv, T hv):
Op(op), LowerValue(lv), HigherValue(hv) {}
protected:
bool evalRel(T val);
private:
enum RelOperator Op;
T LowerValue;
T HigherValue;
};
template <class T>
bool RelExpression<T>::evalRel(T val) {
switch (Op) {
case Equals:
return LowerValue == val;
case GreaterEquals:
return LowerValue >= val;
case Greater:
return LowerValue > val;
case SmallerEquals:
return LowerValue <= val;
case Smaller:
return LowerValue < val;
case InRange:
return (LowerValue <= val) && (val <= HigherValue);
default:
return false;
}
}
/******************************************************************************************
Binary Predicate for Case Insensitive search
******************************************************************************************/
/*Binary predicate for case insensitive character comparison.*/
/*TODOS:
*Factor locales in the comparison
*/
struct CompareCharIC :
public std::binary_function< char , char , bool> {
bool operator () ( char ch1 , char ch2 ) const {
return tolower( static_cast < unsigned char > (ch1) )
== tolower( static_cast < unsigned char > (ch2) );
}
};
/******************************************************************************************
Some implementations of StringExpressions.
******************************************************************************************/
class NameExpression: public StringExpression {
public:
NameExpression(enum StringOperator op, std::list<std::string> &t, bool ic):
StringExpression(op,t,ic) {}
bool eval(FileEntry *file);
};
class PathExpression: public StringExpression {
public:
PathExpression(enum StringOperator op, std::list<std::string> &t, bool ic):
StringExpression(op,t,ic) {}
bool eval(FileEntry *file);
};
class ExtExpression: public StringExpression {
public:
ExtExpression(enum StringOperator op, std::list<std::string> &t, bool ic):
StringExpression(op,t,ic) {}
bool eval(FileEntry *file);
};
class HashExpression: public StringExpression {
public:
HashExpression(enum StringOperator op, std::list<std::string> &t):
StringExpression(op,t, true) {}
bool eval(FileEntry *file);
};
/******************************************************************************************
Some implementations of Relational Expressions.
******************************************************************************************/
class DateExpression: public RelExpression<int> {
public:
DateExpression(enum RelOperator op, int v): RelExpression<int>(op,v,v){}
DateExpression(enum RelOperator op, int lv, int hv):
RelExpression<int>(op,lv,hv) {}
bool eval(FileEntry *file);
};
class SizeExpression: public RelExpression<int> {
public:
SizeExpression(enum RelOperator op, int v): RelExpression<int>(op,v,v){}
SizeExpression(enum RelOperator op, int lv, int hv):
RelExpression<int>(op,lv,hv) {}
bool eval(FileEntry *file);
};
class PopExpression: public RelExpression<int> {
public:
PopExpression(enum RelOperator op, int v): RelExpression<int>(op,v,v){}
PopExpression(enum RelOperator op, int lv, int hv):
RelExpression<int>(op,lv,hv) {}
bool eval(FileEntry *file);
};
#endif /* RS_EXPRESSIONS_H */

View file

@ -0,0 +1,349 @@
#ifndef RETROSHARE_GUI_INTERFACE_H
#define RETROSHARE_GUI_INTERFACE_H
/*
* "$Id: rsiface.h,v 1.9 2007-04-21 19:08:51 rmf24 Exp $"
*
* RetroShare C++ Interface.
*
* Copyright 2004-2006 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 "rstypes.h"
#include <map>
class NotifyBase;
class RsIface;
class RsControl;
//class RsServer;
class RsInit;
class Expression;
/* declare single RsIface for everyone to use! */
extern RsIface *rsiface;
extern RsControl *rsicontrol;
/* RsInit -> Configuration Parameters for RetroShare Startup
*/
RsInit *InitRsConfig();
const char *RsConfigDirectory(RsInit *config);
void CleanupRsConfig(RsInit *);
// Called First... (handles comandline options)
int InitRetroShare(int argc, char **argv, RsInit *config);
// This Functions are used for Login.
bool ValidateCertificate(RsInit *config, std::string &userName);
bool ValidateTrustedUser(RsInit *config, std::string fname, std::string &userName);
bool LoadPassword(RsInit *config, std::string passwd);
bool RsGenerateCertificate(RsInit *config, std::string name, std::string org,
std::string loc, std::string country, std::string passwd, std::string &errString);
/* Auto Login Fns */
bool RsTryAutoLogin(RsInit *config);
bool RsStoreAutoLogin(RsInit *config);
bool RsClearAutoLogin(std::string basedir);
// Handle actual Login.
int LoadCertificates(RsInit *config, bool autoLoginNT);
RsIface *createRsIface (NotifyBase &notify);
RsControl *createRsControl(RsIface &iface, NotifyBase &notify);
class RsIface /* The Main Interface Class - create a single one! */
{
public:
RsIface(NotifyBase &callback)
:cb(callback) { return; }
virtual ~RsIface() { return; }
/****************************************/
/* Stubs for Very Important Fns -> Locking Functions */
virtual void lockData() = 0;
virtual void unlockData() = 0;
const std::map<RsCertId,NeighbourInfo> &getNeighbourMap()
{ return mNeighbourMap; }
const std::map<RsCertId,NeighbourInfo> &getFriendMap()
{ return mFriendMap; }
const NeighbourInfo * getFriend(std::string id);
const std::list<FileTransferInfo> &getTransferList()
{ return mTransferList; }
const std::list<PersonInfo> &getRemoteDirectoryList()
{ return mRemoteDirList; }
const std::list<PersonInfo> &getLocalDirectoryList()
{ return mLocalDirList; }
const PersonInfo *getPerson(std::string id);
const DirInfo *getDirectory(std::string id, std::string path);
const std::list<MessageInfo> &getMessages()
{ return mMessageList; }
const std::map<RsChanId, ChannelInfo> &getChannels()
{ return mChannelMap; }
const std::map<RsChanId, ChannelInfo> &getOurChannels()
{ return mChannelOwnMap; }
const MessageInfo *getMessage(std::string cId, std::string mId);
const MessageInfo *getChannelMsg(std::string chId, std::string mId);
std::list<ChatInfo> getChatNew()
{
std::list<ChatInfo> newList = mChatList;
mChatList.clear();
return newList;
}
const std::list<FileInfo> &getRecommendList()
{ return mRecommendList; }
const RsConfig &getConfig()
{ return mConfig; }
/****************************************/
/* Flags to indicate used or not */
enum DataFlags
{
Neighbour = 0,
Friend = 1,
DirLocal = 2, /* Not Used - QModel instead */
DirRemote = 3, /* Not Used - QModel instead */
Transfer = 4,
Message = 5,
Channel = 6,
Chat = 7,
Recommend = 8,
Config = 9,
NumOfFlags = 10
};
/*
* Operations for flags
*/
bool setChanged(DataFlags set); /* set to true */
bool getChanged(DataFlags set); /* leaves it */
bool hasChanged(DataFlags set); /* resets it */
private:
/* Internal Fn for getting the Directory Entry */
PersonInfo *getPersonMod(std::string id);
DirInfo *getDirectoryMod(std::string id, std::string path);
void fillLists(); /* create some dummy data to display */
/* Internals */
std::map<RsCertId,NeighbourInfo> mNeighbourMap;
std::map<RsCertId,NeighbourInfo> mFriendMap;
std::list<PersonInfo> mRemoteDirList;
std::list<PersonInfo> mLocalDirList;
std::list<FileTransferInfo> mTransferList;
std::list<MessageInfo> mMessageList;
std::map<RsChanId, ChannelInfo> mChannelMap;
std::map<RsChanId, ChannelInfo> mChannelOwnMap;
std::list<ChatInfo> mChatList;
std::list<FileInfo> mRecommendList;
bool mChanged[NumOfFlags];
RsConfig mConfig;
NotifyBase &cb;
/* Classes which can update the Lists! */
friend class RsControl;
friend class RsServer;
};
class RsControl /* The Main Interface Class - for controlling the server */
{
public:
RsControl(RsIface &i, NotifyBase &callback)
:cb(callback), rsIface(i) { return; }
virtual ~RsControl() { return; }
/* Real Startup Fn */
virtual int StartupRetroShare(RsInit *config) = 0;
/****************************************/
/* Neighbour Operations */
virtual std::string NeighGetInvite() = 0;
virtual int NeighLoadPEMString(std::string pem, std::string &id) = 0;
virtual int NeighLoadCertificate(std::string fname, std::string &id) = 0;
virtual int NeighAuthFriend(std::string id, RsAuthId code) = 0;
virtual int NeighAddFriend(std::string id) = 0;
virtual int NeighGetSigners(std::string uid, char *out, int len) = 0;
/****************************************/
/* Friend Operations */
virtual int FriendStatus(std::string id, bool accept) = 0;
virtual int FriendRemove(std::string id) = 0;
virtual int FriendConnectAttempt(std::string id) = 0;
virtual int FriendSignCert(std::string id) = 0;
virtual int FriendTrustSignature(std::string id, bool trust) = 0;
virtual int FriendSetLocalAddress(std::string id, std::string addr,
unsigned short port) = 0;
virtual int FriendSetExtAddress(std::string id, std::string addr,
unsigned short port) = 0;
virtual int FriendSetDNSAddress(std::string id, std::string addr) = 0;
virtual int FriendSetFirewall(std::string id, bool firewalled, bool forwarded) = 0;
virtual int FriendSaveCertificate(std::string id, std::string fname) = 0;
/*
virtual int FriendSetConnectMode(std::string id, int mode) = 0;
*/
virtual int FriendSetBandwidth(std::string id, float outkB, float inkB) = 0;
/****************************************/
/* Directory Actions */
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details) = 0;
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) = 0;
/****************************************/
/* Search Actions */
virtual int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results) = 0;
virtual int SearchBoolExp(Expression *exp, std::list<FileDetail> &results) = 0;
/****************************************/
/* Actions For Upload/Download */
//virtual int FileDelete(std::string uId, std::string fname) = 0;
//virtual int FileMove(std::string uId, std::string src, std::string dest) = 0;
virtual int FileRecommend(std::string fname, std::string hash, int size) = 0;
virtual int FileRequest(std::string fname, std::string hash, uint32_t size, std::string dest) = 0;
virtual int FileCancel(std::string fname, std::string hash, uint32_t size) = 0;
// Transfer control.
virtual int FileClearCompleted() = 0;
virtual int FileSetBandwidthTotals(float outkB, float inkB) = 0;
/****************************************/
/* Message Items */
virtual int MessageSend(MessageInfo &info) = 0;
virtual int MessageDelete(std::string id) = 0;
virtual int MessageRead(std::string id) = 0;
/* Channel Items */
virtual int ChannelCreateNew(ChannelInfo &info) = 0;
virtual int ChannelSendMsg(ChannelInfo &info) = 0;
/****************************************/
/* Chat */
virtual int ChatSend(ChatInfo &ci) = 0;
/****************************************/
/* Flagging Persons / Channels / Files in or out of a set (CheckLists) */
virtual int SetInChat(std::string id, bool in) = 0; /* friend : chat msgs */
virtual int SetInMsg(std::string id, bool in) = 0; /* friend : msg receipients */
virtual int SetInBroadcast(std::string id, bool in) = 0; /* channel : channel broadcast */
virtual int SetInSubscribe(std::string id, bool in) = 0; /* channel : subscribed channels */
virtual int SetInRecommend(std::string id, bool in) = 0; /* file : recommended file */
virtual int ClearInChat() = 0;
virtual int ClearInMsg() = 0;
virtual int ClearInBroadcast() = 0;
virtual int ClearInSubscribe() = 0;
virtual int ClearInRecommend() = 0;
/****************************************/
/* RsIface Networking */
virtual int NetworkDHTActive(bool active) = 0;
virtual int NetworkUPnPActive(bool active) = 0;
/****************************************/
/* Config */
virtual int ConfigAddSharedDir( std::string dir ) = 0;
virtual int ConfigRemoveSharedDir( std::string dir ) = 0;
virtual int ConfigSetIncomingDir( std::string dir ) = 0;
virtual int ConfigSetLocalAddr( std::string ipAddr, int port ) = 0;
virtual int ConfigSetExtAddr( std::string ipAddr, int port ) = 0;
virtual int ConfigSetExtName( std::string addr ) = 0;
virtual int ConfigSetLanConfig( bool fire, bool forw ) = 0;
virtual int ConfigSetDataRates( int total, int indiv ) = 0;
virtual int ConfigSetBootPrompt( bool on ) = 0;
virtual int ConfigSave( ) = 0;
/****************************************/
NotifyBase &getNotify() { return cb; }
RsIface &getIface() { return rsIface; }
private:
NotifyBase &cb;
RsIface &rsIface;
};
/********************** Overload this Class for callback *****************/
class NotifyBase
{
public:
NotifyBase() { return; }
virtual ~NotifyBase() { return; }
virtual void notifyListPreChange(int list, int type) { (void) list; (void) type; return; }
virtual void notifyListChange(int list, int type) { (void) list; (void) type; return; }
virtual void notifyErrorMsg(int list, int sev, std::string msg) { (void) list; (void) sev; (void) msg; return; }
virtual void notifyChat() { return; }
};
const int NOTIFY_LIST_NEIGHBOURS = 1;
const int NOTIFY_LIST_FRIENDS = 2;
const int NOTIFY_LIST_DIRLIST = 3;
const int NOTIFY_LIST_SEARCHLIST = 4;
const int NOTIFY_LIST_MESSAGELIST = 5;
const int NOTIFY_LIST_CHANNELLIST = 6;
const int NOTIFY_LIST_TRANSFERLIST = 7;
const int NOTIFY_TYPE_SAME = 0x01;
const int NOTIFY_TYPE_MOD = 0x02; /* general purpose, check all */
const int NOTIFY_TYPE_ADD = 0x04; /* flagged additions */
const int NOTIFY_TYPE_DEL = 0x08; /* flagged deletions */
#endif

View file

@ -0,0 +1,410 @@
#ifndef RS_TYPES_GUI_INTERFACE_H
#define RS_TYPES_GUI_INTERFACE_H
/*
* "$Id: rstypes.h,v 1.7 2007-05-05 16:10:05 rmf24 Exp $"
*
* RetroShare C++ Interface.
*
* Copyright 2004-2006 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 <list>
#include <iostream>
#include <string>
#define RSCERTIDLEN 16
class RsCertId
{
public:
RsCertId();
RsCertId(std::string idstr);
bool operator<(const RsCertId &ref) const;
bool operator==(const RsCertId &ref) const;
bool operator!=(const RsCertId &ref) const;
char data[RSCERTIDLEN];
};
std::ostream &operator<<(std::ostream &out, const RsCertId &id);
/* use RsCertId, (not unsigned long) because the definition will change
typedef unsigned long RsCertId;
*/
typedef RsCertId RsChanId;
typedef RsCertId RsMsgId;
typedef std::string RsAuthId;
/* forward declarations of the classes */
#define INFO_SAME 0x01
#define INFO_CHG 0x02
#define INFO_NEW 0x04
#define INFO_DEL 0x08
class BaseInfo
{
public:
BaseInfo() :flags(0), mId(0) { return; }
RsCertId id; /* key for matching everything */
int flags; /* INFO_TAG above */
/* allow this to be tweaked by the GUI Model */
mutable unsigned int mId; /* (GUI) Model Id -> unique number */
};
class NeighbourInfo: public BaseInfo
{
public:
std::string name;
std::string org;
std::string loc;
std::string state;
std::string country;
int trustLvl;
std::string trustString;
std::list<RsCertId> signers;
std::string authCode;
int status;
std::string acceptString;
std::string statusString;
std::string connectString;
std::string lastConnect;
std::string peerAddress;
/* server settings */
std::string localAddr;
int localPort;
std::string extAddr;
int extPort;
std::string extName;
bool firewalled;
bool forwardPort;
int maxRate; /* kb */
bool ownsign;
/* Flags to indicate if they are in
* chat or msg list
*/
bool inChat;
bool inMsg;
};
/********************** For the Directory Listing *****************/
class FileInfo: public BaseInfo
{
public:
static const int kRsFiStatusNone = 0;
static const int kRsFiStatusStall = 1;
static const int kRsFiStatusProgress = 2;
static const int kRsFiStatusDone = 2;
/* FileInfo(); */
int searchId; /* 0 if none */
std::string path;
std::string fname;
std::string hash;
std::string ext;
int size;
int avail; /* how much we have */
int status;
bool inRecommend;
double rank;
int age;
};
class DirInfo: public BaseInfo
{
public:
DirInfo() :infoAge(0), nofiles(0), nobytes(0) { return; }
std::string path;
std::string dirname;
std::list<DirInfo> subdirs;
std::list<FileInfo> files;
int infoAge;
int nofiles;
int nobytes;
double rank;
int age;
int merge(const DirInfo &udir);
bool exists(const DirInfo&);
DirInfo* existsPv(const DirInfo&);
bool add(const DirInfo&);
int update(const DirInfo &udir);
bool exists(const FileInfo&);
FileInfo* existsPv(const FileInfo&);
bool add(const FileInfo&);
};
class PersonInfo: public BaseInfo
{
public:
std::string name;
bool online;
int infoAge; /* time() at when this was last updated */
DirInfo rootdir;
};
/********************** For Messages and Channels *****************/
class FileTransferInfo: public FileInfo
{
public:
std::string source;
int transfered;
double tfRate; /* kbytes */
bool download;
int downloadStatus; /* 0 = Err, 1 = Ok, 2 = Done */
};
/********************** For Messages and Channels *****************/
#define RS_MSG_BOXMASK 0x000f /* Mask for determining Box */
#define RS_MSG_OUTGOING 0x0001 /* !Inbox */
#define RS_MSG_PENDING 0x0002 /* OutBox */
#define RS_MSG_DRAFT 0x0004 /* Draft */
/* ORs of above */
#define RS_MSG_INBOX 0x00 /* Inbox */
#define RS_MSG_SENTBOX 0x01 /* Sentbox */
#define RS_MSG_OUTBOX 0x03 /* Outbox */
#define RS_MSG_DRAFTBOX 0x05 /* Draftbox */
#define RS_MSG_NEW 0x0010
class MessageInfo: public BaseInfo
{
public:
MessageInfo() {}
RsMsgId msgId;
unsigned int msgflags;
std::string srcname;
std::string title;
std::string header;
std::string msg;
std::list<FileInfo> files;
int size; /* total of files */
int count; /* file count */
int ts;
};
class ChannelInfo: public BaseInfo
{
public:
ChannelInfo() :publisher(false) {}
RsChanId chanId;
bool publisher;
std::string chanName;
std::list<MessageInfo> msglist;
/* details */
int mode;
float rank;
bool inBroadcast;
bool inSubscribe;
int size; /* total of msgs */
int count; /* msg count */
};
#define RS_CHAT_PUBLIC 0x0001
#define RS_CHAT_PRIVATE 0x0002
class ChatInfo: public BaseInfo
{
public:
std::string rsid;
unsigned int chatflags;
std::string name;
std::string msg;
};
/* matched to the uPnP states */
#define UPNP_STATE_UNINITIALISED 0
#define UPNP_STATE_UNAVAILABILE 1
#define UPNP_STATE_READY 2
#define UPNP_STATE_FAILED_TCP 3
#define UPNP_STATE_FAILED_UDP 4
#define UPNP_STATE_ACTIVE 5
class RsConfig
{
public:
std::string ownId;
std::string ownName;
std::list<std::string> sharedDirList;
std::string incomingDir;
std::string localAddr;
int localPort;
std::string extAddr;
int extPort;
std::string extName;
bool firewalled;
bool forwardPort;
int maxDataRate; /* kb */
int maxIndivDataRate; /* kb */
int promptAtBoot; /* popup the password prompt */
bool DHTActive;
bool uPnPActive;
int uPnPState;
int DHTPeers;
};
/********************** For Search Interface *****************/
/* This is still rough, implement later! */
/* text based ones */
const std::string TypeExt = "ext";
const std::string TypeName = "name";
const std::string TypeHash = "hash";
const std::string TypeSize = "size";
const int OpContains = 0x001;
const int OpExactMatch = 0x002;
const int OpLessThan = 0x003;
const int OpGreaterThan = 0x004;
class Condition
{
public:
std::string type;
int op;
double value;
std::string name;
};
class SearchRequest
{
public:
int searchId;
RsCertId toId; /* all zeros for everyone! */
std::list<Condition> tests;
};
std::ostream &operator<<(std::ostream &out, const NeighbourInfo &info);
std::ostream &operator<<(std::ostream &out, const MessageInfo &info);
std::ostream &operator<<(std::ostream &out, const ChannelInfo &info);
std::ostream &operator<<(std::ostream &out, const ChatInfo &info);
std::ostream &operator<<(std::ostream &out, const PersonInfo &info);
std::ostream &print(std::ostream &out, const DirInfo &info, int indentLvl);
/********************** For FileCache Interface *****************/
#define DIR_TYPE_ROOT 0x01
#define DIR_TYPE_PERSON 0x02
#define DIR_TYPE_DIR 0x04
#define DIR_TYPE_FILE 0x08
/* flags for Directry request -
* two types;
* (1) Local / Remote (top byte)
* (2) Request type: Parent / Child - allows reduction in workload.
* (TODO)
*/
#define DIR_FLAGS_LOCAL 0x1000
#define DIR_FLAGS_REMOTE 0x2000
#define DIR_FLAGS_PARENT 0x0001
#define DIR_FLAGS_DETAILS 0x0002
#define DIR_FLAGS_CHILDREN 0x0004
class DirStub
{
public:
uint8_t type;
std::string name;
void *ref;
};
class DirDetails
{
public:
void *parent;
uint32_t prow; /* parent row */
void *ref;
uint8_t type;
std::string id;
std::string name;
std::string hash;
std::string path;
uint32_t count;
uint32_t age;
uint32_t rank;
std::list<DirStub> children;
};
class FileDetail
{
public:
std::string id;
std::string name;
std::string hash;
std::string path;
uint32_t size;
uint32_t age;
uint32_t rank;
};
#endif