This repository has been archived on 2021-12-16. You can view files and clone it, but cannot push or open issues or pull requests.
lemonbbs/src/oslib.h
2021-12-15 18:52:53 +01:00

41 lines
1.2 KiB
C

// LemonOSLib (lolib): simple system abstractions made specifically for LemonBBS
#ifndef LEMONBBS_OSLIB_H
#define LEMONBBS_OSLIB_H
#include <openssl/ssl.h>
#ifdef _WIN32
#include <Ws2tcpip.h>
#elif defined(unix)
typedef int SOCKET;
#define INVALID_SOCKET -1
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#else
#error Platform not supported.
#endif
struct LemonClientSocket {
int type;
union Descriptor {
SSL* sslDescriptor;
SOCKET tcpDescriptor;
} descriptor;
};
typedef SOCKET LemonServerSocket;
int lolib_init();
int lolib_quit();
int lolib_finalize(struct LemonClientSocket *socket);
int lolib_enableSsl(const char* certfilePath, const char* keyfilePath, char* keyfilePassword);
int lolib_createServerSocket(const char* bindAddress, unsigned short port, LemonServerSocket *dst);
int lolib_acceptTcpSocket(LemonServerSocket serverSocket, struct LemonClientSocket *dst);
int lolib_acceptSslSocket(LemonServerSocket serverSocket, struct LemonClientSocket *dst);
int lolib_writeSocket(struct LemonClientSocket *socket, const char* data, unsigned int dataLength);
int lolib_readSocket(struct LemonClientSocket *socket, char *data, unsigned int bytesToRead);
#endif