/* ***************************************************************************** * p7servtest/server.c -- p7servtest virtual server. * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey * * This file is part of p7utils. * p7utils 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 2.0 of the License, * or (at your option) any later version. * * p7utils 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 p7utils; if not, see . * ************************************************************************** */ #include "main.h" #include #include #include /* ************************************************************************** */ /* Server callbacks */ /* ************************************************************************** */ /** * directory_exists: * Check if a directory exists. * * @arg cookie the cookie. * @arg dirname the directory. * @arg devname the devname. * @return the error (0 if ok). */ static int directory_exists(void *cookie, const char *dirname) { (void)cookie; /* check directory name */ if (!strcmp(dirname, "oui")) return (0); else return (p7_error_notfound); } /* ************************************************************************** */ /* Server configuration */ /* ************************************************************************** */ /* the server information */ static p7_server_t server_information = { /* main calculator information */ .cpuid = "The CPU ID, wow!", .hwid = "TESTSERV", .product_id = "OMGOMGOMGOMGOMGO", /* system configuration */ .username = "Cow", /* preprogrammed ROM information */ .preprog_rom_wiped = 1, /* flash ROM and RAM information */ .flash_rom_capacity = 8 * 1024 * 1024, .ram_capacity = 256 * 1024, /* bootcode information */ .bootcode_wiped = 1, /* OS information */ .os_offset = 0x80000000, .os_size = 0x100000, .os_version = { .major = 2, .minor = 9, .rev = 2201 }, }; /* the server filesystems */ static p7_filesystem_t server_filesystems[] = { /* main filesystem: the flash */ { .name = "fls0", .directory_exists = directory_exists }, {NULL} }; /* ************************************************************************** */ /* Server functions */ /* ************************************************************************** */ /** * run_server: * Run the server! * * @arg in the input. * @arg out the output. */ int run_server(int in, int out) { /* make the stream */ p7_stream_t stream; int err = p7_sopen_streams(&stream, NULL, in, out); if (err) { fprintf(stderr, "Server stream initialization has encountered " "an error: %s\n", p7_strerror(err)); return (1); } /* make the handle */ p7_handle_t *handle = NULL; err = p7_sinit(&handle, 0, "server", &stream, NULL); if (err) { fprintf(stderr, "Server initialization has encountered an error: %s\n", p7_strerror(err)); return (1); } /* protect and serve */ p7_serve(handle, &server_information, server_filesystems); p7_exit(handle); return (0); }