/[winpt]/trunk/Src/wptGPGMEWrapper.cpp
ViewVC logotype

Contents of /trunk/Src/wptGPGMEWrapper.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 167 - (show annotations)
Thu Jan 26 10:17:17 2006 UTC (19 years, 1 month ago) by twoaday
File size: 3253 byte(s)
2006-01-25  Timo Schulz  <ts@g10code.com>
 
        * wptRegistry.cpp (get_reg_entry_gpg): Return NULL if
        the key exist with no value.
        * wptMDSumDlg.cpp (mdsum_dlg_proc): Translate string.
        * wptKeysignDlg.cpp (do_fill_seclist): Select the
        default key if possible.
        * wptFirstRunDlg.cpp (firstrun_dlg_proc): Directly
        return the choice.
        * wptKeylist.cpp (get_key_desc): New.
        (keylist_upd_key): Free memory.
        * wptKeyCache.cpp (gpg_keycache_get_default_key): New.
        (gpg_keycache_set_default_key): New.
        * WinPT.cpp (gpg_prefs_ok): New.
        (WinMain): Only start gpg prefs if needed.
         


1 /* wptGPGMEWrapper.cpp - Object oriented wrapper for GPGME
2 * Copyright (C) 2006 Timo Schulz
3 *
4 * This file is part of WinPT.
5 *
6 * WinPT is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * WinPT 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 GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with WinPT; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include <windows.h>
26 #include <stdio.h>
27 #include <string.h>
28
29 #include "gpgme.h"
30 #include "wptGPG.h"
31 #include "wptGPGME.h"
32
33 /* Macros to change to normal and wait cursor. */
34 #define op_begin() SetCursor (LoadCursor (NULL, IDC_WAIT))
35 #define op_end() SetCursor (LoadCursor (NULL, IDC_ARROW))
36
37 /* Constructor to build gpgme context. */
38 GPGME::GPGME ()
39 {
40 gpgme_new (&ctx);
41 }
42
43 /* Destructor to release gpgme context. */
44 GPGME::~GPGME ()
45 {
46 if (ctx != NULL)
47 gpgme_release (ctx);
48 }
49
50 /* Enable or disable the feature to add the
51 WinPT version to armored output. */
52 void
53 GPGME::setChangeVersion (bool val)
54 {
55 chg_ver = val;
56 }
57
58 /* Enable or disable armor. */
59 void
60 GPGME::setArmor (bool val)
61 {
62 gpgme_set_armor (ctx, val? 1 : 0);
63 }
64
65 bool
66 GPGME::getArmor (void)
67 {
68 return gpgme_get_armor (ctx)? true: false;
69 }
70
71 /* Export key pattern @patt to file @outfile.
72 Return value: 0 on success. */
73 gpgme_error_t
74 GPGME::exportToFile (const char *patt, const char *outfile)
75 {
76 gpgme_data_t dat;
77 gpgme_error_t err;
78
79 err = gpgme_data_new (&dat);
80 if (err)
81 return err;
82 op_begin ();
83 err = gpgme_op_export (ctx, patt, 0, dat);
84 op_end ();
85 if (err) {
86 gpgme_data_release (dat);
87 return err;
88 }
89 err = gpg_data_release_and_set_file (dat, outfile);
90 return err;
91 }
92
93
94 /* Export key pattern @patt to the clipboard.
95 Return value: 0 on success. */
96 gpgme_error_t
97 GPGME::exportToClipboard (const char *patt)
98 {
99 gpgme_data_t dat;
100 gpgme_error_t err;
101
102 err = gpgme_data_new (&dat);
103 if (err)
104 return err;
105 op_begin ();
106 err = gpgme_op_export (ctx, patt, 0, dat);
107 op_end ();
108 if (err) {
109 gpgme_data_release (dat);
110 return err;
111 }
112 gpg_data_release_and_set_clipboard (dat, chg_ver? 1 : 0);
113 return err;
114 }
115
116
117 /* Export key pattern @patt to the buffer @outdata.
118 Return value: 0 on success. */
119 gpgme_error_t
120 GPGME::exportToBuffer (const char *patt, char **outdata)
121 {
122 gpgme_error_t err;
123 gpgme_data_t dat;
124 size_t n;
125 char *p;
126
127 err = gpgme_data_new (&dat);
128 if (err)
129 return err;
130 op_begin ();
131 err = gpgme_op_export (ctx, patt, 0, dat);
132 op_end ();
133 if (err) {
134 gpgme_data_release (dat);
135 return err;
136 }
137 p = gpgme_data_release_and_get_mem (dat, &n);
138
139 *outdata = new char[n+1];
140 memcpy (*outdata, p, n);
141 (*outdata)[n] = 0;
142 gpgme_free (p);
143
144 return err;
145 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26