dbus-marshal-byteswap: Byte-swap Unix fd indexes if needed
[platform/upstream/dbus.git] / dbus / dbus-message-private.h
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-message-private.h header shared between dbus-message.c and dbus-message-util.c
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 #ifndef DBUS_MESSAGE_PRIVATE_H
24 #define DBUS_MESSAGE_PRIVATE_H
25
26 #include <dbus/dbus-message.h>
27 #include <dbus/dbus-message-internal.h>
28 #include <dbus/dbus-string.h>
29 #include <dbus/dbus-dataslot.h>
30 #include <dbus/dbus-marshal-header.h>
31
32 DBUS_BEGIN_DECLS
33
34 /**
35  * @addtogroup DBusMessageInternals
36  * @{
37  */
38
39 /**
40  * @typedef DBusMessageLoader
41  *
42  * The DBusMessageLoader object encapsulates the process of converting
43  * a byte stream into a series of DBusMessage. It buffers the incoming
44  * bytes as efficiently as possible, and generates a queue of
45  * messages. DBusMessageLoader is typically used as part of a
46  * DBusTransport implementation. The DBusTransport then hands off
47  * the loaded messages to a DBusConnection, making the messages
48  * visible to the application.
49  *
50  * @todo write tests for break-loader that a) randomly delete header
51  * fields and b) set string fields to zero-length and other funky
52  * values.
53  *
54  */
55
56 /**
57  * Implementation details of DBusMessageLoader.
58  * All members are private.
59  */
60 struct DBusMessageLoader
61 {
62   int refcount;        /**< Reference count. */
63
64   DBusString data;     /**< Buffered data */
65
66   DBusList *messages;  /**< Complete messages. */
67
68   long max_message_size; /**< Maximum size of a message */
69   unsigned long max_message_unix_fds; /**< Maximum unix fds in a message */
70
71   DBusValidity corruption_reason; /**< why we were corrupted */
72
73   unsigned int corrupted : 1; /**< We got broken data, and are no longer working */
74
75   unsigned int buffer_outstanding : 1; /**< Someone is using the buffer to read */
76
77 #ifdef HAVE_UNIX_FD_PASSING
78   unsigned int unix_fds_outstanding : 1; /**< Someone is using the unix fd array to read */
79
80   int *unix_fds; /**< File descriptors that have been read from the transport but not yet been handed to any message. Array will be allocated at first use. */
81   unsigned n_unix_fds_allocated; /**< Number of file descriptors this array has space for */
82   unsigned n_unix_fds; /**< Number of valid file descriptors in array */
83   void (* unix_fds_change) (void *); /**< Notify when the pending fds change */
84   void *unix_fds_change_data;
85 #endif
86   uint64_t unique_sender_id;
87 };
88
89
90 /** How many bits are in the changed_stamp used to validate iterators */
91 #define CHANGED_STAMP_BITS 21
92
93 /**
94  * @brief Internals of DBusMessage
95  *
96  * Object representing a message received from or to be sent to
97  * another application. This is an opaque object, all members
98  * are private.
99  */
100 struct DBusMessage
101 {
102   DBusAtomic refcount; /**< Reference count */
103
104   DBusHeader header; /**< Header network data and associated cache */
105
106   DBusString body;   /**< Body network data. */
107
108   unsigned int locked : 1; /**< Message being sent, no modifications allowed. */
109
110 #ifndef DBUS_DISABLE_CHECKS
111   unsigned int in_cache : 1; /**< Has been "freed" since it's in the cache (this is a debug feature) */
112 #endif
113
114   DBusList *counters;   /**< 0-N DBusCounter used to track message size/unix fds. */
115   long size_counter_delta;   /**< Size we incremented the size counters by.   */
116   int timeout_ms;
117
118   dbus_uint32_t changed_stamp : CHANGED_STAMP_BITS; /**< Incremented when iterators are invalidated. */
119
120   DBusDataSlotList slot_list;   /**< Data stored by allocated integer ID */
121
122 #ifndef DBUS_DISABLE_CHECKS
123   int generation; /**< _dbus_current_generation when message was created */
124 #endif
125
126 #ifdef HAVE_UNIX_FD_PASSING
127   int *unix_fds;
128   /**< Unix file descriptors associated with this message. These are
129      closed when the message is destroyed, hence make sure to dup()
130      them when adding or removing them here. */
131   unsigned n_unix_fds; /**< Number of valid fds in the array */
132   unsigned n_unix_fds_allocated; /**< Allocated size of the array */
133
134   long unix_fd_counter_delta; /**< Size we incremented the unix fd counter by */
135 #endif
136   DBusString *signature; /**< A placeholder for signature of received GVariant messages */
137   DBusString *unique_sender; /**< A placeholder for sender name of received GVariant messages */
138   size_t gvariant_body_last_offset; /**< Offset of end of last variable-sized element of body. */
139   size_t gvariant_body_last_pos; /**< Offset of last writing position. */
140 };
141
142 DBUS_PRIVATE_EXPORT
143 dbus_bool_t _dbus_message_iter_get_args_valist (DBusMessageIter *iter,
144                                                 DBusError       *error,
145                                                 int              first_arg_type,
146                                                 va_list          var_args);
147
148 /** @} */
149
150 DBUS_END_DECLS
151
152 #endif /* DBUS_MESSAGE_H */