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 message_type_from_string (const DBusString *str,
274 s = _dbus_string_get_const_data_len (str, start,
275 _dbus_string_get_length (str) - start);
277 if (strncmp (s, "method_call", strlen ("method_call")) == 0)
278 return DBUS_MESSAGE_TYPE_METHOD_CALL;
279 else if (strncmp (s, "method_return", strlen ("method_return")) == 0)
280 return DBUS_MESSAGE_TYPE_METHOD_RETURN;
281 else if (strncmp (s, "signal", strlen ("signal")) == 0)
282 return DBUS_MESSAGE_TYPE_SIGNAL;
283 else if (strncmp (s, "error", strlen ("error")) == 0)
284 return DBUS_MESSAGE_TYPE_ERROR;
285 else if (strncmp (s, "invalid", strlen ("invalid")) == 0)
286 return DBUS_MESSAGE_TYPE_INVALID;
292 * Reads the given filename, which should be in "message description
293 * language" (look at some examples), and builds up the message data
294 * from it. The message data may be invalid, or valid.
296 * The parser isn't very strict, it's just a hack for test programs.
298 * The file format is:
300 * VALID_HEADER <type> normal header; byte order, type, padding, header len, body len, serial
301 * BIG_ENDIAN switch to big endian
302 * LITTLE_ENDIAN switch to little endian
303 * OPPOSITE_ENDIAN switch to opposite endian
304 * ALIGN <N> aligns to the given value
305 * UNALIGN skips alignment for the next marshal
306 * BYTE <N> inserts the given integer in [0,255] or char in 'a' format
307 * START_LENGTH <name> marks the start of a length to measure
308 * END_LENGTH <name> records the length since START_LENGTH under the given name
309 * (or if no START_LENGTH, absolute length)
310 * LENGTH <name> inserts the saved length of the same name
311 * CHOP <N> chops last N bytes off the data
312 * FIELD_NAME <abcd> inserts 4-byte field name
313 * TYPE <typename> inserts a typecode byte
316 * Following commands insert aligned data unless
317 * preceded by "UNALIGN":
319 * INT32 <N> marshals an INT32
320 * UINT32 <N> marshals a UINT32
321 * INT64 <N> marshals an INT64
322 * UINT64 <N> marshals a UINT64
323 * DOUBLE <N> marshals a double
324 * STRING 'Foo' marshals a string
325 * BYTE_ARRAY { 'a', 3, 4, 5, 6} marshals a BYTE array
326 * BOOLEAN_ARRAY { false, true, false} marshals a BOOLEAN array
327 * INT32_ARRAY { 3, 4, 5, 6} marshals an INT32 array
328 * UINT32_ARRAY { 3, 4, 5, 6} marshals an UINT32 array
329 * DOUBLE_ARRAY { 1.0, 2.0, 3.0, 4.0} marshals a DOUBLE array
330 * STRING_ARRAY { "foo", "bar", "gazonk"} marshals a STRING array
333 * @todo add support for array types INT32_ARRAY { 3, 4, 5, 6 }
336 * @param dest the string to append the message data to
337 * @param filename the filename to load
338 * @returns #TRUE on success
341 _dbus_message_data_load (DBusString *dest,
342 const DBusString *filename)
350 DBusHashTable *length_hash;
357 if (!_dbus_string_init (&file))
360 if (!_dbus_string_init (&line))
362 _dbus_string_free (&file);
366 _dbus_verbose ("Loading %s\n", _dbus_string_get_const_data (filename));
368 dbus_error_init (&error);
369 if (!_dbus_file_get_contents (&file, filename, &error))
371 _dbus_warn ("Getting contents of %s failed: %s\n",
372 _dbus_string_get_const_data (filename), error.message);
373 dbus_error_free (&error);
377 length_hash = _dbus_hash_table_new (DBUS_HASH_STRING,
380 if (length_hash == NULL)
383 endian = DBUS_COMPILER_BYTE_ORDER;
387 while (_dbus_string_pop_line (&file, &line))
389 dbus_bool_t just_set_unalign;
391 just_set_unalign = FALSE;
394 _dbus_string_delete_leading_blanks (&line);
396 if (_dbus_string_get_length (&line) == 0)
401 else if (_dbus_string_starts_with_c_str (&line,
404 /* Ignore this comment */
407 else if (_dbus_string_starts_with_c_str (&line,
414 if (_dbus_string_get_length (&line) < (int) strlen ("VALID_HEADER "))
416 _dbus_warn ("no args to VALID_HEADER\n");
420 if (!_dbus_string_append_byte (dest, endian))
422 _dbus_warn ("could not append endianness\n");
426 message_type = message_type_from_string (&line,
427 strlen ("VALID_HEADER "));
428 if (message_type < 0)
430 _dbus_warn ("VALID_HEADER not followed by space then known message type\n");
434 if (!_dbus_string_append_byte (dest, message_type))
436 _dbus_warn ("could not append message type\n");
443 if (!_dbus_string_append_byte (dest, '\0'))
445 _dbus_warn ("could not append nul pad\n");
451 _dbus_string_init_const (&name, "Header");
452 if (!append_saved_length (dest, length_hash,
453 &name, _dbus_string_get_length (dest),
457 _dbus_string_init_const (&name, "Body");
458 if (!append_saved_length (dest, length_hash,
459 &name, _dbus_string_get_length (dest),
464 if (!_dbus_marshal_int32 (dest, endian, 1))
466 _dbus_warn ("couldn't append client serial\n");
470 else if (_dbus_string_starts_with_c_str (&line,
473 endian = DBUS_BIG_ENDIAN;
475 else if (_dbus_string_starts_with_c_str (&line,
478 endian = DBUS_LITTLE_ENDIAN;
480 else if (_dbus_string_starts_with_c_str (&line,
483 if (endian == DBUS_BIG_ENDIAN)
484 endian = DBUS_LITTLE_ENDIAN;
486 endian = DBUS_BIG_ENDIAN;
488 else if (_dbus_string_starts_with_c_str (&line,
495 _dbus_string_delete_first_word (&line);
497 if (!_dbus_string_parse_int (&line, 0, &val, &end))
499 _dbus_warn ("Failed to parse integer\n");
505 _dbus_warn ("Aligning to %ld boundary is crack\n",
510 orig_len = _dbus_string_get_length (dest);
512 if (!_dbus_string_align_length (dest, val))
515 if (_dbus_string_parse_int (&line, end, &val, NULL))
517 /* If there's an optional second int argument,
518 * fill in align padding with that value
520 if (val < 0 || val > 255)
522 _dbus_warn ("can't fill align padding with %ld, must be a byte value\n", val);
527 while (end < _dbus_string_get_length (dest))
529 _dbus_string_set_byte (dest, end, val);
534 else if (_dbus_string_starts_with_c_str (&line, "UNALIGN"))
537 just_set_unalign = TRUE;
539 else if (_dbus_string_starts_with_c_str (&line, "CHOP"))
543 /* FIXME if you CHOP the offset for a LENGTH
544 * command, we segfault.
547 _dbus_string_delete_first_word (&line);
549 if (!_dbus_string_parse_int (&line, 0, &val, NULL))
551 _dbus_warn ("Failed to parse integer to chop\n");
555 if (val > _dbus_string_get_length (dest))
557 _dbus_warn ("Trying to chop %ld bytes but we only have %d\n",
559 _dbus_string_get_length (dest));
563 _dbus_string_shorten (dest, val);
565 else if (_dbus_string_starts_with_c_str (&line,
568 _dbus_string_delete_first_word (&line);
570 if (!save_start (length_hash, &line,
571 _dbus_string_get_length (dest)))
573 _dbus_warn ("failed to save length start\n");
577 else if (_dbus_string_starts_with_c_str (&line,
580 _dbus_string_delete_first_word (&line);
582 if (!save_length (length_hash, &line,
583 _dbus_string_get_length (dest)))
585 _dbus_warn ("failed to save length end\n");
589 else if (_dbus_string_starts_with_c_str (&line,
592 SAVE_FOR_UNALIGN (dest, 4);
594 _dbus_string_delete_first_word (&line);
596 if (!append_saved_length (dest, length_hash,
598 unalign ? align_pad_start : align_pad_end,
601 _dbus_warn ("failed to add LENGTH\n");
605 PERFORM_UNALIGN (dest);
607 else if (_dbus_string_starts_with_c_str (&line,
610 _dbus_string_delete_first_word (&line);
612 if (_dbus_string_get_length (&line) != 4)
614 _dbus_warn ("Field name must be four characters not \"%s\"\n",
615 _dbus_string_get_const_data (&line));
622 _dbus_string_align_length (dest, 4);
624 if (!_dbus_string_copy (&line, 0, dest,
625 _dbus_string_get_length (dest)))
628 else if (_dbus_string_starts_with_c_str (&line,
633 _dbus_string_delete_first_word (&line);
635 if (_dbus_string_starts_with_c_str (&line, "INVALID"))
636 code = DBUS_TYPE_INVALID;
637 else if (_dbus_string_starts_with_c_str (&line, "NIL"))
638 code = DBUS_TYPE_NIL;
639 else if (_dbus_string_starts_with_c_str (&line, "BYTE"))
640 code = DBUS_TYPE_BYTE;
641 else if (_dbus_string_starts_with_c_str (&line, "BOOLEAN"))
642 code = DBUS_TYPE_BOOLEAN;
643 else if (_dbus_string_starts_with_c_str (&line, "INT32"))
644 code = DBUS_TYPE_INT32;
645 else if (_dbus_string_starts_with_c_str (&line, "UINT32"))
646 code = DBUS_TYPE_UINT32;
647 else if (_dbus_string_starts_with_c_str (&line, "DOUBLE"))
648 code = DBUS_TYPE_DOUBLE;
649 else if (_dbus_string_starts_with_c_str (&line, "STRING"))
650 code = DBUS_TYPE_STRING;
651 else if (_dbus_string_starts_with_c_str (&line, "NAMED"))
652 code = DBUS_TYPE_NAMED;
653 else if (_dbus_string_starts_with_c_str (&line, "ARRAY"))
654 code = DBUS_TYPE_ARRAY;
655 else if (_dbus_string_starts_with_c_str (&line, "DICT"))
656 code = DBUS_TYPE_DICT;
659 _dbus_warn ("%s is not a valid type name\n", _dbus_string_get_const_data (&line));
663 if (!_dbus_string_append_byte (dest, code))
665 _dbus_warn ("could not append typecode byte\n");
669 else if (_dbus_string_starts_with_c_str (&line,
672 SAVE_FOR_UNALIGN (dest, 4);
673 int i, len, allocated;
674 unsigned char *values;
679 values = dbus_new (unsigned char, allocated);
682 _dbus_warn ("could not allocate memory for BYTE_ARRAY\n");
688 _dbus_string_delete_first_word (&line);
689 _dbus_string_skip_blank (&line, 0, &i);
690 b = _dbus_string_get_byte (&line, i++);
695 while (i < _dbus_string_get_length (&line))
697 _dbus_string_skip_blank (&line, i, &i);
699 if (_dbus_string_get_byte (&line, i) == '\'' &&
700 _dbus_string_get_length (&line) >= i + 4 &&
701 _dbus_string_get_byte (&line, i + 1) == '\\' &&
702 _dbus_string_get_byte (&line, i + 2) == '\'' &&
703 _dbus_string_get_byte (&line, i + 3) == '\'')
708 else if (_dbus_string_get_byte (&line, i) == '\'' &&
709 _dbus_string_get_length (&line) >= i + 3 &&
710 _dbus_string_get_byte (&line, i + 2) == '\'')
712 val = _dbus_string_get_byte (&line, i + 1);
717 if (!_dbus_string_parse_int (&line, i, &val, &i))
719 _dbus_warn ("Failed to parse integer for BYTE_ARRAY\n");
723 if (val < 0 || val > 255)
725 _dbus_warn ("A byte must be in range 0-255 not %ld\n",
732 if (len == allocated)
735 values = dbus_realloc (values, allocated * sizeof (unsigned char));
738 _dbus_warn ("could not allocate memory for BYTE_ARRAY\n");
743 _dbus_string_skip_blank (&line, i, &i);
745 b = _dbus_string_get_byte (&line, i++);
753 if (!_dbus_marshal_int32 (dest, endian, len) ||
754 !_dbus_string_append_len (dest, values, len))
756 _dbus_warn ("failed to append BYTE_ARRAY\n");
761 PERFORM_UNALIGN (dest);
763 else if (_dbus_string_starts_with_c_str (&line,
766 SAVE_FOR_UNALIGN (dest, 4);
767 int i, len, allocated;
768 unsigned char *values;
769 unsigned char b, val;
772 values = dbus_new (unsigned char, allocated);
775 _dbus_warn ("could not allocate memory for BOOLEAN_ARRAY\n");
781 _dbus_string_delete_first_word (&line);
782 _dbus_string_skip_blank (&line, 0, &i);
783 b = _dbus_string_get_byte (&line, i++);
788 while (i < _dbus_string_get_length (&line))
790 _dbus_string_skip_blank (&line, i, &i);
792 if (_dbus_string_find_to (&line, i, i + 5,
798 else if (_dbus_string_find_to (&line, i, i + 4,
806 _dbus_warn ("could not parse BOOLEAN_ARRAY\n");
811 if (len == allocated)
814 values = dbus_realloc (values, allocated * sizeof (unsigned char));
817 _dbus_warn ("could not allocate memory for BOOLEAN_ARRAY\n");
822 _dbus_string_skip_blank (&line, i, &i);
824 b = _dbus_string_get_byte (&line, i++);
832 if (!_dbus_marshal_int32 (dest, endian, len) ||
833 !_dbus_string_append_len (dest, values, len))
835 _dbus_warn ("failed to append BOOLEAN_ARRAY\n");
840 PERFORM_UNALIGN (dest);
842 else if (_dbus_string_starts_with_c_str (&line,
845 SAVE_FOR_UNALIGN (dest, 4);
846 int i, len, allocated;
847 dbus_int32_t *values;
852 values = dbus_new (dbus_int32_t, allocated);
855 _dbus_warn ("could not allocate memory for INT32_ARRAY\n");
861 _dbus_string_delete_first_word (&line);
862 _dbus_string_skip_blank (&line, 0, &i);
863 b = _dbus_string_get_byte (&line, i++);
868 while (i < _dbus_string_get_length (&line))
870 _dbus_string_skip_blank (&line, i, &i);
872 if (!_dbus_string_parse_int (&line, i, &val, &i))
874 _dbus_warn ("could not parse integer for INT32_ARRAY\n");
879 if (len == allocated)
882 values = dbus_realloc (values, allocated * sizeof (dbus_int32_t));
885 _dbus_warn ("could not allocate memory for INT32_ARRAY\n");
890 _dbus_string_skip_blank (&line, i, &i);
892 b = _dbus_string_get_byte (&line, i++);
900 if (!_dbus_marshal_int32_array (dest, endian, values, len))
902 _dbus_warn ("failed to append INT32_ARRAY\n");
907 PERFORM_UNALIGN (dest);
909 else if (_dbus_string_starts_with_c_str (&line,
912 SAVE_FOR_UNALIGN (dest, 4);
913 int i, len, allocated;
914 dbus_uint32_t *values;
919 values = dbus_new (dbus_uint32_t, allocated);
922 _dbus_warn ("could not allocate memory for UINT32_ARRAY\n");
928 _dbus_string_delete_first_word (&line);
929 _dbus_string_skip_blank (&line, 0, &i);
930 b = _dbus_string_get_byte (&line, i++);
935 while (i < _dbus_string_get_length (&line))
937 _dbus_string_skip_blank (&line, i, &i);
939 if (!_dbus_string_parse_int (&line, i, &val, &i))
941 _dbus_warn ("could not parse integer for UINT32_ARRAY\n");
946 if (len == allocated)
949 values = dbus_realloc (values, allocated * sizeof (dbus_uint32_t));
952 _dbus_warn ("could not allocate memory for UINT32_ARRAY\n");
957 _dbus_string_skip_blank (&line, i, &i);
959 b = _dbus_string_get_byte (&line, i++);
967 if (!_dbus_marshal_uint32_array (dest, endian, values, len))
969 _dbus_warn ("failed to append UINT32_ARRAY\n");
974 PERFORM_UNALIGN (dest);
976 else if (_dbus_string_starts_with_c_str (&line,
979 SAVE_FOR_UNALIGN (dest, 8);
980 int i, len, allocated;
986 values = dbus_new (double, allocated);
989 _dbus_warn ("could not allocate memory for DOUBLE_ARRAY\n");
995 _dbus_string_delete_first_word (&line);
996 _dbus_string_skip_blank (&line, 0, &i);
997 b = _dbus_string_get_byte (&line, i++);
1002 while (i < _dbus_string_get_length (&line))
1004 _dbus_string_skip_blank (&line, i, &i);
1006 if (!_dbus_string_parse_double (&line, i, &val, &i))
1008 _dbus_warn ("could not parse double for DOUBLE_ARRAY\n");
1012 values[len++] = val;
1013 if (len == allocated)
1016 values = dbus_realloc (values, allocated * sizeof (double));
1019 _dbus_warn ("could not allocate memory for DOUBLE_ARRAY\n");
1024 _dbus_string_skip_blank (&line, i, &i);
1026 b = _dbus_string_get_byte (&line, i++);
1034 if (!_dbus_marshal_double_array (dest, endian, values, len))
1036 _dbus_warn ("failed to append DOUBLE_ARRAY\n");
1041 PERFORM_UNALIGN (dest);
1043 else if (_dbus_string_starts_with_c_str (&line,
1046 SAVE_FOR_UNALIGN (dest, 4);
1047 int i, len, allocated;
1054 values = dbus_new (char *, allocated);
1057 _dbus_warn ("could not allocate memory for STRING_ARRAY\n");
1063 _dbus_string_delete_first_word (&line);
1064 _dbus_string_skip_blank (&line, 0, &i);
1065 b = _dbus_string_get_byte (&line, i++);
1070 _dbus_string_init (&val_str);
1071 while (i < _dbus_string_get_length (&line))
1073 _dbus_string_skip_blank (&line, i, &i);
1075 if (!append_quoted_string (&val_str, &line, i, &i))
1077 _dbus_warn ("could not parse quoted string for STRING_ARRAY\n");
1082 if (!_dbus_string_steal_data (&val_str, &val))
1084 _dbus_warn ("could not allocate memory for STRING_ARRAY string\n");
1088 values[len++] = val;
1089 if (len == allocated)
1092 values = dbus_realloc (values, allocated * sizeof (char *));
1095 _dbus_warn ("could not allocate memory for STRING_ARRAY\n");
1100 _dbus_string_skip_blank (&line, i, &i);
1102 b = _dbus_string_get_byte (&line, i++);
1108 _dbus_warn ("missing comma when parsing STRING_ARRAY\n");
1112 _dbus_string_free (&val_str);
1114 if (!_dbus_marshal_string_array (dest, endian, (const char **)values, len))
1116 _dbus_warn ("failed to append STRING_ARRAY\n");
1121 dbus_free_string_array (values);
1123 PERFORM_UNALIGN (dest);
1125 else if (_dbus_string_starts_with_c_str (&line, "BYTE"))
1127 unsigned char the_byte;
1129 _dbus_string_delete_first_word (&line);
1131 if (_dbus_string_equal_c_str (&line, "'\\''"))
1133 else if (_dbus_string_get_byte (&line, 0) == '\'' &&
1134 _dbus_string_get_length (&line) >= 3 &&
1135 _dbus_string_get_byte (&line, 2) == '\'')
1136 the_byte = _dbus_string_get_byte (&line, 1);
1140 if (!_dbus_string_parse_int (&line, 0, &val, NULL))
1142 _dbus_warn ("Failed to parse integer for BYTE\n");
1148 _dbus_warn ("A byte must be in range 0-255 not %ld\n",
1152 the_byte = (unsigned char) val;
1155 _dbus_string_append_byte (dest, the_byte);
1157 else if (_dbus_string_starts_with_c_str (&line,
1162 _dbus_string_delete_first_word (&line);
1164 if (_dbus_string_starts_with_c_str (&line, "true"))
1166 else if (_dbus_string_starts_with_c_str (&line, "false"))
1170 _dbus_warn ("could not parse BOOLEAN\n");
1173 if (!_dbus_string_append_byte (dest, val))
1175 _dbus_warn ("failed to append BOOLEAN\n");
1180 else if (_dbus_string_starts_with_c_str (&line,
1183 SAVE_FOR_UNALIGN (dest, 4);
1186 _dbus_string_delete_first_word (&line);
1188 if (!_dbus_string_parse_int (&line, 0, &val, NULL))
1190 _dbus_warn ("could not parse integer for INT32\n");
1194 if (!_dbus_marshal_int32 (dest, endian,
1197 _dbus_warn ("failed to append INT32\n");
1201 PERFORM_UNALIGN (dest);
1203 else if (_dbus_string_starts_with_c_str (&line,
1206 SAVE_FOR_UNALIGN (dest, 4);
1209 _dbus_string_delete_first_word (&line);
1211 if (!_dbus_string_parse_uint (&line, 0, &val, NULL))
1214 if (!_dbus_marshal_uint32 (dest, endian,
1217 _dbus_warn ("failed to append UINT32\n");
1221 PERFORM_UNALIGN (dest);
1223 else if (_dbus_string_starts_with_c_str (&line,
1226 SAVE_FOR_UNALIGN (dest, 8);
1229 _dbus_string_delete_first_word (&line);
1231 if (!_dbus_string_parse_double (&line, 0, &val, NULL))
1234 if (!_dbus_marshal_double (dest, endian,
1237 _dbus_warn ("failed to append DOUBLE\n");
1241 PERFORM_UNALIGN (dest);
1243 else if (_dbus_string_starts_with_c_str (&line,
1246 SAVE_FOR_UNALIGN (dest, 4);
1250 _dbus_string_delete_first_word (&line);
1252 size_offset = _dbus_string_get_length (dest);
1253 size_offset = _DBUS_ALIGN_VALUE (size_offset, 4);
1254 if (!_dbus_marshal_uint32 (dest, endian, 0))
1256 _dbus_warn ("Failed to append string size\n");
1260 old_len = _dbus_string_get_length (dest);
1261 if (!append_quoted_string (dest, &line, 0, NULL))
1263 _dbus_warn ("Failed to append quoted string\n");
1267 _dbus_marshal_set_uint32 (dest, endian, size_offset,
1268 /* subtract 1 for nul */
1269 _dbus_string_get_length (dest) - old_len - 1);
1271 PERFORM_UNALIGN (dest);
1276 if (!just_set_unalign && unalign)
1278 _dbus_warn ("UNALIGN prior to something that isn't aligned\n");
1282 goto next_iteration; /* skip parse_failed */
1286 _dbus_warn ("couldn't process line %d \"%s\"\n",
1287 line_no, _dbus_string_get_const_data (&line));
1292 _dbus_hash_iter_init (length_hash, &iter);
1293 while (_dbus_hash_iter_next (&iter))
1295 SavedLength *sl = _dbus_hash_iter_get_value (&iter);
1298 s = _dbus_string_get_const_data (&sl->name);
1302 _dbus_warn ("Used LENGTH %s but never did END_LENGTH\n",
1306 else if (sl->offset < 0)
1308 _dbus_warn ("Did END_LENGTH %s but never used LENGTH\n",
1317 _dbus_verbose ("Filling in length %s endian = %d offset = %d start = %d length = %d\n",
1318 s, sl->endian, sl->offset, sl->start, sl->length);
1319 _dbus_marshal_set_int32 (dest,
1322 sl->length - sl->start);
1325 _dbus_hash_iter_remove_entry (&iter);
1330 _dbus_verbose_bytes_of_string (dest, 0, _dbus_string_get_length (dest));
1333 if (length_hash != NULL)
1334 _dbus_hash_table_unref (length_hash);
1336 _dbus_string_free (&file);
1337 _dbus_string_free (&line);
1342 #endif /* DBUS_BUILD_TESTS */