FreeBSD/contrib/subversion/subversion/libsvn_ra_svn/marshal.c
/* Read LEN bytes from CONN into already-allocated structure ITEM.
 * Afterwards, *ITEM is of type 'SVN_RA_SVN_STRING', and its string
 * data is allocated in POOL. */
Read LEN bytes from CONN into already-allocated structure ITEM.
Afterwards, *ITEM is of type 'SVN_RA_SVN_STRING', and its string
data is allocated in POOL.
Read LEN bytes from CONN into already - allocated structure ITEM . Afterwards * ITEM is of type ' SVN_RA_SVN_STRING ' and its string data is allocated in POOL .
static svn_error_t *read_string(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
                                svn_ra_svn_item_t *item, apr_uint64_t len64)
{
  apr_size_t len = (apr_size_t)len64;
  apr_size_t readbuf_len;
  char *dest;
  apr_size_t buflen;
  if (len64 > APR_SIZE_MAX)
    return svn_error_create(SVN_ERR_RA_SVN_MALFORMED_DATA, NULL,
                            _("String length larger than maximum"));
  buflen = conn->read_end - conn->read_ptr;
  if (len <= buflen)
    {
      item->kind = SVN_RA_SVN_STRING;
      item->u.string = svn_string_ncreate(conn->read_ptr, len, pool);
      conn->read_ptr += len;
    }
  else
    {
      svn_stringbuf_t *stringbuf = svn_stringbuf_create_empty(pool);
      do
        {
          readbuf_len
            = len < SUSPICIOUSLY_HUGE_STRING_SIZE_THRESHOLD
                  ? len
                  : SUSPICIOUSLY_HUGE_STRING_SIZE_THRESHOLD;
          svn_stringbuf_ensure(stringbuf, stringbuf->len + readbuf_len);
          dest = stringbuf->data + stringbuf->len;
          SVN_ERR(readbuf_read(conn, pool, dest, readbuf_len));
          stringbuf->len += readbuf_len;
          len -= readbuf_len;
        }
      while (len);
      stringbuf->data[stringbuf->len] = '\0';
      item->kind = SVN_RA_SVN_STRING;
      item->u.string = svn_stringbuf__morph_into_string(stringbuf);
    }
  return SVN_NO_ERROR;
}
static svn_error_t * read_string ( svn_ra_svn_conn_t * conn , apr_pool_t * pool , svn_ra_svn_item_t * item , apr_uint64_t len64 ) { apr_size_t len = ( apr_size_t ) len64 ; apr_size_t readbuf_len ; char * dest ; apr_size_t buflen ; if ( len64 > APR_SIZE_MAX ) return svn_error_create ( SVN_ERR_RA_SVN_MALFORMED_DATA , NULL , _ ( " " ) ) ; buflen = conn -> read_end - conn -> read_ptr ; if ( len <= buflen ) { item -> kind = SVN_RA_SVN_STRING ; item -> u . string = svn_string_ncreate ( conn -> read_ptr , len , pool ) ; conn -> read_ptr += len ; } else { svn_stringbuf_t * stringbuf = svn_stringbuf_create_empty ( pool ) ; do { readbuf_len = len < SUSPICIOUSLY_HUGE_STRING_SIZE_THRESHOLD ? len : SUSPICIOUSLY_HUGE_STRING_SIZE_THRESHOLD ; svn_stringbuf_ensure ( stringbuf , stringbuf -> len + readbuf_len ) ; dest = stringbuf -> data + stringbuf -> len ; SVN_ERR ( readbuf_read ( conn , pool , dest , readbuf_len ) ) ; stringbuf -> len += readbuf_len ; len -= readbuf_len ; } while ( len ) ; stringbuf -> data [ stringbuf -> len ] = ' \0 ' ; item -> kind = SVN_RA_SVN_STRING ; item -> u . string = svn_stringbuf__morph_into_string ( stringbuf ) ; } return SVN_NO_ERROR ; }
Read LEN bytes from CONN into already-allocated structure ITEM.
Read LEN bytes from CONN into already - allocated structure ITEM .
/* We can't store strings longer than the maximum size of apr_size_t,
   * so check for wrapping */ /* Shorter strings can be copied directly from the read buffer. */ /* Read the string in chunks.  The chunk size is large enough to avoid
       * re-allocation in typical cases, and small enough to ensure we do
       * not pre-allocate an unreasonable amount of memory if (perhaps due
       * to network data corruption or a DOS attack), we receive a bogus
       * claim that a very long string is going to follow.  In that case, we
       * start small and wait for all that data to actually show up.  This
       * does not fully prevent DOS attacks but makes them harder (you have
       * to actually send gigabytes of data). */ /* Read string data directly into the string structure.
       * Do it iteratively.  */ /* Determine length of chunk to read and re-alloc the buffer. */ /* read data & update length info */ /* zero-terminate the string */ /* Return the string properly wrapped into an RA_SVN item. */