svn_stream_t * svn_stream_from_aprfile2(apr_file_t *file, svn_boolean_t disown, apr_pool_t *pool) { struct baton_apr *baton; svn_stream_t *stream; if (file == NULL) return svn_stream_empty(pool); baton = apr_palloc(pool, sizeof(*baton)); baton->file = file; baton->pool = pool; stream = svn_stream_create(baton, pool); svn_stream_set_read(stream, read_handler_apr); svn_stream_set_write(stream, write_handler_apr); svn_stream_set_skip(stream, skip_handler_apr); svn_stream_set_mark(stream, mark_handler_apr); svn_stream_set_seek(stream, seek_handler_apr); svn_stream__set_is_buffered(stream, is_buffered_handler_apr); if (! disown) svn_stream_set_close(stream, close_handler_apr); return stream; }
static svn_error_t *ra_svn_apply_textdelta(void *file_baton, const char *base_checksum, apr_pool_t *pool, svn_txdelta_window_handler_t *wh, void **wh_baton) { ra_svn_baton_t *b = file_baton; svn_stream_t *diff_stream; /* Tell the other side we're starting a text delta. */ SVN_ERR(check_for_error(b->eb, pool)); SVN_ERR(svn_ra_svn__write_cmd_apply_textdelta(b->conn, pool, b->token, base_checksum)); /* Transform the window stream to an svndiff stream. Reuse the * file baton for the stream handler, since it has all the * needed information. */ diff_stream = svn_stream_create(b, pool); svn_stream_set_write(diff_stream, ra_svn_svndiff_handler); svn_stream_set_close(diff_stream, ra_svn_svndiff_close_handler); /* If the connection does not support SVNDIFF1 or if we don't want to use * compression, use the non-compressing "version 0" implementation */ if ( svn_ra_svn_compression_level(b->conn) > 0 && svn_ra_svn_has_capability(b->conn, SVN_RA_SVN_CAP_SVNDIFF1)) svn_txdelta_to_svndiff3(wh, wh_baton, diff_stream, 1, b->conn->compression_level, pool); else svn_txdelta_to_svndiff3(wh, wh_baton, diff_stream, 0, b->conn->compression_level, pool); return SVN_NO_ERROR; }
svn_stream_t * svn_txdelta_target_push(svn_txdelta_window_handler_t handler, void *handler_baton, svn_stream_t *source, apr_pool_t *pool) { struct tpush_baton *tb; svn_stream_t *stream; /* Initialize baton. */ tb = apr_palloc(pool, sizeof(*tb)); tb->source = source; tb->wh = handler; tb->whb = handler_baton; tb->pool = pool; tb->buf = apr_palloc(pool, 2 * SVN_DELTA_WINDOW_SIZE); tb->source_offset = 0; tb->source_len = 0; tb->source_done = FALSE; tb->target_len = 0; /* Create and return writable stream. */ stream = svn_stream_create(tb, pool); svn_stream_set_write(stream, tpush_write_handler); svn_stream_set_close(stream, tpush_close_handler); return stream; }
svn_stream_t * svn_stream_compressed(svn_stream_t *stream, apr_pool_t *pool) { struct svn_stream_t *zstream; struct zbaton *baton; assert(stream != NULL); baton = apr_palloc(pool, sizeof(*baton)); baton->in = baton->out = NULL; baton->read = stream->read_fn; baton->write = stream->write_fn; baton->close = stream->close_fn; baton->subbaton = stream->baton; baton->pool = pool; baton->read_buffer = NULL; baton->read_flush = Z_SYNC_FLUSH; zstream = svn_stream_create(baton, pool); svn_stream_set_read(zstream, read_handler_gz); svn_stream_set_write(zstream, write_handler_gz); svn_stream_set_close(zstream, close_handler_gz); return zstream; }
svn_stream_t * svn_stream_empty(apr_pool_t *pool) { svn_stream_t *stream; stream = svn_stream_create(NULL, pool); svn_stream_set_read(stream, read_handler_empty); svn_stream_set_write(stream, write_handler_empty); svn_stream_set_mark(stream, mark_handler_empty); svn_stream_set_seek(stream, seek_handler_empty); svn_stream__set_is_buffered(stream, is_buffered_handler_empty); return stream; }
svn_stream_t * svn_stream_disown(svn_stream_t *stream, apr_pool_t *pool) { svn_stream_t *s = svn_stream_create(stream, pool); svn_stream_set_read(s, read_handler_disown); svn_stream_set_skip(s, skip_handler_disown); svn_stream_set_write(s, write_handler_disown); svn_stream_set_mark(s, mark_handler_disown); svn_stream_set_seek(s, seek_handler_disown); svn_stream__set_is_buffered(s, is_buffered_handler_disown); return s; }
/* This implements `svn_opt_subcommand_t'. */ static svn_error_t * subcommand_index (apr_getopt_t *os, void *baton, apr_pool_t *pool) { struct svnindex_opt_state *opt_state = baton; svn_repos_t *repos; svn_fs_t *fs; svn_stream_t *stderr_stream = NULL; struct recode_write_baton stderr_stream_rwb = { 0 }; svn_revnum_t lower = SVN_INVALID_REVNUM, upper = SVN_INVALID_REVNUM; svn_revnum_t youngest; SVN_ERR (open_repos (&repos, opt_state->repository_path, pool)); fs = svn_repos_fs (repos); SVN_ERR (svn_fs_youngest_rev (&youngest, fs, pool)); /* Find the revision numbers at which to start and end. */ SVN_ERR (get_revnum (&lower, &opt_state->start_revision, youngest, repos, pool)); SVN_ERR (get_revnum (&upper, &opt_state->end_revision, youngest, repos, pool)); if (lower > upper) return svn_error_create (SVN_ERR_CL_ARG_PARSING_ERROR, NULL, _("First revision cannot be higher than second")); /* Progress feedback goes to stderr, unless they asked to suppress it. */ if (! opt_state->quiet) { stderr_stream = svn_stream_create (&stderr_stream_rwb, pool); stderr_stream_rwb.pool = pool; stderr_stream_rwb.out = stderr; svn_stream_set_write (stderr_stream, recode_write); } SVN_ERR (svnindex__index (repos, stderr_stream, lower, upper, opt_state->verbose, opt_state->db, check_cancel, NULL, pool)); return SVN_NO_ERROR; }
svn_ra_svn__stream_t * svn_ra_svn__stream_from_sock(apr_socket_t *sock, apr_pool_t *result_pool) { sock_baton_t *b = apr_palloc(result_pool, sizeof(*b)); svn_stream_t *sock_stream; b->sock = sock; b->pool = svn_pool_create(result_pool); sock_stream = svn_stream_create(b, result_pool); svn_stream_set_read2(sock_stream, sock_read_cb, NULL /* use default */); svn_stream_set_write(sock_stream, sock_write_cb); svn_stream_set_data_available(sock_stream, sock_pending_cb); return svn_ra_svn__stream_create(sock_stream, sock_stream, b, sock_timeout_cb, result_pool); }
svn_stream_t * svn_stream__from_spillbuf(svn_spillbuf_t *buf, apr_pool_t *result_pool) { svn_stream_t *stream; struct spillbuf_baton *sb = apr_palloc(result_pool, sizeof(*sb)); sb->reader = apr_pcalloc(result_pool, sizeof(*sb->reader)); sb->reader->buf = buf; sb->scratch_pool = svn_pool_create(result_pool); stream = svn_stream_create(sb, result_pool); svn_stream_set_read2(stream, NULL /* only full read support */, read_handler_spillbuf); svn_stream_set_write(stream, write_handler_spillbuf); return stream; }
static int l_cat (lua_State *L) { const char *path = luaL_checkstring (L, 1); svn_opt_revision_t peg_revision; svn_opt_revision_t revision; peg_revision.kind = svn_opt_revision_unspecified; if (lua_gettop (L) < 2 || lua_isnil (L, 2)) { revision.kind = get_revision_kind (path); } else { revision.kind = svn_opt_revision_number; revision.value.number = lua_tointeger (L, 2); } apr_pool_t *pool; svn_error_t *err; svn_client_ctx_t *ctx; init_function (&ctx, &pool, L); path = svn_path_canonicalize (path, pool); svn_stream_t *stream; stream = svn_stream_empty (pool); svn_stream_set_write (stream, write_fn); svn_stringbuf_t *buffer = svn_stringbuf_create ("\0", pool); svn_stream_set_baton (stream, buffer); err = svn_client_cat2 (stream, path, &peg_revision, &revision, ctx, pool); IF_ERROR_RETURN (err, pool, L); lua_pushstring (L, buffer->data); svn_pool_destroy (pool); return 1; }
svn_ra_svn__stream_t * svn_ra_svn__stream_create(void *baton, svn_read_fn_t read_cb, svn_write_fn_t write_cb, ra_svn_timeout_fn_t timeout_cb, ra_svn_pending_fn_t pending_cb, apr_pool_t *pool) { svn_ra_svn__stream_t *s = apr_palloc(pool, sizeof(*s)); s->stream = svn_stream_empty(pool); svn_stream_set_baton(s->stream, baton); if (read_cb) svn_stream_set_read(s->stream, read_cb); if (write_cb) svn_stream_set_write(s->stream, write_cb); s->baton = baton; s->timeout_fn = timeout_cb; s->pending_fn = pending_cb; return s; }
svn_stream_t * svn_stream_from_stringbuf(svn_stringbuf_t *str, apr_pool_t *pool) { svn_stream_t *stream; struct stringbuf_stream_baton *baton; if (! str) return svn_stream_empty(pool); baton = apr_palloc(pool, sizeof(*baton)); baton->str = str; baton->amt_read = 0; stream = svn_stream_create(baton, pool); svn_stream_set_read(stream, read_handler_stringbuf); svn_stream_set_skip(stream, skip_handler_stringbuf); svn_stream_set_write(stream, write_handler_stringbuf); svn_stream_set_mark(stream, mark_handler_stringbuf); svn_stream_set_seek(stream, seek_handler_stringbuf); svn_stream__set_is_buffered(stream, is_buffered_handler_stringbuf); return stream; }
svn_stream_t * svn_stream_tee(svn_stream_t *out1, svn_stream_t *out2, apr_pool_t *pool) { struct baton_tee *baton; svn_stream_t *stream; if (out1 == NULL) return out2; if (out2 == NULL) return out1; baton = apr_palloc(pool, sizeof(*baton)); baton->out1 = out1; baton->out2 = out2; stream = svn_stream_create(baton, pool); svn_stream_set_write(stream, write_handler_tee); svn_stream_set_close(stream, close_handler_tee); return stream; }
svn_stream_t * svn_stream_lazyopen_create(svn_stream_lazyopen_func_t open_func, void *open_baton, apr_pool_t *result_pool) { lazyopen_baton_t *lob = apr_pcalloc(result_pool, sizeof(*lob)); svn_stream_t *stream; lob->open_func = open_func; lob->open_baton = open_baton; lob->real_stream = NULL; lob->pool = result_pool; stream = svn_stream_create(lob, result_pool); svn_stream_set_read(stream, read_handler_lazyopen); svn_stream_set_skip(stream, skip_handler_lazyopen); svn_stream_set_write(stream, write_handler_lazyopen); svn_stream_set_close(stream, close_handler_lazyopen); svn_stream_set_mark(stream, mark_handler_lazyopen); svn_stream_set_seek(stream, seek_handler_lazyopen); return stream; }
svn_stream_t * svn_stream_checksummed2(svn_stream_t *stream, svn_checksum_t **read_checksum, svn_checksum_t **write_checksum, svn_checksum_kind_t checksum_kind, svn_boolean_t read_all, apr_pool_t *pool) { svn_stream_t *s; struct checksum_stream_baton *baton; if (read_checksum == NULL && write_checksum == NULL) return stream; baton = apr_palloc(pool, sizeof(*baton)); if (read_checksum) baton->read_ctx = svn_checksum_ctx_create(checksum_kind, pool); else baton->read_ctx = NULL; if (write_checksum) baton->write_ctx = svn_checksum_ctx_create(checksum_kind, pool); else baton->write_ctx = NULL; baton->read_checksum = read_checksum; baton->write_checksum = write_checksum; baton->proxy = stream; baton->read_more = read_all; baton->pool = pool; s = svn_stream_create(baton, pool); svn_stream_set_read(s, read_handler_checksum); svn_stream_set_write(s, write_handler_checksum); svn_stream_set_close(s, close_handler_checksum); return s; }
svn_stream_t * svn_stream_checksummed(svn_stream_t *stream, const unsigned char **read_digest, const unsigned char **write_digest, svn_boolean_t read_all, apr_pool_t *pool) { svn_stream_t *s; struct md5_stream_baton *baton; if (! read_digest && ! write_digest) return stream; baton = apr_palloc(pool, sizeof(*baton)); baton->read_digest = read_digest; baton->write_digest = write_digest; baton->pool = pool; /* Set BATON->proxy to a stream that will fill in BATON->read_checksum * and BATON->write_checksum (if we want them) when it is closed. */ baton->proxy = svn_stream_checksummed2(stream, read_digest ? &baton->read_checksum : NULL, write_digest ? &baton->write_checksum : NULL, svn_checksum_md5, read_all, pool); /* Create a stream that will forward its read/write/close operations to * BATON->proxy and will fill in *READ_DIGEST and *WRITE_DIGEST (if we * want them) after it closes BATON->proxy. */ s = svn_stream_create(baton, pool); svn_stream_set_read(s, read_handler_md5); svn_stream_set_skip(s, skip_handler_md5); svn_stream_set_write(s, write_handler_md5); svn_stream_set_close(s, close_handler_md5); return s; }
svn_error_t * svn_wc__internal_translated_stream(svn_stream_t **stream, svn_wc__db_t *db, const char *local_abspath, const char *versioned_abspath, apr_uint32_t flags, apr_pool_t *result_pool, apr_pool_t *scratch_pool) { svn_boolean_t special; svn_boolean_t to_nf = flags & SVN_WC_TRANSLATE_TO_NF; svn_subst_eol_style_t style; const char *eol; apr_hash_t *keywords; svn_boolean_t repair_forced = flags & SVN_WC_TRANSLATE_FORCE_EOL_REPAIR; SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath)); SVN_ERR_ASSERT(svn_dirent_is_absolute(versioned_abspath)); SVN_ERR(svn_wc__get_translate_info(&style, &eol, &keywords, &special, db, versioned_abspath, NULL, FALSE, scratch_pool, scratch_pool)); if (special) { if (to_nf) return svn_subst_read_specialfile(stream, local_abspath, result_pool, scratch_pool); return svn_subst_create_specialfile(stream, local_abspath, result_pool, scratch_pool); } if (to_nf) SVN_ERR(svn_stream_open_readonly(stream, local_abspath, result_pool, scratch_pool)); else { apr_file_t *file; /* We don't want the "open-exclusively" feature of the normal svn_stream_open_writable interface. Do this manually. */ SVN_ERR(svn_io_file_open(&file, local_abspath, APR_CREATE | APR_WRITE | APR_BUFFERED, APR_OS_DEFAULT, result_pool)); *stream = svn_stream_from_aprfile2(file, FALSE, result_pool); } if (svn_subst_translation_required(style, eol, keywords, special, TRUE)) { if (to_nf) { if (style == svn_subst_eol_style_native) eol = SVN_SUBST_NATIVE_EOL_STR; else if (style == svn_subst_eol_style_fixed) repair_forced = TRUE; else if (style != svn_subst_eol_style_none) return svn_error_create(SVN_ERR_IO_UNKNOWN_EOL, NULL, NULL); /* Wrap the stream to translate to normal form */ *stream = svn_subst_stream_translated(*stream, eol, repair_forced, keywords, FALSE /* expand */, result_pool); /* Enforce our contract. TO_NF streams are readonly */ svn_stream_set_write(*stream, write_handler_unsupported); } else { *stream = svn_subst_stream_translated(*stream, eol, TRUE, keywords, TRUE, result_pool); /* Enforce our contract. FROM_NF streams are write-only */ svn_stream_set_read(*stream, read_handler_unsupported); } } return SVN_NO_ERROR; }