💾 Archived View for gemini.thededem.de › lc19 › src › src › main.c captured on 2021-12-03 at 14:04:38.
-=-=-=-=-=-=-
/* Copyright 2020, 2021 Lukas Wedeking * * This file is part of LC19. * * LC19 is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * LC19 is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with LC19. If not, see <https://www.gnu.org/licenses/>. */ #include<assert.h> #include<locale.h> #include<stdio.h> #include<stdlib.h> #include<string.h> #include "../include/conf.h" #include "../include/srv.h" #include "../include/url.h" #include "../include/util.h" #ifndef DATA_DIR #define DATA_DIR "/var/gemini" #endif #ifndef FILE_CHUNK_SIZE #define FILE_CHUNK_SIZE 4096 /* 4 KB */ #endif #ifndef MIMEDB_FILE #define MIMEDB_FILE "/etc/mime.types" #endif #ifndef INPUT_SIZE #define INPUT_SIZE 1027 /* Maximum size of the URL plus cr lf 0 */ #endif enum Loglevel loglevel = LOGLEVEL_ERROR; struct Response response = {RESPONSESTATE_UNSET, 0, {0}, NULL, RESOURCETYPE_PLAIN}; struct Configuration configuration = {DATA_DIR, FILE_CHUNK_SIZE, MIMEDB_FILE}; int main(int argc, char *argv[]) { extern struct Response response; char buffer[INPUT_SIZE] = { 0x0 }; struct Url *url = NULL; setlocale(LC_ALL, ""); conf_init(argc, argv); fgets(buffer, INPUT_SIZE, stdin); url = url_create(buffer, INPUT_SIZE); assert(url != NULL); assert(url->port != NULL); assert(url->path != NULL); if (srv_response_url_error(url)) { goto cleanup; } srv_response_resource(url); cleanup: for (size_t i = 0; buffer[i] != 0x0 && i < INPUT_SIZE; i++) { if (buffer[i] == '\n') { buffer[i] = 'N'; } else if (buffer[i] == '\r') { buffer[i] = 'R'; } } log_msg(LOGLEVEL_INFO, "Request for %s: %d %s", buffer, response.status, response.meta); srv_response_flush(); url_destroy(url); return 0; }