Shadow Network Framework  0.0.1-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
14/// @brief Defines SNF_opcode_mmbr_t 's size
15#define SNF_opcode_mmbr_t uint8_t
16/// @brief Defines SNF_opcode_mmbr_t 's maximum possible Value
17#define SNF_opcode_mmbr_MAX UINT8_MAX
18
19/// @brief Shortened definiton of struct SNF_opcode_t .
21/// @brief Shortened definiton of struct SNF_opcode_LL_item_t .
23
24/// @brief Structure for the opcode
25/// @note If you wanna access the contents
26/// * For struct use ***strct*** member See SNF_opcode_struct
27/// * For a Table use ***opcode*** member See SNF_opcode::opcode
29{
30 /// @brief SNF_opcode's Structure if you wanna access it using a structure
32 {
33 /// @brief opcode's Category
35 /// @brief opcode's Sub-Category
37 /// @brief opcode's Command
39 /// @brief opcode's Detail
42 /// @brief SNF_opcode's Structure if you wanna access using a table
43 /// @note The content of opcode goest as the following
44 /// * Index <strong>0 -></strong> Category
45 /// * Index <strong>1 -></strong> Sub-Category
46 /// * Index <strong>2 -></strong> Command
47 /// * Index <strong>3 -></strong> Detail
49};
50
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 the next opcode member of the same \ref SNF_opcode_LL_item_t "Rank" (and of same Parent if they have one).
67 /// @brief Parent ( or higher in Rank ) opcode Member
68 /// @note Category Rank opcode member should have this member with a value of **NULL**
70 /// @brief Child ( or lower in Rank ) opcode Member
71 /// @note Detail Rank opcode member should have this member with a value of **NULL**
73};
74
75/// @brief Data structure where opcodes will be saved.
77/// @brief used to check if SNF's base opcodes are initialized
78extern int SNF_opcode_base_isinit;
79/// @brief Initializes the SNF's opcodes
80/// @return The possible results :
81/// * **-1** On fail (Shall fail if calloc fails, check errno depending on calloc error codes)
82/// * **0** On Success
83extern int snf_opcode_init();
84/// @brief Defines an opcode Category
85/// @param Code OPcode category's value
86/// @param Definition String Definition for The category
87/// @return The possible results :
88/// * **0** On Success
89/// * **1** if the Category already exists
90/// * **-1** On fail ( Shall fail if calloc fails, check calloc error codes )
93 const char *Definition);
94/// @brief Defines an opcode Sub-Category
95/// @param Category OPcode's Category
96/// @param Code OPcode subcategory's value
97/// @param Definition String Definition for The sub-category
98/// @return The possible results :
99/// * **0** On Success
100/// * **1** if Sub-Category Already Exists
101/// * **-1** On calloc fail
102/// * **-2** if Category was not found or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
104 SNF_opcode_mmbr_t Category,
106 const char *Definition);
107/// @brief Defines an opcode Command
108/// @param Category OPcode's Category
109/// @param SubCategory OPcode's Sub-Category
110/// @param Code Opcode command's value
111/// @param Definition String Definition for The command/// @return The possible results :
112/// * **0** On Success
113/// * **1** if Command Already Exists
114/// * **-1** On calloc fail
115/// * **-2** if Sub-Category was not found or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
117 SNF_opcode_mmbr_t Category,
118 SNF_opcode_mmbr_t SubCategory,
120 const char *Definition);
121/// @brief Defines an opcode Detail
122/// @param Category OPcode's Category
123/// @param SubCategory OPcode's Sub-Category
124/// @param Command Opcode's Command
125/// @param Code Opcode detail's value
126/// @param Definition String Definition for The detail
127/// @return The possible results :
128/// * **0** On Success
129/// * **1** if Detail Already Exists
130/// * **-1** On calloc fail
131/// * **-2** if Command was not found or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
133 SNF_opcode_mmbr_t Category,
134 SNF_opcode_mmbr_t SubCategory,
135 SNF_opcode_mmbr_t Command,
137 const char *Definition);
138
139/// @brief Fetches the opcode Category from the opcode's data structure.
140/// @param Category Category to be fetched.
141/// @return The possible results :
142/// * **NULL** if Category wasn't found or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
143/// * **Pointer** to the Category
145 SNF_opcode_mmbr_t Category);
146/// @brief Fetches the opcode Sub-Category from the opcode's data structure.
147/// @param Category Parent Category
148/// @param SubCategory Sub-Category to be fetched.
149/// @return The possible results :
150/// * **NULL** if Sub-Category wasn't found
151/// * **Pointer** to the Sub-Category or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
153 SNF_opcode_mmbr_t Category,
154 SNF_opcode_mmbr_t SubCategory);
155/// @brief Fetches the opcode Command from the opcode's data structure.
156/// @param Category Parent Category
157/// @param SubCategory Parent Sub-Category
158/// @param Command Command to be fetched.
159/// @return The possible results :
160/// * **NULL** if Command wasn't found
161/// * **Pointer** to the Command or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
163 SNF_opcode_mmbr_t Category,
164 SNF_opcode_mmbr_t SubCategory,
165 SNF_opcode_mmbr_t Command);
166/// @param Category Parent Category
167/// @param SubCategory Parent Sub-Category
168/// @param Command Parent Command
169/// @param Detail Detail to be fetched.
170/// @return The possible results :
171/// * **NULL** if Detail wasn't found
172/// * **Pointer** to the Detail
174 SNF_opcode_mmbr_t Category,
175 SNF_opcode_mmbr_t SubCategory,
176 SNF_opcode_mmbr_t Command,
177 SNF_opcode_mmbr_t Detail);
178/// @brief Fetches a fully structured OPcode
179/// @param Category Parent Category.
180/// @param SubCategory Parent Sub-Category
181/// @param Command Executing Command
182/// @param Detail Given Detail.
183/// @return The possible results :
184/// * **NULL** if any of the Members was not found
185/// * **Pointer** to the \ref SNF_opcode instance
186/// @note If you want to generate an Undetailed ( Detail's value is equal to \ref SNF_OPCODE_BASE_DET_UNDETAILED ) then use
187/// \ref snf_opcode_getu()
189 SNF_opcode_mmbr_t Category,
190 SNF_opcode_mmbr_t SubCategory,
191 SNF_opcode_mmbr_t Command,
192 SNF_opcode_mmbr_t Detail);
193/// @brief Fetches a fully structured OPcode using the default Detail
194/// @param Category Parent Category.
195/// @param SubCategory Parent Sub-Category
196/// @param Command Executing Command
197/// @return The possible results :
198/// * **NULL** if any of the Members was not found
199/// * **Pointer** to the undetailed \ref SNF_opcode instance
200/// @note Detail's value will be equal to \ref SNF_OPCODE_BASE_DET_UNDETAILED
202 SNF_opcode_mmbr_t Category,
203 SNF_opcode_mmbr_t SubCategory,
204 SNF_opcode_mmbr_t Command);
205
206/// @brief Compares between two opcodes.
207/// @param op1 OPCode 1
208/// @param op2 OPCode 2
209/// @return The possible results :
210/// * **-2 Given opcodes are different
211/// * **-1 if either opcodes are NULL
212/// * **0** when opcodes are equal
213/// * **1** Opcodes have equal command. but op1 has bigger Detail
214/// * **2** Opcodes have equal command. but op2 has bigger Detail
216 SNF_opcode *op1,
217 SNF_opcode *op2);
218
219#pragma region[Base Opcode Values]
220/// @brief Base Category for SNF
221/// @warning Do not add anything under this Catergory
222#define SNF_OPCODE_BASE_CAT (SNF_opcode_mmbr_t)0x00
223/// @brief Base Sub-Category for SNF
224/// @warning Do not add anything under this Sub-Catergory
225#define SNF_OPCODE_BASE_SUBCAT (SNF_opcode_mmbr_t)0x00
226/// @brief Default Detail
227/// @note This will always be added by default to every Command
228#define SNF_OPCODE_BASE_DET_UNDETAILED (SNF_opcode_mmbr_t)0x00
229
230/// @brief When client attemps to connect.
231/// @warning Do not add anything under this Command
232#define SNF_OPCODE_BASE_CMD_CONNECT (SNF_opcode_mmbr_t)0x00
233/// @brief When client attemps to reconnect - or forced to.
234/// @warning Do not add anything under this Command
235#define SNF_OPCODE_BASE_CMD_RECONNECT (SNF_opcode_mmbr_t)0x01
236/// @brief When client attemps to disconnect.
237/// @warning Do not add anything under this Command
238#define SNF_OPCODE_BASE_CMD_DISCONNECT (SNF_opcode_mmbr_t)0x02
239/// @brief When client requests SNF version of the Server.
240/// @warning Do not add anything under this Command
241#define SNF_OPCODE_BASE_CMD_SNF_VER (SNF_opcode_mmbr_t)0x03
242/// @brief When client was forced to disconnect ( Kicked ).
243/// @warning Do not add anything under this Command
244#define SNF_OPCODE_BASE_CMD_KICK (SNF_opcode_mmbr_t)0x04
245/// @brief When client's reuqest was confirmed.
246/// @warning Do not add anything under this Command
247#define SNF_OPCODE_BASE_CMD_CONFIRM (SNF_opcode_mmbr_t)0x05
248/// @brief When client's request was rejected.
249/// @warning Do not add anything under this Command
250#define SNF_OPCODE_BASE_CMD_REJECT (SNF_opcode_mmbr_t)0x06
251
252#pragma region[Base Command: Invalid]
253/// @brief When client's request was invalid either, wrong version or incomplete request.
254/// @warning Do not add anything under this Command
255#define SNF_OPCODE_BASE_CMD_INVALID (SNF_opcode_mmbr_t)0xFF
256/// @brief Received opcode was not registred
257#define SNF_OPCODE_BASE_DET_INVALID_UNREGISTRED_OPCODE (SNF_opcode_mmbr_t)0x01
258/// @brief Protocol used is invalid
259#define SNF_OPCODE_BASE_DET_INVALID_ERROR_PROTOCOL (SNF_opcode_mmbr_t)0x02
260#pragma endregion
261#pragma endregion
262
263#pragma region[Base Opcode Function]
264
265/// @brief Fetches the base opcode Category from the opcode's data structure.
266/// @return The possible results :
267/// * **NULL** if Category wasn't found or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
268/// * **Pointer** to the Category
270/// @brief Fetches the base opcode Sub-Category from the opcode's data structure.
271/// @return The possible results :
272/// * **NULL** if Sub-Category wasn't found
273/// * **Pointer** to the Sub-Category or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
275/// @brief Fetches a base opcode Command from the opcode's data structure.
276/// @param Command requested Command
277/// @return The possible results :
278/// * **NULL** if Command wasn't found
279/// * **Pointer** to the Command or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
281 SNF_opcode_mmbr_t Command);
282/// @brief Fetches a base opcode Command from the opcode's data structure.
283/// @param Command Parent Command
284/// @param Detail Command's Detail
285/// @return The possible results :
286/// * **NULL** if Detail wasn't found
287/// * **Pointer** to the Detail or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
289 SNF_opcode_mmbr_t Command,
290 SNF_opcode_mmbr_t Detail);
291/// @brief Fetches a fully structured OPcode with a base "Command"
292/// @param Command Base Command's Value
293/// @param Detail Base Command Detail's Value
294/// @return The possible results :
295/// * **NULL** if any of the Members was not found
296/// * **Pointer** to the \ref SNF_opcode instance
297/// @note If you want to generate an Undetailed ( Detail's value is equal to \ref SNF_OPCODE_BASE_DET_UNDETAILED ) then use
298/// \ref snf_opcode_getu_base()
300 SNF_opcode_mmbr_t Command,
301 SNF_opcode_mmbr_t Detail);
302/// @brief Fetches a fully structured OPcode witha base "Command" using the default Detail
303/// @param Command Base Command's Value
304/// @return The possible results :
305/// * **NULL** if any of the Members was not found
306/// * **Pointer** to the undetailed \ref SNF_opcode instance
307/// @note Detail's value will be equal to \ref SNF_OPCODE_BASE_DET_UNDETAILED
309 SNF_opcode_mmbr_t Command);
310#pragma endregion
311
312#endif
This file includes necessary Checks and includes the the nesessary libraries of the 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:15
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_base_isinit
used to check if SNF's base opcodes are initialized
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.
int snf_opcode_define_command(SNF_opcode_mmbr_t Category, SNF_opcode_mmbr_t SubCategory, SNF_opcode_mmbr_t Code, const char *Definition)
Defines an opcode Command.
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:69
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:66
SNF_opcode_LL_item * sub
Child ( or lower in Rank ) opcode Member.
Definition opcode.h:72
SNF_opcode_mmbr_t OPmmbr
opcode Member value
Definition opcode.h:62
SNF_opcode's Structure if you wanna access it using a structure.
Definition opcode.h:32
SNF_opcode_mmbr_t SubCategory
opcode's Sub-Category
Definition opcode.h:36
SNF_opcode_mmbr_t Category
opcode's Category
Definition opcode.h:34
SNF_opcode_mmbr_t Detail
opcode's Detail
Definition opcode.h:40
SNF_opcode_mmbr_t Command
opcode's Command
Definition opcode.h:38
Structure for the opcode.
Definition opcode.h:29
SNF_opcode_mmbr_t opcode[4]
SNF_opcode's Structure if you wanna access using a table.
Definition opcode.h:48
struct SNF_opcode_t::SNF_opcode_struct strct