111 lines
3.1 KiB
C
111 lines
3.1 KiB
C
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
* Copyright (c) Camden Dixie O'Brien
|
|
*/
|
|
|
|
#ifndef CONFIG_H
|
|
#define CONFIG_H
|
|
|
|
#include <stddef.h>
|
|
|
|
#define CONFIG_MAX_VALUE_SIZE 32U
|
|
|
|
/**
|
|
* Callback type for config updates
|
|
*/
|
|
typedef void (*ConfigCallback)(const char *value);
|
|
|
|
/**
|
|
* Initialize the configuration module.
|
|
*
|
|
* If there is a saved configuration, it will be loaded. Otherwise,
|
|
* the default configuration will be loaded and saved.
|
|
*/
|
|
void config_init(void);
|
|
|
|
/**
|
|
* Set the device's hostname.
|
|
*
|
|
* The argument should be a null-terminated string. If the maximum
|
|
* length is exceeded, the value will still be used, but will be
|
|
* truncated.
|
|
*/
|
|
void config_set_hostname(const char *hostname);
|
|
|
|
/**
|
|
* Write the device's hostname into the given buffer.
|
|
*
|
|
* The length of the hostname is returned. If the value's size exceeds
|
|
* the size of the buffer, nothing will be written to the buffer but
|
|
* the length is still returned.
|
|
*/
|
|
size_t config_get_hostname(char *buffer, size_t buffer_size);
|
|
|
|
/**
|
|
* Add a callback for hostname updates.
|
|
*
|
|
* The function specified in the argument will be invoked whenever a
|
|
* the hostname is updated, with the new value as its argument. The
|
|
* lifetime of the passed argument will be static, but the value may
|
|
* be modified once the callback returns.
|
|
*/
|
|
void config_add_hostname_callback(ConfigCallback callback);
|
|
|
|
/**
|
|
* Set the SSID of the WiFi network.
|
|
*
|
|
* The argument should be a null-terminated string. If the maximum
|
|
* length is exceeded, the value will still be used, but will be
|
|
* truncated.
|
|
*/
|
|
void config_set_ssid(const char *ssid);
|
|
|
|
/**
|
|
* Write the SSID of the WiFi network into the given buffer.
|
|
*
|
|
* The length of the SSID is returned. If the value's size exceeds
|
|
* the size of the buffer, nothing will be written to the buffer but
|
|
* the length is still returned.
|
|
*/
|
|
size_t config_get_ssid(char *buffer, size_t buffer_size);
|
|
|
|
/**
|
|
* Add a callback for SSID updates.
|
|
*
|
|
* The function specified in the argument will be invoked whenever a
|
|
* the ssid is updated, with the new value as its argument. The
|
|
* lifetime of the passed argument will be static, but the value may
|
|
* be modified once the callback returns.
|
|
*/
|
|
void config_add_ssid_callback(ConfigCallback callback);
|
|
|
|
/**
|
|
* Set the PSK for the WiFi network.
|
|
*
|
|
* The argument should be a null-terminated string. If the maximum
|
|
* length is exceeded, the value will still be used, but will be
|
|
* truncated.
|
|
*/
|
|
void config_set_psk(const char *psk);
|
|
|
|
/**
|
|
* Write the PSK for the WiFi network into the given buffer.
|
|
*
|
|
* The length of the psk is returned. If the value's size exceeds
|
|
* the size of the buffer, nothing will be written to the buffer but
|
|
* the length is still returned.
|
|
*/
|
|
size_t config_get_psk(char *buffer, size_t buffer_size);
|
|
|
|
/**
|
|
* Add a callback for PSK updates.
|
|
*
|
|
* The function specified in the argument will be invoked whenever a
|
|
* the psk is updated, with the new value as its argument. The
|
|
* lifetime of the passed argument will be static, but the value may
|
|
* be modified once the callback returns.
|
|
*/
|
|
void config_add_psk_callback(ConfigCallback callback);
|
|
|
|
#endif
|