mirror of
https://github.com/zigzap/zap.git
synced 2025-10-21 15:44:10 +00:00
1.fix 0.12.0-dev.2334+aef1da163 build
This commit is contained in:
parent
518199fca5
commit
bd75fcdbbd
24 changed files with 184 additions and 164 deletions
35
build.zig
35
build.zig
|
@ -1,9 +1,9 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const build_facilio = @import("facil.io/build.zig").build_facilio;
|
const build_facilio = @import("facil.io/build.zig").build_facilio;
|
||||||
|
|
||||||
pub fn build(b: *std.build.Builder) !void {
|
pub fn build(b: *std.Build) !void {
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
if (target.getOsTag() == .windows) {
|
if (target.result.os.tag == .windows) {
|
||||||
std.log.err("\x1b[31mPlatform Not Supported\x1b[0m\nCurrently, Facil.io and Zap are not compatible with Windows. Consider using Linux or Windows Subsystem for Linux (WSL) instead.\nFor more information, please see:\n- https://github.com/zigzap/zap#most-faq\n- https://facil.io/#forking-contributing-and-all-that-jazz\n", .{});
|
std.log.err("\x1b[31mPlatform Not Supported\x1b[0m\nCurrently, Facil.io and Zap are not compatible with Windows. Consider using Linux or Windows Subsystem for Linux (WSL) instead.\nFor more information, please see:\n- https://github.com/zigzap/zap#most-faq\n- https://facil.io/#forking-contributing-and-all-that-jazz\n", .{});
|
||||||
std.os.exit(1);
|
std.os.exit(1);
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,9 @@ pub fn build(b: *std.build.Builder) !void {
|
||||||
};
|
};
|
||||||
|
|
||||||
// create a module to be used internally.
|
// create a module to be used internally.
|
||||||
var zap_module = b.createModule(.{
|
const zap_module = b.addModule("zap",.{
|
||||||
.source_file = .{ .path = "src/zap.zig" },
|
.root_source_file = .{ .path = "src/zap.zig" },
|
||||||
});
|
});
|
||||||
|
|
||||||
// register the module so it can be referenced using the package manager.
|
|
||||||
try b.modules.put(b.dupe("zap"), zap_module);
|
|
||||||
|
|
||||||
const facilio = try build_facilio("facil.io", b, target, optimize, use_openssl);
|
const facilio = try build_facilio("facil.io", b, target, optimize, use_openssl);
|
||||||
|
|
||||||
|
@ -84,12 +81,12 @@ pub fn build(b: *std.build.Builder) !void {
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
|
example.root_module.addImport("zap",zap_module);
|
||||||
example.linkLibrary(facilio);
|
example.linkLibrary(facilio);
|
||||||
example.addModule("zap", zap_module);
|
|
||||||
|
|
||||||
// const example_run = example.run();
|
// const example_run = example.run();
|
||||||
const example_run = b.addRunArtifact(example);
|
const example_run = b.addRunArtifact(example);
|
||||||
|
|
||||||
example_run_step.dependOn(&example_run.step);
|
example_run_step.dependOn(&example_run.step);
|
||||||
|
|
||||||
// install the artifact - depending on the "example"
|
// install the artifact - depending on the "example"
|
||||||
|
@ -125,10 +122,10 @@ pub fn build(b: *std.build.Builder) !void {
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
auth_tests.linkLibrary(facilio);
|
auth_tests.linkLibrary(facilio);
|
||||||
auth_tests.addModule("zap", zap_module);
|
auth_tests.root_module.addImport("zap", zap_module);
|
||||||
|
|
||||||
const run_auth_tests = b.addRunArtifact(auth_tests);
|
const run_auth_tests = b.addRunArtifact(auth_tests);
|
||||||
const install_auth_tests = b.addInstallArtifact(auth_tests, .{});
|
// const install_auth_tests = b.addInstallArtifact(auth_tests, .{});
|
||||||
|
|
||||||
// mustache tests
|
// mustache tests
|
||||||
const mustache_tests = b.addTest(.{
|
const mustache_tests = b.addTest(.{
|
||||||
|
@ -138,7 +135,7 @@ pub fn build(b: *std.build.Builder) !void {
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
mustache_tests.linkLibrary(facilio);
|
mustache_tests.linkLibrary(facilio);
|
||||||
mustache_tests.addModule("zap", zap_module);
|
mustache_tests.root_module.addImport("zap", zap_module);
|
||||||
|
|
||||||
const run_mustache_tests = b.addRunArtifact(mustache_tests);
|
const run_mustache_tests = b.addRunArtifact(mustache_tests);
|
||||||
const install_mustache_tests = b.addInstallArtifact(mustache_tests, .{});
|
const install_mustache_tests = b.addInstallArtifact(mustache_tests, .{});
|
||||||
|
@ -152,7 +149,7 @@ pub fn build(b: *std.build.Builder) !void {
|
||||||
});
|
});
|
||||||
|
|
||||||
httpparams_tests.linkLibrary(facilio);
|
httpparams_tests.linkLibrary(facilio);
|
||||||
httpparams_tests.addModule("zap", zap_module);
|
httpparams_tests.root_module.addImport("zap", zap_module);
|
||||||
const run_httpparams_tests = b.addRunArtifact(httpparams_tests);
|
const run_httpparams_tests = b.addRunArtifact(httpparams_tests);
|
||||||
// TODO: for some reason, tests aren't run more than once unless
|
// TODO: for some reason, tests aren't run more than once unless
|
||||||
// dependencies have changed.
|
// dependencies have changed.
|
||||||
|
@ -169,14 +166,14 @@ pub fn build(b: *std.build.Builder) !void {
|
||||||
});
|
});
|
||||||
|
|
||||||
sendfile_tests.linkLibrary(facilio);
|
sendfile_tests.linkLibrary(facilio);
|
||||||
sendfile_tests.addModule("zap", zap_module);
|
sendfile_tests.root_module.addImport("zap", zap_module);
|
||||||
const run_sendfile_tests = b.addRunArtifact(sendfile_tests);
|
const run_sendfile_tests = b.addRunArtifact(sendfile_tests);
|
||||||
const install_sendfile_tests = b.addInstallArtifact(sendfile_tests, .{});
|
const install_sendfile_tests = b.addInstallArtifact(sendfile_tests, .{});
|
||||||
|
|
||||||
// test commands
|
// test commands
|
||||||
const run_auth_test_step = b.step("test-authentication", "Run auth unit tests [REMOVE zig-cache!]");
|
const run_auth_test_step = b.step("test-authentication", "Run auth unit tests [REMOVE zig-cache!]");
|
||||||
run_auth_test_step.dependOn(&run_auth_tests.step);
|
run_auth_test_step.dependOn(&run_auth_tests.step);
|
||||||
run_auth_test_step.dependOn(&install_auth_tests.step);
|
// run_auth_test_step.dependOn(&install_auth_tests.step);
|
||||||
|
|
||||||
const run_mustache_test_step = b.step("test-mustache", "Run mustache unit tests [REMOVE zig-cache!]");
|
const run_mustache_test_step = b.step("test-mustache", "Run mustache unit tests [REMOVE zig-cache!]");
|
||||||
run_mustache_test_step.dependOn(&run_mustache_tests.step);
|
run_mustache_test_step.dependOn(&run_mustache_tests.step);
|
||||||
|
@ -202,7 +199,7 @@ pub fn build(b: *std.build.Builder) !void {
|
||||||
//
|
//
|
||||||
// pkghash
|
// pkghash
|
||||||
//
|
//
|
||||||
var pkghash_exe = b.addExecutable(.{
|
const pkghash_exe = b.addExecutable(.{
|
||||||
.name = "pkghash",
|
.name = "pkghash",
|
||||||
.root_source_file = .{ .path = "./tools/pkghash.zig" },
|
.root_source_file = .{ .path = "./tools/pkghash.zig" },
|
||||||
.target = target,
|
.target = target,
|
||||||
|
@ -216,13 +213,13 @@ pub fn build(b: *std.build.Builder) !void {
|
||||||
//
|
//
|
||||||
// announceybot
|
// announceybot
|
||||||
//
|
//
|
||||||
var announceybot_exe = b.addExecutable(.{
|
const announceybot_exe = b.addExecutable(.{
|
||||||
.name = "announceybot",
|
.name = "announceybot",
|
||||||
.root_source_file = .{ .path = "./tools/announceybot.zig" },
|
.root_source_file = .{ .path = "./tools/announceybot.zig" },
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
var announceybot_step = b.step("announceybot", "Build announceybot");
|
const announceybot_step = b.step("announceybot", "Build announceybot");
|
||||||
const announceybot_build_step = b.addInstallArtifact(announceybot_exe, .{});
|
const announceybot_build_step = b.addInstallArtifact(announceybot_exe, .{});
|
||||||
announceybot_step.dependOn(&announceybot_build_step.step);
|
announceybot_step.dependOn(&announceybot_build_step.step);
|
||||||
all_step.dependOn(&announceybot_build_step.step);
|
all_step.dependOn(&announceybot_build_step.step);
|
||||||
|
|
|
@ -1 +1,11 @@
|
||||||
.{ .name = "zap", .version = "0.6.0" }
|
.{
|
||||||
|
.name = "zap",
|
||||||
|
.version = "0.6.1",
|
||||||
|
|
||||||
|
.dependencies = .{
|
||||||
|
},
|
||||||
|
|
||||||
|
.paths = .{
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ const Handler = struct {
|
||||||
// check for query params (for ?terminate=true)
|
// check for query params (for ?terminate=true)
|
||||||
r.parseQuery();
|
r.parseQuery();
|
||||||
|
|
||||||
var param_count = r.getParamCount();
|
const param_count = r.getParamCount();
|
||||||
std.log.info("param_count: {}", .{param_count});
|
std.log.info("param_count: {}", .{param_count});
|
||||||
|
|
||||||
// iterate over all params
|
// iterate over all params
|
||||||
|
@ -87,7 +87,7 @@ pub fn main() !void {
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||||
.thread_safe = true,
|
.thread_safe = true,
|
||||||
}){};
|
}){};
|
||||||
var allocator = gpa.allocator();
|
const allocator = gpa.allocator();
|
||||||
|
|
||||||
Handler.alloc = allocator;
|
Handler.alloc = allocator;
|
||||||
|
|
||||||
|
|
|
@ -11,12 +11,14 @@ fn makeRequest(a: std.mem.Allocator, url: []const u8) !void {
|
||||||
var http_client: std.http.Client = .{ .allocator = a };
|
var http_client: std.http.Client = .{ .allocator = a };
|
||||||
defer http_client.deinit();
|
defer http_client.deinit();
|
||||||
|
|
||||||
var req = try http_client.request(.GET, uri, h, .{});
|
var result = try http_client.fetch(a,.{
|
||||||
defer req.deinit();
|
.method = .GET,
|
||||||
|
.location = .{
|
||||||
try req.headers.append("cookie", "ZIG_ZAP=awesome");
|
.uri = uri,
|
||||||
try req.start();
|
},
|
||||||
try req.wait();
|
.headers = h,
|
||||||
|
});
|
||||||
|
defer result.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn makeRequestThread(a: std.mem.Allocator, url: []const u8) !std.Thread {
|
fn makeRequestThread(a: std.mem.Allocator, url: []const u8) !std.Thread {
|
||||||
|
@ -28,7 +30,7 @@ pub fn main() !void {
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||||
.thread_safe = true,
|
.thread_safe = true,
|
||||||
}){};
|
}){};
|
||||||
var allocator = gpa.allocator();
|
const allocator = gpa.allocator();
|
||||||
|
|
||||||
const Handler = struct {
|
const Handler = struct {
|
||||||
var alloc: std.mem.Allocator = undefined;
|
var alloc: std.mem.Allocator = undefined;
|
||||||
|
@ -39,7 +41,7 @@ pub fn main() !void {
|
||||||
|
|
||||||
r.parseCookies(false);
|
r.parseCookies(false);
|
||||||
|
|
||||||
var cookie_count = r.getCookiesCount();
|
const cookie_count = r.getCookiesCount();
|
||||||
std.log.info("cookie_count: {}", .{cookie_count});
|
std.log.info("cookie_count: {}", .{cookie_count});
|
||||||
|
|
||||||
// iterate over all cookies as strings
|
// iterate over all cookies as strings
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub fn main() !void {
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||||
.thread_safe = true,
|
.thread_safe = true,
|
||||||
}){};
|
}){};
|
||||||
var allocator = gpa.allocator();
|
const allocator = gpa.allocator();
|
||||||
|
|
||||||
// we scope everything that can allocate within this block for leak detection
|
// we scope everything that can allocate within this block for leak detection
|
||||||
{
|
{
|
||||||
|
|
|
@ -41,12 +41,12 @@ pub fn addByName(self: *Self, first: ?[]const u8, last: ?[]const u8) !usize {
|
||||||
user.lastnamelen = 0;
|
user.lastnamelen = 0;
|
||||||
|
|
||||||
if (first) |firstname| {
|
if (first) |firstname| {
|
||||||
std.mem.copy(u8, user.firstnamebuf[0..], firstname);
|
std.mem.copyForwards(u8, user.firstnamebuf[0..], firstname);
|
||||||
user.firstnamelen = firstname.len;
|
user.firstnamelen = firstname.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (last) |lastname| {
|
if (last) |lastname| {
|
||||||
std.mem.copy(u8, user.lastnamebuf[0..], lastname);
|
std.mem.copyForwards(u8, user.lastnamebuf[0..], lastname);
|
||||||
user.lastnamelen = lastname.len;
|
user.lastnamelen = lastname.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,11 +101,11 @@ pub fn update(
|
||||||
pUser.firstnamelen = 0;
|
pUser.firstnamelen = 0;
|
||||||
pUser.lastnamelen = 0;
|
pUser.lastnamelen = 0;
|
||||||
if (first) |firstname| {
|
if (first) |firstname| {
|
||||||
std.mem.copy(u8, pUser.firstnamebuf[0..], firstname);
|
std.mem.copyForwards(u8, pUser.firstnamebuf[0..], firstname);
|
||||||
pUser.firstnamelen = firstname.len;
|
pUser.firstnamelen = firstname.len;
|
||||||
}
|
}
|
||||||
if (last) |lastname| {
|
if (last) |lastname| {
|
||||||
std.mem.copy(u8, pUser.lastnamebuf[0..], lastname);
|
std.mem.copyForwards(u8, pUser.lastnamebuf[0..], lastname);
|
||||||
pUser.lastnamelen = lastname.len;
|
pUser.lastnamelen = lastname.len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ fn listUsers(self: *Self, r: zap.Request) void {
|
||||||
fn postUser(e: *zap.Endpoint, r: zap.Request) void {
|
fn postUser(e: *zap.Endpoint, r: zap.Request) void {
|
||||||
const self = @fieldParentPtr(Self, "ep", e);
|
const self = @fieldParentPtr(Self, "ep", e);
|
||||||
if (r.body) |body| {
|
if (r.body) |body| {
|
||||||
var maybe_user: ?std.json.Parsed(User) = std.json.parseFromSlice(User, self.alloc, body, .{}) catch null;
|
const maybe_user: ?std.json.Parsed(User) = std.json.parseFromSlice(User, self.alloc, body, .{}) catch null;
|
||||||
if (maybe_user) |u| {
|
if (maybe_user) |u| {
|
||||||
defer u.deinit();
|
defer u.deinit();
|
||||||
if (self._users.addByName(u.value.first_name, u.value.last_name)) |id| {
|
if (self._users.addByName(u.value.first_name, u.value.last_name)) |id| {
|
||||||
|
@ -105,7 +105,7 @@ fn putUser(e: *zap.Endpoint, r: zap.Request) void {
|
||||||
if (self.userIdFromPath(path)) |id| {
|
if (self.userIdFromPath(path)) |id| {
|
||||||
if (self._users.get(id)) |_| {
|
if (self._users.get(id)) |_| {
|
||||||
if (r.body) |body| {
|
if (r.body) |body| {
|
||||||
var maybe_user: ?std.json.Parsed(User) = std.json.parseFromSlice(User, self.alloc, body, .{}) catch null;
|
const maybe_user: ?std.json.Parsed(User) = std.json.parseFromSlice(User, self.alloc, body, .{}) catch null;
|
||||||
if (maybe_user) |u| {
|
if (maybe_user) |u| {
|
||||||
defer u.deinit();
|
defer u.deinit();
|
||||||
var jsonbuf: [128]u8 = undefined;
|
var jsonbuf: [128]u8 = undefined;
|
||||||
|
|
|
@ -41,7 +41,7 @@ fn setupUserData(a: std.mem.Allocator) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
var a = std.heap.page_allocator;
|
const a = std.heap.page_allocator;
|
||||||
try setupUserData(a);
|
try setupUserData(a);
|
||||||
var listener = zap.HttpListener.init(.{
|
var listener = zap.HttpListener.init(.{
|
||||||
.port = 3000,
|
.port = 3000,
|
||||||
|
|
|
@ -11,11 +11,14 @@ fn makeRequest(a: std.mem.Allocator, url: []const u8) !void {
|
||||||
var http_client: std.http.Client = .{ .allocator = a };
|
var http_client: std.http.Client = .{ .allocator = a };
|
||||||
defer http_client.deinit();
|
defer http_client.deinit();
|
||||||
|
|
||||||
var req = try http_client.request(.GET, uri, h, .{});
|
var result = try http_client.fetch(a,.{
|
||||||
defer req.deinit();
|
.method = .GET,
|
||||||
|
.location = .{
|
||||||
try req.start();
|
.uri = uri,
|
||||||
try req.wait();
|
},
|
||||||
|
.headers = h,
|
||||||
|
});
|
||||||
|
defer result.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn makeRequestThread(a: std.mem.Allocator, url: []const u8) !std.Thread {
|
fn makeRequestThread(a: std.mem.Allocator, url: []const u8) !std.Thread {
|
||||||
|
@ -27,7 +30,7 @@ pub fn main() !void {
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||||
.thread_safe = true,
|
.thread_safe = true,
|
||||||
}){};
|
}){};
|
||||||
var allocator = gpa.allocator();
|
const allocator = gpa.allocator();
|
||||||
|
|
||||||
const Handler = struct {
|
const Handler = struct {
|
||||||
var alloc: std.mem.Allocator = undefined;
|
var alloc: std.mem.Allocator = undefined;
|
||||||
|
@ -44,7 +47,7 @@ pub fn main() !void {
|
||||||
// check for query parameters
|
// check for query parameters
|
||||||
r.parseQuery();
|
r.parseQuery();
|
||||||
|
|
||||||
var param_count = r.getParamCount();
|
const param_count = r.getParamCount();
|
||||||
std.log.info("param_count: {}", .{param_count});
|
std.log.info("param_count: {}", .{param_count});
|
||||||
|
|
||||||
// ================================================================
|
// ================================================================
|
||||||
|
|
|
@ -72,7 +72,7 @@ const UserMiddleWare = struct {
|
||||||
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
||||||
|
|
||||||
// this is how we would get our self pointer
|
// this is how we would get our self pointer
|
||||||
var self = @fieldParentPtr(Self, "handler", handler);
|
const self = @fieldParentPtr(Self, "handler", handler);
|
||||||
_ = self;
|
_ = self;
|
||||||
|
|
||||||
// do our work: fill in the user field of the context
|
// do our work: fill in the user field of the context
|
||||||
|
@ -115,7 +115,7 @@ const SessionMiddleWare = struct {
|
||||||
// note that the first parameter is of type *Handler, not *Self !!!
|
// note that the first parameter is of type *Handler, not *Self !!!
|
||||||
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
||||||
// this is how we would get our self pointer
|
// this is how we would get our self pointer
|
||||||
var self = @fieldParentPtr(Self, "handler", handler);
|
const self = @fieldParentPtr(Self, "handler", handler);
|
||||||
_ = self;
|
_ = self;
|
||||||
|
|
||||||
context.session = Session{
|
context.session = Session{
|
||||||
|
@ -151,7 +151,7 @@ const HtmlMiddleWare = struct {
|
||||||
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
||||||
|
|
||||||
// this is how we would get our self pointer
|
// this is how we would get our self pointer
|
||||||
var self = @fieldParentPtr(Self, "handler", handler);
|
const self = @fieldParentPtr(Self, "handler", handler);
|
||||||
_ = self;
|
_ = self;
|
||||||
|
|
||||||
std.debug.print("\n\nHtmlMiddleware: handling request with context: {any}\n\n", .{context});
|
std.debug.print("\n\nHtmlMiddleware: handling request with context: {any}\n\n", .{context});
|
||||||
|
@ -190,7 +190,7 @@ pub fn main() !void {
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||||
.thread_safe = true,
|
.thread_safe = true,
|
||||||
}){};
|
}){};
|
||||||
var allocator = gpa.allocator();
|
const allocator = gpa.allocator();
|
||||||
SharedAllocator.init(allocator);
|
SharedAllocator.init(allocator);
|
||||||
|
|
||||||
// we create our HTML middleware component that handles the request
|
// we create our HTML middleware component that handles the request
|
||||||
|
|
|
@ -60,7 +60,7 @@ const UserMiddleWare = struct {
|
||||||
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
||||||
|
|
||||||
// this is how we would get our self pointer
|
// this is how we would get our self pointer
|
||||||
var self = @fieldParentPtr(Self, "handler", handler);
|
const self = @fieldParentPtr(Self, "handler", handler);
|
||||||
_ = self;
|
_ = self;
|
||||||
|
|
||||||
// do our work: fill in the user field of the context
|
// do our work: fill in the user field of the context
|
||||||
|
@ -105,7 +105,7 @@ const SessionMiddleWare = struct {
|
||||||
// note that the first parameter is of type *Handler, not *Self !!!
|
// note that the first parameter is of type *Handler, not *Self !!!
|
||||||
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
||||||
// this is how we would get our self pointer
|
// this is how we would get our self pointer
|
||||||
var self = @fieldParentPtr(Self, "handler", handler);
|
const self = @fieldParentPtr(Self, "handler", handler);
|
||||||
_ = self;
|
_ = self;
|
||||||
|
|
||||||
context.session = Session{
|
context.session = Session{
|
||||||
|
@ -200,7 +200,7 @@ pub fn main() !void {
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||||
.thread_safe = true,
|
.thread_safe = true,
|
||||||
}){};
|
}){};
|
||||||
var allocator = gpa.allocator();
|
const allocator = gpa.allocator();
|
||||||
SharedAllocator.init(allocator);
|
SharedAllocator.init(allocator);
|
||||||
|
|
||||||
// create the endpoint
|
// create the endpoint
|
||||||
|
|
|
@ -73,7 +73,7 @@ pub fn main() !void {
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||||
.thread_safe = true,
|
.thread_safe = true,
|
||||||
}){};
|
}){};
|
||||||
var allocator = gpa.allocator();
|
const allocator = gpa.allocator();
|
||||||
|
|
||||||
var simpleRouter = zap.Router.init(allocator, .{
|
var simpleRouter = zap.Router.init(allocator, .{
|
||||||
.not_found = not_found,
|
.not_found = not_found,
|
||||||
|
|
|
@ -46,8 +46,8 @@ const ContextManager = struct {
|
||||||
self.lock.lock();
|
self.lock.lock();
|
||||||
defer self.lock.unlock();
|
defer self.lock.unlock();
|
||||||
|
|
||||||
var ctx = try self.allocator.create(Context);
|
const ctx = try self.allocator.create(Context);
|
||||||
var userName = try std.fmt.allocPrint(
|
const userName = try std.fmt.allocPrint(
|
||||||
self.allocator,
|
self.allocator,
|
||||||
"{s}{d}",
|
"{s}{d}",
|
||||||
.{ self.usernamePrefix, self.contexts.items.len },
|
.{ self.usernamePrefix, self.contexts.items.len },
|
||||||
|
@ -202,7 +202,7 @@ pub fn main() !void {
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||||
.thread_safe = true,
|
.thread_safe = true,
|
||||||
}){};
|
}){};
|
||||||
var allocator = gpa.allocator();
|
const allocator = gpa.allocator();
|
||||||
|
|
||||||
GlobalContextManager = ContextManager.init(allocator, "chatroom", "user-");
|
GlobalContextManager = ContextManager.init(allocator, "chatroom", "user-");
|
||||||
defer GlobalContextManager.deinit();
|
defer GlobalContextManager.deinit();
|
||||||
|
|
|
@ -2,11 +2,11 @@ const std = @import("std");
|
||||||
|
|
||||||
pub fn build_facilio(
|
pub fn build_facilio(
|
||||||
comptime subdir: []const u8,
|
comptime subdir: []const u8,
|
||||||
b: *std.build.Builder,
|
b: *std.Build,
|
||||||
target: std.zig.CrossTarget,
|
target: std.Build.ResolvedTarget,
|
||||||
optimize: std.builtin.OptimizeMode,
|
optimize: std.builtin.OptimizeMode,
|
||||||
use_openssl: bool,
|
use_openssl: bool,
|
||||||
) !*std.build.CompileStep {
|
) !*std.Build.Step.Compile{
|
||||||
const lib = b.addStaticLibrary(.{
|
const lib = b.addStaticLibrary(.{
|
||||||
.name = "facil.io",
|
.name = "facil.io",
|
||||||
.target = target,
|
.target = target,
|
||||||
|
@ -15,7 +15,7 @@ pub fn build_facilio(
|
||||||
|
|
||||||
// Generate flags
|
// Generate flags
|
||||||
var flags = std.ArrayList([]const u8).init(std.heap.page_allocator);
|
var flags = std.ArrayList([]const u8).init(std.heap.page_allocator);
|
||||||
if (lib.optimize != .Debug) try flags.append("-Os");
|
if (optimize != .Debug) try flags.append("-Os");
|
||||||
try flags.append("-Wno-return-type-c-linkage");
|
try flags.append("-Wno-return-type-c-linkage");
|
||||||
try flags.append("-fno-sanitize=undefined");
|
try flags.append("-fno-sanitize=undefined");
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ pub fn build_facilio(
|
||||||
//
|
//
|
||||||
|
|
||||||
try flags.append("-DFIO_HTTP_EXACT_LOGGING");
|
try flags.append("-DFIO_HTTP_EXACT_LOGGING");
|
||||||
if (target.getAbi() == .musl)
|
if (target.result.abi == .musl)
|
||||||
try flags.append("-D_LARGEFILE64_SOURCE");
|
try flags.append("-D_LARGEFILE64_SOURCE");
|
||||||
if (use_openssl)
|
if (use_openssl)
|
||||||
try flags.append("-DHAVE_OPENSSL -DFIO_TLS_FOUND");
|
try flags.append("-DHAVE_OPENSSL -DFIO_TLS_FOUND");
|
||||||
|
@ -42,30 +42,36 @@ pub fn build_facilio(
|
||||||
lib.addIncludePath(.{ .path = subdir ++ "/lib/facil/tls" });
|
lib.addIncludePath(.{ .path = subdir ++ "/lib/facil/tls" });
|
||||||
|
|
||||||
// C source files
|
// C source files
|
||||||
lib.addCSourceFiles(&.{
|
lib.addCSourceFiles(.{
|
||||||
subdir ++ "/lib/facil/fio.c",
|
.files = &.{
|
||||||
subdir ++ "/lib/facil/fio_zig.c",
|
subdir ++ "/lib/facil/fio.c",
|
||||||
subdir ++ "/lib/facil/http/http.c",
|
subdir ++ "/lib/facil/fio_zig.c",
|
||||||
subdir ++ "/lib/facil/http/http1.c",
|
subdir ++ "/lib/facil/http/http.c",
|
||||||
subdir ++ "/lib/facil/http/websockets.c",
|
subdir ++ "/lib/facil/http/http1.c",
|
||||||
subdir ++ "/lib/facil/http/http_internal.c",
|
subdir ++ "/lib/facil/http/websockets.c",
|
||||||
subdir ++ "/lib/facil/fiobj/fiobj_numbers.c",
|
subdir ++ "/lib/facil/http/http_internal.c",
|
||||||
subdir ++ "/lib/facil/fiobj/fio_siphash.c",
|
subdir ++ "/lib/facil/fiobj/fiobj_numbers.c",
|
||||||
subdir ++ "/lib/facil/fiobj/fiobj_str.c",
|
subdir ++ "/lib/facil/fiobj/fio_siphash.c",
|
||||||
subdir ++ "/lib/facil/fiobj/fiobj_ary.c",
|
subdir ++ "/lib/facil/fiobj/fiobj_str.c",
|
||||||
subdir ++ "/lib/facil/fiobj/fiobj_data.c",
|
subdir ++ "/lib/facil/fiobj/fiobj_ary.c",
|
||||||
subdir ++ "/lib/facil/fiobj/fiobj_hash.c",
|
subdir ++ "/lib/facil/fiobj/fiobj_data.c",
|
||||||
subdir ++ "/lib/facil/fiobj/fiobj_json.c",
|
subdir ++ "/lib/facil/fiobj/fiobj_hash.c",
|
||||||
subdir ++ "/lib/facil/fiobj/fiobject.c",
|
subdir ++ "/lib/facil/fiobj/fiobj_json.c",
|
||||||
subdir ++ "/lib/facil/fiobj/fiobj_mustache.c",
|
subdir ++ "/lib/facil/fiobj/fiobject.c",
|
||||||
subdir ++ "/lib/facil/cli/fio_cli.c",
|
subdir ++ "/lib/facil/fiobj/fiobj_mustache.c",
|
||||||
}, flags.items);
|
subdir ++ "/lib/facil/cli/fio_cli.c",
|
||||||
|
},
|
||||||
|
.flags = flags.items,
|
||||||
|
});
|
||||||
|
|
||||||
if (use_openssl) {
|
if (use_openssl) {
|
||||||
lib.addCSourceFiles(&.{
|
lib.addCSourceFiles(.{
|
||||||
subdir ++ "/lib/facil/tls/fio_tls_openssl.c",
|
.files = &.{
|
||||||
subdir ++ "/lib/facil/tls/fio_tls_missing.c",
|
subdir ++ "/lib/facil/tls/fio_tls_openssl.c",
|
||||||
}, flags.items);
|
subdir ++ "/lib/facil/tls/fio_tls_missing.c",
|
||||||
|
},
|
||||||
|
.flags = flags.items
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// link against libc
|
// link against libc
|
||||||
|
|
28
src/fio.zig
28
src/fio.zig
|
@ -118,10 +118,10 @@ pub const struct_fio_str_info_s = extern struct {
|
||||||
pub const fio_str_info_s = struct_fio_str_info_s;
|
pub const fio_str_info_s = struct_fio_str_info_s;
|
||||||
pub extern fn http_send_body(h: [*c]http_s, data: ?*anyopaque, length: usize) c_int;
|
pub extern fn http_send_body(h: [*c]http_s, data: ?*anyopaque, length: usize) c_int;
|
||||||
pub fn fiobj_each1(arg_o: FIOBJ, arg_start_at: usize, arg_task: ?*const fn (FIOBJ, ?*anyopaque) callconv(.C) c_int, arg_arg: ?*anyopaque) callconv(.C) usize {
|
pub fn fiobj_each1(arg_o: FIOBJ, arg_start_at: usize, arg_task: ?*const fn (FIOBJ, ?*anyopaque) callconv(.C) c_int, arg_arg: ?*anyopaque) callconv(.C) usize {
|
||||||
var o = arg_o;
|
const o = arg_o;
|
||||||
var start_at = arg_start_at;
|
const start_at = arg_start_at;
|
||||||
var task = arg_task;
|
const task = arg_task;
|
||||||
var arg = arg_arg;
|
const arg = arg_arg;
|
||||||
if ((((o != 0) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) == @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 0)))))) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) != @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6)))))) and (fiobj_type_vtable(o).*.each != null)) return fiobj_type_vtable(o).*.each.?(o, start_at, task, arg);
|
if ((((o != 0) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) == @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 0)))))) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) != @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6)))))) and (fiobj_type_vtable(o).*.each != null)) return fiobj_type_vtable(o).*.each.?(o, start_at, task, arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -288,8 +288,8 @@ pub const fiobj_object_header_s = extern struct {
|
||||||
ref: u32,
|
ref: u32,
|
||||||
};
|
};
|
||||||
pub fn fiobj_type_is(arg_o: FIOBJ, arg_type: fiobj_type_enum) callconv(.C) usize {
|
pub fn fiobj_type_is(arg_o: FIOBJ, arg_type: fiobj_type_enum) callconv(.C) usize {
|
||||||
var o = arg_o;
|
const o = arg_o;
|
||||||
var @"type" = arg_type;
|
const @"type" = arg_type;
|
||||||
while (true) {
|
while (true) {
|
||||||
switch (@as(c_int, @bitCast(@as(c_uint, @"type")))) {
|
switch (@as(c_int, @bitCast(@as(c_uint, @"type")))) {
|
||||||
@as(c_int, 1) => return @as(usize, @bitCast(@as(c_long, @intFromBool(((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) != 0) or (@as(c_int, @bitCast(@as(c_uint, @as([*c]fiobj_type_enum, @ptrFromInt(o))[@as(c_uint, @intCast(@as(c_int, 0)))]))) == FIOBJ_T_NUMBER))))),
|
@as(c_int, 1) => return @as(usize, @bitCast(@as(c_long, @intFromBool(((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) != 0) or (@as(c_int, @bitCast(@as(c_uint, @as([*c]fiobj_type_enum, @ptrFromInt(o))[@as(c_uint, @intCast(@as(c_int, 0)))]))) == FIOBJ_T_NUMBER))))),
|
||||||
|
@ -311,7 +311,7 @@ pub fn fiobj_type_is(arg_o: FIOBJ, arg_type: fiobj_type_enum) callconv(.C) usize
|
||||||
return @as(usize, @bitCast(@as(c_long, @intFromBool((((o != 0) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) == @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 0)))))) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) != @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6)))))) and (@as(c_int, @bitCast(@as(c_uint, @as([*c]fiobj_type_enum, @ptrCast(@alignCast(@as(?*anyopaque, @ptrFromInt(o & ~@as(usize, @bitCast(@as(c_long, @as(c_int, 7)))))))))[@as(c_uint, @intCast(@as(c_int, 0)))]))) == @as(c_int, @bitCast(@as(c_uint, @"type"))))))));
|
return @as(usize, @bitCast(@as(c_long, @intFromBool((((o != 0) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) == @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 0)))))) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) != @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6)))))) and (@as(c_int, @bitCast(@as(c_uint, @as([*c]fiobj_type_enum, @ptrCast(@alignCast(@as(?*anyopaque, @ptrFromInt(o & ~@as(usize, @bitCast(@as(c_long, @as(c_int, 7)))))))))[@as(c_uint, @intCast(@as(c_int, 0)))]))) == @as(c_int, @bitCast(@as(c_uint, @"type"))))))));
|
||||||
}
|
}
|
||||||
pub fn fiobj_type(arg_o: FIOBJ) callconv(.C) fiobj_type_enum {
|
pub fn fiobj_type(arg_o: FIOBJ) callconv(.C) fiobj_type_enum {
|
||||||
var o = arg_o;
|
const o = arg_o;
|
||||||
if (!(o != 0)) return @as(u8, @bitCast(@as(i8, @truncate(FIOBJ_T_NULL))));
|
if (!(o != 0)) return @as(u8, @bitCast(@as(i8, @truncate(FIOBJ_T_NULL))));
|
||||||
if ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) != 0) return @as(u8, @bitCast(@as(i8, @truncate(FIOBJ_T_NUMBER))));
|
if ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) != 0) return @as(u8, @bitCast(@as(i8, @truncate(FIOBJ_T_NUMBER))));
|
||||||
if ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) == @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) return @as(u8, @bitCast(@as(u8, @truncate(o))));
|
if ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) == @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) return @as(u8, @bitCast(@as(u8, @truncate(o))));
|
||||||
|
@ -326,7 +326,7 @@ pub extern const FIOBJECT_VTABLE_ARRAY: fiobj_object_vtable_s;
|
||||||
pub extern const FIOBJECT_VTABLE_HASH: fiobj_object_vtable_s;
|
pub extern const FIOBJECT_VTABLE_HASH: fiobj_object_vtable_s;
|
||||||
pub extern const FIOBJECT_VTABLE_DATA: fiobj_object_vtable_s;
|
pub extern const FIOBJECT_VTABLE_DATA: fiobj_object_vtable_s;
|
||||||
pub fn fiobj_type_vtable(arg_o: FIOBJ) callconv(.C) [*c]const fiobj_object_vtable_s {
|
pub fn fiobj_type_vtable(arg_o: FIOBJ) callconv(.C) [*c]const fiobj_object_vtable_s {
|
||||||
var o = arg_o;
|
const o = arg_o;
|
||||||
while (true) {
|
while (true) {
|
||||||
switch (@as(c_int, @bitCast(@as(c_uint, fiobj_type(o))))) {
|
switch (@as(c_int, @bitCast(@as(c_uint, fiobj_type(o))))) {
|
||||||
@as(c_int, 1) => return &FIOBJECT_VTABLE_NUMBER,
|
@as(c_int, 1) => return &FIOBJECT_VTABLE_NUMBER,
|
||||||
|
@ -361,7 +361,7 @@ pub fn fiobj_obj2float(o: FIOBJ) callconv(.C) f64 {
|
||||||
pub extern fn fio_ltocstr(c_long) fio_str_info_s;
|
pub extern fn fio_ltocstr(c_long) fio_str_info_s;
|
||||||
pub fn fiobj_obj2cstr(o: FIOBJ) callconv(.C) fio_str_info_s {
|
pub fn fiobj_obj2cstr(o: FIOBJ) callconv(.C) fio_str_info_s {
|
||||||
if (!(o != 0)) {
|
if (!(o != 0)) {
|
||||||
var ret: fio_str_info_s = fio_str_info_s{
|
const ret: fio_str_info_s = fio_str_info_s{
|
||||||
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
||||||
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 4)))),
|
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 4)))),
|
||||||
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("null"))),
|
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("null"))),
|
||||||
|
@ -374,7 +374,7 @@ pub fn fiobj_obj2cstr(o: FIOBJ) callconv(.C) fio_str_info_s {
|
||||||
switch (@as(c_int, @bitCast(@as(c_uint, @as(u8, @bitCast(@as(u8, @truncate(o)))))))) {
|
switch (@as(c_int, @bitCast(@as(c_uint, @as(u8, @bitCast(@as(u8, @truncate(o)))))))) {
|
||||||
@as(c_int, 6) => {
|
@as(c_int, 6) => {
|
||||||
{
|
{
|
||||||
var ret: fio_str_info_s = fio_str_info_s{
|
const ret: fio_str_info_s = fio_str_info_s{
|
||||||
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
||||||
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 4)))),
|
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 4)))),
|
||||||
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("null"))),
|
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("null"))),
|
||||||
|
@ -384,7 +384,7 @@ pub fn fiobj_obj2cstr(o: FIOBJ) callconv(.C) fio_str_info_s {
|
||||||
},
|
},
|
||||||
@as(c_int, 38) => {
|
@as(c_int, 38) => {
|
||||||
{
|
{
|
||||||
var ret: fio_str_info_s = fio_str_info_s{
|
const ret: fio_str_info_s = fio_str_info_s{
|
||||||
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
||||||
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 5)))),
|
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 5)))),
|
||||||
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("false"))),
|
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("false"))),
|
||||||
|
@ -394,7 +394,7 @@ pub fn fiobj_obj2cstr(o: FIOBJ) callconv(.C) fio_str_info_s {
|
||||||
},
|
},
|
||||||
@as(c_int, 22) => {
|
@as(c_int, 22) => {
|
||||||
{
|
{
|
||||||
var ret: fio_str_info_s = fio_str_info_s{
|
const ret: fio_str_info_s = fio_str_info_s{
|
||||||
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
||||||
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 4)))),
|
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 4)))),
|
||||||
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("true"))),
|
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("true"))),
|
||||||
|
@ -556,8 +556,8 @@ pub extern fn http_date2rfc7231(target: [*c]u8, tmbuf: [*c]struct_tm) usize;
|
||||||
pub extern fn http_date2rfc2109(target: [*c]u8, tmbuf: [*c]struct_tm) usize;
|
pub extern fn http_date2rfc2109(target: [*c]u8, tmbuf: [*c]struct_tm) usize;
|
||||||
pub extern fn http_date2rfc2822(target: [*c]u8, tmbuf: [*c]struct_tm) usize;
|
pub extern fn http_date2rfc2822(target: [*c]u8, tmbuf: [*c]struct_tm) usize;
|
||||||
pub fn http_date2str(arg_target: [*c]u8, arg_tmbuf: [*c]struct_tm) callconv(.C) usize {
|
pub fn http_date2str(arg_target: [*c]u8, arg_tmbuf: [*c]struct_tm) callconv(.C) usize {
|
||||||
var target = arg_target;
|
const target = arg_target;
|
||||||
var tmbuf = arg_tmbuf;
|
const tmbuf = arg_tmbuf;
|
||||||
return http_date2rfc7231(target, tmbuf);
|
return http_date2rfc7231(target, tmbuf);
|
||||||
}
|
}
|
||||||
pub extern fn http_time2str(target: [*c]u8, t: time_t) usize;
|
pub extern fn http_time2str(target: [*c]u8, t: time_t) usize;
|
||||||
|
|
|
@ -122,7 +122,7 @@ pub fn Basic(comptime Lookup: type, comptime kind: BasicAuthStrategy) type {
|
||||||
);
|
);
|
||||||
return .AuthFailed;
|
return .AuthFailed;
|
||||||
}
|
}
|
||||||
var decoded = buffer[0..decoded_size];
|
const decoded = buffer[0..decoded_size];
|
||||||
decoder.decode(decoded, encoded) catch |err| {
|
decoder.decode(decoded, encoded) catch |err| {
|
||||||
zap.debug(
|
zap.debug(
|
||||||
"ERROR: UserPassAuth: unable to decode `{s}`: {any}\n",
|
"ERROR: UserPassAuth: unable to decode `{s}`: {any}\n",
|
||||||
|
@ -400,7 +400,7 @@ pub fn UserPassSession(comptime Lookup: type, comptime lockedPwLookups: bool) ty
|
||||||
lookup: *Lookup,
|
lookup: *Lookup,
|
||||||
args: UserPassSessionArgs,
|
args: UserPassSessionArgs,
|
||||||
) !Self {
|
) !Self {
|
||||||
var ret: Self = .{
|
const ret: Self = .{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.settings = .{
|
.settings = .{
|
||||||
.usernameParam = try allocator.dupe(u8, args.usernameParam),
|
.usernameParam = try allocator.dupe(u8, args.usernameParam),
|
||||||
|
|
|
@ -146,22 +146,20 @@ fn makeRequest(a: std.mem.Allocator, url: []const u8, auth: ?ClientAuthReqHeader
|
||||||
var http_client: std.http.Client = .{ .allocator = a };
|
var http_client: std.http.Client = .{ .allocator = a };
|
||||||
defer http_client.deinit();
|
defer http_client.deinit();
|
||||||
|
|
||||||
var req = try http_client.request(.GET, uri, h, .{});
|
var result = try http_client.fetch(a,.{
|
||||||
defer req.deinit();
|
.location = .{
|
||||||
|
.uri = uri,
|
||||||
try req.start();
|
},
|
||||||
try req.wait();
|
.headers = h,
|
||||||
// req.deinit() panics!
|
});
|
||||||
// defer req.deinit();
|
defer result.deinit();
|
||||||
|
|
||||||
// without this block, the tests sometimes get stuck which
|
// without this block, the tests sometimes get stuck which
|
||||||
// might have to do with connection pooling and connections being in
|
// might have to do with connection pooling and connections being in
|
||||||
// a different state when all data has been read?!?
|
// a different state when all data has been read?!?
|
||||||
{
|
{
|
||||||
var buffer: [1024]u8 = undefined;
|
if(result.body)|body|{
|
||||||
// we know we won't receive a lot
|
std.debug.print("RESPONSE:\n{s}\n", .{body[0..]});
|
||||||
const len = try req.reader().readAll(&buffer);
|
}
|
||||||
std.debug.print("RESPONSE:\n{s}\n", .{buffer[0..len]});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
zap.stop();
|
zap.stop();
|
||||||
|
|
|
@ -10,11 +10,14 @@ fn makeRequest(a: std.mem.Allocator, url: []const u8) !void {
|
||||||
var http_client: std.http.Client = .{ .allocator = a };
|
var http_client: std.http.Client = .{ .allocator = a };
|
||||||
defer http_client.deinit();
|
defer http_client.deinit();
|
||||||
|
|
||||||
var req = try http_client.request(.GET, uri, h, .{});
|
var result = try http_client.fetch(a,.{
|
||||||
defer req.deinit();
|
.method = .GET,
|
||||||
|
.location = .{
|
||||||
try req.start();
|
.uri = uri,
|
||||||
try req.wait();
|
},
|
||||||
|
.headers = h,
|
||||||
|
});
|
||||||
|
defer result.deinit();
|
||||||
zap.stop();
|
zap.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +26,7 @@ fn makeRequestThread(a: std.mem.Allocator, url: []const u8) !std.Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
test "http parameters" {
|
test "http parameters" {
|
||||||
var allocator = std.testing.allocator;
|
const allocator = std.testing.allocator;
|
||||||
|
|
||||||
const Handler = struct {
|
const Handler = struct {
|
||||||
var alloc: std.mem.Allocator = undefined;
|
var alloc: std.mem.Allocator = undefined;
|
||||||
|
|
|
@ -15,13 +15,19 @@ fn makeRequest(a: std.mem.Allocator, url: []const u8) !void {
|
||||||
var http_client: std.http.Client = .{ .allocator = a };
|
var http_client: std.http.Client = .{ .allocator = a };
|
||||||
defer http_client.deinit();
|
defer http_client.deinit();
|
||||||
|
|
||||||
var req = try http_client.request(.GET, uri, h, .{});
|
var result = try http_client.fetch(a,.{
|
||||||
defer req.deinit();
|
.method = .GET,
|
||||||
|
.location = .{
|
||||||
try req.start();
|
.uri = uri,
|
||||||
try req.wait();
|
},
|
||||||
read_len = try req.readAll(&buffer);
|
.headers = h,
|
||||||
|
});
|
||||||
|
defer result.deinit();
|
||||||
|
|
||||||
|
if(result.body)|body|{
|
||||||
|
read_len = body.len;
|
||||||
|
std.mem.copyForwards(u8,&buffer,body);
|
||||||
|
}
|
||||||
zap.stop();
|
zap.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +39,7 @@ pub fn on_request(r: zap.Request) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
test "send file" {
|
test "send file" {
|
||||||
var allocator = std.testing.allocator;
|
const allocator = std.testing.allocator;
|
||||||
|
|
||||||
// setup listener
|
// setup listener
|
||||||
var listener = zap.HttpListener.init(
|
var listener = zap.HttpListener.init(
|
||||||
|
|
|
@ -50,7 +50,7 @@ pub fn Handler(comptime ContextType: type) type {
|
||||||
|
|
||||||
/// This function will end the HTTP stage of the connection and attempt to "upgrade" to a WebSockets connection.
|
/// This function will end the HTTP stage of the connection and attempt to "upgrade" to a WebSockets connection.
|
||||||
pub fn upgrade(h: [*c]fio.http_s, settings: *WebSocketSettings) WebSocketError!void {
|
pub fn upgrade(h: [*c]fio.http_s, settings: *WebSocketSettings) WebSocketError!void {
|
||||||
var fio_settings: fio.websocket_settings_s = .{
|
const fio_settings: fio.websocket_settings_s = .{
|
||||||
.on_message = internal_on_message,
|
.on_message = internal_on_message,
|
||||||
.on_open = internal_on_open,
|
.on_open = internal_on_open,
|
||||||
.on_ready = internal_on_ready,
|
.on_ready = internal_on_ready,
|
||||||
|
@ -64,8 +64,8 @@ pub fn Handler(comptime ContextType: type) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn internal_on_message(handle: WsHandle, msg: fio.fio_str_info_s, is_text: u8) callconv(.C) void {
|
fn internal_on_message(handle: WsHandle, msg: fio.fio_str_info_s, is_text: u8) callconv(.C) void {
|
||||||
var user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
const user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
||||||
var message = msg.data[0..msg.len];
|
const message = msg.data[0..msg.len];
|
||||||
if (user_provided_settings) |settings| {
|
if (user_provided_settings) |settings| {
|
||||||
if (settings.on_message) |on_message| {
|
if (settings.on_message) |on_message| {
|
||||||
on_message(settings.context, handle, message, is_text == 1);
|
on_message(settings.context, handle, message, is_text == 1);
|
||||||
|
@ -74,7 +74,7 @@ pub fn Handler(comptime ContextType: type) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn internal_on_open(handle: WsHandle) callconv(.C) void {
|
fn internal_on_open(handle: WsHandle) callconv(.C) void {
|
||||||
var user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
const user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
||||||
if (user_provided_settings) |settings| {
|
if (user_provided_settings) |settings| {
|
||||||
if (settings.on_open) |on_open| {
|
if (settings.on_open) |on_open| {
|
||||||
on_open(settings.context, handle);
|
on_open(settings.context, handle);
|
||||||
|
@ -83,7 +83,7 @@ pub fn Handler(comptime ContextType: type) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn internal_on_ready(handle: WsHandle) callconv(.C) void {
|
fn internal_on_ready(handle: WsHandle) callconv(.C) void {
|
||||||
var user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
const user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
||||||
if (user_provided_settings) |settings| {
|
if (user_provided_settings) |settings| {
|
||||||
if (settings.on_ready) |on_ready| {
|
if (settings.on_ready) |on_ready| {
|
||||||
on_ready(settings.context, handle);
|
on_ready(settings.context, handle);
|
||||||
|
@ -92,7 +92,7 @@ pub fn Handler(comptime ContextType: type) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn internal_on_shutdown(handle: WsHandle) callconv(.C) void {
|
fn internal_on_shutdown(handle: WsHandle) callconv(.C) void {
|
||||||
var user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
const user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
||||||
if (user_provided_settings) |settings| {
|
if (user_provided_settings) |settings| {
|
||||||
if (settings.on_shutdown) |on_shutdown| {
|
if (settings.on_shutdown) |on_shutdown| {
|
||||||
on_shutdown(settings.context, handle);
|
on_shutdown(settings.context, handle);
|
||||||
|
@ -101,7 +101,7 @@ pub fn Handler(comptime ContextType: type) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn internal_on_close(uuid: isize, udata: ?*anyopaque) callconv(.C) void {
|
fn internal_on_close(uuid: isize, udata: ?*anyopaque) callconv(.C) void {
|
||||||
var user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(udata)));
|
const user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(udata)));
|
||||||
if (user_provided_settings) |settings| {
|
if (user_provided_settings) |settings| {
|
||||||
if (settings.on_close) |on_close| {
|
if (settings.on_close) |on_close| {
|
||||||
on_close(settings.context, uuid);
|
on_close(settings.context, uuid);
|
||||||
|
@ -192,7 +192,7 @@ pub fn Handler(comptime ContextType: type) type {
|
||||||
/// we need it to look up the ziggified callbacks.
|
/// we need it to look up the ziggified callbacks.
|
||||||
pub inline fn subscribe(handle: WsHandle, args: *SubscribeArgs) WebSocketError!usize {
|
pub inline fn subscribe(handle: WsHandle, args: *SubscribeArgs) WebSocketError!usize {
|
||||||
if (handle == null) return error.SubscribeError;
|
if (handle == null) return error.SubscribeError;
|
||||||
var fio_args: fio.websocket_subscribe_s_zigcompat = .{
|
const fio_args: fio.websocket_subscribe_s_zigcompat = .{
|
||||||
.ws = handle.?,
|
.ws = handle.?,
|
||||||
.channel = util.str2fio(args.channel),
|
.channel = util.str2fio(args.channel),
|
||||||
.on_message = if (args.on_message) |_| internal_subscription_on_message else null,
|
.on_message = if (args.on_message) |_| internal_subscription_on_message else null,
|
||||||
|
|
|
@ -88,7 +88,7 @@ fn get_tag_annotation(allocator: std.mem.Allocator, tagname: []const u8) ![]cons
|
||||||
tagname,
|
tagname,
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = try std.ChildProcess.exec(.{
|
const result = try std.ChildProcess.run(.{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.argv = &args,
|
.argv = &args,
|
||||||
});
|
});
|
||||||
|
@ -160,29 +160,22 @@ fn sendToDiscordPart(allocator: std.mem.Allocator, url: []const u8, message_json
|
||||||
var http_client: std.http.Client = .{ .allocator = allocator };
|
var http_client: std.http.Client = .{ .allocator = allocator };
|
||||||
defer http_client.deinit();
|
defer http_client.deinit();
|
||||||
|
|
||||||
// request
|
var result = try http_client.fetch(allocator,.{
|
||||||
var req = try http_client.request(.POST, uri, h, .{});
|
.method = .POST,
|
||||||
defer req.deinit();
|
.location = .{
|
||||||
|
.uri = uri,
|
||||||
req.transfer_encoding = .chunked;
|
},
|
||||||
|
.payload = .{
|
||||||
// connect, send request
|
.string = message_json,
|
||||||
try req.start();
|
},
|
||||||
|
});
|
||||||
// send POST payload
|
defer result.deinit();
|
||||||
try req.writer().writeAll(message_json);
|
|
||||||
try req.finish();
|
|
||||||
|
|
||||||
// wait for response
|
|
||||||
try req.wait();
|
|
||||||
var buffer: [1024]u8 = undefined;
|
|
||||||
_ = try req.readAll(&buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sendToDiscord(allocator: std.mem.Allocator, url: []const u8, message: []const u8) !void {
|
fn sendToDiscord(allocator: std.mem.Allocator, url: []const u8, message: []const u8) !void {
|
||||||
// json payload
|
// json payload
|
||||||
// max size: 100kB
|
// max size: 100kB
|
||||||
var buf: []u8 = try allocator.alloc(u8, 100 * 1024);
|
const buf: []u8 = try allocator.alloc(u8, 100 * 1024);
|
||||||
defer allocator.free(buf);
|
defer allocator.free(buf);
|
||||||
var fba = std.heap.FixedBufferAllocator.init(buf);
|
var fba = std.heap.FixedBufferAllocator.init(buf);
|
||||||
var string = std.ArrayList(u8).init(fba.allocator());
|
var string = std.ArrayList(u8).init(fba.allocator());
|
||||||
|
@ -399,7 +392,7 @@ fn command_update_readme(allocator: std.mem.Allocator, tag: []const u8) !void {
|
||||||
// we need to put the \n back in.
|
// we need to put the \n back in.
|
||||||
// TODO: change this by using some "search" iterator that just
|
// TODO: change this by using some "search" iterator that just
|
||||||
// returns indices etc
|
// returns indices etc
|
||||||
var output_line = try std.fmt.allocPrint(allocator, "{s}\n", .{line});
|
const output_line = try std.fmt.allocPrint(allocator, "{s}\n", .{line});
|
||||||
defer allocator.free(output_line);
|
defer allocator.free(output_line);
|
||||||
_ = try writer.write(output_line);
|
_ = try writer.write(output_line);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ pub const usage_pkg =
|
||||||
;
|
;
|
||||||
|
|
||||||
pub fn gitLatestTag(gpa: Allocator, pkg_dir: []const u8) ![]const u8 {
|
pub fn gitLatestTag(gpa: Allocator, pkg_dir: []const u8) ![]const u8 {
|
||||||
const result = try std.ChildProcess.exec(.{
|
const result = try std.ChildProcess.run(.{
|
||||||
.allocator = gpa,
|
.allocator = gpa,
|
||||||
.argv = &.{
|
.argv = &.{
|
||||||
"git",
|
"git",
|
||||||
|
@ -97,7 +97,7 @@ pub fn gitLatestTag(gpa: Allocator, pkg_dir: []const u8) ![]const u8 {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gitFileList(gpa: Allocator, pkg_dir: []const u8) ![]const u8 {
|
pub fn gitFileList(gpa: Allocator, pkg_dir: []const u8) ![]const u8 {
|
||||||
const result = try std.ChildProcess.exec(.{
|
const result = try std.ChildProcess.run(.{
|
||||||
.allocator = gpa,
|
.allocator = gpa,
|
||||||
.argv = &.{
|
.argv = &.{
|
||||||
"git",
|
"git",
|
||||||
|
@ -266,8 +266,7 @@ pub fn cmdPkg(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
|
||||||
|
|
||||||
// computePackageHash will close the directory after completion
|
// computePackageHash will close the directory after completion
|
||||||
// std.debug.print("abspath: {s}\n", .{cwd_absolute_path});
|
// std.debug.print("abspath: {s}\n", .{cwd_absolute_path});
|
||||||
var cwd_copy = try fs.openIterableDirAbsolute(cwd_absolute_path, .{});
|
const dir = try fs.openDirAbsolute(cwd_absolute_path, .{});
|
||||||
errdefer cwd_copy.dir.close();
|
|
||||||
|
|
||||||
var thread_pool: ThreadPool = undefined;
|
var thread_pool: ThreadPool = undefined;
|
||||||
try thread_pool.init(.{ .allocator = gpa });
|
try thread_pool.init(.{ .allocator = gpa });
|
||||||
|
@ -281,7 +280,7 @@ pub fn cmdPkg(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
|
||||||
};
|
};
|
||||||
break :blk try computePackageHashExcludingDirectories(
|
break :blk try computePackageHashExcludingDirectories(
|
||||||
&thread_pool,
|
&thread_pool,
|
||||||
.{ .dir = cwd_copy.dir },
|
dir,
|
||||||
excluded_directories,
|
excluded_directories,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -355,7 +354,7 @@ fn isExecutable(file: fs.File) !bool {
|
||||||
|
|
||||||
pub fn computePackageHashExcludingDirectories(
|
pub fn computePackageHashExcludingDirectories(
|
||||||
thread_pool: *ThreadPool,
|
thread_pool: *ThreadPool,
|
||||||
pkg_dir: fs.IterableDir,
|
pkg_dir: fs.Dir,
|
||||||
excluded_directories: []const []const u8,
|
excluded_directories: []const []const u8,
|
||||||
) ![Manifest.Hash.digest_length]u8 {
|
) ![Manifest.Hash.digest_length]u8 {
|
||||||
const gpa = thread_pool.allocator;
|
const gpa = thread_pool.allocator;
|
||||||
|
@ -405,7 +404,7 @@ pub fn computePackageHashExcludingDirectories(
|
||||||
.failure = undefined, // to be populated by the worker
|
.failure = undefined, // to be populated by the worker
|
||||||
};
|
};
|
||||||
wait_group.start();
|
wait_group.start();
|
||||||
try thread_pool.spawn(workerHashFile, .{ pkg_dir.dir, hashed_file, &wait_group });
|
try thread_pool.spawn(workerHashFile, .{ pkg_dir, hashed_file, &wait_group });
|
||||||
|
|
||||||
try all_files.append(hashed_file);
|
try all_files.append(hashed_file);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,4 +7,7 @@
|
||||||
.hash = "1220548f8727394522081ab48ed2f7111c20fa5f051ff287ec3c3f82340faa5d68c2",
|
.hash = "1220548f8727394522081ab48ed2f7111c20fa5f051ff287ec3c3f82340faa5d68c2",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
.paths = .{
|
||||||
|
"",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@ pub fn main() !void {
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||||
.thread_safe = true,
|
.thread_safe = true,
|
||||||
}){};
|
}){};
|
||||||
var allocator = gpa.allocator();
|
const allocator = gpa.allocator();
|
||||||
|
|
||||||
var server = std.http.Server.init(allocator, .{
|
var server = std.http.Server.init(.{
|
||||||
.reuse_address = true,
|
.reuse_address = true,
|
||||||
});
|
});
|
||||||
defer server.deinit();
|
defer server.deinit();
|
||||||
|
@ -30,7 +30,7 @@ pub fn main() !void {
|
||||||
res.transfer_encoding = .{ .content_length = server_body.len };
|
res.transfer_encoding = .{ .content_length = server_body.len };
|
||||||
try res.headers.append("content-type", "text/plain");
|
try res.headers.append("content-type", "text/plain");
|
||||||
try res.headers.append("connection", "close");
|
try res.headers.append("connection", "close");
|
||||||
try res.do();
|
try res.send();
|
||||||
|
|
||||||
var buf: [128]u8 = undefined;
|
var buf: [128]u8 = undefined;
|
||||||
_ = try res.readAll(&buf);
|
_ = try res.readAll(&buf);
|
||||||
|
|
Loading…
Add table
Reference in a new issue