Add NETCONF CallHome via TLS feature.
[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 KS_CERT_NAME                                "melacon_server_cert"
30 #define SERVER_PUBLIC_SSH_KEY_PATH                  "/home/netconf/.ssh/melacon.server.key.pub"
31 #define SERVER_CERT_PATH                            "/home/netconf/.ssh/melacon.server.crt"
32
33 //filesystem functions
34 bool dir_exists(const char *path);
35 bool file_exists(const char *fname);
36 void file_touch(const char *fname, const char *content);    //content can be null for just-touching
37 char *file_read_content(const char *fname);
38
39 int get_int_from_string_with_default(const char *string, int default_value);
40 char *get_current_date_and_time(void);
41 long int get_microseconds_since_epoch(void);
42
43 //networking functions
44 bool get_local_ips(const char *ifname, char **ipv4, char **ipv6);
45 bool check_port_open(const char *host, uint16_t port);
46
47 char *b64_encode(const uint8_t *data, size_t input_length);
48 uint8_t *b64_decode(const char *data, size_t input_length, size_t *output_length);
49 char *str_replace(const char *orig, const char *rep, const char *with);
50
51 char *read_key(const char *filename);
52
53 void vsftp_daemon_init(void);
54 void vsftp_daemon_deinit(void);
55 void sftp_daemon_init(void);
56 void sftp_daemon_deinit(void);