Coverage report for bus/config-loader-expat.c.gcov
-: 0:Source:config-loader-expat.c
-: 0:Graph:config-loader-expat.gcno
-: 0:Data:config-loader-expat.gcda
-: 0:Runs:10112
-: 0:Programs:2
-: 1:/* -*- mode: C; c-file-style: "gnu" -*- */
-: 2:/* config-loader-expat.c expat XML loader
-: 3: *
-: 4: * Copyright (C) 2003 Red Hat, Inc.
-: 5: *
-: 6: * Licensed under the Academic Free License version 2.1
-: 7: *
-: 8: * This program is free software; you can redistribute it and/or modify
-: 9: * it under the terms of the GNU General Public License as published by
-: 10: * the Free Software Foundation; either version 2 of the License, or
-: 11: * (at your option) any later version.
-: 12: *
-: 13: * This program is distributed in the hope that it will be useful,
-: 14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
-: 15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-: 16: * GNU General Public License for more details.
-: 17: *
-: 18: * You should have received a copy of the GNU General Public License
-: 19: * along with this program; if not, write to the Free Software
-: 20: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-: 21: *
-: 22: */
-: 23:
-: 24:#include "config-parser.h"
-: 25:#include <dbus/dbus-internals.h>
-: 26:#include <expat.h>
-: 27:
-: 28:static XML_Memory_Handling_Suite memsuite =
-: 29:{
-: 30: dbus_malloc,
-: 31: dbus_realloc,
-: 32: dbus_free
-: 33:};
-: 34:
-: 35:typedef struct
-: 36:{
-: 37: BusConfigParser *parser;
-: 38: const char *filename;
-: 39: DBusString content;
-: 40: DBusError *error;
-: 41: dbus_bool_t failed;
-: 42:} ExpatParseContext;
-: 43:
-: 44:static dbus_bool_t
-: 45:process_content (ExpatParseContext *context)
function process_content called 610 returned 100% blocks executed 100%
610: 46:{
610: 47: if (context->failed)
branch 0 taken 8% (fallthrough)
branch 1 taken 92%
50: 48: return FALSE;
-: 49:
560: 50: if (_dbus_string_get_length (&context->content) > 0)
call 0 returned 100%
branch 1 taken 81% (fallthrough)
branch 2 taken 19%
-: 51: {
452: 52: if (!bus_config_parser_content (context->parser,
call 0 returned 100%
branch 1 taken 4% (fallthrough)
branch 2 taken 96%
-: 53: &context->content,
-: 54: context->error))
-: 55: {
18: 56: context->failed = TRUE;
18: 57: return FALSE;
-: 58: }
434: 59: _dbus_string_set_length (&context->content, 0);
call 0 returned 100%
-: 60: }
-: 61:
542: 62: return TRUE;
-: 63:}
-: 64:
-: 65:static void
-: 66:expat_StartElementHandler (void *userData,
-: 67: const XML_Char *name,
-: 68: const XML_Char **atts)
function expat_StartElementHandler called 323 returned 100% blocks executed 72%
323: 69:{
323: 70: ExpatParseContext *context = userData;
-: 71: int i;
-: 72: char **names;
-: 73: char **values;
-: 74:
-: 75: /* Expat seems to suck and can't abort the parse if we
-: 76: * throw an error. Expat 2.0 is supposed to fix this.
-: 77: */
323: 78: if (context->failed)
branch 0 taken 10% (fallthrough)
branch 1 taken 90%
33: 79: return;
-: 80:
290: 81: if (!process_content (context))
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
#####: 82: return;
-: 83:
-: 84: /* "atts" is key, value, key, value, NULL */
290: 85: for (i = 0; atts[i] != NULL; ++i)
branch 0 taken 52%
branch 1 taken 48% (fallthrough)
-: 86: ; /* nothing */
-: 87:
290: 88: _dbus_assert (i % 2 == 0);
call 0 returned 100%
290: 89: names = dbus_new0 (char *, i / 2 + 1);
call 0 returned 100%
290: 90: values = dbus_new0 (char *, i / 2 + 1);
call 0 returned 100%
-: 91:
290: 92: if (names == NULL || values == NULL)
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
branch 2 taken 0% (fallthrough)
branch 3 taken 100%
-: 93: {
#####: 94: dbus_set_error (context->error, DBUS_ERROR_NO_MEMORY, NULL);
call 0 never executed
#####: 95: context->failed = TRUE;
#####: 96: dbus_free (names);
call 0 never executed
#####: 97: dbus_free (values);
call 0 never executed
#####: 98: return;
-: 99: }
-: 100:
290: 101: i = 0;
737: 102: while (atts[i] != NULL)
branch 0 taken 35%
branch 1 taken 65% (fallthrough)
-: 103: {
157: 104: _dbus_assert (i % 2 == 0);
call 0 returned 100%
157: 105: names [i / 2] = (char*) atts[i];
157: 106: values[i / 2] = (char*) atts[i+1];
-: 107:
157: 108: i += 2;
-: 109: }
-: 110:
290: 111: if (!bus_config_parser_start_element (context->parser,
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 112: name,
-: 113: (const char **) names,
-: 114: (const char **) values,
-: 115: context->error))
-: 116: {
#####: 117: dbus_free (names);
call 0 never executed
#####: 118: dbus_free (values);
call 0 never executed
#####: 119: context->failed = TRUE;
#####: 120: return;
-: 121: }
-: 122:
290: 123: dbus_free (names);
call 0 returned 100%
290: 124: dbus_free (values);
call 0 returned 100%
-: 125:}
-: 126:
-: 127:static void
-: 128:expat_EndElementHandler (void *userData,
-: 129: const XML_Char *name)
function expat_EndElementHandler called 320 returned 100% blocks executed 86%
320: 130:{
320: 131: ExpatParseContext *context = userData;
-: 132:
320: 133: if (!process_content (context))
call 0 returned 100%
branch 1 taken 21% (fallthrough)
branch 2 taken 79%
68: 134: return;
-: 135:
252: 136: if (!bus_config_parser_end_element (context->parser,
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 137: name,
-: 138: context->error))
-: 139: {
#####: 140: context->failed = TRUE;
#####: 141: return;
-: 142: }
-: 143:}
-: 144:
-: 145:/* s is not 0 terminated. */
-: 146:static void
-: 147:expat_CharacterDataHandler (void *userData,
-: 148: const XML_Char *s,
-: 149: int len)
function expat_CharacterDataHandler called 960 returned 100% blocks executed 71%
960: 150:{
960: 151: ExpatParseContext *context = userData;
960: 152: if (context->failed)
branch 0 taken 12% (fallthrough)
branch 1 taken 88%
118: 153: return;
-: 154:
842: 155: if (!_dbus_string_append_len (&context->content,
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 156: s, len))
-: 157: {
#####: 158: dbus_set_error (context->error, DBUS_ERROR_NO_MEMORY, NULL);
call 0 never executed
#####: 159: context->failed = TRUE;
#####: 160: return;
-: 161: }
-: 162:}
-: 163:
-: 164:
-: 165:BusConfigParser*
-: 166:bus_config_load (const DBusString *file,
-: 167: dbus_bool_t is_toplevel,
-: 168: const BusConfigParser *parent,
-: 169: DBusError *error)
function bus_config_load called 45 returned 100% blocks executed 79%
45: 170:{
-: 171: XML_Parser expat;
-: 172: const char *filename;
-: 173: BusConfigParser *parser;
-: 174: ExpatParseContext context;
-: 175: DBusString dirname;
-: 176:
45: 177: _DBUS_ASSERT_ERROR_IS_CLEAR (error);
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
call 2 returned 100%
branch 3 taken 100% (fallthrough)
branch 4 taken 0%
call 5 returned 100%
-: 178:
45: 179: parser = NULL;
45: 180: expat = NULL;
45: 181: context.error = error;
45: 182: context.failed = FALSE;
-: 183:
45: 184: filename = _dbus_string_get_const_data (file);
call 0 returned 100%
-: 185:
45: 186: if (!_dbus_string_init (&context.content))
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 187: {
#####: 188: dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call 0 never executed
#####: 189: return NULL;
-: 190: }
-: 191:
45: 192: if (!_dbus_string_init (&dirname))
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 193: {
#####: 194: dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call 0 never executed
#####: 195: _dbus_string_free (&context.content);
call 0 never executed
#####: 196: return NULL;
-: 197: }
-: 198:
45: 199: expat = XML_ParserCreate_MM ("UTF-8", &memsuite, NULL);
call 0 returned 100%
45: 200: if (expat == NULL)
branch 0 taken 0% (fallthrough)
branch 1 taken 100%
-: 201: {
#####: 202: dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call 0 never executed
#####: 203: goto failed;
-: 204: }
-: 205:
45: 206: if (!_dbus_string_get_dirname (file, &dirname))
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 207: {
#####: 208: dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call 0 never executed
#####: 209: goto failed;
-: 210: }
-: 211:
45: 212: parser = bus_config_parser_new (&dirname, is_toplevel, parent);
call 0 returned 100%
45: 213: if (parser == NULL)
branch 0 taken 0% (fallthrough)
branch 1 taken 100%
-: 214: {
#####: 215: dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call 0 never executed
#####: 216: goto failed;
-: 217: }
45: 218: context.parser = parser;
-: 219:
45: 220: XML_SetUserData (expat, &context);
call 0 returned 100%
45: 221: XML_SetElementHandler (expat,
call 0 returned 100%
-: 222: expat_StartElementHandler,
-: 223: expat_EndElementHandler);
45: 224: XML_SetCharacterDataHandler (expat,
call 0 returned 100%
-: 225: expat_CharacterDataHandler);
-: 226:
-: 227: {
-: 228: DBusString data;
-: 229: const char *data_str;
-: 230:
45: 231: if (!_dbus_string_init (&data))
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 232: {
#####: 233: dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call 0 never executed
#####: 234: goto failed;
-: 235: }
-: 236:
45: 237: if (!_dbus_file_get_contents (&data, file, error))
call 0 returned 100%
branch 1 taken 20% (fallthrough)
branch 2 taken 80%
-: 238: {
9: 239: _dbus_string_free (&data);
call 0 returned 100%
9: 240: goto failed;
-: 241: }
-: 242:
36: 243: data_str = _dbus_string_get_const_data (&data);
call 0 returned 100%
-: 244:
36: 245: if (!XML_Parse (expat, data_str, _dbus_string_get_length (&data), TRUE))
call 0 returned 100%
call 1 returned 100%
branch 2 taken 6% (fallthrough)
branch 3 taken 94%
-: 246: {
2: 247: if (context.error != NULL &&
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
call 2 returned 100%
branch 3 taken 50% (fallthrough)
branch 4 taken 50%
-: 248: !dbus_error_is_set (context.error))
-: 249: {
-: 250: enum XML_Error e;
-: 251:
1: 252: e = XML_GetErrorCode (expat);
call 0 returned 100%
1: 253: if (e == XML_ERROR_NO_MEMORY)
branch 0 taken 0% (fallthrough)
branch 1 taken 100%
#####: 254: dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call 0 never executed
-: 255: else
1: 256: dbus_set_error (error, DBUS_ERROR_FAILED,
call 0 returned 100%
call 1 returned 100%
call 2 returned 100%
call 3 returned 100%
-: 257: "Error in file %s, line %d, column %d: %s\n",
-: 258: filename,
-: 259: XML_GetCurrentLineNumber (expat),
-: 260: XML_GetCurrentColumnNumber (expat),
-: 261: XML_ErrorString (e));
-: 262: }
-: 263:
2: 264: _dbus_string_free (&data);
call 0 returned 100%
2: 265: goto failed;
-: 266: }
-: 267:
34: 268: _dbus_string_free (&data);
call 0 returned 100%
-: 269:
34: 270: if (context.failed)
branch 0 taken 50% (fallthrough)
branch 1 taken 50%
17: 271: goto failed;
-: 272: }
-: 273:
17: 274: if (!bus_config_parser_finished (parser, error))
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
#####: 275: goto failed;
-: 276:
17: 277: _dbus_string_free (&dirname);
call 0 returned 100%
17: 278: _dbus_string_free (&context.content);
call 0 returned 100%
17: 279: XML_ParserFree (expat);
call 0 returned 100%
-: 280:
17: 281: _DBUS_ASSERT_ERROR_IS_CLEAR (error);
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
call 2 returned 100%
branch 3 taken 100% (fallthrough)
branch 4 taken 0%
call 5 returned 100%
17: 282: return parser;
-: 283:
28: 284: failed:
28: 285: _DBUS_ASSERT_ERROR_IS_SET (error);
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
call 2 returned 100%
branch 3 taken 100% (fallthrough)
branch 4 taken 0%
call 5 returned 100%
-: 286:
28: 287: _dbus_string_free (&dirname);
call 0 returned 100%
28: 288: _dbus_string_free (&context.content);
call 0 returned 100%
28: 289: if (expat)
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
28: 290: XML_ParserFree (expat);
call 0 returned 100%
28: 291: if (parser)
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
28: 292: bus_config_parser_unref (parser);
call 0 returned 100%
28: 293: return NULL;
-: 294:}