summaryrefslogtreecommitdiff
path: root/src/message.c
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2013-11-21 23:11:36 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2013-11-22 08:25:04 +0100
commit19250ba1e16857c70cbbfe15b9e939b95e009896 (patch)
tree2bfd6228b1e65cefe584196566bbc40de6321d5b /src/message.c
parent68992dfac34263d8da2ba9523342d92cbd6f6f98 (diff)
downloadcmumble-19250ba1e16857c70cbbfe15b9e939b95e009896.tar.gz
cmumble-19250ba1e16857c70cbbfe15b9e939b95e009896.tar.bz2
cmumble-19250ba1e16857c70cbbfe15b9e939b95e009896.zip
Pass message type implicity in cmumble_send_*
This also removes the unneeded "struct mumble_*" which is ugly in use.
Diffstat (limited to 'src/message.c')
-rw-r--r--src/message.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/message.c b/src/message.c
index 6cb2c3c..01160c9 100644
--- a/src/message.c
+++ b/src/message.c
@@ -39,20 +39,16 @@ get_preamble(uint8_t *buffer, int *type, int *len)
}
void
-cmumble_send_msg(struct cmumble *cm, ProtobufCMessage *msg)
+cmumble_send_msg(struct cmumble *cm, ProtobufCMessage *msg,
+ enum cmumble_message type)
{
uint8_t pad[128];
uint8_t preamble[PREAMBLE_SIZE];
- int type = -1;
- int i;
ProtobufCBufferSimple buffer = PROTOBUF_C_BUFFER_SIMPLE_INIT(pad);
- for (i = 0; i < G_N_ELEMENTS(messages); ++i)
- if (messages[i].descriptor == msg->descriptor)
- type = i;
- assert(type >= 0);
+ assert(type < CMUMBLE_MESSAGE_COUNT);
- if (type == UDPTunnel) {
+ if (type == CMUMBLE_MESSAGE_UDPTunnel) {
MumbleProto__UDPTunnel *tunnel = (MumbleProto__UDPTunnel *) msg;
buffer.data = tunnel->packet.data;
buffer.len = tunnel->packet.len;
@@ -107,7 +103,7 @@ cmumble_recv_msg(struct cmumble *cm)
get_preamble(preamble, &type, &len);
- if (!(type >= 0 && type < G_N_ELEMENTS(messages))) {
+ if (!(type >= 0 && type < CMUMBLE_MESSAGE_COUNT)) {
g_printerr("unknown message type: %d\n", type);
return 0;
}
@@ -127,15 +123,15 @@ cmumble_recv_msg(struct cmumble *cm)
/* tunneled udp data - not a regular protobuf message
* create dummy ProtobufCMessage */
- if (type == UDPTunnel) {
+ if (type == CMUMBLE_MESSAGE_UDPTunnel) {
MumbleProto__UDPTunnel udptunnel;
mumble_proto__udptunnel__init(&udptunnel);
udptunnel.packet.len = len;
udptunnel.packet.data = (uint8_t *) data;
- if (cm->callbacks[UDPTunnel])
- cm->callbacks[UDPTunnel](&udptunnel.base, cm);
+ if (cm->callbacks[type])
+ cm->callbacks[type](&udptunnel.base, cm);
g_free(data);
return 0;