user: add API for displaying queries to the user
[siplcs.git] / src / core / sipe-user.c
blob844f5dc04595ff08b1ca2ea83a3c40ed45bb6909
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 #include <glib.h>
25 #include "sipe-common.h"
26 #include "sipmsg.h"
27 #include "sip-transport.h"
28 #include "sipe-backend.h"
29 #include "sipe-chat.h"
30 #include "sipe-core.h"
31 #include "sipe-core-private.h"
32 #include "sipe-dialog.h"
33 #include "sipe-im.h"
34 #include "sipe-nls.h"
35 #include "sipe-session.h"
36 #include "sipe-user.h"
37 #include "sipe-utils.h"
39 void sipe_user_present_info(struct sipe_core_private *sipe_private,
40 struct sip_session *session,
41 const gchar *message)
43 sipe_backend_notify_message_info(SIPE_CORE_PUBLIC,
44 session->chat_session ? session->chat_session->backend : NULL,
45 session->with,
46 message);
49 void sipe_user_present_error(struct sipe_core_private *sipe_private,
50 struct sip_session *session,
51 const gchar *message)
53 sipe_backend_notify_message_error(SIPE_CORE_PUBLIC,
54 session->chat_session ? session->chat_session->backend : NULL,
55 session->with,
56 message);
59 void sipe_user_present_message_undelivered(struct sipe_core_private *sipe_private,
60 struct sip_session *session,
61 int sip_error,
62 int sip_warning,
63 const gchar *who,
64 const gchar *message)
66 char *msg, *msg_tmp, *msg_tmp2;
67 const char *label;
69 msg_tmp = message ? sipe_backend_markup_strip_html(message) : NULL;
70 msg = msg_tmp ? g_strdup_printf("<font color=\"#888888\"></b>%s<b></font>", msg_tmp) : NULL;
71 g_free(msg_tmp);
72 /* Service unavailable; Server Internal Error; Server Time-out */
73 if (sip_error == 606 && sip_warning == 309) { /* Not acceptable all. */ /* Message contents not allowed by policy */
74 label = _("Your message or invitation was not delivered, possibly because it contains a hyperlink or other content that the system administrator has blocked.");
75 g_free(msg);
76 msg = NULL;
77 } else if (sip_error == 500 || sip_error == 503 || sip_error == 504 || sip_error == 603) {
78 label = _("This message was not delivered to %s because the service is not available");
79 } else if (sip_error == 486) { /* Busy Here */
80 label = _("This message was not delivered to %s because one or more recipients do not want to be disturbed");
81 } else if (sip_error == 415) { /* Unsupported media type */
82 label = _("This message was not delivered to %s because one or more recipients don't support this type of message");
83 } else {
84 label = _("This message was not delivered to %s because one or more recipients are offline");
87 msg_tmp = g_strdup_printf( "%s%s\n%s" ,
88 msg_tmp2 = g_strdup_printf(label, who ? who : ""),
89 msg ? ":" : "",
90 msg ? msg : "");
91 sipe_user_present_error(sipe_private, session, msg_tmp);
92 g_free(msg_tmp2);
93 g_free(msg_tmp);
94 g_free(msg);
97 static gboolean process_info_typing_response(struct sipe_core_private *sipe_private,
98 struct sipmsg *msg,
99 SIPE_UNUSED_PARAMETER struct transaction *trans)
101 /* Indicates dangling IM session which needs to be dropped */
102 if (msg->response == 408 || /* Request timeout */
103 msg->response == 480 || /* Temporarily Unavailable */
104 msg->response == 481) { /* Call/Transaction Does Not Exist */
105 gchar *with = parse_from(sipmsg_find_header(msg, "To"));
106 struct sip_session *session = sipe_session_find_im(sipe_private, with);
107 struct sip_dialog *dialog = sipe_dialog_find(session, with);
108 if (dialog)
109 sipe_im_cancel_dangling(sipe_private, session, dialog, with,
110 sipe_im_cancel_unconfirmed);
111 g_free(with);
113 return(TRUE);
116 void sipe_core_user_feedback_typing(struct sipe_core_public *sipe_public,
117 const gchar *to)
119 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
120 struct sip_session *session = sipe_session_find_im(sipe_private, to);
121 struct sip_dialog *dialog = sipe_dialog_find(session, to);
123 if (session && dialog && dialog->is_established) {
124 sip_transport_info(sipe_private,
125 "Content-Type: application/xml\r\n",
126 "<?xml version=\"1.0\"?>"
127 "<KeyboardActivity>"
128 "<status status=\"type\" />"
129 "</KeyboardActivity>",
130 dialog,
131 process_info_typing_response);
135 struct sipe_user_ask_ctx {
136 struct sipe_core_private *sipe_private;
137 SipeUserAskCb accept_cb;
138 SipeUserAskCb decline_cb;
139 gpointer data;
142 struct sipe_user_ask_ctx * sipe_user_ask(struct sipe_core_private *sipe_private,
143 const gchar *message,
144 const gchar *accept_label,
145 SipeUserAskCb accept_cb,
146 const gchar *decline_label,
147 SipeUserAskCb decline_cb,
148 gpointer data)
150 struct sipe_user_ask_ctx *ctx = g_new0(struct sipe_user_ask_ctx, 1);
151 ctx->sipe_private = sipe_private;
152 ctx->accept_cb = accept_cb;
153 ctx->decline_cb = decline_cb;
154 ctx->data = data;
156 sipe_backend_user_ask(SIPE_CORE_PUBLIC, message,
157 accept_label, decline_label,
158 ctx);
160 return ctx;
163 void sipe_core_user_ask_cb(gpointer context, gboolean accepted)
165 struct sipe_user_ask_ctx *ctx = context;
167 if (accepted && ctx->accept_cb)
168 ctx->accept_cb(ctx->sipe_private, ctx->data);
169 else if (ctx->decline_cb)
170 ctx->decline_cb(ctx->sipe_private, ctx->data);
172 g_free(ctx);
175 void sipe_user_close_ask(struct sipe_user_ask_ctx *context)
177 sipe_backend_user_close_ask(context);
178 g_free(context);
182 Local Variables:
183 mode: c
184 c-file-style: "bsd"
185 indent-tabs-mode: t
186 tab-width: 8
187 End: