/* The settings list (settings.c): what each user setting pic offers is, which
* values it allows, its default and when a change applies. get_settings,
* set_setting and pic settings read it; the terminal interface's panel and a
* phone draw from what get_settings returns. Values stay in
* ~/.pic/pic.sqlite (userdb.h); keys the list does not know pass unchecked. */
#ifndef PIC_SETTINGS_H
#define PIC_SETTINGS_H
#include <stddef.h>
/* A row's kind: one of a list, a whole number in a range, checked text, or a
* row whose value is chosen in a picker of its own (a model, a theme). */
typedef enum { PIC_SET_CHOICE, PIC_SET_NUMBER, PIC_SET_TEXT, PIC_SET_PICKER } pic_setting_kind;
/* When a change takes effect. */
typedef enum {
PIC_APPLY_NOW, /* the terminal interface applies it at once */
PIC_APPLY_REPLY_END, /* when the running reply ends */
PIC_APPLY_EXIT, /* when pic exits */
PIC_APPLY_NEXT_REQUEST, /* a request reads it when it starts */
PIC_APPLY_NEW_CONVERSATION,
PIC_APPLY_NEXT_USE /* the next time the command that reads it runs */
} pic_setting_applies;
#define PIC_SETTING_VALUES 8
typedef struct {
const char *id; /* the name: the key, or "compaction.reserveTokens" for a field */
const char *def; /* the default as stored text; "" when it is worked out (def_label says how) */
const char *key; /* the stored key ("compaction") */
const char *field; /* the field inside the key's JSON object, or NULL */
const char *group, *name;
pic_setting_kind kind;
const char *values[PIC_SETTING_VALUES]; /* PIC_SET_CHOICE, NULL-terminated */
const char *labels[PIC_SETTING_VALUES]; /* how each value is shown, or NULL: as stored */
long long min, max; /* PIC_SET_NUMBER */
const char *unit; /* PIC_SET_NUMBER: "tokens"; PIC_SET_TEXT: its check */
const char *def_label; /* how the default is shown, or NULL: def */
const char *description;
pic_setting_applies applies;
} pic_setting_def;
/* The list, in the order the panel shows it. */
size_t pic_settings_count(void);
const pic_setting_def *pic_settings_at(size_t i);
/* The row named ID (a key or a field's dotted name), or NULL. */
const pic_setting_def *pic_settings_find(const char *id);
/* The row for the stored KEY and the JSON PATH inside it ("$.enabled"), or NULL. */
const pic_setting_def *pic_settings_find_path(const char *key, const char *path);
/* "now", "when the reply ends", ... */
const char *pic_settings_applies_name(pic_setting_applies a);
/* "choice", "number", "text", "picker". */
const char *pic_settings_kind_name(pic_setting_kind k);
/* Whether VALUE (the text form: "16384", "true") is allowed for D: 0, or -1
* with ERR naming what is allowed. NULL (back to the default) is always
* allowed. */
int pic_settings_check(const pic_setting_def *d, const char *value, char *err, size_t errcap);
/* Whether a whole JSON object stored under KEY (pic settings compaction
* '{...}') holds allowed values for the fields the list knows: 0, or -1 with
* ERR. A key with no field rows passes. */
int pic_settings_check_object(const char *key, const char *json, char *err, size_t errcap);
/* The stored text of D (malloc'd; a field's value as text), or NULL when unset. */
char *pic_settings_stored(const pic_setting_def *d);
/* The value in effect: the stored one when allowed, else the default
* (malloc'd; "" for a worked-out default). *valid: 0 when a stored value is
* not allowed. */
char *pic_settings_effective(const pic_setting_def *d, int *valid);
/* Saves VALUE for D (NULL: back to the default) after the check: 0, or -1
* with ERR. A field is written inside its key's JSON object. */
int pic_settings_write(const pic_setting_def *d, const char *value, char *err, size_t errcap);
/* The user database's change counter as this process sees it: it moves when
* another connection commits (PRAGMA data_version), and on this process's
* own writes through pic_settings_write. -1 without a database. */
long long pic_settings_version(void);
/* 1 when URL is one pic may send to or show: https://, or http:// to this machine only
* (127.0.0.1, localhost, [::1]), and only printable ASCII (no control character, C1 included, no
* space). The setting artifactsUrl and /share's viewer link both pass through it. */
int pic_secure_url(const char *url);
#endif