xml.c revision bcf3295d2b0d87caefad2e73d221aac080d0c11e
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek/***
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek This file is part of systemd.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek Copyright 2013 Lennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
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
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
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/>.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek***/
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
24882e06c135584f16f31ba8a00fecde8b7f6fadLennart Poettering#include <string.h>
24882e06c135584f16f31ba8a00fecde8b7f6fadLennart Poettering
24882e06c135584f16f31ba8a00fecde8b7f6fadLennart Poettering#include "util.h"
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering#include "xml.h"
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poetteringenum {
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering STATE_NULL,
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering STATE_TEXT,
24882e06c135584f16f31ba8a00fecde8b7f6fadLennart Poettering STATE_TAG,
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering STATE_ATTRIBUTE,
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering};
74df0fca09b3c31ed19e14ba80f996fdff772417Lennart Poettering
74df0fca09b3c31ed19e14ba80f996fdff772417Lennart Poetteringstatic void inc_lines(unsigned *line, const char *s, size_t n) {
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering const char *p = s;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
b5efdb8af40ea759a1ea584c1bc44ecc81dd00ceLennart Poettering if (!line)
430f0182b72373145c839dbfe99d2382855cb8f8Lennart Poettering return;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek for (;;) {
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering const char *f;
0dec689b098cf62b948d43dc78bde859665056ecTom Gundersen
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering f = memchr(p, '\n', n);
33d52ab92f2f0bfd706e6f343d172618d1e03f3dLennart Poettering if (!f)
958b66ea16deddd794b3a52643bd44633e165eadLennart Poettering return;
f4f15635ec05293ffcc83a5b39f624bbabbd8fd0Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering n -= (f - p) + 1;
958b66ea16deddd794b3a52643bd44633e165eadLennart Poettering p = f + 1;
afc5dbf37fd2399d37976388d9dd9ab470ecf446Lennart Poettering (*line)++;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering }
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering}
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
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 */
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poetteringint xml_tokenize(const char **p, char **name, void **state, unsigned *line) {
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering const char *c, *e, *b;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering char *ret;
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering int t;
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering assert(p);
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering assert(*p);
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering assert(name);
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering assert(state);
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering t = PTR_TO_INT(*state);
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering c = *p;
8b43440b7ef4b81c69c31de7ff820dc07a780254Lennart Poettering
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering if (t == STATE_NULL) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (line)
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek *line = 1;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek t = STATE_TEXT;
26687bf8a907009dedcff79346860ed41511405eOleksii Shevchuk }
7f1ad696a273703789b624fe0b209fb63e953016Lennart Poettering
7f1ad696a273703789b624fe0b209fb63e953016Lennart Poettering for (;;) {
e150e82097211f09b911c7784a89ef9efed713caMichał Bartoszkiewicz if (*c == 0)
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return XML_END;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek switch (t) {
e22aa3d3284709234f086ebebc13a905a295b7a7Lennart Poettering
e22aa3d3284709234f086ebebc13a905a295b7a7Lennart Poettering case STATE_TEXT: {
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering int x;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering e = strchrnul(c, '<');
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering if (e > c) {
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering /* More text... */
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering ret = strndup(c, e - c);
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering if (!ret)
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering return -ENOMEM;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering inc_lines(line, c, e - c);
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
7fd1b19bc9e9f5574f2877936b8ac267c7706947Harald Hoyer *name = ret;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering *p = e;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering *state = INT_TO_PTR(STATE_TEXT);
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return XML_TEXT;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek }
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering assert(*e == '<');
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering b = c + 1;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (startswith(b, "!--")) {
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering /* A comment */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek e = strstr(b + 3, "-->");
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering if (!e)
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return -EINVAL;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering inc_lines(line, b, e + 3 - b);
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering c = e + 3;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek continue;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek }
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (*b == '?') {
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering /* Processing instruction */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek e = strstr(b + 1, "?>");
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering if (!e)
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return -EINVAL;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering inc_lines(line, b, e + 2 - b);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering c = e + 2;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek continue;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek }
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (*b == '!') {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* DTD */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering e = strchr(b + 1, '>');
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering if (!e)
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return -EINVAL;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek inc_lines(line, b, e + 1 - b);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek c = e + 1;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek continue;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek }
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (*b == '/') {
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering /* A closing tag */
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering x = XML_TAG_CLOSE;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering b++;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering } else
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering x = XML_TAG_OPEN;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek e = strpbrk(b, WHITESPACE "/>");
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering if (!e)
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering return -EINVAL;
348ced909724a1331b85d57aede80a102a00e428Zbigniew Jędrzejewski-Szmek
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering ret = strndup(b, e - b);
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering if (!ret)
348ced909724a1331b85d57aede80a102a00e428Zbigniew Jędrzejewski-Szmek return -ENOMEM;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering *name = ret;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering *p = e;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek *state = INT_TO_PTR(STATE_TAG);
670b110c3b59dfa335ac43065b2038400d1d04a9Zbigniew Jędrzejewski-Szmek
670b110c3b59dfa335ac43065b2038400d1d04a9Zbigniew Jędrzejewski-Szmek return x;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering }
670b110c3b59dfa335ac43065b2038400d1d04a9Zbigniew Jędrzejewski-Szmek
670b110c3b59dfa335ac43065b2038400d1d04a9Zbigniew Jędrzejewski-Szmek case STATE_TAG:
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
da2e288bbc4d8cebaa1d38a80f6eec8cde3e9cceLennart Poettering b = c + strspn(c, WHITESPACE);
da2e288bbc4d8cebaa1d38a80f6eec8cde3e9cceLennart Poettering if (*b == 0)
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering return -EINVAL;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
670b110c3b59dfa335ac43065b2038400d1d04a9Zbigniew Jędrzejewski-Szmek inc_lines(line, c, b - c);
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering e = b + strcspn(b, WHITESPACE "=/>");
670b110c3b59dfa335ac43065b2038400d1d04a9Zbigniew Jędrzejewski-Szmek if (e > b) {
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering /* An attribute */
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering ret = strndup(b, e - b);
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering if (!ret)
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering return -ENOMEM;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering *name = ret;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering *p = e;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering *state = INT_TO_PTR(STATE_ATTRIBUTE);
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering return XML_ATTRIBUTE_NAME;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering }
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering if (startswith(b, "/>")) {
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering /* An empty tag */
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering *name = NULL; /* For empty tags we return a NULL name, the caller must be prepared for that */
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering *p = b + 2;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering *state = INT_TO_PTR(STATE_TEXT);
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering return XML_TAG_CLOSE_EMPTY;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering }
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering if (*b != '>')
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering return -EINVAL;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
670b110c3b59dfa335ac43065b2038400d1d04a9Zbigniew Jędrzejewski-Szmek c = b + 1;
670b110c3b59dfa335ac43065b2038400d1d04a9Zbigniew Jędrzejewski-Szmek t = STATE_TEXT;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering continue;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek case STATE_ATTRIBUTE:
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (*c == '=') {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek c++;
0fb398316c6705dfc168733361650fdb6824896dLennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (*c == '\'' || *c == '\"') {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* Tag with a quoted value */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek e = strchr(c+1, *c);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (!e)
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return -EINVAL;
4608af4333d0f7f5f8e3bc632801b04ef07d246dLennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek inc_lines(line, c, e - c);
65089b82401cd395786a7987c470056ff3f01151Lennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek ret = strndup(c+1, e - c - 1);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (!ret)
34c10968cbe3b5591b3c0ce225b8694edd9709d0Lennart Poettering return -ENOMEM;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek *name = ret;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek *p = e + 1;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek *state = INT_TO_PTR(STATE_TAG);
56f64d95763a799ba4475daf44d8e9f72a1bd474Michal Schmidt
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return XML_ATTRIBUTE_VALUE;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek }
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* Tag with a value without quotes */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek b = strpbrk(c, WHITESPACE ">");
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (!b)
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek b = c;
56f64d95763a799ba4475daf44d8e9f72a1bd474Michal Schmidt
0fb398316c6705dfc168733361650fdb6824896dLennart Poettering ret = strndup(c, b - c);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (!ret)
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return -ENOMEM;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
23ad4dd8844c582929115a11ed2830a1371568d6Jan Alexander Steffens (heftig) *name = ret;
23ad4dd8844c582929115a11ed2830a1371568d6Jan Alexander Steffens (heftig) *p = b;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek *state = INT_TO_PTR(STATE_TAG);
709f6e46a35ec492b70eb92943d82a8d838ce918Michal Schmidt return XML_ATTRIBUTE_VALUE;
56f64d95763a799ba4475daf44d8e9f72a1bd474Michal Schmidt }
0fb398316c6705dfc168733361650fdb6824896dLennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek t = STATE_TAG;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek continue;
709f6e46a35ec492b70eb92943d82a8d838ce918Michal Schmidt }
709f6e46a35ec492b70eb92943d82a8d838ce918Michal Schmidt
709f6e46a35ec492b70eb92943d82a8d838ce918Michal Schmidt }
709f6e46a35ec492b70eb92943d82a8d838ce918Michal Schmidt
709f6e46a35ec492b70eb92943d82a8d838ce918Michal Schmidt assert_not_reached("Bad state");
709f6e46a35ec492b70eb92943d82a8d838ce918Michal Schmidt}
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek