comparison contrib/splicex/tools/im-steal/im-steal.c @ 697:a554ba2c1e81 draft

SpliceX now compiles to true binary
author d3v11 <d3v11@d3v11.ano>
date Fri, 28 Oct 2011 19:08:24 -0400
parents
children
comparison
equal deleted inserted replaced
695:24a6ba1d8657 697:a554ba2c1e81
1 /*
2 * Modified libpurple nullclient.c from http://pidgin.sourcearchive.com.
3 * This libpurple program serves no other purpose other than testing
4 * for a successfull login.
5 */
6
7 #include "purple.h"
8 #include <glib.h>
9 #include <signal.h>
10 #include <string.h>
11 #include <unistd.h>
12 #include <stdio.h>
13 #define CUSTOM_USER_DIRECTORY "/dev/null"
14 #define CUSTOM_PLUGIN_PATH ""
15 #define PLUGIN_SAVE_PREF "/purple/user/plugins/saved"
16 #define UI_ID "user"
17 #define PURPLE_GLIB_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR)
18 #define PURPLE_GLIB_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
19
20 typedef struct _PurpleGLibIOClosure {
21 PurpleInputFunction function;
22 guint result;
23 gpointer data;
24 } PurpleGLibIOClosure;
25
26
27 static void purple_glib_io_destroy(gpointer data)
28 {
29 g_free(data);
30 }
31
32 static gboolean purple_glib_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data)
33 {
34 PurpleGLibIOClosure *closure = data;
35 PurpleInputCondition purple_cond = 0;
36
37 if (condition & PURPLE_GLIB_READ_COND)
38 purple_cond |= PURPLE_INPUT_READ;
39 if (condition & PURPLE_GLIB_WRITE_COND)
40 purple_cond |= PURPLE_INPUT_WRITE;
41
42 closure->function(closure->data, g_io_channel_unix_get_fd(source),
43 purple_cond);
44
45 return TRUE;
46 }
47
48 static guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function,
49 gpointer data)
50 {
51 PurpleGLibIOClosure *closure = g_new0(PurpleGLibIOClosure, 1);
52 GIOChannel *channel;
53 GIOCondition cond = 0;
54
55 closure->function = function;
56 closure->data = data;
57
58 if (condition & PURPLE_INPUT_READ)
59 cond |= PURPLE_GLIB_READ_COND;
60 if (condition & PURPLE_INPUT_WRITE)
61 cond |= PURPLE_GLIB_WRITE_COND;
62
63 channel = g_io_channel_unix_new(fd);
64 closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond,
65 purple_glib_io_invoke, closure, purple_glib_io_destroy);
66
67 g_io_channel_unref(channel);
68 return closure->result;
69 }
70
71 static PurpleEventLoopUiOps glib_eventloops =
72 {
73 g_timeout_add,
74 g_source_remove,
75 glib_input_add,
76 g_source_remove,
77 NULL,
78 #if GLIB_CHECK_VERSION(2,14,0)
79 g_timeout_add_seconds,
80 #else
81 NULL,
82 #endif
83 NULL,
84 NULL,
85 NULL
86 };
87
88 static void network_disconnected(void)
89 {
90 printf("This machine has been disconnected from the internet\n");
91 }
92
93 static void report_disconnect_reason(PurpleConnection *gc, PurpleConnectionError reason, const char *text)
94 {
95 PurpleAccount *account = purple_connection_get_account(gc);
96 printf("Connection disconnected: \"%s\" (%s)\n >Error: %d\n >Reason: %s\n", purple_account_get_username(account), purple_account_get_protocol_id(account), reason, text);
97 abort();
98 }
99
100 static PurpleConnectionUiOps connection_uiops =
101 {
102 NULL, /* connect_progress */
103 NULL, /* connected */
104 NULL, /* disconnected */
105 NULL, /* notice */
106 NULL, /* report_disconnect */
107 NULL, /* network_connected */
108 network_disconnected, /* network_disconnected */
109 report_disconnect_reason, /* report_disconnect_reason */
110 NULL,
111 NULL,
112 NULL
113 };
114
115 static void ui_init(void)
116 {
117 purple_connections_set_ui_ops(&connection_uiops);
118 }
119
120 static PurpleCoreUiOps core_uiops =
121 {
122 NULL,
123 NULL,
124 ui_init,
125 NULL,
126
127 /* padding */
128 NULL,
129 NULL,
130 NULL,
131 NULL
132 };
133
134 static void init_libpurple(void)
135 {
136 purple_debug_set_enabled(FALSE);
137 purple_core_set_ui_ops(&core_uiops);
138 purple_eventloop_set_ui_ops(&glib_eventloops);
139
140 if (!purple_core_init(UI_ID)) {
141 fprintf(stderr,
142 "libpurple initialization failed. Dumping core.\n"
143 "Please report this!\n");
144 abort();
145 }
146 purple_set_blist(purple_blist_new()); // "Unnecessary" code left here to prevent output spam.
147 }
148
149 static void signed_on(PurpleConnection *gc)
150 {
151 printf("Account Connected\n");
152 abort();
153 }
154
155 static void connect_to_signals(void)
156 {
157 static int handle;
158 purple_signal_connect(purple_connections_get_handle(), "signed-on", &handle,
159 PURPLE_CALLBACK(signed_on), NULL);
160 }
161
162 int main(int argc, char *argv[])
163 {
164 GMainLoop *loop = g_main_loop_new(NULL, FALSE);
165 signal(SIGCHLD, SIG_IGN);
166 init_libpurple();
167 connect_to_signals();
168 PurpleAccount *account = purple_account_new(argv[2], argv[1]);
169 purple_account_set_password(account, argv[3]);
170 purple_accounts_add(account);
171 purple_account_set_enabled(account, UI_ID, TRUE);
172 g_main_loop_run(loop);
173 return 0;
174 }