| 1 | /* assuan-util.c - Utility functions for Assuan |
| 2 | * Copyright (C) 2001, 2002, 2003, 2004, 2005 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, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include <config.h>cxx . . $ `<file>/config.h`/ |
| 21 | #include <stdlib.h> |
| 22 | #include <stdio.h> |
| 23 | #include <string.h> |
| 24 | #include <ctype.h> |
| 25 | #include <errno.h> |
| 26 | |
| 27 | #include "assuan-defs.h"cxx . . $ `<file>/src/assuan/assuan-defs.h`/ |
| 28 | |
| 29 | static void *(*alloc_funccxx . . $ alloc_func.)(size_t n) = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).; |
| 30 | static void *(*realloc_funccxx . . $ realloc_func.)(void *p, size_t n) = realloccxx . . $ realloc(417ab160f6baadc6).; |
| 31 | static void (*free_funccxx . . $ free_func.)(void*) = freecxx . . $ free(5d22bdacc48458e8).; |
| 32 | |
| 33 | struct assuan_io_hookscxx . . $ assuan_io_hooks# _assuan_io_hookscxx . . $ `src/assuan/assuan.h:172:9`!; |
| 34 | |
| 35 | |
| 36 | |
| 37 | void |
| 38 | assuan_set_malloc_hookscxx . . $ `src/assuan/assuan.h:129:9`! ( void *(*new_alloc_func)(size_t n), |
| 39 | void *(*new_realloc_func)(void *p, size_t n), |
| 40 | void (*new_free_func)(void*) ) |
| 41 | { |
| 42 | alloc_funccxx . . $ alloc_func. = new_alloc_func; |
| 43 | realloc_funccxx . . $ realloc_func. = new_realloc_func; |
| 44 | free_funccxx . . $ free_func. = new_free_func; |
| 45 | } |
| 46 | |
| 47 | |
| 48 | void |
| 49 | assuan_set_io_hookscxx . . $ `src/assuan/assuan.h:130:9`! (assuan_io_hooks_tcxx . . $ assuan_io_hooks_t# io_hooks) |
| 50 | { |
| 51 | _assuan_io_hookscxx . . $ `src/assuan/assuan.h:172:9`!.read_hookcxx . . $ assuan_io_hooks#read_hook. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 52 | _assuan_io_hookscxx . . $ `src/assuan/assuan.h:172:9`!.write_hookcxx . . $ assuan_io_hooks#write_hook. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 53 | if (io_hooks) |
| 54 | { |
| 55 | _assuan_io_hookscxx . . $ `src/assuan/assuan.h:172:9`!.read_hookcxx . . $ assuan_io_hooks#read_hook. = io_hooks->read_hookcxx . . $ assuan_io_hooks#read_hook.; |
| 56 | _assuan_io_hookscxx . . $ `src/assuan/assuan.h:172:9`!.write_hookcxx . . $ assuan_io_hooks#write_hook. = io_hooks->write_hookcxx . . $ assuan_io_hooks#write_hook.; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | |
| 61 | void * |
| 62 | _assuan_malloccxx . . $ `src/assuan/assuan.h:175:9`! (size_t n) |
| 63 | { |
| 64 | return alloc_funccxx . . $ alloc_func. (n); |
| 65 | } |
| 66 | |
| 67 | void * |
| 68 | _assuan_realloccxx . . $ `src/assuan/assuan.h:176:9`! (void *a, size_t n) |
| 69 | { |
| 70 | return realloc_funccxx . . $ realloc_func. (a, n); |
| 71 | } |
| 72 | |
| 73 | void * |
| 74 | _assuan_calloccxx . . $ `src/assuan/assuan.h:177:9`! (size_t n, size_t m) |
| 75 | { |
| 76 | void *p; |
| 77 | size_t nbytes; |
| 78 | |
| 79 | nbytes = n * m; |
| 80 | if (m && nbytes / m != n) |
| 81 | { |
| 82 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 83 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 84 | } |
| 85 | |
| 86 | p = _assuan_malloccxx . . $ `src/assuan/assuan.h:175:9`! (nbytes); |
| 87 | if (p) |
| 88 | memsetcxx . . $ memset(d1de1e4fb215f1c6). (p, 0, nbytes); |
| 89 | return p; |
| 90 | } |
| 91 | |
| 92 | void |
| 93 | _assuan_freecxx . . $ `src/assuan/assuan.h:178:9`! (void *p) |
| 94 | { |
| 95 | if (p) |
| 96 | free_funccxx . . $ free_func. (p); |
| 97 | } |
| 98 | |
| 99 | |
| 100 | /* Store the error in the context so that the error sending function |
| 101 | can take out a descriptive text. Inside the assuan code, use the |
| 102 | macro set_error instead of this function. */ |
| 103 | int |
| 104 | assuan_set_errorcxx . . $ `src/assuan/assuan.h:132:9`! (assuan_context_tcxx . . $ assuan_context_t# ctx, int err, const char *text) |
| 105 | { |
| 106 | ctx->err_nocxx . . $ assuan_context_s#err_no. = err; |
| 107 | ctx->err_strcxx . . $ assuan_context_s#err_str. = text; |
| 108 | return err; |
| 109 | } |
| 110 | |
| 111 | void |
| 112 | assuan_set_pointercxx . . $ `src/assuan/assuan.h:133:9`! (assuan_context_tcxx . . $ assuan_context_t# ctx, void *pointer) |
| 113 | { |
| 114 | if (ctx) |
| 115 | ctx->user_pointercxx . . $ assuan_context_s#user_pointer. = pointer; |
| 116 | } |
| 117 | |
| 118 | void * |
| 119 | assuan_get_pointercxx . . $ `src/assuan/assuan.h:134:9`! (assuan_context_tcxx . . $ assuan_context_t# ctx) |
| 120 | { |
| 121 | return ctx? ctx->user_pointercxx . . $ assuan_context_s#user_pointer. : NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 122 | } |
| 123 | |
| 124 | |
| 125 | void |
| 126 | assuan_begin_confidentialcxx . . $ `src/assuan/assuan.h:136:9`! (assuan_context_tcxx . . $ assuan_context_t# ctx) |
| 127 | { |
| 128 | if (ctx) |
| 129 | { |
| 130 | ctx->confidentialcxx . . $ assuan_context_s#confidential. = 1; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | void |
| 135 | assuan_end_confidentialcxx . . $ `src/assuan/assuan.h:137:9`! (assuan_context_tcxx . . $ assuan_context_t# ctx) |
| 136 | { |
| 137 | if (ctx) |
| 138 | { |
| 139 | ctx->confidentialcxx . . $ assuan_context_s#confidential. = 0; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | |
| 144 | void |
| 145 | assuan_set_io_monitorcxx . . $ `src/assuan/assuan.h:135:9`! (assuan_context_tcxx . . $ assuan_context_t# ctx, |
| 146 | unsigned int (*monitor)(assuan_context_tcxx . . $ assuan_context_t# ctx, |
| 147 | int direction, |
| 148 | const char *line, |
| 149 | size_t linelen)) |
| 150 | { |
| 151 | if (ctx) |
| 152 | { |
| 153 | ctx->io_monitorcxx . . $ assuan_context_s#io_monitor. = monitor; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | /* For context CTX, set the flag FLAG to VALUE. Values for flags |
| 161 | are usually 1 or 0 but certain flags might allow for other values; |
| 162 | see the description of the type assuan_flag_t for details. */ |
| 163 | void |
| 164 | assuan_set_flagcxx . . $ `src/assuan/assuan.h:147:9`! (assuan_context_tcxx . . $ assuan_context_t# ctx, assuan_flag_tcxx . . $ assuan_flag_t# flag, int value) |
| 165 | { |
| 166 | if (!ctx) |
| 167 | return; |
| 168 | switch (flag) |
| 169 | { |
| 170 | case ASSUAN_NO_WAITPIDcxx . . $ ASSUAN_NO_WAITPID.: ctx->flagscxx . . $ assuan_context_s#flags..no_waitpidcxx . . $ assuan_context_s#$anonymous_type_0#no_waitpid. = value; break; |
| 171 | case ASSUAN_CONFIDENTIALcxx . . $ ASSUAN_CONFIDENTIAL.: ctx->confidentialcxx . . $ assuan_context_s#confidential. = value; break; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | /* Return the VALUE of FLAG in context CTX. */ |
| 176 | int |
| 177 | assuan_get_flagcxx . . $ `src/assuan/assuan.h:148:9`! (assuan_context_tcxx . . $ assuan_context_t# ctx, assuan_flag_tcxx . . $ assuan_flag_t# flag) |
| 178 | { |
| 179 | if (!ctx) |
| 180 | return 0; |
| 181 | switch (flag) |
| 182 | { |
| 183 | case ASSUAN_NO_WAITPIDcxx . . $ ASSUAN_NO_WAITPID.: return ctx->flagscxx . . $ assuan_context_s#flags..no_waitpidcxx . . $ assuan_context_s#$anonymous_type_0#no_waitpid.; |
| 184 | case ASSUAN_CONFIDENTIALcxx . . $ ASSUAN_CONFIDENTIAL.: return ctx->confidentialcxx . . $ assuan_context_s#confidential.; |
| 185 | } |
| 186 | return 0; |
| 187 | } |
| 188 |