| 1 | /* assuan.h - Definitions for the Assuan IPC library |
| 2 | * Copyright (C) 2001, 2002, 2003, 2005, 2007, |
| 3 | * 2008 Free Software Foundation, Inc. |
| 4 | * |
| 5 | * This file is part of Assuan. |
| 6 | * |
| 7 | * Assuan 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 | * Assuan 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 ASSUAN_H |
| 22 | #define ASSUAN_H |
| 23 | |
| 24 | #include <stdio.h> |
| 25 | #include <sys/types.h> |
| 26 | #include <unistd.h> |
| 27 | #ifndef _ASSUAN_NO_SOCKET_WRAPPER |
| 28 | #ifdef _WIN32 |
| 29 | #include <ws2tcpip.h> |
| 30 | #else |
| 31 | #include <sys/socket.h> |
| 32 | #endif |
| 33 | #endif /*!_ASSUAN_NO_SOCKET_WRAPPER*/ |
| 34 | |
| 35 | /* To use this file with libraries the following macros are useful: |
| 36 | |
| 37 | #define _ASSUAN_EXT_SYM_PREFIX _foo_ |
| 38 | |
| 39 | This prefixes all external symbols with "_foo_". |
| 40 | |
| 41 | #define _ASSUAN_ONLY_GPG_ERRORS |
| 42 | |
| 43 | If this is defined all old-style Assuan error codes are made |
| 44 | inactive as well as other deprecated stuff. |
| 45 | |
| 46 | #define _ASSUAN_NO_SOCKET_WRAPPER |
| 47 | |
| 48 | Do not include the definitions for the socket wrapper feature. |
| 49 | |
| 50 | The follwing macros are used internally in the implementation of |
| 51 | libassuan: |
| 52 | |
| 53 | #define _ASSUAN_NO_PTH |
| 54 | |
| 55 | This avoids inclusion of special GNU Pth hacks. |
| 56 | |
| 57 | #define _ASSUAN_NO_FIXED_SIGNALS |
| 58 | |
| 59 | This disables changing of certain signal handler; i.e. SIGPIPE. |
| 60 | |
| 61 | #define _ASSUAN_USE_DOUBLE_FORK |
| 62 | |
| 63 | Use a double fork approach when connecting to a server through |
| 64 | a pipe. |
| 65 | */ |
| 66 | #define _ASSUAN_EXT_SYM_PREFIX poldi_ |
| 67 | #define _ASSUAN_NO_PTH |
| 68 | #define _ASSUAN_NO_SOCKET_WRAPPER |
| 69 | /* FIXME: is NO_FIXED_SIGNALS needed for Poldi? -mo */ |
| 70 | #define _ASSUAN_NO_FIXED_SIGNALS |
| 71 | |
| 72 | |
| 73 | #ifdef _ASSUAN_EXT_SYM_PREFIX |
| 74 | #define _ASSUAN_PREFIX1(x,y) x ## y |
| 75 | #define _ASSUAN_PREFIX2(x,y) _ASSUAN_PREFIX1(x,y) |
| 76 | #define _ASSUAN_PREFIX(x) _ASSUAN_PREFIX2(_ASSUAN_EXT_SYM_PREFIX,x) |
| 77 | #define assuan_ _ASSUAN_PREFIX(assuan_) |
| 78 | #define assuan_register_command _ASSUAN_PREFIX(assuan_register_command) |
| 79 | #define assuan_register_post_cmd_notify \ |
| 80 | _ASSUAN_PREFIX(assuan_register_post_cmd_notify) |
| 81 | #define assuan_register_bye_notify _ASSUAN_PREFIX(assuan_register_bye_notify) |
| 82 | #define assuan_register_reset_notify \ |
| 83 | _ASSUAN_PREFIX(assuan_register_reset_notify) |
| 84 | #define assuan_register_cancel_notify \ |
| 85 | _ASSUAN_PREFIX(assuan_register_cancel_notify) |
| 86 | #define assuan_register_input_notify \ |
| 87 | _ASSUAN_PREFIX(assuan_register_input_notify) |
| 88 | #define assuan_register_output_notify \ |
| 89 | _ASSUAN_PREFIX(assuan_register_output_notify) |
| 90 | #define assuan_register_option_handler \ |
| 91 | _ASSUAN_PREFIX(assuan_register_option_handler) |
| 92 | #define assuan_process _ASSUAN_PREFIX(assuan_process) |
| 93 | #define assuan_process_next _ASSUAN_PREFIX(assuan_process_next) |
| 94 | #define assuan_process_done _ASSUAN_PREFIX(assuan_process_done) |
| 95 | #define assuan_get_active_fds _ASSUAN_PREFIX(assuan_get_active_fds) |
| 96 | #define assuan_get_data_fp _ASSUAN_PREFIX(assuan_get_data_fp) |
| 97 | #define assuan_set_okay_line _ASSUAN_PREFIX(assuan_set_okay_line) |
| 98 | #define assuan_write_status _ASSUAN_PREFIX(assuan_write_status) |
| 99 | #define assuan_command_parse_fd _ASSUAN_PREFIX(assuan_command_parse_fd) |
| 100 | #define assuan_set_hello_line _ASSUAN_PREFIX(assuan_set_hello_line) |
| 101 | #define assuan_accept _ASSUAN_PREFIX(assuan_accept) |
| 102 | #define assuan_get_input_fd _ASSUAN_PREFIX(assuan_get_input_fd) |
| 103 | #define assuan_get_output_fd _ASSUAN_PREFIX(assuan_get_output_fd) |
| 104 | #define assuan_close_input_fd _ASSUAN_PREFIX(assuan_close_input_fd) |
| 105 | #define assuan_close_output_fd _ASSUAN_PREFIX(assuan_close_output_fd) |
| 106 | #define assuan_init_pipe_server _ASSUAN_PREFIX(assuan_init_pipe_server) |
| 107 | #define assuan_deinit_server _ASSUAN_PREFIX(assuan_deinit_server) |
| 108 | #define assuan_init_socket_server _ASSUAN_PREFIX(assuan_init_socket_server) |
| 109 | #define assuan_init_connected_socket_server \ |
| 110 | _ASSUAN_PREFIX(assuan_init_connected_socket_server) |
| 111 | #define assuan_init_socket_server_ext \ |
| 112 | _ASSUAN_PREFIX(assuan_init_socket_server_ext) |
| 113 | #define assuan_pipe_connect _ASSUAN_PREFIX(assuan_pipe_connect) |
| 114 | #define assuan_pipe_connect_ext _ASSUAN_PREFIX(assuan_pipe_connect_ext) |
| 115 | #define assuan_socket_connect _ASSUAN_PREFIX(assuan_socket_connect) |
| 116 | #define assuan_socket_connect_ext _ASSUAN_PREFIX(assuan_socket_connect_ext) |
| 117 | #define assuan_disconnect _ASSUAN_PREFIX(assuan_disconnect) |
| 118 | #define assuan_get_pid _ASSUAN_PREFIX(assuan_get_pid) |
| 119 | #define assuan_get_peercred _ASSUAN_PREFIX(assuan_get_peercred) |
| 120 | #define assuan_transact _ASSUAN_PREFIX(assuan_transact) |
| 121 | #define assuan_inquire _ASSUAN_PREFIX(assuan_inquire) |
| 122 | #define assuan_inquire_ext _ASSUAN_PREFIX(assuan_inquire_ext) |
| 123 | #define assuan_read_line _ASSUAN_PREFIX(assuan_read_line) |
| 124 | #define assuan_pending_line _ASSUAN_PREFIX(assuan_pending_line) |
| 125 | #define assuan_write_line _ASSUAN_PREFIX(assuan_write_line) |
| 126 | #define assuan_send_data _ASSUAN_PREFIX(assuan_send_data) |
| 127 | #define assuan_sendfd _ASSUAN_PREFIX(assuan_sendfd) |
| 128 | #define assuan_receivefd _ASSUAN_PREFIX(assuan_receivefd) |
| 129 | #define assuan_set_malloc_hooks _ASSUAN_PREFIX(assuan_set_malloc_hooks) |
| 130 | #define assuan_set_io_hooks _ASSUAN_PREFIX(assuan_set_io_hooks) |
| 131 | #define assuan_set_log_stream _ASSUAN_PREFIX(assuan_set_log_stream) |
| 132 | #define assuan_set_error _ASSUAN_PREFIX(assuan_set_error) |
| 133 | #define assuan_set_pointer _ASSUAN_PREFIX(assuan_set_pointer) |
| 134 | #define assuan_get_pointer _ASSUAN_PREFIX(assuan_get_pointer) |
| 135 | #define assuan_set_io_monitor _ASSUAN_PREFIX(assuan_set_io_monitor) |
| 136 | #define assuan_begin_confidential _ASSUAN_PREFIX(assuan_begin_confidential) |
| 137 | #define assuan_end_confidential _ASSUAN_PREFIX(assuan_end_confidential) |
| 138 | #define assuan_strerror _ASSUAN_PREFIX(assuan_strerror) |
| 139 | #define assuan_set_assuan_err_source \ |
| 140 | _ASSUAN_PREFIX(assuan_set_assuan_err_source) |
| 141 | #define assuan_set_assuan_log_stream \ |
| 142 | _ASSUAN_PREFIX(assuan_set_assuan_log_stream) |
| 143 | #define assuan_get_assuan_log_stream \ |
| 144 | _ASSUAN_PREFIX(assuan_get_assuan_log_stream) |
| 145 | #define assuan_get_assuan_log_prefix \ |
| 146 | _ASSUAN_PREFIX(assuan_get_assuan_log_prefix) |
| 147 | #define assuan_set_flag _ASSUAN_PREFIX(assuan_set_flag) |
| 148 | #define assuan_get_flag _ASSUAN_PREFIX(assuan_get_flag) |
| 149 | #define assuan_pipe_connect2 _ASSUAN_PREFIX(assuan_pipe_connect2) |
| 150 | #define assuan_set_assuan_log_prefix \ |
| 151 | _ASSUAN_PREFIX(assuan_set_assuan_log_prefix) |
| 152 | #define assuan_sock_close _ASSUAN_PREFIX(assuan_sock_close) |
| 153 | #define assuan_sock_new _ASSUAN_PREFIX(assuan_sock_new) |
| 154 | #define assuan_sock_connect _ASSUAN_PREFIX(assuan_sock_connect) |
| 155 | #define assuan_sock_bind _ASSUAN_PREFIX(assuan_sock_bind) |
| 156 | #define assuan_sock_get_nonce _ASSUAN_PREFIX(assuan_sock_get_nonce) |
| 157 | #define assuan_sock_check_nonce _ASSUAN_PREFIX(assuan_sock_check_nonce) |
| 158 | |
| 159 | |
| 160 | /* And now the internal functions, argh... */ |
| 161 | #define _assuan_read_line _ASSUAN_PREFIX(_assuan_read_line) |
| 162 | #define _assuan_cookie_write_data _ASSUAN_PREFIX(_assuan_cookie_write_data) |
| 163 | #define _assuan_cookie_write_flush _ASSUAN_PREFIX(_assuan_cookie_write_flush) |
| 164 | #define _assuan_read_from_server _ASSUAN_PREFIX(_assuan_read_from_server) |
| 165 | #define _assuan_domain_init _ASSUAN_PREFIX(_assuan_domain_init) |
| 166 | #define _assuan_register_std_commands \ |
| 167 | _ASSUAN_PREFIX(_assuan_register_std_commands) |
| 168 | #define _assuan_simple_read _ASSUAN_PREFIX(_assuan_simple_read) |
| 169 | #define _assuan_simple_write _ASSUAN_PREFIX(_assuan_simple_write) |
| 170 | #define _assuan_io_read _ASSUAN_PREFIX(_assuan_io_read) |
| 171 | #define _assuan_io_write _ASSUAN_PREFIX(_assuan_io_write) |
| 172 | #define _assuan_io_hooks _ASSUAN_PREFIX(_assuan_io_hooks) |
| 173 | #define _assuan_new_context _ASSUAN_PREFIX(_assuan_new_context) |
| 174 | #define _assuan_release_context _ASSUAN_PREFIX(_assuan_release_context) |
| 175 | #define _assuan_malloc _ASSUAN_PREFIX(_assuan_malloc) |
| 176 | #define _assuan_realloc _ASSUAN_PREFIX(_assuan_realloc) |
| 177 | #define _assuan_calloc _ASSUAN_PREFIX(_assuan_calloc) |
| 178 | #define _assuan_free _ASSUAN_PREFIX(_assuan_free) |
| 179 | #define _assuan_log_print_buffer _ASSUAN_PREFIX(_assuan_log_print_buffer) |
| 180 | #define _assuan_log_sanitized_string \ |
| 181 | _ASSUAN_PREFIX(_assuan_log_sanitized_string) |
| 182 | #define _assuan_log_printf _ASSUAN_PREFIX(_assuan_log_printf) |
| 183 | #define _assuan_set_default_log_stream \ |
| 184 | _ASSUAN_PREFIX(_assuan_set_default_log_stream) |
| 185 | #define _assuan_w32_strerror _ASSUAN_PREFIX(_assuan_w32_strerror) |
| 186 | #define _assuan_gpg_strerror_r _ASSUAN_PREFIX(_assuan_gpg_strerror_r) |
| 187 | #define _assuan_gpg_strsource _ASSUAN_PREFIX(_assuan_gpg_strsource) |
| 188 | #define _assuan_write_line _ASSUAN_PREFIX(_assuan_write_line) |
| 189 | #define _assuan_error _ASSUAN_PREFIX(_assuan_error) |
| 190 | #define _assuan_error_is_eagain _ASSUAN_PREFIX(_assuan_error_is_eagain) |
| 191 | #define _assuan_init_uds_io _ASSUAN_PREFIX(_assuan_init_uds_io) |
| 192 | #define _assuan_uds_close_fds _ASSUAN_PREFIX(_assuan_uds_close_fds) |
| 193 | #define _assuan_uds_deinit _ASSUAN_PREFIX(_assuan_uds_deinit) |
| 194 | #define _assuan_simple_recvmsg _ASSUAN_PREFIX(_assuan_simple_recvmsg) |
| 195 | #define _assuan_simple_sendmsg _ASSUAN_PREFIX(_assuan_simple_sendmsg) |
| 196 | #define _assuan_waitpid _ASSUAN_PREFIX(_assuan_waitpid) |
| 197 | #define _assuan_sock_wsa2errno _ASSUAN_PREFIX(_assuan_sock_wsa2errno) |
| 198 | #define _assuan_sock_close _ASSUAN_PREFIX(_assuan_sock_close) |
| 199 | #define _assuan_sock_new _ASSUAN_PREFIX(_assuan_sock_new) |
| 200 | #define _assuan_sock_connect _ASSUAN_PREFIX(_assuan_sock_connect) |
| 201 | #define _assuan_sock_bind _ASSUAN_PREFIX(_assuan_sock_bind) |
| 202 | #define _assuan_sock_get_nonce _ASSUAN_PREFIX(_assuan_sock_get_nonce) |
| 203 | #define _assuan_sock_check_nonce _ASSUAN_PREFIX(_assuan_sock_check_nonce) |
| 204 | |
| 205 | #endif /*_ASSUAN_EXT_SYM_PREFIX*/ |
| 206 | |
| 207 | |
| 208 | #ifdef __cplusplus |
| 209 | extern "C" |
| 210 | { |
| 211 | #if 0 |
| 212 | } |
| 213 | #endif |
| 214 | #endif |
| 215 | |
| 216 | |
| 217 | /* Check for compiler features. */ |
| 218 | #if __GNUC__ |
| 219 | #define _ASSUAN_GCC_VERSION (__GNUC__ * 10000 \ |
| 220 | + __GNUC_MINOR__ * 100 \ |
| 221 | + __GNUC_PATCHLEVEL__) |
| 222 | |
| 223 | #if _ASSUAN_GCC_VERSION > 30100 |
| 224 | #define _ASSUAN_DEPRECATED __attribute__ ((__deprecated__)) |
| 225 | #endif |
| 226 | #endif |
| 227 | #ifndef _ASSUAN_DEPRECATED |
| 228 | #define _ASSUAN_DEPRECATED |
| 229 | #endif |
| 230 | |
| 231 | |
| 232 | /* Assuan error codes. These are only used by old applications or |
| 233 | those applications which won't make use of libgpg-error. */ |
| 234 | #ifndef _ASSUAN_ONLY_GPG_ERRORS |
| 235 | #ifndef _ASSUAN_IN_LIBASSUAN |
| 236 | #define ASSUAN_No_Error 0 |
| 237 | #endif |
| 238 | #define ASSUAN_General_Error 1 |
| 239 | #define ASSUAN_Out_Of_Core 2 |
| 240 | #define ASSUAN_Invalid_Value 3 |
| 241 | #ifndef _ASSUAN_IN_LIBASSUAN |
| 242 | #define ASSUAN_Timeout 4 |
| 243 | #endif |
| 244 | #define ASSUAN_Read_Error 5 |
| 245 | #define ASSUAN_Write_Error 6 |
| 246 | #define ASSUAN_Problem_Starting_Server 7 |
| 247 | #define ASSUAN_Not_A_Server 8 |
| 248 | #ifndef _ASSUAN_IN_LIBASSUAN |
| 249 | #define ASSUAN_Not_A_Client 9 |
| 250 | #endif |
| 251 | #define ASSUAN_Nested_Commands 10 |
| 252 | #define ASSUAN_Invalid_Response 11 |
| 253 | #define ASSUAN_No_Data_Callback 12 |
| 254 | #define ASSUAN_No_Inquire_Callback 13 |
| 255 | #define ASSUAN_Connect_Failed 14 |
| 256 | #define ASSUAN_Accept_Failed 15 |
| 257 | |
| 258 | /* Error codes above 99 are meant as status codes */ |
| 259 | #define ASSUAN_Not_Implemented 100 |
| 260 | #define ASSUAN_Server_Fault 101 |
| 261 | #ifndef _ASSUAN_IN_LIBASSUAN |
| 262 | #define ASSUAN_Invalid_Command 102 |
| 263 | #endif |
| 264 | #define ASSUAN_Unknown_Command 103 |
| 265 | #define ASSUAN_Syntax_Error 104 |
| 266 | #ifndef _ASSUAN_IN_LIBASSUAN |
| 267 | #define ASSUAN_Parameter_Error 105 |
| 268 | #endif |
| 269 | #define ASSUAN_Parameter_Conflict 106 |
| 270 | #define ASSUAN_Line_Too_Long 107 |
| 271 | #define ASSUAN_Line_Not_Terminated 108 |
| 272 | #ifndef _ASSUAN_IN_LIBASSUAN |
| 273 | #define ASSUAN_No_Input 109 |
| 274 | #define ASSUAN_No_Output 110 |
| 275 | #endif |
| 276 | #define ASSUAN_Canceled 111 |
| 277 | #ifndef _ASSUAN_IN_LIBASSUAN |
| 278 | #define ASSUAN_Unsupported_Algorithm 112 |
| 279 | #define ASSUAN_Server_Resource_Problem 113 |
| 280 | #define ASSUAN_Server_IO_Error 114 |
| 281 | #define ASSUAN_Server_Bug 115 |
| 282 | #define ASSUAN_No_Data_Available 116 |
| 283 | #define ASSUAN_Invalid_Data 117 |
| 284 | #endif |
| 285 | #define ASSUAN_Unexpected_Command 118 |
| 286 | #define ASSUAN_Too_Much_Data 119 |
| 287 | #ifndef _ASSUAN_IN_LIBASSUAN |
| 288 | #define ASSUAN_Inquire_Unknown 120 |
| 289 | #define ASSUAN_Inquire_Error 121 |
| 290 | #define ASSUAN_Invalid_Option 122 |
| 291 | #define ASSUAN_Invalid_Index 123 |
| 292 | #define ASSUAN_Unexpected_Status 124 |
| 293 | #define ASSUAN_Unexpected_Data 125 |
| 294 | #define ASSUAN_Invalid_Status 126 |
| 295 | #define ASSUAN_Locale_Problem 127 |
| 296 | #endif |
| 297 | #define ASSUAN_Not_Confirmed 128 |
| 298 | |
| 299 | /* Warning: Don't use the Error codes, below they are deprecated. */ |
| 300 | #ifndef _ASSUAN_IN_LIBASSUAN |
| 301 | #define ASSUAN_Bad_Certificate 201 |
| 302 | #define ASSUAN_Bad_Certificate_Chain 202 |
| 303 | #define ASSUAN_Missing_Certificate 203 |
| 304 | #define ASSUAN_Bad_Signature 204 |
| 305 | #define ASSUAN_No_Agent 205 |
| 306 | #define ASSUAN_Agent_Error 206 |
| 307 | #define ASSUAN_No_Public_Key 207 |
| 308 | #define ASSUAN_No_Secret_Key 208 |
| 309 | #define ASSUAN_Invalid_Name 209 |
| 310 | |
| 311 | #define ASSUAN_Cert_Revoked 301 |
| 312 | #define ASSUAN_No_CRL_For_Cert 302 |
| 313 | #define ASSUAN_CRL_Too_Old 303 |
| 314 | #define ASSUAN_Not_Trusted 304 |
| 315 | |
| 316 | #define ASSUAN_Card_Error 401 |
| 317 | #define ASSUAN_Invalid_Card 402 |
| 318 | #define ASSUAN_No_PKCS15_App 403 |
| 319 | #define ASSUAN_Card_Not_Present 404 |
| 320 | #define ASSUAN_Invalid_Id 405 |
| 321 | |
| 322 | /* Error codes in the range 1000 to 9999 may be used by applications |
| 323 | at their own discretion. */ |
| 324 | #define ASSUAN_USER_ERROR_FIRST 1000 |
| 325 | #define ASSUAN_USER_ERROR_LAST 9999 |
| 326 | #endif |
| 327 | |
| 328 | typedef int assuan_error_t; |
| 329 | |
| 330 | typedef assuan_error_t AssuanError _ASSUAN_DEPRECATED; |
| 331 | |
| 332 | /* This is a list of pre-registered ASSUAN commands */ |
| 333 | /* Note, these command IDs are now deprectated and solely exists for |
| 334 | compatibility reasons. */ |
| 335 | typedef enum |
| 336 | { |
| 337 | ASSUAN_CMD_NOP = 0, |
| 338 | ASSUAN_CMD_CANCEL, /* cancel the current request */ |
| 339 | ASSUAN_CMD_BYE, |
| 340 | ASSUAN_CMD_AUTH, |
| 341 | ASSUAN_CMD_RESET, |
| 342 | ASSUAN_CMD_OPTION, |
| 343 | ASSUAN_CMD_DATA, |
| 344 | ASSUAN_CMD_END, |
| 345 | ASSUAN_CMD_INPUT, |
| 346 | ASSUAN_CMD_OUTPUT, |
| 347 | |
| 348 | ASSUAN_CMD_USER = 256 /* Other commands should be used with this offset*/ |
| 349 | } AssuanCommand; |
| 350 | |
| 351 | |
| 352 | #else /*!_ASSUAN_ONLY_GPG_ERRORS*/ |
| 353 | |
| 354 | /* Choose a type compatible with gpg_error_t. */ |
| 355 | typedef unsigned int assuan_error_t; |
| 356 | |
| 357 | #endif /*!_ASSUAN_ONLY_GPG_ERRORS*/ |
| 358 | |
| 359 | |
| 360 | /* Definitions of flags for assuan_set_flag(). */ |
| 361 | typedef enum |
| 362 | { |
| 363 | /* When using a pipe server, by default Assuan will wait for the |
| 364 | forked process to die in assuan_disconnect. In certain cases |
| 365 | this is not desirable. By setting this flag, the waitpid will |
| 366 | be skipped and the caller is responsible to cleanup a forked |
| 367 | process. */ |
| 368 | ASSUAN_NO_WAITPID = 1, |
| 369 | /* This flag indicates whether Assuan logging is in confidential |
| 370 | mode. Use assuan_{begin,end}_condidential to change the |
| 371 | mode. */ |
| 372 | ASSUAN_CONFIDENTIAL = 2 |
| 373 | } |
| 374 | assuan_flag_t; |
| 375 | |
| 376 | #define ASSUAN_LINELENGTH 1002 /* 1000 + [CR,]LF */ |
| 377 | |
| 378 | struct assuan_context_s; |
| 379 | typedef struct assuan_context_s *assuan_context_t; |
| 380 | #ifndef _ASSUAN_ONLY_GPG_ERRORS |
| 381 | typedef struct assuan_context_s *ASSUAN_CONTEXT _ASSUAN_DEPRECATED; |
| 382 | #endif /*_ASSUAN_ONLY_GPG_ERRORS*/ |
| 383 | |
| 384 | /* Because we use system handles and not libc low level file |
| 385 | descriptors on W32, we need to declare them as HANDLE (which |
| 386 | actually is a plain pointer). This is required to eventually |
| 387 | support 64 bit Windows systems. */ |
| 388 | #ifdef _WIN32 |
| 389 | typedef void *assuan_fd_t; |
| 390 | #define ASSUAN_INVALID_FD ((void*)(-1)) |
| 391 | #define ASSUAN_INT2FD(s) ((void *)(s)) |
| 392 | #define ASSUAN_FD2INT(h) ((unsigned int)(h)) |
| 393 | #else |
| 394 | typedef int assuan_fd_t; |
| 395 | #define ASSUAN_INVALID_FD (-1) |
| 396 | #define ASSUAN_INT2FD(s) ((s)) |
| 397 | #define ASSUAN_FD2INT(h) ((h)) |
| 398 | #endif |
| 399 | |
| 400 | |
| 401 | /* Assuan features an emulation of Unix domain sockets based on a |
| 402 | local TCP connections. To implement access permissions based on |
| 403 | file permissions a nonce is used which is expected by th server as |
| 404 | the first bytes received. This structure is used by the server to |
| 405 | save the nonce created initially by bind. On POSIX systems this is |
| 406 | a dummy operation. */ |
| 407 | struct assuan_sock_nonce_s |
| 408 | { |
| 409 | size_t length; |
| 410 | #ifdef _WIN32 |
| 411 | char nonce[16]; |
| 412 | #endif |
| 413 | }; |
| 414 | typedef struct assuan_sock_nonce_s assuan_sock_nonce_t; |
| 415 | |
| 416 | /* Define the Unix domain socket structure for Windows. */ |
| 417 | #if defined(_WIN32) && !defined(_ASSUAN_NO_SOCKET_WRAPPER) |
| 418 | #ifndef AF_LOCAL |
| 419 | #define AF_LOCAL AF_UNIX |
| 420 | #endif |
| 421 | #define EADDRINUSE WSAEADDRINUSE |
| 422 | struct sockaddr_un |
| 423 | { |
| 424 | short sun_family; |
| 425 | unsigned short sun_port; |
| 426 | struct in_addr sun_addr; |
| 427 | char sun_path[108-2-4]; |
| 428 | }; |
| 429 | #endif |
| 430 | |
| 431 | |
| 432 | /* Definition of hook functions used to conditionally replace the |
| 433 | default I/O functions. */ |
| 434 | struct assuan_io_hooks |
| 435 | { |
| 436 | int (*read_hook)(assuan_context_t, assuan_fd_t, void *, size_t, ssize_t *); |
| 437 | int (*write_hook)(assuan_context_t, assuan_fd_t fd, |
| 438 | const void *, size_t, ssize_t *); |
| 439 | }; |
| 440 | typedef struct assuan_io_hooks *assuan_io_hooks_t; |
| 441 | |
| 442 | |
| 443 | |
| 444 | /*-- assuan-handler.c --*/ |
| 445 | int assuan_register_command (assuan_context_t ctx, |
| 446 | const char *cmd_string, |
| 447 | int (*handler)(assuan_context_t, char *)); |
| 448 | int assuan_register_post_cmd_notify (assuan_context_t ctx, |
| 449 | void (*fnc)(assuan_context_t, int)); |
| 450 | int assuan_register_bye_notify (assuan_context_t ctx, |
| 451 | void (*fnc)(assuan_context_t)); |
| 452 | int assuan_register_reset_notify (assuan_context_t ctx, |
| 453 | void (*fnc)(assuan_context_t)); |
| 454 | int assuan_register_cancel_notify (assuan_context_t ctx, |
| 455 | void (*fnc)(assuan_context_t)); |
| 456 | int assuan_register_input_notify (assuan_context_t ctx, |
| 457 | void (*fnc)(assuan_context_t, const char *)); |
| 458 | int assuan_register_output_notify (assuan_context_t ctx, |
| 459 | void (*fnc)(assuan_context_t, const char *)); |
| 460 | |
| 461 | int assuan_register_option_handler (assuan_context_t ctx, |
| 462 | int (*fnc)(assuan_context_t, |
| 463 | const char*, const char*)); |
| 464 | |
| 465 | int assuan_process (assuan_context_t ctx); |
| 466 | int assuan_process_next (assuan_context_t ctx); |
| 467 | int assuan_process_done (assuan_context_t ctx, int rc); |
| 468 | int assuan_get_active_fds (assuan_context_t ctx, int what, |
| 469 | assuan_fd_t *fdarray, int fdarraysize); |
| 470 | |
| 471 | |
| 472 | FILE *assuan_get_data_fp (assuan_context_t ctx); |
| 473 | assuan_error_t assuan_set_okay_line (assuan_context_t ctx, const char *line); |
| 474 | assuan_error_t assuan_write_status (assuan_context_t ctx, |
| 475 | const char *keyword, const char *text); |
| 476 | |
| 477 | /* Negotiate a file descriptor. If LINE contains "FD=N", returns N |
| 478 | assuming a local file descriptor. If LINE contains "FD" reads a |
| 479 | file descriptor via CTX and stores it in *RDF (the CTX must be |
| 480 | capable of passing file descriptors). Under W32 the returned FD is |
| 481 | a libc-type one. */ |
| 482 | assuan_error_t assuan_command_parse_fd (assuan_context_t ctx, char *line, |
| 483 | assuan_fd_t *rfd); |
| 484 | |
| 485 | |
| 486 | /*-- assuan-listen.c --*/ |
| 487 | assuan_error_t assuan_set_hello_line (assuan_context_t ctx, const char *line); |
| 488 | assuan_error_t assuan_accept (assuan_context_t ctx); |
| 489 | assuan_fd_t assuan_get_input_fd (assuan_context_t ctx); |
| 490 | assuan_fd_t assuan_get_output_fd (assuan_context_t ctx); |
| 491 | assuan_error_t assuan_close_input_fd (assuan_context_t ctx); |
| 492 | assuan_error_t assuan_close_output_fd (assuan_context_t ctx); |
| 493 | |
| 494 | |
| 495 | /*-- assuan-pipe-server.c --*/ |
| 496 | int assuan_init_pipe_server (assuan_context_t *r_ctx, int filedes[2]); |
| 497 | void assuan_deinit_server (assuan_context_t ctx); |
| 498 | |
| 499 | /*-- assuan-socket-server.c --*/ |
| 500 | int assuan_init_socket_server (assuan_context_t *r_ctx, assuan_fd_t listen_fd); |
| 501 | int assuan_init_connected_socket_server (assuan_context_t *r_ctx, |
| 502 | assuan_fd_t fd) _ASSUAN_DEPRECATED; |
| 503 | int assuan_init_socket_server_ext (assuan_context_t *r_ctx, assuan_fd_t fd, |
| 504 | unsigned int flags); |
| 505 | void assuan_set_sock_nonce (assuan_context_t ctx, assuan_sock_nonce_t *nonce); |
| 506 | |
| 507 | /*-- assuan-pipe-connect.c --*/ |
| 508 | assuan_error_t assuan_pipe_connect (assuan_context_t *ctx, |
| 509 | const char *name, |
| 510 | const char *const argv[], |
| 511 | int *fd_child_list); |
| 512 | assuan_error_t assuan_pipe_connect2 (assuan_context_t *ctx, |
| 513 | const char *name, |
| 514 | const char *const argv[], |
| 515 | int *fd_child_list, |
| 516 | void (*atfork) (void*, int), |
| 517 | void *atforkvalue) _ASSUAN_DEPRECATED; |
| 518 | assuan_error_t assuan_pipe_connect_ext (assuan_context_t *ctx, |
| 519 | const char *name, |
| 520 | const char *const argv[], |
| 521 | int *fd_child_list, |
| 522 | void (*atfork) (void *, int), |
| 523 | void *atforkvalue, |
| 524 | unsigned int flags); |
| 525 | |
| 526 | /*-- assuan-socket-connect.c --*/ |
| 527 | assuan_error_t assuan_socket_connect (assuan_context_t *ctx, |
| 528 | const char *name, |
| 529 | pid_t server_pid); |
| 530 | assuan_error_t assuan_socket_connect_ext (assuan_context_t *ctx, |
| 531 | const char *name, |
| 532 | pid_t server_pid, |
| 533 | unsigned int flags); |
| 534 | |
| 535 | /*-- assuan-connect.c --*/ |
| 536 | void assuan_disconnect (assuan_context_t ctx); |
| 537 | pid_t assuan_get_pid (assuan_context_t ctx); |
| 538 | #ifndef _WIN32 |
| 539 | assuan_error_t assuan_get_peercred (assuan_context_t ctx, |
| 540 | pid_t *pid, uid_t *uid, gid_t *gid); |
| 541 | #endif |
| 542 | |
| 543 | /*-- assuan-client.c --*/ |
| 544 | assuan_error_t |
| 545 | assuan_transact (assuan_context_t ctx, |
| 546 | const char *command, |
| 547 | assuan_error_t (*data_cb)(void *, const void *, size_t), |
| 548 | void *data_cb_arg, |
| 549 | assuan_error_t (*inquire_cb)(void*, const char *), |
| 550 | void *inquire_cb_arg, |
| 551 | assuan_error_t (*status_cb)(void*, const char *), |
| 552 | void *status_cb_arg); |
| 553 | |
| 554 | |
| 555 | /*-- assuan-inquire.c --*/ |
| 556 | assuan_error_t assuan_inquire (assuan_context_t ctx, const char *keyword, |
| 557 | unsigned char **r_buffer, size_t *r_length, |
| 558 | size_t maxlen); |
| 559 | assuan_error_t assuan_inquire_ext (assuan_context_t ctx, const char *keyword, |
| 560 | size_t maxlen, |
| 561 | int (*cb) (void *cb_data, int rc, |
| 562 | unsigned char *buf, |
| 563 | size_t buf_len), |
| 564 | void *cb_data); |
| 565 | /*-- assuan-buffer.c --*/ |
| 566 | assuan_error_t assuan_read_line (assuan_context_t ctx, |
| 567 | char **line, size_t *linelen); |
| 568 | int assuan_pending_line (assuan_context_t ctx); |
| 569 | assuan_error_t assuan_write_line (assuan_context_t ctx, const char *line ); |
| 570 | assuan_error_t assuan_send_data (assuan_context_t ctx, |
| 571 | const void *buffer, size_t length); |
| 572 | |
| 573 | /* The file descriptor must be pending before assuan_receivefd is |
| 574 | called. This means that assuan_sendfd should be called *before* the |
| 575 | trigger is sent (normally via assuan_write_line ("INPUT FD")). */ |
| 576 | assuan_error_t assuan_sendfd (assuan_context_t ctx, assuan_fd_t fd); |
| 577 | assuan_error_t assuan_receivefd (assuan_context_t ctx, assuan_fd_t *fd); |
| 578 | |
| 579 | |
| 580 | /*-- assuan-util.c --*/ |
| 581 | void assuan_set_malloc_hooks ( void *(*new_alloc_func)(size_t n), |
| 582 | void *(*new_realloc_func)(void *p, size_t n), |
| 583 | void (*new_free_func)(void*) ); |
| 584 | void assuan_set_io_hooks (assuan_io_hooks_t io_hooks); |
| 585 | void assuan_set_log_stream (assuan_context_t ctx, FILE *fp); |
| 586 | int assuan_set_error (assuan_context_t ctx, int err, const char *text); |
| 587 | void assuan_set_pointer (assuan_context_t ctx, void *pointer); |
| 588 | void *assuan_get_pointer (assuan_context_t ctx); |
| 589 | |
| 590 | void assuan_begin_confidential (assuan_context_t ctx); |
| 591 | void assuan_end_confidential (assuan_context_t ctx); |
| 592 | |
| 593 | void assuan_set_io_monitor (assuan_context_t ctx, |
| 594 | unsigned int (*monitor)(assuan_context_t ctx, |
| 595 | int direction, |
| 596 | const char *line, |
| 597 | size_t linelen)); |
| 598 | |
| 599 | /* For context CTX, set the flag FLAG to VALUE. Values for flags |
| 600 | are usually 1 or 0 but certain flags might allow for other values; |
| 601 | see the description of the type assuan_flag_t for details. */ |
| 602 | void assuan_set_flag (assuan_context_t ctx, assuan_flag_t flag, int value); |
| 603 | |
| 604 | /* Return the VALUE of FLAG in context CTX. */ |
| 605 | int assuan_get_flag (assuan_context_t ctx, assuan_flag_t flag); |
| 606 | |
| 607 | |
| 608 | /*-- assuan-errors.c --*/ |
| 609 | |
| 610 | #ifndef _ASSUAN_ONLY_GPG_ERRORS |
| 611 | /* Return a string describing the assuan error. The use of this |
| 612 | function is deprecated; it is better to call |
| 613 | assuan_set_assuan_err_source once and then make use libgpg-error. */ |
| 614 | const char *assuan_strerror (assuan_error_t err); |
| 615 | #endif /*_ASSUAN_ONLY_GPG_ERRORS*/ |
| 616 | |
| 617 | /* Enable gpg-error style error codes. ERRSOURCE is one of gpg-error |
| 618 | sources. Note, that this function is not thread-safe and should be |
| 619 | used right at startup. Switching back to the old style mode is not |
| 620 | supported. */ |
| 621 | void assuan_set_assuan_err_source (int errsource); |
| 622 | |
| 623 | /*-- assuan-logging.c --*/ |
| 624 | |
| 625 | /* Set the stream to which assuan should log message not associated |
| 626 | with a context. By default, this is stderr. The default value |
| 627 | will be changed when the first log stream is associated with a |
| 628 | context. Note, that this function is not thread-safe and should |
| 629 | in general be used right at startup. */ |
| 630 | extern void assuan_set_assuan_log_stream (FILE *fp); |
| 631 | |
| 632 | /* Return the stream which is currently being using for global logging. */ |
| 633 | extern FILE *assuan_get_assuan_log_stream (void); |
| 634 | |
| 635 | /* Set the prefix to be used at the start of a line emitted by assuan |
| 636 | on the log stream. The default is the empty string. Note, that |
| 637 | this function is not thread-safe and should in general be used |
| 638 | right at startup. */ |
| 639 | void assuan_set_assuan_log_prefix (const char *text); |
| 640 | |
| 641 | /* Return a prefix to be used at the start of a line emitted by assuan |
| 642 | on the log stream. The default implementation returns the empty |
| 643 | string, i.e. "" */ |
| 644 | const char *assuan_get_assuan_log_prefix (void); |
| 645 | |
| 646 | |
| 647 | /*-- assuan-socket.c --*/ |
| 648 | |
| 649 | /* These are socket wrapper functions to support an emulation of Unix |
| 650 | domain sockets on Windows W32. */ |
| 651 | int assuan_sock_close (assuan_fd_t fd); |
| 652 | assuan_fd_t assuan_sock_new (int domain, int type, int proto); |
| 653 | int assuan_sock_connect (assuan_fd_t sockfd, |
| 654 | struct sockaddr *addr, int addrlen); |
| 655 | int assuan_sock_bind (assuan_fd_t sockfd, struct sockaddr *addr, int addrlen); |
| 656 | int assuan_sock_get_nonce (struct sockaddr *addr, int addrlen, |
| 657 | assuan_sock_nonce_t *nonce); |
| 658 | int assuan_sock_check_nonce (assuan_fd_t fd, assuan_sock_nonce_t *nonce); |
| 659 | |
| 660 | |
| 661 | #ifdef __cplusplus |
| 662 | } |
| 663 | #endif |
| 664 | #endif /* ASSUAN_H */ |