diff options
| author | Nic Gaffney <gaffney_nic@protonmail.com> | 2026-10-19 20:25:09 -0500 |
|---|---|---|
| committer | Nic Gaffney <gaffney_nic@protonmail.com> | 2026-10-19 20:25:09 -0500 |
| commit | 73e4e4490696a7f680cc0ef5e3b6d2d8ebc9c690 (patch) | |
| tree | 5360ab60fa5e67a7ce356253d3eab875c007be98 /src/lib/tmp.zig | |
| parent | dbf5e0958a6e13c9e36a0b1a29771a708f407c20 (diff) | |
| download | nvlope-73e4e4490696a7f680cc0ef5e3b6d2d8ebc9c690.tar.gz | |
working on HELO/EHLO response
Diffstat (limited to 'src/lib/tmp.zig')
| -rw-r--r-- | src/lib/tmp.zig | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/lib/tmp.zig b/src/lib/tmp.zig new file mode 100644 index 0000000..3777b31 --- /dev/null +++ b/src/lib/tmp.zig @@ -0,0 +1,50 @@ +const std = @import("std"); + +const Code = enum(u16) { + OK = 250, + UNKNOWN = 404, +}; + +const Response = struct { + code: Code, + pass: bool, + msg: []const u8, +}; + +const Message = struct { + name: []const u8, + pass: []const Code, + fail: []const Code, + handle: fn (*std.Io.Writer, *std.Io.net.Server, args: anytype) anyerror!Response, +}; + +const Messages = union(enum(u8)) { + HELO = Message{ + .name = "HELO", + .pass = .{.OK}, + .fail = .{.UNKNOWN}, + .handle = blk: { + const f = struct { + pub fn handle(w: *std.Io.Writer, s: *std.Io.net.Server, args: anytype) !Response { + var resp: Response = .{ .code = .OK, .pass = true, .contents = undefined }; + if (args.domain) |d| { + resp.contents = d; + try w.print("{d} {s}\r\n", .{ resp.code, resp.contents }); + try w.flush(); + return resp; + } + try w.print("{d} ", .{resp.code}); + var buf: [64]u8 = undefined; + var fw: std.Io.Writer = .fixed(&buf); + try s.socket.address.format(&fw); + const full = fw.buffered(); + const host = if (std.mem.lastIndexOfScalar(u8, full, ':')) |i| full[0..i] else full; + try w.print("[{s}]\r\n", .{host}); + resp.contents = host; + return resp; + } + }; + break :blk f.handle; + }, + }, +}; |
