LibDap
This library contains the basic modules that are used in the products of the family DAP
dap_common.h
Go to the documentation of this file.
1 /*
2  * Authors:
3  * Dmitriy A. Gearasimov <kahovski@gmail.com>
4  * DeM Labs Inc. https://demlabs.net
5  * DeM Labs Open source community https://github.com/demlabsinc
6  * Copyright (c) 2017-2018
7  * All rights reserved.
8 
9  This file is part of DAP (Deus Applications Prototypes) the open source project
10 
11  DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
12  it under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  DAP is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
23 */
24 #pragma once
25 #include <stdarg.h>
26 #include <stddef.h>
27 #include <stdlib.h>
28 #include <time.h>
29 
30 #define DAP_NEW(a) ( (a*) malloc(sizeof(a)))
31 #define DAP_NEW_SIZE(a,b) ( (a*) malloc(b))
32 #define DAP_NEW_Z(a) ( (a*) calloc(1,sizeof(a)))
33 #define DAP_NEW_Z_SIZE(a,b) ( (a*) calloc(1,b))
34 
35 #define DAP_DELETE(a) free(a)
36 #define DAP_DUP(a) (__typeof(a) ret = memcpy(ret,a,sizeof(*a)) )
37 
38 #define DAP_PROTOCOL_VERSION 21
39 
40 #if defined(__GNUC__) ||defined (__clang__)
41 #define DAP_ALIGN_PACKED __attribute__((aligned(1),packed))
42 #endif
43 
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 int dap_common_init( const char * a_log_file );
54 void dap_common_deinit(void);
55 
56 void _log_it(const char * log_tag, enum log_level, const char * format,...);
57 void _vlog_it(const char * log_tag, enum log_level, const char * format, va_list ap );
58 #define log_it(_log_level,...) _log_it(LOG_TAG,_log_level,##__VA_ARGS__)
59 #define vlog_it(a_log_level,a_format,a_ap) _vlog_it(LOG_TAG,a_log_level,a_format,a_ap)
60 
61 const char * log_error(void);
62 void set_log_level(enum log_level ll);
63 void dap_set_log_tag_width(size_t width);
64 
65 #ifdef __GNUC__
66 char *itoa(int i);
67 
68 
69 #elif _MSC_VER
70 char *strndup(const char *s, size_t n);
71 #endif
72 int time_to_rfc822(char * out, size_t out_size_max, time_t t);
73 
74 int get_select_breaker(void);
75 int send_select_break(void);
76 char * exec_with_ret(const char * a_cmd);
77 char * exec_with_ret_multistring(const char * a_cmd);
78 char * dap_random_string_create_alloc(size_t a_length);
79 void dap_random_string_fill(char *str, size_t length);
80 
81 #ifdef __cplusplus
82 }
83 #endif
Definition: dap_common.h:47
void dap_set_log_tag_width(size_t width)
dap_set_log_tag_width Sets the length of the label
Definition: dap_common.c:77
Definition: dap_common.h:47
log_level
The log_level enum.
Definition: dap_common.h:47
Definition: dap_common.h:47
char * exec_with_ret_multistring(const char *a_cmd)
exec_with_ret_multistring performs a command with a result return in the form of a multistring ...
Definition: dap_common.c:362
Definition: dap_common.h:47
char * itoa(int i)
itoa The function converts an integer num to a string equivalent and places the result in a string ...
Definition: dap_common.c:228
void dap_common_deinit(void)
dap_common_deinit Deinitialise
Definition: dap_common.c:114
void set_log_level(enum log_level ll)
set_log_level Sets the logging level
Definition: dap_common.c:69
char * dap_random_string_create_alloc(size_t a_length)
random_string_create Generates a random string
Definition: dap_common.c:401
void _vlog_it(const char *log_tag, enum log_level, const char *format, va_list ap)
Definition: dap_common.c:137
int dap_common_init(const char *a_log_file)
dap_common_init initialise
Definition: dap_common.c:94
Definition: dap_common.h:47
int send_select_break(void)
Definition: dap_common.c:293
int time_to_rfc822(char *out, size_t out_size_max, time_t t)
time_to_rfc822 Convert time_t to string with RFC822 formatted date and time
Definition: dap_common.c:257
const char * log_error(void)
log_error Error log
Definition: dap_common.c:215
int get_select_breaker(void)
Definition: dap_common.c:283
void dap_random_string_fill(char *str, size_t length)
random_string_fill Filling a string with random characters
Definition: dap_common.c:390
void _log_it(const char *log_tag, enum log_level, const char *format,...)
_log_it Writes information to the log
Definition: dap_common.c:125
char * exec_with_ret(const char *a_cmd)
exec_with_ret Executes a command with result return
Definition: dap_common.c:339
Definition: dap_common.h:47