Ver Fonte

Fix unused parameters in server.cpp to silence clangd warnings

Fszontagh há 3 meses atrás
pai
commit
647f242fdf
4 ficheiros alterados com 39 adições e 33 exclusões
  1. 11 13
      src/auth_middleware.cpp
  2. 1 2
      src/main.cpp
  3. 27 17
      src/server.cpp
  4. 0 1
      src/user_manager.cpp

+ 11 - 13
src/auth_middleware.cpp

@@ -1,17 +1,15 @@
 #include "auth_middleware.h"
 #include <httplib.h>
-#include <algorithm>
 #include <chrono>
-#include <fstream>
 #include <iomanip>
 #include <nlohmann/json.hpp>
 #include <regex>
 #include <sstream>
+#include <utility>
 #include "logger.h"
 
-AuthMiddleware::AuthMiddleware(AuthConfig config,
-                               std::shared_ptr<UserManager> userManager)
-    : m_config(std::move(config)), m_userManager(userManager) {
+AuthMiddleware::AuthMiddleware(AuthConfig config, std::shared_ptr<UserManager> userManager)
+    : m_config(std::move(config)), m_userManager(std::move(userManager)) {
 }
 
 AuthMiddleware::~AuthMiddleware() = default;
@@ -437,7 +435,7 @@ AuthContext AuthMiddleware::createGuestContext() const {
 void AuthMiddleware::logAuthAttempt(const httplib::Request& req,
                                     const AuthContext& context,
                                     bool success) const {
-    auto now = std::chrono::system_clock::now();
+    auto now        = std::chrono::system_clock::now();
     auto time_t_now = std::chrono::system_clock::to_time_t(now);
     std::stringstream timestamp_ss;
     timestamp_ss << std::put_time(std::gmtime(&time_t_now), "%Y-%m-%dT%H:%M:%S");
@@ -446,15 +444,15 @@ void AuthMiddleware::logAuthAttempt(const httplib::Request& req,
 
     std::string clientIp  = getClientIp(req);
     std::string userAgent = getUserAgent(req);
-    std::string username = context.authenticated ? context.username : "unknown";
-    std::string status = success ? "success" : "failure";
+    std::string username  = context.authenticated ? context.username : "unknown";
+    std::string status    = success ? "success" : "failure";
 
     std::string message = "Authentication " + status + " - " +
-                         "timestamp=" + timestamp_ss.str() + ", " +
-                         "ip=" + (clientIp.empty() ? "unknown" : clientIp) + ", " +
-                         "username=" + (username.empty() ? "unknown" : username) + ", " +
-                         "path=" + req.path + ", " +
-                         "user-agent=" + (userAgent.empty() ? "unknown" : userAgent);
+                          "timestamp=" + timestamp_ss.str() + ", " +
+                          "ip=" + (clientIp.empty() ? "unknown" : clientIp) + ", " +
+                          "username=" + (username.empty() ? "unknown" : username) + ", " +
+                          "path=" + req.path + ", " +
+                          "user-agent=" + (userAgent.empty() ? "unknown" : userAgent);
 
     if (success) {
         Logger::getInstance().info(message);

+ 1 - 2
src/main.cpp

@@ -1,5 +1,4 @@
-#include <signal.h>
-#include <algorithm>
+#include <csignal>
 #include <atomic>
 #include <chrono>
 #include <filesystem>

+ 27 - 17
src/server.cpp

@@ -355,7 +355,7 @@ void Server::registerEndpoints() {
         std::cout << "UI version: " << uiVersion << std::endl;
 
         // Serve dynamic config.js that provides runtime configuration to the web UI
-        m_httpServer->Get("/ui/config.js", [this, uiVersion](const httplib::Request& req, httplib::Response& res) {
+        m_httpServer->Get("/ui/config.js", [this, uiVersion](const httplib::Request& /*req*/, httplib::Response& res) {
             // Generate JavaScript configuration with current server settings
             std::ostringstream configJs;
             configJs << "// Auto-generated configuration\n"
@@ -609,7 +609,7 @@ void Server::registerEndpoints() {
         m_httpServer->Get("/ui/.*", uiHandler);
 
         // Redirect /ui to /ui/ to ensure proper routing
-        m_httpServer->Get("/ui", [](const httplib::Request& req, httplib::Response& res) {
+        m_httpServer->Get("/ui", [](const httplib::Request& /*req*/, httplib::Response& res) {
             res.set_redirect("/ui/");
         });
     }
@@ -752,7 +752,7 @@ void Server::handleLogin(const httplib::Request& req, httplib::Response& res) {
     }
 }
 
-void Server::handleLogout(const httplib::Request& req, httplib::Response& res) {
+void Server::handleLogout(const httplib::Request& /*req*/, httplib::Response& res) {
     std::string requestId = generateRequestId();
 
     try {
@@ -831,7 +831,7 @@ void Server::handleValidateToken(const httplib::Request& req, httplib::Response&
     }
 }
 
-void Server::handleRefreshToken(const httplib::Request& req, httplib::Response& res) {
+void Server::handleRefreshToken(const httplib::Request& /*req*/, httplib::Response& res) {
     std::string requestId = generateRequestId();
 
     try {
@@ -885,7 +885,7 @@ void Server::handleGetCurrentUser(const httplib::Request& req, httplib::Response
 void Server::setupCORS() {
     // Use post-routing handler to set CORS headers after the response is generated
     // This ensures we don't duplicate headers that may be set by other handlers
-    m_httpServer->set_post_routing_handler([](const httplib::Request& req, httplib::Response& res) {
+    m_httpServer->set_post_routing_handler([](const httplib::Request& /*req*/, httplib::Response& res) {
         // Only add CORS headers if they haven't been set already
         if (!res.has_header("Access-Control-Allow-Origin")) {
             res.set_header("Access-Control-Allow-Origin", "*");
@@ -907,7 +907,7 @@ void Server::setupCORS() {
     });
 }
 
-void Server::handleHealthCheck(const httplib::Request& req, httplib::Response& res) {
+void Server::handleHealthCheck(const httplib::Request& /*req*/, httplib::Response& res) {
     try {
         nlohmann::json response = {
             {"status", "healthy"},
@@ -921,7 +921,7 @@ void Server::handleHealthCheck(const httplib::Request& req, httplib::Response& r
     }
 }
 
-void Server::handleApiStatus(const httplib::Request& req, httplib::Response& res) {
+void Server::handleApiStatus(const httplib::Request& /*req*/, httplib::Response& res) {
     try {
         nlohmann::json response = {
             {"server", {
@@ -990,8 +990,8 @@ void Server::handleModelsList(const httplib::Request& req, httplib::Response& re
         // Filter parameters
         bool includeLoaded = req.get_param_value("loaded") == "true";
         bool includeUnloaded = req.get_param_value("unloaded") == "true";
-        bool includeMetadata = req.get_param_value("include_metadata") == "true";
-        bool includeThumbnails = req.get_param_value("include_thumbnails") == "true";
+        (void)req.get_param_value("include_metadata"); // unused but kept for API compatibility
+        (void)req.get_param_value("include_thumbnails"); // unused but kept for API compatibility
 
         // Get all models
         auto allModels = m_modelManager->getAllModels();
@@ -1184,7 +1184,7 @@ void Server::handleModelsList(const httplib::Request& req, httplib::Response& re
 }
 
 
-void Server::handleQueueStatus(const httplib::Request& req, httplib::Response& res) {
+void Server::handleQueueStatus(const httplib::Request& /*req*/, httplib::Response& res) {
     try {
         if (!m_generationQueue) {
             sendErrorResponse(res, "Generation queue not available", 500);
@@ -1361,7 +1361,7 @@ void Server::handleCancelJob(const httplib::Request& req, httplib::Response& res
     }
 }
 
-void Server::handleClearQueue(const httplib::Request& req, httplib::Response& res) {
+void Server::handleClearQueue(const httplib::Request& /*req*/, httplib::Response& res) {
     try {
         if (!m_generationQueue) {
             sendErrorResponse(res, "Generation queue not available", 500);
@@ -3087,7 +3087,7 @@ void Server::handleInpainting(const httplib::Request& req, httplib::Response& re
 }
 
 // Utility endpoints
-void Server::handleSamplers(const httplib::Request& req, httplib::Response& res) {
+void Server::handleSamplers(const httplib::Request& /*req*/, httplib::Response& res) {
     try {
         nlohmann::json samplers = {
             {"samplers", {
@@ -3165,7 +3165,7 @@ void Server::handleSamplers(const httplib::Request& req, httplib::Response& res)
     }
 }
 
-void Server::handleSchedulers(const httplib::Request& req, httplib::Response& res) {
+void Server::handleSchedulers(const httplib::Request& /*req*/, httplib::Response& res) {
     try {
         nlohmann::json schedulers = {
             {"schedulers", {
@@ -3214,7 +3214,7 @@ void Server::handleSchedulers(const httplib::Request& req, httplib::Response& re
     }
 }
 
-void Server::handleParameters(const httplib::Request& req, httplib::Response& res) {
+void Server::handleParameters(const httplib::Request& /*req*/, httplib::Response& res) {
     try {
         nlohmann::json parameters = {
             {"parameters", {
@@ -3432,7 +3432,7 @@ void Server::handleEstimate(const httplib::Request& req, httplib::Response& res)
     }
 }
 
-void Server::handleConfig(const httplib::Request& req, httplib::Response& res) {
+void Server::handleConfig(const httplib::Request& /*req*/, httplib::Response& res) {
     std::string requestId = generateRequestId();
 
     try {
@@ -3467,7 +3467,7 @@ void Server::handleConfig(const httplib::Request& req, httplib::Response& res) {
     }
 }
 
-void Server::handleSystem(const httplib::Request& req, httplib::Response& res) {
+void Server::handleSystem(const httplib::Request& /*req*/, httplib::Response& res) {
     try {
         nlohmann::json system = {
             {"system", {
@@ -3505,7 +3505,7 @@ void Server::handleSystem(const httplib::Request& req, httplib::Response& res) {
     }
 }
 
-void Server::handleSystemRestart(const httplib::Request& req, httplib::Response& res) {
+void Server::handleSystemRestart(const httplib::Request& /*req*/, httplib::Response& res) {
     try {
         nlohmann::json response = {
             {"message", "Server restart initiated. The server will shut down gracefully and exit. Please use a process manager to automatically restart it."},
@@ -4142,6 +4142,8 @@ nlohmann::json Server::checkModelCompatibility(const ModelManager::ModelInfo& mo
 }
 
 nlohmann::json Server::calculateSpecificRequirements(const std::string& modelType, const std::string& resolution, const std::string& batchSize) {
+    (void)modelType; // Suppress unused parameter warning
+
     nlohmann::json specific = {
         {"memory_requirements", nlohmann::json::object()},
         {"performance_impact", nlohmann::json::object()},
@@ -4379,6 +4381,8 @@ void Server::handleUnloadModelById(const httplib::Request& req, httplib::Respons
 }
 
 void Server::handleModelTypes(const httplib::Request& req, httplib::Response& res) {
+    (void)req; // Suppress unused parameter warning
+
     std::string requestId = generateRequestId();
 
     try {
@@ -4449,6 +4453,8 @@ void Server::handleModelTypes(const httplib::Request& req, httplib::Response& re
 }
 
 void Server::handleModelDirectories(const httplib::Request& req, httplib::Response& res) {
+    (void)req; // Suppress unused parameter warning
+
     std::string requestId = generateRequestId();
 
     try {
@@ -4496,6 +4502,8 @@ void Server::handleModelDirectories(const httplib::Request& req, httplib::Respon
 }
 
 void Server::handleRefreshModels(const httplib::Request& req, httplib::Response& res) {
+    (void)req; // Suppress unused parameter warning
+
     std::string requestId = generateRequestId();
 
     try {
@@ -4662,6 +4670,8 @@ void Server::handleConvertModel(const httplib::Request& req, httplib::Response&
 }
 
 void Server::handleModelStats(const httplib::Request& req, httplib::Response& res) {
+    (void)req; // Suppress unused parameter warning
+
     std::string requestId = generateRequestId();
 
     try {

+ 0 - 1
src/user_manager.cpp

@@ -5,7 +5,6 @@
 #include <filesystem>
 #include <sstream>
 #include <iomanip>
-#include <algorithm>
 #include <regex>
 #include <crypt.h>
 #include <unistd.h>