1 |
twoaday |
2 |
/* clip.c |
2 |
|
|
* Copyright (C) 2001, 2002, 2003 Timo Schulz |
3 |
|
|
* |
4 |
|
|
* This file is part of MyGPGME. |
5 |
|
|
* |
6 |
|
|
* MyGPGME is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* MyGPGME is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
|
22 |
|
|
#include <windows.h> |
23 |
|
|
|
24 |
|
|
#include "gpgme.h" |
25 |
|
|
#include "util.h" |
26 |
|
|
|
27 |
|
|
|
28 |
|
|
gpgme_error_t |
29 |
|
|
gpgme_clip_istext_avail( int *r_rc ) |
30 |
|
|
{ |
31 |
|
|
HANDLE clipmem; |
32 |
|
|
char *clipdata; |
33 |
|
|
|
34 |
|
|
if( !r_rc ) |
35 |
|
|
return mk_error( Invalid_Value ); |
36 |
|
|
if( OpenClipboard( NULL ) == FALSE ) |
37 |
|
|
return mk_error( Clip_Open ); |
38 |
|
|
|
39 |
|
|
clipmem = GetClipboardData( CF_TEXT ); |
40 |
|
|
if( !clipmem ) { |
41 |
|
|
*r_rc = 0; |
42 |
|
|
goto leave; |
43 |
|
|
} |
44 |
|
|
clipdata = (char *) GlobalLock( clipmem ); |
45 |
|
|
if( !clipdata ) { |
46 |
|
|
*r_rc = 0; |
47 |
|
|
goto leave; |
48 |
|
|
} |
49 |
|
|
if( strlen( clipdata ) ) |
50 |
|
|
*r_rc = 1; |
51 |
|
|
GlobalUnlock( clipmem ); |
52 |
|
|
|
53 |
|
|
leave: |
54 |
|
|
CloseClipboard(); |
55 |
|
|
return 0; |
56 |
|
|
} /* gpgme_clip_istext_avail */ |
57 |
|
|
|
58 |
|
|
|
59 |
|
|
gpgme_error_t |
60 |
twoaday |
17 |
gpgme_clip_parse_pgpid (const char * data, gpgme_pgptype_t * r_type) |
61 |
twoaday |
2 |
{ |
62 |
twoaday |
17 |
gpgme_pgptype_t type; |
63 |
twoaday |
2 |
|
64 |
|
|
if( !data ) |
65 |
|
|
return mk_error( Invalid_Value ); |
66 |
|
|
if( strlen( data ) < 19 ) { |
67 |
|
|
*r_type = 0; |
68 |
|
|
return 0; |
69 |
|
|
} |
70 |
|
|
type = 0; |
71 |
|
|
if( strstr( data, "BEGIN PGP MESSAGE") ) |
72 |
twoaday |
17 |
type |= GPGME_PGP_MESSAGE; |
73 |
twoaday |
2 |
if( strstr( data, "BEGIN PGP SIGNED MESSAGE" ) ) |
74 |
twoaday |
17 |
type |= GPGME_PGP_CLEARSIG; |
75 |
twoaday |
2 |
if( strstr( data, "BEGIN PGP SIGNATURE" ) ) |
76 |
twoaday |
17 |
type |= GPGME_PGP_SIG; |
77 |
twoaday |
2 |
if( strstr( data, "BEGIN PGP PUBLIC KEY BLOCK" ) ) |
78 |
twoaday |
17 |
type |= GPGME_PGP_PUBKEY; |
79 |
twoaday |
2 |
if( strstr( data, "BEGIN PGP PRIVATE KEY BLOCK" ) |
80 |
|
|
|| strstr( data, "BEGIN PGP SECRET KEY BLOCK" ) ) |
81 |
twoaday |
17 |
type |= GPGME_PGP_SECKEY; |
82 |
twoaday |
2 |
if( strstr( data, "- -----BEGIN" ) ) |
83 |
twoaday |
17 |
type |= GPGME_PGP_DASH_ESCAPED; |
84 |
twoaday |
2 |
*r_type = type; |
85 |
|
|
return 0; |
86 |
|
|
} /* gpgme_clip_parse_pgpid */ |
87 |
|
|
|
88 |
|
|
|
89 |
|
|
gpgme_error_t |
90 |
twoaday |
17 |
gpgme_clip_is_secured (gpgme_pgptype_t * r_type, int * r_rc) |
91 |
twoaday |
2 |
{ |
92 |
|
|
int rc = 0; |
93 |
|
|
HANDLE clipmem; |
94 |
|
|
char *clipdata; |
95 |
|
|
|
96 |
|
|
if( !r_rc ) |
97 |
|
|
return mk_error( Invalid_Value ); |
98 |
|
|
if( OpenClipboard( NULL ) == FALSE ) |
99 |
|
|
return mk_error( Clip_Open ); |
100 |
|
|
clipmem = GetClipboardData( CF_TEXT ); |
101 |
|
|
if( !clipmem ) { |
102 |
|
|
*r_rc = 0; |
103 |
|
|
goto leave; |
104 |
|
|
} |
105 |
|
|
clipdata = (char *) GlobalLock( clipmem ); |
106 |
|
|
if( !clipdata ) { |
107 |
|
|
*r_rc = 0; |
108 |
|
|
goto leave; |
109 |
|
|
} |
110 |
|
|
if( strstr( clipdata, "-----BEGIN PGP" ) |
111 |
|
|
&& strstr( clipdata, "-----END PGP" ) ) |
112 |
|
|
*r_rc = 1; |
113 |
|
|
GlobalUnlock( clipmem ); |
114 |
|
|
gpgme_clip_parse_pgpid( clipdata, r_type ); |
115 |
|
|
|
116 |
|
|
leave: |
117 |
|
|
CloseClipboard(); |
118 |
|
|
return rc; |
119 |
|
|
} /* gpgme_clip_is_secured */ |
120 |
|
|
|
121 |
|
|
|
122 |
|
|
gpgme_error_t |
123 |
|
|
gpgme_clip_do_check( int * r_rc ) |
124 |
|
|
{ |
125 |
|
|
int has_data = 0; |
126 |
|
|
gpgme_error_t err; |
127 |
|
|
err = gpgme_clip_istext_avail( &has_data ); |
128 |
|
|
if( err ) |
129 |
|
|
return err; |
130 |
|
|
if( !has_data ) |
131 |
|
|
return mk_error( Clip_Empty ); |
132 |
|
|
gpgme_clip_is_secured( NULL, r_rc ); |
133 |
|
|
return 0; |
134 |
|
|
} /* gpgme_clip_do_check */ |
135 |
|
|
|
136 |
|
|
|
137 |
|
|
gpgme_error_t |
138 |
twoaday |
17 |
gpgme_clip_get_pgptype (gpgme_pgptype_t * r_type) |
139 |
twoaday |
2 |
{ |
140 |
|
|
gpgme_error_t rc = 0; |
141 |
|
|
HANDLE clipmem; |
142 |
|
|
char * clipdata; |
143 |
|
|
|
144 |
|
|
if( OpenClipboard( NULL ) == FALSE ) |
145 |
|
|
return mk_error( Clip_Open ); |
146 |
|
|
clipmem = GetClipboardData( CF_TEXT ); |
147 |
|
|
if( !clipmem ) { |
148 |
|
|
rc = mk_error( Clip_Get ); |
149 |
|
|
goto leave; |
150 |
|
|
} |
151 |
|
|
clipdata = (char *)GlobalLock( clipmem ); |
152 |
|
|
if( !clipdata ) { |
153 |
|
|
rc = mk_error( Clip_Get ); |
154 |
|
|
goto leave; |
155 |
|
|
} |
156 |
|
|
gpgme_clip_parse_pgpid( clipdata, r_type ); |
157 |
|
|
GlobalUnlock( clipmem ); |
158 |
|
|
|
159 |
|
|
leave: |
160 |
|
|
CloseClipboard( ); |
161 |
|
|
return rc; |
162 |
|
|
} /* clip_get_pgp_type */ |