Use Client_find_by_session() instead of a few open-coded loops.
[umurmur.git] / src / messages.h
1 /* Copyright (C) 2009-2014, Martin Johansson <martin@fatbob.nu>
2    Copyright (C) 2005-2014, Thorvald Natvig <thorvald@natvig.com>
3
4    All rights reserved.
5
6    Redistribution and use in source and binary forms, with or without
7    modification, are permitted provided that the following conditions
8    are met:
9
10    - Redistributions of source code must retain the above copyright notice,
11      this list of conditions and the following disclaimer.
12    - Redistributions in binary form must reproduce the above copyright notice,
13      this list of conditions and the following disclaimer in the documentation
14      and/or other materials provided with the distribution.
15    - Neither the name of the Developers nor the names of its contributors may
16      be used to endorse or promote products derived from this software without
17      specific prior written permission.
18
19    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
23    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31 #ifndef MESSAGES_H_89768
32 #define MESSAGES_H_89768
33
34 #include <stdint.h>
35 #include <arpa/inet.h>
36 #include "Mumble.pb-c.h"
37 #include "list.h"
38 #include "types.h"
39
40 #define PROTVER_MAJOR 1
41 #define PROTVER_MINOR 2
42 #define PROTVER_PATCH 4
43 #define PROTOCOL_VERSION ((PROTVER_MAJOR << 16) | (PROTVER_MINOR << 8) | (PROTVER_PATCH))
44
45 #define PERM_NONE 0x0
46 #define PERM_WRITE 0x1
47 #define PERM_TRAVERSE 0x2
48 #define PERM_ENTER 0x4
49 #define PERM_SPEAK 0x8
50 #define PERM_MUTEDEAFEN 0x10
51 #define PERM_MOVE 0x20
52 #define PERM_MAKECHANNEL 0x40
53 #define PERM_LINKCHANNEL 0x80
54 #define PERM_WHISPER 0x100
55 #define PERM_TEXTMESSAGE 0x200
56 #define PERM_MAKETEMPCHANNEL 0x400
57 // Root channel only
58 #define PERM_KICK 0x10000
59 #define PERM_BAN 0x20000
60 #define PERM_REGISTER 0x40000
61 #define PERM_SELFREGISTER 0x80000       
62 #define PERM_CACHED 0x8000000
63 #define PERM_ALL 0xf07ff
64
65 #define PERM_DEFAULT (PERM_TRAVERSE | PERM_ENTER | PERM_SPEAK | PERM_WHISPER | PERM_TEXTMESSAGE | PERM_MAKETEMPCHANNEL)
66 #define PERM_ADMIN (PERM_DEFAULT | PERM_MUTEDEAFEN | PERM_MOVE | PERM_KICK | PERM_BAN)
67
68 typedef enum {
69         Version,
70         UDPTunnel,
71         Authenticate,
72         Ping,
73         Reject,
74         ServerSync,
75         ChannelRemove,
76         ChannelState,
77         UserRemove,
78         UserState,
79         BanList, /* 10 */
80         TextMessage,
81         PermissionDenied,
82         ACL,
83         QueryUsers,
84         CryptSetup,
85         ContextActionAdd,
86         ContextAction,
87         UserList,
88         VoiceTarget,
89         PermissionQuery, /* 20 */
90         CodecVersion,
91         UserStats,
92         RequestBlob,
93         ServerConfig
94 } messageType_t;
95
96 typedef enum {
97         UDPVoiceCELTAlpha,
98         UDPPing,
99         UDPVoiceSpeex,
100         UDPVoiceCELTBeta,
101         UDPVoiceOpus,
102 } UDPMessageType_t;
103
104
105 typedef union payload {
106         struct  _MumbleProto__Version *version;
107         struct  _MumbleProto__UDPTunnel *UDPTunnel;
108         struct  _MumbleProto__Authenticate *authenticate;
109         struct  _MumbleProto__Ping *ping;
110         struct  _MumbleProto__Reject *reject;
111         struct  _MumbleProto__ServerSync *serverSync;
112         struct  _MumbleProto__ChannelRemove *channelRemove;
113         struct  _MumbleProto__ChannelState *channelState;
114         struct  _MumbleProto__UserRemove *userRemove;
115         struct  _MumbleProto__UserState *userState;
116         struct  _MumbleProto__BanList *banList; 
117         struct  _MumbleProto__TextMessage *textMessage;
118         struct  _MumbleProto__PermissionDenied *permissionDenied;
119         /* ChanACL not supported */
120         /* ACL not supported */
121         struct  _MumbleProto__QueryUsers *queryUsers;
122         struct  _MumbleProto__CryptSetup *cryptSetup;
123         /* ContextActionAdd not supported */
124         /* ContextAction not supported */
125         struct  _MumbleProto__UserList__User *userList_user;
126         struct  _MumbleProto__UserList *userList;
127         struct  _MumbleProto__VoiceTarget__Target *voiceTarget_target;
128         struct  _MumbleProto__VoiceTarget *voiceTarget;
129         struct  _MumbleProto__PermissionQuery *permissionQuery;
130         struct  _MumbleProto__CodecVersion *codecVersion;
131         struct  _MumbleProto__UserStats *userStats;
132         struct  _MumbleProto__ServerConfig *serverConfig;
133 } payload_t;
134
135 typedef struct message {
136         messageType_t messageType;
137         int refcount;
138         struct dlist node;
139         bool_t unpacked;
140         payload_t payload;
141 } message_t;
142
143
144 int Msg_messageToNetwork(message_t *msg, uint8_t *buffer);
145 message_t *Msg_networkToMessage(uint8_t *data, int size);
146 void Msg_free(message_t *msg);
147 void Msg_inc_ref(message_t *msg);
148
149 message_t *Msg_CreateVoiceMsg(uint8_t *data, int size);
150 message_t *Msg_create(messageType_t messageType);
151 void Msg_banList_addEntry(message_t *msg, int index, uint8_t *address, uint32_t mask,
152                           char *name, char *hash, char *reason, char *start, uint32_t duration);
153 void Msg_banList_getEntry(message_t *msg, int index, uint8_t **address, uint32_t *mask,
154                           char **name, char **hash, char **reason, char **start, uint32_t *duration);
155 message_t *Msg_banList_create(int n_bans);
156
157
158 #endif