Mercurial > pidgin.yaz
annotate src/protocols/icq/gaim_icq.c @ 4166:481c51159627
[gaim-migrate @ 4395]
Yay for Paco-Paco and ISO 8859-1 in away messages and info!!!
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 02 Jan 2003 01:18:21 +0000 |
parents | 474265997752 |
children | cd84b0fd63fc |
rev | line source |
---|---|
2086 | 1 #include <string.h> |
2 #include <stdlib.h> | |
3 #include "icq.h" /* well, we're doing ICQ, right? */ | |
4 #include "multi.h" /* needed for gaim_connection */ | |
5 #include "prpl.h" /* needed for prpl */ | |
6 #include "gaim.h" /* needed for every other damn thing */ | |
7 #include "proxy.h" | |
8 | |
3579 | 9 #include "pixmaps/protocols/icq/gnomeicu-online.xpm" |
10 #include "pixmaps/protocols/icq/gnomeicu-away.xpm" | |
11 #include "pixmaps/protocols/icq/gnomeicu-dnd.xpm" | |
12 #include "pixmaps/protocols/icq/gnomeicu-na.xpm" | |
13 #include "pixmaps/protocols/icq/gnomeicu-occ.xpm" | |
14 #include "pixmaps/protocols/icq/gnomeicu-ffc.xpm" | |
2086 | 15 |
16 #define USEROPT_NICK 0 | |
17 | |
18 struct icq_data { | |
19 icq_Link *link; | |
20 int cur_status; | |
2515
3ec36a342496
[gaim-migrate @ 2528]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
21 gboolean connected; |
2086 | 22 }; |
23 | |
24 static guint ack_timer = 0; | |
25 | |
26 static void icq_do_log(icq_Link *link, time_t time, unsigned char level, const char *log) { | |
27 debug_printf("ICQ debug %d: %s", level, log); | |
28 } | |
29 | |
30 GList *sockets = NULL; | |
31 struct gaim_sock { | |
32 int socket; | |
33 int type; | |
34 gint inpa; | |
35 }; | |
36 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
37 static void gaim_icq_handler(gpointer data, gint source, GaimInputCondition cond) { |
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
38 if (cond & GAIM_INPUT_READ) |
2086 | 39 icq_HandleReadySocket(source, ICQ_SOCKET_READ); |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
40 if (cond & GAIM_INPUT_WRITE) |
2086 | 41 icq_HandleReadySocket(source, ICQ_SOCKET_WRITE); |
42 } | |
43 | |
44 static void icq_sock_notify(int socket, int type, int status) { | |
45 struct gaim_sock *gs = NULL; | |
46 if (status) { | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
47 GaimInputCondition cond; |
2086 | 48 if (type == ICQ_SOCKET_READ) |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
49 cond = GAIM_INPUT_READ; |
2086 | 50 else |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
51 cond = GAIM_INPUT_WRITE; |
2086 | 52 gs = g_new0(struct gaim_sock, 1); |
53 gs->socket = socket; | |
54 gs->type = type; | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
55 gs->inpa = gaim_input_add(socket, cond, gaim_icq_handler, NULL); |
2086 | 56 sockets = g_list_append(sockets, gs); |
57 debug_printf("Adding socket notifier: %d %d (%d)\n", socket, type, gs->inpa); | |
58 } else { | |
59 GList *m = sockets; | |
60 while (m) { | |
61 gs = m->data; | |
62 if ((gs->socket == socket) && (gs->type == type)) | |
63 break; | |
64 m = g_list_next(m); | |
65 } | |
66 if (m) { | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
67 gaim_input_remove(gs->inpa); |
2086 | 68 sockets = g_list_remove(sockets, gs); |
69 debug_printf("Removing socket notifier: %d %d (%d)\n", socket, type, gs->inpa); | |
70 g_free(gs); | |
71 } | |
72 } | |
73 } | |
74 | |
75 static void icq_online(icq_Link *link) { | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
76 struct gaim_connection *gc = link->icq_UserData; |
2086 | 77 struct icq_data *id = (struct icq_data *)gc->proto_data; |
78 debug_printf("%s is now online.\n", gc->username); | |
2516
d379814be59e
[gaim-migrate @ 2529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2515
diff
changeset
|
79 if (!id->connected) { |
d379814be59e
[gaim-migrate @ 2529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2515
diff
changeset
|
80 account_online(gc); |
d379814be59e
[gaim-migrate @ 2529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2515
diff
changeset
|
81 serv_finish_login(gc); |
d379814be59e
[gaim-migrate @ 2529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2515
diff
changeset
|
82 icq_ChangeStatus(id->link, STATUS_ONLINE); |
d379814be59e
[gaim-migrate @ 2529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2515
diff
changeset
|
83 id->connected = TRUE; |
d379814be59e
[gaim-migrate @ 2529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2515
diff
changeset
|
84 } |
2086 | 85 } |
86 | |
87 static void icq_logged_off(icq_Link *link) { | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
88 struct gaim_connection *gc = link->icq_UserData; |
2086 | 89 struct icq_data *id = (struct icq_data *)gc->proto_data; |
90 | |
2515
3ec36a342496
[gaim-migrate @ 2528]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
91 if (!id->connected) { |
3ec36a342496
[gaim-migrate @ 2528]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
92 hide_login_progress(gc, "Unable to connect"); |
3ec36a342496
[gaim-migrate @ 2528]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
93 signoff(gc); |
3ec36a342496
[gaim-migrate @ 2528]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
94 return; |
3ec36a342496
[gaim-migrate @ 2528]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
95 } |
3ec36a342496
[gaim-migrate @ 2528]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
96 |
2086 | 97 if (icq_Connect(link, "icq.mirabilis.com", 4000) < 1) { |
98 hide_login_progress(gc, "Unable to connect"); | |
99 signoff(gc); | |
100 return; | |
101 } | |
102 | |
2516
d379814be59e
[gaim-migrate @ 2529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2515
diff
changeset
|
103 icq_Login(link, id->cur_status); |
2086 | 104 } |
105 | |
106 static void icq_msg_incoming(icq_Link *link, unsigned long uin, unsigned char hour, unsigned char minute, | |
107 unsigned char day, unsigned char month, unsigned short year, const char *data) { | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
108 struct gaim_connection *gc = link->icq_UserData; |
2086 | 109 char buf[256], *tmp = g_malloc(BUF_LONG); |
110 g_snprintf(tmp, BUF_LONG, "%s", data); | |
111 g_snprintf(buf, sizeof buf, "%lu", uin); | |
112 strip_linefeed(tmp); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
113 serv_got_im(gc, buf, tmp, 0, time(NULL), -1); |
2086 | 114 g_free(tmp); |
115 } | |
116 | |
117 static void icq_user_online(icq_Link *link, unsigned long uin, unsigned long st, | |
118 unsigned long ip, unsigned short port, unsigned long real_ip, | |
119 unsigned char tcp_flags) { | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
120 struct gaim_connection *gc = link->icq_UserData; |
2086 | 121 guint status; |
122 char buf[256]; | |
123 | |
124 g_snprintf(buf, sizeof buf, "%lu", uin); | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
125 status = (st == STATUS_ONLINE) ? 0 : UC_UNAVAILABLE | (st << 1); |
2086 | 126 serv_got_update(gc, buf, 1, 0, 0, 0, status, 0); |
127 } | |
128 | |
129 static void icq_user_offline(icq_Link *link, unsigned long uin) { | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
130 struct gaim_connection *gc = link->icq_UserData; |
2086 | 131 char buf[256]; g_snprintf(buf, sizeof buf, "%lu", uin); |
132 serv_got_update(gc, buf, 0, 0, 0, 0, 0, 0); | |
133 } | |
134 | |
135 static void icq_user_status(icq_Link *link, unsigned long uin, unsigned long st) { | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
136 struct gaim_connection *gc = link->icq_UserData; |
2086 | 137 guint status; |
138 char buf[256]; | |
139 | |
140 g_snprintf(buf, sizeof buf, "%lu", uin); | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
141 status = (st == STATUS_ONLINE) ? 0 : UC_UNAVAILABLE | (st << 1); |
2086 | 142 serv_got_update(gc, buf, 1, 0, 0, 0, status, 0); |
143 } | |
144 | |
2130
50c7a704ee56
[gaim-migrate @ 2140]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
145 static gboolean icq_set_timeout_cb(gpointer data) { |
2086 | 146 icq_HandleTimeout(); |
147 ack_timer = 0; | |
148 return FALSE; | |
149 } | |
150 | |
151 static void icq_set_timeout(long interval) { | |
152 debug_printf("icq_SetTimeout: %ld\n", interval); | |
153 if (interval > 0 && ack_timer == 0) | |
2130
50c7a704ee56
[gaim-migrate @ 2140]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
154 ack_timer = g_timeout_add(interval * 1000, icq_set_timeout_cb, NULL); |
2086 | 155 else if (ack_timer > 0) { |
2130
50c7a704ee56
[gaim-migrate @ 2140]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
156 g_source_remove(ack_timer); |
2086 | 157 ack_timer = 0; |
158 } | |
159 } | |
160 | |
161 static void icq_url_incoming(icq_Link *link, unsigned long uin, unsigned char hour, | |
162 unsigned char minute, unsigned char day, unsigned char month, | |
163 unsigned short year, const char *url, const char *descr) { | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
164 struct gaim_connection *gc = link->icq_UserData; |
2086 | 165 char *msg = g_malloc(BUF_LONG), buf[256]; |
166 g_snprintf(msg, BUF_LONG, "<A HREF=\"%s\">%s</A>", url, descr); | |
167 g_snprintf(buf, 256, "%lu", uin); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
168 serv_got_im(gc, buf, msg, 0, time(NULL), -1); |
2086 | 169 g_free(msg); |
170 } | |
171 | |
172 static void icq_wrong_passwd(icq_Link *link) { | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
173 struct gaim_connection *gc = link->icq_UserData; |
2086 | 174 hide_login_progress(gc, "Invalid password."); |
175 signoff(gc); | |
176 } | |
177 | |
178 static void icq_invalid_uin(icq_Link *link) { | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
179 struct gaim_connection *gc = link->icq_UserData; |
2086 | 180 hide_login_progress(gc, "Invalid UIN."); |
181 signoff(gc); | |
182 } | |
183 | |
184 static void icq_info_reply(icq_Link *link, unsigned long uin, const char *nick, | |
185 const char *first, const char *last, const char *email, char auth) { | |
2773
a0fd8f91e294
[gaim-migrate @ 2786]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2706
diff
changeset
|
186 struct gaim_connection *gc = link->icq_UserData; |
2086 | 187 char buf[16 * 1024]; |
2773
a0fd8f91e294
[gaim-migrate @ 2786]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2706
diff
changeset
|
188 char who[16]; |
2086 | 189 |
2773
a0fd8f91e294
[gaim-migrate @ 2786]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2706
diff
changeset
|
190 g_snprintf(who, sizeof who, "%lu", uin); |
2086 | 191 g_snprintf(buf, sizeof buf, |
192 "<B>UIN:</B> %lu<BR>" | |
193 "<B>Nick:</B> %s<BR>" | |
194 "<B>Name:</B> %s %s<BR>" | |
195 "<B>Email:</B> %s\n", | |
196 uin, | |
197 nick, | |
198 first, last, | |
199 email); | |
2791
8f6365332a05
[gaim-migrate @ 2804]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2773
diff
changeset
|
200 g_show_info_text(gc, who, 2, buf, NULL); |
2086 | 201 } |
202 | |
203 static void icq_web_pager(icq_Link *link, unsigned char hour, unsigned char minute, | |
204 unsigned char day, unsigned char month, unsigned short year, const char *nick, | |
205 const char *email, const char *msg) { | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
206 struct gaim_connection *gc = link->icq_UserData; |
2086 | 207 char *who = g_strdup_printf("ICQ Web Pager: %s (%s)", nick, email); |
208 char *what = g_malloc(BUF_LONG); | |
209 g_snprintf(what, BUF_LONG, "%s", msg); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
210 serv_got_im(gc, who, what, 0, time(NULL), -1); |
2086 | 211 g_free(who); |
212 g_free(what); | |
213 } | |
214 | |
215 static void icq_mail_express(icq_Link *link, unsigned char hour, unsigned char minute, | |
216 unsigned char day, unsigned char month, unsigned short year, const char *nick, | |
217 const char *email, const char *msg) { | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
218 struct gaim_connection *gc = link->icq_UserData; |
2086 | 219 char *who = g_strdup_printf("ICQ Mail Express: %s (%s)", nick, email); |
220 char *what = g_malloc(BUF_LONG); | |
221 g_snprintf(what, BUF_LONG, "%s", msg); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
222 serv_got_im(gc, who, what, 0, time(NULL), -1); |
2086 | 223 g_free(who); |
224 g_free(what); | |
225 } | |
226 | |
227 static void icq_req_not(icq_Link *link, unsigned long id, int type, int arg, void *data) { | |
228 if (type == ICQ_NOTIFY_FAILED) | |
3427 | 229 do_error_dialog(_("Gaim encountered an error communicating with the ICQ server."), NULL, GAIM_ERROR); |
2086 | 230 return; |
231 } | |
232 | |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
233 static void icq_recv_add(icq_Link *link, unsigned long id, unsigned char hour, unsigned char minute, |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
234 unsigned char day, unsigned char month, unsigned short year, const char *nick, |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
235 const char *first, const char *last, const char *email) |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
236 { |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
237 char uin[16]; |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
238 g_snprintf(uin, sizeof(uin), "%ld", id); |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
239 show_got_added(link->icq_UserData, NULL, uin, nick, NULL); |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
240 } |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
241 |
2086 | 242 struct icq_auth { |
243 icq_Link *link; | |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
244 char *nick; |
2086 | 245 unsigned long uin; |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
246 struct gaim_connection *gc; |
2086 | 247 }; |
248 | |
3730 | 249 static void icq_den_auth(struct icq_auth *iq) |
2086 | 250 { |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
251 g_free(iq->nick); |
2086 | 252 g_free(iq); |
253 } | |
254 | |
3730 | 255 static void icq_add_after_auth(struct icq_auth *iq) |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
256 { |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
257 char uin[16]; |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
258 g_snprintf(uin, sizeof(uin), "%ld", iq->uin); |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
259 show_add_buddy(iq->gc, uin, NULL, iq->nick); |
3730 | 260 icq_den_auth(iq); |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
261 } |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
262 |
3730 | 263 static void icq_acc_auth(struct icq_auth *iq) |
2086 | 264 { |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
265 char msg[1024]; |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
266 char uin[16]; |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
267 struct icq_auth *iqnew; |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
268 |
2086 | 269 icq_SendAuthMsg(iq->link, iq->uin); |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
270 |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
271 g_snprintf(uin, sizeof(uin), "%ld", iq->uin); |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
272 if (find_buddy(iq->gc, uin)) |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
273 return; |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
274 |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
275 iqnew = g_memdup(iq, sizeof(struct icq_auth)); |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
276 iqnew->nick = g_strdup(iq->nick); |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
277 |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
278 g_snprintf(msg, sizeof(msg), "Add %ld to your buddy list?", iq->uin); |
3730 | 279 do_ask_dialog(msg, NULL, iqnew, _("Add"), icq_add_after_auth, _("Cancel"), icq_den_auth); |
280 icq_den_auth(iq); | |
2086 | 281 } |
282 | |
283 static void icq_auth_req(icq_Link *link, unsigned long uin, unsigned char hour, unsigned char minute, | |
284 unsigned char day, unsigned char month, unsigned short year, const char *nick, | |
285 const char *first, const char *last, const char *email, const char *reason) | |
286 { | |
287 char msg[8192]; | |
288 struct icq_auth *iq = g_new0(struct icq_auth, 1); | |
289 iq->link = link; | |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
290 iq->nick = g_strdup(nick); |
2086 | 291 iq->uin = uin; |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
292 iq->gc = link->icq_UserData; |
2086 | 293 |
294 g_snprintf(msg, sizeof(msg), "The user %s (%s%s%s%s%s) wants you to authorize them.", | |
295 nick, first ? first : "", first && last ? " " : "", last ? last : "", | |
296 (first || last) && email ? ", " : "", email ? email : ""); | |
3730 | 297 do_ask_dialog(msg, NULL, iq, _("Authorize"), icq_acc_auth, _("Deny"), icq_den_auth); |
2086 | 298 } |
299 | |
300 static void icq_login(struct aim_user *user) { | |
301 struct gaim_connection *gc = new_gaim_conn(user); | |
302 struct icq_data *id = gc->proto_data = g_new0(struct icq_data, 1); | |
303 icq_Link *link; | |
304 char ps[9]; | |
305 | |
2706
e841b14b5b89
[gaim-migrate @ 2719]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
306 gc->checkbox = _("Send message through server"); |
e841b14b5b89
[gaim-migrate @ 2719]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
307 |
2086 | 308 icq_LogLevel = ICQ_LOG_MESSAGE; |
309 | |
310 g_snprintf(ps, sizeof(ps), "%s", user->password); | |
311 link = id->link = icq_ICQLINKNew(atol(user->username), ps, | |
312 user->proto_opt[USEROPT_NICK][0] ? user->proto_opt[USEROPT_NICK] : "gaim user", | |
313 TRUE); | |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
314 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", user->proto_opt[USEROPT_NICK]); |
2086 | 315 |
316 link->icq_Logged = icq_online; | |
317 link->icq_Disconnected = icq_logged_off; | |
318 link->icq_RecvMessage = icq_msg_incoming; | |
319 link->icq_RecvURL = icq_url_incoming; | |
320 link->icq_RecvWebPager = icq_web_pager; | |
321 link->icq_RecvMailExpress = icq_mail_express; | |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
322 link->icq_RecvAdded = icq_recv_add; |
2086 | 323 link->icq_RecvAuthReq = icq_auth_req; |
324 link->icq_UserOnline = icq_user_online; | |
325 link->icq_UserOffline = icq_user_offline; | |
326 link->icq_UserStatusUpdate = icq_user_status; | |
327 link->icq_InfoReply = icq_info_reply; | |
328 link->icq_WrongPassword = icq_wrong_passwd; | |
329 link->icq_InvalidUIN = icq_invalid_uin; | |
330 link->icq_Log = icq_do_log; | |
331 link->icq_RequestNotify = icq_req_not; | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
332 link->icq_UserData = gc; |
2086 | 333 |
334 if (proxytype == PROXY_SOCKS5) | |
335 icq_SetProxy(link, proxyhost, proxyport, proxyuser[0], proxyuser, proxypass); | |
336 | |
337 icq_ContactClear(id->link); | |
338 if (bud_list_cache_exists(gc)) | |
2382
569ae9f2bb89
[gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2303
diff
changeset
|
339 do_import(gc, NULL); |
2086 | 340 |
341 if (icq_Connect(link, "icq.mirabilis.com", 4000) < 1) { | |
342 hide_login_progress(gc, "Unable to connect"); | |
343 signoff(gc); | |
344 return; | |
345 } | |
346 | |
2516
d379814be59e
[gaim-migrate @ 2529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2515
diff
changeset
|
347 id->cur_status = STATUS_ONLINE; |
2086 | 348 icq_Login(link, STATUS_ONLINE); |
349 | |
350 set_login_progress(gc, 0, "Connecting..."); | |
351 } | |
352 | |
353 static void icq_close(struct gaim_connection *gc) { | |
354 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
355 | |
356 icq_Logout(id->link); | |
357 icq_Disconnect(id->link); | |
358 icq_ICQLINKDelete(id->link); | |
359 g_free(id); | |
360 } | |
361 | |
3033 | 362 static int icq_send_msg(struct gaim_connection *gc, char *who, char *msg, int len, int flags) { |
2231
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
363 if (!(flags & IM_FLAG_AWAY) && (strlen(msg) > 0)) { |
2086 | 364 struct icq_data *id = (struct icq_data *)gc->proto_data; |
365 long w = atol(who); | |
2231
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
366 icq_SendMessage(id->link, w, msg, |
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
367 (flags & IM_FLAG_CHECKBOX) ? ICQ_SEND_THRUSERVER : ICQ_SEND_BESTWAY); |
2086 | 368 } |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
369 return 1; |
2086 | 370 } |
371 | |
372 static void icq_keepalive(struct gaim_connection *gc) { | |
373 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
374 icq_KeepAlive(id->link); | |
375 } | |
376 | |
3466 | 377 static void icq_add_buddy(struct gaim_connection *gc, const char *who) { |
2086 | 378 struct icq_data *id = (struct icq_data *)gc->proto_data; |
379 icq_ContactAdd(id->link, atol(who)); | |
380 icq_ContactSetVis(id->link, atol(who), TRUE); | |
381 } | |
382 | |
383 static void icq_add_buddies(struct gaim_connection *gc, GList *whos) { | |
384 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
385 while (whos) { | |
386 icq_ContactAdd(id->link, atol(whos->data)); | |
387 icq_ContactSetVis(id->link, atol(whos->data), TRUE); | |
388 whos = whos->next; | |
389 } | |
390 } | |
391 | |
2681
37d80035e77f
[gaim-migrate @ 2694]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
392 static void icq_rem_buddy(struct gaim_connection *gc, char *who, char *group) { |
2086 | 393 struct icq_data *id = (struct icq_data *)gc->proto_data; |
394 icq_ContactRemove(id->link, atol(who)); | |
395 } | |
396 | |
397 static void icq_set_away(struct gaim_connection *gc, char *state, char *msg) { | |
398 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
399 | |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
400 if (gc->away) { |
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
401 g_free(gc->away); |
2086 | 402 gc->away = NULL; |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
403 } |
2086 | 404 |
405 if (!strcmp(state, "Online")) | |
406 icq_ChangeStatus(id->link, STATUS_ONLINE); | |
407 else if (!strcmp(state, "Away")) { | |
408 icq_ChangeStatus(id->link, STATUS_AWAY); | |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
409 gc->away = g_strdup(""); |
2086 | 410 } else if (!strcmp(state, "Do Not Disturb")) { |
411 icq_ChangeStatus(id->link, STATUS_DND); | |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
412 gc->away = g_strdup(""); |
2086 | 413 } else if (!strcmp(state, "Not Available")) { |
414 icq_ChangeStatus(id->link, STATUS_NA); | |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
415 gc->away = g_strdup(""); |
2086 | 416 } else if (!strcmp(state, "Occupied")) { |
417 icq_ChangeStatus(id->link, STATUS_OCCUPIED); | |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
418 gc->away = g_strdup(""); |
2086 | 419 } else if (!strcmp(state, "Free For Chat")) { |
420 icq_ChangeStatus(id->link, STATUS_FREE_CHAT); | |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
421 gc->away = g_strdup(""); |
2086 | 422 } else if (!strcmp(state, "Invisible")) { |
423 icq_ChangeStatus(id->link, STATUS_INVISIBLE); | |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
424 gc->away = g_strdup(""); |
2086 | 425 } else if (!strcmp(state, GAIM_AWAY_CUSTOM)) { |
426 if (msg) { | |
427 icq_ChangeStatus(id->link, STATUS_NA); | |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
428 gc->away = g_strdup(""); |
2086 | 429 } else { |
430 icq_ChangeStatus(id->link, STATUS_ONLINE); | |
431 } | |
432 } | |
433 } | |
434 | |
435 static char **icq_list_icon(int uc) { | |
436 guint status; | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
437 if (uc == 0) |
2086 | 438 return icon_online_xpm; |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
439 status = uc >> 1; |
2086 | 440 if (status & STATUS_NA) |
441 return icon_na_xpm; | |
442 if (status & STATUS_DND) | |
443 return icon_dnd_xpm; | |
444 if (status & STATUS_OCCUPIED) | |
445 return icon_occ_xpm; | |
446 if (status & STATUS_AWAY) | |
447 return icon_away_xpm; | |
448 if (status & STATUS_FREE_CHAT) | |
449 return icon_ffc_xpm; | |
450 if (status & STATUS_INVISIBLE) | |
451 return NULL; | |
452 return icon_online_xpm; | |
453 } | |
454 | |
455 static void icq_get_info(struct gaim_connection *gc, char *who) { | |
456 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
457 icq_SendInfoReq(id->link, atol(who)); | |
458 } | |
459 | |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
460 static void icq_info(struct gaim_connection *gc, char *who) { |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
461 serv_get_info(gc, who); |
2086 | 462 } |
463 | |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
464 static GList *icq_buddy_menu(struct gaim_connection *gc, char *who) { |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
465 GList *m = NULL; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
466 struct proto_buddy_menu *pbm; |
2086 | 467 |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
468 pbm = g_new0(struct proto_buddy_menu, 1); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
469 pbm->label = _("Get Info"); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
470 pbm->callback = icq_info; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
471 pbm->gc = gc; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
472 m = g_list_append(m, pbm); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
473 |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
474 return m; |
2086 | 475 } |
476 | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
477 static GList *icq_away_states(struct gaim_connection *gc) { |
2086 | 478 GList *m = NULL; |
479 | |
480 m = g_list_append(m, "Online"); | |
481 m = g_list_append(m, "Away"); | |
482 m = g_list_append(m, "Do Not Disturb"); | |
483 m = g_list_append(m, "Not Available"); | |
484 m = g_list_append(m, "Occupied"); | |
485 m = g_list_append(m, "Free For Chat"); | |
486 m = g_list_append(m, "Invisible"); | |
487 | |
488 return m; | |
489 } | |
490 | |
491 static struct prpl *my_protocol = NULL; | |
492 | |
493 void icq_init(struct prpl *ret) { | |
3572 | 494 struct proto_user_opt *puo; |
2086 | 495 ret->protocol = PROTO_ICQ; |
3572 | 496 ret->name = g_strdup("ICQ"); |
2086 | 497 ret->list_icon = icq_list_icon; |
498 ret->away_states = icq_away_states; | |
499 ret->buddy_menu = icq_buddy_menu; | |
500 ret->login = icq_login; | |
501 ret->close = icq_close; | |
502 ret->send_im = icq_send_msg; | |
503 ret->add_buddy = icq_add_buddy; | |
504 ret->add_buddies = icq_add_buddies; | |
505 ret->remove_buddy = icq_rem_buddy; | |
506 ret->get_info = icq_get_info; | |
507 ret->set_away = icq_set_away; | |
508 ret->keepalive = icq_keepalive; | |
509 | |
3572 | 510 puo = g_new0(struct proto_user_opt, 1); |
4115 | 511 puo->label = g_strdup(_("Nick:")); |
512 puo->def = g_strdup(_("Gaim User")); | |
3572 | 513 puo->pos = USEROPT_NICK; |
514 ret->user_opts = g_list_append(ret->user_opts, puo); | |
515 | |
2086 | 516 my_protocol = ret; |
517 | |
518 icq_SocketNotify = icq_sock_notify; | |
519 icq_SetTimeout = icq_set_timeout; | |
520 } | |
521 | |
522 #ifndef STATIC | |
523 | |
3867 | 524 G_MODULE_EXPORT void gaim_prpl_init(struct prpl *prpl) |
2086 | 525 { |
3572 | 526 icq_init(prpl); |
527 prpl->plug->desc.api_version = PLUGIN_API_VERSION; | |
2086 | 528 } |
529 #endif |