00001 #ifndef SST_REG_H
00002 #define SST_REG_H
00003
00004 #include <QHash>
00005 #include <QString>
00006 #include <QStringList>
00007 #include <QByteArray>
00008 #include <QFlags>
00009
00010 namespace SST {
00011
00012 class XdrStream;
00013 class Endpoint;
00014
00015
00016 #define REGSERVER_DEFAULT_PORT 8662
00017
00018
00019
00020
00021 #define REG_MAGIC (quint32)0x004e7273
00022
00023 #define REG_REQUEST 0x100 // Client-to-server request
00024 #define REG_RESPONSE 0x200 // Server-to-client response
00025 #define REG_NOTIFY 0x300 // Server-to-client async callback
00026
00027 #define REG_INSERT1 0x00 // Insert entry - preliminary request
00028 #define REG_INSERT2 0x01 // Insert entry - authenticated request
00029 #define REG_LOOKUP 0x02 // Lookup host by ID, optionally notify
00030 #define REG_SEARCH 0x03 // Search entry by keyword
00031
00032
00033
00034
00035
00036 class RegInfo
00037 {
00038 public:
00039
00040
00041 enum AttrFlag {
00042 Invalid = 0x00000000,
00043
00044
00045 SearchFlag = 0x00010000,
00046
00047
00048 Endpoints = 0x00000001,
00049
00050
00051 HostName = 0x00010001,
00052 OwnerName = 0x00010002,
00053 City = 0x00010003,
00054 Region = 0x00010004,
00055 Country = 0x00010005,
00056 };
00057 Q_DECLARE_FLAGS(Attr, AttrFlag)
00058
00059 private:
00060 QHash<Attr, QByteArray> at;
00061
00062
00063 public:
00064
00065 inline QByteArray attr(Attr tag) const
00066 { return at.value(tag); }
00067 inline void setAttr(Attr tag, const QByteArray &value)
00068 { at.insert(tag, value); }
00069 inline void remove(Attr tag)
00070 { setAttr(tag, QByteArray()); }
00071 inline bool isEmpty() const { return at.isEmpty(); }
00072 inline QList<Attr> tags() const { return at.keys(); }
00073
00074
00075 inline QString string(Attr tag) const
00076 { return QString::fromUtf8(at.value(tag)); }
00077 inline void setString(Attr tag, const QString &value)
00078 { at.insert(tag, value.toUtf8()); }
00079
00080
00081 inline QString hostName() const { return string(HostName); }
00082 inline QString ownerName() const { return string(OwnerName); }
00083 inline QString city() const { return string(City); }
00084 inline QString region() const { return string(Region); }
00085 inline QString country() const { return string(Country); }
00086
00087 inline void setHostName(const QString &str)
00088 { setString(HostName, str); }
00089 inline void setOwnerName(const QString &str)
00090 { setString(OwnerName, str); }
00091 inline void setCity(const QString &str)
00092 { setString(City, str); }
00093 inline void setRegion(const QString &str)
00094 { setString(Region, str); }
00095 inline void setCountry(const QString &str)
00096 { setString(Country, str); }
00097
00098
00099 QList<Endpoint> endpoints() const;
00100 void setEndpoints(const QList<Endpoint> &endpoints);
00101
00102
00103 QStringList keywords() const;
00104
00105
00106 void encode(XdrStream &ws) const;
00107 void decode(XdrStream &ws);
00108 QByteArray encode() const;
00109 static RegInfo decode(const QByteArray &data);
00110
00111
00112 inline RegInfo() { }
00113 inline RegInfo(const RegInfo &other) : at(other.at) { }
00114 inline RegInfo(const QByteArray &data) { *this = decode(data); }
00115 };
00116
00117 Q_DECLARE_OPERATORS_FOR_FLAGS(RegInfo::Attr)
00118
00119 inline XdrStream &operator<<(XdrStream &xs, const RegInfo &fi)
00120 { fi.encode(xs); return xs; }
00121 inline XdrStream &operator>>(XdrStream &xs, RegInfo &fi)
00122 { fi.decode(xs); return xs; }
00123
00124
00125 }
00126
00127 #endif // SST_REG_H