From e6a204263eb29ecf0eb77d22d057afb553963cd0 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 30 Apr 2018 07:30:34 -0700 Subject: [PATCH] modules/media: Convey a user_id through the download stack for the file room. --- modules/console.cc | 3 ++- modules/media/download.cc | 11 ++++++++++- modules/media/media.cc | 13 ++++++++----- modules/media/media.h | 5 ++++- modules/media/thumbnail.cc | 11 ++++++++++- modules/media/upload.cc | 2 +- 6 files changed, 35 insertions(+), 10 deletions(-) diff --git a/modules/console.cc b/modules/console.cc index 5b60a7463..b73be179b 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -4589,6 +4589,7 @@ console_cmd__file__download(opt &out, const string_view &line) using prototype = m::room::id::buf (const string_view &server, const string_view &file, + const m::user::id &, const net::hostport &remote); static m::import download @@ -4598,7 +4599,7 @@ console_cmd__file__download(opt &out, const string_view &line) const m::room::id::buf room_id { - download(server, file, remote) + download(server, file, m::me.user_id, remote) }; out << room_id << std::endl; diff --git a/modules/media/download.cc b/modules/media/download.cc index e8c6a4915..286040583 100644 --- a/modules/media/download.cc +++ b/modules/media/download.cc @@ -57,9 +57,18 @@ get__download(client &client, request.parv[1] }; + // Download doesn't require auth so if there is no user_id detected + // then we download on behalf of @ircd. + const m::user::id &user_id + { + request.user_id? + m::user::id{request.user_id}: + m::me.user_id + }; + const m::room::id::buf room_id { - download(server, file) + download(server, file, user_id) }; return get__download_local(client, request, server, file, room_id); diff --git a/modules/media/media.cc b/modules/media/media.cc index 9dea8e499..53dc2d932 100644 --- a/modules/media/media.cc +++ b/modules/media/media.cc @@ -31,6 +31,7 @@ downloading_dock; m::room::id::buf download(const string_view &server, const string_view &mediaid, + const m::user::id &user_id, const net::hostport &remote) { const m::room::id::buf room_id @@ -38,13 +39,14 @@ download(const string_view &server, file_room_id(server, mediaid) }; - download(server, mediaid, remote, room_id); + download(server, mediaid, user_id, remote, room_id); return room_id; } m::room download(const string_view &server, const string_view &mediaid, + const m::user::id &user_id, const net::hostport &remote, const m::room::id &room_id) try @@ -115,11 +117,11 @@ try room_id, &vmopts }; - create(room, m::me.user_id, "file"); + create(room, user_id, "file"); const size_t written { - write_file(room, content, content_type) + write_file(room, user_id, content, content_type) }; return room; @@ -197,17 +199,18 @@ download(const mutable_buffer &head_buf, size_t write_file(const m::room &room, + const m::user::id &user_id, const const_buffer &content, const string_view &content_type) { //TODO: TXN - send(room, m::me.user_id, "ircd.file.stat", "size", + send(room, user_id, "ircd.file.stat", "size", { { "value", long(size(content)) } }); //TODO: TXN - send(room, m::me.user_id, "ircd.file.stat", "type", + send(room, user_id, "ircd.file.stat", "type", { { "value", content_type } }); diff --git a/modules/media/media.h b/modules/media/media.h index 540d72369..0e5cee8e0 100644 --- a/modules/media/media.h +++ b/modules/media/media.h @@ -27,7 +27,8 @@ read_each_block(const m::room &, const std::function &); extern "C" size_t -write_file(const m::room &room, +write_file(const m::room &, + const m::user::id &, const const_buffer &content, const string_view &content_type); @@ -41,10 +42,12 @@ download(const mutable_buffer &head_buf, m::room download(const string_view &server, const string_view &mediaid, + const m::user::id &user_id, const net::hostport &remote, const m::room::id &room_id); extern "C" m::room::id::buf download(const string_view &server, const string_view &mediaid, + const m::user::id &user_id, const net::hostport &remote = {}); diff --git a/modules/media/thumbnail.cc b/modules/media/thumbnail.cc index f39ced88f..a494e66a2 100644 --- a/modules/media/thumbnail.cc +++ b/modules/media/thumbnail.cc @@ -69,9 +69,18 @@ get__thumbnail(client &client, request.parv[1] }; + // Thumbnail doesn't require auth so if there is no user_id detected + // then we download on behalf of @ircd. + const m::user::id &user_id + { + request.user_id? + m::user::id{request.user_id}: + m::me.user_id + }; + const m::room::id::buf room_id { - download(server, file) + download(server, file, user_id) }; return get__thumbnail_local(client, request, server, file, room_id); diff --git a/modules/media/upload.cc b/modules/media/upload.cc index ba05fd4f2..a774c06e4 100644 --- a/modules/media/upload.cc +++ b/modules/media/upload.cc @@ -78,7 +78,7 @@ post__upload(client &client, const size_t written { - write_file(room, buf, content_type) + write_file(room, request.user_id, buf, content_type) }; char uribuf[256];