summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audio.c6
-rw-r--r--src/cmumble.c18
-rw-r--r--src/commands.c12
-rw-r--r--src/message.c20
-rw-r--r--src/message.h34
5 files changed, 36 insertions, 54 deletions
diff --git a/src/audio.c b/src/audio.c
index 1c537dd..d7909c9 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -23,7 +23,7 @@ pull_buffer(GstAppSink *sink, gpointer user_data)
GstBuffer *buf;
uint8_t data[1024];
uint32_t write = 0, pos = 0;
- MumbleProto__UDPTunnel tunnel;
+ mumble_udptunnel_t tunnel;
static int seq = 0;
/* FIXME: Make this more generic/disable pulling
@@ -54,10 +54,10 @@ pull_buffer(GstAppSink *sink, gpointer user_data)
gst_buffer_unref(buf);
- mumble_proto__udptunnel__init(&tunnel);
+ cmumble_init_udptunnel(&tunnel);
tunnel.packet.data = data;
tunnel.packet.len = pos;
- cmumble_send_msg(cm, &tunnel.base);
+ cmumble_send_udptunnel(cm, &tunnel);
return GST_FLOW_OK;
}
diff --git a/src/cmumble.c b/src/cmumble.c
index d18376a..cafef90 100644
--- a/src/cmumble.c
+++ b/src/cmumble.c
@@ -260,13 +260,13 @@ static const struct {
static gboolean
do_ping(struct cmumble *cm)
{
- struct mumble_ping ping;
+ mumble_ping_t ping;
GTimeVal tv;
cmumble_init_ping(&ping);
g_get_current_time(&tv);
- ping.m.timestamp = tv.tv_sec;
- ping.m.resync = 1;
+ ping.timestamp = tv.tv_sec;
+ ping.resync = 1;
cmumble_send_ping(cm, &ping);
return TRUE;
@@ -275,22 +275,22 @@ do_ping(struct cmumble *cm)
void
cmumble_protocol_init(struct cmumble *cm)
{
- MumbleProto__Version version;
- MumbleProto__Authenticate authenticate;
+ mumble_version_t version;
+ mumble_authenticate_t authenticate;
GSource *source;
- mumble_proto__version__init(&version);
+ cmumble_init_version(&version);
version.version = 0x010203;
version.release = PACKAGE_STRING;
version.os = "Gentoo/Linux";
- cmumble_send_msg(cm, &version.base);
+ cmumble_send_version(cm, &version);
- mumble_proto__authenticate__init(&authenticate);
+ cmumble_init_authenticate(&authenticate);
authenticate.username = cm->user_name;
authenticate.password = "";
authenticate.n_celt_versions = 1;
authenticate.celt_versions = (int32_t[]) { 0x8000000b };
- cmumble_send_msg(cm, &authenticate.base);
+ cmumble_send_authenticate(cm, &authenticate);
source = g_timeout_source_new_seconds(5);
g_source_set_callback(source, (GSourceFunc) do_ping, cm, NULL);
diff --git a/src/commands.c b/src/commands.c
index 60e840f..83bc3f0 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -14,7 +14,7 @@ static void
join_channel(struct cmumble *cm,
int argc, char **argv)
{
- MumbleProto__UserState state;
+ mumble_user_state_t state;
char *end;
long num;
@@ -29,13 +29,13 @@ join_channel(struct cmumble *cm,
return;
}
- mumble_proto__user_state__init(&state);
+ cmumble_init_user_state(&state);
state.channel_id = num;
state.has_channel_id = 1;
state.session = cm->session;
state.has_session = 1;
- cmumble_send_msg(cm, &state.base);
+ cmumble_send_user_state(cm, &state);
}
static void
@@ -99,9 +99,9 @@ static void
msg(struct cmumble *cm,
int argc, char **argv)
{
- MumbleProto__TextMessage message;
+ mumble_text_message_t message;
- mumble_proto__text_message__init(&message);
+ cmumble_init_text_message(&message);
message.actor = cm->session;
if (argc < 2) {
@@ -122,7 +122,7 @@ msg(struct cmumble *cm,
message.n_session = 0;
message.n_tree_id = 0;
- cmumble_send_msg(cm, &message.base);
+ cmumble_send_text_message(cm, &message);
}
static const struct cmumble_command commands[] = {
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;
diff --git a/src/message.h b/src/message.h
index b34bed7..a665301 100644
--- a/src/message.h
+++ b/src/message.h
@@ -5,29 +5,12 @@
#include "mumble.pb-c.h"
enum cmumble_message {
-#define MUMBLE_MSG(a,b) a,
+#define MUMBLE_MSG(a,b) CMUMBLE_MESSAGE_##a,
MUMBLE_MSGS
#undef MUMBLE_MSG
+ CMUMBLE_MESSAGE_COUNT
};
-#define PREAMBLE_SIZE 6
-struct mumble_msg_base {
- uint8_t preamble[PREAMBLE_SIZE];
-};
-
-struct __attribute__ ((__packed__)) mumble_message {
- struct mumble_msg_base base;
- ProtobufCMessage msg;
-};
-
-#define MUMBLE_MSG(cname, name) \
- struct __attribute__ ((__packed__)) mumble_##name { \
- struct mumble_msg_base base; \
- MumbleProto__##cname m; \
- };
-MUMBLE_MSGS
-#undef MUMBLE_MSG
-
/* Makro to hide ugly protobuf-c constat names. */
#define MUMBLE_REJECT_TYPE(type) MUMBLE_PROTO__REJECT__REJECT_TYPE__##type
@@ -35,23 +18,26 @@ MUMBLE_MSGS
struct cmumble;
void
-cmumble_send_msg(struct cmumble *cm, ProtobufCMessage *msg);
+cmumble_send_msg(struct cmumble *cm, ProtobufCMessage *msg,
+ enum cmumble_message type);
int
cmumble_recv_msg(struct cmumble *cm);
#define MUMBLE_MSG(cname, name) \
+ typedef MumbleProto__##cname mumble_##name##_t; \
+ \
static inline void \
- cmumble_init_##name(struct mumble_##name *msg) \
+ cmumble_init_##name(mumble_##name##_t *msg) \
{ \
- mumble_proto__##name##__init(&msg->m); \
+ mumble_proto__##name##__init(msg); \
} \
\
static inline void \
- cmumble_send_##name(struct cmumble *cm, struct mumble_##name *msg) \
+ cmumble_send_##name(struct cmumble *cm, mumble_##name##_t *msg) \
{ \
- cmumble_send_msg(cm, &msg->m.base); \
+ cmumble_send_msg(cm, &msg->base, CMUMBLE_MESSAGE_##cname); \
}
MUMBLE_MSGS
#undef MUMBLE_MSG