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
25 #include "sipe-common.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"
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
,
43 sipe_backend_notify_message_info(SIPE_CORE_PUBLIC
,
44 session
->chat_session
? session
->chat_session
->backend
: NULL
,
49 void sipe_user_present_error(struct sipe_core_private
*sipe_private
,
50 struct sip_session
*session
,
53 sipe_backend_notify_message_error(SIPE_CORE_PUBLIC
,
54 session
->chat_session
? session
->chat_session
->backend
: NULL
,
59 void sipe_user_present_message_undelivered(struct sipe_core_private
*sipe_private
,
60 struct sip_session
*session
,
66 char *msg
, *msg_tmp
, *msg_tmp2
;
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
;
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.");
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");
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
: ""),
91 sipe_user_present_error(sipe_private
, session
, msg_tmp
);
97 static gboolean
process_info_typing_response(struct sipe_core_private
*sipe_private
,
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
);
109 sipe_im_cancel_dangling(sipe_private
, session
, dialog
, with
,
110 sipe_im_cancel_unconfirmed
);
116 void sipe_core_user_feedback_typing(struct sipe_core_public
*sipe_public
,
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\"?>"
128 "<status status=\"type\" />"
129 "</KeyboardActivity>",
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
;
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
,
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
;
156 sipe_backend_user_ask(SIPE_CORE_PUBLIC
, message
,
157 accept_label
, decline_label
,
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
);
175 void sipe_user_close_ask(struct sipe_user_ask_ctx
*context
)
177 sipe_backend_user_close_ask(context
);