1 /* gpgme.c - GnuPG Made Easy
2 * Copyright (C) 2000 Werner Koch (dd9jn)
4 * This file is part of GPGME.
6 * GPGME 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.
11 * GPGME 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.
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
30 #define my_isdigit(a) ( (a) >='0' && (a) <= '9' )
31 #define my_isxdigit(a) ( my_isdigit((a)) \
32 || ((a) >= 'A' && (a) <= 'F') \
33 || ((a) >= 'f' && (a) <= 'f') )
37 * @r_ctx: Returns the new context
39 * Create a new context to be used with most of the other GPGME
40 * functions. Use gpgme_release_contect() to release all resources
42 * Return value: An error code
45 gpgme_new (GpgmeCtx *r_ctx)
49 c = xtrycalloc ( 1, sizeof *c );
51 return mk_error (Out_Of_Core);
53 c->use_armor = 1; /* fixme: reset this to 0 */
61 * @c: Context to be released.
63 * Release all resources associated with the given context.
66 gpgme_release ( GpgmeCtx c )
70 _gpgme_gpg_release ( c->gpg );
71 _gpgme_release_result ( c );
72 _gpgme_key_release ( c->tmp_key );
73 gpgme_data_release ( c->help_data_1 );
74 gpgme_data_release ( c->notation );
75 /* fixme: release the key_queue */
81 _gpgme_release_result ( GpgmeCtx c )
83 switch (c->result_type) {
84 case RESULT_TYPE_NONE:
86 case RESULT_TYPE_VERIFY:
87 _gpgme_release_verify_result ( c->result.verify );
89 case RESULT_TYPE_DECRYPT:
90 _gpgme_release_decrypt_result ( c->result.decrypt );
92 case RESULT_TYPE_SIGN:
93 _gpgme_release_sign_result ( c->result.sign );
97 c->result.verify = NULL;
98 c->result_type = RESULT_TYPE_NONE;
106 * Cancel the current operation. It is not guaranteed that it will work for
107 * all kinds of operations. It is especially useful in a passphrase callback
108 * to stop the system from asking another time for the passphrase.
112 gpgme_cancel (GpgmeCtx c)
118 * gpgme_get_notation:
121 * If there is notation data available from the last signature check, this
122 * function may be used to return this notation data as a string. The string
123 * is an XML represantaton of that data embedded in a %<notation> container.
125 * Return value: An XML string or NULL if no notation data is available.
128 gpgme_get_notation ( GpgmeCtx c )
132 return _gpgme_data_get_as_string ( c->notation );
139 * @yes: boolean value to set or clear that flag
141 * Enable or disable the use of an ascii armor for all output.
144 gpgme_set_armor ( GpgmeCtx c, int yes )
152 * gpgme_set_textmode:
154 * @yes: boolean flag whether textmode should be enabled
156 * Enable or disable the use of the special textmode. Textmode is for example
157 * used for MIME (RFC2015) signatures
160 gpgme_set_textmode ( GpgmeCtx c, int yes )
164 c->use_textmode = yes;
168 * gpgme_set_passphrase_cb:
170 * @cb: A callback function
171 * @cb_value: The value passed to the callback function
173 * This function sets a callback function to be used to pass a passphrase
174 * to gpg. The preferred way to handle this is by using the gpg-agent, but
175 * because that beast is not ready for real use, you can use this passphrase
178 * The callback function is defined as:
180 * typedef const char *(*GpgmePassphraseCb)(void*cb_value,
184 * and called whenever gpgme needs a passphrase. DESC will have a nice
185 * text, to be used to prompt for the passphrase and R_HD is just a parameter
186 * to be used by the callback it self. Becuase the callback returns a const
187 * string, the callback might want to know when it can releae resources
188 * assocated with that returned string; gpgme helps here by calling this
189 * passphrase callback with an DESC of %NULL as soon as it does not need
190 * the returned string anymore. The callback function might then choose
191 * to release resources depending on R_HD.
195 gpgme_set_passphrase_cb ( GpgmeCtx c, GpgmePassphraseCb cb, void *cb_value )
197 c->passphrase_cb = cb;
198 c->passphrase_cb_value = cb_value;
202 * gpgme_set_pprogress_cb:
204 * @cb: A callback function
205 * @cb_value: The value passed to the callback function
207 * This function sets a callback function to be used as a progress indicator.
209 * The callback function is defined as:
211 * typedef void (*GpgmeProgressCb) (void*cb_value,
212 * const char *what, int type,
213 * int curretn, int total);
215 * For details on the progress events, see the entry for the PROGRESS
216 * status in the file doc/DETAILS of the GnuPG distribution.
219 gpgme_set_progress_cb ( GpgmeCtx c, GpgmeProgressCb cb, void *cb_value )
222 c->progress_cb_value = cb_value;