Teonet library
0.4.7
|
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include "rlutil.h"
#include "string_arr.h"
#include "config/conf.h"
Go to the source code of this file.
Data Structures | |
struct | addr_port |
Macros | |
#define | _ksn_printf_type_(type) |
#define | _ksn_printf_format_(format) "%s %s: " _ANSI_GREY "%s:(%s:%d)" _ANSI_NONE ": " _ANSI_GREEN format _ANSI_NONE |
#define | _ksn_printf_format_display_m(format) "%s%s%s%s%d\b" format |
#define | ksn_printf(ke, module, type, format,...) |
#define | ksn_puts(ke, module, type, format) |
Typedefs | |
typedef struct addr_port | addr_port_t |
typedef enum ksnet_printf_type | ksnet_printf_type |
KSNet printf messages types. More... | |
Enumerations | |
enum | ksnet_printf_type { NONE_LOG, ERROR_M, CONNECT, MESSAGE, DEBUG, DEBUG_VV, DEBUG_VVV, DISPLAY_M } |
KSNet printf messages types. More... | |
Functions | |
addr_port_t * | wrap_inet_ntop (const struct sockaddr *sa) |
void | addr_port_free (addr_port_t *ap_obj) |
int | teoLogPuts (teonet_cfg *teo_cfg, const char *module, int type, const char *message) |
int | ksnet_printf (teonet_cfg *teo_cfg, int type, const char *format,...) |
KSNet printf. More... | |
char * | ksnet_formatMessage (const char *fmt,...) |
Create formated message in new null terminated string. More... | |
char * | ksnet_sformatMessage (char *str_to_free, const char *fmt,...) |
Create formated message in new null terminated string, and free str_to_free. More... | |
char * | ksnet_vformatMessage (const char *fmt, va_list ap) |
char * | getRandomHostName (void) |
Get random host name. More... | |
void * | memdup (const void *d, size_t s) |
Duplicate memory. More... | |
char * | trim (char *str) |
Remove trailing or leading space. More... | |
char * | trimlf (char *str) |
Remove trailing line feeds characters from null terminated string. More... | |
char * | removeTEsc (char *str) |
Remove terminal escape substrings from string. More... | |
int | calculate_lines (char *str) |
Calculate number of lines in string. More... | |
int | inarray (int val, const int *arr, int size) |
Check if a value exist in a array. More... | |
int | set_reuseaddr (int sd) |
Make socket reusable. More... | |
char * | getDataPath (void) |
Get path to teonet data folder. More... | |
char * | ksnet_getSysConfigDir (void) |
Getting path to ksnet configuration folder. More... | |
ksnet_stringArr | getIPs (teonet_cfg *conf) |
Get IPs. More... | |
int | ip_is_private (char *ip) |
Detect if input IP address is private. More... | |
int | ip_to_array (char *ip, uint8_t *arr) |
Convert IP to bytes array. More... | |
size_t | get_num_of_tags (char *data, size_t data_length) |
Calculate number of tags in json string. More... | |
void | KSN_SET_TEST_MODE (int test_mode) |
int | KSN_GET_TEST_MODE () |
char * | ksn_base64_encode (const unsigned char *data, size_t input_length, size_t *output_length) |
Base64 encode. More... | |
unsigned char * | ksn_base64_decode (const char *data, size_t input_length, size_t *output_length) |
Base64decode. More... | |
void | dump_bytes (char *buffer, int buffer_len, uint8_t *data, int data_len) |
void | printHexDump (void *addr, size_t len) |
void | resolveDnsName (teonet_cfg *conf) |
#define _ksn_printf_format_ | ( | format | ) | "%s %s: " _ANSI_GREY "%s:(%s:%d)" _ANSI_NONE ": " _ANSI_GREEN format _ANSI_NONE |
#define _ksn_printf_format_display_m | ( | format | ) | "%s%s%s%s%d\b" format |
#define _ksn_printf_type_ | ( | type | ) |
#define ksn_printf | ( | ke, | |
module, | |||
type, | |||
format, | |||
... | |||
) |
Referenced by _check_connected(), _cmd_tcpp_read_cb(), _decrypt(), cmd_disconnected_cb(), cmd_l0_cb(), cmd_l0_check_cb(), cmd_l0_kick_client(), cmd_l0_to_cb(), cmd_reconnect_cb(), cmd_stream_cb(), cmd_udpp_read_cb(), connect_r_host_cb(), event_cb(), idle_activity_cb(), idle_cb(), idle_stdin_cb(), kq_connect_cb(), ksnCommandCheck(), ksnCommandSendCmdConnect(), ksnCommandSendCmdConnectA(), ksnCoreBind(), ksnCoreCheckNewPeer(), ksnCoreProcessPacket(), ksnCoreSendCmdto(), ksnCoreSendCmdtoA(), ksnCoreSendto(), ksnDecryptPackage(), ksnEncryptPackage(), ksnetEvMgrFree(), ksnetEvMgrRun(), ksnLNullClientDisconnect(), ksnLNullPacketSend(), ksnLNullSendToL0(), ksnLNulltrudpCheckPaket(), ksnSplitCombine(), ksnSplitPacket(), ksnStreamClose(), ksnStreamCreate(), ksnTCPProxyClientConnect(), ksnTCPProxyServerClientConnect(), ksnTCPProxyServerClientDisconnect(), ksnTCPProxyServerStart(), ksnTRUDPsendto(), open_local_port(), sendCmdAnswerToBinaryA(), sendCmdT(), sigusr2_cb(), stream_out_cb(), teo_recvfrom(), teo_sendto(), teoBroadcastSend(), teoLNullPacketCheckMiscrypted(), teoLogReaderOpenCbPP(), teoMetricInit(), teoSScrSend(), teoSScrSendA(), teoSScrSubscribeA(), teoSScrSubscription(), teoSScrUnSubscription(), timer_cb(), and trudp_event_cb().
#define ksn_puts | ( | ke, | |
module, | |||
type, | |||
format | |||
) |
Referenced by event_cb(), ksnetEvMgrRun(), ksnReconnectInit(), ksnSplitCombine(), main(), sig_async_cb(), sigint_cb(), stdin_cb(), teoAsyncDestroy(), teoAsyncInit(), teoAsyncTest(), teoLoggingClientDestroy(), teoLoggingClientInit(), teoLoggingServerDestroy(), teoLoggingServerInit(), teoLogReaderDestroy(), teoLogReaderInit(), teoWSInit(), and trudp_event_cb().
typedef struct addr_port addr_port_t |
typedef enum ksnet_printf_type ksnet_printf_type |
KSNet printf messages types.
enum ksnet_printf_type |
void addr_port_free | ( | addr_port_t * | ap_obj | ) |
References addr_port::addr, and free().
Referenced by find_arp_by_addr_cb(), ksnCoreProcessPacket(), ksnTRUDPsendto(), resolveDnsName(), teo_recvfrom(), teo_sendto(), and trudp_send_event_ack_to_app().
int calculate_lines | ( | char * | str | ) |
Calculate number of lines in string.
Calculate number of line with line feed \n at the end in null input terminated string
str | Input null terminated string |
Referenced by ksnetArpShow(), and ksnTRUDPstatShow().
void dump_bytes | ( | char * | buffer, |
int | buffer_len, | ||
uint8_t * | data, | ||
int | data_len | ||
) |
Referenced by ksnLNullPacketSend(), and teoLNullPacketCheckMiscrypted().
size_t get_num_of_tags | ( | char * | data, |
size_t | data_length | ||
) |
Calculate number of tags in json string.
data | |
data_length |
char* getDataPath | ( | void | ) |
Get path to teonet data folder.
References free(), KSN_BUFFER_SIZE, and ksnet_formatMessage().
Referenced by teo::Teonet::getPath(), ksnet_optRead(), ksnetEvMgrRun(), read_config(), teowebConfigRead(), and uconfigFileName().
ksnet_stringArr getIPs | ( | teonet_cfg * | conf | ) |
Get IPs.
Get IP address of this host
References ksnet_stringArrAdd(), ksnet_stringArrCreate(), and teonet_cfg::vpn_ip.
Referenced by createCmdConnectRPacketUdp(), and open_local_port().
char* getRandomHostName | ( | void | ) |
Get random host name.
Create random host name. Should be free after use.
References ksnet_formatMessage().
Referenced by set_defaults().
int inarray | ( | int | val, |
const int * | arr, | ||
int | size | ||
) |
Check if a value exist in a array.
val | Integer value |
arr | Integer array |
size | Array size |
int ip_is_private | ( | char * | ip | ) |
Detect if input IP address is private.
ip |
References ip_to_array().
Referenced by createCmdConnectRPacketUdp(), and open_local_port().
int ip_to_array | ( | char * | ip, |
uint8_t * | arr | ||
) |
Convert IP to bytes array.
ip | |
arr |
References free().
Referenced by ip_is_private(), and open_local_port().
unsigned char* ksn_base64_decode | ( | const char * | data, |
size_t | input_length, | ||
size_t * | output_length | ||
) |
Base64decode.
data | Input encoded data |
input_length | Input data length |
output_length | Output data length |
References build_decoding_table(), and malloc().
char* ksn_base64_encode | ( | const unsigned char * | data, |
size_t | input_length, | ||
size_t * | output_length | ||
) |
Base64 encode.
[in] | data | Input data |
[in] | input_length | Input data length |
[out] | output_length | Output data length |
References malloc().
|
inline |
Referenced by ksnet_printf().
|
inline |
Referenced by main().
char* ksnet_formatMessage | ( | const char * | fmt, |
... | |||
) |
Create formated message in new null terminated string.
fmt | Format string like in printf function |
... | Parameter |
References ksnet_vformatMessage().
Referenced by cmd_disconnected_cb(), event_cb(), teo::Teonet::formatMessage(), getDataPath(), getRandomHostName(), ksnet_optRead(), ksnetArpShowHeader(), ksnetArpShowLine(), ksnetArpShowStr(), ksnetEvMgrRestart(), ksnMultiShowListStr(), open_local_port(), read_config(), teowebConfigRead(), and uconfigFileName().
char* ksnet_getSysConfigDir | ( | void | ) |
Getting path to ksnet configuration folder.
Referenced by read_config(), teowebConfigRead(), and uconfigFileName().
int ksnet_printf | ( | teonet_cfg * | teo_cfg, |
int | type, | ||
const char * | format, | ||
... | |||
) |
KSNet printf.
Make format output to stdout. Instead of standard printf function this function has type parameter which define type of print. It should be used this function instead of standard printf function.
teo_cfg | Pointer to teonet_cfg |
type | MESSAGE – print always; CONNECT – print if connect show flag connect is set; DEBUG – print if debug show flag is set on; DEBUG_VV – print if debug extra show flag is set on; ERROR_M – print always. |
format | Format like in standard printf function |
... | Parameters |
References _ANSI_NONE, teonet_cfg::color_output_disable_f, CONNECT, data, DEBUG, DEBUG_VV, DEBUG_VVV, DISPLAY_M, ERROR_M, free(), teonet_cfg::ke, KSN_GET_TEST_MODE(), ksnet_vformatMessage(), ksnetEvMgrGetTime(), teonet_cfg::log_prefix, teonet_cfg::log_priority, MESSAGE, removeTEsc(), teonet_cfg::show_connect_f, teonet_cfg::show_debug_f, teonet_cfg::show_debug_vv_f, teonet_cfg::show_debug_vvv_f, teoFilterFlagCheck(), teoLogCheck(), teoLoggingClientSend(), and trimlf().
Referenced by event_cb(), ksnetArpShow(), main(), start_stop_daemon(), tcp_read_cb(), teoLogPuts(), and test2().
char* ksnet_sformatMessage | ( | char * | str_to_free, |
const char * | fmt, | ||
... | |||
) |
Create formated message in new null terminated string, and free str_to_free.
str_to_free | |
fmt | Format string like in printf function |
... | Parameter |
References free(), and ksnet_vformatMessage().
Referenced by event_cb(), ksnet_optRead(), ksnetArpShowHeader(), ksnetArpShowStr(), ksnMultiShowListStr(), and teoGetFullAppTypeFromHostInfo().
char* ksnet_vformatMessage | ( | const char * | fmt, |
va_list | ap | ||
) |
References free(), KSN_BUFFER_SM_SIZE, malloc(), and va_copy.
Referenced by ksnet_formatMessage(), ksnet_printf(), and ksnet_sformatMessage().
void* memdup | ( | const void * | d, |
size_t | s | ||
) |
Duplicate memory.
Allocate memory and copy selected value to it
d | Pointer to value to copy |
s | Length of value |
References malloc().
Referenced by event_cb(), and get_cb().
void printHexDump | ( | void * | addr, |
size_t | len | ||
) |
char* removeTEsc | ( | char * | str | ) |
void resolveDnsName | ( | teonet_cfg * | conf | ) |
References addr_port::addr, addr_port_free(), KSN_BUFFER_SM_SIZE, teonet_cfg::r_host_addr, teonet_cfg::r_host_addr_opt, and wrap_inet_ntop().
Referenced by connect_r_host_cb(), and ksnet_optRead().
int set_reuseaddr | ( | int | sd | ) |
Make socket reusable.
sd |
int teoLogPuts | ( | teonet_cfg * | teo_cfg, |
const char * | module, | ||
int | type, | ||
const char * | message | ||
) |
References _ANSI_GREEN, _ANSI_NONE, _ksn_printf_type_, teonet_cfg::app_name, and ksnet_printf().
char* trim | ( | char * | str | ) |
Remove trailing or leading space.
Remove trailing or leading space or tabulation characters in input null terminated string
str | Null terminated input string to remove trailing and leading spaces in |
char* trimlf | ( | char * | str | ) |
Remove trailing line feeds characters from null terminated string.
str |
Referenced by hotkeys_cb(), and ksnet_printf().
addr_port_t* wrap_inet_ntop | ( | const struct sockaddr * | sa | ) |
References wr__ntop().
Referenced by find_arp_by_addr_cb(), ksnCoreProcessPacket(), ksnTRUDPsendto(), resolveDnsName(), teo_recvfrom(), teo_sendto(), and trudp_send_event_ack_to_app().