static svn_error_t * test_stream_base64(apr_pool_t *pool) { svn_stream_t *stream; svn_stringbuf_t *actual = svn_stringbuf_create_empty(pool); svn_stringbuf_t *expected = svn_stringbuf_create_empty(pool); int i; static const char *strings[] = { "fairly boring test data... blah blah", "A", "abc", "012345679", NULL }; stream = svn_stream_from_stringbuf(actual, pool); stream = svn_base64_decode(stream, pool); stream = svn_base64_encode(stream, pool); for (i = 0; strings[i]; i++) { apr_size_t len = strlen(strings[i]); svn_stringbuf_appendbytes(expected, strings[i], len); SVN_ERR(svn_stream_write(stream, strings[i], &len)); } SVN_ERR(svn_stream_close(stream)); SVN_TEST_STRING_ASSERT(actual->data, expected->data); return SVN_NO_ERROR; }
static svn_error_t * test_compress_lz4_empty(apr_pool_t *pool) { svn_stringbuf_t *compressed = svn_stringbuf_create_empty(pool); svn_stringbuf_t *decompressed = svn_stringbuf_create_empty(pool); SVN_ERR(svn__compress_lz4("", 0, compressed)); SVN_ERR(svn__decompress_lz4(compressed->data, compressed->len, decompressed, 100)); SVN_TEST_STRING_ASSERT(decompressed->data, ""); return SVN_NO_ERROR; }
const char * svn_log__log(const apr_array_header_t *paths, svn_revnum_t start, svn_revnum_t end, int limit, svn_boolean_t discover_changed_paths, svn_boolean_t strict_node_history, svn_boolean_t include_merged_revisions, const apr_array_header_t *revprops, apr_pool_t *pool) { int i; apr_pool_t *iterpool = svn_pool_create(pool); svn_stringbuf_t *space_separated_paths = svn_stringbuf_create_empty(pool); svn_stringbuf_t *options = svn_stringbuf_create_empty(pool); for (i = 0; i < paths->nelts; i++) { const char *path = APR_ARRAY_IDX(paths, i, const char *); svn_pool_clear(iterpool); if (i != 0) svn_stringbuf_appendcstr(space_separated_paths, " "); svn_stringbuf_appendcstr(space_separated_paths, svn_path_uri_encode(path, iterpool)); } if (limit) { const char *tmp = apr_psprintf(pool, " limit=%d", limit); svn_stringbuf_appendcstr(options, tmp); } if (discover_changed_paths) svn_stringbuf_appendcstr(options, " discover-changed-paths"); if (strict_node_history) svn_stringbuf_appendcstr(options, " strict"); if (include_merged_revisions) svn_stringbuf_appendcstr(options, log_include_merged_revisions(include_merged_revisions)); if (revprops == NULL) svn_stringbuf_appendcstr(options, " revprops=all"); else if (revprops->nelts > 0) { svn_stringbuf_appendcstr(options, " revprops=("); for (i = 0; i < revprops->nelts; i++) { const char *name = APR_ARRAY_IDX(revprops, i, const char *); svn_pool_clear(iterpool); if (i != 0) svn_stringbuf_appendcstr(options, " "); svn_stringbuf_appendcstr(options, svn_path_uri_encode(name, iterpool)); } svn_stringbuf_appendcstr(options, ")"); }
const char * svn_log__get_mergeinfo(const apr_array_header_t *paths, svn_mergeinfo_inheritance_t inherit, svn_boolean_t include_descendants, apr_pool_t *pool) { int i; apr_pool_t *iterpool = svn_pool_create(pool); svn_stringbuf_t *space_separated_paths = svn_stringbuf_create_empty(pool); for (i = 0; i < paths->nelts; i++) { const char *path = APR_ARRAY_IDX(paths, i, const char *); svn_pool_clear(iterpool); if (i != 0) svn_stringbuf_appendcstr(space_separated_paths, " "); svn_stringbuf_appendcstr(space_separated_paths, svn_path_uri_encode(path, iterpool)); } svn_pool_destroy(iterpool); return apr_psprintf(pool, "get-mergeinfo (%s) %s%s", space_separated_paths->data, svn_inheritance_to_word(inherit), include_descendants ? " include-descendants" : ""); }
/* Read a line of original or modified hunk text from the specified * RANGE within FILE. FILE is expected to contain unidiff text. * Leading unidiff symbols ('+', '-', and ' ') are removed from the line, * Any lines commencing with the VERBOTEN character are discarded. * VERBOTEN should be '+' or '-', depending on which form of hunk text * is being read. * * All other parameters are as in svn_diff_hunk_readline_original_text() * and svn_diff_hunk_readline_modified_text(). */ static svn_error_t * hunk_readline_original_or_modified(apr_file_t *file, struct svn_diff__hunk_range *range, svn_stringbuf_t **stringbuf, const char **eol, svn_boolean_t *eof, char verboten, apr_pool_t *result_pool, apr_pool_t *scratch_pool) { apr_size_t max_len; svn_boolean_t filtered; apr_off_t pos; svn_stringbuf_t *str; if (range->current >= range->end) { /* We're past the range. Indicate that no bytes can be read. */ *eof = TRUE; if (eol) *eol = NULL; *stringbuf = svn_stringbuf_create_empty(result_pool); return SVN_NO_ERROR; } pos = 0; SVN_ERR(svn_io_file_seek(file, APR_CUR, &pos, scratch_pool)); SVN_ERR(svn_io_file_seek(file, APR_SET, &range->current, scratch_pool)); do { max_len = range->end - range->current; SVN_ERR(svn_io_file_readline(file, &str, eol, eof, max_len, result_pool, scratch_pool)); range->current = 0; SVN_ERR(svn_io_file_seek(file, APR_CUR, &range->current, scratch_pool)); filtered = (str->data[0] == verboten || str->data[0] == '\\'); } while (filtered && ! *eof); if (filtered) { /* EOF, return an empty string. */ *stringbuf = svn_stringbuf_create_ensure(0, result_pool); } else if (str->data[0] == '+' || str->data[0] == '-' || str->data[0] == ' ') { /* Shave off leading unidiff symbols. */ *stringbuf = svn_stringbuf_create(str->data + 1, result_pool); } else { /* Return the line as-is. */ *stringbuf = svn_stringbuf_dup(str, result_pool); } SVN_ERR(svn_io_file_seek(file, APR_SET, &pos, scratch_pool)); return SVN_NO_ERROR; }
static svn_error_t * test_compress_lz4(apr_pool_t *pool) { const char input[] = "aaaabbbbccccaaaaccccbbbbaaaabbbb" "aaaabbbbccccaaaaccccbbbbaaaabbbb" "aaaabbbbccccaaaaccccbbbbaaaabbbb"; svn_stringbuf_t *compressed = svn_stringbuf_create_empty(pool); svn_stringbuf_t *decompressed = svn_stringbuf_create_empty(pool); SVN_ERR(svn__compress_lz4(input, sizeof(input), compressed)); SVN_ERR(svn__decompress_lz4(compressed->data, compressed->len, decompressed, 100)); SVN_TEST_STRING_ASSERT(decompressed->data, input); return SVN_NO_ERROR; }
apr_status_t svn_subr__win32_xlate_to_stringbuf(win32_xlate_t *handle, const char *src_data, apr_size_t src_length, svn_stringbuf_t **dest, apr_pool_t *pool) { WCHAR * wide_str; int retval, wide_size; if (src_length == 0) { *dest = svn_stringbuf_create_empty(pool); return APR_SUCCESS; } retval = MultiByteToWideChar(handle->from_page_id, 0, src_data, src_length, NULL, 0); if (retval == 0) return apr_get_os_error(); wide_size = retval; /* Allocate temporary buffer for small strings on stack instead of heap. */ if (wide_size <= MAX_PATH) { wide_str = alloca(wide_size * sizeof(WCHAR)); } else { wide_str = apr_palloc(pool, wide_size * sizeof(WCHAR)); } retval = MultiByteToWideChar(handle->from_page_id, 0, src_data, src_length, wide_str, wide_size); if (retval == 0) return apr_get_os_error(); retval = WideCharToMultiByte(handle->to_page_id, 0, wide_str, wide_size, NULL, 0, NULL, NULL); if (retval == 0) return apr_get_os_error(); /* Ensure that buffer is enough to hold result string and termination character. */ *dest = svn_stringbuf_create_ensure(retval + 1, pool); (*dest)->len = retval; retval = WideCharToMultiByte(handle->to_page_id, 0, wide_str, wide_size, (*dest)->data, (*dest)->len, NULL, NULL); if (retval == 0) return apr_get_os_error(); (*dest)->len = retval; return APR_SUCCESS; }
svn_error_t * svn_ra_serf__list(svn_ra_session_t *ra_session, const char *path, svn_revnum_t revision, const apr_array_header_t *patterns, svn_depth_t depth, apr_uint32_t dirent_fields, svn_ra_dirent_receiver_t receiver, void *receiver_baton, apr_pool_t *scratch_pool) { list_context_t *list_ctx; svn_ra_serf__session_t *session = ra_session->priv; svn_ra_serf__handler_t *handler; svn_ra_serf__xml_context_t *xmlctx; const char *req_url; list_ctx = apr_pcalloc(scratch_pool, sizeof(*list_ctx)); list_ctx->pool = scratch_pool; list_ctx->receiver = receiver; list_ctx->receiver_baton = receiver_baton; list_ctx->path = path; list_ctx->revision = revision; list_ctx->patterns = patterns; list_ctx->depth = depth; list_ctx->dirent_fields = dirent_fields; list_ctx->props = svn_ra_serf__get_dirent_props(dirent_fields, session, scratch_pool); list_ctx->author_buf = svn_stringbuf_create_empty(scratch_pool); /* At this point, we may have a deleted file. So, we'll match ra_neon's * behavior and use the larger of start or end as our 'peg' rev. */ SVN_ERR(svn_ra_serf__get_stable_url(&req_url, NULL /* latest_revnum */, session, NULL /* url */, revision, scratch_pool, scratch_pool)); xmlctx = svn_ra_serf__xml_context_create(log_ttable, NULL, item_closed, NULL, list_ctx, scratch_pool); handler = svn_ra_serf__create_expat_handler(session, xmlctx, NULL, scratch_pool); handler->method = "REPORT"; handler->path = req_url; handler->body_delegate = create_list_body; handler->body_delegate_baton = list_ctx; handler->body_type = "text/xml"; SVN_ERR(svn_ra_serf__context_run_one(handler, scratch_pool)); if (handler->sline.code != 200) SVN_ERR(svn_ra_serf__unexpected_status(handler)); return SVN_NO_ERROR; }
static svn_error_t * verify_expected_record(svn_fs_t *fs, const char *key, const char *expected_text, apr_size_t expected_len, trail_t *trail) { apr_size_t size; char buf[100]; svn_stringbuf_t *text; svn_filesize_t offset = 0; svn_filesize_t string_size; /* Check the string size. */ SVN_ERR(svn_fs_bdb__string_size(&string_size, fs, key, trail, trail->pool)); if (string_size > SVN_MAX_OBJECT_SIZE) return svn_error_createf(SVN_ERR_FS_GENERAL, NULL, "record size is too large " "(got %" SVN_FILESIZE_T_FMT ", " "limit is %" APR_SIZE_T_FMT ")", string_size, SVN_MAX_OBJECT_SIZE); size = (apr_size_t) string_size; if (size != expected_len) return svn_error_createf(SVN_ERR_FS_GENERAL, NULL, "record has unexpected size " "(got %" APR_SIZE_T_FMT ", " "expected %" APR_SIZE_T_FMT ")", size, expected_len); /* Read the string back in 100-byte chunks. */ text = svn_stringbuf_create_empty(trail->pool); while (1) { size = sizeof(buf); SVN_ERR(svn_fs_bdb__string_read(fs, key, buf, offset, &size, trail, trail->pool)); if (size == 0) break; svn_stringbuf_appendbytes(text, buf, size); offset += size; } /* Check the size and contents of the read data. */ if (text->len != expected_len) return svn_error_createf(SVN_ERR_FS_GENERAL, NULL, "record read returned unexpected size " "(got %" APR_SIZE_T_FMT ", " "expected %" APR_SIZE_T_FMT ")", size, expected_len); if (memcmp(expected_text, text->data, expected_len)) return svn_error_create(SVN_ERR_FS_GENERAL, NULL, "record read returned unexpected data"); return SVN_NO_ERROR; }
svn_error_t * svn_cl__xml_print_footer(const char *tagname, apr_pool_t *pool) { svn_stringbuf_t *sb = svn_stringbuf_create_empty(pool); /* "</TAGNAME>" */ svn_xml_make_close_tag(&sb, pool, tagname); return svn_cl__error_checked_fputs(sb->data, stdout); }
/* Prints XML target element with path attribute TARGET, using POOL for temporary allocations. */ static svn_error_t * print_start_target_xml(const char *target, apr_pool_t *pool) { svn_stringbuf_t *sb = svn_stringbuf_create_empty(pool); svn_xml_make_open_tag(&sb, pool, svn_xml_normal, "target", "path", target, SVN_VA_NULL); return svn_cl__error_checked_fputs(sb->data, stdout); }
static svn_error_t * test_stream_tee(apr_pool_t *pool) { svn_stringbuf_t *test_bytes = generate_test_bytes(100, pool); svn_stringbuf_t *output_buf1 = svn_stringbuf_create_empty(pool); svn_stringbuf_t *output_buf2 = svn_stringbuf_create_empty(pool); svn_stream_t *source_stream = svn_stream_from_stringbuf(test_bytes, pool); svn_stream_t *output_stream1 = svn_stream_from_stringbuf(output_buf1, pool); svn_stream_t *output_stream2 = svn_stream_from_stringbuf(output_buf2, pool); svn_stream_t *tee_stream; tee_stream = svn_stream_tee(output_stream1, output_stream2, pool); SVN_ERR(svn_stream_copy3(source_stream, tee_stream, NULL, NULL, pool)); if (!svn_stringbuf_compare(output_buf1, output_buf2)) return svn_error_create(SVN_ERR_TEST_FAILED, NULL, "Duplicated streams did not match."); return SVN_NO_ERROR; }
static svn_error_t * test_serialization(apr_pool_t *pool) { svn_stringbuf_t *original_content; svn_stringbuf_t *written_content; svn_config_t *cfg; const struct { const char *section; const char *option; const char *value; } test_data[] = { { "my section", "value1", "some" }, { "my section", "value2", "something" }, { "another Section", "value1", "one" }, { "another Section", "value2", "two" }, { "another Section", "value 3", "more" }, }; int i; /* Format the original with the same formatting that the writer will use. */ original_content = svn_stringbuf_create("\n[my section]\n" "value1=some\n" "value2=%(value1)sthing\n" "\n[another Section]\n" "value1=one\n" "value2=two\n" "value 3=more\n", pool); written_content = svn_stringbuf_create_empty(pool); SVN_ERR(svn_config_parse(&cfg, svn_stream_from_stringbuf(original_content, pool), TRUE, TRUE, pool)); SVN_ERR(svn_config__write(svn_stream_from_stringbuf(written_content, pool), cfg, pool)); SVN_ERR(svn_config_parse(&cfg, svn_stream_from_stringbuf(written_content, pool), TRUE, TRUE, pool)); /* The serialized and re-parsed config must have the expected contents. */ for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); ++i) { const char *val; svn_config_get(cfg, &val, test_data[i].section, test_data[i].option, NULL); SVN_TEST_STRING_ASSERT(val, test_data[i].value); } return SVN_NO_ERROR; }
svn_error_t * svn_config_create2(svn_config_t **cfgp, svn_boolean_t section_names_case_sensitive, svn_boolean_t option_names_case_sensitive, apr_pool_t *result_pool) { svn_config_t *cfg = apr_palloc(result_pool, sizeof(*cfg)); cfg->sections = apr_hash_make(result_pool); cfg->pool = result_pool; cfg->x_pool = svn_pool_create(result_pool); cfg->x_values = FALSE; cfg->tmp_key = svn_stringbuf_create_empty(result_pool); cfg->tmp_value = svn_stringbuf_create_empty(result_pool); cfg->section_names_case_sensitive = section_names_case_sensitive; cfg->option_names_case_sensitive = option_names_case_sensitive; cfg->read_only = FALSE; *cfgp = cfg; return SVN_NO_ERROR; }
svn_error_t * svn_cl__xml_print_header(const char *tagname, apr_pool_t *pool) { svn_stringbuf_t *sb = svn_stringbuf_create_empty(pool); /* <?xml version="1.0" encoding="UTF-8"?> */ svn_xml_make_header2(&sb, "UTF-8", pool); /* "<TAGNAME>" */ svn_xml_make_open_tag(&sb, pool, svn_xml_normal, tagname, SVN_VA_NULL); return svn_cl__error_checked_fputs(sb->data, stdout); }
static svn_error_t * test_one_long_keyword(const char *keyword, const char *expected, apr_pool_t *pool) { svn_string_t *src_string; svn_stream_t *src_stream, *dst_stream; svn_stringbuf_t *dst_stringbuf, *src_stringbuf; apr_hash_t *keywords = apr_hash_make(pool); svn_string_t *expanded = svn_string_create("abcdefg", pool); svn_hash_sets(keywords, keyword, expanded); /* Expand */ src_string = svn_string_createf(pool, "$%s$", keyword); src_stream = svn_stream_from_string(src_string, pool); dst_stringbuf = svn_stringbuf_create_empty(pool); dst_stream = svn_stream_from_stringbuf(dst_stringbuf, pool); dst_stream = svn_subst_stream_translated(dst_stream, NULL, FALSE, keywords, TRUE, pool); SVN_ERR(svn_stream_copy3(src_stream, dst_stream, NULL, NULL, pool)); SVN_TEST_STRING_ASSERT(dst_stringbuf->data, expected); /* Unexpand */ src_stringbuf = dst_stringbuf; src_stream = svn_stream_from_stringbuf(src_stringbuf, pool); dst_stringbuf = svn_stringbuf_create_empty(pool); dst_stream = svn_stream_from_stringbuf(dst_stringbuf, pool); dst_stream = svn_subst_stream_translated(dst_stream, NULL, FALSE, keywords, FALSE, pool); SVN_ERR(svn_stream_copy3(src_stream, dst_stream, NULL, NULL, pool)); SVN_TEST_STRING_ASSERT(dst_stringbuf->data, src_string->data); return SVN_NO_ERROR; }
svn_error_t * svn_diff_hunk_readline_diff_text(svn_diff_hunk_t *hunk, svn_stringbuf_t **stringbuf, const char **eol, svn_boolean_t *eof, apr_pool_t *result_pool, apr_pool_t *scratch_pool) { svn_stringbuf_t *line; apr_size_t max_len; apr_off_t pos; if (hunk->diff_text_range.current >= hunk->diff_text_range.end) { /* We're past the range. Indicate that no bytes can be read. */ *eof = TRUE; if (eol) *eol = NULL; *stringbuf = svn_stringbuf_create_empty(result_pool); return SVN_NO_ERROR; } pos = 0; SVN_ERR(svn_io_file_seek(hunk->apr_file, APR_CUR, &pos, scratch_pool)); SVN_ERR(svn_io_file_seek(hunk->apr_file, APR_SET, &hunk->diff_text_range.current, scratch_pool)); max_len = hunk->diff_text_range.end - hunk->diff_text_range.current; SVN_ERR(svn_io_file_readline(hunk->apr_file, &line, eol, eof, max_len, result_pool, scratch_pool)); hunk->diff_text_range.current = 0; SVN_ERR(svn_io_file_seek(hunk->apr_file, APR_CUR, &hunk->diff_text_range.current, scratch_pool)); SVN_ERR(svn_io_file_seek(hunk->apr_file, APR_SET, &pos, scratch_pool)); if (hunk->patch->reverse) { if (line->data[0] == '+') line->data[0] = '-'; else if (line->data[0] == '-') line->data[0] = '+'; } *stringbuf = line; return SVN_NO_ERROR; }
/* Create a separator string of the appropriate length. */ static const char * get_sep_string(apr_pool_t *result_pool) { int line_width = LINE_DISPLAY_WIDTH; int i; svn_stringbuf_t *buf; buf = svn_stringbuf_create_empty(result_pool); for (i = 0; i < line_width; i++) svn_stringbuf_appendbyte(buf, '-'); svn_stringbuf_appendbyte(buf, '+'); for (i = 0; i < line_width; i++) svn_stringbuf_appendbyte(buf, '-'); svn_stringbuf_appendbyte(buf, '\n'); return buf->data; }
char * svn_cstring_join(const apr_array_header_t *strings, const char *separator, apr_pool_t *pool) { svn_stringbuf_t *new_str = svn_stringbuf_create_empty(pool); size_t sep_len = strlen(separator); int i; for (i = 0; i < strings->nelts; i++) { const char *string = APR_ARRAY_IDX(strings, i, const char *); svn_stringbuf_appendbytes(new_str, string, strlen(string)); svn_stringbuf_appendbytes(new_str, separator, sep_len); } return new_str->data; }
static svn_error_t * test_decompress_lz4(apr_pool_t *pool) { const char input[] = "\x61\xc0\x61\x61\x61\x61\x62\x62\x62\x62\x63\x63\x63\x63\x0c\x00\x00\x08" "\x00\x00\x10\x00\x00\x0c\x00\x08\x08\x00\x00\x18\x00\x00\x14\x00\x00\x08" "\x00\x08\x18\x00\x00\x14\x00\x00\x10\x00\x00\x18\x00\x00\x0c\x00\x00\x08" "\x00\x00\x10\x00\x90\x61\x61\x61\x61\x62\x62\x62\x62"; svn_stringbuf_t *decompressed = svn_stringbuf_create_empty(pool); SVN_ERR(svn__decompress_lz4(input, sizeof(input), decompressed, 100)); SVN_TEST_STRING_ASSERT(decompressed->data, "aaaabbbbccccaaaaccccbbbbaaaabbbb" "aaaabbbbccccaaaaccccbbbbaaaabbbb" "aaaabbbbccccaaaaccccbbbbaaaabbbb"); return SVN_NO_ERROR; }
static svn_error_t * store_and_load_table(string_table_t **table, apr_pool_t *pool) { svn_stringbuf_t *stream_buffer = svn_stringbuf_create_empty(pool); svn_stream_t *stream; stream = svn_stream_from_stringbuf(stream_buffer, pool); SVN_ERR(svn_fs_x__write_string_table(stream, *table, pool)); SVN_ERR(svn_stream_close(stream)); *table = NULL; stream = svn_stream_from_stringbuf(stream_buffer, pool); SVN_ERR(svn_fs_x__read_string_table(table, stream, pool, pool)); SVN_ERR(svn_stream_close(stream)); return SVN_NO_ERROR; }
/* Finish a target element by optionally printing an against element if * REPOS_REV is a valid revision number, and then printing an target end tag. * Use POOL for temporary allocations. */ static svn_error_t * print_finish_target_xml(svn_revnum_t repos_rev, apr_pool_t *pool) { svn_stringbuf_t *sb = svn_stringbuf_create_empty(pool); if (SVN_IS_VALID_REVNUM(repos_rev)) { const char *repos_rev_str; repos_rev_str = apr_psprintf(pool, "%ld", repos_rev); svn_xml_make_open_tag(&sb, pool, svn_xml_self_closing, "against", "revision", repos_rev_str, SVN_VA_NULL); } svn_xml_make_close_tag(&sb, pool, "target"); return svn_cl__error_checked_fputs(sb->data, stdout); }
svn_error_t * svn_ra_neon__replay(svn_ra_session_t *session, svn_revnum_t revision, svn_revnum_t low_water_mark, svn_boolean_t send_deltas, const svn_delta_editor_t *editor, void *edit_baton, apr_pool_t *pool) { svn_ra_neon__session_t *ras = session->priv; replay_baton_t rb; const char *body = apr_psprintf(pool, "<S:replay-report xmlns:S=\"svn:\">\n" " <S:revision>%ld</S:revision>\n" " <S:low-water-mark>%ld</S:low-water-mark>\n" " <S:send-deltas>%d</S:send-deltas>\n" "</S:replay-report>", revision, low_water_mark, send_deltas); memset(&rb, 0, sizeof(rb)); rb.editor = editor; rb.edit_baton = edit_baton; rb.pool = pool; rb.dirs = apr_array_make(pool, 5, sizeof(dir_item_t)); rb.prop_pool = svn_pool_create(pool); rb.prop_accum = svn_stringbuf_create_empty(rb.prop_pool); return svn_ra_neon__parsed_request(ras, "REPORT", ras->url->data, body, NULL, NULL, start_element, cdata_handler, end_element, &rb, NULL, /* extra headers */ NULL, /* status code */ FALSE, /* spool response */ pool); }
/* Escape all non-ascii or control characters similar to * svn_xml_fuzzy_escape() and svn_utf_cstring_from_utf8_fuzzy(). * All of the encoding formats somewhat overlap with ascii (BMPString * and UniversalString are actually always wider so you'll end up * with a bunch of escaped nul bytes, but ideally we don't get here * for those). The result is always a nul-terminated C string. */ static const char * fuzzy_escape(const svn_string_t *src, apr_pool_t *result_pool) { const char *end = src->data + src->len; const char *p = src->data, *q; svn_stringbuf_t *outstr; char escaped_char[6]; /* ? \ u u u \0 */ for (q = p; q < end; q++) { if (!svn_ctype_isascii(*q) || svn_ctype_iscntrl(*q)) break; } if (q == end) return src->data; outstr = svn_stringbuf_create_empty(result_pool); while (1) { q = p; /* Traverse till either unsafe character or eos. */ while (q < end && svn_ctype_isascii(*q) && !svn_ctype_iscntrl(*q)) q++; /* copy chunk before marker */ svn_stringbuf_appendbytes(outstr, p, q - p); if (q == end) break; apr_snprintf(escaped_char, sizeof(escaped_char), "?\\%03u", (unsigned char) *q); svn_stringbuf_appendcstr(outstr, escaped_char); p = q + 1; } return outstr->data; }
static svn_error_t * test_svn_subst_truncated_keywords(apr_pool_t *pool) { svn_string_t *src_string = svn_string_create("$Qq: " "01234567890123456789012345678901234567890123456789" "01234567890123456789012345678901234567890123456789" "01234567890123456789012345678901234567890123456789" "01234567890123456789012345678901234567890123456789" "012345678901234567890123456789012345678901234567" " $", pool); svn_stream_t *src_stream = svn_stream_from_string(src_string, pool); svn_stringbuf_t *dst_stringbuf = svn_stringbuf_create_empty(pool); svn_stream_t *dst_stream = svn_stream_from_stringbuf(dst_stringbuf, pool); apr_hash_t *keywords = apr_hash_make(pool); svn_string_t *expanded = svn_string_create("01234567890123456789012345678901234567890123456789" "01234567890123456789012345678901234567890123456789" "01234567890123456789012345678901234567890123456789" "01234567890123456789012345678901234567890123456789" "012345678901234567890123456789012345678901234567" "xxxxxxxxxx", pool); /* The source is already at the maximum length. */ SVN_TEST_ASSERT(src_string->len == SVN_KEYWORD_MAX_LEN); svn_hash_sets(keywords, "Qq", expanded); dst_stream = svn_subst_stream_translated(dst_stream, NULL, FALSE, keywords, TRUE, pool); SVN_ERR(svn_stream_copy3(src_stream, dst_stream, NULL, NULL, pool)); /* The expanded value would make the keyword longer than the maximum allowed so it must be truncated; the remaining part of the expanded value is the same as the source. */ SVN_TEST_STRING_ASSERT(dst_stringbuf->data, src_string->data); return SVN_NO_ERROR; }
/* Escape only NUL characters from a string that is presumed to * be UTF-8 encoded and return a nul-terminated C string. */ static const char * nul_escape(const svn_string_t *src, apr_pool_t *result_pool) { const char *end = src->data + src->len; const char *p = src->data, *q; svn_stringbuf_t *outstr; for (q = p; q < end; q++) { if (*q == '\0') break; } if (q == end) return src->data; outstr = svn_stringbuf_create_empty(result_pool); while (1) { q = p; /* Traverse till either unsafe character or eos. */ while (q < end && *q != '\0') q++; /* copy chunk before marker */ svn_stringbuf_appendbytes(outstr, p, q - p); if (q == end) break; svn_stringbuf_appendcstr(outstr, "?\\000"); p = q + 1; } return outstr->data; }
/* Print a revision record header for REVISION to STDOUT_STREAM. Use * SESSION to contact the repository for revision properties and * such. */ static svn_error_t * dump_revision_header(svn_ra_session_t *session, svn_stream_t *stdout_stream, svn_revnum_t revision, apr_pool_t *pool) { apr_hash_t *prophash; svn_stringbuf_t *propstring; svn_stream_t *propstream; SVN_ERR(svn_stream_printf(stdout_stream, pool, SVN_REPOS_DUMPFILE_REVISION_NUMBER ": %ld\n", revision)); prophash = apr_hash_make(pool); propstring = svn_stringbuf_create_empty(pool); SVN_ERR(svn_ra_rev_proplist(session, revision, &prophash, pool)); propstream = svn_stream_from_stringbuf(propstring, pool); SVN_ERR(svn_hash_write2(prophash, propstream, "PROPS-END", pool)); SVN_ERR(svn_stream_close(propstream)); /* Property-content-length: 14; Content-length: 14 */ SVN_ERR(svn_stream_printf(stdout_stream, pool, SVN_REPOS_DUMPFILE_PROP_CONTENT_LENGTH ": %" APR_SIZE_T_FMT "\n", propstring->len)); SVN_ERR(svn_stream_printf(stdout_stream, pool, SVN_REPOS_DUMPFILE_CONTENT_LENGTH ": %" APR_SIZE_T_FMT "\n\n", propstring->len)); /* The properties */ SVN_ERR(svn_stream_write(stdout_stream, propstring->data, &(propstring->len))); SVN_ERR(svn_stream_printf(stdout_stream, pool, "\n")); return SVN_NO_ERROR; }
/* Compute and return a delta window using the xdelta algorithm on DATA, which contains SOURCE_LEN bytes of source data and TARGET_LEN bytes of target data. SOURCE_OFFSET gives the offset of the source data, and is simply copied into the window's sview_offset field. */ static svn_txdelta_window_t * compute_window(const char *data, apr_size_t source_len, apr_size_t target_len, svn_filesize_t source_offset, apr_pool_t *pool) { svn_txdelta__ops_baton_t build_baton = { 0 }; svn_txdelta_window_t *window; /* Compute the delta operations. */ build_baton.new_data = svn_stringbuf_create_empty(pool); if (source_len == 0) svn_txdelta__insert_op(&build_baton, svn_txdelta_new, 0, target_len, data, pool); else svn_txdelta__xdelta(&build_baton, data, source_len, target_len, pool); /* Create and return the delta window. */ window = svn_txdelta__make_window(&build_baton, pool); window->sview_offset = source_offset; window->sview_len = source_len; window->tview_len = target_len; return window; }
/* generate some poorly compressable data */ static svn_stringbuf_t * generate_test_bytes(int num_bytes, apr_pool_t *pool) { svn_stringbuf_t *buffer = svn_stringbuf_create_empty(pool); int total, repeat, repeat_iter; char c; for (total = 0, repeat = repeat_iter = 1, c = 0; total < num_bytes; total++) { svn_stringbuf_appendbyte(buffer, c); repeat_iter--; if (repeat_iter == 0) { if (c == 127) repeat++; c = (char)((c + 1) % 127); repeat_iter = repeat; } } return buffer; }
svn_error_t * SVNAuthData::cleanup_callback(svn_boolean_t *delete_cred, void *cleanup_baton, const char *cred_kind, const char *realmstring, apr_hash_t * hash, apr_pool_t * scratch_pool) { std::tuple<std::vector<std::tuple<CString, CString, SVNAuthDataInfo>>*, std::vector<std::tuple<CString, CString, SVNAuthDataInfo>>> * tupleBaton = (std::tuple<std::vector<std::tuple<CString, CString, SVNAuthDataInfo>>*, std::vector<std::tuple<CString, CString, SVNAuthDataInfo>>>*)cleanup_baton; auto authList = std::get<0>(*tupleBaton); auto delList = std::get<1>(*tupleBaton); CString s1, s2; if (cred_kind) s1 = CUnicodeUtils::GetUnicode(cred_kind); if (realmstring) s2 = CUnicodeUtils::GetUnicode(realmstring); SVNAuthDataInfo authinfodata; for (apr_hash_index_t *hi = apr_hash_first(scratch_pool, hash); hi; hi = apr_hash_next(hi)) { const void *vkey; void *val; apr_hash_this(hi, &vkey, NULL, &val); const char * key = (const char*)vkey; svn_string_t *value = (svn_string_t *)val; if (strcmp(key, SVN_CONFIG_AUTHN_PASSWORD_KEY) == 0) { CStringA data(value->data, (int)value->len); authinfodata.password = CUnicodeUtils::GetUnicode(data); } else if (strcmp(key, SVN_CONFIG_AUTHN_PASSPHRASE_KEY) == 0) { CStringA data(value->data, (int)value->len); authinfodata.passphrase = CUnicodeUtils::GetUnicode(data); } else if (strcmp(key, SVN_CONFIG_AUTHN_PASSTYPE_KEY) == 0) { CStringA data(value->data, (int)value->len); authinfodata.passtype = CUnicodeUtils::GetUnicode(data); } else if (strcmp(key, SVN_CONFIG_AUTHN_USERNAME_KEY) == 0) { CStringA data(value->data, (int)value->len); authinfodata.username = CUnicodeUtils::GetUnicode(data); } else if (strcmp(key, SVN_CONFIG_AUTHN_ASCII_CERT_KEY) == 0) { const svn_string_t * der_cert = nullptr; svn_x509_certinfo_t * certinfo = nullptr; const apr_array_header_t * hostnames = nullptr; svn_error_t *err; /* Convert header-less PEM to DER by undoing base64 encoding. */ der_cert = svn_base64_decode_string(value, scratch_pool); err = svn_x509_parse_cert(&certinfo, der_cert->data, der_cert->len, scratch_pool, scratch_pool); if (err) continue; authinfodata.subject = svn_x509_certinfo_get_subject(certinfo, scratch_pool); authinfodata.validfrom = svn_time_to_human_cstring(svn_x509_certinfo_get_valid_from(certinfo), scratch_pool); authinfodata.validuntil = svn_time_to_human_cstring(svn_x509_certinfo_get_valid_to(certinfo), scratch_pool); authinfodata.issuer = svn_x509_certinfo_get_issuer(certinfo, scratch_pool); authinfodata.fingerprint = svn_checksum_to_cstring_display(svn_x509_certinfo_get_digest(certinfo), scratch_pool); hostnames = svn_x509_certinfo_get_hostnames(certinfo); if (hostnames && !apr_is_empty_array(hostnames)) { int i; svn_stringbuf_t *buf = svn_stringbuf_create_empty(scratch_pool); for (i = 0; i < hostnames->nelts; ++i) { const char *hostname = APR_ARRAY_IDX(hostnames, i, const char*); if (i > 0) svn_stringbuf_appendbytes(buf, ", ", 2); svn_stringbuf_appendbytes(buf, hostname, strlen(hostname)); } authinfodata.hostname = buf->data; } } else if (strcmp(key, SVN_CONFIG_AUTHN_FAILURES_KEY) == 0)