Mercurial > pidgin
annotate src/protocols/jabber/chat.c @ 7326:00a9ab26d607
[gaim-migrate @ 7912]
Added an option to remove the formatting toolbar, both globally and on a
per-window basis. Patch by Nathan Fredrickson.
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Sat, 25 Oct 2003 00:03:13 +0000 |
| parents | ab828b8c3f22 |
| children | d60e1629ffde |
| rev | line source |
|---|---|
| 7014 | 1 /* |
| 2 * gaim - Jabber Protocol Plugin | |
| 3 * | |
| 4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> | |
| 5 * | |
| 6 * This program is free software; you can redistribute it and/or modify | |
| 7 * it under the terms of the GNU General Public License as published by | |
| 8 * the Free Software Foundation; either version 2 of the License, or | |
| 9 * (at your option) any later version. | |
| 10 * | |
| 11 * This program is distributed in the hope that it will be useful, | |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 * GNU General Public License for more details. | |
| 15 * | |
| 16 * You should have received a copy of the GNU General Public License | |
| 17 * along with this program; if not, write to the Free Software | |
| 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 * | |
| 20 */ | |
| 21 #include "internal.h" | |
| 22 #include "debug.h" | |
| 23 #include "multi.h" /* for proto_chat_entry */ | |
| 7310 | 24 #include "notify.h" |
| 7014 | 25 |
| 26 #include "chat.h" | |
| 27 #include "message.h" | |
| 7073 | 28 #include "presence.h" |
| 7014 | 29 |
| 30 GList *jabber_chat_info(GaimConnection *gc) | |
| 31 { | |
| 32 GList *m = NULL; | |
| 33 struct proto_chat_entry *pce; | |
| 34 JabberStream *js = gc->proto_data; | |
| 35 | |
| 36 pce = g_new0(struct proto_chat_entry, 1); | |
| 37 pce->label = _("Room:"); | |
| 38 pce->identifier = "room"; | |
| 39 m = g_list_append(m, pce); | |
| 40 | |
| 41 /* we're gonna default to a conference server I know is true, until | |
| 42 * I can figure out how to disco for a chat server */ | |
| 43 pce = g_new0(struct proto_chat_entry, 1); | |
| 44 pce->label = _("Server:"); | |
| 45 pce->identifier = "server"; | |
| 46 pce->def = "conference.jabber.org"; | |
| 47 m = g_list_append(m, pce); | |
| 48 | |
| 49 pce = g_new0(struct proto_chat_entry, 1); | |
| 50 pce->label = _("Handle:"); | |
| 51 pce->identifier = "handle"; | |
| 52 pce->def = js->user->node; | |
| 53 m = g_list_append(m, pce); | |
| 54 | |
| 55 pce = g_new0(struct proto_chat_entry, 1); | |
| 56 pce->label = _("Password:"); | |
| 57 pce->identifier = "password"; | |
| 58 pce->secret = TRUE; | |
| 59 m = g_list_append(m, pce); | |
| 60 | |
| 61 return m; | |
| 62 } | |
| 63 | |
| 64 JabberChat *jabber_chat_find(JabberStream *js, const char *room, | |
| 65 const char *server) | |
| 66 { | |
| 67 JabberChat *chat; | |
| 68 char *room_jid; | |
| 69 | |
| 70 room_jid = g_strdup_printf("%s@%s", room, server); | |
| 71 | |
| 7322 | 72 chat = g_hash_table_lookup(js->chats, jabber_normalize(NULL, room_jid)); |
| 7014 | 73 g_free(room_jid); |
| 74 | |
| 75 return chat; | |
| 76 } | |
| 77 | |
| 78 struct _find_by_id_data { | |
| 79 int id; | |
| 80 JabberChat *chat; | |
| 81 }; | |
| 82 | |
| 83 void find_by_id_foreach_cb(gpointer key, gpointer value, gpointer user_data) | |
| 84 { | |
| 85 JabberChat *chat = value; | |
| 86 struct _find_by_id_data *fbid = user_data; | |
| 87 | |
| 88 if(chat->id == fbid->id) | |
| 89 fbid->chat = chat; | |
| 90 } | |
| 91 | |
| 92 JabberChat *jabber_chat_find_by_id(JabberStream *js, int id) | |
| 93 { | |
| 94 JabberChat *chat; | |
| 95 struct _find_by_id_data *fbid = g_new0(struct _find_by_id_data, 1); | |
| 7073 | 96 fbid->id = id; |
| 7014 | 97 g_hash_table_foreach(js->chats, find_by_id_foreach_cb, fbid); |
| 98 chat = fbid->chat; | |
| 99 g_free(fbid); | |
| 100 return chat; | |
| 101 } | |
| 102 | |
| 103 void jabber_chat_invite(GaimConnection *gc, int id, const char *msg, | |
| 104 const char *name) | |
| 105 { | |
| 106 JabberStream *js = gc->proto_data; | |
| 107 JabberChat *chat; | |
| 108 xmlnode *message, *body, *x, *invite; | |
| 109 char *room_jid; | |
| 110 | |
| 111 chat = jabber_chat_find_by_id(js, id); | |
| 112 if(!chat) | |
| 113 return; | |
| 114 | |
| 115 message = xmlnode_new("message"); | |
| 116 | |
| 117 room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 118 | |
| 119 if(chat->muc) { | |
| 120 xmlnode_set_attrib(message, "to", room_jid); | |
| 121 x = xmlnode_new_child(message, "x"); | |
| 122 xmlnode_set_attrib(x, "xmlns", "http://jabber.org/protocol/muc#user"); | |
| 123 invite = xmlnode_new_child(x, "invite"); | |
| 124 xmlnode_set_attrib(invite, "to", name); | |
| 125 body = xmlnode_new_child(invite, "reason"); | |
| 126 xmlnode_insert_data(body, msg, -1); | |
| 127 } else { | |
| 128 xmlnode_set_attrib(message, "to", name); | |
| 129 body = xmlnode_new_child(message, "body"); | |
| 130 xmlnode_insert_data(body, msg, -1); | |
| 131 x = xmlnode_new_child(message, "x"); | |
| 132 xmlnode_set_attrib(x, "jid", room_jid); | |
| 133 xmlnode_set_attrib(x, "xmlns", "jabber:x:conference"); | |
| 134 } | |
| 135 | |
| 136 jabber_send(js, message); | |
| 137 xmlnode_free(message); | |
| 138 g_free(room_jid); | |
| 139 } | |
| 140 | |
| 141 void jabber_chat_whisper(GaimConnection *gc, int id, const char *who, | |
| 142 const char *message) | |
| 143 { | |
| 144 JabberStream *js = gc->proto_data; | |
| 145 JabberChat *chat; | |
| 146 char *full_jid; | |
| 147 | |
| 148 chat = jabber_chat_find_by_id(js, id); | |
| 149 | |
| 150 full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, who); | |
| 151 | |
| 152 jabber_message_send_im(gc, full_jid, message, 0); | |
| 153 | |
| 154 g_free(full_jid); | |
| 155 } | |
| 156 | |
| 157 void jabber_chat_join(GaimConnection *gc, GHashTable *data) | |
| 158 { | |
| 159 JabberChat *chat; | |
| 160 char *room, *server, *handle, *passwd; | |
| 161 xmlnode *presence, *x; | |
| 7262 | 162 char *tmp, *room_jid, *full_jid; |
| 7014 | 163 JabberStream *js = gc->proto_data; |
| 164 | |
| 165 room = g_hash_table_lookup(data, "room"); | |
| 166 server = g_hash_table_lookup(data, "server"); | |
| 167 handle = g_hash_table_lookup(data, "handle"); | |
| 168 passwd = g_hash_table_lookup(data, "password"); | |
| 169 | |
| 170 if(!room || !server || !handle) | |
| 171 return; | |
| 172 | |
| 7310 | 173 if(!jabber_nodeprep_validate(room)) { |
| 174 char *buf = g_strdup_printf(_("%s is not a valid room name"), room); | |
| 175 gaim_notify_error(gc, _("Invalid Room Name"), _("Invalid Room Name"), | |
| 176 buf); | |
| 177 g_free(buf); | |
| 178 return; | |
| 179 } else if(!jabber_nameprep_validate(server)) { | |
| 180 char *buf = g_strdup_printf(_("%s is not a valid server name"), server); | |
| 181 gaim_notify_error(gc, _("Invalid Server Name"), | |
| 182 _("Invalid Server Name"), buf); | |
| 183 g_free(buf); | |
| 184 return; | |
| 185 } else if(!jabber_resourceprep_validate(handle)) { | |
| 186 char *buf = g_strdup_printf(_("%s is not a valid room handle"), handle); | |
| 187 gaim_notify_error(gc, _("Invalid Room Handle"), | |
| 188 _("Invalid Room Handle"), buf); | |
| 189 } | |
| 190 | |
| 7014 | 191 if(jabber_chat_find(js, room, server)) |
| 192 return; | |
| 193 | |
| 7262 | 194 tmp = g_strdup_printf("%s@%s", room, server); |
| 7322 | 195 room_jid = g_strdup(jabber_normalize(NULL, tmp)); |
| 7262 | 196 g_free(tmp); |
| 7014 | 197 |
| 198 chat = g_new0(JabberChat, 1); | |
| 199 chat->js = gc->proto_data; | |
| 200 | |
| 201 chat->room = g_strdup(room); | |
| 202 chat->server = g_strdup(server); | |
| 203 chat->nick = g_strdup(handle); | |
| 204 | |
| 205 g_hash_table_insert(js->chats, room_jid, chat); | |
| 206 | |
| 7073 | 207 presence = jabber_presence_create(gc->away_state, gc->away); |
| 7014 | 208 full_jid = g_strdup_printf("%s/%s", room_jid, handle); |
| 209 xmlnode_set_attrib(presence, "to", full_jid); | |
| 210 g_free(full_jid); | |
| 211 | |
| 212 x = xmlnode_new_child(presence, "x"); | |
| 213 xmlnode_set_attrib(x, "xmlns", "http://jabber.org/protocol/muc"); | |
| 214 | |
| 215 if(passwd && *passwd) { | |
| 216 xmlnode *password = xmlnode_new_child(x, "password"); | |
| 217 xmlnode_insert_data(password, passwd, -1); | |
| 218 } | |
| 219 | |
| 220 jabber_send(js, presence); | |
| 221 xmlnode_free(presence); | |
| 222 } | |
| 223 | |
| 224 void jabber_chat_leave(GaimConnection *gc, int id) | |
| 225 { | |
| 226 JabberStream *js = gc->proto_data; | |
| 227 JabberChat *chat = jabber_chat_find_by_id(js, id); | |
| 228 char *room_jid; | |
| 229 xmlnode *presence; | |
| 230 | |
| 231 if(!chat) | |
| 232 return; | |
| 233 | |
| 234 room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 235 gaim_debug(GAIM_DEBUG_INFO, "jabber", "%s is leaving chat %s\n", | |
| 236 chat->nick, room_jid); | |
| 237 presence = xmlnode_new("presence"); | |
| 238 xmlnode_set_attrib(presence, "to", room_jid); | |
| 239 xmlnode_set_attrib(presence, "type", "unavailable"); | |
| 240 jabber_send(js, presence); | |
| 241 xmlnode_free(presence); | |
| 242 } | |
| 243 | |
| 244 void jabber_chat_destroy(JabberChat *chat) | |
| 245 { | |
| 246 JabberStream *js = chat->js; | |
| 247 char *room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 248 | |
| 7322 | 249 g_hash_table_remove(js->chats, jabber_normalize(NULL, room_jid)); |
| 7014 | 250 g_free(room_jid); |
| 251 | |
| 252 g_free(chat->room); | |
| 253 g_free(chat->server); | |
| 254 g_free(chat->nick); | |
| 255 g_free(chat); | |
| 256 } | |
| 257 | |
| 258 gboolean jabber_chat_find_buddy(GaimConversation *conv, const char *name) | |
| 259 { | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7073
diff
changeset
|
260 GList *m = gaim_conv_chat_get_users(GAIM_CONV_CHAT(conv)); |
| 7014 | 261 |
| 262 while(m) { | |
| 263 if(!strcmp(m->data, name)) | |
| 264 return TRUE; | |
| 265 m = m->next; | |
| 266 } | |
| 267 | |
| 268 return FALSE; | |
| 269 } | |
| 270 |
