supla-device
Loading...
Searching...
No Matches
tools.h
1/*
2 Copyright (C) AC SOFTWARE SP. Z O.O.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#ifndef ARDUINO
20
21#ifndef suplatools_H_
22#define suplatools_H_
23
24#include <stdlib.h>
25
26#include "proto.h"
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32typedef struct {
33 double h;
34 double s;
35 double v;
37
38#define BCRYPT_HASH_MAXSIZE 65
39
40extern unsigned char st_app_terminate;
41
42unsigned char st_file_exists(const char *fp);
43void st_hook_signals(void);
44void st_hook_critical_signals(void);
45char st_try_fork(void);
46char st_set_ug_id(int uid, int gid);
47char st_setpidfile(char *pidfile_path);
48void st_delpidfile(char *pidfile_path);
49void st_mainloop_init();
50void st_mainloop_wait(int usec);
51void st_mainloop_free();
52
53void st_guid2hex(char GUIDHEX[SUPLA_GUID_HEXSIZE],
54 const char GUID[SUPLA_GUID_SIZE]);
55void st_authkey2hex(char AuthKeyHEX[SUPLA_AUTHKEY_HEXSIZE],
56 const char AuthKey[SUPLA_AUTHKEY_SIZE]);
57
58char *st_str2hex(char *buffer, const char *str, size_t maxlen);
59char *st_bin2hex(char *buffer, const char *src, size_t len);
60
61char st_read_randkey_from_file(char *file, char *KEY, int size, char create);
62char st_read_guid_from_file(char *file, char *GUID, char create);
63char st_read_authkey_from_file(char *file, char *AuthKey, char create);
64
65time_t st_get_utc_time(void);
66
67char *st_get_zulu_time(char buffer[64]);
68char *st_get_datetime_str(char buffer[64]);
69
70_color_hsv_t st_rgb2hsv(int rgb);
71int st_hsv2rgb(_color_hsv_t in);
72int st_hue2rgb(double hue);
73
74void st_random_alpha_string(char *buffer, int buffer_size);
75void st_uuid_v4(char buffer[37]);
76
77#ifdef __BCRYPT
78
79char st_bcrypt_gensalt(char *salt, int salt_buffer_size, char rounds);
80char st_bcrypt_hash(const char *str, const char *salt, char *hash,
81 int hash_buffer_size);
82char st_bcrypt_crypt(char *str, char *hash, int hash_buffer_size, char rounds);
83char st_bcrypt_check(const char *str, char *hash, int hash_len);
84char *st_get_authkey_hash_hex(const char AuthKey[SUPLA_AUTHKEY_SIZE]);
85
86#endif
87
88unsigned _supla_int_t st_crc32_checksum(const unsigned char *data,
89 size_t length);
90
91#ifdef __OPENSSL_TOOLS
92char *st_openssl_base64_encode(const char *src, int src_len);
93char *st_openssl_base64_decode(const char *src, int src_len, int *dst_len);
94#endif
95
96#ifdef __cplusplus
97}
98#endif
99
100#endif /* suplatools_H_ */
101#endif /* !ARDUINO */
Definition tools.h:32