From 19250ba1e16857c70cbbfe15b9e939b95e009896 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Thu, 21 Nov 2013 23:11:36 +0100 Subject: Pass message type implicity in cmumble_send_* This also removes the unneeded "struct mumble_*" which is ugly in use. --- src/message.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/message.c') 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; -- cgit