authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-05-02 02:26:24 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-05-02 02:26:24 -07:00
log543e3137f4d4f9841089923264ff370c54136822
treefae3f1510bba45692de0f67cab7ffbb338bf97be
parentabbca727c328121a78971940e79df3e3afc56cf9

switch from zuri/iguanatls to zfetch/json


3 files changed, 41 insertions(+), 55 deletions(-)

deps.zig+19-7
......@@ -30,9 +30,13 @@ pub const _ids = .{
3030 "8mdbh0zuneb0i3hs5jby5je0heem1i6yxusl7c8y8qx68hqc",
3131 "s84v9o48ucb0xq0cmzq0cn433hgw0iaqztugja16h8bzxu3h",
3232 "2ta738wrqbaqzl3iwzoo8nj35k9ynwz5p5iyz80ryrpp4ttf",
33 "2b7mq571jmq31ktmpigopu29480iw245heueajgxzxn7ab8o",
34 "csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe",
3533 "0npcrzfdlrvkf44mzjo8bduj9gmqyefo0j3rstt6b0pm2r6r",
34 "ejw82j2ipa0eul25ohgdh6yy5nkrtn2pf0rq18m0079w6wj7",
35 "9k24gimke1anv665ilg4si32ayl3dsaqgmdfdpu1ceoky8tl",
36 "csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe",
37 "yyhw90zkzgmubwpp87n0pzf936n850an66y1c6qan5y6sogv",
38 "1vv8d3ee4k0g7kmy1bhi9qon55bj1arxq9181hc8sesa7x3f",
39 "ocmr9rtohgccd6gm6tp8b1yzylyzkqwvo1q4btrsvj0cse9y",
3640};
3741
3842pub const _paths = .{
......@@ -40,18 +44,26 @@ pub const _paths = .{
4044 "/v/git/github.com/yaml/libyaml/tag-0.2.5/",
4145 "/v/git/github.com/nektro/zig-ansi/commit-25039ca/",
4246 "/v/git/github.com/ziglibs/known-folders/commit-f0f4188/",
43 "/v/git/github.com/Vexu/zuri/commit-41bcd78/",
44 "/v/git/github.com/alexnask/iguanaTLS/commit-1767e48/",
4547 "/v/git/github.com/nektro/zig-licenses/commit-1a19e4b/",
48 "/v/git/github.com/truemedian/zfetch/commit-5b9d6a2/",
49 "/git/github.com/truemedian/hzzp/",
50 "/git/github.com/alexnask/iguanaTLS/",
51 "/git/github.com/MasterQ32/zig-network/",
52 "/git/github.com/MasterQ32/zig-uri/",
53 "/v/git/github.com/nektro/zig-json/commit-ad4232e/",
4654};
4755
4856pub const package_data = struct {
4957 pub const _s84v9o48ucb0xq0cmzq0cn433hgw0iaqztugja16h8bzxu3h = std.build.Pkg{ .name = "ansi", .path = cache ++ "/v/git/github.com/nektro/zig-ansi/commit-25039ca/src/lib.zig", .dependencies = &[_]std.build.Pkg{ } };
5058 pub const _2ta738wrqbaqzl3iwzoo8nj35k9ynwz5p5iyz80ryrpp4ttf = std.build.Pkg{ .name = "known-folders", .path = cache ++ "/v/git/github.com/ziglibs/known-folders/commit-f0f4188/known-folders.zig", .dependencies = &[_]std.build.Pkg{ } };
51 pub const _2b7mq571jmq31ktmpigopu29480iw245heueajgxzxn7ab8o = std.build.Pkg{ .name = "zuri", .path = cache ++ "/v/git/github.com/Vexu/zuri/commit-41bcd78/src/zuri.zig", .dependencies = &[_]std.build.Pkg{ } };
52 pub const _csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe = std.build.Pkg{ .name = "iguanatls", .path = cache ++ "/v/git/github.com/alexnask/iguanaTLS/commit-1767e48/src/main.zig", .dependencies = &[_]std.build.Pkg{ } };
5359 pub const _0npcrzfdlrvkf44mzjo8bduj9gmqyefo0j3rstt6b0pm2r6r = std.build.Pkg{ .name = "licenses", .path = cache ++ "/v/git/github.com/nektro/zig-licenses/commit-1a19e4b/src/lib.zig", .dependencies = &[_]std.build.Pkg{ } };
54 pub const _89ujp8gq842x6mzok8feypwze138n2d96zpugw44hcq7406r = std.build.Pkg{ .name = "zigmod", .path = cache ++ "/../../src/lib.zig", .dependencies = &[_]std.build.Pkg{ _s84v9o48ucb0xq0cmzq0cn433hgw0iaqztugja16h8bzxu3h, _2ta738wrqbaqzl3iwzoo8nj35k9ynwz5p5iyz80ryrpp4ttf, _2b7mq571jmq31ktmpigopu29480iw245heueajgxzxn7ab8o, _csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe, _0npcrzfdlrvkf44mzjo8bduj9gmqyefo0j3rstt6b0pm2r6r, } };
60 pub const _9k24gimke1anv665ilg4si32ayl3dsaqgmdfdpu1ceoky8tl = std.build.Pkg{ .name = "hzzp", .path = cache ++ "/git/github.com/truemedian/hzzp/src/main.zig", .dependencies = &[_]std.build.Pkg{ } };
61 pub const _csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe = std.build.Pkg{ .name = "iguanaTLS", .path = cache ++ "/git/github.com/alexnask/iguanaTLS/src/main.zig", .dependencies = &[_]std.build.Pkg{ } };
62 pub const _yyhw90zkzgmubwpp87n0pzf936n850an66y1c6qan5y6sogv = std.build.Pkg{ .name = "network", .path = cache ++ "/git/github.com/MasterQ32/zig-network/network.zig", .dependencies = &[_]std.build.Pkg{ } };
63 pub const _1vv8d3ee4k0g7kmy1bhi9qon55bj1arxq9181hc8sesa7x3f = std.build.Pkg{ .name = "uri", .path = cache ++ "/git/github.com/MasterQ32/zig-uri/uri.zig", .dependencies = &[_]std.build.Pkg{ } };
64 pub const _ejw82j2ipa0eul25ohgdh6yy5nkrtn2pf0rq18m0079w6wj7 = std.build.Pkg{ .name = "zfetch", .path = cache ++ "/v/git/github.com/truemedian/zfetch/commit-5b9d6a2/src/main.zig", .dependencies = &[_]std.build.Pkg{ _9k24gimke1anv665ilg4si32ayl3dsaqgmdfdpu1ceoky8tl, _csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe, _yyhw90zkzgmubwpp87n0pzf936n850an66y1c6qan5y6sogv, _1vv8d3ee4k0g7kmy1bhi9qon55bj1arxq9181hc8sesa7x3f, } };
65 pub const _ocmr9rtohgccd6gm6tp8b1yzylyzkqwvo1q4btrsvj0cse9y = std.build.Pkg{ .name = "json", .path = cache ++ "/v/git/github.com/nektro/zig-json/commit-ad4232e/src/lib.zig", .dependencies = &[_]std.build.Pkg{ } };
66 pub const _89ujp8gq842x6mzok8feypwze138n2d96zpugw44hcq7406r = std.build.Pkg{ .name = "zigmod", .path = cache ++ "/../../src/lib.zig", .dependencies = &[_]std.build.Pkg{ _s84v9o48ucb0xq0cmzq0cn433hgw0iaqztugja16h8bzxu3h, _2ta738wrqbaqzl3iwzoo8nj35k9ynwz5p5iyz80ryrpp4ttf, _0npcrzfdlrvkf44mzjo8bduj9gmqyefo0j3rstt6b0pm2r6r, _ejw82j2ipa0eul25ohgdh6yy5nkrtn2pf0rq18m0079w6wj7, _ocmr9rtohgccd6gm6tp8b1yzylyzkqwvo1q4btrsvj0cse9y, } };
5567};
5668
5769pub const packages = &[_]std.build.Pkg{
src/cmd/zpm_add.zig+19-45
......@@ -1,8 +1,9 @@
11const std = @import("std");
22const gpa = std.heap.c_allocator;
33
4const zuri = @import("zuri");
5const iguanatls = @import("iguanatls");
4const zfetch = @import("zfetch");
5const json = @import("json");
6
67const u = @import("./../util/index.zig");
78
89//
......@@ -20,47 +21,20 @@ pub const Zpm = struct {
2021};
2122
2223pub fn execute(args: [][]u8) !void {
23 const url = try zuri.Uri.parse("https://zpm.random-projects.net:443/api/packages", true);
24
25 const sock = try std.net.tcpConnectToHost(gpa, url.host.name, url.port.?);
26 defer sock.close();
27
28 var client = try iguanatls.client_connect(.{
29 .reader = sock.reader(),
30 .writer = sock.writer(),
31 .cert_verifier = .none,
32 .temp_allocator = gpa,
33 .ciphersuites = iguanatls.ciphersuites.all,
34 }, url.host.name);
35 defer client.close_notify() catch {};
24 const url = "https://zpm.random-projects.net/api/packages";
3625
37 const w = client.writer();
38 try w.print("GET {s} HTTP/1.1\r\n", .{url.path});
39 try w.print("Host: {s}:{}\r\n", .{ url.host.name, url.port.? });
40 try w.writeAll("Accept: application/json; charset=UTF-8\r\n");
41 try w.writeAll("Connection: close\r\n");
42 try w.writeAll("\r\n");
43
44 const r = client.reader();
45 var buf: [1]u8 = undefined;
46 const data = &std.ArrayList(u8).init(gpa);
47 while (true) {
48 const len = try r.read(&buf);
49 if (len == 0) {
50 break;
51 }
52 try data.appendSlice(buf[0..len]);
53 }
26 const req = try zfetch.Request.init(gpa, url, null);
27 defer req.deinit();
5428
55 const index = std.mem.indexOf(u8, data.items, "\r\n\r\n").?;
56 const html_contents = data.items[index..];
29 try req.do(.GET, null, null);
30 const r = req.reader();
5731
58 var stream = std.json.TokenStream.init(html_contents[4..]);
59 const res = try std.json.parse([]Zpm.Package, &stream, .{ .allocator = gpa });
32 const body_content = try r.readAllAlloc(gpa, std.math.maxInt(usize));
33 const val = try json.parse(gpa, body_content);
6034
6135 const found = blk: {
62 for (res) |pkg| {
63 if (std.mem.eql(u8, pkg.name, args[0])) {
36 for (val.Array) |pkg| {
37 if (std.mem.eql(u8, pkg.get("name").?.String, args[0])) {
6438 break :blk pkg;
6539 }
6640 }
......@@ -68,12 +42,12 @@ pub fn execute(args: [][]u8) !void {
6842 unreachable;
6943 };
7044
71 u.assert(found.root_file != null, "package must have an entry point to be able to be added to your dependencies", .{});
45 u.assert(found.get("root_file") != null, "package must have an entry point to be able to be added to your dependencies", .{});
7246
7347 const self_module = try u.ModFile.init(gpa, "zig.mod");
7448 for (self_module.deps) |dep| {
75 if (std.mem.eql(u8, dep.name, found.name)) {
76 u.assert(false, "dependency with name '{s}' already exists in your dependencies", .{found.name});
49 if (std.mem.eql(u8, dep.name, found.get("name").?.String)) {
50 u.assert(false, "dependency with name '{s}' already exists in your dependencies", .{found.get("name").?.String});
7751 }
7852 }
7953
......@@ -82,9 +56,9 @@ pub fn execute(args: [][]u8) !void {
8256
8357 const file_w = file.writer();
8458 try file_w.print("\n", .{});
85 try file_w.print(" - src: git {s}\n", .{found.git});
86 try file_w.print(" name: {s}\n", .{found.name});
87 try file_w.print(" main: {s}\n", .{found.root_file.?[1..]});
59 try file_w.print(" - src: git {s}\n", .{found.get("git").?.String});
60 try file_w.print(" name: {s}\n", .{found.get("name").?.String});
61 try file_w.print(" main: {s}\n", .{found.get("root_file").?.String[1..]});
8862
89 std.log.info("Successfully added package {s} by {s}", .{ found.name, found.author });
63 std.log.info("Successfully added package {s} by {s}", .{ found.get("name").?.String, found.get("author").?.String });
9064}
zig.mod+3-3
......@@ -32,11 +32,11 @@ dependencies:
3232
3333 - src: git https://github.com/ziglibs/known-folders commit-f0f4188
3434
35 - src: git https://github.com/Vexu/zuri commit-41bcd78
35 - src: git https://github.com/nektro/zig-licenses commit-1a19e4b
3636
37 - src: git https://github.com/alexnask/iguanaTLS commit-1767e48
37 - src: git https://github.com/truemedian/zfetch commit-5b9d6a2
3838
39 - src: git https://github.com/nektro/zig-licenses commit-1a19e4b
39 - src: git https://github.com/nektro/zig-json commit-ad4232e
4040
4141dev_dependencies:
4242 - src: git https://github.com/nektro/zig-ansi commit-25039ca