Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 560 lines (501 sloc) 15.974 kb
a849cf23 » Mark Nunberg
2010-08-17 initial commit
1 #include <purple.h>
2 #include <glib.h>
3 #include <stdio.h>
4 #include <string.h> /*memset*/
5 #include <errno.h>
6 #include <assert.h>
005eb8ba »
2010-08-27 Some more changes.. changed python stuff to have
7 #include <limits.h>
a849cf23 » Mark Nunberg
2010-08-17 initial commit
8
9 #include <unistd.h>
10
11 /*For initiating the connection*/
12 #include <fcntl.h>
13
14 #include "yobot_ui.h"
15 #include "yobotproto.h"
16 #include "yobotutil.h"
17 #include "protoclient.h"
18 #include "yobot_blist.h"
adac280f »
2010-08-22 some more windows support stuff
19 #include "yobot_log.h"
a849cf23 » Mark Nunberg
2010-08-17 initial commit
20
21 #define conv_send(conv,msg) \
22 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT) { \
23 purple_conv_chat_send(conv->u.chat,msg); puts("purple_conv_chat_send called"); } \
24 else { purple_conv_im_send(conv->u.im,msg); puts("purple_conv_im_send called"); }
25
26 #include "contrib/tpl.h"
27
28 extern tpl_hook_t tpl_hook;
29
30 /*Some internal structures used by our functions*/
31
32 /*satisfying some externs*/
33 int client_write_fd;
34 int server_write_fd;
35 GHashTable *yobot_acct_table;
36 GHashTable *yobot_request_table;
37
38
39 /*private functions*/
40 static void cmd_handler(yobot_protoclient_segment *seg);
41 static void join_chat(char *room_name, PurpleConnection *gc);
42 static void init_listener(gboolean first_time);
43 static void yobot_listener(gpointer _null, gint fd, PurpleInputCondition cond);
44
45
46
47 void yobot_core_ui_init()
48 {
d583dca5 »
2010-08-23 ...
49 yobot_log_debug("begin");
a849cf23 » Mark Nunberg
2010-08-17 initial commit
50 yobot_acct_table = g_hash_table_new(g_direct_hash, g_direct_equal);
51 yobot_request_table = g_hash_table_new(g_direct_hash, g_direct_equal);
005eb8ba »
2010-08-27 Some more changes.. changed python stuff to have
52 yobot_purple_account_refcount = g_hash_table_new_full(g_direct_hash,
53 g_direct_equal, NULL, free);
a849cf23 » Mark Nunberg
2010-08-17 initial commit
54
55 /*Set UiOps*/
56 purple_connections_set_ui_ops(&yobot_connection_uiops);
57 purple_conversations_set_ui_ops(&yobot_conversation_uiops);
58 purple_accounts_set_ui_ops(&yobot_account_uiops);
59 purple_blist_set_ui_ops(&yobot_blist_uiops);
005eb8ba »
2010-08-27 Some more changes.. changed python stuff to have
60 purple_request_set_ui_ops(&yobot_request_uiops);
61 purple_notify_set_ui_ops(&yobot_notify_uiops);
a849cf23 » Mark Nunberg
2010-08-17 initial commit
62
63
64 /*Connect signal handlers.. each module should implement its own wrapper*/
65 yobot_account_signals_register();
66 yobot_conversation_signals_register();
67 yobot_connection_signals_register();
68 yobot_blist_signals_register();
69 /*...*/
d583dca5 »
2010-08-23 ...
70 yobot_proto_setlogger(yobot_log_params.prefix);
a849cf23 » Mark Nunberg
2010-08-17 initial commit
71 init_listener(TRUE);
72 }
73
005eb8ba »
2010-08-27 Some more changes.. changed python stuff to have
74 int *yobot_purple_account_refcount_get(PurpleAccount *acct) {
75 int *tmp = g_hash_table_lookup(yobot_purple_account_refcount, acct);
76 if(!tmp) /*NULL POINTER*/ {
77 yobot_log_err("got null value for refcount - for acct ptr %p", acct);
78 }
79 return tmp;
80 }
81
82 int *yobot_purple_account_refcount_decrease(PurpleAccount *acct) {
83 int *tmp = yobot_purple_account_refcount_get(acct);
84 if(!tmp) {
85 yobot_log_err("refcount is already null for %p", acct);
86 return tmp;
87 }
88 (*tmp)--;
89 if(*tmp == 0) {
90 purple_account_destroy(acct);
91 g_hash_table_destroy(((account_uidata*)acct->ui_data)->buddy_requests);
92 g_hash_table_destroy(((account_uidata*)acct->ui_data)->general_requests);
93 }
94 return tmp;
95 }
96
97 int *yobot_purple_account_refcount_increase(PurpleAccount *acct) {
98 int *tmp = yobot_purple_account_refcount_get(acct);
99 if(!tmp) {
100 yobot_log_err("refcount is null for acct %p", acct);
101 return tmp;
102 }
103 (*tmp)++;
104 yobot_log_debug("tmp is now %d", *tmp);
105 return tmp;
106 }
107
108 int *yobot_purple_account_refcount_register(PurpleAccount *acct) {
109 yobot_log_debug("adding account %p to the refcount table", acct);
110 int *tmp = malloc(sizeof(int));
111 *tmp = 0;
112 g_hash_table_insert(yobot_purple_account_refcount, acct, tmp);
113 return tmp;
114
115 }
116
a849cf23 » Mark Nunberg
2010-08-17 initial commit
117 static void join_chat(char *room_name, PurpleConnection *gc) {
dfc446ae » Mark Nunberg
2010-08-18 Some more cleanup.. this is a bitch
118 /*check if chat already exists...*/
119 if(purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, room_name, gc->account)) {
120 /*exists, return success...*/
121 struct yobot_eventinfo info;
122 memset(&info,0,sizeof(info));
123 info.event = YOBOT_EVENT_ROOM_JOINED;
124 info.acctid = yobot_get_acct_id(gc->account);
125 info.data = room_name;
126 info.len = strlen(room_name) + 1;
127 yobot_protoclient_event_encode(info, &server_write_fd, YOBOT_PROTOCLIENT_TO_FD);
128 return;
129 }
a849cf23 » Mark Nunberg
2010-08-17 initial commit
130 if(!gc) {
adac280f »
2010-08-22 some more windows support stuff
131 yobot_log_err("Connection is null for account. Not joining");
132 return;
a849cf23 » Mark Nunberg
2010-08-17 initial commit
133 }
134 PurplePlugin *prpl = purple_connection_get_prpl(gc);
135 if(!prpl) {
adac280f »
2010-08-22 some more windows support stuff
136 yobot_log_err("Couldn't get prpl");
137 return;
a849cf23 » Mark Nunberg
2010-08-17 initial commit
138 }
139 PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
140 if(!prpl_info) {
adac280f »
2010-08-22 some more windows support stuff
141 yobot_log_err("prpl_info is null");
142 return;
a849cf23 » Mark Nunberg
2010-08-17 initial commit
143 }
144 GHashTable *components = prpl_info->chat_info_defaults(gc, room_name);
145 if(!components) {
adac280f »
2010-08-22 some more windows support stuff
146 yobot_log_err("Couldn't get chat components");
147 return;
a849cf23 » Mark Nunberg
2010-08-17 initial commit
148 }
149 serv_join_chat(gc, components);
150 }
151
152
153 static void init_listener(gboolean first_time)
154 {
d583dca5 »
2010-08-23 ...
155 yobot_proto_segfrombuf(yobot_log_params.prefix);
adac280f »
2010-08-22 some more windows support stuff
156 yobot_log_info("BEGIN");
157 #ifndef WIN32
a849cf23 » Mark Nunberg
2010-08-17 initial commit
158 tpl_hook.oops = printf;
adac280f »
2010-08-22 some more windows support stuff
159 #endif
a849cf23 » Mark Nunberg
2010-08-17 initial commit
160 /*Initialize the pipes*/
161 int in, out, in_w;
162 static guint cb_handle;
163 static int s, yobot_socket;
164 struct sockaddr_storage incoming_addr;
adac280f »
2010-08-22 some more windows support stuff
165 #ifdef WIN32
166 if (first_time) {
167 WSADATA wsadata;
168 if(WSAStartup(MAKEWORD(2,0), &wsadata)!=0) {
169 fprintf(stderr, "WSAStartup Failed!\n");
170 exit(1);
171 }
172 }
173 #endif
a849cf23 » Mark Nunberg
2010-08-17 initial commit
174
175 int status;
176
177 /*remove all the accounts first...*/
178 GList *accounts = purple_accounts_get_all();
179 for (; accounts; accounts = accounts->next) {
180 purple_accounts_remove((PurpleAccount*)accounts->data);
181 }
182
183 /*initialize the listening socket*/
184 if (first_time == TRUE) {
185 /*called first time only*/
186 struct addrinfo hints;
187 struct addrinfo *result;
188
189 memset(&hints, 0, sizeof(struct addrinfo));
190 hints.ai_family = AF_INET;
191 hints.ai_socktype = SOCK_STREAM;
192 hints.ai_next = NULL;
193
194 status = getaddrinfo("localhost", "7771", &hints, &result);
195 if (status < 0)
196 perror("getaddrinfo");
197 s = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
198 if (s < 0)
199 perror("socket");
adac280f »
2010-08-22 some more windows support stuff
200 #ifndef _WIN32
a849cf23 » Mark Nunberg
2010-08-17 initial commit
201 unsigned int opt = 1;
adac280f »
2010-08-22 some more windows support stuff
202 #else
203 char opt = 1;
204 #endif
a849cf23 » Mark Nunberg
2010-08-17 initial commit
205 status = setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(opt));
206 if (status < 0)
207 perror("setsockopt");
208
209 status = bind(s, result->ai_addr, result->ai_addrlen);
210 if (status < 0)
211 perror("bind");
212
213 freeaddrinfo(result);
214 status = listen(s, 5);
215 }
216 else {
217 /*we need to close the old socket first*/
218 purple_input_remove(cb_handle);
219 close(yobot_socket);
220 }
221
222 /*block....*/
223 socklen_t addr_size = sizeof incoming_addr;
224 must_succeed(yobot_socket = accept(s,(struct sockaddr*)&incoming_addr,
225 &addr_size));
226 /*don't block anymore*/
227
228 /*write a hello message*/
229 struct yobot_eventinfo info;
230 memset(&info, 0, sizeof(info));
231 info.event = YOBOT_EVENT_CLIENT_REGISTERED;
232 info.purple_type = YOBOT_CLIENT_INTERNAL;
233 info.severity = YOBOT_INFO;
234 yobot_protoclient_event_encode(info, &yobot_socket, YOBOT_PROTOCLIENT_TO_FD);
235
236
adac280f »
2010-08-22 some more windows support stuff
237 //status = fcntl(yobot_socket,F_SETFL, flags|O_NONBLOCK);
238 YOBOT_SET_SOCK_BLOCK(yobot_socket, 1, status);
239 if(status <= -1 ) {
a849cf23 » Mark Nunberg
2010-08-17 initial commit
240 perror(__func__);
adac280f »
2010-08-22 some more windows support stuff
241 yobot_log_crit("fcntl failed");
a849cf23 » Mark Nunberg
2010-08-17 initial commit
242 }
243
244 in = in_w = out = yobot_socket;
245
246 client_write_fd = in;
247 server_write_fd = out;
248
249 cb_handle = purple_input_add(in,
250 PURPLE_INPUT_READ,
251 yobot_listener,NULL);
adac280f »
2010-08-22 some more windows support stuff
252 yobot_log_info("END");
253
a849cf23 » Mark Nunberg
2010-08-17 initial commit
254 }
255
256 static void yobot_listener(gpointer _null, gint fd, PurpleInputCondition cond)
257 {
adac280f »
2010-08-22 some more windows support stuff
258 yobot_log_debug("BEGIN");
a849cf23 » Mark Nunberg
2010-08-17 initial commit
259 struct segment_r segr;
260 yobot_protoclient_segment *seg = NULL;
261 segr = yobot_proto_read_segment(&fd);
262 int old_errno = errno;
263 if(!(segr.len)) {
adac280f »
2010-08-22 some more windows support stuff
264 yobot_log_warn("segr.len is empty... empty read, going to error");
a849cf23 » Mark Nunberg
2010-08-17 initial commit
265 goto err;
266 }
267
268 seg = yobot_protoclient_segment_decode(segr);
269 segr.data = NULL;
270 if(!seg) {
adac280f »
2010-08-22 some more windows support stuff
271 yobot_log_warn("got NULL decoded segment");
a849cf23 » Mark Nunberg
2010-08-17 initial commit
272 goto err;
273 }
274
275 if(seg->struct_type == YOBOT_PROTOCLIENT_CMD_SIMPLE ||
276 seg->struct_type == YOBOT_PROTOCLIENT_YCMDI ||
277 seg->struct_type == YOBOT_PROTOCLIENT_YMSGI ||
278 seg->struct_type == YOBOT_PROTOCLIENT_YMKACCTI)
279 cmd_handler(seg);
280 else
adac280f »
2010-08-22 some more windows support stuff
281 yobot_log_err("unsupported transmission");
a849cf23 » Mark Nunberg
2010-08-17 initial commit
282
283 yobot_protoclient_free_segment(seg);
284 return;
285
286 err:
287 if(old_errno && !(old_errno == EAGAIN || old_errno == EWOULDBLOCK)) {
adac280f »
2010-08-22 some more windows support stuff
288 yobot_log_err("read error: %s", strerror(old_errno));
a849cf23 » Mark Nunberg
2010-08-17 initial commit
289 }
290
291 yobot_protoclient_free_segment(seg);
292 if(segr.data)
293 free(segr.data);
294
295 init_listener(FALSE);
296 return;
297 }
298
299 static void cmd_handler(yobot_protoclient_segment *seg) {
300 /*Some stuff almost everything uses*/
301 yobotcmd cmd;
302 yobotcmd_internal *yci = seg->cmdi;
303 cmd = *(yci->cmd);
304 yobotcomm *comm = seg->comm;
305
306 PurpleAccount *account = get_acct_from_id(cmd.acct_id);
307 PurpleConnection *gc = NULL;
308
309 if (account) {
005eb8ba »
2010-08-27 Some more changes.. changed python stuff to have
310 yobot_purple_account_context_set(account);
a849cf23 » Mark Nunberg
2010-08-17 initial commit
311 gc = purple_account_get_connection(account);
312 if (!gc) {
adac280f »
2010-08-22 some more windows support stuff
313 if (!(
314 cmd.command == YOBOT_CMD_ACCT_ENABLE||
a849cf23 » Mark Nunberg
2010-08-17 initial commit
315 cmd.command == YOBOT_CMD_ACCT_NEW ||
adac280f »
2010-08-22 some more windows support stuff
316 cmd.command == YOBOT_CMD_ACCT_REMOVE
317 )) {
318 yobot_log_warn(" (command %d): Got NULL connection for account %d",
319 cmd.command, cmd.acct_id);
a849cf23 » Mark Nunberg
2010-08-17 initial commit
320 if (comm->reference) {
321 struct yobot_eventinfo info;
322 memset(&info, 0, sizeof(info));
323 info.commflags = YOBOT_RESPONSE_END;
324 info.data = "Could not find the account requested";
325 info.acctid = cmd.acct_id;
326 info.severity = YOBOT_WARN;
327 info.len = strlen(info.data);
328 info.event = YOBOT_EVENT_ERR;
329 yobot_protoclient_event_encode(info, &server_write_fd, YOBOT_PROTOCLIENT_TO_FD);
330 }
331 return;
332 }
333 }
adac280f »
2010-08-22 some more windows support stuff
334 } else {
7409623b »
2010-08-24 Modified logging facilities. Now the C code can also do color logging
335 if(cmd.command != YOBOT_CMD_ACCT_NEW) {
336 yobot_log_err(" (command %d): Could not find account %d. Possible trouble ahead",
adac280f »
2010-08-22 some more windows support stuff
337 cmd.command, cmd.acct_id);
7409623b »
2010-08-24 Modified logging facilities. Now the C code can also do color logging
338 }
a849cf23 » Mark Nunberg
2010-08-17 initial commit
339 }
adac280f »
2010-08-22 some more windows support stuff
340 yobot_log_debug("got command %d", cmd.command);
a849cf23 » Mark Nunberg
2010-08-17 initial commit
341 switch (cmd.command) {
342 case YOBOT_CMD_ROOM_JOIN: {
343 char *room_name = yci->data;
344 join_chat(room_name, gc);
345 break;
346 }
dfc446ae » Mark Nunberg
2010-08-18 Some more cleanup.. this is a bitch
347 case YOBOT_CMD_ROOM_LEAVE: {
348 char *room_name = yci->data;
adac280f »
2010-08-22 some more windows support stuff
349 PurpleConversation *conv = purple_find_conversation_with_account(
350 PURPLE_CONV_TYPE_CHAT, room_name, account);
dfc446ae » Mark Nunberg
2010-08-18 Some more cleanup.. this is a bitch
351 if(!conv) {
adac280f »
2010-08-22 some more windows support stuff
352 yobot_log_warn("got request to leave room %s which we are not joined to",
353 room_name);
dfc446ae » Mark Nunberg
2010-08-18 Some more cleanup.. this is a bitch
354 return;
355 }
356 purple_conversation_destroy(conv);
357 break;
358 }
a849cf23 » Mark Nunberg
2010-08-17 initial commit
359 case YOBOT_CMD_MSG_SEND: {
360 yobotmsg_internal *ymi = seg->msgi;
361 PurpleConversation *conv;
362 const char *destination = ymi->to;
363 const char *msgbody = ymi->txt;
364
365 if (comm->flags & YOBOT_MSG_ATTENTION) {
366 serv_send_attention(gc,destination, 0);
367 break;
368 }
369
370 conv = purple_find_conversation_with_account(
371 yobot_proto_get_conv_type(comm->flags), destination,
372 account);
373
374 if (!conv) {
375 if (comm->flags & YOBOT_MSG_TYPE_CHAT) {
adac280f »
2010-08-22 some more windows support stuff
376 yobot_log_warn(" (acct %d) trying to send message to room %s which is not joined",
377 cmd.acct_id, destination);
dfc446ae » Mark Nunberg
2010-08-18 Some more cleanup.. this is a bitch
378 //TODO: notify the client
a849cf23 » Mark Nunberg
2010-08-17 initial commit
379 break;
380 /*bail -- no such conversation, we'll bother the client to re-join
381 * if we're sure*/
382 }
383 conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account,
384 destination);
385 if (!conv) {
386 puts("couldn't create conversation! BAILING!!!");
387 break;
388 }
389 }
390 conv_send(conv, msgbody);
391 break;
392 }
393
394 case YOBOT_CMD_ACCT_NEW: {
adac280f »
2010-08-22 some more windows support stuff
395 yobot_log_info("YOBOT_CMD_ACCT_NEW");
a849cf23 » Mark Nunberg
2010-08-17 initial commit
396 const char *name, *pass;
397 yobotmkacct_internal *ymkaccti = seg->mkaccti;
398 name = ymkaccti->user;
399 pass = ymkaccti->pass;
adac280f »
2010-08-22 some more windows support stuff
400 yobot_log_info("new user: %s, proto %s",
401 name, yobot_proto_get_prpl_id(ymkaccti->yomkacct->improto));
402 yobot_log_debug("calling purple_acount_new");
403
a849cf23 » Mark Nunberg
2010-08-17 initial commit
404 PurpleAccount *acct = purple_account_new(name,
405 yobot_proto_get_prpl_id(ymkaccti->yomkacct->improto));
005eb8ba »
2010-08-27 Some more changes.. changed python stuff to have
406 yobot_purple_account_refcount_register(acct);
407 yobot_purple_account_refcount_increase(acct);
408 yobot_purple_account_context_set(acct);
adac280f »
2010-08-22 some more windows support stuff
409 yobot_log_debug("done.. now setting up account ui data");
a849cf23 » Mark Nunberg
2010-08-17 initial commit
410 purple_account_set_password(acct, pass);
411 account_uidata *tmp = malloc(sizeof(account_uidata));
412 tmp->id = cmd.acct_id;
413 acct->ui_data = tmp;
414 purple_accounts_add(acct);
adac280f »
2010-08-22 some more windows support stuff
415 yobot_log_debug("added account");
a849cf23 » Mark Nunberg
2010-08-17 initial commit
416 break;
417 }
418
419 case YOBOT_CMD_ACCT_ENABLE: {
adac280f »
2010-08-22 some more windows support stuff
420 yobot_log_info("YOBOT_CMD_ACCT_ENABLE");
a849cf23 » Mark Nunberg
2010-08-17 initial commit
421 assert (cmd.len == 0);
422 purple_account_set_enabled(account,"user",TRUE);
adac280f »
2010-08-22 some more windows support stuff
423 // purple_account_connect(account);
424 yobot_log_debug("account connecting...");
a849cf23 » Mark Nunberg
2010-08-17 initial commit
425 break;
426 }
427 case YOBOT_CMD_ACCT_REMOVE: {
adac280f »
2010-08-22 some more windows support stuff
428 yobot_log_info("YOBOT_CMD_ACCT_REMOVE");
a849cf23 » Mark Nunberg
2010-08-17 initial commit
429 assert (cmd.len == 0);
430 if(!account) {
adac280f »
2010-08-22 some more windows support stuff
431 yobot_log_warn("account %d is NULL, not removing", cmd.acct_id);
a849cf23 » Mark Nunberg
2010-08-17 initial commit
432 }
005eb8ba »
2010-08-27 Some more changes.. changed python stuff to have
433 purple_accounts_remove(account); /*remove ID too*/
434 account_uidata *priv = account->ui_data;
435 priv->id = 0;
436 yobot_purple_account_refcount_decrease(account);
adac280f »
2010-08-22 some more windows support stuff
437 yobot_log_debug("removed");
a849cf23 » Mark Nunberg
2010-08-17 initial commit
438 break;
439 }
440 case YOBOT_CMD_ROOM_FETCH_USERS: {
441 assert(yci->data);
442 char *room = yci->data;
443 GList *users;
444 /*find corresponding conv*/
445 PurpleConversation *conv;
446 struct yobot_eventinfo info;
447 memset(&info, 0, sizeof(info));
448 info.acctid = cmd.acct_id;
449 info.reference = comm->reference;
450 info.severity = YOBOT_INFO;
451 info.event = YOBOT_EVENT_ROOM_USER_JOIN;
452 info.purple_type = YOBOT_PURPLE_ACCOUNT;
453 conv = purple_find_conversation_with_account(
454 PURPLE_CONV_TYPE_CHAT, room, account);
455 if (!conv) {
483cc6d0 »
2010-08-30 a ton of other stuff.. i'm getting sick of this
456 yobot_log_err("couldn't find room %s. can't fetch user list", room);
a849cf23 » Mark Nunberg
2010-08-17 initial commit
457 /*return a failure notice*/
458 info.severity = YOBOT_WARN;
459 info.data = "Room doesn't exist";
460 info.len = strlen(info.data);
461 yobot_protoclient_event_encode(info, &server_write_fd, YOBOT_PROTOCLIENT_TO_FD);
462 return;
463 }
464 users = purple_conv_chat_get_users(conv->u.chat);
465 info.commflags = YOBOT_RESPONSE;
466 for (; users; users = users->next) {
dfc446ae » Mark Nunberg
2010-08-18 Some more cleanup.. this is a bitch
467 PurpleConvChatBuddy *chatbuddy = users->data;
468 char *room_user = g_strconcat(room, YOBOT_TEXT_DELIM, chatbuddy->name, NULL);
469 info.len = strlen(room_user) + 1;
a849cf23 » Mark Nunberg
2010-08-17 initial commit
470 info.data = room_user;
471 yobot_protoclient_event_encode(info, &server_write_fd,
472 YOBOT_PROTOCLIENT_TO_FD);
473 g_free(room_user);
474 memset(&info, 0, sizeof(info));
475 }
476 info.commflags = YOBOT_RESPONSE_END;
477 info.data = room;
478 info.len = strlen(room);
479
480 yobot_protoclient_event_encode(info, &server_write_fd, YOBOT_PROTOCLIENT_TO_FD);
481 break;
482 }
483
484 case YOBOT_CMD_FETCH_BUDDIES: {
485 GSList *buddies = purple_find_buddies(account, NULL);
486 PurpleBuddy *buddy;
487 yobot_status_r ystatus;
488 memset(&ystatus, 0, sizeof(ystatus));
489
490 for (; buddies; buddies = buddies->next) {
491 buddy = buddies->data;
492 ystatus = yobot_blist_get_status(
493 purple_presence_get_active_status(buddy->presence));
494 yobot_blist_send_status_change(buddy->name, ystatus, 0, YOBOT_RESPONSE,
495 comm->reference, cmd.acct_id);
496 }
497 struct yobot_eventinfo info;
498 memset(&info,0,sizeof(info));
499 info.event = YOBOT_EVENT_DUMMY;
500 info.commflags = YOBOT_RESPONSE_END;
501 info.acctid = cmd.acct_id;
502 info.reference = comm->reference;
503 yobot_protoclient_event_encode(info, &server_write_fd, YOBOT_PROTOCLIENT_TO_FD);
504 break;
505 }
506 case YOBOT_CMD_FETCH_BUDDY_ICONS: {
507 GSList *buddies = purple_find_buddies(account, NULL);
508 PurpleBuddy *buddy = NULL;
509 for (; buddies; buddies = buddies->next) {
510 buddy = buddies->data;
511 yobot_blist_send_icon(buddy, 0, YOBOT_RESPONSE, comm->reference, cmd.acct_id);
512 }
513 struct yobot_eventinfo info;
514 memset(&info,0,sizeof(info));
515 info.event = YOBOT_EVENT_DUMMY;
516 info.commflags = YOBOT_RESPONSE_END;
517 info.acctid = cmd.acct_id;
518 info.reference = comm->reference;
519 yobot_protoclient_event_encode(info, &server_write_fd, YOBOT_PROTOCLIENT_TO_FD);
520 break;
521 }
522
523 case YOBOT_CMD_USER_AUTHORIZE_ADD_DENY:
524 case YOBOT_CMD_USER_AUTHORIZE_ADD_ACCEPT: {
525 /*get the user*/
526 char *user = yci->data;
527 if (cmd.command == YOBOT_CMD_USER_AUTHORIZE_ADD_ACCEPT)
528 yobot_user_authorize(account, user, TRUE);
529 else
530 yobot_user_authorize(account, user, FALSE);
531 break;
532 }
533 case YOBOT_CMD_USER_ADD: {
534 PurpleBuddy *buddy = purple_buddy_new(account, yci->data, NULL);
535 if(!buddy) {
483cc6d0 »
2010-08-30 a ton of other stuff.. i'm getting sick of this
536 yobot_log_err("ADD: buddy is null");
a849cf23 » Mark Nunberg
2010-08-17 initial commit
537 break;
538 }
539 purple_account_add_buddy(account, buddy);
540 break;
541 }
542 case YOBOT_CMD_USER_REMOVE: {
543 PurpleBuddy *buddy = purple_find_buddy(account, yci->data);
544 if(!buddy) {
483cc6d0 »
2010-08-30 a ton of other stuff.. i'm getting sick of this
545 yobot_log_err("REMOVE: buddy is null");
a849cf23 » Mark Nunberg
2010-08-17 initial commit
546 break;
547 }
548 purple_account_remove_buddy(account, buddy, purple_buddy_get_group(buddy));
549 break;
550 }
005eb8ba »
2010-08-27 Some more changes.. changed python stuff to have
551 case YOBOT_CMD_PURPLE_REQUEST_GENERIC_RESPONSE: {
552 yobot_log_info("YOBOT_CMD_PURPLE_REQUEST_GENERIC_RESPONSE");
553 yobot_request_handle_response(account, yci->data, comm->reference);
554 break;
555 }
a849cf23 » Mark Nunberg
2010-08-17 initial commit
556 default:
483cc6d0 »
2010-08-30 a ton of other stuff.. i'm getting sick of this
557 yobot_log_warn("unknown command %d.", cmd.command);
a849cf23 » Mark Nunberg
2010-08-17 initial commit
558 break;
559 }
560 }
Something went wrong with that request. Please try again.