/* * room_chat.c * * Copyright (C) 2012 James Booth * * This file is part of Profanity. * * Profanity is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Profanity is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Profanity. If not, see . * */ #include #include #include #include typedef struct _muc_room_t { char *room; char *nick; gboolean pending_nick_change; GHashTable *roster; GHashTable *nick_changes; gboolean roster_received; } muc_room; GHashTable *rooms = NULL; static void _room_free(muc_room *room); void room_join(const char * const room, const char * const nick) { if (rooms == NULL) { rooms = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_room_free); } muc_room *new_room = malloc(sizeof(muc_room)); new_room->room = strdup(room); new_room->nick = strdup(nick); new_room->roster = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)p_contact_free); new_room->nick_changes = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); new_room->roster_received = FALSE; new_room->pending_nick_change = FALSE; g_hash_table_insert(rooms, strdup(room), new_room); } void room_set_pending_nick_change(const char * const room) { muc_room *chat_room = g_hash_table_lookup(rooms, room); if (chat_room != NULL) { chat_room->pending_nick_change = TRUE; } } gboolean room_is_pending_nick_change(const char * const room) { muc_room *chat_room = g_hash_table_lookup(rooms, room); if (chat_room != NULL) { return chat_room->pending_nick_change; } else { return FALSE; } } void room_change_nick(const char * const room, const char * const nick) { muc_room *chat_room = g_hash_table_lookup(rooms, room); if (chat_room != NULL) { free(chat_room->nick); chat_room->nick = strdup(nick); chat_room->pending_nick_change = FALSE; } } void room_leave(const char * const room) { g_hash_table_remove(rooms, room); } gboolean room_is_active(const char * const full_room_jid) { char **tokens = g_strsplit(full_room_jid, "/", 0); char *room_part = tokens[0]; if (rooms != NULL) { muc_room *chat_room = g_hash_table_lookup(rooms, room_part); if (chat_room != NULL) { return TRUE; } else { return FALSE; } } else { return FALSE; } } GList * room_get_rooms(void) { if (rooms != NULL) { return g_hash_table_get_keys(rooms); } else { return NULL; } } char * room_get_nick_for_room(const char * const room) { if (rooms != NULL) { muc_room *chat_room = g_hash_table_lookup(rooms, room); if (chat_room != NULL) {