xml.c revision bcf3295d2b0d87caefad2e73d221aac080d0c11e
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek This file is part of systemd.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek Copyright 2013 Lennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek systemd is free software; you can redistribute it and/or modify it
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek under the terms of the GNU Lesser General Public License as published by
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek the Free Software Foundation; either version 2.1 of the License, or
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek (at your option) any later version.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek systemd is distributed in the hope that it will be useful, but
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek WITHOUT ANY WARRANTY; without even the implied warranty of
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek Lesser General Public License for more details.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek You should have received a copy of the GNU Lesser General Public License
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek along with systemd; If not, see <http://www.gnu.org/licenses/>.
74df0fca09b3c31ed19e14ba80f996fdff772417Lennart Poetteringstatic void inc_lines(unsigned *line, const char *s, size_t n) {
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering const char *p = s;
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering const char *f;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering n -= (f - p) + 1;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek/* We don't actually do real XML here. We only read a simplistic
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering * subset, that is a bit less strict that XML and lacks all the more
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * complex features, like entities, or namespaces. However, we do
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * support some HTML5-like simplifications */
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poetteringint xml_tokenize(const char **p, char **name, void **state, unsigned *line) {
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering const char *c, *e, *b;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering /* More text... */
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering /* A comment */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (*b == '?') {
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering /* Processing instruction */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (*b == '!') {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (*b == '/') {
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering /* A closing tag */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek e = strpbrk(b, WHITESPACE "/>");
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering /* An attribute */
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering /* An empty tag */
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering *name = NULL; /* For empty tags we return a NULL name, the caller must be prepared for that */
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering if (*b != '>')
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (*c == '=') {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* Tag with a quoted value */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* Tag with a value without quotes */