Mercurial > pidgin.yaz
annotate src/protocols/icq/gaim_icq.c @ 3466:7a3f16a375a5
[gaim-migrate @ 3516]
some patches from some people.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Thu, 29 Aug 2002 01:47:15 +0000 |
parents | 8fa61405af2b |
children | bdd0bebd2d04 |
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 static void icq_msg_incoming(icq_Link *link, unsigned long uin, unsigned char hour, unsigned char minute, | |
111 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
|
112 struct gaim_connection *gc = link->icq_UserData; |
2086 | 113 char buf[256], *tmp = g_malloc(BUF_LONG); |
114 g_snprintf(tmp, BUF_LONG, "%s", data); | |
115 g_snprintf(buf, sizeof buf, "%lu", uin); | |
116 strip_linefeed(tmp); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
117 serv_got_im(gc, buf, tmp, 0, time(NULL), -1); |
2086 | 118 g_free(tmp); |
119 } | |
120 | |
121 static void icq_user_online(icq_Link *link, unsigned long uin, unsigned long st, | |
122 unsigned long ip, unsigned short port, unsigned long real_ip, | |
123 unsigned char tcp_flags) { | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
124 struct gaim_connection *gc = link->icq_UserData; |
2086 | 125 guint status; |
126 char buf[256]; | |
127 | |
128 g_snprintf(buf, sizeof buf, "%lu", uin); | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
129 status = (st == STATUS_ONLINE) ? 0 : UC_UNAVAILABLE | (st << 1); |
2086 | 130 serv_got_update(gc, buf, 1, 0, 0, 0, status, 0); |
131 } | |
132 | |
133 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
|
134 struct gaim_connection *gc = link->icq_UserData; |
2086 | 135 char buf[256]; g_snprintf(buf, sizeof buf, "%lu", uin); |
136 serv_got_update(gc, buf, 0, 0, 0, 0, 0, 0); | |
137 } | |
138 | |
139 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
|
140 struct gaim_connection *gc = link->icq_UserData; |
2086 | 141 guint status; |
142 char buf[256]; | |
143 | |
144 g_snprintf(buf, sizeof buf, "%lu", uin); | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
145 status = (st == STATUS_ONLINE) ? 0 : UC_UNAVAILABLE | (st << 1); |
2086 | 146 serv_got_update(gc, buf, 1, 0, 0, 0, status, 0); |
147 } | |
148 | |
2130
50c7a704ee56
[gaim-migrate @ 2140]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
149 static gboolean icq_set_timeout_cb(gpointer data) { |
2086 | 150 icq_HandleTimeout(); |
151 ack_timer = 0; | |
152 return FALSE; | |
153 } | |
154 | |
155 static void icq_set_timeout(long interval) { | |
156 debug_printf("icq_SetTimeout: %ld\n", interval); | |
157 if (interval > 0 && ack_timer == 0) | |
2130
50c7a704ee56
[gaim-migrate @ 2140]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
158 ack_timer = g_timeout_add(interval * 1000, icq_set_timeout_cb, NULL); |
2086 | 159 else if (ack_timer > 0) { |
2130
50c7a704ee56
[gaim-migrate @ 2140]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
160 g_source_remove(ack_timer); |
2086 | 161 ack_timer = 0; |
162 } | |
163 } | |
164 | |
165 static void icq_url_incoming(icq_Link *link, unsigned long uin, unsigned char hour, | |
166 unsigned char minute, unsigned char day, unsigned char month, | |
167 unsigned short year, const char *url, const char *descr) { | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
168 struct gaim_connection *gc = link->icq_UserData; |
2086 | 169 char *msg = g_malloc(BUF_LONG), buf[256]; |
170 g_snprintf(msg, BUF_LONG, "<A HREF=\"%s\">%s</A>", url, descr); | |
171 g_snprintf(buf, 256, "%lu", uin); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
172 serv_got_im(gc, buf, msg, 0, time(NULL), -1); |
2086 | 173 g_free(msg); |
174 } | |
175 | |
176 static void icq_wrong_passwd(icq_Link *link) { | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
177 struct gaim_connection *gc = link->icq_UserData; |
2086 | 178 hide_login_progress(gc, "Invalid password."); |
179 signoff(gc); | |
180 } | |
181 | |
182 static void icq_invalid_uin(icq_Link *link) { | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
183 struct gaim_connection *gc = link->icq_UserData; |
2086 | 184 hide_login_progress(gc, "Invalid UIN."); |
185 signoff(gc); | |
186 } | |
187 | |
188 static void icq_info_reply(icq_Link *link, unsigned long uin, const char *nick, | |
189 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
|
190 struct gaim_connection *gc = link->icq_UserData; |
2086 | 191 char buf[16 * 1024]; |
2773
a0fd8f91e294
[gaim-migrate @ 2786]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2706
diff
changeset
|
192 char who[16]; |
2086 | 193 |
2773
a0fd8f91e294
[gaim-migrate @ 2786]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2706
diff
changeset
|
194 g_snprintf(who, sizeof who, "%lu", uin); |
2086 | 195 g_snprintf(buf, sizeof buf, |
196 "<B>UIN:</B> %lu<BR>" | |
197 "<B>Nick:</B> %s<BR>" | |
198 "<B>Name:</B> %s %s<BR>" | |
199 "<B>Email:</B> %s\n", | |
200 uin, | |
201 nick, | |
202 first, last, | |
203 email); | |
2791
8f6365332a05
[gaim-migrate @ 2804]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2773
diff
changeset
|
204 g_show_info_text(gc, who, 2, buf, NULL); |
2086 | 205 } |
206 | |
207 static void icq_web_pager(icq_Link *link, unsigned char hour, unsigned char minute, | |
208 unsigned char day, unsigned char month, unsigned short year, const char *nick, | |
209 const char *email, const char *msg) { | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
210 struct gaim_connection *gc = link->icq_UserData; |
2086 | 211 char *who = g_strdup_printf("ICQ Web Pager: %s (%s)", nick, email); |
212 char *what = g_malloc(BUF_LONG); | |
213 g_snprintf(what, BUF_LONG, "%s", msg); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
214 serv_got_im(gc, who, what, 0, time(NULL), -1); |
2086 | 215 g_free(who); |
216 g_free(what); | |
217 } | |
218 | |
219 static void icq_mail_express(icq_Link *link, unsigned char hour, unsigned char minute, | |
220 unsigned char day, unsigned char month, unsigned short year, const char *nick, | |
221 const char *email, const char *msg) { | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
222 struct gaim_connection *gc = link->icq_UserData; |
2086 | 223 char *who = g_strdup_printf("ICQ Mail Express: %s (%s)", nick, email); |
224 char *what = g_malloc(BUF_LONG); | |
225 g_snprintf(what, BUF_LONG, "%s", msg); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
226 serv_got_im(gc, who, what, 0, time(NULL), -1); |
2086 | 227 g_free(who); |
228 g_free(what); | |
229 } | |
230 | |
231 static void icq_req_not(icq_Link *link, unsigned long id, int type, int arg, void *data) { | |
232 if (type == ICQ_NOTIFY_FAILED) | |
3427 | 233 do_error_dialog(_("Gaim encountered an error communicating with the ICQ server."), NULL, GAIM_ERROR); |
2086 | 234 return; |
235 } | |
236 | |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
237 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
|
238 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
|
239 const char *first, const char *last, const char *email) |
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 char uin[16]; |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
242 g_snprintf(uin, sizeof(uin), "%ld", id); |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
243 show_got_added(link->icq_UserData, NULL, uin, nick, NULL); |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
244 } |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
245 |
2086 | 246 struct icq_auth { |
247 icq_Link *link; | |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
248 char *nick; |
2086 | 249 unsigned long uin; |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
250 struct gaim_connection *gc; |
2086 | 251 }; |
252 | |
253 static void icq_den_auth(gpointer x, struct icq_auth *iq) | |
254 { | |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
255 g_free(iq->nick); |
2086 | 256 g_free(iq); |
257 } | |
258 | |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
259 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
|
260 { |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
261 char uin[16]; |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
262 g_snprintf(uin, sizeof(uin), "%ld", iq->uin); |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
263 show_add_buddy(iq->gc, uin, NULL, iq->nick); |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
264 } |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
265 |
2086 | 266 static void icq_acc_auth(gpointer x, struct icq_auth *iq) |
267 { | |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
268 char msg[1024]; |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
269 char uin[16]; |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
270 struct icq_auth *iqnew; |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
271 |
2086 | 272 icq_SendAuthMsg(iq->link, iq->uin); |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
273 |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
274 g_snprintf(uin, sizeof(uin), "%ld", iq->uin); |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
275 if (find_buddy(iq->gc, uin)) |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
276 return; |
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 iqnew = g_memdup(iq, sizeof(struct icq_auth)); |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
279 iqnew->nick = g_strdup(iq->nick); |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
280 |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
281 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
|
282 do_ask_dialog(msg, iqnew, icq_add_after_auth, icq_den_auth); |
2086 | 283 } |
284 | |
285 static void icq_auth_req(icq_Link *link, unsigned long uin, unsigned char hour, unsigned char minute, | |
286 unsigned char day, unsigned char month, unsigned short year, const char *nick, | |
287 const char *first, const char *last, const char *email, const char *reason) | |
288 { | |
289 char msg[8192]; | |
290 struct icq_auth *iq = g_new0(struct icq_auth, 1); | |
291 iq->link = link; | |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
292 iq->nick = g_strdup(nick); |
2086 | 293 iq->uin = uin; |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
294 iq->gc = link->icq_UserData; |
2086 | 295 |
296 g_snprintf(msg, sizeof(msg), "The user %s (%s%s%s%s%s) wants you to authorize them.", | |
297 nick, first ? first : "", first && last ? " " : "", last ? last : "", | |
298 (first || last) && email ? ", " : "", email ? email : ""); | |
299 do_ask_dialog(msg, iq, icq_acc_auth, icq_den_auth); | |
300 } | |
301 | |
302 static void icq_login(struct aim_user *user) { | |
303 struct gaim_connection *gc = new_gaim_conn(user); | |
304 struct icq_data *id = gc->proto_data = g_new0(struct icq_data, 1); | |
305 icq_Link *link; | |
306 char ps[9]; | |
307 | |
2706
e841b14b5b89
[gaim-migrate @ 2719]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
308 gc->checkbox = _("Send message through server"); |
e841b14b5b89
[gaim-migrate @ 2719]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
309 |
2086 | 310 icq_LogLevel = ICQ_LOG_MESSAGE; |
311 | |
312 g_snprintf(ps, sizeof(ps), "%s", user->password); | |
313 link = id->link = icq_ICQLINKNew(atol(user->username), ps, | |
314 user->proto_opt[USEROPT_NICK][0] ? user->proto_opt[USEROPT_NICK] : "gaim user", | |
315 TRUE); | |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
316 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", user->proto_opt[USEROPT_NICK]); |
2086 | 317 |
318 link->icq_Logged = icq_online; | |
319 link->icq_Disconnected = icq_logged_off; | |
320 link->icq_RecvMessage = icq_msg_incoming; | |
321 link->icq_RecvURL = icq_url_incoming; | |
322 link->icq_RecvWebPager = icq_web_pager; | |
323 link->icq_RecvMailExpress = icq_mail_express; | |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
324 link->icq_RecvAdded = icq_recv_add; |
2086 | 325 link->icq_RecvAuthReq = icq_auth_req; |
326 link->icq_UserOnline = icq_user_online; | |
327 link->icq_UserOffline = icq_user_offline; | |
328 link->icq_UserStatusUpdate = icq_user_status; | |
329 link->icq_InfoReply = icq_info_reply; | |
330 link->icq_WrongPassword = icq_wrong_passwd; | |
331 link->icq_InvalidUIN = icq_invalid_uin; | |
332 link->icq_Log = icq_do_log; | |
333 link->icq_RequestNotify = icq_req_not; | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
334 link->icq_UserData = gc; |
2086 | 335 |
336 if (proxytype == PROXY_SOCKS5) | |
337 icq_SetProxy(link, proxyhost, proxyport, proxyuser[0], proxyuser, proxypass); | |
338 | |
339 icq_ContactClear(id->link); | |
340 if (bud_list_cache_exists(gc)) | |
2382
569ae9f2bb89
[gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2303
diff
changeset
|
341 do_import(gc, NULL); |
2086 | 342 |
343 if (icq_Connect(link, "icq.mirabilis.com", 4000) < 1) { | |
344 hide_login_progress(gc, "Unable to connect"); | |
345 signoff(gc); | |
346 return; | |
347 } | |
348 | |
2516
d379814be59e
[gaim-migrate @ 2529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2515
diff
changeset
|
349 id->cur_status = STATUS_ONLINE; |
2086 | 350 icq_Login(link, STATUS_ONLINE); |
351 | |
352 set_login_progress(gc, 0, "Connecting..."); | |
353 } | |
354 | |
355 static void icq_close(struct gaim_connection *gc) { | |
356 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
357 | |
358 icq_Logout(id->link); | |
359 icq_Disconnect(id->link); | |
360 icq_ICQLINKDelete(id->link); | |
361 g_free(id); | |
362 } | |
363 | |
3033 | 364 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
|
365 if (!(flags & IM_FLAG_AWAY) && (strlen(msg) > 0)) { |
2086 | 366 struct icq_data *id = (struct icq_data *)gc->proto_data; |
367 long w = atol(who); | |
2231
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
368 icq_SendMessage(id->link, w, msg, |
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
369 (flags & IM_FLAG_CHECKBOX) ? ICQ_SEND_THRUSERVER : ICQ_SEND_BESTWAY); |
2086 | 370 } |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
371 return 1; |
2086 | 372 } |
373 | |
374 static void icq_keepalive(struct gaim_connection *gc) { | |
375 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
376 icq_KeepAlive(id->link); | |
377 } | |
378 | |
3466 | 379 static void icq_add_buddy(struct gaim_connection *gc, const char *who) { |
2086 | 380 struct icq_data *id = (struct icq_data *)gc->proto_data; |
381 icq_ContactAdd(id->link, atol(who)); | |
382 icq_ContactSetVis(id->link, atol(who), TRUE); | |
383 } | |
384 | |
385 static void icq_add_buddies(struct gaim_connection *gc, GList *whos) { | |
386 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
387 while (whos) { | |
388 icq_ContactAdd(id->link, atol(whos->data)); | |
389 icq_ContactSetVis(id->link, atol(whos->data), TRUE); | |
390 whos = whos->next; | |
391 } | |
392 } | |
393 | |
2681
37d80035e77f
[gaim-migrate @ 2694]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
394 static void icq_rem_buddy(struct gaim_connection *gc, char *who, char *group) { |
2086 | 395 struct icq_data *id = (struct icq_data *)gc->proto_data; |
396 icq_ContactRemove(id->link, atol(who)); | |
397 } | |
398 | |
399 static void icq_set_away(struct gaim_connection *gc, char *state, char *msg) { | |
400 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
401 | |
402 if (gc->away) | |
403 gc->away = NULL; | |
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); | |
409 gc->away = ""; | |
410 } else if (!strcmp(state, "Do Not Disturb")) { | |
411 icq_ChangeStatus(id->link, STATUS_DND); | |
412 gc->away = ""; | |
413 } else if (!strcmp(state, "Not Available")) { | |
414 icq_ChangeStatus(id->link, STATUS_NA); | |
415 gc->away = ""; | |
416 } else if (!strcmp(state, "Occupied")) { | |
417 icq_ChangeStatus(id->link, STATUS_OCCUPIED); | |
418 gc->away = ""; | |
419 } else if (!strcmp(state, "Free For Chat")) { | |
420 icq_ChangeStatus(id->link, STATUS_FREE_CHAT); | |
421 gc->away = ""; | |
422 } else if (!strcmp(state, "Invisible")) { | |
423 icq_ChangeStatus(id->link, STATUS_INVISIBLE); | |
424 gc->away = ""; | |
425 } else if (!strcmp(state, GAIM_AWAY_CUSTOM)) { | |
426 if (msg) { | |
427 icq_ChangeStatus(id->link, STATUS_NA); | |
428 gc->away = ""; | |
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 | |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2138
diff
changeset
|
477 static GList *icq_user_opts() { |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2138
diff
changeset
|
478 GList *m = NULL; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2138
diff
changeset
|
479 struct proto_user_opt *puo; |
2086 | 480 |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2138
diff
changeset
|
481 puo = g_new0(struct proto_user_opt, 1); |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2138
diff
changeset
|
482 puo->label = "Nick:"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2138
diff
changeset
|
483 puo->def = "Gaim User"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2138
diff
changeset
|
484 puo->pos = USEROPT_NICK; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2138
diff
changeset
|
485 m = g_list_append(m, puo); |
2086 | 486 |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2138
diff
changeset
|
487 return m; |
2086 | 488 } |
489 | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
490 static GList *icq_away_states(struct gaim_connection *gc) { |
2086 | 491 GList *m = NULL; |
492 | |
493 m = g_list_append(m, "Online"); | |
494 m = g_list_append(m, "Away"); | |
495 m = g_list_append(m, "Do Not Disturb"); | |
496 m = g_list_append(m, "Not Available"); | |
497 m = g_list_append(m, "Occupied"); | |
498 m = g_list_append(m, "Free For Chat"); | |
499 m = g_list_append(m, "Invisible"); | |
500 | |
501 return m; | |
502 } | |
503 | |
504 static struct prpl *my_protocol = NULL; | |
505 | |
506 void icq_init(struct prpl *ret) { | |
507 ret->protocol = PROTO_ICQ; | |
508 ret->name = icq_name; | |
509 ret->list_icon = icq_list_icon; | |
510 ret->away_states = icq_away_states; | |
511 ret->buddy_menu = icq_buddy_menu; | |
512 ret->user_opts = icq_user_opts; | |
513 ret->login = icq_login; | |
514 ret->close = icq_close; | |
515 ret->send_im = icq_send_msg; | |
516 ret->add_buddy = icq_add_buddy; | |
517 ret->add_buddies = icq_add_buddies; | |
518 ret->remove_buddy = icq_rem_buddy; | |
519 ret->get_info = icq_get_info; | |
520 ret->set_away = icq_set_away; | |
521 ret->keepalive = icq_keepalive; | |
522 | |
523 my_protocol = ret; | |
524 | |
525 icq_SocketNotify = icq_sock_notify; | |
526 icq_SetTimeout = icq_set_timeout; | |
527 } | |
528 | |
529 #ifndef STATIC | |
530 | |
531 char *gaim_plugin_init(GModule *handle) | |
532 { | |
533 load_protocol(icq_init, sizeof(struct prpl)); | |
534 return NULL; | |
535 } | |
536 | |
537 void gaim_plugin_remove() | |
538 { | |
539 struct prpl *p = find_prpl(PROTO_ICQ); | |
540 if (p == my_protocol) | |
541 unload_protocol(p); | |
542 } | |
543 | |
544 char *name() | |
545 { | |
546 return "ICQ"; | |
547 } | |
548 | |
549 char *description() | |
550 { | |
2162
a464da684307
[gaim-migrate @ 2172]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2154
diff
changeset
|
551 return PRPL_DESC("ICQ"); |
2086 | 552 } |
553 | |
554 #endif |