summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/audio.c54
-rw-r--r--src/audio.h10
-rw-r--r--src/cmumble.c96
-rw-r--r--src/cmumble.h6
-rw-r--r--src/commands.c34
-rw-r--r--src/commands.h6
-rw-r--r--src/connection.c44
-rw-r--r--src/connection.h6
-rw-r--r--src/io.c34
-rw-r--r--src/io.h6
-rw-r--r--src/message.c26
-rw-r--r--src/message.h6
-rw-r--r--src/util.h8
13 files changed, 168 insertions, 168 deletions
diff --git a/src/audio.c b/src/audio.c
index 16ac74d..a83471d 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -7,7 +7,7 @@
#define CHANNELS 1
void
-cmumble_audio_push(struct cmumble_context *ctx, struct cmumble_user *user,
+cmumble_audio_push(struct cmumlbe *cm, struct cmumble_user *user,
const guint8 *data, gsize size)
{
GstBuffer *gstbuf;
@@ -19,7 +19,7 @@ cmumble_audio_push(struct cmumble_context *ctx, struct cmumble_user *user,
static GstFlowReturn
pull_buffer(GstAppSink *sink, gpointer user_data)
{
- struct cmumble_context *ctx = user_data;
+ struct cmumlbe *cm = user_data;
GstBuffer *buf;
uint8_t data[1024];
uint32_t write = 0, pos = 0;
@@ -29,10 +29,10 @@ pull_buffer(GstAppSink *sink, gpointer user_data)
/* FIXME: Make this more generic/disable pulling
* the pipeline completely if not connected?
*/
- if (ctx->con.conn == NULL)
+ if (cm->con.conn == NULL)
return GST_FLOW_OK;
- buf = gst_app_sink_pull_buffer(ctx->audio.sink);
+ buf = gst_app_sink_pull_buffer(cm->audio.sink);
if (++seq <= 2) {
gst_buffer_unref(buf);
@@ -45,7 +45,7 @@ pull_buffer(GstAppSink *sink, gpointer user_data)
data[pos++] = (udp_voice_celt_alpha << 5) | (udp_normal_talking);
- encode_varint(&data[pos], &write, ++ctx->sequence, 1024-pos);
+ encode_varint(&data[pos], &write, ++cm->sequence, 1024-pos);
pos += write;
data[pos++] = 0x00 /*: 0x80 */ | (GST_BUFFER_SIZE(buf) & 0x7F);
@@ -57,13 +57,13 @@ pull_buffer(GstAppSink *sink, gpointer user_data)
mumble_proto__udptunnel__init(&tunnel);
tunnel.packet.data = data;
tunnel.packet.len = pos;
- cmumble_send_msg(ctx, &tunnel.base);
+ cmumble_send_msg(cm, &tunnel.base);
return GST_FLOW_OK;
}
static int
-setup_recording_gst_pipeline(struct cmumble_context *ctx)
+setup_recording_gst_pipeline(struct cmumlbe *cm)
{
GstElement *pipeline, *cutter, *sink;
GError *error = NULL;
@@ -79,28 +79,28 @@ setup_recording_gst_pipeline(struct cmumble_context *ctx)
return -1;
}
sink = gst_bin_get_by_name(GST_BIN(pipeline), "sink");
- ctx->audio.sink = GST_APP_SINK(sink);
- ctx->audio.record_pipeline = pipeline;
+ cm->audio.sink = GST_APP_SINK(sink);
+ cm->audio.record_pipeline = pipeline;
cutter = gst_bin_get_by_name(GST_BIN(pipeline), "cutter");
g_object_set(G_OBJECT(cutter),
"threshold_dB", -45.0, "leaky", TRUE, NULL);
- gst_app_sink_set_emit_signals(ctx->audio.sink, TRUE);
- gst_app_sink_set_drop(ctx->audio.sink, FALSE);;
- g_signal_connect(sink, "new-buffer", G_CALLBACK(pull_buffer), ctx);
+ gst_app_sink_set_emit_signals(cm->audio.sink, TRUE);
+ gst_app_sink_set_drop(cm->audio.sink, FALSE);;
+ g_signal_connect(sink, "new-buffer", G_CALLBACK(pull_buffer), cm);
caps = gst_caps_new_simple("audio/x-celt",
"rate", G_TYPE_INT, SAMPLERATE,
"channels", G_TYPE_INT, 1,
"frame-size", G_TYPE_INT, SAMPLERATE/100,
NULL);
- gst_app_sink_set_caps(ctx->audio.sink, caps);
+ gst_app_sink_set_caps(cm->audio.sink, caps);
gst_caps_unref(caps);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
- ctx->sequence = 0;
+ cm->sequence = 0;
return 0;
}
@@ -140,7 +140,7 @@ out:
}
int
-cmumble_audio_create_playback_pipeline(struct cmumble_context *ctx,
+cmumble_audio_create_playback_pipeline(struct cmumlbe *cm,
struct cmumble_user *user)
{
GstElement *pipeline, *sink_bin;
@@ -171,40 +171,40 @@ cmumble_audio_create_playback_pipeline(struct cmumble_context *ctx,
gst_iterator_free(iter);
/* Setup Celt Decoder */
- cmumble_audio_push(ctx, user,
- ctx->audio.celt_header_packet, sizeof(CELTHeader));
+ cmumble_audio_push(cm, user,
+ cm->audio.celt_header_packet, sizeof(CELTHeader));
/* fake vorbiscomment buffer */
- cmumble_audio_push(ctx, user, NULL, 0);
+ cmumble_audio_push(cm, user, NULL, 0);
return 0;
}
static int
-setup_playback_gst_pipeline(struct cmumble_context *ctx)
+setup_playback_gst_pipeline(struct cmumlbe *cm)
{
- ctx->audio.celt_mode = celt_mode_create(SAMPLERATE,
+ cm->audio.celt_mode = celt_mode_create(SAMPLERATE,
SAMPLERATE / 100, NULL);
- celt_header_init(&ctx->audio.celt_header, ctx->audio.celt_mode, CHANNELS);
- celt_header_to_packet(&ctx->audio.celt_header,
- ctx->audio.celt_header_packet, sizeof(CELTHeader));
+ celt_header_init(&cm->audio.celt_header, cm->audio.celt_mode, CHANNELS);
+ celt_header_to_packet(&cm->audio.celt_header,
+ cm->audio.celt_header_packet, sizeof(CELTHeader));
return 0;
}
int
-cmumble_audio_init(struct cmumble_context *ctx)
+cmumble_audio_init(struct cmumlbe *cm)
{
- if (setup_playback_gst_pipeline(ctx) < 0)
+ if (setup_playback_gst_pipeline(cm) < 0)
return -1;
- if (setup_recording_gst_pipeline(ctx) < 0)
+ if (setup_recording_gst_pipeline(cm) < 0)
return -1;
return 0;
}
int
-cmumble_audio_fini(struct cmumble_context *ctx)
+cmumble_audio_fini(struct cmumlbe *cm)
{
return 0;
diff --git a/src/audio.h b/src/audio.h
index 5731257..6cae07f 100644
--- a/src/audio.h
+++ b/src/audio.h
@@ -20,21 +20,21 @@ struct cmumble_audio {
CELTMode *celt_mode;
};
-struct cmumble_context;
+struct cmumlbe;
struct cmumble_user;
int
-cmumble_audio_init(struct cmumble_context *ctx);
+cmumble_audio_init(struct cmumlbe *cm);
int
-cmumble_audio_fini(struct cmumble_context *ctx);
+cmumble_audio_fini(struct cmumlbe *cm);
int
-cmumble_audio_create_playback_pipeline(struct cmumble_context *ctx,
+cmumble_audio_create_playback_pipeline(struct cmumlbe *cm,
struct cmumble_user *user);
void
-cmumble_audio_push(struct cmumble_context *ctx, struct cmumble_user *user,
+cmumble_audio_push(struct cmumlbe *cm, struct cmumble_user *user,
const guint8 *data, gsize size);
#endif /* _AUDIO_H_ */
diff --git a/src/cmumble.c b/src/cmumble.c
index fd444c6..e76920e 100644
--- a/src/cmumble.c
+++ b/src/cmumble.c
@@ -9,7 +9,7 @@
#include "util.h"
static void
-recv_udp_tunnel(MumbleProto__UDPTunnel *tunnel, struct cmumble_context *ctx)
+recv_udp_tunnel(MumbleProto__UDPTunnel *tunnel, struct cmumlbe *cm)
{
int64_t session, sequence;
uint32_t pos = 1, read = 0;
@@ -23,7 +23,7 @@ recv_udp_tunnel(MumbleProto__UDPTunnel *tunnel, struct cmumble_context *ctx)
sequence = decode_varint(&data[pos], &read, len-pos);
pos += read;
- user = find_user(ctx, session);
+ user = find_user(cm, session);
if (user == NULL) {
g_printerr("received audio packet from unknown user, "
"dropping.\n");
@@ -38,7 +38,7 @@ recv_udp_tunnel(MumbleProto__UDPTunnel *tunnel, struct cmumble_context *ctx)
if (frame_len == 0 || frame_len > len-pos)
break;
- cmumble_audio_push(ctx, user, &data[pos], frame_len);
+ cmumble_audio_push(cm, user, &data[pos], frame_len);
pos += frame_len;
sequence++;
@@ -46,7 +46,7 @@ recv_udp_tunnel(MumbleProto__UDPTunnel *tunnel, struct cmumble_context *ctx)
}
static void
-recv_version(MumbleProto__Version *version, struct cmumble_context *ctx)
+recv_version(MumbleProto__Version *version, struct cmumlbe *cm)
{
g_print("version: 0x%x\n", version->version);
g_print("release: %s\n", version->release);
@@ -54,18 +54,18 @@ recv_version(MumbleProto__Version *version, struct cmumble_context *ctx)
static void
recv_channel_state(MumbleProto__ChannelState *state,
- struct cmumble_context *ctx)
+ struct cmumlbe *cm)
{
struct cmumble_channel *channel;
- channel = find_channel(ctx, state->channel_id);
+ channel = find_channel(cm, state->channel_id);
if (channel == NULL) {
channel = g_slice_new0(struct cmumble_channel);
if (channel == NULL) {
g_printerr("Out of memory.\n");
exit(1);
}
- ctx->channels = g_list_prepend(ctx->channels, channel);
+ cm->channels = g_list_prepend(cm->channels, channel);
if (channel->name)
g_free(channel->name);
@@ -85,18 +85,18 @@ recv_channel_state(MumbleProto__ChannelState *state,
}
static void
-recv_server_sync(MumbleProto__ServerSync *sync, struct cmumble_context *ctx)
+recv_server_sync(MumbleProto__ServerSync *sync, struct cmumlbe *cm)
{
- ctx->session = sync->session;
- ctx->user = find_user(ctx, ctx->session);
+ cm->session = sync->session;
+ cm->user = find_user(cm, cm->session);
if (sync->welcome_text)
g_print("Welcome Message: %s\n", sync->welcome_text);
- g_print("got session: %d\n", ctx->session);
+ g_print("got session: %d\n", cm->session);
}
static void
-recv_crypt_setup(MumbleProto__CryptSetup *crypt, struct cmumble_context *ctx)
+recv_crypt_setup(MumbleProto__CryptSetup *crypt, struct cmumlbe *cm)
{
#if 0
int i;
@@ -124,20 +124,20 @@ recv_crypt_setup(MumbleProto__CryptSetup *crypt, struct cmumble_context *ctx)
static void
recv_codec_version(MumbleProto__CodecVersion *codec,
- struct cmumble_context *ctx)
+ struct cmumlbe *cm)
{
g_print("Codec Version: alpha: %d, beta: %d, pefer_alpha: %d\n",
codec->alpha, codec->beta, codec->prefer_alpha);
}
static void
-recv_user_remove(MumbleProto__UserRemove *remove, struct cmumble_context *ctx)
+recv_user_remove(MumbleProto__UserRemove *remove, struct cmumlbe *cm)
{
struct cmumble_user *user = NULL;
- user = find_user(ctx, remove->session);
+ user = find_user(cm, remove->session);
if (user) {
- ctx->users = g_list_remove(ctx->users, user);
+ cm->users = g_list_remove(cm->users, user);
g_free(user->name);
/* FIXME: destroy playback pipeline */
g_slice_free(struct cmumble_user, user);
@@ -145,11 +145,11 @@ recv_user_remove(MumbleProto__UserRemove *remove, struct cmumble_context *ctx)
}
static void
-recv_user_state(MumbleProto__UserState *state, struct cmumble_context *ctx)
+recv_user_state(MumbleProto__UserState *state, struct cmumlbe *cm)
{
struct cmumble_user *user = NULL;
- user = find_user(ctx, state->session);
+ user = find_user(cm, state->session);
if (user) {
/* update */
return;
@@ -164,29 +164,29 @@ recv_user_state(MumbleProto__UserState *state, struct cmumble_context *ctx)
user->session = state->session;
user->name = g_strdup(state->name);
user->id = state->user_id;
- user->channel = find_channel(ctx, state->channel_id);
+ user->channel = find_channel(cm, state->channel_id);
- if (ctx->session == user->session)
- ctx->user = user;
+ if (cm->session == user->session)
+ cm->user = user;
- cmumble_audio_create_playback_pipeline(ctx, user);
+ cmumble_audio_create_playback_pipeline(cm, user);
g_print("receive user: %s\n", user->name);
- ctx->users = g_list_prepend(ctx->users, user);
+ cm->users = g_list_prepend(cm->users, user);
}
static void
-recv_text_message(MumbleProto__TextMessage *text, struct cmumble_context *ctx)
+recv_text_message(MumbleProto__TextMessage *text, struct cmumlbe *cm)
{
struct cmumble_user *user;
- user = find_user(ctx, text->actor);
+ user = find_user(cm, text->actor);
if (user != NULL)
g_print("%s> %s\n", user->name, text->message);
}
static const struct {
#define MUMBLE_MSG(a,b) void (* a)(MumbleProto__##a *, \
- struct cmumble_context *);
+ struct cmumlbe *);
MUMBLE_MSGS
#undef MUMBLE_MSG
} callbacks = {
@@ -219,7 +219,7 @@ static const struct {
};
static gboolean
-do_ping(struct cmumble_context *ctx)
+do_ping(struct cmumlbe *cm)
{
MumbleProto__Ping ping;
GTimeVal tv;
@@ -228,13 +228,13 @@ do_ping(struct cmumble_context *ctx)
mumble_proto__ping__init(&ping);
ping.timestamp = tv.tv_sec;
ping.resync = 1;
- cmumble_send_msg(ctx, &ping.base);
+ cmumble_send_msg(cm, &ping.base);
return TRUE;
}
void
-cmumble_protocol_init(struct cmumble_context *ctx)
+cmumble_protocol_init(struct cmumlbe *cm)
{
MumbleProto__Version version;
MumbleProto__Authenticate authenticate;
@@ -244,17 +244,17 @@ cmumble_protocol_init(struct cmumble_context *ctx)
version.version = 0x010203;
version.release = PACKAGE_STRING;
version.os = "Gentoo/Linux";
- cmumble_send_msg(ctx, &version.base);
+ cmumble_send_msg(cm, &version.base);
mumble_proto__authenticate__init(&authenticate);
- authenticate.username = ctx->user_name;
+ authenticate.username = cm->user_name;
authenticate.password = "";
authenticate.n_celt_versions = 1;
authenticate.celt_versions = (int32_t[]) { 0x8000000b };
- cmumble_send_msg(ctx, &authenticate.base);
+ cmumble_send_msg(cm, &authenticate.base);
source = g_timeout_source_new_seconds(5);
- g_source_set_callback(source, (GSourceFunc) do_ping, ctx, NULL);
+ g_source_set_callback(source, (GSourceFunc) do_ping, cm, NULL);
g_source_attach(source, NULL);
g_source_unref(source);
}
@@ -281,7 +281,7 @@ static GOptionEntry entries[] = {
int main(int argc, char **argv)
{
- struct cmumble_context ctx;
+ struct cmumlbe cm;
GError *error = NULL;
GOptionContext *context;
@@ -294,32 +294,32 @@ int main(int argc, char **argv)
exit(1);
}
- memset(&ctx, 0, sizeof(ctx));
+ memset(&cm, 0, sizeof(cm));
- ctx.user_name = user;
- ctx.users = NULL;
+ cm.user_name = user;
+ cm.users = NULL;
g_type_init();
- ctx.loop = g_main_loop_new(NULL, FALSE);
- ctx.callbacks = (const callback_t *) &callbacks;
+ cm.loop = g_main_loop_new(NULL, FALSE);
+ cm.callbacks = (const callback_t *) &callbacks;
- cmumble_commands_init(&ctx);
- if (cmumble_connection_init(&ctx, host, port) < 0)
+ cmumble_commands_init(&cm);
+ if (cmumble_connection_init(&cm, host, port) < 0)
return 1;
gst_init(&argc, &argv);
- if (cmumble_audio_init(&ctx) < 0)
+ if (cmumble_audio_init(&cm) < 0)
return 1;
- cmumble_io_init(&ctx);
+ cmumble_io_init(&cm);
- g_main_loop_run(ctx.loop);
+ g_main_loop_run(cm.loop);
- g_main_loop_unref(ctx.loop);
+ g_main_loop_unref(cm.loop);
- cmumble_io_fini(&ctx);
- cmumble_audio_init(&ctx);
- cmumble_connection_fini(&ctx);
+ cmumble_io_fini(&cm);
+ cmumble_audio_init(&cm);
+ cmumble_connection_fini(&cm);
return 0;
}
diff --git a/src/cmumble.h b/src/cmumble.h
index cc29ef4..cc40149 100644
--- a/src/cmumble.h
+++ b/src/cmumble.h
@@ -12,9 +12,9 @@
#include "audio.h"
#include "commands.h"
-typedef void (*callback_t)(ProtobufCMessage *msg, struct cmumble_context *);
+typedef void (*callback_t)(ProtobufCMessage *msg, struct cmumlbe *);
-struct cmumble_context {
+struct cmumlbe {
struct cmumble_connection con;
struct cmumble_io io;
struct cmumble_audio audio;
@@ -72,6 +72,6 @@ enum udp_message_target {
};
void
-cmumble_protocol_init(struct cmumble_context *ctx);
+cmumble_protocol_init(struct cmumlbe *cm);
#endif
diff --git a/src/commands.c b/src/commands.c
index fa2fa23..9ca2d8a 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -9,13 +9,13 @@
#include <readline/history.h>
static void
-list_users(struct cmumble_context *ctx,
+list_users(struct cmumlbe *cm,
int argc, char **argv)
{
struct cmumble_user *user = NULL;
GList *l;
- for (l = ctx->users; l; l = l->next) {
+ for (l = cm->users; l; l = l->next) {
user = l->data;
g_print("%4d: %s\n", user->session, user->name);
@@ -23,13 +23,13 @@ list_users(struct cmumble_context *ctx,
}
static void
-list_channels(struct cmumble_context *ctx,
+list_channels(struct cmumlbe *cm,
int argc, char **argv)
{
struct cmumble_channel *channel = NULL;
GList *l;
- for (l = ctx->channels; l; l = l->next) {
+ for (l = cm->channels; l; l = l->next) {
channel = l->data;
g_print("%4d: %s\n", channel->id, channel->name);
@@ -37,15 +37,15 @@ list_channels(struct cmumble_context *ctx,
}
static void
-quit(struct cmumble_context *ctx,
+quit(struct cmumlbe *cm,
int argc, char **argv)
{
rl_already_prompted = 1;
- g_main_loop_quit(ctx->loop);
+ g_main_loop_quit(cm->loop);
}
static void
-clear(struct cmumble_context *ctx,
+clear(struct cmumlbe *cm,
int argc, char **argv)
{
rl_clear_screen(0,0);
@@ -54,24 +54,24 @@ clear(struct cmumble_context *ctx,
}
static void
-help(struct cmumble_context *ctx,
+help(struct cmumlbe *cm,
int argc, char **argv)
{
int i;
- for (i = 0; ctx->commands[i].name; ++i)
+ for (i = 0; cm->commands[i].name; ++i)
g_print("%s\t%s\n",
- ctx->commands[i].name, ctx->commands[i].description);
+ cm->commands[i].name, cm->commands[i].description);
}
static void
-msg(struct cmumble_context *ctx,
+msg(struct cmumlbe *cm,
int argc, char **argv)
{
MumbleProto__TextMessage message;
mumble_proto__text_message__init(&message);
- message.actor = ctx->session;
+ message.actor = cm->session;
if (argc < 2) {
g_print("usage: msg message\n");
@@ -81,17 +81,17 @@ msg(struct cmumble_context *ctx,
message.message = argv[argc-1];
/* FIXME: cache this in general somehow? */
- if (!ctx->user || !ctx->user->channel) {
+ if (!cm->user || !cm->user->channel) {
g_printerr("No information about current CHannel available\n");
return;
}
message.n_channel_id = 1;
- message.channel_id = (uint32_t[]) { ctx->user->channel->id };
+ message.channel_id = (uint32_t[]) { cm->user->channel->id };
message.n_session = 0;
message.n_tree_id = 0;
- cmumble_send_msg(ctx, &message.base);
+ cmumble_send_msg(cm, &message.base);
}
static const struct cmumble_command commands[] = {
@@ -143,9 +143,9 @@ complete(const char *in, int n)
}
void
-cmumble_commands_init(struct cmumble_context *ctx)
+cmumble_commands_init(struct cmumlbe *cm)
{
- ctx->commands = commands;
+ cm->commands = commands;
rl_completion_entry_function = complete;
}
diff --git a/src/commands.h b/src/commands.h
index a2cca59..24290af 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -1,17 +1,17 @@
#ifndef _COMMANDS_H_
#define _COMMANDS_H_
-struct cmumble_context;
+struct cmumlbe;
struct cmumble_command {
const char *name;
- void (*callback)(struct cmumble_context *,
+ void (*callback)(struct cmumlbe *,
int argc, char **argv);
const char *description;
};
void
-cmumble_commands_init(struct cmumble_context *ctx);
+cmumble_commands_init(struct cmumlbe *cm);
const char *
cmumble_command_expand_shortcut(const char *text);
diff --git a/src/connection.c b/src/connection.c
index 73cd973..7fefdb3 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -8,11 +8,11 @@ static gboolean
read_cb(GObject *pollable_stream, gpointer data)
{
GPollableInputStream *input = G_POLLABLE_INPUT_STREAM(pollable_stream);
- struct cmumble_context *ctx = data;
+ struct cmumlbe *cm = data;
gint count;
do {
- count = cmumble_recv_msg(ctx);
+ count = cmumble_recv_msg(cm);
} while (count && g_pollable_input_stream_is_readable(input));
return TRUE;
@@ -21,15 +21,15 @@ read_cb(GObject *pollable_stream, gpointer data)
static void
connection_ready(GObject *source_object, GAsyncResult *res, gpointer user_data)
{
- struct cmumble_context *ctx = user_data;
- struct cmumble_connection *con = &ctx->con;
+ struct cmumlbe *cm = user_data;
+ struct cmumble_connection *con = &cm->con;
GError *error = NULL;
con->conn = g_socket_client_connect_to_host_finish (con->sock_client,
res, &error);
if (error) {
g_printerr("connect failed: %s\n", error->message);
- g_main_loop_quit(ctx->loop);
+ g_main_loop_quit(cm->loop);
g_error_free(error);
return;
}
@@ -41,23 +41,23 @@ connection_ready(GObject *source_object, GAsyncResult *res, gpointer user_data)
if (!G_IS_POLLABLE_INPUT_STREAM(con->input) ||
!g_pollable_input_stream_can_poll(con->input)) {
g_printerr("Error: GSocketConnection is not pollable\n");
- g_main_loop_quit(ctx->loop);
+ g_main_loop_quit(cm->loop);
return;
}
con->source = g_pollable_input_stream_create_source(con->input, NULL);
- g_source_set_callback(con->source, (GSourceFunc) read_cb, ctx, NULL);
+ g_source_set_callback(con->source, (GSourceFunc) read_cb, cm, NULL);
g_source_attach(con->source, NULL);
g_source_unref(con->source);
- cmumble_protocol_init(ctx);
+ cmumble_protocol_init(cm);
}
int
-cmumble_connection_init(struct cmumble_context *ctx,
+cmumble_connection_init(struct cmumlbe *cm,
const char *host, int port)
{
- struct cmumble_connection *con = &ctx->con;
+ struct cmumble_connection *con = &cm->con;
con->sock_client = g_socket_client_new();
g_socket_client_set_tls(con->sock_client, TRUE);
@@ -71,27 +71,27 @@ cmumble_connection_init(struct cmumble_context *ctx,
g_socket_client_connect_to_host_async(con->sock_client,
host, port, NULL,
- connection_ready, ctx);
+ connection_ready, cm);
return 0;
}
int
-cmumble_connection_fini(struct cmumble_context *ctx)
+cmumble_connection_fini(struct cmumlbe *cm)
{
- if (ctx->con.source) {
- g_source_remove(g_source_get_id(ctx->con.source));
- g_source_unref(ctx->con.source);
+ if (cm->con.source) {
+ g_source_remove(g_source_get_id(cm->con.source));
+ g_source_unref(cm->con.source);
}
- if (ctx->con.conn) {
- g_object_unref(G_OBJECT(ctx->con.input));
- g_object_unref(G_OBJECT(ctx->con.output));
- g_io_stream_close(G_IO_STREAM(ctx->con.conn), NULL, NULL);
- g_object_unref(G_OBJECT(ctx->con.conn));
+ if (cm->con.conn) {
+ g_object_unref(G_OBJECT(cm->con.input));
+ g_object_unref(G_OBJECT(cm->con.output));
+ g_io_stream_close(G_IO_STREAM(cm->con.conn), NULL, NULL);
+ g_object_unref(G_OBJECT(cm->con.conn));
}
- if (ctx->con.sock_client)
- g_object_unref(G_OBJECT(ctx->con.sock_client));
+ if (cm->con.sock_client)
+ g_object_unref(G_OBJECT(cm->con.sock_client));
return 0;
}
diff --git a/src/connection.h b/src/connection.h
index f37c0c7..508a71c 100644
--- a/src/connection.h
+++ b/src/connection.h
@@ -14,13 +14,13 @@ struct cmumble_connection {
GSource *source;
};
-struct cmumble_context;
+struct cmumlbe;
int
-cmumble_connection_init(struct cmumble_context *ctx,
+cmumble_connection_init(struct cmumlbe *cm,
const char *host, int port);
int
-cmumble_connection_fini(struct cmumble_context *ctx);
+cmumble_connection_fini(struct cmumlbe *cm);
#endif /* _CONNECTION_H_ */
diff --git a/src/io.c b/src/io.c
index 473ce30..e0d608a 100644
--- a/src/io.c
+++ b/src/io.c
@@ -22,10 +22,10 @@ static gpointer global_rl_user_data = NULL;
static gboolean
read_cb(GIOChannel *source, GIOCondition condition, gpointer data)
{
- struct cmumble_context *ctx = data;
+ struct cmumlbe *cm = data;
if (condition & G_IO_IN) {
- global_rl_user_data = ctx;
+ global_rl_user_data = cm;
rl_callback_read_char();
global_rl_user_data = NULL;
}
@@ -144,7 +144,7 @@ command_split(char *cmd, char ***argv)
static void
process_line(char *line)
{
- struct cmumble_context *ctx = global_rl_user_data;
+ struct cmumlbe *cm = global_rl_user_data;
int i;
int argc;
char **argv;
@@ -158,7 +158,7 @@ process_line(char *line)
printf("quit");
rl_already_prompted = 1;
rl_crlf();
- g_main_loop_quit(ctx->loop);
+ g_main_loop_quit(cm->loop);
return;
}
line = g_strdup(line);
@@ -171,36 +171,36 @@ process_line(char *line)
goto out;
cmd = cmumble_command_expand_shortcut(argv[0]);
- for (i = 0; ctx->commands[i].name; ++i) {
- if (strlen(cmd) == strlen(ctx->commands[i].name) &&
- strcmp(cmd, ctx->commands[i].name) == 0) {
- ctx->commands[i].callback(ctx, argc, argv);
+ for (i = 0; cm->commands[i].name; ++i) {
+ if (strlen(cmd) == strlen(cm->commands[i].name) &&
+ strcmp(cmd, cm->commands[i].name) == 0) {
+ cm->commands[i].callback(cm, argc, argv);
break;
}
}
- if (ctx->commands[i].name == NULL)
+ if (cm->commands[i].name == NULL)
g_print("Unknown command: %s\n", line);
out:
free(line);
}
int
-cmumble_io_init(struct cmumble_context *ctx)
+cmumble_io_init(struct cmumlbe *cm)
{
struct termios term;
- ctx->io.input_channel = g_io_channel_unix_new(STDIN_FILENO);
+ cm->io.input_channel = g_io_channel_unix_new(STDIN_FILENO);
- g_io_add_watch(ctx->io.input_channel, G_IO_IN | G_IO_HUP,
- read_cb, ctx);
+ g_io_add_watch(cm->io.input_channel, G_IO_IN | G_IO_HUP,
+ read_cb, cm);
if (tcgetattr(STDIN_FILENO, &term) < 0) {
g_printerr("tcgetattr failed");
return -1;
}
- ctx->io.term = term;
+ cm->io.term = term;
term.c_lflag &= ~ICANON;
term.c_cc[VTIME] = 1;
@@ -217,12 +217,12 @@ cmumble_io_init(struct cmumble_context *ctx)
}
int
-cmumble_io_fini(struct cmumble_context *ctx)
+cmumble_io_fini(struct cmumlbe *cm)
{
rl_callback_handler_remove();
- g_io_channel_unref(ctx->io.input_channel);
+ g_io_channel_unref(cm->io.input_channel);
- if (tcsetattr(STDIN_FILENO, TCSANOW, &ctx->io.term) < 0) {
+ if (tcsetattr(STDIN_FILENO, TCSANOW, &cm->io.term) < 0) {
g_printerr("tcsetattr failed");
return -1;
}
diff --git a/src/io.h b/src/io.h
index c774b6a..7fbf1bb 100644
--- a/src/io.h
+++ b/src/io.h
@@ -10,12 +10,12 @@ struct cmumble_io {
struct termios term;
};
-struct cmumble_context;
+struct cmumlbe;
int
-cmumble_io_init(struct cmumble_context *ctx);
+cmumble_io_init(struct cmumlbe *cm);
int
-cmumble_io_fini(struct cmumble_context *ctx);
+cmumble_io_fini(struct cmumlbe *cm);
#endif /* _IO_H_ */
diff --git a/src/message.c b/src/message.c
index a7da5da..d4d42c0 100644
--- a/src/message.c
+++ b/src/message.c
@@ -39,7 +39,7 @@ get_preamble(uint8_t *buffer, int *type, int *len)
}
void
-cmumble_send_msg(struct cmumble_context *ctx, ProtobufCMessage *msg)
+cmumble_send_msg(struct cmumlbe *cm, ProtobufCMessage *msg)
{
uint8_t pad[128];
uint8_t preamble[PREAMBLE_SIZE];
@@ -64,15 +64,15 @@ cmumble_send_msg(struct cmumble_context *ctx, ProtobufCMessage *msg)
add_preamble(preamble, type, buffer.len);
g_static_mutex_lock(&write_mutex);
- g_output_stream_write(ctx->con.output, preamble, PREAMBLE_SIZE, NULL, NULL);
- g_output_stream_write(ctx->con.output, buffer.data, buffer.len, NULL, NULL);
+ g_output_stream_write(cm->con.output, preamble, PREAMBLE_SIZE, NULL, NULL);
+ g_output_stream_write(cm->con.output, buffer.data, buffer.len, NULL, NULL);
g_static_mutex_unlock(&write_mutex);
PROTOBUF_C_BUFFER_SIMPLE_CLEAR(&buffer);
}
int
-cmumble_recv_msg(struct cmumble_context *ctx)
+cmumble_recv_msg(struct cmumlbe *cm)
{
uint8_t preamble[PREAMBLE_SIZE];
ProtobufCMessage *msg;
@@ -81,9 +81,9 @@ cmumble_recv_msg(struct cmumble_context *ctx)
gssize ret;
GError *error = NULL;
- g_assert(ctx->callbacks);
+ g_assert(cm->callbacks);
- ret = g_pollable_input_stream_read_nonblocking(ctx->con.input,
+ ret = g_pollable_input_stream_read_nonblocking(cm->con.input,
preamble, PREAMBLE_SIZE,
NULL, &error);
@@ -93,7 +93,7 @@ cmumble_recv_msg(struct cmumble_context *ctx)
if (g_error_matches(error, G_TLS_ERROR, G_TLS_ERROR_EOF)) {
g_print("%s\n", error->message);
- g_main_loop_quit(ctx->loop);
+ g_main_loop_quit(cm->loop);
return 0;
}
@@ -119,9 +119,9 @@ cmumble_recv_msg(struct cmumble_context *ctx)
data = g_malloc(len);
if (data == NULL) {
g_printerr("out of mem\n");
- g_main_loop_quit (ctx->loop);
+ g_main_loop_quit (cm->loop);
}
- ret = g_input_stream_read(G_INPUT_STREAM(ctx->con.input),
+ ret = g_input_stream_read(G_INPUT_STREAM(cm->con.input),
data, len, NULL, NULL);
/* tunneled udp data - not a regular protobuf message
@@ -133,8 +133,8 @@ cmumble_recv_msg(struct cmumble_context *ctx)
udptunnel.packet.len = len;
udptunnel.packet.data = (uint8_t *) data;
- if (ctx->callbacks[UDPTunnel])
- ctx->callbacks[UDPTunnel](&udptunnel.base, ctx);
+ if (cm->callbacks[UDPTunnel])
+ cm->callbacks[UDPTunnel](&udptunnel.base, cm);
g_free(data);
return 0;
@@ -148,8 +148,8 @@ cmumble_recv_msg(struct cmumble_context *ctx)
}
g_print("debug: received message: %s type:%d, len:%d\n", messages[type].name, type, len);
- if (ctx->callbacks[type])
- ctx->callbacks[type](msg, ctx);
+ if (cm->callbacks[type])
+ cm->callbacks[type](msg, cm);
protobuf_c_message_free_unpacked(msg, NULL);
g_free(data);
diff --git a/src/message.h b/src/message.h
index d70743b..7f3ffe4 100644
--- a/src/message.h
+++ b/src/message.h
@@ -10,12 +10,12 @@ enum cmumble_message {
#undef MUMBLE_MSG
};
-struct cmumble_context;
+struct cmumlbe;
void
-cmumble_send_msg(struct cmumble_context *ctx, ProtobufCMessage *msg);
+cmumble_send_msg(struct cmumlbe *cm, ProtobufCMessage *msg);
int
-cmumble_recv_msg(struct cmumble_context *ctx);
+cmumble_recv_msg(struct cmumlbe *cm);
#endif /* _MESSAGE_H_ */
diff --git a/src/util.h b/src/util.h
index dc27dd0..ec180be 100644
--- a/src/util.h
+++ b/src/util.h
@@ -8,17 +8,17 @@ gpointer
cmumble_find_by_id(GList *list, gsize member_offset, guint id);
static inline struct cmumble_user *
-find_user(struct cmumble_context *ctx, uint32_t session_id)
+find_user(struct cmumlbe *cm, uint32_t session_id)
{
- return cmumble_find_by_id(ctx->users,
+ return cmumble_find_by_id(cm->users,
G_STRUCT_OFFSET(struct cmumble_user, session),
session_id);
}
static inline struct cmumble_channel *
-find_channel(struct cmumble_context *ctx, guint channel_id)
+find_channel(struct cmumlbe *cm, guint channel_id)
{
- return cmumble_find_by_id(ctx->channels,
+ return cmumble_find_by_id(cm->channels,
G_STRUCT_OFFSET(struct cmumble_channel, id),
channel_id);
}