D-Bus: dbus-marshal-header.h Source File

D-Bus 1.13.18

dbus-marshal-header.h
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-marshal-header.h Managing marshaling/demarshaling of message headers
3 *
4 * Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23
24 #ifndef DBUS_MARSHAL_HEADER_H
25 #define DBUS_MARSHAL_HEADER_H
26
27 #include <dbus/dbus-marshal-basic.h>
28 #include <dbus/dbus-marshal-validate.h>
29
30 typedef struct DBusHeader DBusHeader;
31 typedef struct DBusHeaderField DBusHeaderField;
32
33 #define _DBUS_HEADER_FIELD_VALUE_UNKNOWN -1
34 #define _DBUS_HEADER_FIELD_VALUE_NONEXISTENT -2
35
39 struct DBusHeaderField
40 {
41 int value_pos;
42 };
43
87 struct DBusHeader
88 {
89 DBusString data;
100 DBusHeaderField fields[DBUS_HEADER_FIELD_LAST + 1];
104 dbus_uint32_t padding : 3;
106 dbus_uint32_t byte_order : 8;
108 };
109
110 dbus_bool_t _dbus_header_init (DBusHeader *header);
111 void _dbus_header_free (DBusHeader *header);
112 void _dbus_header_reinit (DBusHeader *header);
113 dbus_bool_t _dbus_header_create (DBusHeader *header,
114 int byte_order,
115 int type,
116 const char *destination,
117 const char *path,
118 const char *interface,
119 const char *member,
120 const char *error_name);
121 dbus_bool_t _dbus_header_copy (const DBusHeader *header,
122 DBusHeader *dest);
123 int _dbus_header_get_message_type (DBusHeader *header);
124 void _dbus_header_set_serial (DBusHeader *header,
125 dbus_uint32_t serial);
126 dbus_uint32_t _dbus_header_get_serial (DBusHeader *header);
127 void _dbus_header_update_lengths (DBusHeader *header,
128 int body_len);
129 DBUS_PRIVATE_EXPORT
130 dbus_bool_t _dbus_header_set_field_basic (DBusHeader *header,
131 int field,
132 int type,
133 const void *value);
134 dbus_bool_t _dbus_header_get_field_basic (DBusHeader *header,
135 int field,
136 int type,
137 void *value);
138 DBUS_PRIVATE_EXPORT
139 dbus_bool_t _dbus_header_get_field_raw (DBusHeader *header,
140 int field,
141 const DBusString **str,
142 int *pos);
143 DBUS_PRIVATE_EXPORT
144 dbus_bool_t _dbus_header_delete_field (DBusHeader *header,
145 int field);
146 void _dbus_header_toggle_flag (DBusHeader *header,
147 dbus_uint32_t flag,
148 dbus_bool_t value);
149 dbus_bool_t _dbus_header_get_flag (DBusHeader *header,
150 dbus_uint32_t flag);
151 dbus_bool_t _dbus_header_ensure_signature (DBusHeader *header,
152 DBusString **type_str,
153 int *type_pos);
154 dbus_bool_t _dbus_header_have_message_untrusted (int max_message_length,
155 DBusValidity *validity,
156 int *byte_order,
157 int *fields_array_len,
158 int *header_len,
159 int *body_len,
160 const DBusString *str,
161 int start,
162 int len);
163 dbus_bool_t _dbus_header_load (DBusHeader *header,
164 DBusValidationMode mode,
165 DBusValidity *validity,
166 int byte_order,
167 int fields_array_len,
168 int header_len,
169 int body_len,
170 const DBusString *str);
171 void _dbus_header_byteswap (DBusHeader *header,
172 int new_order);
173 DBUS_PRIVATE_EXPORT
174 char _dbus_header_get_byte_order (const DBusHeader *header);
175 dbus_bool_t _dbus_header_remove_unknown_fields (DBusHeader *header);
176
177 #endif /* DBUS_MARSHAL_HEADER_H */
DBusHeader::data
DBusString data
Header network data, stored separately from body so we can independently realloc it.
Definition: dbus-marshal-header.h:89
DBusValidationMode
DBusValidationMode
This is used rather than a bool for high visibility.
Definition: dbus-marshal-validate.h:39
DBusHeader::byte_order
dbus_uint32_t byte_order
byte order of header (must always match the content of byte 0)
Definition: dbus-marshal-header.h:106
_dbus_header_update_lengths
void _dbus_header_update_lengths(DBusHeader *header, int body_len)
Fills in the correct body length.
Definition: dbus-marshal-header.c:1205
DBusHeader::padding
dbus_uint32_t padding
0-7 bytes of alignment in header, the distance from [B] to [C]
Definition: dbus-marshal-header.h:104
DBUS_HEADER_FIELD_LAST
#define DBUS_HEADER_FIELD_LAST
Value of the highest-numbered header field code, can be used to determine the size of an array indexe...
Definition: dbus-protocol.h:315
_dbus_header_set_serial
void _dbus_header_set_serial(DBusHeader *header, dbus_uint32_t serial)
Sets the serial number of a header.
Definition: dbus-marshal-header.c:407
_dbus_header_delete_field
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_header_delete_field(DBusHeader *header, int field)
Deletes a field, if it exists.
Definition: dbus-marshal-header.c:1425
_dbus_header_get_serial
dbus_uint32_t _dbus_header_get_serial(DBusHeader *header)
See dbus_message_get_serial()
Definition: dbus-marshal-header.c:430
DBusHeader
Message header data and some cached details of it.
Definition: dbus-marshal-header.h:88
_dbus_header_get_byte_order
DBUS_PRIVATE_EXPORT char _dbus_header_get_byte_order(const DBusHeader *header)
Returns the header's byte order.
Definition: dbus-marshal-header.c:177
_dbus_header_get_message_type
int _dbus_header_get_message_type(DBusHeader *header)
Gets the type of the message.
Definition: dbus-marshal-header.c:389
_dbus_header_remove_unknown_fields
dbus_bool_t _dbus_header_remove_unknown_fields(DBusHeader *header)
Remove every header field not known to this version of dbus.
Definition: dbus-marshal-header.c:1530
DBusHeaderField::value_pos
int value_pos
Position of field value, or -1/-2.
Definition: dbus-marshal-header.h:41
DBusHeaderField
Cached information about a header field in the message.
Definition: dbus-marshal-header.h:40
_dbus_header_toggle_flag
void _dbus_header_toggle_flag(DBusHeader *header, dbus_uint32_t flag, dbus_bool_t value)
Toggles a message flag bit, turning on the bit if value = TRUE and flipping it off if value = FALSE.
Definition: dbus-marshal-header.c:1466
DBusString
Definition: dbus-string.h:43
dbus_uint32_t
unsigned int dbus_uint32_t
Definition: dbus-arch-deps.h:43
_dbus_header_get_flag
dbus_bool_t _dbus_header_get_flag(DBusHeader *header, dbus_uint32_t flag)
Gets a message flag bit, returning TRUE if the bit is set.
Definition: dbus-marshal-header.c:1488
_dbus_header_copy
dbus_bool_t _dbus_header_copy(const DBusHeader *header, DBusHeader *dest)
Initializes dest with a copy of the given header.
Definition: dbus-marshal-header.c:493
_dbus_header_have_message_untrusted
dbus_bool_t _dbus_header_have_message_untrusted(int max_message_length, DBusValidity *validity, int *byte_order, int *fields_array_len, int *header_len, int *body_len, const DBusString *str, int start, int len)
Given data long enough to contain the length of the message body and the fields array,...
Definition: dbus-marshal-header.c:679
_dbus_header_get_field_raw
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_header_get_field_raw(DBusHeader *header, int field, const DBusString **str, int *pos)
Gets the raw marshaled data for a field.
Definition: dbus-marshal-header.c:1401
_dbus_header_free
void _dbus_header_free(DBusHeader *header)
Frees a header.
Definition: dbus-marshal-header.c:479
_dbus_header_get_field_basic
dbus_bool_t _dbus_header_get_field_basic(DBusHeader *header, int field, int type, void *value)
Gets the value of a field with basic type.
Definition: dbus-marshal-header.c:1360
_dbus_header_byteswap
void _dbus_header_byteswap(DBusHeader *header, int new_order)
Swaps the header into the given order if required.
Definition: dbus-marshal-header.c:1505
DBusHeader::fields
DBusHeaderField fields[DBUS_HEADER_FIELD_LAST+1]
Track the location of each field in header.
Definition: dbus-marshal-header.h:100
_dbus_header_load
dbus_bool_t _dbus_header_load(DBusHeader *header, DBusValidationMode mode, DBusValidity *validity, int byte_order, int fields_array_len, int header_len, int body_len, const DBusString *str)
Creates a message header from potentially-untrusted data.
Definition: dbus-marshal-header.c:979
_dbus_header_reinit
void _dbus_header_reinit(DBusHeader *header)
Re-initializes a header that was previously initialized and never freed.
Definition: dbus-marshal-header.c:446
_dbus_header_create
dbus_bool_t _dbus_header_create(DBusHeader *header, int byte_order, int type, const char *destination, const char *path, const char *interface, const char *member, const char *error_name)
Fills in the primary fields of the header, so the header is ready for use.
Definition: dbus-marshal-header.c:531
_dbus_header_set_field_basic
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_header_set_field_basic(DBusHeader *header, int field, int type, const void *value)
Sets the value of a field with basic type.
Definition: dbus-marshal-header.c:1282
_dbus_header_init
dbus_bool_t _dbus_header_init(DBusHeader *header)
Initializes a header, but doesn't prepare it for use; to make the header valid, you have to call _dbu...
Definition: dbus-marshal-header.c:463
dbus_bool_t
dbus_uint32_t dbus_bool_t
Definition: dbus-types.h:35
DBusValidity
DBusValidity
This is primarily used in unit testing, so we can verify that each invalid message is invalid for the...
Definition: dbus-marshal-validate.h:52