mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-03 12:11:33 +01:00
Added Libestream.
This commit is contained in:
parent
3504abfa29
commit
0271a8ef1d
@ -2,7 +2,7 @@
|
||||
|
||||
**MERGED FROM MAIN BRANCH, RE-PATCHED**
|
||||
|
||||
* command-ssh.c: New file.
|
||||
* command-ssh.c, estream.c, estream.h: New file.
|
||||
|
||||
* findkey.c (modify_description): New function.
|
||||
(agent_key_from_file): New variables: comment, comment_sexp,
|
||||
|
2376
agent/estream.c
Normal file
2376
agent/estream.c
Normal file
File diff suppressed because it is too large
Load Diff
159
agent/estream.h
Normal file
159
agent/estream.h
Normal file
@ -0,0 +1,159 @@
|
||||
/* estream.h - Extended stream I/O/ Library
|
||||
Copyright (C) 2004 g10 Code GmbH
|
||||
|
||||
This file is part of Libestream.
|
||||
|
||||
Libestream is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
Libestream is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Libestream; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
02111-1307, USA. */
|
||||
|
||||
#ifndef ESTREAM_H
|
||||
#define ESTREAM_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
typedef struct estream_public *estream_t;
|
||||
typedef struct estream_internal *estream_internal_t;
|
||||
|
||||
/* This struct is entirely private - use it and you will shoot
|
||||
yourself in the foot. */
|
||||
struct estream_public
|
||||
{
|
||||
estream_internal_t internal;
|
||||
unsigned char *buffer;
|
||||
size_t buffer_size;
|
||||
size_t data_size;
|
||||
off_t data_offset;
|
||||
size_t data_flushed;
|
||||
unsigned char *unread_buffer;
|
||||
size_t unread_buffer_size;
|
||||
off_t unread_data_offset;
|
||||
unsigned int dirty: 1;
|
||||
};
|
||||
|
||||
typedef ssize_t (*es_cookie_read_function_t) (void *cookie,
|
||||
char *buffer, size_t size);
|
||||
typedef ssize_t (*es_cookie_write_function_t) (void *cookie,
|
||||
const char *buffer, size_t size);
|
||||
typedef int (*es_cookie_seek_function_t) (void *cookie,
|
||||
off_t *pos, int whence);
|
||||
typedef int (*es_cookie_close_function_t) (void *cookie);
|
||||
|
||||
typedef struct es_cookie_io_functions
|
||||
{
|
||||
es_cookie_read_function_t func_read;
|
||||
es_cookie_write_function_t func_write;
|
||||
es_cookie_seek_function_t func_seek;
|
||||
es_cookie_close_function_t func_close;
|
||||
} es_cookie_io_functions_t;
|
||||
|
||||
#define restrict
|
||||
|
||||
int es_init (void);
|
||||
|
||||
estream_t es_fopen (const char * restrict path, const char * restrict mode);
|
||||
estream_t es_mopen (unsigned char *data, size_t data_n, size_t data_size,
|
||||
unsigned int grow,
|
||||
void *(*func_realloc) (void *mem, size_t size),
|
||||
void (*func_free) (void *mem),
|
||||
const char * restrict mode);
|
||||
estream_t es_open_memstream (char **ptr, size_t *size);
|
||||
estream_t es_fdopen (int filedes, const char *mode);
|
||||
estream_t es_freopen (const char *path, const char *mode, estream_t stream);
|
||||
estream_t es_fopencookie (void *cookie,
|
||||
const char * restrict mode, es_cookie_io_functions_t functions);
|
||||
int es_fclose (estream_t stream);
|
||||
int es_fileno (estream_t stream);
|
||||
int es_fileno_unlocked (estream_t stream);
|
||||
|
||||
void es_flockfile (estream_t stream);
|
||||
int es_ftrylockfile (estream_t stream);
|
||||
void es_funlockfile (estream_t stream);
|
||||
|
||||
int es_feof (estream_t stream);
|
||||
int es_feof_unlocked (estream_t stream);
|
||||
int es_ferror (estream_t stream);
|
||||
int es_ferror_unlocked (estream_t stream);
|
||||
void es_clearerr (estream_t stream);
|
||||
void es_clearerr_unlocked (estream_t stream);
|
||||
|
||||
int es_fflush (estream_t stream);
|
||||
int es_fseek (estream_t stream, long int offset, int whence);
|
||||
int es_fseeko (estream_t stream, off_t offset, int whence);
|
||||
long int es_ftell (estream_t stream);
|
||||
off_t es_ftello (estream_t stream);
|
||||
void es_rewind (estream_t stream);
|
||||
|
||||
int es_fgetc (estream_t stream);
|
||||
int es_fputc (int c, estream_t stream);
|
||||
|
||||
int _es_getc_underflow (estream_t stream);
|
||||
int _es_putc_overflow (int c, estream_t stream);
|
||||
|
||||
#define es_getc_unlocked(stream) \
|
||||
(((! (stream)->dirty) \
|
||||
&& ((stream)->data_offset < (stream)->data_size) \
|
||||
&& (! (stream)->unread_data_offset)) ? \
|
||||
((int) (unsigned char) \
|
||||
(stream)->buffer[((stream)->data_offset)++]) : \
|
||||
_es_getc_underflow ((stream)))
|
||||
|
||||
#define es_putc_unlocked(c, stream) \
|
||||
(((stream)->dirty \
|
||||
&& ((stream)->data_offset < (stream)->buffer_size) \
|
||||
&& (c != '\n')) ? \
|
||||
((int) (unsigned char) \
|
||||
(stream)->buffer[((stream)->data_offset)++] = (c)) : \
|
||||
_es_putc_overflow ((c), (stream)))
|
||||
|
||||
#define es_getc(stream) \
|
||||
es_fgetc (stream)
|
||||
#define es_putc(c, stream) \
|
||||
es_fputc (c, stream)
|
||||
|
||||
int es_ungetc (int c, estream_t stream);
|
||||
|
||||
int es_read (estream_t stream,
|
||||
char *buffer, size_t bytes_to_read, size_t *bytes_read);
|
||||
int es_write (estream_t stream,
|
||||
const char *buffer, size_t bytes_to_write, size_t *bytes_written);
|
||||
|
||||
size_t es_fread (void * restrict ptr, size_t size, size_t nitems,
|
||||
estream_t restrict stream);
|
||||
size_t es_fwrite (const void * restrict ptr, size_t size, size_t memb,
|
||||
estream_t restrict stream);
|
||||
|
||||
char *es_fgets (char * restrict s, int n, estream_t restrict stream);
|
||||
int es_fputs (const char * restrict s, estream_t restrict stream);
|
||||
|
||||
ssize_t es_getline (char **lineptr, size_t *n, estream_t stream);
|
||||
|
||||
int es_fprintf (estream_t restrict stream, const char * restrict format, ...);
|
||||
int es_vfprintf (estream_t restrict stream, const char *restrict format,
|
||||
va_list ap);
|
||||
|
||||
int es_setvbuf (estream_t restrict stream,
|
||||
char * restrict buf, int mode, size_t size);
|
||||
void es_setbuf (estream_t restrict stream, char * restrict buf);
|
||||
|
||||
estream_t es_tmpfile (void);
|
||||
|
||||
void es_opaque_set (estream_t stream, void *opaque);
|
||||
void *es_opaque_get (estream_t stream);
|
||||
|
||||
#endif
|
@ -1,41 +0,0 @@
|
||||
/* stream.c - Stream I/O/ layer
|
||||
Copyright (C) 2004 g10 Code GmbH
|
||||
|
||||
This file is part of libgpg-stream.
|
||||
|
||||
libgpg-stream is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
libgpg-stream is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with libgpg-stream; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
02111-1307, USA. */
|
||||
|
||||
#ifndef GPG_STREAM_CONFIG_H
|
||||
#define GPG_STREAM_CONFIG_H
|
||||
|
||||
#define USE_PTH
|
||||
|
||||
#ifdef USE_PTH
|
||||
#include <pth.h>
|
||||
|
||||
#define READ pth_read
|
||||
#define WRITE pth_write
|
||||
|
||||
#else
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#define READ read
|
||||
#define WRITE write
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
1440
agent/gpg-stream.c
1440
agent/gpg-stream.c
File diff suppressed because it is too large
Load Diff
@ -1,166 +0,0 @@
|
||||
/* stream.h - Stream I/O layer
|
||||
Copyright (C) 2004 g10 Code GmbH
|
||||
|
||||
This file is part of libgpg-stream.
|
||||
|
||||
libgpg-stream is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
libgpg-stream is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with libgpg-stream; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
02111-1307, USA. */
|
||||
|
||||
#ifndef GPG_STREAM_H
|
||||
#define GPG_STREAM_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <gpg-error.h>
|
||||
|
||||
|
||||
|
||||
#define STREAM_BLOCK_SIZE 1024
|
||||
|
||||
|
||||
|
||||
typedef struct gpg_stream *gpg_stream_t;
|
||||
|
||||
typedef gpg_error_t (*gpg_stream_func_create_t) (void **handle,
|
||||
void *spec,
|
||||
unsigned int flags);
|
||||
typedef gpg_error_t (*gpg_stream_func_read_t) (void *handle,
|
||||
char *buffer,
|
||||
size_t bytes_to_read,
|
||||
size_t *bytes_read);
|
||||
typedef gpg_error_t (*gpg_stream_func_write_t) (void *handle,
|
||||
const char *buffer,
|
||||
size_t bytes_to_write,
|
||||
size_t *bytes_written);
|
||||
typedef gpg_error_t (*gpg_stream_func_seek_t) (void *handle,
|
||||
off_t pos,
|
||||
int whence);
|
||||
typedef gpg_error_t (*gpg_stream_func_stat_t) (void *handle,
|
||||
size_t *size);
|
||||
typedef gpg_error_t (*gpg_stream_func_destroy_t) (void *handle);
|
||||
|
||||
typedef struct gpg_stream_functions
|
||||
{
|
||||
gpg_stream_func_create_t func_create;
|
||||
gpg_stream_func_read_t func_read;
|
||||
gpg_stream_func_write_t func_write;
|
||||
gpg_stream_func_seek_t func_seek;
|
||||
gpg_stream_func_stat_t func_stat;
|
||||
gpg_stream_func_destroy_t func_destroy;
|
||||
} gpg_stream_functions_t;
|
||||
|
||||
typedef void *(*gpg_stream_func_realloc_t) (void *mem, size_t size);
|
||||
typedef void (*gpg_stream_func_free_t) (void *mem);
|
||||
|
||||
typedef struct gpg_stream_buffer_spec
|
||||
{
|
||||
size_t block_size;
|
||||
gpg_stream_func_realloc_t func_realloc;
|
||||
gpg_stream_func_free_t func_free;
|
||||
} gpg_stream_buffer_spec_t;
|
||||
|
||||
|
||||
#define GPG_STREAM_FLAG_READ (1 << 0)
|
||||
#define GPG_STREAM_FLAG_WRITE (1 << 1)
|
||||
#define GPG_STREAM_FLAG_EXCLUSIVE (1 << 2)
|
||||
#define GPG_STREAM_FLAG_APPEND (1 << 3)
|
||||
#define GPG_STREAM_FLAG_CREATE (1 << 4)
|
||||
#define GPG_STREAM_FLAG_NONBLOCK (1 << 5)
|
||||
#define GPG_STREAM_FLAG_TRUNCATE (1 << 6)
|
||||
#define GPG_STREAM_FLAG_BINARY (1 << 7)
|
||||
|
||||
gpg_error_t gpg_stream_create (gpg_stream_t *stream,
|
||||
gpg_stream_buffer_spec_t *buffer_spec,
|
||||
void *spec,
|
||||
unsigned int flags,
|
||||
gpg_stream_functions_t functions);
|
||||
|
||||
gpg_error_t gpg_stream_create_file (gpg_stream_t *stream,
|
||||
const char *filename,
|
||||
unsigned int flags);
|
||||
|
||||
gpg_error_t gpg_stream_create_fd (gpg_stream_t *stream,
|
||||
int fd,
|
||||
unsigned int flags);
|
||||
|
||||
gpg_error_t gpg_stream_destroy (gpg_stream_t stream);
|
||||
|
||||
gpg_error_t gpg_stream_read (gpg_stream_t stream,
|
||||
char *buffer,
|
||||
size_t bytes_to_read,
|
||||
size_t *bytes_read);
|
||||
|
||||
gpg_error_t gpg_stream_write (gpg_stream_t stream,
|
||||
const char *buffer,
|
||||
size_t bytes_to_write,
|
||||
size_t *bytes_written);
|
||||
|
||||
gpg_error_t gpg_stream_read_line (gpg_stream_t stream,
|
||||
char **line,
|
||||
size_t *line_length);
|
||||
|
||||
gpg_error_t gpg_stream_print_va (gpg_stream_t stream,
|
||||
const char *format,
|
||||
va_list ap);
|
||||
|
||||
gpg_error_t gpg_stream_print (gpg_stream_t stream,
|
||||
const char *format,
|
||||
...);
|
||||
|
||||
gpg_error_t gpg_stream_flush (gpg_stream_t stream);
|
||||
|
||||
gpg_error_t gpg_stream_peek (gpg_stream_t stream,
|
||||
char **buffer,
|
||||
size_t *size);
|
||||
|
||||
gpg_error_t gpg_stream_seek (gpg_stream_t stream,
|
||||
off_t offset,
|
||||
int whence);
|
||||
|
||||
gpg_error_t gpg_stream_stat (gpg_stream_t stream,
|
||||
size_t *size);
|
||||
|
||||
gpg_error_t gpg_stream_copy (gpg_stream_t dst,
|
||||
gpg_stream_t src);
|
||||
|
||||
typedef struct gpg_stream_spec_mem
|
||||
{
|
||||
char *memory;
|
||||
size_t memory_size;
|
||||
unsigned int grow: 1;
|
||||
size_t block_size;
|
||||
void *(*func_realloc) (void *mem, size_t size);
|
||||
void (*func_free) (void *mem);
|
||||
} gpg_stream_spec_mem_t;
|
||||
|
||||
extern gpg_stream_functions_t gpg_stream_functions_mem;
|
||||
|
||||
typedef struct gpg_stream_spec_file
|
||||
{
|
||||
const char *filename;
|
||||
mode_t mode;
|
||||
} gpg_stream_spec_file_t;
|
||||
|
||||
extern gpg_stream_functions_t gpg_stream_functions_file;
|
||||
|
||||
typedef struct gpg_stream_spec_fd
|
||||
{
|
||||
int fd;
|
||||
} gpg_stream_spec_fd_t;
|
||||
|
||||
extern gpg_stream_functions_t gpg_stream_functions_fd;
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user