1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-transport-protected.h Used by subclasses of DBusTransport object (internal to D-Bus implementation)
4 * Copyright (C) 2002, 2004 Red Hat Inc.
6 * Licensed under the Academic Free License version 2.1
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #ifndef DBUS_TRANSPORT_PROTECTED_H
24 #define DBUS_TRANSPORT_PROTECTED_H
26 #include <dbus/dbus-internals.h>
27 #include <dbus/dbus-errors.h>
28 #include <dbus/dbus-transport.h>
29 #include <dbus/dbus-message-internal.h>
30 #include <dbus/dbus-auth.h>
31 #include <dbus/dbus-resources.h>
35 typedef struct DBusTransportVTable DBusTransportVTable;
38 * The virtual table that must be implemented to
39 * create a new kind of transport.
41 struct DBusTransportVTable
43 void (* finalize) (DBusTransport *transport);
44 /**< The finalize method must free the transport. */
46 dbus_bool_t (* handle_watch) (DBusTransport *transport,
49 /**< The handle_watch method handles reading/writing
50 * data as indicated by the flags.
53 void (* disconnect) (DBusTransport *transport);
54 /**< Disconnect this transport. */
56 dbus_bool_t (* connection_set) (DBusTransport *transport);
57 /**< Called when transport->connection has been filled in */
59 void (* do_iteration) (DBusTransport *transport,
61 int timeout_milliseconds);
62 /**< Called to do a single "iteration" (block on select/poll
63 * followed by reading or writing data).
66 void (* live_messages_changed) (DBusTransport *transport);
67 /**< Outstanding messages counter changed */
69 dbus_bool_t (* get_socket_fd) (DBusTransport *transport,
71 /**< Get socket file descriptor */
74 typedef dbus_bool_t (*DBusTransportGetUnixUserFunction) (DBusTransport *transport,
76 typedef dbus_bool_t (*DBusTransportGetUnixPIDFunction) (DBusTransport *transport,
78 typedef DBusMessage * (*DBusTransportSendSyncCallFunction) (DBusTransport *transport,
79 DBusMessage *message);
80 typedef dbus_bool_t (*DBusTransportAssureProtocolFunction) (DBusMessage **message);
82 * Object representing a transport such as a socket.
83 * A transport can shuttle messages from point A to point B,
84 * and is the backend for a #DBusConnection.
89 int refcount; /**< Reference count. */
91 const DBusTransportVTable *vtable; /**< Virtual methods for this instance. */
93 DBusConnection *connection; /**< Connection owning this transport. */
95 DBusMessageLoader *loader; /**< Message-loading buffer. */
97 DBusAuth *auth; /**< Authentication conversation */
99 DBusCredentials *credentials; /**< Credentials of other end read from the socket */
101 long max_live_messages_size; /**< Max total size of received messages. */
102 long max_live_messages_unix_fds; /**< Max total unix fds of received messages. */
104 DBusCounter *live_messages; /**< Counter for size/unix fds of all live messages. */
106 char *address; /**< Address of the server we are connecting to (#NULL for the server side of a transport) */
108 char *expected_guid; /**< GUID we expect the server to have, #NULL on server side or if we don't have an expectation */
110 DBusAllowUnixUserFunction unix_user_function; /**< Function for checking whether a user is authorized. */
111 void *unix_user_data; /**< Data for unix_user_function */
113 DBusFreeFunction free_unix_user_data; /**< Function to free unix_user_data */
115 DBusAllowWindowsUserFunction windows_user_function; /**< Function for checking whether a user is authorized. */
116 void *windows_user_data; /**< Data for windows_user_function */
118 DBusFreeFunction free_windows_user_data; /**< Function to free windows_user_data */
120 DBusTransportGetUnixUserFunction get_unix_user_function; /**< Function for getting Unix user ID */
121 DBusTransportGetUnixPIDFunction get_unix_process_id_function; /**< Function for getting Unix process ID */
122 DBusTransportAssureProtocolFunction assure_protocol_function; /**< Function for converting messages, if needed */
123 DBusTransportSendSyncCallFunction send_sync_call_function; /**< Function for sending synchronous calls */
124 int protocol; /**< type of protocol for this transport */
126 unsigned int disconnected : 1; /**< #TRUE if we are disconnected. */
127 unsigned int authenticated : 1; /**< Cache of auth state; use _dbus_transport_peek_is_authenticated() to query value */
128 unsigned int send_credentials_pending : 1; /**< #TRUE if we need to send credentials */
129 unsigned int receive_credentials_pending : 1; /**< #TRUE if we need to receive credentials */
130 unsigned int is_server : 1; /**< #TRUE if on the server side */
131 unsigned int unused_bytes_recovered : 1; /**< #TRUE if we've recovered unused bytes from auth */
132 unsigned int allow_anonymous : 1; /**< #TRUE if an anonymous client can connect */
133 unsigned int overflowed : 1; /**< #TRUE if last write didn't write all the data */
136 dbus_bool_t _dbus_transport_init_base (DBusTransport *transport,
137 const DBusTransportVTable *vtable,
138 const DBusString *server_guid,
139 const DBusString *address);
140 dbus_bool_t _dbus_transport_init_base_authenticated (DBusTransport *transport,
141 const DBusTransportVTable *vtable,
142 const DBusString *server_guid,
143 const DBusString *address);
144 void _dbus_transport_finalize_base (DBusTransport *transport);
146 void _dbus_transport_set_get_unix_user_function (DBusTransport *transport,
147 DBusTransportGetUnixUserFunction function);
148 void _dbus_transport_set_get_unix_process_id_function (DBusTransport *transport,
149 DBusTransportGetUnixPIDFunction function);
150 void _dbus_transport_set_send_sync_call_function (DBusTransport *transport,
151 DBusTransportSendSyncCallFunction function);
152 void _dbus_transport_set_assure_protocol_function (DBusTransport *transport,
153 DBusTransportAssureProtocolFunction function,
155 int _dbus_transport_get_protocol (DBusTransport *transport);
159 DBUS_TRANSPORT_OPEN_NOT_HANDLED, /**< we aren't in charge of this address type */
160 DBUS_TRANSPORT_OPEN_OK, /**< we set up the listen */
161 DBUS_TRANSPORT_OPEN_BAD_ADDRESS, /**< malformed address */
162 DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT /**< well-formed address but failed to set it up */
163 } DBusTransportOpenResult;
165 DBusTransportOpenResult _dbus_transport_open_platform_specific (DBusAddressEntry *entry,
166 DBusTransport **transport_p,
169 #define DBUS_TRANSPORT_CAN_SEND_UNIX_FD(x) \
170 _dbus_auth_get_unix_fd_negotiated((x)->auth)
174 #endif /* DBUS_TRANSPORT_PROTECTED_H */