8c389a6dbc73d13d673907c360881061fe23313a
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23 #ifndef DBUS_TRANSPORT_PROTECTED_H
24 #define DBUS_TRANSPORT_PROTECTED_H
25
26 #include <config.h>
27
28 #include <dbus/dbus-internals.h>
29 #include <dbus/dbus-errors.h>
30 #include <dbus/dbus-transport.h>
31 #include <dbus/dbus-message-internal.h>
32 #include <dbus/dbus-auth.h>
33 #include <dbus/dbus-resources.h>
34
35 DBUS_BEGIN_DECLS
36
37 typedef struct DBusTransportVTable DBusTransportVTable;
38
39 /**
40  * The virtual table that must be implemented to
41  * create a new kind of transport.
42  */
43 struct DBusTransportVTable
44 {
45   void        (* finalize)              (DBusTransport *transport);
46   /**< The finalize method must free the transport. */
47
48   dbus_bool_t (* handle_watch)          (DBusTransport *transport,
49                                          DBusWatch     *watch,
50                                          unsigned int   flags);
51   /**< The handle_watch method handles reading/writing
52    * data as indicated by the flags.
53    */
54
55   void        (* disconnect)            (DBusTransport *transport);
56   /**< Disconnect this transport. */
57
58   dbus_bool_t (* connection_set)        (DBusTransport *transport);
59   /**< Called when transport->connection has been filled in */
60
61   void        (* do_iteration)          (DBusTransport *transport,
62                                          unsigned int   flags,
63                                          int            timeout_milliseconds);
64   /**< Called to do a single "iteration" (block on select/poll
65    * followed by reading or writing data).
66    */
67
68   void        (* live_messages_changed) (DBusTransport *transport);
69   /**< Outstanding messages counter changed */
70
71   dbus_bool_t (* get_socket_fd) (DBusTransport *transport,
72                                  int           *fd_p);
73   /**< Get socket file descriptor */
74 };
75
76 /** How many unix file descriptors may be queued up before they are
77    handed off to messages */
78 #define DBUS_MAX_QUEUED_FDS 1024
79
80 /**
81  * Object representing a transport such as a socket.
82  * A transport can shuttle messages from point A to point B,
83  * and is the backend for a #DBusConnection.
84  *
85  */
86 struct DBusTransport
87 {
88   int refcount;                               /**< Reference count. */
89
90   const DBusTransportVTable *vtable;          /**< Virtual methods for this instance. */
91
92   DBusConnection *connection;                 /**< Connection owning this transport. */
93
94   DBusMessageLoader *loader;                  /**< Message-loading buffer. */
95
96   DBusAuth *auth;                             /**< Authentication conversation */
97
98   DBusCredentials *credentials;               /**< Credentials of other end read from the socket */  
99
100   long max_live_messages_size;                /**< Max total size of received messages. */
101
102   DBusCounter *live_messages_size;            /**< Counter for size of all live messages. */
103
104
105   char *address;                              /**< Address of the server we are connecting to (#NULL for the server side of a transport) */
106
107   char *expected_guid;                        /**< GUID we expect the server to have, #NULL on server side or if we don't have an expectation */
108   
109   DBusAllowUnixUserFunction unix_user_function; /**< Function for checking whether a user is authorized. */
110   void *unix_user_data;                         /**< Data for unix_user_function */
111   
112   DBusFreeFunction free_unix_user_data;         /**< Function to free unix_user_data */
113
114   DBusAllowWindowsUserFunction windows_user_function; /**< Function for checking whether a user is authorized. */
115   void *windows_user_data;                            /**< Data for windows_user_function */
116   
117   DBusFreeFunction free_windows_user_data;            /**< Function to free windows_user_data */
118   
119   unsigned int disconnected : 1;              /**< #TRUE if we are disconnected. */
120   unsigned int authenticated : 1;             /**< Cache of auth state; use _dbus_transport_get_is_authenticated() to query value */
121   unsigned int send_credentials_pending : 1;  /**< #TRUE if we need to send credentials */
122   unsigned int receive_credentials_pending : 1; /**< #TRUE if we need to receive credentials */
123   unsigned int is_server : 1;                 /**< #TRUE if on the server side */
124   unsigned int unused_bytes_recovered : 1;    /**< #TRUE if we've recovered unused bytes from auth */
125   unsigned int allow_anonymous : 1;           /**< #TRUE if an anonymous client can connect */
126 };
127
128 dbus_bool_t _dbus_transport_init_base     (DBusTransport             *transport,
129                                            const DBusTransportVTable *vtable,
130                                            const DBusString          *server_guid,
131                                            const DBusString          *address);
132 void        _dbus_transport_finalize_base (DBusTransport             *transport);
133
134
135 typedef enum
136 {
137   DBUS_TRANSPORT_OPEN_NOT_HANDLED,    /**< we aren't in charge of this address type */
138   DBUS_TRANSPORT_OPEN_OK,             /**< we set up the listen */
139   DBUS_TRANSPORT_OPEN_BAD_ADDRESS,    /**< malformed address */
140   DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT /**< well-formed address but failed to set it up */
141 } DBusTransportOpenResult;
142
143 DBusTransportOpenResult _dbus_transport_open_platform_specific (DBusAddressEntry  *entry,
144                                                                 DBusTransport    **transport_p,
145                                                                 DBusError         *error);
146
147 #define DBUS_TRANSPORT_CAN_SEND_UNIX_FD(x)      \
148   _dbus_auth_get_unix_fd_negotiated((x)->auth)
149
150 DBUS_END_DECLS
151
152 #endif /* DBUS_TRANSPORT_PROTECTED_H */