Mercurial > pidgin
annotate src/protocols/icq/gaim_icq.c @ 3572:bdd0bebd2d04
[gaim-migrate @ 3670]
Phase II. No longer do you have to worry about protocol plugins. When
Gaim probes plugins on load, it will detect protocol plugins and add them
to the list of available protocols. When you try to log an account on with
one of them, Gaim will automatically load the plugin--when no more accounts
need the protocol--Gaim will automatically unload it. Protocol plugins are
no longer available in the plugins ui, and no protocols are compiled statically
by default.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 30 Sep 2002 01:05:18 +0000 |
parents | 7a3f16a375a5 |
children | 8b3491f1ca56 |
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 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 | |
249 static void icq_den_auth(gpointer x, struct icq_auth *iq) | |
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 | |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
255 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
|
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); |
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 |
2086 | 262 static void icq_acc_auth(gpointer x, struct icq_auth *iq) |
263 { | |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
264 char msg[1024]; |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
265 char uin[16]; |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
266 struct icq_auth *iqnew; |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
267 |
2086 | 268 icq_SendAuthMsg(iq->link, iq->uin); |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
269 |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
270 g_snprintf(uin, sizeof(uin), "%ld", iq->uin); |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
271 if (find_buddy(iq->gc, uin)) |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
272 return; |
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 iqnew = g_memdup(iq, sizeof(struct icq_auth)); |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
275 iqnew->nick = g_strdup(iq->nick); |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
276 |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
277 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
|
278 do_ask_dialog(msg, iqnew, icq_add_after_auth, icq_den_auth); |
2086 | 279 } |
280 | |
281 static void icq_auth_req(icq_Link *link, unsigned long uin, unsigned char hour, unsigned char minute, | |
282 unsigned char day, unsigned char month, unsigned short year, const char *nick, | |
283 const char *first, const char *last, const char *email, const char *reason) | |
284 { | |
285 char msg[8192]; | |
286 struct icq_auth *iq = g_new0(struct icq_auth, 1); | |
287 iq->link = link; | |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
288 iq->nick = g_strdup(nick); |
2086 | 289 iq->uin = uin; |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
290 iq->gc = link->icq_UserData; |
2086 | 291 |
292 g_snprintf(msg, sizeof(msg), "The user %s (%s%s%s%s%s) wants you to authorize them.", | |
293 nick, first ? first : "", first && last ? " " : "", last ? last : "", | |
294 (first || last) && email ? ", " : "", email ? email : ""); | |
295 do_ask_dialog(msg, iq, icq_acc_auth, icq_den_auth); | |
296 } | |
297 | |
298 static void icq_login(struct aim_user *user) { | |
299 struct gaim_connection *gc = new_gaim_conn(user); | |
300 struct icq_data *id = gc->proto_data = g_new0(struct icq_data, 1); | |
301 icq_Link *link; | |
302 char ps[9]; | |
303 | |
2706
e841b14b5b89
[gaim-migrate @ 2719]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
304 gc->checkbox = _("Send message through server"); |
e841b14b5b89
[gaim-migrate @ 2719]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
305 |
2086 | 306 icq_LogLevel = ICQ_LOG_MESSAGE; |
307 | |
308 g_snprintf(ps, sizeof(ps), "%s", user->password); | |
309 link = id->link = icq_ICQLINKNew(atol(user->username), ps, | |
310 user->proto_opt[USEROPT_NICK][0] ? user->proto_opt[USEROPT_NICK] : "gaim user", | |
311 TRUE); | |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
312 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", user->proto_opt[USEROPT_NICK]); |
2086 | 313 |
314 link->icq_Logged = icq_online; | |
315 link->icq_Disconnected = icq_logged_off; | |
316 link->icq_RecvMessage = icq_msg_incoming; | |
317 link->icq_RecvURL = icq_url_incoming; | |
318 link->icq_RecvWebPager = icq_web_pager; | |
319 link->icq_RecvMailExpress = icq_mail_express; | |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2516
diff
changeset
|
320 link->icq_RecvAdded = icq_recv_add; |
2086 | 321 link->icq_RecvAuthReq = icq_auth_req; |
322 link->icq_UserOnline = icq_user_online; | |
323 link->icq_UserOffline = icq_user_offline; | |
324 link->icq_UserStatusUpdate = icq_user_status; | |
325 link->icq_InfoReply = icq_info_reply; | |
326 link->icq_WrongPassword = icq_wrong_passwd; | |
327 link->icq_InvalidUIN = icq_invalid_uin; | |
328 link->icq_Log = icq_do_log; | |
329 link->icq_RequestNotify = icq_req_not; | |
2138
cfa83a1b3d49
[gaim-migrate @ 2148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2137
diff
changeset
|
330 link->icq_UserData = gc; |
2086 | 331 |
332 if (proxytype == PROXY_SOCKS5) | |
333 icq_SetProxy(link, proxyhost, proxyport, proxyuser[0], proxyuser, proxypass); | |
334 | |
335 icq_ContactClear(id->link); | |
336 if (bud_list_cache_exists(gc)) | |
2382
569ae9f2bb89
[gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2303
diff
changeset
|
337 do_import(gc, NULL); |
2086 | 338 |
339 if (icq_Connect(link, "icq.mirabilis.com", 4000) < 1) { | |
340 hide_login_progress(gc, "Unable to connect"); | |
341 signoff(gc); | |
342 return; | |
343 } | |
344 | |
2516
d379814be59e
[gaim-migrate @ 2529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2515
diff
changeset
|
345 id->cur_status = STATUS_ONLINE; |
2086 | 346 icq_Login(link, STATUS_ONLINE); |
347 | |
348 set_login_progress(gc, 0, "Connecting..."); | |
349 } | |
350 | |
351 static void icq_close(struct gaim_connection *gc) { | |
352 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
353 | |
354 icq_Logout(id->link); | |
355 icq_Disconnect(id->link); | |
356 icq_ICQLINKDelete(id->link); | |
357 g_free(id); | |
358 } | |
359 | |
3033 | 360 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
|
361 if (!(flags & IM_FLAG_AWAY) && (strlen(msg) > 0)) { |
2086 | 362 struct icq_data *id = (struct icq_data *)gc->proto_data; |
363 long w = atol(who); | |
2231
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
364 icq_SendMessage(id->link, w, msg, |
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
365 (flags & IM_FLAG_CHECKBOX) ? ICQ_SEND_THRUSERVER : ICQ_SEND_BESTWAY); |
2086 | 366 } |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
367 return 1; |
2086 | 368 } |
369 | |
370 static void icq_keepalive(struct gaim_connection *gc) { | |
371 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
372 icq_KeepAlive(id->link); | |
373 } | |
374 | |
3466 | 375 static void icq_add_buddy(struct gaim_connection *gc, const char *who) { |
2086 | 376 struct icq_data *id = (struct icq_data *)gc->proto_data; |
377 icq_ContactAdd(id->link, atol(who)); | |
378 icq_ContactSetVis(id->link, atol(who), TRUE); | |
379 } | |
380 | |
381 static void icq_add_buddies(struct gaim_connection *gc, GList *whos) { | |
382 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
383 while (whos) { | |
384 icq_ContactAdd(id->link, atol(whos->data)); | |
385 icq_ContactSetVis(id->link, atol(whos->data), TRUE); | |
386 whos = whos->next; | |
387 } | |
388 } | |
389 | |
2681
37d80035e77f
[gaim-migrate @ 2694]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
390 static void icq_rem_buddy(struct gaim_connection *gc, char *who, char *group) { |
2086 | 391 struct icq_data *id = (struct icq_data *)gc->proto_data; |
392 icq_ContactRemove(id->link, atol(who)); | |
393 } | |
394 | |
395 static void icq_set_away(struct gaim_connection *gc, char *state, char *msg) { | |
396 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
397 | |
398 if (gc->away) | |
399 gc->away = NULL; | |
400 | |
401 if (!strcmp(state, "Online")) | |
402 icq_ChangeStatus(id->link, STATUS_ONLINE); | |
403 else if (!strcmp(state, "Away")) { | |
404 icq_ChangeStatus(id->link, STATUS_AWAY); | |
405 gc->away = ""; | |
406 } else if (!strcmp(state, "Do Not Disturb")) { | |
407 icq_ChangeStatus(id->link, STATUS_DND); | |
408 gc->away = ""; | |
409 } else if (!strcmp(state, "Not Available")) { | |
410 icq_ChangeStatus(id->link, STATUS_NA); | |
411 gc->away = ""; | |
412 } else if (!strcmp(state, "Occupied")) { | |
413 icq_ChangeStatus(id->link, STATUS_OCCUPIED); | |
414 gc->away = ""; | |
415 } else if (!strcmp(state, "Free For Chat")) { | |
416 icq_ChangeStatus(id->link, STATUS_FREE_CHAT); | |
417 gc->away = ""; | |
418 } else if (!strcmp(state, "Invisible")) { | |
419 icq_ChangeStatus(id->link, STATUS_INVISIBLE); | |
420 gc->away = ""; | |
421 } else if (!strcmp(state, GAIM_AWAY_CUSTOM)) { | |
422 if (msg) { | |
423 icq_ChangeStatus(id->link, STATUS_NA); | |
424 gc->away = ""; | |
425 } else { | |
426 icq_ChangeStatus(id->link, STATUS_ONLINE); | |
427 } | |
428 } | |
429 } | |
430 | |
431 static char **icq_list_icon(int uc) { | |
432 guint status; | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
433 if (uc == 0) |
2086 | 434 return icon_online_xpm; |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
435 status = uc >> 1; |
2086 | 436 if (status & STATUS_NA) |
437 return icon_na_xpm; | |
438 if (status & STATUS_DND) | |
439 return icon_dnd_xpm; | |
440 if (status & STATUS_OCCUPIED) | |
441 return icon_occ_xpm; | |
442 if (status & STATUS_AWAY) | |
443 return icon_away_xpm; | |
444 if (status & STATUS_FREE_CHAT) | |
445 return icon_ffc_xpm; | |
446 if (status & STATUS_INVISIBLE) | |
447 return NULL; | |
448 return icon_online_xpm; | |
449 } | |
450 | |
451 static void icq_get_info(struct gaim_connection *gc, char *who) { | |
452 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
453 icq_SendInfoReq(id->link, atol(who)); | |
454 } | |
455 | |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
456 static void icq_info(struct gaim_connection *gc, char *who) { |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
457 serv_get_info(gc, who); |
2086 | 458 } |
459 | |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
460 static GList *icq_buddy_menu(struct gaim_connection *gc, char *who) { |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
461 GList *m = NULL; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
462 struct proto_buddy_menu *pbm; |
2086 | 463 |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
464 pbm = g_new0(struct proto_buddy_menu, 1); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
465 pbm->label = _("Get Info"); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
466 pbm->callback = icq_info; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
467 pbm->gc = gc; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
468 m = g_list_append(m, pbm); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
469 |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
470 return m; |
2086 | 471 } |
472 | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
473 static GList *icq_away_states(struct gaim_connection *gc) { |
2086 | 474 GList *m = NULL; |
475 | |
476 m = g_list_append(m, "Online"); | |
477 m = g_list_append(m, "Away"); | |
478 m = g_list_append(m, "Do Not Disturb"); | |
479 m = g_list_append(m, "Not Available"); | |
480 m = g_list_append(m, "Occupied"); | |
481 m = g_list_append(m, "Free For Chat"); | |
482 m = g_list_append(m, "Invisible"); | |
483 | |
484 return m; | |
485 } | |
486 | |
487 static struct prpl *my_protocol = NULL; | |
488 | |
489 void icq_init(struct prpl *ret) { | |
3572 | 490 struct proto_user_opt *puo; |
2086 | 491 ret->protocol = PROTO_ICQ; |
3572 | 492 ret->name = g_strdup("ICQ"); |
2086 | 493 ret->list_icon = icq_list_icon; |
494 ret->away_states = icq_away_states; | |
495 ret->buddy_menu = icq_buddy_menu; | |
496 ret->login = icq_login; | |
497 ret->close = icq_close; | |
498 ret->send_im = icq_send_msg; | |
499 ret->add_buddy = icq_add_buddy; | |
500 ret->add_buddies = icq_add_buddies; | |
501 ret->remove_buddy = icq_rem_buddy; | |
502 ret->get_info = icq_get_info; | |
503 ret->set_away = icq_set_away; | |
504 ret->keepalive = icq_keepalive; | |
505 | |
3572 | 506 puo = g_new0(struct proto_user_opt, 1); |
507 puo->label = g_strdup("Nick:"); | |
508 puo->def = g_strdup("Gaim User"); | |
509 puo->pos = USEROPT_NICK; | |
510 ret->user_opts = g_list_append(ret->user_opts, puo); | |
511 | |
2086 | 512 my_protocol = ret; |
513 | |
514 icq_SocketNotify = icq_sock_notify; | |
515 icq_SetTimeout = icq_set_timeout; | |
516 } | |
517 | |
518 #ifndef STATIC | |
519 | |
3572 | 520 void *gaim_prpl_init(struct prpl *prpl) |
2086 | 521 { |
3572 | 522 icq_init(prpl); |
523 prpl->plug->desc.api_version = PLUGIN_API_VERSION; | |
2086 | 524 } |
525 #endif |