| 1 |
#pragma once |
| 2 |
|
| 3 |
/* |
| 4 |
* D-Bus Peer Addresses |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <c-stdaux.h> |
| 8 |
#include <stdlib.h> |
| 9 |
|
| 10 |
typedef struct Address Address; |
| 11 |
|
| 12 |
enum { |
| 13 |
ADDRESS_TYPE_OTHER, |
| 14 |
ADDRESS_TYPE_ID, |
| 15 |
ADDRESS_TYPE_NAME, |
| 16 |
_ADDRESS_TYPE_N, |
| 17 |
}; |
| 18 |
|
| 19 |
/* invalid ID address */ |
| 20 |
#define ADDRESS_ID_INVALID (ULLONG_MAX) |
| 21 |
/* max length of string representation of ID addresses */ |
| 22 |
#define ADDRESS_ID_STRING_MAX (3 + C_DECIMAL_MAX(uint64_t)) |
| 23 |
|
| 24 |
struct Address { |
| 25 |
unsigned int type; |
| 26 |
char buffer[ADDRESS_ID_STRING_MAX + 1]; |
| 27 |
union { |
| 28 |
uint64_t id; |
| 29 |
const char *name; |
| 30 |
}; |
| 31 |
}; |
| 32 |
|
| 33 |
#define ADDRESS_NULL { .type = _ADDRESS_TYPE_OTHER } |
| 34 |
#define ADDRESS_INIT_ID(_id) { .type = ADDRESS_TYPE_ID, .id = (_id) } |
| 35 |
#define ADDRESS_INIT_NAME(_name) { .type = ADDRESS_TYPE_NAME, .name = (_name) } |
| 36 |
|
| 37 |
void address_init_from_id(Address *address, uint64_t id); |
| 38 |
void address_init_from_name(Address *address, const char *name); |
| 39 |
|
| 40 |
void address_from_string(Address *address, const char *string); |
| 41 |
const char *address_to_string(Address *address); |
| 42 |
|
| 43 |
void address_write(Address *address, char *buffer, size_t n_buffer); |