Imported Upstream version 1.8.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   /* Flags for keylist mode.  */
118   gpgme_keylist_mode_t keylist_mode;
119
120   /* The current pinnetry mode.  */
121   gpgme_pinentry_mode_t pinentry_mode;
122
123   /* Number of certs to be included.  */
124   unsigned int include_certs;
125
126   /* The actual number of keys in SIGNERS, the allocated size of the
127    * array, and the array with the signing keys.  */
128   unsigned int signers_len;
129   unsigned int signers_size;
130   gpgme_key_t *signers;
131
132   /* The signature notations for this context.  */
133   gpgme_sig_notation_t sig_notations;
134
135   /* The sender's addr-spec or NULL.  */
136   char *sender;
137
138   /* The gpg specific override session key or NULL. */
139   char *override_session_key;
140
141   /* The locale for the pinentry.  */
142   char *lc_ctype;
143   char *lc_messages;
144
145   /* The operation data hooked into the context.  */
146   ctx_op_data_t op_data;
147
148   /* The user provided passphrase callback and its hook value.  */
149   gpgme_passphrase_cb_t passphrase_cb;
150   void *passphrase_cb_value;
151
152   /* The user provided progress callback and its hook value.  */
153   gpgme_progress_cb_t progress_cb;
154   void *progress_cb_value;
155
156   /* The user provided status callback and its hook value.  */
157   gpgme_status_cb_t status_cb;
158   void *status_cb_value;
159
160   /* A list of file descriptors in active use by the current
161      operation.  */
162   struct fd_table fdt;
163   struct gpgme_io_cbs io_cbs;
164 };
165
166 #endif  /* CONTEXT_H */