6 * Copyright (C) 2010 SIPE Project <http://sipe.sourceforge.net/>
7 * Copyright (C) 2009 pier11 <pier11@operamail.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "sipe-common.h"
31 #include "sipe-backend.h"
32 #include "sipe-core.h"
33 #include "sipe-core-private.h"
35 #include "sipe-utils.h"
37 #include "newpluginapi.h"
38 #include "m_protosvc.h"
39 #include "m_protoint.h"
45 #include "miranda-private.h"
47 struct sipe_backend_chat_session
{
52 void sipe_backend_chat_session_destroy(SIPE_UNUSED_PARAMETER
struct sipe_backend_chat_session
*session
)
54 /* Nothing to do here */
57 void sipe_backend_chat_add(struct sipe_backend_chat_session
*backend_session
,
61 SIPPROTO
*pr
= backend_session
->pr
;
62 struct sipe_core_public
*sipe_public
= pr
->sip
;
63 gchar
*self
= sip_uri_self(SIPE_CORE_PRIVATE
);
68 SIPE_DEBUG_INFO("sipe_backend_chat_add: Adding user <%s> to chat <%s>", uri
, backend_session
->conv
);
70 gcd
.pszModule
= pr
->proto
.m_szModuleName
;
71 gcd
.pszID
= backend_session
->conv
;
72 gcd
.iType
= GC_EVENT_JOIN
;
74 gce
.cbSize
= sizeof(gce
);
78 gce
.pszStatus
= "Normal";
79 gce
.bIsMe
= !strcmp(self
, uri
);
82 retval
= CallService( MS_GC_EVENT
, 0, (LPARAM
)&gce
);
84 SIPE_DEBUG_WARNING("sipe_backend_chat_add: Failed to add user to chat: <%d>", retval
);
88 void sipe_backend_chat_close(struct sipe_backend_chat_session
*backend_session
)
96 SIPE_DEBUG_WARNING_NOFORMAT("Attempted to close NULL backend_session");
100 pr
= backend_session
->pr
;
102 gce
.cbSize
= sizeof(gce
);
105 gcd
.pszModule
= pr
->proto
.m_szModuleName
;
106 gcd
.pszID
= backend_session
->conv
;
107 gcd
.iType
= GC_EVENT_CONTROL
;
109 if (CallServiceSync( MS_GC_EVENT
, SESSION_TERMINATE
, (LPARAM
)&gce
))
111 SIPE_DEBUG_WARNING_NOFORMAT("sipe_backend_groupchat_room_terminate: Failed to close chat session");
115 struct sipe_backend_chat_session
*sipe_backend_chat_create(struct sipe_core_public
*sipe_public
,
116 struct sipe_chat_session
*session
,
120 SIPPROTO
*pr
= sipe_public
->backend_private
;
124 gchar
*id
= g_strdup(title
); /* FIXME: Generate ID */
125 struct sipe_backend_chat_session
*conv
= g_new0(struct sipe_backend_chat_session
,1);
127 gs
.cbSize
= sizeof(gs
);
128 gs
.iType
= GCW_CHATROOM
;
129 gs
.pszModule
= pr
->proto
.m_szModuleName
;
132 gs
.pszStatusbarText
= NULL
;
134 gs
.dwItemData
= (DWORD
)session
;
136 if (CallServiceSync( MS_GC_NEWSESSION
, 0, (LPARAM
)&gs
))
138 SIPE_DEBUG_ERROR("sipe_backend_chat_create: Failed to create chat session <%d> <%s>", id
, title
);
141 gcd
.pszModule
= pr
->proto
.m_szModuleName
;
144 gce
.cbSize
= sizeof(gce
);
147 gcd
.iType
= GC_EVENT_ADDGROUP
;
148 gce
.pszStatus
= "Normal";
149 if (CallService( MS_GC_EVENT
, 0, (LPARAM
)&gce
))
151 SIPE_DEBUG_WARNING_NOFORMAT("sipe_backend_chat_create: Failed to add normal status to chat session");
154 gce
.pszStatus
= "Presenter";
155 if (CallService( MS_GC_EVENT
, 0, (LPARAM
)&gce
))
157 SIPE_DEBUG_WARNING_NOFORMAT("sipe_backend_chat_create: Failed to add presenter status to chat session");
161 gcd
.iType
= GC_EVENT_CONTROL
;
163 if (CallServiceSync( MS_GC_EVENT
, SESSION_INITDONE
, (LPARAM
)&gce
))
165 SIPE_DEBUG_WARNING_NOFORMAT("sipe_backend_chat_create: Failed to initdone chat session");
167 if (CallServiceSync( MS_GC_EVENT
, SESSION_ONLINE
, (LPARAM
)&gce
))
169 SIPE_DEBUG_ERROR_NOFORMAT("sipe_backend_chat_create: Failed to set chat session online");
178 gboolean
sipe_backend_chat_find(struct sipe_backend_chat_session
*backend_session
,
181 SIPPROTO
*pr
= backend_session
->pr
;
183 const gchar
*context
;
186 gci
.Flags
= BYID
| USERS
;
187 gci
.pszID
= mir_a2t(backend_session
->conv
);
188 gci
.pszModule
= pr
->proto
.m_szModuleName
;
190 if(CallServiceSync( MS_GC_GETINFO
, 0, (LPARAM
)&gci
)) {
191 SIPE_DEBUG_ERROR_NOFORMAT("sipe_backend_chat_find: Failed to get chat user list");
198 user
= strtok_s(gci
.pszUsers
, " ", &context
);
201 SIPE_DEBUG_INFO("sipe_backend_chat_find: Found user <%s>", user
);
202 if (!strcmp(uri
, user
)) {
203 mir_free(gci
.pszUsers
);
206 user
= strtok_s(NULL
, " ", &context
);
209 mir_free(gci
.pszUsers
);
213 gboolean
sipe_backend_chat_is_operator(struct sipe_backend_chat_session
*backend_session
,
220 void sipe_backend_chat_message(struct sipe_core_public
*sipe_public
,
221 struct sipe_backend_chat_session
*backend_session
,
225 SIPPROTO
*pr
= backend_session
->pr
;
226 gchar
*self
= sip_uri_self(SIPE_CORE_PRIVATE
);
231 gcd
.pszModule
= pr
->proto
.m_szModuleName
;
232 gcd
.pszID
= backend_session
->conv
;
233 gcd
.iType
= GC_EVENT_MESSAGE
;
235 msg
= sipe_miranda_eliminate_html(html
, strlen(html
));
237 gce
.cbSize
= sizeof(gce
);
242 gce
.bIsMe
= !strcmp(self
, from
);
243 // gce.time = mtime; // FIXME: Generate timestamp
246 CallService( MS_GC_EVENT
, 0, (LPARAM
)&gce
);
250 void sipe_backend_chat_operator(struct sipe_backend_chat_session
*backend_session
,
256 void sipe_backend_chat_rejoin(struct sipe_core_public
*sipe_public
,
257 struct sipe_backend_chat_session
*backend_session
,
265 * Connection re-established: tell core what chats need to be rejoined
267 void sipe_backend_chat_rejoin_all(struct sipe_core_public
*sipe_public
)
272 void sipe_backend_chat_remove(struct sipe_backend_chat_session
*backend_session
,
275 SIPPROTO
*pr
= backend_session
->pr
;
276 struct sipe_core_public
*sipe_public
= pr
->sip
;
277 gchar
*self
= sip_uri_self(SIPE_CORE_PRIVATE
);
281 SIPE_DEBUG_INFO("sipe_backend_chat_remove: Removing user <%s> from chat <%s>", uri
, backend_session
->conv
);
283 gcd
.pszModule
= pr
->proto
.m_szModuleName
;
284 gcd
.pszID
= backend_session
->conv
;
285 gcd
.iType
= GC_EVENT_PART
;
287 gce
.cbSize
= sizeof(gce
);
292 gce
.bIsMe
= !strcmp(self
, uri
);
295 CallService( MS_GC_EVENT
, 0, (LPARAM
)&gce
);
298 void sipe_backend_chat_show(struct sipe_backend_chat_session
*backend_session
)
303 void sipe_backend_chat_topic(struct sipe_backend_chat_session
*backend_session
,
306 SIPPROTO
*pr
= backend_session
->pr
;
310 SIPE_DEBUG_INFO("sipe_backend_chat_topic: conv <%s> topic <%s>", backend_session
->conv
, topic
);
312 gcd
.pszModule
= pr
->proto
.m_szModuleName
;
313 gcd
.pszID
= backend_session
->conv
;
314 gcd
.iType
= GC_EVENT_TOPIC
;
316 gce
.cbSize
= sizeof(gce
);
322 CallService( MS_GC_EVENT
, 0, (LPARAM
)&gce
);