6 * Copyright (C) 2010-2013 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"
35 #include "newpluginapi.h"
36 #include "m_protosvc.h"
37 #include "m_protoint.h"
42 #include "miranda-private.h"
44 void sipe_backend_chat_session_destroy(SIPE_UNUSED_PARAMETER
struct sipe_backend_chat_session
*session
)
46 /* Nothing to do here */
49 void sipe_backend_chat_add(struct sipe_backend_chat_session
*backend_session
,
53 SIPPROTO
*pr
= backend_session
->pr
;
54 struct sipe_core_public
*sipe_public
= pr
->sip
;
55 gchar
*self
= sipe_miranda_uri_self(pr
);
59 HANDLE hContact
= sipe_backend_buddy_find( sipe_public
, uri
, NULL
);
60 gchar
*nick
= sipe_miranda_getContactString(pr
, hContact
, "Nick");
62 SIPE_DEBUG_INFO("sipe_backend_chat_add: Adding user <%s> to chat <%s>", uri
, backend_session
->conv
);
64 gcd
.pszModule
= pr
->proto
.m_szModuleName
;
65 gcd
.pszID
= backend_session
->conv
;
66 gcd
.iType
= GC_EVENT_JOIN
;
68 gce
.cbSize
= sizeof(gce
);
72 gce
.pszStatus
= "Normal";
73 gce
.bIsMe
= !strcmp(self
, uri
);
76 retval
= CallService( MS_GC_EVENT
, 0, (LPARAM
)&gce
);
78 SIPE_DEBUG_WARNING("sipe_backend_chat_add: Failed to add user to chat: <%d>", retval
);
83 void sipe_backend_chat_close(struct sipe_backend_chat_session
*backend_session
)
88 struct sipe_chat_session
*session
;
92 SIPE_DEBUG_WARNING_NOFORMAT("Attempted to close NULL backend_session");
96 pr
= backend_session
->pr
;
98 gce
.cbSize
= sizeof(gce
);
101 gcd
.pszModule
= pr
->proto
.m_szModuleName
;
102 gcd
.pszID
= backend_session
->conv
;
103 gcd
.iType
= GC_EVENT_CONTROL
;
105 session
= (struct sipe_chat_session
*)CallServiceSync( MS_GC_EVENT
, SESSION_TERMINATE
, (LPARAM
)&gce
);
108 struct sipe_backend_chat_session
*sipe_backend_chat_create(struct sipe_core_public
*sipe_public
,
109 struct sipe_chat_session
*session
,
113 SIPPROTO
*pr
= sipe_public
->backend_private
;
117 gchar
*id
= g_strdup(title
); /* FIXME: Generate ID */
118 struct sipe_backend_chat_session
*conv
= g_new0(struct sipe_backend_chat_session
,1);
120 gs
.cbSize
= sizeof(gs
);
121 gs
.iType
= GCW_CHATROOM
;
122 gs
.pszModule
= pr
->proto
.m_szModuleName
;
125 gs
.pszStatusbarText
= NULL
;
127 gs
.dwItemData
= (DWORD
)session
;
129 if (CallServiceSync( MS_GC_NEWSESSION
, 0, (LPARAM
)&gs
))
131 SIPE_DEBUG_ERROR("Failed to create chat session <%d> <%s>", id
, title
);
134 gcd
.pszModule
= pr
->proto
.m_szModuleName
;
137 gce
.cbSize
= sizeof(gce
);
140 gcd
.iType
= GC_EVENT_ADDGROUP
;
141 gce
.pszStatus
= "Normal";
142 if (CallService( MS_GC_EVENT
, 0, (LPARAM
)&gce
))
144 SIPE_DEBUG_WARNING_NOFORMAT("Failed to add normal status to chat session");
147 gce
.pszStatus
= "Presenter";
148 if (CallService( MS_GC_EVENT
, 0, (LPARAM
)&gce
))
150 SIPE_DEBUG_WARNING_NOFORMAT("Failed to add presenter status to chat session");
154 gcd
.iType
= GC_EVENT_CONTROL
;
156 if (CallServiceSync( MS_GC_EVENT
, SESSION_INITDONE
, (LPARAM
)&gce
))
158 SIPE_DEBUG_WARNING_NOFORMAT("Failed to initdone chat session");
160 if (CallServiceSync( MS_GC_EVENT
, SESSION_ONLINE
, (LPARAM
)&gce
))
162 SIPE_DEBUG_ERROR_NOFORMAT("Failed to set chat session online");
171 gboolean
sipe_backend_chat_find(struct sipe_backend_chat_session
*backend_session
,
174 SIPPROTO
*pr
= backend_session
->pr
;
179 gci
.Flags
= BYID
| USERS
;
180 gci
.pszID
= mir_a2t(backend_session
->conv
);
181 gci
.pszModule
= pr
->proto
.m_szModuleName
;
183 if(CallServiceSync( MS_GC_GETINFO
, 0, (LPARAM
)&gci
)) {
184 SIPE_DEBUG_ERROR_NOFORMAT("Failed to get chat user list");
191 user
= strtok_s(gci
.pszUsers
, " ", &context
);
194 SIPE_DEBUG_INFO("sipe_backend_chat_find: Found user <%s>", user
);
195 if (!strcmp(uri
, user
)) {
196 mir_free(gci
.pszUsers
);
199 user
= strtok_s(NULL
, " ", &context
);
202 mir_free(gci
.pszUsers
);
206 gboolean
sipe_backend_chat_is_operator(struct sipe_backend_chat_session
*backend_session
,
213 void sipe_backend_chat_message(struct sipe_core_public
*sipe_public
,
214 struct sipe_backend_chat_session
*backend_session
,
219 SIPPROTO
*pr
= backend_session
->pr
;
220 gchar
*self
= sipe_miranda_uri_self(pr
);
224 HANDLE hContact
= sipe_backend_buddy_find( sipe_public
, from
, NULL
);
225 gchar
*nick
= sipe_miranda_getContactString(pr
, hContact
, "Nick");
227 gcd
.pszModule
= pr
->proto
.m_szModuleName
;
228 gcd
.pszID
= backend_session
->conv
;
229 gcd
.iType
= GC_EVENT_MESSAGE
;
231 msg
= sipe_miranda_eliminate_html(html
, strlen(html
));
233 gce
.cbSize
= sizeof(gce
);
238 gce
.bIsMe
= !strcmp(self
, from
);
239 // gce.time = mtime; // FIXME: Generate timestamp
242 CallService( MS_GC_EVENT
, 0, (LPARAM
)&gce
);
247 void sipe_backend_chat_operator(struct sipe_backend_chat_session
*backend_session
,
255 struct sipe_core_public
*sipe_public
;
257 if (!backend_session
)
259 SIPE_DEBUG_WARNING_NOFORMAT("Attempted to set operator on NULL backend_session");
263 pr
= backend_session
->pr
;
264 sipe_public
= pr
->sip
;
266 hContact
= sipe_backend_buddy_find( sipe_public
, uri
, NULL
);
267 nick
= sipe_miranda_getContactString(pr
, hContact
, "Nick");
269 gce
.cbSize
= sizeof(gce
);
273 gce
.pszText
= "Presenter";
274 gce
.pszStatus
= "Presenter";
276 gcd
.pszModule
= pr
->proto
.m_szModuleName
;
277 gcd
.pszID
= backend_session
->conv
;
278 gcd
.iType
= GC_EVENT_ADDSTATUS
;
280 if (CallServiceSync( MS_GC_EVENT
, 0, (LPARAM
)&gce
))
282 SIPE_DEBUG_WARNING_NOFORMAT("Failed to set presenter status");
287 void sipe_backend_chat_rejoin(struct sipe_core_public
*sipe_public
,
288 struct sipe_backend_chat_session
*backend_session
,
296 * Connection re-established: tell core what chats need to be rejoined
298 void sipe_backend_chat_rejoin_all(struct sipe_core_public
*sipe_public
)
303 void sipe_backend_chat_remove(struct sipe_backend_chat_session
*backend_session
,
306 SIPPROTO
*pr
= backend_session
->pr
;
307 struct sipe_core_public
*sipe_public
= pr
->sip
;
308 gchar
*self
= sipe_miranda_uri_self(pr
);
311 HANDLE hContact
= sipe_backend_buddy_find( sipe_public
, uri
, NULL
);
312 gchar
*nick
= sipe_miranda_getContactString(pr
, hContact
, "Nick");
314 SIPE_DEBUG_INFO("sipe_backend_chat_remove: Removing user <%s> from chat <%s>", uri
, backend_session
->conv
);
316 gcd
.pszModule
= pr
->proto
.m_szModuleName
;
317 gcd
.pszID
= backend_session
->conv
;
318 gcd
.iType
= GC_EVENT_PART
;
320 gce
.cbSize
= sizeof(gce
);
325 gce
.bIsMe
= !strcmp(self
, uri
);
328 CallService( MS_GC_EVENT
, 0, (LPARAM
)&gce
);
332 void sipe_backend_chat_show(struct sipe_backend_chat_session
*backend_session
)
337 void sipe_backend_chat_topic(struct sipe_backend_chat_session
*backend_session
,
340 SIPPROTO
*pr
= backend_session
->pr
;
344 SIPE_DEBUG_INFO("sipe_backend_chat_topic: conv <%s> topic <%s>", backend_session
->conv
, topic
);
346 gcd
.pszModule
= pr
->proto
.m_szModuleName
;
347 gcd
.pszID
= backend_session
->conv
;
348 gcd
.iType
= GC_EVENT_TOPIC
;
350 gce
.cbSize
= sizeof(gce
);
356 CallService( MS_GC_EVENT
, 0, (LPARAM
)&gce
);