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

Annotation of /trunk/w32gpgme/w32-clip.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 78 - (hide annotations)
Tue Nov 15 08:54:44 2005 UTC (19 years, 3 months ago) by twoaday
File MIME type: text/plain
File size: 4607 byte(s)
2005-11-14  Timo Schulz  <ts@g10code.com>
 
        * wptGPG.cpp (check_gnupg_engine): Fix version check.
        * wptMainProc.cpp (winpt_main_proc): Check keyring
        file permissions always and do not use interative output
        when the windows session ends.
        * wptProxySettingsDlg.cpp (proxy_settings_dlg_proc):
        Localize all strings.
        * wptPassphraseDlg.cpp (passwd_dlg_proc): Likewise.
        * wptGPGPrefsDlg.cpp (gpg_prefs_dlg): Likewise.
        * wptKeyEditDlgs.cpp (do_init_keylist): Skip all
        non-valid keys.
         


1 werner 36 /* w32-clip.c - W32 API clipboard functions
2     * Copyright (C) 2001, 2002, 2003, 2005 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     #include "w32gpgme.h"
23    
24     int gpg_data_wrap_lines (gpgme_data_t *r_dh, size_t wraplen);
25    
26     //FIXME #include "wptVersion.h"
27 twoaday 78 #define PGM_VERSION "0.11.0-beta"
28 werner 36
29     /* Retrieve the thext of the clipboard.
30     Return value: the text as a string, NULL otherwise. */
31     static char*
32     get_w32_clip_text (void)
33     {
34     char *private_clip = NULL;
35     char *clip = NULL;
36     size_t size;
37     HANDLE cb;
38    
39     if (!OpenClipboard (NULL))
40     return NULL;
41     cb = GetClipboardData (CF_TEXT);
42     if (!cb)
43     goto leave;
44     private_clip = GlobalLock (cb);
45     if (!private_clip)
46     goto leave;
47     size = strlen (private_clip);
48     clip = malloc (size + 1);
49     if (!clip) {
50     GlobalUnlock (cb);
51     goto leave;
52     }
53     memcpy (clip, private_clip, size);
54     clip[size] = '\0';
55     GlobalUnlock(cb);
56    
57     leave:
58     CloseClipboard ();
59     return clip;
60     }
61    
62    
63     /* Set the new clipboard data to @data. */
64     static void
65     set_w32_clip_text (const char *data, int size)
66     {
67     HANDLE cb;
68     char *private_data;
69    
70     if (!OpenClipboard(NULL))
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     }
88    
89    
90     /* Retrieve the clipboard data and create a new gpgme
91     data object @r_dh and return it. If @wraplen is > 0
92     wrap lines of the buffer.
93     Return value: 0 on success. */
94     gpgme_error_t
95     gpg_data_new_from_clipboard (gpgme_data_t *r_dh, int wraplen)
96     {
97     gpgme_error_t err = 0;
98     gpgme_data_t dh;
99     char *clip_text = NULL;
100    
101     if (!r_dh)
102     return gpg_error (GPG_ERR_INV_ARG);
103     *r_dh = NULL;
104     clip_text = get_w32_clip_text ();
105     if (!clip_text)
106     return gpg_error (GPG_ERR_NO_DATA);
107     err = gpgme_data_new_from_mem (&dh, clip_text, strlen (clip_text), 1);
108     if (clip_text)
109     free (clip_text);
110     if (wraplen > 0)
111     gpg_data_wrap_lines (&dh, wraplen);
112    
113     *r_dh = dh;
114     return err;
115     }
116    
117    
118     /* Search for the armor header 'Version:' in @r_dh and
119     add the WinPT version. On success @r_dh is replaced
120     with the modified data.
121     Return value: 0 on success. */
122     static gpgme_error_t
123     gpg_data_change_version (gpgme_data_t *r_dh)
124     {
125     gpgme_error_t err = 0;
126     gpgme_data_t mdh;
127     char line[128+32];
128     int n;
129    
130     if (!r_dh)
131     return gpg_error (GPG_ERR_INV_ARG);
132    
133     err = gpgme_data_new (&mdh);
134     if (err)
135     return err;
136    
137     gpgme_data_rewind (*r_dh);
138     while ((n=gpg_data_readline (*r_dh, line, 128)) > 0) {
139     if (strlen (line) > 14 &&
140     !strncmp (line, "Version: GnuPG", 14) &&
141     !strstr (line, "WinPT "PGM_VERSION)) {
142     line[strlen (line) - 2] = '\0';
143     strcat (line, " - " );
144     strcat (line, "WinPT "PGM_VERSION);
145     strcat (line, "\r\n");
146     }
147     gpgme_data_write (mdh, line, strlen (line));
148     }
149    
150     gpgme_data_write (mdh, "", 1);
151     gpgme_data_rewind (mdh);
152     gpgme_data_release (*r_dh);
153     *r_dh = mdh;
154     return err;
155     }
156    
157     /* Release a gpgme data object @dh and write the contents of
158     the object to the clipboard. If @chg_ver is set, modify the
159     Version: header and add WinPT information. */
160     void
161     gpg_data_release_and_set_clipboard (gpgme_data_t dh, int chg_ver)
162     {
163     gpgme_data_t in;
164     char *clip_text;
165     size_t n;
166    
167     if (!dh)
168     return;
169    
170     in = dh;
171     if (chg_ver)
172     gpg_data_change_version (&in);
173    
174     clip_text = gpgme_data_release_and_get_mem (in, &n);
175     if (clip_text && *clip_text) {
176     set_w32_clip_text (clip_text, n);
177     memset (clip_text, 0xFF, n);
178     gpgme_free (clip_text);
179     }
180     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26