security: fix target name memory leak in Kerberos
[siplcs.git] / src / core / sipe-user.c
blobbca786cf256749a8f65cd4d40a3d63778fdf4254
1 /**
2 * @file sipe-user.c
4 * pidgin-sipe
6 * Copyright (C) 2010-11 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 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
27 #include <glib.h>
29 #include "sipe-common.h"
30 #include "sipmsg.h"
31 #include "sip-transport.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-dialog.h"
37 #include "sipe-im.h"
38 #include "sipe-nls.h"
39 #include "sipe-session.h"
40 #include "sipe-user.h"
41 #include "sipe-utils.h"
43 void sipe_user_present_info(struct sipe_core_private *sipe_private,
44 struct sip_session *session,
45 const gchar *message)
47 sipe_backend_notify_message_info(SIPE_CORE_PUBLIC,
48 session->chat_session ? session->chat_session->backend : NULL,
49 session->with,
50 message);
53 void sipe_user_present_error(struct sipe_core_private *sipe_private,
54 struct sip_session *session,
55 const gchar *message)
57 sipe_backend_notify_message_error(SIPE_CORE_PUBLIC,
58 session->chat_session ? session->chat_session->backend : NULL,
59 session->with,
60 message);
63 void sipe_user_present_message_undelivered(struct sipe_core_private *sipe_private,
64 struct sip_session *session,
65 int sip_error,
66 int sip_warning,
67 const gchar *who,
68 const gchar *message)
70 char *msg, *msg_tmp, *msg_tmp2;
71 const char *label;
73 msg_tmp = message ? sipe_backend_markup_strip_html(message) : NULL;
74 msg = msg_tmp ? g_strdup_printf("<font color=\"#888888\"></b>%s<b></font>", msg_tmp) : NULL;
75 g_free(msg_tmp);
76 /* Service unavailable; Server Internal Error; Server Time-out */
77 if (sip_error == 606 && sip_warning == 309) { /* Not acceptable all. */ /* Message contents not allowed by policy */
78 label = _("Your message or invitation was not delivered, possibly because it contains a hyperlink or other content that the system administrator has blocked.");
79 g_free(msg);
80 msg = NULL;
81 } else if (sip_error == 500 || sip_error == 503 || sip_error == 504 || sip_error == 603) {
82 label = _("This message was not delivered to %s because the service is not available");
83 } else if (sip_error == 486) { /* Busy Here */
84 label = _("This message was not delivered to %s because one or more recipients do not want to be disturbed");
85 } else if (sip_error == 415) { /* Unsupported media type */
86 label = _("This message was not delivered to %s because one or more recipients don't support this type of message");
87 } else {
88 label = _("This message was not delivered to %s because one or more recipients are offline");
91 msg_tmp = g_strdup_printf( "%s%s\n%s" ,
92 msg_tmp2 = g_strdup_printf(label, who ? who : ""),
93 msg ? ":" : "",
94 msg ? msg : "");
95 sipe_user_present_error(sipe_private, session, msg_tmp);
96 g_free(msg_tmp2);
97 g_free(msg_tmp);
98 g_free(msg);
101 static gboolean process_info_typing_response(struct sipe_core_private *sipe_private,
102 struct sipmsg *msg,
103 SIPE_UNUSED_PARAMETER struct transaction *trans)
105 /* Indicates dangling IM session which needs to be dropped */
106 if (msg->response == 408 || /* Request timeout */
107 msg->response == 480 || /* Temporarily Unavailable */
108 msg->response == 481) { /* Call/Transaction Does Not Exist */
109 gchar *with = parse_from(sipmsg_find_header(msg, "To"));
110 struct sip_session *session = sipe_session_find_im(sipe_private, with);
111 struct sip_dialog *dialog = sipe_dialog_find(session, with);
112 if (dialog)
113 sipe_im_cancel_dangling(sipe_private, session, dialog, with,
114 sipe_im_cancel_unconfirmed);
115 g_free(with);
117 return(TRUE);
120 void sipe_core_user_feedback_typing(struct sipe_core_public *sipe_public,
121 const gchar *to)
123 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
124 struct sip_session *session = sipe_session_find_im(sipe_private, to);
125 struct sip_dialog *dialog = sipe_dialog_find(session, to);
127 if (session && dialog && dialog->is_established) {
128 sip_transport_info(sipe_private,
129 "Content-Type: application/xml\r\n",
130 "<?xml version=\"1.0\"?>"
131 "<KeyboardActivity>"
132 "<status status=\"type\" />"
133 "</KeyboardActivity>",
134 dialog,
135 process_info_typing_response);
139 struct sipe_user_ask_ctx {
140 struct sipe_core_private *sipe_private;
141 SipeUserAskCb accept_cb;
142 SipeUserAskCb decline_cb;
143 gpointer data;
146 struct sipe_user_ask_ctx * sipe_user_ask(struct sipe_core_private *sipe_private,
147 const gchar *message,
148 const gchar *accept_label,
149 SipeUserAskCb accept_cb,
150 const gchar *decline_label,
151 SipeUserAskCb decline_cb,
152 gpointer data)
154 struct sipe_user_ask_ctx *ctx = g_new0(struct sipe_user_ask_ctx, 1);
155 ctx->sipe_private = sipe_private;
156 ctx->accept_cb = accept_cb;
157 ctx->decline_cb = decline_cb;
158 ctx->data = data;
160 sipe_backend_user_ask(SIPE_CORE_PUBLIC, message,
161 accept_label, decline_label,
162 ctx);
164 return ctx;
167 void sipe_core_user_ask_cb(gpointer context, gboolean accepted)
169 struct sipe_user_ask_ctx *ctx = context;
171 if (accepted && ctx->accept_cb)
172 ctx->accept_cb(ctx->sipe_private, ctx->data);
173 else if (ctx->decline_cb)
174 ctx->decline_cb(ctx->sipe_private, ctx->data);
176 g_free(ctx);
179 void sipe_user_close_ask(struct sipe_user_ask_ctx *context)
181 sipe_backend_user_close_ask(context);
182 g_free(context);
186 Local Variables:
187 mode: c
188 c-file-style: "bsd"
189 indent-tabs-mode: t
190 tab-width: 8
191 End: