/[winpt]/trunk/MyGPGME/w32-clip.c
ViewVC logotype

Contents of /trunk/MyGPGME/w32-clip.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 17 - (show annotations)
Fri May 20 08:38:32 2005 UTC (19 years, 9 months ago) by twoaday
File MIME type: text/plain
File size: 3785 byte(s)
2005-05-20      Timo Schulz  <twoaday@freakmail.de>
 
        * gpgme.h: s/cliptype/pgptype. Suggested by Kurt Fitzner.
        s/CLIP/PGP. Likewise.
        * w32-io.c (_gpgme_io_select): Increment the right loop variable.
        Kudos to Kurt.
        * keylist.c (gpgme_op_keylist_getkey): New. Handy function to
        retrieve a single key.
        * verify.c (gpgme_get_sig_key): Use it here.
        * keycache.c (gpgme_keycache_update_key): Update a single key.
 


1 /* w32-clip.c - W32 API clipboard functions
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 #include <windows.h>
22
23 #include "util.h"
24 #include "ops.h"
25 #include "context.h"
26
27
28 static char*
29 get_w32_clip_text( int *r_size )
30 {
31 int rc, size;
32 char *private_clip = NULL;
33 char *clip = NULL;
34 HANDLE cb;
35
36 rc = OpenClipboard( NULL );
37 if( !rc )
38 return NULL;
39 cb = GetClipboardData( CF_TEXT );
40 if( !cb )
41 goto leave;
42 private_clip = GlobalLock( cb );
43 if( !private_clip )
44 goto leave;
45 size = strlen( private_clip );
46 clip = malloc( size + 1 );
47 if( !clip ) {
48 GlobalUnlock( cb );
49 goto leave;
50 }
51 memcpy( clip, private_clip, size );
52 clip[size] = '\0';
53 *r_size = size;
54 GlobalUnlock( cb );
55
56 leave:
57 CloseClipboard();
58 return clip;
59 } /* get_w32_clip_text */
60
61
62 static void
63 set_w32_clip_text( const char *data, int size )
64 {
65 int rc;
66 HANDLE cb;
67 char *private_data;
68
69 rc = OpenClipboard( NULL );
70 if( !rc )
71 return;
72 EmptyClipboard();
73 cb = GlobalAlloc( GHND, size+1 );
74 if( !cb )
75 goto leave;
76 private_data = GlobalLock( cb );
77 if( !private_data )
78 goto leave;
79 memcpy( private_data, data, size );
80 private_data[size] = '\0';
81 SetClipboardData( CF_TEXT, cb );
82 GlobalUnlock( cb );
83
84 leave:
85 CloseClipboard( );
86 GlobalFree( cb );
87 } /* set_w32_clip_text */
88
89
90 gpgme_error_t
91 gpgme_data_new_from_clipboard (gpgme_data_t *r_dh)
92 {
93 gpgme_error_t err = 0;
94 gpgme_data_t dh;
95 char *clip_text;
96 int size;
97
98 if (!r_dh)
99 return mk_error (Invalid_Value);
100 *r_dh = NULL;
101 clip_text = get_w32_clip_text (&size);
102 if (!clip_text)
103 return mk_error (No_Data);
104 err = gpgme_data_new_from_mem (&dh, clip_text, size, 1);
105 safe_free (clip_text);
106 *r_dh = dh;
107 return err;
108 } /* gpgme_data_new_from_clipboard */
109
110
111 void
112 gpgme_data_release_and_set_clipboard (gpgme_data_t dh)
113 {
114 char *clip_text;
115 int size = 0;
116
117 if (!dh)
118 return;
119 clip_text = _gpgme_data_get_as_string (dh);
120 if (clip_text && (size = strlen (clip_text)) > 0) {
121 set_w32_clip_text (clip_text, size);
122 safe_free (clip_text);
123 }
124 gpgme_data_release (dh);
125 } /* gpgme_data_release_and_set_clipboard */
126
127
128 gpgme_error_t
129 gpgme_data_fix_clipboard( gpgme_data_t dh )
130 {
131 const char *packets[] = {
132 "-----BEGIN PGP MESSAGE-----"
133 "-----BEGIN PGP PRIVATE KEY-----",
134 "-----BEGIN PGP PUBLIC KEY-----",
135 "-----BEGIN PGP SIGNED MESSAGE-----"
136 };
137 const char *headers[] = {
138 "Comment"
139 "Hash",
140 "Version"
141 };
142 char *p;
143 int idx;
144
145 p = _gpgme_data_get_as_string( dh );
146 if( p == NULL )
147 return mk_error( Invalid_Value );
148 for( idx = 0; idx < 4; idx++ ) {
149 if( strstr( p, packets[idx] ) )
150 break;
151 }
152 safe_free( p );
153
154 return 1;
155 } /* gpgme_data_fix_clipboard */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26