Shadow Network Framework  0.0.1-alpha
C Server Library for Shadow Network Framework
Loading...
Searching...
No Matches
request.h
Go to the documentation of this file.
1//////////////////////////////////////////////////////////////
2///
3/// \file request.h
4/// This file Defines everything related to handling Requests
5///
6/// //////////////////////////////////////////////////////////
7#ifndef REQUEST_H
8#define REQUEST_H
9
10#include <SNF/SNF.h>
11#include <SNF/clt.h>
12#include <SNF/utility.h>
13#include <SNF/opcode.h>
14#include <SNF/network.h>
15
16/// @brief Requests's Default Request ID
17/// @note Server Requests to client always must have this as their ID
18#define NULLREQUEST "000000000000000"
19/// @brief Defines the Requests' maximum length
20#define SNF_REQUEST_MAXSIZE 4096
21
22/// @brief Shortened definition of struct SNF_Request_t .
23typedef struct SNF_Request_t SNF_RQST;
24/// @brief Shortened definition of struct SNF_Request_args_t .
26
27/// @brief The Structure for saving Requests
29{
30 /// @brief Defines the UID Saved
31 /// @note You must take in mind that
32 /// * In Case the SNF_RQST came from a client
33 /// * The UID represents the Request's ID
34 /// * In Case the SNF_RQST is generated by the server
35 /// * In Case you want to reply to a SNF_RQST ,the generates reponse's UID must be the same as the Client Request's UID.
36 /// * use \ref snf_request_gen_response
37 /// * In Case you want to send a server request, then the request's UID must be equal to \ref NULLREQUEST
38 /// * use \ref snf_request_gen_server_OPCODE (Although you cant put any arguments)
39 /// * use \ref snf_request_gen_response ( \ref snf_request_gen_wUID ( \ref NULLREQUEST ), Your OPCODE, Your ARGUMENTS);
40 char UID[16];
41 /// @brief Defines The OPCODE of the request
43 /// @brief Defines the arguments inside the Request
45};
46
48{
49 /// @brief The Argument's Content
50 char *arg;
51 /// @brief The next argument
53};
54
55/// @brief Frees a SNF_RQST *
56/// @param Request Pointer to be free'd
57extern void snf_request_free(SNF_RQST *Request);
58/// @brief Generates a new empty request
59/// @return The possible results :
60/// * **NULL** if there was an error with calloc ( See errno and calloc's errcodes )
61/// * **Pointer** to the \ref SNF_RQST instance
63/// @brief Generates a new empty request that has an UID
64/// @param UID The new Request's UID
65/// @return The possible results :
66/// * **NULL** if there was an error with calloc ( See errno and calloc's errcodes )
67/// * **Pointer** to the \ref SNF_RQST instance
68extern SNF_RQST *snf_request_gen_wUID(const char UID[16]);
69/// @brief Generates a new response request
70/// @param Original The request to reply to
71/// @param OPCODE Thre response's OPCODE
72/// @param Args The response's arguments
73/// @return The possible results :
74/// * **NULL** if there was an error with calloc ( See errno and calloc's errcodes )
75/// * **Pointer** to the \ref SNF_RQST instance
76/// @note The response Request's UID will match the <strong>Original</strong>'s UID, See \ref SNF_RQST::UID
78/// @brief Generates a server request
79/// @param OPCODE server request's OPCODE
80/// @return The possible results :
81/// * **NULL** if there was an error with calloc ( See errno and calloc's errcodes )
82/// * **Pointer** to the \ref SNF_RQST instance
84/// @brief Generates a response request using base OPCode
85/// @param Original The request to respond to
86/// @param Command Base Command
87/// @param Detail Base Command's Detail
88/// @return The possible results :
89/// * **NULL** if there was an error with calloc ( See errno and calloc's errcodes )
90/// * **Pointer** to the \ref SNF_RQST instance
92/// @brief Generates a response request using undetailed base OPCode
93/// @param Original The request to respond to
94/// @param Command Base Command
95/// @return The possible results :
96/// * **NULL** if there was an error with calloc ( See errno and calloc's errcodes )
97/// * **Pointer** to the \ref SNF_RQST instance
99/// @brief Gets the amount of arguments a request has
100/// @param args The request to get it's arguments
101/// @return The possible results :
102/// * **0** if any of the args were empty
103/// * **int** Amount of \ref SNF_RQST_ARG
105
106/// @brief Generates a new Argumment
107/// @param arg Argument's Content
108/// @return The possible results :
109/// * **NULL** if there was an error with calloc ( See errno and calloc's errcodes )
110/// * **Pointer** to the \ref SNF_RQST_ARG instance
111extern SNF_RQST_ARG *snf_request_arg_gen(const char *arg);
112/// @brief Frees an instance of \ref SNF_RQST_ARG
113/// @param arg Instance to be free'd
114/// @warning Do not free an argumment if \ref SNF_RQST_ARG::next contains a pointer, and it could cause a memoery leak<br>
115/// * If you wish to free all arguments then use \ref snf_request_args_free
116/// * If you wish to free just that one argument then save the \ref SNF_RQST_ARG::next in a variable, replace the **arg** instance with the the latter variable, and then free **arg**
118/// @brief Frees all instance of \ref SNF_RQST_ARG that were linked together using \ref SNF_RQST_ARG::next
119/// @param arg arg Instances to be free'd
121// Only use on first time. unless you dont care about execution time
122
123/// @brief Inserts an arguments to the end of **Request**'s \ref SNF_RQST_ARG List
124/// @param Request Request to be operated on
125/// @param arg Argument to be added
126/// @note If you want to Insert a bunch of instances of \ref SNF_RQST_ARG then preferably avoid calling this function
127/// but instead crteate the first instance in *head* variable( \ref SNF_RQST_ARG ) and also put it in a *pointer*( \ref SNF_RQST_ARG ) variable
128/// ( at first it's value *Must* be the same as the *head* variable ) variable then everytime you create a new argument
129/// you save it in the \ref SNF_RQST_ARG::next member of the *pointer* variable, and then assign the \ref SNF_RQST_ARG::next 's new value as the *pointer*
130/// variable, at the end, use this function only the *head* variable
131extern void snf_request_arg_insert(SNF_RQST *Request, SNF_RQST_ARG *arg);
132/// @brief Fetches the request from the incoming Client
133/// @param Client Client to receive request from.
134/// @return The possible results :
135/// * **NULL** if there was an error with calloc ( See errno and calloc's errcodes )
136/// * **Pointer** to the \ref SNF_RQST instance
138
139/// @brief Send a request to a Client
140/// @param Client Receiving Client
141/// @param Request Request to Send
142extern void snf_request_send(SNF_CLT *Client, SNF_RQST *Request);
143/// @brief Sends a confirmation Response request to the client
144/// @param Client Receiving Client
145/// @param Original Client's Original Request
146extern void snf_request_send_confirm(SNF_CLT *Client, SNF_RQST *Original);
147/// @brief Sends a rejection Response request to the client
148/// @param Client Receiving Client
149/// @param Original Client's Original Request
150extern void snf_request_send_reject(SNF_CLT *Client, SNF_RQST *Original);
151/// @brief Sends a invalidation Response request to the client
152/// @param Client Receiving Client
153/// @param Original Client's Original Request
154extern void snf_request_send_invalid(SNF_CLT *Client, SNF_RQST *Original);
155
156#endif
This file includes necessary Checks and includes the the nesessary libraries of the library.
This file Defines everything related to handling Clients.
This file Defines everything related to networking.
This file Defines everything related to Opcodes ( Short for OP**eartion**Codes )
#define SNF_opcode_mmbr_t
Defines SNF_opcode_mmbr_t 's size.
Definition opcode.h:15
void snf_request_send_invalid(SNF_CLT *Client, SNF_RQST *Original)
Sends a invalidation Response request to the client.
SNF_RQST * snf_request_genu_base(SNF_RQST *Original, SNF_opcode_mmbr_t Command)
Generates a response request using undetailed base OPCode.
void snf_request_send_confirm(SNF_CLT *Client, SNF_RQST *Original)
Sends a confirmation Response request to the client.
SNF_RQST * snf_request_gen_response(SNF_RQST *Original, SNF_opcode *OPCODE, SNF_RQST_ARG *Args)
Generates a new response request.
void snf_request_send_reject(SNF_CLT *Client, SNF_RQST *Original)
Sends a rejection Response request to the client.
SNF_RQST * snf_request_gen_base(SNF_RQST *Original, SNF_opcode_mmbr_t Command, SNF_opcode_mmbr_t Detail)
Generates a response request using base OPCode.
void snf_request_send(SNF_CLT *Client, SNF_RQST *Request)
Send a request to a Client.
void snf_request_free(SNF_RQST *Request)
Frees a SNF_RQST *.
void snf_request_args_free(SNF_RQST_ARG *arg)
Frees all instance of SNF_RQST_ARG that were linked together using SNF_RQST_ARG::next.
SNF_RQST * snf_request_gen_wUID(const char UID[16])
Generates a new empty request that has an UID.
int snf_request_get_nargs(SNF_RQST *args)
Gets the amount of arguments a request has.
SNF_RQST * snf_request_gen_server_OPCODE(SNF_opcode *OPCODE)
Generates a server request.
SNF_RQST * snf_request_fetch(SNF_CLT *Client)
Fetches the request from the incoming Client.
void snf_request_arg_insert(SNF_RQST *Request, SNF_RQST_ARG *arg)
Inserts an arguments to the end of Request's SNF_RQST_ARG List.
SNF_RQST * snf_request_gen()
Generates a new empty request.
void snf_request_arg_free(SNF_RQST_ARG *arg)
Frees an instance of SNF_RQST_ARG.
SNF_RQST_ARG * snf_request_arg_gen(const char *arg)
Generates a new Argumment.
The structure for each saved client.
Definition clt.h:25
Definition request.h:48
SNF_RQST_ARG * next
The next argument.
Definition request.h:52
char * arg
The Argument's Content.
Definition request.h:50
The Structure for saving Requests.
Definition request.h:29
SNF_RQST_ARG * args
Defines the arguments inside the Request.
Definition request.h:44
SNF_opcode * OPCODE
Defines The OPCODE of the request.
Definition request.h:42
char UID[16]
Defines the UID Saved.
Definition request.h:40
Structure for the opcode.
Definition opcode.h:29