Add the Client_find_by_session() function.
[umurmur.git] / src / client.h
index 081c99e3a0020837617e0fbd128c2ba02c179da5..9e3fcb5fa7b379f5ca18f2db33e6b2516b508910 100644 (file)
@@ -1,5 +1,5 @@
-/* Copyright (C) 2009, Martin Johansson <martin@fatbob.nu>
-   Copyright (C) 2005-2009, Thorvald Natvig <thorvald@natvig.com>
+/* Copyright (C) 2009-2014, Martin Johansson <martin@fatbob.nu>
+   Copyright (C) 2005-2014, Thorvald Natvig <thorvald@natvig.com>
 
    All rights reserved.
 
@@ -31,7 +31,7 @@
 #ifndef CLIENT_H_45786678
 #define CLIENT_H_45786678
 
-#include <openssl/ssl.h>
+#include "config.h"
 #include <stdint.h>
 #include <unistd.h>             /* close() */
 #include <sys/types.h>
 #include "crypt.h"
 #include "timer.h"
 #include "pds.h"
+#include "ssl.h"
 
-#define BUFSIZE 2048
+#define BUFSIZE 8192
 #define UDP_BUFSIZE 512
-#define INACTICITY_TIMEOUT 15 /* Seconds */
+#define INACTIVITY_TIMEOUT 15 /* Seconds */
 #define MAX_CODECS 10
+#define MAX_TOKENSIZE 64
+#define MAX_TOKENS 32
+#define KEY_LENGTH sizeof(uint16_t) + 4 * sizeof(in_addr_t)
 
 #define IS_AUTH(_a_) ((_a_)->authenticated)
 
+struct channel;
+
 typedef struct {
-       int tcpfd;
-       SSL *ssl;
-       bool_t SSLready;
-       bool_t shutdown_wait;
-       cryptState_t cryptState;
-       bool_t readBlockedOnWrite, writeBlockedOnRead;
-       
-       struct sockaddr_in remote_tcp;
-       struct sockaddr_in remote_udp; 
-       uint8_t rxbuf[BUFSIZE], txbuf[BUFSIZE];
+       SSL_handle_t *ssl;
+       struct dlist node;
+       char *username;
+       char *os, *release, *os_version;
        uint32_t rxcount, msgsize, drainleft, txcount, txsize;
        int sessionId;
-       uint64_t key;
-       char *playerName;
-       bool_t authenticated, deaf, mute;
-       char *os, *release;
        uint32_t version;
        int codec_count;
-       int32_t codecs[MAX_CODECS];
-       int availableBandwidth;
-       etimer_t lastActivity;
-       struct dlist node;
+       struct dlist codecs;
+       etimer_t lastActivity, connectTime, idleTime;
        struct dlist txMsgQueue;
        int txQueueCount;
-       /* Channel */
-       void *channel; /*Ugly... */
+       int availableBandwidth;
+       struct channel *channel;
+       char *context;
        struct dlist chan_node;
        struct dlist voicetargets;
+       struct dlist tokens;
+       int tokencount;
+       int tcpfd;
+       float UDPPingAvg, UDPPingVar, TCPPingAvg, TCPPingVar;
+       uint32_t UDPPackets, TCPPackets;
+
+       bool_t SSLready;
+       bool_t shutdown_wait;
+       bool_t readBlockedOnWrite, writeBlockedOnRead;
+       bool_t bUDP, authenticated, deaf, mute, self_deaf, self_mute, recording, bOpus;
+       bool_t isAdmin;
+       bool_t isSuppressed;
+
+       struct sockaddr_storage remote_tcp;
+       struct sockaddr_storage remote_udp;
+
+       uint8_t key[KEY_LENGTH];
+       uint8_t hash[20];
+       cryptState_t cryptState;
+       uint8_t rxbuf[BUFSIZE], txbuf[BUFSIZE];
 } client_t;
 
+typedef struct {
+       int codec, count;
+       struct dlist node;
+} codec_t;
+
+typedef struct {
+       char *token;
+       struct dlist node;
+} token_t;
 
 void Client_init();
 int Client_getfds(struct pollfd *pollfds);
 void Client_janitor();
-int Client_add(int fd, struct sockaddr_in *remote);
+int Client_add(int fd, struct sockaddr_storage *remote);
 int Client_read_fd(int fd);
 int Client_write_fd(int fd);
 int Client_send_message(client_t *client, message_t *msg);
+int Client_send_message_ver(client_t *client, message_t *msg, uint32_t version);
+int Client_send_message_except_ver(client_t *client, message_t *msg, uint32_t version);
 int Client_count(void);
 void Client_close(client_t *client);
 client_t *Client_iterate(client_t **client);
 int Client_send_message_except(client_t *client, message_t *msg);
-int Client_read_udp(void);
+int Client_read_udp(int udpsock);
 void Client_disconnect_all();
 int Client_voiceMsg(client_t *client, uint8_t *data, int len);
-void recheckCodecVersions();
+void recheckCodecVersions(client_t *connectingClient);
+void Client_codec_add(client_t *client, int codec);
+void Client_codec_free(client_t *client);
+codec_t *Client_codec_iterate(client_t *client, codec_t **codec_itr);
+void Client_textmessage(client_t *client, const char *text);
+bool_t Client_token_match(client_t *client, char const *str);
+void Client_token_free(client_t *client);
+void Client_token_add(client_t *client, char *token_string);
+
+/**
+ * Retrieve the client that matches the given session ID.
+ * Returns NULL if there's no such client.
+ */
+client_t *Client_find_by_session(int session_id);
 
 #endif