Convert miscellaneous socket APIs to DBusSocket

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89444
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
This commit is contained in:
Simon McVittie 2015-03-12 18:35:48 +00:00
parent bbbd79b6ea
commit 68d8c66680
9 changed files with 58 additions and 51 deletions

View file

@ -31,7 +31,7 @@
#include <stdio.h>
static dbus_bool_t
do_check_nonce (int fd, const DBusString *nonce, DBusError *error)
do_check_nonce (DBusSocket fd, const DBusString *nonce, DBusError *error)
{
DBusString buffer;
DBusString p;
@ -156,17 +156,17 @@ _dbus_accept_with_noncefile (DBusSocket listen_fd, const DBusNonceFile *noncefil
_dbus_assert (noncefile != NULL);
if (!_dbus_string_init (&nonce))
return -1;
return _dbus_socket_get_invalid ();
//PENDING(kdab): set better errors
if (_dbus_read_nonce (_dbus_noncefile_get_path(noncefile), &nonce, NULL) != TRUE)
return -1;
return _dbus_socket_get_invalid ();
fd = _dbus_accept (listen_fd);
if (_dbus_socket_is_invalid (fd))
if (!DBUS_SOCKET_IS_VALID (fd))
return fd;
if (do_check_nonce(fd, &nonce, NULL) != TRUE) {
_dbus_verbose ("nonce check failed. Closing socket.\n");
_dbus_close_socket(fd, NULL);
return -1;
return _dbus_socket_get_invalid ();
}
return fd;
@ -210,7 +210,9 @@ generate_and_write_nonce (const DBusString *filename, DBusError *error)
* indicate whether the server accepted the nonce.
*/
dbus_bool_t
_dbus_send_nonce (int fd, const DBusString *noncefile, DBusError *error)
_dbus_send_nonce (DBusSocket fd,
const DBusString *noncefile,
DBusError *error)
{
dbus_bool_t read_result;
int send_result;

View file

@ -64,7 +64,7 @@ dbus_bool_t _dbus_read_nonce (const DBusString *fname,
// client
dbus_bool_t _dbus_send_nonce (int fd,
dbus_bool_t _dbus_send_nonce (DBusSocket fd,
const DBusString *noncefile,
DBusError *error);

View file

@ -267,7 +267,7 @@ _dbus_transport_debug_pipe_new (const char *server_name,
_dbus_string_free (&address);
client_fd = -1;
DBUS_SOCKET_INVALIDATE (client_fd);
server_transport = _dbus_transport_new_for_socket (server_fd,
&server->guid_hex, NULL);
@ -279,7 +279,7 @@ _dbus_transport_debug_pipe_new (const char *server_name,
return NULL;
}
server_fd = -1;
DBUS_SOCKET_INVALIDATE (server_fd);
if (!_dbus_transport_set_auth_mechanisms (server_transport,
(const char**) server->auth_mechanisms))

View file

@ -84,14 +84,15 @@ socket_finalize (DBusServer *server)
/* Return value is just for memory, not other failures. */
static dbus_bool_t
handle_new_client_fd_and_unlock (DBusServer *server,
int client_fd)
DBusSocket client_fd)
{
DBusConnection *connection;
DBusTransport *transport;
DBusNewConnectionFunction new_connection_function;
void *new_connection_data;
_dbus_verbose ("Creating new client connection with fd %d\n", client_fd);
_dbus_verbose ("Creating new client connection with fd %" DBUS_SOCKET_FORMAT "\n",
DBUS_SOCKET_PRINTABLE (client_fd));
HAVE_LOCK_CHECK (server);
@ -195,7 +196,7 @@ socket_handle_watch (DBusWatch *watch,
saved_errno = _dbus_save_socket_errno ();
if (client_fd == DBUS_SOCKET_INVALID)
if (!DBUS_SOCKET_IS_VALID (client_fd))
{
/* EINTR handled for us */
@ -243,7 +244,7 @@ socket_disconnect (DBusServer *server)
}
_dbus_close_socket (socket_server->fds[i], NULL);
socket_server->fds[i] = DBUS_SOCKET_INVALID;
DBUS_SOCKET_INVALIDATE (socket_server->fds[i]);
}
if (socket_server->socket_name != NULL)

View file

@ -199,7 +199,8 @@ _dbus_server_listen_platform_specific (DBusAddressEntry *entry,
}
else if (strcmp (method, "systemd") == 0)
{
int i, n, *fds;
int i, n;
DBusSocket *fds;
DBusString address;
n = _dbus_listen_systemd_sockets (&fds, error);

View file

@ -205,7 +205,7 @@ _dbus_open_unix_socket (int *fd,
* @returns #FALSE if error is set
*/
dbus_bool_t
_dbus_close_socket (int fd,
_dbus_close_socket (DBusSocket fd,
DBusError *error)
{
return _dbus_close (fd, error);
@ -221,7 +221,7 @@ _dbus_close_socket (int fd,
* @returns number of bytes appended to the string
*/
int
_dbus_read_socket (int fd,
_dbus_read_socket (DBusSocket fd,
DBusString *buffer,
int count)
{
@ -239,7 +239,7 @@ _dbus_read_socket (int fd,
* @returns the number of bytes written or -1 on error
*/
int
_dbus_write_socket (int fd,
_dbus_write_socket (DBusSocket fd,
const DBusString *buffer,
int start,
int len)
@ -437,7 +437,7 @@ _dbus_read_socket_with_unix_fds (DBusSocket fd,
}
int
_dbus_write_socket_with_unix_fds(int fd,
_dbus_write_socket_with_unix_fds(DBusSocket fd,
const DBusString *buffer,
int start,
int len,
@ -458,7 +458,7 @@ _dbus_write_socket_with_unix_fds(int fd,
}
int
_dbus_write_socket_with_unix_fds_two(int fd,
_dbus_write_socket_with_unix_fds_two(DBusSocket fd,
const DBusString *buffer1,
int start1,
int len1,
@ -550,7 +550,7 @@ _dbus_write_socket_with_unix_fds_two(int fd,
* @returns total bytes written from both buffers, or -1 on error
*/
int
_dbus_write_socket_two (int fd,
_dbus_write_socket_two (DBusSocket fd,
const DBusString *buffer1,
int start1,
int len1,
@ -1163,13 +1163,13 @@ _dbus_listen_unix_socket (const char *path,
* @returns the number of file descriptors
*/
int
_dbus_listen_systemd_sockets (int **fds,
DBusError *error)
_dbus_listen_systemd_sockets (DBusSocket **fds,
DBusError *error)
{
#ifdef HAVE_SYSTEMD
int r, n;
int fd;
int *new_fds;
DBusSocket *new_fds;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
@ -1211,7 +1211,7 @@ _dbus_listen_systemd_sockets (int **fds,
/* OK, the file descriptors are all good, so let's take posession of
them then. */
new_fds = dbus_new (int, n);
new_fds = dbus_new (DBusSocket, n);
if (!new_fds)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
@ -1262,7 +1262,7 @@ _dbus_listen_systemd_sockets (int **fds,
* @param error return location for error code
* @returns connection file descriptor or -1 on error
*/
int
DBusSocket
_dbus_connect_tcp_socket (const char *host,
const char *port,
const char *family,
@ -1271,7 +1271,7 @@ _dbus_connect_tcp_socket (const char *host,
return _dbus_connect_tcp_socket_with_nonce (host, port, family, (const char*)NULL, error);
}
int
DBusSocket
_dbus_connect_tcp_socket_with_nonce (const char *host,
const char *port,
const char *family,
@ -1391,11 +1391,12 @@ _dbus_listen_tcp_socket (const char *host,
const char *port,
const char *family,
DBusString *retport,
int **fds_p,
DBusSocket **fds_p,
DBusError *error)
{
int saved_errno;
int nlisten_fd = 0, *listen_fd = NULL, res, i;
int nlisten_fd = 0, res, i;
DBusSocket *listen_fd = NULL;
struct addrinfo hints;
struct addrinfo *ai, *tmp;
unsigned int reuseaddr;
@ -1437,7 +1438,9 @@ _dbus_listen_tcp_socket (const char *host,
tmp = ai;
while (tmp)
{
int fd = -1, *newlisten_fd, tcp_nodelay_on;
int fd = -1, tcp_nodelay_on;
DBusSocket *newlisten_fd;
if (!_dbus_open_socket (&fd, tmp->ai_family, SOCK_STREAM, 0, error))
{
_DBUS_ASSERT_ERROR_IS_SET(error);
@ -1498,7 +1501,7 @@ _dbus_listen_tcp_socket (const char *host,
goto failed;
}
newlisten_fd = dbus_realloc(listen_fd, sizeof(int)*(nlisten_fd+1));
newlisten_fd = dbus_realloc(listen_fd, sizeof(DBusSocket)*(nlisten_fd+1));
if (!newlisten_fd)
{
saved_errno = errno;
@ -2123,7 +2126,7 @@ _dbus_read_credentials_socket (DBusSocket client_fd,
* @returns #TRUE if the byte was sent
*/
dbus_bool_t
_dbus_send_credentials_socket (int server_fd,
_dbus_send_credentials_socket (DBusSocket server_fd,
DBusError *error)
{
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
@ -2143,10 +2146,10 @@ _dbus_send_credentials_socket (int server_fd,
* @param listen_fd the listen file descriptor
* @returns the connection fd of the client, or -1 on error
*/
int
_dbus_accept (int listen_fd)
DBusSocket
_dbus_accept (DBusSocket listen_fd)
{
int client_fd;
DBusSocket client_fd;
struct sockaddr addr;
socklen_t addrlen;
#ifdef HAVE_ACCEPT4
@ -4233,8 +4236,8 @@ _dbus_delete_directory (const DBusString *filename,
*
*/
dbus_bool_t
_dbus_socket_can_pass_unix_fd(int fd) {
_dbus_socket_can_pass_unix_fd (DBusSocket fd)
{
#ifdef SCM_RIGHTS
union {
struct sockaddr sa;
@ -4385,7 +4388,7 @@ _dbus_check_setuid (void)
* @param error return location for error code
*/
dbus_bool_t
_dbus_append_address_from_socket (int fd,
_dbus_append_address_from_socket (DBusSocket fd,
DBusString *address,
DBusError *error)
{

View file

@ -77,8 +77,8 @@ int _dbus_connect_exec (const char *path,
char *const argv[],
DBusError *error);
int _dbus_listen_systemd_sockets (int **fd,
DBusError *error);
int _dbus_listen_systemd_sockets (DBusSocket **fd,
DBusError *error);
dbus_bool_t _dbus_read_credentials (int client_fd,
DBusCredentials *credentials,
@ -148,7 +148,7 @@ dbus_bool_t _dbus_parse_uid (const DBusString *uid_str,
DBUS_PRIVATE_EXPORT
void _dbus_close_all (void);
dbus_bool_t _dbus_append_address_from_socket (int fd,
dbus_bool_t _dbus_append_address_from_socket (DBusSocket fd,
DBusString *address,
DBusError *error);

View file

@ -1492,7 +1492,7 @@ _dbus_exit (int code)
* @param error return location for error code
* @returns connection file descriptor or -1 on error
*/
int
DBusSocket
_dbus_connect_tcp_socket (const char *host,
const char *port,
const char *family,
@ -1501,7 +1501,7 @@ _dbus_connect_tcp_socket (const char *host,
return _dbus_connect_tcp_socket_with_nonce (host, port, family, (const char*)NULL, error);
}
int
DBusSocket
_dbus_connect_tcp_socket_with_nonce (const char *host,
const char *port,
const char *family,

View file

@ -211,15 +211,15 @@ int _dbus_write_socket_with_unix_fds_two (DBusSocket fd,
dbus_bool_t _dbus_socket_is_invalid (DBusSocket fd);
int _dbus_connect_tcp_socket (const char *host,
const char *port,
const char *family,
DBusError *error);
int _dbus_connect_tcp_socket_with_nonce (const char *host,
const char *port,
const char *family,
const char *noncefile,
DBusError *error);
DBusSocket _dbus_connect_tcp_socket (const char *host,
const char *port,
const char *family,
DBusError *error);
DBusSocket _dbus_connect_tcp_socket_with_nonce (const char *host,
const char *port,
const char *family,
const char *noncefile,
DBusError *error);
int _dbus_listen_tcp_socket (const char *host,
const char *port,
const char *family,