1 // Copyright 2005-2019 The Mumble Developers. All rights reserved. 2 // Use of this source code is governed by a BSD-style license 3 // that can be found in the LICENSE file at the root of the 4 // Mumble source tree or at <https://www.mumble.info/LICENSE>. 5 6 #ifdef USE_DBUS 7 #ifndef MUMBLE_MURMUR_DBUS_H_ 8 #define MUMBLE_MURMUR_DBUS_H_ 9 10 #include <QtDBus/QDBusAbstractAdaptor> 11 #include <QtDBus/QDBusConnection> 12 13 #include "ACL.h" 14 #include "Channel.h" 15 #include "Group.h" 16 #include "Meta.h" 17 #include "Server.h" 18 #include "ServerDB.h" 19 #include "User.h" 20 21 struct Ban; 22 class QDBusObjectPath; 23 class QDBusMessage; 24 25 struct PlayerInfo { 26 unsigned int session; 27 bool mute, deaf, suppressed; 28 bool selfMute, selfDeaf; 29 int channel; PlayerInfoPlayerInfo30 PlayerInfo() : session(0), mute(false), deaf(false), suppressed(false), selfMute(false), selfDeaf(false), channel(-1) { }; 31 PlayerInfo(const User *); 32 }; 33 Q_DECLARE_METATYPE(PlayerInfo); 34 35 struct PlayerInfoExtended : public PlayerInfo { 36 int id; 37 QString name; 38 int onlinesecs; 39 int bytespersec; PlayerInfoExtendedPlayerInfoExtended40 PlayerInfoExtended() : id(-1), onlinesecs(-1), bytespersec(-1) {}; 41 PlayerInfoExtended(const User *); 42 }; 43 Q_DECLARE_METATYPE(PlayerInfoExtended); 44 Q_DECLARE_METATYPE(QList<PlayerInfoExtended>); 45 46 struct ChannelInfo { 47 int id; 48 QString name; 49 int parent; 50 QList<int> links; ChannelInfoChannelInfo51 ChannelInfo() : id(-1), parent(-1) { }; 52 ChannelInfo(const Channel *c); 53 }; 54 Q_DECLARE_METATYPE(ChannelInfo); 55 Q_DECLARE_METATYPE(QList<ChannelInfo>); 56 57 struct GroupInfo { 58 QString name; 59 bool inherited, inherit, inheritable; 60 QList<int> add, remove, members; GroupInfoGroupInfo61 GroupInfo() : inherited(false), inherit(false), inheritable(false) { }; 62 GroupInfo(const Group *g); 63 }; 64 Q_DECLARE_METATYPE(GroupInfo); 65 Q_DECLARE_METATYPE(QList<GroupInfo>); 66 67 struct ACLInfo { 68 bool applyHere, applySubs, inherited; 69 int playerid; 70 QString group; 71 unsigned int allow, deny; ACLInfoACLInfo72 ACLInfo() : applyHere(false), applySubs(false), inherited(false), playerid(-1), allow(0), deny(0) { }; 73 ACLInfo(const ChanACL *acl); 74 }; 75 Q_DECLARE_METATYPE(ACLInfo); 76 Q_DECLARE_METATYPE(QList<ACLInfo>); 77 78 struct BanInfo { 79 unsigned int address; 80 int bits; BanInfoBanInfo81 BanInfo() : address(0), bits(0) { }; 82 BanInfo(const Ban &); 83 }; 84 Q_DECLARE_METATYPE(BanInfo); 85 Q_DECLARE_METATYPE(QList<BanInfo>); 86 87 struct RegisteredPlayer { 88 int id; 89 QString name; 90 QString email; 91 QString pw; 92 RegisteredPlayer(); 93 }; 94 Q_DECLARE_METATYPE(RegisteredPlayer); 95 Q_DECLARE_METATYPE(QList<RegisteredPlayer>); 96 97 struct LogEntry { 98 unsigned int timestamp; 99 QString txt; 100 LogEntry(); 101 LogEntry(const ServerDB::LogRecord &); 102 }; 103 Q_DECLARE_METATYPE(LogEntry); 104 Q_DECLARE_METATYPE(QList<LogEntry>); 105 106 class MurmurDBus : public QDBusAbstractAdaptor { 107 private: 108 Q_OBJECT 109 Q_CLASSINFO("D-Bus Interface", "net.sourceforge.mumble.Murmur") 110 Q_DISABLE_COPY(MurmurDBus) 111 protected: 112 Server *server; 113 bool bReentrant; 114 QString qsAuthService; 115 QString qsAuthPath; 116 void removeAuthenticator(); 117 public: 118 static QDBusConnection *qdbc; 119 120 MurmurDBus(Server *srv); 121 static void registerTypes(); 122 public slots: 123 // These have the result ref as the first parameter, so won't be converted to DBus 124 void authenticateSlot(int &res, QString &uname, int sessionId, const QList<QSslCertificate> &certs, const QString &certhash, bool strong, const QString &pw); 125 void registerUserSlot(int &res, const QMap<int, QString> &); 126 void unregisterUserSlot(int &res, int id); 127 void getRegisteredUsersSlot(const QString &filter, QMap<int, QString> &res); 128 void getRegistrationSlot(int &, int, QMap<int, QString> &); 129 void setInfoSlot(int &, int, const QMap<int, QString> &); 130 void setTextureSlot(int &res, int id, const QByteArray &texture); 131 void nameToIdSlot(int &res, const QString &name); 132 void idToNameSlot(QString &res, int id); 133 void idToTextureSlot(QByteArray &res, int id); 134 135 // These use private types, so won't be converted to DBus 136 void userStateChanged(const User *p); 137 void userTextMessage(const User *, const TextMessage &); 138 void userConnected(const User *p); 139 void userDisconnected(const User *p); 140 141 void channelStateChanged(const Channel *c); 142 void channelCreated(const Channel *c); 143 void channelRemoved(const Channel *c); 144 145 public slots: 146 // Order of paremeters is IMPORTANT, or Qt will barf. 147 // Needs to be: 148 // First all input parameters (non-ref or const-ref) 149 // Then const QDbusMessage ref 150 // Then output paremeters (ref) 151 // Unfortunately, this makes things look chaotic, but luckily it looks sane again when introspected. 152 // make SURE arguments have sane names, the argument-name will be exported in introspection xml. 153 154 void getPlayers(QList<PlayerInfoExtended> &player_list); 155 void getChannels(QList<ChannelInfo> &channel_list); 156 157 void getACL(int channel, const QDBusMessage &, QList<ACLInfo> &acls,QList<GroupInfo> &groups, bool &inherit); 158 void setACL(int channel, const QList<ACLInfo> &acls, const QList<GroupInfo> &groups, bool inherit, const QDBusMessage &); 159 160 void getBans(QList<BanInfo> &bans); 161 void setBans(const QList<BanInfo> &bans, const QDBusMessage &); 162 163 void kickPlayer(unsigned int session, const QString &reason, const QDBusMessage &); 164 void getPlayerState(unsigned int session, const QDBusMessage &, PlayerInfo &state); 165 void setPlayerState(const PlayerInfo &state, const QDBusMessage &); 166 void sendMessage(unsigned int session, const QString &text, const QDBusMessage &); 167 168 void getChannelState(int id, const QDBusMessage &, ChannelInfo &state); 169 void setChannelState(const ChannelInfo &state, const QDBusMessage &); 170 void removeChannel(int id, const QDBusMessage &); 171 void addChannel(const QString &name, int parent, const QDBusMessage &, int &newid); 172 void sendMessageChannel(int id, bool tree, const QString &text, const QDBusMessage &); 173 174 void getPlayerNames(const QList<int> &ids, const QDBusMessage &, QStringList &names); 175 void getPlayerIds(const QStringList &names, const QDBusMessage &, QList<int> &ids); 176 177 void setAuthenticator(const QDBusObjectPath &path, bool reentrant, const QDBusMessage &); 178 void setTemporaryGroups(int channel, int playerid, const QStringList &groups, const QDBusMessage &); 179 180 void registerPlayer(const QString &name, const QDBusMessage &, int &id); 181 void unregisterPlayer(int id, const QDBusMessage &); 182 void updateRegistration(const RegisteredPlayer &player, const QDBusMessage &); 183 void setRegistration(int id, const QString &name, const QString &email, const QString &pw, const QDBusMessage &); 184 void getRegistration(int id, const QDBusMessage &, RegisteredPlayer &player); 185 void getRegisteredPlayers(const QString &filter, QList<RegisteredPlayer> &players); 186 void verifyPassword(int id, const QString &pw, const QDBusMessage &, bool &ok); 187 void getTexture(int id, const QDBusMessage &, QByteArray &texture); 188 void setTexture(int id, const QByteArray &, const QDBusMessage &); 189 signals: 190 void playerStateChanged(const PlayerInfo &state); 191 void playerConnected(const PlayerInfo &state); 192 void playerDisconnected(const PlayerInfo &state); 193 194 void channelStateChanged(const ChannelInfo &state); 195 void channelCreated(const ChannelInfo &state); 196 void channelRemoved(const ChannelInfo &state); 197 }; 198 199 typedef QMap<QString, QString> ConfigMap; 200 Q_DECLARE_METATYPE(ConfigMap); 201 202 class MetaDBus : public QDBusAbstractAdaptor { 203 private: 204 Q_OBJECT 205 Q_CLASSINFO("D-Bus Interface", "net.sourceforge.mumble.Meta") 206 Q_DISABLE_COPY(MetaDBus) 207 protected: 208 Meta *meta; 209 public: 210 MetaDBus(Meta *m); 211 212 public slots: 213 void started(Server *s); 214 void stopped(Server *s); 215 public slots: 216 void start(int server_id, const QDBusMessage &); 217 void stop(int server_id, const QDBusMessage &); 218 void newServer(int &server_id); 219 void deleteServer(int server_id, const QDBusMessage &); 220 void getBootedServers(QList<int> &server_list); 221 void getAllServers(QList<int> &server_list); 222 void isBooted(int server_id, bool &booted); 223 void getConf(int server_id, const QString &key, const QDBusMessage &, QString &value); 224 void getAllConf(int server_id, const QDBusMessage &, ConfigMap &values); 225 void getDefaultConf(ConfigMap &values); 226 void setConf(int server_id, const QString &key, const QString &value, const QDBusMessage &); 227 void setSuperUserPassword(int server_id, const QString &pw, const QDBusMessage &); 228 void getLog(int server_id, int min_offset, int max_offset, const QDBusMessage &, QList<LogEntry> &entries); 229 void getVersion(int &major, int &minor, int &patch, QString &string); 230 void quit(); 231 signals: 232 void started(int server_id); 233 void stopped(int server_id); 234 }; 235 236 #endif 237 #endif 238