2022-01-01 23:50:23 +01:00

63 lines
1.3 KiB
C++

#ifndef GERMANAIRLINESVA_GACONNECTOR_WEBSOCKET_H
#define GERMANAIRLINESVA_GACONNECTOR_WEBSOCKET_H
#define BUFSIZE 1024
#define MD5LEN 16
#include <IXNetSystem.h>
#include <IXWebSocketServer.h>
#include <json.hpp>
#include "types.h"
#ifdef IBM
// clang-format off
#include <wtypes.h>
#include <wincrypt.h>
// clang-format on
#endif
#ifdef APL
#include <CommonCrypto/CommonDigest.h>
#include <sys/mman.h>
#endif
#ifdef LIN
#include <openssl/md5.h>
#include <sys/mman.h>
#endif
#include <cstring>
#include <functional>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
class websocket
{
private:
char lastPath[513] = "";
char lastHash[2 * MD5LEN + 1] = "";
ix::WebSocket *webSocket = nullptr;
ix::WebSocketServer *server;
std::mutex wsLock;
std::function<void(std::string)> toLog;
public:
explicit websocket(std::function<void(const std::string)> toLog);
~websocket();
void onClientMessageCallback(
std::shared_ptr<ix::ConnectionState> &connectionState,
ix::WebSocket &ws,
const ix::WebSocketMessagePtr &msg);
void sendData(data d);
int generateMD5(const char *filepath);
};
#if defined APL || defined LIN
unsigned long get_size_by_fd(int fd);
#endif
void to_hex(const char *hash, char *buffer);
#endif