Release 1.25.0 -- Buddy Idle Time, RTF
[siplcs.git] / src / miranda / miranda-im.c
blobc2f761f34ec7d0a84991c6b416e923129331dd0e
1 /**
2 * @file miranda-im.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 <windows.h>
24 #include <stdio.h>
26 #include <glib.h>
28 #include "newpluginapi.h"
29 #include "m_protosvc.h"
30 #include "m_protoint.h"
31 #include "m_system.h"
32 #include "m_database.h"
33 #include "m_protomod.h"
35 #include "sipe-backend.h"
36 #include "sipe-core.h"
37 #include "miranda-private.h"
39 void sipe_backend_im_message(struct sipe_core_public *sipe_public,
40 const gchar *from,
41 const gchar *html)
43 SIPPROTO *pr = sipe_public->backend_private;
45 CCSDATA ccs;
46 PROTORECVEVENT pre = {0};
47 HANDLE hContact;
48 gchar *msg;
50 hContact = sipe_backend_buddy_find( sipe_public, from, NULL );
51 if (!hContact)
53 SIPE_DEBUG_INFO("Adding miranda contact for incoming talker <%s>", from);
54 hContact = ( HANDLE )CallService( MS_DB_CONTACT_ADD, 0, 0 );
55 CallService( MS_PROTO_ADDTOCONTACT, ( WPARAM )hContact,( LPARAM )pr->proto.m_szModuleName );
56 DBWriteContactSettingByte( hContact, "CList", "NotOnList", 1 );
57 sipe_miranda_setContactString( pr, hContact, SIP_UNIQUEID, from ); // name
60 msg = sipe_miranda_eliminate_html(html, strlen(html));
62 pre.szMessage = msg;
63 // pre.flags = PREF_UTF + (isRtl ? PREF_RTL : 0);
64 pre.timestamp = (DWORD)time(NULL);
65 pre.lParam = 0;
67 ccs.szProtoService = PSR_MESSAGE;
68 ccs.hContact = hContact;
69 ccs.wParam = 0;
70 ccs.lParam = (LPARAM)&pre;
71 CallService(MS_PROTO_CHAINRECV, 0, (LPARAM)&ccs);
73 mir_free(msg);
77 int sipe_miranda_SendMsg(SIPPROTO *pr,
78 HANDLE hContact,
79 int flags,
80 const char* msg )
82 DBVARIANT dbv;
84 SIPE_DEBUG_INFO("SendMsg: flags <%x> msg <%s>", flags, msg);
86 if ( !DBGetContactSettingString( hContact, pr->proto.m_szModuleName, SIP_UNIQUEID, &dbv )) {
87 LOCK;
88 sipe_core_im_send(pr->sip, dbv.pszVal, msg);
89 UNLOCK;
90 sipe_miranda_SendProtoAck( pr, hContact, 1, ACKRESULT_SUCCESS, ACKTYPE_MESSAGE, NULL );
91 DBFreeVariant(&dbv);
92 } else {
93 sipe_miranda_SendProtoAck( pr, hContact, 1, ACKRESULT_FAILED, ACKTYPE_MESSAGE, NULL );
95 return 1;
98 int sipe_miranda_RecvMsg(SIPPROTO *pr,
99 HANDLE hContact,
100 PROTORECVEVENT* pre)
102 // char *msg = EliminateHtml( pre->szMessage, strlen(pre->szMessage));
103 // mir_free(pre->szMessage);
104 // pre->szMessage = msg;
106 CCSDATA ccs = { hContact, PSR_MESSAGE, 0, ( LPARAM )pre };
107 return CallService( MS_PROTO_RECVMSG, 0, ( LPARAM )&ccs );
110 void sipe_backend_im_topic(struct sipe_core_public *sipe_public,
111 const gchar *with,
112 const gchar *topic)
114 SIPPROTO *pr = sipe_public->backend_private;
115 HANDLE hContact;
117 hContact = sipe_backend_buddy_find( sipe_public, with, NULL );
118 if (!hContact)
120 _NIF();
121 } else {
122 sipe_miranda_AddEvent(pr, hContact, SIPE_EVENTTYPE_IM_TOPIC, time(NULL), DBEF_UTF, strlen(topic), (PBYTE)topic);
128 Local Variables:
129 mode: c
130 c-file-style: "bsd"
131 indent-tabs-mode: t
132 tab-width: 8
133 End: