/[winpt]/trunk/w32gpgme/clip.c
ViewVC logotype

Annotation of /trunk/w32gpgme/clip.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (hide annotations)
Wed Oct 12 10:04:26 2005 UTC (19 years, 4 months ago) by twoaday
File MIME type: text/plain
File size: 4141 byte(s)
First testing phase finished.
Provide bug fixes for a lot of (minor) problems.

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26