Shadow Network Framework  0.0.1-alpha
C Server Library for Shadow Network Framework
Loading...
Searching...
No Matches
clt.h
Go to the documentation of this file.
1//////////////////////////////////////////////////////////////
2///
3/// \file clt.h
4/// This file Defines everything related to handling Clients
5///
6/// //////////////////////////////////////////////////////////
7
8#ifndef clt_h
9#define clt_h
10
11#include <pthread.h>
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15#include <unistd.h>
16#include <uuid/uuid.h>
17#include <SNF/SNF.h>
18#include <SNF/opcode.h>
19
20/// @brief Shortened definiton of struct SNF_Client_t .
21typedef struct SNF_Client_t SNF_CLT;
22
23/// @brief The structure for each saved client.
25{
26 /// @brief Mutex used to avoid Race Condition.
27 pthread_mutex_t mutex;
28 /// @brief Saves the 36 ( +1 Null character ) character wide Unique User IDentifier. Used to defined the connected Client
29 char UUID[37];
30 /// @brief Saves the socket id
31 int sock;
32};
33
34/// @brief Initialises the HashTable that saves the clients
35/// @param ht_min_Size The HashTable's length ( See note )
36/// @note **ht_min_Size** isnt (in most cases) the same as the true size of HashTable length <br><br>
37/// @note See \ref snf_hashtable_inis() .
38extern void snf_clt_init(int ht_min_Size);
39
40/// @brief Creates (and allocates) a new Client using their **Sockfd**,
41/// with a default \ref SNF_CLT::UUID with the value of "00000000-0000-0000-0000-000000000000"
42/// @param Sockfd The Client's \ref SNF_CLT::sock ( Client's Socket Discriptor )
43/// @return the new \ref SNF_CLT Instance.
44/// @note Free with \ref snf_clt_free
45extern SNF_CLT *snf_clt_new(int Sockfd);
46
47/// @brief Frees the allocated \ref SNF_CLT
48/// @param Client The \ref SNF_CLT instance to be free'd.
49/// @warning Make sure you closed the \ref SNF_CLT::sock if you have no use for it.
50extern void snf_clt_free(SNF_CLT *Client);
51/// @brief Searches for a \ref SNF_CLT depending on their \ref SNF_CLT::sock
52/// @param Sockfd The socket descriptor to search with
53/// @return \ref SNF_CLT address pointer where it's value could be:
54/// * The searched \ref SNF_CLT instance's address.<br>
55/// * **NULL** if no \ref SNF_CLT found.<br>
56/// @warning NOT YET IMPLEMENTED. DO NOT USE.
57extern SNF_CLT *snf_clt_get_sockfd(int Sockfd);
58/// @brief Searches for a \ref SNF_CLT depending on their \ref SNF_CLT::UUID
59/// @param uuid The socket descriptor to search with
60/// @return \ref SNF_CLT address pointer where it's value could be:
61/// * The searched \ref SNF_CLT instance's address.<br>
62/// * **NULL** if no \ref SNF_CLT found.<br>
63/// @warning NOT YET IMPLEMENTED. DO NOT USE.
64extern SNF_CLT *snf_clt_get_uuid(const char *uuid);
65
66/// @brief Checks the existance of a \ref SNF_CLT depending on their \ref SNF_CLT::sock
67/// @param Sockfd The socket descriptor to search with
68/// @return An Integer dipicting the check's result:
69/// * **1** if found<br>
70/// * **0** if not found.<br>
71/// @warning NOT YET IMPLEMENTED. DO NOT USE.
72extern int snf_clt_check_sockfd(int Sockfd);
73/// @brief Checks the existance of a \ref SNF_CLT depending on their \ref SNF_CLT::UUID
74/// @param uuid The socket descriptor to search with
75/// @return An Integer dipicting the check's result:
76/// * **1** if found<br>
77/// * **0** if not found.<br>
78/// @warning NOT YET IMPLEMENTED. DO NOT USE.
79extern int snf_clt_check_uuid(const char *uuid);
80
81/// @brief Handles new incoming Clients.
82/// @param arg new Clitent's address ( \ref SNF_CLT pointer)
83/// @return **NULL**
84/// @warning Core Function in network.c do not use it elsewhere.
85extern void *snf_clt_handle_new(void *arg);
86/// @brief Handles existing Clients.
87/// @param arg new Clitent's address ( \ref SNF_CLT pointer)
88/// @return **NULL**
89/// @warning Core Function in network.c do not use it elsewhere.
90extern void *snf_clt_handle(void *arg);
91
92/// @brief Function to be called upon Client Connection.
93/// @param Client Connecting Client( \ref SNF_CLT pointer)
94/// @warning Core Function in clt.c do not use it elsewhere.
95extern void snf_clt_connect(SNF_CLT *Client);
96/// @brief Function to be called upon Client Re-Connection
97/// @param Client Re-Connecting Client
98/// @warning Core Function in clt.c do not use it elsewhere.
99extern void snf_clt_reconnect(SNF_CLT *Client);
100/// @brief Function to be called upon Client Disconnection
101/// @param Client Disconnecting Client.
102/// @warning Core Function in clt.c do not use it elsewhere.
103extern void snf_clt_disconnect(SNF_CLT *Client);
104
105#include <SNF/hashtable.h>
106#include <SNF/request.h>
107#include <SNF/epoll.h>
108#include <SNF/utility.h>
109#include <SNF/network.h>
110#endif
This file includes necessary Checks and includes the the nesessary libraries of the library.
void snf_clt_init(int ht_min_Size)
Initialises the HashTable that saves the clients.
int snf_clt_check_sockfd(int Sockfd)
Checks the existance of a SNF_CLT depending on their SNF_CLT::sock.
SNF_CLT * snf_clt_get_sockfd(int Sockfd)
Searches for a SNF_CLT depending on their SNF_CLT::sock.
void * snf_clt_handle(void *arg)
Handles existing Clients.
SNF_CLT * snf_clt_get_uuid(const char *uuid)
Searches for a SNF_CLT depending on their SNF_CLT::UUID.
void * snf_clt_handle_new(void *arg)
Handles new incoming Clients.
void snf_clt_free(SNF_CLT *Client)
Frees the allocated SNF_CLT.
void snf_clt_disconnect(SNF_CLT *Client)
Function to be called upon Client Disconnection.
SNF_CLT * snf_clt_new(int Sockfd)
Creates (and allocates) a new Client using their Sockfd, with a default SNF_CLT::UUID with the value ...
int snf_clt_check_uuid(const char *uuid)
Checks the existance of a SNF_CLT depending on their SNF_CLT::UUID.
void snf_clt_connect(SNF_CLT *Client)
Function to be called upon Client Connection.
void snf_clt_reconnect(SNF_CLT *Client)
Function to be called upon Client Re-Connection.
This file is used to define functions related to epoll that would be used mainly in network....
This file Defines the HashTable functions and macros The HashTable uses locate3.c 's hashing function...
This file Defines everything related to networking.
This file Defines everything related to Opcodes ( Short for OP**eartion**Codes )
This file Defines everything related to handling Requests.
The structure for each saved client.
Definition clt.h:25
char UUID[37]
Saves the 36 ( +1 Null character ) character wide Unique User IDentifier. Used to defined the connect...
Definition clt.h:29
pthread_mutex_t mutex
Mutex used to avoid Race Condition.
Definition clt.h:27
int sock
Saves the socket id.
Definition clt.h:31