9a6d7b539d0dc1e8aa6cf4bee3d97d3bd6cea878
[gpgme.git] / gpgme / gpgme.c
1 /* gpgme.c -  GnuPG Made Easy
2  *      Copyright (C) 2000 Werner Koch (dd9jn)
3  *
4  * This file is part of GPGME.
5  *
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.
10  *
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.
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 <config.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24
25 #include "util.h"
26 #include "context.h"
27 #include "ops.h"
28
29 #define my_isdigit(a)  ( (a) >='0' && (a) <= '9' )
30 #define my_isxdigit(a) ( my_isdigit((a))               \
31                          || ((a) >= 'A' && (a) <= 'F') \
32                          || ((a) >= 'f' && (a) <= 'f') )
33
34 /**
35  * gpgme_new:
36  * @r_ctx: Returns the new context
37  * 
38  * Create a new context to be used with most of the other GPGME
39  * functions.  Use gpgme_release_contect() to release all resources
40  *
41  * Return value: An error code 
42  **/
43 GpgmeError
44 gpgme_new (GpgmeCtx *r_ctx)
45 {
46     GpgmeCtx c;
47
48     c = xtrycalloc ( 1, sizeof *c );
49     if (!c)
50         return mk_error (Out_Of_Core);
51     c->verbosity = 1;
52     c->use_armor = 1; /* fixme: reset this to 0 */
53     *r_ctx = c;
54     return 0;
55 }
56
57 /**
58  * gpgme_release:
59  * @c: Context to be released. 
60  * 
61  * Release all resources associated with the given context.
62  **/
63 void
64 gpgme_release ( GpgmeCtx c )
65 {
66     
67     _gpgme_gpg_release ( c->gpg ); 
68     _gpgme_release_result ( c );
69     _gpgme_key_release ( c->tmp_key );
70     gpgme_data_release ( c->notation );
71     /* fixme: release the key_queue */
72     xfree ( c );
73 }
74
75
76 void
77 _gpgme_release_result ( GpgmeCtx c )
78 {
79     switch (c->result_type) {
80       case RESULT_TYPE_NONE:
81         break;
82       case RESULT_TYPE_VERIFY:
83         _gpgme_release_verify_result ( c->result.verify );
84         break;
85       case RESULT_TYPE_DECRYPT:
86         _gpgme_release_decrypt_result ( c->result.decrypt );
87         break;
88       case RESULT_TYPE_SIGN:
89         _gpgme_release_sign_result ( c->result.sign );
90         break;
91     }
92
93     c->result.verify = NULL;
94     c->result_type = RESULT_TYPE_NONE;
95 }
96
97
98 /**
99  * gpgme_get_notation:
100  * @c: the context 
101  * 
102  * If there is notation data available from the last signature check, this
103  * function may be used to return this notation data as a string.  The string
104  * is an XML represantaton of that data embedded in a %<notation> container.
105  * 
106  * Return value: An XML string or NULL if no notation data is available.
107  **/
108 char *
109 gpgme_get_notation ( GpgmeCtx c )
110 {
111     if ( !c->notation )
112         return NULL;
113     return _gpgme_data_get_as_string ( c->notation );
114 }
115
116
117 /**
118  * gpgme_set_armor:
119  * @c: the contect 
120  * @yes: boolean value to set or clear that flag
121  * 
122  * Enable or disable the use of an ascii armor for all output.  
123  **/
124 void
125 gpgme_set_armor ( GpgmeCtx c, int yes )
126 {
127     if ( !c )
128         return; /* oops */
129     c->use_armor = yes;
130 }
131
132 /**
133  * gpgme_set_textmode:
134  * @c: the context 
135  * @yes: boolean flag whether textmode should be enabled
136  * 
137  * Enable or disable the use of the special textmode.  Textmode is for example
138  * used for MIME (RFC2015) signatures
139  **/
140 void
141 gpgme_set_textmode ( GpgmeCtx c, int yes )
142 {
143     if ( !c )
144         return; /* oops */
145     c->use_textmode = yes;
146 }
147
148 #if 0
149 void
150 gpgme_set_passphrase_cb ( GpgmeCtx c, GpgmePassphraseCb fnc, void *fncval )
151 {
152     if ( c ) {
153         c->passphrase_cb = fnc;
154         c->passphrase_cb_value = fncval;
155     }
156 }
157 #endif
158
159
160
161
162
163
164
165