diff options
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/cmumble.c | 6 | ||||
-rw-r--r-- | src/cmumble.h | 21 | ||||
-rwxr-xr-x | src/gen_message.sh | 12 |
4 files changed, 32 insertions, 11 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index b07626b..fdb5c84 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ bin_PROGRAMS = cmumble -noinst_HEADERS = messages.h mumble.pb-c.h varint.h +noinst_HEADERS = cmumble.h messages.h mumble.pb-c.h varint.h cmumble_SOURCES = cmumble.c mumble.pb-c.c varint.c cmumble_LDADD = $(PROTOBUF_LIBS) $(GLIB_LIBS) $(GIO_LIBS) $(GSTREAMER_LIBS) $(CELT_LIBS) @@ -9,7 +9,7 @@ AM_CFLAGS = $(GCC_FLAGS) $(cmumble_SOURCES): messages.h mumble.pb-c.h -messages.h: messages.txt +messages.h: messages.txt gen_message.sh ./gen_message.sh < $< > $@ mumble.pb-c.c mumble.pb-c.h: mumble.proto diff --git a/src/cmumble.c b/src/cmumble.c index aa7aa04..acee323 100644 --- a/src/cmumble.c +++ b/src/cmumble.c @@ -21,7 +21,7 @@ #include "mumble.pb-c.h" #include "varint.h" -#include "messages.h" +#include "cmumble.h" #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) @@ -157,7 +157,7 @@ pull_buffer(GstAppSink *sink, gpointer user_data) gst_buffer_unref(buf); - add_preamble(&data[0], 1, pos-PREAMBLE_SIZE); + add_preamble(&data[0], UDPTunnel, pos-PREAMBLE_SIZE); g_static_mutex_lock(&write_mutex); g_output_stream_write(output, data, PREAMBLE_SIZE, NULL, NULL); g_output_stream_write(output, &data[PREAMBLE_SIZE], pos-PREAMBLE_SIZE, NULL, NULL); @@ -378,7 +378,7 @@ recv_msg(struct context *ctx, const callback_t *callbacks, uint32_t callback_siz ret = g_input_stream_read(input, data, len, NULL, NULL); /* tunneled udp data - not a regular protobuf message */ - if (type == 1) { + if (type == UDPTunnel) { handle_udp(ctx, data, len); free(data); return; diff --git a/src/cmumble.h b/src/cmumble.h new file mode 100644 index 0000000..94ac8dd --- /dev/null +++ b/src/cmumble.h @@ -0,0 +1,21 @@ +#ifndef _CMUMBLE_H_ +#define _CMUMBLE_H_ + +#include "messages.h" + +enum mumble_message { +#define MUMBLE_MSG(a,b,c) a, + MUMBLE_MSGS +#undef MUMBLE_MSG +}; + +static const struct { + const ProtobufCMessageDescriptor *descriptor; + const char *name; +} messages[] = { +#define MUMBLE_MSG(a,b,c) { &mumble_proto_##b##__descriptor, c }, + MUMBLE_MSGS +#undef MUMBLE_MSG +}; + +#endif diff --git a/src/gen_message.sh b/src/gen_message.sh index 2fbe75c..32ef978 100755 --- a/src/gen_message.sh +++ b/src/gen_message.sh @@ -1,11 +1,11 @@ #!/bin/sh - -echo "static const struct { const ProtobufCMessageDescriptor *descriptor; const char *name; } messages[] = {" +echo "#ifndef _MESSAGES_H_" +echo "#define _MESSAGES_H_" +echo "#define MUMBLE_MSGS \\" while read message do - #lower_name=$(echo $message | tr '[:upper:]' '_[:lower:]' | sed "s/^_\(.*\)$/\1/") - prefixed_lower_name=$(echo "$message" | sed "s/\(^\|[a-z]\)\([A-Z][A-Z]*\)/\1_\L\2/g") - echo -e "\t/* ${message} */ { &mumble_proto_${prefixed_lower_name}__descriptor, \"$message\" }," + echo -e "\tMUMBLE_MSG(${message}, ${prefixed_lower_name}, \"${message}\") \\" done -echo "};" +echo +echo "#endif" |