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