Skip to content

Commit

Permalink
Refactor rdpdr client (#12750)
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaiah Becker-Mayer authored Jun 25, 2022
1 parent 7a651a7 commit 41577e8
Show file tree
Hide file tree
Showing 4 changed files with 356 additions and 299 deletions.
9 changes: 4 additions & 5 deletions lib/srv/desktop/rdp/rdpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,11 @@ func (c *Client) start() {
defer C.free(unsafe.Pointer(path))
if errCode := C.handle_tdp_sd_info_response(c.rustClient, C.CGOSharedDirectoryInfoResponse{
completion_id: C.uint32_t(m.CompletionID),
err_code: C.uint32_t(m.ErrCode),
err_code: m.ErrCode,
fso: C.CGOFileSystemObject{
last_modified: C.uint64_t(m.Fso.LastModified),
size: C.uint64_t(m.Fso.Size),
file_type: C.uint32_t(m.Fso.FileType),
file_type: m.Fso.FileType,
path: path,
},
}); errCode != C.ErrCodeSuccess {
Expand All @@ -417,7 +417,7 @@ func (c *Client) start() {
if c.cfg.AllowDirectorySharing {
if errCode := C.handle_tdp_sd_create_response(c.rustClient, C.CGOSharedDirectoryCreateResponse{
completion_id: C.uint32_t(m.CompletionID),
err_code: C.uint32_t(m.ErrCode),
err_code: m.ErrCode,
}); errCode != C.ErrCodeSuccess {
c.cfg.Log.Errorf("SharedDirectoryCreateResponse failed: %v", errCode)
return
Expand All @@ -427,7 +427,7 @@ func (c *Client) start() {
if c.cfg.AllowDirectorySharing {
if errCode := C.handle_tdp_sd_delete_response(c.rustClient, C.CGOSharedDirectoryDeleteResponse{
completion_id: C.uint32_t(m.CompletionID),
err_code: C.uint32_t(m.ErrCode),
err_code: m.ErrCode,
}); errCode != C.ErrCodeSuccess {
c.cfg.Log.Errorf("SharedDirectoryDeleteResponse failed: %v", errCode)
return
Expand Down Expand Up @@ -506,7 +506,6 @@ func tdp_sd_acknowledge(handle C.uintptr_t, ack *C.CGOSharedDirectoryAcknowledge
})
}

// sharedDirectoryAcknowledge acknowledges that a `Shared Directory Announce` TDP message was processed.
func (c *Client) sharedDirectoryAcknowledge(ack tdp.SharedDirectoryAcknowledge) C.CGOErrCode {
if c.cfg.AllowDirectorySharing {
if err := c.cfg.Conn.OutputMessage(ack); err != nil {
Expand Down
34 changes: 29 additions & 5 deletions lib/srv/desktop/rdp/rdpclient/librdprs.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ typedef enum CGOPointerWheel {
PointerWheelHorizontal,
} CGOPointerWheel;

typedef enum FileType {
File = 0,
Directory = 1,
} FileType;

typedef enum TdpErrCode {
/**
* nil (no error, operation succeeded)
*/
Nil = 0,
/**
* operation failed
*/
Failed = 1,
/**
* resource does not exist
*/
DoesNotExist = 2,
/**
* resource already exists
*/
AlreadyExists = 3,
} TdpErrCode;

/**
* Client has an unusual lifecycle:
* - connect_rdp creates it on the heap, grabs a raw pointer and returns in to Go
Expand Down Expand Up @@ -82,13 +106,13 @@ typedef struct CGOSharedDirectoryAnnounce {
typedef struct CGOFileSystemObject {
uint64_t last_modified;
uint64_t size;
uint32_t file_type;
enum FileType file_type;
const char *path;
} CGOFileSystemObject;

typedef struct CGOSharedDirectoryInfoResponse {
uint32_t completion_id;
uint32_t err_code;
enum TdpErrCode err_code;
struct CGOFileSystemObject fso;
} CGOSharedDirectoryInfoResponse;

Expand All @@ -98,7 +122,7 @@ typedef struct CGOSharedDirectoryInfoResponse {
*/
typedef struct SharedDirectoryCreateResponse {
uint32_t completion_id;
uint32_t err_code;
enum TdpErrCode err_code;
} SharedDirectoryCreateResponse;

typedef struct SharedDirectoryCreateResponse CGOSharedDirectoryCreateResponse;
Expand Down Expand Up @@ -149,7 +173,7 @@ typedef struct CGOBitmap {
* to acknowledge that a SharedDirectoryAnnounce was received.
*/
typedef struct SharedDirectoryAcknowledge {
uint32_t err_code;
enum TdpErrCode err_code;
uint32_t directory_id;
} SharedDirectoryAcknowledge;

Expand All @@ -164,7 +188,7 @@ typedef struct CGOSharedDirectoryInfoRequest {
typedef struct CGOSharedDirectoryCreateRequest {
uint32_t completion_id;
uint32_t directory_id;
uint32_t file_type;
enum FileType file_type;
const char *path;
} CGOSharedDirectoryCreateRequest;

Expand Down
36 changes: 28 additions & 8 deletions lib/srv/desktop/rdp/rdpclient/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ pub struct CGOSharedDirectoryAnnounce {
#[derive(Debug)]
#[repr(C)]
pub struct SharedDirectoryAcknowledge {
pub err_code: u32,
pub err_code: TdpErrCode,
pub directory_id: u32,
}

Expand Down Expand Up @@ -1027,14 +1027,14 @@ impl From<ServerCreateDriveRequest> for SharedDirectoryInfoRequest {
#[allow(dead_code)]
pub struct SharedDirectoryInfoResponse {
completion_id: u32,
err_code: u32,
err_code: TdpErrCode,
fso: FileSystemObject,
}

#[repr(C)]
pub struct CGOSharedDirectoryInfoResponse {
pub completion_id: u32,
pub err_code: u32,
pub err_code: TdpErrCode,
pub fso: CGOFileSystemObject,
}

Expand All @@ -1055,15 +1055,15 @@ impl From<CGOSharedDirectoryInfoResponse> for SharedDirectoryInfoResponse {
pub struct FileSystemObject {
last_modified: u64,
size: u64,
file_type: u32, // TODO(isaiah): make an enum
file_type: FileType,
path: String,
}

#[repr(C)]
pub struct CGOFileSystemObject {
pub last_modified: u64,
pub size: u64,
pub file_type: u32, // TODO(isaiah): make an enum
pub file_type: FileType,
pub path: *const c_char,
}

Expand All @@ -1080,21 +1080,41 @@ impl From<CGOFileSystemObject> for FileSystemObject {
}
}

#[repr(C)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum FileType {
File = 0,
Directory = 1,
}

#[repr(C)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum TdpErrCode {
/// nil (no error, operation succeeded)
Nil = 0,
/// operation failed
Failed = 1,
/// resource does not exist
DoesNotExist = 2,
/// resource already exists
AlreadyExists = 3,
}

/// SharedDirectoryCreateRequest is sent by the TDP server to
/// the client to request the creation of a new file or directory.
#[derive(Debug)]
pub struct SharedDirectoryCreateRequest {
completion_id: u32,
directory_id: u32,
file_type: u32,
file_type: FileType,
path: String,
}

#[repr(C)]
pub struct CGOSharedDirectoryCreateRequest {
pub completion_id: u32,
pub directory_id: u32,
pub file_type: u32,
pub file_type: FileType,
pub path: *const c_char,
}

Expand All @@ -1104,7 +1124,7 @@ pub struct CGOSharedDirectoryCreateRequest {
#[repr(C)]
pub struct SharedDirectoryCreateResponse {
pub completion_id: u32,
pub err_code: u32,
pub err_code: TdpErrCode,
}

type CGOSharedDirectoryCreateResponse = SharedDirectoryCreateResponse;
Expand Down
Loading

0 comments on commit 41577e8

Please sign in to comment.