diff options
| author | Mosder <xmosder12@gmail.com> | 2026-07-20 15:48:51 +0200 |
|---|---|---|
| committer | Mosder <xmosder12@gmail.com> | 2026-07-20 15:48:51 +0200 |
| commit | c182f2f4f850589c23b2241e11dab143e1003ff2 (patch) | |
| tree | 45d9ba272af2ffdeec55af31b63591790ac4342f | |
| parent | e0bf82fe2af66ef55872569ae15733f70b4913d4 (diff) | |
refactor: changed #ifndef guards, so that there is one per file
| -rw-r--r-- | analyzer/parser/fight_results.h | 17 | ||||
| -rw-r--r-- | analyzer/parser/parser_defs.h | 15 | ||||
| -rw-r--r-- | analyzer/structures/heap.h | 8 | ||||
| -rw-r--r-- | analyzer/utils/tcp.h | 11 |
4 files changed, 19 insertions, 32 deletions
diff --git a/analyzer/parser/fight_results.h b/analyzer/parser/fight_results.h index ca45348..3aadf09 100644 --- a/analyzer/parser/fight_results.h +++ b/analyzer/parser/fight_results.h @@ -4,6 +4,9 @@ #include "parser/parser_defs.h" #include "utils/tcp.h" +#ifndef FIGHT_RESULTS_H +#define FIGHT_RESULTS_H + // Payload structure: // FIGHT_RESULTS_START EntityResults (SEPARATOR_ENTITY EntityResults)* FIGHT_RESULTS_END // @@ -92,8 +95,6 @@ &entity_results.saturation \ } -#ifndef ENTITY_RESULTS_DEFINED -#define ENTITY_RESULTS_DEFINED typedef struct { int team; // friend or enemy char *name; @@ -131,7 +132,6 @@ typedef struct { char *field34; char *saturation; } EntityResults; -#endif // items/gear/drifs fields parsing info #define INIT_ITEMS_CAPACITY 8 @@ -143,8 +143,6 @@ typedef struct { #define TEAM_ENEMY 2 // fight results data for friendly -#ifndef FRIENDLY_RESULTS_DEFINED -#define FRIENDLY_RESULTS_DEFINED typedef struct { char *name; int exp; @@ -157,29 +155,24 @@ typedef struct { char *saturation_type; int saturation; } FriendlyResults; -#endif // fight results data for enemy -#ifndef ENEMY_RESULTS_DEFINED -#define ENEMY_RESULTS_DEFINED typedef struct { char *name; int level; } EnemyResults; -#endif #define MAX_ENTITIES_PER_SIDE 8 // entire fight resutls -#ifndef FIGHT_RESULTS_DEFINED -#define FIGHT_RESULTS_DEFINED typedef struct { size_t num_friendly; FriendlyResults friendly_results[MAX_ENTITIES_PER_SIDE]; size_t num_enemy; EnemyResults enemy_results[MAX_ENTITIES_PER_SIDE]; } FightResults; -#endif extern find_function_t find_fight_results; extern parse_function_t parse_fight_results; + +#endif diff --git a/analyzer/parser/parser_defs.h b/analyzer/parser/parser_defs.h index 6af6059..aa39a4c 100644 --- a/analyzer/parser/parser_defs.h +++ b/analyzer/parser/parser_defs.h @@ -3,18 +3,13 @@ #include "utils/tcp.h" -#ifndef TYPE_ENUM_DEFINED -#define TYPE_ENUM_DEFINED +#ifndef PARSER_DEFS_H +#define PARSER_DEFS_H + typedef enum { INT, FLOAT, DOUBLE, STRING } TypeEnum; -#endif -#ifndef RESULTS_ENUM_DEFINED -#define RESULTS_ENUM_DEFINED typedef enum { TYPE_FIGHT_RESULTS } ResultsEnum; -#endif -#ifndef PARSED_DATA_DEFINED -#define PARSED_DATA_DEFINED // "generic" type for parsed data typedef struct { ResultsEnum data_type; // type of data represented by an enum @@ -22,7 +17,6 @@ typedef struct { void (*data_cleanup)(void *data); // function to cleanup internal allocations inside data // if no internal allocations - this should be NULL } ParsedData; -#endif // find the first results data of specific type in stream // params: @@ -42,10 +36,9 @@ typedef byte_t *find_function_t(TCPStream *stream, int offset, int *length); typedef ParsedData parse_function_t(byte_t *data, size_t length); // struct for holding the find and parse function for every result type -#ifndef FIND_PARSE_FUNCTIONS_DEFINED -#define FIND_PARSE_FUNCTIONS_DEFINED typedef struct { find_function_t *find_fn; parse_function_t *parse_fn; } FindParseFunctions; + #endif diff --git a/analyzer/structures/heap.h b/analyzer/structures/heap.h index 8a23164..1ae72c0 100644 --- a/analyzer/structures/heap.h +++ b/analyzer/structures/heap.h @@ -3,11 +3,12 @@ #include <stddef.h> +#ifndef HEAP_H +#define HEAP_H + #define INIT_HEAP_DEPTH 7 #define INIT_HEAP_CAPACITY (1 << INIT_HEAP_DEPTH) - 1 -#ifndef HEAP_DEFINED -#define HEAP_DEFINED typedef struct { void **data; size_t n_elements; @@ -16,7 +17,6 @@ typedef struct { int (*compare)(void *element1, void *element2); void (*element_cleanup)(void *element); } Heap; -#endif // create a new heap // params: @@ -56,3 +56,5 @@ extern void heap_top_remove(Heap *heap); // free the heap // - heap - heap to free extern void heap_free(Heap *heap); + +#endif diff --git a/analyzer/utils/tcp.h b/analyzer/utils/tcp.h index 9c6a949..13cbb15 100644 --- a/analyzer/utils/tcp.h +++ b/analyzer/utils/tcp.h @@ -5,19 +5,19 @@ #include "structures/heap.h" +#ifndef TCP_H +#define TCP_H + typedef unsigned char byte_t; // struct to persistently store TCP segments // payload field is malloced and needs to be freed -#ifndef TCP_SEGMENT_DEFINED -#define TCP_SEGMENT_DEFINED typedef struct { byte_t *payload; // payload in the segment size_t len; // length of the payload uint32_t seq; // TCP sequence number of the segment uint16_t port; // destination (client) port of connection the segment was received from } TCPSegment; -#endif // get TCP segment from captured packet // params: @@ -28,8 +28,6 @@ typedef struct { extern TCPSegment get_segment_from_packet(const byte_t *packet, const struct pcap_pkthdr *packet_data); // struct that stores all the information about stream -#ifndef TCP_STREAM_DEFINED -#define TCP_STREAM_DEFINED typedef struct { byte_t *data; // bytes in the stream size_t len; // length of the stream @@ -38,7 +36,6 @@ typedef struct { uint16_t port; // destination (client) port of current analyzed connection Heap *pending; // min heap of segments yet to be added to stream (sorted by TCP sequence number) } TCPStream; -#endif #define INIT_STREAM_CAPACITY 256 @@ -68,3 +65,5 @@ extern void remove_parsed_data(TCPStream *stream, size_t parsed_len); // returns: // 1 if the segment was added to the stream, 0 if it was discarded or saved to pending extern int handle_segment(TCPStream *stream, TCPSegment segment); + +#endif |
