Debian Codegraph @

src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/platform_linux.c

raw
1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4 #include "azure_c_shared_utility/platform.h"
5 #include "azure_c_shared_utility/xio.h"
6 #include "azure_c_shared_utility/xlogging.h"
7 #ifdef USE_HTTP
8 #include "azure_c_shared_utility/httpapiex.h"
9 #endif // USE_HTTP
10 #ifdef USE_OPENSSL
11 #include "azure_c_shared_utility/tlsio_openssl.h"
12 #else
13 const IO_INTERFACE_DESCRIPTION* tlsio_openssl_get_interface_description();
14 #endif
15 #if USE_CYCLONESSL
16 #include "azure_c_shared_utility/tlsio_cyclonessl.h"
17 #endif
18 #if USE_WOLFSSL
19 #include "azure_c_shared_utility/tlsio_wolfssl.h"
20 #endif
21 #if USE_MBEDTLS
22 #include "azure_c_shared_utility/tlsio_mbedtls.h"
23 #endif
24 #if USE_BEARSSL
25 #include "azure_c_shared_utility/tlsio_bearssl.h"
26 #endif
27
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <sys/utsname.h>
31
32 int platform_init(void)
33 {
34 int result = 0;
35 #ifdef USE_HTTP
36 #ifndef DONT_USE_UPLOADTOBLOB
37 if (HTTPAPIEX_Init() == HTTPAPIEX_ERROR)
38 {
39 LogError("HTTP for upload to blob failed on initialization.");
40 result = MU_FAILURE;
41 }
42 #endif /* DONT_USE_UPLOADTOBLOB */
43 #endif /* USE_HTTP */
44 #ifdef USE_OPENSSL
45 if (result == 0)
46 {
47 result = tlsio_openssl_init();
48 }
49 #elif USE_WOLFSSL
50 if (result == 0)
51 {
52 result = tlsio_wolfssl_init();
53 }
54 #endif
55 return result;
56 }
57
58 const IO_INTERFACE_DESCRIPTION* platform_get_default_tlsio(void)
59 {
60 #if USE_CYCLONESSL
61 return tlsio_cyclonessl_get_interface_description();
62 #elif USE_WOLFSSL
63 return tlsio_wolfssl_get_interface_description();
64 #elif USE_MBEDTLS
65 return tlsio_mbedtls_get_interface_description();
66 #elif USE_BEARSSL
67 return tlsio_bearssl_get_interface_description();
68 #else
69 // Default to openssl
70 return tlsio_openssl_get_interface_description();
71 #endif
72 }
73
74 STRING_HANDLE platform_get_platform_info(PLATFORM_INFO_OPTION options)
75 {
76 // No applicable options, so ignoring parameter
77 (void)options;
78
79 // Expected format: "(<runtime name>; <operating system name>; <platform>)"
80
81 STRING_HANDLE result;
82 struct utsname nnn;
83
84 if (uname(&nnn) == 0)
85 {
86 result = STRING_construct_sprintf("(native; %s; %s)", nnn.sysname, nnn.machine);
87 }
88 else
89 {
90 LogInfo("WARNING: failed to find machine info.");
91 result = STRING_construct("(native; Linux; undefined)");
92 }
93 return result;
94 }
95
96 void platform_deinit(void)
97 {
98 #ifdef USE_HTTP
99 #ifndef DONT_USE_UPLOADTOBLOB
100 HTTPAPIEX_Deinit();
101 #endif /* DONT_USE_UPLOADTOBLOB */
102 #endif /* USE_HTTP */
103
104 #ifdef USE_OPENSSL
105 tlsio_openssl_deinit();
106 #elif USE_WOLFSSL
107 tlsio_wolfssl_deinit();
108 #endif
109 }