~ubuntu-branches/ubuntu/lucid/gpgme1.0/lucid

« back to all changes in this revision

Viewing changes to assuan/assuan-defs.h

  • Committer: Bazaar Package Importer
  • Author(s): Jose Carlos Garcia Sogo
  • Date: 2004-11-16 21:36:40 UTC
  • Revision ID: james.westby@ubuntu.com-20041116213640-6ffmegu7bqe05u7l
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* assuan-defs.c - Internal definitions to Assuan
 
2
 *      Copyright (C) 2001, 2002 Free Software Foundation, Inc.
 
3
 *
 
4
 * This file is part of Assuan.
 
5
 *
 
6
 * Assuan is free software; you can redistribute it and/or modify it
 
7
 * under the terms of the GNU Lesser General Public License as
 
8
 * published by the Free Software Foundation; either version 2.1 of
 
9
 * the License, or (at your option) any later version.
 
10
 *
 
11
 * Assuan is distributed in the hope that it will be useful, but
 
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public
 
17
 * License along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 
 
19
 */
 
20
 
 
21
#ifndef ASSUAN_DEFS_H
 
22
#define ASSUAN_DEFS_H
 
23
 
 
24
#include <sys/types.h>
 
25
#include <sys/socket.h>
 
26
#include <sys/un.h>
 
27
#include <unistd.h>
 
28
 
 
29
#include "assuan.h"
 
30
 
 
31
#define LINELENGTH ASSUAN_LINELENGTH
 
32
 
 
33
struct cmdtbl_s
 
34
{
 
35
  const char *name;
 
36
  int (*handler)(ASSUAN_CONTEXT, char *line);
 
37
};
 
38
 
 
39
struct assuan_io
 
40
{
 
41
  /* Routine to read from input_fd.  */
 
42
  ssize_t (*read) (ASSUAN_CONTEXT, void *, size_t);
 
43
  /* Routine to write to output_fd.  */
 
44
  ssize_t (*write) (ASSUAN_CONTEXT, const void *, size_t);
 
45
  /* Send a file descriptor.  */
 
46
  AssuanError (*sendfd) (ASSUAN_CONTEXT, int);
 
47
  /* Receive a file descriptor.  */
 
48
  AssuanError (*receivefd) (ASSUAN_CONTEXT, int *);
 
49
};  
 
50
 
 
51
struct assuan_context_s
 
52
{
 
53
  AssuanError err_no;
 
54
  const char *err_str;
 
55
  int os_errno;  /* last system error number used with certain error codes*/
 
56
 
 
57
  int confidential;
 
58
  int is_server;  /* set if this is context belongs to a server */
 
59
  int in_inquire;
 
60
  char *hello_line;
 
61
  char *okay_line; /* see assan_set_okay_line() */
 
62
  
 
63
  void *user_pointer;  /* for assuan_[gs]et_pointer () */
 
64
 
 
65
  FILE *log_fp;
 
66
 
 
67
  struct {
 
68
    int fd;
 
69
    int eof;
 
70
    char line[LINELENGTH];
 
71
    int linelen;  /* w/o CR, LF - might not be the same as
 
72
                     strlen(line) due to embedded nuls. However a nul
 
73
                     is always written at this pos */
 
74
    struct {
 
75
      char line[LINELENGTH];
 
76
      int linelen ;
 
77
      int pending; /* i.e. at least one line is available in the attic */
 
78
    } attic;
 
79
  } inbound;
 
80
 
 
81
  struct {
 
82
    int fd;
 
83
    struct {
 
84
      FILE *fp;
 
85
      char line[LINELENGTH];
 
86
      int linelen; 
 
87
      int error;
 
88
    } data; 
 
89
  } outbound;
 
90
 
 
91
  int pipe_mode;  /* We are in pipe mode, i.e. we can handle just one
 
92
                     connection and must terminate then */
 
93
  pid_t pid;      /* In pipe mode, the pid of the child server process.  
 
94
                     In socket mode, the pid of the server */
 
95
  int listen_fd;  /* The fd we are listening on (used by socket servers) */
 
96
  int connected_fd; /* helper */
 
97
 
 
98
  pid_t client_pid; /* for a socket server the PID of the client or -1
 
99
                       if not available */
 
100
 
 
101
  /* Used for Unix domain sockets.  */
 
102
  struct sockaddr_un myaddr;
 
103
  struct sockaddr_un serveraddr;
 
104
  /* When reading from datagram sockets, we must read an entire
 
105
     message at a time.  This means that we have to do our own
 
106
     buffering to be able to get the semantics of read.  */
 
107
  void *domainbuffer;
 
108
  /* Offset of start of buffer.  */
 
109
  int domainbufferoffset;
 
110
  /* Bytes buffered.  */
 
111
  int domainbuffersize;
 
112
  /* Memory allocated.  */
 
113
  int domainbufferallocated;
 
114
 
 
115
  int *pendingfds;
 
116
  int pendingfdscount;
 
117
 
 
118
  void (*deinit_handler)(ASSUAN_CONTEXT);  
 
119
  int (*accept_handler)(ASSUAN_CONTEXT);
 
120
  int (*finish_handler)(ASSUAN_CONTEXT);
 
121
 
 
122
  struct cmdtbl_s *cmdtbl;
 
123
  size_t cmdtbl_used; /* used entries */
 
124
  size_t cmdtbl_size; /* allocated size of table */
 
125
 
 
126
  void (*bye_notify_fnc)(ASSUAN_CONTEXT);
 
127
  void (*reset_notify_fnc)(ASSUAN_CONTEXT);
 
128
  void (*cancel_notify_fnc)(ASSUAN_CONTEXT);
 
129
  int  (*option_handler_fnc)(ASSUAN_CONTEXT,const char*, const char*);
 
130
  void (*input_notify_fnc)(ASSUAN_CONTEXT, const char *);
 
131
  void (*output_notify_fnc)(ASSUAN_CONTEXT, const char *);
 
132
 
 
133
  int input_fd;   /* set by INPUT command */
 
134
  int output_fd;  /* set by OUTPUT command */
 
135
 
 
136
  /* io routines.  */
 
137
  struct assuan_io *io;
 
138
};
 
139
 
 
140
/*-- assuan-pipe-server.c --*/
 
141
int _assuan_new_context (ASSUAN_CONTEXT *r_ctx);
 
142
void _assuan_release_context (ASSUAN_CONTEXT ctx);
 
143
 
 
144
/*-- assuan-domain-connect.c --*/
 
145
/* Make a connection to the Unix domain socket NAME and return a new
 
146
   Assuan context in CTX.  SERVER_PID is currently not used but may
 
147
   become handy in the future.  */
 
148
AssuanError _assuan_domain_init (ASSUAN_CONTEXT *r_ctx,
 
149
                                 int rendezvousfd,
 
150
                                 pid_t peer);
 
151
 
 
152
/*-- assuan-handler.c --*/
 
153
int _assuan_register_std_commands (ASSUAN_CONTEXT ctx);
 
154
 
 
155
/*-- assuan-buffer.c --*/
 
156
int _assuan_read_line (ASSUAN_CONTEXT ctx);
 
157
int _assuan_cookie_write_data (void *cookie, const char *buffer, size_t size);
 
158
int _assuan_cookie_write_flush (void *cookie);
 
159
 
 
160
/*-- assuan-client.c --*/
 
161
AssuanError _assuan_read_from_server (ASSUAN_CONTEXT ctx, int *okay, int *off);
 
162
 
 
163
 
 
164
/*-- assuan-util.c --*/
 
165
void *_assuan_malloc (size_t n);
 
166
void *_assuan_calloc (size_t n, size_t m);
 
167
void *_assuan_realloc (void *p, size_t n);
 
168
void  _assuan_free (void *p);
 
169
 
 
170
#define xtrymalloc(a)    _assuan_malloc ((a))
 
171
#define xtrycalloc(a,b)  _assuan_calloc ((a),(b))
 
172
#define xtryrealloc(a,b) _assuan_realloc((a),(b))
 
173
#define xfree(a)         _assuan_free ((a))
 
174
 
 
175
#define set_error(c,e,t) assuan_set_error ((c), ASSUAN_ ## e, (t))
 
176
 
 
177
void _assuan_log_print_buffer (FILE *fp, const void *buffer, size_t  length);
 
178
void _assuan_log_sanitized_string (const char *string);
 
179
 
 
180
/*-- assuan-io.c --*/
 
181
ssize_t _assuan_simple_read (ASSUAN_CONTEXT ctx, void *buffer, size_t size);
 
182
ssize_t _assuan_simple_write (ASSUAN_CONTEXT ctx, const void *buffer,
 
183
                              size_t size);
 
184
 
 
185
#ifdef HAVE_FOPENCOOKIE
 
186
/* We have to implement funopen in terms of glibc's fopencookie. */
 
187
FILE *funopen(const void *cookie, cookie_read_function_t *readfn,
 
188
              cookie_write_function_t *writefn,
 
189
              cookie_seek_function_t *seekfn,
 
190
              cookie_close_function_t *closefn);
 
191
#endif /*HAVE_FOPENCOOKIE*/
 
192
 
 
193
#endif /*ASSUAN_DEFS_H*/
 
194