Mercurial > pidgin
annotate src/protocols/irc/irc.c @ 6350:34c07f5f34a0
[gaim-migrate @ 6849]
-Compile warning fixes from The Man (Paco-Paco)
-2 memleak fixes from me. One of them leaked the size of a chat message when
either sending or receiving, I forgot which (my bad!)
-Hopefully make AIM correctly refetch your buddy list when AOL doesn't
send it to you the first time
-Maybe something else
-Chocolate
-Vanilla
-Strawberry
-Napoleon
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Thu, 31 Jul 2003 23:21:36 +0000 |
| parents | e06e04e44914 |
| children | 07b30424146b |
| rev | line source |
|---|---|
| 6333 | 1 /** |
| 2 * @file irc.c | |
| 3 * | |
| 4 * gaim | |
| 2086 | 5 * |
| 6333 | 6 * Copyright (C) 2003, Ethan Blanton <eblanton@cs.purdue.edu> |
| 7 * Copyright (C) 2000-2003, Rob Flynn <rob@tgflinux.com> | |
| 2086 | 8 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> |
| 9 * | |
| 10 * This program is free software; you can redistribute it and/or modify | |
| 11 * it under the terms of the GNU General Public License as published by | |
| 12 * the Free Software Foundation; either version 2 of the License, or | |
| 13 * (at your option) any later version. | |
| 14 * | |
| 15 * This program is distributed in the hope that it will be useful, | |
| 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 18 * GNU General Public License for more details. | |
| 19 * | |
| 20 * You should have received a copy of the GNU General Public License | |
| 21 * along with this program; if not, write to the Free Software | |
| 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 23 */ | |
| 6333 | 24 |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5791
diff
changeset
|
25 #include "internal.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5791
diff
changeset
|
26 |
| 6333 | 27 #include "plugin.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5791
diff
changeset
|
28 #include "accountopt.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5791
diff
changeset
|
29 #include "multi.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5791
diff
changeset
|
30 #include "prpl.h" |
| 6333 | 31 #include "conversation.h" |
| 32 #include "debug.h" | |
| 33 #include "blist.h" | |
| 6350 | 34 #include "util.h" |
| 6333 | 35 #include "irc.h" |
| 4422 | 36 |
| 6333 | 37 static void irc_buddy_append(char *name, struct irc_buddy *ib, GString *string); |
| 2086 | 38 |
| 6333 | 39 static const char *irc_blist_icon(GaimAccount *a, struct buddy *b); |
| 40 static void irc_blist_emblems(struct buddy *b, char **se, char **sw, char **nw, char **ne); | |
| 41 static GList *irc_away_states(GaimConnection *gc); | |
| 42 /* static GList *irc_chat_info(GaimConnection *gc); */ | |
| 43 static void irc_login(GaimAccount *account); | |
| 44 static void irc_login_cb(gpointer data, gint source, GaimInputCondition cond); | |
| 45 static void irc_close(GaimConnection *gc); | |
| 46 static int irc_im_send(GaimConnection *gc, const char *who, const char *what, int len, int flags); | |
| 47 static int irc_chat_send(GaimConnection *gc, int id, const char *what); | |
| 48 static void irc_chat_join (GaimConnection *gc, GHashTable *data); | |
| 49 static void irc_input_cb(gpointer data, gint source, GaimInputCondition cond); | |
| 3751 | 50 |
| 6333 | 51 static guint irc_nick_hash(const char *nick); |
| 52 static gboolean irc_nick_equal(const char *nick1, const char *nick2); | |
| 53 static void irc_buddy_free(struct irc_buddy *ib); | |
| 3751 | 54 |
| 6333 | 55 static GaimPlugin *_irc_plugin = NULL; |
| 3029 | 56 |
| 6333 | 57 int irc_send(struct irc_conn *irc, const char *buf) |
| 3751 | 58 { |
| 6333 | 59 if (irc->fd < 0) |
| 60 return -1; | |
|
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2171
diff
changeset
|
61 |
| 6333 | 62 /* gaim_debug(GAIM_DEBUG_MISC, "irc", "sent: %s", buf); */ |
| 63 return write(irc->fd, buf, strlen(buf)); | |
|
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2171
diff
changeset
|
64 } |
|
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2171
diff
changeset
|
65 |
| 6333 | 66 /* XXX I don't like messing directly with these buddies */ |
| 67 gboolean irc_blist_timeout(struct irc_conn *irc) | |
| 2086 | 68 { |
| 6333 | 69 GString *string = g_string_sized_new(512); |
| 70 char *list, *buf; | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
71 |
| 6333 | 72 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
|
73 |
| 6333 | 74 list = g_string_free(string, FALSE); |
| 75 if (!list || !strlen(list)) { | |
| 76 g_free(list); | |
|
2137
18722ae5b882
[gaim-migrate @ 2147]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2131
diff
changeset
|
77 return TRUE; |
| 2086 | 78 } |
|
4416
8e62cee6d738
[gaim-migrate @ 4689]
Christian Hammond <chipx86@chipx86.com>
parents:
4373
diff
changeset
|
79 |
| 6333 | 80 buf = irc_format(irc, "v:", "ISON", list); |
| 81 g_free(list); | |
| 82 irc_send(irc, buf); | |
| 83 g_free(buf); | |
|
4416
8e62cee6d738
[gaim-migrate @ 4689]
Christian Hammond <chipx86@chipx86.com>
parents:
4373
diff
changeset
|
84 |
|
2131
acc11216ec5d
[gaim-migrate @ 2141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
85 return TRUE; |
| 2086 | 86 } |
| 87 | |
| 6333 | 88 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
|
89 { |
| 6333 | 90 ib->flag = FALSE; |
| 91 g_string_append_printf(string, "%s ", name); | |
| 3511 | 92 } |
| 93 | |
| 6333 | 94 static const char *irc_blist_icon(GaimAccount *a, struct buddy *b) |
| 3029 | 95 { |
| 6333 | 96 return "irc"; |
|
2339
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
97 } |
|
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
98 |
| 6333 | 99 static void irc_blist_emblems(struct buddy *b, char **se, char **sw, char **nw, char **ne) |
| 3751 | 100 { |
| 6333 | 101 if (b->present == GAIM_BUDDY_OFFLINE) |
| 102 *se = "offline"; | |
| 2086 | 103 } |
| 104 | |
| 6333 | 105 static GList *irc_away_states(GaimConnection *gc) |
| 2086 | 106 { |
| 6333 | 107 return g_list_append(NULL, (gpointer)GAIM_AWAY_CUSTOM); |
| 3452 | 108 } |
| 109 | |
| 6333 | 110 static GList *irc_buddy_menu(GaimConnection *gc, const char *who) |
| 2086 | 111 { |
| 6333 | 112 return NULL; |
| 2086 | 113 } |
| 114 | |
| 6333 | 115 static GList *irc_chat_join_info(GaimConnection *gc) |
| 2086 | 116 { |
|
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
117 GList *m = NULL; |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
118 struct proto_chat_entry *pce; |
|
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
119 |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
120 pce = g_new0(struct proto_chat_entry, 1); |
|
2466
f8eb5f120603
[gaim-migrate @ 2479]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2459
diff
changeset
|
121 pce->label = _("Channel:"); |
| 5234 | 122 pce->identifier = "channel"; |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
123 m = g_list_append(m, pce); |
|
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
124 |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
125 pce = g_new0(struct proto_chat_entry, 1); |
|
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
126 pce->label = _("Password:"); |
| 5234 | 127 pce->identifier = "password"; |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
128 m = g_list_append(m, pce); |
|
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
129 |
|
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
130 return m; |
| 2086 | 131 } |
| 132 | |
| 6333 | 133 static void irc_login(GaimAccount *account) |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
134 { |
| 6333 | 135 GaimConnection *gc; |
| 136 struct irc_conn *irc; | |
| 137 char *buf, **userparts; | |
| 138 const char *username = gaim_account_get_username(account); | |
| 139 int err; | |
| 140 | |
| 141 gc = gaim_account_get_connection(account); | |
| 142 | |
| 143 gc->flags |= OPT_CONN_AUTO_RESP; | |
| 144 | |
| 145 gc->proto_data = irc = g_new0(struct irc_conn, 1); | |
| 146 irc->account = account; | |
| 147 | |
| 148 userparts = g_strsplit(username, "@", 2); | |
| 149 gaim_connection_set_display_name(gc, userparts[0]); | |
| 150 irc->server = g_strdup(userparts[1]); | |
| 151 g_strfreev(userparts); | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
152 |
| 6333 | 153 irc->buddies = g_hash_table_new_full((GHashFunc)irc_nick_hash, (GEqualFunc)irc_nick_equal, |
| 154 NULL, (GDestroyNotify)irc_buddy_free); | |
| 155 irc->cmds = g_hash_table_new(g_str_hash, g_str_equal); | |
| 156 irc_cmd_table_build(irc); | |
| 157 irc->msgs = g_hash_table_new(g_str_hash, g_str_equal); | |
| 158 irc_msg_table_build(irc); | |
| 159 | |
| 160 buf = g_strdup_printf(_("Signon: %s"), username); | |
| 161 gaim_connection_update_progress(gc, buf, 1, 2); | |
| 162 g_free(buf); | |
| 163 | |
| 164 err = gaim_proxy_connect(account, irc->server, | |
| 165 gaim_account_get_int(account, "port", IRC_DEFAULT_PORT), | |
| 166 irc_login_cb, gc); | |
| 167 | |
| 168 if (err || !account->gc) { | |
| 169 gaim_connection_error(gc, _("Couldn't create socket")); | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
170 return; |
| 6333 | 171 } |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
172 } |
|
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
173 |
| 6333 | 174 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
|
175 { |
| 6333 | 176 GaimConnection *gc = data; |
| 177 struct irc_conn *irc = gc->proto_data; | |
| 178 char hostname[256]; | |
| 179 char *buf; | |
| 180 GList *connections = gaim_connections_get_all(); | |
| 181 | |
| 182 if (source < 0) | |
| 183 return; | |
| 184 | |
| 185 if (!g_list_find(connections, gc)) { | |
| 186 close(source); | |
| 187 return; | |
| 188 } | |
| 189 | |
| 190 irc->fd = source; | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
191 |
| 6333 | 192 if (gc->account->password && *gc->account->password) { |
| 193 buf = irc_format(irc, "vv", "PASS", gc->account->password); | |
| 194 if (irc_send(irc, buf) < 0) { | |
| 195 gaim_connection_error(gc, "Error sending password"); | |
| 196 return; | |
| 197 } | |
| 198 g_free(buf); | |
| 199 } | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
200 |
| 6333 | 201 gethostname(hostname, sizeof(hostname)); |
| 202 hostname[sizeof(hostname) - 1] = '\0'; | |
| 203 buf = irc_format(irc, "vvvv:", "USER", g_get_user_name(), hostname, irc->server, | |
| 204 gc->account->alias && *gc->account->alias ? gc->account->alias : IRC_DEFAULT_ALIAS); | |
| 205 if (irc_send(irc, buf) < 0) { | |
| 206 gaim_connection_error(gc, "Error registering with server"); | |
| 207 return; | |
| 208 } | |
| 209 g_free(buf); | |
| 210 buf = irc_format(irc, "vn", "NICK", gaim_connection_get_display_name(gc)); | |
| 211 if (irc_send(irc, buf) < 0) { | |
| 212 gaim_connection_error(gc, "Error sending nickname"); | |
| 213 return; | |
| 214 } | |
| 215 g_free(buf); | |
| 216 | |
| 217 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
|
218 } |
|
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
219 |
| 6333 | 220 static void irc_close(GaimConnection *gc) |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
221 { |
| 6333 | 222 struct irc_conn *irc = gc->proto_data; |
| 223 | |
| 224 irc_cmd_quit(irc, "quit", NULL, NULL); | |
| 225 | |
| 226 if (gc->inpa) | |
| 227 g_source_remove(gc->inpa); | |
| 228 | |
| 229 g_free(irc->inbuf); | |
| 230 close(irc->fd); | |
| 231 if (irc->timer) | |
| 232 g_source_remove(irc->timer); | |
| 233 g_hash_table_destroy(irc->cmds); | |
| 234 g_hash_table_destroy(irc->msgs); | |
| 235 if (irc->motd) | |
| 236 g_string_free(irc->motd, TRUE); | |
| 237 g_free(irc->server); | |
| 238 g_free(irc); | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
239 } |
|
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
240 |
| 6333 | 241 static int irc_im_send(GaimConnection *gc, const char *who, const char *what, int len, int flags) |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
242 { |
| 6333 | 243 struct irc_conn *irc = gc->proto_data; |
| 244 const char *args[2]; | |
| 245 | |
| 246 if (*who == '@' || *who == '%' || *who == '+') | |
| 247 args[0] = who + 1; | |
| 248 else | |
| 249 args[0] = who; | |
| 250 args[1] = what; | |
| 251 | |
| 252 if (*what == '/') { | |
| 253 return irc_parse_cmd(irc, who, what + 1); | |
| 254 } | |
| 255 | |
| 256 irc_cmd_privmsg(irc, "msg", NULL, args); | |
| 257 return 1; | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
258 } |
| 2086 | 259 |
| 6333 | 260 static void irc_get_info(GaimConnection *gc, const char *who) |
| 2086 | 261 { |
| 6333 | 262 struct irc_conn *irc = gc->proto_data; |
| 263 const char *args[1]; | |
| 264 args[0] = who; | |
| 265 irc_cmd_whois(irc, "whois", NULL, args); | |
| 266 } | |
| 267 | |
| 268 static void irc_set_away(GaimConnection *gc, const char *state, const char *msg) | |
| 269 { | |
| 270 struct irc_conn *irc = gc->proto_data; | |
| 271 const char *args[1]; | |
| 2086 | 272 |
|
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4067
diff
changeset
|
273 if (gc->away) { |
|
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4067
diff
changeset
|
274 g_free(gc->away); |
|
2394
579f8d4347ad
[gaim-migrate @ 2407]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
275 gc->away = NULL; |
|
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4067
diff
changeset
|
276 } |
|
2393
a7ecfd3f7714
[gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
277 |
| 6333 | 278 if (msg) |
|
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4067
diff
changeset
|
279 gc->away = g_strdup(msg); |
| 2086 | 280 |
| 6333 | 281 args[0] = msg; |
| 282 irc_cmd_away(irc, "away", NULL, args); | |
| 4916 | 283 } |
| 284 | |
| 6333 | 285 static void irc_add_buddy(GaimConnection *gc, const char *who) |
| 3029 | 286 { |
| 6333 | 287 struct irc_conn *irc = (struct irc_conn *)gc->proto_data; |
| 288 struct irc_buddy *ib = g_new0(struct irc_buddy, 1); | |
| 289 ib->name = g_strdup(who); | |
| 290 g_hash_table_insert(irc->buddies, ib->name, ib); | |
| 3029 | 291 } |
| 3622 | 292 |
| 6333 | 293 static void irc_remove_buddy(GaimConnection *gc, const char *who, const char *group) |
| 294 { | |
| 295 struct irc_conn *irc = (struct irc_conn *)gc->proto_data; | |
| 296 g_hash_table_remove(irc->buddies, who); | |
| 3616 | 297 } |
|
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4509
diff
changeset
|
298 |
| 3616 | 299 |
| 6333 | 300 static void irc_input_cb(gpointer data, gint source, GaimInputCondition cond) |
| 301 { | |
| 302 GaimConnection *gc = data; | |
| 303 struct irc_conn *irc = gc->proto_data; | |
| 304 char *cur, *end; | |
| 305 int len; | |
| 306 | |
| 307 if (irc->inbuflen < irc->inbufused + IRC_INITIAL_BUFSIZE) { | |
| 308 irc->inbuflen += IRC_INITIAL_BUFSIZE; | |
| 309 irc->inbuf = g_realloc(irc->inbuf, irc->inbuflen); | |
| 3708 | 310 } |
| 3616 | 311 |
| 6333 | 312 if ((len = read(irc->fd, irc->inbuf + irc->inbufused, IRC_INITIAL_BUFSIZE - 1)) < 0) { |
| 313 gaim_connection_error(gc, "Read error"); | |
| 314 return; | |
| 315 } | |
| 316 irc->inbufused += len; | |
| 317 irc->inbuf[irc->inbufused] = '\0'; | |
| 3616 | 318 |
| 6333 | 319 for (cur = irc->inbuf; cur < irc->inbuf + irc->inbufused && (end = strstr(cur, "\r\n")); cur = end + 2) { |
| 320 *end = '\0'; | |
| 321 irc_parse_msg(irc, cur); | |
| 322 } | |
| 323 if (cur != irc->inbuf + irc->inbufused) { /* leftover */ | |
| 324 irc->inbufused -= (cur - irc->inbuf); | |
| 325 memmove(irc->inbuf, cur, irc->inbufused); | |
| 326 } else { | |
| 327 irc->inbufused = 0; | |
| 328 } | |
| 3616 | 329 } |
| 330 | |
| 6333 | 331 static void irc_chat_join (GaimConnection *gc, GHashTable *data) |
| 332 { | |
| 333 struct irc_conn *irc = gc->proto_data; | |
| 334 const char *args[2]; | |
| 3616 | 335 |
| 6333 | 336 args[0] = g_hash_table_lookup(data, "channel"); |
| 337 args[1] = g_hash_table_lookup(data, "password"); | |
| 338 irc_cmd_join(irc, "join", NULL, args); | |
| 3622 | 339 } |
| 340 | |
| 6333 | 341 static void irc_chat_invite(GaimConnection *gc, int id, const char *message, const char *name) |
| 3751 | 342 { |
| 6333 | 343 struct irc_conn *irc = gc->proto_data; |
| 344 GaimConversation *convo = gaim_find_chat(gc, id); | |
| 345 const char *args[2]; | |
| 3751 | 346 |
| 6333 | 347 if (!convo) { |
| 348 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Got chat invite request for bogus chat\n"); | |
| 349 return; | |
| 350 } | |
| 351 args[0] = name; | |
| 352 args[1] = gaim_conversation_get_name(convo); | |
| 353 irc_cmd_invite(irc, "invite", gaim_conversation_get_name(convo), args); | |
| 3707 | 354 } |
| 355 | |
| 6333 | 356 |
| 357 static void irc_chat_leave (GaimConnection *gc, int id) | |
| 3707 | 358 { |
| 6333 | 359 struct irc_conn *irc = gc->proto_data; |
| 360 GaimConversation *convo = gaim_find_chat(gc, id); | |
| 361 const char *args[2]; | |
| 5298 | 362 |
| 6333 | 363 if (!convo) |
| 364 return; | |
| 3735 | 365 |
| 6333 | 366 args[0] = gaim_conversation_get_name(convo); |
| 367 args[1] = NULL; | |
| 368 irc_cmd_part(irc, "part", gaim_conversation_get_name(convo), args); | |
| 369 serv_got_chat_left(gc, id); | |
| 3735 | 370 } |
| 371 | |
| 6333 | 372 static int irc_chat_send(GaimConnection *gc, int id, const char *what) |
| 3735 | 373 { |
| 6333 | 374 struct irc_conn *irc = gc->proto_data; |
| 375 GaimConversation *convo = gaim_find_chat(gc, id); | |
| 376 const char *args[2]; | |
| 377 | |
| 378 if (!convo) { | |
| 379 gaim_debug(GAIM_DEBUG_ERROR, "irc", "chat send on nonexistent chat\n"); | |
| 380 return -EINVAL; | |
| 381 } | |
| 382 | |
| 383 if (*what == '/') { | |
| 384 return irc_parse_cmd(irc, convo->name, what + 1); | |
| 385 } | |
| 386 | |
| 387 args[0] = convo->name; | |
| 388 args[1] = what; | |
| 389 | |
| 390 irc_cmd_privmsg(irc, "msg", NULL, args); | |
| 391 serv_got_chat_in(gc, id, gaim_connection_get_display_name(gc), 0, what, time(NULL)); | |
| 392 return 0; | |
| 3707 | 393 } |
| 394 | |
| 6333 | 395 static guint irc_nick_hash(const char *nick) |
| 396 { | |
| 397 char *lc; | |
| 398 guint bucket; | |
|
6270
1bf6fd117797
[gaim-migrate @ 6767]
Christian Hammond <chipx86@chipx86.com>
parents:
6240
diff
changeset
|
399 |
| 6333 | 400 lc = g_utf8_strdown(nick, -1); |
| 401 bucket = g_str_hash(lc); | |
| 402 g_free(lc); | |
|
6270
1bf6fd117797
[gaim-migrate @ 6767]
Christian Hammond <chipx86@chipx86.com>
parents:
6240
diff
changeset
|
403 |
| 6333 | 404 return bucket; |
| 3029 | 405 } |
| 406 | |
| 6333 | 407 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
|
408 { |
| 6333 | 409 return (gaim_utf8_strcasecmp(nick1, nick2) == 0); |
|
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
410 } |
|
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
411 |
| 6333 | 412 static void irc_buddy_free(struct irc_buddy *ib) |
|
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
413 { |
| 6333 | 414 g_free(ib->name); |
| 415 g_free(ib); | |
|
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
416 } |
|
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
417 |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
418 static GaimPluginProtocolInfo prpl_info = |
| 2086 | 419 { |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
420 GAIM_PROTO_IRC, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
421 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_PASSWORD_OPTIONAL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
422 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
423 NULL, |
| 6333 | 424 irc_blist_icon, |
| 425 irc_blist_emblems, | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
426 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
427 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
428 irc_away_states, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
429 NULL, |
| 6350 | 430 irc_buddy_menu, |
| 6333 | 431 irc_chat_join_info, |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
432 irc_login, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
433 irc_close, |
| 6333 | 434 irc_im_send, |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
435 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
436 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
437 irc_get_info, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
438 irc_set_away, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
439 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
440 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
441 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
442 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
443 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
444 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
445 irc_add_buddy, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
446 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
447 irc_remove_buddy, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
448 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
449 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
450 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
451 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
452 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
453 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
454 NULL, |
| 6333 | 455 irc_chat_join, |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
456 irc_chat_invite, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
457 irc_chat_leave, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
458 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
459 irc_chat_send, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
460 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
461 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
462 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
463 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
464 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
465 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
466 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
467 NULL, |
| 6333 | 468 NULL, /*irc_convo_closed,*/ |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
469 NULL |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
470 }; |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
471 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
472 static GaimPluginInfo info = |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
473 { |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
474 2, /**< api_version */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
475 GAIM_PLUGIN_PROTOCOL, /**< type */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
476 NULL, /**< ui_requirement */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
477 0, /**< flags */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
478 NULL, /**< dependencies */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
479 GAIM_PRIORITY_DEFAULT, /**< priority */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
480 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
481 "prpl-irc", /**< id */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
482 "IRC", /**< name */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
483 VERSION, /**< version */ |
| 6333 | 484 N_("IRC Protocol Plugin"), /** summary */ |
| 485 N_("The IRC Protocol Plugin that Sucks Less"), /** description */ | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
486 NULL, /**< author */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
487 WEBSITE, /**< homepage */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
488 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
489 NULL, /**< load */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
490 NULL, /**< unload */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
491 NULL, /**< destroy */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
492 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
493 NULL, /**< ui_info */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
494 &prpl_info /**< extra_info */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
495 }; |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
496 |
| 6333 | 497 static void _init_plugin(GaimPlugin *plugin) |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
498 { |
|
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
499 GaimAccountUserSplit *split; |
|
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
500 GaimAccountOption *option; |
|
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
501 |
| 6333 | 502 split = gaim_account_user_split_new(_("Server"), IRC_DEFAULT_SERVER, '@'); |
|
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
503 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
|
504 |
| 6333 | 505 option = gaim_account_option_int_new(_("Port:"), "port", IRC_DEFAULT_PORT); |
| 506 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
|
507 |
| 6333 | 508 option = gaim_account_option_string_new(_("Encoding"), "encoding", IRC_DEFAULT_CHARSET); |
| 509 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
|
510 |
| 6333 | 511 _irc_plugin = plugin; |
| 2086 | 512 } |
| 513 | |
| 6333 | 514 GAIM_INIT_PLUGIN(irc, _init_plugin, info); |
