44 #define _ksn_printf_type_(type) \
45 (type == MESSAGE ? "MESSAGE" : \
46 type == ERROR_M ? "ERROR" : \
47 type == DEBUG ? "DEBUG" : \
48 type == DEBUG_VV ? "DEBUG_VV" : \
49 type == DEBUG_VVV ? "DEBUG_VVV" : \
50 type == CONNECT ? "CONNECT" : "DISPLAY")
52 #define _ksn_printf_format_(format) "%s %s: " _ANSI_GREY "%s:(%s:%d)" _ANSI_NONE ": " _ANSI_GREEN format _ANSI_NONE
53 #define _ksn_printf_format_display_m(format) "%s%s%s%s%d\b" format
55 #define ksn_printf(ke, module, type, format, ...) \
56 ksnet_printf(&((ke)->teo_cfg), type, \
57 _ksn_printf_format_(format), \
58 _ksn_printf_type_(type), \
59 module[0] == '\0' ? (ke)->teo_cfg.app_name : module, \
60 __func__, __FILE__, __LINE__, __VA_ARGS__)
62 #define ksn_puts(ke, module, type, format) \
63 ksnet_printf(&((ke)->teo_cfg), type, \
64 _ksn_printf_format_(format) "\n", \
65 _ksn_printf_type_(type), \
66 module[0] == '\0' ? (ke)->teo_cfg.app_name : module, \
67 __func__, __FILE__, __LINE__)
82 void *
memdup(
const void* d,
size_t s);
83 char *
trim(
char *str);
88 int inarray(
int val,
const int *arr,
int size);
107 size_t *output_length);
111 size_t *output_length);
113 void dump_bytes(
char *buffer,
int buffer_len, uint8_t* data,
int data_len);
#2 Connect or Auth messages
Definition: src/utils/utils.h:35
void * memdup(const void *d, size_t s)
Duplicate memory.
Definition: utils.c:358
char * ksnet_vformatMessage(const char *fmt, va_list ap)
Definition: utils.c:263
void resolveDnsName(teonet_cfg *conf)
Definition: utils.c:815
#7 Regular messages (display only)
Definition: src/utils/utils.h:40
char * addr
Definition: src/utils/utils.h:20
int ip_is_private(char *ip)
Detect if input IP address is private.
Definition: utils.c:847
const char data[]
Make it with: gcc -o post-callback post-callback.c -lcurl.
Definition: post-callback.c:23
int calculate_lines(char *str)
Calculate number of lines in string.
Definition: utils.c:387
ksnet_printf_type
KSNet printf messages types.
Definition: src/utils/utils.h:31
int KSN_GET_TEST_MODE()
Definition: utils.c:37
Definition: src/utils/utils.h:19
#6 Debug message (extra+)
Definition: src/utils/utils.h:39
int set_reuseaddr(int sd)
Make socket reusable.
Definition: utils.c:553
char * ksn_base64_encode(const unsigned char *data, size_t input_length, size_t *output_length)
Base64 encode.
Definition: base64.c:48
char * ksnet_getSysConfigDir(void)
Getting path to ksnet configuration folder.
Definition: utils.c:569
#1 Error message
Definition: src/utils/utils.h:34
int ip_to_array(char *ip, uint8_t *arr)
Convert IP to bytes array.
Definition: utils.c:739
addr_port_t * wrap_inet_ntop(const struct sockaddr *sa)
Definition: utils.c:722
#0 Log off
Definition: src/utils/utils.h:33
char * trim(char *str)
Remove trailing or leading space.
Definition: utils.c:328
char ** ksnet_stringArr
Definition: string_arr.h:11
void printHexDump(void *addr, size_t len)
Definition: utils.c:773
size_t get_num_of_tags(char *data, size_t data_length)
Calculate number of tags in json string.
Definition: utils.c:867
#5 Debug message (extra)
Definition: src/utils/utils.h:38
void addr_port_free(addr_port_t *ap_obj)
Definition: utils.c:679
ksnet_stringArr getIPs(teonet_cfg *conf)
Get IPs.
Definition: utils.c:613
#3 Regular messages
Definition: src/utils/utils.h:36
void dump_bytes(char *buffer, int buffer_len, uint8_t *data, int data_len)
uint16_t port
Definition: src/utils/utils.h:21
char * ksnet_formatMessage(const char *fmt,...)
Create formated message in new null terminated string.
Definition: utils.c:231
char * trimlf(char *str)
Remove trailing line feeds characters from null terminated string.
Definition: utils.c:308
void KSN_SET_TEST_MODE(int test_mode)
Definition: utils.c:34
#4 Debug message (normal)
Definition: src/utils/utils.h:37
char * ksnet_sformatMessage(char *str_to_free, const char *fmt,...)
Create formated message in new null terminated string, and free str_to_free.
Definition: utils.c:249
struct addr_port addr_port_t
int ksnet_printf(teonet_cfg *teo_cfg, int type, const char *format,...)
KSNet printf.
Definition: utils.c:59
char * removeTEsc(char *str)
Remove terminal escape substrings from string.
Definition: utils.c:210
int inarray(int val, const int *arr, int size)
Check if a value exist in a array.
Definition: utils.c:585
char * getRandomHostName(void)
Get random host name.
Definition: utils.c:403
unsigned char * ksn_base64_decode(const char *data, size_t input_length, size_t *output_length)
Base64decode.
Definition: base64.c:89
int teoLogPuts(teonet_cfg *teo_cfg, const char *module, int type, const char *message)
Definition: utils.c:196
int(* equal)(struct addr_port *, char *, uint16_t)
Definition: src/utils/utils.h:22
char * getDataPath(void)
Get path to teonet data folder.
Definition: utils.c:416