From cecc03e1ed2c957ea2b86e85e4473d2433212543 Mon Sep 17 00:00:00 2001 From: Francis Bouvier Date: Fri, 7 Jun 2024 16:12:31 +0200 Subject: [PATCH] Add fetch.disable Signed-off-by: Francis Bouvier --- src/cdp/cdp.zig | 3 +++ src/cdp/fetch.zig | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/cdp/fetch.zig diff --git a/src/cdp/cdp.zig b/src/cdp/cdp.zig index a0d36918..7d9c670d 100644 --- a/src/cdp/cdp.zig +++ b/src/cdp/cdp.zig @@ -10,6 +10,7 @@ const log = @import("log.zig").log; const runtime = @import("runtime.zig").runtime; const network = @import("network.zig").network; const emulation = @import("emulation.zig").emulation; +const fetch = @import("fetch.zig").fetch; pub const Error = error{ UnknonwDomain, @@ -35,6 +36,7 @@ const Domains = enum { Runtime, Network, Emulation, + Fetch, }; // The caller is responsible for calling `free` on the returned slice. @@ -84,6 +86,7 @@ pub fn do( .Runtime => runtime(alloc, id, iter.next().?, &scanner, ctx), .Network => network(alloc, id, iter.next().?, &scanner, ctx), .Emulation => emulation(alloc, id, iter.next().?, &scanner, ctx), + .Fetch => fetch(alloc, id, iter.next().?, &scanner, ctx), }; } diff --git a/src/cdp/fetch.zig b/src/cdp/fetch.zig new file mode 100644 index 00000000..46c1fba6 --- /dev/null +++ b/src/cdp/fetch.zig @@ -0,0 +1,37 @@ +const std = @import("std"); + +const server = @import("../server.zig"); +const Ctx = server.Cmd; +const cdp = @import("cdp.zig"); +const result = cdp.result; +const getMsg = cdp.getMsg; + +const FetchMethods = enum { + disable, +}; + +pub fn fetch( + alloc: std.mem.Allocator, + id: ?u16, + action: []const u8, + scanner: *std.json.Scanner, + ctx: *Ctx, +) ![]const u8 { + const method = std.meta.stringToEnum(FetchMethods, action) orelse + return error.UnknownMethod; + + return switch (method) { + .disable => fetchDisable(alloc, id, scanner, ctx), + }; +} + +fn fetchDisable( + alloc: std.mem.Allocator, + id: ?u16, + scanner: *std.json.Scanner, + _: *Ctx, +) ![]const u8 { + const msg = try getMsg(alloc, void, scanner); + + return result(alloc, id orelse msg.id.?, null, null, msg.sessionID); +}