diff options
author | Marcus Brinkmann <[email protected]> | 2006-09-19 14:01:54 +0000 |
---|---|---|
committer | Marcus Brinkmann <[email protected]> | 2006-09-19 14:01:54 +0000 |
commit | 9e09d93de83fe1160689acb36b082c02ccb52716 (patch) | |
tree | 807126be9dd89fe2850ad748de978de0c5d3b340 /assuan/assuan-buffer.c | |
parent | 2006-07-29 Marcus Brinkmann <[email protected]> (diff) | |
download | gpgme-9e09d93de83fe1160689acb36b082c02ccb52716.tar.gz gpgme-9e09d93de83fe1160689acb36b082c02ccb52716.zip |
assuan/
Update to current version.
2006-09-19 Marcus Brinkmann <[email protected]>
* configure.ac: Turn stpcpy into a replacement function.
Check for unistd.h and add setenv as replacement function.
gpgme/
2006-09-19 Marcus Brinkmann <[email protected]>
* setenv.c: New file.
Diffstat (limited to 'assuan/assuan-buffer.c')
-rw-r--r-- | assuan/assuan-buffer.c | 111 |
1 files changed, 62 insertions, 49 deletions
diff --git a/assuan/assuan-buffer.c b/assuan/assuan-buffer.c index 99ea72e3..5580392a 100644 --- a/assuan/assuan-buffer.c +++ b/assuan/assuan-buffer.c @@ -15,7 +15,8 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. */ #include <config.h> @@ -30,8 +31,11 @@ #endif #include "assuan-defs.h" + +/* Extended version of write(2) to guarantee that all bytes are + written. Returns 0 on success or -1 and ERRNO on failure. */ static int -writen (ASSUAN_CONTEXT ctx, const char *buffer, size_t length) +writen (assuan_context_t ctx, const char *buffer, size_t length) { while (length) { @@ -49,9 +53,11 @@ writen (ASSUAN_CONTEXT ctx, const char *buffer, size_t length) return 0; /* okay */ } -/* Read an entire line. */ +/* Read an entire line. Returns 0 on success or -1 and ERRNo on + failure. EOF is indictated by setting the integer at address + R_EOF. */ static int -readline (ASSUAN_CONTEXT ctx, char *buf, size_t buflen, +readline (assuan_context_t ctx, char *buf, size_t buflen, int *r_nread, int *r_eof) { size_t nleft = buflen; @@ -88,8 +94,9 @@ readline (ASSUAN_CONTEXT ctx, char *buf, size_t buflen, } -int -_assuan_read_line (ASSUAN_CONTEXT ctx) +/* Function returns an Assuan error. */ +assuan_error_t +_assuan_read_line (assuan_context_t ctx) { char *line = ctx->inbound.line; int nread, atticlen; @@ -97,7 +104,7 @@ _assuan_read_line (ASSUAN_CONTEXT ctx) char *endp = 0; if (ctx->inbound.eof) - return -1; + return _assuan_error (-1); atticlen = ctx->inbound.attic.linelen; if (atticlen) @@ -128,19 +135,20 @@ _assuan_read_line (ASSUAN_CONTEXT ctx) if (rc) { if (ctx->log_fp) - fprintf (ctx->log_fp, "%s[%u.%p] DBG: <- [Error: %s]\n", + fprintf (ctx->log_fp, "%s[%u.%d] DBG: <- [Error: %s]\n", assuan_get_assuan_log_prefix (), - (unsigned int)getpid (), ctx, strerror (errno)); - return ASSUAN_Read_Error; + (unsigned int)getpid (), ctx->inbound.fd, + strerror (errno)); + return _assuan_error (ASSUAN_Read_Error); } if (!nread) { assert (ctx->inbound.eof); if (ctx->log_fp) - fprintf (ctx->log_fp, "%s[%u.%p] DBG: <- [EOF]\n", + fprintf (ctx->log_fp, "%s[%u.%d] DBG: <- [EOF]\n", assuan_get_assuan_log_prefix (), - (unsigned int)getpid (), ctx); - return -1; + (unsigned int)getpid (), ctx->inbound.fd); + return _assuan_error (-1); } ctx->inbound.attic.pending = 0; @@ -170,9 +178,9 @@ _assuan_read_line (ASSUAN_CONTEXT ctx) ctx->inbound.linelen = endp - line; if (ctx->log_fp) { - fprintf (ctx->log_fp, "%s[%u.%p] DBG: <- ", + fprintf (ctx->log_fp, "%s[%u.%d] DBG: <- ", assuan_get_assuan_log_prefix (), - (unsigned int)getpid (), ctx); + (unsigned int)getpid (), ctx->inbound.fd); if (ctx->confidential) fputs ("[Confidential data not shown]", ctx->log_fp); else @@ -186,13 +194,14 @@ _assuan_read_line (ASSUAN_CONTEXT ctx) else { if (ctx->log_fp) - fprintf (ctx->log_fp, "%s[%u.%p] DBG: <- [Invalid line]\n", + fprintf (ctx->log_fp, "%s[%u.%d] DBG: <- [Invalid line]\n", assuan_get_assuan_log_prefix (), - (unsigned int)getpid (), ctx); + (unsigned int)getpid (), ctx->inbound.fd); *line = 0; ctx->inbound.linelen = 0; - return ctx->inbound.eof ? ASSUAN_Line_Not_Terminated - : ASSUAN_Line_Too_Long; + return _assuan_error (ctx->inbound.eof + ? ASSUAN_Line_Not_Terminated + : ASSUAN_Line_Too_Long); } } @@ -207,12 +216,12 @@ _assuan_read_line (ASSUAN_CONTEXT ctx) See also: assuan_pending_line(). */ assuan_error_t -assuan_read_line (ASSUAN_CONTEXT ctx, char **line, size_t *linelen) +assuan_read_line (assuan_context_t ctx, char **line, size_t *linelen) { assuan_error_t err; if (!ctx) - return ASSUAN_Invalid_Value; + return _assuan_error (ASSUAN_Invalid_Value); err = _assuan_read_line (ctx); *line = ctx->inbound.line; @@ -224,7 +233,7 @@ assuan_read_line (ASSUAN_CONTEXT ctx, char **line, size_t *linelen) /* Return true if a full line is buffered (i.e. an entire line may be read without any I/O). */ int -assuan_pending_line (ASSUAN_CONTEXT ctx) +assuan_pending_line (assuan_context_t ctx) { return ctx && ctx->inbound.attic.pending; } @@ -234,17 +243,17 @@ assuan_error_t _assuan_write_line (assuan_context_t ctx, const char *prefix, const char *line, size_t len) { - int rc = 0; + assuan_error_t rc = 0; size_t prefixlen = prefix? strlen (prefix):0; /* Make sure that the line is short enough. */ if (len + prefixlen + 2 > ASSUAN_LINELENGTH) { if (ctx->log_fp) - fprintf (ctx->log_fp, "%s[%u.%p] DBG: -> " + fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> " "[supplied line too long -truncated]\n", assuan_get_assuan_log_prefix (), - (unsigned int)getpid (), ctx); + (unsigned int)getpid (), ctx->inbound.fd); if (prefixlen > 5) prefixlen = 5; if (len > ASSUAN_LINELENGTH - prefixlen - 2) @@ -254,13 +263,17 @@ _assuan_write_line (assuan_context_t ctx, const char *prefix, /* Fixme: we should do some kind of line buffering. */ if (ctx->log_fp) { - fprintf (ctx->log_fp, "%s[%u.%p] DBG: -> ", + fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> ", assuan_get_assuan_log_prefix (), - (unsigned int)getpid (), ctx); + (unsigned int)getpid (), ctx->inbound.fd); if (ctx->confidential) fputs ("[Confidential data not shown]", ctx->log_fp); else - _assuan_log_print_buffer (ctx->log_fp, line, len); + { + if (prefixlen) + _assuan_log_print_buffer (ctx->log_fp, prefix, prefixlen); + _assuan_log_print_buffer (ctx->log_fp, line, len); + } putc ('\n', ctx->log_fp); } @@ -268,18 +281,18 @@ _assuan_write_line (assuan_context_t ctx, const char *prefix, { rc = writen (ctx, prefix, prefixlen); if (rc) - rc = ASSUAN_Write_Error; + rc = _assuan_error (ASSUAN_Write_Error); } if (!rc) { rc = writen (ctx, line, len); if (rc) - rc = ASSUAN_Write_Error; + rc = _assuan_error (ASSUAN_Write_Error); if (!rc) { rc = writen (ctx, "\n", 1); if (rc) - rc = ASSUAN_Write_Error; + rc = _assuan_error (ASSUAN_Write_Error); } } return rc; @@ -287,13 +300,13 @@ _assuan_write_line (assuan_context_t ctx, const char *prefix, assuan_error_t -assuan_write_line (ASSUAN_CONTEXT ctx, const char *line) +assuan_write_line (assuan_context_t ctx, const char *line) { size_t len; const char *s; if (!ctx) - return ASSUAN_Invalid_Value; + return _assuan_error (ASSUAN_Invalid_Value); /* Make sure that we never take a LF from the user - this might violate the protocol. */ @@ -301,10 +314,10 @@ assuan_write_line (ASSUAN_CONTEXT ctx, const char *line) len = s? (s-line) : strlen (line); if (ctx->log_fp && s) - fprintf (ctx->log_fp, "%s[%u.%p] DBG: -> " - "[supplied line contained a LF -truncated]\n", + fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> " + "[supplied line contained a LF - truncated]\n", assuan_get_assuan_log_prefix (), - (unsigned int)getpid (), ctx); + (unsigned int)getpid (), ctx->inbound.fd); return _assuan_write_line (ctx, NULL, line, len); } @@ -316,7 +329,7 @@ assuan_write_line (ASSUAN_CONTEXT ctx, const char *line) int _assuan_cookie_write_data (void *cookie, const char *buffer, size_t orig_size) { - ASSUAN_CONTEXT ctx = cookie; + assuan_context_t ctx = cookie; size_t size = orig_size; char *line; size_t linelen; @@ -359,9 +372,9 @@ _assuan_cookie_write_data (void *cookie, const char *buffer, size_t orig_size) { if (ctx->log_fp) { - fprintf (ctx->log_fp, "%s[%u.%p] DBG: -> ", + fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> ", assuan_get_assuan_log_prefix (), - (unsigned int)getpid (), ctx); + (unsigned int)getpid (), ctx->inbound.fd); if (ctx->confidential) fputs ("[Confidential data not shown]", ctx->log_fp); @@ -375,7 +388,7 @@ _assuan_cookie_write_data (void *cookie, const char *buffer, size_t orig_size) linelen++; if (writen (ctx, ctx->outbound.data.line, linelen)) { - ctx->outbound.data.error = ASSUAN_Write_Error; + ctx->outbound.data.error = _assuan_error (ASSUAN_Write_Error); return 0; } line = ctx->outbound.data.line; @@ -393,7 +406,7 @@ _assuan_cookie_write_data (void *cookie, const char *buffer, size_t orig_size) int _assuan_cookie_write_flush (void *cookie) { - ASSUAN_CONTEXT ctx = cookie; + assuan_context_t ctx = cookie; char *line; size_t linelen; @@ -407,9 +420,9 @@ _assuan_cookie_write_flush (void *cookie) { if (ctx->log_fp) { - fprintf (ctx->log_fp, "%s[%u.%p] DBG: -> ", + fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> ", assuan_get_assuan_log_prefix (), - (unsigned int)getpid (), ctx); + (unsigned int)getpid (), ctx->inbound.fd); if (ctx->confidential) fputs ("[Confidential data not shown]", ctx->log_fp); else @@ -421,7 +434,7 @@ _assuan_cookie_write_flush (void *cookie) linelen++; if (writen (ctx, ctx->outbound.data.line, linelen)) { - ctx->outbound.data.error = ASSUAN_Write_Error; + ctx->outbound.data.error = _assuan_error (ASSUAN_Write_Error); return 0; } ctx->outbound.data.linelen = 0; @@ -449,12 +462,12 @@ _assuan_cookie_write_flush (void *cookie) **/ assuan_error_t -assuan_send_data (ASSUAN_CONTEXT ctx, const void *buffer, size_t length) +assuan_send_data (assuan_context_t ctx, const void *buffer, size_t length) { if (!ctx) - return ASSUAN_Invalid_Value; + return _assuan_error (ASSUAN_Invalid_Value); if (!buffer && length) - return ASSUAN_Invalid_Value; + return _assuan_error (ASSUAN_Invalid_Value); if (!buffer) { /* flush what we have */ @@ -475,7 +488,7 @@ assuan_send_data (ASSUAN_CONTEXT ctx, const void *buffer, size_t length) } assuan_error_t -assuan_sendfd (ASSUAN_CONTEXT ctx, int fd) +assuan_sendfd (assuan_context_t ctx, int fd) { if (! ctx->io->sendfd) return set_error (ctx, Not_Implemented, @@ -485,7 +498,7 @@ assuan_sendfd (ASSUAN_CONTEXT ctx, int fd) } assuan_error_t -assuan_receivefd (ASSUAN_CONTEXT ctx, int *fd) +assuan_receivefd (assuan_context_t ctx, int *fd) { if (! ctx->io->receivefd) return set_error (ctx, Not_Implemented, |