util.c (251886) | util.c (253734) |
---|---|
1/* 2 * util.c : serf utility routines for ra_serf 3 * 4 * ==================================================================== 5 * Licensed to the Apache Software Foundation (ASF) under one 6 * or more contributor license agreements. See the NOTICE file 7 * distributed with this work for additional information 8 * regarding copyright ownership. The ASF licenses this file --- 359 unchanged lines hidden (view full) --- 368 { 369 /* input stream */ 370 *read_bkt = serf_bucket_ssl_decrypt_create(*read_bkt, conn->ssl_context, 371 conn->bkt_alloc); 372 if (!conn->ssl_context) 373 { 374 conn->ssl_context = serf_bucket_ssl_encrypt_context_get(*read_bkt); 375 | 1/* 2 * util.c : serf utility routines for ra_serf 3 * 4 * ==================================================================== 5 * Licensed to the Apache Software Foundation (ASF) under one 6 * or more contributor license agreements. See the NOTICE file 7 * distributed with this work for additional information 8 * regarding copyright ownership. The ASF licenses this file --- 359 unchanged lines hidden (view full) --- 368 { 369 /* input stream */ 370 *read_bkt = serf_bucket_ssl_decrypt_create(*read_bkt, conn->ssl_context, 371 conn->bkt_alloc); 372 if (!conn->ssl_context) 373 { 374 conn->ssl_context = serf_bucket_ssl_encrypt_context_get(*read_bkt); 375 |
376#if SERF_VERSION_AT_LEAST(1,0,0) | |
377 serf_ssl_set_hostname(conn->ssl_context, 378 conn->session->session_url.hostname); | 376 serf_ssl_set_hostname(conn->ssl_context, 377 conn->session->session_url.hostname); |
379#endif | |
380 381 serf_ssl_client_cert_provider_set(conn->ssl_context, 382 svn_ra_serf__handle_client_cert, 383 conn, conn->session->pool); 384 serf_ssl_client_cert_password_set(conn->ssl_context, 385 svn_ra_serf__handle_client_cert_pw, 386 conn, conn->session->pool); 387 serf_ssl_server_cert_callback_set(conn->ssl_context, --- 84 unchanged lines hidden (view full) --- 472 473static svn_error_t * 474connection_closed(svn_ra_serf__connection_t *conn, 475 apr_status_t why, 476 apr_pool_t *pool) 477{ 478 if (why) 479 { | 378 379 serf_ssl_client_cert_provider_set(conn->ssl_context, 380 svn_ra_serf__handle_client_cert, 381 conn, conn->session->pool); 382 serf_ssl_client_cert_password_set(conn->ssl_context, 383 svn_ra_serf__handle_client_cert_pw, 384 conn, conn->session->pool); 385 serf_ssl_server_cert_callback_set(conn->ssl_context, --- 84 unchanged lines hidden (view full) --- 470 471static svn_error_t * 472connection_closed(svn_ra_serf__connection_t *conn, 473 apr_status_t why, 474 apr_pool_t *pool) 475{ 476 if (why) 477 { |
480 SVN_ERR_MALFUNCTION(); | 478 return svn_error_wrap_apr(why, NULL); |
481 } 482 483 if (conn->session->using_ssl) 484 conn->ssl_context = NULL; 485 486 return SVN_NO_ERROR; 487} 488 --- 148 unchanged lines hidden (view full) --- 637 const char *method, const char *url, 638 serf_bucket_t *body_bkt, const char *content_type, 639 const char *accept_encoding, 640 apr_pool_t *request_pool, 641 apr_pool_t *scratch_pool) 642{ 643 serf_bucket_alloc_t *allocator = serf_request_get_alloc(request); 644 | 479 } 480 481 if (conn->session->using_ssl) 482 conn->ssl_context = NULL; 483 484 return SVN_NO_ERROR; 485} 486 --- 148 unchanged lines hidden (view full) --- 635 const char *method, const char *url, 636 serf_bucket_t *body_bkt, const char *content_type, 637 const char *accept_encoding, 638 apr_pool_t *request_pool, 639 apr_pool_t *scratch_pool) 640{ 641 serf_bucket_alloc_t *allocator = serf_request_get_alloc(request); 642 |
645#if SERF_VERSION_AT_LEAST(1, 1, 0) | |
646 svn_spillbuf_t *buf; | 643 svn_spillbuf_t *buf; |
644 svn_boolean_t set_CL = session->http10 || !session->using_chunked_requests; |
|
647 | 645 |
648 if (session->http10 && body_bkt != NULL) | 646 if (set_CL && body_bkt != NULL) |
649 { 650 /* Ugh. Use HTTP/1.0 to talk to the server because we don't know if 651 it speaks HTTP/1.1 (and thus, chunked requests), or because the 652 server actually responded as only supporting HTTP/1.0. 653 654 We'll take the existing body_bkt, spool it into a spillbuf, and 655 then wrap a bucket around that spillbuf. The spillbuf will give 656 us the Content-Length value. */ 657 SVN_ERR(svn_ra_serf__copy_into_spillbuf(&buf, body_bkt, 658 request_pool, 659 scratch_pool)); 660 /* Destroy original bucket since it content is already copied 661 to spillbuf. */ 662 serf_bucket_destroy(body_bkt); 663 664 body_bkt = svn_ra_serf__create_sb_bucket(buf, allocator, 665 request_pool, 666 scratch_pool); 667 } | 647 { 648 /* Ugh. Use HTTP/1.0 to talk to the server because we don't know if 649 it speaks HTTP/1.1 (and thus, chunked requests), or because the 650 server actually responded as only supporting HTTP/1.0. 651 652 We'll take the existing body_bkt, spool it into a spillbuf, and 653 then wrap a bucket around that spillbuf. The spillbuf will give 654 us the Content-Length value. */ 655 SVN_ERR(svn_ra_serf__copy_into_spillbuf(&buf, body_bkt, 656 request_pool, 657 scratch_pool)); 658 /* Destroy original bucket since it content is already copied 659 to spillbuf. */ 660 serf_bucket_destroy(body_bkt); 661 662 body_bkt = svn_ra_serf__create_sb_bucket(buf, allocator, 663 request_pool, 664 scratch_pool); 665 } |
668#endif | |
669 670 /* Create a request bucket. Note that this sucker is kind enough to 671 add a "Host" header for us. */ 672 *req_bkt = serf_request_bucket_request_create(request, method, url, 673 body_bkt, allocator); 674 675 /* Set the Content-Length value. This will also trigger an HTTP/1.0 676 request (rather than the default chunked request). */ | 666 667 /* Create a request bucket. Note that this sucker is kind enough to 668 add a "Host" header for us. */ 669 *req_bkt = serf_request_bucket_request_create(request, method, url, 670 body_bkt, allocator); 671 672 /* Set the Content-Length value. This will also trigger an HTTP/1.0 673 request (rather than the default chunked request). */ |
677#if SERF_VERSION_AT_LEAST(1, 1, 0) 678 if (session->http10) | 674 if (set_CL) |
679 { 680 if (body_bkt == NULL) 681 serf_bucket_request_set_CL(*req_bkt, 0); 682 else 683 serf_bucket_request_set_CL(*req_bkt, svn_spillbuf__get_size(buf)); 684 } | 675 { 676 if (body_bkt == NULL) 677 serf_bucket_request_set_CL(*req_bkt, 0); 678 else 679 serf_bucket_request_set_CL(*req_bkt, svn_spillbuf__get_size(buf)); 680 } |
685#endif | |
686 687 *hdrs_bkt = serf_bucket_request_get_headers(*req_bkt); 688 689 /* We use serf_bucket_headers_setn() because the USERAGENT has a 690 lifetime longer than this bucket. Thus, there is no need to copy 691 the header values. */ 692 serf_bucket_headers_setn(*hdrs_bkt, "User-Agent", session->useragent); 693 694 if (content_type) 695 { 696 serf_bucket_headers_setn(*hdrs_bkt, "Content-Type", content_type); 697 } 698 | 681 682 *hdrs_bkt = serf_bucket_request_get_headers(*req_bkt); 683 684 /* We use serf_bucket_headers_setn() because the USERAGENT has a 685 lifetime longer than this bucket. Thus, there is no need to copy 686 the header values. */ 687 serf_bucket_headers_setn(*hdrs_bkt, "User-Agent", session->useragent); 688 689 if (content_type) 690 { 691 serf_bucket_headers_setn(*hdrs_bkt, "Content-Type", content_type); 692 } 693 |
699#if SERF_VERSION_AT_LEAST(1, 1, 0) | |
700 if (session->http10) | 694 if (session->http10) |
695 { |
|
701 serf_bucket_headers_setn(*hdrs_bkt, "Connection", "keep-alive"); | 696 serf_bucket_headers_setn(*hdrs_bkt, "Connection", "keep-alive"); |
702#endif | 697 } |
703 704 if (accept_encoding) 705 { 706 serf_bucket_headers_setn(*hdrs_bkt, "Accept-Encoding", accept_encoding); 707 } 708 709 /* These headers need to be sent with every request; see issue #3255 710 ("mod_dav_svn does not pass client capabilities to start-commit --- 1674 unchanged lines hidden (view full) --- 2385 /* Otherwise, we'll use the default VCC. */ 2386 else 2387 SVN_ERR(svn_ra_serf__discover_vcc(report_target, session, conn, pool)); 2388 2389 return SVN_NO_ERROR; 2390} 2391 2392svn_error_t * | 698 699 if (accept_encoding) 700 { 701 serf_bucket_headers_setn(*hdrs_bkt, "Accept-Encoding", accept_encoding); 702 } 703 704 /* These headers need to be sent with every request; see issue #3255 705 ("mod_dav_svn does not pass client capabilities to start-commit --- 1674 unchanged lines hidden (view full) --- 2380 /* Otherwise, we'll use the default VCC. */ 2381 else 2382 SVN_ERR(svn_ra_serf__discover_vcc(report_target, session, conn, pool)); 2383 2384 return SVN_NO_ERROR; 2385} 2386 2387svn_error_t * |
2393svn_ra_serf__error_on_status(int status_code, | 2388svn_ra_serf__error_on_status(serf_status_line sline, |
2394 const char *path, 2395 const char *location) 2396{ | 2389 const char *path, 2390 const char *location) 2391{ |
2397 switch(status_code) | 2392 switch(sline.code) |
2398 { 2399 case 301: 2400 case 302: 2401 case 307: 2402 return svn_error_createf(SVN_ERR_RA_DAV_RELOCATED, NULL, | 2393 { 2394 case 301: 2395 case 302: 2396 case 307: 2397 return svn_error_createf(SVN_ERR_RA_DAV_RELOCATED, NULL, |
2403 (status_code == 301) | 2398 (sline.code == 301) |
2404 ? _("Repository moved permanently to '%s';" 2405 " please relocate") 2406 : _("Repository moved temporarily to '%s';" 2407 " please relocate"), location); 2408 case 403: 2409 return svn_error_createf(SVN_ERR_RA_DAV_FORBIDDEN, NULL, 2410 _("Access to '%s' forbidden"), path); 2411 2412 case 404: 2413 return svn_error_createf(SVN_ERR_FS_NOT_FOUND, NULL, 2414 _("'%s' path not found"), path); 2415 case 423: 2416 return svn_error_createf(SVN_ERR_FS_NO_LOCK_TOKEN, NULL, 2417 _("'%s': no lock token available"), path); | 2399 ? _("Repository moved permanently to '%s';" 2400 " please relocate") 2401 : _("Repository moved temporarily to '%s';" 2402 " please relocate"), location); 2403 case 403: 2404 return svn_error_createf(SVN_ERR_RA_DAV_FORBIDDEN, NULL, 2405 _("Access to '%s' forbidden"), path); 2406 2407 case 404: 2408 return svn_error_createf(SVN_ERR_FS_NOT_FOUND, NULL, 2409 _("'%s' path not found"), path); 2410 case 423: 2411 return svn_error_createf(SVN_ERR_FS_NO_LOCK_TOKEN, NULL, 2412 _("'%s': no lock token available"), path); |
2413 2414 case 411: 2415 return svn_error_createf(SVN_ERR_RA_DAV_REQUEST_FAILED, NULL, 2416 _("DAV request failed: 411 Content length required. The " 2417 "server or an intermediate proxy does not accept " 2418 "chunked encoding. Try setting 'http-chunked-requests' " 2419 "to 'auto' or 'no' in your client configuration.")); |
|
2418 } 2419 | 2420 } 2421 |
2422 if (sline.code >= 300) 2423 return svn_error_createf(SVN_ERR_RA_DAV_REQUEST_FAILED, NULL, 2424 _("Unexpected HTTP status %d '%s' on '%s'\n"), 2425 sline.code, sline.reason, path); 2426 |
|
2420 return SVN_NO_ERROR; 2421} 2422 2423svn_error_t * 2424svn_ra_serf__register_editor_shim_callbacks(svn_ra_session_t *ra_session, 2425 svn_delta_shim_callbacks_t *callbacks) 2426{ 2427 svn_ra_serf__session_t *session = ra_session->priv; --- 187 unchanged lines hidden --- | 2427 return SVN_NO_ERROR; 2428} 2429 2430svn_error_t * 2431svn_ra_serf__register_editor_shim_callbacks(svn_ra_session_t *ra_session, 2432 svn_delta_shim_callbacks_t *callbacks) 2433{ 2434 svn_ra_serf__session_t *session = ra_session->priv; --- 187 unchanged lines hidden --- |