28#include "dbus-internals.h"
29#include "dbus-sysdeps.h"
30#include "dbus-threads.h"
31#include "dbus-protocol.h"
32#include "dbus-string.h"
54#elif (defined __APPLE__)
55# include <crt_externs.h>
56# define environ (*_NSGetEnviron())
57#elif HAVE_DECL_ENVIRON && defined(HAVE_UNISTD_H)
64#include "dbus-sockets-win.h"
67#include <netinet/in.h>
68#include <sys/socket.h>
93 _dbus_print_backtrace ();
140 len = strlen (varname);
146 putenv_value = malloc (len + 2);
147 if (putenv_value ==
NULL)
150 strcpy (putenv_value, varname);
152 strcat (putenv_value,
"=");
155 return (putenv (putenv_value) == 0);
161 return (setenv (varname, value,
TRUE) == 0);
168 varname_len = strlen (varname);
169 value_len = strlen (value);
171 len = varname_len + value_len + 1 ;
177 putenv_value = malloc (len + 1);
178 if (putenv_value ==
NULL)
181 strcpy (putenv_value, varname);
182 strcpy (putenv_value + varname_len,
"=");
183 strcpy (putenv_value + varname_len + 1, value);
185 return (putenv (putenv_value) == 0);
204 return getenv (varname);
218 if (clearenv () != 0)
369#define MAX_LONG_LEN ((sizeof (long) * 8 + 2) / 3 + 1)
381 snprintf (buf, MAX_LONG_LEN,
"%ld", value);
407#define MAX_ULONG_LEN (MAX_LONG_LEN * 2)
419 snprintf (buf, MAX_ULONG_LEN,
"%lu", value);
460 v = strtol (p, &end, 0);
461 if (end ==
NULL || end == p || errno != 0)
467 *end_return = start + (end - p);
487 unsigned long *value_return,
499 v = strtoul (p, &end, 0);
500 if (end ==
NULL || end == p || errno != 0)
506 *end_return = start + (end - p);
535 _DBUS_SET_OOM (error);
565 static const char letters[] =
566 "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
579 (
sizeof (letters) - 1)]);
603 switch (error_number)
608#ifdef EPROTONOSUPPORT
609 case EPROTONOSUPPORT:
611#elif defined(WSAEPROTONOSUPPORT)
612 case WSAEPROTONOSUPPORT:
618#elif defined(WSAEAFNOSUPPORT)
619 case WSAEAFNOSUPPORT:
649#elif defined(WSAECONNREFUSED)
650 case WSAECONNREFUSED:
656#elif defined(WSAETIMEDOUT)
663#elif defined(WSAENETUNREACH)
670#elif defined(WSAEADDRINUSE)
749 return e == ETOOMANYREFS;
762 return _dbus_strerror (errno);
778 va_start (args, msg);
798_dbus_inet_sockaddr_to_string (
const void *sockaddr_pointer,
802 const char **family_name,
809 struct sockaddr_storage storage;
810 struct sockaddr_in ipv4;
811 struct sockaddr_in6 ipv6;
815 if (len >
sizeof (addr))
819 memcpy (&addr, sockaddr_pointer, len);
821 switch (addr.sa.sa_family)
824 if (inet_ntop (AF_INET, &addr.ipv4.sin_addr,
string, string_len) !=
NULL)
826 if (family_name !=
NULL)
827 *family_name =
"ipv4";
830 *port = ntohs (addr.ipv4.sin_port);
836 saved_errno = _dbus_get_low_level_socket_errno ();
838 "Failed to get identity of IPv4 socket: %s",
839 _dbus_strerror (saved_errno));
846 if (inet_ntop (AF_INET6, &addr.ipv6.sin6_addr,
string, string_len) !=
NULL)
848 if (family_name !=
NULL)
849 *family_name =
"ipv6";
852 *port = ntohs (addr.ipv6.sin6_port);
858 saved_errno = _dbus_get_low_level_socket_errno ();
860 "Failed to get identity of IPv6 socket: %s",
861 _dbus_strerror (saved_errno));
869 "Failed to get identity of socket: unknown family");
885_dbus_set_error_with_inet_sockaddr (
DBusError *error,
886 const void *sockaddr_pointer,
888 const char *description,
891 char string[INET6_ADDRSTRLEN];
893 const struct sockaddr *addr = sockaddr_pointer;
895 if (_dbus_inet_sockaddr_to_string (sockaddr_pointer, len,
896 string,
sizeof (
string),
NULL, &port,
900 "%s \"%s\" port %u: %s",
901 description,
string, port, _dbus_strerror (saved_errno));
906 "%s <address of unknown family %d>: %s",
907 description, addr->sa_family,
908 _dbus_strerror (saved_errno));
913_dbus_combine_tcp_errors (
DBusList **sources,
919 DBusString message = _DBUS_STRING_INIT_INVALID;
929 const char *name =
NULL;
937 _DBUS_SET_OOM (dest);
952 else if (strcmp (name, error->
name) != 0)
963 _DBUS_SET_OOM (dest);
972 summary, host ? host :
"*", port,
void dbus_move_error(DBusError *src, DBusError *dest)
Moves an error src into dest, freeing src and overwriting dest.
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
dbus_bool_t _dbus_get_is_errno_epipe(int e)
See if errno is EPIPE.
dbus_bool_t _dbus_get_is_errno_etoomanyrefs(int e)
See if errno is ETOOMANYREFS.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
void _dbus_log(DBusSystemLogSeverity severity, const char *msg,...)
Log a message to the system log file (e.g.
const char * _dbus_error_from_errno(int error_number)
Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.
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...
const char * _dbus_error_from_system_errno(void)
Converts the current system errno value into a DBusError name.
const char * _dbus_strerror_from_errno(void)
Get error message from errno.
dbus_bool_t _dbus_get_is_errno_eintr(int e)
See if errno is EINTR.
#define _DBUS_ZERO(object)
Sets all bits in an object to zero.
void _dbus_set_errno_to_zero(void)
Assign 0 to the global errno variable.
dbus_bool_t _dbus_get_is_errno_enomem(int e)
See if errno is ENOMEM.
dbus_bool_t _dbus_generate_random_bytes_buffer(char *buffer, int n_bytes, DBusError *error)
Fills n_bytes of the given buffer with random bytes.
DBusList * _dbus_list_get_first_link(DBusList **list)
Gets the first link in the list.
dbus_bool_t _dbus_list_length_is_one(DBusList **list)
Check whether length is exactly one.
void _dbus_list_clear_full(DBusList **list, DBusFreeFunction function)
Free every link and every element in the list.
void * _dbus_list_get_first(DBusList **list)
Gets the first data in the list.
dbus_bool_t _dbus_list_append(DBusList **list, void *data)
Appends a value to the list.
#define _dbus_list_get_next_link(list, link)
Gets the next link in the list, or NULL if there are no more links.
#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().
dbus_bool_t dbus_setenv(const char *varname, const char *value)
Wrapper for setenv().
#define DBUS_ERROR_TIMEOUT
Certain timeout errors, possibly ETIMEDOUT on a socket.
#define DBUS_ERROR_NOT_SUPPORTED
Requested operation isn't supported (like ENOSYS on UNIX).
#define DBUS_ERROR_ADDRESS_IN_USE
Can't bind a socket since its address is in use (i.e.
#define DBUS_ERROR_ACCESS_DENIED
Security restrictions don't allow doing what you're trying to do.
#define DBUS_ERROR_NO_SERVER
Unable to connect to server (probably caused by ECONNREFUSED on a socket).
#define DBUS_ERROR_FILE_EXISTS
Existing file and the operation you're using does not silently overwrite.
#define DBUS_ERROR_LIMITS_EXCEEDED
Some limited resource is exhausted.
#define DBUS_ERROR_NO_NETWORK
No network access (probably ENETUNREACH on a socket).
#define DBUS_ERROR_FAILED
A generic error; "something went wrong" - see the error message for more.
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
#define DBUS_ERROR_FILE_NOT_FOUND
Missing file.
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
dbus_bool_t _dbus_string_append_int(DBusString *str, long value)
Appends an integer to a DBusString.
dbus_bool_t _dbus_string_find(const DBusString *str, int start, const char *substr, int *found)
Finds the given substring in the string, returning TRUE and filling in the byte index where the subst...
char * _dbus_string_get_data_len(DBusString *str, int start, int len)
Gets a sub-portion of the raw character buffer from the string.
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...
void _dbus_string_shorten(DBusString *str, int length_to_remove)
Makes a string shorter by the given number of bytes.
dbus_bool_t _dbus_string_copy_data(const DBusString *str, char **data_return)
Copies the data from the string into a char*.
dbus_bool_t _dbus_string_parse_uint(const DBusString *str, int start, unsigned long *value_return, int *end_return)
Parses an unsigned integer contained in a DBusString.
dbus_bool_t _dbus_string_lengthen(DBusString *str, int additional_length)
Makes a string longer by the given number of bytes.
dbus_bool_t _dbus_string_parse_int(const DBusString *str, int start, long *value_return, int *end_return)
Parses an integer contained in a DBusString.
dbus_bool_t _dbus_string_validate_ascii(const DBusString *str, int start, int len)
Checks that the given range of the string is valid ASCII with no nul bytes.
int _dbus_string_get_length(const DBusString *str)
Gets the length of a string (not including nul termination).
dbus_bool_t _dbus_string_append_uint(DBusString *str, unsigned long value)
Appends an unsigned integer to a DBusString.
void _dbus_string_chop_white(DBusString *str)
Deletes leading and trailing whitespace.
const char * _dbus_string_get_const_data_len(const DBusString *str, int start, int len)
const version of _dbus_string_get_data_len().
void _dbus_string_set_byte(DBusString *str, int i, unsigned char byte)
Sets the value of the byte at the given position.
const char * _dbus_string_get_const_data(const DBusString *str)
Gets the raw character buffer from a const string.
unsigned char _dbus_string_get_byte(const DBusString *str, int start)
Gets the byte at the given position.
dbus_bool_t _dbus_string_copy_len(const DBusString *source, int start, int len, DBusString *dest, int insert_at)
Like _dbus_string_copy(), but can copy a segment from the middle of the source string.
void _dbus_string_copy_to_buffer(const DBusString *str, char *buffer, int avail_len)
Copies the contents of a DBusString into a different buffer.
void _dbus_logv(DBusSystemLogSeverity severity, const char *msg, va_list args)
Log a message to the system log file (e.g.
unsigned long _dbus_pid_for_log(void)
The only reason this is separate from _dbus_getpid() is to allow it on Windows for logging but not fo...
dbus_bool_t _dbus_clearenv(void)
Wrapper for clearenv().
void _dbus_exit(int code)
Exit the process, returning the given value.
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
dbus_bool_t _dbus_check_setuid(void)
NOTE: If you modify this function, please also consider making the corresponding change in GLib.
void _dbus_sleep_milliseconds(int milliseconds)
Sleeps the given number of milliseconds.
dbus_bool_t _dbus_generate_random_bytes(DBusString *str, int n_bytes, DBusError *error)
Generates the given number of securely random bytes, using the best mechanism we can come up with.
void _dbus_abort(void)
Aborts the program with SIGABRT (dumping core).
dbus_bool_t _dbus_concat_dir_and_file(DBusString *dir, const DBusString *next_component)
Appends the given filename to the given directory.
dbus_bool_t _dbus_split_paths_and_append(DBusString *dirs, const char *suffix, DBusList **dir_list)
Split paths into a list of char strings.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
unsigned short dbus_uint16_t
A 16-bit unsigned integer on all platforms.
Object representing an exception.
const char * name
public error name field
const char * message
public error message field
void * data
Data stored at this element.