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