1 /* gpgme.c - GnuPG Made Easy
2 * Copyright (C) 2000 Werner Koch (dd9jn)
3 * Copyright (C) 2001, 2002 g10 Code GmbH
5 * This file is part of GPGME.
7 * GPGME 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.
12 * GPGME 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.
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
34 * @r_ctx: Returns the new context
36 * Create a new context to be used with most of the other GPGME
37 * functions. Use gpgme_release_contect() to release all resources
39 * Return value: An error code
42 gpgme_new (GpgmeCtx *r_ctx)
47 return mk_error (Invalid_Value);
49 ctx = xtrycalloc (1, sizeof *ctx);
51 return mk_error (Out_Of_Core);
60 * @c: Context to be released.
62 * Release all resources associated with the given context.
65 gpgme_release (GpgmeCtx ctx)
69 _gpgme_engine_release (ctx->engine);
70 _gpgme_release_result (ctx);
71 gpgme_key_release (ctx->tmp_key);
72 gpgme_data_release (ctx->help_data_1);
73 gpgme_data_release (ctx->notation);
74 gpgme_signers_clear (ctx);
77 /* FIXME: Release the key_queue. */
82 _gpgme_release_result (GpgmeCtx ctx)
84 _gpgme_release_verify_result (ctx->result.verify);
85 _gpgme_release_decrypt_result (ctx->result.decrypt);
86 _gpgme_release_sign_result (ctx->result.sign);
87 _gpgme_release_encrypt_result (ctx->result.encrypt);
88 _gpgme_release_passphrase_result (ctx->result.passphrase);
89 memset (&ctx->result, 0, sizeof (ctx->result));
90 _gpgme_set_op_info (ctx, NULL);
98 * Cancel the current operation. It is not guaranteed that it will work for
99 * all kinds of operations. It is especially useful in a passphrase callback
100 * to stop the system from asking another time for the passphrase.
103 gpgme_cancel (GpgmeCtx ctx)
105 return_if_fail (ctx);
111 * gpgme_get_notation:
114 * If there is notation data available from the last signature check,
115 * this function may be used to return this notation data as a string.
116 * The string is an XML represantaton of that data embedded in a
117 * %<notation> container.
119 * Return value: An XML string or NULL if no notation data is available.
122 gpgme_get_notation (GpgmeCtx ctx)
126 return _gpgme_data_get_as_string (ctx->notation);
135 * Return information about the last information. The caller has to
136 * free the string. NULL is returned if there is not previous
137 * operation available or the operation has not yet finished.
139 * Here is a sample information we return:
142 * <GnupgOperationInfo>
144 * <detached/> <!-- or cleartext or standard -->
146 * <hashalgo>2</hashalgo>
147 * <micalg>pgp-sha1</micalg>
148 * <sigclass>01</sigclass>
149 * <created>9222222</created>
150 * <fpr>121212121212121212</fpr>
152 * </GnupgOperationInfo>
155 * Return value: NULL for no info available or an XML string
158 gpgme_get_op_info (GpgmeCtx ctx, int reserved)
160 if (!ctx || reserved)
161 return NULL; /* Invalid value. */
163 return _gpgme_data_get_as_string (ctx->op_info);
168 * Store the data object with the operation info in the
169 * context. Caller should not use that object anymore.
172 _gpgme_set_op_info (GpgmeCtx ctx, GpgmeData info)
176 gpgme_data_release (ctx->op_info);
185 gpgme_set_protocol (GpgmeCtx ctx, GpgmeProtocol protocol)
188 return mk_error (Invalid_Value);
192 case GPGME_PROTOCOL_OpenPGP:
195 case GPGME_PROTOCOL_CMS:
198 case GPGME_PROTOCOL_AUTO:
199 return mk_error (Not_Implemented);
201 return mk_error (Invalid_Value);
211 * @yes: boolean value to set or clear that flag
213 * Enable or disable the use of an ascii armor for all output.
216 gpgme_set_armor (GpgmeCtx ctx, int yes)
220 ctx->use_armor = yes;
228 * Return the state of the armor flag which can be changed using
231 * Return value: Boolean whether armor mode is to be used.
234 gpgme_get_armor (GpgmeCtx ctx)
236 return ctx && ctx->use_armor;
241 * gpgme_set_textmode:
243 * @yes: boolean flag whether textmode should be enabled
245 * Enable or disable the use of the special textmode. Textmode is for example
246 * used for the RFC2015 signatures; note that the updated RFC 3156 mandates
247 * that the MUA does some preparations so that textmode is not needed anymore.
250 gpgme_set_textmode (GpgmeCtx ctx, int yes)
254 ctx->use_textmode = yes;
258 * gpgme_get_textmode:
261 * Return the state of the textmode flag which can be changed using
262 * gpgme_set_textmode().
264 * Return value: Boolean whether textmode is to be used.
267 gpgme_get_textmode (GpgmeCtx ctx)
269 return ctx && ctx->use_textmode;
274 * gpgme_set_keylist_mode:
276 * @mode: listing mode
278 * This function changes the default behaviour of the keylisting functions.
279 * Defines values for @mode are: %0 = normal, %1 = fast listing without
280 * information about key validity.
283 gpgme_set_keylist_mode (GpgmeCtx ctx, int mode)
287 ctx->keylist_mode = mode;
292 * gpgme_set_passphrase_cb:
294 * @cb: A callback function
295 * @cb_value: The value passed to the callback function
297 * This function sets a callback function to be used to pass a passphrase
298 * to gpg. The preferred way to handle this is by using the gpg-agent, but
299 * because that beast is not ready for real use, you can use this passphrase
302 * The callback function is defined as:
304 * typedef const char *(*GpgmePassphraseCb)(void*cb_value,
308 * and called whenever gpgme needs a passphrase. DESC will have a nice
309 * text, to be used to prompt for the passphrase and R_HD is just a parameter
310 * to be used by the callback it self. Because the callback returns a const
311 * string, the callback might want to know when it can release resources
312 * assocated with that returned string; gpgme helps here by calling this
313 * passphrase callback with an DESC of %NULL as soon as it does not need
314 * the returned string anymore. The callback function might then choose
315 * to release resources depending on R_HD.
319 gpgme_set_passphrase_cb (GpgmeCtx ctx, GpgmePassphraseCb cb, void *cb_value)
323 ctx->passphrase_cb = cb;
324 ctx->passphrase_cb_value = cb_value;
329 * gpgme_set_progress_cb:
331 * @cb: A callback function
332 * @cb_value: The value passed to the callback function
334 * This function sets a callback function to be used as a progress indicator.
336 * The callback function is defined as:
338 * typedef void (*GpgmeProgressCb) (void *cb_value,
339 * const char *what, int type,
340 * int curretn, int total);
342 * For details on the progress events, see the entry for the PROGRESS
343 * status in the file doc/DETAILS of the GnuPG distribution.
346 gpgme_set_progress_cb (GpgmeCtx ctx, GpgmeProgressCb cb, void *cb_value)
350 ctx->progress_cb = cb;
351 ctx->progress_cb_value = cb_value;