Shadow Network Framework  0.0.2-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
19/// @brief Shortened definiton of struct SNF_Client_t .
20typedef struct SNF_Client_t SNF_CLT;
21
22/// @brief The structure for each saved client.
24{
25 /// @brief Mutex used to avoid Race Condition.
26 pthread_mutex_t mutex;
27 /// @brief Saves the 36 ( +1 Null character ) character wide Unique User IDentifier. Used to defined the connected Client
28 char UUID[37];
29 /// @brief Saves the socket id
30 int sock;
31};
32
33#include <SNF/opcode.h>
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 socket file descriptor socket's file descriptor
43/// @return the new Instance.
44/// @note Free with snf_clt_free
45extern SNF_CLT *snf_clt_new(int Sockfd);
46
47/// @brief Frees the allocated \ref SNF_CLT
48/// @param Client The SNF_CLT instance to be free'd.
49/// @warning Make sure you closed the socket file discriptor if you have no use for it.
50extern void snf_clt_free(SNF_CLT *Client);
51/// @brief Searches for a SNF_CLT depending on their socket file discriptor
52/// @param Sockfd The socket descriptor to search with
53/// @return SNF_CLT address pointer where it's value could be:
54/// * The searched SNF_CLT instance's address.<br>
55/// * **NULL** if no SNF_CLT instance found.<br>
56/// @warning NOT YET IMPLEMENTED. DO NOT USE.
57extern SNF_CLT *snf_clt_get_sockfd(int Sockfd);
58/// @brief Searches for a SNF_CLT depending on their UUID
59/// @param uuid The socket descriptor to search with
60/// @return SNF_CLT address pointer where it's value could be:
61/// * The searched SNF_CLT instance's address.<br>
62/// * **NULL** if no 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 SNF_CLT depending on their socket's file descriptor
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 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 ( 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 ( 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( 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#include <SNF/cmds.h>
111#endif
Main Header FileThis File Calls for all the header files exisitng in this 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 socket's file descriptor.
SNF_CLT * snf_clt_get_sockfd(int Sockfd)
Searches for a SNF_CLT depending on their socket file discriptor.
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 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 that would be called either by default or Base Command OPCode's...
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 lookup3.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:24
char UUID[37]
Saves the 36 ( +1 Null character ) character wide Unique User IDentifier. Used to defined the connect...
Definition clt.h:28
pthread_mutex_t mutex
Mutex used to avoid Race Condition.
Definition clt.h:26
int sock
Saves the socket id.
Definition clt.h:30