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

Annotation of /trunk/w32gpgme/clip.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (hide annotations)
Fri Sep 30 10:10:16 2005 UTC (19 years, 5 months ago) by twoaday
File MIME type: text/plain
File size: 3950 byte(s)
Almost finished phase 1 of the WinPT GPGME port.
Still need more cleanup, comments and tests.


1 twoaday 23 /* 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     #include <windows.h>
21     #include "w32gpgme.h"
22    
23     /* XXX: define clipboard errors. */
24    
25     gpgme_error_t
26     gpgme_clip_istext_avail( int *r_rc )
27     {
28     HANDLE clipmem;
29     char *clipdata;
30    
31     if( !r_rc )
32     return GPG_ERR_INV_ARG;
33     if( OpenClipboard( NULL ) == FALSE )
34     return GPG_ERR_NO_DATA;
35    
36     clipmem = GetClipboardData( CF_TEXT );
37     if( !clipmem ) {
38     *r_rc = 0;
39     goto leave;
40     }
41     clipdata = (char *) GlobalLock( clipmem );
42     if( !clipdata ) {
43     *r_rc = 0;
44     goto leave;
45     }
46     if( strlen( clipdata ) )
47     *r_rc = 1;
48     GlobalUnlock( clipmem );
49    
50     leave:
51     CloseClipboard();
52     return 0;
53     } /* gpgme_clip_istext_avail */
54    
55    
56     gpgme_error_t
57     gpgme_clip_parse_pgpid (const char * data, gpgme_pgptype_t * r_type)
58     {
59     gpgme_pgptype_t type;
60    
61     if( !data )
62     return GPG_ERR_INV_ARG;
63     if( strlen( data ) < 19 ) {
64     *r_type = 0;
65     return 0;
66     }
67     type = 0;
68     if( strstr( data, "BEGIN PGP MESSAGE") )
69     type |= PGP_MESSAGE;
70     if( strstr( data, "BEGIN PGP SIGNED MESSAGE" ) )
71     type |= PGP_CLEARSIG;
72     if( strstr( data, "BEGIN PGP SIGNATURE" ) )
73     type |= PGP_SIG;
74     if( strstr( data, "BEGIN PGP PUBLIC KEY BLOCK" ) )
75     type |= PGP_PUBKEY;
76     if( strstr( data, "BEGIN PGP PRIVATE KEY BLOCK" )
77     || strstr( data, "BEGIN PGP SECRET KEY BLOCK" ) )
78     type |= PGP_SECKEY;
79     if( strstr( data, "- -----BEGIN" ) )
80     type |= PGP_DASH_ESCAPED;
81     *r_type = type;
82     return 0;
83     } /* gpgme_clip_parse_pgpid */
84    
85    
86     gpgme_error_t
87     gpgme_clip_is_secured (gpgme_pgptype_t * r_type, int * r_rc)
88     {
89     int rc = 0;
90     HANDLE clipmem;
91     char *clipdata;
92    
93     if( !r_rc )
94     return GPG_ERR_INV_ARG;
95     if( OpenClipboard( NULL ) == FALSE )
96     return GPG_ERR_INTERNAL;
97     clipmem = GetClipboardData( CF_TEXT );
98     if( !clipmem ) {
99     *r_rc = 0;
100     goto leave;
101     }
102     clipdata = (char *) GlobalLock( clipmem );
103     if( !clipdata ) {
104     *r_rc = 0;
105     goto leave;
106     }
107     if( strstr( clipdata, "-----BEGIN PGP" )
108     && strstr( clipdata, "-----END PGP" ) )
109     *r_rc = 1;
110     GlobalUnlock( clipmem );
111     gpgme_clip_parse_pgpid( clipdata, r_type );
112    
113     leave:
114     CloseClipboard();
115     return rc;
116     } /* gpgme_clip_is_secured */
117    
118    
119     gpgme_error_t
120     gpgme_clip_do_check( int * r_rc )
121     {
122     int has_data = 0;
123     gpgme_error_t err;
124     err = gpgme_clip_istext_avail( &has_data );
125     if( err )
126     return err;
127     if( !has_data )
128     return GPG_ERR_NO_DATA;
129     gpgme_clip_is_secured( NULL, r_rc );
130     return 0;
131     } /* gpgme_clip_do_check */
132    
133    
134     gpgme_error_t
135     gpgme_clip_get_pgptype (gpgme_pgptype_t * r_type)
136     {
137     gpgme_error_t rc = 0;
138     HANDLE clipmem;
139     char * clipdata;
140    
141     if( OpenClipboard( NULL ) == FALSE )
142     return GPG_ERR_INTERNAL;
143     clipmem = GetClipboardData( CF_TEXT );
144     if( !clipmem ) {
145     rc = GPG_ERR_NO_DATA;
146     goto leave;
147     }
148     clipdata = (char *)GlobalLock( clipmem );
149     if( !clipdata ) {
150     rc = GPG_ERR_NO_DATA;
151     goto leave;
152     }
153     gpgme_clip_parse_pgpid( clipdata, r_type );
154     GlobalUnlock( clipmem );
155    
156     leave:
157     CloseClipboard( );
158     return rc;
159     } /* clip_get_pgp_type */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26