Mercurial > pidgin
annotate src/protocols/irc/irc.c @ 10131:a6c3b931214f
[gaim-migrate @ 11194]
I think Luke forgot to move the old Catalan translator over on
October 6th.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 23 Oct 2004 15:24:58 +0000 |
parents | 56e34a659db2 |
children | 952fb08c60b0 |
rev | line source |
---|---|
6333 | 1 /** |
2 * @file irc.c | |
6459
b52870734c21
[gaim-migrate @ 6968]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
3 * |
6333 | 4 * gaim |
2086 | 5 * |
8351 | 6 * Copyright (C) 2003, Robbert Haarman <gaim@inglorion.net> |
6333 | 7 * Copyright (C) 2003, Ethan Blanton <eblanton@cs.purdue.edu> |
8 * Copyright (C) 2000-2003, Rob Flynn <rob@tgflinux.com> | |
2086 | 9 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> |
6459
b52870734c21
[gaim-migrate @ 6968]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
10 * |
2086 | 11 * This program is free software; you can redistribute it and/or modify |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
6333 | 25 |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5791
diff
changeset
|
26 #include "internal.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5791
diff
changeset
|
27 |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5791
diff
changeset
|
28 #include "accountopt.h" |
9030 | 29 #include "blist.h" |
6333 | 30 #include "conversation.h" |
9030 | 31 #include "debug.h" |
7148 | 32 #include "notify.h" |
9030 | 33 #include "prpl.h" |
34 #include "plugin.h" | |
6350 | 35 #include "util.h" |
9943 | 36 #include "version.h" |
9030 | 37 |
6333 | 38 #include "irc.h" |
4422 | 39 |
6333 | 40 static void irc_buddy_append(char *name, struct irc_buddy *ib, GString *string); |
2086 | 41 |
6695 | 42 static const char *irc_blist_icon(GaimAccount *a, GaimBuddy *b); |
9953 | 43 static void irc_blist_emblems(GaimBuddy *b, const char **se, const char **sw, const char **nw, const char **ne); |
9951 | 44 static GList *irc_status_types(GaimAccount *account); |
9015 | 45 static GList *irc_actions(GaimPlugin *plugin, gpointer context); |
6333 | 46 /* static GList *irc_chat_info(GaimConnection *gc); */ |
47 static void irc_login(GaimAccount *account); | |
48 static void irc_login_cb(gpointer data, gint source, GaimInputCondition cond); | |
49 static void irc_close(GaimConnection *gc); | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
50 static int irc_im_send(GaimConnection *gc, const char *who, const char *what, GaimConvImFlags flags); |
6333 | 51 static int irc_chat_send(GaimConnection *gc, int id, const char *what); |
52 static void irc_chat_join (GaimConnection *gc, GHashTable *data); | |
53 static void irc_input_cb(gpointer data, gint source, GaimInputCondition cond); | |
3751 | 54 |
7711 | 55 static guint irc_nick_hash(const char *nick); |
56 static gboolean irc_nick_equal(const char *nick1, const char *nick2); | |
57 static void irc_buddy_free(struct irc_buddy *ib); | |
58 | |
59 static GaimPlugin *_irc_plugin = NULL; | |
60 | |
61 static const char *status_chars = "@+%&"; | |
62 | |
9015 | 63 static void irc_view_motd(GaimPluginAction *action) |
7148 | 64 { |
9015 | 65 GaimConnection *gc = (GaimConnection *) action->context; |
7148 | 66 struct irc_conn *irc; |
67 char *title; | |
68 | |
69 if (gc == NULL || gc->proto_data == NULL) { | |
70 gaim_debug(GAIM_DEBUG_ERROR, "irc", "got MOTD request for NULL gc\n"); | |
71 return; | |
72 } | |
73 irc = gc->proto_data; | |
74 if (irc->motd == NULL) { | |
75 gaim_notify_error(gc, _("Error displaying MOTD"), _("No MOTD available"), | |
76 _("There is no MOTD associated with this connection.")); | |
77 return; | |
78 } | |
79 title = g_strdup_printf(_("MOTD for %s"), irc->server); | |
80 gaim_notify_formatted(gc, title, title, NULL, irc->motd->str, NULL, NULL); | |
81 } | |
82 | |
6333 | 83 int irc_send(struct irc_conn *irc, const char *buf) |
3751 | 84 { |
9440 | 85 int ret; |
86 | |
6333 | 87 if (irc->fd < 0) |
88 return -1; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2171
diff
changeset
|
89 |
6333 | 90 /* gaim_debug(GAIM_DEBUG_MISC, "irc", "sent: %s", buf); */ |
9440 | 91 if ((ret = write(irc->fd, buf, strlen(buf))) < 0) |
92 gaim_connection_error(gaim_account_get_connection(irc->account), | |
93 _("Server has disconnected")); | |
94 | |
95 return ret; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2171
diff
changeset
|
96 } |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2171
diff
changeset
|
97 |
6333 | 98 /* XXX I don't like messing directly with these buddies */ |
99 gboolean irc_blist_timeout(struct irc_conn *irc) | |
2086 | 100 { |
6333 | 101 GString *string = g_string_sized_new(512); |
102 char *list, *buf; | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
103 |
6333 | 104 g_hash_table_foreach(irc->buddies, (GHFunc)irc_buddy_append, (gpointer)string); |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4349
diff
changeset
|
105 |
6333 | 106 list = g_string_free(string, FALSE); |
107 if (!list || !strlen(list)) { | |
108 g_free(list); | |
2137
18722ae5b882
[gaim-migrate @ 2147]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2131
diff
changeset
|
109 return TRUE; |
2086 | 110 } |
4416
8e62cee6d738
[gaim-migrate @ 4689]
Christian Hammond <chipx86@chipx86.com>
parents:
4373
diff
changeset
|
111 |
8038 | 112 buf = irc_format(irc, "vn", "ISON", list); |
6333 | 113 g_free(list); |
114 irc_send(irc, buf); | |
115 g_free(buf); | |
4416
8e62cee6d738
[gaim-migrate @ 4689]
Christian Hammond <chipx86@chipx86.com>
parents:
4373
diff
changeset
|
116 |
2131
acc11216ec5d
[gaim-migrate @ 2141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
117 return TRUE; |
2086 | 118 } |
119 | |
6333 | 120 static void irc_buddy_append(char *name, struct irc_buddy *ib, GString *string) |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
121 { |
6333 | 122 ib->flag = FALSE; |
123 g_string_append_printf(string, "%s ", name); | |
3511 | 124 } |
125 | |
9553 | 126 static void irc_ison_one(struct irc_conn *irc, struct irc_buddy *ib) |
127 { | |
128 char *buf; | |
129 | |
130 ib->flag = FALSE; | |
131 buf = irc_format(irc, "vn", "ISON", ib->name); | |
132 irc_send(irc, buf); | |
133 g_free(buf); | |
134 } | |
135 | |
136 | |
6695 | 137 static const char *irc_blist_icon(GaimAccount *a, GaimBuddy *b) |
3029 | 138 { |
6333 | 139 return "irc"; |
2339
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
140 } |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
141 |
9953 | 142 static void irc_blist_emblems(GaimBuddy *b, const char **se, const char **sw, const char **nw, const char **ne) |
3751 | 143 { |
6333 | 144 if (b->present == GAIM_BUDDY_OFFLINE) |
145 *se = "offline"; | |
2086 | 146 } |
147 | |
9944 | 148 static GList *irc_status_types(GaimAccount *account) |
2086 | 149 { |
9944 | 150 GaimStatusType *type; |
151 GList *types = NULL; | |
152 | |
153 type = gaim_status_type_new(GAIM_STATUS_OFFLINE, "offline", | |
154 _("Offline"), FALSE); | |
155 types = g_list_append(types, type); | |
156 | |
157 type = gaim_status_type_new(GAIM_STATUS_ONLINE, "online", | |
158 _("Online"), FALSE); | |
159 types = g_list_append(types, type); | |
160 | |
161 type = gaim_status_type_new(GAIM_STATUS_AVAILABLE, "available", | |
162 _("Available"), TRUE); | |
163 types = g_list_append(types, type); | |
164 | |
165 type = gaim_status_type_new_with_attrs( | |
166 GAIM_STATUS_AWAY, "away", _("Away"), TRUE, TRUE, FALSE, | |
10009 | 167 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING), NULL); |
9944 | 168 types = g_list_append(types, type); |
169 | |
170 return types; | |
3452 | 171 } |
172 | |
9015 | 173 static GList *irc_actions(GaimPlugin *plugin, gpointer context) |
7148 | 174 { |
175 GList *list = NULL; | |
9015 | 176 GaimPluginAction *act = NULL; |
7148 | 177 |
9015 | 178 act = gaim_plugin_action_new(_("View MOTD"), irc_view_motd); |
179 list = g_list_append(list, act); | |
7148 | 180 |
181 return list; | |
182 } | |
183 | |
6333 | 184 static GList *irc_chat_join_info(GaimConnection *gc) |
2086 | 185 { |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
186 GList *m = NULL; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
187 struct proto_chat_entry *pce; |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
188 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
189 pce = g_new0(struct proto_chat_entry, 1); |
7841 | 190 pce->label = _("_Channel:"); |
5234 | 191 pce->identifier = "channel"; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
192 m = g_list_append(m, pce); |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
193 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
194 pce = g_new0(struct proto_chat_entry, 1); |
7841 | 195 pce->label = _("_Password:"); |
5234 | 196 pce->identifier = "password"; |
6499 | 197 pce->secret = TRUE; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
198 m = g_list_append(m, pce); |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
199 |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
200 return m; |
2086 | 201 } |
202 | |
9754 | 203 GHashTable *irc_chat_info_defaults(GaimConnection *gc, const char *chat_name) |
204 { | |
205 GHashTable *defaults; | |
206 | |
207 defaults = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free); | |
208 | |
209 if (chat_name != NULL) | |
210 g_hash_table_insert(defaults, "channel", g_strdup(chat_name)); | |
211 | |
212 return defaults; | |
213 } | |
214 | |
6333 | 215 static void irc_login(GaimAccount *account) |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
216 { |
6333 | 217 GaimConnection *gc; |
218 struct irc_conn *irc; | |
219 char *buf, **userparts; | |
220 const char *username = gaim_account_get_username(account); | |
221 int err; | |
222 | |
223 gc = gaim_account_get_connection(account); | |
8677 | 224 gc->flags |= GAIM_CONNECTION_NO_NEWLINES; |
6333 | 225 |
6752 | 226 if (strpbrk(username, " \t\v\r\n") != NULL) { |
227 gaim_connection_error(gc, _("IRC nicks may not contain whitespace")); | |
228 return; | |
229 } | |
230 | |
6333 | 231 gc->proto_data = irc = g_new0(struct irc_conn, 1); |
232 irc->account = account; | |
233 | |
234 userparts = g_strsplit(username, "@", 2); | |
235 gaim_connection_set_display_name(gc, userparts[0]); | |
236 irc->server = g_strdup(userparts[1]); | |
237 g_strfreev(userparts); | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
238 |
6333 | 239 irc->buddies = g_hash_table_new_full((GHashFunc)irc_nick_hash, (GEqualFunc)irc_nick_equal, |
240 NULL, (GDestroyNotify)irc_buddy_free); | |
241 irc->cmds = g_hash_table_new(g_str_hash, g_str_equal); | |
242 irc_cmd_table_build(irc); | |
243 irc->msgs = g_hash_table_new(g_str_hash, g_str_equal); | |
244 irc_msg_table_build(irc); | |
245 | |
246 buf = g_strdup_printf(_("Signon: %s"), username); | |
247 gaim_connection_update_progress(gc, buf, 1, 2); | |
248 g_free(buf); | |
249 | |
250 err = gaim_proxy_connect(account, irc->server, | |
251 gaim_account_get_int(account, "port", IRC_DEFAULT_PORT), | |
252 irc_login_cb, gc); | |
253 | |
254 if (err || !account->gc) { | |
255 gaim_connection_error(gc, _("Couldn't create socket")); | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
256 return; |
6333 | 257 } |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
258 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
259 |
6333 | 260 static void irc_login_cb(gpointer data, gint source, GaimInputCondition cond) |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
261 { |
6333 | 262 GaimConnection *gc = data; |
263 struct irc_conn *irc = gc->proto_data; | |
264 char hostname[256]; | |
265 char *buf; | |
10002 | 266 const char *username, *realname; |
6333 | 267 GList *connections = gaim_connections_get_all(); |
268 | |
8778 | 269 if (source < 0) { |
270 gaim_connection_error(gc, _("Couldn't connect to host")); | |
6333 | 271 return; |
8778 | 272 } |
6333 | 273 |
274 if (!g_list_find(connections, gc)) { | |
275 close(source); | |
276 return; | |
277 } | |
278 | |
279 irc->fd = source; | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
280 |
6333 | 281 if (gc->account->password && *gc->account->password) { |
282 buf = irc_format(irc, "vv", "PASS", gc->account->password); | |
283 if (irc_send(irc, buf) < 0) { | |
284 gaim_connection_error(gc, "Error sending password"); | |
285 return; | |
286 } | |
287 g_free(buf); | |
288 } | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
289 |
6333 | 290 gethostname(hostname, sizeof(hostname)); |
291 hostname[sizeof(hostname) - 1] = '\0'; | |
7323 | 292 username = gaim_account_get_string(irc->account, "username", ""); |
10002 | 293 realname = gaim_account_get_string(irc->account, "realname", ""); |
7323 | 294 buf = irc_format(irc, "vvvv:", "USER", strlen(username) ? username : g_get_user_name(), hostname, irc->server, |
10002 | 295 strlen(realname) ? realname : IRC_DEFAULT_ALIAS); |
6333 | 296 if (irc_send(irc, buf) < 0) { |
297 gaim_connection_error(gc, "Error registering with server"); | |
298 return; | |
299 } | |
300 g_free(buf); | |
301 buf = irc_format(irc, "vn", "NICK", gaim_connection_get_display_name(gc)); | |
302 if (irc_send(irc, buf) < 0) { | |
303 gaim_connection_error(gc, "Error sending nickname"); | |
304 return; | |
305 } | |
306 g_free(buf); | |
307 | |
308 gc->inpa = gaim_input_add(irc->fd, GAIM_INPUT_READ, irc_input_cb, gc); | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
309 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
310 |
6333 | 311 static void irc_close(GaimConnection *gc) |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
312 { |
6333 | 313 struct irc_conn *irc = gc->proto_data; |
314 | |
6752 | 315 if (irc == NULL) |
316 return; | |
317 | |
6333 | 318 irc_cmd_quit(irc, "quit", NULL, NULL); |
319 | |
320 if (gc->inpa) | |
9441 | 321 gaim_input_remove(gc->inpa); |
6333 | 322 |
323 g_free(irc->inbuf); | |
324 close(irc->fd); | |
325 if (irc->timer) | |
8287
ef881489396e
[gaim-migrate @ 9011]
Christian Hammond <chipx86@chipx86.com>
parents:
8170
diff
changeset
|
326 gaim_timeout_remove(irc->timer); |
6333 | 327 g_hash_table_destroy(irc->cmds); |
328 g_hash_table_destroy(irc->msgs); | |
329 if (irc->motd) | |
330 g_string_free(irc->motd, TRUE); | |
331 g_free(irc->server); | |
332 g_free(irc); | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
333 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
334 |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
335 static int irc_im_send(GaimConnection *gc, const char *who, const char *what, GaimConvImFlags flags) |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
336 { |
6333 | 337 struct irc_conn *irc = gc->proto_data; |
338 const char *args[2]; | |
339 | |
7711 | 340 if (strchr(status_chars, *who) != NULL) |
6333 | 341 args[0] = who + 1; |
342 else | |
343 args[0] = who; | |
344 args[1] = what; | |
9442 | 345 |
6333 | 346 irc_cmd_privmsg(irc, "msg", NULL, args); |
347 return 1; | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
348 } |
2086 | 349 |
6333 | 350 static void irc_get_info(GaimConnection *gc, const char *who) |
2086 | 351 { |
6333 | 352 struct irc_conn *irc = gc->proto_data; |
353 const char *args[1]; | |
354 args[0] = who; | |
355 irc_cmd_whois(irc, "whois", NULL, args); | |
356 } | |
357 | |
9944 | 358 static void irc_set_status(GaimAccount *account, GaimStatus *status) |
6333 | 359 { |
9944 | 360 GaimConnection *gc = gaim_account_get_connection(account); |
6333 | 361 struct irc_conn *irc = gc->proto_data; |
362 const char *args[1]; | |
9944 | 363 const char *status_id = gaim_status_get_id(status); |
2086 | 364 |
9944 | 365 if (!strcmp(status_id, "away")) |
366 args[0] = gaim_status_get_attr_string(status, "message"); | |
367 else if (!strcmp(status_id, "available")) | |
368 args[0] = NULL; | |
2393
a7ecfd3f7714
[gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
369 |
6333 | 370 irc_cmd_away(irc, "away", NULL, args); |
4916 | 371 } |
372 | |
9285 | 373 static void irc_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) |
3029 | 374 { |
6333 | 375 struct irc_conn *irc = (struct irc_conn *)gc->proto_data; |
376 struct irc_buddy *ib = g_new0(struct irc_buddy, 1); | |
9285 | 377 ib->name = g_strdup(buddy->name); |
6333 | 378 g_hash_table_insert(irc->buddies, ib->name, ib); |
9238 | 379 |
9553 | 380 /* if the timer isn't set, this is during signon, so we don't want to flood |
381 * ourself off with ISON's, so we don't, but after that we want to know when | |
382 * someone's online asap */ | |
383 if (irc->timer) | |
384 irc_ison_one(irc, ib); | |
3029 | 385 } |
3622 | 386 |
9285 | 387 static void irc_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) |
6333 | 388 { |
389 struct irc_conn *irc = (struct irc_conn *)gc->proto_data; | |
9285 | 390 g_hash_table_remove(irc->buddies, buddy->name); |
3616 | 391 } |
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4509
diff
changeset
|
392 |
6333 | 393 static void irc_input_cb(gpointer data, gint source, GaimInputCondition cond) |
394 { | |
395 GaimConnection *gc = data; | |
396 struct irc_conn *irc = gc->proto_data; | |
397 char *cur, *end; | |
398 int len; | |
399 | |
400 if (irc->inbuflen < irc->inbufused + IRC_INITIAL_BUFSIZE) { | |
401 irc->inbuflen += IRC_INITIAL_BUFSIZE; | |
402 irc->inbuf = g_realloc(irc->inbuf, irc->inbuflen); | |
3708 | 403 } |
3616 | 404 |
6333 | 405 if ((len = read(irc->fd, irc->inbuf + irc->inbufused, IRC_INITIAL_BUFSIZE - 1)) < 0) { |
7653 | 406 gaim_connection_error(gc, _("Read error")); |
6333 | 407 return; |
6369 | 408 } else if (len == 0) { |
9440 | 409 gaim_connection_error(gc, _("Server has disconnected")); |
6369 | 410 return; |
6333 | 411 } |
6369 | 412 |
6333 | 413 irc->inbufused += len; |
414 irc->inbuf[irc->inbufused] = '\0'; | |
3616 | 415 |
8156 | 416 cur = irc->inbuf; |
417 while (cur < irc->inbuf + irc->inbufused && | |
418 ((end = strstr(cur, "\r\n")) || (end = strstr(cur, "\n")))) { | |
419 int step = (*end == '\r' ? 2 : 1); | |
6333 | 420 *end = '\0'; |
421 irc_parse_msg(irc, cur); | |
8156 | 422 cur = end + step; |
6333 | 423 } |
424 if (cur != irc->inbuf + irc->inbufused) { /* leftover */ | |
425 irc->inbufused -= (cur - irc->inbuf); | |
426 memmove(irc->inbuf, cur, irc->inbufused); | |
427 } else { | |
428 irc->inbufused = 0; | |
429 } | |
3616 | 430 } |
431 | |
6333 | 432 static void irc_chat_join (GaimConnection *gc, GHashTable *data) |
433 { | |
434 struct irc_conn *irc = gc->proto_data; | |
435 const char *args[2]; | |
3616 | 436 |
6333 | 437 args[0] = g_hash_table_lookup(data, "channel"); |
438 args[1] = g_hash_table_lookup(data, "password"); | |
439 irc_cmd_join(irc, "join", NULL, args); | |
3622 | 440 } |
441 | |
9917 | 442 static char *irc_get_chat_name(GHashTable *data) { |
443 return g_strdup(g_hash_table_lookup(data, "channel")); | |
444 } | |
445 | |
6333 | 446 static void irc_chat_invite(GaimConnection *gc, int id, const char *message, const char *name) |
3751 | 447 { |
6333 | 448 struct irc_conn *irc = gc->proto_data; |
449 GaimConversation *convo = gaim_find_chat(gc, id); | |
450 const char *args[2]; | |
3751 | 451 |
6333 | 452 if (!convo) { |
453 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Got chat invite request for bogus chat\n"); | |
454 return; | |
455 } | |
456 args[0] = name; | |
457 args[1] = gaim_conversation_get_name(convo); | |
458 irc_cmd_invite(irc, "invite", gaim_conversation_get_name(convo), args); | |
3707 | 459 } |
460 | |
6333 | 461 |
462 static void irc_chat_leave (GaimConnection *gc, int id) | |
3707 | 463 { |
6333 | 464 struct irc_conn *irc = gc->proto_data; |
465 GaimConversation *convo = gaim_find_chat(gc, id); | |
466 const char *args[2]; | |
5298 | 467 |
6333 | 468 if (!convo) |
469 return; | |
3735 | 470 |
6333 | 471 args[0] = gaim_conversation_get_name(convo); |
472 args[1] = NULL; | |
473 irc_cmd_part(irc, "part", gaim_conversation_get_name(convo), args); | |
474 serv_got_chat_left(gc, id); | |
3735 | 475 } |
476 | |
6333 | 477 static int irc_chat_send(GaimConnection *gc, int id, const char *what) |
3735 | 478 { |
6333 | 479 struct irc_conn *irc = gc->proto_data; |
480 GaimConversation *convo = gaim_find_chat(gc, id); | |
481 const char *args[2]; | |
8163 | 482 char *tmp; |
6333 | 483 |
484 if (!convo) { | |
485 gaim_debug(GAIM_DEBUG_ERROR, "irc", "chat send on nonexistent chat\n"); | |
486 return -EINVAL; | |
487 } | |
9130 | 488 #if 0 |
6333 | 489 if (*what == '/') { |
490 return irc_parse_cmd(irc, convo->name, what + 1); | |
491 } | |
9130 | 492 #endif |
6333 | 493 args[0] = convo->name; |
494 args[1] = what; | |
495 | |
496 irc_cmd_privmsg(irc, "msg", NULL, args); | |
8163 | 497 |
498 tmp = gaim_escape_html(what); | |
499 serv_got_chat_in(gc, id, gaim_connection_get_display_name(gc), 0, tmp, time(NULL)); | |
500 g_free(tmp); | |
6333 | 501 return 0; |
3707 | 502 } |
503 | |
6333 | 504 static guint irc_nick_hash(const char *nick) |
505 { | |
506 char *lc; | |
507 guint bucket; | |
6270
1bf6fd117797
[gaim-migrate @ 6767]
Christian Hammond <chipx86@chipx86.com>
parents:
6240
diff
changeset
|
508 |
6333 | 509 lc = g_utf8_strdown(nick, -1); |
510 bucket = g_str_hash(lc); | |
511 g_free(lc); | |
6270
1bf6fd117797
[gaim-migrate @ 6767]
Christian Hammond <chipx86@chipx86.com>
parents:
6240
diff
changeset
|
512 |
6333 | 513 return bucket; |
3029 | 514 } |
515 | |
6333 | 516 static gboolean irc_nick_equal(const char *nick1, const char *nick2) |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
517 { |
6333 | 518 return (gaim_utf8_strcasecmp(nick1, nick2) == 0); |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
519 } |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
520 |
6333 | 521 static void irc_buddy_free(struct irc_buddy *ib) |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
522 { |
6333 | 523 g_free(ib->name); |
524 g_free(ib); | |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
525 } |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
526 |
9154 | 527 static void irc_chat_set_topic(GaimConnection *gc, int id, const char *topic) |
528 { | |
529 char *buf; | |
530 const char *name = NULL; | |
531 struct irc_conn *irc; | |
532 | |
533 irc = gc->proto_data; | |
534 name = gaim_conversation_get_name(gaim_find_chat(gc, id)); | |
535 | |
536 if (name == NULL) | |
537 return; | |
538 | |
539 buf = irc_format(irc, "vt:", "TOPIC", name, topic); | |
540 irc_send(irc, buf); | |
541 g_free(buf); | |
542 } | |
543 | |
8114 | 544 static GaimRoomlist *irc_roomlist_get_list(GaimConnection *gc) |
545 { | |
546 struct irc_conn *irc; | |
547 GList *fields = NULL; | |
548 GaimRoomlistField *f; | |
8352 | 549 char *buf; |
8114 | 550 |
551 irc = gc->proto_data; | |
552 | |
553 if (irc->roomlist) | |
554 gaim_roomlist_unref(irc->roomlist); | |
555 | |
556 irc->roomlist = gaim_roomlist_new(gaim_connection_get_account(gc)); | |
557 | |
558 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "channel", TRUE); | |
559 fields = g_list_append(fields, f); | |
560 | |
561 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_INT, _("Users"), "users", FALSE); | |
562 fields = g_list_append(fields, f); | |
563 | |
564 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, _("Topic"), "topic", FALSE); | |
565 fields = g_list_append(fields, f); | |
566 | |
567 gaim_roomlist_set_fields(irc->roomlist, fields); | |
568 | |
8352 | 569 buf = irc_format(irc, "v", "LIST"); |
570 irc_send(irc, buf); | |
571 g_free(buf); | |
8114 | 572 |
573 return irc->roomlist; | |
574 } | |
575 | |
576 static void irc_roomlist_cancel(GaimRoomlist *list) | |
577 { | |
578 GaimConnection *gc = gaim_account_get_connection(list->account); | |
579 struct irc_conn *irc; | |
580 | |
581 if (gc == NULL) | |
582 return; | |
583 | |
584 irc = gc->proto_data; | |
585 | |
586 gaim_roomlist_set_in_progress(list, FALSE); | |
587 | |
588 if (irc->roomlist == list) { | |
589 irc->roomlist = NULL; | |
590 gaim_roomlist_unref(list); | |
591 } | |
592 } | |
593 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
594 static GaimPluginProtocolInfo prpl_info = |
2086 | 595 { |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
596 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_PASSWORD_OPTIONAL, |
9475 | 597 NULL, /* user_splits */ |
598 NULL, /* protocol_options */ | |
9951 | 599 NO_BUDDY_ICONS, /* icon_spec */ |
600 irc_blist_icon, /* list_icon */ | |
601 irc_blist_emblems, /* list_emblems */ | |
9475 | 602 NULL, /* status_text */ |
603 NULL, /* tooltip_text */ | |
9951 | 604 irc_status_types, /* away_states */ |
9475 | 605 NULL, /* blist_node_menu */ |
9951 | 606 irc_chat_join_info, /* chat_info */ |
9754 | 607 irc_chat_info_defaults, /* chat_info_defaults */ |
9951 | 608 irc_login, /* login */ |
609 irc_close, /* close */ | |
610 irc_im_send, /* send_im */ | |
9475 | 611 NULL, /* set_info */ |
612 NULL, /* send_typing */ | |
9951 | 613 irc_get_info, /* get_info */ |
614 irc_set_status, /* set_status */ | |
9475 | 615 NULL, /* set_idle */ |
616 NULL, /* change_passwd */ | |
9951 | 617 irc_add_buddy, /* add_buddy */ |
9475 | 618 NULL, /* add_buddies */ |
9951 | 619 irc_remove_buddy, /* remove_buddy */ |
9475 | 620 NULL, /* remove_buddies */ |
9741 | 621 NULL, /* add_permit */ |
622 NULL, /* add_deny */ | |
623 NULL, /* rem_permit */ | |
624 NULL, /* rem_deny */ | |
625 NULL, /* set_permit_deny */ | |
9475 | 626 NULL, /* warn */ |
9951 | 627 irc_chat_join, /* join_chat */ |
9475 | 628 NULL, /* reject_chat */ |
9951 | 629 irc_get_chat_name, /* get_chat_name */ |
630 irc_chat_invite, /* chat_invite */ | |
631 irc_chat_leave, /* chat_leave */ | |
9475 | 632 NULL, /* chat_whisper */ |
9951 | 633 irc_chat_send, /* chat_send */ |
9475 | 634 NULL, /* keepalive */ |
635 NULL, /* register_user */ | |
636 NULL, /* get_cb_info */ | |
637 NULL, /* get_cb_away */ | |
638 NULL, /* alias_buddy */ | |
639 NULL, /* group_buddy */ | |
640 NULL, /* rename_group */ | |
641 NULL, /* buddy_free */ | |
642 NULL, /* convo_closed */ | |
643 NULL, /* normalize */ | |
644 NULL, /* set_buddy_icon */ | |
645 NULL, /* remove_group */ | |
646 NULL, /* get_cb_real_name */ | |
9951 | 647 irc_chat_set_topic, /* set_chat_topic */ |
9475 | 648 NULL, /* find_blist_chat */ |
649 irc_roomlist_get_list, /* roomlist_get_list */ | |
650 irc_roomlist_cancel, /* roomlist_cancel */ | |
651 NULL, /* roomlist_expand_category */ | |
652 NULL, /* can_receive_file */ | |
653 irc_dccsend_send_file /* send_file */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
654 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
655 |
8114 | 656 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
657 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
658 { |
9943 | 659 GAIM_PLUGIN_MAGIC, |
660 GAIM_MAJOR_VERSION, | |
661 GAIM_MINOR_VERSION, | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
662 GAIM_PLUGIN_PROTOCOL, /**< type */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
663 NULL, /**< ui_requirement */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
664 0, /**< flags */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
665 NULL, /**< dependencies */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
666 GAIM_PRIORITY_DEFAULT, /**< priority */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
667 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
668 "prpl-irc", /**< id */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
669 "IRC", /**< name */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
670 VERSION, /**< version */ |
6333 | 671 N_("IRC Protocol Plugin"), /** summary */ |
672 N_("The IRC Protocol Plugin that Sucks Less"), /** description */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
673 NULL, /**< author */ |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6369
diff
changeset
|
674 GAIM_WEBSITE, /**< homepage */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
675 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
676 NULL, /**< load */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
677 NULL, /**< unload */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
678 NULL, /**< destroy */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
679 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
680 NULL, /**< ui_info */ |
8993 | 681 &prpl_info, /**< extra_info */ |
682 NULL, | |
9015 | 683 irc_actions |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
684 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
685 |
6333 | 686 static void _init_plugin(GaimPlugin *plugin) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
687 { |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
688 GaimAccountUserSplit *split; |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
689 GaimAccountOption *option; |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
690 |
6333 | 691 split = gaim_account_user_split_new(_("Server"), IRC_DEFAULT_SERVER, '@'); |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
692 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split); |
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
693 |
6459
b52870734c21
[gaim-migrate @ 6968]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
694 option = gaim_account_option_int_new(_("Port"), "port", IRC_DEFAULT_PORT); |
6333 | 695 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
696 |
6333 | 697 option = gaim_account_option_string_new(_("Encoding"), "encoding", IRC_DEFAULT_CHARSET); |
698 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
699 |
7323 | 700 option = gaim_account_option_string_new(_("Username"), "username", ""); |
701 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
702 | |
10002 | 703 option = gaim_account_option_string_new(_("Real name"), "realname", ""); |
704 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
705 | |
6333 | 706 _irc_plugin = plugin; |
9130 | 707 |
708 irc_register_commands(); | |
2086 | 709 } |
710 | |
6333 | 711 GAIM_INIT_PLUGIN(irc, _init_plugin, info); |