cake
/
p7utils
Archived
1
0
Fork 0

Corrected p7servtest with new library interface.

This commit is contained in:
Thomas Touhey 2017-04-04 11:01:34 +02:00
parent 099db134de
commit 7c265e8bda
4 changed files with 46 additions and 18 deletions

View File

@ -37,9 +37,9 @@ int dump(p7_handle_t *handle)
/* Wiped out things */
if (info->preprog_rom_wiped)
log("Warning: Preprogrammed ROM information looks wiped out !\n");
log("Warning: Preprogrammed ROM information looks wiped out!\n");
if (info->bootcode_wiped)
log("Warning: Bootcode information looks wiped out !\n");
log("Warning: Bootcode information looks wiped out!\n");
if (info->os_wiped)
log("Warning: OS information looks wiped out!\n");
if (!info->username[0])

View File

@ -21,15 +21,25 @@
#include <libp7/packetio.h>
#include <libp7/stream.h>
void run_client(int in, int out)
int run_client(int in, int out)
{
/* make the stream */
p7_stream_t stream;
int err = p7_sopen_streams(&stream, NULL, in, out);
if (err) {
fprintf(stderr, "Client stream initialization has encountered "
"an error: %s\n", p7_strerror(err));
return (1);
}
/* make the handle */
p7_handle_t *handle = NULL; int err;
if ((err = p7_fdinit(&handle, P7_ACTIVE | P7_CHECK | P7_TERM, "client",
in, out, &p7_default_settings))) {
fprintf(stderr, "Client initialization encountered an error: %s\n",
p7_handle_t *handle = NULL;
err = p7_sinit(&handle, p7_flag_active | p7_flag_check | p7_flag_term,
"client", &stream, NULL);
if (err) {
fprintf(stderr, "Client initialization has encountered an error: %s\n",
p7_strerror(err));
return ;
return (1);
}
/* change working directory. */
@ -38,4 +48,5 @@ void run_client(int in, int out)
/* we're done. */
p7_exit(handle);
return (0);
}

View File

@ -19,10 +19,11 @@
#ifndef MAIN_H
# define MAIN_H
# include <stdio.h>
# include <libp7/streams.h>
int parse_args(int ac, char **av);
void run_server(int in, int out);
void run_client(int in, int out);
int run_server(int in, int out);
int run_client(int in, int out);
#endif /* MAIN_H */

View File

@ -28,12 +28,16 @@
* 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(const char *dirname)
static int directory_exists(void *cookie, const char *dirname)
{
(void)cookie;
/* check directory name */
if (!strcmp(dirname, "oui"))
return (0);
@ -90,16 +94,28 @@ static p7_filesystem_t server_filesystems[] = {
* @arg out the output.
*/
void run_server(int in, int out)
int run_server(int in, int out)
{
p7_handle_t *handle = NULL; int err;
if ((err = p7_fdinit(&handle, 0, "server", in, out,
&p7_default_settings))) {
fprintf(stderr, "Server encountered an error while initializing: %s\n",
p7_strerror(err));
return ;
/* 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);
}