Commit 041b0767 authored by Havoc Pennington's avatar Havoc Pennington

2002-11-24 Havoc Pennington <hp@pobox.com>

        * test/echo-client.c, test/echo-server.c: cheesy test
	clients.

	* configure.in (AC_CHECK_FUNCS): check for writev

	* dbus/dbus-message.c (_dbus_message_get_network_data): new
	function

	* dbus/dbus-list.c (_dbus_list_foreach): new function

	* dbus/dbus-internals.c (_dbus_verbose): new function

	* dbus/dbus-server.c, dbus/dbus-server.h: public object
	representing a server that listens for connections.

	* dbus/.cvsignore: create

	* dbus/dbus-errors.h, dbus/dbus-errors.c:
	public API for reporting errors

	* dbus/dbus-connection.h, dbus/dbus-connection.c:
	public object representing a connection that
	sends/receives messages. (Same object used for
	both client and server.)

	* dbus/dbus-transport.h, dbus/dbus-transport.c:
	Basic abstraction for different kinds of stream
	that we might read/write messages from.
parent 576cdb6e
config.log
config.status
config.sub
configure
*.pc
libtool
ltmain.sh
stamp-h1
Doxyfile
Makefile
Makefile.in
aclocal.m4
autom4te.cache
config.guess
config.h
config.h.in
2002-11-24 Havoc Pennington <hp@pobox.com>
* test/echo-client.c, test/echo-server.c: cheesy test
clients.
* configure.in (AC_CHECK_FUNCS): check for writev
* dbus/dbus-message.c (_dbus_message_get_network_data): new
function
* dbus/dbus-list.c (_dbus_list_foreach): new function
* dbus/dbus-internals.c (_dbus_verbose): new function
* dbus/dbus-server.c, dbus/dbus-server.h: public object
representing a server that listens for connections.
* dbus/.cvsignore: create
* dbus/dbus-errors.h, dbus/dbus-errors.c:
public API for reporting errors
* dbus/dbus-connection.h, dbus/dbus-connection.c:
public object representing a connection that
sends/receives messages. (Same object used for
both client and server.)
* dbus/dbus-transport.h, dbus/dbus-transport.c:
Basic abstraction for different kinds of stream
that we might read/write messages from.
2002-11-23 Havoc Pennington <hp@pobox.com>
* dbus/dbus-internals.h (_DBUS_INT_MAX): add _DBUS_INT_MIN
......
.deps
.libs
Makefile
Makefile.in
*.lo
*.la
dbus-daemon-1
......@@ -102,6 +102,10 @@ AC_C_BIGENDIAN
AC_CHECK_FUNCS(vsnprintf vasprintf)
dnl check for writev header and writev function so we're
dnl good to go if HAVE_WRITEV gets defined.
AC_CHECK_HEADERS(sys/uio.h, [AC_CHECK_FUNCS(writev)])
DBUS_CLIENT_CFLAGS=
DBUS_CLIENT_LIBS=
AC_SUBST(DBUS_CLIENT_CFLAGS)
......@@ -112,6 +116,11 @@ DBUS_BUS_LIBS=
AC_SUBST(DBUS_BUS_CFLAGS)
AC_SUBST(DBUS_BUS_LIBS)
DBUS_TEST_CFLAGS=
DBUS_TEST_LIBS=
AC_SUBST(DBUS_TEST_CFLAGS)
AC_SUBST(DBUS_TEST_LIBS)
AC_OUTPUT([
Makefile
Doxyfile
......
.deps
.libs
Makefile
Makefile.in
*.lo
*.la
dbus-test
......@@ -7,18 +7,38 @@ lib_LTLIBRARIES=libdbus-1.la
dbusinclude_HEADERS= \
dbus.h \
dbus-errors.h \
dbus-macros.h \
dbus-memory.h \
dbus-message.h \
dbus-server.h \
dbus-types.h
libdbus_1_la_SOURCES= \
dbus-connection.c \
dbus-connection-internal.h \
dbus-errors.c \
dbus-memory.c \
dbus-message.c
dbus-message.c \
dbus-message-internal.h \
dbus-server.c \
dbus-server-protected.h \
dbus-server-unix.c \
dbus-server-unix.h \
dbus-transport.c \
dbus-transport.h \
dbus-transport-protected.h \
dbus-transport-unix.c \
dbus-transport-unix.h \
dbus-watch.c \
dbus-watch.h
## this library is linked into both libdbus and the bus
## itself, but does not export any symbols from libdbus.
## It contains utility functions not in the public API.
## i.e. the point is to contain symbols that we don't
## want the shared lib to export, but we do want the
## message bus to be able to use.
noinst_LTLIBRARIES=libdbus-convenience.la
......
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-connection-internal.h DBusConnection internal interfaces
*
* Copyright (C) 2002 Red Hat Inc.
*
* Licensed under the Academic Free License version 1.2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef DBUS_CONNECTION_INTERNAL_H
#define DBUS_CONNECTION_INTERNAL_H
#include <dbus/dbus-internals.h>
#include <dbus/dbus-connection.h>
#include <dbus/dbus-message.h>
#include <dbus/dbus-transport.h>
DBUS_BEGIN_DECLS;
typedef enum
{
DBUS_ITERATION_DO_WRITING = 1 << 0, /**< Write messages out. */
DBUS_ITERATION_DO_READING = 1 << 1, /**< Read messages in. */
DBUS_ITERATION_BLOCK = 1 << 2 /**< Block if nothing to do. */
} DBusIterationFlags;
dbus_bool_t _dbus_connection_queue_received_message (DBusConnection *connection,
DBusMessage *message);
dbus_bool_t _dbus_connection_have_messages_to_send (DBusConnection *connection);
DBusMessage* _dbus_connection_get_message_to_send (DBusConnection *connection);
void _dbus_connection_message_sent (DBusConnection *connection,
DBusMessage *message);
dbus_bool_t _dbus_connection_add_watch (DBusConnection *connection,
DBusWatch *watch);
void _dbus_connection_remove_watch (DBusConnection *connection,
DBusWatch *watch);
DBusConnection* _dbus_connection_new_for_transport (DBusTransport *transport);
void _dbus_connection_do_iteration (DBusConnection *connection,
unsigned int flags,
int timeout_milliseconds);
void _dbus_connection_transport_error (DBusConnection *connection,
DBusResultCode result_code);
DBUS_END_DECLS;
#endif /* DBUS_CONNECTION_INTERNAL_H */
This diff is collapsed.
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-connection.h DBusConnection object
*
* Copyright (C) 2002 Red Hat Inc.
*
* Licensed under the Academic Free License version 1.2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
#error "Only <dbus/dbus.h> can be included directly, this file may disappear or change contents."
#endif
#ifndef DBUS_CONNECTION_H
#define DBUS_CONNECTION_H
#include <dbus/dbus-errors.h>
#include <dbus/dbus-message.h>
#include <dbus/dbus-memory.h>
DBUS_BEGIN_DECLS;
typedef struct DBusConnection DBusConnection;
typedef struct DBusWatch DBusWatch;
typedef enum
{
DBUS_WATCH_READABLE = 1 << 0, /**< As in POLLIN */
DBUS_WATCH_WRITABLE = 1 << 1, /**< As in POLLOUT */
DBUS_WATCH_ERROR = 1 << 2, /**< As in POLLERR (can't watch for this, but
* the flag can be passed to dbus_connection_handle_watch()).
*/
DBUS_WATCH_HANGUP = 1 << 3 /**< As in POLLHUP (can't watch for it, but
* can be present in current state). */
} DBusWatchFlags;
typedef void (* DBusAddWatchFunction) (DBusWatch *watch,
void *data);
typedef void (* DBusRemoveWatchFunction) (DBusWatch *watch,
void *data);
typedef void (* DBusConnectionErrorFunction) (DBusConnection *connection,
DBusResultCode error_code,
void *data);
DBusConnection* dbus_connection_open (const char *address,
DBusResultCode *result);
void dbus_connection_ref (DBusConnection *connection);
void dbus_connection_unref (DBusConnection *connection);
void dbus_connection_disconnect (DBusConnection *connection);
dbus_bool_t dbus_connection_get_is_connected (DBusConnection *connection);
dbus_bool_t dbus_connection_send_message (DBusConnection *connection,
DBusMessage *message,
DBusResultCode *result);
void dbus_connection_flush (DBusConnection *connection);
int dbus_connection_get_n_messages (DBusConnection *connection);
DBusMessage* dbus_connection_peek_message (DBusConnection *connection);
DBusMessage* dbus_connection_pop_message (DBusConnection *connection);
void dbus_connection_set_error_function (DBusConnection *connection,
DBusConnectionErrorFunction error_function,
void *data,
DBusFreeFunction free_data_function);
void dbus_connection_set_watch_functions (DBusConnection *connection,
DBusAddWatchFunction add_function,
DBusRemoveWatchFunction remove_function,
void *data,
DBusFreeFunction free_data_function);
void dbus_connection_handle_watch (DBusConnection *connection,
DBusWatch *watch,
unsigned int condition);
int dbus_watch_get_fd (DBusWatch *watch);
unsigned int dbus_watch_get_flags (DBusWatch *watch);
void* dbus_watch_get_data (DBusWatch *watch);
void dbus_watch_set_data (DBusWatch *watch,
void *data,
DBusFreeFunction free_data_function);
DBUS_END_DECLS;
#endif /* DBUS_CONNECTION_H */
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-errors.c Error reporting
*
* Copyright (C) 2002 Red Hat Inc.
*
* Licensed under the Academic Free License version 1.2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "dbus-errors.h"
/**
* @defgroup DBusErrors Error reporting
* @ingroup DBus
* @brief Error reporting
*
* Types and functions related to reporting errors.
*
*
* In essence D-BUS error reporting works as follows:
*
* @code
* DBusResultCode result = DBUS_RESULT_SUCCESS;
* dbus_some_function (arg1, arg2, &result);
* if (result != DBUS_RESULT_SUCCESS)
* printf ("an error occurred\n");
* @endcode
*
* @{
*/
/**
* Set a result code at a result code location,
* if code_address is not #NULL.
*
* @param code_address place to store the result code.
* @param code the result code itself.
*/
void
dbus_set_result (DBusResultCode *code_address,
DBusResultCode code)
{
if (code_address)
*code_address = code;
}
/**
* Returns a string describing the given result code.
*
* @param code the result code to describe.
* @returns a constant string describing the code.
*/
const char*
dbus_result_to_string (DBusResultCode code)
{
/* This is a switch to the compiler will complain if we
* aren't handling some codes
*/
switch (code)
{
case DBUS_RESULT_SUCCESS:
return "Success";
case DBUS_RESULT_FAILED:
return "Unknown error";
case DBUS_RESULT_NO_MEMORY:
return "Not enough memory available";
case DBUS_RESULT_IO_ERROR:
return "Error reading or writing data";
case DBUS_RESULT_BAD_ADDRESS:
return "Could not parse address";
case DBUS_RESULT_NOT_SUPPORTED:
return "Feature not supported";
case DBUS_RESULT_LIMITS_EXCEEDED:
return "Resource limits exceeded";
case DBUS_RESULT_ACCESS_DENIED:
return "Permission denied";
case DBUS_RESULT_AUTH_FAILED:
return "Could not authenticate to server";
case DBUS_RESULT_NO_SERVER:
return "No server";
case DBUS_RESULT_TIMEOUT:
return "Connection timed out";
case DBUS_RESULT_NO_NETWORK:
return "Network unavailable";
case DBUS_RESULT_ADDRESS_IN_USE:
return "Address already in use";
case DBUS_RESULT_DISCONNECTED:
return "Disconnected.";
/* no default, it would break our compiler warnings */
}
return "Invalid error code";
}
/** @} */
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-errors.h Error reporting
*
* Copyright (C) 2002 Red Hat Inc.
*
* Licensed under the Academic Free License version 1.2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
#error "Only <dbus/dbus.h> can be included directly, this file may disappear or change contents."
#endif
#ifndef DBUS_ERROR_H
#define DBUS_ERROR_H
#include <dbus/dbus-macros.h>
DBUS_BEGIN_DECLS;
typedef enum
{
DBUS_RESULT_SUCCESS, /**< Operation was successful. */
DBUS_RESULT_FAILED, /**< Operation failed for unspecified reason. */
DBUS_RESULT_NO_MEMORY, /**< Operation failed for lack of memory. */
DBUS_RESULT_IO_ERROR, /**< Operation failed because of an IO error,
* typically the other end closed the
* connection.
*/
DBUS_RESULT_BAD_ADDRESS, /**< Address was bad, could not be parsed. */
DBUS_RESULT_NOT_SUPPORTED, /**< Feature is not supported. */
DBUS_RESULT_LIMITS_EXCEEDED, /**< Some kernel resource limit exceeded. */
DBUS_RESULT_ACCESS_DENIED, /**< Some sort of permissions/security problem. */
DBUS_RESULT_AUTH_FAILED, /**< Could not authenticate. */
DBUS_RESULT_NO_SERVER, /**< No one listening on the other end. */
DBUS_RESULT_TIMEOUT, /**< Timed out trying to connect. */
DBUS_RESULT_NO_NETWORK, /**< Can't find the network */
DBUS_RESULT_ADDRESS_IN_USE, /**< Someone's already using the address */
DBUS_RESULT_DISCONNECTED /**< No more connection. */
} DBusResultCode;
void dbus_set_result (DBusResultCode *code_address,
DBusResultCode code);
const char* dbus_result_to_string (DBusResultCode code);
DBUS_END_DECLS;
#endif /* DBUS_ERROR_H */
......@@ -23,6 +23,11 @@
#include "dbus-internals.h"
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
/**
* @defgroup DBusInternals D-BUS internal implementation details
......@@ -31,7 +36,7 @@
*/
/**
* @defgroup DBusInternalsUtils Utilities
* @defgroup DBusInternalsUtils Utilities and portability
* @ingroup DBusInternals
* @brief Utility functions (_dbus_assert(), _dbus_warn(), etc.)
* @{
......@@ -82,7 +87,13 @@
*
* @param integer the integer to stuff into a pointer.
*/
/**
* @def _DBUS_ZERO
*
* Sets all bits in an object to zero.
*
* @param object the object to be zeroed.
*/
/**
* @def _DBUS_INT_MIN
*
......@@ -93,6 +104,25 @@
*
* Maximum value of type "int"
*/
/**
* @def _DBUS_MAX_SUN_PATH_LENGTH
*
* Maximum length of the path to a UNIX domain socket,
* sockaddr_un::sun_path member. POSIX requires that all systems
* support at least 100 bytes here, including the nul termination.
* We use 99 for the max value to allow for the nul.
*
* We could probably also do sizeof (addr.sun_path)
* but this way we are the same on all platforms
* which is probably a good idea.
*/
/**
* @typedef DBusForeachFunction
*
* Used to iterate over each item in a collection, such as
* a DBusList.
*/
/**
* Prints a warning message to stderr.
......@@ -111,6 +141,134 @@ _dbus_warn (const char *format,
va_end (args);
}
/**
* Prints a warning message to stderr
* if the user has enabled verbose mode.
*
* @param format printf-style format string.
*/
void
_dbus_verbose (const char *format,
...)
{
va_list args;
static dbus_bool_t verbose = TRUE;
static dbus_bool_t initted = FALSE;
if (!verbose)
return;
if (!initted)
{
verbose = getenv ("DBUS_VERBOSE") != NULL;
initted = TRUE;
}
va_start (args, format);
vfprintf (stderr, format, args);
va_end (args);
}
/**
* A wrapper around strerror() because some platforms
* may be lame and not have strerror().
*
* @param error_number errno.
* @returns error description.
*/
const char*
_dbus_strerror (int error_number)
{
return strerror (error_number);
}
/**
* Converts a UNIX errno into a DBusResultCode.
*
* @param error_number the errno.
* @returns the result code.
*/
DBusResultCode
_dbus_result_from_errno (int error_number)
{
switch (error_number)
{
case 0:
return DBUS_RESULT_SUCCESS;
#ifdef EPROTONOSUPPORT
case EPROTONOSUPPORT:
return DBUS_RESULT_NOT_SUPPORTED;
#endif
#ifdef EAFNOSUPPORT
case EAFNOSUPPORT:
return DBUS_RESULT_NOT_SUPPORTED;
#endif
#ifdef ENFILE
case ENFILE:
return DBUS_RESULT_LIMITS_EXCEEDED; /* kernel out of memory */
#endif
#ifdef EMFILE
case EMFILE:
return DBUS_RESULT_LIMITS_EXCEEDED;
#endif
#ifdef EACCES
case EACCES:
return DBUS_RESULT_ACCESS_DENIED;
#endif
#ifdef EPERM
case EPERM:
return DBUS_RESULT_ACCESS_DENIED;
#endif
#ifdef ENOBUFS
case ENOBUFS:
return DBUS_RESULT_NO_MEMORY;
#endif
#ifdef ENOMEM
case ENOMEM:
return DBUS_RESULT_NO_MEMORY;
#endif
#ifdef EINVAL
case EINVAL:
return DBUS_RESULT_FAILED;
#endif
#ifdef EBADF
case EBADF:
return DBUS_RESULT_FAILED;
#endif
#ifdef EFAULT
case EFAULT:
return DBUS_RESULT_FAILED;
#endif
#ifdef ENOTSOCK
case ENOTSOCK:
return DBUS_RESULT_FAILED;
#endif
#ifdef EISCONN
case EISCONN:
return DBUS_RESULT_FAILED;
#endif
#ifdef ECONNREFUSED
case ECONNREFUSED:
return DBUS_RESULT_NO_SERVER;
#endif
#ifdef ETIMEDOUT
case ETIMEDOUT:
return DBUS_RESULT_TIMEOUT;
#endif
#ifdef ENETUNREACH
case ENETUNREACH:
return DBUS_RESULT_NO_NETWORK;
#endif
#ifdef EADDRINUSE
case EADDRINUSE:
return DBUS_RESULT_ADDRESS_IN_USE;
#endif
}
return DBUS_RESULT_FAILED;
}
/**
* Duplicates a string. Result must be freed with
* dbus_free(). Returns #NULL if memory allocation fails.
......@@ -139,4 +297,38 @@ _dbus_strdup (const char *str)
return copy;
}
/**
* Sets a file descriptor to be nonblocking.
*
* @param fd the file descriptor.
* @param result address of result code.
* @returns #TRUE on success.
*/
dbus_bool_t
_dbus_set_fd_nonblocking (int fd,
DBusResultCode *result)
{
int val;
val = fcntl (fd, F_GETFL, 0);
if (val < 0)
{
dbus_set_result (result, _dbus_result_from_errno (errno));
_dbus_verbose ("Failed to get flags for fd %d: %s\n", fd,
_dbus_strerror (errno));
return FALSE;
}
if (fcntl (fd, F_SETFL, val | O_NONBLOCK) < 0)
{
dbus_set_result (result, _dbus_result_from_errno (errno));
_dbus_verbose ("Failed to set fd %d nonblocking: %s\n",
fd, _dbus_strerror (errno));
return FALSE;
}
return TRUE;
}
/** @} */
......@@ -20,6 +20,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifdef DBUS_INSIDE_DBUS_H
#error "You can't include dbus-internals.h in the public header dbus.h"
#endif
#ifndef DBUS_INTERNALS_H
#define DBUS_INTERNALS_H
......@@ -28,13 +31,20 @@
#include <dbus/dbus-memory.h>
#include <dbus/dbus-types.h>
#include <dbus/dbus-errors.h>
#include <stdlib.h> /* for abort() */
#include <string.h> /* just so it's there in every file */
DBUS_BEGIN_DECLS;
void _dbus_warn (const char *format,
...);
void _dbus_warn (const char *format,
...);
void _dbus_verbose (const char *format,
...);
const char* _dbus_strerror (int error_number);
DBusResultCode _dbus_result_from_errno (int error_number);
#define _dbus_assert(condition) \
do { \
......@@ -58,10 +68,19 @@ do {
#define _DBUS_POINTER_TO_INT(pointer) ((long)(pointer))
#define _DBUS_INT_TO_POINTER(integer) ((void*)((long)(integer)))
#define _DBUS_ZERO(object) (memset (&(object), '\0', sizeof ((object))))
char* _dbus_strdup (const char *str);
#define _DBUS_INT_MIN (-_DBUS_INT_MAX - 1)
#define _DBUS_INT_MAX 2147483647
#define _DBUS_MAX_SUN_PATH_LENGTH 99
typedef void (* DBusForeachFunction) (void *element,
void *data);
dbus_bool_t _dbus_set_fd_nonblocking (int fd,
DBusResultCode *result);
DBUS_END_DECLS