0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-29 04:08:54 +02:00

modules/media: Provide suitable extern linkage for file_room_id.

This commit is contained in:
Jason Volk 2018-04-24 17:41:51 -07:00
parent 2b6fd1c985
commit a068857bb9
2 changed files with 46 additions and 27 deletions

View file

@ -16,32 +16,6 @@ IRCD_MODULE
"11.7 :Content respository"
};
m::room::id::buf
file_room_id(const string_view &server,
const string_view &file)
{
if(empty(server) || empty(file))
throw m::BAD_REQUEST
{
"Invalid MXC: empty server or file parameters..."
};
size_t len;
thread_local char buf[512];
len = strlcpy(buf, server);
len = strlcat(buf, "/"_sv);
len = strlcat(buf, file);
const sha256::buf hash
{
sha256{string_view{buf, len}}
};
return m::room::id::buf
{
b58encode(buf, hash), my_host()
};
}
size_t
write_file(const m::room &room,
const string_view &content,
@ -178,3 +152,41 @@ read_each_block(const m::room &room,
return ret;
}
m::room::id::buf
file_room_id(const string_view &server,
const string_view &file)
{
m::room::id::buf ret;
file_room_id(ret, server, file);
return ret;
}
m::room::id
file_room_id(m::room::id::buf &out,
const string_view &server,
const string_view &file)
{
if(empty(server) || empty(file))
throw m::BAD_REQUEST
{
"Invalid MXC: empty server or file parameters..."
};
size_t len;
thread_local char buf[512];
len = strlcpy(buf, server);
len = strlcat(buf, "/"_sv);
len = strlcat(buf, file);
const sha256::buf hash
{
sha256{string_view{buf, len}}
};
out =
{
b58encode(buf, hash), my_host()
};
return out;
}

View file

@ -10,7 +10,14 @@
using namespace ircd;
m::room::id::buf file_room_id(const string_view &server, const string_view &file);
extern "C" m::room::id
file_room_id(m::room::id::buf &out,
const string_view &server,
const string_view &file);
m::room::id::buf
file_room_id(const string_view &server,
const string_view &file);
size_t read_each_block(const m::room &, const std::function<void (const string_view &)> &);
size_t write_file(const m::room &room, const string_view &content, const string_view &content_type);