| 1 | /* assuan-buffer.c - read and send data |
| 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 <string.h> |
| 24 | #include <stdio.h> |
| 25 | #include <errno.h> |
| 26 | #include <unistd.h> |
| 27 | #include <assert.h> |
| 28 | #ifdef USE_GNU_PTH |
| 29 | # include <pth.h> |
| 30 | #endif |
| 31 | #include "assuan-defs.h"cxx . . $ `<file>/assuan/assuan-defs.h`/ |
| 32 | |
| 33 | #ifdef HAVE_JNLIB_LOGGING |
| 34 | #include "../jnlib/logging.h" |
| 35 | #endif |
| 36 | |
| 37 | |
| 38 | static const char * |
| 39 | my_log_prefixcxx . . $ my_log_prefix(33a1f659e94feb42). (void) |
| 40 | { |
| 41 | #ifdef HAVE_JNLIB_LOGGING |
| 42 | return log_get_prefix (NULL); |
| 43 | #else |
| 44 | return ""; |
| 45 | #endif |
| 46 | } |
| 47 | |
| 48 | |
| 49 | static int |
| 50 | writencxx . . $ writen(b038ed77b6a083f0). ( int fd, const char *buffer, size_t length ) |
| 51 | { |
| 52 | while (length) |
| 53 | { |
| 54 | #ifdef USE_GNU_PTH |
| 55 | int nwritten = pth_write (fd, buffer, length); |
| 56 | #else |
| 57 | int nwritten = writecxx . . $ write(41184a59d38b4f65). (fd, buffer, length); |
| 58 | #endif |
| 59 | |
| 60 | if (nwritten < 0) |
| 61 | { |
| 62 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!) |
| 63 | continue; |
| 64 | return -1; /* write error */ |
| 65 | } |
| 66 | length -= nwritten; |
| 67 | buffer += nwritten; |
| 68 | } |
| 69 | return 0; /* okay */ |
| 70 | } |
| 71 | |
| 72 | /* read an entire line */ |
| 73 | static int |
| 74 | readlinecxx . . $ readline(22c5a39278ae1672). (int fd, char *buf, size_t buflen, int *r_nread, int *iseof) |
| 75 | { |
| 76 | size_t nleft = buflen; char *p; |
| 77 | |
| 78 | *iseof = 0; |
| 79 | *r_nread = 0; |
| 80 | while (nleft > 0) |
| 81 | { |
| 82 | #ifdef USE_GNU_PTH |
| 83 | int n = pth_read (fd, buf, nleft); |
| 84 | #else |
| 85 | int n = readcxx . . $ read(7e34d0a36f355389). (fd, buf, nleft); |
| 86 | #endif |
| 87 | if (n < 0) |
| 88 | { |
| 89 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!) |
| 90 | continue; |
| 91 | return -1; /* read error */ |
| 92 | } |
| 93 | else if (!n) |
| 94 | { |
| 95 | *iseof = 1; |
| 96 | break; /* allow incomplete lines */ |
| 97 | } |
| 98 | p = buf; |
| 99 | nleft -= n; |
| 100 | buf += n; |
| 101 | *r_nread += n; |
| 102 | |
| 103 | for (; n && *p != '\n'; n--, p++) |
| 104 | ; |
| 105 | if (n) |
| 106 | break; /* at least one full line available - that's enough for now */ |
| 107 | } |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | |
| 113 | int |
| 114 | _assuan_read_linecxx . . $ _assuan_read_line(29493cd997091d1). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx) |
| 115 | { |
| 116 | char *line = ctx->inboundcxx . . $ assuan_context_s#inbound..linecxx . . $ assuan_context_s#$anonymous_type_0#line.; |
| 117 | int n, nread, atticlen; |
| 118 | int rc; |
| 119 | |
| 120 | if (ctx->inboundcxx . . $ assuan_context_s#inbound..eofcxx . . $ assuan_context_s#$anonymous_type_0#eof.) |
| 121 | return -1; |
| 122 | |
| 123 | atticlen = ctx->inboundcxx . . $ assuan_context_s#inbound..atticcxx . . $ assuan_context_s#$anonymous_type_0#attic..linelencxx . . $ assuan_context_s#$anonymous_type_0#$anonymous_type_1#linelen.; |
| 124 | if (atticlen) |
| 125 | { |
| 126 | memcpycxx . . $ memcpy(cc817cb175f282d). (line, ctx->inboundcxx . . $ assuan_context_s#inbound..atticcxx . . $ assuan_context_s#$anonymous_type_0#attic..linecxx . . $ assuan_context_s#$anonymous_type_0#$anonymous_type_1#line., atticlen); |
| 127 | ctx->inboundcxx . . $ assuan_context_s#inbound..atticcxx . . $ assuan_context_s#$anonymous_type_0#attic..linelencxx . . $ assuan_context_s#$anonymous_type_0#$anonymous_type_1#linelen. = 0; |
| 128 | for (n=0; n < atticlen && line[n] != '\n'; n++) |
| 129 | ; |
| 130 | if (n < atticlen) |
| 131 | { |
| 132 | rc = 0; /* found another line in the attic */ |
| 133 | nread = atticlen; |
| 134 | atticlen = 0; |
| 135 | } |
| 136 | else |
| 137 | { /* read the rest */ |
| 138 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`! (atticlen < LINELENGTHcxx . . $ `assuan/assuan-defs.h:27:9`!); |
| 139 | rc = readlinecxx . . $ readline(22c5a39278ae1672). (ctx->inboundcxx . . $ assuan_context_s#inbound..fdcxx . . $ assuan_context_s#$anonymous_type_0#fd., line + atticlen, |
| 140 | LINELENGTHcxx . . $ `assuan/assuan-defs.h:27:9`! - atticlen, &nread, &ctx->inboundcxx . . $ assuan_context_s#inbound..eofcxx . . $ assuan_context_s#$anonymous_type_0#eof.); |
| 141 | } |
| 142 | } |
| 143 | else |
| 144 | rc = readlinecxx . . $ readline(22c5a39278ae1672). (ctx->inboundcxx . . $ assuan_context_s#inbound..fdcxx . . $ assuan_context_s#$anonymous_type_0#fd., line, LINELENGTHcxx . . $ `assuan/assuan-defs.h:27:9`!, |
| 145 | &nread, &ctx->inboundcxx . . $ assuan_context_s#inbound..eofcxx . . $ assuan_context_s#$anonymous_type_0#eof.); |
| 146 | if (rc) |
| 147 | { |
| 148 | if (ctx->log_fpcxx . . $ assuan_context_s#log_fp.) |
| 149 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (ctx->log_fpcxx . . $ assuan_context_s#log_fp., "%s[%p] <- [Error: %s]\n", |
| 150 | my_log_prefixcxx . . $ my_log_prefix(33a1f659e94feb42). (), ctx, strerrorcxx . . $ strerror(ff224f080444ee45). (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 151 | return ASSUAN_Read_Errorcxx . . $ ASSUAN_Read_Error.; |
| 152 | } |
| 153 | if (!nread) |
| 154 | { |
| 155 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`! (ctx->inbound.eof); |
| 156 | if (ctx->log_fpcxx . . $ assuan_context_s#log_fp.) |
| 157 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (ctx->log_fpcxx . . $ assuan_context_s#log_fp., "%s[%p] <- [EOF]\n", my_log_prefixcxx . . $ my_log_prefix(33a1f659e94feb42). (),ctx); |
| 158 | return -1; |
| 159 | } |
| 160 | |
| 161 | ctx->inboundcxx . . $ assuan_context_s#inbound..atticcxx . . $ assuan_context_s#$anonymous_type_0#attic..pendingcxx . . $ assuan_context_s#$anonymous_type_0#$anonymous_type_1#pending. = 0; |
| 162 | nread += atticlen; |
| 163 | for (n=0; n < nread; n++) |
| 164 | { |
| 165 | if (line[n] == '\n') |
| 166 | { |
| 167 | if (n+1 < nread) |
| 168 | { |
| 169 | char *s, *d; |
| 170 | int i; |
| 171 | |
| 172 | n++; |
| 173 | /* we have to copy the rest because the handlers are |
| 174 | allowed to modify the passed buffer */ |
| 175 | for (d=ctx->inboundcxx . . $ assuan_context_s#inbound..atticcxx . . $ assuan_context_s#$anonymous_type_0#attic..linecxx . . $ assuan_context_s#$anonymous_type_0#$anonymous_type_1#line., s=line+n, i=nread-n; i; i--) |
| 176 | { |
| 177 | if (*s=='\n') |
| 178 | ctx->inboundcxx . . $ assuan_context_s#inbound..atticcxx . . $ assuan_context_s#$anonymous_type_0#attic..pendingcxx . . $ assuan_context_s#$anonymous_type_0#$anonymous_type_1#pending. = 1; |
| 179 | *d++ = *s++; |
| 180 | } |
| 181 | ctx->inboundcxx . . $ assuan_context_s#inbound..atticcxx . . $ assuan_context_s#$anonymous_type_0#attic..linelencxx . . $ assuan_context_s#$anonymous_type_0#$anonymous_type_1#linelen. = nread-n; |
| 182 | n--; |
| 183 | } |
| 184 | if (n && line[n-1] == '\r') |
| 185 | n--; |
| 186 | line[n] = 0; |
| 187 | ctx->inboundcxx . . $ assuan_context_s#inbound..linelencxx . . $ assuan_context_s#$anonymous_type_0#linelen. = n; |
| 188 | if (ctx->log_fpcxx . . $ assuan_context_s#log_fp.) |
| 189 | { |
| 190 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (ctx->log_fpcxx . . $ assuan_context_s#log_fp., "%s[%p] <- ", my_log_prefixcxx . . $ my_log_prefix(33a1f659e94feb42). (), ctx); |
| 191 | if (ctx->confidentialcxx . . $ assuan_context_s#confidential.) |
| 192 | fputscxx . . $ fputs(874fa6a5e59ab9bd). ("[Confidential data not shown]", ctx->log_fpcxx . . $ assuan_context_s#log_fp.); |
| 193 | else |
| 194 | _assuan_log_print_buffercxx . . $ _assuan_log_print_buffer(4a34f311aa103ecc). (ctx->log_fpcxx . . $ assuan_context_s#log_fp., |
| 195 | ctx->inboundcxx . . $ assuan_context_s#inbound..linecxx . . $ assuan_context_s#$anonymous_type_0#line., |
| 196 | ctx->inboundcxx . . $ assuan_context_s#inbound..linelencxx . . $ assuan_context_s#$anonymous_type_0#linelen.); |
| 197 | putccxx . . $ putc(b1cd03d6c470d1bd). ('\n', ctx->log_fpcxx . . $ assuan_context_s#log_fp.); |
| 198 | } |
| 199 | return 0; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | if (ctx->log_fpcxx . . $ assuan_context_s#log_fp.) |
| 204 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (ctx->log_fpcxx . . $ assuan_context_s#log_fp., "%s[%p] <- [Invalid line]\n", my_log_prefixcxx . . $ my_log_prefix(33a1f659e94feb42). (), ctx); |
| 205 | *line = 0; |
| 206 | ctx->inboundcxx . . $ assuan_context_s#inbound..linelencxx . . $ assuan_context_s#$anonymous_type_0#linelen. = 0; |
| 207 | return ctx->inboundcxx . . $ assuan_context_s#inbound..eofcxx . . $ assuan_context_s#$anonymous_type_0#eof.? ASSUAN_Line_Not_Terminatedcxx . . $ ASSUAN_Line_Not_Terminated. : ASSUAN_Line_Too_Longcxx . . $ ASSUAN_Line_Too_Long.; |
| 208 | } |
| 209 | |
| 210 | |
| 211 | /* Read the next line from the client or server and return a pointer |
| 212 | to a buffer with holding that line. linelen returns the length of |
| 213 | the line. This buffer is valid until another read operation is |
| 214 | done on this buffer. The caller is allowed to modify this buffer. |
| 215 | He should only use the buffer if the function returns without an |
| 216 | error. |
| 217 | |
| 218 | Returns: 0 on success or an assuan error code |
| 219 | See also: assuan_pending_line(). |
| 220 | */ |
| 221 | AssuanErrorcxx . . $ AssuanError# |
| 222 | assuan_read_linecxx . . $ assuan_read_line(cf365bd337ca36f2). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, char **line, size_t *linelen) |
| 223 | { |
| 224 | AssuanErrorcxx . . $ AssuanError# err; |
| 225 | |
| 226 | if (!ctx) |
| 227 | return ASSUAN_Invalid_Valuecxx . . $ ASSUAN_Invalid_Value.; |
| 228 | |
| 229 | err = _assuan_read_linecxx . . $ _assuan_read_line(29493cd997091d1). (ctx); |
| 230 | *line = ctx->inboundcxx . . $ assuan_context_s#inbound..linecxx . . $ assuan_context_s#$anonymous_type_0#line.; |
| 231 | *linelen = ctx->inboundcxx . . $ assuan_context_s#inbound..linelencxx . . $ assuan_context_s#$anonymous_type_0#linelen.; |
| 232 | return err; |
| 233 | } |
| 234 | |
| 235 | |
| 236 | /* Return true when a full line is pending for a read, without the need |
| 237 | for actual IO */ |
| 238 | int |
| 239 | assuan_pending_linecxx . . $ assuan_pending_line(29493cd997091d1). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx) |
| 240 | { |
| 241 | return ctx && ctx->inboundcxx . . $ assuan_context_s#inbound..atticcxx . . $ assuan_context_s#$anonymous_type_0#attic..pendingcxx . . $ assuan_context_s#$anonymous_type_0#$anonymous_type_1#pending.; |
| 242 | } |
| 243 | |
| 244 | |
| 245 | AssuanErrorcxx . . $ AssuanError# |
| 246 | assuan_write_linecxx . . $ assuan_write_line(ee7b1645795a12df). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, const char *line ) |
| 247 | { |
| 248 | int rc; |
| 249 | |
| 250 | if (!ctx) |
| 251 | return ASSUAN_Invalid_Valuecxx . . $ ASSUAN_Invalid_Value.; |
| 252 | |
| 253 | /* fixme: we should do some kind of line buffering */ |
| 254 | if (ctx->log_fpcxx . . $ assuan_context_s#log_fp.) |
| 255 | { |
| 256 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (ctx->log_fpcxx . . $ assuan_context_s#log_fp., "%s[%p] -> ", my_log_prefixcxx . . $ my_log_prefix(33a1f659e94feb42). (), ctx); |
| 257 | if (ctx->confidentialcxx . . $ assuan_context_s#confidential.) |
| 258 | fputscxx . . $ fputs(874fa6a5e59ab9bd). ("[Confidential data not shown]", ctx->log_fpcxx . . $ assuan_context_s#log_fp.); |
| 259 | else |
| 260 | _assuan_log_print_buffercxx . . $ _assuan_log_print_buffer(4a34f311aa103ecc). (ctx->log_fpcxx . . $ assuan_context_s#log_fp., |
| 261 | line, strlencxx . . $ strlen(751346f8406fd082). (line)); |
| 262 | putccxx . . $ putc(b1cd03d6c470d1bd). ('\n', ctx->log_fpcxx . . $ assuan_context_s#log_fp.); |
| 263 | } |
| 264 | |
| 265 | rc = writencxx . . $ writen(b038ed77b6a083f0). (ctx->outboundcxx . . $ assuan_context_s#outbound..fdcxx . . $ assuan_context_s#$anonymous_type_2#fd., line, strlencxx . . $ strlen(751346f8406fd082).(line)); |
| 266 | if (rc) |
| 267 | rc = ASSUAN_Write_Errorcxx . . $ ASSUAN_Write_Error.; |
| 268 | if (!rc) |
| 269 | { |
| 270 | rc = writencxx . . $ writen(b038ed77b6a083f0). (ctx->outboundcxx . . $ assuan_context_s#outbound..fdcxx . . $ assuan_context_s#$anonymous_type_2#fd., "\n", 1); |
| 271 | if (rc) |
| 272 | rc = ASSUAN_Write_Errorcxx . . $ ASSUAN_Write_Error.; |
| 273 | } |
| 274 | |
| 275 | return rc; |
| 276 | } |
| 277 | |
| 278 | |
| 279 | |
| 280 | /* Write out the data in buffer as datalines with line wrapping and |
| 281 | percent escaping. This fucntion is used for GNU's custom streams */ |
| 282 | int |
| 283 | _assuan_cookie_write_datacxx . . $ _assuan_cookie_write_data(886e92dd2af22b63). (void *cookie, const char *buffer, size_t size) |
| 284 | { |
| 285 | ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx = cookie; |
| 286 | char *line; |
| 287 | size_t linelen; |
| 288 | |
| 289 | if (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.) |
| 290 | return 0; |
| 291 | |
| 292 | line = ctx->outboundcxx . . $ assuan_context_s#outbound..datacxx . . $ assuan_context_s#$anonymous_type_2#data..linecxx . . $ assuan_context_s#$anonymous_type_2#$anonymous_type_3#line.; |
| 293 | linelen = 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.; |
| 294 | line += linelen; |
| 295 | while (size) |
| 296 | { |
| 297 | /* insert data line header */ |
| 298 | if (!linelen) |
| 299 | { |
| 300 | *line++ = 'D'; |
| 301 | *line++ = ' '; |
| 302 | linelen += 2; |
| 303 | } |
| 304 | |
| 305 | /* copy data, keep some space for the CRLF and to escape one character */ |
| 306 | while (size && linelen < LINELENGTHcxx . . $ `assuan/assuan-defs.h:27:9`!-2-2) |
| 307 | { |
| 308 | if (*buffer == '%' || *buffer == '\r' || *buffer == '\n') |
| 309 | { |
| 310 | sprintfcxx . . $ sprintf(26c8642d26409d6d). (line, "%%%02X", *(unsigned char*)buffer); |
| 311 | line += 3; |
| 312 | linelen += 3; |
| 313 | buffer++; |
| 314 | } |
| 315 | else |
| 316 | { |
| 317 | *line++ = *buffer++; |
| 318 | linelen++; |
| 319 | } |
| 320 | size--; |
| 321 | } |
| 322 | |
| 323 | if (linelen >= LINELENGTHcxx . . $ `assuan/assuan-defs.h:27:9`!-2-2) |
| 324 | { |
| 325 | if (ctx->log_fpcxx . . $ assuan_context_s#log_fp.) |
| 326 | { |
| 327 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (ctx->log_fpcxx . . $ assuan_context_s#log_fp., "%s[%p] -> ", my_log_prefixcxx . . $ my_log_prefix(33a1f659e94feb42). (), ctx); |
| 328 | if (ctx->confidentialcxx . . $ assuan_context_s#confidential.) |
| 329 | fputscxx . . $ fputs(874fa6a5e59ab9bd). ("[Confidential data not shown]", ctx->log_fpcxx . . $ assuan_context_s#log_fp.); |
| 330 | else |
| 331 | _assuan_log_print_buffercxx . . $ _assuan_log_print_buffer(4a34f311aa103ecc). (ctx->log_fpcxx . . $ assuan_context_s#log_fp., |
| 332 | ctx->outboundcxx . . $ assuan_context_s#outbound..datacxx . . $ assuan_context_s#$anonymous_type_2#data..linecxx . . $ assuan_context_s#$anonymous_type_2#$anonymous_type_3#line., |
| 333 | linelen); |
| 334 | putccxx . . $ putc(b1cd03d6c470d1bd). ('\n', ctx->log_fpcxx . . $ assuan_context_s#log_fp.); |
| 335 | } |
| 336 | *line++ = '\n'; |
| 337 | linelen++; |
| 338 | if (writencxx . . $ writen(b038ed77b6a083f0). (ctx->outboundcxx . . $ assuan_context_s#outbound..fdcxx . . $ assuan_context_s#$anonymous_type_2#fd., ctx->outboundcxx . . $ assuan_context_s#outbound..datacxx . . $ assuan_context_s#$anonymous_type_2#data..linecxx . . $ assuan_context_s#$anonymous_type_2#$anonymous_type_3#line., linelen)) |
| 339 | { |
| 340 | 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. = ASSUAN_Write_Errorcxx . . $ ASSUAN_Write_Error.; |
| 341 | return 0; |
| 342 | } |
| 343 | line = ctx->outboundcxx . . $ assuan_context_s#outbound..datacxx . . $ assuan_context_s#$anonymous_type_2#data..linecxx . . $ assuan_context_s#$anonymous_type_2#$anonymous_type_3#line.; |
| 344 | linelen = 0; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | 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. = linelen; |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | |
| 353 | /* Write out any buffered data |
| 354 | This fucntion is used for GNU's custom streams */ |
| 355 | int |
| 356 | _assuan_cookie_write_flushcxx . . $ _assuan_cookie_write_flush(dedf1e9b1c614a07). (void *cookie) |
| 357 | { |
| 358 | ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx = cookie; |
| 359 | char *line; |
| 360 | size_t linelen; |
| 361 | |
| 362 | if (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.) |
| 363 | return 0; |
| 364 | |
| 365 | line = ctx->outboundcxx . . $ assuan_context_s#outbound..datacxx . . $ assuan_context_s#$anonymous_type_2#data..linecxx . . $ assuan_context_s#$anonymous_type_2#$anonymous_type_3#line.; |
| 366 | linelen = 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.; |
| 367 | line += linelen; |
| 368 | if (linelen) |
| 369 | { |
| 370 | if (ctx->log_fpcxx . . $ assuan_context_s#log_fp.) |
| 371 | { |
| 372 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (ctx->log_fpcxx . . $ assuan_context_s#log_fp., "%s[%p] -> ", my_log_prefixcxx . . $ my_log_prefix(33a1f659e94feb42). (), ctx); |
| 373 | if (ctx->confidentialcxx . . $ assuan_context_s#confidential.) |
| 374 | fputscxx . . $ fputs(874fa6a5e59ab9bd). ("[Confidential data not shown]", ctx->log_fpcxx . . $ assuan_context_s#log_fp.); |
| 375 | else |
| 376 | _assuan_log_print_buffercxx . . $ _assuan_log_print_buffer(4a34f311aa103ecc). (ctx->log_fpcxx . . $ assuan_context_s#log_fp., |
| 377 | ctx->outboundcxx . . $ assuan_context_s#outbound..datacxx . . $ assuan_context_s#$anonymous_type_2#data..linecxx . . $ assuan_context_s#$anonymous_type_2#$anonymous_type_3#line., |
| 378 | linelen); |
| 379 | putccxx . . $ putc(b1cd03d6c470d1bd). ('\n', ctx->log_fpcxx . . $ assuan_context_s#log_fp.); |
| 380 | } |
| 381 | *line++ = '\n'; |
| 382 | linelen++; |
| 383 | if (writencxx . . $ writen(b038ed77b6a083f0). (ctx->outboundcxx . . $ assuan_context_s#outbound..fdcxx . . $ assuan_context_s#$anonymous_type_2#fd., ctx->outboundcxx . . $ assuan_context_s#outbound..datacxx . . $ assuan_context_s#$anonymous_type_2#data..linecxx . . $ assuan_context_s#$anonymous_type_2#$anonymous_type_3#line., linelen)) |
| 384 | { |
| 385 | 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. = ASSUAN_Write_Errorcxx . . $ ASSUAN_Write_Error.; |
| 386 | return 0; |
| 387 | } |
| 388 | 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; |
| 389 | } |
| 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | |
| 394 | /** |
| 395 | * assuan_send_data: |
| 396 | * @ctx: An assuan context |
| 397 | * @buffer: Data to send or NULL to flush |
| 398 | * @length: length of the data to send/ |
| 399 | * |
| 400 | * This function may be used by the server or the client to send data |
| 401 | * lines. The data will be escaped as required by the Assuan protocol |
| 402 | * and may get buffered until a line is full. To force sending the |
| 403 | * data out @buffer may be passed as NULL (in which case @length must |
| 404 | * also be 0); however when used by a client this flush operation does |
| 405 | * also send the terminating "END" command to terminate the reponse on |
| 406 | * a INQUIRE response. However, when assuan_transact() is used, this |
| 407 | * function takes care of sending END itself. |
| 408 | * |
| 409 | * Return value: 0 on success or an error code |
| 410 | **/ |
| 411 | |
| 412 | AssuanErrorcxx . . $ AssuanError# |
| 413 | assuan_send_datacxx . . $ assuan_send_data(7bfc732ed11f6ee8). (ASSUAN_CONTEXTcxx . . $ ASSUAN_CONTEXT# ctx, const void *buffer, size_t length) |
| 414 | { |
| 415 | if (!ctx) |
| 416 | return ASSUAN_Invalid_Valuecxx . . $ ASSUAN_Invalid_Value.; |
| 417 | if (!buffer && length) |
| 418 | return ASSUAN_Invalid_Valuecxx . . $ ASSUAN_Invalid_Value.; |
| 419 | |
| 420 | if (!buffer) |
| 421 | { /* flush what we have */ |
| 422 | _assuan_cookie_write_flushcxx . . $ _assuan_cookie_write_flush(dedf1e9b1c614a07). (ctx); |
| 423 | if (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.) |
| 424 | return 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.; |
| 425 | if (!ctx->is_servercxx . . $ assuan_context_s#is_server.) |
| 426 | return assuan_write_linecxx . . $ assuan_write_line(ee7b1645795a12df). (ctx, "END"); |
| 427 | } |
| 428 | else |
| 429 | { |
| 430 | _assuan_cookie_write_datacxx . . $ _assuan_cookie_write_data(886e92dd2af22b63). (ctx, buffer, length); |
| 431 | if (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.) |
| 432 | return 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.; |
| 433 | } |
| 434 | |
| 435 | return 0; |
| 436 | } |
| 437 | |
| 438 | |
| 439 | |
| 440 |