Skip to content

Commit

Permalink
finalize: allocator always 1st-ish arg
Browse files Browse the repository at this point in the history
  • Loading branch information
renerocksai committed Jan 9, 2024
1 parent a84204d commit 1e1b5f5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions examples/bindataformpost/bindataformpost.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand All @@ -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});
Expand Down
2 changes: 1 addition & 1 deletion examples/cookies/cookies.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions examples/http_params/http_params.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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")) {
Expand Down
8 changes: 4 additions & 4 deletions src/http_auth.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_http_params.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
}
Expand Down
14 changes: 7 additions & 7 deletions src/zap.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -454,11 +454,11 @@ pub const Request = struct {
// this is thread-safe, guaranteed by fio
var 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;
},
Expand Down Expand Up @@ -507,11 +507,11 @@ pub const Request = struct {
// this is thread-safe, guaranteed by fio
var 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;
},
Expand Down Expand Up @@ -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);
}
};

Expand Down Expand Up @@ -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 };
},
Expand Down

0 comments on commit 1e1b5f5

Please sign in to comment.