1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-message-builder.c Build messages from text files for testing (internal to D-BUS implementation)
4 * Copyright (C) 2003 Red Hat, Inc.
6 * Licensed under the Academic Free License version 1.2
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.
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.
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
25 #ifdef DBUS_BUILD_TESTS
27 #include "dbus-message-builder.h"
28 #include "dbus-hash.h"
29 #include "dbus-internals.h"
30 #include "dbus-marshal.h"
33 * @defgroup DBusMessageBuilder code for loading test message data
34 * @ingroup DBusInternals
35 * @brief code for loading up test data for unit tests
37 * The code in here is used for unit testing, it loads
38 * up message data from a description in a file.
46 int start; /**< Calculate length since here */
47 int length; /**< length to write */
48 int offset; /**< where to write it into the data */
49 int endian; /**< endianness to write with */
53 free_saved_length (void *data)
55 SavedLength *sl = data;
58 return; /* all hash free functions have to accept NULL */
60 _dbus_string_free (&sl->name);
65 ensure_saved_length (DBusHashTable *hash,
66 const DBusString *name)
71 s = _dbus_string_get_const_data (name);
73 sl = _dbus_hash_table_lookup_string (hash, s);
77 sl = dbus_new0 (SavedLength, 1);
79 if (!_dbus_string_init (&sl->name))
85 if (!_dbus_string_copy (name, 0, &sl->name, 0))
88 s = _dbus_string_get_const_data (&sl->name);
90 if (!_dbus_hash_table_insert_string (hash, (char*)s, sl))
101 free_saved_length (sl);
106 save_start (DBusHashTable *hash,
107 const DBusString *name,
112 sl = ensure_saved_length (hash, name);
116 else if (sl->start >= 0)
118 _dbus_warn ("Same START_LENGTH given twice\n");
128 save_length (DBusHashTable *hash,
129 const DBusString *name,
134 sl = ensure_saved_length (hash, name);
138 else if (sl->length >= 0)
140 _dbus_warn ("Same END_LENGTH given twice\n");
150 save_offset (DBusHashTable *hash,
151 const DBusString *name,
157 sl = ensure_saved_length (hash, name);
161 else if (sl->offset >= 0)
163 _dbus_warn ("Same LENGTH given twice\n");
175 /** Saves the segment to delete in order to unalign the next item */
176 #define SAVE_FOR_UNALIGN(str, boundary) \
177 int align_pad_start = _dbus_string_get_length (str); \
178 int align_pad_end = _DBUS_ALIGN_VALUE (align_pad_start, (boundary))
180 /** Deletes the alignment padding */
181 #define PERFORM_UNALIGN(str) \
184 _dbus_string_delete ((str), align_pad_start, \
185 align_pad_end - align_pad_start); \
191 append_quoted_string (DBusString *dest,
192 const DBusString *quoted,
196 dbus_bool_t in_quotes = FALSE;
199 /* FIXME: We might want to add escaping in case we want to put '
200 * characters in our strings.
204 while (i < _dbus_string_get_length (quoted))
208 b = _dbus_string_get_byte (quoted, i);
216 if (!_dbus_string_append_byte (dest, b))
224 else if (b == ' ' || b == '\n' || b == '\t')
225 break; /* end on whitespace if not quoted */
228 if (!_dbus_string_append_byte (dest, b))
239 if (!_dbus_string_append_byte (dest, '\0'))
245 append_saved_length (DBusString *dest,
246 DBusHashTable *length_hash,
247 const DBusString *name,
251 if (!save_offset (length_hash, name,
254 _dbus_warn ("failed to save offset to LENGTH\n");
258 if (!_dbus_marshal_uint32 (dest, endian,
261 _dbus_warn ("failed to append a length\n");
269 * Reads the given filename, which should be in "message description
270 * language" (look at some examples), and builds up the message data
271 * from it. The message data may be invalid, or valid.
273 * The parser isn't very strict, it's just a hack for test programs.
275 * The file format is:
277 * VALID_HEADER normal header; byte order, padding, header len, body len, serial
278 * BIG_ENDIAN switch to big endian
279 * LITTLE_ENDIAN switch to little endian
280 * OPPOSITE_ENDIAN switch to opposite endian
281 * ALIGN <N> aligns to the given value
282 * UNALIGN skips alignment for the next marshal
283 * BYTE <N> inserts the given integer in [0,255] or char in 'a' format
284 * START_LENGTH <name> marks the start of a length to measure
285 * END_LENGTH <name> records the length since START_LENGTH under the given name
286 * (or if no START_LENGTH, absolute length)
287 * LENGTH <name> inserts the saved length of the same name
288 * CHOP <N> chops last N bytes off the data
289 * FIELD_NAME <abcd> inserts 4-byte field name
290 * TYPE <typename> inserts a typecode byte
293 * Following commands insert aligned data unless
294 * preceded by "UNALIGN":
296 * INT32 <N> marshals an INT32
297 * UINT32 <N> marshals a UINT32
298 * INT64 <N> marshals an INT64
299 * UINT64 <N> marshals a UINT64
300 * DOUBLE <N> marshals a double
301 * STRING 'Foo' marshals a string
302 * BYTE_ARRAY { 'a', 3, 4, 5, 6} marshals a BYTE array
303 * BOOLEAN_ARRAY { false, true, false} marshals a BOOLEAN array
304 * INT32_ARRAY { 3, 4, 5, 6} marshals an INT32 array
305 * UINT32_ARRAY { 3, 4, 5, 6} marshals an UINT32 array
306 * DOUBLE_ARRAY { 1.0, 2.0, 3.0, 4.0} marshals a DOUBLE array
307 * STRING_ARRAY { "foo", "bar", "gazonk"} marshals a STRING array
310 * @todo add support for array types INT32_ARRAY { 3, 4, 5, 6 }
313 * @param dest the string to append the message data to
314 * @param filename the filename to load
315 * @returns #TRUE on success
318 _dbus_message_data_load (DBusString *dest,
319 const DBusString *filename)
327 DBusHashTable *length_hash;
334 if (!_dbus_string_init (&file))
337 if (!_dbus_string_init (&line))
339 _dbus_string_free (&file);
343 _dbus_verbose ("Loading %s\n", _dbus_string_get_const_data (filename));
345 dbus_error_init (&error);
346 if (!_dbus_file_get_contents (&file, filename, &error))
348 _dbus_warn ("Getting contents of %s failed: %s\n",
349 _dbus_string_get_const_data (filename), error.message);
350 dbus_error_free (&error);
354 length_hash = _dbus_hash_table_new (DBUS_HASH_STRING,
357 if (length_hash == NULL)
360 endian = DBUS_COMPILER_BYTE_ORDER;
364 while (_dbus_string_pop_line (&file, &line))
366 dbus_bool_t just_set_unalign;
368 just_set_unalign = FALSE;
371 _dbus_string_delete_leading_blanks (&line);
373 if (_dbus_string_get_length (&line) == 0)
378 else if (_dbus_string_starts_with_c_str (&line,
381 /* Ignore this comment */
384 else if (_dbus_string_starts_with_c_str (&line,
390 if (!_dbus_string_append_byte (dest, endian))
392 _dbus_warn ("could not append endianness\n");
399 if (!_dbus_string_append_byte (dest, '\0'))
401 _dbus_warn ("could not append nul pad\n");
407 _dbus_string_init_const (&name, "Header");
408 if (!append_saved_length (dest, length_hash,
409 &name, _dbus_string_get_length (dest),
413 _dbus_string_init_const (&name, "Body");
414 if (!append_saved_length (dest, length_hash,
415 &name, _dbus_string_get_length (dest),
420 if (!_dbus_marshal_int32 (dest, endian, 1))
422 _dbus_warn ("couldn't append client serial\n");
426 else if (_dbus_string_starts_with_c_str (&line,
429 endian = DBUS_BIG_ENDIAN;
431 else if (_dbus_string_starts_with_c_str (&line,
434 endian = DBUS_LITTLE_ENDIAN;
436 else if (_dbus_string_starts_with_c_str (&line,
439 if (endian == DBUS_BIG_ENDIAN)
440 endian = DBUS_LITTLE_ENDIAN;
442 endian = DBUS_BIG_ENDIAN;
444 else if (_dbus_string_starts_with_c_str (&line,
451 _dbus_string_delete_first_word (&line);
453 if (!_dbus_string_parse_int (&line, 0, &val, &end))
455 _dbus_warn ("Failed to parse integer\n");
461 _dbus_warn ("Aligning to %ld boundary is crack\n",
466 orig_len = _dbus_string_get_length (dest);
468 if (!_dbus_string_align_length (dest, val))
471 if (_dbus_string_parse_int (&line, end, &val, NULL))
473 /* If there's an optional second int argument,
474 * fill in align padding with that value
476 if (val < 0 || val > 255)
478 _dbus_warn ("can't fill align padding with %ld, must be a byte value\n", val);
483 while (end < _dbus_string_get_length (dest))
485 _dbus_string_set_byte (dest, end, val);
490 else if (_dbus_string_starts_with_c_str (&line, "UNALIGN"))
493 just_set_unalign = TRUE;
495 else if (_dbus_string_starts_with_c_str (&line, "CHOP"))
499 /* FIXME if you CHOP the offset for a LENGTH
500 * command, we segfault.
503 _dbus_string_delete_first_word (&line);
505 if (!_dbus_string_parse_int (&line, 0, &val, NULL))
507 _dbus_warn ("Failed to parse integer to chop\n");
511 if (val > _dbus_string_get_length (dest))
513 _dbus_warn ("Trying to chop %ld bytes but we only have %d\n",
515 _dbus_string_get_length (dest));
519 _dbus_string_shorten (dest, val);
521 else if (_dbus_string_starts_with_c_str (&line,
524 _dbus_string_delete_first_word (&line);
526 if (!save_start (length_hash, &line,
527 _dbus_string_get_length (dest)))
529 _dbus_warn ("failed to save length start\n");
533 else if (_dbus_string_starts_with_c_str (&line,
536 _dbus_string_delete_first_word (&line);
538 if (!save_length (length_hash, &line,
539 _dbus_string_get_length (dest)))
541 _dbus_warn ("failed to save length end\n");
545 else if (_dbus_string_starts_with_c_str (&line,
548 SAVE_FOR_UNALIGN (dest, 4);
550 _dbus_string_delete_first_word (&line);
552 if (!append_saved_length (dest, length_hash,
554 unalign ? align_pad_start : align_pad_end,
557 _dbus_warn ("failed to add LENGTH\n");
561 PERFORM_UNALIGN (dest);
563 else if (_dbus_string_starts_with_c_str (&line,
566 _dbus_string_delete_first_word (&line);
568 if (_dbus_string_get_length (&line) != 4)
570 _dbus_warn ("Field name must be four characters not \"%s\"\n",
571 _dbus_string_get_const_data (&line));
578 _dbus_string_align_length (dest, 4);
580 if (!_dbus_string_copy (&line, 0, dest,
581 _dbus_string_get_length (dest)))
584 else if (_dbus_string_starts_with_c_str (&line,
589 _dbus_string_delete_first_word (&line);
591 if (_dbus_string_starts_with_c_str (&line, "INVALID"))
592 code = DBUS_TYPE_INVALID;
593 else if (_dbus_string_starts_with_c_str (&line, "NIL"))
594 code = DBUS_TYPE_NIL;
595 else if (_dbus_string_starts_with_c_str (&line, "BYTE"))
596 code = DBUS_TYPE_BYTE;
597 else if (_dbus_string_starts_with_c_str (&line, "BOOLEAN"))
598 code = DBUS_TYPE_BOOLEAN;
599 else if (_dbus_string_starts_with_c_str (&line, "INT32"))
600 code = DBUS_TYPE_INT32;
601 else if (_dbus_string_starts_with_c_str (&line, "UINT32"))
602 code = DBUS_TYPE_UINT32;
603 else if (_dbus_string_starts_with_c_str (&line, "DOUBLE"))
604 code = DBUS_TYPE_DOUBLE;
605 else if (_dbus_string_starts_with_c_str (&line, "STRING"))
606 code = DBUS_TYPE_STRING;
607 else if (_dbus_string_starts_with_c_str (&line, "NAMED"))
608 code = DBUS_TYPE_NAMED;
609 else if (_dbus_string_starts_with_c_str (&line, "ARRAY"))
610 code = DBUS_TYPE_ARRAY;
611 else if (_dbus_string_starts_with_c_str (&line, "DICT"))
612 code = DBUS_TYPE_DICT;
615 _dbus_warn ("%s is not a valid type name\n", _dbus_string_get_const_data (&line));
619 if (!_dbus_string_append_byte (dest, code))
621 _dbus_warn ("could not append typecode byte\n");
625 else if (_dbus_string_starts_with_c_str (&line,
628 SAVE_FOR_UNALIGN (dest, 4);
629 int i, len, allocated;
630 unsigned char *values;
635 values = dbus_new (unsigned char, allocated);
638 _dbus_warn ("could not allocate memory for BYTE_ARRAY\n");
644 _dbus_string_delete_first_word (&line);
645 _dbus_string_skip_blank (&line, 0, &i);
646 b = _dbus_string_get_byte (&line, i++);
651 while (i < _dbus_string_get_length (&line))
653 _dbus_string_skip_blank (&line, i, &i);
655 if (_dbus_string_get_byte (&line, i) == '\'' &&
656 _dbus_string_get_length (&line) >= i + 4 &&
657 _dbus_string_get_byte (&line, i + 1) == '\\' &&
658 _dbus_string_get_byte (&line, i + 2) == '\'' &&
659 _dbus_string_get_byte (&line, i + 3) == '\'')
664 else if (_dbus_string_get_byte (&line, i) == '\'' &&
665 _dbus_string_get_length (&line) >= i + 3 &&
666 _dbus_string_get_byte (&line, i + 2) == '\'')
668 val = _dbus_string_get_byte (&line, i + 1);
673 if (!_dbus_string_parse_int (&line, i, &val, &i))
675 _dbus_warn ("Failed to parse integer for BYTE_ARRAY\n");
679 if (val < 0 || val > 255)
681 _dbus_warn ("A byte must be in range 0-255 not %ld\n",
688 if (len == allocated)
691 values = dbus_realloc (values, allocated * sizeof (unsigned char));
694 _dbus_warn ("could not allocate memory for BYTE_ARRAY\n");
699 _dbus_string_skip_blank (&line, i, &i);
701 b = _dbus_string_get_byte (&line, i++);
709 if (!_dbus_marshal_int32 (dest, endian, len) ||
710 !_dbus_string_append_len (dest, values, len))
712 _dbus_warn ("failed to append BYTE_ARRAY\n");
717 PERFORM_UNALIGN (dest);
719 else if (_dbus_string_starts_with_c_str (&line,
722 SAVE_FOR_UNALIGN (dest, 4);
723 int i, len, allocated;
724 unsigned char *values;
725 unsigned char b, val;
728 values = dbus_new (unsigned char, allocated);
731 _dbus_warn ("could not allocate memory for BOOLEAN_ARRAY\n");
737 _dbus_string_delete_first_word (&line);
738 _dbus_string_skip_blank (&line, 0, &i);
739 b = _dbus_string_get_byte (&line, i++);
744 while (i < _dbus_string_get_length (&line))
746 _dbus_string_skip_blank (&line, i, &i);
748 if (_dbus_string_find_to (&line, i, i + 5,
754 else if (_dbus_string_find_to (&line, i, i + 4,
762 _dbus_warn ("could not parse BOOLEAN_ARRAY\n");
767 if (len == allocated)
770 values = dbus_realloc (values, allocated * sizeof (unsigned char));
773 _dbus_warn ("could not allocate memory for BOOLEAN_ARRAY\n");
778 _dbus_string_skip_blank (&line, i, &i);
780 b = _dbus_string_get_byte (&line, i++);
788 if (!_dbus_marshal_int32 (dest, endian, len) ||
789 !_dbus_string_append_len (dest, values, len))
791 _dbus_warn ("failed to append BOOLEAN_ARRAY\n");
796 PERFORM_UNALIGN (dest);
798 else if (_dbus_string_starts_with_c_str (&line,
801 SAVE_FOR_UNALIGN (dest, 4);
802 int i, len, allocated;
803 dbus_int32_t *values;
808 values = dbus_new (dbus_int32_t, allocated);
811 _dbus_warn ("could not allocate memory for INT32_ARRAY\n");
817 _dbus_string_delete_first_word (&line);
818 _dbus_string_skip_blank (&line, 0, &i);
819 b = _dbus_string_get_byte (&line, i++);
824 while (i < _dbus_string_get_length (&line))
826 _dbus_string_skip_blank (&line, i, &i);
828 if (!_dbus_string_parse_int (&line, i, &val, &i))
830 _dbus_warn ("could not parse integer for INT32_ARRAY\n");
835 if (len == allocated)
838 values = dbus_realloc (values, allocated * sizeof (dbus_int32_t));
841 _dbus_warn ("could not allocate memory for INT32_ARRAY\n");
846 _dbus_string_skip_blank (&line, i, &i);
848 b = _dbus_string_get_byte (&line, i++);
856 if (!_dbus_marshal_int32_array (dest, endian, values, len))
858 _dbus_warn ("failed to append INT32_ARRAY\n");
863 PERFORM_UNALIGN (dest);
865 else if (_dbus_string_starts_with_c_str (&line,
868 SAVE_FOR_UNALIGN (dest, 4);
869 int i, len, allocated;
870 dbus_uint32_t *values;
875 values = dbus_new (dbus_uint32_t, allocated);
878 _dbus_warn ("could not allocate memory for UINT32_ARRAY\n");
884 _dbus_string_delete_first_word (&line);
885 _dbus_string_skip_blank (&line, 0, &i);
886 b = _dbus_string_get_byte (&line, i++);
891 while (i < _dbus_string_get_length (&line))
893 _dbus_string_skip_blank (&line, i, &i);
895 if (!_dbus_string_parse_int (&line, i, &val, &i))
897 _dbus_warn ("could not parse integer for UINT32_ARRAY\n");
902 if (len == allocated)
905 values = dbus_realloc (values, allocated * sizeof (dbus_uint32_t));
908 _dbus_warn ("could not allocate memory for UINT32_ARRAY\n");
913 _dbus_string_skip_blank (&line, i, &i);
915 b = _dbus_string_get_byte (&line, i++);
923 if (!_dbus_marshal_uint32_array (dest, endian, values, len))
925 _dbus_warn ("failed to append UINT32_ARRAY\n");
930 PERFORM_UNALIGN (dest);
932 else if (_dbus_string_starts_with_c_str (&line,
935 SAVE_FOR_UNALIGN (dest, 8);
936 int i, len, allocated;
942 values = dbus_new (double, allocated);
945 _dbus_warn ("could not allocate memory for DOUBLE_ARRAY\n");
951 _dbus_string_delete_first_word (&line);
952 _dbus_string_skip_blank (&line, 0, &i);
953 b = _dbus_string_get_byte (&line, i++);
958 while (i < _dbus_string_get_length (&line))
960 _dbus_string_skip_blank (&line, i, &i);
962 if (!_dbus_string_parse_double (&line, i, &val, &i))
964 _dbus_warn ("could not parse double for DOUBLE_ARRAY\n");
969 if (len == allocated)
972 values = dbus_realloc (values, allocated * sizeof (double));
975 _dbus_warn ("could not allocate memory for DOUBLE_ARRAY\n");
980 _dbus_string_skip_blank (&line, i, &i);
982 b = _dbus_string_get_byte (&line, i++);
990 if (!_dbus_marshal_double_array (dest, endian, values, len))
992 _dbus_warn ("failed to append DOUBLE_ARRAY\n");
997 PERFORM_UNALIGN (dest);
999 else if (_dbus_string_starts_with_c_str (&line,
1002 SAVE_FOR_UNALIGN (dest, 4);
1003 int i, len, allocated;
1010 values = dbus_new (char *, allocated);
1013 _dbus_warn ("could not allocate memory for STRING_ARRAY\n");
1019 _dbus_string_delete_first_word (&line);
1020 _dbus_string_skip_blank (&line, 0, &i);
1021 b = _dbus_string_get_byte (&line, i++);
1026 _dbus_string_init (&val_str);
1027 while (i < _dbus_string_get_length (&line))
1029 _dbus_string_skip_blank (&line, i, &i);
1031 if (!append_quoted_string (&val_str, &line, i, &i))
1033 _dbus_warn ("could not parse quoted string for STRING_ARRAY\n");
1038 if (!_dbus_string_steal_data (&val_str, &val))
1040 _dbus_warn ("could not allocate memory for STRING_ARRAY string\n");
1044 values[len++] = val;
1045 if (len == allocated)
1048 values = dbus_realloc (values, allocated * sizeof (char *));
1051 _dbus_warn ("could not allocate memory for STRING_ARRAY\n");
1056 _dbus_string_skip_blank (&line, i, &i);
1058 b = _dbus_string_get_byte (&line, i++);
1064 _dbus_warn ("missing comma when parsing STRING_ARRAY\n");
1068 _dbus_string_free (&val_str);
1070 if (!_dbus_marshal_string_array (dest, endian, (const char **)values, len))
1072 _dbus_warn ("failed to append STRING_ARRAY\n");
1077 dbus_free_string_array (values);
1079 PERFORM_UNALIGN (dest);
1081 else if (_dbus_string_starts_with_c_str (&line, "BYTE"))
1083 unsigned char the_byte;
1085 _dbus_string_delete_first_word (&line);
1087 if (_dbus_string_equal_c_str (&line, "'\\''"))
1089 else if (_dbus_string_get_byte (&line, 0) == '\'' &&
1090 _dbus_string_get_length (&line) >= 3 &&
1091 _dbus_string_get_byte (&line, 2) == '\'')
1092 the_byte = _dbus_string_get_byte (&line, 1);
1096 if (!_dbus_string_parse_int (&line, 0, &val, NULL))
1098 _dbus_warn ("Failed to parse integer for BYTE\n");
1104 _dbus_warn ("A byte must be in range 0-255 not %ld\n",
1108 the_byte = (unsigned char) val;
1111 _dbus_string_append_byte (dest, the_byte);
1113 else if (_dbus_string_starts_with_c_str (&line,
1118 _dbus_string_delete_first_word (&line);
1120 if (_dbus_string_starts_with_c_str (&line, "true"))
1122 else if (_dbus_string_starts_with_c_str (&line, "false"))
1126 _dbus_warn ("could not parse BOOLEAN\n");
1129 if (!_dbus_string_append_byte (dest, val))
1131 _dbus_warn ("failed to append BOOLEAN\n");
1136 else if (_dbus_string_starts_with_c_str (&line,
1139 SAVE_FOR_UNALIGN (dest, 4);
1142 _dbus_string_delete_first_word (&line);
1144 if (!_dbus_string_parse_int (&line, 0, &val, NULL))
1146 _dbus_warn ("could not parse integer for INT32\n");
1150 if (!_dbus_marshal_int32 (dest, endian,
1153 _dbus_warn ("failed to append INT32\n");
1157 PERFORM_UNALIGN (dest);
1159 else if (_dbus_string_starts_with_c_str (&line,
1162 SAVE_FOR_UNALIGN (dest, 4);
1165 _dbus_string_delete_first_word (&line);
1167 /* FIXME should have _dbus_string_parse_uint32 */
1168 if (!_dbus_string_parse_int (&line, 0, &val, NULL))
1171 if (!_dbus_marshal_uint32 (dest, endian,
1174 _dbus_warn ("failed to append UINT32\n");
1178 PERFORM_UNALIGN (dest);
1180 else if (_dbus_string_starts_with_c_str (&line,
1183 SAVE_FOR_UNALIGN (dest, 8);
1186 _dbus_string_delete_first_word (&line);
1188 if (!_dbus_string_parse_double (&line, 0, &val, NULL))
1191 if (!_dbus_marshal_double (dest, endian,
1194 _dbus_warn ("failed to append DOUBLE\n");
1198 PERFORM_UNALIGN (dest);
1200 else if (_dbus_string_starts_with_c_str (&line,
1203 SAVE_FOR_UNALIGN (dest, 4);
1207 _dbus_string_delete_first_word (&line);
1209 size_offset = _dbus_string_get_length (dest);
1210 size_offset = _DBUS_ALIGN_VALUE (size_offset, 4);
1211 if (!_dbus_marshal_uint32 (dest, endian, 0))
1213 _dbus_warn ("Failed to append string size\n");
1217 old_len = _dbus_string_get_length (dest);
1218 if (!append_quoted_string (dest, &line, 0, NULL))
1220 _dbus_warn ("Failed to append quoted string\n");
1224 _dbus_marshal_set_uint32 (dest, endian, size_offset,
1225 /* subtract 1 for nul */
1226 _dbus_string_get_length (dest) - old_len - 1);
1228 PERFORM_UNALIGN (dest);
1233 if (!just_set_unalign && unalign)
1235 _dbus_warn ("UNALIGN prior to something that isn't aligned\n");
1239 goto next_iteration; /* skip parse_failed */
1243 _dbus_warn ("couldn't process line %d \"%s\"\n",
1244 line_no, _dbus_string_get_const_data (&line));
1249 _dbus_hash_iter_init (length_hash, &iter);
1250 while (_dbus_hash_iter_next (&iter))
1252 SavedLength *sl = _dbus_hash_iter_get_value (&iter);
1255 s = _dbus_string_get_const_data (&sl->name);
1259 _dbus_warn ("Used LENGTH %s but never did END_LENGTH\n",
1263 else if (sl->offset < 0)
1265 _dbus_warn ("Did END_LENGTH %s but never used LENGTH\n",
1274 _dbus_verbose ("Filling in length %s endian = %d offset = %d start = %d length = %d\n",
1275 s, sl->endian, sl->offset, sl->start, sl->length);
1276 _dbus_marshal_set_int32 (dest,
1279 sl->length - sl->start);
1282 _dbus_hash_iter_remove_entry (&iter);
1288 if (length_hash != NULL)
1289 _dbus_hash_table_unref (length_hash);
1291 _dbus_string_free (&file);
1292 _dbus_string_free (&line);
1297 #endif /* DBUS_BUILD_TESTS */