Imported Upstream version 1.7.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 <http://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   } ctx_op_data_id_t;
43
44
45 /* "gpgmeres" in ASCII.  */
46 #define CTX_OP_DATA_MAGIC 0x736572656d677067ULL
47 struct ctx_op_data
48 {
49   /* A magic word just to make sure people don't deallocate something
50      that ain't a result structure.  */
51   unsigned long long magic;
52
53   /* The next element in the linked list, or NULL if this is the last
54      element.  Used by op data structures linked into a context.  */
55   struct ctx_op_data *next;
56
57   /* The type of the hook data, which can be used by a routine to
58      lookup the hook data.  */
59   ctx_op_data_id_t type;
60
61   /* The function to release HOOK and all its associated resources.
62      Can be NULL if no special deallocation routine is necessary.  */
63   void (*cleanup) (void *hook);
64
65   /* The hook that points to the operation data.  */
66   void *hook;
67
68   /* The number of outstanding references.  */
69   int references;
70 };
71 typedef struct ctx_op_data *ctx_op_data_t;
72
73 \f
74 /* The context defines an environment in which crypto operations can
75    be performed (sequentially).  */
76 struct gpgme_context
77 {
78   DECLARE_LOCK (lock);
79
80   /* True if the context was canceled asynchronously.  */
81   int canceled;
82
83   /* The engine info for this context.  */
84   gpgme_engine_info_t engine_info;
85
86   /* The protocol used by this context.  */
87   gpgme_protocol_t protocol;
88
89   /* The running engine process.  */
90   engine_t engine;
91
92   /* Engine's sub protocol.  */
93   gpgme_protocol_t sub_protocol;
94
95   /* True if armor mode should be used.  */
96   unsigned int use_armor : 1;
97
98   /* True if text mode should be used.  */
99   unsigned int use_textmode : 1;
100
101   /* True if offline mode should be used.  */
102   unsigned int offline : 1;
103
104   /* True if a status callback shall be called for nearly all status
105    * lines.  */
106   unsigned int full_status : 1;
107
108   /* The Tofu info has a human readable string which is presented to
109    * the user in a directly usable format.  By enabling this flag the
110    * unmodified string, as received form gpg, will be returned.  */
111   unsigned int raw_description : 1;
112
113   /* Flags for keylist mode.  */
114   gpgme_keylist_mode_t keylist_mode;
115
116   /* The current pinnetry mode.  */
117   gpgme_pinentry_mode_t pinentry_mode;
118
119   /* Number of certs to be included.  */
120   unsigned int include_certs;
121
122   /* The number of keys in signers.  */
123   unsigned int signers_len;
124
125   /* Size of the following array.  */
126   unsigned int signers_size;
127   gpgme_key_t *signers;
128
129   /* The signature notations for this context.  */
130   gpgme_sig_notation_t sig_notations;
131
132   /* The locale for the pinentry.  */
133   char *lc_ctype;
134   char *lc_messages;
135
136   /* The operation data hooked into the context.  */
137   ctx_op_data_t op_data;
138
139   /* The user provided passphrase callback and its hook value.  */
140   gpgme_passphrase_cb_t passphrase_cb;
141   void *passphrase_cb_value;
142
143   /* The user provided progress callback and its hook value.  */
144   gpgme_progress_cb_t progress_cb;
145   void *progress_cb_value;
146
147   /* The user provided status callback and its hook value.  */
148   gpgme_status_cb_t status_cb;
149   void *status_cb_value;
150
151   /* A list of file descriptors in active use by the current
152      operation.  */
153   struct fd_table fdt;
154   struct gpgme_io_cbs io_cbs;
155 };
156
157 #endif  /* CONTEXT_H */