diff --git a/src/bin/pushpin-handler.rs b/src/bin/pushpin-handler.rs index 4d464cc2..81673151 100644 --- a/src/bin/pushpin-handler.rs +++ b/src/bin/pushpin-handler.rs @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Fastly, Inc. + * Copyright (C) 2023-2025 Fastly, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,20 +15,20 @@ */ use clap::Parser; -use pushpin::handler::handlercliargs::ffi::HandlerCliArgs; -use pushpin::handler::handlercliargs::{destroy_handler_cli_args, CliArgs}; +use pushpin::handler::cliargs::ffi::HandlerCliArgs; +use pushpin::handler::cliargs::{destroy_handler_cli_args, CliArgs}; use pushpin::import_cpp; use std::process::ExitCode; import_cpp! { - fn handler_main(args: *const HandlerCliArgs) -> libc::c_int; + fn handler_init(args: *const HandlerCliArgs) -> libc::c_int; } fn main() -> ExitCode { let cli_args = CliArgs::parse().verify(); let cli_args_ffi = cli_args.to_ffi(); - let exit_code = unsafe { handler_main(&cli_args_ffi) }; + let exit_code = unsafe { handler_init(&cli_args_ffi) }; // Clean up the allocated memory unsafe { destroy_handler_cli_args(cli_args_ffi) }; diff --git a/src/bin/pushpin-proxy.rs b/src/bin/pushpin-proxy.rs index 49165846..f6a44a71 100644 --- a/src/bin/pushpin-proxy.rs +++ b/src/bin/pushpin-proxy.rs @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Fastly, Inc. + * Copyright (C) 2023-2025 Fastly, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,19 +16,19 @@ use clap::Parser; use pushpin::import_cpp; -use pushpin::proxy::proxycliargs::ffi::ProxyCliArgs; -use pushpin::proxy::proxycliargs::{destroy_proxy_cli_args, CliArgs}; +use pushpin::proxy::cliargs::ffi::ProxyCliArgs; +use pushpin::proxy::cliargs::{destroy_proxy_cli_args, CliArgs}; use std::process::ExitCode; import_cpp! { - fn proxy_main(args: *const ProxyCliArgs) -> libc::c_int; + fn proxy_init(args: *const ProxyCliArgs) -> libc::c_int; } fn main() -> ExitCode { let cli_args = CliArgs::parse().verify(); let cli_args_ffi = cli_args.to_ffi(); - let exit_code = unsafe { proxy_main(&cli_args_ffi) }; + let exit_code = unsafe { proxy_init(&cli_args_ffi) }; // Clean up the allocated memory unsafe { destroy_proxy_cli_args(cli_args_ffi) }; diff --git a/src/handler/handlercliargs.rs b/src/handler/cliargs.rs similarity index 100% rename from src/handler/handlercliargs.rs rename to src/handler/cliargs.rs diff --git a/src/handler/handler.pri b/src/handler/handler.pri index 4645e37b..4ecbfba4 100644 --- a/src/handler/handler.pri +++ b/src/handler/handler.pri @@ -27,9 +27,7 @@ HEADERS += \ $$PWD/filter.h \ $$PWD/filterstack.h \ $$PWD/handlerengine.h \ - $$PWD/handlerapp.h \ - $$PWD/main.h \ - $$PWD/handlerargsdata.h + $$PWD/handlerargsdata.h SOURCES += \ $$PWD/deferred.cpp \ @@ -56,6 +54,5 @@ SOURCES += \ $$PWD/filter.cpp \ $$PWD/filterstack.cpp \ $$PWD/handlerengine.cpp \ - $$PWD/handlerapp.cpp \ - $$PWD/handlermain.cpp \ - $$PWD/handlerargsdata.cpp + $$PWD/handlerargsdata.cpp \ + $$PWD/handlerapp.cpp diff --git a/src/handler/handlerapp.cpp b/src/handler/handlerapp.cpp index 8d27e204..f94ea482 100644 --- a/src/handler/handlerapp.cpp +++ b/src/handler/handlerapp.cpp @@ -21,17 +21,15 @@ * $FANOUT_END_LICENSE$ */ -#include "handlerapp.h" -#include "handlerargsdata.h" -#include "rust/bindings.h" - #include +#include #include #include #include #include #include #include +#include "rust/bindings.h" #include "timer.h" #include "defercall.h" #include "eventloop.h" @@ -42,9 +40,9 @@ #include "wssession.h" #include "httpsessionupdatemanager.h" #include "settings.h" -#include "handlerengine.h" #include "config.h" -#include +#include "handlerengine.h" +#include "handlerargsdata.h" #define DEFAULT_HTTP_MAX_HEADERS_SIZE 10000 #define DEFAULT_HTTP_MAX_BODY_SIZE 1000000 @@ -85,6 +83,18 @@ static QString firstSpec(const QString &s, int peerCount) return s; } +class HandlerApp +{ +public: + HandlerApp(); + ~HandlerApp(); + + int run(const ffi::HandlerCliArgs *argsFfi); + +private: + class Private; +}; + class HandlerApp::Private { public: @@ -379,4 +389,21 @@ HandlerApp::~HandlerApp() = default; int HandlerApp::run(const ffi::HandlerCliArgs *argsFfi) { return Private::run(argsFfi); -} \ No newline at end of file +} + +extern "C" { + +int handler_init(const ffi::HandlerCliArgs *argsFfi) +{ + // Create dummy argc/argv for QCoreApplication + int argc = 1; + char app_name[] = "pushpin-handler"; + char* argv[] = { app_name, nullptr }; + + QCoreApplication qapp(argc, argv); + + HandlerApp app; + return app.run(argsFfi); +} + +} diff --git a/src/handler/handlerapp.h b/src/handler/handlerapp.h deleted file mode 100644 index 708e8073..00000000 --- a/src/handler/handlerapp.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2016 Fanout, Inc. - * Copyright (C) 2025 Fastly, Inc. - * - * This file is part of Pushpin. - * - * $FANOUT_BEGIN_LICENSE:APACHE2$ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * $FANOUT_END_LICENSE$ - */ - -#ifndef HANDLERAPP_H -#define HANDLERAPP_H -#include "rust/bindings.h" - -class HandlerApp -{ -public: - HandlerApp(); - ~HandlerApp(); - - int run(const ffi::HandlerCliArgs *argsFfi); - -private: - class Private; -}; - -#endif diff --git a/src/handler/handlermain.cpp b/src/handler/handlermain.cpp deleted file mode 100644 index de726e25..00000000 --- a/src/handler/handlermain.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2016 Fanout, Inc. - * Copyright (C) 2024-2025 Fastly, Inc. - * - * This file is part of Pushpin. - * - * $FANOUT_BEGIN_LICENSE:APACHE2$ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * $FANOUT_END_LICENSE$ - */ - -#include -#include "handlerapp.h" -#include "rust/bindings.h" - -extern "C" { - - int handler_main(const ffi::HandlerCliArgs *argsFfi) - { - // Create dummy argc/argv for QCoreApplication - int argc = 1; - char app_name[] = "pushpin-handler"; - char* argv[] = { app_name, nullptr }; - - QCoreApplication qapp(argc, argv); - - HandlerApp app; - return app.run(argsFfi); - } - -} diff --git a/src/handler/mod.rs b/src/handler/mod.rs index 14855ffe..ec4cf5e5 100644 --- a/src/handler/mod.rs +++ b/src/handler/mod.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -pub mod handlercliargs; +pub mod cliargs; #[cfg(test)] mod tests { diff --git a/src/proxy/app.h b/src/proxy/app.h deleted file mode 100644 index 1eee90ff..00000000 --- a/src/proxy/app.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2016 Fanout, Inc. - * Copyright (C) 2025 Fastly, Inc. - * - * This file is part of Pushpin. - * - * $FANOUT_BEGIN_LICENSE:APACHE2$ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * $FANOUT_END_LICENSE$ - */ - -#ifndef APP_H -#define APP_H - -#include "rust/bindings.h" - -class App -{ -public: - App(); - ~App(); - - int run(const ffi::ProxyCliArgs *argsFfi); - -private: - class Private; -}; - -#endif diff --git a/src/proxy/proxycliargs.rs b/src/proxy/cliargs.rs similarity index 100% rename from src/proxy/proxycliargs.rs rename to src/proxy/cliargs.rs diff --git a/src/proxy/main.cpp b/src/proxy/main.cpp deleted file mode 100644 index 9a006bea..00000000 --- a/src/proxy/main.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2016 Fanout, Inc. - * Copyright (C) 2025 Fastly, Inc. - * - * This file is part of Pushpin. - * - * $FANOUT_BEGIN_LICENSE:APACHE2$ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * $FANOUT_END_LICENSE$ - */ - -#include -#include "app.h" -#include "rust/bindings.h" - -extern "C" { - -int proxy_main(const ffi::ProxyCliArgs *argsFfi) -{ - // Create dummy argc/argv for QCoreApplication - int argc = 1; - char app_name[] = "pushpin-proxy"; - char* argv[] = { app_name, nullptr }; - - QCoreApplication qapp(argc, argv); - - App app; - return app.run(argsFfi); -} - -} diff --git a/src/proxy/main.h b/src/proxy/main.h deleted file mode 100644 index 96a92e5e..00000000 --- a/src/proxy/main.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef PROXY_MAIN_H -#define PROXY_MAIN_H - -#include "rust/bindings.h" - -int proxy_main(const ffi::ProxyCliArgs *argsFfi); - -#endif diff --git a/src/proxy/mod.rs b/src/proxy/mod.rs index df36d8d0..7f3cec2d 100644 --- a/src/proxy/mod.rs +++ b/src/proxy/mod.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -pub mod proxycliargs; +pub mod cliargs; #[cfg(test)] mod tests { diff --git a/src/proxy/proxy.pri b/src/proxy/proxy.pri index d57cd59e..3999e801 100644 --- a/src/proxy/proxy.pri +++ b/src/proxy/proxy.pri @@ -19,10 +19,8 @@ HEADERS += \ $$PWD/proxyutil.h \ $$PWD/proxysession.h \ $$PWD/wsproxysession.h \ - $$PWD/engine.h \ - $$PWD/app.h \ - $$PWD/main.h \ - $$PWD/proxyargsdata.h + $$PWD/proxyengine.h \ + $$PWD/proxyargsdata.h SOURCES += \ $$PWD/testhttprequest.cpp \ @@ -43,7 +41,6 @@ SOURCES += \ $$PWD/proxyutil.cpp \ $$PWD/proxysession.cpp \ $$PWD/wsproxysession.cpp \ - $$PWD/engine.cpp \ - $$PWD/app.cpp \ - $$PWD/main.cpp \ - $$PWD/proxyargsdata.cpp + $$PWD/proxyengine.cpp \ + $$PWD/proxyargsdata.cpp \ + $$PWD/proxyapp.cpp diff --git a/src/proxy/app.cpp b/src/proxy/proxyapp.cpp similarity index 97% rename from src/proxy/app.cpp rename to src/proxy/proxyapp.cpp index af56e0a8..6e5bf856 100644 --- a/src/proxy/app.cpp +++ b/src/proxy/proxyapp.cpp @@ -21,13 +21,12 @@ * $FANOUT_END_LICENSE$ */ -#include "app.h" -#include "proxyargsdata.h" -#include "rust/bindings.h" - #include +#include +#include #include #include +#include #include #include #include @@ -35,6 +34,7 @@ #include #include #include +#include "rust/bindings.h" #include "eventloop.h" #include "processquit.h" #include "timer.h" @@ -44,11 +44,9 @@ #include "settings.h" #include "xffrule.h" #include "domainmap.h" -#include "engine.h" #include "config.h" -#include -#include -#include +#include "proxyengine.h" +#include "proxyargsdata.h" static void trimlist(QStringList *list) { @@ -308,6 +306,18 @@ class EngineThread } }; +class App +{ +public: + App(); + ~App(); + + int run(const ffi::ProxyCliArgs *argsFfi); + +private: + class Private; +}; + class App::Private { public: @@ -680,3 +690,20 @@ int App::run(const ffi::ProxyCliArgs *argsFfi) { return Private::run(argsFfi); } + +extern "C" { + +int proxy_init(const ffi::ProxyCliArgs *argsFfi) +{ + // Create dummy argc/argv for QCoreApplication + int argc = 1; + char app_name[] = "pushpin-proxy"; + char* argv[] = { app_name, nullptr }; + + QCoreApplication qapp(argc, argv); + + App app; + return app.run(argsFfi); +} + +} diff --git a/src/proxy/engine.cpp b/src/proxy/proxyengine.cpp similarity index 99% rename from src/proxy/engine.cpp rename to src/proxy/proxyengine.cpp index ad8a82f8..89d45525 100644 --- a/src/proxy/engine.cpp +++ b/src/proxy/proxyengine.cpp @@ -21,7 +21,7 @@ * $FANOUT_END_LICENSE$ */ -#include "engine.h" +#include "proxyengine.h" #include #include "zmqsocket.h" diff --git a/src/proxy/engine.h b/src/proxy/proxyengine.h similarity index 98% rename from src/proxy/engine.h rename to src/proxy/proxyengine.h index 06728a9f..82824df2 100644 --- a/src/proxy/engine.h +++ b/src/proxy/proxyengine.h @@ -21,13 +21,13 @@ * $FANOUT_END_LICENSE$ */ -#ifndef ENGINE_H -#define ENGINE_H +#ifndef PROXYENGINE_H +#define PROXYENGINE_H +#include #include #include #include -#include #include "jwt.h" #include "xffrule.h" diff --git a/src/proxy/proxyenginetest.cpp b/src/proxy/proxyenginetest.cpp index 69099678..1224a502 100644 --- a/src/proxy/proxyenginetest.cpp +++ b/src/proxy/proxyenginetest.cpp @@ -44,7 +44,7 @@ #include "zhttpmanager.h" #include "statsmanager.h" #include "domainmap.h" -#include "engine.h" +#include "proxyengine.h" using namespace std::chrono_literals;