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
32 #include "sipe-backend.h"
33 #include "sipe-chat.h"
34 #include "sipe-core.h"
35 #include "sipe-core-private.h"
37 #include "sipe-session.h"
38 #include "sipe-utils.h"
41 void sipe_core_chat_create(struct sipe_core_public
*sipe_public
, int id
,
44 struct sipe_account_data
*sip
= SIPE_ACCOUNT_DATA
;
45 struct sip_session
*session
= sipe_session_find_chat_by_id(sip
, id
);
48 gchar
*uri
= sip_uri(name
);
49 sipe_invite_to_chat(sip
, session
, uri
);
54 /** See below. Same as chat_names but swapped key with values */
55 static GHashTable
*chat_names_inverse
= NULL
;
58 sipe_chat_get_name(const gchar
*proto_chat_id
)
61 * A non-volatile mapping of protocol's chat identification
62 * to purple's chat-name. The latter is very important to
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
;
72 * A non-volatile chat counter.
73 * Should survive protocol reload.
75 static int chat_seq
= 0;
77 char *chat_name
= NULL
;
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
);
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");
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
);
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
));