core cleanup: decouple sipe.h and sip-sec.h
[siplcs.git] / src / core / sipe-chat.c
blob9674d1008ffe65a621ac4d0ede95bb5a2ae29ad6
1 /**
2 * @file sipe-chat.c
4 * pidgin-sipe
6 * Copyright (C) 2010 SIPE Project <http://sipe.sourceforge.net/>
7 * Copyright (C) 2009 SIPE Project <http://sipe.sourceforge.net/>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
28 #include <time.h>
30 #include <glib.h>
32 #include "sipe-backend.h"
33 #include "sipe-chat.h"
34 #include "sipe-core.h"
35 #include "sipe-core-private.h"
36 #include "sipe-nls.h"
37 #include "sipe-session.h"
38 #include "sipe-utils.h"
39 #include "sipe.h"
41 void sipe_core_chat_create(struct sipe_core_public *sipe_public, int id,
42 const char *name)
44 struct sipe_account_data *sip = SIPE_ACCOUNT_DATA;
45 struct sip_session *session = sipe_session_find_chat_by_id(sip, id);
47 if (session) {
48 gchar *uri = sip_uri(name);
49 sipe_invite_to_chat(sip, session, uri);
50 g_free(uri);
54 /** See below. Same as chat_names but swapped key with values */
55 static GHashTable *chat_names_inverse = NULL;
57 gchar *
58 sipe_chat_get_name(const gchar *proto_chat_id)
60 /**
61 * A non-volatile mapping of protocol's chat identification
62 * to purple's chat-name. The latter is very important to
63 * find/rejoin chat.
65 * @key for 2007 conference this is (gchar *) Focus URI
66 * for 2005 multiparty chat this is (gchar *) Call-Id of the conversation.
67 * @value a purple chat name.
69 static GHashTable *chat_names = NULL;
71 /**
72 * A non-volatile chat counter.
73 * Should survive protocol reload.
75 static int chat_seq = 0;
77 char *chat_name = NULL;
79 if (!chat_names) {
80 chat_names = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
82 if (!chat_names_inverse) {
83 chat_names_inverse = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
86 if (proto_chat_id) {
87 chat_name = g_hash_table_lookup(chat_names, proto_chat_id);
88 SIPE_DEBUG_INFO("sipe_chat_get_name: lookup results: %s", chat_name ? chat_name : "NULL");
90 if (!chat_name) {
91 chat_name = g_strdup_printf(_("Chat #%d"), ++chat_seq);
92 g_hash_table_insert(chat_names, g_strdup(proto_chat_id), chat_name);
93 g_hash_table_insert(chat_names_inverse, chat_name, g_strdup(proto_chat_id));
94 SIPE_DEBUG_INFO("sipe_chat_get_name: added new: %s", chat_name);
97 return g_strdup(chat_name);
100 const gchar *
101 sipe_chat_find_name(const gchar *chat_name)
103 if (!chat_names_inverse) return NULL;
104 return(g_hash_table_lookup(chat_names_inverse, chat_name));
108 Local Variables:
109 mode: c
110 c-file-style: "bsd"
111 indent-tabs-mode: t
112 tab-width: 8
113 End: