diff options
Diffstat (limited to 'assuan/assuan-buffer.c')
| -rw-r--r-- | assuan/assuan-buffer.c | 60 | 
1 files changed, 38 insertions, 22 deletions
| diff --git a/assuan/assuan-buffer.c b/assuan/assuan-buffer.c index 31f33945..b9e35721 100644 --- a/assuan/assuan-buffer.c +++ b/assuan/assuan-buffer.c @@ -14,9 +14,7 @@   * Lesser General Public License for more details.   *   * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA.  + * License along with this program; if not, see <http://www.gnu.org/licenses/>.   */  #include <config.h> @@ -53,9 +51,10 @@ writen (assuan_context_t ctx, const char *buffer, size_t length)    return 0;  /* okay */  } -/* Read an entire line. Returns 0 on success or -1 and ERRNo on +/* 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.  */ +   R_EOF.  Note: BUF, R_NREAD and R_EOF contain a valid result even if +   an error is returned.  */  static int  readline (assuan_context_t ctx, char *buf, size_t buflen,  	  int *r_nread, int *r_eof) @@ -94,7 +93,7 @@ readline (assuan_context_t ctx, char *buf, size_t buflen,  } -/* Function returns an Assuan error. */ +/* Function returns an Assuan error.  */  assuan_error_t  _assuan_read_line (assuan_context_t ctx)  { @@ -134,11 +133,23 @@ _assuan_read_line (assuan_context_t ctx)                     &nread, &ctx->inbound.eof);    if (rc)      { +      int saved_errno = errno; +        if (ctx->log_fp) -	fprintf (ctx->log_fp, "%s[%u.%d] DBG: <- [Error: %s (%d)]\n", -		 assuan_get_assuan_log_prefix (), -                 (unsigned int)getpid (), ctx->inbound.fd, -                 strerror (errno), errno); +	fprintf (ctx->log_fp, "%s[%u.%d] DBG: <- [Error: %s]\n", +                 assuan_get_assuan_log_prefix (), +                 (unsigned int)getpid (), (int)ctx->inbound.fd, +                 strerror (errno)); + +      if (saved_errno == EAGAIN) +        { +          /* We have to save a partial line.  */ +          memcpy (ctx->inbound.attic.line, line, atticlen + nread); +          ctx->inbound.attic.pending = 0; +          ctx->inbound.attic.linelen = atticlen + nread; +        } + +      errno = saved_errno;        return _assuan_error (ASSUAN_Read_Error);      }    if (!nread) @@ -147,7 +158,7 @@ _assuan_read_line (assuan_context_t ctx)        if (ctx->log_fp)  	fprintf (ctx->log_fp, "%s[%u.%d] DBG: <- [EOF]\n",  		 assuan_get_assuan_log_prefix (), -                 (unsigned int)getpid (), ctx->inbound.fd); +                 (unsigned int)getpid (), (int)ctx->inbound.fd);        return _assuan_error (-1);      } @@ -191,7 +202,7 @@ _assuan_read_line (assuan_context_t ctx)  	{  	  fprintf (ctx->log_fp, "%s[%u.%d] DBG: <- ",  		   assuan_get_assuan_log_prefix (), -                   (unsigned int)getpid (), ctx->inbound.fd); +                   (unsigned int)getpid (), (int)ctx->inbound.fd);  	  if (ctx->confidential)  	    fputs ("[Confidential data not shown]", ctx->log_fp);  	  else @@ -207,7 +218,7 @@ _assuan_read_line (assuan_context_t ctx)        if (ctx->log_fp)  	fprintf (ctx->log_fp, "%s[%u.%d] DBG: <- [Invalid line]\n",  		 assuan_get_assuan_log_prefix (), -                 (unsigned int)getpid (), ctx->inbound.fd); +                 (unsigned int)getpid (), (int)ctx->inbound.fd);        *line = 0;        ctx->inbound.linelen = 0;        return _assuan_error (ctx->inbound.eof  @@ -234,7 +245,12 @@ assuan_read_line (assuan_context_t ctx, char **line, size_t *linelen)    if (!ctx)      return _assuan_error (ASSUAN_Invalid_Value); -  err = _assuan_read_line (ctx); +  do +    { +      err = _assuan_read_line (ctx); +    } +  while (_assuan_error_is_eagain (err)); +    *line = ctx->inbound.line;    *linelen = ctx->inbound.linelen;    return err; @@ -265,7 +281,7 @@ _assuan_write_line (assuan_context_t ctx, const char *prefix,          fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> "                   "[supplied line too long -truncated]\n",                   assuan_get_assuan_log_prefix (), -                 (unsigned int)getpid (), ctx->inbound.fd); +                 (unsigned int)getpid (), (int)ctx->inbound.fd);        if (prefixlen > 5)          prefixlen = 5;        if (len > ASSUAN_LINELENGTH - prefixlen - 2) @@ -281,7 +297,7 @@ _assuan_write_line (assuan_context_t ctx, const char *prefix,      {        fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> ",  	       assuan_get_assuan_log_prefix (), -               (unsigned int)getpid (), ctx->inbound.fd); +               (unsigned int)getpid (), (int)ctx->inbound.fd);        if (ctx->confidential)  	fputs ("[Confidential data not shown]", ctx->log_fp);        else @@ -333,7 +349,7 @@ assuan_write_line (assuan_context_t ctx, const char *line)      fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> "               "[supplied line contained a LF - truncated]\n",               assuan_get_assuan_log_prefix (), -             (unsigned int)getpid (), ctx->inbound.fd); +             (unsigned int)getpid (), (int)ctx->inbound.fd);    return _assuan_write_line (ctx, NULL, line, len);  } @@ -398,7 +414,7 @@ _assuan_cookie_write_data (void *cookie, const char *buffer, size_t orig_size)              {  	      fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> ",  		       assuan_get_assuan_log_prefix (), -                       (unsigned int)getpid (), ctx->inbound.fd); +                       (unsigned int)getpid (), (int)ctx->inbound.fd);                if (ctx->confidential)                  fputs ("[Confidential data not shown]", ctx->log_fp); @@ -454,7 +470,7 @@ _assuan_cookie_write_flush (void *cookie)  	{  	  fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> ",  		   assuan_get_assuan_log_prefix (), -                   (unsigned int)getpid (), ctx->inbound.fd); +                   (unsigned int)getpid (), (int)ctx->inbound.fd);  	  if (ctx->confidential)  	    fputs ("[Confidential data not shown]", ctx->log_fp);  	  else @@ -524,11 +540,11 @@ assuan_send_data (assuan_context_t ctx, const void *buffer, size_t length)  }  assuan_error_t -assuan_sendfd (assuan_context_t ctx, int fd) +assuan_sendfd (assuan_context_t ctx, assuan_fd_t fd)  {    /* It is explicitly allowed to use (NULL, -1) as a runtime test to       check whether descriptor passing is available. */ -  if (!ctx && fd == -1) +  if (!ctx && fd == ASSUAN_INVALID_FD)  #ifdef USE_DESCRIPTOR_PASSING      return 0;  #else @@ -543,7 +559,7 @@ assuan_sendfd (assuan_context_t ctx, int fd)  }  assuan_error_t -assuan_receivefd (assuan_context_t ctx, int *fd) +assuan_receivefd (assuan_context_t ctx, assuan_fd_t *fd)  {    if (! ctx->io->receivefd)      return set_error (ctx, Not_Implemented, | 
