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

1 #ifndef _GEMINI_H_

2 #define _GEMINI_H_

3

4 #include <netdb.h>

5 #include <unistd.h>

6 #include <stddef.h>

7 #include <pthread.h>

8 #include <poll.h>

9 #include <netinet/in.h>

10 #include "memcheck.h"

11

12 #define GMI 9

13 #define P_FILE 7

14 #define MAX_URL 1024

15 #define MAX_META 1024

16

17 struct gmi_page {

18 char** links;

19 int links_count;

20 char* data;

21 int data_len;

22 int code;

23 int lines;

24 char meta[MAX_META];

25 struct img {

26 int tried;

27 unsigned char* data;

28 int w;

29 int h;

30 int channels;

31 } img;

32 };

33

34 struct gmi_link {

35 char url[MAX_URL];

36 struct gmi_link* prev;

37 struct gmi_link* next;

38 int scroll;

39 struct gmi_page page;

40 int cached;

41 };

42

43 #define STATE_DONE 0

44 #define STATE_REQUESTED 1

45 #define STATE_DNS 2

46 #define STATE_CONNECTING 3

47 #define STATE_CONNECTED 4

48 #define STATE_RECV_HEADER 5

49 #define STATE_RECV_BODY 6

50 #define STATE_CANCEL 7

51 #define STATE_STARTED 8

52

53 struct gmi_tab {

54 struct gmi_link* history;

55 struct gmi_page page;

56 int scroll;

57 int selected;

58 char selected_url[MAX_URL];

59 char url[MAX_URL];

60 char error[256];

61 int show_error;

62 char info[256];

63 struct search {

64 char entry[MAX_URL];

65 int cursor;

66 int count;

67 int scroll;

68 int pos[2];

69 } search;

70 int show_info;

71 // async

72 int pair[2];

73 struct request {

74 #ifdef __linux__

75 struct gaicb* gaicb_ptr;

76 int resolved;

77 #endif

78 pthread_t thread;

79 pthread_mutex_t mutex;

80 int loaded;

81 int socket;

82 struct tls* tls;

83 int state;

84 int ask;

85 char info[1024];

86 char action[128];

87 unsigned short port;

88 char host[256];

89 union {

90 struct sockaddr_in addr4;

91 struct sockaddr_in6 addr6;

92 } _addr;

93 struct sockaddr* addr;

94 int family;

95 char url[1024];

96 char meta[1024];

97 char* data;

98 int recv;

99 int download;

100 char error[1024];

101 } request;

102 struct thread {

103 pthread_t thread;

104 int started;

105 int pair[2];

106 char url[1024];

107 int add;

108 } thread;

109 pthread_mutex_t render_mutex;

110 };

111

112 struct gmi_client {

113 struct gmi_tab* tabs;

114 struct pollfd* tabs_fds;

115 int tabs_changed;

116 int tabs_count;

117 struct input {

118 char label[MAX_URL];

119 char field[MAX_URL * 2];

120 int cursor;

121 int mode;

122 } input;

123 struct vim {

124 char counter[6];

125 int g;

126 } vim;

127 struct cert_cache {

128 char host[1024];

129 char* crt;

130 size_t crt_len;

131 char* key;

132 size_t key_len;

133 } *certs;

134 int certs_size;

135 char** bookmarks;

136 int tab;

137 #ifndef DISABLE_XDG

138 int xdg;

139 #endif

140 int c256;

141 int shutdown;

142 };

143

144 extern struct gmi_client client;

145 int gmi_init();

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

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

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

149 void gmi_load(struct gmi_page* page);

150 int gmi_render(struct gmi_tab* tab);

151 int gmi_parseurl(const char* url, char* host, int host_len, char* urlbuf, int url_len, unsigned short* port);

152 void gmi_cleanforward(struct gmi_tab* tab);

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

154 struct gmi_tab* gmi_newtab();

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

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

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

158 void gmi_addtohistory(struct gmi_tab* tab);

159 int gmi_removebookmark(int index);

160 void gmi_polling();

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

162 void gmi_freepage(struct gmi_page* page);

163 void gmi_freetab(struct gmi_tab* tab);

164 void gmi_free();

165

166 void fatal();

167 int fatalI();

168 void* fatalP();

169

170 #include "img.h"

171 #ifdef TERMINAL_IMG_VIEWER

172 #undef TB_WHITE

173 #define TB_WHITE 15

174 #undef TB_BLACK

175 #define TB_BLACK 16

176 #undef TB_BLUE

177 #define TB_BLUE 4

178 #undef TB_RED

179 #define TB_RED 9

180 #undef TB_GREEN

181 #define TB_GREEN 2

182 #undef TB_CYAN

183 #define TB_CYAN 14

184 #undef TB_MAGENTA

185 #define TB_MAGENTA 13

186 #undef TB_ITALIC

187 #define TB_ITALIC 0

188 #endif

189

190 #endif

191