diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2020-06-23 07:39:29 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2020-06-23 07:39:29 +0200 |
commit | c84c3f459919aa8db2a24c8461aab9e547be961f (patch) | |
tree | 58a71c95096f386f0b043f64cecbd382ec978348 | |
parent | ca37489b388764b3a8f2d558a9e9a24e3e0d4105 (diff) | |
download | dns-c84c3f459919aa8db2a24c8461aab9e547be961f.tar.gz |
Comments, white space errors
-rw-r--r-- | src/dns.c | 2 | ||||
-rw-r--r-- | src/dns.h | 2 | ||||
-rw-r--r-- | src/log.c | 2 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/server.c | 2 | ||||
-rw-r--r-- | src/test.c | 6 | ||||
-rw-r--r-- | src/tree.h | 48 |
7 files changed, 45 insertions, 19 deletions
@@ -11,7 +11,7 @@ int dns_construct_header ( struct dns_header* _header, char* _buffer, int _buffl return -1; *((uint16_t*)_buffer) = _header->id; //Since only copied, no flipping necessary - _buffer[2] = + _buffer[2] = ((_header->QR & 0x01) << 7) | ((_header->OPCODE & 0x0F) << 3) | ((_header->AA & 0x01) << 2) | @@ -161,7 +161,7 @@ int dns_destroy_struct ( struct dns_message* _msg ); int dns_parse_packet ( char* _buffer, int _bufflen, struct dns_message* _msg ); /** - * Convert a null terminated string containing a + * Convert a null terminated string containing a * fqdn (eg server.example.com) to the binary format used by DNS records * ( [6]server[7]example[3]com[0] ) * returns: length of string in _sink, < 0 on failure @@ -24,7 +24,7 @@ int log_init_stdout(unsigned int _verbosity) { log_loglevel = _verbosity;// > _LOG_DEBUG ? _LOG_DEBUG : _verbosity; log_fd = STDIN_FILENO; - + LOGPRINTF(0, "=== RESTART ==="); LOGPRINTF(0, "Verbosity: %i", _verbosity); @@ -18,6 +18,6 @@ int main(int argc, char* argv[]) #else run_dns_server(); #endif - + } diff --git a/src/server.c b/src/server.c index 4a449da..1b28b14 100644 --- a/src/server.c +++ b/src/server.c @@ -109,7 +109,7 @@ void signal_term ( ) { printf( "Recieved Signal. Terminating active connections and closing socket\n" ); //terminate all children >:) - kill ( 0, SIGTERM ); + kill ( 0, SIGTERM ); shutdown ( sock_server, SHUT_RDWR ); close ( sock_server ); @@ -10,7 +10,7 @@ void run_test () { //Space for temporary tests - + //tree_balanced_insert(NULL, NULL, NULL, 15 ); //Normal tests test_tree(); @@ -24,10 +24,10 @@ int test_tree () printf("\n-> test_tree()\n======\n\n"); struct tree_node* root = NULL; - + tree_insert ( &root, "eins", "Test eins" ); tree_insert ( &root, "zwei", "Test zwei" ); - + printf("After Insert\n"); printf("%s\n", tree_get(&root, "zwei")); @@ -4,11 +4,43 @@ * License: MIT * */ +/** + * Binary tree designed to serve as a static lookup table. + * On the fly rebalancing is not intended. + * + * The char* _key is used as a primary key, the tree can + * carry any generic payload in void* _data. + * + * The root does not need special initialization. + * + * A query with tree_get() returns _data on an exact match, + * NULL if no matching key is found. + * + * To free the memory, do not use free() on root, but + * tree_destroy() instead. _key and _data can be freed + * by providing _TREE_FREE_DATA | _TREE_FREE_KEY. + * + * Example: + * + * struct tree_node* root = NULL; + * + * // A String is used as data + * tree_insert ( &root, "one", "data one" ); + * tree_insert ( &root, "two", "data two" ); + * + * printf( "%s\n", tree_get( &root, "two" ) ); + * + * tree_destroy ( &root, 0 ); + * + **/ + #pragma once #include <stdlib.h> #include <stdint.h> +#include <math.h> +//TODO remove #include <stdio.h> #define _TREE_FREE_DATA 0x01 @@ -23,7 +55,11 @@ struct tree_node { int tree_insert ( struct tree_node** _root, char* _key, void* _data ); -int tree_balance( struct tree_node** _root ); +/** + * Inserts the given list into the tree, achieving optimal depth. + * Expects a sorted list. + * */ +int tree_balanced_insert( struct tree_node** _root, void* _data[], char* _key[], unsigned int _len); /** * Returns (void*)node->data on success, NULL on failure @@ -31,13 +67,3 @@ int tree_balance( struct tree_node** _root ); void* tree_get ( struct tree_node** _root, char* _query ); int tree_destroy( struct tree_node** _root, uint8_t _options ); - -/** - * ignore-case alphabetical string compare - * returns: - * 0 :: _1 == _2 - * -1 :: _1 < _2 - * +1 :: _1 > _2 - * */ -int string_compare ( char* _1, char* _2 ); - |