Use Client_find_by_session() instead of a few open-coded loops.
[umurmur.git] / src / messages.h
index 5283222a45202598ed617743ca3508b5c40cd10e..0ba277d530c70d5dde9ee80fbdf92862afbe21f9 100644 (file)
@@ -1,5 +1,5 @@
-/* Copyright (C) 2009, Martin Johansson <martin@fatbob.nu>
-   Copyright (C) 2005-2009, Thorvald Natvig <thorvald@natvig.com>
+/* Copyright (C) 2009-2014, Martin Johansson <martin@fatbob.nu>
+   Copyright (C) 2005-2014, Thorvald Natvig <thorvald@natvig.com>
 
    All rights reserved.
 
 #define MESSAGES_H_89768
 
 #include <stdint.h>
-#include <openssl/aes.h>
+#include <arpa/inet.h>
+#include "Mumble.pb-c.h"
 #include "list.h"
 #include "types.h"
 
-#define MAX_TEXT 64
-#define SPEEX_DATA_SIZE 1024
-#define MESSAGE_STREAM_VERSION 4
+#define PROTVER_MAJOR 1
+#define PROTVER_MINOR 2
+#define PROTVER_PATCH 4
+#define PROTOCOL_VERSION ((PROTVER_MAJOR << 16) | (PROTVER_MINOR << 8) | (PROTVER_PATCH))
+
+#define PERM_NONE 0x0
+#define PERM_WRITE 0x1
+#define PERM_TRAVERSE 0x2
+#define PERM_ENTER 0x4
+#define PERM_SPEAK 0x8
+#define PERM_MUTEDEAFEN 0x10
+#define PERM_MOVE 0x20
+#define PERM_MAKECHANNEL 0x40
+#define PERM_LINKCHANNEL 0x80
+#define PERM_WHISPER 0x100
+#define PERM_TEXTMESSAGE 0x200
+#define PERM_MAKETEMPCHANNEL 0x400
+// Root channel only
+#define PERM_KICK 0x10000
+#define PERM_BAN 0x20000
+#define PERM_REGISTER 0x40000
+#define PERM_SELFREGISTER 0x80000      
+#define PERM_CACHED 0x8000000
+#define PERM_ALL 0xf07ff
+
+#define PERM_DEFAULT (PERM_TRAVERSE | PERM_ENTER | PERM_SPEAK | PERM_WHISPER | PERM_TEXTMESSAGE | PERM_MAKETEMPCHANNEL)
+#define PERM_ADMIN (PERM_DEFAULT | PERM_MUTEDEAFEN | PERM_MOVE | PERM_KICK | PERM_BAN)
 
 typedef enum {
-       ServerReject,
-       ServerAuthenticate,
-       Speex,
+       Version,
+       UDPTunnel,
+       Authenticate,
+       Ping,
+       Reject,
        ServerSync,
-       ServerJoin,
-       ServerLeave,
-       ServerBanList,
-       PlayerMute,
-       PlayerDeaf,
-       PlayerKick,
-       PlayerRename, /*10 */
-       PlayerBan,
-       PlayerMove,
-       PlayerSelfMuteDeaf,
-       ChannelAdd,
        ChannelRemove,
-       ChannelMove,
-       ChannelLink,
-       ChannelRename,
+       ChannelState,
+       UserRemove,
+       UserState,
+       BanList, /* 10 */
+       TextMessage,
        PermissionDenied,
-       EditACL, /* 20 */
+       ACL,
        QueryUsers,
-       Ping,
-       TextMessage,
-       PlayerTexture,
        CryptSetup,
-       CryptSync,
-       PingStats,
+       ContextActionAdd,
        ContextAction,
-       ContextAddAction,
-       ChannelDescUpdate,
+       UserList,
+       VoiceTarget,
+       PermissionQuery, /* 20 */
+       CodecVersion,
+       UserStats,
+       RequestBlob,
+       ServerConfig
 } messageType_t;
 
-
 typedef enum {
-       AltSpeak = 0x01,
-       LoopBack = 0x02,
-       EndSpeech = 0x04,
-       FrameCountMask = 0x30
-} speexflag_t;
-
-typedef struct {
-       int speexflag;
-       int seq;
-       uint8_t *data;
-       int size;
-} speex_t;
-
-typedef struct {
-       int maxBandwidth;
-       char welcomeText[MAX_TEXT];
-} serverSync_t;
-
-typedef struct {
-       char playerName[MAX_TEXT];
-       int id;
-} serverLeave_t;
+       UDPVoiceCELTAlpha,
+       UDPPing,
+       UDPVoiceSpeex,
+       UDPVoiceCELTBeta,
+       UDPVoiceOpus,
+} UDPMessageType_t;
 
-typedef enum {
-       None,
-       WrongVersion,
-       InvalidUsername,
-       WrongUserPW,
-       WrongServerPW,
-       UsernameInUse,
-       ServerFull
-} rejectType_t;
-
-typedef struct {
-       char reason[MAX_TEXT];
-       rejectType_t type;
-} serverReject_t;
-
-typedef struct {
-       int version;
-       char userName[MAX_TEXT];
-       char password[MAX_TEXT];
-} serverAuthenticate_t;
-
-typedef struct {
-       int id;
-       int parentId;
-       char name[MAX_TEXT];
-} channelAdd_t;
-
-typedef struct {
-       int id;
-       char desc[MAX_TEXT];
-} channelDescUpdate_t;
-
-typedef struct {
-       char playerName[MAX_TEXT];
-       int id;
-} serverJoin_t;
-
-typedef struct {
-       int victim;
-       int channel;
-} playerMove_t;
-
-typedef struct {
-       uint8_t key[AES_BLOCK_SIZE];
-       uint8_t clientNonce[AES_BLOCK_SIZE];
-       uint8_t serverNonce[AES_BLOCK_SIZE];
-} cryptSetup_t;
-
-typedef struct {
-       bool_t empty;
-       uint8_t nonce[AES_BLOCK_SIZE];
-} cryptSync_t;
-
-typedef struct {
-       uint64_t timestamp;
-} ping_t;
-
-typedef struct {
-       uint64_t timestamp;
-       uint32_t good;
-       uint32_t late;
-       uint32_t lost;
-       uint32_t resync;
-       double dUDPPingAvg;
-       double dUDPPingVar;
-       uint32_t UDPPackets;
-       double dTCPPingAvg;
-       double dTCPPingVar;
-       uint32_t TCPPackets;
-} pingStats_t;
-
-typedef struct {
-       char reason[MAX_TEXT];
-} permissionDenied_t;
-
-typedef struct {
-       uint32_t victim;
-       bool_t bMute;
-} playerMute_t;
-
-typedef struct {
-       uint32_t victim;
-       bool_t bDeaf;
-} playerDeaf_t;
-
-typedef struct {
-       bool_t bMute;
-       bool_t bDeaf;
-} playerSelfMuteDeaf_t;
-
-typedef struct {
-       int32_t victim;
-       int32_t channel;
-       bool_t bTree;
-       char message[MAX_TEXT];
-} textMessage_t;
 
 typedef union payload {
-       speex_t speex;
-       serverSync_t serverSync;
-       serverJoin_t serverJoin;
-       serverLeave_t serverLeave;
-       serverReject_t serverReject;
-       serverAuthenticate_t serverAuthenticate;
-       cryptSetup_t cryptSetup;
-       cryptSync_t cryptSync;
-       pingStats_t pingStats;
-       ping_t ping;
-       channelAdd_t channelAdd;
-       channelDescUpdate_t channelDescUpdate;
-       playerMove_t playerMove;
-       permissionDenied_t permissinDenied;
-       playerMute_t playerMute;
-       playerDeaf_t playerDeaf;
-       playerSelfMuteDeaf_t playerSelfMuteDeaf;
-       permissionDenied_t permissionDenied;
-       textMessage_t textMessage;
+       struct  _MumbleProto__Version *version;
+       struct  _MumbleProto__UDPTunnel *UDPTunnel;
+       struct  _MumbleProto__Authenticate *authenticate;
+       struct  _MumbleProto__Ping *ping;
+       struct  _MumbleProto__Reject *reject;
+       struct  _MumbleProto__ServerSync *serverSync;
+       struct  _MumbleProto__ChannelRemove *channelRemove;
+       struct  _MumbleProto__ChannelState *channelState;
+       struct  _MumbleProto__UserRemove *userRemove;
+       struct  _MumbleProto__UserState *userState;
+       struct  _MumbleProto__BanList *banList; 
+       struct  _MumbleProto__TextMessage *textMessage;
+       struct  _MumbleProto__PermissionDenied *permissionDenied;
+       /* ChanACL not supported */
+       /* ACL not supported */
+       struct  _MumbleProto__QueryUsers *queryUsers;
+       struct  _MumbleProto__CryptSetup *cryptSetup;
+       /* ContextActionAdd not supported */
+       /* ContextAction not supported */
+       struct  _MumbleProto__UserList__User *userList_user;
+       struct  _MumbleProto__UserList *userList;
+       struct  _MumbleProto__VoiceTarget__Target *voiceTarget_target;
+       struct  _MumbleProto__VoiceTarget *voiceTarget;
+       struct  _MumbleProto__PermissionQuery *permissionQuery;
+       struct  _MumbleProto__CodecVersion *codecVersion;
+       struct  _MumbleProto__UserStats *userStats;
+       struct  _MumbleProto__ServerConfig *serverConfig;
 } payload_t;
 
 typedef struct message {
        messageType_t messageType;
-       uint32_t sessionId;
        int refcount;
        struct dlist node;
+       bool_t unpacked;
        payload_t payload;
 } message_t;
 
 
-
-int Msg_messageToNetwork(message_t *msg, uint8_t *buffer, int bufsize);
+int Msg_messageToNetwork(message_t *msg, uint8_t *buffer);
 message_t *Msg_networkToMessage(uint8_t *data, int size);
 void Msg_free(message_t *msg);
 void Msg_inc_ref(message_t *msg);
 
+message_t *Msg_CreateVoiceMsg(uint8_t *data, int size);
 message_t *Msg_create(messageType_t messageType);
+void Msg_banList_addEntry(message_t *msg, int index, uint8_t *address, uint32_t mask,
+                          char *name, char *hash, char *reason, char *start, uint32_t duration);
+void Msg_banList_getEntry(message_t *msg, int index, uint8_t **address, uint32_t *mask,
+                          char **name, char **hash, char **reason, char **start, uint32_t *duration);
+message_t *Msg_banList_create(int n_bans);
+
 
 #endif