Imported Upstream version 1.12.0
[platform/upstream/gpgme.git] / src / context.h
1 /* context.h - Definitions for a GPGME context.
2    Copyright (C) 2000 Werner Koch (dd9jn)
3    Copyright (C) 2001, 2002, 2003, 2004, 2005, 2010 g10 Code GmbH
4
5    This file is part of GPGME.
6
7    GPGME is free software; you can redistribute it and/or modify it
8    under the terms of the GNU Lesser General Public License as
9    published by the Free Software Foundation; either version 2.1 of
10    the License, or (at your option) any later version.
11
12    GPGME is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    Lesser General Public License for more details.
16
17    You should have received a copy of the GNU Lesser General Public
18    License along with this program; if not, see <https://www.gnu.org/licenses/>.
19  */
20
21 #ifndef CONTEXT_H
22 #define CONTEXT_H
23
24 #include "gpgme.h"
25 #include "engine.h"
26 #include "wait.h"
27 #include "sema.h"
28
29 \f
30 extern gpgme_error_t _gpgme_selftest;
31
32 /* Operations might require to remember arbitrary information and data
33    objects during invocations of the status handler.  The
34    ctx_op_data structure provides a generic framework to hook in
35    such additional data.  */
36 typedef enum
37   {
38     OPDATA_DECRYPT, OPDATA_SIGN, OPDATA_ENCRYPT, OPDATA_PASSPHRASE,
39     OPDATA_IMPORT, OPDATA_GENKEY, OPDATA_KEYLIST, OPDATA_EDIT,
40     OPDATA_VERIFY, OPDATA_TRUSTLIST, OPDATA_ASSUAN, OPDATA_VFS_MOUNT,
41     OPDATA_PASSWD, OPDATA_EXPORT, OPDATA_KEYSIGN, OPDATA_TOFU_POLICY,
42     OPDATA_QUERY_SWDB
43   } ctx_op_data_id_t;
44
45
46 /* "gpgmeres" in ASCII.  */
47 #define CTX_OP_DATA_MAGIC 0x736572656d677067ULL
48 struct ctx_op_data
49 {
50   /* A magic word just to make sure people don't deallocate something
51      that ain't a result structure.  */
52   unsigned long long magic;
53
54   /* The next element in the linked list, or NULL if this is the last
55      element.  Used by op data structures linked into a context.  */
56   struct ctx_op_data *next;
57
58   /* The type of the hook data, which can be used by a routine to
59      lookup the hook data.  */
60   ctx_op_data_id_t type;
61
62   /* The function to release HOOK and all its associated resources.
63      Can be NULL if no special deallocation routine is necessary.  */
64   void (*cleanup) (void *hook);
65
66   /* The hook that points to the operation data.  */
67   void *hook;
68
69   /* The number of outstanding references.  */
70   int references;
71 };
72 typedef struct ctx_op_data *ctx_op_data_t;
73
74 \f
75 /* The context defines an environment in which crypto operations can
76    be performed (sequentially).  */
77 struct gpgme_context
78 {
79   DECLARE_LOCK (lock);
80
81   /* True if the context was canceled asynchronously.  */
82   int canceled;
83
84   /* The engine info for this context.  */
85   gpgme_engine_info_t engine_info;
86
87   /* The protocol used by this context.  */
88   gpgme_protocol_t protocol;
89
90   /* The running engine process.  */
91   engine_t engine;
92
93   /* Engine's sub protocol.  */
94   gpgme_protocol_t sub_protocol;
95
96   /* True if armor mode should be used.  */
97   unsigned int use_armor : 1;
98
99   /* True if text mode should be used.  */
100   unsigned int use_textmode : 1;
101
102   /* True if offline mode should be used.  */
103   unsigned int offline : 1;
104
105   /* True if a status callback shall be called for nearly all status
106    * lines.  */
107   unsigned int full_status : 1;
108
109   /* The Tofu info has a human readable string which is presented to
110    * the user in a directly usable format.  By enabling this flag the
111    * unmodified string, as received form gpg, will be returned.  */
112   unsigned int raw_description : 1;
113
114   /* True if session keys should be exported upon decryption.  */
115   unsigned int export_session_keys : 1;
116
117   /* True if a Pinentry was launched during the last operation.  This
118    * flag is cleared with each operation.  */
119   unsigned int redraw_suggested : 1;
120
121   /* True if the option --auto-key-retrieve shall be passed to gpg.  */
122   unsigned int auto_key_retrieve : 1;
123
124   /* Do not use the symmtric encryption passphrase cache.  */
125   unsigned int no_symkey_cache : 1;
126
127   /* Pass --ignore-mdc-error to gpg.  Note that this flag is reset
128    * after the operation.  */
129   unsigned int ignore_mdc_error : 1;
130
131   /* Flags for keylist mode.  */
132   gpgme_keylist_mode_t keylist_mode;
133
134   /* The current pinentry mode.  */
135   gpgme_pinentry_mode_t pinentry_mode;
136
137   /* Number of certs to be included.  */
138   unsigned int include_certs;
139
140   /* The actual number of keys in SIGNERS, the allocated size of the
141    * array, and the array with the signing keys.  */
142   unsigned int signers_len;
143   unsigned int signers_size;
144   gpgme_key_t *signers;
145
146   /* The signature notations for this context.  */
147   gpgme_sig_notation_t sig_notations;
148
149   /* The sender's addr-spec or NULL.  */
150   char *sender;
151
152   /* The gpg specific override session key or NULL. */
153   char *override_session_key;
154
155   /* The optional request origin.  */
156   char *request_origin;
157
158   /* The optional auto key locate options.  */
159   char *auto_key_locate;
160
161   /* The locale for the pinentry.  */
162   char *lc_ctype;
163   char *lc_messages;
164
165   /* The operation data hooked into the context.  */
166   ctx_op_data_t op_data;
167
168   /* The user provided passphrase callback and its hook value.  */
169   gpgme_passphrase_cb_t passphrase_cb;
170   void *passphrase_cb_value;
171
172   /* The user provided progress callback and its hook value.  */
173   gpgme_progress_cb_t progress_cb;
174   void *progress_cb_value;
175
176   /* The user provided status callback and its hook value.  */
177   gpgme_status_cb_t status_cb;
178   void *status_cb_value;
179
180   /* A list of file descriptors in active use by the current
181      operation.  */
182   struct fd_table fdt;
183   struct gpgme_io_cbs io_cbs;
184 };
185
186 #endif  /* CONTEXT_H */