2009-06-18 Marcus Brinkmann <marcus@g10code.de>
[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 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, write to the Free Software
19    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20    02111-1307, USA.  */
21
22 #ifndef CONTEXT_H
23 #define CONTEXT_H
24
25 #include "gpgme.h"
26 #include "engine.h"
27 #include "wait.h"
28 #include "sema.h"
29
30 \f
31 extern gpgme_error_t _gpgme_selftest;
32
33 /* Operations might require to remember arbitrary information and data
34    objects during invocations of the status handler.  The
35    ctx_op_data structure provides a generic framework to hook in
36    such additional data.  */
37 typedef enum
38   {
39     OPDATA_DECRYPT, OPDATA_SIGN, OPDATA_ENCRYPT, OPDATA_PASSPHRASE,
40     OPDATA_IMPORT, OPDATA_GENKEY, OPDATA_KEYLIST, OPDATA_EDIT,
41     OPDATA_VERIFY, OPDATA_TRUSTLIST, OPDATA_ASSUAN
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   /* True if armor mode should be used.  */
93   unsigned int use_armor : 1;
94
95   /* True if text mode should be used.  */
96   unsigned int use_textmode : 1;
97
98   /* Flags for keylist mode.  */
99   gpgme_keylist_mode_t keylist_mode;
100
101   /* Number of certs to be included.  */
102   unsigned int include_certs;
103
104   /* The number of keys in signers.  */
105   unsigned int signers_len;
106
107   /* Size of the following array.  */
108   unsigned int signers_size;
109   gpgme_key_t *signers;
110
111   /* The signature notations for this context.  */
112   gpgme_sig_notation_t sig_notations;
113
114   /* The locale for the pinentry.  */
115   char *lc_ctype;
116   char *lc_messages;
117
118   /* The operation data hooked into the context.  */
119   ctx_op_data_t op_data;
120
121   /* The user provided passphrase callback and its hook value.  */
122   gpgme_passphrase_cb_t passphrase_cb;
123   void *passphrase_cb_value;
124
125   /* The user provided progress callback and its hook value.  */
126   gpgme_progress_cb_t progress_cb;
127   void *progress_cb_value;
128
129   /* A list of file descriptors in active use by the current
130      operation.  */
131   struct fd_table fdt;
132   struct gpgme_io_cbs io_cbs;
133 };
134
135 #endif  /* CONTEXT_H */