93380ab97ed9eee05b82fbd11a9e836915672d63
[platform/upstream/dbus.git] / dbus / dbus-transport-protected.h
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)
3  *
4  * Copyright (C) 2002, 2004  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_TRANSPORT_PROTECTED_H
24 #define DBUS_TRANSPORT_PROTECTED_H
25
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-authorization.h>
31 #include <dbus/dbus-auth.h>
32 #include <dbus/dbus-resources.h>
33
34 DBUS_BEGIN_DECLS
35
36 typedef struct DBusTransportVTable DBusTransportVTable;
37
38 /**
39  * The virtual table that must be implemented to
40  * create a new kind of transport.
41  */
42 struct DBusTransportVTable
43 {
44   void        (* finalize)              (DBusTransport *transport);
45   /**< The finalize method must free the transport. */
46
47   dbus_bool_t (* handle_watch)          (DBusTransport *transport,
48                                          DBusWatch     *watch,
49                                          unsigned int   flags);
50   /**< The handle_watch method handles reading/writing
51    * data as indicated by the flags.
52    */
53
54   void        (* disconnect)            (DBusTransport *transport);
55   /**< Disconnect this transport. */
56
57   dbus_bool_t (* connection_set)        (DBusTransport *transport);
58   /**< Called when transport->connection has been filled in */
59
60   void        (* do_iteration)          (DBusTransport *transport,
61                                          unsigned int   flags,
62                                          int            timeout_milliseconds);
63   /**< Called to do a single "iteration" (block on select/poll
64    * followed by reading or writing data).
65    */
66
67   void        (* live_messages_changed) (DBusTransport *transport);
68   /**< Outstanding messages counter changed */
69
70   dbus_bool_t (* get_socket_fd) (DBusTransport *transport,
71                                  int           *fd_p);
72   /**< Get socket file descriptor */
73 };
74
75 /**
76  * Object representing a transport such as a socket.
77  * A transport can shuttle messages from point A to point B,
78  * and is the backend for a #DBusConnection.
79  *
80  */
81 struct DBusTransport
82 {
83   int refcount;                               /**< Reference count. */
84
85   const DBusTransportVTable *vtable;          /**< Virtual methods for this instance. */
86
87   DBusConnection *connection;                 /**< Connection owning this transport. */
88
89   DBusMessageLoader *loader;                  /**< Message-loading buffer. */
90
91   DBusAuth *auth;                             /**< Authentication conversation */
92   DBusAuthorization *authorization;           /**< Authorization conversation */
93
94   DBusCredentials *credentials;               /**< Credentials of other end read from the socket */  
95
96   long max_live_messages_size;                /**< Max total size of received messages. */
97   long max_live_messages_unix_fds;            /**< Max total unix fds of received messages. */
98
99   DBusCounter *live_messages;                 /**< Counter for size/unix fds of all live messages. */
100
101   char *address;                              /**< Address of the server we are connecting to (#NULL for the server side of a transport) */
102
103   char *expected_guid;                        /**< GUID we expect the server to have, #NULL on server side or if we don't have an expectation */
104   
105   unsigned int disconnected : 1;              /**< #TRUE if we are disconnected. */
106   unsigned int authenticated : 1;             /**< Cache of auth state; use _dbus_transport_peek_is_authenticated() to query value */
107   unsigned int send_credentials_pending : 1;  /**< #TRUE if we need to send credentials */
108   unsigned int receive_credentials_pending : 1; /**< #TRUE if we need to receive credentials */
109   unsigned int is_server : 1;                 /**< #TRUE if on the server side */
110   unsigned int unused_bytes_recovered : 1;    /**< #TRUE if we've recovered unused bytes from auth */
111 };
112
113 dbus_bool_t _dbus_transport_init_base     (DBusTransport             *transport,
114                                            const DBusTransportVTable *vtable,
115                                            const DBusString          *server_guid,
116                                            const DBusString          *address);
117 void        _dbus_transport_finalize_base (DBusTransport             *transport);
118
119
120 typedef enum
121 {
122   DBUS_TRANSPORT_OPEN_NOT_HANDLED,    /**< we aren't in charge of this address type */
123   DBUS_TRANSPORT_OPEN_OK,             /**< we set up the listen */
124   DBUS_TRANSPORT_OPEN_BAD_ADDRESS,    /**< malformed address */
125   DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT /**< well-formed address but failed to set it up */
126 } DBusTransportOpenResult;
127
128 DBusTransportOpenResult _dbus_transport_open_platform_specific (DBusAddressEntry  *entry,
129                                                                 DBusTransport    **transport_p,
130                                                                 DBusError         *error);
131
132 #define DBUS_TRANSPORT_CAN_SEND_UNIX_FD(x)      \
133   _dbus_auth_get_unix_fd_negotiated((x)->auth)
134
135 DBUS_END_DECLS
136
137 #endif /* DBUS_TRANSPORT_PROTECTED_H */