libpurple/example/nullclient.c

branch
soc.2008.masterpassword
changeset 34023
6bc30809f7fe
parent 33992
a4299c59c1b0
parent 32623
547eacef0b63
child 34028
a3050b6df38e
equal deleted inserted replaced
34022:c49f6e9ea27d 34023:6bc30809f7fe
25 25
26 #include <glib.h> 26 #include <glib.h>
27 27
28 #include <signal.h> 28 #include <signal.h>
29 #include <string.h> 29 #include <string.h>
30 #ifndef _WIN32
30 #include <unistd.h> 31 #include <unistd.h>
32 #else
33 #include "win32/win32dep.h"
34 #endif
31 35
32 #include "defines.h" 36 #include "defines.h"
33 37
34 /** 38 /**
35 * The following eventloop functions are used in both pidgin and purple-text. If your 39 * The following eventloop functions are used in both pidgin and purple-text. If your
78 if (condition & PURPLE_INPUT_READ) 82 if (condition & PURPLE_INPUT_READ)
79 cond |= PURPLE_GLIB_READ_COND; 83 cond |= PURPLE_GLIB_READ_COND;
80 if (condition & PURPLE_INPUT_WRITE) 84 if (condition & PURPLE_INPUT_WRITE)
81 cond |= PURPLE_GLIB_WRITE_COND; 85 cond |= PURPLE_GLIB_WRITE_COND;
82 86
87 #if defined _WIN32 && !defined WINPIDGIN_USE_GLIB_IO_CHANNEL
88 channel = wpurple_g_io_channel_win32_new_socket(fd);
89 #else
83 channel = g_io_channel_unix_new(fd); 90 channel = g_io_channel_unix_new(fd);
91 #endif
84 closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond, 92 closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond,
85 purple_glib_io_invoke, closure, purple_glib_io_destroy); 93 purple_glib_io_invoke, closure, purple_glib_io_destroy);
86 94
87 g_io_channel_unref(channel); 95 g_io_channel_unref(channel);
88 return closure->result; 96 return closure->result;
89 } 97 }
90 98
91 static PurpleEventLoopUiOps glib_eventloops = 99 static PurpleEventLoopUiOps glib_eventloops =
92 { 100 {
93 g_timeout_add, 101 g_timeout_add,
94 g_source_remove, 102 g_source_remove,
95 glib_input_add, 103 glib_input_add,
96 g_source_remove, 104 g_source_remove,
124 printf("(%s) %s %s: %s\n", purple_conversation_get_name(conv), 132 printf("(%s) %s %s: %s\n", purple_conversation_get_name(conv),
125 purple_utf8_strftime("(%H:%M:%S)", localtime(&mtime)), 133 purple_utf8_strftime("(%H:%M:%S)", localtime(&mtime)),
126 name, message); 134 name, message);
127 } 135 }
128 136
129 static PurpleConversationUiOps null_conv_uiops = 137 static PurpleConversationUiOps null_conv_uiops =
130 { 138 {
131 NULL, /* create_conversation */ 139 NULL, /* create_conversation */
132 NULL, /* destroy_conversation */ 140 NULL, /* destroy_conversation */
133 NULL, /* write_chat */ 141 NULL, /* write_chat */
134 NULL, /* write_im */ 142 NULL, /* write_im */
157 * just initialize the UI for conversations. 165 * just initialize the UI for conversations.
158 */ 166 */
159 purple_conversations_set_ui_ops(&null_conv_uiops); 167 purple_conversations_set_ui_ops(&null_conv_uiops);
160 } 168 }
161 169
162 static PurpleCoreUiOps null_core_uiops = 170 static PurpleCoreUiOps null_core_uiops =
163 { 171 {
164 NULL, 172 NULL,
165 NULL, 173 NULL,
166 null_ui_init, 174 null_ui_init,
167 NULL, 175 NULL,
227 235
228 static void 236 static void
229 signed_on(PurpleConnection *gc, gpointer null) 237 signed_on(PurpleConnection *gc, gpointer null)
230 { 238 {
231 PurpleAccount *account = purple_connection_get_account(gc); 239 PurpleAccount *account = purple_connection_get_account(gc);
232 printf("Account connected: %s %s\n", account->username, account->protocol_id); 240 printf("Account connected: %s %s\n", purple_account_get_username(account), purple_account_get_protocol_id(account));
233 } 241 }
234 242
235 static void 243 static void
236 connect_to_signals_for_demonstration_purposes_only(void) 244 connect_to_signals_for_demonstration_purposes_only(void)
237 { 245 {
251 GMainLoop *loop = g_main_loop_new(NULL, FALSE); 259 GMainLoop *loop = g_main_loop_new(NULL, FALSE);
252 PurpleAccount *account; 260 PurpleAccount *account;
253 PurpleSavedStatus *status; 261 PurpleSavedStatus *status;
254 char *res; 262 char *res;
255 263
264 #ifndef _WIN32
256 /* libpurple's built-in DNS resolution forks processes to perform 265 /* libpurple's built-in DNS resolution forks processes to perform
257 * blocking lookups without blocking the main process. It does not 266 * blocking lookups without blocking the main process. It does not
258 * handle SIGCHLD itself, so if the UI does not you quickly get an army 267 * handle SIGCHLD itself, so if the UI does not you quickly get an army
259 * of zombie subprocesses marching around. 268 * of zombie subprocesses marching around.
260 */ 269 */
261 signal(SIGCHLD, SIG_IGN); 270 signal(SIGCHLD, SIG_IGN);
271 #endif
262 272
263 init_libpurple(); 273 init_libpurple();
264 274
265 printf("libpurple initialized.\n"); 275 printf("libpurple initialized.\n");
266 276

mercurial