| 1 |
/* |
| 2 |
* Copyright (c) 2021-2022 joshua stein <jcs@jcs.org> |
| 3 |
* |
| 4 |
* Permission to use, copy, modify, and distribute this software for any |
| 5 |
* purpose with or without fee is hereby granted, provided that the above |
| 6 |
* copyright notice and this permission notice appear in all copies. |
| 7 |
* |
| 8 |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 |
*/ |
| 16 |
|
| 17 |
#ifndef __BROWSER_H__ |
| 18 |
#define __BROWSER_H__ |
| 19 |
|
| 20 |
#include <stdlib.h> |
| 21 |
#include "tcp.h" |
| 22 |
#include "util.h" |
| 23 |
|
| 24 |
enum { |
| 25 |
REQ_STATE_IDLE, |
| 26 |
REQ_STATE_CONNECTED, |
| 27 |
REQ_STATE_DISCONNECTED |
| 28 |
}; |
| 29 |
|
| 30 |
enum { |
| 31 |
GEM_STATE_HEADER, |
| 32 |
GEM_STATE_GEMTEXT, |
| 33 |
GEM_STATE_REDIRECT, |
| 34 |
GEM_STATE_DOWNLOAD |
| 35 |
}; |
| 36 |
|
| 37 |
#define STYLE_NONE 0 |
| 38 |
#define STYLE_BOLD (1UL << 0) |
| 39 |
#define STYLE_ITALIC (1UL << 1) |
| 40 |
#define STYLE_H1 (1UL << 2) |
| 41 |
#define STYLE_H2 (1UL << 3) |
| 42 |
#define STYLE_H3 (1UL << 4) |
| 43 |
#define STYLE_LINK (1UL << 5) |
| 44 |
#define STYLE_PRE (1UL << 6) |
| 45 |
#define STYLE_LIST (1UL << 7) |
| 46 |
#define STYLE_QUOTE (1UL << 8) |
| 47 |
|
| 48 |
struct client_link { |
| 49 |
char *link; |
| 50 |
char *title; |
| 51 |
unsigned short pos; |
| 52 |
unsigned short len; |
| 53 |
}; |
| 54 |
|
| 55 |
struct tcp_request { |
| 56 |
short tls_id; |
| 57 |
|
| 58 |
unsigned char tcp_buf[(4 * 1500) + 2048]; /* 4*MTU + tcp_input */ |
| 59 |
unsigned char tcp_input[2048]; |
| 60 |
size_t tcp_input_len; |
| 61 |
short state; |
| 62 |
|
| 63 |
char hostname[256]; |
| 64 |
ip_addr host_ip; |
| 65 |
unsigned short port; |
| 66 |
|
| 67 |
TCPiopb tcp_iopb; |
| 68 |
StreamPtr tcp_stream; |
| 69 |
wdsEntry tcp_wds[2]; |
| 70 |
TCPStatusPB tcp_status_pb; |
| 71 |
|
| 72 |
char uri[1024 + 2]; |
| 73 |
size_t uri_len; |
| 74 |
|
| 75 |
short gem_state; |
| 76 |
char input[1024]; |
| 77 |
size_t input_len; |
| 78 |
|
| 79 |
char mime_type[64]; |
| 80 |
unsigned long style; |
| 81 |
|
| 82 |
size_t links_count; |
| 83 |
size_t links_size; |
| 84 |
struct client_link *links; |
| 85 |
}; |
| 86 |
|
| 87 |
struct client { |
| 88 |
WindowPtr win; |
| 89 |
TEHandle uri_te; |
| 90 |
ControlHandle go_button; |
| 91 |
TEHandle output_te; |
| 92 |
ControlHandle output_te_scroller; |
| 93 |
Handle scrp_rec_h; |
| 94 |
#define CLIENT_SCRAP_ELEMENTS 20 |
| 95 |
TEHandle active_te; |
| 96 |
struct tcp_request *req; |
| 97 |
|
| 98 |
unsigned char scsi_buf[2048]; |
| 99 |
}; |
| 100 |
|
| 101 |
struct client * client_init(void); |
| 102 |
size_t client_print(struct client *client, const char *str, size_t len); |
| 103 |
void client_clear(struct client *client); |
| 104 |
|
| 105 |
#endif |