-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswf_clipboard.c
128 lines (95 loc) · 3.59 KB
/
swf_clipboard.c
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
#include "swf_clipboard.h"
UINT cliprdr_send_capabilities(CliprdrClientContext* clipboard) {
CLIPRDR_GENERAL_CAPABILITY_SET cap_set = {
.capabilitySetType = CB_CAPSTYPE_GENERAL, /* CLIPRDR specification requires that this is CB_CAPSTYPE_GENERAL, the only defined set type */
.capabilitySetLength = 12, /* The size of the capability set within the PDU - for CB_CAPSTYPE_GENERAL, this is ALWAYS 12 bytes */
.version = CB_CAPS_VERSION_2, /* The version of the CLIPRDR specification supported */
.generalFlags = CB_USE_LONG_FORMAT_NAMES /* Bitwise OR of all supported feature flags */
};
CLIPRDR_CAPABILITIES caps = {
.cCapabilitiesSets = 1,
.capabilitySets = (CLIPRDR_CAPABILITY_SET*)&cap_set
};
return clipboard->ClientCapabilities(clipboard, &caps);
}
UINT cliprdr_send_format_list(CliprdrClientContext* cliprdr) {
CLIPRDR_FORMAT_LIST format_list = {
.formats = (CLIPRDR_FORMAT[]) {
{.formatId = CF_TEXT },
{ .formatId = CF_UNICODETEXT }
},
.numFormats = 2
};
return cliprdr->ClientFormatList(cliprdr, &format_list);
}
UINT cliprdr_send_format_data_request(CliprdrClientContext* cliprdr, UINT32 format) {
CLIPRDR_FORMAT_LIST_RESPONSE format_list_response = {
.msgFlags = CB_RESPONSE_OK
};
/* Report successful processing of format list */
cliprdr->ClientFormatListResponse(cliprdr, &format_list_response);
}
UINT swf_cliprdr_monitor_ready(CliprdrClientContext* context,
CLIPRDR_MONITOR_READY* monitorReady)
{
UINT rc = ERROR_INTERNAL_ERROR;
swfClipboard* clipboard = (swfClipboard*)context->custom;
if (!context || !monitorReady)
return ERROR_INTERNAL_ERROR;
rc = cliprdr_send_capabilities(context);
if (rc != CHANNEL_RC_OK)
return rc;
return cliprdr_send_format_list(context);
}
UINT swf_cliprdr_server_format_data_request(CliprdrClientContext* context, CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest) {
UINT rc = CHANNEL_RC_OK;
HANDLE hClipdata;
swfContext * swfContxt = (swfContext *)context->custom;
UINT32 requestedFormatId = formatDataRequest->requestedFormatId;
CLIPRDR_FORMAT_DATA_RESPONSE response;
size_t size = 0;
char* globlemem = NULL;
void* buff = NULL;
if (!OpenClipboard(swfContxt->hwnd))
return ERROR_INTERNAL_ERROR;
hClipdata = GetClipboardData(requestedFormatId);
if (!hClipdata)
{
CloseClipboard();
return ERROR_INTERNAL_ERROR;
}
globlemem = (char*)GlobalLock(hClipdata);
size = (int)GlobalSize(hClipdata);
buff = malloc(size);
CopyMemory(buff, globlemem, size);
GlobalUnlock(hClipdata);
CloseClipboard();
response.msgFlags = CB_RESPONSE_OK;
response.dataLen = size;
response.requestedFormatData = (BYTE*)buff;
rc = context->ClientFormatDataResponse(context,&response);
free(buff);
return rc;
}
UINT swf_cliprdr_server_format_data_response(CliprdrClientContext* context,CLIPRDR_FORMAT_DATA_RESPONSE* format_data_response) {
return CHANNEL_RC_OK;
}
UINT swf_cliprdr_server_format_list(CliprdrClientContext* context,CLIPRDR_FORMAT_LIST* formatList) {
UINT rc = CHANNEL_RC_OK;
return rc;
}
BOOL swf_cliprdr_init(swfContext* swfc, CliprdrClientContext* cliprdr) {
swfClipboard * clipboard = (swfClipboard*)calloc(1, sizeof(swfClipboard));
clipboard->context = cliprdr;
swfc->clipboard = clipboard;
cliprdr->custom = clipboard;
cliprdr->MonitorReady = swf_cliprdr_monitor_ready;
//cliprdr->ServerFormatList = swf_cliprdr_server_format_list;
cliprdr->ServerFormatDataRequest = swf_cliprdr_server_format_data_request;
cliprdr->ServerFormatDataResponse = swf_cliprdr_server_format_data_response;
return TRUE;
}
void swf_cliprdr_uninit(swfContext* swfc, CliprdrClientContext* cliprdr) {
swfc->clipboard = NULL;
cliprdr->custom = NULL;
}