2021-03-02 14:23:32 +01:00
|
|
|
/* Copyright (C) 2021 Kasm
|
|
|
|
*
|
|
|
|
* This is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this software; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
|
|
* USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __NETWORK_GET_API_H__
|
|
|
|
#define __NETWORK_GET_API_H__
|
|
|
|
|
2021-03-03 13:55:14 +01:00
|
|
|
#include <kasmpasswd.h>
|
2021-03-02 14:23:32 +01:00
|
|
|
#include <pthread.h>
|
2022-01-17 18:10:24 +01:00
|
|
|
#include <network/GetAPIEnums.h>
|
2021-03-02 14:23:32 +01:00
|
|
|
#include <rfb/PixelBuffer.h>
|
|
|
|
#include <rfb/PixelFormat.h>
|
|
|
|
#include <stdint.h>
|
2021-07-26 17:58:29 +02:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2021-03-02 14:23:32 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace network {
|
|
|
|
|
|
|
|
class GetAPIMessager {
|
|
|
|
public:
|
2021-03-03 13:55:14 +01:00
|
|
|
GetAPIMessager(const char *passwdfile_);
|
2021-03-02 14:23:32 +01:00
|
|
|
|
|
|
|
// from main thread
|
|
|
|
void mainUpdateScreen(rfb::PixelBuffer *pb);
|
2021-07-26 17:58:29 +02:00
|
|
|
void mainUpdateBottleneckStats(const char userid[], const char stats[]);
|
2021-08-02 11:45:51 +02:00
|
|
|
void mainClearBottleneckStats(const char userid[]);
|
2021-07-27 14:33:48 +02:00
|
|
|
void mainUpdateServerFrameStats(uint8_t changedPerc, uint32_t all,
|
|
|
|
uint32_t jpeg, uint32_t webp, uint32_t analysis,
|
|
|
|
uint32_t jpegarea, uint32_t webparea,
|
|
|
|
uint16_t njpeg, uint16_t nwebp,
|
2021-08-02 12:47:48 +02:00
|
|
|
uint16_t enc, uint16_t scale, uint16_t shot,
|
2021-07-27 14:33:48 +02:00
|
|
|
uint16_t w, uint16_t h);
|
|
|
|
void mainUpdateClientFrameStats(const char userid[], uint32_t render, uint32_t all,
|
|
|
|
uint32_t ping);
|
|
|
|
void mainUpdateUserInfo(const uint8_t ownerConn, const uint8_t numUsers);
|
2021-03-02 14:23:32 +01:00
|
|
|
|
|
|
|
// from network threads
|
|
|
|
uint8_t *netGetScreenshot(uint16_t w, uint16_t h,
|
|
|
|
const uint8_t q, const bool dedup,
|
|
|
|
uint32_t &len, uint8_t *staging);
|
2022-01-28 13:24:38 +01:00
|
|
|
uint8_t netAddUser(const char name[], const char pw[],
|
|
|
|
const bool read, const bool write, const bool owner);
|
2021-03-03 13:55:14 +01:00
|
|
|
uint8_t netRemoveUser(const char name[]);
|
2022-01-24 17:42:29 +01:00
|
|
|
uint8_t netUpdateUser(const char name[], const uint64_t mask,
|
|
|
|
const char password[],
|
2022-01-28 13:24:38 +01:00
|
|
|
const bool read, const bool write, const bool owner);
|
2022-01-24 17:42:29 +01:00
|
|
|
uint8_t netAddOrUpdateUser(const struct kasmpasswd_entry_t *entry);
|
2022-01-17 18:10:24 +01:00
|
|
|
void netGetUsers(const char **ptr);
|
2021-07-26 17:58:29 +02:00
|
|
|
void netGetBottleneckStats(char *buf, uint32_t len);
|
2021-07-27 14:33:48 +02:00
|
|
|
void netGetFrameStats(char *buf, uint32_t len);
|
2022-01-28 13:24:38 +01:00
|
|
|
void netResetFrameStatsCall();
|
2021-07-27 14:33:48 +02:00
|
|
|
uint8_t netServerFrameStatsReady();
|
2022-07-26 12:38:14 +02:00
|
|
|
void netUdpUpgrade(void *client, uint32_t ip);
|
2023-01-09 12:32:30 +01:00
|
|
|
void netClearClipboard();
|
2021-03-03 13:55:14 +01:00
|
|
|
|
|
|
|
enum USER_ACTION {
|
2022-01-28 13:24:38 +01:00
|
|
|
NONE,
|
2021-07-27 14:33:48 +02:00
|
|
|
WANT_FRAME_STATS_SERVERONLY,
|
|
|
|
WANT_FRAME_STATS_ALL,
|
|
|
|
WANT_FRAME_STATS_OWNER,
|
|
|
|
WANT_FRAME_STATS_SPECIFIC,
|
2023-01-09 12:32:30 +01:00
|
|
|
UDP_UPGRADE,
|
|
|
|
CLEAR_CLIPBOARD,
|
2021-03-03 13:55:14 +01:00
|
|
|
};
|
|
|
|
|
2021-07-27 14:33:48 +02:00
|
|
|
uint8_t netRequestFrameStats(USER_ACTION what, const char *client);
|
|
|
|
uint8_t netOwnerConnected();
|
|
|
|
uint8_t netNumActiveUsers();
|
|
|
|
uint8_t netGetClientFrameStatsNum();
|
|
|
|
|
2021-03-03 13:55:14 +01:00
|
|
|
struct action_data {
|
|
|
|
enum USER_ACTION action;
|
2022-07-26 12:38:14 +02:00
|
|
|
union {
|
|
|
|
kasmpasswd_entry_t data;
|
|
|
|
struct {
|
|
|
|
void *client;
|
|
|
|
uint32_t ip;
|
|
|
|
} udp;
|
|
|
|
};
|
2021-03-03 13:55:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
pthread_mutex_t userMutex;
|
|
|
|
std::vector<action_data> actionQueue;
|
|
|
|
|
2021-03-02 14:23:32 +01:00
|
|
|
private:
|
2021-03-03 13:55:14 +01:00
|
|
|
const char *passwdfile;
|
|
|
|
|
2021-03-02 14:23:32 +01:00
|
|
|
pthread_mutex_t screenMutex;
|
|
|
|
rfb::ManagedPixelBuffer screenPb;
|
|
|
|
uint16_t screenW, screenH;
|
|
|
|
uint64_t screenHash;
|
|
|
|
|
|
|
|
std::vector<uint8_t> cachedJpeg;
|
|
|
|
uint16_t cachedW, cachedH;
|
|
|
|
uint8_t cachedQ;
|
2021-07-26 17:58:29 +02:00
|
|
|
|
|
|
|
std::map<std::string, std::string> bottleneckStats;
|
|
|
|
pthread_mutex_t statMutex;
|
2021-07-27 14:33:48 +02:00
|
|
|
|
|
|
|
struct clientFrameStats_t {
|
|
|
|
uint32_t render;
|
|
|
|
uint32_t all;
|
|
|
|
uint32_t ping;
|
|
|
|
};
|
|
|
|
struct serverFrameStats_t {
|
|
|
|
uint32_t all;
|
|
|
|
uint32_t jpeg;
|
|
|
|
uint32_t webp;
|
|
|
|
uint32_t analysis;
|
|
|
|
uint32_t jpegarea;
|
|
|
|
uint32_t webparea;
|
|
|
|
uint16_t njpeg;
|
|
|
|
uint16_t nwebp;
|
2021-08-02 12:47:48 +02:00
|
|
|
uint16_t enc;
|
|
|
|
uint16_t scale;
|
|
|
|
uint16_t shot;
|
2021-07-27 14:33:48 +02:00
|
|
|
uint16_t w;
|
|
|
|
uint16_t h;
|
|
|
|
uint8_t changedPerc;
|
|
|
|
|
|
|
|
uint8_t inprogress;
|
|
|
|
};
|
|
|
|
std::map<std::string, clientFrameStats_t> clientFrameStats;
|
|
|
|
serverFrameStats_t serverFrameStats;
|
|
|
|
pthread_mutex_t frameStatMutex;
|
|
|
|
|
|
|
|
uint8_t ownerConnected;
|
|
|
|
uint8_t activeUsers;
|
|
|
|
pthread_mutex_t userInfoMutex;
|
2021-03-02 14:23:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __NETWORK_GET_API_H__
|