cdp: add security.enable

This commit is contained in:
Pierre Tachoire
2025-01-08 16:15:54 +01:00
parent 90fb90b186
commit 03e87155ca
2 changed files with 62 additions and 0 deletions

View File

@@ -35,6 +35,7 @@ const Input = @import("msg.zig").Input;
const inspector = @import("inspector.zig").inspector; const inspector = @import("inspector.zig").inspector;
const dom = @import("dom.zig").dom; const dom = @import("dom.zig").dom;
const css = @import("css.zig").css; const css = @import("css.zig").css;
const security = @import("security.zig").security;
const log_cdp = std.log.scoped(.cdp); const log_cdp = std.log.scoped(.cdp);
@@ -69,6 +70,7 @@ const Domains = enum {
Emulation, Emulation,
Fetch, Fetch,
Performance, Performance,
Security,
}; };
// The caller is responsible for calling `free` on the returned slice. // The caller is responsible for calling `free` on the returned slice.
@@ -112,6 +114,7 @@ pub fn dispatch(
.Emulation => emulation(alloc, msg, action, ctx), .Emulation => emulation(alloc, msg, action, ctx),
.Fetch => fetch(alloc, msg, action, ctx), .Fetch => fetch(alloc, msg, action, ctx),
.Performance => performance(alloc, msg, action, ctx), .Performance => performance(alloc, msg, action, ctx),
.Security => security(alloc, msg, action, ctx),
}; };
} }

59
src/cdp/security.zig Normal file
View File

@@ -0,0 +1,59 @@
// Copyright (C) 2023-2024 Lightpanda (Selecy SAS)
//
// Francis Bouvier <francis@lightpanda.io>
// Pierre Tachoire <pierre@lightpanda.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
const std = @import("std");
const server = @import("../server.zig");
const Ctx = server.Ctx;
const cdp = @import("cdp.zig");
const result = cdp.result;
const IncomingMessage = @import("msg.zig").IncomingMessage;
const Input = @import("msg.zig").Input;
const log = std.log.scoped(.cdp);
const Methods = enum {
enable,
};
pub fn security(
alloc: std.mem.Allocator,
msg: *IncomingMessage,
action: []const u8,
ctx: *Ctx,
) ![]const u8 {
const method = std.meta.stringToEnum(Methods, action) orelse
return error.UnknownMethod;
return switch (method) {
.enable => enable(alloc, msg, ctx),
};
}
fn enable(
alloc: std.mem.Allocator,
msg: *IncomingMessage,
_: *Ctx,
) ![]const u8 {
// input
const input = try Input(void).get(alloc, msg);
defer input.deinit();
log.debug("Req > id {d}, method {s}", .{ input.id, "security.enable" });
return result(alloc, input.id, null, null, input.sessionId);
}