Skip to content

Commit

Permalink
more json chikanery
Browse files Browse the repository at this point in the history
  • Loading branch information
donpdonp committed Apr 9, 2024
1 parent a9910a3 commit 6b0d3e6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ fn oauthback(command: *thread.Command) void {
const tree = command.verb.http.tree;
const rootJsonType = @TypeOf(tree);
if (true) { //todo: rootJsonType == std.json.Value) {
if (tree.root.Object.get("client_id")) |cid| {
column.oauthClientId = cid.String;
if (tree.object.get("client_id")) |cid| {
column.oauthClientId = cid.string;
}
if (tree.root.Object.get("client_secret")) |cid| {
column.oauthClientSecret = cid.String;
if (tree.object.get("client_secret")) |cid| {
column.oauthClientSecret = cid.string;
}
warn("*oauthback client id {s} secret {s}\n", .{ column.oauthClientId, column.oauthClientSecret });
gui.schedule(gui.column_config_oauth_url_schedule, @as(*anyopaque, @ptrCast(column)));
Expand All @@ -228,10 +228,10 @@ fn netback(command: *thread.Command) void {
if (command.verb.http.response_code >= 200 and command.verb.http.response_code < 300) {
if (command.verb.http.body.len > 0) {
const tree = command.verb.http.tree;
if (tree == .Array) {
if (@TypeOf(tree) == std.json.Array) {
column.inError = false;
warn("netback payload is array len {}\n", .{tree.root.Array.items.len});
for (tree.root.Array.items) |jsonValue| {
warn("netback payload is array len {}\n", .{tree.array.items.len});
for (tree.array.items) |jsonValue| {
const item = jsonValue.Object;
const toot = alloc.create(toot_lib.Type) catch unreachable;
toot.* = toot_lib.Type.init(item, alloc);
Expand Down Expand Up @@ -260,12 +260,12 @@ fn netback(command: *thread.Command) void {
}
}
}
} else if (tree.root == .Object) {
if (tree.root.Object.get("error")) |err| {
} else if (@TypeOf(tree) == std.json.ObjectMap) {
if (tree.object.get("error")) |err| {
warn("netback json err {s} \n", .{err.String});
}
} else {
warn("!netback json unknown root tagtype {}\n", .{tree.root});
warn("!netback json unknown root tagtype {}\n", .{tree});
}
} else { // empty body
column.inError = true;
Expand Down
8 changes: 4 additions & 4 deletions src/net.zig
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ pub fn go(data: ?*anyopaque) callconv(.C) ?*anyopaque {
std.mem.eql(u8, actor.payload.http.content_type, "application/json; charset=utf-8")))
{
//warn("{}\n", body); // json dump
var json_parser = std.json.Parser.init(allocator, false);
if (json_parser.parse(body)) |value_tree| {
actor.payload.http.tree = value_tree;
if (std.json.parseFromSlice(std.json.Value, allocator, body, .{})) |value_tree| {
defer value_tree.deinit();
actor.payload.http.tree = value_tree.value;
} else |err| {
warn("net json err {}\n", .{err});
actor.payload.http.response_code = 1000;
Expand All @@ -52,7 +52,7 @@ pub fn httpget(req: *config.HttpInfo) ![]const u8 {
_ = c.curl_global_init(0);
var curl = c.curl_easy_init();
if (curl != null) {
var cstr = util.sliceAddNull(allocator, req.url) catch unreachable;
var cstr = util.sliceAddNull(allocator, req.url);
_ = c.curl_easy_setopt(curl, c.CURLOPT_URL, cstr.ptr);

var zero: c_long = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/thread.zig
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn create(
return error.BadValue;
}

pub fn signal(actor: *Actor, command: *const Command) void {
pub fn signal(actor: *Actor, command: *Command) void {
command.actor = actor; // fill in the command
//const command_address_bytes: *const [8]u8 = @ptrCast([*]const u8, command)[0..8]; // not OK
const command_address_bytes: *align(8) const [8]u8 = std.mem.asBytes(&command); // OK
Expand Down

0 comments on commit 6b0d3e6

Please sign in to comment.