6 * Copyright (C) 2010-11 SIPE Project <http://sipe.sourceforge.net/>
7 * Copyright (C) 2010 Jakub Adam <jakub.adam@ktknet.cz>
8 * Copyright (C) 2010 Tomáš Hrabčík <tomas.hrabcik@tieto.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 "newpluginapi.h"
31 #include "m_protosvc.h"
32 #include "m_protoint.h"
33 #include "m_database.h"
34 #include "m_protomod.h"
36 #include "sipe-common.h"
37 #include "sipe-backend.h"
38 #include "sipe-core.h"
40 #include "miranda-private.h"
42 struct sipe_backend_file_transfer
{
46 void sipe_backend_ft_error(struct sipe_file_transfer
*ft
,
52 const gchar
*sipe_backend_ft_get_error(SIPE_UNUSED_PARAMETER
struct sipe_file_transfer
*ft
)
58 void sipe_backend_ft_deallocate(struct sipe_file_transfer
*ft
)
60 g_free(ft
->backend_private
);
63 gssize
sipe_backend_ft_read(struct sipe_file_transfer
*ft
,
71 gssize
sipe_backend_ft_write(struct sipe_file_transfer
*ft
,
79 void sipe_backend_ft_cancel_local(struct sipe_file_transfer
*ft
)
84 void sipe_backend_ft_cancel_remote(struct sipe_file_transfer
*ft
)
89 void sipe_backend_ft_incoming(struct sipe_core_public
*sipe_public
,
90 struct sipe_file_transfer
*ft
,
92 const gchar
*file_name
,
95 SIPPROTO
*pr
= sipe_public
->backend_private
;
96 PROTORECVFILET pre
= {0};
100 hContact
= sipe_backend_buddy_find( sipe_public
, who
, NULL
);
103 SIPE_DEBUG_INFO("Adding miranda contact for incoming transfer from <%s>", who
);
104 hContact
= ( HANDLE
)CallService( MS_DB_CONTACT_ADD
, 0, 0 );
105 CallService( MS_PROTO_ADDTOCONTACT
, ( WPARAM
)hContact
,( LPARAM
)pr
->proto
.m_szModuleName
);
106 DBWriteContactSettingByte( hContact
, "CList", "NotOnList", 1 );
107 sipe_miranda_setContactString( pr
, hContact
, SIP_UNIQUEID
, who
); // name
110 ft
->backend_private
= g_new0(struct sipe_backend_file_transfer
, 1);
111 ft
->backend_private
->incoming
= TRUE
;
113 pre
.flags
= PREF_TCHAR
;
114 pre
.timestamp
= time(NULL
);
115 pre
.tszDescription
= mir_a2t(file_name
);
117 pre
.ptszFiles
= &pre
.tszDescription
;
118 pre
.lParam
= (LPARAM
)ft
;
120 ccs
.szProtoService
= PSR_FILE
;
121 ccs
.hContact
= hContact
;
123 ccs
.lParam
= (LPARAM
)&pre
;
124 CallService(MS_PROTO_CHAINRECV
, 0, (LPARAM
)&ccs
);
129 sipe_backend_ft_incoming_accept(struct sipe_file_transfer
*ft
,
131 unsigned short port_min
,
132 unsigned short port_max
)
139 sipe_backend_ft_start(struct sipe_file_transfer
*ft
, struct sipe_backend_fd
*fd
,
140 const char* ip
, unsigned port
)
146 sipe_backend_ft_is_incoming(struct sipe_file_transfer
*ft
)
148 return ft
->backend_private
->incoming
;
152 sipe_miranda_SendFile( SIPPROTO
*pr
, HANDLE hContact
, const PROTOCHAR
* szDescription
, PROTOCHAR
** ppszFiles
)
154 struct sipe_file_transfer
*ft
= sipe_core_ft_allocate(pr
->sip
);
157 if ( !DBGetContactSettingString( hContact
, pr
->proto
.m_szModuleName
, SIP_UNIQUEID
, &dbv
)) {
159 ft
->backend_private
= g_new0(struct sipe_backend_file_transfer
, 1);
160 ft
->backend_private
->incoming
= FALSE
;
161 sipe_core_ft_outgoing_init(ft
, TCHAR2CHAR(ppszFiles
[0]), 10, dbv
.pszVal
);
164 SIPE_DEBUG_INFO("SendFile: desc <%ls> name <%s> to <%s>", szDescription
, TCHAR2CHAR(ppszFiles
[0]), dbv
.pszVal
);
165 DBFreeVariant( &dbv
);
172 sipe_miranda_RecvFile( SIPPROTO
*pr
, HANDLE hContact
, PROTOFILEEVENT
* evt
)
174 CCSDATA ccs
= { hContact
, PSR_FILE
, 0, (LPARAM
)evt
};
175 return CallService(MS_PROTO_RECVFILET
, 0, (LPARAM
)&ccs
);
179 sipe_miranda_FileAllow( SIPPROTO
*pr
, HANDLE hContact
, HANDLE hTransfer
, const PROTOCHAR
* szPath
)
181 struct sipe_file_transfer
*ft
= (struct sipe_file_transfer
*)hTransfer
;
182 sipe_core_ft_incoming_init(ft
);