Feature #3594094: Add HTTPS to autodiscover probe
[siplcs.git] / src / miranda / miranda-chat.c
blob96cd4905fed028314edb2b8d398b21271cacf143
1 /**
2 * @file miranda-chat.c
4 * pidgin-sipe
6 * Copyright (C) 2010-11 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
25 #include <windows.h>
26 #include <stdio.h>
28 #include <glib.h>
30 #include "sipe-common.h"
31 #include "sipe-backend.h"
32 #include "sipe-core.h"
33 #include "sipe-nls.h"
35 #include "newpluginapi.h"
36 #include "m_protosvc.h"
37 #include "m_protoint.h"
38 #include "m_chat.h"
39 #include "m_utils.h"
40 #include "m_system.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,
50 const gchar *uri,
51 gboolean is_new)
53 SIPPROTO *pr = backend_session->pr;
54 struct sipe_core_public *sipe_public = pr->sip;
55 gchar *self = sipe_miranda_uri_self(pr);
56 GCDEST gcd = {0};
57 GCEVENT gce = {0};
58 int retval;
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);
69 gce.pDest = &gcd;
70 gce.pszNick = nick;
71 gce.pszUID = uri;
72 gce.pszStatus = "Normal";
73 gce.bIsMe = !strcmp(self, uri);
75 g_free(self);
76 retval = CallService( MS_GC_EVENT, 0, (LPARAM)&gce );
77 if (retval) {
78 SIPE_DEBUG_WARNING("sipe_backend_chat_add: Failed to add user to chat: <%d>", retval);
80 mir_free(nick);
83 void sipe_backend_chat_close(struct sipe_backend_chat_session *backend_session)
85 SIPPROTO *pr;
86 GCEVENT gce = {0};
87 GCDEST gcd = {0};
88 struct sipe_chat_session *session;
90 if (!backend_session)
92 SIPE_DEBUG_WARNING_NOFORMAT("Attempted to close NULL backend_session");
93 return;
96 pr = backend_session->pr;
98 gce.cbSize = sizeof(gce);
99 gce.pDest = &gcd;
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,
110 const gchar *title,
111 const gchar *nick)
113 SIPPROTO *pr = sipe_public->backend_private;
114 GCSESSION gs;
115 GCDEST gcd = {0};
116 GCEVENT gce = {0};
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;
123 gs.pszName = title;
124 gs.pszID = id;
125 gs.pszStatusbarText = NULL;
126 gs.dwFlags = 0;
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;
135 gcd.pszID = id;
137 gce.cbSize = sizeof(gce);
138 gce.pDest = &gcd;
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");
165 conv->conv = id;
166 conv->pr = pr;
168 return conv;
171 gboolean sipe_backend_chat_find(struct sipe_backend_chat_session *backend_session,
172 const gchar *uri)
174 SIPPROTO *pr = backend_session->pr;
175 GC_INFO gci = {0};
176 gchar *context;
177 const gchar *user;
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");
185 return FALSE;
188 if (!gci.pszUsers)
189 return FALSE;
191 user = strtok_s(gci.pszUsers, " ", &context);
192 while (user)
194 SIPE_DEBUG_INFO("sipe_backend_chat_find: Found user <%s>", user);
195 if (!strcmp(uri, user)) {
196 mir_free(gci.pszUsers);
197 return TRUE;
199 user = strtok_s(NULL, " ", &context);
202 mir_free(gci.pszUsers);
203 return FALSE;
206 gboolean sipe_backend_chat_is_operator(struct sipe_backend_chat_session *backend_session,
207 const gchar *uri)
209 _NIF();
210 return TRUE;
213 void sipe_backend_chat_message(struct sipe_core_public *sipe_public,
214 struct sipe_backend_chat_session *backend_session,
215 const gchar *from,
216 const gchar *html)
218 SIPPROTO *pr = backend_session->pr;
219 gchar *self = sipe_miranda_uri_self(pr);
220 gchar *msg;
221 GCDEST gcd = {0};
222 GCEVENT gce = {0};
223 HANDLE hContact = sipe_backend_buddy_find( sipe_public, from, NULL );
224 gchar *nick = sipe_miranda_getContactString(pr, hContact, "Nick");
226 gcd.pszModule = pr->proto.m_szModuleName;
227 gcd.pszID = backend_session->conv;
228 gcd.iType = GC_EVENT_MESSAGE;
230 msg = sipe_miranda_eliminate_html(html, strlen(html));
232 gce.cbSize = sizeof(gce);
233 gce.pDest = &gcd;
234 gce.pszNick = nick;
235 gce.pszUID = from;
236 gce.pszText = msg;
237 gce.bIsMe = !strcmp(self, from);
238 // gce.time = mtime; // FIXME: Generate timestamp
239 g_free(self);
241 CallService( MS_GC_EVENT, 0, (LPARAM)&gce );
242 mir_free(nick);
243 mir_free(msg);
246 void sipe_backend_chat_operator(struct sipe_backend_chat_session *backend_session,
247 const gchar *uri)
249 SIPPROTO *pr;
250 GCEVENT gce = {0};
251 GCDEST gcd = {0};
252 HANDLE hContact;
253 gchar *nick;
254 struct sipe_core_public *sipe_public;
256 if (!backend_session)
258 SIPE_DEBUG_WARNING_NOFORMAT("Attempted to set operator on NULL backend_session");
259 return;
262 pr = backend_session->pr;
263 sipe_public = pr->sip;
265 hContact = sipe_backend_buddy_find( sipe_public, uri, NULL );
266 nick = sipe_miranda_getContactString(pr, hContact, "Nick");
268 gce.cbSize = sizeof(gce);
269 gce.pDest = &gcd;
270 gce.pszNick = nick;
271 gce.pszUID = uri;
272 gce.pszText = "Presenter";
273 gce.pszStatus = "Presenter";
275 gcd.pszModule = pr->proto.m_szModuleName;
276 gcd.pszID = backend_session->conv;
277 gcd.iType = GC_EVENT_ADDSTATUS;
279 if (CallServiceSync( MS_GC_EVENT, 0, (LPARAM)&gce ))
281 SIPE_DEBUG_WARNING_NOFORMAT("Failed to set presenter status");
283 mir_free(nick);
286 void sipe_backend_chat_rejoin(struct sipe_core_public *sipe_public,
287 struct sipe_backend_chat_session *backend_session,
288 const gchar *nick,
289 const gchar *title)
291 _NIF();
295 * Connection re-established: tell core what chats need to be rejoined
297 void sipe_backend_chat_rejoin_all(struct sipe_core_public *sipe_public)
299 _NIF();
302 void sipe_backend_chat_remove(struct sipe_backend_chat_session *backend_session,
303 const gchar *uri)
305 SIPPROTO *pr = backend_session->pr;
306 struct sipe_core_public *sipe_public = pr->sip;
307 gchar *self = sipe_miranda_uri_self(pr);
308 GCDEST gcd = {0};
309 GCEVENT gce = {0};
310 HANDLE hContact = sipe_backend_buddy_find( sipe_public, uri, NULL );
311 gchar *nick = sipe_miranda_getContactString(pr, hContact, "Nick");
313 SIPE_DEBUG_INFO("sipe_backend_chat_remove: Removing user <%s> from chat <%s>", uri, backend_session->conv);
315 gcd.pszModule = pr->proto.m_szModuleName;
316 gcd.pszID = backend_session->conv;
317 gcd.iType = GC_EVENT_PART;
319 gce.cbSize = sizeof(gce);
320 gce.pDest = &gcd;
321 gce.pszNick = nick;
322 gce.pszUID = uri;
323 gce.pszStatus = 0;
324 gce.bIsMe = !strcmp(self, uri);
326 g_free(self);
327 CallService( MS_GC_EVENT, 0, (LPARAM)&gce );
328 mir_free(nick);
331 void sipe_backend_chat_show(struct sipe_backend_chat_session *backend_session)
333 _NIF();
336 void sipe_backend_chat_topic(struct sipe_backend_chat_session *backend_session,
337 const gchar *topic)
339 SIPPROTO *pr = backend_session->pr;
340 GCDEST gcd = {0};
341 GCEVENT gce = {0};
343 SIPE_DEBUG_INFO("sipe_backend_chat_topic: conv <%s> topic <%s>", backend_session->conv, topic);
345 gcd.pszModule = pr->proto.m_szModuleName;
346 gcd.pszID = backend_session->conv;
347 gcd.iType = GC_EVENT_TOPIC;
349 gce.cbSize = sizeof(gce);
350 gce.pDest = &gcd;
351 gce.pszNick = NULL;
352 gce.pszUID = NULL;
353 gce.pszText = topic;
355 CallService( MS_GC_EVENT, 0, (LPARAM)&gce );
359 Local Variables:
360 mode: c
361 c-file-style: "bsd"
362 indent-tabs-mode: t
363 tab-width: 8
364 End: