💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Vgmi › files › d590c1623d62b94f95ea16fa6a02e… captured on 2024-02-05 at 09:56:47. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

Go Back

0 /*

1 * ISC License

2 * Copyright (c) 2023 RMF <rawmonk@firemail.cc>

3 */

4 #include <stdlib.h>

5 #include <stdio.h>

6 #include <errno.h>

7 #include <string.h>

8

9 #include <sys/types.h>

10 #include <sys/socket.h>

11 #include <netdb.h>

12 #include <tls.h>

13

14 #include "strlcpy.h"

15 #include "macro.h"

16 #include "error.h"

17

18 #define ERROR_MASK 0xFFFF

19

20 char error_tls[1024];

21

22 int error_string(int error, char *out, size_t len) {

23 const char *ptr;

24 switch (error & ERROR_MASK) {

25 case ERROR_MEMORY_FAILURE:

26 strlcpy(out, "Memory failure", len);

27 break;

28 case ERROR_ERRNO:

29 strlcpy(out, strerror(errno), len);

30 break;

31 case ERROR_UNKNOWN_PROTOCOL:

32 strlcpy(out, "Unknown protocol", len);

33 break;

34 case ERROR_UNSUPPORTED_PROTOCOL:

35 strlcpy(out, "Protocol not supported", len);

36 break;

37 case ERROR_UNKNOWN_HOST:

38 strlcpy(out, "Unknown host", len);

39 break;

40 case ERROR_TLS_FAILURE:

41 strlcpy(out, error_tls, len);

42 break;

43 case ERROR_GETADDRINFO:

44 ptr = gai_strerror(-((error & 0xFFFF0000) >> 16));

45 if (!errno) {

46 snprintf(out, len, "DNS: %s", ptr);

47 break;

48 }

49 snprintf(out, len, "DNS: %s (%s)", ptr, strerror(errno));

50 break;

51 case ERROR_INVALID_DATA:

52 strlcpy(out, "Invalid response", len);

53 break;

54 case ERROR_INVALID_ARGUMENT:

55 strlcpy(out, "Invalid argument", len);

56 break;

57 case ERROR_INVALID_METADATA:

58 strlcpy(out, "No metadata", len);

59 break;

60 case ERROR_INVALID_ADDRESS:

61 strlcpy(out, "Invalid address", len);

62 break;

63 case ERROR_INVALID_STATUS:

64 strlcpy(out, "Invalid status", len);

65 break;

66 case ERROR_NO_CRLN:

67 strlcpy(out, "Invalid response", len);

68 break;

69 case ERROR_TERMBOX_FAILURE:

70 strlcpy(out, "Failed initializing TUI mode", len);

71 break;

72 case ERROR_TOO_MANY_REDIRECT:

73 strlcpy(out, "Too many redirects", len);

74 break;

75 case ERROR_INVALID_URL:

76 strlcpy(out, "Invalid URL", len);

77 break;

78 case ERROR_CERTIFICATE_MISMATCH:

79 strlcpy(out, "The server certificate changed", len);

80 break;

81 case ERROR_STORAGE_ACCESS:

82 snprintf(out, len, "Failed to access disk storage (%s)",

83 strerror(errno));

84 break;

85 case ERROR_SANDBOX_FAILURE:

86 snprintf(out, len, "Failed to apply sandboxing (%s)",

87 strerror(errno));

88 break;

89 case ERROR_RESPONSE_TOO_LARGE:

90 strlcpy(out, "The server response is too large", len);

91 break;

92 case ERROR_XDG:

93 strlcpy(out, "Unable to open the link", len);

94 break;

95 default:

96 snprintf(out, len, "Unknown error (%d)", error);

97 return -1;

98 }

99 return 0;

100 }

101