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

Annotation of /trunk/w32gpgme/clip.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 47 - (hide annotations)
Mon Oct 31 14:04:59 2005 UTC (19 years, 4 months ago) by werner
File MIME type: text/plain
File size: 3960 byte(s)
Minor changes; compiles now but gettext is still missing.

1 werner 36 /* clip.c
2     * Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz
3     * Copyright (C) 2005 g10 Code GmbH
4     *
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 werner 47
23 werner 36 #include "w32gpgme.h"
24 werner 47 #include "wptCrypto.h"
25 werner 36
26     /* XXX: define clipboard errors. */
27    
28     /* Check if the clipboard contains text. @r_rc contains
29     one text data is available.
30     Return value: 0 on success. */
31     gpgme_error_t
32     gpg_clip_istext_avail (int *r_rc)
33     {
34     HANDLE clipmem;
35     char *clipdata;
36    
37     if (!r_rc)
38     return gpg_error (GPG_ERR_INV_ARG);
39     if (OpenClipboard (NULL) == FALSE)
40     return gpg_error (GPG_ERR_NO_DATA);
41    
42     *r_rc = 0;
43     clipmem = GetClipboardData (CF_TEXT);
44     if (!clipmem)
45     goto leave;
46    
47     clipdata = (char *) GlobalLock (clipmem);
48     if (!clipdata)
49     goto leave;
50     if (strlen (clipdata) > 0)
51     *r_rc = 1;
52     GlobalUnlock (clipmem);
53    
54     leave:
55     CloseClipboard ();
56     return 0;
57     }
58    
59    
60     /* Figure out what kind of PGP data is stored in @data.
61     @r_type contains the ORed types on success.
62     Return value: 0 on success. */
63     gpgme_error_t
64 werner 47 gpg_clip_parse_pgpid (const char *data, int *r_type)
65 werner 36 {
66 werner 47 int type;
67 werner 36
68     if (!data)
69     return gpg_error (GPG_ERR_INV_ARG);
70     if (strlen (data) < 19) {
71     *r_type = 0;
72     return 0;
73     }
74     type = 0;
75     if (strstr( data, "BEGIN PGP MESSAGE") )
76     type |= PGP_MESSAGE;
77     if (strstr (data, "BEGIN PGP SIGNED MESSAGE"))
78     type |= PGP_CLEARSIG;
79     if (strstr (data, "BEGIN PGP SIGNATURE"))
80     type |= PGP_SIG;
81     if (strstr (data, "BEGIN PGP PUBLIC KEY BLOCK"))
82     type |= PGP_PUBKEY;
83     if (strstr (data, "BEGIN PGP PRIVATE KEY BLOCK")
84     || strstr (data, "BEGIN PGP SECRET KEY BLOCK"))
85     type |= PGP_SECKEY;
86     if (strstr (data, "- -----BEGIN"))
87     type |= PGP_DASH_ESCAPED;
88     *r_type = type;
89     return 0;
90     }
91    
92    
93     gpgme_error_t
94 werner 47 gpg_clip_is_secured (int *r_type, int *r_rc)
95 werner 36 {
96     int rc = 0;
97     HANDLE clipmem;
98     char *clipdata;
99    
100     if( !r_rc )
101     return gpg_error (GPG_ERR_INV_ARG);
102     if( OpenClipboard( NULL ) == FALSE )
103     return gpg_error (GPG_ERR_INTERNAL);
104     clipmem = GetClipboardData( CF_TEXT );
105     if( !clipmem ) {
106     *r_rc = 0;
107     goto leave;
108     }
109     clipdata = (char *) GlobalLock( clipmem );
110     if( !clipdata ) {
111     *r_rc = 0;
112     goto leave;
113     }
114     if( strstr( clipdata, "-----BEGIN PGP" )
115     && strstr( clipdata, "-----END PGP" ) )
116     *r_rc = 1;
117     GlobalUnlock( clipmem );
118     gpg_clip_parse_pgpid( clipdata, r_type );
119    
120     leave:
121     CloseClipboard();
122     return rc;
123     }
124    
125    
126     gpgme_error_t
127     gpg_clip_do_check( int * r_rc )
128     {
129     int has_data = 0;
130     gpgme_error_t err;
131    
132     err = gpg_clip_istext_avail (&has_data);
133     if (err)
134     return err;
135     if (!has_data)
136     return gpg_error (GPG_ERR_NO_DATA);
137     gpg_clip_is_secured (NULL, r_rc);
138     return 0;
139     }
140    
141    
142     gpgme_error_t
143 werner 47 gpg_clip_get_pgptype (int *r_type)
144 werner 36 {
145     gpgme_error_t rc = 0;
146     HANDLE clipmem;
147     char *clipdata;
148    
149     if (OpenClipboard (NULL) == FALSE)
150     return gpg_error (GPG_ERR_INTERNAL);
151     clipmem = GetClipboardData (CF_TEXT);
152     if (!clipmem) {
153     rc = gpg_error (GPG_ERR_NO_DATA);
154     goto leave;
155     }
156     clipdata = (char *)GlobalLock( clipmem );
157     if (!clipdata) {
158     rc = gpg_error (GPG_ERR_NO_DATA);
159     goto leave;
160     }
161     gpg_clip_parse_pgpid (clipdata, r_type);
162     GlobalUnlock (clipmem);
163    
164     leave:
165     CloseClipboard ();
166     return rc;
167     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26