mirror of
				https://github.com/falk-werner/webfuse
				synced 2025-06-13 12:54:15 +00:00 
			
		
		
		
	makes wsfs_server_config opaque
This commit is contained in:
		
							parent
							
								
									40eafc19d7
								
							
						
					
					
						commit
						7dd3827555
					
				@ -12,7 +12,7 @@
 | 
			
		||||
 | 
			
		||||
struct args
 | 
			
		||||
{
 | 
			
		||||
	struct wsfs_server_config config;
 | 
			
		||||
	struct wsfs_server_config * config;
 | 
			
		||||
	bool show_help;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -53,6 +53,7 @@ static int parse_arguments(int argc, char * argv[], struct args * args)
 | 
			
		||||
 | 
			
		||||
	bool result = EXIT_SUCCESS;
 | 
			
		||||
	bool finished = false;
 | 
			
		||||
	bool has_mountpoint = false;
 | 
			
		||||
	while ((!finished) && (EXIT_SUCCESS == result))
 | 
			
		||||
	{
 | 
			
		||||
		int option_index = 0;
 | 
			
		||||
@ -68,27 +69,23 @@ static int parse_arguments(int argc, char * argv[], struct args * args)
 | 
			
		||||
				finished = true;
 | 
			
		||||
				break;
 | 
			
		||||
			case 'm':
 | 
			
		||||
				free(args->config.mount_point);
 | 
			
		||||
				args->config.mount_point = strdup(optarg);
 | 
			
		||||
				wsfs_server_config_set_mountpoint(args->config, optarg);
 | 
			
		||||
				has_mountpoint = true;
 | 
			
		||||
				break;
 | 
			
		||||
			case 'd':
 | 
			
		||||
				free(args->config.document_root);
 | 
			
		||||
				args->config.document_root = strdup(optarg);
 | 
			
		||||
				wsfs_server_config_set_documentroot(args->config, optarg);
 | 
			
		||||
				break;
 | 
			
		||||
			case 'c':
 | 
			
		||||
				free(args->config.cert_path);
 | 
			
		||||
				args->config.cert_path = strdup(optarg);
 | 
			
		||||
				wsfs_server_config_set_certpath(args->config, optarg);
 | 
			
		||||
				break;
 | 
			
		||||
			case 'k':
 | 
			
		||||
				free(args->config.key_path);
 | 
			
		||||
				args->config.key_path = strdup(optarg);
 | 
			
		||||
				wsfs_server_config_set_keypath(args->config, optarg);
 | 
			
		||||
				break;
 | 
			
		||||
			case 'n':
 | 
			
		||||
				free(args->config.vhost_name);
 | 
			
		||||
				args->config.vhost_name = strdup(optarg);
 | 
			
		||||
				wsfs_server_config_set_vhostname(args->config, optarg);
 | 
			
		||||
				break;
 | 
			
		||||
			case 'p':
 | 
			
		||||
				args->config.port = atoi(optarg);
 | 
			
		||||
				wsfs_server_config_set_port(args->config, atoi(optarg));
 | 
			
		||||
				break;
 | 
			
		||||
			default:
 | 
			
		||||
				fprintf(stderr, "error: unknown argument\n");
 | 
			
		||||
@ -99,7 +96,7 @@ static int parse_arguments(int argc, char * argv[], struct args * args)
 | 
			
		||||
 | 
			
		||||
	if ((EXIT_SUCCESS == result) && (!args->show_help))
 | 
			
		||||
	{
 | 
			
		||||
		if (NULL == args->config.mount_point)
 | 
			
		||||
		if (!has_mountpoint)
 | 
			
		||||
		{
 | 
			
		||||
			fprintf(stderr, "error: missing mount point\n");
 | 
			
		||||
			result = EXIT_FAILURE;
 | 
			
		||||
@ -123,26 +120,18 @@ static void on_interrupt(int signal_id)
 | 
			
		||||
 | 
			
		||||
int main(int argc, char * argv[])
 | 
			
		||||
{
 | 
			
		||||
	struct args args =
 | 
			
		||||
	{
 | 
			
		||||
		.config = 
 | 
			
		||||
		{
 | 
			
		||||
			.mount_point = NULL,
 | 
			
		||||
			.document_root = NULL,
 | 
			
		||||
			.cert_path = NULL,
 | 
			
		||||
			.key_path = NULL,
 | 
			
		||||
			.vhost_name = strdup("localhost"),
 | 
			
		||||
			.port = 8080,
 | 
			
		||||
		},
 | 
			
		||||
		.show_help = 0
 | 
			
		||||
	};
 | 
			
		||||
	struct args args;
 | 
			
		||||
	args.config = wsfs_server_config_create();
 | 
			
		||||
	wsfs_server_config_set_vhostname(args.config, "localhost");
 | 
			
		||||
	wsfs_server_config_set_port(args.config, 8080);
 | 
			
		||||
	args.show_help = false;
 | 
			
		||||
 | 
			
		||||
	int result = parse_arguments(argc, argv, &args);
 | 
			
		||||
	
 | 
			
		||||
	if (!args.show_help)
 | 
			
		||||
	{
 | 
			
		||||
		signal(SIGINT, on_interrupt);
 | 
			
		||||
		server = wsfs_server_create(&args.config);
 | 
			
		||||
		server = wsfs_server_create(args.config);
 | 
			
		||||
		if (NULL != server)
 | 
			
		||||
		{
 | 
			
		||||
			wsfs_server_run(server);
 | 
			
		||||
@ -159,7 +148,7 @@ int main(int argc, char * argv[])
 | 
			
		||||
		show_help();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	wsfs_server_config_cleanup(&args.config);
 | 
			
		||||
	wsfs_server_config_dispose(args.config);
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -3,30 +3,42 @@
 | 
			
		||||
 | 
			
		||||
#include "wsfs/adapter/api.h"
 | 
			
		||||
 | 
			
		||||
struct wsfs_server_config
 | 
			
		||||
{
 | 
			
		||||
    char * mount_point;
 | 
			
		||||
	char * document_root;
 | 
			
		||||
	char * key_path;
 | 
			
		||||
	char * cert_path;
 | 
			
		||||
	char * vhost_name;
 | 
			
		||||
	int port;
 | 
			
		||||
};
 | 
			
		||||
struct wsfs_server_config;
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C"
 | 
			
		||||
{
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
extern WSFSA_API void wsfs_server_config_init(
 | 
			
		||||
extern WSFSA_API struct wsfs_server_config * wsfs_server_config_create(void);
 | 
			
		||||
 | 
			
		||||
extern WSFSA_API void wsfs_server_config_dispose(
 | 
			
		||||
    struct wsfs_server_config * config);
 | 
			
		||||
 | 
			
		||||
extern WSFSA_API void wsfs_server_config_cleanup(
 | 
			
		||||
    struct wsfs_server_config * config);
 | 
			
		||||
 | 
			
		||||
extern WSFSA_API void wsfs_server_config_clone(
 | 
			
		||||
	struct wsfs_server_config * config,
 | 
			
		||||
	struct wsfs_server_config * clone);
 | 
			
		||||
extern WSFSA_API void wsfs_server_config_set_mountpoint(
 | 
			
		||||
    struct wsfs_server_config * config,
 | 
			
		||||
	char const * mount_point);
 | 
			
		||||
 | 
			
		||||
extern WSFSA_API void wsfs_server_config_set_documentroot(
 | 
			
		||||
    struct wsfs_server_config * config,
 | 
			
		||||
	char const * document_root);
 | 
			
		||||
 | 
			
		||||
extern WSFSA_API void wsfs_server_config_set_keypath(
 | 
			
		||||
    struct wsfs_server_config * config,
 | 
			
		||||
	char const * key_path);
 | 
			
		||||
 | 
			
		||||
extern WSFSA_API void wsfs_server_config_set_certpath(
 | 
			
		||||
    struct wsfs_server_config * config,
 | 
			
		||||
	char const * cert_path);
 | 
			
		||||
 | 
			
		||||
extern WSFSA_API void wsfs_server_config_set_vhostname(
 | 
			
		||||
    struct wsfs_server_config * config,
 | 
			
		||||
	char const * vhost_name);
 | 
			
		||||
 | 
			
		||||
extern WSFSA_API void wsfs_server_config_set_port(
 | 
			
		||||
    struct wsfs_server_config * config,
 | 
			
		||||
	int port);
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -4,7 +4,7 @@
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include <libwebsockets.h>
 | 
			
		||||
 | 
			
		||||
#include "wsfs/adapter/server_config.h"
 | 
			
		||||
#include "wsfs/adapter/server_config_intern.h"
 | 
			
		||||
#include "wsfs/adapter/server_protocol_intern.h"
 | 
			
		||||
 | 
			
		||||
#define WSFS_DISABLE_LWS_LOG 0
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
#include "wsfs/adapter/server_config.h"
 | 
			
		||||
#include "wsfs/adapter/server_config_intern.h"
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
@ -43,3 +43,68 @@ void wsfs_server_config_clone(
 | 
			
		||||
	clone->vhost_name = wsfs_server_config_strdup(config->vhost_name);
 | 
			
		||||
	clone->port = config->port;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct wsfs_server_config * wsfs_server_config_create(void)
 | 
			
		||||
{
 | 
			
		||||
    struct wsfs_server_config * config = malloc(sizeof(struct wsfs_server_config));
 | 
			
		||||
    if (NULL != config)
 | 
			
		||||
    {
 | 
			
		||||
        wsfs_server_config_init(config);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return config;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wsfs_server_config_dispose(
 | 
			
		||||
    struct wsfs_server_config * config)
 | 
			
		||||
{
 | 
			
		||||
    wsfs_server_config_cleanup(config);
 | 
			
		||||
    free(config);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wsfs_server_config_set_mountpoint(
 | 
			
		||||
    struct wsfs_server_config * config,
 | 
			
		||||
	char const * mount_point)
 | 
			
		||||
{
 | 
			
		||||
    free(config->mount_point);
 | 
			
		||||
    config->mount_point = strdup(mount_point);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wsfs_server_config_set_documentroot(
 | 
			
		||||
    struct wsfs_server_config * config,
 | 
			
		||||
	char const * document_root)
 | 
			
		||||
{
 | 
			
		||||
    free(config->document_root);
 | 
			
		||||
    config->document_root = strdup(document_root);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wsfs_server_config_set_keypath(
 | 
			
		||||
    struct wsfs_server_config * config,
 | 
			
		||||
	char const * key_path)
 | 
			
		||||
{
 | 
			
		||||
    free(config->key_path);
 | 
			
		||||
    config->key_path = strdup(key_path);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wsfs_server_config_set_certpath(
 | 
			
		||||
    struct wsfs_server_config * config,
 | 
			
		||||
	char const * cert_path)
 | 
			
		||||
{
 | 
			
		||||
    free(config->cert_path);
 | 
			
		||||
    config->cert_path = strdup(cert_path);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wsfs_server_config_set_vhostname(
 | 
			
		||||
    struct wsfs_server_config * config,
 | 
			
		||||
	char const * vhost_name)
 | 
			
		||||
{
 | 
			
		||||
    free(config->vhost_name);
 | 
			
		||||
    config->vhost_name = strdup(vhost_name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wsfs_server_config_set_port(
 | 
			
		||||
    struct wsfs_server_config * config,
 | 
			
		||||
	int port)
 | 
			
		||||
{
 | 
			
		||||
    config->port = port;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										35
									
								
								lib/wsfs/adapter/server_config_intern.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								lib/wsfs/adapter/server_config_intern.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,35 @@
 | 
			
		||||
#ifndef WSFS_ADAPTER_SERVER_CONFIG_INTERN_H
 | 
			
		||||
#define WSFS_ADAPTER_SERVER_CONFIG_INTERN_H
 | 
			
		||||
 | 
			
		||||
#include "wsfs/adapter/server_config.h"
 | 
			
		||||
 | 
			
		||||
struct wsfs_server_config
 | 
			
		||||
{
 | 
			
		||||
    char * mount_point;
 | 
			
		||||
	char * document_root;
 | 
			
		||||
	char * key_path;
 | 
			
		||||
	char * cert_path;
 | 
			
		||||
	char * vhost_name;
 | 
			
		||||
	int port;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C"
 | 
			
		||||
{
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
extern void wsfs_server_config_init(
 | 
			
		||||
    struct wsfs_server_config * config);
 | 
			
		||||
 | 
			
		||||
extern void wsfs_server_config_cleanup(
 | 
			
		||||
    struct wsfs_server_config * config);
 | 
			
		||||
 | 
			
		||||
extern void wsfs_server_config_clone(
 | 
			
		||||
	struct wsfs_server_config * config,
 | 
			
		||||
	struct wsfs_server_config * clone);
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@ -13,12 +13,13 @@ TEST(server, create_dispose)
 | 
			
		||||
{
 | 
			
		||||
    mkdir("test", 0700);
 | 
			
		||||
 | 
			
		||||
    struct wsfs_server_config config = {strdup("test"), nullptr, nullptr, nullptr, nullptr, 0};
 | 
			
		||||
    struct wsfs_server * server = wsfs_server_create(&config);
 | 
			
		||||
    struct wsfs_server_config * config = wsfs_server_config_create();
 | 
			
		||||
    wsfs_server_config_set_mountpoint(config, "test");
 | 
			
		||||
    struct wsfs_server * server = wsfs_server_create(config);
 | 
			
		||||
    ASSERT_NE(nullptr, server);
 | 
			
		||||
 | 
			
		||||
    wsfs_server_dispose(server);
 | 
			
		||||
    wsfs_server_config_cleanup(&config);
 | 
			
		||||
    wsfs_server_config_dispose(config);
 | 
			
		||||
 | 
			
		||||
    rmdir("test");
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user