2022-12-21 00:38:10 +02:00
|
|
|
#ifndef _JITTERBUG__SERVER_H
|
|
|
|
#define _JITTERBUG__SERVER_H
|
|
|
|
|
2023-01-10 14:57:16 +02:00
|
|
|
#include "wire.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
|
|
|
|
2023-01-16 19:47:40 +02:00
|
|
|
#define MATCH_RULE_MAX 1024
|
|
|
|
#define MATCH_RULE_MAX_ARG 12
|
|
|
|
|
2023-01-19 02:46:49 +02:00
|
|
|
typedef struct {
|
2023-01-16 19:47:40 +02:00
|
|
|
uint8_t type;
|
|
|
|
bool eavesdrop;
|
|
|
|
char *sender, *interface, *member, *path, *path_namespace, *destination, *arg0namespace, *rule_string;
|
|
|
|
char *arg[MATCH_RULE_MAX_ARG]; /* TODO: spec states that indexes 0 to 63 should be supported */
|
|
|
|
char *arg_path[MATCH_RULE_MAX_ARG]; /* TODO: spec states that indexes 0 to 63 should be supported */
|
2023-01-19 02:46:49 +02:00
|
|
|
} MatchRule;
|
2023-01-16 19:47:40 +02:00
|
|
|
|
2022-12-21 21:38:48 +02:00
|
|
|
// TODO: dynamically size the arrays
|
2023-01-10 13:08:49 +02:00
|
|
|
#define BUS_MAX_CLIENTS 256
|
|
|
|
#define BUS_MAX_NAMES 512
|
|
|
|
#define BUS_MAX_MATCH 12
|
2023-01-16 19:47:40 +02:00
|
|
|
#define BUS_NAMES_PER_CLIENT 4
|
2023-01-10 13:08:49 +02:00
|
|
|
#define BUS_BACKLOG 12
|
2022-12-21 00:38:10 +02:00
|
|
|
|
|
|
|
enum {
|
2023-01-10 13:08:49 +02:00
|
|
|
BUS_CLIENT_STATE_NONE,
|
|
|
|
BUS_CLIENT_STATE_WAIT_AUTH,
|
|
|
|
BUS_CLIENT_STATE_WAIT_BEGIN,
|
|
|
|
BUS_CLIENT_STATE_READY
|
2022-12-21 00:38:10 +02:00
|
|
|
};
|
|
|
|
|
2023-01-19 03:40:37 +02:00
|
|
|
typedef struct bus_name {
|
|
|
|
char *name;
|
|
|
|
struct bus_client *client;
|
|
|
|
} BusName;
|
|
|
|
|
|
|
|
typedef struct bus_client {
|
2022-12-21 00:38:10 +02:00
|
|
|
int fd;
|
2023-01-19 03:40:37 +02:00
|
|
|
BusName *unique_name;
|
|
|
|
int16_t fd_index;
|
2023-01-16 19:47:40 +02:00
|
|
|
uint8_t state;
|
2022-12-31 17:55:32 +02:00
|
|
|
int8_t match_count;
|
2023-01-19 02:46:49 +02:00
|
|
|
MatchRule *matches[BUS_MAX_MATCH];
|
2023-01-19 03:40:37 +02:00
|
|
|
BusName *owned_names[BUS_NAMES_PER_CLIENT];
|
2023-01-19 02:46:49 +02:00
|
|
|
} BusClient;
|
2022-12-21 21:38:48 +02:00
|
|
|
|
2023-01-19 02:46:49 +02:00
|
|
|
typedef struct {
|
2022-12-21 00:38:10 +02:00
|
|
|
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;
|
2023-01-17 23:04:48 +02:00
|
|
|
int urandom_fd;
|
2023-01-19 02:46:49 +02:00
|
|
|
BusClient clients[BUS_MAX_CLIENTS];
|
|
|
|
BusName names[BUS_MAX_NAMES];
|
2023-01-10 13:08:49 +02:00
|
|
|
struct pollfd fds[BUS_MAX_CLIENTS + 1];
|
2023-01-19 02:46:49 +02:00
|
|
|
} Bus;
|
2022-12-21 00:38:10 +02:00
|
|
|
|
2023-01-19 02:46:49 +02:00
|
|
|
typedef struct {
|
2023-01-10 14:57:16 +02:00
|
|
|
const char *name;
|
2023-01-19 03:40:37 +02:00
|
|
|
int (*handler)(Bus *bus, BusClient *client, WireMsg *msg, WireCtx *ctx, WireCtx *reply_ctx);
|
2023-01-19 02:46:49 +02:00
|
|
|
} BusMethodHandler;
|
2023-01-10 14:57:16 +02:00
|
|
|
|
2022-12-21 00:38:10 +02:00
|
|
|
|
2023-01-19 02:46:49 +02:00
|
|
|
int bus_client_add(Bus *s, int fd);
|
2023-01-19 03:40:37 +02:00
|
|
|
void bus_client_remove(Bus *s, BusClient *client);
|
2023-01-19 02:46:49 +02:00
|
|
|
void bus_free(Bus *s);
|
|
|
|
Bus *bus_create(const char *socket_path);
|
|
|
|
int bus_turn(Bus *s);
|
2022-12-21 00:38:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
#endif // _JITTERBUG__SERVER_H
|