From eca4d511f0130fd874a79e6c3a5f90babd55b0e0 Mon Sep 17 00:00:00 2001 From: Rene Schallner Date: Tue, 9 Jan 2024 10:55:27 +0100 Subject: [PATCH] finalize: allocator always 1st-ish arg --- examples/bindataformpost/bindataformpost.zig | 4 ++-- examples/cookies/cookies.zig | 2 +- examples/http_params/http_params.zig | 4 ++-- src/http_auth.zig | 8 ++++---- src/tests/test_http_params.zig | 2 +- src/zap.zig | 14 +++++++------- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/examples/bindataformpost/bindataformpost.zig b/examples/bindataformpost/bindataformpost.zig index e75f56a..0cbdcce 100644 --- a/examples/bindataformpost/bindataformpost.zig +++ b/examples/bindataformpost/bindataformpost.zig @@ -56,7 +56,7 @@ const Handler = struct { else => { // might be a string param, we don't care // let's just get it as string - if (r.getParamStr(kv.key.str, Handler.alloc, false)) |maybe_str| { + if (r.getParamStr(Handler.alloc, kv.key.str, false)) |maybe_str| { const value: []const u8 = if (maybe_str) |s| s.str else "(no value)"; std.log.debug(" {s} = {s}", .{ kv.key.str, value }); } else |err| { @@ -68,7 +68,7 @@ const Handler = struct { } // check if we received a terminate=true parameter - if (r.getParamStr("terminate", Handler.alloc, false)) |maybe_str| { + if (r.getParamStr(Handler.alloc, "terminate", false)) |maybe_str| { if (maybe_str) |*s| { defer s.deinit(); std.log.info("?terminate={s}\n", .{s.str}); diff --git a/examples/cookies/cookies.zig b/examples/cookies/cookies.zig index 6f0498b..d80cafc 100644 --- a/examples/cookies/cookies.zig +++ b/examples/cookies/cookies.zig @@ -61,7 +61,7 @@ pub fn main() !void { // let's get cookie "ZIG_ZAP" by name std.debug.print("\n", .{}); - if (r.getCookieStr("ZIG_ZAP", alloc, false)) |maybe_str| { + if (r.getCookieStr(alloc, "ZIG_ZAP", false)) |maybe_str| { if (maybe_str) |*s| { defer s.deinit(); diff --git a/examples/http_params/http_params.zig b/examples/http_params/http_params.zig index 7005654..38f34dd 100644 --- a/examples/http_params/http_params.zig +++ b/examples/http_params/http_params.zig @@ -66,7 +66,7 @@ pub fn main() !void { // let's get param "one" by name std.debug.print("\n", .{}); - if (r.getParamStr("one", alloc, false)) |maybe_str| { + if (r.getParamStr(alloc, "one", false)) |maybe_str| { if (maybe_str) |*s| { defer s.deinit(); @@ -82,7 +82,7 @@ pub fn main() !void { } // check if we received a terminate=true parameter - if (r.getParamStr("terminate", alloc, false)) |maybe_str| { + if (r.getParamStr(alloc, "terminate", false)) |maybe_str| { if (maybe_str) |*s| { defer s.deinit(); if (std.mem.eql(u8, s.str, "true")) { diff --git a/src/http_auth.zig b/src/http_auth.zig index e5e8e34..3cc8ac7 100644 --- a/src/http_auth.zig +++ b/src/http_auth.zig @@ -449,7 +449,7 @@ pub fn UserPassSessionAuth(comptime Lookup: type, comptime lockedPwLookups: bool r.parseCookies(false); // check for session cookie - if (r.getCookieStr(self.settings.cookieName, self.allocator, false)) |maybe_cookie| { + if (r.getCookieStr(self.allocator, self.settings.cookieName, false)) |maybe_cookie| { if (maybe_cookie) |cookie| { defer cookie.deinit(); self.tokenLookupLock.lock(); @@ -485,7 +485,7 @@ pub fn UserPassSessionAuth(comptime Lookup: type, comptime lockedPwLookups: bool r.parseCookies(false); // check for session cookie - if (r.getCookieStr(self.settings.cookieName, self.allocator, false)) |maybe_cookie| { + if (r.getCookieStr(self.allocator, self.settings.cookieName, false)) |maybe_cookie| { if (maybe_cookie) |cookie| { defer cookie.deinit(); // locked or unlocked token lookup @@ -507,10 +507,10 @@ pub fn UserPassSessionAuth(comptime Lookup: type, comptime lockedPwLookups: bool } // get params of username and password - if (r.getParamStr(self.settings.usernameParam, self.allocator, false)) |maybe_username| { + if (r.getParamStr(self.allocator, self.settings.usernameParam, false)) |maybe_username| { if (maybe_username) |*username| { defer username.deinit(); - if (r.getParamStr(self.settings.passwordParam, self.allocator, false)) |maybe_pw| { + if (r.getParamStr(self.allocator, self.settings.passwordParam, false)) |maybe_pw| { if (maybe_pw) |*pw| { defer pw.deinit(); diff --git a/src/tests/test_http_params.zig b/src/tests/test_http_params.zig index fdf84be..4bb4789 100644 --- a/src/tests/test_http_params.zig +++ b/src/tests/test_http_params.zig @@ -45,7 +45,7 @@ test "http parameters" { // true -> make copies of temp strings params = r.parametersToOwnedList(alloc, true) catch unreachable; - var maybe_str = r.getParamStr("one", alloc, true) catch unreachable; + var maybe_str = r.getParamStr(alloc, "one", true) catch unreachable; if (maybe_str) |*s| { paramOneStr = s.*; } diff --git a/src/zap.zig b/src/zap.zig index e5ec1aa..f64f2bb 100644 --- a/src/zap.zig +++ b/src/zap.zig @@ -370,7 +370,7 @@ pub const Request = struct { if (value == fio.FIOBJ_INVALID) { return null; } - return try util.fio2strAllocOrNot(value, a, always_alloc); + return try util.fio2strAllocOrNot(a, value, always_alloc); } /// Returns the number of cookies after parsing. @@ -454,11 +454,11 @@ pub const Request = struct { // this is thread-safe, guaranteed by fio const fiobj_key: fio.FIOBJ = fio.fiobj_hash_key_in_loop(); ctx.params.append(.{ - .key = util.fio2strAllocOrNot(fiobj_key, ctx.allocator, ctx.always_alloc) catch |err| { + .key = util.fio2strAllocOrNot(ctx.allocator, fiobj_key, ctx.always_alloc) catch |err| { ctx.last_error = err; return -1; }, - .value = util.fio2strAllocOrNot(fiobj_value, ctx.allocator, ctx.always_alloc) catch |err| { + .value = util.fio2strAllocOrNot(ctx.allocator, fiobj_value, ctx.always_alloc) catch |err| { ctx.last_error = err; return -1; }, @@ -507,11 +507,11 @@ pub const Request = struct { // this is thread-safe, guaranteed by fio const fiobj_key: fio.FIOBJ = fio.fiobj_hash_key_in_loop(); ctx.params.append(.{ - .key = util.fio2strAllocOrNot(fiobj_key, ctx.allocator, ctx.dupe_strings) catch |err| { + .key = util.fio2strAllocOrNot(ctx.allocator, fiobj_key, ctx.dupe_strings) catch |err| { ctx.last_error = err; return -1; }, - .value = Fiobj2HttpParam(fiobj_value, ctx.allocator, ctx.dupe_strings) catch |err| { + .value = Fiobj2HttpParam(ctx.allocator, fiobj_value, ctx.dupe_strings) catch |err| { ctx.last_error = err; return -1; }, @@ -546,7 +546,7 @@ pub const Request = struct { if (value == fio.FIOBJ_INVALID) { return null; } - return try util.fio2strAllocOrNot(value, a, always_alloc); + return try util.fio2strAllocOrNot(a, value, always_alloc); } }; @@ -764,7 +764,7 @@ pub fn Fiobj2HttpParam(a: std.mem.Allocator, o: fio.FIOBJ, dupe_string: bool) !? fio.FIOBJ_T_FALSE => .{ .Bool = false }, fio.FIOBJ_T_NUMBER => .{ .Int = fio.fiobj_obj2num(o) }, fio.FIOBJ_T_FLOAT => .{ .Float = fio.fiobj_obj2float(o) }, - fio.FIOBJ_T_STRING => .{ .String = try util.fio2strAllocOrNot(o, a, dupe_string) }, + fio.FIOBJ_T_STRING => .{ .String = try util.fio2strAllocOrNot(a, o, dupe_string) }, fio.FIOBJ_T_ARRAY => { return .{ .Unsupported = null }; },