summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2013-11-21 10:45:44 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2013-11-21 22:20:59 +0100
commitd4abd71aff37402fea80191c9b3b990124b0ee9b (patch)
tree1c237d3714ba7128983f7419a87e430f315454a8
parent3e94de272da73e76219a114395130fd1844e68af (diff)
downloadcmumble-d4abd71aff37402fea80191c9b3b990124b0ee9b.tar.gz
cmumble-d4abd71aff37402fea80191c9b3b990124b0ee9b.tar.bz2
cmumble-d4abd71aff37402fea80191c9b3b990124b0ee9b.zip
message.h: Add wrapper around protobufs ugly func names
They are of cause autogenerated. Only the one wrapper for the reject enum is added as one makro by hand.
-rw-r--r--src/cmumble.c16
-rw-r--r--src/message.h38
2 files changed, 46 insertions, 8 deletions
diff --git a/src/cmumble.c b/src/cmumble.c
index ed97ea1..d514ca4 100644
--- a/src/cmumble.c
+++ b/src/cmumble.c
@@ -198,14 +198,14 @@ static void
recv_reject(MumbleProto__Reject *reject, struct cmumble *cm)
{
switch (reject->type) {
- case MUMBLE_PROTO__REJECT__REJECT_TYPE__None:
- case MUMBLE_PROTO__REJECT__REJECT_TYPE__WrongVersion:
- case MUMBLE_PROTO__REJECT__REJECT_TYPE__InvalidUsername:
- case MUMBLE_PROTO__REJECT__REJECT_TYPE__WrongUserPW:
- case MUMBLE_PROTO__REJECT__REJECT_TYPE__WrongServerPW:
- case MUMBLE_PROTO__REJECT__REJECT_TYPE__UsernameInUse:
- case MUMBLE_PROTO__REJECT__REJECT_TYPE__ServerFull:
- case MUMBLE_PROTO__REJECT__REJECT_TYPE__NoCertificate:
+ case MUMBLE_REJECT_TYPE(None):
+ case MUMBLE_REJECT_TYPE(WrongVersion):
+ case MUMBLE_REJECT_TYPE(InvalidUsername):
+ case MUMBLE_REJECT_TYPE(WrongUserPW):
+ case MUMBLE_REJECT_TYPE(WrongServerPW):
+ case MUMBLE_REJECT_TYPE(UsernameInUse):
+ case MUMBLE_REJECT_TYPE(ServerFull):
+ case MUMBLE_REJECT_TYPE(NoCertificate):
g_printerr("Connection rejected: %s\n", reject->reason);
break;
default:
diff --git a/src/message.h b/src/message.h
index 0186192..b34bed7 100644
--- a/src/message.h
+++ b/src/message.h
@@ -10,6 +10,28 @@ enum cmumble_message {
#undef MUMBLE_MSG
};
+#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
+
+
struct cmumble;
void
@@ -18,4 +40,20 @@ cmumble_send_msg(struct cmumble *cm, ProtobufCMessage *msg);
int
cmumble_recv_msg(struct cmumble *cm);
+
+#define MUMBLE_MSG(cname, name) \
+ static inline void \
+ cmumble_init_##name(struct mumble_##name *msg) \
+ { \
+ mumble_proto__##name##__init(&msg->m); \
+ } \
+ \
+ static inline void \
+ cmumble_send_##name(struct cmumble *cm, struct mumble_##name *msg) \
+ { \
+ cmumble_send_msg(cm, &msg->m.base); \
+ }
+MUMBLE_MSGS
+#undef MUMBLE_MSG
+
#endif /* _MESSAGE_H_ */