| 1 | /* assuan-handler.c - dispatch commands |
| 2 | * Copyright (C) 2001 Free Software Foundation, Inc. |
| 3 | * |
| 4 | * This file is part of GnuPG. |
| 5 | * |
| 6 | * GnuPG is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * GnuPG is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA |
| 19 | */ |
| 20 | |
| 21 | #include <config.h>cxx . . $ `<file>/config.h`/ |
| 22 | #include <stdlib.h> |
| 23 | #include <stdio.h> |
| 24 | #include <string.h> |
| 25 | |
| 26 | #include "assuan-defs.h"cxx . . $ `<file>/assuan/assuan-defs.h`/ |
| 27 | |
| 28 | #define spacepcxx . . $ `assuan/assuan-handler.c:28:9`!(p) (*(p) == ' ' || *(p) == '\t') |
| 29 | #define digitpcxx . . $ `assuan/assuan-handler.c:29:9`!(a) ((a) >= '0' && (a) <= '9') |
| 30 | |
| 31 | |
| 32 | static int |
| 33 | dummy_handlercxx . . $ dummy_handler(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line) |
| 34 | { |
| 35 | return set_errorcxx . . $ `assuan/assuan-defs.h:132:9`! (ctx, Server_Fault, "no handler registered"); |
| 36 | } |
| 37 | |
| 38 | |
| 39 | static int |
| 40 | std_handler_nopcxx . . $ std_handler_nop(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line) |
| 41 | { |
| 42 | return 0; /* okay */ |
| 43 | } |
| 44 | |
| 45 | static int |
| 46 | std_handler_cancelcxx . . $ std_handler_cancel(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line) |
| 47 | { |
| 48 | if (ctx->cancel_notify_fnccxx . . $ assuan_context_s#cancel_notify_fnc.) |
| 49 | ctx->cancel_notify_fnccxx . . $ assuan_context_s#cancel_notify_fnc. (ctx); |
| 50 | return set_errorcxx . . $ `assuan/assuan-defs.h:132:9`! (ctx, Not_Implemented, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 51 | } |
| 52 | |
| 53 | static int |
| 54 | std_handler_optioncxx . . $ std_handler_option(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line) |
| 55 | { |
| 56 | char *key, *value, *p; |
| 57 | |
| 58 | for (key=line; spacepcxx . . $ `assuan/assuan-handler.c:28:9`! (key); key++) |
| 59 | ; |
| 60 | if (!*key) |
| 61 | return set_errorcxx . . $ `assuan/assuan-defs.h:132:9`! (ctx, Syntax_Error, "argument required"); |
| 62 | if (*key == '=') |
| 63 | return set_errorcxx . . $ `assuan/assuan-defs.h:132:9`! (ctx, Syntax_Error, "no option name given"); |
| 64 | for (value=key; *value && !spacepcxx . . $ `assuan/assuan-handler.c:28:9`! (value) && *value != '='; value++) |
| 65 | ; |
| 66 | if (*value) |
| 67 | { |
| 68 | if (spacepcxx . . $ `assuan/assuan-handler.c:28:9`! (value)) |
| 69 | *value++ = 0; /* terminate key */ |
| 70 | for (; spacepcxx . . $ `assuan/assuan-handler.c:28:9`! (value); value++) |
| 71 | ; |
| 72 | if (*value == '=') |
| 73 | { |
| 74 | *value++ = 0; /* terminate key */ |
| 75 | for (; spacepcxx . . $ `assuan/assuan-handler.c:28:9`! (value); value++) |
| 76 | ; |
| 77 | if (!*value) |
| 78 | return set_errorcxx . . $ `assuan/assuan-defs.h:132:9`! (ctx, Syntax_Error, "option argument expected"); |
| 79 | } |
| 80 | if (*value) |
| 81 | { |
| 82 | for (p = value + strlencxx . . $ strlen(751346f8406fd082).(value) - 1; p > value && spacepcxx . . $ `assuan/assuan-handler.c:28:9`! (p); p--) |
| 83 | ; |
| 84 | if (p > value) |
| 85 | *++p = 0; /* strip trailing spaces */ |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | if (*key == '-' && key[1] == '-' && key[2]) |
| 90 | key += 2; /* the double dashes are optional */ |
| 91 | if (*key == '-') |
| 92 | return set_errorcxx . . $ `assuan/assuan-defs.h:132:9`! (ctx, Syntax_Error, |
| 93 | "option should not begin with one dash"); |
| 94 | |
| 95 | if (ctx->option_handler_fnccxx . . $ assuan_context_s#option_handler_fnc.) |
| 96 | return ctx->option_handler_fnccxx . . $ assuan_context_s#option_handler_fnc. (ctx, key, value); |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | static int |
| 101 | std_handler_byecxx . . $ std_handler_bye(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line) |
| 102 | { |
| 103 | if (ctx->bye_notify_fnccxx . . $ assuan_context_s#bye_notify_fnc.) |
| 104 | ctx->bye_notify_fnccxx . . $ assuan_context_s#bye_notify_fnc. (ctx); |
| 105 | assuan_close_input_fdcxx . . $ assuan_close_input_fd(5c60088356380db8). (ctx); |
| 106 | assuan_close_output_fdcxx . . $ assuan_close_output_fd(5c60088356380db8). (ctx); |
| 107 | return -1; /* pretty simple :-) */ |
| 108 | } |
| 109 | |
| 110 | static int |
| 111 | std_handler_authcxx . . $ std_handler_auth(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line) |
| 112 | { |
| 113 | return set_errorcxx . . $ `assuan/assuan-defs.h:132:9`! (ctx, Not_Implemented, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 114 | } |
| 115 | |
| 116 | static int |
| 117 | std_handler_resetcxx . . $ std_handler_reset(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line) |
| 118 | { |
| 119 | if (ctx->reset_notify_fnccxx . . $ assuan_context_s#reset_notify_fnc.) |
| 120 | ctx->reset_notify_fnccxx . . $ assuan_context_s#reset_notify_fnc. (ctx); |
| 121 | assuan_close_input_fdcxx . . $ assuan_close_input_fd(5c60088356380db8). (ctx); |
| 122 | assuan_close_output_fdcxx . . $ assuan_close_output_fd(5c60088356380db8). (ctx); |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | static int |
| 127 | std_handler_endcxx . . $ std_handler_end(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line) |
| 128 | { |
| 129 | return set_errorcxx . . $ `assuan/assuan-defs.h:132:9`! (ctx, Not_Implemented, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 130 | } |
| 131 | |
| 132 | static int |
| 133 | parse_cmd_input_outputcxx . . $ parse_cmd_input_output(49eda4e72b5ac033). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line, int *rfd) |
| 134 | { |
| 135 | char *endp; |
| 136 | |
| 137 | if (strncmpcxx . . $ strncmp(fd278af2f295fa2e). (line, "FD=", 3)) |
| 138 | return set_errorcxx . . $ `assuan/assuan-defs.h:132:9`! (ctx, Syntax_Error, "FD=<n> expected"); |
| 139 | line += 3; |
| 140 | if (!digitpcxx . . $ `assuan/assuan-handler.c:29:9`! (*line)) |
| 141 | return set_errorcxx . . $ `assuan/assuan-defs.h:132:9`! (ctx, Syntax_Error, "number required"); |
| 142 | *rfd = strtoulcxx . . $ strtoul(31746e8d6ec49860). (line, &endp, 10); |
| 143 | /* remove that argument so that a notify handler won't see it */ |
| 144 | memsetcxx . . $ memset(d1de1e4fb215f1c6). (line, ' ', endp? (endp-line):strlencxx . . $ strlen(751346f8406fd082).(line)); |
| 145 | |
| 146 | if (*rfd == ctx->inboundcxx . . $ assuan_context_s#inbound..fdcxx . . $ assuan_context_s#$anonymous_type_0#fd.) |
| 147 | return set_errorcxx . . $ `assuan/assuan-defs.h:132:9`! (ctx, Parameter_Conflict, "fd same as inbound fd"); |
| 148 | if (*rfd == ctx->outboundcxx . . $ assuan_context_s#outbound..fdcxx . . $ assuan_context_s#$anonymous_type_2#fd.) |
| 149 | return set_errorcxx . . $ `assuan/assuan-defs.h:132:9`! (ctx, Parameter_Conflict, "fd same as outbound fd"); |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | /* Format is INPUT FD=<n> */ |
| 154 | static int |
| 155 | std_handler_inputcxx . . $ std_handler_input(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line) |
| 156 | { |
| 157 | int rc, fd; |
| 158 | |
| 159 | rc = parse_cmd_input_outputcxx . . $ parse_cmd_input_output(49eda4e72b5ac033). (ctx, line, &fd); |
| 160 | if (rc) |
| 161 | return rc; |
| 162 | ctx->input_fdcxx . . $ assuan_context_s#input_fd. = fd; |
| 163 | if (ctx->input_notify_fnccxx . . $ assuan_context_s#input_notify_fnc.) |
| 164 | ctx->input_notify_fnccxx . . $ assuan_context_s#input_notify_fnc. (ctx, line); |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | /* Format is OUTPUT FD=<n> */ |
| 169 | static int |
| 170 | std_handler_outputcxx . . $ std_handler_output(6da50a57b69ceb9e). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line) |
| 171 | { |
| 172 | int rc, fd; |
| 173 | |
| 174 | rc = parse_cmd_input_outputcxx . . $ parse_cmd_input_output(49eda4e72b5ac033). (ctx, line, &fd); |
| 175 | if (rc) |
| 176 | return rc; |
| 177 | ctx->output_fdcxx . . $ assuan_context_s#output_fd. = fd; |
| 178 | if (ctx->output_notify_fnccxx . . $ assuan_context_s#output_notify_fnc.) |
| 179 | ctx->output_notify_fnccxx . . $ assuan_context_s#output_notify_fnc. (ctx, line); |
| 180 | return 0; |
| 181 | } |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | /* This is a table with the standard commands and handler for them. |
| 188 | The table is used to initialize a new context and assuciate strings |
| 189 | and handlers with cmd_ids */ |
| 190 | static structcxx . . $ $anonymous_type_53b7d2eb4f2628e8_0# { |
| 191 | const char *namecxx . . $ $anonymous_type_53b7d2eb4f2628e8_0#name.; |
| 192 | int cmd_idcxx . . $ $anonymous_type_53b7d2eb4f2628e8_0#cmd_id.; |
| 193 | int (*handlercxx . . $ $anonymous_type_53b7d2eb4f2628e8_0#handler.)(ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT#, char *line); |
| 194 | int alwayscxx . . $ $anonymous_type_53b7d2eb4f2628e8_0#always.; /* always initialize this command */ |
| 195 | } std_cmd_tablecxx . . $ std_cmd_table.[] = { |
| 196 | { "NOP", ASSUAN_CMD_NOPcxx . . $ ASSUAN_CMD_NOP., std_handler_nopcxx . . $ std_handler_nop(6da50a57b69ceb9e)., 1 }, |
| 197 | { "CANCEL", ASSUAN_CMD_CANCELcxx . . $ ASSUAN_CMD_CANCEL., std_handler_cancelcxx . . $ std_handler_cancel(6da50a57b69ceb9e)., 1 }, |
| 198 | { "OPTION", ASSUAN_CMD_OPTIONcxx . . $ ASSUAN_CMD_OPTION., std_handler_optioncxx . . $ std_handler_option(6da50a57b69ceb9e)., 1 }, |
| 199 | { "BYE", ASSUAN_CMD_BYEcxx . . $ ASSUAN_CMD_BYE., std_handler_byecxx . . $ std_handler_bye(6da50a57b69ceb9e)., 1 }, |
| 200 | { "AUTH", ASSUAN_CMD_AUTHcxx . . $ ASSUAN_CMD_AUTH., std_handler_authcxx . . $ std_handler_auth(6da50a57b69ceb9e)., 1 }, |
| 201 | { "RESET", ASSUAN_CMD_RESETcxx . . $ ASSUAN_CMD_RESET., std_handler_resetcxx . . $ std_handler_reset(6da50a57b69ceb9e)., 1 }, |
| 202 | { "END", ASSUAN_CMD_ENDcxx . . $ ASSUAN_CMD_END., std_handler_endcxx . . $ std_handler_end(6da50a57b69ceb9e)., 1 }, |
| 203 | |
| 204 | { "INPUT", ASSUAN_CMD_INPUTcxx . . $ ASSUAN_CMD_INPUT., std_handler_inputcxx . . $ std_handler_input(6da50a57b69ceb9e). }, |
| 205 | { "OUTPUT", ASSUAN_CMD_OUTPUTcxx . . $ ASSUAN_CMD_OUTPUT., std_handler_outputcxx . . $ std_handler_output(6da50a57b69ceb9e). }, |
| 206 | { "OPTION", ASSUAN_CMD_OPTIONcxx . . $ ASSUAN_CMD_OPTION., std_handler_optioncxx . . $ std_handler_option(6da50a57b69ceb9e)., 1 }, |
| 207 | { NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! } |
| 208 | }; |
| 209 | |
| 210 | |
| 211 | /** |
| 212 | * assuan_register_command: |
| 213 | * @ctx: the server context |
| 214 | * @cmd_id: An ID value for the command |
| 215 | * @cmd_name: A string with the command name |
| 216 | * @handler: The handler function to be called |
| 217 | * |
| 218 | * Register a handler to be used for a given command. |
| 219 | * |
| 220 | * The @cmd_name must be %NULL or an empty string for all @cmd_ids |
| 221 | * below %ASSUAN_CMD_USER because predefined values are used. |
| 222 | * |
| 223 | * Return value: |
| 224 | **/ |
| 225 | int |
| 226 | assuan_register_commandcxx . . $ assuan_register_command(b82481c29d01abcc). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, |
| 227 | int cmd_id, const char *cmd_name, |
| 228 | int (*handler)(ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT#, char *)) |
| 229 | { |
| 230 | int i; |
| 231 | |
| 232 | if (cmd_name && !*cmd_name) |
| 233 | cmd_name = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 234 | |
| 235 | if (cmd_id < ASSUAN_CMD_USERcxx . . $ ASSUAN_CMD_USER.) |
| 236 | { |
| 237 | if (cmd_name) |
| 238 | return ASSUAN_Invalid_Valuecxx . . $ ASSUAN_Invalid_Value.; /* must be NULL for these values*/ |
| 239 | |
| 240 | for (i=0; std_cmd_tablecxx . . $ std_cmd_table.[i].namecxx . . $ $anonymous_type_53b7d2eb4f2628e8_0#name.; i++) |
| 241 | { |
| 242 | if (std_cmd_tablecxx . . $ std_cmd_table.[i].cmd_idcxx . . $ $anonymous_type_53b7d2eb4f2628e8_0#cmd_id. == cmd_id) |
| 243 | { |
| 244 | cmd_name = std_cmd_tablecxx . . $ std_cmd_table.[i].namecxx . . $ $anonymous_type_53b7d2eb4f2628e8_0#name.; |
| 245 | if (!handler) |
| 246 | handler = std_cmd_tablecxx . . $ std_cmd_table.[i].handlercxx . . $ $anonymous_type_53b7d2eb4f2628e8_0#handler.; |
| 247 | break; |
| 248 | } |
| 249 | } |
| 250 | if (!std_cmd_tablecxx . . $ std_cmd_table.[i].namecxx . . $ $anonymous_type_53b7d2eb4f2628e8_0#name.) |
| 251 | return ASSUAN_Invalid_Valuecxx . . $ ASSUAN_Invalid_Value.; /* not a pre-registered one */ |
| 252 | } |
| 253 | |
| 254 | if (!handler) |
| 255 | handler = dummy_handlercxx . . $ dummy_handler(6da50a57b69ceb9e).; |
| 256 | |
| 257 | if (!cmd_name) |
| 258 | return ASSUAN_Invalid_Valuecxx . . $ ASSUAN_Invalid_Value.; |
| 259 | |
| 260 | /* fprintf (stderr, "DBG-assuan: registering %d as `%s'\n", cmd_id, cmd_name); */ |
| 261 | |
| 262 | if (!ctx->cmdtblcxx . . $ assuan_context_s#cmdtbl.) |
| 263 | { |
| 264 | ctx->cmdtbl_sizecxx . . $ assuan_context_s#cmdtbl_size. = 50; |
| 265 | ctx->cmdtblcxx . . $ assuan_context_s#cmdtbl. = xtrycalloccxx . . $ `assuan/assuan-defs.h:128:9`! ( ctx->cmdtbl_size, sizeof *ctx->cmdtbl); |
| 266 | if (!ctx->cmdtblcxx . . $ assuan_context_s#cmdtbl.) |
| 267 | return ASSUAN_Out_Of_Corecxx . . $ ASSUAN_Out_Of_Core.; |
| 268 | ctx->cmdtbl_usedcxx . . $ assuan_context_s#cmdtbl_used. = 0; |
| 269 | } |
| 270 | else if (ctx->cmdtbl_usedcxx . . $ assuan_context_s#cmdtbl_used. >= ctx->cmdtbl_sizecxx . . $ assuan_context_s#cmdtbl_size.) |
| 271 | { |
| 272 | struct cmdtbl_scxx . . $ cmdtbl_s# *x; |
| 273 | |
| 274 | x = xtryrealloccxx . . $ `assuan/assuan-defs.h:129:9`! ( ctx->cmdtbl, (ctx->cmdtbl_size+10) * sizeof *x); |
| 275 | if (!x) |
| 276 | return ASSUAN_Out_Of_Corecxx . . $ ASSUAN_Out_Of_Core.; |
| 277 | ctx->cmdtblcxx . . $ assuan_context_s#cmdtbl. = x; |
| 278 | ctx->cmdtbl_sizecxx . . $ assuan_context_s#cmdtbl_size. += 50; |
| 279 | } |
| 280 | |
| 281 | ctx->cmdtblcxx . . $ assuan_context_s#cmdtbl.[ctx->cmdtbl_usedcxx . . $ assuan_context_s#cmdtbl_used.].namecxx . . $ cmdtbl_s#name. = cmd_name; |
| 282 | ctx->cmdtblcxx . . $ assuan_context_s#cmdtbl.[ctx->cmdtbl_usedcxx . . $ assuan_context_s#cmdtbl_used.].cmd_idcxx . . $ cmdtbl_s#cmd_id. = cmd_id; |
| 283 | ctx->cmdtblcxx . . $ assuan_context_s#cmdtbl.[ctx->cmdtbl_usedcxx . . $ assuan_context_s#cmdtbl_used.].handlercxx . . $ cmdtbl_s#handler. = handler; |
| 284 | ctx->cmdtbl_usedcxx . . $ assuan_context_s#cmdtbl_used.++; |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | int |
| 289 | assuan_register_bye_notifycxx . . $ assuan_register_bye_notify(ec350e409819234). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, void (*fnc)(ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT#)) |
| 290 | { |
| 291 | if (!ctx) |
| 292 | return ASSUAN_Invalid_Valuecxx . . $ ASSUAN_Invalid_Value.; |
| 293 | ctx->bye_notify_fnccxx . . $ assuan_context_s#bye_notify_fnc. = fnc; |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | int |
| 298 | assuan_register_reset_notifycxx . . $ assuan_register_reset_notify(ec350e409819234). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, void (*fnc)(ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT#)) |
| 299 | { |
| 300 | if (!ctx) |
| 301 | return ASSUAN_Invalid_Valuecxx . . $ ASSUAN_Invalid_Value.; |
| 302 | ctx->reset_notify_fnccxx . . $ assuan_context_s#reset_notify_fnc. = fnc; |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | int |
| 307 | assuan_register_cancel_notifycxx . . $ assuan_register_cancel_notify(ec350e409819234). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, void (*fnc)(ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT#)) |
| 308 | { |
| 309 | if (!ctx) |
| 310 | return ASSUAN_Invalid_Valuecxx . . $ ASSUAN_Invalid_Value.; |
| 311 | ctx->cancel_notify_fnccxx . . $ assuan_context_s#cancel_notify_fnc. = fnc; |
| 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | int |
| 316 | assuan_register_option_handlercxx . . $ assuan_register_option_handler(fcbcb73ed245437a). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, |
| 317 | int (*fnc)(ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT#, |
| 318 | const char*, const char*)) |
| 319 | { |
| 320 | if (!ctx) |
| 321 | return ASSUAN_Invalid_Valuecxx . . $ ASSUAN_Invalid_Value.; |
| 322 | ctx->option_handler_fnccxx . . $ assuan_context_s#option_handler_fnc. = fnc; |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | int |
| 327 | assuan_register_input_notifycxx . . $ assuan_register_input_notify(14c8881d1541b099). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, |
| 328 | void (*fnc)(ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT#, const char *)) |
| 329 | { |
| 330 | if (!ctx) |
| 331 | return ASSUAN_Invalid_Valuecxx . . $ ASSUAN_Invalid_Value.; |
| 332 | ctx->input_notify_fnccxx . . $ assuan_context_s#input_notify_fnc. = fnc; |
| 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | int |
| 337 | assuan_register_output_notifycxx . . $ assuan_register_output_notify(14c8881d1541b099). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, |
| 338 | void (*fnc)(ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT#, const char *)) |
| 339 | { |
| 340 | if (!ctx) |
| 341 | return ASSUAN_Invalid_Valuecxx . . $ ASSUAN_Invalid_Value.; |
| 342 | ctx->output_notify_fnccxx . . $ assuan_context_s#output_notify_fnc. = fnc; |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | |
| 347 | /* Helper to register the standards commands */ |
| 348 | int |
| 349 | _assuan_register_std_commandscxx . . $ _assuan_register_std_commands(29493cd997091d1). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx) |
| 350 | { |
| 351 | int i, rc; |
| 352 | |
| 353 | for (i=0; std_cmd_tablecxx . . $ std_cmd_table.[i].namecxx . . $ $anonymous_type_53b7d2eb4f2628e8_0#name.; i++) |
| 354 | { |
| 355 | if (std_cmd_tablecxx . . $ std_cmd_table.[i].alwayscxx . . $ $anonymous_type_53b7d2eb4f2628e8_0#always.) |
| 356 | { |
| 357 | rc = assuan_register_commandcxx . . $ assuan_register_command(b82481c29d01abcc). (ctx, std_cmd_tablecxx . . $ std_cmd_table.[i].cmd_idcxx . . $ $anonymous_type_53b7d2eb4f2628e8_0#cmd_id., |
| 358 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 359 | if (rc) |
| 360 | return rc; |
| 361 | } |
| 362 | } |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | |
| 367 | |
| 368 | /* Process the special data lines. The "D " has already been removed |
| 369 | from the line. As all handlers this function may modify the line. */ |
| 370 | static int |
| 371 | handle_data_linecxx . . $ handle_data_line(13ebee8a28cdfd7a). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line, int linelen) |
| 372 | { |
| 373 | return set_errorcxx . . $ `assuan/assuan-defs.h:132:9`! (ctx, Not_Implemented, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 374 | } |
| 375 | |
| 376 | /* like ascii_strcasecmp but assume that B is already uppercase */ |
| 377 | static int |
| 378 | my_strcasecmpcxx . . $ my_strcasecmp(5ae29d726ae57f88). (const char *a, const char *b) |
| 379 | { |
| 380 | if (a == b) |
| 381 | return 0; |
| 382 | |
| 383 | for (; *a && *b; a++, b++) |
| 384 | { |
| 385 | if (((*a >= 'a' && *a <= 'z')? (*a&~0x20):*a) != *b) |
| 386 | break; |
| 387 | } |
| 388 | return *a == *b? 0 : (((*a >= 'a' && *a <= 'z')? (*a&~0x20):*a) - *b); |
| 389 | } |
| 390 | |
| 391 | /* Parse the line, break out the command, find it in the command |
| 392 | table, remove leading and white spaces from the arguments, all the |
| 393 | handler with the argument line and return the error */ |
| 394 | static int |
| 395 | dispatch_commandcxx . . $ dispatch_command(13ebee8a28cdfd7a). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char *line, int linelen) |
| 396 | { |
| 397 | char *p; |
| 398 | const char *s; |
| 399 | int shift, i; |
| 400 | |
| 401 | if (*line == 'D' && line[1] == ' ') /* divert to special handler */ |
| 402 | return handle_data_linecxx . . $ handle_data_line(13ebee8a28cdfd7a). (ctx, line+2, linelen-2); |
| 403 | |
| 404 | for (p=line; *p && *p != ' ' && *p != '\t'; p++) |
| 405 | ; |
| 406 | if (p==line) |
| 407 | return set_errorcxx . . $ `assuan/assuan-defs.h:132:9`! (ctx, Syntax_Error, "leading white-space"); |
| 408 | if (*p) |
| 409 | { /* Skip over leading WS after the keyword */ |
| 410 | *p++ = 0; |
| 411 | while ( *p == ' ' || *p == '\t') |
| 412 | p++; |
| 413 | } |
| 414 | shift = p - line; |
| 415 | |
| 416 | for (i=0; (s=ctx->cmdtblcxx . . $ assuan_context_s#cmdtbl.[i].namecxx . . $ cmdtbl_s#name.); i++) |
| 417 | { |
| 418 | if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88). (line, s)) |
| 419 | break; |
| 420 | } |
| 421 | if (!s) |
| 422 | { /* and try case insensitive */ |
| 423 | for (i=0; (s=ctx->cmdtblcxx . . $ assuan_context_s#cmdtbl.[i].namecxx . . $ cmdtbl_s#name.); i++) |
| 424 | { |
| 425 | if (!my_strcasecmpcxx . . $ my_strcasecmp(5ae29d726ae57f88). (line, s)) |
| 426 | break; |
| 427 | } |
| 428 | } |
| 429 | if (!s) |
| 430 | return set_errorcxx . . $ `assuan/assuan-defs.h:132:9`! (ctx, Unknown_Command, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 431 | line += shift; |
| 432 | linelen -= shift; |
| 433 | |
| 434 | /* fprintf (stderr, "DBG-assuan: processing %s `%s'\n", s, line); */ |
| 435 | return ctx->cmdtblcxx . . $ assuan_context_s#cmdtbl.[i].handlercxx . . $ cmdtbl_s#handler. (ctx, line); |
| 436 | } |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | static int |
| 442 | process_requestcxx . . $ process_request(29493cd997091d1). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx) |
| 443 | { |
| 444 | int rc; |
| 445 | |
| 446 | if (ctx->in_inquirecxx . . $ assuan_context_s#in_inquire.) |
| 447 | return ASSUAN_Nested_Commandscxx . . $ ASSUAN_Nested_Commands.; |
| 448 | |
| 449 | rc = _assuan_read_linecxx . . $ _assuan_read_line(29493cd997091d1). (ctx); |
| 450 | if (rc) |
| 451 | return rc; |
| 452 | if (*ctx->inboundcxx . . $ assuan_context_s#inbound..linecxx . . $ assuan_context_s#$anonymous_type_0#line. == '#' || !ctx->inboundcxx . . $ assuan_context_s#inbound..linelencxx . . $ assuan_context_s#$anonymous_type_0#linelen.) |
| 453 | return 0; /* comment line - ignore */ |
| 454 | |
| 455 | ctx->outboundcxx . . $ assuan_context_s#outbound..datacxx . . $ assuan_context_s#$anonymous_type_2#data..errorcxx . . $ assuan_context_s#$anonymous_type_2#$anonymous_type_3#error. = 0; |
| 456 | ctx->outboundcxx . . $ assuan_context_s#outbound..datacxx . . $ assuan_context_s#$anonymous_type_2#data..linelencxx . . $ assuan_context_s#$anonymous_type_2#$anonymous_type_3#linelen. = 0; |
| 457 | /* dispatch command and return reply */ |
| 458 | rc = dispatch_commandcxx . . $ dispatch_command(13ebee8a28cdfd7a). (ctx, ctx->inboundcxx . . $ assuan_context_s#inbound..linecxx . . $ assuan_context_s#$anonymous_type_0#line., ctx->inboundcxx . . $ assuan_context_s#inbound..linelencxx . . $ assuan_context_s#$anonymous_type_0#linelen.); |
| 459 | /* check from data write errors */ |
| 460 | if (ctx->outboundcxx . . $ assuan_context_s#outbound..datacxx . . $ assuan_context_s#$anonymous_type_2#data..fpcxx . . $ assuan_context_s#$anonymous_type_2#$anonymous_type_3#fp.) |
| 461 | { /* Flush the data lines */ |
| 462 | fclosecxx . . $ fclose(89bc1efcdac0ca22). (ctx->outboundcxx . . $ assuan_context_s#outbound..datacxx . . $ assuan_context_s#$anonymous_type_2#data..fpcxx . . $ assuan_context_s#$anonymous_type_2#$anonymous_type_3#fp.); |
| 463 | ctx->outboundcxx . . $ assuan_context_s#outbound..datacxx . . $ assuan_context_s#$anonymous_type_2#data..fpcxx . . $ assuan_context_s#$anonymous_type_2#$anonymous_type_3#fp. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 464 | if (!rc && ctx->outboundcxx . . $ assuan_context_s#outbound..datacxx . . $ assuan_context_s#$anonymous_type_2#data..errorcxx . . $ assuan_context_s#$anonymous_type_2#$anonymous_type_3#error.) |
| 465 | rc = ctx->outboundcxx . . $ assuan_context_s#outbound..datacxx . . $ assuan_context_s#$anonymous_type_2#data..errorcxx . . $ assuan_context_s#$anonymous_type_2#$anonymous_type_3#error.; |
| 466 | } |
| 467 | else /* flush any data send w/o using the data fp */ |
| 468 | { |
| 469 | assuan_send_datacxx . . $ assuan_send_data(7bfc732ed11f6ee8). (ctx, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0); |
| 470 | if (!rc && ctx->outboundcxx . . $ assuan_context_s#outbound..datacxx . . $ assuan_context_s#$anonymous_type_2#data..errorcxx . . $ assuan_context_s#$anonymous_type_2#$anonymous_type_3#error.) |
| 471 | rc = ctx->outboundcxx . . $ assuan_context_s#outbound..datacxx . . $ assuan_context_s#$anonymous_type_2#data..errorcxx . . $ assuan_context_s#$anonymous_type_2#$anonymous_type_3#error.; |
| 472 | } |
| 473 | /* Error handling */ |
| 474 | if (!rc) |
| 475 | { |
| 476 | rc = assuan_write_linecxx . . $ assuan_write_line(ee7b1645795a12df). (ctx, ctx->okay_linecxx . . $ assuan_context_s#okay_line.? ctx->okay_linecxx . . $ assuan_context_s#okay_line. : "OK"); |
| 477 | } |
| 478 | else if (rc == -1) |
| 479 | { /* No error checking because the peer may have already disconnect */ |
| 480 | assuan_write_linecxx . . $ assuan_write_line(ee7b1645795a12df). (ctx, "OK closing connection"); |
| 481 | ctx->finish_handlercxx . . $ assuan_context_s#finish_handler. (ctx); |
| 482 | } |
| 483 | else |
| 484 | { |
| 485 | char errline[256]; |
| 486 | |
| 487 | if (rc < 100) |
| 488 | sprintfcxx . . $ sprintf(26c8642d26409d6d). (errline, "ERR %d server fault (%.50s)", |
| 489 | ASSUAN_Server_Faultcxx . . $ ASSUAN_Server_Fault., assuan_strerrorcxx . . $ assuan_strerror(fffa0a52a4999444). (rc)); |
| 490 | else |
| 491 | { |
| 492 | const char *text = ctx->err_nocxx . . $ assuan_context_s#err_no. == rc? ctx->err_strcxx . . $ assuan_context_s#err_str.:NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 493 | |
| 494 | sprintfcxx . . $ sprintf(26c8642d26409d6d). (errline, "ERR %d %.50s%s%.100s", |
| 495 | rc, assuan_strerrorcxx . . $ assuan_strerror(fffa0a52a4999444). (rc), text? " - ":"", text?text:""); |
| 496 | } |
| 497 | rc = assuan_write_linecxx . . $ assuan_write_line(ee7b1645795a12df). (ctx, errline); |
| 498 | } |
| 499 | |
| 500 | ctx->confidentialcxx . . $ assuan_context_s#confidential. = 0; |
| 501 | if (ctx->okay_linecxx . . $ assuan_context_s#okay_line.) |
| 502 | { |
| 503 | xfreecxx . . $ `assuan/assuan-defs.h:130:9`! (ctx->okay_line); |
| 504 | ctx->okay_linecxx . . $ assuan_context_s#okay_line. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 505 | } |
| 506 | return rc; |
| 507 | } |
| 508 | |
| 509 | /** |
| 510 | * assuan_process: |
| 511 | * @ctx: assuan context |
| 512 | * |
| 513 | * This fucntion is used to handle the assuan protocol after a |
| 514 | * connection has been established using assuan_accept(). This is the |
| 515 | * main protocol handler. |
| 516 | * |
| 517 | * Return value: 0 on success or an error code if the assuan operation |
| 518 | * failed. Note, that no error is returned for operational errors. |
| 519 | **/ |
| 520 | int |
| 521 | assuan_processcxx . . $ assuan_process(29493cd997091d1). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx) |
| 522 | { |
| 523 | int rc; |
| 524 | |
| 525 | do { |
| 526 | rc = process_requestcxx . . $ process_request(29493cd997091d1). (ctx); |
| 527 | } while (!rc); |
| 528 | |
| 529 | if (rc == -1) |
| 530 | rc = 0; |
| 531 | |
| 532 | return rc; |
| 533 | } |
| 534 | |
| 535 | |
| 536 | /** |
| 537 | * assuan_process_next: |
| 538 | * @ctx: Assuan context |
| 539 | * |
| 540 | * Same as assuan_process() but the user has to provide the outer |
| 541 | * loop. He should loop as long as the return code is zero and stop |
| 542 | * otherwise; -1 is regular end. |
| 543 | * |
| 544 | * See also: assuan_get_active_fds() |
| 545 | * Return value: -1 for end of server, 0 on success or an error code |
| 546 | **/ |
| 547 | int |
| 548 | assuan_process_nextcxx . . $ assuan_process_next(29493cd997091d1). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx) |
| 549 | { |
| 550 | return process_requestcxx . . $ process_request(29493cd997091d1). (ctx); |
| 551 | } |
| 552 | |
| 553 | |
| 554 | /** |
| 555 | * assuan_get_active_fds: |
| 556 | * @ctx: Assuan context |
| 557 | * @what: 0 for read fds, 1 for write fds |
| 558 | * @fdarray: Caller supplied array to store the FDs |
| 559 | * @fdarraysize: size of that array |
| 560 | * |
| 561 | * Return all active filedescriptors for the given context. This |
| 562 | * function can be used to select on the fds and call |
| 563 | * assuan_process_next() if there is an active one. The first fd in |
| 564 | * the array is the one used for the command connection. |
| 565 | * |
| 566 | * Note, that write FDs are not yet supported. |
| 567 | * |
| 568 | * Return value: number of FDs active and put into @fdarray or -1 on |
| 569 | * error which is most likely a too small fdarray. |
| 570 | **/ |
| 571 | int |
| 572 | assuan_get_active_fdscxx . . $ assuan_get_active_fds(9cac892d37ce2557). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, int what, |
| 573 | int *fdarray, int fdarraysize) |
| 574 | { |
| 575 | int n = 0; |
| 576 | |
| 577 | if (!ctx || fdarraysize < 2 || what < 0 || what > 1) |
| 578 | return -1; |
| 579 | |
| 580 | if (!what) |
| 581 | { |
| 582 | if (ctx->inboundcxx . . $ assuan_context_s#inbound..fdcxx . . $ assuan_context_s#$anonymous_type_0#fd. != -1) |
| 583 | fdarray[n++] = ctx->inboundcxx . . $ assuan_context_s#inbound..fdcxx . . $ assuan_context_s#$anonymous_type_0#fd.; |
| 584 | } |
| 585 | else |
| 586 | { |
| 587 | if (ctx->outboundcxx . . $ assuan_context_s#outbound..fdcxx . . $ assuan_context_s#$anonymous_type_2#fd. != -1) |
| 588 | fdarray[n++] = ctx->outboundcxx . . $ assuan_context_s#outbound..fdcxx . . $ assuan_context_s#$anonymous_type_2#fd.; |
| 589 | if (ctx->outboundcxx . . $ assuan_context_s#outbound..datacxx . . $ assuan_context_s#$anonymous_type_2#data..fpcxx . . $ assuan_context_s#$anonymous_type_2#$anonymous_type_3#fp.) |
| 590 | fdarray[n++] = filenocxx . . $ fileno(89bc1efcdac0ca22). (ctx->outboundcxx . . $ assuan_context_s#outbound..datacxx . . $ assuan_context_s#$anonymous_type_2#data..fpcxx . . $ assuan_context_s#$anonymous_type_2#$anonymous_type_3#fp.); |
| 591 | } |
| 592 | |
| 593 | return n; |
| 594 | } |
| 595 | |
| 596 | |
| 597 | /* Set the text used for the next OK reponse. This string is |
| 598 | automatically reset to NULL after the next command. */ |
| 599 | AssuanErrorcxx . . $ AssuanError# |
| 600 | assuan_set_okay_linecxx . . $ assuan_set_okay_line(ee7b1645795a12df). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, const char *line) |
| 601 | { |
| 602 | if (!ctx) |
| 603 | return ASSUAN_Invalid_Valuecxx . . $ ASSUAN_Invalid_Value.; |
| 604 | if (!line) |
| 605 | { |
| 606 | xfreecxx . . $ `assuan/assuan-defs.h:130:9`! (ctx->okay_line); |
| 607 | ctx->okay_linecxx . . $ assuan_context_s#okay_line. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 608 | } |
| 609 | else |
| 610 | { |
| 611 | /* FIXME: we need to use gcry_is_secure() to test whether |
| 612 | we should allocate the entire line in secure memory */ |
| 613 | char *buf = xtrymalloccxx . . $ `assuan/assuan-defs.h:127:9`! (3+strlen(line)+1); |
| 614 | if (!buf) |
| 615 | return ASSUAN_Out_Of_Corecxx . . $ ASSUAN_Out_Of_Core.; |
| 616 | strcpycxx . . $ strcpy(b7b3a83273496486). (buf, "OK "); |
| 617 | strcpycxx . . $ strcpy(b7b3a83273496486). (buf+3, line); |
| 618 | xfreecxx . . $ `assuan/assuan-defs.h:130:9`! (ctx->okay_line); |
| 619 | ctx->okay_linecxx . . $ assuan_context_s#okay_line. = buf; |
| 620 | } |
| 621 | return 0; |
| 622 | } |
| 623 | |
| 624 | |
| 625 | |
| 626 | void |
| 627 | assuan_write_statuscxx . . $ assuan_write_status(51262ec0335f25d0). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, const char *keyword, const char *text) |
| 628 | { |
| 629 | char buffer[256]; |
| 630 | char *helpbuf; |
| 631 | size_t n; |
| 632 | |
| 633 | if ( !ctx || !keyword) |
| 634 | return; |
| 635 | if (!text) |
| 636 | text = ""; |
| 637 | |
| 638 | n = 2 + strlencxx . . $ strlen(751346f8406fd082). (keyword) + 1 + strlencxx . . $ strlen(751346f8406fd082). (text) + 1; |
| 639 | if (n < sizeof (buffer)) |
| 640 | { |
| 641 | strcpycxx . . $ strcpy(b7b3a83273496486). (buffer, "S "); |
| 642 | strcatcxx . . $ strcat(b7b3a83273496486). (buffer, keyword); |
| 643 | if (*text) |
| 644 | { |
| 645 | strcatcxx . . $ strcat(b7b3a83273496486). (buffer, " "); |
| 646 | strcatcxx . . $ strcat(b7b3a83273496486). (buffer, text); |
| 647 | } |
| 648 | assuan_write_linecxx . . $ assuan_write_line(ee7b1645795a12df). (ctx, buffer); |
| 649 | } |
| 650 | else if ( (helpbuf = xtrymalloccxx . . $ `assuan/assuan-defs.h:127:9`! (n)) ) |
| 651 | { |
| 652 | strcpycxx . . $ strcpy(b7b3a83273496486). (helpbuf, "S "); |
| 653 | strcatcxx . . $ strcat(b7b3a83273496486). (helpbuf, keyword); |
| 654 | if (*text) |
| 655 | { |
| 656 | strcatcxx . . $ strcat(b7b3a83273496486). (helpbuf, " "); |
| 657 | strcatcxx . . $ strcat(b7b3a83273496486). (helpbuf, text); |
| 658 | } |
| 659 | assuan_write_linecxx . . $ assuan_write_line(ee7b1645795a12df). (ctx, helpbuf); |
| 660 | xfreecxx . . $ `assuan/assuan-defs.h:130:9`! (helpbuf); |
| 661 | } |
| 662 | } |