f5c2cf2b22273580fabed3f7ec63e719f27b6e8a
[sim/o1-interface.git] / ntsimulator / ntsim-ng / utils / sys_utils.h
1 /*************************************************************************
2 *
3 * Copyright 2020 highstreet technologies GmbH and others
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 ***************************************************************************/
17
18 #pragma once
19
20 #include <stddef.h>
21 #include <stdint.h>
22 #include <stdbool.h>
23
24 #define STANDARD_NETCONF_PORT   830
25 #define STANDARD_FTP_PORT       21
26 #define STANDARD_SFTP_PORT      22
27
28 #define KS_KEY_NAME                                 "melacon_server_key"
29 #define SERVER_PUBLIC_SSH_KEY_PATH                  "/home/netconf/.ssh/melacon.server.key.pub"
30
31 //filesystem functions
32 bool dir_exists(const char *path);
33 bool file_exists(const char *fname);
34 void file_touch(const char *fname, const char *content);    //content can be null for just-touching
35 char *file_read_content(const char *fname);
36
37 int get_int_from_string_with_default(const char *string, int default_value);
38 char *get_current_date_and_time(void);
39 long int get_microseconds_since_epoch(void);
40
41 //networking functions
42 bool get_local_ips(const char *ifname, char **ipv4, char **ipv6);
43 bool check_port_open(const char *host, uint16_t port);
44
45 char *b64_encode(const uint8_t *data, size_t input_length);
46 uint8_t *b64_decode(const char *data, size_t input_length, size_t *output_length);
47 char *str_replace(const char *orig, const char *rep, const char *with);
48
49 char *read_key(const char *filename);
50
51 void vsftp_daemon_init(void);
52 void vsftp_daemon_deinit(void);
53 void sftp_daemon_init(void);
54 void sftp_daemon_deinit(void);