/* * Copyright (c) 2024 joshua stein * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include "detritus.h" bool finger_accept_uri(struct URI *uri); bool finger_request_init(page_handle pageh); bool finger_process(page_handle pageh); struct page_handler finger_handler = { finger_accept_uri, finger_request_init, page_queue_output, page_consume_data, page_request_cleanup, finger_process, NULL, }; bool finger_accept_uri(struct URI *uri) { return (strcasecmp(uri->scheme, "finger") == 0); } bool finger_request_init(page_handle pageh) { struct page *page = *pageh; size_t path_len; char *output; size_t output_len; if (page->uri->port == 0) page->uri->port = FINGER_PORT; if (page->uri->path[0] == '\0' || (page->uri->path[0] == '/' && page->uri->path[1] == '\0')) path_len = 0; else path_len = strlen(page->uri->path + 1); output_len = path_len + 2; output = xmalloc(output_len + 1); if (output == NULL) { warn("Out of memory"); return false; } snprintf(output, output_len + 1, "%s\r\n", path_len ? page->uri->path + 1 : ""); page->request = request_connect(page->browser, page->uri->hostname, page->uri->port, false, 0); if (page->request == NULL) { xfree(&output); return false; } page->request->output_len = output_len; page->request->output = output; return true; } bool finger_process(page_handle pageh) { struct page *page = *pageh; long n; bool ret = true; if (page->content_pos == page->content_len) return PAGE_CAN_READ_MORE(page); if (page->content_pos == 0) browser_commit_to_loading_page(page->browser); page->browser->style = STYLE_PRE; return page_print_plaintext(pageh); }