2004-07-24 Havoc Pennington <hp@redhat.com>
[platform/upstream/dbus.git] / dbus / dbus-transport-protected.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-transport-protected.h Used by subclasses of DBusTransport object (internal to D-BUS implementation)
3  *
4  * Copyright (C) 2002  Red Hat Inc.
5  *
6  * Licensed under the Academic Free License version 2.0
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 <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>
32
33 DBUS_BEGIN_DECLS;
34
35 typedef struct DBusTransportVTable DBusTransportVTable;
36
37 /**
38  * The virtual table that must be implemented to
39  * create a new kind of transport.
40  */
41 struct DBusTransportVTable
42 {
43   void        (* finalize)              (DBusTransport *transport);
44   /**< The finalize method must free the transport. */
45
46   dbus_bool_t (* handle_watch)          (DBusTransport *transport,
47                                          DBusWatch     *watch,
48                                          unsigned int   flags);
49   /**< The handle_watch method handles reading/writing
50    * data as indicated by the flags.
51    */
52
53   void        (* disconnect)            (DBusTransport *transport);
54   /**< Disconnect this transport. */
55
56   dbus_bool_t (* connection_set)        (DBusTransport *transport);
57   /**< Called when transport->connection has been filled in */
58
59   void        (* messages_pending)      (DBusTransport *transport,
60                                          int            queue_length);
61   /**< Called when the outgoing message queue goes from empty
62    * to non-empty or vice versa.
63    */
64
65   void        (* do_iteration)          (DBusTransport *transport,
66                                          unsigned int   flags,
67                                          int            timeout_milliseconds);
68   /**< Called to do a single "iteration" (block on select/poll
69    * followed by reading or writing data).
70    */
71
72   void        (* live_messages_changed) (DBusTransport *transport);
73   /**< Outstanding messages counter changed */
74
75   dbus_bool_t (* get_unix_fd) (DBusTransport *transport,
76                                int           *fd_p);
77   /**< Get UNIX file descriptor */
78 };
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 */  
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 this server */
106   
107   DBusAllowUnixUserFunction unix_user_function; /**< Function for checking whether a user is authorized. */
108   void *unix_user_data;                         /**< Data for unix_user_function */
109   
110   DBusFreeFunction free_unix_user_data;         /**< Function to free unix_user_data */
111   
112   unsigned int disconnected : 1;              /**< #TRUE if we are disconnected. */
113   unsigned int authenticated : 1;             /**< Cache of auth state; use _dbus_transport_get_is_authenticated() to query value */
114   unsigned int messages_need_sending : 1;     /**< #TRUE if we need to write messages out */
115   unsigned int send_credentials_pending : 1;  /**< #TRUE if we need to send credentials */
116   unsigned int receive_credentials_pending : 1; /**< #TRUE if we need to receive credentials */
117   unsigned int is_server : 1;                 /**< #TRUE if on the server side */
118   unsigned int unused_bytes_recovered : 1;    /**< #TRUE if we've recovered unused bytes from auth */
119 };
120
121 dbus_bool_t _dbus_transport_init_base     (DBusTransport             *transport,
122                                            const DBusTransportVTable *vtable,
123                                            dbus_bool_t                server,
124                                            const DBusString          *address);
125 void        _dbus_transport_finalize_base (DBusTransport             *transport);
126
127
128
129 DBUS_END_DECLS;
130
131 #endif /* DBUS_TRANSPORT_PROTECTED_H */