D-Bus 1.15.2
dbus-server-socket.c
1/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2/* dbus-server-socket.c Server implementation for sockets
3 *
4 * Copyright (C) 2002, 2003, 2004, 2006 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
24#include <config.h>
25#include "dbus-internals.h"
26#include "dbus-server-socket.h"
27#include "dbus-transport-socket.h"
28#include "dbus-connection-internal.h"
29#include "dbus-memory.h"
30#include "dbus-nonce.h"
31#include "dbus-string.h"
32
45
51{
53 int n_fds;
58};
59
60static void
61socket_finalize (DBusServer *server)
62{
63 DBusServerSocket *socket_server = (DBusServerSocket*) server;
64 int i;
65
67
68 for (i = 0 ; i < socket_server->n_fds ; i++)
69 if (socket_server->watch[i])
70 {
71 _dbus_watch_unref (socket_server->watch[i]);
72 socket_server->watch[i] = NULL;
73 }
74
75 dbus_free (socket_server->fds);
76 dbus_free (socket_server->watch);
77 dbus_free (socket_server->socket_name);
78 _dbus_noncefile_delete (&socket_server->noncefile, NULL);
79 dbus_free (server);
80}
81
82/* Return value is just for memory, not other failures. */
83static dbus_bool_t
84handle_new_client_fd_and_unlock (DBusServer *server,
85 DBusSocket client_fd)
86{
87 DBusConnection *connection;
88 DBusTransport *transport;
89 DBusNewConnectionFunction new_connection_function;
90 void *new_connection_data;
91
92 _dbus_verbose ("Creating new client connection with fd %" DBUS_SOCKET_FORMAT "\n",
93 _dbus_socket_printable (client_fd));
94
95 HAVE_LOCK_CHECK (server);
96
97 if (!_dbus_set_socket_nonblocking (client_fd, NULL))
98 {
99 SERVER_UNLOCK (server);
100 return TRUE;
101 }
102
103 transport = _dbus_transport_new_for_socket (client_fd, &server->guid_hex, NULL);
104 if (transport == NULL)
105 {
106 _dbus_close_socket (&client_fd, NULL);
107 SERVER_UNLOCK (server);
108 return FALSE;
109 }
110
112 (const char **) server->auth_mechanisms))
113 {
114 _dbus_transport_unref (transport);
115 SERVER_UNLOCK (server);
116 return FALSE;
117 }
118
119 /* note that client_fd is now owned by the transport, and will be
120 * closed on transport disconnection/finalization
121 */
122
123 connection = _dbus_connection_new_for_transport (transport);
124 _dbus_transport_unref (transport);
125 transport = NULL; /* now under the connection lock */
126
127 if (connection == NULL)
128 {
129 SERVER_UNLOCK (server);
130 return FALSE;
131 }
132
133 /* See if someone wants to handle this new connection, self-referencing
134 * for paranoia.
135 */
136 new_connection_function = server->new_connection_function;
137 new_connection_data = server->new_connection_data;
138
140 SERVER_UNLOCK (server);
141
142 if (new_connection_function)
143 {
144 (* new_connection_function) (server, connection,
145 new_connection_data);
146 }
147 dbus_server_unref (server);
148
149 /* If no one grabbed a reference, the connection will die. */
151 dbus_connection_unref (connection);
152
153 return TRUE;
154}
155
156static dbus_bool_t
157socket_handle_watch (DBusWatch *watch,
158 unsigned int flags,
159 void *data)
160{
161 DBusServer *server = data;
162 DBusServerSocket *socket_server = data;
163
164#ifndef DBUS_DISABLE_ASSERT
165 int i;
166 dbus_bool_t found = FALSE;
167#endif
168
169 SERVER_LOCK (server);
170
171#ifndef DBUS_DISABLE_ASSERT
172 for (i = 0 ; i < socket_server->n_fds ; i++)
173 {
174 if (socket_server->watch[i] == watch)
175 found = TRUE;
176 }
177 _dbus_assert (found);
178#endif
179
180 _dbus_verbose ("Handling client connection, flags 0x%x\n", flags);
181
182 if (flags & DBUS_WATCH_READABLE)
183 {
184 DBusSocket client_fd;
185 DBusSocket listen_fd;
186 int saved_errno;
187
188 listen_fd = _dbus_watch_get_socket (watch);
189
190 if (socket_server->noncefile)
191 client_fd = _dbus_accept_with_noncefile (listen_fd, socket_server->noncefile);
192 else
193 client_fd = _dbus_accept (listen_fd);
194
195 saved_errno = _dbus_save_socket_errno ();
196
197 if (!_dbus_socket_is_valid (client_fd))
198 {
199 /* EINTR handled for us */
200
202 _dbus_verbose ("No client available to accept after all\n");
203 else
204 _dbus_verbose ("Failed to accept a client connection: %s\n",
205 _dbus_strerror (saved_errno));
206
207 SERVER_UNLOCK (server);
208 }
209 else
210 {
211 if (!handle_new_client_fd_and_unlock (server, client_fd))
212 _dbus_verbose ("Rejected client connection due to lack of memory\n");
213 }
214 }
215
216 if (flags & DBUS_WATCH_ERROR)
217 _dbus_verbose ("Error on server listening socket\n");
218
219 if (flags & DBUS_WATCH_HANGUP)
220 _dbus_verbose ("Hangup on server listening socket\n");
221
222 return TRUE;
223}
224
225static void
226socket_disconnect (DBusServer *server)
227{
228 DBusServerSocket *socket_server = (DBusServerSocket*) server;
229 int i;
230
231 HAVE_LOCK_CHECK (server);
232
233 for (i = 0 ; i < socket_server->n_fds ; i++)
234 {
235 if (socket_server->watch[i])
236 {
238 socket_server->watch[i]);
239 _dbus_watch_invalidate (socket_server->watch[i]);
240 _dbus_watch_unref (socket_server->watch[i]);
241 socket_server->watch[i] = NULL;
242 }
243
244 if (_dbus_socket_is_valid (socket_server->fds[i]))
245 _dbus_close_socket (&socket_server->fds[i], NULL);
246 }
247
248 if (socket_server->socket_name != NULL)
249 {
250 DBusString tmp;
251 _dbus_string_init_const (&tmp, socket_server->socket_name);
252 _dbus_delete_file (&tmp, NULL);
253 }
254
255 if (server->published_address)
256 _dbus_daemon_unpublish_session_bus_address();
257
258 HAVE_LOCK_CHECK (server);
259}
260
261static const DBusServerVTable socket_vtable = {
262 socket_finalize,
263 socket_disconnect
264};
265
284 int n_fds,
285 const DBusString *address,
286 DBusNonceFile *noncefile,
287 DBusError *error)
288{
289 DBusServerSocket *socket_server;
290 DBusServer *server;
291 int i;
292
293 socket_server = dbus_new0 (DBusServerSocket, 1);
294 if (socket_server == NULL)
295 goto failed;
296
297 socket_server->noncefile = noncefile;
298
299 socket_server->fds = dbus_new (DBusSocket, n_fds);
300 if (!socket_server->fds)
301 goto failed;
302
303 socket_server->watch = dbus_new0 (DBusWatch *, n_fds);
304 if (!socket_server->watch)
305 goto failed;
306
307 for (i = 0 ; i < n_fds ; i++)
308 {
309 DBusWatch *watch;
310
311 watch = _dbus_watch_new (_dbus_socket_get_pollable (fds[i]),
313 TRUE,
314 socket_handle_watch, socket_server,
315 NULL);
316 if (watch == NULL)
317 goto failed;
318
319 socket_server->n_fds++;
320 socket_server->fds[i] = fds[i];
321 socket_server->watch[i] = watch;
322 }
323
324 if (!_dbus_server_init_base (&socket_server->base,
325 &socket_vtable, address,
326 error))
327 goto failed;
328
329 server = (DBusServer*)socket_server;
330
331 SERVER_LOCK (server);
332
333 for (i = 0 ; i < n_fds ; i++)
334 {
335 if (!_dbus_server_add_watch (&socket_server->base,
336 socket_server->watch[i]))
337 {
338 int j;
339
340 /* The caller is still responsible for closing the fds until
341 * we return successfully, so don't let socket_disconnect()
342 * close them */
343 for (j = 0; j < n_fds; j++)
344 _dbus_socket_invalidate (&socket_server->fds[j]);
345
346 /* socket_disconnect() will try to remove all the watches;
347 * make sure it doesn't see the ones that weren't even added
348 * yet */
349 for (j = i; j < n_fds; j++)
350 {
351 _dbus_watch_invalidate (socket_server->watch[j]);
352 _dbus_watch_unref (socket_server->watch[j]);
353 socket_server->watch[j] = NULL;
354 }
355
356 _dbus_server_disconnect_unlocked (server);
357 SERVER_UNLOCK (server);
358 _dbus_server_finalize_base (&socket_server->base);
359 goto failed;
360 }
361 }
362
363 SERVER_UNLOCK (server);
364
365 _dbus_server_trace_ref (&socket_server->base, 0, 1, "new_for_socket");
366 return (DBusServer*) socket_server;
367
368failed:
369 if (socket_server != NULL)
370 {
371 if (socket_server->watch != NULL)
372 {
373 for (i = 0; i < n_fds; i++)
374 {
375 if (socket_server->watch[i] != NULL)
376 {
377 _dbus_watch_invalidate (socket_server->watch[i]);
378 _dbus_watch_unref (socket_server->watch[i]);
379 socket_server->watch[i] = NULL;
380 }
381 }
382 }
383
384 dbus_free (socket_server->watch);
385 dbus_free (socket_server->fds);
386 dbus_free (socket_server);
387 }
388
389 if (error != NULL && !dbus_error_is_set (error))
390 _DBUS_SET_OOM (error);
391
392 return NULL;
393}
394
416 const char *bind,
417 const char *port,
418 const char *family,
419 DBusError *error,
420 dbus_bool_t use_nonce)
421{
422 DBusServer *server = NULL;
423 DBusSocket *listen_fds = NULL;
424 int nlisten_fds = 0, i;
425 DBusString address = _DBUS_STRING_INIT_INVALID;
426 DBusString host_str; /* Initialized as const later, not freed */
427 DBusString port_str = _DBUS_STRING_INIT_INVALID;
428 DBusNonceFile *noncefile = NULL;
429 const char *family_used = NULL;
430
431 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
432
433 if (!_dbus_string_init (&address))
434 {
436 goto failed;
437 }
438
439 if (!_dbus_string_init (&port_str))
440 {
442 goto failed;
443 }
444
445 if (host == NULL)
446 host = "localhost";
447
448 if (port == NULL)
449 port = "0";
450
451 if (bind == NULL)
452 bind = host;
453 else if (strcmp (bind, "*") == 0)
454 bind = NULL;
455
456 nlisten_fds =_dbus_listen_tcp_socket (bind, port, family,
457 &port_str,
458 &family_used,
459 &listen_fds, error);
460 if (nlisten_fds <= 0)
461 {
462 _DBUS_ASSERT_ERROR_IS_SET(error);
463 goto failed;
464 }
465
466 _dbus_string_init_const (&host_str, host);
467 if (!_dbus_string_append (&address, use_nonce ? "nonce-tcp:host=" : "tcp:host=") ||
468 !_dbus_address_append_escaped (&address, &host_str) ||
469 !_dbus_string_append (&address, ",port=") ||
470 !_dbus_string_append (&address, _dbus_string_get_const_data(&port_str)))
471 {
473 goto failed;
474 }
475 if (family_used &&
476 (!_dbus_string_append (&address, ",family=") ||
477 !_dbus_string_append (&address, family_used)))
478 {
480 goto failed;
481 }
482
483 if (use_nonce)
484 {
485 if (!_dbus_noncefile_create (&noncefile, error))
486 goto failed;
487
488 if (!_dbus_string_append (&address, ",noncefile=") ||
489 !_dbus_address_append_escaped (&address, _dbus_noncefile_get_path (noncefile)))
490 {
492 goto failed;
493 }
494 }
495
496 server = _dbus_server_new_for_socket (listen_fds, nlisten_fds, &address, noncefile, error);
497 if (server == NULL)
498 goto failed;
499
500 /* server has taken ownership of noncefile and the fds in listen_fds */
501 _dbus_string_free (&port_str);
502 _dbus_string_free (&address);
503 dbus_free(listen_fds);
504
505 return server;
506
507failed:
508 _dbus_noncefile_delete (&noncefile, NULL);
509
510 if (listen_fds != NULL)
511 {
512 for (i = 0; i < nlisten_fds; i++)
513 _dbus_close_socket (&listen_fds[i], NULL);
514 dbus_free (listen_fds);
515 }
516
517 _dbus_string_free (&port_str);
518 _dbus_string_free (&address);
519 return NULL;
520}
521
534DBusServerListenResult
536 DBusServer **server_p,
537 DBusError *error)
538{
539 const char *method;
540
541 *server_p = NULL;
542
543 method = dbus_address_entry_get_method (entry);
544
545 if (strcmp (method, "tcp") == 0 || strcmp (method, "nonce-tcp") == 0)
546 {
547 const char *host;
548 const char *port;
549 const char *bind;
550 const char *family;
551
552 host = dbus_address_entry_get_value (entry, "host");
553 bind = dbus_address_entry_get_value (entry, "bind");
554 port = dbus_address_entry_get_value (entry, "port");
555 family = dbus_address_entry_get_value (entry, "family");
556
557 *server_p = _dbus_server_new_for_tcp_socket (host, bind, port,
558 family, error, strcmp (method, "nonce-tcp") == 0 ? TRUE : FALSE);
559
560 if (*server_p)
561 {
562 _DBUS_ASSERT_ERROR_IS_CLEAR(error);
563 return DBUS_SERVER_LISTEN_OK;
564 }
565 else
566 {
567 _DBUS_ASSERT_ERROR_IS_SET(error);
568 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
569 }
570 }
571 else
572 {
573 _DBUS_ASSERT_ERROR_IS_CLEAR(error);
574 return DBUS_SERVER_LISTEN_NOT_HANDLED;
575 }
576}
577
587void
589 char *filename)
590{
591 DBusServerSocket *socket_server = (DBusServerSocket*) server;
592
593 socket_server->socket_name = filename;
594}
595
606 dbus_bool_t abstract,
607 DBusError *error)
608{
609 DBusServer *server;
610 DBusSocket listen_fd;
611 DBusString address;
612 char *path_copy;
613 DBusString path_str;
614
615 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
616
617 if (!_dbus_string_init (&address))
618 {
620 return NULL;
621 }
622
623 _dbus_string_init_const (&path_str, path);
624 if ((abstract &&
625 !_dbus_string_append (&address, "unix:abstract=")) ||
626 (!abstract &&
627 !_dbus_string_append (&address, "unix:path=")) ||
628 !_dbus_address_append_escaped (&address, &path_str))
629 {
631 goto failed_0;
632 }
633
634 if (abstract)
635 {
636 path_copy = NULL;
637 }
638 else
639 {
640 path_copy = _dbus_strdup (path);
641 if (path_copy == NULL)
642 {
644 goto failed_0;
645 }
646 }
647
648 listen_fd = _dbus_listen_unix_socket (path, abstract, error);
649
650 if (!_dbus_socket_is_valid (listen_fd))
651 {
652 _DBUS_ASSERT_ERROR_IS_SET (error);
653 goto failed_1;
654 }
655
656 server = _dbus_server_new_for_socket (&listen_fd, 1, &address, 0, error);
657 if (server == NULL)
658 {
659 goto failed_2;
660 }
661
662 if (path_copy != NULL)
663 _dbus_server_socket_own_filename(server, path_copy);
664
665 _dbus_string_free (&address);
666
667 return server;
668
669 failed_2:
670 _dbus_close_socket (&listen_fd, NULL);
671 failed_1:
672 dbus_free (path_copy);
673 failed_0:
674 _dbus_string_free (&address);
675
676 return NULL;
677}
678
687static DBusServer *
688_dbus_server_new_for_dir (const char *dir,
689 DBusError *error)
690{
691 DBusServer *server;
692 DBusString full_path;
693 DBusString filename;
694
695 if (!_dbus_string_init (&full_path))
696 {
698 return NULL;
699 }
700
701 if (!_dbus_string_init (&filename))
702 {
703 _dbus_string_free (&full_path);
705 return NULL;
706 }
707
708 if (!_dbus_string_append (&filename, "dbus-"))
709 {
710 _dbus_string_free (&full_path);
711 _dbus_string_free (&filename);
713 return NULL;
714 }
715
716 if (!_dbus_generate_random_ascii (&filename, 10, error))
717 {
718 _dbus_string_free (&full_path);
719 _dbus_string_free (&filename);
720 return NULL;
721 }
722
723 if (!_dbus_string_append (&full_path, dir) ||
724 !_dbus_concat_dir_and_file (&full_path, &filename))
725 {
726 _dbus_string_free (&full_path);
727 _dbus_string_free (&filename);
729 return NULL;
730 }
731
732 server =
734 FALSE, /* not abstract */
735 error);
736
737 _dbus_string_free (&full_path);
738 _dbus_string_free (&filename);
739
740 return server;
741}
742
755DBusServerListenResult
757 DBusServer **server_p,
758 DBusError *error)
759{
760 const char *method;
761
762 *server_p = NULL;
763
764 method = dbus_address_entry_get_method (entry);
765
766 if (strcmp (method, "unix") == 0)
767 {
768 const char *path = dbus_address_entry_get_value (entry, "path");
769 const char *dir = dbus_address_entry_get_value (entry, "dir");
770 const char *tmpdir = dbus_address_entry_get_value (entry, "tmpdir");
771 const char *abstract = dbus_address_entry_get_value (entry, "abstract");
772 const char *runtime = dbus_address_entry_get_value (entry, "runtime");
773 int mutually_exclusive_modes = 0;
774
775 mutually_exclusive_modes = (path != NULL) + (tmpdir != NULL) +
776 (abstract != NULL) + (runtime != NULL) + (dir != NULL);
777
778 if (mutually_exclusive_modes < 1)
779 {
780 _dbus_set_bad_address(error, "unix",
781 "path or tmpdir or abstract or runtime or dir",
782 NULL);
783 return DBUS_SERVER_LISTEN_BAD_ADDRESS;
784 }
785
786 if (mutually_exclusive_modes > 1)
787 {
789 "cannot specify two of \"path\", \"tmpdir\", \"abstract\", \"runtime\" and \"dir\" at the same time");
790 return DBUS_SERVER_LISTEN_BAD_ADDRESS;
791 }
792
793 if (runtime != NULL)
794 {
795 DBusString full_path;
796 DBusString filename;
797 const char *runtimedir;
798
799 if (strcmp (runtime, "yes") != 0)
800 {
802 "if given, the only value allowed for \"runtime\" is \"yes\"");
803 return DBUS_SERVER_LISTEN_BAD_ADDRESS;
804 }
805
806 runtimedir = _dbus_getenv ("XDG_RUNTIME_DIR");
807
808 if (runtimedir == NULL)
809 {
810 dbus_set_error (error,
811 DBUS_ERROR_NOT_SUPPORTED, "\"XDG_RUNTIME_DIR\" is not set");
812 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
813 }
814
815 _dbus_string_init_const (&filename, "bus");
816
817 if (!_dbus_string_init (&full_path))
818 {
819 _DBUS_SET_OOM (error);
820 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
821 }
822
823 if (!_dbus_string_append (&full_path, runtimedir) ||
824 !_dbus_concat_dir_and_file (&full_path, &filename))
825 {
826 _dbus_string_free (&full_path);
827 _DBUS_SET_OOM (error);
828 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
829 }
830
831 /* We can safely use filesystem sockets in the runtime directory,
832 * and they are preferred because they can be bind-mounted between
833 * Linux containers. */
835 _dbus_string_get_const_data (&full_path),
836 FALSE, error);
837
838 _dbus_string_free (&full_path);
839 }
840 else if (tmpdir != NULL || dir != NULL)
841 {
842 /* tmpdir is now equivalent to dir. Previously it would try to
843 * use an abstract socket. */
844 if (tmpdir != NULL)
845 dir = tmpdir;
846
847 *server_p = _dbus_server_new_for_dir (dir, error);
848 }
849 else
850 {
851 if (path)
852 *server_p = _dbus_server_new_for_domain_socket (path, FALSE, error);
853 else
854 *server_p = _dbus_server_new_for_domain_socket (abstract, TRUE, error);
855 }
856
857 if (*server_p != NULL)
858 {
859 _DBUS_ASSERT_ERROR_IS_CLEAR(error);
860 return DBUS_SERVER_LISTEN_OK;
861 }
862 else
863 {
864 _DBUS_ASSERT_ERROR_IS_SET(error);
865 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
866 }
867 }
868 else
869 {
870 /* If we don't handle the method, we return NULL with the
871 * error unset
872 */
873 _DBUS_ASSERT_ERROR_IS_CLEAR(error);
874 return DBUS_SERVER_LISTEN_NOT_HANDLED;
875 }
876}
877
878
dbus_bool_t _dbus_address_append_escaped(DBusString *escaped, const DBusString *unescaped)
Appends an escaped version of one string to another string, using the D-Bus address escaping mechanis...
Definition: dbus-address.c:107
void _dbus_set_bad_address(DBusError *error, const char *address_problem_type, const char *address_problem_field, const char *address_problem_other)
Sets DBUS_ERROR_BAD_ADDRESS.
Definition: dbus-address.c:68
const char * dbus_address_entry_get_method(DBusAddressEntry *entry)
Returns the method string of an address entry.
Definition: dbus-address.c:230
const char * dbus_address_entry_get_value(DBusAddressEntry *entry, const char *key)
Returns a value from a key of an entry.
Definition: dbus-address.c:247
DBusConnection * _dbus_connection_new_for_transport(DBusTransport *transport)
Creates a new connection for the given transport.
void _dbus_connection_close_if_only_one_ref(DBusConnection *connection)
Used internally to handle the semantics of dbus_server_set_new_connection_function().
void dbus_connection_unref(DBusConnection *connection)
Decrements the reference count of a DBusConnection, and finalizes it if the count reaches zero.
@ DBUS_WATCH_READABLE
As in POLLIN.
@ DBUS_WATCH_HANGUP
As in POLLHUP (can't watch for it, but can be present in current state passed to dbus_watch_handle())...
@ DBUS_WATCH_ERROR
As in POLLERR (can't watch for this, but can be present in current state passed to dbus_watch_handle(...
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
Definition: dbus-errors.c:354
dbus_bool_t dbus_error_is_set(const DBusError *error)
Checks whether an error occurred (the error is set).
Definition: dbus-errors.c:329
dbus_bool_t _dbus_delete_file(const DBusString *filename, DBusError *error)
Deletes the given file.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
char * _dbus_strdup(const char *str)
Duplicates a string.
dbus_bool_t _dbus_generate_random_ascii(DBusString *str, int n_bytes, DBusError *error)
Generates the given number of random bytes, where the bytes are chosen from the alphanumeric ASCII su...
Definition: dbus-sysdeps.c:559
#define NULL
A null pointer, defined appropriately for C or C++.
#define TRUE
Expands to "1".
#define FALSE
Expands to "0".
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
Definition: dbus-memory.c:692
#define dbus_new(type, count)
Safe macro for using dbus_malloc().
Definition: dbus-memory.h:57
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
Definition: dbus-memory.h:58
#define DBUS_ERROR_NOT_SUPPORTED
Requested operation isn't supported (like ENOSYS on UNIX).
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
dbus_bool_t _dbus_server_add_watch(DBusServer *server, DBusWatch *watch)
Adds a watch for this server, chaining out to application-provided watch handlers.
Definition: dbus-server.c:295
void _dbus_server_remove_watch(DBusServer *server, DBusWatch *watch)
Removes a watch previously added with _dbus_server_remove_watch().
Definition: dbus-server.c:311
dbus_bool_t _dbus_server_init_base(DBusServer *server, const DBusServerVTable *vtable, const DBusString *address, DBusError *error)
Initializes the members of the DBusServer base class.
Definition: dbus-server.c:111
void _dbus_server_finalize_base(DBusServer *server)
Finalizes the members of the DBusServer base class.
Definition: dbus-server.c:200
DBUS_PRIVATE_EXPORT void _dbus_server_ref_unlocked(DBusServer *server)
Like dbus_server_ref() but does not acquire the lock (must already be held)
Definition: dbus-server.c:455
DBusServer * _dbus_server_new_for_domain_socket(const char *path, dbus_bool_t abstract, DBusError *error)
Creates a new server listening on the given Unix domain socket.
DBusServer * _dbus_server_new_for_tcp_socket(const char *host, const char *bind, const char *port, const char *family, DBusError *error, dbus_bool_t use_nonce)
Creates a new server listening on TCP.
DBusServer * _dbus_server_new_for_socket(DBusSocket *fds, int n_fds, const DBusString *address, DBusNonceFile *noncefile, DBusError *error)
Creates a new server listening on the given file descriptor.
DBusServerListenResult _dbus_server_listen_socket(DBusAddressEntry *entry, DBusServer **server_p, DBusError *error)
Tries to interpret the address entry for various socket-related addresses (well, currently only tcp a...
DBusServerListenResult _dbus_server_listen_unix_socket(DBusAddressEntry *entry, DBusServer **server_p, DBusError *error)
Tries to interpret the address entry for UNIX socket addresses.
void _dbus_server_socket_own_filename(DBusServer *server, char *filename)
This is a bad hack since it's really unix domain socket specific.
void dbus_server_unref(DBusServer *server)
Decrements the reference count of a DBusServer.
Definition: dbus-server.c:733
void(* DBusNewConnectionFunction)(DBusServer *server, DBusConnection *new_connection, void *data)
Called when a new connection to the server is available.
Definition: dbus-server.h:48
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
Definition: dbus-string.c:978
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition: dbus-string.c:180
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
Definition: dbus-string.c:195
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as #_DBUS_STRING_I...
Definition: dbus-string.c:276
const char * _dbus_string_get_const_data(const DBusString *str)
Gets the raw character buffer from a const string.
Definition: dbus-string.c:511
dbus_bool_t _dbus_get_is_errno_eagain_or_ewouldblock(int e)
See if errno is EAGAIN or EWOULDBLOCK (this has to be done differently for Winsock so is abstracted)
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
Definition: dbus-sysdeps.c:195
DBusSocket _dbus_listen_unix_socket(const char *path, dbus_bool_t abstract, DBusError *error)
Creates a socket and binds it to the given path, then listens on the socket.
dbus_bool_t _dbus_set_socket_nonblocking(DBusSocket fd, DBusError *error)
Sets a file descriptor to be nonblocking.
int _dbus_listen_tcp_socket(const char *host, const char *port, const char *family, DBusString *retport, const char **retfamily, DBusSocket **fds_p, DBusError *error)
Creates a socket and binds it to the given path, then listens on the socket.
dbus_bool_t _dbus_close_socket(DBusSocket *fd, DBusError *error)
Closes a socket and invalidates it.
dbus_bool_t _dbus_concat_dir_and_file(DBusString *dir, const DBusString *next_component)
Appends the given filename to the given directory.
DBusSocket _dbus_accept(DBusSocket listen_fd)
Accepts a connection on a listening socket.
DBusTransport * _dbus_transport_new_for_socket(DBusSocket fd, const DBusString *server_guid, const DBusString *address)
Creates a new transport for the given socket file descriptor.
dbus_bool_t _dbus_transport_set_auth_mechanisms(DBusTransport *transport, const char **mechanisms)
Sets the SASL authentication mechanisms supported by this transport.
void _dbus_transport_unref(DBusTransport *transport)
Decrements the reference count for the transport.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:35
DBusWatch * _dbus_watch_new(DBusPollable fd, unsigned int flags, dbus_bool_t enabled, DBusWatchHandler handler, void *data, DBusFreeFunction free_data_function)
Creates a new DBusWatch.
Definition: dbus-watch.c:88
void _dbus_watch_unref(DBusWatch *watch)
Decrements the reference count of a DBusWatch object and finalizes the object if the count reaches ze...
Definition: dbus-watch.c:138
void _dbus_watch_invalidate(DBusWatch *watch)
Clears the file descriptor from a now-invalid watch object so that no one tries to use it.
Definition: dbus-watch.c:169
Internals of DBusAddressEntry.
Definition: dbus-address.c:47
Implementation details of DBusConnection.
Object representing an exception.
Definition: dbus-errors.h:49
Implementation details of DBusServerSocket.
int n_fds
Number of active file handles.
DBusSocket * fds
File descriptor or DBUS_SOCKET_INVALID if disconnected.
DBusNonceFile * noncefile
Nonce file used to authenticate clients.
DBusWatch ** watch
File descriptor watch.
DBusServer base
Parent class members.
char * socket_name
Name of domain socket, to unlink if appropriate.
Virtual table to be implemented by all server "subclasses".
Internals of DBusServer object.
dbus_bool_t published_address
flag which indicates that server has published its bus address.
DBusString guid_hex
Hex-encoded version of GUID.
DBusNewConnectionFunction new_connection_function
Callback to invoke when a new connection is created.
void * new_connection_data
Data for new connection callback.
char ** auth_mechanisms
Array of allowed authentication mechanisms.
Socket interface.
Definition: dbus-sysdeps.h:179
Object representing a transport such as a socket.
Implementation of DBusWatch.
Definition: dbus-watch.c:41