Files
.github
AnyEvent-I3
contrib
debian
docs
etc
i3-config-wizard
i3-dump-log
i3-input
i3-msg
i3-nagbar
i3bar
include
i3
all.h
assignments.h
bindings.h
click.h
commands.h
commands_parser.h
con.h
config_directives.h
config_parser.h
configuration.h
data.h
display_version.h
drag.h
ewmh.h
fake_outputs.h
floating.h
handlers.h
i3-atoms_NET_SUPPORTED.xmacro.h
i3-atoms_rest.xmacro.h
i3.h
ipc.h
key_press.h
libi3.h
load_layout.h
log.h
main.h
manage.h
match.h
move.h
output.h
queue.h
randr.h
regex.h
render.h
resize.h
restore_layout.h
scratchpad.h
sd-daemon.h
shmlog.h
sighandler.h
startup.h
sync.h
tree.h
util.h
window.h
workspace.h
x.h
xcb.h
xcursor.h
xinerama.h
yajl_utils.h
libi3
man
meson
parser-specs
release-notes
share
src
testcases
travis
.clang-format
.dockerignore
.editorconfig
.gitignore
DEPENDS
I3_VERSION
LICENSE
PACKAGE-MAINTAINER
README.md
RELEASE-NOTES-4.20.1
generate-command-parser.pl
i3-dmenu-desktop
i3-migrate-config-to-v4
i3-save-tree
i3-sensible-editor
i3-sensible-pager
i3-sensible-terminal
logo.svg
meson.build
meson_options.txt
pseudo-doc.doxygen
release.sh
i3/include/load_layout.h
Michael Stapelberg c45c002bad validate JSON before loading
This commit also introduces slurp() which reads a file in its entirety. Using
this function instead of doing IO in the functions in load_layout.c again and
again makes the code cleaner (fixing at least two memory leaks) and avoids
re-reading the same file 3 times.

related to 
2017-09-13 17:41:05 +02:00

43 lines
1.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009 Michael Stapelberg and contributors (see also: LICENSE)
*
* load_layout.c: Restore (parts of) the layout, for example after an inplace
* restart.
*
*/
#pragma once
#include <config.h>
typedef enum {
// We could not determine the content of the JSON file. This typically
// means its unreadable or contains garbage.
JSON_CONTENT_UNKNOWN = 0,
// The JSON file contains a “normal” container, i.e. a container to be
// appended to an existing workspace (or split container!).
JSON_CONTENT_CON = 1,
// The JSON file contains a workspace container, which needs to be appended
// to the output (next to the other workspaces) with special care to avoid
// naming conflicts and ensuring that the workspace _has_ a name.
JSON_CONTENT_WORKSPACE = 2,
} json_content_t;
/* Parses the given JSON file until it encounters the first “type” property to
* determine whether the file contains workspaces or regular containers, which
* is important to know when deciding where (and how) to append the contents.
* */
json_content_t json_determine_content(const char *buf, const size_t len);
/**
* Returns true if the provided JSON could be parsed by yajl.
*
*/
bool json_validate(const char *buf, const size_t len);
void tree_append_json(Con *con, const char *buf, const size_t len, char **errormsg);