💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Vgmi › files › a9604b89dac7275799dd2bc3bac92… captured on 2023-07-22 at 16:43:39. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-05-24)

➡️ Next capture (2023-09-08)

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

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

26 #define MAX_TEXT_SIZE 4194304 // 4 MB

27 #define MAX_IMAGE_SIZE 33554432 // 32 MB

28

29 struct gmi_page {

30 char** links;

31 char title[64];

32 int title_cached;

33 int links_count;

34 char* data;

35 int data_len;

36 int code;

37 int lines;

38 char meta[MAX_META];

39 #ifdef TERMINAL_IMG_VIEWER

40 struct img {

41 int tried;

42 unsigned char* data;

43 int w;

44 int h;

45 int channels;

46 } img;

47 #endif

48 int no_header;

49 };

50

51 struct gmi_link {

52 char url[MAX_URL];

53 struct gmi_link* prev;

54 struct gmi_link* next;

55 int scroll;

56 struct gmi_page page;

57 int cached;

58 };

59

60 #define STATE_DONE 0

61 #define STATE_REQUESTED 1

62 #define STATE_DNS 2

63 #define STATE_CONNECTING 3

64 #define STATE_CONNECTED 4

65 #define STATE_RECV_HEADER 5

66 #define STATE_RECV_BODY 6

67 #define STATE_CANCEL 7

68 #define STATE_STARTED 8

69

70 struct gmi_tab {

71 struct gmi_tab* next;

72 struct gmi_tab* prev;

73 struct gmi_link* history;

74 struct gmi_page page;

75 int scroll;

76 int selected;

77 char selected_url[MAX_URL];

78 char url[MAX_URL];

79 char error[256];

80 int show_error;

81 char info[256];

82 struct search {

83 char entry[MAX_URL];

84 int cursor;

85 int count;

86 int scroll;

87 int pos[2];

88 } search;

89 int show_info;

90 // async

91 int pair[2];

92 struct request {

93 #ifdef __linux__

94 struct gaicb* gaicb_ptr;

95 int resolved;

96 #endif

97 pthread_t thread;

98 pthread_mutex_t mutex;

99 int loaded;

100 int socket;

101 struct tls* tls;

102 int state;

103 int ask;

104 char info[1024];

105 char action[128];

106 unsigned short port;

107 char host[256];

108 union {

109 struct sockaddr_in addr4;

110 struct sockaddr_in6 addr6;

111 } _addr;

112 struct sockaddr* addr;

113 int family;

114 char url[1024];

115 char meta[1024];

116 char* data;

117 int recv;

118 int download;

119 char error[1024];

120 } request;

121 struct thread {

122 pthread_t thread;

123 int started;

124 int pair[2];

125 char url[1024];

126 int add;

127 } thread;

128 pthread_mutex_t render_mutex;

129 };

130

131 struct gmi_client {

132 struct gmi_tab* tab;

133 struct pollfd* tabs_fds;

134 int tabs_count;

135 struct input {

136 char download[MAX_URL];

137 char label[MAX_URL];

138 char field[MAX_URL * 2];

139 int cursor;

140 int mode;

141 } input;

142 struct vim {

143 char counter[6];

144 int g;

145 } vim;

146 struct cert_cache {

147 char host[1024];

148 char* crt;

149 size_t crt_len;

150 char* key;

151 size_t key_len;

152 } *certs;

153 int certs_size;

154 char** bookmarks;

155 #ifndef DISABLE_XDG

156 int xdg;

157 #endif

158 int c256;

159 int shutdown;

160 };

161

162 extern struct gmi_client client;

163 int gmi_init();

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

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

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

167 void gmi_load(struct gmi_page* page);

168 int gmi_render(struct gmi_tab* tab);

169 void gmi_cleanforward(struct gmi_tab* tab);

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

171 struct gmi_tab* gmi_newtab();

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

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

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

175 void gmi_newbookmarks();

176 int gmi_loadbookmarks();

177 int gmi_savebookmarks();

178 void gmi_addtohistory(struct gmi_tab* tab);

179 int gmi_removebookmark(int index);

180 void gmi_polling();

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

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

183 void gmi_freepage(struct gmi_page* page);

184 void gmi_freetab(struct gmi_tab* tab);

185 void gmi_free();

186

187 void fatal();

188 int fatalI();

189 void* fatalP();

190

191 #include "img.h"

192

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

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

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

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

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

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

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

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

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

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

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

204

205 #endif

206