Imported Upstream version 1.3.2
[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
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   /* Flags for keylist mode.  */
102   gpgme_keylist_mode_t keylist_mode;
103
104   /* Number of certs to be included.  */
105   unsigned int include_certs;
106
107   /* The number of keys in signers.  */
108   unsigned int signers_len;
109
110   /* Size of the following array.  */
111   unsigned int signers_size;
112   gpgme_key_t *signers;
113
114   /* The signature notations for this context.  */
115   gpgme_sig_notation_t sig_notations;
116
117   /* The locale for the pinentry.  */
118   char *lc_ctype;
119   char *lc_messages;
120
121   /* The operation data hooked into the context.  */
122   ctx_op_data_t op_data;
123
124   /* The user provided passphrase callback and its hook value.  */
125   gpgme_passphrase_cb_t passphrase_cb;
126   void *passphrase_cb_value;
127
128   /* The user provided progress callback and its hook value.  */
129   gpgme_progress_cb_t progress_cb;
130   void *progress_cb_value;
131
132   /* A list of file descriptors in active use by the current
133      operation.  */
134   struct fd_table fdt;
135   struct gpgme_io_cbs io_cbs;
136 };
137
138 #endif  /* CONTEXT_H */