5730
|
1 /**
|
|
2 * @file trepia.c The Trepia protocol plugin
|
|
3 *
|
|
4 * gaim
|
|
5 *
|
|
6 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org>
|
|
7 *
|
|
8 * This program is free software; you can redistribute it and/or modify
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
10 * the Free Software Foundation; either version 2 of the License, or
|
|
11 * (at your option) any later version.
|
|
12 *
|
|
13 * This program is distributed in the hope that it will be useful,
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 * GNU General Public License for more details.
|
|
17 *
|
|
18 * You should have received a copy of the GNU General Public License
|
|
19 * along with this program; if not, write to the Free Software
|
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 */
|
|
22 #include "gaim.h"
|
|
23 #include "account.h"
|
|
24 #include "accountopt.h"
|
|
25 #include "md5.h"
|
|
26 #include "profile.h"
|
|
27 #include <string.h>
|
|
28 #include <stdlib.h>
|
|
29 #include <unistd.h>
|
|
30
|
|
31 #ifndef _WIN32
|
|
32 # include <sys/socket.h>
|
|
33 # include <sys/ioctl.h>
|
|
34 # include <netinet/in.h>
|
|
35 # include <arpa/inet.h>
|
|
36 # include <net/if_arp.h>
|
|
37 #endif
|
|
38
|
|
39 static GaimPlugin *my_protocol = NULL;
|
|
40
|
|
41 typedef enum
|
|
42 {
|
|
43 TREPIA_LOGIN = 'C',
|
|
44 TREPIA_PROFILE_REQ = 'D',
|
|
45 TREPIA_MSG_OUTGOING = 'F',
|
|
46 TREPIA_REGISTER = 'J',
|
|
47 TREPIA_USER_LIST = 'L',
|
|
48 TREPIA_MEMBER_UPDATE = 'M',
|
|
49 TREPIA_MEMBER_OFFLINE = 'N',
|
|
50 TREPIA_MEMBER_PROFILE = 'O',
|
|
51 TREPIA_MSG_INCOMING = 'Q'
|
|
52
|
|
53 } TrepiaMessageType;
|
|
54
|
|
55 typedef struct
|
|
56 {
|
|
57 GaimConnection *gc;
|
|
58
|
|
59 int inpa;
|
|
60 int fd;
|
|
61
|
|
62 GString *rxqueue;
|
|
63
|
|
64 } TrepiaSession;
|
|
65
|
|
66 typedef struct
|
|
67 {
|
|
68 TrepiaMessageType *type;
|
|
69 char *tag;
|
|
70
|
|
71 GHashTable *keys;
|
|
72
|
|
73 GString *buffer;
|
|
74
|
|
75 } TrepiaParserData;
|
|
76
|
|
77 #define TREPIA_SERVER "trepia.com"
|
|
78 #define TREPIA_PORT 8201
|
|
79 #define TREPIA_REG_PORT 8209
|
|
80
|
|
81 static int
|
|
82 trepia_write(int fd, const char *data, size_t len)
|
|
83 {
|
|
84 gaim_debug(GAIM_DEBUG_MISC, "trepia", "C: %s%c", data,
|
|
85 (data[strlen(data) - 1] == '\n' ? '\0' : '\n'));
|
|
86
|
|
87 return write(fd, data, len);
|
|
88 }
|
|
89
|
|
90 static void
|
|
91 __clear_user_list(GaimAccount *account)
|
|
92 {
|
|
93 struct gaim_buddy_list *blist;
|
|
94 GaimBlistNode *group, *buddy, *next_buddy;
|
|
95
|
|
96 blist = gaim_get_blist();
|
|
97
|
|
98 for (group = blist->root; group != NULL; group = group->next) {
|
|
99 for (buddy = group->child; buddy != NULL; buddy = next_buddy) {
|
|
100 struct buddy *b = (struct buddy *)buddy;
|
|
101
|
|
102 next_buddy = buddy->next;
|
|
103
|
|
104 if (b->account == account)
|
|
105 gaim_blist_remove_buddy(b);
|
|
106 }
|
|
107 }
|
|
108 }
|
|
109
|
|
110 static char *
|
|
111 __get_mac_address(const char *ip)
|
|
112 {
|
|
113 char *mac = NULL;
|
|
114 #ifndef _WIN32
|
|
115 struct sockaddr_in sin = { 0 };
|
|
116 struct arpreq myarp = { { 0 } };
|
|
117 int sockfd;
|
|
118 unsigned char *ptr;
|
|
119
|
|
120 sin.sin_family = AF_INET;
|
|
121
|
|
122 if (inet_aton(ip, &sin.sin_addr) == 0) {
|
|
123 gaim_debug(GAIM_DEBUG_ERROR, "trepia", "Invalid IP address %s\n", ip);
|
|
124 return NULL;
|
|
125 }
|
|
126
|
|
127 memcpy(&myarp.arp_pa, &sin, sizeof(myarp.arp_pa));
|
|
128 strcpy(myarp.arp_dev, "eth0");
|
|
129
|
|
130 if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
|
|
131 gaim_debug(GAIM_DEBUG_ERROR, "trepia",
|
|
132 "Cannot open socket for retrieving MAC address.\n");
|
|
133 return NULL;
|
|
134 }
|
|
135
|
|
136 if (ioctl(sockfd, SIOCGARP, &myarp) == -1) {
|
|
137 gaim_debug(GAIM_DEBUG_ERROR, "trepia",
|
|
138 "No entry in in arp_cache for %s\n", ip);
|
|
139 return NULL;
|
|
140 }
|
|
141
|
|
142 ptr = &myarp.arp_ha.sa_data[0];
|
|
143
|
|
144 mac = g_strdup_printf("%x:%x:%x:%x:%x:%x",
|
|
145 ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]);
|
|
146 #else
|
|
147 #endif
|
|
148
|
|
149 return mac;
|
|
150 }
|
|
151
|
|
152 /**************************************************************************
|
|
153 * Protocol Plugin ops
|
|
154 **************************************************************************/
|
|
155
|
|
156 static const char *
|
|
157 trepia_list_icon(GaimAccount *a, struct buddy *b)
|
|
158 {
|
|
159 return "trepia";
|
|
160 }
|
|
161
|
|
162 static void
|
|
163 trepia_list_emblems(struct buddy *b, char **se, char **sw,
|
|
164 char **nw, char **ne)
|
|
165 {
|
|
166 TrepiaProfile *profile = (TrepiaProfile *)b->proto_data;
|
|
167
|
|
168 if (trepia_profile_get_sex(profile) == 'M')
|
|
169 *sw = "male";
|
|
170 else if (trepia_profile_get_sex(profile))
|
|
171 *sw = "female";
|
|
172 }
|
|
173
|
|
174 static char *
|
|
175 trepia_status_text(struct buddy *b)
|
|
176 {
|
|
177 return NULL;
|
|
178 }
|
|
179
|
|
180 static char *
|
|
181 trepia_tooltip_text(struct buddy *b)
|
|
182 {
|
|
183 return NULL;
|
|
184 }
|
|
185
|
|
186 static GList *
|
|
187 trepia_away_states(GaimConnection *gc)
|
|
188 {
|
|
189 GList *m = NULL;
|
|
190
|
|
191 return m;
|
|
192 }
|
|
193
|
|
194 static GList *
|
|
195 trepia_actions(GaimConnection *gc)
|
|
196 {
|
|
197 return NULL;
|
|
198 }
|
|
199
|
|
200 static GList *
|
|
201 trepia_buddy_menu(GaimConnection *gc, const char *who)
|
|
202 {
|
|
203 return NULL;
|
|
204 }
|
|
205
|
|
206 static void
|
|
207 __free_parser_data(gpointer user_data)
|
|
208 {
|
|
209 return;
|
|
210
|
|
211 TrepiaParserData *data = user_data;
|
|
212
|
|
213 if (data->buffer != NULL)
|
|
214 g_string_free(data->buffer, TRUE);
|
|
215
|
|
216 if (data->tag != NULL)
|
|
217 g_free(data->tag);
|
|
218
|
|
219 g_free(data);
|
|
220 }
|
|
221
|
|
222 static void
|
|
223 __start_element_handler(GMarkupParseContext *context,
|
|
224 const gchar *element_name,
|
|
225 const gchar **attribute_names,
|
|
226 const gchar **attribute_values,
|
|
227 gpointer user_data, GError **error)
|
|
228 {
|
|
229 TrepiaParserData *data = user_data;
|
|
230
|
|
231 if (data->buffer != NULL) {
|
|
232 g_string_free(data->buffer, TRUE);
|
|
233 data->buffer = NULL;
|
|
234 }
|
|
235
|
|
236 if (*data->type == 0) {
|
|
237 *data->type = *element_name;
|
|
238 }
|
|
239 else {
|
|
240 data->tag = g_strdup(element_name);
|
|
241 }
|
|
242 }
|
|
243
|
|
244 static void
|
|
245 __end_element_handler(GMarkupParseContext *context, const gchar *element_name,
|
|
246 gpointer user_data, GError **error)
|
|
247 {
|
|
248 TrepiaParserData *data = user_data;
|
|
249 gchar *buffer;
|
|
250
|
|
251 if (*element_name == *data->type)
|
|
252 return;
|
|
253
|
|
254 if (data->buffer == NULL || data->tag == NULL) {
|
|
255 data->tag = NULL;
|
|
256 return;
|
|
257 }
|
|
258
|
|
259 buffer = g_string_free(data->buffer, FALSE);
|
|
260 data->buffer = NULL;
|
|
261
|
|
262 g_hash_table_insert(data->keys, data->tag, buffer);
|
|
263
|
|
264 data->tag = NULL;
|
|
265 }
|
|
266
|
|
267 static void
|
|
268 __text_handler(GMarkupParseContext *context, const gchar *text,
|
|
269 gsize text_len, gpointer user_data, GError **error)
|
|
270 {
|
|
271 TrepiaParserData *data = user_data;
|
|
272
|
|
273 if (data->buffer == NULL)
|
|
274 data->buffer = g_string_new_len(text, text_len);
|
|
275 else
|
|
276 g_string_append_len(data->buffer, text, text_len);
|
|
277 }
|
|
278
|
|
279 static GMarkupParser accounts_parser =
|
|
280 {
|
|
281 __start_element_handler,
|
|
282 __end_element_handler,
|
|
283 __text_handler,
|
|
284 NULL,
|
|
285 NULL
|
|
286 };
|
|
287
|
|
288 static int
|
|
289 __parse_message(const char *buf, TrepiaMessageType *type, GHashTable **info)
|
|
290 {
|
|
291 TrepiaParserData *parser_data = g_new0(TrepiaParserData, 1);
|
|
292 GMarkupParseContext *context;
|
|
293 GHashTable *keys;
|
|
294
|
|
295 keys = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
|
296 parser_data->keys = keys;
|
|
297 parser_data->type = type;
|
|
298
|
|
299 context = g_markup_parse_context_new(&accounts_parser, 0,
|
|
300 parser_data, __free_parser_data);
|
|
301
|
|
302 if (!g_markup_parse_context_parse(context, buf, strlen(buf), NULL)) {
|
|
303 g_markup_parse_context_free(context);
|
|
304 g_free(parser_data);
|
|
305 g_hash_table_destroy(keys);
|
|
306
|
|
307 return 1;
|
|
308 }
|
|
309
|
|
310 if (!g_markup_parse_context_end_parse(context, NULL)) {
|
|
311 g_markup_parse_context_free(context);
|
|
312 g_free(parser_data);
|
|
313 g_hash_table_destroy(keys);
|
|
314
|
|
315 return 1;
|
|
316 }
|
|
317
|
|
318 g_markup_parse_context_free(context);
|
|
319
|
|
320 *info = keys;
|
|
321
|
|
322 return 0;
|
|
323 }
|
|
324
|
|
325 static gboolean
|
|
326 __parse_data(TrepiaSession *session, char *buf)
|
|
327 {
|
|
328 GHashTable *info;
|
|
329 GaimAccount *account;
|
|
330 TrepiaMessageType type = 0;
|
|
331 TrepiaProfile *profile;
|
|
332 int ret;
|
|
333 char *buffer;
|
|
334 struct buddy *b;
|
|
335 const char *id = NULL;
|
|
336 const char *value;
|
|
337
|
|
338 account = gaim_connection_get_account(session->gc);
|
|
339
|
|
340 ret = __parse_message(buf, &type, &info);
|
|
341
|
|
342 if (ret == 1)
|
|
343 return TRUE;
|
|
344
|
|
345 gaim_debug(GAIM_DEBUG_INFO, "trepia", "Successful parse.\n");
|
|
346 gaim_debug(GAIM_DEBUG_INFO, "trepia", "Message type: %c\n",
|
|
347 type);
|
|
348
|
|
349 if (info != NULL) {
|
|
350 switch (type) {
|
|
351 case TREPIA_USER_LIST:
|
|
352 gaim_debug(GAIM_DEBUG_INFO, "trepia",
|
|
353 "Signon complete. Showing buddy list.\n");
|
|
354 gaim_connection_set_state(session->gc, GAIM_CONNECTED);
|
|
355 serv_finish_login(session->gc);
|
|
356 break;
|
|
357
|
|
358 case TREPIA_MSG_INCOMING: /* Incoming Message */
|
|
359 gaim_debug(GAIM_DEBUG_INFO, "trepia", "Receiving message\n");
|
|
360 serv_got_im(session->gc,
|
|
361 (char *)g_hash_table_lookup(info, "a"),
|
|
362 (char *)g_hash_table_lookup(info, "b"),
|
|
363 0, time(NULL), -1);
|
|
364 break;
|
|
365
|
|
366 case TREPIA_MEMBER_UPDATE:
|
|
367 id = g_hash_table_lookup(info, "a");
|
|
368 b = gaim_find_buddy(account, id);
|
|
369
|
|
370 if (b == NULL) {
|
|
371 struct group *g;
|
|
372
|
|
373 g = gaim_find_group(_("Local Users"));
|
|
374
|
|
375 if (g == NULL) {
|
|
376 g = gaim_group_new(_("Local Users"));
|
|
377 gaim_blist_add_group(g, NULL);
|
|
378 }
|
|
379
|
|
380 b = gaim_buddy_new(account, id, NULL);
|
|
381
|
|
382 gaim_blist_add_buddy(b, g, NULL);
|
|
383 }
|
|
384
|
|
385 b->proto_data = trepia_profile_new();
|
|
386
|
|
387 serv_got_update(session->gc, id, 1, 0, 0, 0, 0);
|
|
388
|
|
389 buffer = g_strdup_printf(
|
|
390 "<D>\n"
|
|
391 "<a>%s</a>\n"
|
|
392 "<b>1</b>\n"
|
|
393 "</D>",
|
|
394 id);
|
|
395
|
|
396 if (trepia_write(session->fd, buffer, strlen(buffer)) < 0) {
|
|
397 gaim_connection_error(session->gc, _("Write error"));
|
|
398 g_free(buffer);
|
|
399 return 1;
|
|
400 }
|
|
401
|
|
402 buffer = g_strdup_printf(
|
|
403 "<D>\n"
|
|
404 "<a>%s</a>\n"
|
|
405 "<b>2</b>\n"
|
|
406 "</D>",
|
|
407 id);
|
|
408
|
|
409 if (trepia_write(session->fd, buffer, strlen(buffer)) < 0) {
|
|
410 gaim_connection_error(session->gc, _("Write error"));
|
|
411 g_free(buffer);
|
|
412 return 1;
|
|
413 }
|
|
414
|
|
415 g_free(buffer);
|
|
416 break;
|
|
417
|
|
418 case TREPIA_MEMBER_PROFILE:
|
|
419 id = g_hash_table_lookup(info, "a");
|
|
420 b = gaim_find_buddy(account, id);
|
|
421
|
|
422 if (b == NULL)
|
|
423 break;
|
|
424
|
|
425 profile = b->proto_data;
|
|
426
|
|
427 /* ID */
|
|
428 trepia_profile_set_id(profile, atoi(id));
|
|
429
|
|
430 /* Login Time */
|
|
431 if ((value = g_hash_table_lookup(info, "b")) != NULL)
|
|
432 trepia_profile_set_login_time(profile, atoi(value));
|
|
433
|
|
434 /* Age */
|
|
435 if ((value = g_hash_table_lookup(info, "m")) != NULL)
|
|
436 trepia_profile_set_age(profile, atoi(value));
|
|
437
|
|
438 /* ICQ */
|
|
439 if ((value = g_hash_table_lookup(info, "i")) != NULL)
|
|
440 trepia_profile_set_icq(profile, atoi(value));
|
|
441
|
|
442 /* Sex */
|
|
443 if ((value = g_hash_table_lookup(info, "n")) != NULL)
|
|
444 trepia_profile_set_sex(profile, *value);
|
|
445
|
|
446 /* Location */
|
|
447 trepia_profile_set_location(profile,
|
|
448 g_hash_table_lookup(info, "p"));
|
|
449
|
|
450 /* First Name */
|
|
451 trepia_profile_set_first_name(profile,
|
|
452 g_hash_table_lookup(info, "g"));
|
|
453
|
|
454 /* Last Name */
|
|
455 trepia_profile_set_last_name(profile,
|
|
456 g_hash_table_lookup(info, "h"));
|
|
457
|
|
458 /* Profile */
|
|
459 trepia_profile_set_profile(profile,
|
|
460 g_hash_table_lookup(info, "o"));
|
|
461
|
|
462 /* E-mail */
|
|
463 trepia_profile_set_email(profile,
|
|
464 g_hash_table_lookup(info, "e"));
|
|
465
|
|
466 /* AIM */
|
|
467 trepia_profile_set_aim(profile,
|
|
468 g_hash_table_lookup(info, "j"));
|
|
469
|
|
470 /* MSN */
|
|
471 trepia_profile_set_msn(profile,
|
|
472 g_hash_table_lookup(info, "k"));
|
|
473
|
|
474 /* Yahoo */
|
|
475 trepia_profile_set_yahoo(profile,
|
|
476 g_hash_table_lookup(info, "l"));
|
|
477
|
|
478 /* Homepage */
|
|
479 trepia_profile_set_homepage(profile,
|
|
480 g_hash_table_lookup(info, "f"));
|
|
481
|
|
482 /* Country */
|
|
483 trepia_profile_set_country(profile,
|
|
484 g_hash_table_lookup(info, "r"));
|
|
485
|
|
486 /* State */
|
|
487 trepia_profile_set_state(profile,
|
|
488 g_hash_table_lookup(info, "s"));
|
|
489
|
|
490 /* City */
|
|
491 trepia_profile_set_city(profile,
|
|
492 g_hash_table_lookup(info, "t"));
|
|
493
|
|
494 /* Languages */
|
|
495 trepia_profile_set_languages(profile,
|
|
496 g_hash_table_lookup(info, "u"));
|
|
497
|
|
498 /* School */
|
|
499 trepia_profile_set_school(profile,
|
|
500 g_hash_table_lookup(info, "v"));
|
|
501
|
|
502 /* Company */
|
|
503 trepia_profile_set_company(profile,
|
|
504 g_hash_table_lookup(info, "w"));
|
|
505
|
|
506 /* Login Name */
|
|
507 if ((value = g_hash_table_lookup(info, "d")) != NULL) {
|
|
508 serv_got_alias(session->gc, id, value);
|
|
509 trepia_profile_set_location(profile, value);
|
|
510 }
|
|
511
|
|
512 /* Buddy Icon */
|
|
513 if ((value = g_hash_table_lookup(info, "q")) != NULL) {
|
|
514 char *icon;
|
|
515 int icon_len;
|
|
516
|
|
517 frombase64(value, &icon, &icon_len);
|
|
518
|
|
519 set_icon_data(session->gc, id, icon, icon_len);
|
|
520
|
|
521 g_free(icon);
|
|
522 }
|
|
523 break;
|
|
524
|
|
525 case TREPIA_MEMBER_OFFLINE:
|
|
526 id = g_hash_table_lookup(info, "a");
|
|
527
|
|
528 b = gaim_find_buddy(account, id);
|
|
529
|
|
530 if (b != NULL)
|
|
531 serv_got_update(session->gc, id, 0, 0, 0, 0, 0);
|
|
532
|
|
533 gaim_blist_remove_buddy(b);
|
|
534
|
|
535 break;
|
|
536
|
|
537 default:
|
|
538 break;
|
|
539 }
|
|
540
|
|
541 g_hash_table_destroy(info);
|
|
542 }
|
|
543 else {
|
|
544 gaim_debug(GAIM_DEBUG_WARNING, "trepia",
|
|
545 "Unknown data received. Possibly an image?\n");
|
|
546 }
|
|
547
|
|
548 return TRUE;
|
|
549 }
|
|
550
|
|
551 static void
|
|
552 __data_cb(gpointer data, gint source, GaimInputCondition cond)
|
|
553 {
|
|
554 TrepiaSession *session = data;
|
|
555 int i = 0;
|
|
556 char buf[1025];
|
|
557 gboolean cont = TRUE;
|
|
558
|
|
559 i = read(session->fd, buf, 1024);
|
|
560
|
|
561 if (i <= 0) {
|
|
562 gaim_connection_error(session->gc, _("Read error"));
|
|
563 return;
|
|
564 }
|
|
565
|
|
566 buf[i] = '\0';
|
|
567
|
|
568 gaim_debug(GAIM_DEBUG_MISC, "trepia", "__data_cb\n");
|
|
569
|
|
570 if (session->rxqueue == NULL)
|
|
571 session->rxqueue = g_string_new(buf);
|
|
572 else
|
|
573 g_string_append(session->rxqueue, buf);
|
|
574
|
|
575 while (cont) {
|
|
576 char end_tag[5] = "</ >";
|
|
577 char *end_s;
|
|
578
|
|
579 end_tag[2] = session->rxqueue->str[1];
|
|
580
|
|
581 end_s = strstr(session->rxqueue->str, end_tag);
|
|
582
|
|
583 if (end_s != NULL) {
|
|
584 char *buffer;
|
|
585 size_t len;
|
|
586 int ret;
|
|
587
|
|
588 end_s += 4;
|
|
589
|
|
590 len = end_s - session->rxqueue->str;
|
|
591 buffer = g_new0(char, len + 1);
|
|
592 strncpy(buffer, session->rxqueue->str, len);
|
|
593
|
|
594 g_string_erase(session->rxqueue, 0, len);
|
|
595
|
|
596 if (*session->rxqueue->str == '\n')
|
|
597 g_string_erase(session->rxqueue, 0, 1);
|
|
598
|
|
599 gaim_debug(GAIM_DEBUG_MISC, "trepia", "S: %s\n", buffer);
|
|
600
|
|
601 ret = __parse_data(session, buffer);
|
|
602
|
|
603 g_free(buffer);
|
|
604 }
|
|
605 else
|
|
606 break;
|
|
607 }
|
|
608 }
|
|
609
|
|
610 static void
|
|
611 __login_cb(gpointer data, gint source, GaimInputCondition cond)
|
|
612 {
|
|
613 TrepiaSession *session = data;
|
|
614 GaimAccount *account;
|
|
615 const char *password;
|
|
616 char *buffer;
|
|
617 char *mac = "00:04:5A:50:31:DE";
|
|
618 char *gateway_mac = "00:C0:F0:52:D0:A6";
|
|
619 char buf[3];
|
|
620 char md5_password[17];
|
|
621 md5_state_t st;
|
|
622 md5_byte_t di[16];
|
|
623 int i;
|
|
624
|
|
625 #if 0
|
|
626 mac = __get_mac_address();
|
|
627 gateway_mac = mac;
|
|
628 #endif
|
|
629
|
|
630 mac = g_strdup("01:02:03:04:05:06");
|
|
631
|
|
632 gaim_debug(GAIM_DEBUG_INFO, "trepia", "__login_cb\n");
|
|
633
|
|
634 if (source < 0) {
|
|
635 gaim_debug(GAIM_DEBUG_ERROR, "trepia", "Write error.\n");
|
|
636 gaim_connection_error(session->gc, _("Write error"));
|
|
637 return;
|
|
638 }
|
|
639
|
|
640 gaim_debug(GAIM_DEBUG_ERROR, "trepia", "Past the first stage.\n");
|
|
641
|
|
642 session->fd = source;
|
|
643
|
|
644 account = gaim_connection_get_account(session->gc);
|
|
645
|
|
646 password = gaim_account_get_password(account);
|
|
647
|
|
648 md5_init(&st);
|
|
649 md5_append(&st, (const md5_byte_t *)password, strlen(password));
|
|
650 md5_finish(&st, di);
|
|
651
|
|
652 *md5_password = '\0';
|
|
653
|
|
654 for (i = 0; i < 16; i++) {
|
|
655 g_snprintf(buf, sizeof(buf), "%02x", di[i]);
|
|
656 strcat(md5_password, buf);
|
|
657 }
|
|
658
|
|
659 buffer = g_strdup_printf(
|
|
660 "<C>\n"
|
|
661 "<a>%s</a>\n"
|
|
662 "<b1>%s</b1>\n"
|
|
663 "<c>%s</c>\n"
|
|
664 "<d>%s</d>\n"
|
|
665 "<e>2.0</e>\n"
|
|
666 "</C>",
|
|
667 mac, gateway_mac, gaim_account_get_username(account),
|
|
668 md5_password);
|
|
669
|
|
670 g_free(mac);
|
|
671
|
|
672 if (trepia_write(session->fd, buffer, strlen(buffer)) < 0) {
|
|
673 gaim_connection_error(session->gc, _("Write error"));
|
|
674 return;
|
|
675 }
|
|
676
|
|
677 g_free(buffer);
|
|
678
|
|
679 session->gc->inpa = gaim_input_add(session->fd, GAIM_INPUT_READ,
|
|
680 __data_cb, session);
|
|
681 }
|
|
682
|
|
683 static void
|
|
684 trepia_login(GaimAccount *account)
|
|
685 {
|
|
686 GaimConnection *gc;
|
|
687 TrepiaSession *session;
|
|
688 const char *server;
|
|
689 int port;
|
|
690 int i;
|
|
691
|
|
692 gaim_debug(GAIM_DEBUG_INFO, "trepia", "trepia_login\n");
|
|
693
|
|
694 server = gaim_account_get_string(account, "server", TREPIA_SERVER);
|
|
695 port = gaim_account_get_int(account, "port", TREPIA_PORT);
|
|
696
|
|
697 gc = gaim_account_get_connection(account);
|
|
698
|
|
699 session = g_new0(TrepiaSession, 1);
|
|
700 gc->proto_data = session;
|
|
701 session->gc = gc;
|
|
702 session->fd = -1;
|
|
703
|
|
704 __clear_user_list(account);
|
|
705
|
|
706 gaim_debug(GAIM_DEBUG_INFO, "trepia", "connecting to proxy\n");
|
|
707
|
|
708 i = gaim_proxy_connect(account, server, port, __login_cb, session);
|
|
709
|
|
710 if (i != 0)
|
|
711 gaim_connection_error(gc, _("Unable to create socket"));
|
|
712 }
|
|
713
|
|
714 static void
|
|
715 trepia_close(GaimConnection *gc)
|
|
716 {
|
|
717 __clear_user_list(gaim_connection_get_account(gc));
|
|
718
|
|
719 gc->proto_data = NULL;
|
|
720 }
|
|
721
|
|
722 static int
|
|
723 trepia_send_im(GaimConnection *gc, const char *who, const char *message,
|
|
724 int len, int flags)
|
|
725 {
|
|
726 TrepiaSession *session = gc->proto_data;
|
|
727 char *buffer;
|
|
728
|
|
729 buffer = g_strdup_printf(
|
|
730 "<F>\n"
|
|
731 "<a>%s</a>\n"
|
|
732 "<b>%s</b>\n"
|
|
733 "</F>",
|
|
734 who, message);
|
|
735
|
|
736 if (trepia_write(session->fd, buffer, strlen(buffer)) < 0) {
|
|
737 gaim_connection_error(gc, _("Write error"));
|
|
738 g_free(buffer);
|
|
739 return 1;
|
|
740 }
|
|
741
|
|
742 return 1;
|
|
743 }
|
|
744
|
|
745 static void
|
|
746 trepia_add_buddy(GaimConnection *gc, const char *name)
|
|
747 {
|
|
748 }
|
|
749
|
|
750 static void
|
|
751 trepia_rem_buddy(GaimConnection *gc, char *who, char *group)
|
|
752 {
|
|
753 }
|
|
754
|
|
755 static void
|
|
756 trepia_buddy_free(struct buddy *b)
|
|
757 {
|
|
758 if (b->proto_data != NULL) {
|
|
759 trepia_profile_destroy(b->proto_data);
|
|
760
|
|
761 b->proto_data = NULL;
|
|
762 }
|
|
763 }
|
|
764
|
|
765 static void
|
|
766 trepia_register_user(GaimAccount *account)
|
|
767 {
|
|
768 #if 0
|
|
769 char *buffer;
|
|
770
|
|
771 buffer = g_strdup_printf(
|
|
772 "<J><a>%s</a><b1>%s</b1><c>2.0</c><d>%s</d><e>%s</e>"
|
|
773 "<f>%s</f><g></g><h></h><i></i><j></j><k></k><l></l>"
|
|
774 "<m></m></J>");
|
|
775
|
|
776 #endif
|
|
777 }
|
|
778
|
|
779 static GaimPluginProtocolInfo prpl_info =
|
|
780 {
|
|
781 GAIM_PROTO_TREPIA,
|
|
782 OPT_PROTO_BUDDY_ICON,
|
|
783 NULL,
|
|
784 NULL,
|
|
785 trepia_list_icon,
|
|
786 trepia_list_emblems,
|
|
787 NULL,
|
|
788 trepia_tooltip_text,
|
|
789 NULL,
|
|
790 NULL,
|
|
791 NULL,
|
|
792 NULL,
|
|
793 trepia_login,
|
|
794 trepia_close,
|
|
795 trepia_send_im,
|
|
796 NULL,
|
|
797 NULL,
|
|
798 NULL,
|
|
799 NULL,
|
|
800 NULL,
|
|
801 NULL,
|
|
802 NULL,
|
|
803 NULL,
|
|
804 NULL,
|
|
805 NULL,
|
|
806 trepia_add_buddy,
|
|
807 NULL,
|
|
808 trepia_rem_buddy,
|
|
809 NULL,
|
|
810 NULL,
|
|
811 NULL,
|
|
812 NULL,
|
|
813 NULL,
|
|
814 NULL,
|
|
815 NULL,
|
|
816 NULL,
|
|
817 NULL,
|
|
818 NULL,
|
|
819 NULL,
|
|
820 NULL,
|
|
821 NULL,
|
|
822 trepia_register_user,
|
|
823 NULL,
|
|
824 NULL,
|
|
825 NULL,
|
|
826 NULL,
|
|
827 NULL,
|
|
828 trepia_buddy_free,
|
|
829 NULL,
|
|
830 NULL
|
|
831 };
|
|
832
|
|
833 static GaimPluginInfo info =
|
|
834 {
|
|
835 2, /**< api_version */
|
|
836 GAIM_PLUGIN_PROTOCOL, /**< type */
|
|
837 NULL, /**< ui_requirement */
|
|
838 0, /**< flags */
|
|
839 NULL, /**< dependencies */
|
|
840 GAIM_PRIORITY_DEFAULT, /**< priority */
|
|
841
|
|
842 "prpl-trepia", /**< id */
|
|
843 "Trepia", /**< name */
|
|
844 VERSION, /**< version */
|
|
845 /** summary */
|
|
846 N_("Trepia Protocol Plugin"),
|
|
847 /** description */
|
|
848 N_("Trepia Protocol Plugin"),
|
|
849 "Christian Hammond <chipx86@gnupdate.org>", /**< author */
|
|
850 WEBSITE, /**< homepage */
|
|
851
|
|
852 NULL, /**< load */
|
|
853 NULL, /**< unload */
|
|
854 NULL, /**< destroy */
|
|
855
|
|
856 NULL, /**< ui_info */
|
|
857 &prpl_info /**< extra_info */
|
|
858 };
|
|
859
|
|
860 static void
|
|
861 __init_plugin(GaimPlugin *plugin)
|
|
862 {
|
|
863 GaimAccountOption *option;
|
|
864
|
|
865 option = gaim_account_option_string_new(_("Login server"), "server",
|
|
866 TREPIA_SERVER);
|
|
867 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
|
|
868 option);
|
|
869
|
|
870 option = gaim_account_option_int_new(_("Port"), "port", TREPIA_PORT);
|
|
871 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
|
|
872 option);
|
|
873
|
|
874 my_protocol = plugin;
|
|
875 }
|
|
876
|
|
877 GAIM_INIT_PLUGIN(trepia, __init_plugin, info);
|