supla-device
Loading...
Searching...
No Matches
tools.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef ARDUINO
5
6#ifndef suplatools_H_
7#define suplatools_H_
8
9#include <stdlib.h>
10
11#include "proto.h"
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17typedef struct {
18 double h;
19 double s;
20 double v;
22
23#define BCRYPT_HASH_MAXSIZE 65
24
25extern unsigned char st_app_terminate;
26
27unsigned char st_file_exists(const char *fp);
28void st_hook_signals(void);
29void st_hook_critical_signals(void);
30char st_try_fork(void);
31char st_set_ug_id(const char *username, int uid, int gid);
32char st_setpidfile(char *pidfile_path);
33void st_delpidfile(char *pidfile_path);
34void st_mainloop_init();
35void st_mainloop_wait(int usec);
36void st_mainloop_free();
37
38void st_guid2hex(char GUIDHEX[SUPLA_GUID_HEXSIZE],
39 const char GUID[SUPLA_GUID_SIZE]);
40void st_authkey2hex(char AuthKeyHEX[SUPLA_AUTHKEY_HEXSIZE],
41 const char AuthKey[SUPLA_AUTHKEY_SIZE]);
42
43char *st_str2hex(char *buffer, const char *str, size_t maxlen);
44char *st_bin2hex(char *buffer, const char *src, size_t len);
45
46char st_read_randkey_from_file(char *file, char *KEY, int size, char create);
47char st_read_guid_from_file(char *file, char *GUID, char create);
48char st_read_authkey_from_file(char *file, char *AuthKey, char create);
49
50time_t st_get_utc_time(void);
51
52char *st_get_zulu_time(char buffer[64]);
53char *st_get_datetime_str(char buffer[64]);
54
55_color_hsv_t st_rgb2hsv(int rgb);
56int st_hsv2rgb(_color_hsv_t in);
57int st_hue2rgb(double hue);
58
59void st_random_alpha_string(char *buffer, int buffer_size);
60void st_uuid_v4(char buffer[37]);
61
62#ifdef __BCRYPT
63
64char st_bcrypt_gensalt(char *salt, int salt_buffer_size, char rounds);
65char st_bcrypt_hash(const char *str, const char *salt, char *hash,
66 int hash_buffer_size);
67char st_bcrypt_crypt(char *str, char *hash, int hash_buffer_size, char rounds);
68char st_bcrypt_check(const char *str, char *hash, int hash_len);
69char *st_get_authkey_hash_hex(const char AuthKey[SUPLA_AUTHKEY_SIZE]);
70int format_decimal_trunc(double x, int precision, int scale, char *out,
71 size_t outsz);
72#endif
73
74unsigned _supla_int_t st_crc32_checksum(const unsigned char *data,
75 size_t length);
76
77#ifdef __OPENSSL_TOOLS
78char *st_openssl_base64_encode(const char *src, int src_len);
79char *st_openssl_base64_decode(const char *src, int src_len, int *dst_len);
80#endif
81
82#ifdef __cplusplus
83}
84#endif
85
86#endif /* suplatools_H_ */
87#endif /* !ARDUINO */
Definition tools.h:17