39 Server::Private::Private(DBusServer *s)
40 : server(s), auth_enabled(false), anon_enabled(false)
44 Server::Private::~Private()
48 void Server::Private::on_new_conn_cb(DBusServer *server, DBusConnection *conn,
void *data)
54 s->
_pvt->connections.push_back(nc);
58 if (s->
_pvt->auth_enabled)
59 dbus_connection_set_unix_user_function (conn, Private::on_unix_auth_cb, s, NULL);
61 if (s->
_pvt->anon_enabled)
62 dbus_connection_set_allow_anonymous (conn,
true);
64 debug_log(
"incoming connection 0x%08x", conn);
67 dbus_bool_t Server::Private::on_unix_auth_cb(DBusConnection *c,
unsigned long uid,
void *data)
74 Server::Server(
const char *address)
77 DBusServer *server = dbus_server_listen(address, e);
79 if (e)
throw Error(e);
81 debug_log(
"server 0x%08x listening on %s", server, address);
83 _pvt =
new Private(server);
85 dbus_server_set_new_connection_function(_pvt->server, Private::on_new_conn_cb,
this, NULL);
98 dbus_server_unref(_pvt->server);
103 debug_log(
"registering stubs for server %p", _pvt->server);
107 dbus_server_set_watch_functions(
109 Dispatcher::Private::on_add_watch,
110 Dispatcher::Private::on_rem_watch,
111 Dispatcher::Private::on_toggle_watch,
116 dbus_server_set_timeout_functions(
118 Dispatcher::Private::on_add_timeout,
119 Dispatcher::Private::on_rem_timeout,
120 Dispatcher::Private::on_toggle_timeout,
125 _pvt->dispatcher = dispatcher;
130 bool Server::operator == (
const Server &s)
const 132 return _pvt->server == s.
_pvt->server;
135 bool Server::listening()
const 137 return dbus_server_get_is_connected(_pvt->server);
139 void Server::disconnect()
141 dbus_server_disconnect(_pvt->server);
144 bool Server::on_user_auth(
unsigned long uid)
149 void Server::enable_auth(
bool enable)
151 _pvt->auth_enabled = enable;
154 void Server::enable_anon(
bool enable)
156 const char *anon_mech[] = {
"ANONYMOUS", 0};
157 const char *default_mech[] = {
"EXTERNAL",
"DBUS_COOKIE_SHA1",
"ANONYMOUS", 0};
158 const char **used_mech = default_mech;
161 used_mech = anon_mech;
163 if (!dbus_server_set_auth_mechanisms(_pvt->server, used_mech))
166 _pvt->anon_enabled = enable;
DXXAPI Dispatcher * default_dispatcher
virtual void on_new_connection(Connection &c)=0
DXXAPI LogFunction debug_log
virtual bool on_user_auth(unsigned long uid)