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

Annotation of /trunk/w32gpgme/clip.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 36 - (hide annotations)
Thu Oct 27 15:25:13 2005 UTC (19 years, 4 months ago) by werner
File MIME type: text/plain
File size: 3976 byte(s)
First set of changes to use autotools for building.
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     #include "w32gpgme.h"
23    
24     /* XXX: define clipboard errors. */
25    
26     /* Check if the clipboard contains text. @r_rc contains
27     one text data is available.
28     Return value: 0 on success. */
29     gpgme_error_t
30     gpg_clip_istext_avail (int *r_rc)
31     {
32     HANDLE clipmem;
33     char *clipdata;
34    
35     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    
40     *r_rc = 0;
41     clipmem = GetClipboardData (CF_TEXT);
42     if (!clipmem)
43     goto leave;
44    
45     clipdata = (char *) GlobalLock (clipmem);
46     if (!clipdata)
47     goto leave;
48     if (strlen (clipdata) > 0)
49     *r_rc = 1;
50     GlobalUnlock (clipmem);
51    
52     leave:
53     CloseClipboard ();
54     return 0;
55     }
56    
57    
58     /* 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     gpgme_error_t
62     gpg_clip_parse_pgpid (const char *data, gpg_pgptype_t *r_type)
63     {
64     gpg_pgptype_t type;
65    
66     if (!data)
67     return gpg_error (GPG_ERR_INV_ARG);
68     if (strlen (data) < 19) {
69     *r_type = 0;
70     return 0;
71     }
72     type = 0;
73     if (strstr( data, "BEGIN PGP MESSAGE") )
74     type |= PGP_MESSAGE;
75     if (strstr (data, "BEGIN PGP SIGNED MESSAGE"))
76     type |= PGP_CLEARSIG;
77     if (strstr (data, "BEGIN PGP SIGNATURE"))
78     type |= PGP_SIG;
79     if (strstr (data, "BEGIN PGP PUBLIC KEY BLOCK"))
80     type |= PGP_PUBKEY;
81     if (strstr (data, "BEGIN PGP PRIVATE KEY BLOCK")
82     || strstr (data, "BEGIN PGP SECRET KEY BLOCK"))
83     type |= PGP_SECKEY;
84     if (strstr (data, "- -----BEGIN"))
85     type |= PGP_DASH_ESCAPED;
86     *r_type = type;
87     return 0;
88     }
89    
90    
91     gpgme_error_t
92     gpg_clip_is_secured (gpg_pgptype_t *r_type, int *r_rc)
93     {
94     int rc = 0;
95     HANDLE clipmem;
96     char *clipdata;
97    
98     if( !r_rc )
99     return gpg_error (GPG_ERR_INV_ARG);
100     if( OpenClipboard( NULL ) == FALSE )
101     return gpg_error (GPG_ERR_INTERNAL);
102     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     gpg_clip_parse_pgpid( clipdata, r_type );
117    
118     leave:
119     CloseClipboard();
120     return rc;
121     }
122    
123    
124     gpgme_error_t
125     gpg_clip_do_check( int * r_rc )
126     {
127     int has_data = 0;
128     gpgme_error_t err;
129    
130     err = gpg_clip_istext_avail (&has_data);
131     if (err)
132     return err;
133     if (!has_data)
134     return gpg_error (GPG_ERR_NO_DATA);
135     gpg_clip_is_secured (NULL, r_rc);
136     return 0;
137     }
138    
139    
140     gpgme_error_t
141     gpg_clip_get_pgptype (gpg_pgptype_t *r_type)
142     {
143     gpgme_error_t rc = 0;
144     HANDLE clipmem;
145     char *clipdata;
146    
147     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     goto leave;
153     }
154     clipdata = (char *)GlobalLock( clipmem );
155     if (!clipdata) {
156     rc = gpg_error (GPG_ERR_NO_DATA);
157     goto leave;
158     }
159     gpg_clip_parse_pgpid (clipdata, r_type);
160     GlobalUnlock (clipmem);
161    
162     leave:
163     CloseClipboard ();
164     return rc;
165     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26