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