diff options
-rw-r--r-- | build.zig | 19 | ||||
-rw-r--r-- | src/main.zig | 28 | ||||
-rw-r--r-- | src/transmission.zig | 3 | ||||
-rw-r--r-- | src/types.zig | 52 | ||||
-rw-r--r-- | test.c | 16 | ||||
-rw-r--r-- | xmission.h | 2 |
6 files changed, 89 insertions, 31 deletions
@@ -1,4 +1,5 @@ const std = @import("std"); +//const DockerStep = @import("DockerStep.zig"); // Although this function looks imperative, note that its job is to // declaratively construct a build graph that will be executed by an external @@ -29,6 +30,12 @@ pub fn build(b: *std.Build) void { // running `zig build`). b.installArtifact(lib); + //const docker_run = DockerStep.create(b, .{ + //.name = "transmission-zig", + //.image = "docker.io/linuxserver/transmission:4.0.3", + //.ports = &[_][]const u8{"9091:9091"}, + //}); + // Creates a step for unit testing. This only builds the test executable // but does not run it. const main_tests = b.addTest(.{ @@ -42,6 +49,14 @@ pub fn build(b: *std.Build) void { // This creates a build step. It will be visible in the `zig build --help` menu, // and can be selected like this: `zig build test` // This will evaluate the `test` step rather than the default, which is "install". - const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&run_main_tests.step); + const test_step_unit = b.step("test", "Run library unit tests"); + test_step_unit.dependOn(&run_main_tests.step); + + const test_step_int = b.step("test-int", "Run library integration tests"); + test_step_int.dependOn(&run_main_tests.step); + //test_step_int.dependOn(docker_run.step); + + //const docker_rm = DockerStep.remove(b, "transmission-zig"); + + //docker_rm.step.dependOn(test_step_int); } diff --git a/src/main.zig b/src/main.zig index b01188b..a88bf8a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -14,24 +14,13 @@ export fn add(a: i32, b: i32) i32 { var client = transmission.Client.init(allocator, clientOptions); defer client.deinit(); - //{ - //const body = transmission.session_get_raw(&client, null) catch |err| { - //std.debug.print("error: {any}\n", .{err}); - //unreachable; - //}; - //defer allocator.free(body); - //std.debug.print("body: {s}\n", .{body}); - //} - { - const body = transmission.torrent_get_(&client, null) catch |err| { + const body = transmission.session_get_raw(&client, null) catch |err| { std.debug.print("error: {any}\n", .{err}); unreachable; }; - //defer allocator.free(body); - for (body.arguments.torrent_get.torrents.?) |t| { - std.debug.print("name: {any}\n", .{t}); - } + defer allocator.free(body); + std.debug.print("body: {s}\n", .{body}); } //{ @@ -40,6 +29,17 @@ export fn add(a: i32, b: i32) i32 { //unreachable; //}; ////defer allocator.free(body); + //for (body.arguments.torrent_get.torrents.?) |t| { + //std.debug.print("name: {any}\n", .{t}); + //} + //} + + //{ + //const body = transmission.torrent_get_(&client, null) catch |err| { + //std.debug.print("error: {any}\n", .{err}); + //unreachable; + //}; + ////defer allocator.free(body); //std.debug.print("body: {any}\n", .{body}); //} diff --git a/src/transmission.zig b/src/transmission.zig index 409b4b1..9f0f5f0 100644 --- a/src/transmission.zig +++ b/src/transmission.zig @@ -126,6 +126,9 @@ pub fn torrent_get_raw(client: *Client, torrent_get: ?Request.TorrentGet) ![]u8 .arguments = .{ .torrent_get = torrent_get orelse default }, }; const body = try client.do(r); + std.debug.print("{s}\n", .{body}); + if (1 == 1) + @panic(""); return body; } diff --git a/src/types.zig b/src/types.zig index b8029ca..7de8fa1 100644 --- a/src/types.zig +++ b/src/types.zig @@ -11,9 +11,14 @@ pub const Torrent = struct { // When the torrent was first added. addedDate: ?i64 = null, - //availability: []struct {}, array (see below) tr_torrepieceCountntAvailability() + // An array of numbers representing the number of connected peers that + // have each piece, or -1 if we already have the piece ourselves. + availability: ?[]i64 = null, - //bandwidthPriority: ?usize = null, + // ?? + bandwidthPriority: ?i8 = null, + + // ?? comment: ?[]u8 = null, // Byte count of all the corrupt data you've ever downloaded for @@ -21,8 +26,11 @@ pub const Torrent = struct { // grow very large. corruptEver: ?u64 = null, + // ?? creator: ?[]u8 = null, - //dateCreated: ?usize = null, + + // ?? + dateCreated: ?i64 = null, // Byte count of all the piece data we want and don't have yet, // but that a connected peer does have. @@ -31,6 +39,7 @@ pub const Torrent = struct { // When the torrent finished downloading. doneDate: ?i64 = null, + // ?? downloadDir: ?[]u8 = null, // Byte count of all the non-corrupt data you've ever downloaded @@ -38,7 +47,9 @@ pub const Torrent = struct { // time, this will be `2*totalSize`. downloadedEver: ?u64 = null, + // TODO: ?? can't find the definition anywhere //downloadLimit: ?usize = null, + downloadLimited: ?bool = null, // The last time during this session that a rarely-changing field @@ -47,7 +58,22 @@ pub const Torrent = struct { // to reload fields that rarely change. editDate: ?i64 = null, - //@"error": ?usize = null, + // Defines what kind of text is in errorString. + @"error": ?enum { + // everything's fine + ok, + + // when we announced to the tracker, we got a warning in the response + tracker_warning, + + // when we announced to the tracker, we got an error in the response + tracker_error, + + // local trouble, such as disk full or permissions error + local_error, + }, + + // A warning or error message regarding the torrent. errorString: ?[]u8 = null, // If downloading, estimated number of seconds left until the torrent is done. @@ -57,9 +83,21 @@ pub const Torrent = struct { // If seeding, number of seconds left until the idle time limit is reached. etaIdle: ?i64 = null, - //@"file-count": ?usize = null, - ////files array (see below) n/a - ////fileStats array (see below) n/a + // ?? + @"file-count": ?usize = null, + + // ?? TODO: this is most likely outdated, the returned json is missing + // some of the fields in the docs + files: ?[]struct { + bytesCompleted: ?u64 = null, + length: ?u64 = null, + name: ?[]u8 = null, + beginPiece: ?u32 = null, + endPiece: ?u32 = null, + } = null, + + //fileStats array (see below) n/a + group: ?[]u8 = null, hashString: ?[]u8 = null, @@ -3,15 +3,17 @@ #include <stdio.h> int main(int argc, char **argv) { - struct ClientOptions opts; - opts.host = "192.168.0.2"; - opts.port = 9091; - opts.https = false; - opts.user = NULL; - opts.passowrd = NULL; + struct ClientOptions opts = { + .host = "192.168.0.2", + .port = 9091, + .https = false, + NULL, + NULL, + }; c_client client = c_client_init(opts); - c_torrent_get(client); + char *foo = c_torrent_get(client); + printf("%s\n", foo); c_client_deinit(client); return 0; } @@ -17,7 +17,7 @@ typedef struct ClientOptions { c_client c_client_init(ClientOptions_t opts); -int c_torrent_get(c_client); +char *c_torrent_get(c_client); void c_client_deinit(c_client); #endif |