make more things work.

This commit is contained in:
Kitteh 2021-06-03 14:42:39 +01:00
parent a108f9befd
commit 4afff73397
23 changed files with 181 additions and 48 deletions

View file

@ -47,7 +47,12 @@ pub const Client = struct {
try map.put("ClientVersion", .{ .String = "0.1 (quasselclient)" }); try map.put("ClientVersion", .{ .String = "0.1 (quasselclient)" });
try map.put("ClientDate", .{ .String = "Wed, 02 Jun 2021 17:30:30 +0100" }); try map.put("ClientDate", .{ .String = "Wed, 02 Jun 2021 17:30:30 +0100" });
try map.put("Features", .{ .Int = 0 }); try map.put("Features", .{ .Int = 0 });
var empty = std.ArrayList([]const u8).init(s.allocator); var featureList = std.ArrayList([]const u8).init(s.allocator);
defer featureList.deinit();
try featureList.put("LongTime");
try featureList.put("SenderPrefixes");
try featureList.put("RichMessages");
try map.put("FeatureList", .{ .QStringList = empty.items }); try map.put("FeatureList", .{ .QStringList = empty.items });
try write.writeFrame(list.writer(), s.allocator, map); try write.writeFrame(list.writer(), s.allocator, map);

View file

@ -6,7 +6,7 @@ const write = @import("./qtshit/write.zig");
const initClient = @import("./client.zig").initClient; const initClient = @import("./client.zig").initClient;
pub fn main() !void { pub fn main() !void {
const allocator = &std.heap.loggingAllocator(std.heap.page_allocator, std.io.getStdErr().writer()).allocator; const allocator = std.heap.page_allocator;
var argIter = std.process.args(); var argIter = std.process.args();
_ = try argIter.next(allocator).?; _ = try argIter.next(allocator).?;

View file

@ -1,5 +1,5 @@
const std = @import("std"); const std = @import("std");
pub fn readByte(reader: anytype) !u8 { pub fn readByte(reader: anytype) !u8 {
std.debug.print("read: readByte\n", .{}); //std.debug.print("read: readByte\n", .{});
return try reader.readByte(); return try reader.readByte();
} }

View file

@ -1,6 +1,6 @@
const std = @import("std"); const std = @import("std");
pub fn readInt(reader: anytype) !i32 { pub fn readInt(reader: anytype) !i32 {
std.debug.print("read: readInt\n", .{}); //std.debug.print("read: readInt\n", .{});
return try reader.readIntBig(i32); return try reader.readIntBig(i32);
} }

View file

@ -1,6 +1,6 @@
const std = @import("std"); const std = @import("std");
pub fn readLong(reader: anytype) !i64 { pub fn readLong(reader: anytype) !i64 {
std.debug.print("read: readLong\n", .{}); //std.debug.print("read: readLong\n", .{});
return try reader.readIntBig(i64); return try reader.readIntBig(i64);
} }

View file

@ -3,12 +3,13 @@ const readUInt = @import("./readUInt.zig").readUInt;
pub fn readQByteArray(reader: anytype, allocator: *std.mem.Allocator) ![]u8 { pub fn readQByteArray(reader: anytype, allocator: *std.mem.Allocator) ![]u8 {
var length = try readUInt(reader); var length = try readUInt(reader);
std.debug.print("read: readQByteArray length={d} \n", .{length}); //std.debug.print("read: readQByteArray length={d} \n", .{length});
var byteList = try allocator.alloc(u8, @intCast(usize, length)); var byteList = try allocator.alloc(u8, @intCast(usize, length));
var index: usize = 0; var index: usize = 0;
while (true) { while (true) {
//std.debug.print("read: readQByteArray length={d} index={d} \n", .{length, index});
if (index == length) return byteList; if (index == length) return byteList;
const byte = try reader.readByte(); const byte = try reader.readByte();

View file

@ -0,0 +1,13 @@
const std = @import("std");
const readInt = @import("./readInt.zig").readInt;
const readByte = @import("./readByte.zig").readByte;
const QDateTime = @import("../types/QVariant.zig").QDateTime;
pub fn readQDateTime(reader: anytype) !QDateTime {
//std.debug.print("read: readQDateTime\n", .{});
return QDateTime{
.JulianDay = try readInt(reader),
.MillisOfDay = try readInt(reader),
.Zone = try readByte(reader),
};
}

View file

@ -6,7 +6,7 @@ const readString = @import("./readString.zig").readString;
pub fn readQStringList(reader: anytype, allocator: *std.mem.Allocator) ![][]const u8 { pub fn readQStringList(reader: anytype, allocator: *std.mem.Allocator) ![][]const u8 {
var length = try readUInt(reader); var length = try readUInt(reader);
std.debug.print("read: readQStringList length={d} \n", .{length}); //std.debug.print("read: readQStringList length={d} \n", .{length});
var stringList = try allocator.alloc([]const u8, @intCast(usize, length)); var stringList = try allocator.alloc([]const u8, @intCast(usize, length));

View file

@ -7,8 +7,7 @@ const QVariant = @import("../types/QVariant.zig").QVariant;
pub fn readQVariant(reader: anytype, allocator: *std.mem.Allocator) !QVariant { pub fn readQVariant(reader: anytype, allocator: *std.mem.Allocator) !QVariant {
var type_id = try readUInt(reader); var type_id = try readUInt(reader);
std.debug.print("read: readQVariant type_id={d}\n", .{type_id}); var mysteryByte = try readByte(reader);
//std.debug.print("read: readQVariant type_id={d} mysteryByte={d} \n", .{type_id, mysteryByte});
_ = try readByte(reader);
return try readQVariantT(reader, type_id, allocator); return try readQVariantT(reader, type_id, allocator);
} }

View file

@ -9,7 +9,7 @@ const QVariant = @import("../types/QVariant.zig").QVariant;
pub fn readQVariantList(reader: anytype, allocator: *std.mem.Allocator) ![]QVariant { pub fn readQVariantList(reader: anytype, allocator: *std.mem.Allocator) ![]QVariant {
var length = try readUInt(reader); var length = try readUInt(reader);
std.debug.print("read: readQVariantList length={d}\n", .{length}); //std.debug.print("read: readQVariantList length={d}\n", .{length});
var variantList = try allocator.alloc(QVariant, @intCast(usize, length)); var variantList = try allocator.alloc(QVariant, @intCast(usize, length));

View file

@ -11,7 +11,7 @@ const QVariant = @import("../types/QVariant.zig").QVariant;
pub fn readQVariantMap(reader: anytype, allocator: *std.mem.Allocator) !std.StringHashMap(QVariant) { pub fn readQVariantMap(reader: anytype, allocator: *std.mem.Allocator) !std.StringHashMap(QVariant) {
var map = std.StringHashMap(QVariant).init(allocator); var map = std.StringHashMap(QVariant).init(allocator);
var numItems = try readUInt(reader); var numItems = try readUInt(reader);
std.debug.print("read: readQVariantMap length={d} \n", .{numItems}); //std.debug.print("read: readQVariantMap length={d} \n", .{numItems});
var iter = range(u32, 0, numItems); var iter = range(u32, 0, numItems);

View file

@ -11,6 +11,7 @@ const readQVariantList = @import("./readQVariantList.zig").readQVariantList;
const readQVariant = @import("./readQVariant.zig").readQVariant; const readQVariant = @import("./readQVariant.zig").readQVariant;
const readQVariantMap = @import("./readQVariantMap.zig").readQVariantMap; const readQVariantMap = @import("./readQVariantMap.zig").readQVariantMap;
const readQStringList = @import("./readQStringList.zig").readQStringList; const readQStringList = @import("./readQStringList.zig").readQStringList;
const readQDateTime = @import("./readQDateTime.zig").readQDateTime;
const readUserType = @import("./usertypes/readUserType.zig").readUserType; const readUserType = @import("./usertypes/readUserType.zig").readUserType;
const QVariant = @import("../types/QVariant.zig").QVariant; const QVariant = @import("../types/QVariant.zig").QVariant;
@ -54,13 +55,19 @@ pub fn readQVariantT(reader: anytype, type_id: u32, allocator: *std.mem.Allocato
var short = try readShort(reader); var short = try readShort(reader);
return QVariant{ .Short = short }; return QVariant{ .Short = short };
}, },
@enumToInt(QVariantTypes.QDateTime) => {
var datetime = try readQDateTime(reader);
return QVariant{ .QDateTime = datetime };
},
@enumToInt(QVariantTypes.UserType) => { @enumToInt(QVariantTypes.UserType) => {
var usertype = try readUserType(reader, allocator); var usertype = try readUserType(reader, allocator);
return QVariant{ .UserType = usertype }; return QVariant{ .UserType = usertype };
}, },
else => { else => {
std.debug.print("Unknown Type ID: {d}\n", .{type_id}); std.debug.print("Unknown Type ID: {d}\n", .{type_id});
@panic("Unknown Type See Above."); return QVariant{ .String = "UnknownType" };
//@panic("Unknown Type See Above.");
}, },
} }
return QVariant{ .empty = true }; return QVariant{ .empty = true };

View file

@ -1,7 +1,6 @@
const std = @import("std"); const std = @import("std");
pub fn readShort(reader: anytype) !u16 { pub fn readShort(reader: anytype) !u16 {
std.debug.print("read: readShort\n", .{}); //std.debug.print("read: readShort\n", .{});
return try reader.readIntBig(u16); return try reader.readIntBig(u16);
} }

View file

@ -1,6 +1,6 @@
const std = @import("std"); const std = @import("std");
pub fn readSignedByte(reader: anytype) !i8 { pub fn readSignedByte(reader: anytype) !i8 {
std.debug.print("read: readSignedByte\n", .{}); //std.debug.print("read: readSignedByte\n", .{});
return try reader.readIntBig(i8); return try reader.readIntBig(i8);
} }

View file

@ -8,13 +8,13 @@ pub fn readString(reader: anytype, allocator: *std.mem.Allocator) ![]u8 {
var length = try readInt(reader); var length = try readInt(reader);
var chars = @divTrunc(length, 2); var chars = @divTrunc(length, 2);
std.debug.print("read: readString length={d} \n", .{length}); //std.debug.print("read: readString length={d} \n", .{length});
var index: usize = 0; var index: usize = 0;
while (true) { while (true) {
if (index == chars) break; if (index == chars) break;
const byte = try reader.readIntBig(u16); const byte = try readShort(reader);
try data.append(@truncate(u8, byte)); try data.append(@truncate(u8, byte));
index += 1; index += 1;
} }
@ -24,7 +24,7 @@ pub fn readString(reader: anytype, allocator: *std.mem.Allocator) ![]u8 {
ut8Str[i] = char; ut8Str[i] = char;
} }
std.debug.print("string: {s}\n", .{ut8Str}); //std.debug.print("string: {s}\n", .{ut8Str});
return ut8Str; return ut8Str;
} }

View file

@ -1,6 +1,6 @@
const std = @import("std"); const std = @import("std");
pub fn readUInt(reader: anytype) !u32 { pub fn readUInt(reader: anytype) !u32 {
std.debug.print("read: readUInt\n", .{}); //std.debug.print("read: readUInt\n", .{});
return try reader.readIntBig(u32); return try reader.readIntBig(u32);
} }

View file

@ -3,6 +3,7 @@ const UserType = @import("../../types/UserType.zig").UserType;
const UserTypeNames = @import("../../types/UserType.zig").UserTypeNames; const UserTypeNames = @import("../../types/UserType.zig").UserTypeNames;
const readInt = @import("../readInt.zig").readInt; const readInt = @import("../readInt.zig").readInt;
const readShort = @import("../readShort.zig").readShort; const readShort = @import("../readShort.zig").readShort;
const readByte = @import("../readByte.zig").readByte;
const readLong = @import("../readLong.zig").readLong; const readLong = @import("../readLong.zig").readLong;
const readQByteArray = @import("../readQByteArray.zig").readQByteArray; const readQByteArray = @import("../readQByteArray.zig").readQByteArray;
const readQVariantMap = @import("../readQVariantMap.zig").readQVariantMap; const readQVariantMap = @import("../readQVariantMap.zig").readQVariantMap;
@ -10,7 +11,7 @@ const readQVariantMap = @import("../readQVariantMap.zig").readQVariantMap;
pub fn readUserType(reader: anytype, allocator: *std.mem.Allocator) !UserType { pub fn readUserType(reader: anytype, allocator: *std.mem.Allocator) !UserType {
var userTypeName = try readQByteArray(reader, allocator); var userTypeName = try readQByteArray(reader, allocator);
userTypeName = userTypeName[0 .. userTypeName.len - 1]; userTypeName = userTypeName[0 .. userTypeName.len - 1];
std.debug.print("read: readUserType name={s} \n", .{userTypeName}); //std.debug.print("read: readUserType name={s} \n", .{userTypeName});
if (std.mem.eql(u8, userTypeName, "BufferId")) { if (std.mem.eql(u8, userTypeName, "BufferId")) {
return UserType{ return UserType{
@ -53,12 +54,23 @@ pub fn readUserType(reader: anytype, allocator: *std.mem.Allocator) !UserType {
.NetworkServer = try readQVariantMap(reader, allocator), .NetworkServer = try readQVariantMap(reader, allocator),
}; };
} else if (std.mem.eql(u8, userTypeName, "BufferInfo")) { } else if (std.mem.eql(u8, userTypeName, "BufferInfo")) {
var id = try readInt(reader);
var networkid = try readInt(reader);
var btype = try readShort(reader);
// 4 undocumented bytes.
_ = try readByte(reader);
_ = try readByte(reader);
_ = try readByte(reader);
_ = try readByte(reader);
var name = try readQByteArray(reader, allocator);
return UserType{ return UserType{
.BufferInfo = .{ .BufferInfo = .{
.ID = try readInt(reader), .ID = id,
.NetworkID = try readInt(reader), .NetworkID = networkid,
.Type = try readShort(reader), .Type = btype,
.Name = try readQByteArray(reader, allocator), .Name = name,
}, },
}; };
} else { } else {

View file

@ -11,5 +11,12 @@ pub const QVariant = union(enum) {
QStringList: [][]const u8, QStringList: [][]const u8,
QVariantList: []QVariant, QVariantList: []QVariant,
QVariantMap: std.StringHashMap(QVariant), QVariantMap: std.StringHashMap(QVariant),
QDateTime: QDateTime,
UserType: UserType, UserType: UserType,
}; };
pub const QDateTime = struct {
JulianDay: i32,
MillisOfDay: i32,
Zone: u8,
};

View file

@ -7,6 +7,7 @@ pub const QVariantTypes = enum(u32) {
String = 10, String = 10,
QStringList = 11, QStringList = 11,
QByteArray = 12, QByteArray = 12,
QDateTime = 16,
Short = 133, Short = 133,
UserType = 127, UserType = 127,
}; };

View file

@ -27,6 +27,9 @@ pub fn QVariantTypeID(variant: QVariant) !u32 {
.QByteArray => { .QByteArray => {
return @enumToInt(QVariantTypes.QByteArray); return @enumToInt(QVariantTypes.QByteArray);
}, },
.QDateTime => {
return @enumToInt(QVariantTypes.QDateTime);
},
.Short => { .Short => {
return @enumToInt(QVariantTypes.Short); return @enumToInt(QVariantTypes.Short);
}, },

View file

@ -1,21 +1,25 @@
const std = @import("std"); const std = @import("std");
const QVariant = @import("../types/QVariant.zig").QVariant; const QVariant = @import("../types/QVariant.zig").QVariant;
pub fn freeQVariantMap(qvariantmap: std.StringHashMap(QVariant), allocator: *std.mem.Allocator) void {
var qMapIter = qvariantmap.iterator();
while (qMapIter.next()) |v| {
allocator.free(v.key);
freeQVariant(v.value, allocator);
}
// Compiler bug maybe? doesnt want me to drop const so have to store it in a variable
var qi = qvariantmap;
qi.deinit();
}
pub fn freeQVariant(variant: QVariant, allocator: *std.mem.Allocator) void { pub fn freeQVariant(variant: QVariant, allocator: *std.mem.Allocator) void {
switch (variant) { switch (variant) {
.Byte, .Int, .UInt, .Short => { .Byte, .Int, .UInt, .Short, .QDateTime => {
// Static // Static
}, },
.QVariantMap => |q| { .QVariantMap => |q| {
var qMapIter = q.iterator(); freeQVariantMap(q, allocator);
while (qMapIter.next()) |v| {
allocator.free(v.key);
freeQVariant(v.value, allocator);
}
// Compiler bug maybe? doesnt want me to drop const so have to store it in a variable
var qi = q;
qi.deinit();
}, },
.QVariantList => |l| { .QVariantList => |l| {
@ -36,8 +40,18 @@ pub fn freeQVariant(variant: QVariant, allocator: *std.mem.Allocator) void {
.QByteArray => |ba| { .QByteArray => |ba| {
allocator.free(ba); allocator.free(ba);
}, },
.UserType => { .UserType => |usertype| {
@panic("Do Not Know How?????"); switch (usertype) {
.BufferId, .IdentityId, .NetworkId, .MsgId, .PeerPtr => {
// Statid
},
.IrcUser, .IrcChannel, .Identity, .NetworkInfo, .NetworkServer => |value| {
freeQVariantMap(value, allocator);
},
.BufferInfo => |value| {
allocator.free(value.Name);
},
}
}, },
} }
} }

View file

@ -1,5 +1,7 @@
const std = @import("std"); const std = @import("std");
const QVariant = @import("../types/QVariant.zig").QVariant; const QVariant = @import("../types/QVariant.zig").QVariant;
const UserType = @import("../types/UserType.zig").UserType;
const range = @import("../utils/RangeIter.zig").range; const range = @import("../utils/RangeIter.zig").range;
pub fn print_indent_level(indentLevel: u64) void { pub fn print_indent_level(indentLevel: u64) void {
@ -9,6 +11,73 @@ pub fn print_indent_level(indentLevel: u64) void {
} }
} }
pub fn prettyPrintUserType(usertype: UserType, indentLevel: u64) void {
switch (usertype) {
.BufferId => |value| {
std.debug.print("BufferId: {d}\n", .{value});
},
.IdentityId => |value| {
std.debug.print("IdentityId: {d}\n", .{value});
},
.NetworkId => |value| {
std.debug.print("NetworkId: {d}\n", .{value});
},
.MsgId => |value| {
std.debug.print("MsgId: {d}\n", .{value});
},
.PeerPtr => |value| {
std.debug.print("PeerPtr: {d}\n", .{value});
},
.IrcUser => |value| {
std.debug.print("IrcUser:\n", .{});
prettyPrintQVariantMap(value, indentLevel + 1);
},
.IrcChannel => |value| {
std.debug.print("IrcChannel:\n", .{});
prettyPrintQVariantMap(value, indentLevel + 1);
},
.Identity => |value| {
std.debug.print("Identity:\n", .{});
prettyPrintQVariantMap(value, indentLevel + 1);
},
.NetworkInfo => |value| {
std.debug.print("NetworkInfo:\n", .{});
prettyPrintQVariantMap(value, indentLevel + 1);
},
.NetworkServer => |value| {
std.debug.print("NetworkServer:\n", .{});
prettyPrintQVariantMap(value, indentLevel + 1);
},
.BufferInfo => |value| {
std.debug.print("BufferInfo:\n", .{});
print_indent_level(indentLevel + 1);
std.debug.print("ID: {d}\n", .{value.ID});
print_indent_level(indentLevel + 1);
std.debug.print("NetworkID: {d}\n", .{value.NetworkID});
print_indent_level(indentLevel + 1);
std.debug.print("Type: {d}\n", .{value.Type});
print_indent_level(indentLevel + 1);
std.debug.print("Name: {s}\n", .{value.Name});
},
//else => {
// std.debug.print("Unknown.\n", .{});
//},
}
}
pub fn prettyPrintQVariantMap(qvariantmap: std.StringHashMap(QVariant), indentLevel: u64) void {
print_indent_level(indentLevel);
std.debug.print("QVariantMap:\n", .{});
var qMapIter = qvariantmap.iterator();
while (qMapIter.next()) |v| {
print_indent_level(indentLevel + 1);
std.debug.print("Key: \"{s}\"\n", .{v.key});
print_indent_level(indentLevel + 1);
std.debug.print("Value:\n", .{});
prettyPrintQVariant(v.value, indentLevel + 2);
}
}
pub fn prettyPrintQVariant(variant: QVariant, indentLevel: u64) void { pub fn prettyPrintQVariant(variant: QVariant, indentLevel: u64) void {
print_indent_level(indentLevel); print_indent_level(indentLevel);
@ -23,19 +92,10 @@ pub fn prettyPrintQVariant(variant: QVariant, indentLevel: u64) void {
std.debug.print("UInt: {d}\n", .{i}); std.debug.print("UInt: {d}\n", .{i});
}, },
.QVariantMap => |q| { .QVariantMap => |q| {
std.debug.print("QVariantMap:\n", .{}); prettyPrintQVariantMap(q, indentLevel + 1);
var qMapIter = q.iterator();
while (qMapIter.next()) |v| {
print_indent_level(indentLevel + 1);
std.debug.print("Key: \"{s}\"\n", .{v.key});
print_indent_level(indentLevel + 1);
std.debug.print("Value:\n", .{});
prettyPrintQVariant(v.value, indentLevel + 2);
}
}, },
.QVariantList => |l| { .QVariantList => |l| {
std.debug.print("QVariantList:\n", .{}); std.debug.print("QVariantList:\n", .{});
for (l) |varient, i| { for (l) |varient, i| {
print_indent_level(indentLevel + 1); print_indent_level(indentLevel + 1);
std.debug.print("Item #{d}\n", .{i}); std.debug.print("Item #{d}\n", .{i});
@ -54,11 +114,20 @@ pub fn prettyPrintQVariant(variant: QVariant, indentLevel: u64) void {
} }
}, },
.QByteArray => {}, .QByteArray => {},
.QDateTime => |value| {
std.debug.print("QDateTime:\n", .{});
print_indent_level(indentLevel + 1);
std.debug.print("JulianDay: {d}\n", .{value.JulianDay});
print_indent_level(indentLevel + 1);
std.debug.print("MillisOfDay: {d}\n", .{value.MillisOfDay});
print_indent_level(indentLevel + 1);
std.debug.print("Zone: {d}\n", .{value.Zone});
},
.Short => |s| { .Short => |s| {
std.debug.print("Short: \"{d}\"\n", .{s}); std.debug.print("Short: \"{d}\"\n", .{s});
}, },
.UserType => { .UserType => |value| {
@panic("HOW PRINT?????"); prettyPrintUserType(value, indentLevel + 1);
}, },
} }
} }

View file

@ -44,6 +44,9 @@ pub fn writeQVariant(writer: anytype, allocator: *std.mem.Allocator, variant: QV
.Short => |out| { .Short => |out| {
try writeShort(writer, out); try writeShort(writer, out);
}, },
.QDateTime => {
@panic("Can't write QDateTime");
},
.UserType => { .UserType => {
@panic("Can't write UserTypes"); @panic("Can't write UserTypes");
}, },