Mercurial > pidgin
annotate src/protocols/irc/irc.c @ 7166:e6b01bd8d6cd
[gaim-migrate @ 7733]
I fixed the notify_added function, Chip had two of the variables swapped :-)
I changed the way tlvlists are done in ssi.c a little bit. You can alias
ICQ buddies that you don't have authorization for yet, and when you alias
a buddy you will no longer lose any Buddy Alerts that may be set.
Why is this? Previously tlvlists (data associated with each server stored
item) were just deleted and recreated when you set an alias, or changed your
permit/deny setting. Now the lists are modified and TLVs that libfaim
doesn't know about are just left in place.
Why did I wait so long to do this? I'm lazy, it's not really all that fun,
and I don't consider it all that important.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Sun, 05 Oct 2003 22:41:29 +0000 |
| parents | bb484e976aa8 |
| children | 443fc7d6fbff |
| 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 * |
| 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> |
|
6459
b52870734c21
[gaim-migrate @ 6968]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
9 * |
| 2086 | 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" |
| 7148 | 32 #include "notify.h" |
| 6333 | 33 #include "debug.h" |
| 34 #include "blist.h" | |
| 6350 | 35 #include "util.h" |
| 6333 | 36 #include "irc.h" |
| 4422 | 37 |
| 6333 | 38 static void irc_buddy_append(char *name, struct irc_buddy *ib, GString *string); |
| 2086 | 39 |
| 6695 | 40 static const char *irc_blist_icon(GaimAccount *a, GaimBuddy *b); |
| 41 static void irc_blist_emblems(GaimBuddy *b, char **se, char **sw, char **nw, char **ne); | |
| 6333 | 42 static GList *irc_away_states(GaimConnection *gc); |
| 7148 | 43 static GList *irc_actions(GaimConnection *gc); |
| 6333 | 44 /* static GList *irc_chat_info(GaimConnection *gc); */ |
| 45 static void irc_login(GaimAccount *account); | |
| 46 static void irc_login_cb(gpointer data, gint source, GaimInputCondition cond); | |
| 47 static void irc_close(GaimConnection *gc); | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
48 static int irc_im_send(GaimConnection *gc, const char *who, const char *what, GaimConvImFlags flags); |
| 6333 | 49 static int irc_chat_send(GaimConnection *gc, int id, const char *what); |
| 50 static void irc_chat_join (GaimConnection *gc, GHashTable *data); | |
| 51 static void irc_input_cb(gpointer data, gint source, GaimInputCondition cond); | |
| 3751 | 52 |
| 7148 | 53 static void irc_view_motd(GaimConnection *gc) |
| 54 { | |
| 55 struct irc_conn *irc; | |
| 56 char *title; | |
| 57 | |
| 58 if (gc == NULL || gc->proto_data == NULL) { | |
| 59 gaim_debug(GAIM_DEBUG_ERROR, "irc", "got MOTD request for NULL gc\n"); | |
| 60 return; | |
| 61 } | |
| 62 irc = gc->proto_data; | |
| 63 if (irc->motd == NULL) { | |
| 64 gaim_notify_error(gc, _("Error displaying MOTD"), _("No MOTD available"), | |
| 65 _("There is no MOTD associated with this connection.")); | |
| 66 return; | |
| 67 } | |
| 68 title = g_strdup_printf(_("MOTD for %s"), irc->server); | |
| 69 gaim_notify_formatted(gc, title, title, NULL, irc->motd->str, NULL, NULL); | |
| 70 } | |
| 71 | |
| 6333 | 72 static guint irc_nick_hash(const char *nick); |
| 73 static gboolean irc_nick_equal(const char *nick1, const char *nick2); | |
| 74 static void irc_buddy_free(struct irc_buddy *ib); | |
| 3751 | 75 |
| 6333 | 76 static GaimPlugin *_irc_plugin = NULL; |
| 3029 | 77 |
| 6333 | 78 int irc_send(struct irc_conn *irc, const char *buf) |
| 3751 | 79 { |
| 6333 | 80 if (irc->fd < 0) |
| 81 return -1; | |
|
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2171
diff
changeset
|
82 |
| 6333 | 83 /* gaim_debug(GAIM_DEBUG_MISC, "irc", "sent: %s", buf); */ |
| 84 return write(irc->fd, buf, strlen(buf)); | |
|
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2171
diff
changeset
|
85 } |
|
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2171
diff
changeset
|
86 |
| 6333 | 87 /* XXX I don't like messing directly with these buddies */ |
| 88 gboolean irc_blist_timeout(struct irc_conn *irc) | |
| 2086 | 89 { |
| 6333 | 90 GString *string = g_string_sized_new(512); |
| 91 char *list, *buf; | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
92 |
| 6333 | 93 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
|
94 |
| 6333 | 95 list = g_string_free(string, FALSE); |
| 96 if (!list || !strlen(list)) { | |
| 97 g_free(list); | |
|
2137
18722ae5b882
[gaim-migrate @ 2147]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2131
diff
changeset
|
98 return TRUE; |
| 2086 | 99 } |
|
4416
8e62cee6d738
[gaim-migrate @ 4689]
Christian Hammond <chipx86@chipx86.com>
parents:
4373
diff
changeset
|
100 |
| 6333 | 101 buf = irc_format(irc, "v:", "ISON", list); |
| 102 g_free(list); | |
| 103 irc_send(irc, buf); | |
| 104 g_free(buf); | |
|
4416
8e62cee6d738
[gaim-migrate @ 4689]
Christian Hammond <chipx86@chipx86.com>
parents:
4373
diff
changeset
|
105 |
|
2131
acc11216ec5d
[gaim-migrate @ 2141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
106 return TRUE; |
| 2086 | 107 } |
| 108 | |
| 6333 | 109 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
|
110 { |
| 6333 | 111 ib->flag = FALSE; |
| 112 g_string_append_printf(string, "%s ", name); | |
| 3511 | 113 } |
| 114 | |
| 6695 | 115 static const char *irc_blist_icon(GaimAccount *a, GaimBuddy *b) |
| 3029 | 116 { |
| 6333 | 117 return "irc"; |
|
2339
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
118 } |
|
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
119 |
| 6695 | 120 static void irc_blist_emblems(GaimBuddy *b, char **se, char **sw, char **nw, char **ne) |
| 3751 | 121 { |
| 6333 | 122 if (b->present == GAIM_BUDDY_OFFLINE) |
| 123 *se = "offline"; | |
| 2086 | 124 } |
| 125 | |
| 6333 | 126 static GList *irc_away_states(GaimConnection *gc) |
| 2086 | 127 { |
| 6333 | 128 return g_list_append(NULL, (gpointer)GAIM_AWAY_CUSTOM); |
| 3452 | 129 } |
| 130 | |
| 7148 | 131 static GList *irc_actions(GaimConnection *gc) |
| 132 { | |
| 133 struct proto_actions_menu *pam; | |
| 134 GList *list = NULL; | |
| 135 | |
| 136 pam = g_new0(struct proto_actions_menu, 1); | |
| 137 pam->label = _("View MOTD"); | |
| 138 pam->callback = irc_view_motd; | |
| 139 pam->gc = gc; | |
| 140 list = g_list_append(list, pam); | |
| 141 | |
| 142 return list; | |
| 143 } | |
| 144 | |
| 6333 | 145 static GList *irc_buddy_menu(GaimConnection *gc, const char *who) |
| 2086 | 146 { |
| 6333 | 147 return NULL; |
| 2086 | 148 } |
| 149 | |
| 6333 | 150 static GList *irc_chat_join_info(GaimConnection *gc) |
| 2086 | 151 { |
|
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
152 GList *m = NULL; |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
153 struct proto_chat_entry *pce; |
|
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
154 |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
155 pce = g_new0(struct proto_chat_entry, 1); |
|
2466
f8eb5f120603
[gaim-migrate @ 2479]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2459
diff
changeset
|
156 pce->label = _("Channel:"); |
| 5234 | 157 pce->identifier = "channel"; |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
158 m = g_list_append(m, pce); |
|
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
159 |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
160 pce = g_new0(struct proto_chat_entry, 1); |
|
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
161 pce->label = _("Password:"); |
| 5234 | 162 pce->identifier = "password"; |
| 6499 | 163 pce->secret = TRUE; |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
164 m = g_list_append(m, pce); |
|
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
165 |
|
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
166 return m; |
| 2086 | 167 } |
| 168 | |
| 6333 | 169 static void irc_login(GaimAccount *account) |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
170 { |
| 6333 | 171 GaimConnection *gc; |
| 172 struct irc_conn *irc; | |
| 173 char *buf, **userparts; | |
| 174 const char *username = gaim_account_get_username(account); | |
| 175 int err; | |
| 176 | |
| 177 gc = gaim_account_get_connection(account); | |
| 178 | |
| 6752 | 179 if (strpbrk(username, " \t\v\r\n") != NULL) { |
| 180 gaim_connection_error(gc, _("IRC nicks may not contain whitespace")); | |
| 181 return; | |
| 182 } | |
| 183 | |
| 6333 | 184 gc->proto_data = irc = g_new0(struct irc_conn, 1); |
| 185 irc->account = account; | |
| 186 | |
| 187 userparts = g_strsplit(username, "@", 2); | |
| 188 gaim_connection_set_display_name(gc, userparts[0]); | |
| 189 irc->server = g_strdup(userparts[1]); | |
| 190 g_strfreev(userparts); | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
191 |
| 6333 | 192 irc->buddies = g_hash_table_new_full((GHashFunc)irc_nick_hash, (GEqualFunc)irc_nick_equal, |
| 193 NULL, (GDestroyNotify)irc_buddy_free); | |
| 194 irc->cmds = g_hash_table_new(g_str_hash, g_str_equal); | |
| 195 irc_cmd_table_build(irc); | |
| 196 irc->msgs = g_hash_table_new(g_str_hash, g_str_equal); | |
| 197 irc_msg_table_build(irc); | |
| 198 | |
| 199 buf = g_strdup_printf(_("Signon: %s"), username); | |
| 200 gaim_connection_update_progress(gc, buf, 1, 2); | |
| 201 g_free(buf); | |
| 202 | |
| 203 err = gaim_proxy_connect(account, irc->server, | |
| 204 gaim_account_get_int(account, "port", IRC_DEFAULT_PORT), | |
| 205 irc_login_cb, gc); | |
| 206 | |
| 207 if (err || !account->gc) { | |
| 208 gaim_connection_error(gc, _("Couldn't create socket")); | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
209 return; |
| 6333 | 210 } |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
211 } |
|
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
212 |
| 6333 | 213 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
|
214 { |
| 6333 | 215 GaimConnection *gc = data; |
| 216 struct irc_conn *irc = gc->proto_data; | |
| 217 char hostname[256]; | |
| 218 char *buf; | |
| 219 GList *connections = gaim_connections_get_all(); | |
| 220 | |
| 221 if (source < 0) | |
| 222 return; | |
| 223 | |
| 224 if (!g_list_find(connections, gc)) { | |
| 225 close(source); | |
| 226 return; | |
| 227 } | |
| 228 | |
| 229 irc->fd = source; | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
230 |
| 6333 | 231 if (gc->account->password && *gc->account->password) { |
| 232 buf = irc_format(irc, "vv", "PASS", gc->account->password); | |
| 233 if (irc_send(irc, buf) < 0) { | |
| 234 gaim_connection_error(gc, "Error sending password"); | |
| 235 return; | |
| 236 } | |
| 237 g_free(buf); | |
| 238 } | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
239 |
| 6333 | 240 gethostname(hostname, sizeof(hostname)); |
| 241 hostname[sizeof(hostname) - 1] = '\0'; | |
| 242 buf = irc_format(irc, "vvvv:", "USER", g_get_user_name(), hostname, irc->server, | |
| 243 gc->account->alias && *gc->account->alias ? gc->account->alias : IRC_DEFAULT_ALIAS); | |
| 244 if (irc_send(irc, buf) < 0) { | |
| 245 gaim_connection_error(gc, "Error registering with server"); | |
| 246 return; | |
| 247 } | |
| 248 g_free(buf); | |
| 249 buf = irc_format(irc, "vn", "NICK", gaim_connection_get_display_name(gc)); | |
| 250 if (irc_send(irc, buf) < 0) { | |
| 251 gaim_connection_error(gc, "Error sending nickname"); | |
| 252 return; | |
| 253 } | |
| 254 g_free(buf); | |
| 255 | |
| 256 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
|
257 } |
|
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
258 |
| 6333 | 259 static void irc_close(GaimConnection *gc) |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
260 { |
| 6333 | 261 struct irc_conn *irc = gc->proto_data; |
| 262 | |
| 6752 | 263 if (irc == NULL) |
| 264 return; | |
| 265 | |
| 6333 | 266 irc_cmd_quit(irc, "quit", NULL, NULL); |
| 267 | |
| 268 if (gc->inpa) | |
| 269 g_source_remove(gc->inpa); | |
| 270 | |
| 271 g_free(irc->inbuf); | |
| 272 close(irc->fd); | |
| 273 if (irc->timer) | |
| 274 g_source_remove(irc->timer); | |
| 275 g_hash_table_destroy(irc->cmds); | |
| 276 g_hash_table_destroy(irc->msgs); | |
| 277 if (irc->motd) | |
| 278 g_string_free(irc->motd, TRUE); | |
| 279 g_free(irc->server); | |
| 280 g_free(irc); | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
281 } |
|
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
282 |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
283 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
|
284 { |
| 6333 | 285 struct irc_conn *irc = gc->proto_data; |
| 286 const char *args[2]; | |
| 287 | |
| 288 if (*who == '@' || *who == '%' || *who == '+') | |
| 289 args[0] = who + 1; | |
| 290 else | |
| 291 args[0] = who; | |
| 292 args[1] = what; | |
| 293 | |
| 294 if (*what == '/') { | |
| 295 return irc_parse_cmd(irc, who, what + 1); | |
| 296 } | |
| 297 | |
| 298 irc_cmd_privmsg(irc, "msg", NULL, args); | |
| 299 return 1; | |
|
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
300 } |
| 2086 | 301 |
| 6333 | 302 static void irc_get_info(GaimConnection *gc, const char *who) |
| 2086 | 303 { |
| 6333 | 304 struct irc_conn *irc = gc->proto_data; |
| 305 const char *args[1]; | |
| 306 args[0] = who; | |
| 307 irc_cmd_whois(irc, "whois", NULL, args); | |
| 308 } | |
| 309 | |
| 310 static void irc_set_away(GaimConnection *gc, const char *state, const char *msg) | |
| 311 { | |
| 312 struct irc_conn *irc = gc->proto_data; | |
| 313 const char *args[1]; | |
| 2086 | 314 |
|
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4067
diff
changeset
|
315 if (gc->away) { |
|
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4067
diff
changeset
|
316 g_free(gc->away); |
|
2394
579f8d4347ad
[gaim-migrate @ 2407]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
317 gc->away = NULL; |
|
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4067
diff
changeset
|
318 } |
|
2393
a7ecfd3f7714
[gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
319 |
| 6333 | 320 if (msg) |
|
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4067
diff
changeset
|
321 gc->away = g_strdup(msg); |
| 2086 | 322 |
| 6333 | 323 args[0] = msg; |
| 324 irc_cmd_away(irc, "away", NULL, args); | |
| 4916 | 325 } |
| 326 | |
|
6787
faa491042c66
[gaim-migrate @ 7326]
Christian Hammond <chipx86@chipx86.com>
parents:
6752
diff
changeset
|
327 static void irc_add_buddy(GaimConnection *gc, const char *who, GaimGroup *group) |
| 3029 | 328 { |
| 6333 | 329 struct irc_conn *irc = (struct irc_conn *)gc->proto_data; |
| 330 struct irc_buddy *ib = g_new0(struct irc_buddy, 1); | |
| 331 ib->name = g_strdup(who); | |
| 332 g_hash_table_insert(irc->buddies, ib->name, ib); | |
| 3029 | 333 } |
| 3622 | 334 |
| 6333 | 335 static void irc_remove_buddy(GaimConnection *gc, const char *who, const char *group) |
| 336 { | |
| 337 struct irc_conn *irc = (struct irc_conn *)gc->proto_data; | |
| 338 g_hash_table_remove(irc->buddies, who); | |
| 3616 | 339 } |
|
4514
7521e29658bc
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
4509
diff
changeset
|
340 |
| 3616 | 341 |
| 6333 | 342 static void irc_input_cb(gpointer data, gint source, GaimInputCondition cond) |
| 343 { | |
| 344 GaimConnection *gc = data; | |
| 345 struct irc_conn *irc = gc->proto_data; | |
| 346 char *cur, *end; | |
| 347 int len; | |
| 348 | |
| 349 if (irc->inbuflen < irc->inbufused + IRC_INITIAL_BUFSIZE) { | |
| 350 irc->inbuflen += IRC_INITIAL_BUFSIZE; | |
| 351 irc->inbuf = g_realloc(irc->inbuf, irc->inbuflen); | |
| 3708 | 352 } |
| 3616 | 353 |
| 6333 | 354 if ((len = read(irc->fd, irc->inbuf + irc->inbufused, IRC_INITIAL_BUFSIZE - 1)) < 0) { |
| 355 gaim_connection_error(gc, "Read error"); | |
| 356 return; | |
| 6369 | 357 } else if (len == 0) { |
| 358 /* Remote closed the connection, probably */ | |
| 359 return; | |
| 6333 | 360 } |
| 6369 | 361 |
| 6333 | 362 irc->inbufused += len; |
| 363 irc->inbuf[irc->inbufused] = '\0'; | |
| 3616 | 364 |
| 6333 | 365 for (cur = irc->inbuf; cur < irc->inbuf + irc->inbufused && (end = strstr(cur, "\r\n")); cur = end + 2) { |
| 366 *end = '\0'; | |
| 367 irc_parse_msg(irc, cur); | |
| 368 } | |
| 369 if (cur != irc->inbuf + irc->inbufused) { /* leftover */ | |
| 370 irc->inbufused -= (cur - irc->inbuf); | |
| 371 memmove(irc->inbuf, cur, irc->inbufused); | |
| 372 } else { | |
| 373 irc->inbufused = 0; | |
| 374 } | |
| 3616 | 375 } |
| 376 | |
| 6333 | 377 static void irc_chat_join (GaimConnection *gc, GHashTable *data) |
| 378 { | |
| 379 struct irc_conn *irc = gc->proto_data; | |
| 380 const char *args[2]; | |
| 3616 | 381 |
| 6333 | 382 args[0] = g_hash_table_lookup(data, "channel"); |
| 383 args[1] = g_hash_table_lookup(data, "password"); | |
| 384 irc_cmd_join(irc, "join", NULL, args); | |
| 3622 | 385 } |
| 386 | |
| 6333 | 387 static void irc_chat_invite(GaimConnection *gc, int id, const char *message, const char *name) |
| 3751 | 388 { |
| 6333 | 389 struct irc_conn *irc = gc->proto_data; |
| 390 GaimConversation *convo = gaim_find_chat(gc, id); | |
| 391 const char *args[2]; | |
| 3751 | 392 |
| 6333 | 393 if (!convo) { |
| 394 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Got chat invite request for bogus chat\n"); | |
| 395 return; | |
| 396 } | |
| 397 args[0] = name; | |
| 398 args[1] = gaim_conversation_get_name(convo); | |
| 399 irc_cmd_invite(irc, "invite", gaim_conversation_get_name(convo), args); | |
| 3707 | 400 } |
| 401 | |
| 6333 | 402 |
| 403 static void irc_chat_leave (GaimConnection *gc, int id) | |
| 3707 | 404 { |
| 6333 | 405 struct irc_conn *irc = gc->proto_data; |
| 406 GaimConversation *convo = gaim_find_chat(gc, id); | |
| 407 const char *args[2]; | |
| 5298 | 408 |
| 6333 | 409 if (!convo) |
| 410 return; | |
| 3735 | 411 |
| 6333 | 412 args[0] = gaim_conversation_get_name(convo); |
| 413 args[1] = NULL; | |
| 414 irc_cmd_part(irc, "part", gaim_conversation_get_name(convo), args); | |
| 415 serv_got_chat_left(gc, id); | |
| 3735 | 416 } |
| 417 | |
| 6333 | 418 static int irc_chat_send(GaimConnection *gc, int id, const char *what) |
| 3735 | 419 { |
| 6333 | 420 struct irc_conn *irc = gc->proto_data; |
| 421 GaimConversation *convo = gaim_find_chat(gc, id); | |
| 422 const char *args[2]; | |
| 423 | |
| 424 if (!convo) { | |
| 425 gaim_debug(GAIM_DEBUG_ERROR, "irc", "chat send on nonexistent chat\n"); | |
| 426 return -EINVAL; | |
| 427 } | |
| 428 | |
| 429 if (*what == '/') { | |
| 430 return irc_parse_cmd(irc, convo->name, what + 1); | |
| 431 } | |
| 432 | |
| 433 args[0] = convo->name; | |
| 434 args[1] = what; | |
| 435 | |
| 436 irc_cmd_privmsg(irc, "msg", NULL, args); | |
| 437 serv_got_chat_in(gc, id, gaim_connection_get_display_name(gc), 0, what, time(NULL)); | |
| 438 return 0; | |
| 3707 | 439 } |
| 440 | |
| 6333 | 441 static guint irc_nick_hash(const char *nick) |
| 442 { | |
| 443 char *lc; | |
| 444 guint bucket; | |
|
6270
1bf6fd117797
[gaim-migrate @ 6767]
Christian Hammond <chipx86@chipx86.com>
parents:
6240
diff
changeset
|
445 |
| 6333 | 446 lc = g_utf8_strdown(nick, -1); |
| 447 bucket = g_str_hash(lc); | |
| 448 g_free(lc); | |
|
6270
1bf6fd117797
[gaim-migrate @ 6767]
Christian Hammond <chipx86@chipx86.com>
parents:
6240
diff
changeset
|
449 |
| 6333 | 450 return bucket; |
| 3029 | 451 } |
| 452 | |
| 6333 | 453 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
|
454 { |
| 6333 | 455 return (gaim_utf8_strcasecmp(nick1, nick2) == 0); |
|
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
456 } |
|
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
457 |
| 6333 | 458 static void irc_buddy_free(struct irc_buddy *ib) |
|
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
459 { |
| 6333 | 460 g_free(ib->name); |
| 461 g_free(ib); | |
|
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
462 } |
|
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
463 |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
464 static GaimPluginProtocolInfo prpl_info = |
| 2086 | 465 { |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
466 GAIM_PROTO_IRC, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
467 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_PASSWORD_OPTIONAL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
468 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
469 NULL, |
| 6333 | 470 irc_blist_icon, |
| 471 irc_blist_emblems, | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
472 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
473 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
474 irc_away_states, |
| 7148 | 475 irc_actions, |
| 6350 | 476 irc_buddy_menu, |
| 6333 | 477 irc_chat_join_info, |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
478 irc_login, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
479 irc_close, |
| 6333 | 480 irc_im_send, |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
481 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
482 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
483 irc_get_info, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
484 irc_set_away, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
485 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
486 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
487 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
488 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
489 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
490 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
491 irc_add_buddy, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
492 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
493 irc_remove_buddy, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
494 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
495 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
496 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
497 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
498 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
499 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
500 NULL, |
| 6333 | 501 irc_chat_join, |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
502 irc_chat_invite, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
503 irc_chat_leave, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
504 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
505 irc_chat_send, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
506 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
507 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
508 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
509 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
510 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
511 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
512 NULL, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
513 NULL, |
| 6333 | 514 NULL, /*irc_convo_closed,*/ |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
515 NULL |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
516 }; |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
517 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
518 static GaimPluginInfo info = |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
519 { |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
520 2, /**< api_version */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
521 GAIM_PLUGIN_PROTOCOL, /**< type */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
522 NULL, /**< ui_requirement */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
523 0, /**< flags */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
524 NULL, /**< dependencies */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
525 GAIM_PRIORITY_DEFAULT, /**< priority */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
526 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
527 "prpl-irc", /**< id */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
528 "IRC", /**< name */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
529 VERSION, /**< version */ |
| 6333 | 530 N_("IRC Protocol Plugin"), /** summary */ |
| 531 N_("The IRC Protocol Plugin that Sucks Less"), /** description */ | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
532 NULL, /**< author */ |
|
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6369
diff
changeset
|
533 GAIM_WEBSITE, /**< homepage */ |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
534 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
535 NULL, /**< load */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
536 NULL, /**< unload */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
537 NULL, /**< destroy */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
538 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
539 NULL, /**< ui_info */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
540 &prpl_info /**< extra_info */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
541 }; |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
542 |
| 6333 | 543 static void _init_plugin(GaimPlugin *plugin) |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5150
diff
changeset
|
544 { |
|
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
545 GaimAccountUserSplit *split; |
|
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
546 GaimAccountOption *option; |
|
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
547 |
| 6333 | 548 split = gaim_account_user_split_new(_("Server"), IRC_DEFAULT_SERVER, '@'); |
|
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
549 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
|
550 |
|
6459
b52870734c21
[gaim-migrate @ 6968]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
551 option = gaim_account_option_int_new(_("Port"), "port", IRC_DEFAULT_PORT); |
| 6333 | 552 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
|
553 |
| 6333 | 554 option = gaim_account_option_string_new(_("Encoding"), "encoding", IRC_DEFAULT_CHARSET); |
| 555 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
|
556 |
| 6333 | 557 _irc_plugin = plugin; |
| 2086 | 558 } |
| 559 | |
| 6333 | 560 GAIM_INIT_PLUGIN(irc, _init_plugin, info); |
