385
376
void *handler_baton,
386
377
apr_pool_t *scratch_pool);
379
/* Callback when the request is done */
380
typedef svn_error_t *
381
(*svn_ra_serf__response_done_delegate_t)(serf_request_t *request,
383
apr_pool_t *scratch_pool);
388
385
/* Callback for when a request body is needed. */
389
/* ### should pass a scratch_pool */
390
386
typedef svn_error_t *
391
387
(*svn_ra_serf__request_body_delegate_t)(serf_bucket_t **body_bkt,
393
389
serf_bucket_alloc_t *alloc,
394
apr_pool_t *request_pool);
390
apr_pool_t *request_pool,
391
apr_pool_t *scratch_pool);
396
393
/* Callback for when request headers are needed. */
397
/* ### should pass a scratch_pool */
398
394
typedef svn_error_t *
399
395
(*svn_ra_serf__request_header_delegate_t)(serf_bucket_t *headers,
401
apr_pool_t *request_pool);
397
apr_pool_t *request_pool,
398
apr_pool_t *scratch_pool);
403
400
/* Callback for when a response has an error. */
404
401
typedef svn_error_t *
512
535
void svn_ra_serf__request_create(svn_ra_serf__handler_t *handler);
514
/* XML helper callbacks. */
516
typedef struct svn_ra_serf__xml_state_t {
517
/* A numeric value that represents the current state in parsing.
519
* Value 0 is reserved for use as the default state.
523
/* Private pointer set by the parsing code. */
526
/* Allocations should be made in this pool to match the lifetime of the
531
/* The currently-declared namespace for this state. */
532
svn_ra_serf__ns_t *ns_list;
534
/* Our previous states. */
535
struct svn_ra_serf__xml_state_t *prev;
536
} svn_ra_serf__xml_state_t;
538
/* Forward declaration of the XML parser structure. */
539
typedef struct svn_ra_serf__xml_parser_t svn_ra_serf__xml_parser_t;
541
/* Callback invoked with @a baton by our XML @a parser when an element with
542
* the @a name containing @a attrs is opened.
544
typedef svn_error_t *
545
(*svn_ra_serf__xml_start_element_t)(svn_ra_serf__xml_parser_t *parser,
546
svn_ra_serf__dav_props_t name,
548
apr_pool_t *scratch_pool);
550
/* Callback invoked with @a baton by our XML @a parser when an element with
551
* the @a name is closed.
553
typedef svn_error_t *
554
(*svn_ra_serf__xml_end_element_t)(svn_ra_serf__xml_parser_t *parser,
555
svn_ra_serf__dav_props_t name,
556
apr_pool_t *scratch_pool);
558
/* Callback invoked with @a baton by our XML @a parser when a CDATA portion
559
* of @a data with size @a len is encountered.
561
* This may be invoked multiple times for the same tag.
563
typedef svn_error_t *
564
(*svn_ra_serf__xml_cdata_chunk_handler_t)(svn_ra_serf__xml_parser_t *parser,
567
apr_pool_t *scratch_pool);
570
* Helper structure associated with handle_xml_parser handler that will
571
* specify how an XML response will be processed.
573
struct svn_ra_serf__xml_parser_t {
574
/* Temporary allocations should be made in this pool. */
577
/* What kind of response are we parsing? If set, this should typically
578
define the report name. */
579
const char *response_type;
581
/* Caller-specific data passed to the start, end, cdata callbacks. */
584
/* Callback invoked when a tag is opened. */
585
svn_ra_serf__xml_start_element_t start;
587
/* Callback invoked when a tag is closed. */
588
svn_ra_serf__xml_end_element_t end;
590
/* Callback invoked when a cdata chunk is received. */
591
svn_ra_serf__xml_cdata_chunk_handler_t cdata;
593
/* Our associated expat-based XML parser. */
596
/* Our current state. */
597
svn_ra_serf__xml_state_t *state;
599
/* Our previously used states (will be reused). */
600
svn_ra_serf__xml_state_t *free_state;
602
/* If non-NULL, this value will be set to TRUE when the response is
607
/* If non-NULL, when this parser completes, it will add done_item to
610
svn_ra_serf__list_t **done_list;
612
/* A pointer to the item that will be inserted into the list upon
615
svn_ra_serf__list_t *done_item;
617
/* If this flag is TRUE, errors during parsing will be ignored.
619
* This is mainly used when we are processing an error XML response to
620
* avoid infinite loops.
622
svn_boolean_t ignore_errors;
624
/* If an error occurred, this value will be non-NULL. */
627
/* Deciding whether to pause, or not, is performed within the parsing
628
callbacks. If a callback decides to set this flag, then the loop
629
driving the parse (generally, a series of calls to serf_context_run())
630
is going to need to coordinate the un-pausing of the parser by
631
processing pending content. Thus, deciding to pause the parser is a
632
coordinate effort rather than merely setting this flag.
634
When an XML parsing callback sets this flag, note that additional
635
elements may be parsed (as the current buffer is consumed). At some
636
point, the flag will be recognized and arriving network content will
637
be stashed away in the PENDING structure (see below).
639
At some point, the controlling loop should clear this value. The
640
underlying network processing will note the change and begin passing
641
content into the XML callbacks.
643
Note that the controlling loop should also process pending content
644
since the arriving network content will typically finish first. */
645
svn_boolean_t paused;
647
/* While the XML parser is paused, content arriving from the server
648
must be saved locally. We cannot stop reading, or the server may
649
decide to drop the connection. The content will be stored in memory
650
up to a certain limit, and will then be spilled over to disk.
652
See libsvn_ra_serf/util.c */
653
struct svn_ra_serf__pending_t *pending;
657
537
/* v2 of the XML parsing functions */
659
539
/* The XML parsing context. */
784
675
apr_pool_t *result_pool);
786
/* Destroy all subpools for this structure. */
788
svn_ra_serf__xml_context_destroy(
789
svn_ra_serf__xml_context_t *xmlctx);
677
/* Verifies if the parsing completed successfully and destroys
680
svn_ra_serf__xml_context_done(svn_ra_serf__xml_context_t *xmlctx);
791
682
/* Construct a handler with the response function/baton set up to parse
792
683
a response body using the given XML context. The handler and its
793
684
internal structures are allocated in RESULT_POOL.
686
As part of the handling the http status value is compared to 200, or
687
if EXPECTED_STATUS is not NULL to all the values in EXPECTED_STATUS.
688
EXPECTED_STATUS is expected to be a list of integers ending with a 0
689
that lives at least as long as RESULT_POOL. If the status doesn't
690
match the request has failed and will be parsed as en error response.
795
692
This also initializes HANDLER_POOL to the given RESULT_POOL. */
796
693
svn_ra_serf__handler_t *
797
svn_ra_serf__create_expat_handler(svn_ra_serf__xml_context_t *xmlctx,
694
svn_ra_serf__create_expat_handler(svn_ra_serf__session_t *session,
695
svn_ra_serf__xml_context_t *xmlctx,
696
const int *expected_status,
798
697
apr_pool_t *result_pool);
834
733
svn_ra_serf__xml_state_pool(svn_ra_serf__xml_estate_t *xes);
837
/* Any XML parser may be used. When an opening tag is seen, call this
838
function to feed the information into XMLCTX. */
840
svn_ra_serf__xml_cb_start(svn_ra_serf__xml_context_t *xmlctx,
841
const char *raw_name,
842
const char *const *attrs);
845
/* When a close tag is seen, call this function to feed the information
848
svn_ra_serf__xml_cb_end(svn_ra_serf__xml_context_t *xmlctx,
849
const char *raw_name);
852
/* When cdata is parsed by the wrapping XML parser, call this function to
853
feed the cdata into the XMLCTX. */
855
svn_ra_serf__xml_cb_cdata(svn_ra_serf__xml_context_t *xmlctx,
861
736
* Parses a server-side error message into a local Subversion error.
863
738
struct svn_ra_serf__server_error_t {
864
/* Our local representation of the error. */
867
/* Are we done with the response? */
870
/* Have we seen an error tag? */
871
svn_boolean_t in_error;
873
/* Have we seen a HTTP "412 Precondition Failed" error? */
874
svn_boolean_t contains_precondition_error;
876
/* Should we be collecting the XML cdata? */
877
svn_boolean_t collect_cdata;
879
/* Collected cdata. NULL if cdata not needed. */
880
svn_stringbuf_t *cdata;
882
741
/* XML parser and namespace used to parse the remote response */
883
svn_ra_serf__xml_parser_t parser;
742
svn_ra_serf__xml_context_t *xmlctx;
744
svn_ra_serf__response_handler_t response_handler;
745
void *response_baton;
747
/* The partial errors to construct the final error from */
748
apr_array_header_t *items;
750
/* The hooked handler */
751
svn_ra_serf__handler_t *handler;
888
755
* Handler that discards the entire @a response body associated with a
889
756
* @a request. Implements svn_ra_serf__response_handler_t.
943
* This function will feed the RESPONSE body into XMLP. When parsing is
944
* completed (i.e. an EOF is received), *DONE is set to TRUE.
945
* Implements svn_ra_serf__response_handler_t.
947
* If an error occurs during processing RESP_ERR is invoked with the
950
* Temporary allocations are made in POOL.
953
svn_ra_serf__handle_xml_parser(serf_request_t *request,
954
serf_bucket_t *response,
810
* This function sets up error parsing for an existing request
813
svn_ra_serf__setup_error_parsing(svn_ra_serf__server_error_t **server_err,
814
svn_ra_serf__handler_t *handler,
815
svn_boolean_t expect_207_only,
816
apr_pool_t *result_pool,
817
apr_pool_t *scratch_pool);
820
* Forwards response data to the server error parser
823
svn_ra_serf__handle_server_error(svn_ra_serf__server_error_t *server_error,
824
svn_ra_serf__handler_t *handler,
825
serf_request_t *request,
826
serf_bucket_t *response,
827
apr_status_t *serf_status,
828
apr_pool_t *scratch_pool);
831
* Creates the svn_error_t * instance from the error recorded in
832
* HANDLER->server_error
835
svn_ra_serf__server_error_create(svn_ra_serf__handler_t *handler,
836
apr_pool_t *scratch_pool);
958
838
/* serf_response_handler_t implementation that completely discards
1051
919
svn_ra_serf__add_cdata_len_buckets(serf_bucket_t *agg_bucket,
1052
920
serf_bucket_alloc_t *bkt_alloc,
1053
921
const char *data, apr_size_t len);
1055
* Look up the @a attrs array for namespace definitions and add each one
1056
* to the @a ns_list of namespaces.
1058
* New namespaces will be allocated in RESULT_POOL.
1061
svn_ra_serf__define_ns(svn_ra_serf__ns_t **ns_list,
1062
const char *const *attrs,
1063
apr_pool_t *result_pool);
1066
* Look up @a name in the @a ns_list list for previously declared namespace
1069
* Return (in @a *returned_prop_name) a #svn_ra_serf__dav_props_t tuple
1070
* representing the expanded name.
1073
svn_ra_serf__expand_ns(svn_ra_serf__dav_props_t *returned_prop_name,
1074
const svn_ra_serf__ns_t *ns_list,
1078
924
/** PROPFIND-related functions **/
1081
* This function will deliver a PROP_CTX PROPFIND request in the SESS
1082
* serf context for the properties listed in LOOKUP_PROPS at URL for
1083
* DEPTH ("0","1","infinity").
1085
* This function will not block waiting for the response. Callers are
1086
* expected to call svn_ra_serf__wait_for_props().
1089
svn_ra_serf__deliver_props(svn_ra_serf__handler_t **propfind_handler,
1090
apr_hash_t *prop_vals,
1091
svn_ra_serf__session_t *sess,
1092
svn_ra_serf__connection_t *conn,
1096
const svn_ra_serf__dav_props_t *lookup_props,
1097
svn_ra_serf__list_t **done_list,
1101
* This helper function will block until PROPFIND_HANDLER indicates that is
1102
* done or another error is returned.
1105
svn_ra_serf__wait_for_props(svn_ra_serf__handler_t *handler,
1106
apr_pool_t *scratch_pool);
1108
/* This is a blocking version of deliver_props.
1110
The properties are fetched and placed into RESULTS, allocated in
1113
### more docco about the other params.
1115
Temporary allocations are made in SCRATCH_POOL.
1118
svn_ra_serf__retrieve_props(apr_hash_t **results,
1119
svn_ra_serf__session_t *sess,
1120
svn_ra_serf__connection_t *conn,
1124
const svn_ra_serf__dav_props_t *props,
1125
apr_pool_t *result_pool,
1126
apr_pool_t *scratch_pool);
1129
/* Using CONN, fetch the properties specified by WHICH_PROPS using CONN
926
/* Removes all non regular properties from PROPS */
928
svn_ra_serf__keep_only_regular_props(apr_hash_t *props,
929
apr_pool_t *scratch_pool);
932
/* Callback used via svn_ra_serf__deliver_props2 */
933
typedef svn_error_t *
934
(*svn_ra_serf__prop_func_t)(void *baton,
938
const svn_string_t *value,
939
apr_pool_t *scratch_pool);
942
* Implementation of svn_ra_serf__prop_func_t that just delivers svn compatible
943
* properties in the apr_hash_t * that is used as baton.
946
svn_ra_serf__deliver_svn_props(void *baton,
950
const svn_string_t *value,
951
apr_pool_t *scratch_pool);
954
* This function will create a handler for a PROPFIND request, which will deliver
955
* properties to PROP_FUNC() with PROP_BATON for the properties listed in LOOKUP_PROPS
956
* at URL for DEPTH ("0","1","infinity").
959
svn_ra_serf__create_propfind_handler(svn_ra_serf__handler_t **handler,
960
svn_ra_serf__session_t *session,
964
const svn_ra_serf__dav_props_t *find_props,
965
svn_ra_serf__prop_func_t prop_func,
966
void *prop_func_baton,
967
apr_pool_t *result_pool);
970
/* Using SESSION, fetch the properties specified by WHICH_PROPS using CONN
1130
971
for URL at REVISION. The resulting properties are placed into a 2-level
1131
972
hash in RESULTS, mapping NAMESPACE -> hash<PROPNAME, PROPVALUE>, which
1132
973
is allocated in RESULT_POOL.
1161
1002
Temporary allocations are made in SCRATCH_POOL. */
1163
1004
svn_ra_serf__fetch_dav_prop(const char **value,
1164
svn_ra_serf__connection_t *conn,
1005
svn_ra_serf__session_t *session,
1165
1006
const char *url,
1166
1007
svn_revnum_t revision,
1167
1008
const char *propname,
1168
1009
apr_pool_t *result_pool,
1169
1010
apr_pool_t *scratch_pool);
1172
/* Set PROPS for PATH at REV revision with a NS:NAME VAL.
1174
* The POOL governs allocation.
1177
svn_ra_serf__set_ver_prop(apr_hash_t *props,
1178
const char *path, svn_revnum_t rev,
1179
const char *ns, const char *name,
1180
const svn_string_t *val, apr_pool_t *pool);
1181
#define svn_ra_serf__set_rev_prop svn_ra_serf__set_ver_prop
1183
/** Property walker functions **/
1185
typedef svn_error_t *
1186
(*svn_ra_serf__walker_visitor_t)(void *baton,
1189
const svn_string_t *val,
1193
svn_ra_serf__walk_all_props(apr_hash_t *props,
1196
svn_ra_serf__walker_visitor_t walker,
1201
/* Like walk_all_props(), but a 2-level hash. */
1203
svn_ra_serf__walk_node_props(apr_hash_t *props,
1204
svn_ra_serf__walker_visitor_t walker,
1206
apr_pool_t *scratch_pool);
1209
typedef svn_error_t *
1210
(*svn_ra_serf__path_rev_walker_t)(void *baton,
1211
const char *path, apr_ssize_t path_len,
1212
const char *ns, apr_ssize_t ns_len,
1213
const char *name, apr_ssize_t name_len,
1214
const svn_string_t *val,
1217
svn_ra_serf__walk_all_paths(apr_hash_t *props,
1219
svn_ra_serf__path_rev_walker_t walker,
1224
1012
/* Map a property name, as passed over the wire, into its corresponding
1225
1013
Subversion-internal name. The returned name will be a static value,
1226
1014
or allocated within RESULT_POOL.
1232
1020
const char *name,
1233
1021
apr_pool_t *result_pool);
1236
/* Select the basic revision properties from the set of "all" properties.
1237
Return these in *REVPROPS, allocated from RESULT_POOL. */
1239
svn_ra_serf__select_revprops(apr_hash_t **revprops,
1242
apr_hash_t *all_revprops,
1243
apr_pool_t *result_pool,
1244
apr_pool_t *scratch_pool);
1247
/* PROPS is nested hash tables mapping NS -> NAME -> VALUE.
1248
This function takes the NS:NAME:VALUE hashes and flattens them into a set of
1249
names to VALUE. The names are composed of NS:NAME, with specific
1250
rewrite from wire names (DAV) to SVN names. This mapping is managed
1251
by the svn_ra_serf__set_baton_props() function.
1253
FLAT_PROPS is allocated in RESULT_POOL.
1254
### right now, we do a shallow copy from PROPS to FLAT_PROPS. therefore,
1255
### the names and values in PROPS must be in the proper pool.
1257
Temporary allocations are made in SCRATCH_POOL. */
1259
svn_ra_serf__flatten_props(apr_hash_t **flat_props,
1261
apr_pool_t *result_pool,
1262
apr_pool_t *scratch_pool);
1265
/* Return the property value for PATH at REV revision with a NS:NAME.
1266
* PROPS is a four-level nested hash: (svn_revnum_t => char *path =>
1267
* char *ns => char *name => svn_string_t *). */
1268
const svn_string_t *
1269
svn_ra_serf__get_ver_prop_string(apr_hash_t *props,
1270
const char *path, svn_revnum_t rev,
1271
const char *ns, const char *name);
1273
/* Same as svn_ra_serf__get_ver_prop_string(), but returns a C string. */
1275
svn_ra_serf__get_ver_prop(apr_hash_t *props,
1276
const char *path, svn_revnum_t rev,
1277
const char *ns, const char *name);
1279
/* Same as svn_ra_serf__get_ver_prop_string(), but for the unknown revision. */
1280
const svn_string_t *
1281
svn_ra_serf__get_prop_string(apr_hash_t *props,
1286
/* Same as svn_ra_serf__get_ver_prop(), but for the unknown revision. */
1288
svn_ra_serf__get_prop(apr_hash_t *props,
1293
/* Same as svn_ra_serf__set_rev_prop(), but for the unknown revision. */
1295
svn_ra_serf__set_prop(apr_hash_t *props, const char *path,
1296
const char *ns, const char *name,
1297
const svn_string_t *val, apr_pool_t *pool);
1300
svn_ra_serf__get_resource_type(svn_node_kind_t *kind,
1304
1023
/** MERGE-related functions **/
1307
svn_ra_serf__merge_lock_token_list(apr_hash_t *lock_tokens,
1309
serf_bucket_t *body,
1310
serf_bucket_alloc_t *alloc,
1313
1025
/* Create an MERGE request aimed at the SESSION url, requesting the
1314
1026
merge of the resource identified by MERGE_RESOURCE_URL.
1315
1027
LOCK_TOKENS is a hash mapping paths to lock tokens owned by the
1362
1072
All temporary allocations will be made in SCRATCH_POOL. */
1364
1074
svn_ra_serf__v1_get_activity_collection(const char **activity_url,
1365
svn_ra_serf__connection_t *conn,
1075
svn_ra_serf__session_t *session,
1366
1076
apr_pool_t *result_pool,
1367
1077
apr_pool_t *scratch_pool);
1370
1080
/* Set @a VCC_URL to the default VCC for our repository based on @a
1371
1081
* ORIG_PATH for the session @a SESSION, ensuring that the VCC URL and
1372
* repository root URLs are cached in @a SESSION. Use @a CONN for any
1373
* required network communications if it is non-NULL; otherwise use the
1374
* default connection.
1082
* repository root URLs are cached in @a SESSION.
1376
* All temporary allocations will be made in @a POOL. */
1084
* All temporary allocations will be made in @a SCRATCH_POOL. */
1378
1086
svn_ra_serf__discover_vcc(const char **vcc_url,
1379
1087
svn_ra_serf__session_t *session,
1380
svn_ra_serf__connection_t *conn,
1088
apr_pool_t *scratch_pool);
1383
1090
/* Set @a REPORT_TARGET to the URI of the resource at which generic
1384
* (path-agnostic) REPORTs should be aimed for @a SESSION. Use @a
1385
* CONN for any required network communications if it is non-NULL;
1386
* otherwise use the default connection.
1091
* (path-agnostic) REPORTs should be aimed for @a SESSION.
1388
1093
* All temporary allocations will be made in @a POOL.
1391
1096
svn_ra_serf__report_resource(const char **report_target,
1392
1097
svn_ra_serf__session_t *session,
1393
svn_ra_serf__connection_t *conn,
1394
1098
apr_pool_t *pool);
1396
1100
/* Set @a REL_PATH to a path (not URI-encoded) relative to the root of