diff --git a/rust/rust_project/src/http_aws_sigv4.rs b/rust/rust_project/src/http_aws_sigv4.rs index 38149147b24cdbf7da86fbfcefdfbe957df8424c..a5f7670476618c50b5c85379943bd3b76af12bc1 100644 --- a/rust/rust_project/src/http_aws_sigv4.rs +++ b/rust/rust_project/src/http_aws_sigv4.rs @@ -18,11 +18,11 @@ use rust_ffi::src::ffi_struct::struct_define::*; extern "C" fn sha256_to_hex(mut dst: *mut libc::c_char, mut sha: *mut u8, mut dst_l: size_t) { - unsafe { let mut i: i32 = 0; #[cfg(all(DEBUGBUILD, HAVE_ASSERT_H))] if dst_l >= 65 as libc::c_int as u64 { } else { + unsafe{ __assert_fail( b"dst_l >= 65\0" as *const u8 as *const libc::c_char, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, @@ -31,26 +31,25 @@ b"void sha256_to_hex(char *, unsigned char *, size_t)\0", )) .as_ptr(), - ); + );} } i = 0 as i32; while i < 32 as i32 { + unsafe{ curl_msnprintf( dst.offset((i * 2 as i32) as isize), dst_l.wrapping_sub((i * 2 as i32) as u64), b"%02x\0" as *const u8 as *const libc::c_char, *sha.offset(i as isize) as i32, - ); + );} i += 1; } - } } #[no_mangle] pub extern "C" fn Curl_output_aws_sigv4(mut data: *mut Curl_easy, mut proxy: bool) -> CURLcode { - unsafe { let mut current_block: u64; let mut ret: CURLcode = CURLE_OUT_OF_MEMORY; - let mut conn: *mut connectdata = (*data).conn; + let mut conn: *mut connectdata = unsafe{(*data).conn}; let mut len: size_t = 0; let mut tmp0: *const libc::c_char = 0 as *const libc::c_char; let mut tmp1: *const libc::c_char = 0 as *const libc::c_char; @@ -60,7 +59,7 @@ let mut provider1_mid: *mut libc::c_char = 0 as *mut libc::c_char; let mut region: *mut libc::c_char = 0 as *mut libc::c_char; let mut service: *mut libc::c_char = 0 as *mut libc::c_char; - let mut hostname: *const libc::c_char = (*conn).host.name; + let mut hostname: *const libc::c_char =unsafe{ (*conn).host.name}; #[cfg(DEBUGBUILD)] let mut force_timestamp: *mut libc::c_char = 0 as *mut libc::c_char; let mut clock: time_t = 0; @@ -79,14 +78,15 @@ }; let mut timestamp: [libc::c_char; 17] = [0; 17]; let mut date: [libc::c_char; 9] = [0; 9]; - let mut content_type: *const libc::c_char = - Curl_checkheaders(data, b"Content-Type\0" as *const u8 as *const libc::c_char); + let mut content_type: *const libc::c_char =unsafe{ + Curl_checkheaders(data, b"Content-Type\0" as *const u8 as *const libc::c_char)}; let mut canonical_headers: *mut libc::c_char = 0 as *mut libc::c_char; let mut signed_headers: *mut libc::c_char = 0 as *mut libc::c_char; let mut httpreq: Curl_HttpReq = HTTPREQ_GET; let mut method: *const libc::c_char = 0 as *const libc::c_char; - let mut post_data: *const libc::c_char = (if !((*data).set.postfields).is_null() { - (*data).set.postfields + let mut post_data: *const libc::c_char = (if unsafe{!((*data).set.postfields).is_null() }{ + unsafe{ + (*data).set.postfields} } else { b"\0" as *const u8 as *const libc::c_char as *const libc::c_void }) as *const libc::c_char; @@ -96,13 +96,13 @@ let mut request_type: *mut libc::c_char = 0 as *mut libc::c_char; let mut credential_scope: *mut libc::c_char = 0 as *mut libc::c_char; let mut str_to_sign: *mut libc::c_char = 0 as *mut libc::c_char; - let mut user: *const libc::c_char = if !((*data).state.aptr.user).is_null() { - (*data).state.aptr.user as *const libc::c_char + let mut user: *const libc::c_char = if unsafe{!((*data).state.aptr.user).is_null()} { + unsafe{(*data).state.aptr.user as *const libc::c_char} } else { b"\0" as *const u8 as *const libc::c_char }; - let mut passwd: *const libc::c_char = if !((*data).state.aptr.passwd).is_null() { - (*data).state.aptr.passwd as *const libc::c_char + let mut passwd: *const libc::c_char = if unsafe{!((*data).state.aptr.passwd).is_null()} { + unsafe{(*data).state.aptr.passwd as *const libc::c_char} } else { b"\0" as *const u8 as *const libc::c_char }; @@ -119,6 +119,7 @@ #[cfg(all(DEBUGBUILD, HAVE_ASSERT_H))] if !proxy { } else { + unsafe{ __assert_fail( b"!proxy\0" as *const u8 as *const libc::c_char, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, @@ -127,10 +128,10 @@ b"CURLcode Curl_output_aws_sigv4(struct Curl_easy *, _Bool)\0", )) .as_ptr(), - ); + );} } - if !(Curl_checkheaders(data, b"Authorization\0" as *const u8 as *const libc::c_char)) - .is_null() + if unsafe{!(Curl_checkheaders(data, b"Authorization\0" as *const u8 as *const libc::c_char)) + .is_null()} { /* Authorization already present, Bailing out */ return CURLE_OK; @@ -142,214 +143,220 @@ * AWS is the default because most of non-amazon providers * are still using aws:amz as a prefix. */ - tmp0 = if !((*data).set.str_0[STRING_AWS_SIGV4 as usize]).is_null() { - (*data).set.str_0[STRING_AWS_SIGV4 as usize] as *const libc::c_char + tmp0 = if unsafe{ !((*data).set.str_0[STRING_AWS_SIGV4 as usize]).is_null()} { + unsafe{(*data).set.str_0[STRING_AWS_SIGV4 as usize] as *const libc::c_char} } else { b"aws:amz\0" as *const u8 as *const libc::c_char }; - tmp1 = strchr(tmp0, ':' as i32); + tmp1 = unsafe{strchr(tmp0, ':' as i32)}; len = if !tmp1.is_null() { - tmp1.offset_from(tmp0) as size_t + unsafe{ + tmp1.offset_from(tmp0) as size_t} } else { - strlen(tmp0) + unsafe{ strlen(tmp0)} }; 'fail: loop { if len < 1 as i32 as u64 { + unsafe{ Curl_infof( data, b"first provider can't be empty\0" as *const u8 as *const libc::c_char, - ); + );} ret = CURLE_BAD_FUNCTION_ARGUMENT; break 'fail; } match () { #[cfg(not(CURLDEBUG))] _ => { - provider0_low = Curl_cmalloc.expect("non-null function pointer")( + provider0_low = unsafe{ Curl_cmalloc.expect("non-null function pointer")( len.wrapping_add(1 as u64), - ) as *mut libc::c_char; - provider0_up = Curl_cmalloc.expect("non-null function pointer")( + ) as *mut libc::c_char}; + provider0_up = unsafe{Curl_cmalloc.expect("non-null function pointer")( len.wrapping_add(1 as u64), - ) as *mut libc::c_char; + ) as *mut libc::c_char}; } #[cfg(CURLDEBUG)] _ => { - provider0_low = curl_dbg_malloc( + provider0_low = unsafe{curl_dbg_malloc( len.wrapping_add(1 as u64), 133, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, - ) as *mut libc::c_char; - provider0_up = curl_dbg_malloc( + ) as *mut libc::c_char}; + provider0_up = unsafe{curl_dbg_malloc( len.wrapping_add(1 as u64), 134, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, - ) as *mut libc::c_char; + ) as *mut libc::c_char}; } } if provider0_low.is_null() || provider0_up.is_null() { break 'fail; } - Curl_strntolower(provider0_low, tmp0, len); + unsafe{Curl_strntolower(provider0_low, tmp0, len); *provider0_low.offset(len as isize) = '\u{0}' as libc::c_char; Curl_strntoupper(provider0_up, tmp0, len); - *provider0_up.offset(len as isize) = '\u{0}' as libc::c_char; + *provider0_up.offset(len as isize) = '\u{0}' as libc::c_char;} if !tmp1.is_null() { - tmp0 = tmp1.offset(1 as isize); - tmp1 = strchr(tmp0, ':' as i32); + tmp0 = unsafe{tmp1.offset(1 as isize)}; + tmp1 = unsafe{strchr(tmp0, ':' as i32)}; len = if !tmp1.is_null() { - tmp1.offset_from(tmp0) as size_t + unsafe{tmp1.offset_from(tmp0) as size_t} } else { - strlen(tmp0) + unsafe{strlen(tmp0)} }; if len < 1 as u64 { + unsafe{ Curl_infof( data, b"second provider can't be empty\0" as *const u8 as *const libc::c_char, - ); + );} ret = CURLE_BAD_FUNCTION_ARGUMENT; break 'fail; } match () { #[cfg(not(CURLDEBUG))] _ => { - provider1_low = + provider1_low =unsafe{ Curl_cmalloc.expect("non-null function pointer")(len.wrapping_add(1 as u64)) - as *mut libc::c_char; - provider1_mid = + as *mut libc::c_char}; + provider1_mid =unsafe{ Curl_cmalloc.expect("non-null function pointer")(len.wrapping_add(1 as u64)) - as *mut libc::c_char; + as *mut libc::c_char}; } #[cfg(CURLDEBUG)] _ => { - provider1_low = curl_dbg_malloc( + provider1_low = unsafe{curl_dbg_malloc( len.wrapping_add(1 as libc::c_int as libc::c_ulong), 152 as libc::c_int, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, - ) as *mut libc::c_char; - provider1_mid = curl_dbg_malloc( + ) as *mut libc::c_char}; + provider1_mid = unsafe{curl_dbg_malloc( len.wrapping_add(1 as libc::c_int as libc::c_ulong), 153 as libc::c_int, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, - ) as *mut libc::c_char; + ) as *mut libc::c_char}; } } if provider1_low.is_null() || provider1_mid.is_null() { break 'fail; } - Curl_strntolower(provider1_low, tmp0, len); + unsafe{Curl_strntolower(provider1_low, tmp0, len); *provider1_low.offset(len as isize) = '\u{0}' as libc::c_char; Curl_strntolower(provider1_mid, tmp0, len); *provider1_mid.offset(0 as isize) = Curl_raw_toupper(*provider1_mid.offset(0 as isize)); - *provider1_mid.offset(len as isize) = '\u{0}' as libc::c_char; + *provider1_mid.offset(len as isize) = '\u{0}' as libc::c_char;} if !tmp1.is_null() { - tmp0 = tmp1.offset(1 as isize); - tmp1 = strchr(tmp0, ':' as i32); + tmp0 = unsafe{tmp1.offset(1 as isize)}; + tmp1 = unsafe{strchr(tmp0, ':' as i32)}; len = if !tmp1.is_null() { - tmp1.offset_from(tmp0) as size_t + unsafe{tmp1.offset_from(tmp0) as size_t} } else { - strlen(tmp0) + unsafe{strlen(tmp0)} }; if len < 1 as u64 { - Curl_infof( + unsafe{Curl_infof( data, b"region can't be empty\0" as *const u8 as *const libc::c_char, - ); + );} ret = CURLE_BAD_FUNCTION_ARGUMENT; break 'fail; } - region = Curl_memdup(tmp0 as *const libc::c_void, len.wrapping_add(1 as u64)) - as *mut libc::c_char; + region = unsafe{Curl_memdup(tmp0 as *const libc::c_void, len.wrapping_add(1 as u64)) + as *mut libc::c_char}; if region.is_null() { break 'fail; } - *region.offset(len as isize) = '\u{0}' as libc::c_char; + unsafe{*region.offset(len as isize) = '\u{0}' as libc::c_char;} if !tmp1.is_null() { - tmp0 = tmp1.offset(1 as isize); + tmp0 = unsafe{tmp1.offset(1 as isize)}; #[cfg(not(CURLDEBUG))] let mut new_service: *mut libc::c_char = - Curl_cstrdup.expect("non-null function pointer")(tmp0); + unsafe{Curl_cstrdup.expect("non-null function pointer")(tmp0)}; #[cfg(CURLDEBUG)] - let mut new_service: *mut libc::c_char = curl_dbg_strdup( + let mut new_service: *mut libc::c_char = unsafe{curl_dbg_strdup( tmp0, 180, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, - ); + )}; service = new_service; if service.is_null() { break 'fail; } - if strlen(service) < 1 as u64 { + if unsafe{strlen(service)} < 1 as u64 { + unsafe{ Curl_infof( data, b"service can't be empty\0" as *const u8 as *const libc::c_char, - ); + );} ret = CURLE_BAD_FUNCTION_ARGUMENT; break 'fail; } } } } else { - provider1_low = Curl_memdup( + provider1_low =unsafe{Curl_memdup( provider0_low as *const libc::c_void, len.wrapping_add(1 as u64), - ) as *mut libc::c_char; - provider1_mid = Curl_memdup( + ) as *mut libc::c_char}; + provider1_mid = unsafe{Curl_memdup( provider0_low as *const libc::c_void, len.wrapping_add(1 as u64), - ) as *mut libc::c_char; + ) as *mut libc::c_char}; if provider1_low.is_null() || provider1_mid.is_null() { break 'fail; } - *provider1_mid.offset(0 as isize) = - Curl_raw_toupper(*provider1_mid.offset(0 as isize)); + unsafe{*provider1_mid.offset(0 as isize) = + Curl_raw_toupper(*provider1_mid.offset(0 as isize));} } if service.is_null() { tmp0 = hostname; - tmp1 = strchr(tmp0, '.' as i32); - len = tmp1.offset_from(tmp0) as size_t; + tmp1 = unsafe{strchr(tmp0, '.' as i32)}; + len = unsafe{tmp1.offset_from(tmp0) as size_t}; if tmp1.is_null() || len < 1 as u64 { - Curl_infof( + unsafe{Curl_infof( data, b"service missing in parameters or hostname\0" as *const u8 as *const libc::c_char, - ); + );} ret = CURLE_URL_MALFORMAT; break 'fail; } - service = Curl_memdup(tmp0 as *const libc::c_void, len.wrapping_add(1 as u64)) - as *mut libc::c_char; + service = unsafe{Curl_memdup(tmp0 as *const libc::c_void, len.wrapping_add(1 as u64)) + as *mut libc::c_char}; if service.is_null() { break 'fail; } - *service.offset(len as isize) = '\u{0}' as libc::c_char; + unsafe{*service.offset(len as isize) = '\u{0}' as libc::c_char;} if region.is_null() { - tmp0 = tmp1.offset(1 as isize); - tmp1 = strchr(tmp0, '.' as i32); - len = tmp1.offset_from(tmp0) as size_t; + tmp0 = unsafe{tmp1.offset(1 as isize)}; + tmp1 = unsafe{strchr(tmp0, '.' as i32)}; + len = unsafe{tmp1.offset_from(tmp0) as size_t}; if tmp1.is_null() || len < 1 as u64 { + unsafe{ Curl_infof( data, b"region missing in parameters or hostname\0" as *const u8 as *const libc::c_char, - ); + );} ret = CURLE_URL_MALFORMAT; break 'fail; } - region = Curl_memdup(tmp0 as *const libc::c_void, len.wrapping_add(1 as u64)) - as *mut libc::c_char; + region = unsafe{Curl_memdup(tmp0 as *const libc::c_void, len.wrapping_add(1 as u64)) + as *mut libc::c_char}; if region.is_null() { break 'fail; } - *region.offset(len as isize) = '\u{0}' as libc::c_char; + unsafe{*region.offset(len as isize) = '\u{0}' as libc::c_char;} } } + unsafe{ match () { #[cfg(CURLDEBUG)] _ => { force_timestamp = - getenv(b"CURL_FORCETIME\0" as *const u8 as *const libc::c_char); + getenv(b"CURL_FORCETIME\0" as *const u8 as *const libc::c_char); if !force_timestamp.is_null() { clock = 0 as time_t; } else { @@ -361,75 +368,76 @@ time(&mut clock); } } - ret = Curl_gmtime(clock, &mut tm); + } + ret = unsafe{Curl_gmtime(clock, &mut tm)}; if ret as u32 != CURLE_OK as u32 { break 'fail; } - if strftime( + if unsafe{strftime( timestamp.as_mut_ptr(), ::std::mem::size_of::<[libc::c_char; 17]>() as u64, b"%Y%m%dT%H%M%SZ\0" as *const u8 as *const libc::c_char, &mut tm, - ) == 0 + )} == 0 { break 'fail; } - memcpy( + unsafe{memcpy( date.as_mut_ptr() as *mut libc::c_void, timestamp.as_mut_ptr() as *const libc::c_void, ::std::mem::size_of::<[libc::c_char; 9]>() as u64, - ); + );} date[(::std::mem::size_of::<[libc::c_char; 9]>() as u64).wrapping_sub(1 as u64) as usize] = 0 as libc::c_char; if !content_type.is_null() { - content_type = strchr(content_type, ':' as i32); + content_type =unsafe{ strchr(content_type, ':' as i32)}; if content_type.is_null() { ret = CURLE_FAILED_INIT; break 'fail; } - content_type = content_type.offset(1); - while *content_type as i32 == ' ' as i32 || *content_type as i32 == '\t' as i32 { - content_type = content_type.offset(1); + content_type = unsafe{content_type.offset(1)}; + while unsafe{*content_type as i32} == ' ' as i32 || unsafe{*content_type as i32} == '\t' as i32 { + content_type = unsafe{content_type.offset(1)}; } - canonical_headers = curl_maprintf( + canonical_headers = unsafe{curl_maprintf( b"content-type:%s\nhost:%s\nx-%s-date:%s\n\0" as *const u8 as *const libc::c_char, content_type, hostname, provider1_low, timestamp.as_mut_ptr(), - ); - signed_headers = curl_maprintf( + )}; + signed_headers = unsafe{curl_maprintf( b"content-type;host;x-%s-date\0" as *const u8 as *const libc::c_char, provider1_low, - ); + )}; } else { - canonical_headers = curl_maprintf( + canonical_headers = unsafe{curl_maprintf( b"host:%s\nx-%s-date:%s\n\0" as *const u8 as *const libc::c_char, hostname, provider1_low, timestamp.as_mut_ptr(), - ); - signed_headers = curl_maprintf( + )}; + signed_headers = unsafe{curl_maprintf( b"host;x-%s-date\0" as *const u8 as *const libc::c_char, provider1_low, - ); + )}; } if canonical_headers.is_null() || signed_headers.is_null() { break 'fail; } - Curl_sha256it( + unsafe{Curl_sha256it( sha_hash.as_mut_ptr(), post_data as *const u8, strlen(post_data), - ); + );} sha256_to_hex( sha_hex.as_mut_ptr(), sha_hash.as_mut_ptr(), ::std::mem::size_of::<[libc::c_char; 65]>() as u64, ); - Curl_http_method(data, conn, &mut method, &mut httpreq); - canonical_request = curl_maprintf( + unsafe{Curl_http_method(data, conn, &mut method, &mut httpreq);} + canonical_request =unsafe{ curl_maprintf( b"%s\n%s\n%s\n%s\n%s\n%s\0" as *const u8 as *const libc::c_char, method, (*data).state.up.path, @@ -441,32 +449,32 @@ canonical_headers, signed_headers, sha_hex.as_mut_ptr(), - ); + )}; if canonical_request.is_null() { break 'fail; } - request_type = curl_maprintf( + request_type = unsafe{curl_maprintf( b"%s4_request\0" as *const u8 as *const libc::c_char, provider0_low, - ); + )}; if request_type.is_null() { break 'fail; } - credential_scope = curl_maprintf( + credential_scope = unsafe{curl_maprintf( b"%s/%s/%s/%s\0" as *const u8 as *const libc::c_char, date.as_mut_ptr(), region, service, request_type, - ); + )}; if credential_scope.is_null() { break 'fail; } - Curl_sha256it( + unsafe{Curl_sha256it( sha_hash.as_mut_ptr(), canonical_request as *mut u8, strlen(canonical_request), - ); + );} sha256_to_hex( sha_hex.as_mut_ptr(), sha_hash.as_mut_ptr(), @@ -476,76 +484,76 @@ * Google allow to use rsa key instead of HMAC, so this code might change * In the furure, but for now we support only HMAC version */ - str_to_sign = curl_maprintf( + str_to_sign =unsafe{ curl_maprintf( b"%s4-HMAC-SHA256\n%s\n%s\n%s\0" as *const u8 as *const libc::c_char, provider0_up, timestamp.as_mut_ptr(), credential_scope, sha_hex.as_mut_ptr(), - ); + )}; if str_to_sign.is_null() { break 'fail; } - secret = curl_maprintf( + secret = unsafe{curl_maprintf( b"%s4%s\0" as *const u8 as *const libc::c_char, provider0_up, passwd, - ); + )}; if secret.is_null() { break 'fail; } - ret = Curl_hmacit( + ret = unsafe{Curl_hmacit( Curl_HMAC_SHA256.as_ptr(), secret as *mut u8, strlen(secret) as size_t, date.as_mut_ptr() as *mut u8, strlen(date.as_mut_ptr()) as size_t, tmp_sign0.as_mut_ptr(), - ); + )}; if ret as u32 != CURLE_OK as u32 { break 'fail; } - ret = Curl_hmacit( + ret = unsafe{Curl_hmacit( Curl_HMAC_SHA256.as_ptr(), tmp_sign0.as_mut_ptr(), ::std::mem::size_of::<[u8; 32]>() as u32 as size_t, region as *mut u8, strlen(region) as size_t, tmp_sign1.as_mut_ptr(), - ); + )}; if ret as u32 != CURLE_OK as u32 { break 'fail; } - ret = Curl_hmacit( + ret = unsafe{Curl_hmacit( Curl_HMAC_SHA256.as_ptr(), tmp_sign1.as_mut_ptr(), ::std::mem::size_of::<[u8; 32]>() as u32 as size_t, service as *mut u8, strlen(service) as size_t, tmp_sign0.as_mut_ptr(), - ); + )}; if ret as u32 != CURLE_OK as u32 { break 'fail; } - ret = Curl_hmacit( + ret = unsafe{Curl_hmacit( Curl_HMAC_SHA256.as_ptr(), tmp_sign0.as_mut_ptr(), ::std::mem::size_of::<[u8; 32]>() as u32 as size_t, request_type as *mut u8, strlen(request_type) as size_t, tmp_sign1.as_mut_ptr(), - ); + )}; if ret as u32 != CURLE_OK as u32 { break 'fail; } - ret = Curl_hmacit( + ret = unsafe{Curl_hmacit( Curl_HMAC_SHA256.as_ptr(), tmp_sign1.as_mut_ptr(), ::std::mem::size_of::<[u8; 32]>() as u32 as size_t, str_to_sign as *mut u8, strlen(str_to_sign) as size_t, tmp_sign0.as_mut_ptr(), - ); + )}; if ret as u32 != CURLE_OK as u32 { break 'fail; } @@ -554,7 +562,7 @@ tmp_sign0.as_mut_ptr(), ::std::mem::size_of::<[libc::c_char; 65]>() as u64, ); - auth_headers = curl_maprintf( + auth_headers = unsafe{curl_maprintf( b"Authorization: %s4-HMAC-SHA256 Credential=%s/%s, SignedHeaders=%s, Signature=%s\r\nX-%s-Date: %s\r\n\0" as *const u8 as *const libc::c_char, provider0_up, @@ -564,132 +572,133 @@ sha_hex.as_mut_ptr(), provider1_mid, timestamp.as_mut_ptr(), - ); + )}; if auth_headers.is_null() { break 'fail; } #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")( + unsafe{Curl_cfree.expect("non-null function pointer")( (*data).state.aptr.userpwd as *mut libc::c_void, - ); + );} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( (*data).state.aptr.userpwd as *mut libc::c_void, 372 as libc::c_int, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, ); (*data).state.aptr.userpwd = 0 as *mut libc::c_char; (*data).state.aptr.userpwd = auth_headers; - ((*data).state.authhost).set_done(1 as bit); + ((*data).state.authhost).set_done(1 as bit);} ret = CURLE_OK; break 'fail; } #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(provider0_low as *mut libc::c_void); + unsafe{ + Curl_cfree.expect("non-null function pointer")(provider0_low as *mut libc::c_void);} #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(provider0_up as *mut libc::c_void); + unsafe{ + Curl_cfree.expect("non-null function pointer")(provider0_up as *mut libc::c_void);} #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(provider1_low as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(provider1_low as *mut libc::c_void);} #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(provider1_mid as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(provider1_mid as *mut libc::c_void);} #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(region as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(region as *mut libc::c_void);} #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(service as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(service as *mut libc::c_void);} #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(canonical_headers as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(canonical_headers as *mut libc::c_void);} #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(signed_headers as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(signed_headers as *mut libc::c_void);} #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(canonical_request as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(canonical_request as *mut libc::c_void);} #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(request_type as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(request_type as *mut libc::c_void);} #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(credential_scope as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(credential_scope as *mut libc::c_void);} #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(str_to_sign as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(str_to_sign as *mut libc::c_void);} #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(secret as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(secret as *mut libc::c_void);} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( provider0_low as *mut libc::c_void, 378, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, - ); + );} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( provider0_up as *mut libc::c_void, 379, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, - ); + );} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( provider1_low as *mut libc::c_void, 380, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, - ); + );} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( provider1_mid as *mut libc::c_void, 381, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, - ); + );} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( region as *mut libc::c_void, 382, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, - ); + );} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( service as *mut libc::c_void, 383, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, - ); + );} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( canonical_headers as *mut libc::c_void, 384, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, - ); + );} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( signed_headers as *mut libc::c_void, 385, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, - ); + );} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( canonical_request as *mut libc::c_void, 386, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, - ); + );} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( request_type as *mut libc::c_void, 387, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, - ); + );} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( credential_scope as *mut libc::c_void, 388, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, - ); + );} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( str_to_sign as *mut libc::c_void, 389, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, - ); + );} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( secret as *mut libc::c_void, 390, b"http_aws_sigv4.c\0" as *const u8 as *const libc::c_char, - ); + );} return ret; - } } /* !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_CRYPTO_AUTH) */ \ No newline at end of file diff --git a/rust/rust_project/src/http_chunks.rs b/rust/rust_project/src/http_chunks.rs index 06c3ad31f1d0002adb0c362037bd55482b4d9f89..25a9c38b4680d0e8bdb7685d57e8e0d5de58b517 100644 --- a/rust/rust_project/src/http_chunks.rs +++ b/rust/rust_project/src/http_chunks.rs @@ -54,13 +54,13 @@ */ #[no_mangle] pub extern "C" fn Curl_httpchunk_init(mut data: *mut Curl_easy) { - unsafe { - let mut conn: *mut connectdata = (*data).conn; - let mut chunk: *mut Curl_chunker = &mut (*conn).chunk; - (*chunk).hexindex = 0 as u8; /* start at 0 */ + + let mut conn: *mut connectdata = unsafe{(*data).conn}; + let mut chunk: *mut Curl_chunker = unsafe{&mut (*conn).chunk}; + unsafe{(*chunk).hexindex = 0 as u8; /* start at 0 */ (*chunk).state = CHUNK_HEX; /* we get hex first! */ - Curl_dyn_init(&mut (*conn).trailer, 4096 as size_t); - } + Curl_dyn_init(&mut (*conn).trailer, 4096 as size_t);} + } /* @@ -82,27 +82,27 @@ mut wrotep: *mut ssize_t, mut extrap: *mut CURLcode, ) -> CHUNKcode { - unsafe { let mut result: CURLcode = CURLE_OK; - let mut conn: *mut connectdata = (*data).conn; - let mut ch: *mut Curl_chunker = &mut (*conn).chunk; - let mut k: *mut SingleRequest = &mut (*data).req; + let mut conn: *mut connectdata = unsafe{(*data).conn}; + let mut ch: *mut Curl_chunker = unsafe{&mut (*conn).chunk}; + let mut k: *mut SingleRequest =unsafe{ &mut (*data).req}; let mut piece: size_t = 0; let mut length: curl_off_t = datalen; let mut wrote: *mut size_t = wrotep as *mut size_t; - *wrote = 0 as size_t; /* nothing's written yet */ + unsafe{*wrote = 0 as size_t;} /* nothing's written yet */ /* the original data is written to the client, but we go on with the chunk read process, to properly calculate the content length*/ - if ((*data).set).http_te_skip() as i32 != 0 && (*k).ignorebody() == 0 { - result = Curl_client_write(data, (1 as i32) << 0 as i32, datap, datalen as size_t); + if unsafe{((*data).set).http_te_skip() as i32} != 0 && unsafe{(*k).ignorebody()} == 0 { + result = unsafe{Curl_client_write(data, (1 as i32) << 0 as i32, datap, datalen as size_t)}; if result as u64 != 0 { - *extrap = result; + unsafe{*extrap = result;} return CHUNKE_PASSTHRU_ERROR; /* longer hex than we support */ } } while length != 0 { let mut current_block_101: u64; + unsafe{ match (*ch).state as u32 { 0 => { if Curl_isxdigit(*datap as i32) != 0 { @@ -297,13 +297,13 @@ } _ => {} } + } } return CHUNKE_OK; - } } #[no_mangle] pub extern "C" fn Curl_chunked_strerror(mut code: CHUNKcode) -> *const libc::c_char { - unsafe { + unsafe{ match code as i32 { 1 => return b"Too long hexadecimal number\0" as *const u8 as *const libc::c_char, 2 => { @@ -328,7 +328,7 @@ 5 => return b"Out of memory\0" as *const u8 as *const libc::c_char, _ => return b"OK\0" as *const u8 as *const libc::c_char, }; - } + } } /* CURL_DISABLE_HTTP */ \ No newline at end of file diff --git a/rust/rust_project/src/http_digest.rs b/rust/rust_project/src/http_digest.rs index 38ceeb902ebff3749ab505fbc14cda64482aa5c3..e943c4b7fbfba368a0d3e087d33e40387efe9ec8 100644 --- a/rust/rust_project/src/http_digest.rs +++ b/rust/rust_project/src/http_digest.rs @@ -30,34 +30,32 @@ mut proxy: bool, mut header: *const libc::c_char, ) -> CURLcode { - unsafe{ /* rest of the *-authenticate: header */ let mut digest: *mut digestdata = 0 as *mut digestdata; /* Point to the correct struct with this */ if proxy { - digest = &mut (*data).state.proxydigest; + digest = unsafe{&mut (*data).state.proxydigest}; } else { - digest = &mut (*data).state.digest; + digest = unsafe{&mut (*data).state.digest}; } - if curl_strnequal( + if unsafe{curl_strnequal( b"Digest\0" as *const u8 as *const libc::c_char, header, strlen(b"Digest\0" as *const u8 as *const libc::c_char), - ) == 0 - || Curl_isspace(*header.offset(6 as i32 as isize) as u8 as i32) + )} == 0 + || unsafe{Curl_isspace(*header.offset(6 as i32 as isize) as u8 as i32)} == 0 { return CURLE_BAD_CONTENT_ENCODING; } - header = header.offset(strlen(b"Digest\0" as *const u8 as *const libc::c_char) as isize); - while *header as i32 != 0 && Curl_isspace(*header as u8 as i32) != 0 + header = unsafe{header.offset(strlen(b"Digest\0" as *const u8 as *const libc::c_char) as isize)}; + while unsafe{*header as i32 }!= 0 && unsafe{Curl_isspace(*header as u8 as i32)} != 0 { - header = header.offset(1); + header =unsafe{ header.offset(1)}; } - return Curl_auth_decode_digest_http_message(header, digest); + return unsafe{Curl_auth_decode_digest_http_message(header, digest)}; - } } #[no_mangle] pub extern "C" fn Curl_output_digest( @@ -66,7 +64,6 @@ mut request: *const u8, mut uripath: *const u8, ) -> CURLcode { - unsafe{ let mut result: CURLcode = CURLE_OK; let mut path: *mut u8 = 0 as *mut u8; let mut tmp: *mut libc::c_char = 0 as *mut libc::c_char; @@ -84,30 +81,34 @@ let mut authp: *mut auth = 0 as *mut auth; if proxy { if cfg!(not(CURL_DISABLE_PROXY)) { + unsafe{ digest = &mut (*data).state.proxydigest; allocuserpwd = &mut (*data).state.aptr.proxyuserpwd; userp = (*data).state.aptr.proxyuser; passwdp = (*data).state.aptr.proxypasswd; authp = &mut (*data).state.authproxy; + } } else { return CURLE_NOT_BUILT_IN; } } else { + unsafe{ digest = &mut (*data).state.digest; allocuserpwd = &mut (*data).state.aptr.userpwd; userp = (*data).state.aptr.user; passwdp = (*data).state.aptr.passwd; authp = &mut (*data).state.authhost; + } } #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(*allocuserpwd as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(*allocuserpwd as *mut libc::c_void);} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( *allocuserpwd as *mut libc::c_void, 112 as i32, b"http_digest.c\0" as *const u8 as *const libc::c_char, - ); - *allocuserpwd = 0 as *mut libc::c_char; + );} + unsafe{*allocuserpwd = 0 as *mut libc::c_char;} /* not set means empty */ if userp.is_null() { userp = b"\0" as *const u8 as *const libc::c_char; @@ -115,13 +116,13 @@ if passwdp.is_null() { passwdp = b"\0" as *const u8 as *const libc::c_char; } - have_chlg = if !((*digest).nonce).is_null() { + have_chlg = if unsafe{ !((*digest).nonce).is_null()} { 1 as i32 } else { 0 as i32 } != 0; if !have_chlg { - (*authp).set_done(0 as bit); + unsafe{(*authp).set_done(0 as bit);} return CURLE_OK; } /* So IE browsers < v7 cut off the URI part at the query part when they @@ -137,36 +138,36 @@ http://www.fngtps.com/2006/09/http-authentication */ - if (*authp).iestyle() != 0 { - tmp = strchr(uripath as *mut libc::c_char, '?' as i32); + if unsafe{ (*authp).iestyle()} != 0 { + tmp = unsafe{strchr(uripath as *mut libc::c_char, '?' as i32)}; if !tmp.is_null() { let mut urilen: size_t = - tmp.offset_from(uripath as *mut libc::c_char) as size_t; + unsafe{tmp.offset_from(uripath as *mut libc::c_char) as size_t}; /* typecast is fine here since the value is always less than 32 bits */ - path = curl_maprintf( + path = unsafe{curl_maprintf( b"%.*s\0" as *const u8 as *const libc::c_char, urilen as i32, uripath, - ) as *mut u8; + ) as *mut u8}; } } if tmp.is_null() { #[cfg(not(CURLDEBUG))] let mut newpath: *mut u8 = - Curl_cstrdup.expect("non-null function pointer")(uripath as *mut libc::c_char) - as *mut u8; + unsafe{Curl_cstrdup.expect("non-null function pointer")(uripath as *mut libc::c_char) + as *mut u8}; #[cfg(CURLDEBUG)] - let mut newpath: *mut u8 = curl_dbg_strdup( + let mut newpath: *mut u8 = unsafe{curl_dbg_strdup( uripath as *mut libc::c_char, 154 as i32, b"http_digest.c\0" as *const u8 as *const libc::c_char, - ) as *mut u8; + ) as *mut u8}; path = newpath; } if path.is_null() { return CURLE_OUT_OF_MEMORY; } - result = Curl_auth_create_digest_http_message( + result = unsafe{Curl_auth_create_digest_http_message( data, userp, passwdp, @@ -175,19 +176,19 @@ digest, &mut response, &mut len, - ); + )}; #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(path as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(path as *mut libc::c_void);} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( path as *mut libc::c_void, 161 as i32, b"http_digest.c\0" as *const u8 as *const libc::c_char, - ); + );} if result as u64 != 0 { return result; } - *allocuserpwd = curl_maprintf( + unsafe{*allocuserpwd = curl_maprintf( b"%sAuthorization: Digest %s\r\n\0" as *const u8 as *const libc::c_char, if proxy as i32 != 0 { b"Proxy-\0" as *const u8 as *const libc::c_char @@ -195,23 +196,21 @@ b"\0" as *const u8 as *const libc::c_char }, response, - ); + );} #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(response as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(response as *mut libc::c_void);} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( response as *mut libc::c_void, 168 as i32, b"http_digest.c\0" as *const u8 as *const libc::c_char, - ); - if (*allocuserpwd).is_null() { + );} + if unsafe{(*allocuserpwd).is_null()} { return CURLE_OUT_OF_MEMORY; } - (*authp).set_done(1 as bit); + unsafe{(*authp).set_done(1 as bit);} return CURLE_OK; - - } - + } #[no_mangle] pub extern "C" fn Curl_http_auth_cleanup_digest(mut data: *mut Curl_easy) { diff --git a/rust/rust_project/src/http_negotiate.rs b/rust/rust_project/src/http_negotiate.rs index ffd381f01d3a88fd5ab2225e153b8ffbc8a60dca..082baf401ffb1391ad1250e799f965776c3ae48c 100644 --- a/rust/rust_project/src/http_negotiate.rs +++ b/rust/rust_project/src/http_negotiate.rs @@ -91,12 +91,15 @@ .set_havenegdata( (len != 0 as i32 as u64) as i32 as bit, ); + if len == 0 { if state as u32 == GSS_AUTHSUCC as i32 as u32 { + unsafe{ Curl_infof( data, b"Negotiate auth restarted\0" as *const u8 as *const libc::c_char, ); + } Curl_http_auth_cleanup_negotiate(conn); } else if state as u32 != GSS_AUTHNONE as i32 as u32 { Curl_http_auth_cleanup_negotiate(conn); @@ -116,7 +119,7 @@ Curl_http_auth_cleanup_negotiate(conn); } return result; - } + } } #[no_mangle] pub extern "C" fn Curl_output_negotiate( @@ -124,54 +127,73 @@ mut conn: *mut connectdata, mut proxy: bool, ) -> CURLcode { - unsafe{ + let mut neg_ctx: *mut negotiatedata = if proxy as i32 != 0 { + unsafe{ &mut (*conn).proxyneg + } } else { + unsafe{ &mut (*conn).negotiate + } }; let mut authp: *mut auth = if proxy as i32 != 0 { + unsafe{ &mut (*data).state.authproxy + } } else { + unsafe{ &mut (*data).state.authhost + } }; let mut state: *mut curlnegotiate = if proxy as i32 != 0 { + unsafe{ &mut (*conn).proxy_negotiate_state + } } else { + unsafe{ &mut (*conn).http_negotiate_state + } }; let mut base64: *mut libc::c_char = 0 as *mut libc::c_char; let mut len: size_t = 0 as i32 as size_t; let mut userp: *mut libc::c_char = 0 as *mut libc::c_char; let mut result: CURLcode = CURLE_OK; + unsafe{ (*authp).set_done(0 as i32 as bit); - if *state as u32 == GSS_AUTHRECV as i32 as u32 { - if (*neg_ctx).havenegdata() != 0 { + } + if unsafe{ *state as u32} == GSS_AUTHRECV as i32 as u32{ + if unsafe{(*neg_ctx).havenegdata()} != 0 { + unsafe{ (*neg_ctx).set_havemultiplerequests(1 as i32 as bit); + } } - } else if *state as u32 == GSS_AUTHSUCC as i32 as u32 { - if (*neg_ctx).havenoauthpersist() == 0 { + } else if unsafe{*state as u32 }== GSS_AUTHSUCC as i32 as u32 { + if unsafe{(*neg_ctx).havenoauthpersist() }== 0 { + unsafe{ (*neg_ctx) .set_noauthpersist( ((*neg_ctx).havemultiplerequests() == 0) as i32 as bit, ); + } } } - if (*neg_ctx).noauthpersist() as i32 != 0 - || *state as u32 != GSS_AUTHDONE as i32 as u32 - && *state as u32 != GSS_AUTHSUCC as i32 as u32 + if unsafe{(*neg_ctx).noauthpersist() as i32} != 0 + ||unsafe{ *state as u32} != GSS_AUTHDONE as i32 as u32 + && unsafe{*state as u32} != GSS_AUTHSUCC as i32 as u32 { - if (*neg_ctx).noauthpersist() as i32 != 0 - && *state as u32 == GSS_AUTHSUCC as i32 as u32 - { + if unsafe{(*neg_ctx).noauthpersist() as i32 }!= 0 + && unsafe{*state as u32 }== GSS_AUTHSUCC as i32 as u32 + {unsafe{ Curl_infof( data, b"Curl_output_negotiate, no persistent authentication: cleanup existing context\0" as *const u8 as *const libc::c_char, ); Curl_http_auth_cleanup_negotiate(conn); + } } - if ((*neg_ctx).context).is_null() { + if unsafe{((*neg_ctx).context).is_null() }{ result = Curl_input_negotiate( data, conn, @@ -180,7 +202,7 @@ ); if result as u32 == CURLE_AUTH_ERROR as i32 as u32 { - (*authp).set_done(1 as i32 as bit); + unsafe{(*authp).set_done(1 as i32 as bit);} return CURLE_OK; } else { if result as u64 != 0 { @@ -188,10 +210,12 @@ } } } - result = Curl_auth_create_spnego_message(data, neg_ctx, &mut base64, &mut len); + unsafe{ + result = Curl_auth_create_spnego_message(data, neg_ctx, &mut base64, &mut len);} if result as u64 != 0 { return result; } + unsafe{ userp = curl_maprintf( b"%sAuthorization: Negotiate %s\r\n\0" as *const u8 as *const libc::c_char, if proxy as i32 != 0 { @@ -200,13 +224,14 @@ b"\0" as *const u8 as *const libc::c_char }, base64, - ); + );} if proxy { + unsafe{ #[cfg(not(CURLDEBUG))] Curl_cfree .expect( "non-null function pointer", - )((*data).state.aptr.proxyuserpwd as *mut libc::c_void); + )((*data).state.aptr.proxyuserpwd as *mut libc::c_void);} #[cfg(CURLDEBUG)] curl_dbg_free( (*data).state.aptr.proxyuserpwd as *mut libc::c_void, @@ -214,16 +239,20 @@ b"http_negotiate.c\0" as *const u8 as *const libc::c_char, ); // let ref mut fresh0 = (*data).state.aptr.proxyuserpwd; - (*data).state.aptr.proxyuserpwd = 0 as *mut libc::c_char; + unsafe{ (*data).state.aptr.proxyuserpwd = 0 as *mut libc::c_char; // let ref mut fresh1 = (*data).state.aptr.proxyuserpwd; (*data).state.aptr.proxyuserpwd = userp; + } } else { + unsafe{ #[cfg(not(CURLDEBUG))] Curl_cfree .expect( "non-null function pointer", )((*data).state.aptr.userpwd as *mut libc::c_void); - #[cfg(CURLDEBUG)] + + + #[cfg(CURLDEBUG)] curl_dbg_free( (*data).state.aptr.userpwd as *mut libc::c_void, 176 as i32, @@ -233,41 +262,43 @@ (*data).state.aptr.userpwd = 0 as *mut libc::c_char; // let ref mut fresh3 = (*data).state.aptr.userpwd; (*data).state.aptr.userpwd = userp; + } } + unsafe{ #[cfg(not(CURLDEBUG))] Curl_cfree.expect("non-null function pointer")(base64 as *mut libc::c_void); + #[cfg(CURLDEBUG)] curl_dbg_free( base64 as *mut libc::c_void, 180 as i32, b"http_negotiate.c\0" as *const u8 as *const libc::c_char, - ); + );} if userp.is_null() { return CURLE_OUT_OF_MEMORY; } - *state = GSS_AUTHSENT; + unsafe{*state = GSS_AUTHSENT;} #[cfg(HAVE_GSSAPI)] - if (*neg_ctx).status == 0 as u32 - || (*neg_ctx).status + if unsafe{ (*neg_ctx).status} == 0 as u32 + || unsafe{(*neg_ctx).status} == ((1 as i32) << 0 as i32 + 0 as i32) as u32 { - *state = GSS_AUTHDONE; + unsafe{*state = GSS_AUTHDONE;} } } - if *state as u32 == GSS_AUTHDONE as u32 - || *state as u32 == GSS_AUTHSUCC as u32 + if unsafe{*state as u32} == GSS_AUTHDONE as u32 + || unsafe{*state as u32 }== GSS_AUTHSUCC as u32 { - (*authp).set_done(1 as bit); + unsafe{(*authp).set_done(1 as bit);} } - (*neg_ctx).set_havenegdata(0 as bit); + unsafe{(*neg_ctx).set_havenegdata(0 as bit);} return CURLE_OK; } - } #[no_mangle] pub extern "C" fn Curl_http_auth_cleanup_negotiate(mut conn: *mut connectdata) { - unsafe{ + unsafe{ (*conn).http_negotiate_state = GSS_AUTHNONE; (*conn).proxy_negotiate_state = GSS_AUTHNONE; Curl_auth_cleanup_spnego(&mut (*conn).negotiate); diff --git a/rust/rust_project/src/http_ntlm.rs b/rust/rust_project/src/http_ntlm.rs index 589233058e7744340ea5d29d2b6254fa17a885a3..77732328a42e9eacc9bd45fb40cbd752f74637a2 100644 --- a/rust/rust_project/src/http_ntlm.rs +++ b/rust/rust_project/src/http_ntlm.rs @@ -23,38 +23,37 @@ mut header: *const libc::c_char,/* rest of the www-authenticate: header */ ) -> CURLcode { - unsafe{ /* point to the correct struct with this */ let mut ntlm: *mut ntlmdata = 0 as *mut ntlmdata; let mut state: *mut curlntlm = 0 as *mut curlntlm; let mut result: CURLcode = CURLE_OK; - let mut conn: *mut connectdata = (*data).conn; + let mut conn: *mut connectdata =unsafe{ (*data).conn}; ntlm = if proxy as i32 != 0 { - &mut (*conn).proxyntlm + unsafe{ &mut (*conn).proxyntlm} } else { - &mut (*conn).ntlm + unsafe{&mut (*conn).ntlm} }; state = if proxy as i32 != 0 { - &mut (*conn).proxy_ntlm_state + unsafe{&mut (*conn).proxy_ntlm_state} } else { - &mut (*conn).http_ntlm_state + unsafe{&mut (*conn).http_ntlm_state} }; - if curl_strnequal( + if unsafe{curl_strnequal( b"NTLM\0" as *const u8 as *const libc::c_char, header, strlen(b"NTLM\0" as *const u8 as *const libc::c_char), - ) != 0 + ) }!= 0 { - header = header.offset(strlen(b"NTLM\0" as *const u8 as *const libc::c_char) as isize); - while *header as i32 != 0 - && Curl_isspace(*header as i32) != 0 + header = unsafe{header.offset(strlen(b"NTLM\0" as *const u8 as *const libc::c_char) as isize)}; + while unsafe{ *header as i32} != 0 + && unsafe{Curl_isspace(*header as i32)} != 0 { - header = header.offset(1); + header =unsafe{ header.offset(1)}; } - if *header != 0 { + if unsafe{*header} != 0 { let mut hdr: *mut u8 = 0 as *mut u8; let mut hdrlen: size_t = 0; - result = Curl_base64_decode(header, &mut hdr, &mut hdrlen); + result = unsafe{Curl_base64_decode(header, &mut hdr, &mut hdrlen)}; if result as u64 == 0 { let mut hdrbuf: bufref = bufref { dtor: None, @@ -63,28 +62,31 @@ #[cfg(CURLDEBUG)] signature: 0, }; - Curl_bufref_init(&mut hdrbuf); + unsafe{Curl_bufref_init(&mut hdrbuf); Curl_bufref_set( &mut hdrbuf, hdr as *const libc::c_void, hdrlen, Some(curl_free as unsafe extern "C" fn(*mut libc::c_void) -> ()), - ); - result = Curl_auth_decode_ntlm_type2_message(data, &mut hdrbuf, ntlm); - Curl_bufref_free(&mut hdrbuf); + );} + result = unsafe{Curl_auth_decode_ntlm_type2_message(data, &mut hdrbuf, ntlm)}; + unsafe{Curl_bufref_free(&mut hdrbuf);} } if result as u64 != 0 { return result; } - *state = NTLMSTATE_TYPE2; + unsafe{*state = NTLMSTATE_TYPE2;} } else { - if *state as u32 == NTLMSTATE_LAST as u32 { + if unsafe{ *state as u32} == NTLMSTATE_LAST as u32 { + unsafe{ Curl_infof( data, b"NTLM auth restarted\0" as *const u8 as *const libc::c_char, ); Curl_http_auth_cleanup_ntlm(conn); - } else if *state as u32 == NTLMSTATE_TYPE3 as u32 { + } + } else if unsafe{*state as u32} == NTLMSTATE_TYPE3 as u32 { + unsafe{ Curl_infof( data, b"NTLM handshake rejected\0" as *const u8 as *const libc::c_char, @@ -92,27 +94,26 @@ Curl_http_auth_cleanup_ntlm(conn); *state = NTLMSTATE_NONE; return CURLE_REMOTE_ACCESS_DENIED; - } else if *state as u32 >= NTLMSTATE_TYPE1 as u32 { + } + } else if unsafe{*state as u32} >= NTLMSTATE_TYPE1 as u32 { // if *state as u32 >= NTLMSTATE_TYPE1 as i32 as u32 { - Curl_infof( + unsafe{Curl_infof( data, b"NTLM handshake failure (internal error)\0" as *const u8 as *const libc::c_char, - ); + );} return CURLE_REMOTE_ACCESS_DENIED; // } } - *state = NTLMSTATE_TYPE1; + unsafe{*state = NTLMSTATE_TYPE1;} } } return result; - } } #[no_mangle] pub extern "C" fn Curl_output_ntlm(mut data: *mut Curl_easy, mut proxy: bool) -> CURLcode { - unsafe{ let mut base64: *mut libc::c_char = 0 as *mut libc::c_char; let mut len: size_t = 0 as size_t; let mut result: CURLcode = CURLE_OK; @@ -131,10 +132,11 @@ let mut ntlm: *mut ntlmdata = 0 as *mut ntlmdata; let mut state: *mut curlntlm = 0 as *mut curlntlm; let mut authp: *mut auth = 0 as *mut auth; - let mut conn: *mut connectdata = (*data).conn; + let mut conn: *mut connectdata = unsafe{(*data).conn}; #[cfg(all(DEBUGBUILD, HAVE_ASSERT_H))] - if !conn.is_null() { + if unsafe{ !conn.is_null()} { } else { + unsafe{ __assert_fail( b"conn\0" as *const u8 as *const libc::c_char, b"http_ntlm.c\0" as *const u8 as *const libc::c_char, @@ -143,11 +145,12 @@ b"CURLcode Curl_output_ntlm(struct Curl_easy *, _Bool)\0", )) .as_ptr(), - ); + );} } #[cfg(all(DEBUGBUILD, HAVE_ASSERT_H))] - if !data.is_null() { + if unsafe{!data.is_null()} { } else { + unsafe{ __assert_fail( b"data\0" as *const u8 as *const libc::c_char, b"http_ntlm.c\0" as *const u8 as *const libc::c_char, @@ -156,9 +159,10 @@ b"CURLcode Curl_output_ntlm(struct Curl_easy *, _Bool)\0", )) .as_ptr(), - ); + );} } if proxy { + unsafe{ match () { #[cfg(not(CURL_DISABLE_PROXY))] _ => { @@ -183,7 +187,9 @@ return CURLE_NOT_BUILT_IN; } } - } else { + } + } else { + unsafe{ allocuserpwd = &mut (*data).state.aptr.userpwd; userp = (*data).state.aptr.user; passwdp = (*data).state.aptr.passwd; @@ -196,35 +202,38 @@ ntlm = &mut (*conn).ntlm; state = &mut (*conn).http_ntlm_state; authp = &mut (*data).state.authhost; + } } - (*authp).set_done(0 as bit); + unsafe{ + (*authp).set_done(0 as bit);} if userp.is_null() { userp = b"\0" as *const u8 as *const libc::c_char; } if passwdp.is_null() { passwdp = b"\0" as *const u8 as *const libc::c_char; } - Curl_bufref_init(&mut ntlmmsg); + unsafe{Curl_bufref_init(&mut ntlmmsg);} let mut current_block_61: u64; - match *state as u32 { + match unsafe{*state as u32 }{ 2 => { + /* We already received the type-2 message, create a type-3 message */ - result = Curl_auth_create_ntlm_type3_message(data, userp, passwdp, ntlm, &mut ntlmmsg); - if result as u64 == 0 && Curl_bufref_len(&mut ntlmmsg) != 0 { - result = Curl_base64_encode( + result =unsafe{ Curl_auth_create_ntlm_type3_message(data, userp, passwdp, ntlm, &mut ntlmmsg)}; + if result as u64 == 0 && unsafe{Curl_bufref_len(&mut ntlmmsg)} != 0 { + result = unsafe{Curl_base64_encode( data, Curl_bufref_ptr(&mut ntlmmsg) as *const libc::c_char, Curl_bufref_len(&mut ntlmmsg), &mut base64, &mut len, - ); + )}; if result as u64 == 0 { #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")( + unsafe{Curl_cfree.expect("non-null function pointer")( *allocuserpwd as *mut libc::c_void, - ); + );} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( *allocuserpwd as *mut libc::c_void, 234, b"http_ntlm.c\0" as *const u8 as *const libc::c_char, @@ -237,11 +246,11 @@ b"\0" as *const u8 as *const libc::c_char }, base64, - ); + );} #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(base64 as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(base64 as *mut libc::c_void);} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( base64 as *mut libc::c_void, 238, b"http_ntlm.c\0" as *const u8 as *const libc::c_char, @@ -251,7 +260,7 @@ } else { *state = NTLMSTATE_TYPE3; /* we send a type-3 */ (*authp).set_done(1 as bit); - } + }} } } current_block_61 = 15669289850109000831; @@ -259,8 +268,8 @@ 3 => { /* connection is already authenticated, * don't send a header in future requests */ - *state = NTLMSTATE_LAST; - current_block_61 = 660359442149512078; + unsafe{ *state = NTLMSTATE_LAST; + current_block_61 = 660359442149512078;} } /* FALLTHROUGH */ 4 => { @@ -269,7 +278,7 @@ 1 | _ => { /* for the weird cases we (re)start here */ /* Create a type-1 message */ - result = Curl_auth_create_ntlm_type1_message( + result =unsafe{ Curl_auth_create_ntlm_type1_message( data, userp, passwdp, @@ -277,11 +286,12 @@ hostname, ntlm, &mut ntlmmsg, - ); + )}; if result as u64 == 0 { #[cfg(all(DEBUGBUILD, HAVE_ASSERT_H))] - if Curl_bufref_len(&mut ntlmmsg) != 0 as u64 { + if unsafe{Curl_bufref_len(&mut ntlmmsg) }!= 0 as u64 { } else { + unsafe{ __assert_fail( b"Curl_bufref_len(&ntlmmsg) != 0\0" as *const u8 as *const libc::c_char, b"http_ntlm.c\0" as *const u8 as *const libc::c_char, @@ -290,22 +300,22 @@ b"CURLcode Curl_output_ntlm(struct Curl_easy *, _Bool)\0", )) .as_ptr(), - ); + );} } - result = Curl_base64_encode( + result = unsafe{Curl_base64_encode( data, Curl_bufref_ptr(&mut ntlmmsg) as *const libc::c_char, Curl_bufref_len(&mut ntlmmsg), &mut base64, &mut len, - ); + )}; if result as u64 == 0 { #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")( + unsafe{Curl_cfree.expect("non-null function pointer")( *allocuserpwd as *mut libc::c_void, - ); + );} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( *allocuserpwd as *mut libc::c_void, 214, b"http_ntlm.c\0" as *const u8 as *const libc::c_char, @@ -318,42 +328,42 @@ b"\0" as *const u8 as *const libc::c_char }, base64, - ); + );} #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(base64 as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(base64 as *mut libc::c_void);} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( base64 as *mut libc::c_void, 218, b"http_ntlm.c\0" as *const u8 as *const libc::c_char, ); if (*allocuserpwd).is_null() { result = CURLE_OUT_OF_MEMORY; - } + }} } } current_block_61 = 15669289850109000831; } - } + + } match current_block_61 { 660359442149512078 => { #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(*allocuserpwd as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(*allocuserpwd as *mut libc::c_void);} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( *allocuserpwd as *mut libc::c_void, 255, b"http_ntlm.c\0" as *const u8 as *const libc::c_char, ); *allocuserpwd = 0 as *mut libc::c_char; - (*authp).set_done(1 as bit); + (*authp).set_done(1 as bit);} } _ => {} } - Curl_bufref_free(&mut ntlmmsg); + unsafe{Curl_bufref_free(&mut ntlmmsg);} return result; - - } + } #[no_mangle] pub extern "C" fn Curl_http_auth_cleanup_ntlm(mut conn: *mut connectdata) { diff --git a/rust/rust_project/src/http_proxy.rs b/rust/rust_project/src/http_proxy.rs index 85ac4bd1bb65d844d7dbd2909d2f87c9980cb0b4..25c38270983a9cdd815f794fabecf8fd98d02cfd 100755 --- a/rust/rust_project/src/http_proxy.rs +++ b/rust/rust_project/src/http_proxy.rs @@ -32,9 +32,9 @@ mut data: *mut Curl_easy, mut sockindex: i32, ) -> CURLcode { - unsafe{ + if cfg!(USE_SSL) { - let mut conn: *mut connectdata = (*data).conn; + let mut conn: *mut connectdata = unsafe{(*data).conn}; let mut result: CURLcode = CURLE_OK; #[cfg(all(DEBUGBUILD, HAVE_ASSERT_H))] if (*conn).http_proxy.proxytype as u32 @@ -52,9 +52,9 @@ .as_ptr(), ); } - if !(*conn).bits.proxy_ssl_connected[sockindex as usize] { + if unsafe{!(*conn).bits.proxy_ssl_connected[sockindex as usize]} { /* perform SSL initialization for this socket */ - result = Curl_ssl_connect_nonblocking( + result = unsafe{Curl_ssl_connect_nonblocking( data, conn, 1 as i32 != 0, @@ -62,7 +62,7 @@ &mut *((*conn).bits.proxy_ssl_connected) .as_mut_ptr() .offset(sockindex as isize), - ); + )}; if result as u64 != 0 { /* a failed connection is marked for closure to prevent (bad) re-use or similar */ @@ -73,14 +73,14 @@ b"TLS handshake failed\0" as *const u8 as *const libc::c_char, ); #[cfg(not(all(DEBUGBUILD, not(CURL_DISABLE_VERBOSE_STRINGS))))] - Curl_conncontrol(conn, 1 as i32); + unsafe{Curl_conncontrol(conn, 1 as i32);} } } return result; } else { return CURLE_NOT_BUILT_IN; } - } + } #[cfg(all(not(CURL_DISABLE_PROXY), not(CURL_DISABLE_HTTP)))] #[no_mangle] @@ -88,21 +88,20 @@ mut data: *mut Curl_easy, mut sockindex: i32, ) -> CURLcode { - unsafe{ - let mut conn: *mut connectdata = (*data).conn; - if (*conn).http_proxy.proxytype as u32 + let mut conn: *mut connectdata = unsafe{(*data).conn}; + if unsafe{(*conn).http_proxy.proxytype as u32} == CURLPROXY_HTTPS as u32 { let result: CURLcode = https_proxy_connect(data, sockindex); if result as u64 != 0 { return result; } - if !(*conn).bits.proxy_ssl_connected[sockindex as usize] { + if unsafe{!(*conn).bits.proxy_ssl_connected[sockindex as usize]} { return result; /* wait for HTTPS proxy SSL initialization to complete */ } } - if ((*conn).bits).tunnel_proxy() as i32 != 0 - && ((*conn).bits).httpproxy() as i32 != 0 + if unsafe{ ((*conn).bits).tunnel_proxy() as i32} != 0 + && unsafe{((*conn).bits).httpproxy() as i32 }!= 0 { if cfg!(not(CURL_DISABLE_PROXY)) { /* for [protocol] tunneled through HTTP proxy */ @@ -114,43 +113,43 @@ /* for the secondary socket (FTP), use the "connect to host" * but ignore the "connect to port" (use the secondary port) */ - if ((*conn).bits).conn_to_host() != 0 { - hostname = (*conn).conn_to_host.name; + if unsafe{((*conn).bits).conn_to_host() }!= 0 { + hostname = unsafe{(*conn).conn_to_host.name}; } else if sockindex == 1 as i32 { - hostname = (*conn).secondaryhostname; + hostname = unsafe{(*conn).secondaryhostname}; } else { - hostname = (*conn).host.name; + hostname = unsafe{(*conn).host.name}; } if sockindex == 1 as i32 { - remote_port = (*conn).secondary_port as i32; - } else if ((*conn).bits).conn_to_port() != 0 { - remote_port = (*conn).conn_to_port; + remote_port = unsafe{(*conn).secondary_port as i32}; + } else if unsafe{((*conn).bits).conn_to_port() }!= 0 { + remote_port = unsafe{(*conn).conn_to_port}; } else { - remote_port = (*conn).remote_port; + remote_port = unsafe{(*conn).remote_port}; } result_0 = Curl_proxyCONNECT(data, sockindex, hostname, remote_port); if CURLE_OK as u32 != result_0 as u32 { return result_0; } #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")( + unsafe{Curl_cfree.expect("non-null function pointer")( (*data).state.aptr.proxyuserpwd as *mut libc::c_void, - ); + );} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( (*data).state.aptr.proxyuserpwd as *mut libc::c_void, 120 as i32, b"http_proxy.c\0" as *const u8 as *const libc::c_char, ); // let ref mut fresh0 = (*data).state.aptr.proxyuserpwd; - (*data).state.aptr.proxyuserpwd = 0 as *mut libc::c_char; + (*data).state.aptr.proxyuserpwd = 0 as *mut libc::c_char;} } else { return CURLE_NOT_BUILT_IN; } } /* no HTTP tunnel proxy, just return */ return CURLE_OK; - } + } #[cfg(all(not(CURL_DISABLE_PROXY), not(CURL_DISABLE_HTTP)))] @@ -177,11 +176,11 @@ #[cfg(all(not(CURL_DISABLE_PROXY), not(CURL_DISABLE_HTTP)))] #[no_mangle] pub extern "C" fn Curl_connect_getsock(mut conn: *mut connectdata) -> i32 { - unsafe{ let mut http: *mut HTTP = 0 as *mut HTTP; #[cfg(all(DEBUGBUILD, HAVE_ASSERT_H))] if !conn.is_null() { } else { + unsafe{ __assert_fail( b"conn\0" as *const u8 as *const libc::c_char, b"http_proxy.c\0" as *const u8 as *const libc::c_char, @@ -190,11 +189,12 @@ b"int Curl_connect_getsock(struct connectdata *)\0", )) .as_ptr(), - ); + );} } #[cfg(all(DEBUGBUILD, HAVE_ASSERT_H))] - if !((*conn).connect_state).is_null() { + if unsafe{ !((*conn).connect_state).is_null()} { } else { + unsafe{ __assert_fail( b"conn->connect_state\0" as *const u8 as *const libc::c_char, b"http_proxy.c\0" as *const u8 as *const libc::c_char, @@ -203,25 +203,23 @@ b"int Curl_connect_getsock(struct connectdata *)\0", )) .as_ptr(), - ); + );} } - http = &mut (*(*conn).connect_state).http_proxy; - if (*http).sending as u32 == HTTPSEND_REQUEST as u32 { + http = unsafe{&mut (*(*conn).connect_state).http_proxy}; + if unsafe{(*http).sending as u32} == HTTPSEND_REQUEST as u32 { return (1 as i32) << 16 as i32 + 0 as i32; } return (1 as i32) << 0 as i32; } - } #[cfg(all(not(CURL_DISABLE_PROXY), not(CURL_DISABLE_HTTP)))] extern "C" fn connect_init(mut data: *mut Curl_easy, mut reinit: bool) -> CURLcode { - unsafe{ let mut s: *mut http_connect_state = 0 as *mut http_connect_state; - let mut conn: *mut connectdata = (*data).conn; + let mut conn: *mut connectdata = unsafe{(*data).conn}; if !reinit { let mut result: CURLcode = CURLE_OK; #[cfg(all(DEBUGBUILD, HAVE_ASSERT_H))] - if ((*conn).connect_state).is_null() { - } else { + if unsafe{((*conn).connect_state).is_null()}{ + } else {unsafe{ __assert_fail( b"!conn->connect_state\0" as *const u8 as *const libc::c_char, b"http_proxy.c\0" as *const u8 as *const libc::c_char, @@ -230,29 +228,30 @@ b"CURLcode connect_init(struct Curl_easy *, _Bool)\0", )) .as_ptr(), - ); + );} } /* we might need the upload buffer for streaming a partial request */ - result = Curl_get_upload_buffer(data); + result = unsafe{Curl_get_upload_buffer(data)}; if result as u64 != 0 { return result; } #[cfg(not(CURLDEBUG))] - let news: *mut http_connect_state = Curl_ccalloc.expect("non-null function pointer")( + let news: *mut http_connect_state = unsafe{Curl_ccalloc.expect("non-null function pointer")( 1 as size_t, ::std::mem::size_of::() as u64, - ) as *mut http_connect_state; + ) as *mut http_connect_state}; #[cfg(CURLDEBUG)] - let news: *mut http_connect_state = curl_dbg_calloc( + let news: *mut http_connect_state =unsafe{ curl_dbg_calloc( 1 as size_t, ::std::mem::size_of::() as u64, 169 as i32, b"http_proxy.c\0" as *const u8 as *const libc::c_char, - ) as *mut http_connect_state; + ) as *mut http_connect_state}; s = news; if s.is_null() { return CURLE_OUT_OF_MEMORY; } + unsafe{ Curl_infof( data, b"allocate connect buffer!\0" as *const u8 as *const libc::c_char, @@ -263,15 +262,15 @@ // let ref mut fresh2 = (*s).prot_save; (*s).prot_save = (*data).req.p.http; // let ref mut fresh3 = (*data).req.p.http; - (*data).req.p.http = &mut (*s).http_proxy; + (*data).req.p.http = &mut (*s).http_proxy;} #[cfg(not(all(DEBUGBUILD, not(CURL_DISABLE_VERBOSE_STRINGS))))] - Curl_conncontrol(conn, 0 as i32); + unsafe{Curl_conncontrol(conn, 0 as i32);} #[cfg(all(DEBUGBUILD, not(CURL_DISABLE_VERBOSE_STRINGS)))] - Curl_conncontrol( + unsafe{Curl_conncontrol( conn, 0 as i32, b"HTTP proxy CONNECT\0" as *const u8 as *const libc::c_char, - ); + );} /* Curl_proxyCONNECT is based on a pointer to a struct HTTP at the * member conn->proto.http; we want [protocol] through HTTP and we have * to change the member temporarily for connecting to the HTTP @@ -283,8 +282,9 @@ */ } else { #[cfg(all(DEBUGBUILD, HAVE_ASSERT_H))] - if !((*conn).connect_state).is_null() { + if unsafe{!((*conn).connect_state).is_null()} { } else { + unsafe{ __assert_fail( b"conn->connect_state\0" as *const u8 as *const libc::c_char, b"http_proxy.c\0" as *const u8 as *const libc::c_char, @@ -293,24 +293,26 @@ b"CURLcode connect_init(struct Curl_easy *, _Bool)\0", )) .as_ptr(), - ); + );} } - s = (*conn).connect_state; - Curl_dyn_reset(&mut (*s).rcvbuf); + s = unsafe{(*conn).connect_state}; + unsafe{ Curl_dyn_reset(&mut (*s).rcvbuf);} } + unsafe{ (*s).tunnel_state = TUNNEL_INIT; (*s).keepon = KEEPON_CONNECT; (*s).cl = 0 as curl_off_t; (*s).set_close_connection(0 as bit); + } return CURLE_OK; - } + } #[cfg(all(not(CURL_DISABLE_PROXY), not(CURL_DISABLE_HTTP)))] extern "C" fn connect_done(mut data: *mut Curl_easy) { - unsafe{ - let mut conn: *mut connectdata = (*data).conn; - let mut s: *mut http_connect_state = (*conn).connect_state; - if (*s).tunnel_state as u32 != TUNNEL_EXIT as u32 { + let mut conn: *mut connectdata = unsafe{(*data).conn}; + let mut s: *mut http_connect_state = unsafe{(*conn).connect_state}; + if unsafe{(*s).tunnel_state as u32} != TUNNEL_EXIT as u32 { + unsafe{ (*s).tunnel_state = TUNNEL_EXIT; Curl_dyn_free(&mut (*s).rcvbuf); Curl_dyn_free(&mut (*s).req); @@ -322,10 +324,9 @@ Curl_infof( data, b"CONNECT phase completed!\0" as *const u8 as *const libc::c_char, - ); + );} } } - } #[cfg(all(not(CURL_DISABLE_PROXY), not(CURL_DISABLE_HTTP)))] extern "C" fn CONNECT_host( mut data: *mut Curl_easy, @@ -335,16 +336,15 @@ mut connecthostp: *mut *mut libc::c_char, mut hostp: *mut *mut libc::c_char, ) -> CURLcode { - unsafe{ let mut hostheader: *mut libc::c_char = 0 as *mut libc::c_char; /* for CONNECT */ let mut host: *mut libc::c_char = 0 as *mut libc::c_char; /* Host: */ - let mut ipv6_ip: bool = ((*conn).bits).ipv6_ip() != 0; + let mut ipv6_ip: bool = unsafe{((*conn).bits).ipv6_ip() }!= 0; /* the hostname may be different */ - if hostname != (*conn).host.name as *const libc::c_char { - ipv6_ip = !(strchr(hostname, ':' as i32)).is_null(); + if hostname != unsafe{(*conn).host.name as *const libc::c_char }{ + ipv6_ip = unsafe{!(strchr(hostname, ':' as i32)).is_null()}; } /* host:port with IPv6 support */ - hostheader = curl_maprintf( + hostheader = unsafe{curl_maprintf( b"%s%s%s:%d\0" as *const u8 as *const libc::c_char, if ipv6_ip as i32 != 0 { b"[\0" as *const u8 as *const libc::c_char @@ -358,83 +358,83 @@ b"\0" as *const u8 as *const libc::c_char }, remote_port, - ); + )}; if hostheader.is_null() { return CURLE_OUT_OF_MEMORY; } - if (Curl_checkProxyheaders(data, conn, b"Host\0" as *const u8 as *const libc::c_char)).is_null() + if unsafe{(Curl_checkProxyheaders(data, conn, b"Host\0" as *const u8 as *const libc::c_char)).is_null()} { - host = curl_maprintf( + host = unsafe{curl_maprintf( b"Host: %s\r\n\0" as *const u8 as *const libc::c_char, hostheader, - ); + )}; if host.is_null() { #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(hostheader as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(hostheader as *mut libc::c_void);} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( hostheader as *mut libc::c_void, 240 as i32, b"http_proxy.c\0" as *const u8 as *const libc::c_char, - ); + );} return CURLE_OUT_OF_MEMORY; } } + unsafe{ *connecthostp = hostheader; - *hostp = host; + *hostp = host;} return CURLE_OK; } - } - #[cfg(all(not(CURL_DISABLE_PROXY), not(CURL_DISABLE_HTTP), not(USE_HYPER)))] +// #[cfg(all(not(CURL_DISABLE_PROXY), not(CURL_DISABLE_HTTP), not(USE_HYPER)))] +#[cfg(all(not(CURL_DISABLE_PROXY), not(CURL_DISABLE_HTTP), not(USE_HYPER)))] extern "C" fn CONNECT( mut data: *mut Curl_easy, mut sockindex: i32, mut hostname: *const libc::c_char, mut remote_port: i32, ) -> CURLcode { - unsafe{ let mut subversion: i32 = 0 as i32; - let mut k: *mut SingleRequest = &mut (*data).req; + let mut k: *mut SingleRequest = unsafe{&mut (*data).req}; let mut result: CURLcode = CURLE_OK; - let mut conn: *mut connectdata = (*data).conn; - let mut tunnelsocket: curl_socket_t = (*conn).sock[sockindex as usize]; - let mut s: *mut http_connect_state = (*conn).connect_state; - let mut http: *mut HTTP = (*data).req.p.http; + let mut conn: *mut connectdata = unsafe{(*data).conn}; + let mut tunnelsocket: curl_socket_t = unsafe{(*conn).sock[sockindex as usize]}; + let mut s: *mut http_connect_state =unsafe{ (*conn).connect_state}; + let mut http: *mut HTTP =unsafe{ (*data).req.p.http}; let mut linep: *mut libc::c_char = 0 as *mut libc::c_char; let mut perline: size_t = 0; if Curl_connect_complete(conn) { return CURLE_OK; /* CONNECT is already completed */ } // let ref mut fresh6 = (*conn).bits; - ((*conn).bits).set_proxy_connect_closed(0 as bit); + unsafe{((*conn).bits).set_proxy_connect_closed(0 as bit)}; loop { let mut check: timediff_t = 0; - if TUNNEL_INIT as u32 == (*s).tunnel_state as u32 { + if TUNNEL_INIT as u32 == unsafe{(*s).tunnel_state as u32} { /* BEGIN CONNECT PHASE */ - let mut req: *mut dynbuf = &mut (*s).req; + let mut req: *mut dynbuf = unsafe{&mut (*s).req}; let mut hostheader: *mut libc::c_char = 0 as *mut libc::c_char; let mut host: *mut libc::c_char = 0 as *mut libc::c_char; - Curl_infof( + unsafe{Curl_infof( data, b"Establish HTTP proxy tunnel to %s:%d\0" as *const u8 as *const libc::c_char, hostname, remote_port, - ); + );} /* This only happens if we've looped here due to authentication reasons, and we don't really use the newly cloned URL here then. Just free() it. */ #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")((*data).req.newurl as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")((*data).req.newurl as *mut libc::c_void);} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( (*data).req.newurl as *mut libc::c_void, 287 as i32, b"http_proxy.c\0" as *const u8 as *const libc::c_char, - ); + );} // let ref mut fresh7 = (*data).req.newurl; - (*data).req.newurl = 0 as *mut libc::c_char; + unsafe{(*data).req.newurl = 0 as *mut libc::c_char; /* initialize send-buffer */ - Curl_dyn_init(req, (1024 as i32 * 1024 as i32) as size_t); + Curl_dyn_init(req, (1024 as i32 * 1024 as i32) as size_t)}; /* Setup the proxy-authorization header, if any */ result = CONNECT_host( data, @@ -447,23 +447,23 @@ if result as u64 != 0 { return result; } - result = Curl_http_output_auth( + result = unsafe{Curl_http_output_auth( data, conn, b"CONNECT\0" as *const u8 as *const libc::c_char, HTTPREQ_GET, hostheader, 1 as i32 != 0, - ); + )}; if result as u64 == 0 { - let mut httpv: *const libc::c_char = if (*conn).http_proxy.proxytype as u32 + let mut httpv: *const libc::c_char = if unsafe{ (*conn).http_proxy.proxytype as u32} == CURLPROXY_HTTP_1_0 as u32 { b"1.0\0" as *const u8 as *const libc::c_char } else { b"1.1\0" as *const u8 as *const libc::c_char }; - result = Curl_dyn_addf( + result = unsafe{Curl_dyn_addf( req, b"CONNECT %s HTTP/%s\r\n%s%s\0" as *const u8 as *const libc::c_char, hostheader, /* Host: */ @@ -478,191 +478,192 @@ } else { b"\0" as *const u8 as *const libc::c_char }, - ); + )}; if result as u64 == 0 - && (Curl_checkProxyheaders( + && unsafe{(Curl_checkProxyheaders( data, conn, b"User-Agent\0" as *const u8 as *const libc::c_char, )) - .is_null() - && !((*data).set.str_0[STRING_USERAGENT as usize]).is_null() + .is_null()} + && unsafe{!((*data).set.str_0[STRING_USERAGENT as usize]).is_null()} { - result = Curl_dyn_addf( + result = unsafe{Curl_dyn_addf( req, b"User-Agent: %s\r\n\0" as *const u8 as *const libc::c_char, (*data).set.str_0[STRING_USERAGENT as usize], - ); + )}; } if result as u64 == 0 - && (Curl_checkProxyheaders( + && unsafe{(Curl_checkProxyheaders( data, conn, b"Proxy-Connection\0" as *const u8 as *const libc::c_char, )) - .is_null() + .is_null()} { /* CRLF terminate the request */ - result = Curl_dyn_add( + result = unsafe{Curl_dyn_add( req, b"Proxy-Connection: Keep-Alive\r\n\0" as *const u8 as *const libc::c_char, - ); + )}; } if result as u64 == 0 { /* Send the connect request to the proxy */ - result = Curl_add_custom_headers(data, 1 as i32 != 0, req); + result = unsafe{Curl_add_custom_headers(data, 1 as i32 != 0, req)}; } if result as u64 == 0 { - result = Curl_dyn_add(req, b"\r\n\0" as *const u8 as *const libc::c_char); + result = unsafe{Curl_dyn_add(req, b"\r\n\0" as *const u8 as *const libc::c_char)}; } if result as u64 == 0 { - result = Curl_buffer_send( + result = unsafe{Curl_buffer_send( req, data, &mut (*data).info.request_size, 0 as curl_off_t, sockindex, - ); + )}; } if result as u64 != 0 { - Curl_failf( + unsafe{Curl_failf( data, b"Failed sending CONNECT to proxy\0" as *const u8 as *const libc::c_char, - ); + );} } } #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(host as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(host as *mut libc::c_void);} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( host as *mut libc::c_void, 340 as i32, b"http_proxy.c\0" as *const u8 as *const libc::c_char, - ); + );} #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(hostheader as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")(hostheader as *mut libc::c_void);} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( hostheader as *mut libc::c_void, 341 as i32, b"http_proxy.c\0" as *const u8 as *const libc::c_char, - ); + );} if result as u64 != 0 { return result; } - (*s).tunnel_state = TUNNEL_CONNECT;/* END CONNECT PHASE */ + unsafe{(*s).tunnel_state = TUNNEL_CONNECT;}/* END CONNECT PHASE */ } - check = Curl_timeleft(data, 0 as *mut curltime, 1 as i32 != 0); + check = unsafe{Curl_timeleft(data, 0 as *mut curltime, 1 as i32 != 0)}; if check <= 0 as i64 { - Curl_failf( + unsafe{ Curl_failf( data, b"Proxy CONNECT aborted due to timeout\0" as *const u8 as *const libc::c_char, - ); + );} return CURLE_OPERATION_TIMEDOUT; } - if !Curl_conn_data_pending(conn, sockindex) && (*http).sending as u64 == 0 { + if unsafe{!Curl_conn_data_pending(conn, sockindex)} && unsafe{(*http).sending as u64 }== 0 { return CURLE_OK; /* return so we'll be called again polling-style */ } /* at this point, the tunnel_connecting phase is over. */ - if (*http).sending as u32 == HTTPSEND_REQUEST as u32 { - if (*s).nsend == 0 { + if unsafe{(*http).sending as u32 }== HTTPSEND_REQUEST as u32 { + if unsafe{(*s).nsend} == 0 { let mut fillcount: size_t = 0; // let ref mut fresh8 = (*k).upload_fromhere; - (*k).upload_fromhere = (*data).state.ulbuf; + unsafe{(*k).upload_fromhere = (*data).state.ulbuf; result = Curl_fillreadbuffer( data, (*data).set.upload_buffer_size as size_t, &mut fillcount, - ); + );} if result as u64 != 0 { return result; } - (*s).nsend = fillcount; + unsafe{(*s).nsend = fillcount;} } - if (*s).nsend != 0 { + if unsafe{(*s).nsend }!= 0 { let mut bytes_written: ssize_t = 0; /* write to socket (send away data) */ - result = Curl_write( + result = unsafe{Curl_write( data, (*conn).writesockfd, /* socket to send to */ (*k).upload_fromhere as *const libc::c_void, /* buffer pointer */ (*s).nsend, /* buffer size */ &mut bytes_written, /* actually sent */ - ); + )}; if result as u64 == 0 { /* send to debug callback! */ - result = Curl_debug( + result = unsafe{Curl_debug( data, CURLINFO_HEADER_OUT, (*k).upload_fromhere, bytes_written as size_t, - ) as CURLcode; + ) as CURLcode}; } // let ref mut fresh9 = (*s).nsend; - (*s).nsend = ((*s).nsend as u64).wrapping_sub(bytes_written as u64) + unsafe{(*s).nsend = ((*s).nsend as u64).wrapping_sub(bytes_written as u64) as size_t as size_t; // let ref mut fresh10 = (*k).upload_fromhere; - (*k).upload_fromhere = ((*k).upload_fromhere).offset(bytes_written as isize); + (*k).upload_fromhere = ((*k).upload_fromhere).offset(bytes_written as isize);} return result; } - (*http).sending = HTTPSEND_NADA; + unsafe{(*http).sending = HTTPSEND_NADA;} /* if nothing left to send, continue */ } /* READING RESPONSE PHASE */ let mut error: i32 = 0 as i32; - while (*s).keepon as u64 != 0 { + while unsafe{(*s).keepon as u64} != 0 { let mut gotbytes: ssize_t = 0; let mut byte: libc::c_char = 0; /* Read one byte at a time to avoid a race condition. Wait at most one second before looping to ensure continuous pgrsUpdates. */ - result = Curl_read( + result = unsafe{Curl_read( data, tunnelsocket, &mut byte, 1 as size_t, &mut gotbytes, - ); + )}; if result as u32 == CURLE_AGAIN as u32 { /* socket buffer drained, return */ return CURLE_OK; } - if Curl_pgrsUpdate(data) != 0 { + if unsafe{Curl_pgrsUpdate(data)} != 0 { return CURLE_ABORTED_BY_CALLBACK; } if result as u64 != 0 { - (*s).keepon = KEEPON_DONE; + unsafe{(*s).keepon = KEEPON_DONE;} break; } else if gotbytes <= 0 as i64 { - if (*data).set.proxyauth != 0 - && (*data).state.authproxy.avail != 0 - && !((*data).state.aptr.proxyuserpwd).is_null() + if unsafe{(*data).set.proxyauth} != 0 + && unsafe{(*data).state.authproxy.avail} != 0 + && unsafe{!((*data).state.aptr.proxyuserpwd).is_null()} { /* proxy auth was requested and there was proxy auth available, then deem this as "mere" proxy disconnect */ // let ref mut fresh11 = (*conn).bits; - ((*conn).bits).set_proxy_connect_closed(1 as bit); + unsafe{((*conn).bits).set_proxy_connect_closed(1 as bit); Curl_infof( data, b"Proxy CONNECT connection closed\0" as *const u8 as *const libc::c_char, - ); + );} } else { error = 1 as i32; + unsafe{ Curl_failf( data, b"Proxy CONNECT aborted\0" as *const u8 as *const libc::c_char, - ); + );} } - (*s).keepon = KEEPON_DONE; + unsafe{ (*s).keepon = KEEPON_DONE;} break; - } else if (*s).keepon as u32 == KEEPON_IGNORE as u32 { + } else if unsafe{(*s).keepon as u32} == KEEPON_IGNORE as u32 { /* This means we are currently ignoring a response-body */ - if (*s).cl != 0 { + if unsafe{(*s).cl} != 0 { // let ref mut fresh12 = (*s).cl; /* A Content-Length based body: simply count down the counter and make sure to break out of the loop when we're done! */ - (*s).cl -= 1; + unsafe{(*s).cl -= 1; if !((*s).cl <= 0 as i64) { continue; } (*s).keepon = KEEPON_DONE; - (*s).tunnel_state = TUNNEL_COMPLETE; + (*s).tunnel_state = TUNNEL_COMPLETE;} break; } else { /* chunked-encoded body, so we need to do the chunked dance @@ -672,15 +673,16 @@ let mut tookcareof: ssize_t = 0 as ssize_t; /* now parse the chunked piece of data so that we can properly tell when the stream ends */ - r = Curl_httpchunk_read( + r = unsafe{Curl_httpchunk_read( data, &mut byte, 1 as ssize_t, &mut tookcareof, &mut extra, - ); + )}; if r as i32 == CHUNKE_STOP as i32 { /* we're done reading chunks! */ + unsafe{ Curl_infof( data, b"chunk reading DONE\0" as *const u8 as *const libc::c_char, @@ -688,28 +690,29 @@ (*s).keepon = KEEPON_DONE; /* we did the full CONNECT treatment, go COMPLETE */ (*s).tunnel_state = TUNNEL_COMPLETE; + } } } } else { - if Curl_dyn_addn( + if unsafe{Curl_dyn_addn( &mut (*s).rcvbuf, &mut byte as *mut libc::c_char as *const libc::c_void, 1 as size_t, - ) as u64 + ) as u64} != 0 { - Curl_failf( + unsafe{ Curl_failf( data, b"CONNECT response too large!\0" as *const u8 as *const libc::c_char, - ); + );} return CURLE_RECV_ERROR; } /* if this is not the end of a header line then continue */ if byte as i32 != 0xa as i32 { continue; } - linep = Curl_dyn_ptr(&mut (*s).rcvbuf); - perline = Curl_dyn_len(&mut (*s).rcvbuf);/* amount of bytes in this line */ + linep = unsafe{Curl_dyn_ptr(&mut (*s).rcvbuf)}; + perline = unsafe{Curl_dyn_len(&mut (*s).rcvbuf)};/* amount of bytes in this line */ /* convert from the network encoding */ result = CURLE_OK as CURLcode; /* Curl_convert_from_network calls failf if unsuccessful */ @@ -717,7 +720,7 @@ return result; } /* output debug if that is requested */ - Curl_debug(data, CURLINFO_HEADER_IN, linep, perline); + unsafe{ Curl_debug(data, CURLINFO_HEADER_IN, linep, perline); if ((*data).set).suppress_connect_headers() == 0 { /* send the header to the callback */ let mut writetype: i32 = (1 as i32) << 1 as i32; @@ -731,13 +734,15 @@ } // let ref mut fresh13 = (*data).info.header_size; (*data).info.header_size += perline as i64; + } /* Newlines are CRLF, so the CR is ignored as the line isn't really terminated until the LF comes. Treat a following CR as end-of-headers as well.*/ - if '\r' as i32 == *linep.offset(0 as isize) as i32 - || '\n' as i32 == *linep.offset(0 as isize) as i32 + if '\r' as i32 == unsafe{*linep.offset(0 as isize) as i32} + || '\n' as i32 == unsafe{*linep.offset(0 as isize) as i32} { /* end of response-headers from the proxy */ - if 407 as i32 == (*k).httpcode && ((*data).state).authproblem() == 0 { + if 407 as i32 == unsafe{(*k).httpcode} && unsafe{((*data).state).authproblem()} == 0 { + unsafe{ /* If we get a 407 response code with content length when we have no auth problem, we must ignore the whole response-body */ @@ -785,27 +790,30 @@ (*s).keepon = KEEPON_DONE; /* we did the full CONNECT treatment, go to COMPLETE */ (*s).tunnel_state = TUNNEL_COMPLETE; - } + } } else { /* without content-length or chunked encoding, we can't keep the connection alive since the close is the end signal so we bail out at once instead */ (*s).keepon = KEEPON_DONE; } - } else { - (*s).keepon = KEEPON_DONE; + } + } else { + unsafe{ + (*s).keepon = KEEPON_DONE;} } - if (*s).keepon as u32 == KEEPON_DONE as u32 - && (*s).cl == 0 - { + if unsafe{(*s).keepon as u32} == KEEPON_DONE as u32 + && unsafe{(*s).cl }== 0 + { unsafe{ /* we did the full CONNECT treatment, go to COMPLETE */ - (*s).tunnel_state = TUNNEL_COMPLETE; + (*s).tunnel_state = TUNNEL_COMPLETE;} } #[cfg(all(DEBUGBUILD, HAVE_ASSERT_H))] - if (*s).keepon as u32 == KEEPON_IGNORE as u32 - || (*s).keepon as u32 == KEEPON_DONE as u32 + if unsafe{(*s).keepon as u32} == KEEPON_IGNORE as u32 + || unsafe{(*s).keepon as u32} == KEEPON_DONE as u32 { } else { + unsafe{ __assert_fail( b"s->keepon == KEEPON_IGNORE || s->keepon == KEEPON_DONE\0" as *const u8 as *const libc::c_char, @@ -816,8 +824,10 @@ )) .as_ptr(), ); + } } } else { + unsafe{ if curl_strnequal( b"WWW-Authenticate:\0" as *const u8 as *const libc::c_char, linep, @@ -930,42 +940,45 @@ (*data).info.httpproxycode = (*k).httpcode; } Curl_dyn_reset(&mut (*s).rcvbuf); + } } /* while there's buffer left and loop is requested */ } } - if Curl_pgrsUpdate(data) != 0 { + if unsafe{Curl_pgrsUpdate(data)} != 0 { return CURLE_ABORTED_BY_CALLBACK; } if error != 0 { return CURLE_RECV_ERROR; } - if (*data).info.httpproxycode / 100 as i32 != 2 as i32 { + if unsafe{(*data).info.httpproxycode / 100 as i32 }!= 2 as i32 { /* Deal with the possibly already received authenticate headers. 'newurl' is set to a new URL if we must loop. */ - result = Curl_http_auth_act(data); + result = unsafe{Curl_http_auth_act(data)}; if result as u64 != 0 { return result; } - if ((*conn).bits).close() != 0 { + if unsafe{ ((*conn).bits).close() }!= 0 { /* the connection has been marked for closure, most likely in the Curl_http_auth_act() function and thus we can kill it at once below */ - (*s).set_close_connection(1 as bit); + unsafe{(*s).set_close_connection(1 as bit);} } } - if (*s).close_connection() as i32 != 0 && !((*data).req.newurl).is_null() { + if unsafe{(*s).close_connection() as i32} != 0 && unsafe{!((*data).req.newurl).is_null()} { + unsafe{ /* Connection closed by server. Don't use it anymore */ Curl_closesocket(data, conn, (*conn).sock[sockindex as usize]); (*conn).sock[sockindex as usize] = -(1 as i32); + } break; } else { - if !((*data).req.newurl).is_null() + if unsafe{!((*data).req.newurl).is_null()} && TUNNEL_COMPLETE as u32 - == (*s).tunnel_state as u32 + == unsafe{(*s).tunnel_state as u32} { connect_init(data, 1 as i32 != 0); } - if ((*data).req.newurl).is_null() { + if unsafe{((*data).req.newurl).is_null()} { break; } } /* END READING RESPONSE PHASE */ @@ -973,60 +986,61 @@ /* If we are supposed to continue and request a new URL, which basically * means the HTTP authentication is still going on so if the tunnel * is complete we start over in INIT state */ - if (*data).info.httpproxycode / 100 as i32 != 2 as i32 { - if (*s).close_connection() as i32 != 0 && !((*data).req.newurl).is_null() { + if unsafe{(*data).info.httpproxycode / 100 as i32} != 2 as i32 { + if unsafe{(*s).close_connection() as i32} != 0 && unsafe{!((*data).req.newurl).is_null()} { // let ref mut fresh14 = (*conn).bits; - ((*conn).bits).set_proxy_connect_closed(1 as bit); + unsafe{((*conn).bits).set_proxy_connect_closed(1 as bit); Curl_infof( data, b"Connect me again please\0" as *const u8 as *const libc::c_char, ); connect_done(data); + } } else { #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")((*data).req.newurl as *mut libc::c_void); + unsafe{Curl_cfree.expect("non-null function pointer")((*data).req.newurl as *mut libc::c_void);} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{curl_dbg_free( (*data).req.newurl as *mut libc::c_void, 663 as i32, b"http_proxy.c\0" as *const u8 as *const libc::c_char, ); // let ref mut fresh15 = (*data).req.newurl; - (*data).req.newurl = 0 as *mut libc::c_char; + (*data).req.newurl = 0 as *mut libc::c_char;} #[cfg(not(all(DEBUGBUILD, not(CURL_DISABLE_VERBOSE_STRINGS))))] - Curl_conncontrol(conn, 2 as i32); + unsafe{Curl_conncontrol(conn, 2 as i32);} #[cfg(all(DEBUGBUILD, not(CURL_DISABLE_VERBOSE_STRINGS)))] - Curl_conncontrol( + unsafe{Curl_conncontrol( conn, 2 as i32, b"proxy CONNECT failure\0" as *const u8 as *const libc::c_char, ); Curl_closesocket(data, conn, (*conn).sock[sockindex as usize]); - (*conn).sock[sockindex as usize] = -(1 as i32); + (*conn).sock[sockindex as usize] = -(1 as i32);} } - (*s).tunnel_state = TUNNEL_INIT;/* to back to init state */ - if ((*conn).bits).proxy_connect_closed() != 0 { + unsafe{(*s).tunnel_state = TUNNEL_INIT;}/* to back to init state */ + if unsafe{((*conn).bits).proxy_connect_closed()} != 0 { /* this is not an error, just part of the connection negotiation */ return CURLE_OK; } - Curl_dyn_free(&mut (*s).rcvbuf); + unsafe{Curl_dyn_free(&mut (*s).rcvbuf); Curl_failf( data, b"Received HTTP code %d from proxy after CONNECT\0" as *const u8 as *const libc::c_char, (*data).req.httpcode, - ); + );} return CURLE_RECV_ERROR; } - (*s).tunnel_state = TUNNEL_COMPLETE; + unsafe{(*s).tunnel_state = TUNNEL_COMPLETE;} /* If a proxy-authorization header was used for the proxy, then we should make sure that it isn't accidentally used for the document request after we've connected. So let's free and clear it here. */ #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")( + unsafe{Curl_cfree.expect("non-null function pointer")( (*data).state.aptr.proxyuserpwd as *mut libc::c_void, - ); + );} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{ curl_dbg_free( (*data).state.aptr.proxyuserpwd as *mut libc::c_void, 688 as i32, b"http_proxy.c\0" as *const u8 as *const libc::c_char, @@ -1049,10 +1063,9 @@ // let ref mut fresh21 = (*conn).bits; ((*conn).bits).set_rewindaftersend(0 as bit);/* make sure this isn't set for the document request */ - Curl_dyn_free(&mut (*s).rcvbuf); + Curl_dyn_free(&mut (*s).rcvbuf);} return CURLE_OK; } - } /* The Hyper version of CONNECT */ #[cfg(all(not(CURL_DISABLE_PROXY), not(CURL_DISABLE_HTTP), USE_HYPER))] extern "C" fn CONNECT( @@ -1061,12 +1074,11 @@ mut hostname: *const libc::c_char, mut remote_port: i32, ) -> CURLcode { - unsafe{ let mut current_block: u64; - let mut conn: *mut connectdata = (*data).conn; - let mut h: *mut hyptransfer = &mut (*data).hyp; - let mut tunnelsocket: curl_socket_t = (*conn).sock[sockindex as usize]; - let mut s: *mut http_connect_state = (*conn).connect_state; + let mut conn: *mut connectdata = unsafe {(*data).conn}; + let mut h: *mut hyptransfer = unsafe {&mut (*data).hyp}; + let mut tunnelsocket: curl_socket_t = unsafe {(*conn).sock[sockindex as usize]}; + let mut s: *mut http_connect_state = unsafe {(*conn).connect_state}; let mut result: CURLcode = CURLE_OUT_OF_MEMORY; let mut io: *mut hyper_io = 0 as *mut hyper_io; let mut req: *mut hyper_request = 0 as *mut hyper_request; @@ -1083,8 +1095,9 @@ return CURLE_OK;/* CONNECT is already completed */ } // let ref mut fresh6 = (*conn).bits; - ((*conn).bits).set_proxy_connect_closed(0 as bit); + unsafe {((*conn).bits).set_proxy_connect_closed(0 as bit);} 's_65: loop { + unsafe { match (*s).tunnel_state as u32 { 0 => { /* BEGIN CONNECT PHASE */ @@ -1488,15 +1501,17 @@ current_block = 14027225908442187354; break; } - } + } + } match current_block { 14027225908442187354 => { result = CURLE_OK; - if (*s).tunnel_state as u32 == TUNNEL_COMPLETE as u32 { - (*data).info.httpproxycode = (*data).req.httpcode; - if (*data).info.httpproxycode / 100 as i32 != 2 as i32 { - if ((*conn).bits).close() as i32 != 0 && !((*data).req.newurl).is_null() - { + if unsafe {(*s).tunnel_state as u32} == TUNNEL_COMPLETE as u32 { + unsafe { + (*data).info.httpproxycode = (*data).req.httpcode;} + if unsafe {(*data).info.httpproxycode / 100 as i32} != 2 as i32 { + if unsafe {((*conn).bits).close() as i32} != 0 &&unsafe { !((*data).req.newurl).is_null()} + {unsafe { // let ref mut fresh11 = (*conn).bits; ((*conn).bits).set_proxy_connect_closed(1 as bit); Curl_infof( @@ -1504,7 +1519,9 @@ b"Connect me again please\0" as *const u8 as *const libc::c_char, ); connect_done(data); + } } else { + unsafe { Curl_cfree.expect("non-null function pointer")( (*data).req.newurl as *mut libc::c_void, ); @@ -1513,15 +1530,18 @@ Curl_conncontrol(conn, 2 as i32); Curl_closesocket(data, conn, (*conn).sock[sockindex as usize]); (*conn).sock[sockindex as usize] = -(1 as i32); + } } - (*s).tunnel_state = TUNNEL_INIT; - if ((*conn).bits).proxy_connect_closed() == 0 { + unsafe { + (*s).tunnel_state = TUNNEL_INIT;} + if unsafe {((*conn).bits).proxy_connect_closed()} == 0 { + unsafe { Curl_failf( data, b"Received HTTP code %d from proxy after CONNECT\0" as *const u8 as *const libc::c_char, (*data).req.httpcode, - ); + );} result = CURLE_RECV_ERROR; } } @@ -1529,54 +1549,60 @@ } _ => {} } + unsafe { Curl_cfree.expect("non-null function pointer")(host as *mut libc::c_void); Curl_cfree.expect("non-null function pointer")(hostheader as *mut libc::c_void); + } if !io.is_null() { + unsafe { hyper_io_free(io); + } } if !options.is_null() { - hyper_clientconn_options_free(options); + unsafe { + hyper_clientconn_options_free(options);} } if !handshake.is_null() { - hyper_task_free(handshake); + unsafe { + hyper_task_free(handshake);} } if !hypererr.is_null() { let mut errbuf: [uint8_t; 256] = [0; 256]; - let mut errlen: size_t = hyper_error_print( + let mut errlen: size_t = unsafe {hyper_error_print( hypererr, errbuf.as_mut_ptr(), ::std::mem::size_of::<[uint8_t; 256]>() as u64, - ); + )}; + unsafe { Curl_failf( data, b"Hyper: %.*s\0" as *const u8 as *const libc::c_char, errlen as i32, errbuf.as_mut_ptr(), ); - hyper_error_free(hypererr); + hyper_error_free(hypererr);} } return result; } - } + #[cfg(all(not(CURL_DISABLE_PROXY), not(CURL_DISABLE_HTTP)))] #[no_mangle] pub extern "C" fn Curl_connect_free(mut data: *mut Curl_easy) { - unsafe{ - let mut conn: *mut connectdata = (*data).conn; - let mut s: *mut http_connect_state = (*conn).connect_state; + let mut conn: *mut connectdata = unsafe{ (*data).conn}; + let mut s: *mut http_connect_state = unsafe{ (*conn).connect_state}; if !s.is_null() { #[cfg(not(CURLDEBUG))] - Curl_cfree.expect("non-null function pointer")(s as *mut libc::c_void); + unsafe{ Curl_cfree.expect("non-null function pointer")(s as *mut libc::c_void);} #[cfg(CURLDEBUG)] - curl_dbg_free( + unsafe{ curl_dbg_free( s as *mut libc::c_void, 968 as i32, b"http_proxy.c\0" as *const u8 as *const libc::c_char, ); // let ref mut fresh22 = (*conn).connect_state; - (*conn).connect_state = 0 as *mut http_connect_state; + (*conn).connect_state = 0 as *mut http_connect_state;} } - } + } #[cfg(all(not(CURL_DISABLE_PROXY), not(CURL_DISABLE_HTTP)))] #[no_mangle] @@ -1586,21 +1612,21 @@ mut hostname: *const libc::c_char, mut remote_port: i32, ) -> CURLcode { - unsafe{ + let mut result: CURLcode = CURLE_OK; - let mut conn: *mut connectdata = (*data).conn; - if ((*conn).connect_state).is_null() { - result = connect_init(data, 0 as i32 != 0); + let mut conn: *mut connectdata = unsafe{ (*data).conn}; + if unsafe{ ((*conn).connect_state).is_null() }{ + result = unsafe{ connect_init(data, 0 as i32 != 0)}; if result as u64 != 0 { return result; } } - result = CONNECT(data, sockindex, hostname, remote_port); - if result as u32 != 0 || Curl_connect_complete(conn) as i32 != 0 { + result = unsafe{ CONNECT(data, sockindex, hostname, remote_port)}; + if result as u32 != 0 || unsafe{ Curl_connect_complete(conn) as i32} != 0 { connect_done(data); } return result; - } + } /*