| 1 |
/* |
| 2 |
* Copyright (c) 2021-2024 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 |
#include <stdarg.h> |
| 18 |
#include <stdio.h> |
| 19 |
#include <string.h> |
| 20 |
|
| 21 |
#include "detritus.h" |
| 22 |
|
| 23 |
#ifndef __GEMINI_H__ |
| 24 |
#define __GEMINI_H__ |
| 25 |
|
| 26 |
#define GEMINI_PORT 1965 |
| 27 |
|
| 28 |
extern struct request_handler gemini_handler; |
| 29 |
|
| 30 |
enum { |
| 31 |
REQ_STATE_NEGOTIATING = 1, |
| 32 |
REQ_STATE_SENDING_REQUEST, |
| 33 |
REQ_STATE_PARSING_RESPONSE |
| 34 |
}; |
| 35 |
|
| 36 |
enum { |
| 37 |
GEM_STATE_HEADER, |
| 38 |
GEM_STATE_GEMTEXT, |
| 39 |
GEM_STATE_REDIRECT, |
| 40 |
GEM_STATE_DOWNLOAD |
| 41 |
}; |
| 42 |
|
| 43 |
struct gemini_request { |
| 44 |
struct browser *browser; |
| 45 |
struct URI *uri; |
| 46 |
|
| 47 |
uint8_t tls_id; |
| 48 |
unsigned char tcp_buf[(4 * 1500) + 2048]; /* 4*MTU + tcp_input */ |
| 49 |
unsigned char tcp_input[2048]; |
| 50 |
size_t tcp_input_len; |
| 51 |
short state; |
| 52 |
|
| 53 |
TCPiopb tcp_iopb; |
| 54 |
StreamPtr tcp_stream; |
| 55 |
wdsEntry tcp_wds[2]; |
| 56 |
TCPStatusPB tcp_status_pb; |
| 57 |
bool tcp_done_reading; |
| 58 |
|
| 59 |
char message[1024 + 3]; |
| 60 |
size_t message_len; |
| 61 |
|
| 62 |
short gem_state; |
| 63 |
char response[1024]; |
| 64 |
size_t response_len; |
| 65 |
size_t total_response_len; |
| 66 |
|
| 67 |
char mime_type[64]; |
| 68 |
unsigned long style; |
| 69 |
}; |
| 70 |
|
| 71 |
struct URI * gemini_parse_uri(char *uristr); |
| 72 |
void * gemini_init_request(struct browser *browser, struct URI *uri); |
| 73 |
bool gemini_process_request(void *cookie); |
| 74 |
void gemini_free(void *cookie); |
| 75 |
|
| 76 |
#endif |