2002-07-30 19:38:54 +02:00
|
|
|
/* assuan.c - Definitions for the Assuan protocol
|
2002-01-21 13:03:14 +01:00
|
|
|
* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
|
2001-11-06 16:42:37 +01:00
|
|
|
*
|
2002-07-30 19:38:54 +02:00
|
|
|
* This file is part of Assuan.
|
2001-11-06 16:42:37 +01:00
|
|
|
*
|
2002-07-30 19:38:54 +02:00
|
|
|
* Assuan is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2.1 of
|
|
|
|
* the License, or (at your option) any later version.
|
2001-11-06 16:42:37 +01:00
|
|
|
*
|
2002-07-30 19:38:54 +02:00
|
|
|
* Assuan 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.
|
2001-11-06 16:42:37 +01:00
|
|
|
*
|
2002-07-30 19:38:54 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
2001-11-06 16:42:37 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ASSUAN_H
|
|
|
|
#define ASSUAN_H
|
|
|
|
|
2001-11-24 22:20:22 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
2002-05-23 11:07:12 +02:00
|
|
|
#include <unistd.h> /* for ssize_t */
|
2001-11-24 22:20:22 +01:00
|
|
|
|
2001-11-06 16:42:37 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#if 0
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
ASSUAN_No_Error = 0,
|
|
|
|
ASSUAN_General_Error = 1,
|
|
|
|
ASSUAN_Out_Of_Core = 2,
|
|
|
|
ASSUAN_Invalid_Value = 3,
|
2001-11-07 18:43:05 +01:00
|
|
|
ASSUAN_Timeout = 4,
|
|
|
|
ASSUAN_Read_Error = 5,
|
|
|
|
ASSUAN_Write_Error = 6,
|
2001-11-25 15:53:39 +01:00
|
|
|
ASSUAN_Problem_Starting_Server = 7,
|
2001-12-06 00:45:01 +01:00
|
|
|
ASSUAN_Not_A_Server = 8,
|
|
|
|
ASSUAN_Not_A_Client = 9,
|
|
|
|
ASSUAN_Nested_Commands = 10,
|
|
|
|
ASSUAN_Invalid_Response = 11,
|
|
|
|
ASSUAN_No_Data_Callback = 12,
|
|
|
|
ASSUAN_No_Inquire_Callback = 13,
|
2001-12-12 10:17:23 +01:00
|
|
|
ASSUAN_Connect_Failed = 14,
|
2002-01-19 19:20:15 +01:00
|
|
|
ASSUAN_Accept_Failed = 15,
|
2001-11-06 16:42:37 +01:00
|
|
|
|
|
|
|
/* error codes above 99 are meant as status codes */
|
2001-11-07 18:43:05 +01:00
|
|
|
ASSUAN_Not_Implemented = 100,
|
|
|
|
ASSUAN_Server_Fault = 101,
|
|
|
|
ASSUAN_Invalid_Command = 102,
|
|
|
|
ASSUAN_Unknown_Command = 103,
|
|
|
|
ASSUAN_Syntax_Error = 104,
|
|
|
|
ASSUAN_Parameter_Error = 105,
|
|
|
|
ASSUAN_Parameter_Conflict = 106,
|
|
|
|
ASSUAN_Line_Too_Long = 107,
|
|
|
|
ASSUAN_Line_Not_Terminated = 108,
|
|
|
|
ASSUAN_No_Input = 109,
|
|
|
|
ASSUAN_No_Output = 110,
|
2001-11-24 15:26:27 +01:00
|
|
|
ASSUAN_Canceled = 111,
|
2001-11-25 15:53:39 +01:00
|
|
|
ASSUAN_Unsupported_Algorithm = 112,
|
2001-11-26 10:07:11 +01:00
|
|
|
ASSUAN_Server_Resource_Problem = 113,
|
|
|
|
ASSUAN_Server_IO_Error = 114,
|
|
|
|
ASSUAN_Server_Bug = 115,
|
|
|
|
ASSUAN_No_Data_Available = 116,
|
2001-12-06 00:45:01 +01:00
|
|
|
ASSUAN_Invalid_Data = 117,
|
|
|
|
ASSUAN_Unexpected_Command = 118,
|
|
|
|
ASSUAN_Too_Much_Data = 119,
|
2002-01-11 18:07:05 +01:00
|
|
|
ASSUAN_Inquire_Unknown = 120,
|
|
|
|
ASSUAN_Inquire_Error = 121,
|
2002-01-20 17:49:34 +01:00
|
|
|
ASSUAN_Invalid_Option = 122,
|
2002-02-28 12:05:57 +01:00
|
|
|
ASSUAN_Invalid_Index = 123,
|
2002-03-04 11:35:34 +01:00
|
|
|
ASSUAN_Unexpected_Status = 124,
|
|
|
|
ASSUAN_Unexpected_Data = 125,
|
|
|
|
ASSUAN_Invalid_Status = 126,
|
2001-11-26 10:07:11 +01:00
|
|
|
|
2002-02-18 21:45:52 +01:00
|
|
|
ASSUAN_Not_Confirmed = 128,
|
|
|
|
|
2001-11-26 10:07:11 +01:00
|
|
|
ASSUAN_Bad_Certificate = 201,
|
2002-08-16 16:24:25 +02:00
|
|
|
ASSUAN_Bad_Certificate_Chain = 202,
|
2001-11-26 10:07:11 +01:00
|
|
|
ASSUAN_Missing_Certificate = 203,
|
|
|
|
ASSUAN_Bad_Signature = 204,
|
|
|
|
ASSUAN_No_Agent = 205,
|
|
|
|
ASSUAN_Agent_Error = 206,
|
|
|
|
ASSUAN_No_Public_Key = 207,
|
2001-11-26 14:08:00 +01:00
|
|
|
ASSUAN_No_Secret_Key = 208,
|
2001-12-11 13:27:10 +01:00
|
|
|
ASSUAN_Invalid_Name = 209,
|
2001-11-06 16:42:37 +01:00
|
|
|
|
|
|
|
ASSUAN_Cert_Revoked = 301,
|
|
|
|
ASSUAN_No_CRL_For_Cert = 302,
|
2001-12-06 00:45:01 +01:00
|
|
|
ASSUAN_CRL_Too_Old = 303,
|
2002-01-15 14:02:13 +01:00
|
|
|
ASSUAN_Not_Trusted = 304,
|
2001-11-06 16:42:37 +01:00
|
|
|
|
2002-02-18 21:45:52 +01:00
|
|
|
ASSUAN_Card_Error = 401,
|
|
|
|
ASSUAN_Invalid_Card = 402,
|
|
|
|
ASSUAN_No_PKCS15_App = 403,
|
2002-02-28 12:05:57 +01:00
|
|
|
ASSUAN_Card_Not_Present = 404,
|
|
|
|
ASSUAN_Invalid_Id = 405
|
2002-02-18 21:45:52 +01:00
|
|
|
|
2001-11-06 16:42:37 +01:00
|
|
|
} AssuanError;
|
|
|
|
|
|
|
|
/* This is a list of pre-registered ASSUAN commands */
|
|
|
|
typedef enum {
|
|
|
|
ASSUAN_CMD_NOP = 0,
|
|
|
|
ASSUAN_CMD_CANCEL, /* cancel the current request */
|
|
|
|
ASSUAN_CMD_BYE,
|
|
|
|
ASSUAN_CMD_AUTH,
|
|
|
|
ASSUAN_CMD_RESET,
|
2002-01-20 17:49:34 +01:00
|
|
|
ASSUAN_CMD_OPTION,
|
2001-11-06 16:42:37 +01:00
|
|
|
ASSUAN_CMD_DATA,
|
|
|
|
ASSUAN_CMD_END,
|
|
|
|
ASSUAN_CMD_INPUT,
|
|
|
|
ASSUAN_CMD_OUTPUT,
|
|
|
|
|
|
|
|
ASSUAN_CMD_USER = 256 /* Other commands should be used with this offset*/
|
|
|
|
} AssuanCommand;
|
|
|
|
|
2001-12-14 00:20:02 +01:00
|
|
|
#define ASSUAN_LINELENGTH 1002 /* 1000 + [CR,]LF */
|
2001-11-06 16:42:37 +01:00
|
|
|
|
|
|
|
struct assuan_context_s;
|
|
|
|
typedef struct assuan_context_s *ASSUAN_CONTEXT;
|
|
|
|
|
2001-11-07 18:43:05 +01:00
|
|
|
/*-- assuan-handler.c --*/
|
2001-11-06 16:42:37 +01:00
|
|
|
int assuan_register_command (ASSUAN_CONTEXT ctx,
|
|
|
|
int cmd_id, const char *cmd_string,
|
|
|
|
int (*handler)(ASSUAN_CONTEXT, char *));
|
2001-11-25 15:53:39 +01:00
|
|
|
int assuan_register_bye_notify (ASSUAN_CONTEXT ctx,
|
|
|
|
void (*fnc)(ASSUAN_CONTEXT));
|
|
|
|
int assuan_register_reset_notify (ASSUAN_CONTEXT ctx,
|
|
|
|
void (*fnc)(ASSUAN_CONTEXT));
|
|
|
|
int assuan_register_cancel_notify (ASSUAN_CONTEXT ctx,
|
|
|
|
void (*fnc)(ASSUAN_CONTEXT));
|
2001-11-27 18:39:09 +01:00
|
|
|
int assuan_register_input_notify (ASSUAN_CONTEXT ctx,
|
|
|
|
void (*fnc)(ASSUAN_CONTEXT, const char *));
|
|
|
|
int assuan_register_output_notify (ASSUAN_CONTEXT ctx,
|
|
|
|
void (*fnc)(ASSUAN_CONTEXT, const char *));
|
2002-01-20 17:49:34 +01:00
|
|
|
|
|
|
|
int assuan_register_option_handler (ASSUAN_CONTEXT ctx,
|
|
|
|
int (*fnc)(ASSUAN_CONTEXT,
|
|
|
|
const char*, const char*));
|
|
|
|
|
2001-11-07 18:43:05 +01:00
|
|
|
int assuan_process (ASSUAN_CONTEXT ctx);
|
2001-11-25 17:52:42 +01:00
|
|
|
int assuan_process_next (ASSUAN_CONTEXT ctx);
|
|
|
|
int assuan_get_active_fds (ASSUAN_CONTEXT ctx, int what,
|
|
|
|
int *fdarray, int fdarraysize);
|
|
|
|
|
|
|
|
|
2001-11-19 17:15:43 +01:00
|
|
|
FILE *assuan_get_data_fp (ASSUAN_CONTEXT ctx);
|
2002-01-10 20:46:04 +01:00
|
|
|
AssuanError assuan_set_okay_line (ASSUAN_CONTEXT ctx, const char *line);
|
2001-11-19 13:40:30 +01:00
|
|
|
void assuan_write_status (ASSUAN_CONTEXT ctx,
|
|
|
|
const char *keyword, const char *text);
|
2001-11-07 18:43:05 +01:00
|
|
|
|
2001-11-06 16:42:37 +01:00
|
|
|
|
2001-11-07 18:43:05 +01:00
|
|
|
/*-- assuan-listen.c --*/
|
2001-12-12 10:17:23 +01:00
|
|
|
AssuanError assuan_set_hello_line (ASSUAN_CONTEXT ctx, const char *line);
|
|
|
|
AssuanError assuan_accept (ASSUAN_CONTEXT ctx);
|
2001-11-07 18:43:05 +01:00
|
|
|
int assuan_get_input_fd (ASSUAN_CONTEXT ctx);
|
|
|
|
int assuan_get_output_fd (ASSUAN_CONTEXT ctx);
|
2001-12-14 20:35:56 +01:00
|
|
|
AssuanError assuan_close_input_fd (ASSUAN_CONTEXT ctx);
|
|
|
|
AssuanError assuan_close_output_fd (ASSUAN_CONTEXT ctx);
|
2001-11-06 16:42:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*-- assuan-pipe-server.c --*/
|
2001-11-06 20:14:14 +01:00
|
|
|
int assuan_init_pipe_server (ASSUAN_CONTEXT *r_ctx, int filedes[2]);
|
2002-01-19 19:20:15 +01:00
|
|
|
void assuan_deinit_server (ASSUAN_CONTEXT ctx);
|
|
|
|
|
|
|
|
/*-- assuan-socket-server.c --*/
|
|
|
|
int assuan_init_socket_server (ASSUAN_CONTEXT *r_ctx, int listen_fd);
|
2002-05-23 11:07:12 +02:00
|
|
|
int assuan_init_connected_socket_server (ASSUAN_CONTEXT *r_ctx, int fd);
|
2001-11-06 16:42:37 +01:00
|
|
|
|
|
|
|
|
2002-01-21 13:03:14 +01:00
|
|
|
/*-- assuan-pipe-connect.c --*/
|
2001-11-20 03:22:23 +01:00
|
|
|
AssuanError assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name,
|
2001-12-19 01:20:55 +01:00
|
|
|
char *const argv[], int *fd_child_list);
|
2002-01-21 13:03:14 +01:00
|
|
|
/*-- assuan-socket-connect.c --*/
|
|
|
|
AssuanError assuan_socket_connect (ASSUAN_CONTEXT *ctx, const char *name,
|
|
|
|
pid_t server_pid);
|
|
|
|
|
|
|
|
/*-- assuan-connect.c --*/
|
|
|
|
void assuan_disconnect (ASSUAN_CONTEXT ctx);
|
2001-11-24 22:20:22 +01:00
|
|
|
pid_t assuan_get_pid (ASSUAN_CONTEXT ctx);
|
2001-11-20 03:22:23 +01:00
|
|
|
|
2001-12-06 00:45:01 +01:00
|
|
|
/*-- assuan-client.c --*/
|
|
|
|
AssuanError
|
|
|
|
assuan_transact (ASSUAN_CONTEXT ctx,
|
|
|
|
const char *command,
|
|
|
|
AssuanError (*data_cb)(void *, const void *, size_t),
|
|
|
|
void *data_cb_arg,
|
|
|
|
AssuanError (*inquire_cb)(void*, const char *),
|
2002-02-28 12:05:57 +01:00
|
|
|
void *inquire_cb_arg,
|
|
|
|
AssuanError (*status_cb)(void*, const char *),
|
|
|
|
void *status_cb_arg);
|
2001-12-06 00:45:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*-- assuan-inquire.c --*/
|
|
|
|
AssuanError assuan_inquire (ASSUAN_CONTEXT ctx, const char *keyword,
|
|
|
|
char **r_buffer, size_t *r_length, size_t maxlen);
|
|
|
|
|
|
|
|
/*-- assuan-buffer.c --*/
|
2001-12-12 10:17:23 +01:00
|
|
|
AssuanError assuan_read_line (ASSUAN_CONTEXT ctx,
|
|
|
|
char **line, size_t *linelen);
|
|
|
|
int assuan_pending_line (ASSUAN_CONTEXT ctx);
|
|
|
|
AssuanError assuan_write_line (ASSUAN_CONTEXT ctx, const char *line );
|
2001-12-06 00:45:01 +01:00
|
|
|
AssuanError assuan_send_data (ASSUAN_CONTEXT ctx,
|
|
|
|
const void *buffer, size_t length);
|
|
|
|
|
|
|
|
|
2001-11-06 16:42:37 +01:00
|
|
|
/*-- assuan-util.c --*/
|
|
|
|
void assuan_set_malloc_hooks ( void *(*new_alloc_func)(size_t n),
|
|
|
|
void *(*new_realloc_func)(void *p, size_t n),
|
|
|
|
void (*new_free_func)(void*) );
|
2002-05-23 11:07:12 +02:00
|
|
|
void assuan_set_io_func (ssize_t (*r)(int,void*,size_t),
|
|
|
|
ssize_t (*w)(int,const void*,size_t));
|
2002-01-19 19:20:15 +01:00
|
|
|
void assuan_set_log_stream (ASSUAN_CONTEXT ctx, FILE *fp);
|
2001-11-07 18:43:05 +01:00
|
|
|
int assuan_set_error (ASSUAN_CONTEXT ctx, int err, const char *text);
|
2001-11-19 13:40:30 +01:00
|
|
|
void assuan_set_pointer (ASSUAN_CONTEXT ctx, void *pointer);
|
|
|
|
void *assuan_get_pointer (ASSUAN_CONTEXT ctx);
|
|
|
|
|
2002-01-19 19:20:15 +01:00
|
|
|
void assuan_begin_confidential (ASSUAN_CONTEXT ctx);
|
|
|
|
void assuan_end_confidential (ASSUAN_CONTEXT ctx);
|
2001-11-06 16:42:37 +01:00
|
|
|
|
2001-11-06 20:14:14 +01:00
|
|
|
/*-- assuan-errors.c (built) --*/
|
|
|
|
const char *assuan_strerror (AssuanError err);
|
2001-11-06 16:42:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /*ASSUAN_H*/
|