💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Vgmi › files › 430c83d6d2e70719545d1f43064c4… captured on 2023-11-04 at 12:17:34. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-09-28)

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

Go Back

0 /* See LICENSE file for copyright and license details. */

1 #ifndef _GEMINI_H_

2 #define _GEMINI_H_

3

4 #define LTS 0

5 #define MAJOR "1"

6 #define MINOR "5"

7 #if LTS

8 #define VERSION MAJOR "." MINOR " LTS"

9 #else

10 #define VERSION MAJOR "." MINOR " (" __DATE__ " " __TIME__ ")"

11 #endif

12

13 #include <netdb.h>

14 #include <unistd.h>

15 #include <stddef.h>

16 #include <pthread.h>

17 #include <poll.h>

18 #include <netinet/in.h>

19 #include "memcheck.h"

20 #include "url.h"

21

22 #define GMI 9

23 #define P_FILE 7

24 #define MAX_META 1024

25 #define MAX_REDIRECT 5

26

27 #define MAX_TEXT_SIZE 4194304 // 4 MB

28 #define MAX_IMAGE_SIZE 33554432 // 32 MB

29

30 struct gmi_page {

31 char** links;

32 char title[64];

33 int title_cached;

34 int links_count;

35 char* data;

36 int data_len;

37 int code;

38 int lines;

39 char meta[MAX_META];

40 #ifdef TERMINAL_IMG_VIEWER

41 struct img {

42 int tried;

43 unsigned char* data;

44 int w;

45 int h;

46 int channels;

47 } img;

48 #endif

49 int no_header;

50 };

51

52 struct gmi_link {

53 char url[MAX_URL];

54 struct gmi_link* prev;

55 struct gmi_link* next;

56 int scroll;

57 struct gmi_page page;

58 int cached;

59 };

60

61 #define STATE_DONE 0

62 #define STATE_REQUESTED 1

63 #define STATE_DNS 2

64 #define STATE_CONNECTING 3

65 #define STATE_CONNECTED 4

66 #define STATE_RECV_HEADER 5

67 #define STATE_RECV_BODY 6

68 #define STATE_CANCEL 7

69 #define STATE_STARTED 8

70

71 struct gmi_tab {

72 struct gmi_tab* next;

73 struct gmi_tab* prev;

74 struct gmi_link* history;

75 struct gmi_page page;

76 int scroll;

77 int selected;

78 char selected_url[MAX_URL];

79 char url[MAX_URL];

80 char error[256];

81 int show_error;

82 int redirects;

83 char info[256];

84 struct search {

85 char entry[MAX_URL];

86 int cursor;

87 int count;

88 int scroll;

89 int pos[2];

90 } search;

91 int show_info;

92 // async

93 int pair[2];

94 struct request {

95 #ifdef __linux__

96 struct gaicb* gaicb_ptr;

97 int resolved;

98 #endif

99 pthread_t thread;

100 pthread_mutex_t mutex;

101 int loaded;

102 int socket;

103 struct tls* tls;

104 int state;

105 int ask;

106 char info[1024];

107 char action[128];

108 unsigned short port;

109 char host[256];

110 union {

111 struct sockaddr_in addr4;

112 struct sockaddr_in6 addr6;

113 } _addr;

114 struct sockaddr* addr;

115 int family;

116 char url[1024];

117 char meta[1024];

118 char* data;

119 int recv;

120 int download;

121 char error[1024];

122 } request;

123 struct thread {

124 pthread_t thread;

125 int started;

126 int pair[2];

127 char url[1024];

128 int add;

129 } thread;

130 pthread_mutex_t render_mutex;

131 };

132

133 struct gmi_client {

134 struct gmi_tab* tab;

135 struct pollfd* tabs_fds;

136 int tabs_count;

137 struct input {

138 char download[MAX_URL];

139 char label[MAX_URL];

140 char field[MAX_URL * 2];

141 int cursor;

142 int mode;

143 } input;

144 struct vim {

145 char counter[6];

146 int g;

147 } vim;

148 struct cert_cache {

149 char host[1024];

150 char* crt;

151 size_t crt_len;

152 char* key;

153 size_t key_len;

154 } *certs;

155 int certs_size;

156 char** bookmarks;

157 #ifndef DISABLE_XDG

158 int xdg;

159 #endif

160 int c256;

161 int shutdown;

162 };

163

164 extern struct gmi_client client;

165 int gmi_init();

166 int gmi_goto(struct gmi_tab* tab, int id);

167 int gmi_goto_new(struct gmi_tab* tab, int id);

168 int gmi_request(struct gmi_tab* tab, const char* url, int add);

169 void gmi_load(struct gmi_page* page);

170 int gmi_render(struct gmi_tab* tab);

171 void gmi_cleanforward(struct gmi_tab* tab);

172 int gmi_nextlink(struct gmi_tab* tab, char* url, char* link);

173 struct gmi_tab* gmi_newtab();

174 struct gmi_tab* gmi_newtab_url(const char* url);

175 int gmi_loadfile(struct gmi_tab* tab, char* path);

176 void gmi_addbookmark(struct gmi_tab* tab, char* url, char* title);

177 void gmi_newbookmarks();

178 int gmi_loadbookmarks();

179 int gmi_savebookmarks();

180 void gmi_addtohistory(struct gmi_tab* tab);

181 int gmi_removebookmark(int index);

182 void gmi_polling();

183 void gmi_gohome(struct gmi_tab* tab, int add);

184 void gmi_gettitle(struct gmi_page* page, const char* url);

185 void gmi_freepage(struct gmi_page* page);

186 void gmi_freetab(struct gmi_tab* tab);

187 void gmi_free();

188

189 void fatal();

190 int fatalI();

191 void* fatalP();

192

193 #include "img.h"

194

195 #define WHITE (client.c256?15:TB_WHITE)

196 #define BLACK (client.c256?16:TB_BLACK)

197 #define BLUE (client.c256?25:TB_BLUE)

198 #define RED (client.c256?9:TB_RED)

199 #define GREEN (client.c256?2:TB_GREEN)

200 #define CYAN (client.c256?14:TB_CYAN)

201 #define MAGENTA (client.c256?13:TB_MAGENTA)

202 #define YELLOW (client.c256?58:TB_YELLOW)

203 #define GREY (client.c256?252:TB_WHITE)

204 #define ORANGE (client.c256?172:ITALIC|TB_WHITE)

205 #define ITALIC (client.c256?0:TB_ITALIC)

206

207 #endif

208