]> PatchyGit - patchyircd.git/commitdiff
job: use std::move_only_function
authorEgor <egor@patchysicp.xyz>
Sat, 31 Jan 2026 21:02:53 +0000 (23:02 +0200)
committerEgor <egor@patchysicp.xyz>
Sat, 31 Jan 2026 21:02:53 +0000 (23:02 +0200)
src/job.cpp
src/job.hpp

index f8730b6..da040a1 100644 (file)
@@ -93,7 +93,7 @@ void job_kill(Client *cl)
 // FIXME: make a better version of this and use it throughout the codebase
 struct SecureStringWrapper {
        char *data;
-       operator char*() { return data; }
+       operator char*() const { return data; }
        SecureStringWrapper(const char *s) :data(nullptr) {
                if (s) {
                        size_t len = strlen(s);
@@ -102,12 +102,10 @@ struct SecureStringWrapper {
                        data[len] = '\0';
                }
        }
-       SecureStringWrapper(const SecureStringWrapper &) = delete;
-       SecureStringWrapper& operator=(const SecureStringWrapper &) = delete;
-       SecureStringWrapper(SecureStringWrapper &&other) {
+       SecureStringWrapper(SecureStringWrapper&& other) noexcept {
                data = std::exchange(other.data, nullptr);
        }
-       SecureStringWrapper& operator=(SecureStringWrapper &&other) {
+       SecureStringWrapper& operator=(SecureStringWrapper&& other) noexcept {
                std::swap(data, other.data);
                return *this;
        }
@@ -120,13 +118,11 @@ struct SecureStringWrapper {
 };
 static void job_password_check_internal(Client *client, const char *salt, const char *pw, contproc_t&& then)
 {
-       // FIXME: make_shared only really needed here cuz std::function wants a copyable object
-       // C++23 adds a std::move_only_function
-       job_add(client, [pw=std::make_shared<SecureStringWrapper>(pw), salt=std::make_shared<SecureStringWrapper>(salt)]() -> int {
-               if (!*salt)
+       job_add(client, [pw=SecureStringWrapper(pw), salt=SecureStringWrapper(salt)]() -> int {
+               if (!salt)
                        return 1;
-               char *hash = password_crypt(*pw, *salt);
-               int rv = !hash || strcmp(hash, *salt) != 0;
+               char *hash = password_crypt(pw, salt);
+               int rv = !hash || strcmp(hash, salt) != 0;
                if (hash)
                        memset(hash, 0, strlen(hash));
                return rv;
index 1d27887..a0ca166 100644 (file)
@@ -3,8 +3,8 @@
 #ifndef JOB_H_
 #define JOB_H_
 #include "ircdata.hpp"
-using jobproc_t = std::function<int()>;
-using contproc_t = std::function<void(int res)>;
+using jobproc_t = std::move_only_function<int()>;
+using contproc_t = std::move_only_function<void(int res)>;
 void job_init(void);
 void job_fini(void);
 void job_process(void);