Wed, 04 Jun 2003 08:59:33 +0000
[gaim-migrate @ 6169]
This should fix the infinite loop on disconnect in Trepia.
| 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 | { | |
|
5736
9da8189897a5
[gaim-migrate @ 6160]
Christian Hammond <chipx86@chipx86.com>
parents:
5735
diff
changeset
|
113 | #if 0 |
| 5730 | 114 | char *mac = NULL; |
| 115 | #ifndef _WIN32 | |
| 116 | struct sockaddr_in sin = { 0 }; | |
| 117 | struct arpreq myarp = { { 0 } }; | |
| 118 | int sockfd; | |
| 119 | unsigned char *ptr; | |
| 120 | ||
| 121 | sin.sin_family = AF_INET; | |
| 122 | ||
| 123 | if (inet_aton(ip, &sin.sin_addr) == 0) { | |
| 124 | gaim_debug(GAIM_DEBUG_ERROR, "trepia", "Invalid IP address %s\n", ip); | |
| 125 | return NULL; | |
| 126 | } | |
| 127 | ||
| 128 | memcpy(&myarp.arp_pa, &sin, sizeof(myarp.arp_pa)); | |
| 129 | strcpy(myarp.arp_dev, "eth0"); | |
| 130 | ||
| 131 | if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { | |
| 132 | gaim_debug(GAIM_DEBUG_ERROR, "trepia", | |
| 133 | "Cannot open socket for retrieving MAC address.\n"); | |
| 134 | return NULL; | |
| 135 | } | |
| 136 | ||
| 137 | if (ioctl(sockfd, SIOCGARP, &myarp) == -1) { | |
| 138 | gaim_debug(GAIM_DEBUG_ERROR, "trepia", | |
| 139 | "No entry in in arp_cache for %s\n", ip); | |
| 140 | return NULL; | |
| 141 | } | |
| 142 | ||
| 143 | ptr = &myarp.arp_ha.sa_data[0]; | |
| 144 | ||
| 145 | mac = g_strdup_printf("%x:%x:%x:%x:%x:%x", | |
| 146 | ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]); | |
| 147 | #else | |
| 148 | #endif | |
| 149 | ||
| 150 | return mac; | |
|
5736
9da8189897a5
[gaim-migrate @ 6160]
Christian Hammond <chipx86@chipx86.com>
parents:
5735
diff
changeset
|
151 | #endif |
|
9da8189897a5
[gaim-migrate @ 6160]
Christian Hammond <chipx86@chipx86.com>
parents:
5735
diff
changeset
|
152 | |
|
9da8189897a5
[gaim-migrate @ 6160]
Christian Hammond <chipx86@chipx86.com>
parents:
5735
diff
changeset
|
153 | return NULL; |
| 5730 | 154 | } |
| 155 | ||
| 156 | /************************************************************************** | |
| 157 | * Protocol Plugin ops | |
| 158 | **************************************************************************/ | |
| 159 | ||
| 160 | static const char * | |
| 161 | trepia_list_icon(GaimAccount *a, struct buddy *b) | |
| 162 | { | |
| 163 | return "trepia"; | |
| 164 | } | |
| 165 | ||
| 166 | static void | |
| 167 | trepia_list_emblems(struct buddy *b, char **se, char **sw, | |
| 168 | char **nw, char **ne) | |
| 169 | { | |
| 170 | TrepiaProfile *profile = (TrepiaProfile *)b->proto_data; | |
| 171 | ||
| 172 | if (trepia_profile_get_sex(profile) == 'M') | |
| 173 | *sw = "male"; | |
| 174 | else if (trepia_profile_get_sex(profile)) | |
| 175 | *sw = "female"; | |
| 176 | } | |
| 177 | ||
| 178 | static char * | |
| 179 | trepia_status_text(struct buddy *b) | |
| 180 | { | |
|
5731
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
181 | TrepiaProfile *profile = (TrepiaProfile *)b->proto_data; |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
182 | const char *value; |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
183 | char *text = NULL; |
|
5731
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
184 | |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
185 | gaim_debug(GAIM_DEBUG_INFO, "trepia", "trepia_status_text\n"); |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
186 | gaim_debug(GAIM_DEBUG_MISC, "trepia", "profile = '%s'\n", |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
187 | trepia_profile_get_profile(profile)); |
|
5731
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
188 | |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
189 | if ((value = trepia_profile_get_profile(profile)) != NULL) |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
190 | text = g_strdup(value); |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
191 | |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
192 | return text; |
| 5730 | 193 | } |
| 194 | ||
| 195 | static char * | |
| 196 | trepia_tooltip_text(struct buddy *b) | |
| 197 | { | |
|
5731
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
198 | TrepiaProfile *profile = (TrepiaProfile *)b->proto_data; |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
199 | const char *value; |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
200 | const char *first_name, *last_name; |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
201 | int int_value; |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
202 | char *text = NULL; |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
203 | char *tmp, *tmp2; |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
204 | |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
205 | text = g_strdup(""); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
206 | |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
207 | first_name = trepia_profile_get_first_name(profile); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
208 | last_name = trepia_profile_get_last_name(profile); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
209 | |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
210 | if (first_name != NULL || last_name != NULL) { |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
211 | tmp = g_strdup_printf("<b>Name:</b> %s%s%s\n", |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
212 | (first_name == NULL ? "" : first_name), |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
213 | (first_name == NULL ? "" : " "), |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
214 | (last_name == NULL ? "" : last_name)); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
215 | |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
216 | tmp2 = g_strconcat(text, tmp, NULL); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
217 | g_free(tmp); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
218 | g_free(text); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
219 | text = tmp2; |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
220 | } |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
221 | |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
222 | if ((int_value = trepia_profile_get_age(profile)) != 0) { |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
223 | tmp = g_strdup_printf("<b>Age:</b> %d\n", int_value); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
224 | |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
225 | tmp2 = g_strconcat(text, tmp, NULL); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
226 | g_free(tmp); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
227 | g_free(text); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
228 | text = tmp2; |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
229 | } |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
230 | |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
231 | tmp = g_strdup_printf("<b>Gender:</b> %s\n", |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
232 | (trepia_profile_get_sex(profile) == 'F' ? "Female" : "Male")); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
233 | |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
234 | tmp2 = g_strconcat(text, tmp, NULL); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
235 | g_free(tmp); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
236 | g_free(text); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
237 | text = tmp2; |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
238 | |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
239 | if ((value = trepia_profile_get_city(profile)) != NULL) { |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
240 | tmp = g_strdup_printf("<b>City:</b> %s\n", value); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
241 | |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
242 | tmp2 = g_strconcat(text, tmp, NULL); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
243 | g_free(tmp); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
244 | g_free(text); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
245 | text = tmp2; |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
246 | } |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
247 | |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
248 | if ((value = trepia_profile_get_state(profile)) != NULL) { |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
249 | tmp = g_strdup_printf("<b>State:</b> %s\n", value); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
250 | |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
251 | tmp2 = g_strconcat(text, tmp, NULL); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
252 | g_free(tmp); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
253 | g_free(text); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
254 | text = tmp2; |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
255 | } |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
256 | |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
257 | if ((value = trepia_profile_get_country(profile)) != NULL) { |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
258 | tmp = g_strdup_printf("<b>Country:</b> %s\n", value); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
259 | |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
260 | tmp2 = g_strconcat(text, tmp, NULL); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
261 | g_free(tmp); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
262 | g_free(text); |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
263 | text = tmp2; |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
264 | } |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
265 | |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
266 | if ((value = trepia_profile_get_profile(profile)) != NULL) { |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
267 | tmp = g_strdup_printf("<b>Profile:</b> %s\n", value); |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
268 | |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
269 | tmp2 = g_strconcat(text, tmp, NULL); |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
270 | g_free(tmp); |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
271 | g_free(text); |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
272 | text = tmp2; |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
273 | } |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
274 | |
|
5732
b7ca6636c6c4
[gaim-migrate @ 6156]
Christian Hammond <chipx86@chipx86.com>
parents:
5731
diff
changeset
|
275 | text[strlen(text) - 1] = '\0'; |
|
5731
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
276 | |
|
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
277 | return text; |
| 5730 | 278 | } |
| 279 | ||
| 280 | static void | |
| 281 | __free_parser_data(gpointer user_data) | |
| 282 | { | |
| 283 | return; | |
| 284 | ||
| 285 | TrepiaParserData *data = user_data; | |
| 286 | ||
| 287 | if (data->buffer != NULL) | |
| 288 | g_string_free(data->buffer, TRUE); | |
| 289 | ||
| 290 | if (data->tag != NULL) | |
| 291 | g_free(data->tag); | |
| 292 | ||
| 293 | g_free(data); | |
| 294 | } | |
| 295 | ||
| 296 | static void | |
| 297 | __start_element_handler(GMarkupParseContext *context, | |
| 298 | const gchar *element_name, | |
| 299 | const gchar **attribute_names, | |
| 300 | const gchar **attribute_values, | |
| 301 | gpointer user_data, GError **error) | |
| 302 | { | |
| 303 | TrepiaParserData *data = user_data; | |
| 304 | ||
| 305 | if (data->buffer != NULL) { | |
| 306 | g_string_free(data->buffer, TRUE); | |
| 307 | data->buffer = NULL; | |
| 308 | } | |
| 309 | ||
| 310 | if (*data->type == 0) { | |
| 311 | *data->type = *element_name; | |
| 312 | } | |
| 313 | else { | |
| 314 | data->tag = g_strdup(element_name); | |
| 315 | } | |
| 316 | } | |
| 317 | ||
| 318 | static void | |
| 319 | __end_element_handler(GMarkupParseContext *context, const gchar *element_name, | |
| 320 | gpointer user_data, GError **error) | |
| 321 | { | |
| 322 | TrepiaParserData *data = user_data; | |
| 323 | gchar *buffer; | |
| 324 | ||
| 325 | if (*element_name == *data->type) | |
| 326 | return; | |
| 327 | ||
| 328 | if (data->buffer == NULL || data->tag == NULL) { | |
| 329 | data->tag = NULL; | |
| 330 | return; | |
| 331 | } | |
| 332 | ||
| 333 | buffer = g_string_free(data->buffer, FALSE); | |
| 334 | data->buffer = NULL; | |
| 335 | ||
| 336 | g_hash_table_insert(data->keys, data->tag, buffer); | |
| 337 | ||
| 338 | data->tag = NULL; | |
| 339 | } | |
| 340 | ||
| 341 | static void | |
| 342 | __text_handler(GMarkupParseContext *context, const gchar *text, | |
| 343 | gsize text_len, gpointer user_data, GError **error) | |
| 344 | { | |
| 345 | TrepiaParserData *data = user_data; | |
| 346 | ||
| 347 | if (data->buffer == NULL) | |
| 348 | data->buffer = g_string_new_len(text, text_len); | |
| 349 | else | |
| 350 | g_string_append_len(data->buffer, text, text_len); | |
| 351 | } | |
| 352 | ||
| 353 | static GMarkupParser accounts_parser = | |
| 354 | { | |
| 355 | __start_element_handler, | |
| 356 | __end_element_handler, | |
| 357 | __text_handler, | |
| 358 | NULL, | |
| 359 | NULL | |
| 360 | }; | |
| 361 | ||
| 362 | static int | |
| 363 | __parse_message(const char *buf, TrepiaMessageType *type, GHashTable **info) | |
| 364 | { | |
| 365 | TrepiaParserData *parser_data = g_new0(TrepiaParserData, 1); | |
| 366 | GMarkupParseContext *context; | |
| 367 | GHashTable *keys; | |
| 368 | ||
| 369 | keys = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
| 370 | parser_data->keys = keys; | |
| 371 | parser_data->type = type; | |
| 372 | ||
| 373 | context = g_markup_parse_context_new(&accounts_parser, 0, | |
| 374 | parser_data, __free_parser_data); | |
| 375 | ||
| 376 | if (!g_markup_parse_context_parse(context, buf, strlen(buf), NULL)) { | |
| 377 | g_markup_parse_context_free(context); | |
| 378 | g_free(parser_data); | |
| 379 | g_hash_table_destroy(keys); | |
| 380 | ||
| 381 | return 1; | |
| 382 | } | |
| 383 | ||
| 384 | if (!g_markup_parse_context_end_parse(context, NULL)) { | |
| 385 | g_markup_parse_context_free(context); | |
| 386 | g_free(parser_data); | |
| 387 | g_hash_table_destroy(keys); | |
| 388 | ||
| 389 | return 1; | |
| 390 | } | |
| 391 | ||
| 392 | g_markup_parse_context_free(context); | |
| 393 | ||
| 394 | *info = keys; | |
| 395 | ||
| 396 | return 0; | |
| 397 | } | |
| 398 | ||
| 399 | static gboolean | |
| 400 | __parse_data(TrepiaSession *session, char *buf) | |
| 401 | { | |
| 402 | GHashTable *info; | |
| 403 | GaimAccount *account; | |
| 404 | TrepiaMessageType type = 0; | |
| 405 | TrepiaProfile *profile; | |
| 406 | int ret; | |
| 407 | char *buffer; | |
| 408 | struct buddy *b; | |
| 409 | const char *id = NULL; | |
| 410 | const char *value; | |
| 411 | ||
| 412 | account = gaim_connection_get_account(session->gc); | |
| 413 | ||
| 414 | ret = __parse_message(buf, &type, &info); | |
| 415 | ||
| 416 | if (ret == 1) | |
| 417 | return TRUE; | |
| 418 | ||
| 419 | gaim_debug(GAIM_DEBUG_INFO, "trepia", "Successful parse.\n"); | |
| 420 | gaim_debug(GAIM_DEBUG_INFO, "trepia", "Message type: %c\n", | |
| 421 | type); | |
| 422 | ||
| 423 | if (info != NULL) { | |
| 424 | switch (type) { | |
| 425 | case TREPIA_USER_LIST: | |
| 426 | gaim_debug(GAIM_DEBUG_INFO, "trepia", | |
| 427 | "Signon complete. Showing buddy list.\n"); | |
| 428 | gaim_connection_set_state(session->gc, GAIM_CONNECTED); | |
| 429 | serv_finish_login(session->gc); | |
| 430 | break; | |
| 431 | ||
| 432 | case TREPIA_MSG_INCOMING: /* Incoming Message */ | |
| 433 | gaim_debug(GAIM_DEBUG_INFO, "trepia", "Receiving message\n"); | |
| 434 | serv_got_im(session->gc, | |
| 435 | (char *)g_hash_table_lookup(info, "a"), | |
| 436 | (char *)g_hash_table_lookup(info, "b"), | |
| 437 | 0, time(NULL), -1); | |
| 438 | break; | |
| 439 | ||
| 440 | case TREPIA_MEMBER_UPDATE: | |
| 441 | id = g_hash_table_lookup(info, "a"); | |
| 442 | b = gaim_find_buddy(account, id); | |
| 443 | ||
| 444 | if (b == NULL) { | |
| 445 | struct group *g; | |
| 446 | ||
| 447 | g = gaim_find_group(_("Local Users")); | |
| 448 | ||
| 449 | if (g == NULL) { | |
| 450 | g = gaim_group_new(_("Local Users")); | |
| 451 | gaim_blist_add_group(g, NULL); | |
| 452 | } | |
| 453 | ||
| 454 | b = gaim_buddy_new(account, id, NULL); | |
| 455 | ||
| 456 | gaim_blist_add_buddy(b, g, NULL); | |
| 457 | } | |
| 458 | ||
| 459 | b->proto_data = trepia_profile_new(); | |
| 460 | ||
| 461 | serv_got_update(session->gc, id, 1, 0, 0, 0, 0); | |
| 462 | ||
| 463 | buffer = g_strdup_printf( | |
| 464 | "<D>\n" | |
| 465 | "<a>%s</a>\n" | |
| 466 | "<b>1</b>\n" | |
| 467 | "</D>", | |
| 468 | id); | |
| 469 | ||
| 470 | if (trepia_write(session->fd, buffer, strlen(buffer)) < 0) { | |
| 471 | gaim_connection_error(session->gc, _("Write error")); | |
| 472 | g_free(buffer); | |
| 473 | return 1; | |
| 474 | } | |
| 475 | ||
| 476 | buffer = g_strdup_printf( | |
| 477 | "<D>\n" | |
| 478 | "<a>%s</a>\n" | |
| 479 | "<b>2</b>\n" | |
| 480 | "</D>", | |
| 481 | id); | |
| 482 | ||
| 483 | if (trepia_write(session->fd, buffer, strlen(buffer)) < 0) { | |
| 484 | gaim_connection_error(session->gc, _("Write error")); | |
| 485 | g_free(buffer); | |
| 486 | return 1; | |
| 487 | } | |
| 488 | ||
| 489 | g_free(buffer); | |
| 490 | break; | |
| 491 | ||
| 492 | case TREPIA_MEMBER_PROFILE: | |
| 493 | id = g_hash_table_lookup(info, "a"); | |
| 494 | b = gaim_find_buddy(account, id); | |
| 495 | ||
| 496 | if (b == NULL) | |
| 497 | break; | |
| 498 | ||
| 499 | profile = b->proto_data; | |
| 500 | ||
| 501 | /* ID */ | |
| 502 | trepia_profile_set_id(profile, atoi(id)); | |
| 503 | ||
| 504 | /* Login Time */ | |
| 505 | if ((value = g_hash_table_lookup(info, "b")) != NULL) | |
| 506 | trepia_profile_set_login_time(profile, atoi(value)); | |
| 507 | ||
| 508 | /* Age */ | |
| 509 | if ((value = g_hash_table_lookup(info, "m")) != NULL) | |
| 510 | trepia_profile_set_age(profile, atoi(value)); | |
| 511 | ||
| 512 | /* ICQ */ | |
| 513 | if ((value = g_hash_table_lookup(info, "i")) != NULL) | |
| 514 | trepia_profile_set_icq(profile, atoi(value)); | |
| 515 | ||
| 516 | /* Sex */ | |
| 517 | if ((value = g_hash_table_lookup(info, "n")) != NULL) | |
| 518 | trepia_profile_set_sex(profile, *value); | |
| 519 | ||
| 520 | /* Location */ | |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
521 | if ((value = g_hash_table_lookup(info, "p")) != NULL) |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
522 | trepia_profile_set_location(profile, value); |
| 5730 | 523 | |
| 524 | /* First Name */ | |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
525 | if ((value = g_hash_table_lookup(info, "g")) != NULL) |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
526 | trepia_profile_set_first_name(profile, value); |
| 5730 | 527 | |
| 528 | /* Last Name */ | |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
529 | if ((value = g_hash_table_lookup(info, "h")) != NULL) |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
530 | trepia_profile_set_last_name(profile, value); |
| 5730 | 531 | |
| 532 | /* Profile */ | |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
533 | if ((value = g_hash_table_lookup(info, "o")) != NULL) |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
534 | trepia_profile_set_profile(profile, value); |
| 5730 | 535 | |
| 536 | /* E-mail */ | |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
537 | if ((value = g_hash_table_lookup(info, "e")) != NULL) |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
538 | trepia_profile_set_email(profile, value); |
| 5730 | 539 | |
| 540 | /* AIM */ | |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
541 | if ((value = g_hash_table_lookup(info, "j")) != NULL) |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
542 | trepia_profile_set_aim(profile, value); |
| 5730 | 543 | |
| 544 | /* MSN */ | |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
545 | if ((value = g_hash_table_lookup(info, "k")) != NULL) |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
546 | trepia_profile_set_msn(profile, value); |
| 5730 | 547 | |
| 548 | /* Yahoo */ | |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
549 | if ((value = g_hash_table_lookup(info, "l")) != NULL) |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
550 | trepia_profile_set_yahoo(profile, value); |
| 5730 | 551 | |
| 552 | /* Homepage */ | |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
553 | if ((value = g_hash_table_lookup(info, "f")) != NULL) |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
554 | trepia_profile_set_homepage(profile, value); |
| 5730 | 555 | |
| 556 | /* Country */ | |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
557 | if ((value = g_hash_table_lookup(info, "r")) != NULL) |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
558 | trepia_profile_set_country(profile, value); |
| 5730 | 559 | |
| 560 | /* State */ | |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
561 | if ((value = g_hash_table_lookup(info, "s")) != NULL) |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
562 | trepia_profile_set_state(profile, value); |
| 5730 | 563 | |
| 564 | /* City */ | |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
565 | if ((value = g_hash_table_lookup(info, "t")) != NULL) |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
566 | trepia_profile_set_city(profile, value); |
| 5730 | 567 | |
| 568 | /* Languages */ | |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
569 | if ((value = g_hash_table_lookup(info, "u")) != NULL) |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
570 | trepia_profile_set_languages(profile, value); |
| 5730 | 571 | |
| 572 | /* School */ | |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
573 | if ((value = g_hash_table_lookup(info, "v")) != NULL) |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
574 | trepia_profile_set_school(profile, value); |
| 5730 | 575 | |
| 576 | /* Company */ | |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
577 | if ((value = g_hash_table_lookup(info, "w")) != NULL) |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
578 | trepia_profile_set_company(profile, value); |
| 5730 | 579 | |
| 580 | /* Login Name */ | |
| 581 | if ((value = g_hash_table_lookup(info, "d")) != NULL) { | |
| 582 | serv_got_alias(session->gc, id, value); | |
| 583 | trepia_profile_set_location(profile, value); | |
| 584 | } | |
| 585 | ||
| 586 | /* Buddy Icon */ | |
| 587 | if ((value = g_hash_table_lookup(info, "q")) != NULL) { | |
| 588 | char *icon; | |
| 589 | int icon_len; | |
| 590 | ||
| 591 | frombase64(value, &icon, &icon_len); | |
| 592 | ||
| 593 | set_icon_data(session->gc, id, icon, icon_len); | |
| 594 | ||
| 595 | g_free(icon); | |
| 596 | } | |
|
5735
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
597 | |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
598 | gaim_debug(GAIM_DEBUG_INFO, "trepia", "Calling serv_got_update\n"); |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
599 | serv_got_update(session->gc, id, 1, 0, |
|
e3583263f94d
[gaim-migrate @ 6159]
Christian Hammond <chipx86@chipx86.com>
parents:
5732
diff
changeset
|
600 | trepia_profile_get_login_time(profile), 0, 0); |
| 5730 | 601 | break; |
| 602 | ||
| 603 | case TREPIA_MEMBER_OFFLINE: | |
| 604 | id = g_hash_table_lookup(info, "a"); | |
| 605 | ||
| 606 | b = gaim_find_buddy(account, id); | |
| 607 | ||
| 608 | if (b != NULL) | |
| 609 | serv_got_update(session->gc, id, 0, 0, 0, 0, 0); | |
| 610 | ||
| 611 | gaim_blist_remove_buddy(b); | |
| 612 | ||
| 613 | break; | |
| 614 | ||
| 615 | default: | |
| 616 | break; | |
| 617 | } | |
| 618 | ||
| 619 | g_hash_table_destroy(info); | |
| 620 | } | |
| 621 | else { | |
| 622 | gaim_debug(GAIM_DEBUG_WARNING, "trepia", | |
| 623 | "Unknown data received. Possibly an image?\n"); | |
| 624 | } | |
| 625 | ||
| 626 | return TRUE; | |
| 627 | } | |
| 628 | ||
| 629 | static void | |
| 630 | __data_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 631 | { | |
| 632 | TrepiaSession *session = data; | |
| 633 | int i = 0; | |
| 634 | char buf[1025]; | |
| 635 | gboolean cont = TRUE; | |
| 636 | ||
| 637 | i = read(session->fd, buf, 1024); | |
| 638 | ||
| 639 | if (i <= 0) { | |
| 640 | gaim_connection_error(session->gc, _("Read error")); | |
| 641 | return; | |
| 642 | } | |
| 643 | ||
| 644 | buf[i] = '\0'; | |
| 645 | ||
| 646 | gaim_debug(GAIM_DEBUG_MISC, "trepia", "__data_cb\n"); | |
| 647 | ||
| 648 | if (session->rxqueue == NULL) | |
| 649 | session->rxqueue = g_string_new(buf); | |
| 650 | else | |
| 651 | g_string_append(session->rxqueue, buf); | |
| 652 | ||
| 653 | while (cont) { | |
| 654 | char end_tag[5] = "</ >"; | |
| 655 | char *end_s; | |
| 656 | ||
| 657 | end_tag[2] = session->rxqueue->str[1]; | |
| 658 | ||
| 659 | end_s = strstr(session->rxqueue->str, end_tag); | |
| 660 | ||
| 661 | if (end_s != NULL) { | |
| 662 | char *buffer; | |
| 663 | size_t len; | |
| 664 | int ret; | |
| 665 | ||
| 666 | end_s += 4; | |
| 667 | ||
| 668 | len = end_s - session->rxqueue->str; | |
| 669 | buffer = g_new0(char, len + 1); | |
| 670 | strncpy(buffer, session->rxqueue->str, len); | |
| 671 | ||
| 672 | g_string_erase(session->rxqueue, 0, len); | |
| 673 | ||
| 674 | if (*session->rxqueue->str == '\n') | |
| 675 | g_string_erase(session->rxqueue, 0, 1); | |
| 676 | ||
| 677 | gaim_debug(GAIM_DEBUG_MISC, "trepia", "S: %s\n", buffer); | |
| 678 | ||
| 679 | ret = __parse_data(session, buffer); | |
| 680 | ||
| 681 | g_free(buffer); | |
| 682 | } | |
| 683 | else | |
| 684 | break; | |
| 685 | } | |
| 686 | } | |
| 687 | ||
| 688 | static void | |
| 689 | __login_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 690 | { | |
| 691 | TrepiaSession *session = data; | |
| 692 | GaimAccount *account; | |
| 693 | const char *password; | |
| 694 | char *buffer; | |
| 695 | char *mac = "00:04:5A:50:31:DE"; | |
| 696 | char *gateway_mac = "00:C0:F0:52:D0:A6"; | |
| 697 | char buf[3]; | |
| 698 | char md5_password[17]; | |
| 699 | md5_state_t st; | |
| 700 | md5_byte_t di[16]; | |
| 701 | int i; | |
| 702 | ||
| 703 | #if 0 | |
| 704 | mac = __get_mac_address(); | |
| 705 | gateway_mac = mac; | |
| 706 | #endif | |
| 707 | ||
| 708 | mac = g_strdup("01:02:03:04:05:06"); | |
| 709 | ||
| 710 | gaim_debug(GAIM_DEBUG_INFO, "trepia", "__login_cb\n"); | |
| 711 | ||
| 712 | if (source < 0) { | |
| 713 | gaim_debug(GAIM_DEBUG_ERROR, "trepia", "Write error.\n"); | |
| 714 | gaim_connection_error(session->gc, _("Write error")); | |
| 715 | return; | |
| 716 | } | |
| 717 | ||
| 718 | gaim_debug(GAIM_DEBUG_ERROR, "trepia", "Past the first stage.\n"); | |
| 719 | ||
| 720 | session->fd = source; | |
| 721 | ||
| 722 | account = gaim_connection_get_account(session->gc); | |
| 723 | ||
| 724 | password = gaim_account_get_password(account); | |
| 725 | ||
| 726 | md5_init(&st); | |
| 727 | md5_append(&st, (const md5_byte_t *)password, strlen(password)); | |
| 728 | md5_finish(&st, di); | |
| 729 | ||
| 730 | *md5_password = '\0'; | |
| 731 | ||
| 732 | for (i = 0; i < 16; i++) { | |
| 733 | g_snprintf(buf, sizeof(buf), "%02x", di[i]); | |
| 734 | strcat(md5_password, buf); | |
| 735 | } | |
| 736 | ||
| 737 | buffer = g_strdup_printf( | |
| 738 | "<C>\n" | |
| 739 | "<a>%s</a>\n" | |
| 740 | "<b1>%s</b1>\n" | |
| 741 | "<c>%s</c>\n" | |
| 742 | "<d>%s</d>\n" | |
| 743 | "<e>2.0</e>\n" | |
| 744 | "</C>", | |
| 745 | mac, gateway_mac, gaim_account_get_username(account), | |
| 746 | md5_password); | |
| 747 | ||
| 748 | g_free(mac); | |
| 749 | ||
| 750 | if (trepia_write(session->fd, buffer, strlen(buffer)) < 0) { | |
| 751 | gaim_connection_error(session->gc, _("Write error")); | |
| 752 | return; | |
| 753 | } | |
| 754 | ||
| 755 | g_free(buffer); | |
| 756 | ||
| 757 | session->gc->inpa = gaim_input_add(session->fd, GAIM_INPUT_READ, | |
| 758 | __data_cb, session); | |
| 759 | } | |
| 760 | ||
| 761 | static void | |
| 762 | trepia_login(GaimAccount *account) | |
| 763 | { | |
| 764 | GaimConnection *gc; | |
| 765 | TrepiaSession *session; | |
| 766 | const char *server; | |
| 767 | int port; | |
| 768 | int i; | |
| 769 | ||
| 770 | gaim_debug(GAIM_DEBUG_INFO, "trepia", "trepia_login\n"); | |
| 771 | ||
| 772 | server = gaim_account_get_string(account, "server", TREPIA_SERVER); | |
| 773 | port = gaim_account_get_int(account, "port", TREPIA_PORT); | |
| 774 | ||
| 775 | gc = gaim_account_get_connection(account); | |
| 776 | ||
| 777 | session = g_new0(TrepiaSession, 1); | |
| 778 | gc->proto_data = session; | |
| 779 | session->gc = gc; | |
| 780 | session->fd = -1; | |
| 781 | ||
| 782 | __clear_user_list(account); | |
| 783 | ||
| 784 | gaim_debug(GAIM_DEBUG_INFO, "trepia", "connecting to proxy\n"); | |
| 785 | ||
| 786 | i = gaim_proxy_connect(account, server, port, __login_cb, session); | |
| 787 | ||
| 788 | if (i != 0) | |
| 789 | gaim_connection_error(gc, _("Unable to create socket")); | |
| 790 | } | |
| 791 | ||
| 792 | static void | |
| 793 | trepia_close(GaimConnection *gc) | |
| 794 | { | |
|
5745
0263593cf0ce
[gaim-migrate @ 6169]
Christian Hammond <chipx86@chipx86.com>
parents:
5739
diff
changeset
|
795 | TrepiaSession *session = gc->proto_data; |
|
0263593cf0ce
[gaim-migrate @ 6169]
Christian Hammond <chipx86@chipx86.com>
parents:
5739
diff
changeset
|
796 | |
| 5730 | 797 | __clear_user_list(gaim_connection_get_account(gc)); |
| 798 | ||
|
5745
0263593cf0ce
[gaim-migrate @ 6169]
Christian Hammond <chipx86@chipx86.com>
parents:
5739
diff
changeset
|
799 | if (session->rxqueue != NULL) |
|
0263593cf0ce
[gaim-migrate @ 6169]
Christian Hammond <chipx86@chipx86.com>
parents:
5739
diff
changeset
|
800 | g_string_free(session->rxqueue, TRUE); |
|
0263593cf0ce
[gaim-migrate @ 6169]
Christian Hammond <chipx86@chipx86.com>
parents:
5739
diff
changeset
|
801 | |
|
0263593cf0ce
[gaim-migrate @ 6169]
Christian Hammond <chipx86@chipx86.com>
parents:
5739
diff
changeset
|
802 | if (session->inpa) |
|
0263593cf0ce
[gaim-migrate @ 6169]
Christian Hammond <chipx86@chipx86.com>
parents:
5739
diff
changeset
|
803 | gaim_input_remove(session->inpa); |
|
0263593cf0ce
[gaim-migrate @ 6169]
Christian Hammond <chipx86@chipx86.com>
parents:
5739
diff
changeset
|
804 | |
|
0263593cf0ce
[gaim-migrate @ 6169]
Christian Hammond <chipx86@chipx86.com>
parents:
5739
diff
changeset
|
805 | close(session->fd); |
|
0263593cf0ce
[gaim-migrate @ 6169]
Christian Hammond <chipx86@chipx86.com>
parents:
5739
diff
changeset
|
806 | |
|
0263593cf0ce
[gaim-migrate @ 6169]
Christian Hammond <chipx86@chipx86.com>
parents:
5739
diff
changeset
|
807 | g_free(session); |
|
5739
b070eb327624
[gaim-migrate @ 6163]
Christian Hammond <chipx86@chipx86.com>
parents:
5737
diff
changeset
|
808 | |
| 5730 | 809 | gc->proto_data = NULL; |
| 810 | } | |
| 811 | ||
| 812 | static int | |
| 813 | trepia_send_im(GaimConnection *gc, const char *who, const char *message, | |
| 814 | int len, int flags) | |
| 815 | { | |
| 816 | TrepiaSession *session = gc->proto_data; | |
|
5737
70be0426f186
[gaim-migrate @ 6161]
Christian Hammond <chipx86@chipx86.com>
parents:
5736
diff
changeset
|
817 | char *escaped_msg; |
| 5730 | 818 | char *buffer; |
| 819 | ||
|
5737
70be0426f186
[gaim-migrate @ 6161]
Christian Hammond <chipx86@chipx86.com>
parents:
5736
diff
changeset
|
820 | escaped_msg = g_markup_escape_text(message, -1); |
|
70be0426f186
[gaim-migrate @ 6161]
Christian Hammond <chipx86@chipx86.com>
parents:
5736
diff
changeset
|
821 | |
| 5730 | 822 | buffer = g_strdup_printf( |
| 823 | "<F>\n" | |
| 824 | "<a>%s</a>\n" | |
| 825 | "<b>%s</b>\n" | |
| 826 | "</F>", | |
|
5737
70be0426f186
[gaim-migrate @ 6161]
Christian Hammond <chipx86@chipx86.com>
parents:
5736
diff
changeset
|
827 | who, escaped_msg); |
|
70be0426f186
[gaim-migrate @ 6161]
Christian Hammond <chipx86@chipx86.com>
parents:
5736
diff
changeset
|
828 | |
|
70be0426f186
[gaim-migrate @ 6161]
Christian Hammond <chipx86@chipx86.com>
parents:
5736
diff
changeset
|
829 | g_free(escaped_msg); |
| 5730 | 830 | |
| 831 | if (trepia_write(session->fd, buffer, strlen(buffer)) < 0) { | |
| 832 | gaim_connection_error(gc, _("Write error")); | |
| 833 | g_free(buffer); | |
| 834 | return 1; | |
| 835 | } | |
| 836 | ||
| 837 | return 1; | |
| 838 | } | |
| 839 | ||
| 840 | static void | |
| 841 | trepia_add_buddy(GaimConnection *gc, const char *name) | |
| 842 | { | |
| 843 | } | |
| 844 | ||
| 845 | static void | |
| 846 | trepia_rem_buddy(GaimConnection *gc, char *who, char *group) | |
| 847 | { | |
| 848 | } | |
| 849 | ||
| 850 | static void | |
| 851 | trepia_buddy_free(struct buddy *b) | |
| 852 | { | |
| 853 | if (b->proto_data != NULL) { | |
| 854 | trepia_profile_destroy(b->proto_data); | |
| 855 | ||
| 856 | b->proto_data = NULL; | |
| 857 | } | |
| 858 | } | |
| 859 | ||
| 860 | static void | |
| 861 | trepia_register_user(GaimAccount *account) | |
| 862 | { | |
| 863 | #if 0 | |
| 864 | char *buffer; | |
| 865 | ||
| 866 | buffer = g_strdup_printf( | |
| 867 | "<J><a>%s</a><b1>%s</b1><c>2.0</c><d>%s</d><e>%s</e>" | |
| 868 | "<f>%s</f><g></g><h></h><i></i><j></j><k></k><l></l>" | |
| 869 | "<m></m></J>"); | |
| 870 | ||
| 871 | #endif | |
| 872 | } | |
| 873 | ||
| 874 | static GaimPluginProtocolInfo prpl_info = | |
| 875 | { | |
| 876 | GAIM_PROTO_TREPIA, | |
| 877 | OPT_PROTO_BUDDY_ICON, | |
| 878 | NULL, | |
| 879 | NULL, | |
| 880 | trepia_list_icon, | |
| 881 | trepia_list_emblems, | |
|
5731
02f3551087ca
[gaim-migrate @ 6155]
Christian Hammond <chipx86@chipx86.com>
parents:
5730
diff
changeset
|
882 | trepia_status_text, |
| 5730 | 883 | trepia_tooltip_text, |
| 884 | NULL, | |
| 885 | NULL, | |
| 886 | NULL, | |
| 887 | NULL, | |
| 888 | trepia_login, | |
| 889 | trepia_close, | |
| 890 | trepia_send_im, | |
| 891 | NULL, | |
| 892 | NULL, | |
| 893 | NULL, | |
| 894 | NULL, | |
| 895 | NULL, | |
| 896 | NULL, | |
| 897 | NULL, | |
| 898 | NULL, | |
| 899 | NULL, | |
| 900 | NULL, | |
| 901 | trepia_add_buddy, | |
| 902 | NULL, | |
| 903 | trepia_rem_buddy, | |
| 904 | NULL, | |
| 905 | NULL, | |
| 906 | NULL, | |
| 907 | NULL, | |
| 908 | NULL, | |
| 909 | NULL, | |
| 910 | NULL, | |
| 911 | NULL, | |
| 912 | NULL, | |
| 913 | NULL, | |
| 914 | NULL, | |
| 915 | NULL, | |
| 916 | NULL, | |
| 917 | trepia_register_user, | |
| 918 | NULL, | |
| 919 | NULL, | |
| 920 | NULL, | |
| 921 | NULL, | |
| 922 | NULL, | |
| 923 | trepia_buddy_free, | |
| 924 | NULL, | |
| 925 | NULL | |
| 926 | }; | |
| 927 | ||
| 928 | static GaimPluginInfo info = | |
| 929 | { | |
| 930 | 2, /**< api_version */ | |
| 931 | GAIM_PLUGIN_PROTOCOL, /**< type */ | |
| 932 | NULL, /**< ui_requirement */ | |
| 933 | 0, /**< flags */ | |
| 934 | NULL, /**< dependencies */ | |
| 935 | GAIM_PRIORITY_DEFAULT, /**< priority */ | |
| 936 | ||
| 937 | "prpl-trepia", /**< id */ | |
| 938 | "Trepia", /**< name */ | |
| 939 | VERSION, /**< version */ | |
| 940 | /** summary */ | |
| 941 | N_("Trepia Protocol Plugin"), | |
| 942 | /** description */ | |
| 943 | N_("Trepia Protocol Plugin"), | |
| 944 | "Christian Hammond <chipx86@gnupdate.org>", /**< author */ | |
| 945 | WEBSITE, /**< homepage */ | |
| 946 | ||
| 947 | NULL, /**< load */ | |
| 948 | NULL, /**< unload */ | |
| 949 | NULL, /**< destroy */ | |
| 950 | ||
| 951 | NULL, /**< ui_info */ | |
| 952 | &prpl_info /**< extra_info */ | |
| 953 | }; | |
| 954 | ||
| 955 | static void | |
| 956 | __init_plugin(GaimPlugin *plugin) | |
| 957 | { | |
| 958 | GaimAccountOption *option; | |
| 959 | ||
| 960 | option = gaim_account_option_string_new(_("Login server"), "server", | |
| 961 | TREPIA_SERVER); | |
| 962 | prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | |
| 963 | option); | |
| 964 | ||
| 965 | option = gaim_account_option_int_new(_("Port"), "port", TREPIA_PORT); | |
| 966 | prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | |
| 967 | option); | |
| 968 | ||
| 969 | my_protocol = plugin; | |
| 970 | } | |
| 971 | ||
| 972 | GAIM_INIT_PLUGIN(trepia, __init_plugin, info); |