Shadow Network Framework  0.0.2-alpha
C Server Library for Shadow Network Framework
Loading...
Searching...
No Matches
opcode.h
Go to the documentation of this file.
1//////////////////////////////////////////////////////////////
2///
3/// \file opcode.h
4/// This file Defines everything related to Opcodes ( Short for
5/// **OP**eartion**Codes** )
6///
7/// //////////////////////////////////////////////////////////
8
9#ifndef opcode_h
10#define opcode_h
11
12#include <SNF/SNF.h>
13/// @brief Defines SNF_opcode_mmbr_t 's size
14#define SNF_opcode_mmbr_t uint8_t
15/// @brief Defines SNF_opcode_mmbr_t 's maximum possible Value
16#define SNF_opcode_mmbr_MAX UINT8_MAX
17
18/// @brief Shortened definiton of struct SNF_opcode_t .
20/// @brief Shortened definiton of struct SNF_opcode_LL_item_t .
22
23/// @brief Structure for the opcode
24/// @note If you wanna access the contents
25/// * For struct use ***strct*** member See SNF_opcode_struct
26/// * For a Table use ***opcode*** member See SNF_opcode::opcode
28{
29 /// @brief SNF_opcode's Structure if you wanna access it as a struct
31 {
32 /// @brief opcode's Category
34 /// @brief opcode's Sub-Category
36 /// @brief opcode's Command
38 /// @brief opcode's Detail
41 /// @brief SNF_opcode's Structure if you wanna access as a table
42 /// @note The content of opcode goest as the following
43 /// * Index <strong>0 -></strong> Category
44 /// * Index <strong>1 -></strong> Sub-Category
45 /// * Index <strong>2 -></strong> Command
46 /// * Index <strong>3 -></strong> Detail
48};
49
50#include <SNF/request.h>
51/// @brief Structure used to save registred opcode members
52/// @note Ranks are:
53/// * Category
54/// * Sub Category
55/// * Command
56/// * Detail
57/// @warning Don't define opcode members by allocating this structure manually, use appropriate functions snf_define_< \ref SNF_opcode_LL_item_t "Rank" >(..),
58/// <br><strong>Example :</strong> for Categories use \ref snf_opcode_define_category()
60{
61 /// @brief opcode Member value
63 /// @brief opcode Member's definition
65 /// @brief Function to be called when the registred command is called
66 /// @note by default it will call snf_cmd_unimplemented()
67 SNF_RQST *(*func)(SNF_RQST *);
68 /// @brief the next opcode member of the same \ref SNF_opcode_LL_item_t "Rank" (and of same Parent if they have one).
70 /// @brief Parent ( or higher in Rank ) opcode Member
71 /// @note Category Rank opcode member should have this member with a value of **NULL**
73 /// @brief Child ( or lower in Rank ) opcode Member
74 /// @note Detail Rank opcode member should have this member with a value of **NULL**
76};
77
78/// @brief Data structure where opcodes will be saved.
80/// @brief used to check if SNF's base opcodes are initialized
81extern int SNF_opcode_base_isinit;
82/// @brief Initializes the SNF's opcodes
83/// @return The possible results :
84/// * **-1** On fail (Shall fail if calloc fails, check errno depending on calloc error codes)
85/// * **0** On Success
86extern int snf_opcode_init();
87/// @brief Defines an opcode Category
88/// @param Code OPcode category's value
89/// @param Definition String Definition for The category
90/// @return The possible results :
91/// * **0** On Success
92/// * **1** if the Category already exists
93/// * **-1** On fail ( Shall fail if calloc fails, check calloc error codes )
96 const char *Definition);
97/// @brief Defines an opcode Sub-Category
98/// @param Category OPcode's Category
99/// @param Code OPcode subcategory's value
100/// @param Definition String Definition for The sub-category
101/// @return The possible results :
102/// * **0** On Success
103/// * **1** if Sub-Category Already Exists
104/// * **-1** On calloc fail
105/// * **-2** if Category was not found or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
107 SNF_opcode_mmbr_t Category,
109 const char *Definition);
110/// @brief Defines an opcode Command
111/// @param Category OPcode's Category
112/// @param SubCategory OPcode's Sub-Category
113/// @param Code Opcode command's value
114/// @param Definition String Definition for The command/// @return The possible results :
115/// * **0** On Success
116/// * **1** if Command Already Exists
117/// * **-1** On calloc fail
118/// * **-2** if Sub-Category was not found or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
120 SNF_opcode_mmbr_t Category,
121 SNF_opcode_mmbr_t SubCategory,
123 const char *Definition,
124 SNF_RQST *(func)(SNF_RQST *));
125/// @brief Defines an opcode Detail
126/// @param Category OPcode's Category
127/// @param SubCategory OPcode's Sub-Category
128/// @param Command Opcode's Command
129/// @param Code Opcode detail's value
130/// @param Definition String Definition for The detail
131/// @return The possible results :
132/// * **0** On Success
133/// * **1** if Detail Already Exists
134/// * **-1** On calloc fail
135/// * **-2** if Command was not found or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
137 SNF_opcode_mmbr_t Category,
138 SNF_opcode_mmbr_t SubCategory,
139 SNF_opcode_mmbr_t Command,
141 const char *Definition);
142
143/// @brief Fetches the opcode Category from the opcode's data structure.
144/// @param Category Category to be fetched.
145/// @return The possible results :
146/// * **NULL** if Category wasn't found or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
147/// * **Pointer** to the Category
149 SNF_opcode_mmbr_t Category);
150/// @brief Fetches the opcode Sub-Category from the opcode's data structure.
151/// @param Category Parent Category
152/// @param SubCategory Sub-Category to be fetched.
153/// @return The possible results :
154/// * **NULL** if Sub-Category wasn't found
155/// * **Pointer** to the Sub-Category or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
157 SNF_opcode_mmbr_t Category,
158 SNF_opcode_mmbr_t SubCategory);
159/// @brief Fetches the opcode Command from the opcode's data structure.
160/// @param Category Parent Category
161/// @param SubCategory Parent Sub-Category
162/// @param Command Command to be fetched.
163/// @return The possible results :
164/// * **NULL** if Command wasn't found
165/// * **Pointer** to the Command or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
167 SNF_opcode_mmbr_t Category,
168 SNF_opcode_mmbr_t SubCategory,
169 SNF_opcode_mmbr_t Command);
170/// @param Category Parent Category
171/// @param SubCategory Parent Sub-Category
172/// @param Command Parent Command
173/// @param Detail Detail to be fetched.
174/// @return The possible results :
175/// * **NULL** if Detail wasn't found
176/// * **Pointer** to the Detail
178 SNF_opcode_mmbr_t Category,
179 SNF_opcode_mmbr_t SubCategory,
180 SNF_opcode_mmbr_t Command,
181 SNF_opcode_mmbr_t Detail);
182/// @brief Fetches a fully structured OPcode
183/// @param Category Parent Category.
184/// @param SubCategory Parent Sub-Category
185/// @param Command Executing Command
186/// @param Detail Given Detail.
187/// @return The possible results :
188/// * **NULL** if any of the Members was not found
189/// * **Pointer** to the \ref SNF_opcode instance
190/// @note If you want to generate an Undetailed ( Detail's value is equal to \ref SNF_OPCODE_BASE_DET_UNDETAILED ) then use
191/// \ref snf_opcode_getu()
193 SNF_opcode_mmbr_t Category,
194 SNF_opcode_mmbr_t SubCategory,
195 SNF_opcode_mmbr_t Command,
196 SNF_opcode_mmbr_t Detail);
197/// @brief Fetches a fully structured OPcode using the default Detail
198/// @param Category Parent Category.
199/// @param SubCategory Parent Sub-Category
200/// @param Command Executing Command
201/// @return The possible results :
202/// * **NULL** if any of the Members was not found
203/// * **Pointer** to the undetailed \ref SNF_opcode instance
204/// @note Detail's value will be equal to \ref SNF_OPCODE_BASE_DET_UNDETAILED
206 SNF_opcode_mmbr_t Category,
207 SNF_opcode_mmbr_t SubCategory,
208 SNF_opcode_mmbr_t Command);
209
210/// @brief Compares between two opcodes.
211/// @param op1 OPCode 1
212/// @param op2 OPCode 2
213/// @return The possible results :
214/// * **-2 Given opcodes are different
215/// * **-1 if either opcodes are NULL
216/// * **0** when opcodes are equal
217/// * **1** Opcodes have equal command. but op1 has bigger Detail
218/// * **2** Opcodes have equal command. but op2 has bigger Detail
220 SNF_opcode *op1,
221 SNF_opcode *op2);
223 SNF_opcode *op);
224#pragma region[Base Opcode Values]
225/// @brief Base Category for SNF
226/// @warning Do not add anything under this Catergory
227#define SNF_OPCODE_BASE_CAT (SNF_opcode_mmbr_t)0x00
228/// @brief Base Sub-Category for SNF
229/// @warning Do not add anything under this Sub-Catergory
230#define SNF_OPCODE_BASE_SUBCAT (SNF_opcode_mmbr_t)0x00
231/// @brief Default Detail
232/// @note This will always be added by default to every Command
233#define SNF_OPCODE_BASE_DET_UNDETAILED (SNF_opcode_mmbr_t)0x00
234
235/// @brief When client attemps to connect.
236/// @warning Do not add anything under this Command
237#define SNF_OPCODE_BASE_CMD_CONNECT (SNF_opcode_mmbr_t)0x00
238/// @brief When client attemps to reconnect - or forced to.
239/// @warning Do not add anything under this Command
240#define SNF_OPCODE_BASE_CMD_RECONNECT (SNF_opcode_mmbr_t)0x01
241/// @brief When client attemps to disconnect.
242/// @warning Do not add anything under this Command
243#define SNF_OPCODE_BASE_CMD_DISCONNECT (SNF_opcode_mmbr_t)0x02
244/// @brief When client requests SNF version of the Server.
245/// @warning Do not add anything under this Command
246#define SNF_OPCODE_BASE_CMD_SNF_VER (SNF_opcode_mmbr_t)0x03
247/// @brief When client was forced to disconnect ( Kicked ).
248/// @warning Do not add anything under this Command
249#define SNF_OPCODE_BASE_CMD_KICK (SNF_opcode_mmbr_t)0x04
250/// @brief When client's reuqest was confirmed.
251/// @warning Do not add anything under this Command
252#define SNF_OPCODE_BASE_CMD_CONFIRM (SNF_opcode_mmbr_t)0x05
253/// @brief When client's request was rejected.
254/// @warning Do not add anything under this Command
255#define SNF_OPCODE_BASE_CMD_REJECT (SNF_opcode_mmbr_t)0x06
256
257#pragma region[Base Command: Invalid]
258/// @brief When client's request was invalid either, wrong version or incomplete request.
259/// @warning Do not add anything under this Command
260#define SNF_OPCODE_BASE_CMD_INVALID (SNF_opcode_mmbr_t)0xFF
261/// @brief Received opcode was not registred
262#define SNF_OPCODE_BASE_DET_INVALID_UNREGISTRED_OPCODE (SNF_opcode_mmbr_t)0x01
263/// @brief Protocol used is invalid
264#define SNF_OPCODE_BASE_DET_INVALID_ERROR_PROTOCOL (SNF_opcode_mmbr_t)0x02
265/// @brief Received opcode does not have a function to call
266#define SNF_OPCODE_BASE_DET_INVALID_UNIMPLEMENTED_OPCODE (SNF_opcode_mmbr_t)0x03
267#pragma endregion
268#pragma endregion
269
270#pragma region[Base Opcode Function]
271
272/// @brief Fetches the base opcode Category from the opcode's data structure.
273/// @return The possible results :
274/// * **NULL** if Category wasn't found or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
275/// * **Pointer** to the Category
277/// @brief Fetches the base opcode Sub-Category from the opcode's data structure.
278/// @return The possible results :
279/// * **NULL** if Sub-Category wasn't found
280/// * **Pointer** to the Sub-Category or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
282/// @brief Fetches a base opcode Command from the opcode's data structure.
283/// @param Command requested Command
284/// @return The possible results :
285/// * **NULL** if Command wasn't found
286/// * **Pointer** to the Command or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
288 SNF_opcode_mmbr_t Command);
289/// @brief Fetches a base opcode Command from the opcode's data structure.
290/// @param Command Parent Command
291/// @param Detail Command's Detail
292/// @return The possible results :
293/// * **NULL** if Detail wasn't found
294/// * **Pointer** to the Detail or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
296 SNF_opcode_mmbr_t Command,
297 SNF_opcode_mmbr_t Detail);
298/// @brief Fetches a fully structured OPcode with a base "Command"
299/// @param Command Base Command's Value
300/// @param Detail Base Command Detail's Value
301/// @return The possible results :
302/// * **NULL** if any of the Members was not found
303/// * **Pointer** to the \ref SNF_opcode instance
304/// @note If you want to generate an Undetailed ( Detail's value is equal to \ref SNF_OPCODE_BASE_DET_UNDETAILED ) then use
305/// \ref snf_opcode_getu_base()
307 SNF_opcode_mmbr_t Command,
308 SNF_opcode_mmbr_t Detail);
309/// @brief Fetches a fully structured OPcode witha base "Command" using the default Detail
310/// @param Command Base Command's Value
311/// @return The possible results :
312/// * **NULL** if any of the Members was not found
313/// * **Pointer** to the undetailed \ref SNF_opcode instance
314/// @note Detail's value will be equal to \ref SNF_OPCODE_BASE_DET_UNDETAILED
316 SNF_opcode_mmbr_t Command);
317#pragma endregion
318
319#endif
Main Header FileThis File Calls for all the header files exisitng in this library,...
SNF_opcode_LL_item * snf_opcode_get_base_detail(SNF_opcode_mmbr_t Command, SNF_opcode_mmbr_t Detail)
Fetches a base opcode Command from the opcode's data structure.
SNF_opcode * snf_opcode_getu(SNF_opcode_mmbr_t Category, SNF_opcode_mmbr_t SubCategory, SNF_opcode_mmbr_t Command)
Fetches a fully structured OPcode using the default Detail.
SNF_opcode * snf_opcode_getu_base(SNF_opcode_mmbr_t Command)
Fetches a fully structured OPcode witha base "Command" using the default Detail.
int snf_opcode_define_category(SNF_opcode_mmbr_t Code, const char *Definition)
Defines an opcode Category.
SNF_opcode_LL_item * snf_opcode_get_command(SNF_opcode_mmbr_t Category, SNF_opcode_mmbr_t SubCategory, SNF_opcode_mmbr_t Command)
Fetches the opcode Command from the opcode's data structure.
SNF_opcode_LL_item * snf_opcode_get_category(SNF_opcode_mmbr_t Category)
Fetches the opcode Category from the opcode's data structure.
#define SNF_opcode_mmbr_t
Defines SNF_opcode_mmbr_t 's size.
Definition opcode.h:14
int snf_opcode_define_detail(SNF_opcode_mmbr_t Category, SNF_opcode_mmbr_t SubCategory, SNF_opcode_mmbr_t Command, SNF_opcode_mmbr_t Code, const char *Definition)
Defines an opcode Detail.
int snf_opcode_define_command(SNF_opcode_mmbr_t Category, SNF_opcode_mmbr_t SubCategory, SNF_opcode_mmbr_t Code, const char *Definition, SNF_RQST *(func)(SNF_RQST *))
Defines an opcode Command.
int SNF_opcode_base_isinit
used to check if SNF's base opcodes are initialized
int snf_opcode_isbase(SNF_opcode *op)
SNF_opcode_LL_item * snf_opcode_get_sub_category(SNF_opcode_mmbr_t Category, SNF_opcode_mmbr_t SubCategory)
Fetches the opcode Sub-Category from the opcode's data structure.
SNF_opcode_LL_item * snf_opcode_get_base_sub_category()
Fetches the base opcode Sub-Category from the opcode's data structure.
SNF_opcode * snf_opcode_get_base(SNF_opcode_mmbr_t Command, SNF_opcode_mmbr_t Detail)
Fetches a fully structured OPcode with a base "Command".
SNF_opcode_LL_item * SNF_opcode_LL
Data structure where opcodes will be saved.
int snf_opcode_define_sub_category(SNF_opcode_mmbr_t Category, SNF_opcode_mmbr_t Code, const char *Definition)
Defines an opcode Sub-Category.
SNF_opcode_LL_item * snf_opcode_get_base_category()
Fetches the base opcode Category from the opcode's data structure.
int snf_opcode_init()
Initializes the SNF's opcodes.
SNF_opcode_LL_item * snf_opcode_get_detail(SNF_opcode_mmbr_t Category, SNF_opcode_mmbr_t SubCategory, SNF_opcode_mmbr_t Command, SNF_opcode_mmbr_t Detail)
SNF_opcode_LL_item * snf_opcode_get_base_command(SNF_opcode_mmbr_t Command)
Fetches a base opcode Command from the opcode's data structure.
int snf_opcode_compare(SNF_opcode *op1, SNF_opcode *op2)
Compares between two opcodes.
SNF_opcode * snf_opcode_get(SNF_opcode_mmbr_t Category, SNF_opcode_mmbr_t SubCategory, SNF_opcode_mmbr_t Command, SNF_opcode_mmbr_t Detail)
Fetches a fully structured OPcode.
This file Defines everything related to handling Requests.
The Structure for saving Requests.
Definition request.h:27
Structure used to save registred opcode members.
Definition opcode.h:60
SNF_opcode_LL_item * parent
Parent ( or higher in Rank ) opcode Member.
Definition opcode.h:72
char * Definition
opcode Member's definition
Definition opcode.h:64
SNF_opcode_LL_item * next
the next opcode member of the same Rank (and of same Parent if they have one).
Definition opcode.h:69
SNF_opcode_LL_item * sub
Child ( or lower in Rank ) opcode Member.
Definition opcode.h:75
SNF_opcode_mmbr_t OPmmbr
opcode Member value
Definition opcode.h:62
SNF_opcode's Structure if you wanna access it as a struct.
Definition opcode.h:31
SNF_opcode_mmbr_t SubCategory
opcode's Sub-Category
Definition opcode.h:35
SNF_opcode_mmbr_t Category
opcode's Category
Definition opcode.h:33
SNF_opcode_mmbr_t Detail
opcode's Detail
Definition opcode.h:39
SNF_opcode_mmbr_t Command
opcode's Command
Definition opcode.h:37
Structure for the opcode.
Definition opcode.h:28
SNF_opcode_mmbr_t opcode[4]
SNF_opcode's Structure if you wanna access as a table.
Definition opcode.h:47
struct SNF_opcode_t::SNF_opcode_struct strct