71 lines
No EOL
1.7 KiB
C
71 lines
No EOL
1.7 KiB
C
#ifndef _JITTERBUG__SERVER_H
|
|
#define _JITTERBUG__SERVER_H
|
|
|
|
#include "wire.h"
|
|
#include <poll.h>
|
|
#include <stdint.h>
|
|
|
|
#define MATCH_RULE_MAX 1024
|
|
#define MATCH_RULE_MAX_ARG 12
|
|
|
|
typedef struct {
|
|
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 */
|
|
} MatchRule;
|
|
|
|
// TODO: dynamically size the arrays
|
|
#define BUS_MAX_CLIENTS 256
|
|
#define BUS_MAX_NAMES 512
|
|
#define BUS_MAX_MATCH 12
|
|
#define BUS_NAMES_PER_CLIENT 4
|
|
#define BUS_BACKLOG 12
|
|
|
|
enum {
|
|
BUS_CLIENT_STATE_NONE,
|
|
BUS_CLIENT_STATE_WAIT_AUTH,
|
|
BUS_CLIENT_STATE_WAIT_BEGIN,
|
|
BUS_CLIENT_STATE_READY
|
|
};
|
|
|
|
typedef struct {
|
|
int fd;
|
|
int16_t unique_name_index;
|
|
uint8_t state;
|
|
int8_t match_count;
|
|
MatchRule *matches[BUS_MAX_MATCH];
|
|
int16_t owned_names[BUS_NAMES_PER_CLIENT];
|
|
} BusClient;
|
|
|
|
typedef struct {
|
|
char *name;
|
|
int32_t client_index;
|
|
} BusName;
|
|
|
|
typedef struct {
|
|
int sock_fd;
|
|
int fd_num;
|
|
int names_count;
|
|
int clients_count;
|
|
int urandom_fd;
|
|
BusClient clients[BUS_MAX_CLIENTS];
|
|
BusName names[BUS_MAX_NAMES];
|
|
struct pollfd fds[BUS_MAX_CLIENTS + 1];
|
|
} Bus;
|
|
|
|
typedef struct {
|
|
const char *name;
|
|
int (*handler)(Bus *bus, int client_index, WireMsg *msg, WireCtx *ctx, WireCtx *reply_ctx);
|
|
} BusMethodHandler;
|
|
|
|
|
|
int bus_client_add(Bus *s, int fd);
|
|
void bus_client_remove(Bus *s, int i);
|
|
void bus_free(Bus *s);
|
|
Bus *bus_create(const char *socket_path);
|
|
int bus_turn(Bus *s);
|
|
|
|
|
|
#endif // _JITTERBUG__SERVER_H
|