post->put and putCurl

Crowdstrike strikes again. Not sure what is even the issue
this time...
This commit is contained in:
Emil Lerch 2022-01-06 15:22:50 -08:00
parent 404d6a1800
commit 2d9d010b76
Signed by: lobo
GPG Key ID: A7B62D657EF764F8

View File

@ -68,7 +68,7 @@ pub fn clipboardChanged(self: *Self, contents: []const u8) !void {
return;
};
defer aa.free(encrypted);
post(aa, encrypted) catch |e| {
put(aa, encrypted) catch |e| {
std.log.err("error posting clipboard contents {}", .{e});
if (@errorReturnTrace()) |trace| {
std.debug.dumpStackTrace(trace.*);
@ -172,6 +172,32 @@ fn getCurl(allocator: std.mem.Allocator, curl_path: []const u8) ![]const u8 {
}
}
fn putCurl(allocator: std.mem.Allocator, curl_path: []const u8, data: []const u8) !void {
std.log.debug("curl path: {s}", .{curl_path});
const result = try std.ChildProcess.exec(.{
.allocator = allocator,
.argv = &[_][]const u8{
curl_path, // TODO: use Comspec
"-s",
"-X",
"PUT",
"--data-binary",
data,
clipboard_url,
},
});
try std.io.getStdErr().writer().writeAll(result.stderr);
switch (result.term) {
.Exited => |code| if (code == 0) {
return;
} else return error.NonZeroExit,
.Signal => return error.FailedWithSignal,
.Stopped => return error.WasStopped,
.Unknown => return error.Failed,
}
}
fn execLinux(allocator: std.mem.Allocator, cmd: []const u8) !std.ChildProcess.ExecResult {
return std.ChildProcess.exec(.{
.allocator = allocator,
@ -196,7 +222,10 @@ fn execLinux(allocator: std.mem.Allocator, cmd: []const u8) !std.ChildProcess.Ex
// });
// }
fn post(allocator: std.mem.Allocator, data: []const u8) !void {
fn put(allocator: std.mem.Allocator, data: []const u8) !void {
if (config.curl) |curl|
return putCurl(allocator, curl, data);
// TODO: Windows
// var cert_reader = std.io.fixedBufferStream(
// @embedFile("/etc/ssl/certs/ca-certificates.crt"),