Shadow Network Framework  0.0.2-alpha
C Server Library for Shadow Network Framework
Loading...
Searching...
No Matches
opcode.h File Reference

This file Defines everything related to Opcodes ( Short for OP**eartion**Codes ) More...

Go to the source code of this file.

Data Structures

union  SNF_opcode_t
 Structure for the opcode. More...
 
struct  SNF_opcode_t::SNF_opcode_struct
 SNF_opcode's Structure if you wanna access it as a struct. More...
 
struct  SNF_opcode_LL_item_t
 Structure used to save registred opcode members. More...
 

Macros

#define SNF_opcode_mmbr_t   uint8_t
 Defines SNF_opcode_mmbr_t 's size.
 
#define SNF_opcode_mmbr_MAX   UINT8_MAX
 Defines SNF_opcode_mmbr_t 's maximum possible Value.
 
#define SNF_OPCODE_BASE_CAT   (SNF_opcode_mmbr_t)0x00
 Base Category for SNF.
 
#define SNF_OPCODE_BASE_SUBCAT   (SNF_opcode_mmbr_t)0x00
 Base Sub-Category for SNF.
 
#define SNF_OPCODE_BASE_DET_UNDETAILED   (SNF_opcode_mmbr_t)0x00
 Default Detail.
 
#define SNF_OPCODE_BASE_CMD_CONNECT   (SNF_opcode_mmbr_t)0x00
 When client attemps to connect.
 
#define SNF_OPCODE_BASE_CMD_RECONNECT   (SNF_opcode_mmbr_t)0x01
 When client attemps to reconnect - or forced to.
 
#define SNF_OPCODE_BASE_CMD_DISCONNECT   (SNF_opcode_mmbr_t)0x02
 When client attemps to disconnect.
 
#define SNF_OPCODE_BASE_CMD_SNF_VER   (SNF_opcode_mmbr_t)0x03
 When client requests SNF version of the Server.
 
#define SNF_OPCODE_BASE_CMD_KICK   (SNF_opcode_mmbr_t)0x04
 When client was forced to disconnect ( Kicked ).
 
#define SNF_OPCODE_BASE_CMD_CONFIRM   (SNF_opcode_mmbr_t)0x05
 When client's reuqest was confirmed.
 
#define SNF_OPCODE_BASE_CMD_REJECT   (SNF_opcode_mmbr_t)0x06
 When client's request was rejected.
 
#define SNF_OPCODE_BASE_CMD_INVALID   (SNF_opcode_mmbr_t)0xFF
 When client's request was invalid either, wrong version or incomplete request.
 
#define SNF_OPCODE_BASE_DET_INVALID_UNREGISTRED_OPCODE   (SNF_opcode_mmbr_t)0x01
 Received opcode was not registred.
 
#define SNF_OPCODE_BASE_DET_INVALID_ERROR_PROTOCOL   (SNF_opcode_mmbr_t)0x02
 Protocol used is invalid.
 
#define SNF_OPCODE_BASE_DET_INVALID_UNIMPLEMENTED_OPCODE   (SNF_opcode_mmbr_t)0x03
 Received opcode does not have a function to call.
 

Typedefs

typedef union SNF_opcode_t SNF_opcode
 Shortened definiton of struct SNF_opcode_t .
 
typedef struct SNF_opcode_LL_item_t SNF_opcode_LL_item
 Shortened definiton of struct SNF_opcode_LL_item_t .
 

Functions

int snf_opcode_init ()
 Initializes the SNF's opcodes.
 
int snf_opcode_define_category (SNF_opcode_mmbr_t Code, const char *Definition)
 Defines an opcode Category.
 
int snf_opcode_define_sub_category (SNF_opcode_mmbr_t Category, SNF_opcode_mmbr_t Code, const char *Definition)
 Defines an opcode Sub-Category.
 
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_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.
 
SNF_opcode_LL_itemsnf_opcode_get_category (SNF_opcode_mmbr_t Category)
 Fetches the opcode Category from the opcode's data structure.
 
SNF_opcode_LL_itemsnf_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_itemsnf_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_itemsnf_opcode_get_detail (SNF_opcode_mmbr_t Category, SNF_opcode_mmbr_t SubCategory, SNF_opcode_mmbr_t Command, SNF_opcode_mmbr_t Detail)
 
SNF_opcodesnf_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.
 
SNF_opcodesnf_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.
 
int snf_opcode_compare (SNF_opcode *op1, SNF_opcode *op2)
 Compares between two opcodes.
 
int snf_opcode_isbase (SNF_opcode *op)
 
SNF_opcode_LL_itemsnf_opcode_get_base_category ()
 Fetches the base opcode Category from the opcode's data structure.
 
SNF_opcode_LL_itemsnf_opcode_get_base_sub_category ()
 Fetches the base opcode Sub-Category from the opcode's data structure.
 
SNF_opcode_LL_itemsnf_opcode_get_base_command (SNF_opcode_mmbr_t Command)
 Fetches a base opcode Command from the opcode's data structure.
 
SNF_opcode_LL_itemsnf_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_opcodesnf_opcode_get_base (SNF_opcode_mmbr_t Command, SNF_opcode_mmbr_t Detail)
 Fetches a fully structured OPcode with a base "Command".
 
SNF_opcodesnf_opcode_getu_base (SNF_opcode_mmbr_t Command)
 Fetches a fully structured OPcode witha base "Command" using the default Detail.
 

Variables

SNF_opcode_LL_itemSNF_opcode_LL
 Data structure where opcodes will be saved.
 
int SNF_opcode_base_isinit
 used to check if SNF's base opcodes are initialized
 

Detailed Description

This file Defines everything related to Opcodes ( Short for OP**eartion**Codes )

Macro Definition Documentation

◆ SNF_opcode_mmbr_t

#define SNF_opcode_mmbr_t   uint8_t

Defines SNF_opcode_mmbr_t 's size.

◆ SNF_opcode_mmbr_MAX

#define SNF_opcode_mmbr_MAX   UINT8_MAX

Defines SNF_opcode_mmbr_t 's maximum possible Value.

◆ SNF_OPCODE_BASE_CAT

#define SNF_OPCODE_BASE_CAT   (SNF_opcode_mmbr_t)0x00

Base Category for SNF.

Warning
Do not add anything under this Catergory

◆ SNF_OPCODE_BASE_SUBCAT

#define SNF_OPCODE_BASE_SUBCAT   (SNF_opcode_mmbr_t)0x00

Base Sub-Category for SNF.

Warning
Do not add anything under this Sub-Catergory

◆ SNF_OPCODE_BASE_DET_UNDETAILED

#define SNF_OPCODE_BASE_DET_UNDETAILED   (SNF_opcode_mmbr_t)0x00

Default Detail.

Note
This will always be added by default to every Command

◆ SNF_OPCODE_BASE_CMD_CONNECT

#define SNF_OPCODE_BASE_CMD_CONNECT   (SNF_opcode_mmbr_t)0x00

When client attemps to connect.

Warning
Do not add anything under this Command

◆ SNF_OPCODE_BASE_CMD_RECONNECT

#define SNF_OPCODE_BASE_CMD_RECONNECT   (SNF_opcode_mmbr_t)0x01

When client attemps to reconnect - or forced to.

Warning
Do not add anything under this Command

◆ SNF_OPCODE_BASE_CMD_DISCONNECT

#define SNF_OPCODE_BASE_CMD_DISCONNECT   (SNF_opcode_mmbr_t)0x02

When client attemps to disconnect.

Warning
Do not add anything under this Command

◆ SNF_OPCODE_BASE_CMD_SNF_VER

#define SNF_OPCODE_BASE_CMD_SNF_VER   (SNF_opcode_mmbr_t)0x03

When client requests SNF version of the Server.

Warning
Do not add anything under this Command

◆ SNF_OPCODE_BASE_CMD_KICK

#define SNF_OPCODE_BASE_CMD_KICK   (SNF_opcode_mmbr_t)0x04

When client was forced to disconnect ( Kicked ).

Warning
Do not add anything under this Command

◆ SNF_OPCODE_BASE_CMD_CONFIRM

#define SNF_OPCODE_BASE_CMD_CONFIRM   (SNF_opcode_mmbr_t)0x05

When client's reuqest was confirmed.

Warning
Do not add anything under this Command

◆ SNF_OPCODE_BASE_CMD_REJECT

#define SNF_OPCODE_BASE_CMD_REJECT   (SNF_opcode_mmbr_t)0x06

When client's request was rejected.

Warning
Do not add anything under this Command

◆ SNF_OPCODE_BASE_CMD_INVALID

#define SNF_OPCODE_BASE_CMD_INVALID   (SNF_opcode_mmbr_t)0xFF

When client's request was invalid either, wrong version or incomplete request.

Warning
Do not add anything under this Command

◆ SNF_OPCODE_BASE_DET_INVALID_UNREGISTRED_OPCODE

#define SNF_OPCODE_BASE_DET_INVALID_UNREGISTRED_OPCODE   (SNF_opcode_mmbr_t)0x01

Received opcode was not registred.

◆ SNF_OPCODE_BASE_DET_INVALID_ERROR_PROTOCOL

#define SNF_OPCODE_BASE_DET_INVALID_ERROR_PROTOCOL   (SNF_opcode_mmbr_t)0x02

Protocol used is invalid.

◆ SNF_OPCODE_BASE_DET_INVALID_UNIMPLEMENTED_OPCODE

#define SNF_OPCODE_BASE_DET_INVALID_UNIMPLEMENTED_OPCODE   (SNF_opcode_mmbr_t)0x03

Received opcode does not have a function to call.

Typedef Documentation

◆ SNF_opcode

typedef union SNF_opcode_t SNF_opcode

Shortened definiton of struct SNF_opcode_t .

◆ SNF_opcode_LL_item

Shortened definiton of struct SNF_opcode_LL_item_t .

Function Documentation

◆ snf_opcode_init()

int snf_opcode_init ( )
extern

Initializes the SNF's opcodes.

Returns
The possible results :
  • -1 On fail (Shall fail if calloc fails, check errno depending on calloc error codes)
  • 0 On Success

◆ snf_opcode_define_category()

int snf_opcode_define_category ( SNF_opcode_mmbr_t Code,
const char * Definition )
extern

Defines an opcode Category.

Parameters
CodeOPcode category's value
DefinitionString Definition for The category
Returns
The possible results :
  • 0 On Success
  • 1 if the Category already exists
  • -1 On fail ( Shall fail if calloc fails, check calloc error codes )

◆ snf_opcode_define_sub_category()

int snf_opcode_define_sub_category ( SNF_opcode_mmbr_t Category,
SNF_opcode_mmbr_t Code,
const char * Definition )
extern

Defines an opcode Sub-Category.

Parameters
CategoryOPcode's Category
CodeOPcode subcategory's value
DefinitionString Definition for The sub-category
Returns
The possible results :
  • 0 On Success
  • 1 if Sub-Category Already Exists
  • -1 On calloc fail
  • -2 if Category was not found or opcode's data structure is empty ( Possibly snf_opcode_init was not called )

◆ snf_opcode_define_command()

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 * )
extern

Defines an opcode Command.

Parameters
CategoryOPcode's Category
SubCategoryOPcode's Sub-Category
CodeOpcode command's value
DefinitionString Definition for The command///
Returns
The possible results :
  • 0 On Success
  • 1 if Command Already Exists
  • -1 On calloc fail
  • -2 if Sub-Category was not found or opcode's data structure is empty ( Possibly snf_opcode_init was not called )

◆ snf_opcode_define_detail()

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 )
extern

Defines an opcode Detail.

Parameters
CategoryOPcode's Category
SubCategoryOPcode's Sub-Category
CommandOpcode's Command
CodeOpcode detail's value
DefinitionString Definition for The detail
Returns
The possible results :
  • 0 On Success
  • 1 if Detail Already Exists
  • -1 On calloc fail
  • -2 if Command was not found or opcode's data structure is empty ( Possibly snf_opcode_init was not called )

◆ snf_opcode_get_category()

SNF_opcode_LL_item * snf_opcode_get_category ( SNF_opcode_mmbr_t Category)
extern

Fetches the opcode Category from the opcode's data structure.

Parameters
CategoryCategory to be fetched.
Returns
The possible results :
  • NULL if Category wasn't found or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
  • Pointer to the Category

◆ snf_opcode_get_sub_category()

SNF_opcode_LL_item * snf_opcode_get_sub_category ( SNF_opcode_mmbr_t Category,
SNF_opcode_mmbr_t SubCategory )
extern

Fetches the opcode Sub-Category from the opcode's data structure.

Parameters
CategoryParent Category
SubCategorySub-Category to be fetched.
Returns
The possible results :
  • NULL if Sub-Category wasn't found
  • Pointer to the Sub-Category or opcode's data structure is empty ( Possibly snf_opcode_init was not called )

◆ snf_opcode_get_command()

SNF_opcode_LL_item * snf_opcode_get_command ( SNF_opcode_mmbr_t Category,
SNF_opcode_mmbr_t SubCategory,
SNF_opcode_mmbr_t Command )
extern

Fetches the opcode Command from the opcode's data structure.

Parameters
CategoryParent Category
SubCategoryParent Sub-Category
CommandCommand to be fetched.
Returns
The possible results :
  • NULL if Command wasn't found
  • Pointer to the Command or opcode's data structure is empty ( Possibly snf_opcode_init was not called )

◆ snf_opcode_get_detail()

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 )
extern
Parameters
CategoryParent Category
SubCategoryParent Sub-Category
CommandParent Command
DetailDetail to be fetched.
Returns
The possible results :
  • NULL if Detail wasn't found
  • Pointer to the Detail

◆ snf_opcode_get()

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 )
extern

Fetches a fully structured OPcode.

Parameters
CategoryParent Category.
SubCategoryParent Sub-Category
CommandExecuting Command
DetailGiven Detail.
Returns
The possible results :
  • NULL if any of the Members was not found
  • Pointer to the SNF_opcode instance
Note
If you want to generate an Undetailed ( Detail's value is equal to SNF_OPCODE_BASE_DET_UNDETAILED ) then use snf_opcode_getu()

◆ snf_opcode_getu()

SNF_opcode * snf_opcode_getu ( SNF_opcode_mmbr_t Category,
SNF_opcode_mmbr_t SubCategory,
SNF_opcode_mmbr_t Command )
extern

Fetches a fully structured OPcode using the default Detail.

Parameters
CategoryParent Category.
SubCategoryParent Sub-Category
CommandExecuting Command
Returns
The possible results :
  • NULL if any of the Members was not found
  • Pointer to the undetailed SNF_opcode instance
Note
Detail's value will be equal to SNF_OPCODE_BASE_DET_UNDETAILED

◆ snf_opcode_compare()

int snf_opcode_compare ( SNF_opcode * op1,
SNF_opcode * op2 )
extern

Compares between two opcodes.

Parameters
op1OPCode 1
op2OPCode 2
Returns
The possible results :
  • -2 Given opcodes are different
  • **-1 if either opcodes are NULL
  • **0 when opcodes are equal
  • 1 Opcodes have equal command. but op1 has bigger Detail
  • 2 Opcodes have equal command. but op2 has bigger Detail

◆ snf_opcode_isbase()

int snf_opcode_isbase ( SNF_opcode * op)
extern

◆ snf_opcode_get_base_category()

SNF_opcode_LL_item * snf_opcode_get_base_category ( )
extern

Fetches the base opcode Category from the opcode's data structure.

Returns
The possible results :
  • NULL if Category wasn't found or opcode's data structure is empty ( Possibly snf_opcode_init was not called )
  • Pointer to the Category

◆ snf_opcode_get_base_sub_category()

SNF_opcode_LL_item * snf_opcode_get_base_sub_category ( )
extern

Fetches the base opcode Sub-Category from the opcode's data structure.

Returns
The possible results :
  • NULL if Sub-Category wasn't found
  • Pointer to the Sub-Category or opcode's data structure is empty ( Possibly snf_opcode_init was not called )

◆ snf_opcode_get_base_command()

SNF_opcode_LL_item * snf_opcode_get_base_command ( SNF_opcode_mmbr_t Command)
extern

Fetches a base opcode Command from the opcode's data structure.

Parameters
Commandrequested Command
Returns
The possible results :
  • NULL if Command wasn't found
  • Pointer to the Command or opcode's data structure is empty ( Possibly snf_opcode_init was not called )

◆ snf_opcode_get_base_detail()

SNF_opcode_LL_item * snf_opcode_get_base_detail ( SNF_opcode_mmbr_t Command,
SNF_opcode_mmbr_t Detail )
extern

Fetches a base opcode Command from the opcode's data structure.

Parameters
CommandParent Command
DetailCommand's Detail
Returns
The possible results :
  • NULL if Detail wasn't found
  • Pointer to the Detail or opcode's data structure is empty ( Possibly snf_opcode_init was not called )

◆ snf_opcode_get_base()

SNF_opcode * snf_opcode_get_base ( SNF_opcode_mmbr_t Command,
SNF_opcode_mmbr_t Detail )
extern

Fetches a fully structured OPcode with a base "Command".

Parameters
CommandBase Command's Value
DetailBase Command Detail's Value
Returns
The possible results :
  • NULL if any of the Members was not found
  • Pointer to the SNF_opcode instance
Note
If you want to generate an Undetailed ( Detail's value is equal to SNF_OPCODE_BASE_DET_UNDETAILED ) then use snf_opcode_getu_base()

◆ snf_opcode_getu_base()

SNF_opcode * snf_opcode_getu_base ( SNF_opcode_mmbr_t Command)
extern

Fetches a fully structured OPcode witha base "Command" using the default Detail.

Parameters
CommandBase Command's Value
Returns
The possible results :
  • NULL if any of the Members was not found
  • Pointer to the undetailed SNF_opcode instance
Note
Detail's value will be equal to SNF_OPCODE_BASE_DET_UNDETAILED

Variable Documentation

◆ SNF_opcode_LL

SNF_opcode_LL_item* SNF_opcode_LL
extern

Data structure where opcodes will be saved.

◆ SNF_opcode_base_isinit

int SNF_opcode_base_isinit
extern

used to check if SNF's base opcodes are initialized