Updated miranda files from libsipe repo after syncup to current siplcs
[siplcs.git] / src / miranda / miranda-im.c
blob1607d5cd9984a4ae4bff14b8066307698c3d6740
1 /**
2 * @file miranda-im.c
4 * pidgin-sipe
6 * Copyright (C) 2010 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 // SendProtoAck( pr, hContact, 1, ACKRESULT_SENTREQUEST, ACKTYPE_MESSAGE, NULL );
88 sipe_core_im_send(pr->sip, dbv.pszVal, msg);
89 SendProtoAck( pr, hContact, 1, ACKRESULT_SUCCESS, ACKTYPE_MESSAGE, NULL );
90 DBFreeVariant(&dbv);
91 } else {
92 SendProtoAck( pr, hContact, 1, ACKRESULT_FAILED, ACKTYPE_MESSAGE, NULL );
94 return 1;
97 int sipe_miranda_RecvMsg(SIPPROTO *pr,
98 HANDLE hContact,
99 PROTORECVEVENT* pre)
101 // char *msg = EliminateHtml( pre->szMessage, strlen(pre->szMessage));
102 // mir_free(pre->szMessage);
103 // pre->szMessage = msg;
105 CCSDATA ccs = { hContact, PSR_MESSAGE, 0, ( LPARAM )pre };
106 return CallService( MS_PROTO_RECVMSG, 0, ( LPARAM )&ccs );
109 void sipe_backend_im_topic(struct sipe_core_public *sipe_public,
110 const gchar *with,
111 const gchar *topic)
113 _NIF();
117 Local Variables:
118 mode: c
119 c-file-style: "bsd"
120 indent-tabs-mode: t
121 tab-width: 8
122 End: