1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
|
#include "Mra.h"
#include "MraFilesQueue.h"
#include "proto.h"
#define MRA_FT_HELLO "MRA_FT_HELLO"
#define MRA_FT_GET_FILE "MRA_FT_GET_FILE"
struct MRA_FILES_QUEUE : public LIST_MT
{
DWORD dwSendTimeOutInterval;
};
struct MRA_FILES_QUEUE_FILE
{
LPWSTR lpwszName;
size_t dwNameLen;
DWORDLONG dwSize;
};
struct MRA_FILES_QUEUE_ITEM : public LIST_MT_ITEM
{
// internal
BOOL bIsWorking;
DWORD dwSendTime;
// external
CMraProto *ppro;
DWORD dwIDRequest;
DWORD dwFlags;
HANDLE hContact;
DWORDLONG dwFilesCount;
DWORDLONG dwFilesTotalSize;
MRA_FILES_QUEUE_FILE *pmfqfFiles;
LPWSTR pwszFilesList;
LPWSTR pwszDescription;
MRA_ADDR_LIST malAddrList;
LPWSTR lpwszPath;
size_t dwPathSize;
BOOL bSending;
HANDLE hConnection;
HANDLE hListen;
HANDLE hThread;
HANDLE hWaitHandle;
HANDLE hMraMrimProxyData;
};
struct MRA_FILES_THREADPROC_PARAMS
{
HANDLE hFilesQueueHandle;
MRA_FILES_QUEUE_ITEM *dat;
};
DWORD MraFilesQueueItemFindByID(HANDLE hFilesQueueHandle, DWORD dwIDRequest, MRA_FILES_QUEUE_ITEM **ppmrafqFilesQueueItem);
void MraFilesQueueItemFree(MRA_FILES_QUEUE_ITEM *dat);
/////////////////////////////////////////////////////////////////////////////////////////
// File transfer options
static WORD wMraFilesControlsList[] = {
IDC_FILE_SEND_NOOUTCONNECTIONONRECEIVE,
IDC_FILE_SEND_NOOUTCONNECTIONONSEND,
IDC_FILE_SEND_IGNORYADDITIONALPORTS,
IDC_FILE_SEND_HIDE_MY_ADDRESSES,
IDC_FILE_SEND_ADD_EXTRA_ADDRESS,
IDC_FILE_SEND_EXTRA_ADDRESS
};
void MraFilesQueueDlgEnableDirectConsControls(HWND hWndDlg, BOOL bEnabled)
{
EnableControlsArray(hWndDlg, (WORD*)&wMraFilesControlsList, SIZEOF(wMraFilesControlsList), bEnabled);
EnableWindow(GetDlgItem(hWndDlg, IDC_FILE_SEND_EXTRA_ADDRESS), (bEnabled && IS_DLG_BUTTON_CHECKED(hWndDlg, IDC_FILE_SEND_ADD_EXTRA_ADDRESS)));
}
INT_PTR CALLBACK MraFilesQueueDlgProcOpts(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
CMraProto *ppro = (CMraProto*)GetWindowLongPtr(hWndDlg, GWLP_USERDATA);
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hWndDlg);
SetWindowLongPtr(hWndDlg, GWLP_USERDATA, lParam);
ppro = (CMraProto*)lParam;
{
WCHAR szBuff[MAX_PATH];
CHECK_DLG_BUTTON(hWndDlg, IDC_FILE_SEND_ENABLE_DIRECT_CONN, ppro->mraGetByte(NULL, "FileSendEnableDirectConn", MRA_DEF_FS_ENABLE_DIRECT_CONN));
CHECK_DLG_BUTTON(hWndDlg, IDC_FILE_SEND_NOOUTCONNECTIONONRECEIVE, ppro->mraGetByte(NULL, "FileSendNoOutConnOnRcv", MRA_DEF_FS_NO_OUT_CONN_ON_RCV));
CHECK_DLG_BUTTON(hWndDlg, IDC_FILE_SEND_NOOUTCONNECTIONONSEND, ppro->mraGetByte(NULL, "FileSendNoOutConnOnSend", MRA_DEF_FS_NO_OUT_CONN_ON_SEND));
CHECK_DLG_BUTTON(hWndDlg, IDC_FILE_SEND_IGNORYADDITIONALPORTS, ppro->mraGetByte(NULL, "FileSendIgnoryAdditionalPorts", MRA_DEF_FS_IGNORY_ADDITIONAL_PORTS));
CHECK_DLG_BUTTON(hWndDlg, IDC_FILE_SEND_HIDE_MY_ADDRESSES, ppro->mraGetByte(NULL, "FileSendHideMyAddresses", MRA_DEF_FS_HIDE_MY_ADDRESSES));
CHECK_DLG_BUTTON(hWndDlg, IDC_FILE_SEND_ADD_EXTRA_ADDRESS, ppro->mraGetByte(NULL, "FileSendAddExtraAddresses", MRA_DEF_FS_ADD_EXTRA_ADDRESSES));
if (ppro->mraGetStaticStringW(NULL, "FileSendExtraAddresses", szBuff, SIZEOF(szBuff), NULL))
SET_DLG_ITEM_TEXT(hWndDlg, IDC_FILE_SEND_EXTRA_ADDRESS, szBuff);
CHECK_DLG_BUTTON(hWndDlg, IDC_FILE_SEND_ENABLE_MRIMPROXY_CONS, ppro->mraGetByte(NULL, "FileSendEnableMRIMProxyCons", MRA_DEF_FS_ENABLE_MRIM_PROXY_CONS));
SetDlgItemInt(hWndDlg, IDC_FILE_SEND_BLOCK_SIZE, ppro->mraGetDword(NULL, "FileSendBlockSize", MRA_DEFAULT_FILE_SEND_BLOCK_SIZE), FALSE);
MraFilesQueueDlgEnableDirectConsControls(hWndDlg, IS_DLG_BUTTON_CHECKED(hWndDlg, IDC_FILE_SEND_ENABLE_DIRECT_CONN));
}
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDC_FILE_SEND_ENABLE_DIRECT_CONN)
MraFilesQueueDlgEnableDirectConsControls(hWndDlg, IS_DLG_BUTTON_CHECKED(hWndDlg, IDC_FILE_SEND_ENABLE_DIRECT_CONN));
if (LOWORD(wParam) == IDC_FILE_SEND_ADD_EXTRA_ADDRESS)
EnableWindow(GetDlgItem(hWndDlg, IDC_FILE_SEND_EXTRA_ADDRESS), IS_DLG_BUTTON_CHECKED(hWndDlg, IDC_FILE_SEND_ADD_EXTRA_ADDRESS));
if ((LOWORD(wParam) == IDC_FILE_SEND_EXTRA_ADDRESS || LOWORD(wParam) == IDC_FILE_SEND_BLOCK_SIZE) && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) return FALSE;
SendMessage(GetParent(hWndDlg), PSM_CHANGED, 0, 0);
break;
case WM_NOTIFY:
switch (((LPNMHDR)lParam)->code) {
case PSN_APPLY:
{
WCHAR szBuff[MAX_PATH];
ppro->mraSetByte(NULL, "FileSendEnableDirectConn", IS_DLG_BUTTON_CHECKED(hWndDlg, IDC_FILE_SEND_ENABLE_DIRECT_CONN));
ppro->mraSetByte(NULL, "FileSendNoOutConnOnRcv", IS_DLG_BUTTON_CHECKED(hWndDlg, IDC_FILE_SEND_NOOUTCONNECTIONONRECEIVE));
ppro->mraSetByte(NULL, "FileSendNoOutConnOnSend", IS_DLG_BUTTON_CHECKED(hWndDlg, IDC_FILE_SEND_NOOUTCONNECTIONONSEND));
ppro->mraSetByte(NULL, "FileSendIgnoryAdditionalPorts", IS_DLG_BUTTON_CHECKED(hWndDlg, IDC_FILE_SEND_IGNORYADDITIONALPORTS));
ppro->mraSetByte(NULL, "FileSendHideMyAddresses", IS_DLG_BUTTON_CHECKED(hWndDlg, IDC_FILE_SEND_HIDE_MY_ADDRESSES));
ppro->mraSetByte(NULL, "FileSendAddExtraAddresses", IS_DLG_BUTTON_CHECKED(hWndDlg, IDC_FILE_SEND_ADD_EXTRA_ADDRESS));
GET_DLG_ITEM_TEXT(hWndDlg, IDC_FILE_SEND_EXTRA_ADDRESS, szBuff, SIZEOF(szBuff));
ppro->mraSetStringW(NULL, "FileSendExtraAddresses", szBuff);
ppro->mraSetDword(NULL, "FileSendBlockSize", (DWORD)GetDlgItemInt(hWndDlg, IDC_FILE_SEND_BLOCK_SIZE, NULL, FALSE));
ppro->mraSetByte(NULL, "FileSendEnableMRIMProxyCons", IS_DLG_BUTTON_CHECKED(hWndDlg, IDC_FILE_SEND_ENABLE_MRIMPROXY_CONS));
}
return TRUE;
}
break;
}
return FALSE;
}
/////////////////////////////////////////////////////////////////////////////////////////
// MRA files' queue
DWORD MraFilesQueueInitialize(DWORD dwSendTimeOutInterval, HANDLE *phFilesQueueHandle)
{
if (!phFilesQueueHandle)
return ERROR_INVALID_HANDLE;
MRA_FILES_QUEUE *pmrafqFilesQueue = (MRA_FILES_QUEUE*)mir_calloc(sizeof(MRA_FILES_QUEUE));
if (!pmrafqFilesQueue)
return GetLastError();
DWORD dwRetErrorCode = ListMTInitialize(pmrafqFilesQueue, 0);
if (dwRetErrorCode == NO_ERROR) {
pmrafqFilesQueue->dwSendTimeOutInterval = dwSendTimeOutInterval;
*phFilesQueueHandle = (HANDLE)pmrafqFilesQueue;
}
else mir_free(pmrafqFilesQueue);
return dwRetErrorCode;
}
void MraFilesQueueDestroy(HANDLE hFilesQueueHandle)
{
if ( !hFilesQueueHandle)
return;
MRA_FILES_QUEUE *pmrafqFilesQueue = (MRA_FILES_QUEUE*)hFilesQueueHandle;
MRA_FILES_QUEUE_ITEM *dat;
{
mt_lock l(pmrafqFilesQueue);
while ( ListMTItemGetFirst(pmrafqFilesQueue, NULL, (LPVOID*)&dat) == NO_ERROR)
MraFilesQueueItemFree(dat);
}
ListMTDestroy(pmrafqFilesQueue);
mir_free(pmrafqFilesQueue);
}
DWORD MraFilesQueueItemFindByID(HANDLE hFilesQueueHandle, DWORD dwIDRequest, MRA_FILES_QUEUE_ITEM **ppmrafqFilesQueueItem)
{
if (!hFilesQueueHandle)
return ERROR_INVALID_HANDLE;
MRA_FILES_QUEUE *pmrafqFilesQueue = (MRA_FILES_QUEUE*)hFilesQueueHandle;
MRA_FILES_QUEUE_ITEM *dat;
LIST_MT_ITERATOR lmtiIterator;
mt_lock l(pmrafqFilesQueue);
ListMTIteratorMoveFirst(pmrafqFilesQueue, &lmtiIterator);
do {
if (ListMTIteratorGet(&lmtiIterator, NULL, (LPVOID*)&dat) == NO_ERROR)
if (dat->dwIDRequest == dwIDRequest) {
if (ppmrafqFilesQueueItem)
*ppmrafqFilesQueueItem = dat;
return 0;
}
}
while (ListMTIteratorMoveNext(&lmtiIterator));
return ERROR_NOT_FOUND;
}
HANDLE MraFilesQueueItemProxyByID(HANDLE hFilesQueueHandle, DWORD dwIDRequest)
{
MRA_FILES_QUEUE_ITEM *dat;
if ( !MraFilesQueueItemFindByID(hFilesQueueHandle, dwIDRequest, &dat))
return dat->hMraMrimProxyData;
return NULL;
}
void MraFilesQueueItemFree(MRA_FILES_QUEUE_ITEM *dat)
{
LIST_MT *plmtListMT = (LIST_MT*)dat->lpListMT;
for (size_t i = 0;i<dat->dwFilesCount;i++)
mir_free(dat->pmfqfFiles[i].lpwszName);
mir_free(dat->pmfqfFiles);
mir_free(dat->pwszFilesList);
mir_free(dat->pwszDescription);
MraAddrListFree(&dat->malAddrList);
MraMrimProxyFree(dat->hMraMrimProxyData);
mir_free(dat->lpwszPath);
{
mt_lock l(plmtListMT);
ListMTItemDelete(plmtListMT, dat);
}
mir_free(dat);
}
size_t CMraProto::MraFilesQueueGetLocalAddressesList(LPSTR lpszBuff, size_t dwBuffSize, DWORD dwPort)
{
CHAR szHostName[MAX_PATH] = {0};
LPSTR lpszCurPos = lpszBuff;
if (mraGetByte(NULL, "FileSendHideMyAddresses", MRA_DEF_FS_HIDE_MY_ADDRESSES))
{// íå âûäà¸ì âðàãó íàø IP àäðåñ!!! :)
if (mraGetByte(NULL, "FileSendAddExtraAddresses", MRA_DEF_FS_ADD_EXTRA_ADDRESSES) == FALSE)
{// òîëüêî åñëè íå äîáàâëÿåì àäðåñ ðîóòåðà
lpszCurPos += mir_snprintf(lpszCurPos, (dwBuffSize-((size_t)lpszCurPos-(size_t)lpszBuff)), MRA_FILES_NULL_ADDRR);
}
}
else {// ñîçäà¸ì ñïèñîê íàøèõ IP àäðåñîâ
BYTE btAddress[32];
DWORD dwSelfExternalIP;
size_t dwAdapter = 0;
hostent *sh;
dwSelfExternalIP = NTOHL(mraGetDword(NULL, "IP", 0));
if (dwSelfExternalIP) {
memmove(&btAddress, &dwSelfExternalIP, sizeof(DWORD));
lpszCurPos += mir_snprintf(lpszCurPos, (dwBuffSize-((size_t)lpszCurPos-(size_t)lpszBuff)), "%lu.%lu.%lu.%lu:%lu;", btAddress[0], btAddress[1], btAddress[2], btAddress[3], dwPort);
}
if (gethostname(szHostName, SIZEOF(szHostName)) == 0)
if ((sh = gethostbyname((LPSTR)&szHostName))) {
while (sh->h_addr_list[dwAdapter]) {
lpszCurPos += mir_snprintf(lpszCurPos, (dwBuffSize-((size_t)lpszCurPos-(size_t)lpszBuff)), "%s:%lu;", inet_ntoa(*((struct in_addr*)sh->h_addr_list[dwAdapter])), dwPort);
dwAdapter++;
}
}
}
if (mraGetByte(NULL, "FileSendAddExtraAddresses", MRA_DEF_FS_ADD_EXTRA_ADDRESSES))// äîáàâëÿåì ïðîèçâîëüíûé àäðåñ
if (mraGetStaticStringA(NULL, "FileSendExtraAddresses", szHostName, SIZEOF(szHostName), NULL))
lpszCurPos += mir_snprintf(lpszCurPos, (dwBuffSize-((size_t)lpszCurPos-(size_t)lpszBuff)), "%s:%lu;", szHostName, dwPort);
return lpszCurPos - lpszBuff;
}
DWORD CMraProto::MraFilesQueueAccept(HANDLE hFilesQueueHandle, DWORD dwIDRequest, LPCWSTR lpwszPath, size_t dwPathSize)
{
if ( !hFilesQueueHandle || !lpwszPath || !dwPathSize)
return ERROR_INVALID_HANDLE;
MRA_FILES_QUEUE *pmrafqFilesQueue = (MRA_FILES_QUEUE*)hFilesQueueHandle;
MRA_FILES_QUEUE_ITEM *dat;
mt_lock l(pmrafqFilesQueue);
DWORD dwRetErrorCode = MraFilesQueueItemFindByID(hFilesQueueHandle, dwIDRequest, &dat);
if (dwRetErrorCode == NO_ERROR) {
MRA_FILES_THREADPROC_PARAMS *pmftpp = (MRA_FILES_THREADPROC_PARAMS*)mir_calloc(sizeof(MRA_FILES_THREADPROC_PARAMS));
dat->lpwszPath = (LPWSTR)mir_calloc((dwPathSize*sizeof(WCHAR)));
dat->dwPathSize = dwPathSize;
memmove(dat->lpwszPath, lpwszPath, (dwPathSize*sizeof(WCHAR)));
if ( (*(WCHAR*)(dat->lpwszPath+(dat->dwPathSize-1))) != '\\')
{// add slash at the end if needed
(*(WCHAR*)(dat->lpwszPath+dat->dwPathSize)) = '\\';
dat->dwPathSize++;
(*(WCHAR*)(dat->lpwszPath+dat->dwPathSize)) = 0;
}
pmftpp->hFilesQueueHandle = hFilesQueueHandle;
pmftpp->dat = dat;
dat->hThread = ForkThreadEx(&CMraProto::MraFilesQueueRecvThreadProc, pmftpp);
}
return dwRetErrorCode;
}
DWORD CMraProto::MraFilesQueueCancel(HANDLE hFilesQueueHandle, DWORD dwIDRequest, BOOL bSendDecline)
{
if (!hFilesQueueHandle)
return ERROR_INVALID_HANDLE;
MRA_FILES_QUEUE *pmrafqFilesQueue = (MRA_FILES_QUEUE*)hFilesQueueHandle;
MRA_FILES_QUEUE_ITEM *dat;
mt_lock l(pmrafqFilesQueue);
DWORD dwRetErrorCode = MraFilesQueueItemFindByID(hFilesQueueHandle, dwIDRequest, &dat);
if (dwRetErrorCode == NO_ERROR) { //***deb closesocket, send message to thread
InterlockedExchange((volatile LONG*)&dat->bIsWorking, FALSE);
if (bSendDecline) {
CHAR szEMail[MAX_EMAIL_LEN];
size_t dwEMailSize;
if (mraGetStaticStringA(dat->hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize))
MraFileTransferAck(FILE_TRANSFER_STATUS_DECLINE, szEMail, dwEMailSize, dwIDRequest, NULL, 0);
}
MraMrimProxyCloseConnection(dat->hMraMrimProxyData);
Netlib_CloseHandle(dat->hListen);
dat->hListen = NULL;
Netlib_CloseHandle(dat->hConnection);
dat->hConnection = NULL;
SetEvent(dat->hWaitHandle);
if (dat->hThread == NULL)
MraFilesQueueItemFree(dat);
}
return dwRetErrorCode;
}
DWORD CMraProto::MraFilesQueueStartMrimProxy(HANDLE hFilesQueueHandle, DWORD dwIDRequest)
{
if (!hFilesQueueHandle || !mraGetByte(NULL, "FileSendEnableMRIMProxyCons", MRA_DEF_FS_ENABLE_MRIM_PROXY_CONS))
return ERROR_INVALID_HANDLE;
MRA_FILES_QUEUE *pmrafqFilesQueue = (MRA_FILES_QUEUE*)hFilesQueueHandle;
MRA_FILES_QUEUE_ITEM *dat;
mt_lock l(pmrafqFilesQueue);
if ( !MraFilesQueueItemFindByID(hFilesQueueHandle, dwIDRequest, &dat))
if (dat->bSending == FALSE)
SetEvent(dat->hWaitHandle);// cancel wait incomming connection
return 0;
}
DWORD MraFilesQueueFree(HANDLE hFilesQueueHandle, DWORD dwIDRequest)
{
if (!hFilesQueueHandle)
return ERROR_INVALID_HANDLE;
MRA_FILES_QUEUE *pmrafqFilesQueue = (MRA_FILES_QUEUE*)hFilesQueueHandle;
MRA_FILES_QUEUE_ITEM *dat;
LIST_MT_ITERATOR lmtiIterator;
mt_lock l(pmrafqFilesQueue);
ListMTIteratorMoveFirst(pmrafqFilesQueue, &lmtiIterator);
do {
if (ListMTIteratorGet(&lmtiIterator, NULL, (LPVOID*)&dat) == NO_ERROR)
if (dat->dwIDRequest == dwIDRequest) {
MraFilesQueueItemFree(dat);
return 0;
}
}
while (ListMTIteratorMoveNext(&lmtiIterator));
return ERROR_NOT_FOUND;
}
DWORD CMraProto::MraFilesQueueSendMirror(HANDLE hFilesQueueHandle, DWORD dwIDRequest, LPSTR lpszAddreses, size_t dwAddresesSize)
{
if (!hFilesQueueHandle)
return ERROR_INVALID_HANDLE;
MRA_FILES_QUEUE *pmrafqFilesQueue = (MRA_FILES_QUEUE*)hFilesQueueHandle;
MRA_FILES_QUEUE_ITEM *dat;
mt_lock l(pmrafqFilesQueue);
DWORD dwRetErrorCode = MraFilesQueueItemFindByID(hFilesQueueHandle, dwIDRequest, &dat);
if (dwRetErrorCode == NO_ERROR) {
MraAddrListGetFromBuff(lpszAddreses, dwAddresesSize, &dat->malAddrList);
MraAddrListStoreToContact(dat->hContact, &dat->malAddrList);
dat->hConnection = NULL;
SetEvent(dat->hWaitHandle);
}
return dwRetErrorCode;
}
BOOL CMraProto::MraFilesQueueHandCheck(HANDLE hConnection, MRA_FILES_QUEUE_ITEM *dat)
{
BOOL bRet = FALSE;
if (hConnection && dat)
{
CHAR szEMail[MAX_EMAIL_LEN] = {0}, szEMailMy[MAX_EMAIL_LEN] = {0};
BYTE btBuff[((MAX_EMAIL_LEN*2)+(sizeof(MRA_FT_HELLO)*2)+8)] = {0};
size_t dwEMailSize, dwEMailMySize, dwBuffSize;
mraGetStaticStringA(NULL, "e-mail", szEMailMy, SIZEOF(szEMailMy), &dwEMailMySize);BuffToLowerCase(szEMailMy, szEMailMy, dwEMailMySize);
mraGetStaticStringA(dat->hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize);BuffToLowerCase(szEMail, szEMail, dwEMailSize);
if (dat->bSending == FALSE)
{// receiving
dwBuffSize = mir_snprintf((LPSTR)btBuff, SIZEOF(btBuff), "%s %s", MRA_FT_HELLO, szEMailMy)+1;
if (dwBuffSize == Netlib_Send(hConnection, (LPSTR)btBuff, (int)dwBuffSize, 0))
{// my email sended
ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, (HANDLE)dat->dwIDRequest, 0);
dwBuffSize = Netlib_Recv(hConnection, (LPSTR)btBuff, sizeof(btBuff), 0);
if ((dwEMailSize+sizeof(MRA_FT_HELLO)+1) == dwBuffSize)
{// email received
mir_snprintf(((LPSTR)btBuff+dwBuffSize), (SIZEOF(btBuff)-dwBuffSize), "%s %s", MRA_FT_HELLO, szEMail);
if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, (LPSTR)btBuff, dwBuffSize, ((LPSTR)btBuff+dwBuffSize), dwBuffSize) == CSTR_EQUAL)
bRet = TRUE;
}
}
}else {// sending
dwBuffSize = Netlib_Recv(hConnection, (LPSTR)btBuff, sizeof(btBuff), 0);
if ((dwEMailSize+sizeof(MRA_FT_HELLO)+1) == dwBuffSize)
{// email received
ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, (HANDLE)dat->dwIDRequest, 0);
mir_snprintf(((LPSTR)btBuff+dwBuffSize), (SIZEOF(btBuff)-dwBuffSize), "%s %s", MRA_FT_HELLO, szEMail);
if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, (LPSTR)btBuff, dwBuffSize, ((LPSTR)btBuff+dwBuffSize), dwBuffSize) == CSTR_EQUAL)
{// email verified
dwBuffSize = (mir_snprintf((LPSTR)btBuff, SIZEOF(btBuff), "%s %s", MRA_FT_HELLO, szEMailMy)+1);
if (dwBuffSize == Netlib_Send(hConnection, (LPSTR)btBuff, dwBuffSize, 0))
{// my email sended
bRet = TRUE;
}
}
}
}
}
return bRet;
}
HANDLE CMraProto::MraFilesQueueConnectOut(MRA_FILES_QUEUE_ITEM *dat)
{
if (!dat)
return NULL;
if (mraGetByte(NULL, "FileSendEnableDirectConn", MRA_DEF_FS_ENABLE_DIRECT_CONN) && InterlockedExchangeAdd((volatile LONG*)&dat->bIsWorking, 0) && ((dat->bSending == FALSE && mraGetByte(NULL, "FileSendNoOutConnOnRcv", MRA_DEF_FS_NO_OUT_CONN_ON_RCV) == FALSE) || (dat->bSending == TRUE && mraGetByte(NULL, "FileSendNoOutConnOnSend", MRA_DEF_FS_NO_OUT_CONN_ON_SEND) == FALSE))) {
BOOL bFiltering = FALSE, bIsHTTPSProxyUsed = IsHTTPSProxyUsed(hNetlibUser);
DWORD dwLocalPort = 0, dwConnectReTryCount, dwCurConnectReTryCount;
size_t dwAddrCount;
NETLIBOPENCONNECTION nloc = {0};
if (mraGetByte(NULL, "FileSendIgnoryAdditionalPorts", MRA_DEF_FS_IGNORY_ADDITIONAL_PORTS) || bIsHTTPSProxyUsed)
{// ôèëüòðóåì ïîðòû äëÿ îäíîãî IP, âìåñòî 3 áóäåì êîííåêòèòñÿ òîëüêî ê îäíîìó
if (bIsHTTPSProxyUsed)
dwLocalPort = MRA_SERVER_PORT_HTTPS;
else if ((dwLocalPort = mraGetWord(NULL, "ServerPort", MRA_DEFAULT_SERVER_PORT)) == MRA_SERVER_PORT_STANDART_NLB)
dwLocalPort = MRA_SERVER_PORT_STANDART;
dwAddrCount = 0;
for (size_t i = 0; i < dat->malAddrList.dwAddrCount; i++) {
if (dwLocalPort == dat->malAddrList.pmaliAddress[i].dwPort) {
bFiltering = TRUE;
dwAddrCount++;
}
}
}
if (bFiltering == FALSE)
dwAddrCount = dat->malAddrList.dwAddrCount;
if (dwAddrCount) {
dat->hConnection = NULL;
dwConnectReTryCount = mraGetDword(NULL, "ConnectReTryCountFileSend", MRA_DEFAULT_CONN_RETRY_COUNT_FILES);
nloc.cbSize = sizeof(nloc);
nloc.flags = NLOCF_V2;
nloc.timeout = mraGetDword(NULL, "TimeOutConnectFileSend", ((MRA_TIMEOUT_DIRECT_CONN-1)/(dwAddrCount*dwConnectReTryCount)));// -1 ñåê ÷òîáû áûë çàïàñ
if (nloc.timeout<MRA_TIMEOUT_CONN_MIN) nloc.timeout = MRA_TIMEOUT_CONN_MIN;
if (nloc.timeout>MRA_TIMEOUT_CONN_ÌÀÕ) nloc.timeout = MRA_TIMEOUT_CONN_ÌÀÕ;
// Set up the sockaddr structure
for (size_t i = 0;i<dat->malAddrList.dwAddrCount;i++) {
if (dwLocalPort == dat->malAddrList.pmaliAddress[i].dwPort || bFiltering == FALSE) {
ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTING, (HANDLE)dat->dwIDRequest, 0);
nloc.szHost = inet_ntoa((*((in_addr*)&dat->malAddrList.pmaliAddress[i].dwAddr)));
nloc.wPort = (WORD)dat->malAddrList.pmaliAddress[i].dwPort;
dwCurConnectReTryCount = dwConnectReTryCount;
do {
dat->hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)hNetlibUser, (LPARAM)&nloc);
}
while (--dwCurConnectReTryCount && dat->hConnection == NULL);
if (dat->hConnection) {
ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, (HANDLE)dat->dwIDRequest, 0);
if (MraFilesQueueHandCheck(dat->hConnection, dat)) {
// ñâÿçü óñòàíîâëåííàÿ ñ òåì êåì íóæíî
mraSetDword(dat->hContact, "OldIP", mraGetDword(dat->hContact, "IP", 0));
mraSetDword(dat->hContact, "IP", HTONL(dat->malAddrList.pmaliAddress[i].dwAddr));
break;
}
else {
// êàæåòñÿ íå òóäà ïîäêëþ÷èëèñü :)
Netlib_CloseHandle(dat->hConnection);
dat->hConnection = NULL;
}
}
}
}
}
}
return dat->hConnection;
}
LPWSTR GetFileNameFromFullPathW(LPWSTR lpwszFullPath, size_t dwFullPathSize)
{
LPWSTR lpwszFileName = lpwszFullPath, lpwszCurPos;
lpwszCurPos = (lpwszFullPath+dwFullPathSize);
for (; lpwszCurPos>lpwszFullPath; lpwszCurPos--) {
if ((*lpwszCurPos) == '\\') {
lpwszFileName = (lpwszCurPos+1);
break;
}
}
return lpwszFileName;
}
HANDLE CMraProto::MraFilesQueueConnectIn(MRA_FILES_QUEUE_ITEM *dat)
{
if (!dat)
return NULL;
if ( !InterlockedExchangeAdd((volatile LONG*)&dat->bIsWorking, 0))
return NULL;
CHAR szEMail[MAX_EMAIL_LEN];
size_t dwEMailSize;
if (mraGetStaticStringA(dat->hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize)) {
CHAR szAddrList[2048] = {0};
size_t dwAddrListSize;
// êîïèðóåì àäðåñà â ñîîòâåòñòâèè ñ ïðàâèëàìè è íà÷èíàåì ñëóøàòü ïîðò
if (mraGetByte(NULL, "FileSendEnableDirectConn", MRA_DEF_FS_ENABLE_DIRECT_CONN)) {
NETLIBBIND nlbBind = {0};
nlbBind.cbSize = sizeof(nlbBind);
nlbBind.pfnNewConnectionV2 = MraFilesQueueConnectionReceived;
nlbBind.wPort = 0;
nlbBind.pExtra = (LPVOID)dat;
dat->hListen = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)hNetlibUser, (LPARAM)&nlbBind);
if (dat->hListen) {
ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_LISTENING, (HANDLE)dat->dwIDRequest, 0);
dwAddrListSize = MraFilesQueueGetLocalAddressesList(szAddrList, sizeof(szAddrList), nlbBind.wPort);
}
// íå ñìîãëè ñëóøàòü ïîðò, õç ïî÷åìó.
else {
ShowFormattedErrorMessage(L"Files exchange: cant create listen soscket, will try connect to remonte host. Error", GetLastError());
//dwAddrListSize = 0;
memmove(szAddrList, MRA_FILES_NULL_ADDRR, sizeof(MRA_FILES_NULL_ADDRR));
dwAddrListSize = (sizeof(MRA_FILES_NULL_ADDRR)-1);
}
}
// ïîäñòàâëÿåì ëîæíûé àäðåñ, ÷òîáû òî÷íî íå ïîäêëþ÷èëèñü è íå ñëóøàåì ïîðò
else {
memmove(szAddrList, MRA_FILES_NULL_ADDRR, sizeof(MRA_FILES_NULL_ADDRR));
dwAddrListSize = (sizeof(MRA_FILES_NULL_ADDRR)-1);
}
if (dwAddrListSize) {
dat->hWaitHandle = CreateEvent(NULL, TRUE, FALSE, NULL);
if (dat->bSending == FALSE) // çàïðàøèâàåì çåðêàëüíîå ñîåäèíåíèå, òê ñàìè ïîäêëþ÷èòñÿ íå ñìîãëè
MraFileTransferAck(FILE_TRANSFER_MIRROR, szEMail, dwEMailSize, dat->dwIDRequest, (LPBYTE)szAddrList, dwAddrListSize);
else { // çäåñü îòïðàâëÿåì çàïðîñ íà ïåðåäà÷ó(óñòàíîâëåíèå ñîåäèíåíèÿ)
// ñîçäà¸ì òåêñòîâûé ñïèñîê ôàéëîâ äëÿ îòïðàâêè äðóãîé ñòîðîíå
LPWSTR lpwszFiles, lpwszCurPos;
size_t dwFilesSize;
dwFilesSize = ((MAX_PATH*2)*dat->dwFilesCount);
lpwszFiles = (LPWSTR)mir_calloc((dwFilesSize*sizeof(WCHAR)));
if (lpwszFiles) {
lpwszCurPos = lpwszFiles;
for (size_t i = 0;i < dat->dwFilesCount;i++) {
MRA_FILES_QUEUE_FILE &p = dat->pmfqfFiles[i];
lpwszCurPos += mir_sntprintf(lpwszCurPos, (dwFilesSize-((size_t)lpwszCurPos-(size_t)lpwszFiles)), L"%s;%I64u;",
GetFileNameFromFullPathW(p.lpwszName, p.dwNameLen), p.dwSize);
}
dwFilesSize = (lpwszCurPos-lpwszFiles);// size in WCHARs
if (dat->hMraMrimProxyData) {
// óñòàíàâëèâàåì äàííûå äëÿ ìàéëîâñêîé ïðîêñè, åñëè îíà ðàçðåøåíà
LPSTR lpszFiles;
size_t dwFilesSizeA;
dwFilesSizeA = WideCharToMultiByte(MRA_CODE_PAGE, 0, lpwszFiles, dwFilesSize, NULL, 0, NULL, NULL);
lpszFiles = (LPSTR)mir_calloc((dwFilesSizeA+MAX_PATH));
if (lpszFiles) {
dwFilesSizeA = WideCharToMultiByte(MRA_CODE_PAGE, 0, lpwszFiles, dwFilesSize, lpszFiles, (dwFilesSizeA+MAX_PATH), NULL, NULL);
MraMrimProxySetData(dat->hMraMrimProxyData, szEMail, dwEMailSize, dat->dwIDRequest, MRIM_PROXY_TYPE_FILES, lpszFiles, dwFilesSizeA, NULL, 0, NULL);
mir_free(lpszFiles);
}
}
MraFileTransfer(szEMail, dwEMailSize, dat->dwIDRequest, dat->dwFilesTotalSize, lpwszFiles, dwFilesSize, szAddrList, dwAddrListSize);
mir_free(lpwszFiles);
}
}
WaitForSingleObjectEx(dat->hWaitHandle, INFINITE, FALSE);
CloseHandle(dat->hWaitHandle);
dat->hWaitHandle = NULL;
}
}
return dat->hConnection;
}
// This function is called from the Netlib when someone is connecting to
// one of our incomming DC ports
void MraFilesQueueConnectionReceived(HANDLE hNewConnection, DWORD dwRemoteIP, void *pExtra)
{
if (pExtra) {
MRA_FILES_QUEUE_ITEM *dat = (MRA_FILES_QUEUE_ITEM*)pExtra;
ProtoBroadcastAck(dat->ppro->m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, (HANDLE)dat->dwIDRequest, 0);
if ( dat->ppro->MraFilesQueueHandCheck(hNewConnection, dat)) { // ñâÿçü óñòàíîâëåííàÿ ñ òåì êåì íóæíî
dat->hConnection = hNewConnection;
ProtoBroadcastAck(dat->ppro->m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, (HANDLE)dat->dwIDRequest, 0);
dat->ppro->mraSetDword(dat->hContact, "OldIP", dat->ppro->mraGetDword(dat->hContact, "IP", 0));
dat->ppro->mraSetDword(dat->hContact, "IP", dwRemoteIP);
SetEvent(dat->hWaitHandle);
}else {// êàæåòñÿ êòî òî íå òóäà ïîäêëþ÷èëèñÿ :)
ProtoBroadcastAck(dat->ppro->m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_LISTENING, (HANDLE)dat->dwIDRequest, 0);
Netlib_CloseHandle(hNewConnection);
}
}
else Netlib_CloseHandle(hNewConnection);
}
/////////////////////////////////////////////////////////////////////////////////////////
// Receive files
DWORD CMraProto::MraFilesQueueAddReceive(HANDLE hFilesQueueHandle, DWORD dwFlags, HANDLE hContact, DWORD dwIDRequest, LPWSTR lpwszFiles, size_t dwFilesSize, LPSTR lpszAddreses, size_t dwAddresesSize)
{
if (!hFilesQueueHandle || !dwIDRequest)
return ERROR_INVALID_HANDLE;
MRA_FILES_QUEUE *pmrafqFilesQueue = (MRA_FILES_QUEUE*)hFilesQueueHandle;
MRA_FILES_QUEUE_ITEM *dat = (MRA_FILES_QUEUE_ITEM*)mir_calloc(sizeof(MRA_FILES_QUEUE_ITEM)+sizeof(LPSTR)+64);
if ( !dat)
return GetLastError();
WCHAR szBuff[MAX_PATH];
LPWSTR lpwszCurrentItem, lpwszDelimiter, lpwszEndItem;
size_t dwMemSize, dwAllocatedCount, dwFileNameTotalSize;
//dat->lmtListMTItem;
dat->ppro = this;
dat->bIsWorking = TRUE;
dat->dwSendTime = GetTickCount();
dat->dwIDRequest = dwIDRequest;
dat->dwFlags = dwFlags;
dat->hContact = hContact;
if (mraGetByte(NULL, "FileSendEnableMRIMProxyCons", MRA_DEF_FS_ENABLE_MRIM_PROXY_CONS))
dat->hMraMrimProxyData = MraMrimProxyCreate();
dwFileNameTotalSize = 0;
dwAllocatedCount = ALLOCATED_COUNT;
dat->dwFilesCount = 0;
dat->dwFilesTotalSize = 0;
dat->pmfqfFiles = (MRA_FILES_QUEUE_FILE*)mir_calloc((sizeof(MRA_FILES_QUEUE_FILE)*dwAllocatedCount));
lpwszCurrentItem = lpwszFiles;
while (TRUE) {
lpwszDelimiter = (LPWSTR)MemoryFind(((size_t)lpwszCurrentItem-(size_t)lpwszFiles), lpwszFiles, (dwFilesSize*sizeof(WCHAR)), ";", 2);
if (!lpwszDelimiter)
break;
lpwszEndItem = (LPWSTR)MemoryFind((((size_t)lpwszDelimiter+2)-(size_t)lpwszFiles), lpwszFiles, (dwFilesSize*sizeof(WCHAR)), ";", 2);
if (!lpwszEndItem)
break;
if (dat->dwFilesCount == dwAllocatedCount) {
dwAllocatedCount *= 2;
dat->pmfqfFiles = (MRA_FILES_QUEUE_FILE*)mir_realloc(dat->pmfqfFiles, (sizeof(MRA_FILES_QUEUE_FILE)*dwAllocatedCount));
}
MRA_FILES_QUEUE_FILE &p = dat->pmfqfFiles[dat->dwFilesCount];
*lpwszDelimiter++ = 0;
p.lpwszName = mir_wstrdup(lpwszCurrentItem);
p.dwNameLen = lstrlen(p.lpwszName);
p.dwSize = StrToUNum64((LPSTR)lpwszDelimiter, (size_t)lpwszEndItem-(size_t)lpwszDelimiter+1);
dat->dwFilesTotalSize += p.dwSize;
dwFileNameTotalSize += p.dwNameLen * sizeof(TCHAR);
dat->dwFilesCount++;
lpwszCurrentItem = lpwszEndItem+1;
}
dat->pmfqfFiles = (MRA_FILES_QUEUE_FILE*)mir_realloc(dat->pmfqfFiles, (sizeof(MRA_FILES_QUEUE_FILE)*(dat->dwFilesCount+4)));
dwMemSize = (((dat->dwFilesCount+4)*64)+(dwFileNameTotalSize*sizeof(WCHAR))+(dwAddresesSize*sizeof(WCHAR))+128);
dat->pwszFilesList = (LPWSTR)mir_calloc(dwMemSize);
dat->pwszDescription = (LPWSTR)mir_calloc(dwMemSize);
lpwszDelimiter = dat->pwszFilesList;
lpwszCurrentItem = dat->pwszDescription;
StrFormatByteSizeW(dat->dwFilesTotalSize, szBuff, SIZEOF(szBuff));
lpwszCurrentItem += mir_sntprintf(lpwszCurrentItem, ((dwMemSize-((size_t)lpwszCurrentItem-(size_t)dat->pwszDescription))/sizeof(WCHAR)), L"%I64u Files (%s)\r\n", dat->dwFilesCount, szBuff);
// description + filesnames
for (size_t i = 0; i < dat->dwFilesCount; i++) {
lpwszDelimiter += mir_sntprintf(lpwszDelimiter, ((dwMemSize-((size_t)lpwszDelimiter-(size_t)dat->pwszFilesList))/sizeof(WCHAR)), L"%s", dat->pmfqfFiles[i].lpwszName);
StrFormatByteSizeW(dat->pmfqfFiles[i].dwSize, szBuff, SIZEOF(szBuff));
lpwszCurrentItem += mir_sntprintf(lpwszCurrentItem, ((dwMemSize-((size_t)lpwszCurrentItem-(size_t)dat->pwszDescription))/sizeof(WCHAR)), L"%s - %s\r\n", dat->pmfqfFiles[i].lpwszName, szBuff);
}
lpwszCurrentItem += MultiByteToWideChar(MRA_CODE_PAGE, 0, lpszAddreses, dwAddresesSize, lpwszCurrentItem, ((dwMemSize-((size_t)lpwszCurrentItem-(size_t)dat->pwszDescription))/sizeof(WCHAR)));
*lpwszCurrentItem = 0;
MraAddrListGetFromBuff(lpszAddreses, dwAddresesSize, &dat->malAddrList);
MraAddrListStoreToContact(dat->hContact, &dat->malAddrList);
{
mt_lock l(pmrafqFilesQueue);
ListMTItemAdd(pmrafqFilesQueue, dat, dat);
}
// Send chain event
PROTORECVFILET prf;
prf.flags = PREF_UNICODE;
prf.timestamp = _time32(NULL);
prf.tszDescription = dat->pwszDescription;
prf.fileCount = 1;//dat->dwFilesCount;
prf.ptszFiles = &dat->pwszFilesList;
prf.lParam = dwIDRequest;
CCSDATA ccs;
ccs.szProtoService = PSR_FILE;
ccs.hContact = hContact;
ccs.wParam = 0;
ccs.lParam = (LPARAM)&prf;
CallService(MS_PROTO_CHAINRECV, 0, (LPARAM)&ccs);
return NO_ERROR;
}
void CMraProto::MraFilesQueueRecvThreadProc(LPVOID lpParameter)
{
DWORD dwRetErrorCode = NO_ERROR;
if (lpParameter)
{
MRA_FILES_QUEUE *pmrafqFilesQueue = (MRA_FILES_QUEUE*)((MRA_FILES_THREADPROC_PARAMS*)lpParameter)->hFilesQueueHandle;
MRA_FILES_QUEUE_ITEM *dat = ((MRA_FILES_THREADPROC_PARAMS*)lpParameter)->dat;
WCHAR wszFileName[MAX_FILEPATH] = {0};
WCHAR szErrorText[2048];
BYTE btBuff[BUFF_SIZE_RCV];
BOOL bContinue, bFailed, bOK, bConnected;
DWORD dwReceived, dwUpdateTimeNext, dwUpdateTimeCur;
HANDLE hFile;
size_t i, dwBuffSizeUsed;
LARGE_INTEGER liFileSize;
NETLIBSELECT nls = {0};
PROTOFILETRANSFERSTATUS pfts = {0};
mir_free(lpParameter);
bFailed = TRUE;
bConnected = FALSE;
nls.cbSize = sizeof(nls);
pfts.cbSize = sizeof(pfts);
pfts.hContact = dat->hContact;
pfts.flags = (PFTS_RECEIVING|PFTS_UNICODE);// pfts.sending = dat->bSending; //true if sending, false if receiving
//pfts.files;
pfts.totalFiles = dat->dwFilesCount;
//pfts.currentFileNumber = 0;
pfts.totalBytes = dat->dwFilesTotalSize;
//pfts.totalProgress = 0;
pfts.wszWorkingDir = dat->lpwszPath;
//pfts.currentFile;
//pfts.currentFileSize;
//pfts.currentFileProgress;
//pfts.currentFileTime; //as seconds since 1970
if (MraFilesQueueConnectOut(dat))
{
bConnected = TRUE;
}else {
if (MraFilesQueueConnectIn(dat))
{
bConnected = TRUE;
}else {
if (InterlockedExchangeAdd((volatile LONG*)&dat->bIsWorking, 0))
{
ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKRESULT_CONNECTPROXY, ACKRESULT_CONNECTED, (HANDLE)dat->dwIDRequest, 0);
if (MraMrimProxyConnect(dat->hMraMrimProxyData, &dat->hConnection) == NO_ERROR)
{// ïîäêëþ÷èëèñü ê ïðîêñè, ïðîâåðÿåì òà ëè ñåññèÿ (åù¸ ðàç, íà ýòîò ðàç ñàìè)
if (MraFilesQueueHandCheck(dat->hConnection, dat))
{// ñâÿçü óñòàíîâëåííàÿ ñ òåì êåì íóæíî// dat->bSending
ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, (HANDLE)dat->dwIDRequest, 0);
bConnected = TRUE;
}
}
}
}
}
if (bConnected)
{// email verified
bFailed = FALSE;
for (i = 0;i<dat->dwFilesCount;i++)
{// receiving files
pfts.currentFileNumber = i;
pfts.wszCurrentFile = wszFileName;
pfts.currentFileSize = dat->pmfqfFiles[i].dwSize;
pfts.currentFileProgress = 0;
//pfts.currentFileTime; //as seconds since 1970
if ((dat->dwPathSize+dat->pmfqfFiles[i].dwNameLen)<SIZEOF(wszFileName))
{
memmove(wszFileName, dat->lpwszPath, (dat->dwPathSize*sizeof(WCHAR)));
memmove((wszFileName+dat->dwPathSize), dat->pmfqfFiles[i].lpwszName, ((dat->pmfqfFiles[i].dwNameLen+1)*sizeof(WCHAR)));
wszFileName[dat->dwPathSize+dat->pmfqfFiles[i].dwNameLen] = 0;
}else {
dwRetErrorCode = ERROR_BAD_PATHNAME;
ShowFormattedErrorMessage(L"Receive files: error", dwRetErrorCode);
bFailed = TRUE;
break;
}
//***deb add
//dwBuffSizeUsed = ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_FILERESUME, (HANDLE)dat->dwIDRequest, (LPARAM)&pfts);
ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, (HANDLE)dat->dwIDRequest, 0);
//dwBuffSizeUsed = (mir_snprintf((LPSTR)btBuff, SIZEOF(btBuff), "%s %S", MRA_FT_GET_FILE, dat->pmfqfFiles[i].lpwszName)+1);
memmove(btBuff, MRA_FT_GET_FILE, sizeof(MRA_FT_GET_FILE));
btBuff[(sizeof(MRA_FT_GET_FILE)-1)] = ' ';
dwBuffSizeUsed = sizeof(MRA_FT_GET_FILE)+WideCharToMultiByte(MRA_CODE_PAGE, 0, dat->pmfqfFiles[i].lpwszName, dat->pmfqfFiles[i].dwNameLen, (LPSTR)(btBuff+sizeof(MRA_FT_GET_FILE)), (SIZEOF(btBuff)-sizeof(MRA_FT_GET_FILE)), NULL, NULL);
btBuff[dwBuffSizeUsed] = 0;
dwBuffSizeUsed++;
if (dwBuffSizeUsed == Netlib_Send(dat->hConnection, (LPSTR)btBuff, dwBuffSizeUsed, 0))
{// file request sended
hFile = CreateFileW(wszFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{// file opened/created, pre allocating disk space, for best perfomance
bOK = FALSE;
liFileSize.QuadPart = (LONGLONG)dat->pmfqfFiles[i].dwSize;
if (SetFilePointerEx(hFile, liFileSize, NULL, FILE_BEGIN))
if (SetEndOfFile(hFile))
{
liFileSize.QuadPart = 0;
bOK = SetFilePointerEx(hFile, liFileSize, NULL, FILE_BEGIN);
}
if (bOK)
{// disk space pre allocated
bOK = FALSE;
bContinue = TRUE;
dwUpdateTimeNext = GetTickCount();
nls.dwTimeout = (1000*mraGetDword(NULL, "TimeOutReceiveFileData", MRA_DEF_FS_TIMEOUT_RECV));
nls.hReadConns[0] = dat->hConnection;
ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)dat->dwIDRequest, (LPARAM)&pfts);
while (bContinue)
{
switch (CallService(MS_NETLIB_SELECT, 0, (LPARAM)&nls)) {
case SOCKET_ERROR:
case 0:// Time out
dwRetErrorCode = GetLastError();
ShowFormattedErrorMessage(L"Receive files: error on receive file data", dwRetErrorCode);
bContinue = FALSE;
break;
case 1:
dwReceived = Netlib_Recv(dat->hConnection, (LPSTR)&btBuff, SIZEOF(btBuff), 0);
if (dwReceived == 0 || dwReceived == SOCKET_ERROR)
{
dwRetErrorCode = GetLastError();
ShowFormattedErrorMessage(L"Receive files: error on receive file data", dwRetErrorCode);
bContinue = FALSE;
}else {
if (WriteFile(hFile, (LPVOID)&btBuff, dwReceived, &dwReceived, NULL))
{
pfts.currentFileProgress += dwReceived;
pfts.totalProgress += dwReceived;
// progress updates
dwUpdateTimeCur = GetTickCount();
if (dwUpdateTimeNext <= dwUpdateTimeCur || pfts.currentFileProgress >= dat->pmfqfFiles[i].dwSize)
{// we update it
dwUpdateTimeNext = dwUpdateTimeCur+MRA_FILES_QUEUE_PROGRESS_INTERVAL;
ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)dat->dwIDRequest, (LPARAM)&pfts);
if (pfts.currentFileProgress >= dat->pmfqfFiles[i].dwSize)
{// file received
bOK = TRUE;
bContinue = FALSE;
}
}
}else {// err on write file
dwRetErrorCode = GetLastError();
ShowFormattedErrorMessage(L"Receive files: cant write file data, error", dwRetErrorCode);
bContinue = FALSE;
}
}
break;
}
}// end while
}else {// err allocating file disk space
dwRetErrorCode = GetLastError();
mir_sntprintf(szErrorText, SIZEOF(szErrorText), TranslateW(L"Receive files: cant allocate disk space for file, size %lu bytes, error"), dat->pmfqfFiles[i].dwSize);
ShowFormattedErrorMessage(szErrorText, dwRetErrorCode);
}
CloseHandle(hFile);
if (bOK == FALSE)
{// file recv failed
DeleteFileW(wszFileName);
bFailed = TRUE;
break;
}
}else {// err on open file
dwRetErrorCode = GetLastError();
mir_sntprintf(szErrorText, SIZEOF(szErrorText), TranslateW(L"Receive files: cant open file %s, error"), wszFileName);
ShowFormattedErrorMessage(szErrorText, dwRetErrorCode);
bFailed = TRUE;
break;
}
}else {// err on send request for file
dwRetErrorCode = GetLastError();
mir_sntprintf(szErrorText, SIZEOF(szErrorText), TranslateW(L"Receive files: request for file %s not sended, error"), dat->pmfqfFiles[i].lpwszName);
ShowFormattedErrorMessage(szErrorText, NO_ERROR);
bFailed = TRUE;
break;
}
}// end for
Netlib_CloseHandle(dat->hConnection);
dat->hConnection = NULL;
}
if (bFailed) {
CHAR szEMail[MAX_EMAIL_LEN];
size_t dwEMailSize;
if (mraGetStaticStringA(dat->hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize))
MraFileTransferAck(FILE_TRANSFER_STATUS_ERROR, szEMail, dwEMailSize, dat->dwIDRequest, NULL, 0);
ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)dat->dwIDRequest, 0);
}
else ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, (HANDLE)dat->dwIDRequest, 0);
mt_lock l(pmrafqFilesQueue);
MraFilesQueueItemFree(dat);
}
}
/////////////////////////////////////////////////////////////////////////////////////////
// Send files
DWORD CMraProto::MraFilesQueueAddSend(HANDLE hFilesQueueHandle, DWORD dwFlags, HANDLE hContact, LPWSTR *plpwszFiles, size_t dwFilesCount, DWORD *pdwIDRequest)
{
if ( !hFilesQueueHandle)
return ERROR_INVALID_HANDLE;
MRA_FILES_QUEUE *pmrafqFilesQueue = (MRA_FILES_QUEUE*)hFilesQueueHandle;
MRA_FILES_QUEUE_ITEM *dat = (MRA_FILES_QUEUE_ITEM*)mir_calloc(sizeof(MRA_FILES_QUEUE_ITEM)+sizeof(LPSTR)+64);
if ( !dat)
return GetLastError();
ULARGE_INTEGER uliFileSize;
WIN32_FILE_ATTRIBUTE_DATA wfad;
dat->ppro = this;
dat->bIsWorking = TRUE;
dat->dwSendTime = GetTickCount();
dat->dwIDRequest = InterlockedIncrement((LONG volatile*)&dwCMDNum);// óíèêàëüíûé, ðàíäîìíûé èäåíòèôèêàòîð
dat->dwFlags = dwFlags;
dat->hContact = hContact;
if (mraGetByte(NULL, "FileSendEnableMRIMProxyCons", MRA_DEF_FS_ENABLE_MRIM_PROXY_CONS)) dat->hMraMrimProxyData = MraMrimProxyCreate();
dat->dwFilesCount = dwFilesCount;
dat->pmfqfFiles = (MRA_FILES_QUEUE_FILE*)mir_calloc((sizeof(MRA_FILES_QUEUE_FILE)*(dat->dwFilesCount+1)));
dat->dwFilesTotalSize = 0;
for (size_t i = 0; i < dat->dwFilesCount; i++) {
MRA_FILES_QUEUE_FILE &p = dat->pmfqfFiles[i];
if (GetFileAttributesExW(plpwszFiles[i], GetFileExInfoStandard, &wfad)) {
uliFileSize.LowPart = wfad.nFileSizeLow;
uliFileSize.HighPart = wfad.nFileSizeHigh;
p.dwSize = uliFileSize.QuadPart;
dat->dwFilesTotalSize += uliFileSize.QuadPart;
}
else p.dwSize = 0;
p.dwNameLen = lstrlenW(plpwszFiles[i]);
p.lpwszName = mir_wstrdup(plpwszFiles[i]);
}
dat->bSending = TRUE;
if (pdwIDRequest) *pdwIDRequest = dat->dwIDRequest;
{
mt_lock l(pmrafqFilesQueue);
ListMTItemAdd(pmrafqFilesQueue, dat, dat);
}
MRA_FILES_THREADPROC_PARAMS *pmftpp = (MRA_FILES_THREADPROC_PARAMS*)mir_calloc(sizeof(MRA_FILES_THREADPROC_PARAMS));
pmftpp->hFilesQueueHandle = hFilesQueueHandle;
pmftpp->dat = dat;
dat->hThread = ForkThreadEx(&CMraProto::MraFilesQueueSendThreadProc, pmftpp);
return NO_ERROR;
}
void CMraProto::MraFilesQueueSendThreadProc(LPVOID lpParameter)
{
DWORD dwRetErrorCode = NO_ERROR;
if ( !lpParameter)
return;
MRA_FILES_QUEUE *pmrafqFilesQueue = (MRA_FILES_QUEUE*)((MRA_FILES_THREADPROC_PARAMS*)lpParameter)->hFilesQueueHandle;
MRA_FILES_QUEUE_ITEM *dat = ((MRA_FILES_THREADPROC_PARAMS*)lpParameter)->dat;
mir_free(lpParameter);
CHAR szFileName[MAX_FILEPATH] = {0};
WCHAR szErrorText[2048];
BYTE btBuff[BUFF_SIZE_RCV];
BOOL bFailed = TRUE, bOK, bConnected = FALSE;
DWORD dwReceived, dwSendBlockSize, dwUpdateTimeNext, dwUpdateTimeCur;
size_t i, j, dwBuffSizeUsed = 0;
LPWSTR lpwszFileName;
PROTOFILETRANSFERSTATUS pfts = {0};
pfts.cbSize = sizeof(pfts);
pfts.hContact = dat->hContact;
pfts.flags = (PFTS_SENDING|PFTS_UNICODE);// pfts.sending = dat->bSending; //true if sending, false if receiving
pfts.totalFiles = dat->dwFilesCount;
pfts.totalBytes = dat->dwFilesTotalSize;
pfts.wszWorkingDir = dat->lpwszPath;
dwSendBlockSize = mraGetDword(NULL, "FileSendBlockSize", MRA_DEFAULT_FILE_SEND_BLOCK_SIZE);
if (dwSendBlockSize>SIZEOF(btBuff)) dwSendBlockSize = SIZEOF(btBuff);
if (dwSendBlockSize<512) dwSendBlockSize = MRA_DEFAULT_FILE_SEND_BLOCK_SIZE;
if (MraFilesQueueConnectIn(dat))
bConnected = TRUE;
else if (MraFilesQueueConnectOut(dat))
bConnected = TRUE;
else {
if (InterlockedExchangeAdd((volatile LONG*)&dat->bIsWorking, 0)) {
ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKRESULT_CONNECTPROXY, ACKRESULT_CONNECTED, (HANDLE)dat->dwIDRequest, 0);
if (MraMrimProxyConnect(dat->hMraMrimProxyData, &dat->hConnection) == NO_ERROR) {
// ïîäêëþ÷èëèñü ê ïðîêñè, ïðîâåðÿåì òà ëè ñåññèÿ (åù¸ ðàç, íà ýòîò ðàç ñàìè)
if (MraFilesQueueHandCheck(dat->hConnection, dat)) {
// ñâÿçü óñòàíîâëåííàÿ ñ òåì êåì íóæíî// dat->bSending
ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, (HANDLE)dat->dwIDRequest, 0);
bConnected = TRUE;
}
}
}
}
if (bConnected) { // email verified
bFailed = FALSE;
for (i = 0; i < dat->dwFilesCount; i++) { // sending files
ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, (HANDLE)dat->dwIDRequest, 0);
dwBuffSizeUsed = 0;
while (TRUE) {
dwReceived = Netlib_Recv(dat->hConnection, ((LPSTR)btBuff+dwBuffSizeUsed), (SIZEOF(btBuff)-dwBuffSizeUsed), 0);
if (dwReceived == 0 || dwReceived == SOCKET_ERROR) { // err on receive file name to send
dwRetErrorCode = GetLastError();
ShowFormattedErrorMessage(L"Send files: file send request not received, error", dwRetErrorCode);
bFailed = TRUE;
break;
}
else {
dwBuffSizeUsed += dwReceived;
if (MemoryFindByte((dwBuffSizeUsed-dwReceived), btBuff, dwBuffSizeUsed, 0))
break;
}
}// end while (file name passible received)*/
if (bFailed)
break;
// ...received
if (dwBuffSizeUsed > (sizeof(MRA_FT_GET_FILE)+1)) {// file name received
if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, (LPSTR)btBuff, (sizeof(MRA_FT_GET_FILE)-1), MRA_FT_GET_FILE, (sizeof(MRA_FT_GET_FILE)-1)) == CSTR_EQUAL) {
// MRA_FT_GET_FILE verified
bFailed = TRUE;
for (j = 0;j<dat->dwFilesCount;j++) {
lpwszFileName = GetFileNameFromFullPathW(dat->pmfqfFiles[j].lpwszName, dat->pmfqfFiles[j].dwNameLen);
szFileName[WideCharToMultiByte(MRA_CODE_PAGE, 0, lpwszFileName, (dat->pmfqfFiles[j].dwNameLen-(lpwszFileName-dat->pmfqfFiles[j].lpwszName)), szFileName, SIZEOF(szFileName), NULL, NULL)] = 0;
if (CompareStringA( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, (((LPSTR)btBuff)+sizeof(MRA_FT_GET_FILE)), (dwBuffSizeUsed-(sizeof(MRA_FT_GET_FILE)+1)), szFileName, -1) == CSTR_EQUAL) {
bFailed = FALSE;
break;
}
}
if (bFailed == FALSE) {
HANDLE hFile = CreateFileW(dat->pmfqfFiles[j].lpwszName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, (FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN), NULL);
if (hFile != INVALID_HANDLE_VALUE) {
bOK = FALSE;
dwUpdateTimeNext = GetTickCount();
pfts.currentFileNumber = i;
pfts.wszCurrentFile = dat->pmfqfFiles[j].lpwszName;
pfts.currentFileSize = dat->pmfqfFiles[j].dwSize;
pfts.currentFileProgress = 0;
//pfts.currentFileTime; //as seconds since 1970
WideCharToMultiByte(MRA_CODE_PAGE, 0, dat->pmfqfFiles[j].lpwszName, dat->pmfqfFiles[j].dwNameLen, szFileName, SIZEOF(szFileName), NULL, NULL);
ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)dat->dwIDRequest, (LPARAM)&pfts);
while (TRUE) { // read and sending
if (ReadFile(hFile, btBuff, dwSendBlockSize, (DWORD*)&dwBuffSizeUsed, NULL)) {
dwReceived = Netlib_Send(dat->hConnection, (LPSTR)btBuff, dwBuffSizeUsed, 0);
if (dwBuffSizeUsed == dwReceived) {
pfts.currentFileProgress += dwBuffSizeUsed;
pfts.totalProgress += dwBuffSizeUsed;
// progress updates
dwUpdateTimeCur = GetTickCount();
if (dwUpdateTimeNext <= dwUpdateTimeCur || pfts.currentFileProgress >= dat->pmfqfFiles[j].dwSize) { // we update it
dwUpdateTimeNext = dwUpdateTimeCur+MRA_FILES_QUEUE_PROGRESS_INTERVAL;
ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_DATA, (HANDLE)dat->dwIDRequest, (LPARAM)&pfts);
if (pfts.currentFileProgress >= dat->pmfqfFiles[j].dwSize) { // file received
bOK = TRUE;
break;
}
}
}
else { // err on send file data
dwRetErrorCode = GetLastError();
ShowFormattedErrorMessage(L"Send files: error on send file data", dwRetErrorCode);
break;
}
}
else {// read failure
dwRetErrorCode = GetLastError();
ShowFormattedErrorMessage(L"Send files: cant read file data, error", dwRetErrorCode);
break;
}
}// end while
CloseHandle(hFile);
if (bOK == FALSE) { // file recv failed
bFailed = TRUE;
break;
}
}
else {// err on open file
dwRetErrorCode = GetLastError();
mir_sntprintf(szErrorText, SIZEOF(szErrorText), TranslateW(L"Send files: cant open file %s, error"), dat->pmfqfFiles[j].lpwszName);
ShowFormattedErrorMessage(szErrorText, dwRetErrorCode);
bFailed = TRUE;
break;
}
}
else {
mir_sntprintf(szErrorText, SIZEOF(szErrorText), TranslateW(L"Send files: requested file: %S - not found in send files list."), (((LPSTR)btBuff)+sizeof(MRA_FT_GET_FILE)));
ShowFormattedErrorMessage(szErrorText, NO_ERROR);
bFailed = TRUE;
break;
}
}
else {// err on receive, trash
ShowFormattedErrorMessage(L"Send files: bad file send request - invalid header", NO_ERROR);
bFailed = TRUE;
break;
}
}
else {// bad file name or trash
ShowFormattedErrorMessage(L"Send files: bad file send request - to small packet", NO_ERROR);
bFailed = TRUE;
break;
}
}// end for
Netlib_CloseHandle(dat->hConnection);
dat->hConnection = NULL;
}
if (bFailed) {
CHAR szEMail[MAX_EMAIL_LEN];
size_t dwEMailSize;
if (mraGetStaticStringA(dat->hContact, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize))
MraFileTransferAck(FILE_TRANSFER_STATUS_ERROR, szEMail, dwEMailSize, dat->dwIDRequest, NULL, 0);
ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)dat->dwIDRequest, 0);
}
else ProtoBroadcastAck(m_szModuleName, dat->hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, (HANDLE)dat->dwIDRequest, 0);
mt_lock l(pmrafqFilesQueue);
MraFilesQueueItemFree(dat);
}
|