Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add source_ipv4, source_ipv6 functions in EspHttpRawConnection #539

Merged
merged 14 commits into from
Jan 1, 2025

Conversation

indexds
Copy link
Contributor

@indexds indexds commented Dec 28, 2024

Thank you for your contribution!

We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:

Submission Checklist 📝

  • I have updated existing examples or added new ones (if applicable).
  • I have used cargo fmt command to ensure that all changed code is formatted correctly.
  • I have used cargo clippy command to ensure that all changed code passes latest Clippy nightly lints.
  • My changes were added to the CHANGELOG.md in the proper section.

Pull Request Details 📖

Description

My attempt at #538. It works flawlessly on my end.

Testing

    http_server.fn_handler("/", Method::Get, {
        move |mut request| {
            let html = "hello world";

            let connection = request.connection();

            log::info!("SOURCE IP: {}", connection.raw_connection()?.source_ip()?);

            connection.initiate_response(200, Some("OK"), &[("Content-Type", "text/html")])?;

            connection.write(html.as_bytes())?;

            Ok::<(), Error>(())
        }
    })?;
I (00:00:10.545) esp_netif_lwip: DHCP server assigned IP to a client, IP is: 192.168.100.2
I (00:00:12.947) charizhard::http: SOURCE IP: 192.168.100.2

fixes #538

@indexds
Copy link
Contributor Author

indexds commented Dec 28, 2024

Huh. Clippy doesn't complain on 5.2.3 but does on 5.1.2. What's going on here?

@indexds
Copy link
Contributor Author

indexds commented Dec 28, 2024

mod c_char_definition {
    cfg_if! {
        // These are the targets on which c_char is unsigned.
        if #[cfg(any(
            all(
                target_os = "linux",
                any(
                    target_arch = "aarch64",
                    target_arch = "arm",
                    target_arch = "hexagon",
                    target_arch = "powerpc",
                    target_arch = "powerpc64",
                    target_arch = "s390x",
                    target_arch = "riscv64",
                    target_arch = "riscv32",
                    target_arch = "csky"
                )
            ),
            all(target_os = "android", any(target_arch = "aarch64", target_arch = "arm")),
            all(target_os = "l4re", target_arch = "x86_64"),
            all(
                any(target_os = "freebsd", target_os = "openbsd"),
                any(
                    target_arch = "aarch64",
                    target_arch = "arm",
                    target_arch = "powerpc",
                    target_arch = "powerpc64",
                    target_arch = "riscv64"
                )
            ),
            all(
                target_os = "netbsd",
                any(
                    target_arch = "aarch64",
                    target_arch = "arm",
                    target_arch = "powerpc",
                    target_arch = "riscv64"
                )
            ),
            all(
                target_os = "vxworks",
                any(
                    target_arch = "aarch64",
                    target_arch = "arm",
                    target_arch = "powerpc64",
                    target_arch = "powerpc"
                )
            ),
            all(
                target_os = "fuchsia",
                any(target_arch = "aarch64", target_arch = "riscv64")
            ),
            all(target_os = "nto", target_arch = "aarch64"),
            target_os = "horizon",
            target_os = "aix",
        ))] {
            pub type c_char = u8;
        } else {
            // On every other target, c_char is signed.
            pub type c_char = i8;
        }
    }
}

So i'm pretty sure this is what's causing the problem. Do I just paste that cfg in the offending places? That's gonna be ugly

@indexds indexds changed the title Add source_ip function in EspHttpRawConnection Add source_ip4, source_ip6 functions in EspHttpRawConnection Dec 28, 2024
src/http/server.rs Outdated Show resolved Hide resolved
src/http/server.rs Outdated Show resolved Hide resolved
src/http/server.rs Outdated Show resolved Hide resolved
@indexds
Copy link
Contributor Author

indexds commented Jan 1, 2025

UUuuuh everything just broke locally and on the CI, what's going on with the sys crate?

rror[E0433]: failed to resolve: use of undeclared crate or module `bindgen`
   --> C:\Program Files\Rust\.cargo\git\checkouts\esp-idf-sys-d4c2e811b42d99d6\e2795ac\build/build.rs:101:39
    |
101 |     let configure_bindgen = |bindgen: bindgen::Builder| {  
    |                                       ^^^^^^^ use of undeclared crate or module `bindgen`
    |
help: consider importing one of these modules
    |
1   + use crate::bindgen_utils::bindgen;
    |
1   + use embuild::bindgen::bindgen;
    |

warning: unused import: `embuild::bindgen::BindgenExt`
 --> C:\Program Files\Rust\.cargo\git\checkouts\esp-idf-sys-d4c2e811b42d99d6\e2795ac\build/build.rs:6:5
  |
6 | use embuild::bindgen::BindgenExt;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

For more information about this error, try `rustc --explain E0433`.
warning: `esp-idf-sys` (build script) generated 1 warning
error: could not compile `esp-idf-sys` (build script) due to 1 previous error; 1 warning emitted

@indexds
Copy link
Contributor Author

indexds commented Jan 1, 2025

Ah, you broke it I think

esp-rs/esp-idf-sys@e2795ac

@indexds indexds changed the title Add source_ip4, source_ip6 functions in EspHttpRawConnection Add source_ipv4, source_ipv6 functions in EspHttpRawConnection Jan 1, 2025
@ivmarkov
Copy link
Collaborator

ivmarkov commented Jan 1, 2025

Ah, you broke it I think

esp-rs/esp-idf-sys@e2795ac

Should be OK now.

@indexds
Copy link
Contributor Author

indexds commented Jan 1, 2025

Is there an easy way to make an empty commit that forces the CI to re-run?

@ivmarkov
Copy link
Collaborator

ivmarkov commented Jan 1, 2025

Is there an easy way to make an empty commit that forces the CI to re-run?

I'll just bite the bullet and merge as-is. If it breaks the build, I'll fix, no worries.

@ivmarkov ivmarkov merged commit e3b1d81 into esp-rs:master Jan 1, 2025
0 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose source ip of http request
2 participants