summaryrefslogtreecommitdiff
path: root/server/sbus/sssd_dbus_common.c
blob: 3b8a3271b801e24434c43657da0f59a28e770aa7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <sys/time.h>
#include "tevent.h"
#include "dbus/dbus.h"
#include "util/util.h"
#include "util/btreemap.h"

struct timeval _dbus_timeout_get_interval_tv(int interval) {
    struct timeval tv;
    struct timeval rightnow;

    gettimeofday(&rightnow,NULL);

    tv.tv_sec = interval / 1000 + rightnow.tv_sec;
    tv.tv_usec = (interval % 1000) * 1000 + rightnow.tv_usec;
    return tv;
}

/*
 * sbus_remove_watch
 * Hook for D-BUS to remove file descriptor-based events
 * from the libevents mainloop
 */
void sbus_remove_watch(DBusWatch *watch, void *data) {
    struct tevent_fd *fde;

    DEBUG(5, ("%lX\n", watch));
    fde = talloc_get_type(dbus_watch_get_data(watch), struct tevent_fd);

    /* Freeing the event object will remove it from the event loop */
    talloc_free(fde);
    dbus_watch_set_data(watch, NULL, NULL);
}


/*
 * sbus_remove_timeout
 * Hook for D-BUS to remove time-based events from the mainloop
 */
void sbus_remove_timeout(DBusTimeout *timeout, void *data) {
    struct tevent_timer *te;
    te = talloc_get_type(dbus_timeout_get_data(timeout), struct tevent_timer);

    /* Freeing the event object will remove it from the event loop */
    talloc_free(te);
    dbus_timeout_set_data(timeout, NULL, NULL);
}

int sbus_is_dbus_fixed_type(int dbus_type)
{
    switch (dbus_type) {
    case DBUS_TYPE_BYTE:
    case DBUS_TYPE_BOOLEAN:
    case DBUS_TYPE_INT16:
    case DBUS_TYPE_UINT16:
    case DBUS_TYPE_INT32:
    case DBUS_TYPE_UINT32:
    case DBUS_TYPE_INT64:
    case DBUS_TYPE_UINT64:
    case DBUS_TYPE_DOUBLE:
        return true;
    }
    return false;
}

int sbus_is_dbus_string_type(int dbus_type)
{
    switch(dbus_type) {
    case DBUS_TYPE_STRING:
    case DBUS_TYPE_OBJECT_PATH:
    case DBUS_TYPE_SIGNATURE:
        return true;
    }
    return false;
}

size_t sbus_get_dbus_type_size(int dbus_type)
{
    size_t ret;

    switch(dbus_type) {
    /* 1-byte types */
    case DBUS_TYPE_BYTE:
        ret = 1;
        break;

     /* 2-byte types */
    case DBUS_TYPE_INT16:
    case DBUS_TYPE_UINT16:
        ret = 2;
        break;

    /* 4-byte types */
    case DBUS_TYPE_BOOLEAN:
    case DBUS_TYPE_INT32:
    case DBUS_TYPE_UINT32:
        ret = 4;
        break;

    /* 8-byte types */
    case DBUS_TYPE_INT64:
    case DBUS_TYPE_UINT64:
    case DBUS_TYPE_DOUBLE:
        ret = 8;
        break;

    default:
        ret = 0;
    }
    return ret;
}