Update 'es' translation
[siplcs.git] / src / sipe-session.c
blob6f258586e3d914edd5399b45e2f8a8c067af30a0
1 /**
2 * @file sipe-session.c
4 * pidgin-sipe
6 * Copyright (C) 2009 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <string.h>
24 #include <glib.h>
26 #include "debug.h"
28 #include "sipe.h"
29 #include "sipe-dialog.h"
30 #include "sipe-session.h"
31 #include "sipe-utils.h"
33 struct sip_session *
34 sipe_session_add_chat(struct sipe_account_data *sip)
36 struct sip_session *session = g_new0(struct sip_session, 1);
37 session->callid = gencallid();
38 session->is_multiparty = TRUE;
39 session->chat_id = rand();
40 session->unconfirmed_messages = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
41 session->conf_unconfirmed_messages = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
42 sip->sessions = g_slist_append(sip->sessions, session);
43 return session;
46 struct sip_session *
47 sipe_session_find_or_add_chat_by_callid(struct sipe_account_data *sip,
48 const gchar *callid)
50 struct sip_session *session = sipe_session_find_chat_by_callid(sip, callid);
51 if (!session) {
52 purple_debug_info("sipe", "sipe_session_find_or_add_chat_by_callid: new session for %s\n", callid);
53 session = sipe_session_add_chat(sip);
54 session->callid = g_strdup(callid);
56 return session;
59 struct sip_session *
60 sipe_session_find_chat_by_callid(struct sipe_account_data *sip,
61 const gchar *callid)
63 if (sip == NULL || callid == NULL) {
64 return NULL;
67 SIPE_SESSION_FOREACH {
68 if (session->callid &&
69 !g_ascii_strcasecmp(callid, session->callid)) {
70 return session;
72 } SIPE_SESSION_FOREACH_END;
73 return NULL;
76 struct sip_session *
77 sipe_session_find_chat_by_id(struct sipe_account_data *sip,
78 int id)
80 if (sip == NULL) {
81 return NULL;
84 SIPE_SESSION_FOREACH {
85 if (id == session->chat_id) {
86 return session;
88 } SIPE_SESSION_FOREACH_END;
89 return NULL;
92 struct sip_session *
93 sipe_session_find_chat_by_name(struct sipe_account_data *sip,
94 const gchar *name)
96 if (sip == NULL || name == NULL) {
97 return NULL;
100 SIPE_SESSION_FOREACH {
101 if (session->chat_name &&
102 !g_strcasecmp(name, session->chat_name)) {
103 return session;
105 } SIPE_SESSION_FOREACH_END;
106 return NULL;
109 struct sip_session *
110 sipe_session_find_conference(struct sipe_account_data *sip,
111 const gchar *focus_uri)
113 if (sip == NULL || focus_uri == NULL) {
114 return NULL;
117 SIPE_SESSION_FOREACH {
118 if (session->focus_uri &&
119 !g_ascii_strcasecmp(focus_uri, session->focus_uri)) {
120 return session;
122 } SIPE_SESSION_FOREACH_END;
123 return NULL;
126 struct sip_session *
127 sipe_session_find_im(struct sipe_account_data *sip, const gchar *who)
129 if (sip == NULL || who == NULL) {
130 return NULL;
133 SIPE_SESSION_FOREACH {
134 if (session->with && !g_ascii_strcasecmp(who, session->with)) {
135 return session;
137 } SIPE_SESSION_FOREACH_END;
138 return NULL;
141 struct sip_session *
142 sipe_session_find_or_add_im(struct sipe_account_data *sip,
143 const gchar *who)
145 struct sip_session *session = sipe_session_find_im(sip, who);
146 if (!session) {
147 purple_debug_info("sipe", "sipe_session_find_or_add_im: new session for %s\n", who);
148 session = g_new0(struct sip_session, 1);
149 session->is_multiparty = FALSE;
150 session->with = g_strdup(who);
151 session->unconfirmed_messages = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
152 sip->sessions = g_slist_append(sip->sessions, session);
154 return session;
157 void
158 sipe_session_remove(struct sipe_account_data *sip, struct sip_session *session)
160 GSList *entry;
162 sip->sessions = g_slist_remove(sip->sessions, session);
164 sipe_dialog_remove_all(session);
165 sipe_dialog_free(session->focus_dialog);
167 entry = session->outgoing_message_queue;
168 while (entry) {
169 g_free(entry->data);
170 entry = entry->next;
172 g_slist_free(session->outgoing_message_queue);
174 entry = session->pending_invite_queue;
175 while (entry) {
176 g_free(entry->data);
177 entry = entry->next;
179 g_slist_free(session->pending_invite_queue);
181 g_hash_table_destroy(session->unconfirmed_messages);
182 g_hash_table_destroy(session->conf_unconfirmed_messages);
184 g_free(session->with);
185 g_free(session->chat_name);
186 g_free(session->callid);
187 g_free(session->roster_manager);
188 g_free(session->focus_uri);
189 g_free(session->im_mcu_uri);
190 g_free(session->subject);
191 g_free(session);
194 void
195 sipe_session_remove_all(struct sipe_account_data *sip)
197 GSList *entry;
198 while ((entry = sip->sessions) != NULL) {
199 sipe_session_remove(sip, entry->data);
204 Local Variables:
205 mode: c
206 c-file-style: "bsd"
207 indent-tabs-mode: t
208 tab-width: 8
209 End: