2020-01-24 22:30:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 - 2020 Andri Yngvason
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2019-12-30 17:22:19 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <pixman.h>
|
2020-04-03 22:31:16 +00:00
|
|
|
#include <zlib.h>
|
2019-12-30 17:22:19 +00:00
|
|
|
|
|
|
|
#include "rfb-proto.h"
|
|
|
|
#include "sys/queue.h"
|
|
|
|
|
|
|
|
#include "neatvnc.h"
|
2020-04-02 21:52:04 +00:00
|
|
|
#include "tight.h"
|
2020-01-25 15:35:14 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifdef ENABLE_TLS
|
|
|
|
#include <gnutls/gnutls.h>
|
|
|
|
#endif
|
2019-12-30 17:22:19 +00:00
|
|
|
|
|
|
|
#define MAX_ENCODINGS 32
|
|
|
|
#define MAX_OUTGOING_FRAMES 4
|
|
|
|
#define MSG_BUFFER_SIZE 4096
|
|
|
|
|
|
|
|
enum nvnc_client_state {
|
|
|
|
VNC_CLIENT_STATE_ERROR = -1,
|
|
|
|
VNC_CLIENT_STATE_WAITING_FOR_VERSION = 0,
|
|
|
|
VNC_CLIENT_STATE_WAITING_FOR_SECURITY,
|
2020-01-25 15:35:14 +00:00
|
|
|
#ifdef ENABLE_TLS
|
|
|
|
VNC_CLIENT_STATE_WAITING_FOR_VENCRYPT_VERSION,
|
|
|
|
VNC_CLIENT_STATE_WAITING_FOR_VENCRYPT_SUBTYPE,
|
|
|
|
VNC_CLIENT_STATE_WAITING_FOR_VENCRYPT_PLAIN_AUTH,
|
|
|
|
#endif
|
2019-12-30 17:22:19 +00:00
|
|
|
VNC_CLIENT_STATE_WAITING_FOR_INIT,
|
|
|
|
VNC_CLIENT_STATE_READY,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nvnc;
|
2020-01-25 15:35:14 +00:00
|
|
|
struct stream;
|
2020-03-16 20:09:22 +00:00
|
|
|
struct aml_handler;
|
2019-12-30 17:22:19 +00:00
|
|
|
|
|
|
|
struct nvnc_common {
|
|
|
|
void* userdata;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nvnc_client {
|
|
|
|
struct nvnc_common common;
|
|
|
|
int ref;
|
2020-01-25 15:35:14 +00:00
|
|
|
struct stream* net_stream;
|
2019-12-30 17:22:19 +00:00
|
|
|
struct nvnc* server;
|
|
|
|
enum nvnc_client_state state;
|
2020-01-24 22:28:37 +00:00
|
|
|
bool has_pixfmt;
|
2019-12-30 17:22:19 +00:00
|
|
|
struct rfb_pixel_format pixfmt;
|
|
|
|
enum rfb_encodings encodings[MAX_ENCODINGS + 1];
|
|
|
|
size_t n_encodings;
|
|
|
|
LIST_ENTRY(nvnc_client) link;
|
|
|
|
struct pixman_region16 damage;
|
|
|
|
int n_pending_requests;
|
|
|
|
bool is_updating;
|
|
|
|
nvnc_client_fn cleanup_fn;
|
|
|
|
z_stream z_stream;
|
2020-04-02 21:52:04 +00:00
|
|
|
struct tight_encoder tight_encoder;
|
2019-12-30 17:22:19 +00:00
|
|
|
size_t buffer_index;
|
|
|
|
size_t buffer_len;
|
|
|
|
uint8_t msg_buffer[MSG_BUFFER_SIZE];
|
|
|
|
};
|
|
|
|
|
|
|
|
LIST_HEAD(nvnc_client_list, nvnc_client);
|
|
|
|
|
|
|
|
struct vnc_display {
|
|
|
|
uint16_t width;
|
|
|
|
uint16_t height;
|
|
|
|
uint32_t pixfmt; /* fourcc pixel format */
|
|
|
|
char name[256];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nvnc {
|
|
|
|
struct nvnc_common common;
|
2020-01-25 15:35:14 +00:00
|
|
|
int fd;
|
2020-03-16 20:09:22 +00:00
|
|
|
struct aml_handler* poll_handle;
|
2019-12-30 17:22:19 +00:00
|
|
|
struct nvnc_client_list clients;
|
|
|
|
struct vnc_display display;
|
|
|
|
void* userdata;
|
|
|
|
nvnc_key_fn key_fn;
|
|
|
|
nvnc_pointer_fn pointer_fn;
|
|
|
|
nvnc_fb_req_fn fb_req_fn;
|
|
|
|
nvnc_client_fn new_client_fn;
|
|
|
|
struct nvnc_fb* frame;
|
2020-01-25 15:35:14 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_TLS
|
|
|
|
gnutls_certificate_credentials_t tls_creds;
|
|
|
|
nvnc_auth_fn auth_fn;
|
|
|
|
void* auth_ud;
|
|
|
|
#endif
|
2019-12-30 17:22:19 +00:00
|
|
|
};
|