2022-12-21 00:38:10 +02:00
|
|
|
#ifndef _JITTERBUG__SERVER_H
|
|
|
|
#define _JITTERBUG__SERVER_H
|
|
|
|
|
2022-12-29 20:10:36 +02:00
|
|
|
#include "match.h"
|
2022-12-21 00:38:10 +02:00
|
|
|
#include <poll.h>
|
2022-12-21 21:38:48 +02:00
|
|
|
#include <stdint.h>
|
2022-12-21 00:38:10 +02:00
|
|
|
|
2022-12-21 21:38:48 +02:00
|
|
|
// TODO: dynamically size the arrays
|
|
|
|
#define JB_MAX_CLIENTS 256
|
|
|
|
#define JB_MAX_NAMES 512
|
2022-12-31 17:55:32 +02:00
|
|
|
#define JB_MAX_MATCH 12
|
2022-12-21 21:38:48 +02:00
|
|
|
#define JB_BACKLOG 12
|
2022-12-21 00:38:10 +02:00
|
|
|
|
|
|
|
enum {
|
|
|
|
JB_CLIENT_STATE_NONE,
|
|
|
|
JB_CLIENT_STATE_WAIT_AUTH,
|
|
|
|
JB_CLIENT_STATE_WAIT_BEGIN,
|
|
|
|
JB_CLIENT_STATE_READY
|
|
|
|
};
|
|
|
|
|
|
|
|
struct jb_client {
|
|
|
|
int fd;
|
2022-12-21 21:38:48 +02:00
|
|
|
uint8_t state;
|
|
|
|
int16_t unique_name_index;
|
|
|
|
int16_t owned_name_index;
|
2022-12-31 17:55:32 +02:00
|
|
|
int8_t match_count;
|
|
|
|
match_rule_t *matches[JB_MAX_MATCH];
|
2022-12-21 21:38:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct jb_name {
|
|
|
|
char *name;
|
2022-12-29 20:10:36 +02:00
|
|
|
int32_t client_index;
|
|
|
|
};
|
|
|
|
|
2022-12-21 00:38:10 +02:00
|
|
|
struct jb_server {
|
|
|
|
int sock_fd;
|
|
|
|
int fd_num;
|
2022-12-26 18:05:12 +02:00
|
|
|
int names_count;
|
2022-12-31 17:55:32 +02:00
|
|
|
int clients_count;
|
2022-12-21 00:38:10 +02:00
|
|
|
struct jb_client clients[JB_MAX_CLIENTS];
|
2022-12-21 21:38:48 +02:00
|
|
|
struct jb_name names[JB_MAX_NAMES];
|
2022-12-21 00:38:10 +02:00
|
|
|
struct pollfd fds[JB_MAX_CLIENTS + 1];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int jb_server_client_add(struct jb_server *s, int fd);
|
|
|
|
void jb_server_client_remove(struct jb_server *s, int i);
|
|
|
|
void jb_server_free(struct jb_server *s);
|
|
|
|
struct jb_server *jb_server_create(const char *socket_path);
|
|
|
|
int jb_server_turn(struct jb_server *s);
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _JITTERBUG__SERVER_H
|