mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 08:50:40 +01:00
Preserve granted clipboard capability across locked-session handshake and test closed state
This commit is contained in:
1 parent
a18a69c19e
commit
66c8bb3249
4 files changed
+116
-1
No files matched your search
@@ -94,6 +94,7 @@ static void selection_transfer(GDBusConnection *bus,const gchar *sender,const gc
|
||||
g_variant_new("(oub)",p->session,serial,success),NULL,G_DBUS_CALL_FLAGS_NONE,2000,NULL,NULL);
|
||||
if (reply) g_variant_unref(reply);
|
||||
}
|
||||
int uu_portal_clipboard_supported(struct uu_portal *p) { return p && p->clipboard_enabled; }
|
||||
int uu_portal_clipboard_ready(struct uu_portal *p) { return p && p->clipboard_enabled && uu_portal_alive(p); }
|
||||
int uu_portal_clipboard_set(struct uu_portal *p,const uint8_t *text,size_t length) {
|
||||
if (!uu_portal_clipboard_ready(p) || length>CLIP_LIMIT || !g_utf8_validate((const char *)text,(gssize)length,NULL)) return -1;
|
||||
|
||||
@@ -10,6 +10,7 @@ mod native {
|
||||
use std::{ffi::c_void, ptr::NonNull, sync::Mutex};
|
||||
extern "C" {
|
||||
fn uu_portal_open_persist(restore: *const libc::c_char, save: extern "C" fn(*const libc::c_char, *mut c_void), data: *mut c_void, error: *mut i32, width: *mut u32, height: *mut u32) -> *mut c_void;
|
||||
fn uu_portal_clipboard_supported(portal: *mut c_void) -> i32;
|
||||
fn uu_portal_clipboard_ready(portal: *mut c_void) -> i32;
|
||||
fn uu_portal_clipboard_set(portal: *mut c_void, text: *const u8, length: usize) -> i32;
|
||||
fn uu_portal_clipboard_poll(portal: *mut c_void, text: *mut u8, capacity: usize) -> i32;
|
||||
@@ -89,6 +90,9 @@ mod native {
|
||||
if code == 10 || code == 9 { super::blank(frame); Ok(()) } else { super::check(code) }
|
||||
}
|
||||
|
||||
pub fn clipboard_supported(&self) -> bool {
|
||||
self.handle.lock().is_ok_and(|handle| unsafe { uu_portal_clipboard_supported(handle.0.as_ptr()) != 0 })
|
||||
}
|
||||
pub fn clipboard_ready(&self) -> bool {
|
||||
self.handle.lock().is_ok_and(|handle| unsafe { uu_portal_clipboard_ready(handle.0.as_ptr()) != 0 })
|
||||
}
|
||||
@@ -144,6 +148,7 @@ pub use native::Session as PortalSession;
|
||||
pub struct PortalSession { pub width: u32, pub height: u32 }
|
||||
#[cfg(not(all(target_os = "linux", feature = "portal")))]
|
||||
impl PortalSession {
|
||||
pub fn clipboard_supported(&self) -> bool { false }
|
||||
pub fn clipboard_ready(&self) -> bool { false }
|
||||
pub fn clipboard_set(&self, _: &str) -> Result<(), String> { Err(error(2)) }
|
||||
pub fn clipboard_poll(&self) -> Option<String> { None }
|
||||
|
||||
+5
-1
@@ -271,7 +271,11 @@ impl WebRtcSession {
|
||||
let input_clone = input.clone();
|
||||
let control_capture = capture.clone();
|
||||
let control_sequence = Arc::new(std::sync::atomic::AtomicU64::new(1));
|
||||
let text_clipboard_ready = Arc::new(std::sync::atomic::AtomicBool::new(false));
|
||||
// Capability belongs to the granted session, including while GNOME is
|
||||
// locked. Echo can precede TEXT readiness and CONTROL auto-unlock;
|
||||
// advertising false here would disable clipboard for the entire peer.
|
||||
let portal_clipboard_supported = desktop && capture.portal.as_ref().is_some_and(|session| session.clipboard_supported());
|
||||
let text_clipboard_ready = Arc::new(std::sync::atomic::AtomicBool::new(portal_clipboard_supported));
|
||||
// One file-transfer session per peer. The viewer may send FileTransferFtp RPCs on CONTROL,
|
||||
// but it receives file traffic only through streamerDidReceiveFileData, so every reply and
|
||||
// host-initiated request goes out on FILE_DATA_CHANNEL.
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
#define _GNU_SOURCE
|
||||
/* Protocol-independent C bounds/lifecycle checks; never requests consent. */
|
||||
#include <assert.h>
|
||||
#include "portal_engine.c"
|
||||
static void clipboard_bounds(void) {
|
||||
int fds[2]; uint8_t bytes[8]={0};
|
||||
assert(pipe2(fds,O_NONBLOCK)==0);
|
||||
assert(write(fds[1],"abc",3)==3); close(fds[1]);
|
||||
assert(clipboard_io(fds[0],bytes,4,0)==3 && !memcmp(bytes,"abc",3)); close(fds[0]);
|
||||
assert(pipe2(fds,O_NONBLOCK)==0);
|
||||
assert(write(fds[1],"1234",4)==4); close(fds[1]);
|
||||
assert(clipboard_io(fds[0],bytes,4,0)==-1); close(fds[0]);
|
||||
assert(pipe2(fds,O_NONBLOCK)==0); close(fds[0]);
|
||||
assert(clipboard_io(fds[1],bytes,1,1)==-1); close(fds[1]);
|
||||
assert(clipboard_io(-1,bytes,0,1)==0);
|
||||
}
|
||||
int main(void) {
|
||||
clipboard_bounds();
|
||||
struct uu_portal *p = calloc(1, sizeof(*p));
|
||||
assert(p);
|
||||
pthread_mutex_init(&p->lock, NULL);
|
||||
pthread_cond_init(&p->changed, NULL);
|
||||
uint8_t storage[256];
|
||||
struct spa_pod_builder builder = SPA_POD_BUILDER_INIT(storage, sizeof(storage));
|
||||
const struct spa_pod *format = spa_format_video_raw_build(&builder, SPA_PARAM_Format,
|
||||
&SPA_VIDEO_INFO_RAW_INIT(.format=SPA_VIDEO_FORMAT_BGRA, .size=SPA_RECTANGLE(2,2), .framerate=SPA_FRACTION(60,1)));
|
||||
stream_format(p, SPA_PARAM_Format, format);
|
||||
assert(p->width == 2 && p->height == 2 && p->frame_length == 16 && !p->error);
|
||||
uint8_t pixels[16] = {0};
|
||||
assert(uu_portal_capture(p, pixels, sizeof(pixels)) == 10);
|
||||
p->sequence = 1;
|
||||
assert(uu_portal_capture(p, pixels, sizeof(pixels)-1) == 11);
|
||||
assert(uu_portal_capture(p, pixels, sizeof(pixels)) == 0);
|
||||
p->logical_width = p->logical_height = 2;
|
||||
assert(uu_portal_move(p, NAN, 1, 0) == 11);
|
||||
assert(uu_portal_move(p, 2, 1, 0) == 11);
|
||||
assert(uu_portal_alive(p));
|
||||
/* Synthetic RGBA with row padding validates both channel order and stride. */
|
||||
uint8_t source[24] = {255,0,0,255, 0,255,0,255, 99,99,99,99,
|
||||
0,0,255,255, 255,255,255,255, 88,88,88,88};
|
||||
struct spa_chunk chunk = {.offset=0, .size=20, .stride=12};
|
||||
struct spa_data data = {.type=SPA_DATA_MemPtr, .data=source, .maxsize=24, .chunk=&chunk};
|
||||
struct spa_buffer buffer = {.n_datas=1, .datas=&data};
|
||||
p->format=SPA_VIDEO_FORMAT_RGBA;
|
||||
copy_video_buffer(p, &buffer);
|
||||
const uint8_t expected[16] = {0,0,255,255, 0,255,0,255, 255,0,0,255, 255,255,255,255};
|
||||
assert(!memcmp(p->frame, expected, 16) && p->sequence == 2);
|
||||
/* Capacity still contains old bytes, but zero/short chunks are not frames. */
|
||||
for (unsigned size=0; size<20; size++) {
|
||||
chunk.size=size; copy_video_buffer(p, &buffer);
|
||||
assert(p->sequence == 2 && !memcmp(p->frame, expected, 16) && !p->error);
|
||||
}
|
||||
chunk.size=20; chunk.flags=SPA_CHUNK_FLAG_CORRUPTED;
|
||||
copy_video_buffer(p, &buffer);
|
||||
assert(p->sequence==2 && !p->error);
|
||||
chunk.flags=0;
|
||||
struct spa_meta_header header={.flags=SPA_META_HEADER_FLAG_CORRUPTED};
|
||||
struct spa_meta metadata={.type=SPA_META_Header, .size=sizeof(header), .data=&header};
|
||||
buffer.n_metas=1; buffer.metas=&metadata;
|
||||
copy_video_buffer(p, &buffer); assert(p->sequence==2 && !p->error);
|
||||
buffer.n_metas=0; buffer.metas=NULL;
|
||||
/* Explicit EMPTY is opaque black rather than a stale desktop image. */
|
||||
chunk.size=0; chunk.flags=SPA_CHUNK_FLAG_EMPTY;
|
||||
copy_video_buffer(p, &buffer); assert(p->sequence==3);
|
||||
for (unsigned pixel=0; pixel<4; pixel++) {
|
||||
assert(p->frame[pixel*4]==0 && p->frame[pixel*4+1]==0 && p->frame[pixel*4+2]==0 && p->frame[pixel*4+3]==255);
|
||||
}
|
||||
/* A valid buffer after corruption remains usable; no permanent failure. */
|
||||
chunk.size=20; chunk.flags=0; copy_video_buffer(p, &buffer);
|
||||
assert(p->sequence==4 && !memcmp(p->frame, expected, 16));
|
||||
uu_portal_reset_frame(p);
|
||||
assert(uu_portal_capture(p, pixels, sizeof(pixels)) == 10);
|
||||
copy_video_buffer(p, &buffer);
|
||||
assert(uu_portal_capture(p, pixels, sizeof(pixels)) == 0);
|
||||
p->session=g_strdup("/uu_test_session");
|
||||
GVariantBuilder clip_options; g_variant_builder_init(&clip_options,G_VARIANT_TYPE_VARDICT);
|
||||
const char *types[]={"image/png","text/plain",NULL};
|
||||
g_variant_builder_add(&clip_options,"{sv}","mime_types",g_variant_new_strv(types,-1));
|
||||
GVariant *event=g_variant_ref_sink(g_variant_new("(o@a{sv})",p->session,g_variant_builder_end(&clip_options)));
|
||||
selection_owner(NULL,NULL,NULL,NULL,NULL,event,p); g_variant_unref(event);
|
||||
assert(p->clipboard_changed && !strcmp(p->clipboard_mime,"text/plain"));
|
||||
g_variant_builder_init(&clip_options,G_VARIANT_TYPE_VARDICT);
|
||||
g_variant_builder_add(&clip_options,"{sv}","session_is_owner",g_variant_new_boolean(TRUE));
|
||||
event=g_variant_ref_sink(g_variant_new("(o@a{sv})",p->session,g_variant_builder_end(&clip_options)));
|
||||
selection_owner(NULL,NULL,NULL,NULL,NULL,event,p); g_variant_unref(event);
|
||||
assert(!p->clipboard_changed && !p->clipboard_mime);
|
||||
assert(uu_portal_clipboard_set(p,(const uint8_t *)"x",1)==-1);
|
||||
assert(uu_portal_clipboard_poll(p,NULL,CLIP_LIMIT)==-1);
|
||||
p->error=8;
|
||||
assert(!uu_portal_alive(p));
|
||||
assert(uu_portal_key(p, 'a', 1)==9); /* no input into an unusable stream */
|
||||
p->error=0;
|
||||
p->clipboard_enabled=1;
|
||||
assert(uu_portal_clipboard_supported(p));
|
||||
assert(uu_portal_clipboard_ready(p));
|
||||
atomic_store(&p->closed, 1);
|
||||
/* Closing a granted session temporarily removes readiness, not capability. */
|
||||
assert(uu_portal_clipboard_supported(p));
|
||||
assert(!uu_portal_clipboard_ready(p));
|
||||
assert(!uu_portal_alive(p));
|
||||
assert(uu_portal_capture(p, pixels, sizeof(pixels)) == 9);
|
||||
uu_portal_close(p);
|
||||
puts("Portal C bounds/lifecycle checks passed");
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user