2010-03-10 16:38:26 -05:00
|
|
|
/***************************************************************************
|
2010-03-15 08:57:08 -04:00
|
|
|
* Copyright (C) 2009 Cyril Soler *
|
2010-03-10 16:38:26 -05:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program 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 General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#ifndef RETROSHARE_LINK_ANALYZER
|
|
|
|
#define RETROSHARE_LINK_ANALYZER
|
|
|
|
|
|
|
|
// This class implements a RS link.
|
|
|
|
//
|
|
|
|
// The link is done in a way that if valid()==true, then the link can be used.
|
|
|
|
//
|
2010-03-15 08:57:08 -04:00
|
|
|
// The following combinations have been tested:
|
|
|
|
// copy paste-> Transfers (DL) | Message compose (forums) | Private msg | Public chat | private Chat
|
|
|
|
// -------------+----------------+--------------------------+------------------+-------------+-------------
|
|
|
|
// search | Y | Y | Y (send RS link) | Paste menu? | Paste menu?
|
|
|
|
// -------------+----------------+--------------------------+------------------+-------------+-------------
|
|
|
|
// shared | Y | Y | Y (send RS link) | Paste menu? | Paste menu?
|
|
|
|
// -------------+----------------+--------------------------+------------------+-------------+-------------
|
|
|
|
//
|
2010-03-10 16:38:26 -05:00
|
|
|
#include <stdint.h>
|
2014-03-17 16:56:06 -04:00
|
|
|
|
|
|
|
#include <retroshare/rstypes.h>
|
2014-03-29 10:18:05 -04:00
|
|
|
#include <retroshare/rsgxsifacetypes.h>
|
2014-03-17 16:56:06 -04:00
|
|
|
|
2010-03-10 16:38:26 -05:00
|
|
|
#include <QString>
|
|
|
|
#include <QVector>
|
2010-03-10 18:09:35 -05:00
|
|
|
#include <QUrl>
|
2010-03-10 16:38:26 -05:00
|
|
|
|
2012-12-13 17:13:58 -05:00
|
|
|
#define RSLINK_PROCESS_NOTIFY_SUCCESS 1 // notify on success
|
|
|
|
#define RSLINK_PROCESS_NOTIFY_ERROR 2 // notify on error
|
|
|
|
#define RSLINK_PROCESS_NOTIFY_ASK 4 // ask for add the links
|
|
|
|
#define RSLINK_PROCESS_NOTIFY_BAD_CHARS 8 // / or \\ characters in a filename
|
2010-07-15 07:25:34 -04:00
|
|
|
|
2012-12-16 11:28:00 -05:00
|
|
|
#define RSLINK_PROCESS_NOTIFY_ALL 15
|
2010-07-15 07:25:34 -04:00
|
|
|
|
2010-11-18 11:31:44 -05:00
|
|
|
#define RSLINK_SCHEME "retroshare"
|
|
|
|
|
2012-08-16 06:20:34 -04:00
|
|
|
#define RSLINK_SUBTYPE_CERTIFICATE_USER_REQUEST 1
|
2012-11-10 17:59:51 -05:00
|
|
|
#define RSLINK_SUBTYPE_FILE_EXTRA 2
|
2012-08-16 06:20:34 -04:00
|
|
|
|
2010-03-10 16:38:26 -05:00
|
|
|
class RetroShareLink
|
|
|
|
{
|
2010-07-15 07:25:34 -04:00
|
|
|
public:
|
2013-04-13 09:12:13 -04:00
|
|
|
enum enumType { TYPE_UNKNOWN = 0x00,
|
|
|
|
TYPE_FILE = 0x01,
|
|
|
|
TYPE_PERSON = 0x02,
|
|
|
|
TYPE_FORUM = 0x03,
|
|
|
|
TYPE_CHANNEL = 0x04,
|
|
|
|
TYPE_SEARCH = 0x05,
|
|
|
|
TYPE_MESSAGE = 0x06,
|
|
|
|
TYPE_CERTIFICATE = 0x07,
|
|
|
|
TYPE_EXTRAFILE = 0x08,
|
|
|
|
TYPE_PRIVATE_CHAT = 0x09,
|
|
|
|
TYPE_PUBLIC_MSG = 0x0a
|
|
|
|
};
|
2010-07-15 07:25:34 -04:00
|
|
|
|
2010-03-10 16:38:26 -05:00
|
|
|
public:
|
2011-05-04 06:22:49 -04:00
|
|
|
RetroShareLink();
|
2010-03-10 18:09:35 -05:00
|
|
|
RetroShareLink(const QUrl& url);
|
2010-07-15 07:25:34 -04:00
|
|
|
RetroShareLink(const QString& url);
|
2011-05-04 06:22:49 -04:00
|
|
|
|
|
|
|
bool createFile(const QString& name, uint64_t size, const QString& hash);
|
2012-11-10 17:59:51 -05:00
|
|
|
bool createExtraFile(const QString& name, uint64_t size, const QString& hash, const QString& ssl_id);
|
2014-03-17 16:56:06 -04:00
|
|
|
bool createPerson(const RsPgpId &id);
|
2011-05-08 19:11:27 -04:00
|
|
|
bool createForum(const std::string& id, const std::string& msgId);
|
|
|
|
bool createChannel(const std::string& id, const std::string& msgId);
|
2011-05-04 06:22:49 -04:00
|
|
|
bool createSearch(const QString& keywords);
|
2014-03-29 10:18:05 -04:00
|
|
|
bool createMessage(const RsPeerId &peerId, const QString& subject);
|
|
|
|
bool createMessage(const RsGxsId &peerId, const QString& subject);
|
2014-03-17 16:56:06 -04:00
|
|
|
bool createCertificate(const RsPeerId &ssl_id) ;
|
2013-04-13 09:12:13 -04:00
|
|
|
bool createPrivateChatInvite(time_t time_stamp,const QString& gpg_id,const QString& encrypted_chat_info) ;
|
|
|
|
bool createPublicMsgInvite(time_t time_stamp,const QString& pgp_id,const QString& hash) ;
|
2014-03-17 16:56:06 -04:00
|
|
|
bool createUnknwonSslCertificate(const RsPeerId &sslId, const RsPgpId &gpgId = RsPgpId()) ;
|
2010-03-10 16:38:26 -05:00
|
|
|
|
2010-07-15 07:25:34 -04:00
|
|
|
enumType type() const {return _type; }
|
2010-03-10 16:38:26 -05:00
|
|
|
uint64_t size() const { return _size ; }
|
|
|
|
const QString& name() const { return _name ; }
|
|
|
|
const QString& hash() const { return _hash ; }
|
2011-04-19 15:42:44 -04:00
|
|
|
const QString& id() const { return _hash ; }
|
|
|
|
const QString& msgId() const { return _msgId ; }
|
2011-05-07 19:14:09 -04:00
|
|
|
const QString& subject() const { return _subject ; }
|
2012-01-18 15:31:30 -05:00
|
|
|
const QString& GPGRadix64Key() const { return _GPGBase64String ; }
|
|
|
|
const QString& GPGBase64CheckSum() const { return _GPGBase64CheckSum ; }
|
|
|
|
const QString& SSLId() const { return _SSLid ; }
|
|
|
|
const QString& GPGId() const { return _GPGid ; }
|
2012-02-11 09:49:04 -05:00
|
|
|
const QString& localIPAndPort() const { return _loc_ip_port ; }
|
2014-05-06 15:04:57 -04:00
|
|
|
const QString& externalIPAndPort() const { return _ext_ip_port ; }
|
|
|
|
const QString& dyndns() const { return _dyndns_name ; }
|
|
|
|
const QString& location() const { return _location ; }
|
|
|
|
const QString& radix() const { return _radix ; }
|
|
|
|
time_t timeStamp() const { return _time_stamp ; }
|
|
|
|
const QString& encryptedPrivateChatInfo() const { return _encrypted_chat_info ; }
|
|
|
|
QString title() const;
|
2010-03-10 16:38:26 -05:00
|
|
|
|
2012-08-16 06:20:34 -04:00
|
|
|
unsigned int subType() const { return _subType; }
|
|
|
|
void setSubType(unsigned int subType) { _subType = subType; }
|
|
|
|
|
2010-07-15 07:25:34 -04:00
|
|
|
// get nice name for anchor
|
|
|
|
QString niceName() const;
|
|
|
|
|
2010-11-18 11:31:44 -05:00
|
|
|
/// returns the string retroshare://file?name=&size=&hash=
|
|
|
|
/// retroshare://person?name=&hash=
|
2011-10-08 13:49:06 -04:00
|
|
|
QString toString() const;
|
2010-11-18 11:31:44 -05:00
|
|
|
/// returns the string <a href="retroshare://file?name=&size=&hash=">name</a>
|
|
|
|
/// <a href="retroshare://person?name=&hash=">name@hash</a>
|
2010-03-15 08:57:08 -04:00
|
|
|
QString toHtml() const ;
|
2010-11-18 11:31:44 -05:00
|
|
|
/// returns the string <a href="retroshare://file?name=&size=&hash=">retroshare://file?name=&size=&hash=</a>
|
|
|
|
/// <a href="retroshare://person?name=&hash=">retroshare://person?name=&hash=</a>
|
2010-03-21 17:07:12 -04:00
|
|
|
QString toHtmlFull() const ;
|
2010-08-06 11:31:30 -04:00
|
|
|
|
|
|
|
QString toHtmlSize() const ;
|
2010-03-21 17:07:12 -04:00
|
|
|
|
2010-03-10 18:09:35 -05:00
|
|
|
QUrl toUrl() const ;
|
2010-03-10 16:38:26 -05:00
|
|
|
|
2010-07-15 07:25:34 -04:00
|
|
|
bool valid() const { return _valid; }
|
|
|
|
|
|
|
|
bool operator==(const RetroShareLink& l) const { return _type == l._type && _hash == l._hash ; }
|
|
|
|
|
2012-05-11 20:40:53 -04:00
|
|
|
static int process(const QStringList &urls, RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN, uint flag = RSLINK_PROCESS_NOTIFY_ALL);
|
|
|
|
static int process(const QList<RetroShareLink> &links, uint flag = RSLINK_PROCESS_NOTIFY_ALL);
|
2011-05-15 16:21:14 -04:00
|
|
|
|
2010-03-10 16:38:26 -05:00
|
|
|
private:
|
2010-07-15 07:25:34 -04:00
|
|
|
void fromString(const QString &url);
|
2010-11-18 11:31:44 -05:00
|
|
|
void fromUrl(const QUrl &url);
|
|
|
|
void clear();
|
|
|
|
void check();
|
|
|
|
static bool checkHash(const QString& hash);
|
2013-04-13 09:12:13 -04:00
|
|
|
static bool checkRadix64(const QString& s);
|
2011-05-08 19:11:27 -04:00
|
|
|
static bool checkName(const QString& name);
|
2012-11-10 17:59:51 -05:00
|
|
|
static bool checkSSLId(const QString& name);
|
2013-04-13 09:12:13 -04:00
|
|
|
static bool checkPGPId(const QString& name);
|
2010-03-10 16:38:26 -05:00
|
|
|
|
2010-07-15 07:25:34 -04:00
|
|
|
bool _valid;
|
|
|
|
enumType _type;
|
|
|
|
QString _name;
|
2010-03-10 16:38:26 -05:00
|
|
|
uint64_t _size;
|
2011-05-07 19:14:09 -04:00
|
|
|
QString _hash; // or id (forum, channel, message)
|
2011-04-19 15:42:44 -04:00
|
|
|
QString _msgId; // id of the message (forum, channel)
|
2011-05-07 19:14:09 -04:00
|
|
|
QString _subject;
|
2012-01-18 15:31:30 -05:00
|
|
|
QString _SSLid ; // ssl id for rs links
|
|
|
|
QString _GPGid ; // ssl id for rs links
|
|
|
|
QString _GPGBase64String ; // GPG Cert
|
|
|
|
QString _GPGBase64CheckSum ; // GPG Cert
|
|
|
|
QString _location ; // location
|
2014-05-06 15:04:57 -04:00
|
|
|
QString _ext_ip_port ;
|
|
|
|
QString _loc_ip_port ;
|
|
|
|
QString _dyndns_name ;
|
|
|
|
QString _radix ;
|
|
|
|
QString _encrypted_chat_info ; // encrypted data string for the recipient of a chat invite
|
|
|
|
time_t _time_stamp ; // time stamp at which the link will expire.
|
|
|
|
|
2012-08-16 06:20:34 -04:00
|
|
|
unsigned int _subType; // for general use as sub type for _type (RSLINK_SUBTYPE_...)
|
2010-03-10 16:38:26 -05:00
|
|
|
};
|
|
|
|
|
2010-03-15 08:57:08 -04:00
|
|
|
/// This class handles the copy/paste of links. Every member is static to ensure unicity.
|
|
|
|
/// I put no mutex, because all calls supposely com from the GUI thread.
|
2010-03-21 17:07:12 -04:00
|
|
|
///
|
|
|
|
/// All links are stored in html format into the clipboard. Why? Because this allows to import
|
|
|
|
/// links from both the clipboard and the RS application, e.g. paste links from an internet forum.
|
|
|
|
/// This requires many clipboard parsing operations, but this is not a problem because this code is
|
|
|
|
/// not performances-critical.
|
2010-03-15 08:57:08 -04:00
|
|
|
//
|
|
|
|
class RSLinkClipboard
|
|
|
|
{
|
|
|
|
public:
|
2010-03-21 17:07:12 -04:00
|
|
|
// Copy these links to the RS clipboard. Also copy them to the system clipboard
|
|
|
|
//
|
2011-09-11 18:07:24 -04:00
|
|
|
static void copyLinks(const QList<RetroShareLink>& links) ;
|
2010-03-21 17:07:12 -04:00
|
|
|
|
|
|
|
// Get the liste of pasted links, either from the internal RS links, or by default
|
|
|
|
// from the clipboard.
|
|
|
|
//
|
2011-09-11 18:07:24 -04:00
|
|
|
static void pasteLinks(QList<RetroShareLink> &links) ;
|
2010-03-21 17:07:12 -04:00
|
|
|
|
|
|
|
// Produces a list of links with no html structure.
|
|
|
|
static QString toString() ;
|
|
|
|
|
|
|
|
// produces a list of html links that displays with the file names only
|
|
|
|
//
|
|
|
|
static QString toHtml();
|
|
|
|
|
2010-11-18 11:31:44 -05:00
|
|
|
// produces a list of html links that displays with the file name + filesize
|
2010-08-06 11:31:30 -04:00
|
|
|
//
|
|
|
|
static QString toHtmlSize();
|
2010-03-21 17:07:12 -04:00
|
|
|
|
|
|
|
// Returns true is no links are found to paste.
|
|
|
|
// Useful for menus.
|
|
|
|
//
|
2010-07-15 07:25:34 -04:00
|
|
|
static bool empty(RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN);
|
|
|
|
|
|
|
|
// Returns the count of processed links
|
|
|
|
// Useful for menus.
|
|
|
|
//
|
2011-09-11 18:07:24 -04:00
|
|
|
static int process(RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN, uint flag = RSLINK_PROCESS_NOTIFY_ALL);
|
2010-03-21 17:07:12 -04:00
|
|
|
|
2010-03-15 08:57:08 -04:00
|
|
|
private:
|
2011-09-11 18:07:24 -04:00
|
|
|
static void parseClipboard(QList<RetroShareLink> &links) ;
|
2010-03-15 08:57:08 -04:00
|
|
|
};
|
|
|
|
|
2010-03-10 16:38:26 -05:00
|
|
|
#endif
|