1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-21 07:34:08 +00:00

data as string

This commit is contained in:
Rene Schallner 2023-09-12 18:36:57 +02:00
parent 7884d56211
commit ae98019e60

View file

@ -623,8 +623,12 @@ pub fn Fiobj2HttpParam(o: fio.FIOBJ, a: std.mem.Allocator, dupe_string: bool) !?
const data = fio.fiobj_hash_get(o, key_data); const data = fio.fiobj_hash_get(o, key_data);
var data_slice: ?[]const u8 = null; var data_slice: ?[]const u8 = null;
switch (fio.fiobj_type(data)) {
fio.FIOBJ_T_DATA => {
if (fio.is_invalid(data) == 1) { if (fio.is_invalid(data) == 1) {
data_slice = "(zap: invalid data)"; data_slice = "(zap: invalid data)";
std.log.warn("WARNING: HTTP param binary file is not a data object\n", .{});
} else { } else {
// the data // the data
const data_len = fio.fiobj_data_len(data); const data_len = fio.fiobj_data_len(data);
@ -633,16 +637,6 @@ pub fn Fiobj2HttpParam(o: fio.FIOBJ, a: std.mem.Allocator, dupe_string: bool) !?
if (data_len < 0) { if (data_len < 0) {
std.log.warn("WARNING: HTTP param binary file size negative: {d}\n", .{data_len}); std.log.warn("WARNING: HTTP param binary file size negative: {d}\n", .{data_len});
std.log.warn("FIOBJ_TYPE of data is: {d}\n", .{fio.fiobj_type(data)}); std.log.warn("FIOBJ_TYPE of data is: {d}\n", .{fio.fiobj_type(data)});
// try to read anyway
std.log.warn("WARNING: Attempting to read anyway\n", .{});
data_buf = fio.fiobj_data_read(data, 4096);
if (data_buf.len > 0) {
data_slice = data_buf.data[0..data_buf.len];
} else {
std.log.warn("WARNING: HTTP param binary file buffer size negative: {d}\n", .{data_buf.len});
data_slice = "(zap: invalid data: negative BUFFER size)";
}
} else { } else {
if (data_buf.len != data_len) { if (data_buf.len != data_len) {
std.log.warn("WARNING: HTTP param binary file size mismatch: should {d}, is: {d}\n", .{ data_len, data_buf.len }); std.log.warn("WARNING: HTTP param binary file size mismatch: should {d}, is: {d}\n", .{ data_len, data_buf.len });
@ -656,6 +650,23 @@ pub fn Fiobj2HttpParam(o: fio.FIOBJ, a: std.mem.Allocator, dupe_string: bool) !?
} }
} }
} }
},
fio.FIOBJ_T_STRING => {
const fiostr = fio.fiobj_obj2cstr(data);
if (fiostr.len == 0) {
data_slice = "(zap: epmty string data)";
std.log.warn("WARNING: HTTP param binary file has empty string object\n", .{});
} else {
data_slice = fiostr.data[0..fiostr.len];
}
},
fio.FIOBJ_T_ARRAY => {
std.log.warn("WARNING: HTTP param binary file as array object is not implemented\n", .{});
},
else => {
// don't know what to do
},
}
return .{ .Unsupported_Hash = .{ return .{ .Unsupported_Hash = .{
.filename = filename.data[0..filename.len], .filename = filename.data[0..filename.len],