Mercurial > pidgin
annotate src/protocols/irc/irc.c @ 9553:8a64666476e6
[gaim-migrate @ 10386]
(13:06:08) nosnilmot: Paco-Paco / LSchiere: this cures the flooding on
signon for me
committer: Tailor Script <tailor@pidgin.im>
| author | Luke Schierer <lschiere@pidgin.im> |
|---|---|
| date | Sat, 17 Jul 2004 17:08:24 +0000 |
| parents | 7a65fdba750f |
| children | db62420a53a2 |
| 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" |
| 32 #include "multi.h" | |
| 7148 | 33 #include "notify.h" |
| 9030 | 34 #include "prpl.h" |
| 35 #include "plugin.h" | |
| 6350 | 36 #include "util.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); |
| 43 static void irc_blist_emblems(GaimBuddy *b, char **se, char **sw, char **nw, char **ne); | |
| 6333 | 44 static GList *irc_away_states(GaimConnection *gc); |
| 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 |
| 6695 | 142 static void irc_blist_emblems(GaimBuddy *b, char **se, char **sw, char **nw, char **ne) |
| 3751 | 143 { |
| 6333 | 144 if (b->present == GAIM_BUDDY_OFFLINE) |
| 145 *se = "offline"; | |
| 2086 | 146 } |
| 147 | |
| 6333 | 148 static GList *irc_away_states(GaimConnection *gc) |
| 2086 | 149 { |
| 6333 | 150 return g_list_append(NULL, (gpointer)GAIM_AWAY_CUSTOM); |
| 3452 | 151 } |
| 152 | |
| 9015 | 153 static GList *irc_actions(GaimPlugin *plugin, gpointer context) |
| 7148 | 154 { |
| 155 GList *list = NULL; | |
| 9015 | 156 GaimPluginAction *act = NULL; |
| 7148 | 157 |
| 9015 | 158 act = gaim_plugin_action_new(_("View MOTD"), irc_view_motd); |
| 159 list = g_list_append(list, act); | |
| 7148 | 160 |
| 161 return list; | |
| 162 } | |
| 163 | |
| 9466 | 164 #if 0 |
| 9030 | 165 static GList *irc_blist_node_menu(GaimBlistNode *node) |
| 2086 | 166 { |
| 8351 | 167 GList *m = NULL; |
| 9030 | 168 GaimBlistNodeAction *act; |
| 169 | |
| 8351 | 170 return m; |
| 2086 | 171 } |
| 9466 | 172 #endif |
| 2086 | 173 |
| 6333 | 174 static GList *irc_chat_join_info(GaimConnection *gc) |
| 2086 | 175 { |
|
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
176 GList *m = NULL; |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
177 struct proto_chat_entry *pce; |
|
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
178 |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
179 pce = g_new0(struct proto_chat_entry, 1); |
| 7841 | 180 pce->label = _("_Channel:"); |
| 5234 | 181 pce->identifier = "channel"; |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
182 m = g_list_append(m, pce); |
|
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
183 |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
184 pce = g_new0(struct proto_chat_entry, 1); |
| 7841 | 185 pce->label = _("_Password:"); |
| 5234 | 186 pce->identifier = "password"; |
| 6499 | 187 pce->secret = TRUE; |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
188 m = g_list_append(m, pce); |
|
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
189 |
|
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
190 return m; |
| 2086 | 191 } |
| 192 | |
| 6333 | 193 static void irc_login(GaimAccount *account) |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
194 { |
| 6333 | 195 GaimConnection *gc; |
| 196 struct irc_conn *irc; | |
| 197 char *buf, **userparts; | |
| 198 const char *username = gaim_account_get_username(account); | |
| 199 int err; | |
| 200 | |
| 201 gc = gaim_account_get_connection(account); | |
| 8677 | 202 gc->flags |= GAIM_CONNECTION_NO_NEWLINES; |
| 6333 | 203 |
| 6752 | 204 if (strpbrk(username, " \t\v\r\n") != NULL) { |
| 205 gaim_connection_error(gc, _("IRC nicks may not contain whitespace")); | |
| 206 return; | |
| 207 } | |
| 208 | |
| 6333 | 209 gc->proto_data = irc = g_new0(struct irc_conn, 1); |
| 210 irc->account = account; | |
| 211 | |
| 212 userparts = g_strsplit(username, "@", 2); | |
| 213 gaim_connection_set_display_name(gc, userparts[0]); | |
| 214 irc->server = g_strdup(userparts[1]); | |
| 215 g_strfreev(userparts); | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
216 |
| 6333 | 217 irc->buddies = g_hash_table_new_full((GHashFunc)irc_nick_hash, (GEqualFunc)irc_nick_equal, |
| 218 NULL, (GDestroyNotify)irc_buddy_free); | |
| 219 irc->cmds = g_hash_table_new(g_str_hash, g_str_equal); | |
| 220 irc_cmd_table_build(irc); | |
| 221 irc->msgs = g_hash_table_new(g_str_hash, g_str_equal); | |
| 222 irc_msg_table_build(irc); | |
| 223 | |
| 224 buf = g_strdup_printf(_("Signon: %s"), username); | |
| 225 gaim_connection_update_progress(gc, buf, 1, 2); | |
| 226 g_free(buf); | |
| 227 | |
| 228 err = gaim_proxy_connect(account, irc->server, | |
| 229 gaim_account_get_int(account, "port", IRC_DEFAULT_PORT), | |
| 230 irc_login_cb, gc); | |
| 231 | |
| 232 if (err || !account->gc) { | |
| 233 gaim_connection_error(gc, _("Couldn't create socket")); | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
234 return; |
| 6333 | 235 } |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
236 } |
|
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
237 |
| 6333 | 238 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
|
239 { |
| 6333 | 240 GaimConnection *gc = data; |
| 241 struct irc_conn *irc = gc->proto_data; | |
| 242 char hostname[256]; | |
| 243 char *buf; | |
| 7323 | 244 const char *username; |
| 6333 | 245 GList *connections = gaim_connections_get_all(); |
| 246 | |
| 8778 | 247 if (source < 0) { |
| 248 gaim_connection_error(gc, _("Couldn't connect to host")); | |
| 6333 | 249 return; |
| 8778 | 250 } |
| 6333 | 251 |
| 252 if (!g_list_find(connections, gc)) { | |
| 253 close(source); | |
| 254 return; | |
| 255 } | |
| 256 | |
| 257 irc->fd = source; | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
258 |
| 6333 | 259 if (gc->account->password && *gc->account->password) { |
| 260 buf = irc_format(irc, "vv", "PASS", gc->account->password); | |
| 261 if (irc_send(irc, buf) < 0) { | |
| 262 gaim_connection_error(gc, "Error sending password"); | |
| 263 return; | |
| 264 } | |
| 265 g_free(buf); | |
| 266 } | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
267 |
| 6333 | 268 gethostname(hostname, sizeof(hostname)); |
| 269 hostname[sizeof(hostname) - 1] = '\0'; | |
| 7323 | 270 username = gaim_account_get_string(irc->account, "username", ""); |
| 271 buf = irc_format(irc, "vvvv:", "USER", strlen(username) ? username : g_get_user_name(), hostname, irc->server, | |
| 6333 | 272 gc->account->alias && *gc->account->alias ? gc->account->alias : IRC_DEFAULT_ALIAS); |
| 273 if (irc_send(irc, buf) < 0) { | |
| 274 gaim_connection_error(gc, "Error registering with server"); | |
| 275 return; | |
| 276 } | |
| 277 g_free(buf); | |
| 278 buf = irc_format(irc, "vn", "NICK", gaim_connection_get_display_name(gc)); | |
| 279 if (irc_send(irc, buf) < 0) { | |
| 280 gaim_connection_error(gc, "Error sending nickname"); | |
| 281 return; | |
| 282 } | |
| 283 g_free(buf); | |
| 284 | |
| 285 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
|
286 } |
|
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
287 |
| 6333 | 288 static void irc_close(GaimConnection *gc) |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
289 { |
| 6333 | 290 struct irc_conn *irc = gc->proto_data; |
| 291 | |
| 6752 | 292 if (irc == NULL) |
| 293 return; | |
| 294 | |
| 6333 | 295 irc_cmd_quit(irc, "quit", NULL, NULL); |
| 296 | |
| 297 if (gc->inpa) | |
| 9441 | 298 gaim_input_remove(gc->inpa); |
| 6333 | 299 |
| 300 g_free(irc->inbuf); | |
| 301 close(irc->fd); | |
| 302 if (irc->timer) | |
|
8287
ef881489396e
[gaim-migrate @ 9011]
Christian Hammond <chipx86@chipx86.com>
parents:
8170
diff
changeset
|
303 gaim_timeout_remove(irc->timer); |
| 6333 | 304 g_hash_table_destroy(irc->cmds); |
| 305 g_hash_table_destroy(irc->msgs); | |
| 306 if (irc->motd) | |
| 307 g_string_free(irc->motd, TRUE); | |
| 308 g_free(irc->server); | |
| 309 g_free(irc); | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
310 } |
|
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
311 |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
312 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
|
313 { |
| 6333 | 314 struct irc_conn *irc = gc->proto_data; |
| 315 const char *args[2]; | |
| 316 | |
| 7711 | 317 if (strchr(status_chars, *who) != NULL) |
| 6333 | 318 args[0] = who + 1; |
| 319 else | |
| 320 args[0] = who; | |
| 321 args[1] = what; | |
| 9442 | 322 |
| 6333 | 323 irc_cmd_privmsg(irc, "msg", NULL, args); |
| 324 return 1; | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
325 } |
| 2086 | 326 |
| 6333 | 327 static void irc_get_info(GaimConnection *gc, const char *who) |
| 2086 | 328 { |
| 6333 | 329 struct irc_conn *irc = gc->proto_data; |
| 330 const char *args[1]; | |
| 331 args[0] = who; | |
| 332 irc_cmd_whois(irc, "whois", NULL, args); | |
| 333 } | |
| 334 | |
| 335 static void irc_set_away(GaimConnection *gc, const char *state, const char *msg) | |
| 336 { | |
| 337 struct irc_conn *irc = gc->proto_data; | |
| 338 const char *args[1]; | |
| 2086 | 339 |
|
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4067
diff
changeset
|
340 if (gc->away) { |
|
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4067
diff
changeset
|
341 g_free(gc->away); |
|
2394
579f8d4347ad
[gaim-migrate @ 2407]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
342 gc->away = NULL; |
|
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4067
diff
changeset
|
343 } |
|
2393
a7ecfd3f7714
[gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
344 |
| 6333 | 345 if (msg) |
|
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4067
diff
changeset
|
346 gc->away = g_strdup(msg); |
| 2086 | 347 |
| 6333 | 348 args[0] = msg; |
| 349 irc_cmd_away(irc, "away", NULL, args); | |
| 4916 | 350 } |
| 351 | |
| 9285 | 352 static void irc_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) |
| 3029 | 353 { |
| 6333 | 354 struct irc_conn *irc = (struct irc_conn *)gc->proto_data; |
| 355 struct irc_buddy *ib = g_new0(struct irc_buddy, 1); | |
| 9285 | 356 ib->name = g_strdup(buddy->name); |
| 6333 | 357 g_hash_table_insert(irc->buddies, ib->name, ib); |
| 9238 | 358 |
| 9553 | 359 /* if the timer isn't set, this is during signon, so we don't want to flood |
| 360 * ourself off with ISON's, so we don't, but after that we want to know when | |
| 361 * someone's online asap */ | |
| 362 if (irc->timer) | |
| 363 irc_ison_one(irc, ib); | |
| 3029 | 364 } |
| 3622 | 365 |
| 9285 | 366 static void irc_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) |
| 6333 | 367 { |
| 368 struct irc_conn *irc = (struct irc_conn *)gc->proto_data; | |
| 9285 | 369 g_hash_table_remove(irc->buddies, buddy->name); |
| 3616 | 370 } |
|
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4509
diff
changeset
|
371 |
| 6333 | 372 static void irc_input_cb(gpointer data, gint source, GaimInputCondition cond) |
| 373 { | |
| 374 GaimConnection *gc = data; | |
| 375 struct irc_conn *irc = gc->proto_data; | |
| 376 char *cur, *end; | |
| 377 int len; | |
| 378 | |
| 379 if (irc->inbuflen < irc->inbufused + IRC_INITIAL_BUFSIZE) { | |
| 380 irc->inbuflen += IRC_INITIAL_BUFSIZE; | |
| 381 irc->inbuf = g_realloc(irc->inbuf, irc->inbuflen); | |
| 3708 | 382 } |
| 3616 | 383 |
| 6333 | 384 if ((len = read(irc->fd, irc->inbuf + irc->inbufused, IRC_INITIAL_BUFSIZE - 1)) < 0) { |
| 7653 | 385 gaim_connection_error(gc, _("Read error")); |
| 6333 | 386 return; |
| 6369 | 387 } else if (len == 0) { |
| 9440 | 388 gaim_connection_error(gc, _("Server has disconnected")); |
| 6369 | 389 return; |
| 6333 | 390 } |
| 6369 | 391 |
| 6333 | 392 irc->inbufused += len; |
| 393 irc->inbuf[irc->inbufused] = '\0'; | |
| 3616 | 394 |
| 8156 | 395 cur = irc->inbuf; |
| 396 while (cur < irc->inbuf + irc->inbufused && | |
| 397 ((end = strstr(cur, "\r\n")) || (end = strstr(cur, "\n")))) { | |
| 398 int step = (*end == '\r' ? 2 : 1); | |
| 6333 | 399 *end = '\0'; |
| 400 irc_parse_msg(irc, cur); | |
| 8156 | 401 cur = end + step; |
| 6333 | 402 } |
| 403 if (cur != irc->inbuf + irc->inbufused) { /* leftover */ | |
| 404 irc->inbufused -= (cur - irc->inbuf); | |
| 405 memmove(irc->inbuf, cur, irc->inbufused); | |
| 406 } else { | |
| 407 irc->inbufused = 0; | |
| 408 } | |
| 3616 | 409 } |
| 410 | |
| 6333 | 411 static void irc_chat_join (GaimConnection *gc, GHashTable *data) |
| 412 { | |
| 413 struct irc_conn *irc = gc->proto_data; | |
| 414 const char *args[2]; | |
| 3616 | 415 |
| 6333 | 416 args[0] = g_hash_table_lookup(data, "channel"); |
| 417 args[1] = g_hash_table_lookup(data, "password"); | |
| 418 irc_cmd_join(irc, "join", NULL, args); | |
| 3622 | 419 } |
| 420 | |
| 6333 | 421 static void irc_chat_invite(GaimConnection *gc, int id, const char *message, const char *name) |
| 3751 | 422 { |
| 6333 | 423 struct irc_conn *irc = gc->proto_data; |
| 424 GaimConversation *convo = gaim_find_chat(gc, id); | |
| 425 const char *args[2]; | |
| 3751 | 426 |
| 6333 | 427 if (!convo) { |
| 428 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Got chat invite request for bogus chat\n"); | |
| 429 return; | |
| 430 } | |
| 431 args[0] = name; | |
| 432 args[1] = gaim_conversation_get_name(convo); | |
| 433 irc_cmd_invite(irc, "invite", gaim_conversation_get_name(convo), args); | |
| 3707 | 434 } |
| 435 | |
| 6333 | 436 |
| 437 static void irc_chat_leave (GaimConnection *gc, int id) | |
| 3707 | 438 { |
| 6333 | 439 struct irc_conn *irc = gc->proto_data; |
| 440 GaimConversation *convo = gaim_find_chat(gc, id); | |
| 441 const char *args[2]; | |
| 5298 | 442 |
| 6333 | 443 if (!convo) |
| 444 return; | |
| 3735 | 445 |
| 6333 | 446 args[0] = gaim_conversation_get_name(convo); |
| 447 args[1] = NULL; | |
| 448 irc_cmd_part(irc, "part", gaim_conversation_get_name(convo), args); | |
| 449 serv_got_chat_left(gc, id); | |
| 3735 | 450 } |
| 451 | |
| 6333 | 452 static int irc_chat_send(GaimConnection *gc, int id, const char *what) |
| 3735 | 453 { |
| 6333 | 454 struct irc_conn *irc = gc->proto_data; |
| 455 GaimConversation *convo = gaim_find_chat(gc, id); | |
| 456 const char *args[2]; | |
| 8163 | 457 char *tmp; |
| 6333 | 458 |
| 459 if (!convo) { | |
| 460 gaim_debug(GAIM_DEBUG_ERROR, "irc", "chat send on nonexistent chat\n"); | |
| 461 return -EINVAL; | |
| 462 } | |
| 9130 | 463 #if 0 |
| 6333 | 464 if (*what == '/') { |
| 465 return irc_parse_cmd(irc, convo->name, what + 1); | |
| 466 } | |
| 9130 | 467 #endif |
| 6333 | 468 args[0] = convo->name; |
| 469 args[1] = what; | |
| 470 | |
| 471 irc_cmd_privmsg(irc, "msg", NULL, args); | |
| 8163 | 472 |
| 473 tmp = gaim_escape_html(what); | |
| 474 serv_got_chat_in(gc, id, gaim_connection_get_display_name(gc), 0, tmp, time(NULL)); | |
| 475 g_free(tmp); | |
| 6333 | 476 return 0; |
| 3707 | 477 } |
| 478 | |
| 6333 | 479 static guint irc_nick_hash(const char *nick) |
| 480 { | |
| 481 char *lc; | |
| 482 guint bucket; | |
|
6270
1bf6fd117797
[gaim-migrate @ 6767]
Christian Hammond <chipx86@chipx86.com>
parents:
6240
diff
changeset
|
483 |
| 6333 | 484 lc = g_utf8_strdown(nick, -1); |
| 485 bucket = g_str_hash(lc); | |
| 486 g_free(lc); | |
|
6270
1bf6fd117797
[gaim-migrate @ 6767]
Christian Hammond <chipx86@chipx86.com>
parents:
6240
diff
changeset
|
487 |
| 6333 | 488 return bucket; |
| 3029 | 489 } |
| 490 | |
| 6333 | 491 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
|
492 { |
| 6333 | 493 return (gaim_utf8_strcasecmp(nick1, nick2) == 0); |
|
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
494 } |
|
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
495 |
| 6333 | 496 static void irc_buddy_free(struct irc_buddy *ib) |
|
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
497 { |
| 6333 | 498 g_free(ib->name); |
| 499 g_free(ib); | |
|
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
500 } |
|
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
501 |
| 9154 | 502 static void irc_chat_set_topic(GaimConnection *gc, int id, const char *topic) |
| 503 { | |
| 504 char *buf; | |
| 505 const char *name = NULL; | |
| 506 struct irc_conn *irc; | |
| 507 | |
| 508 irc = gc->proto_data; | |
| 509 name = gaim_conversation_get_name(gaim_find_chat(gc, id)); | |
| 510 | |
| 511 if (name == NULL) | |
| 512 return; | |
| 513 | |
| 514 buf = irc_format(irc, "vt:", "TOPIC", name, topic); | |
| 515 irc_send(irc, buf); | |
| 516 g_free(buf); | |
| 517 } | |
| 518 | |
| 8114 | 519 static GaimRoomlist *irc_roomlist_get_list(GaimConnection *gc) |
| 520 { | |
| 521 struct irc_conn *irc; | |
| 522 GList *fields = NULL; | |
| 523 GaimRoomlistField *f; | |
| 8352 | 524 char *buf; |
| 8114 | 525 |
| 526 irc = gc->proto_data; | |
| 527 | |
| 528 if (irc->roomlist) | |
| 529 gaim_roomlist_unref(irc->roomlist); | |
| 530 | |
| 531 irc->roomlist = gaim_roomlist_new(gaim_connection_get_account(gc)); | |
| 532 | |
| 533 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "channel", TRUE); | |
| 534 fields = g_list_append(fields, f); | |
| 535 | |
| 536 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_INT, _("Users"), "users", FALSE); | |
| 537 fields = g_list_append(fields, f); | |
| 538 | |
| 539 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, _("Topic"), "topic", FALSE); | |
| 540 fields = g_list_append(fields, f); | |
| 541 | |
| 542 gaim_roomlist_set_fields(irc->roomlist, fields); | |
| 543 | |
| 8352 | 544 buf = irc_format(irc, "v", "LIST"); |
| 545 irc_send(irc, buf); | |
| 546 g_free(buf); | |
| 8114 | 547 |
| 548 return irc->roomlist; | |
| 549 } | |
| 550 | |
| 551 static void irc_roomlist_cancel(GaimRoomlist *list) | |
| 552 { | |
| 553 GaimConnection *gc = gaim_account_get_connection(list->account); | |
| 554 struct irc_conn *irc; | |
| 555 | |
| 556 if (gc == NULL) | |
| 557 return; | |
| 558 | |
| 559 irc = gc->proto_data; | |
| 560 | |
| 561 gaim_roomlist_set_in_progress(list, FALSE); | |
| 562 | |
| 563 if (irc->roomlist == list) { | |
| 564 irc->roomlist = NULL; | |
| 565 gaim_roomlist_unref(list); | |
| 566 } | |
| 567 } | |
| 568 | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
569 static GaimPluginProtocolInfo prpl_info = |
| 2086 | 570 { |
|
8749
d7b8eb1f0a18
[gaim-migrate @ 9504]
Christian Hammond <chipx86@chipx86.com>
parents:
8713
diff
changeset
|
571 GAIM_PRPL_API_VERSION, |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
572 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_PASSWORD_OPTIONAL, |
| 9475 | 573 NULL, /* user_splits */ |
| 574 NULL, /* protocol_options */ | |
| 575 NO_BUDDY_ICONS, /* icon_spec */ | |
| 576 irc_blist_icon, /* list_icon */ | |
| 577 irc_blist_emblems, /* list_emblems */ | |
| 578 NULL, /* status_text */ | |
| 579 NULL, /* tooltip_text */ | |
| 580 irc_away_states, /* away_states */ | |
| 581 NULL, /* blist_node_menu */ | |
| 582 irc_chat_join_info, /* chat_info */ | |
| 583 irc_login, /* login */ | |
| 584 irc_close, /* close */ | |
| 585 irc_im_send, /* send_im */ | |
| 586 NULL, /* set_info */ | |
| 587 NULL, /* send_typing */ | |
| 588 irc_get_info, /* get_info */ | |
| 589 irc_set_away, /* set_away */ | |
| 590 NULL, /* set_idle */ | |
| 591 NULL, /* change_passwd */ | |
| 592 irc_add_buddy, /* add_buddy */ | |
| 593 NULL, /* add_buddies */ | |
| 594 irc_remove_buddy, /* remove_buddy */ | |
| 595 NULL, /* remove_buddies */ | |
| 596 NULL, /* add_permit */ | |
| 597 NULL, /* add_deny */ | |
| 598 NULL, /* rem_permit */ | |
| 599 NULL, /* rem_deny */ | |
| 600 NULL, /* set_permit_deny */ | |
| 601 NULL, /* warn */ | |
| 602 irc_chat_join, /* join_chat */ | |
| 603 NULL, /* reject_chat */ | |
| 604 irc_chat_invite, /* chat_invite */ | |
| 605 irc_chat_leave, /* chat_leave */ | |
| 606 NULL, /* chat_whisper */ | |
| 607 irc_chat_send, /* chat_send */ | |
| 608 NULL, /* keepalive */ | |
| 609 NULL, /* register_user */ | |
| 610 NULL, /* get_cb_info */ | |
| 611 NULL, /* get_cb_away */ | |
| 612 NULL, /* alias_buddy */ | |
| 613 NULL, /* group_buddy */ | |
| 614 NULL, /* rename_group */ | |
| 615 NULL, /* buddy_free */ | |
| 616 NULL, /* convo_closed */ | |
| 617 NULL, /* normalize */ | |
| 618 NULL, /* set_buddy_icon */ | |
| 619 NULL, /* remove_group */ | |
| 620 NULL, /* get_cb_real_name */ | |
| 621 irc_chat_set_topic, /* set_chat_topic */ | |
| 622 NULL, /* find_blist_chat */ | |
| 623 irc_roomlist_get_list, /* roomlist_get_list */ | |
| 624 irc_roomlist_cancel, /* roomlist_cancel */ | |
| 625 NULL, /* roomlist_expand_category */ | |
| 626 NULL, /* can_receive_file */ | |
| 627 irc_dccsend_send_file /* send_file */ | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
628 }; |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
629 |
| 8114 | 630 |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
631 static GaimPluginInfo info = |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
632 { |
|
8749
d7b8eb1f0a18
[gaim-migrate @ 9504]
Christian Hammond <chipx86@chipx86.com>
parents:
8713
diff
changeset
|
633 GAIM_PLUGIN_API_VERSION, /**< api_version */ |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
634 GAIM_PLUGIN_PROTOCOL, /**< type */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
635 NULL, /**< ui_requirement */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
636 0, /**< flags */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
637 NULL, /**< dependencies */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
638 GAIM_PRIORITY_DEFAULT, /**< priority */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
639 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
640 "prpl-irc", /**< id */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
641 "IRC", /**< name */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
642 VERSION, /**< version */ |
| 6333 | 643 N_("IRC Protocol Plugin"), /** summary */ |
| 644 N_("The IRC Protocol Plugin that Sucks Less"), /** description */ | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
645 NULL, /**< author */ |
|
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6369
diff
changeset
|
646 GAIM_WEBSITE, /**< homepage */ |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
647 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
648 NULL, /**< load */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
649 NULL, /**< unload */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
650 NULL, /**< destroy */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
651 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
652 NULL, /**< ui_info */ |
| 8993 | 653 &prpl_info, /**< extra_info */ |
| 654 NULL, | |
| 9015 | 655 irc_actions |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
656 }; |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
657 |
| 6333 | 658 static void _init_plugin(GaimPlugin *plugin) |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
659 { |
|
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
660 GaimAccountUserSplit *split; |
|
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
661 GaimAccountOption *option; |
|
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
662 |
| 6333 | 663 split = gaim_account_user_split_new(_("Server"), IRC_DEFAULT_SERVER, '@'); |
|
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
664 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
|
665 |
|
6459
b52870734c21
[gaim-migrate @ 6968]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
666 option = gaim_account_option_int_new(_("Port"), "port", IRC_DEFAULT_PORT); |
| 6333 | 667 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
|
668 |
| 6333 | 669 option = gaim_account_option_string_new(_("Encoding"), "encoding", IRC_DEFAULT_CHARSET); |
| 670 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
|
671 |
| 7323 | 672 option = gaim_account_option_string_new(_("Username"), "username", ""); |
| 673 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
| 674 | |
| 6333 | 675 _irc_plugin = plugin; |
| 9130 | 676 |
| 677 irc_register_commands(); | |
| 2086 | 678 } |
| 679 | |
| 6333 | 680 GAIM_INIT_PLUGIN(irc, _init_plugin, info); |
