chiark / gitweb /
id128: add new sd_id128_is_null() call
[elogind.git] / src / systemd / sd-resolve.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #ifndef foosdresolvehfoo
4 #define foosdresolvehfoo
5
6 /***
7   This file is part of systemd.
8
9   Copyright 2005-2014 Lennart Poettering
10
11   systemd is free software; you can redistribute it and/or modify it
12   under the terms of the GNU Lesser General Public License as published by
13   the Free Software Foundation; either version 2.1 of the License, or
14   (at your option) any later version.
15
16   systemd is distributed in the hope that it will be useful, but
17   WITHOUT ANY WARRANTY; without even the implied warranty of
18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19   Lesser General Public License for more details.
20
21   You should have received a copy of the GNU Lesser General Public License
22   along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 ***/
24
25 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include <netdb.h>
28
29 #include "_sd-common.h"
30 #include "sd-event.h"
31
32 _SD_BEGIN_DECLARATIONS;
33
34 /* An opaque sd-resolve session structure */
35 typedef struct sd_resolve sd_resolve;
36
37 /* An opaque sd-resolve query structure */
38 typedef struct sd_resolve_query sd_resolve_query;
39
40 /* A callback on completion */
41 typedef int (*sd_resolve_getaddrinfo_handler_t)(sd_resolve_query *q, int ret, const struct addrinfo *ai, void *userdata);
42 typedef int (*sd_resolve_getnameinfo_handler_t)(sd_resolve_query *q, int ret, const char *host, const char *serv, void *userdata);
43 typedef int (*sd_resolve_res_handler_t)(sd_resolve_query* q, int ret, unsigned char *answer, void *userdata);
44
45 enum {
46         SD_RESOLVE_GET_HOST = 1ULL,
47         SD_RESOLVE_GET_SERVICE = 2ULL,
48         SD_RESOLVE_GET_BOTH = 3ULL
49 };
50
51 int sd_resolve_default(sd_resolve **ret);
52
53 /* Allocate a new sd-resolve session. */
54 int sd_resolve_new(sd_resolve **ret);
55
56 /* Free a sd-resolve session. This destroys all attached
57  * sd_resolve_query objects automatically. */
58 sd_resolve* sd_resolve_unref(sd_resolve *resolve);
59 sd_resolve* sd_resolve_ref(sd_resolve *resolve);
60
61 /* Return the UNIX file descriptor to poll() for events on. Use this
62  * function to integrate sd-resolve with your custom main loop. */
63 int sd_resolve_get_fd(sd_resolve *resolve);
64
65 /* Return the poll() events (a combination of flags like POLLIN,
66  * POLLOUT, ...) to check for. */
67 int sd_resolve_get_events(sd_resolve *resolve);
68
69 /* Return the poll() timeout to pass. Returns (uint64_t) -1 as
70  * timeout if no timeout is needed. */
71 int sd_resolve_get_timeout(sd_resolve *resolve, uint64_t *timeout_usec);
72
73 /* Process pending responses. After this function is called, you can
74  * get the next completed query object(s) using
75  * sd_resolve_get_next(). */
76 int sd_resolve_process(sd_resolve *resolve);
77
78 /* Wait for a resolve event to complete. */
79 int sd_resolve_wait(sd_resolve *resolve, uint64_t timeout_usec);
80
81 int sd_resolve_get_tid(sd_resolve *resolve, pid_t *tid);
82
83 int sd_resolve_attach_event(sd_resolve *resolve, sd_event *e, int priority);
84 int sd_resolve_detach_event(sd_resolve *resolve);
85 sd_event *sd_resolve_get_event(sd_resolve *resolve);
86
87 /* Issue a name-to-address query on the specified session. The
88  * arguments are compatible with those of libc's
89  * getaddrinfo(3). The function returns a new query object. When the
90  * query is completed, you may retrieve the results using
91  * sd_resolve_getaddrinfo_done(). */
92 int sd_resolve_getaddrinfo(sd_resolve *resolve, sd_resolve_query **q, const char *node, const char *service, const struct addrinfo *hints, sd_resolve_getaddrinfo_handler_t callback, void *userdata);
93
94 /* Issue an address-to-name query on the specified session. The
95  * arguments are compatible with those of libc's
96  * getnameinfo(3). The function returns a new query object. When the
97  * query is completed, you may retrieve the results using
98  * sd_resolve_getnameinfo_done(). Set gethost (resp. getserv) to non-zero
99  * if you want to query the hostname (resp. the service name). */
100 int sd_resolve_getnameinfo(sd_resolve *resolve, sd_resolve_query **q, const struct sockaddr *sa, socklen_t salen, int flags, uint64_t get, sd_resolve_getnameinfo_handler_t callback, void *userdata);
101
102 /* Issue a resolver query on the specified session. The arguments are
103  * compatible with those of libc's res_query(3). The function returns a new
104  * query object. When the query is completed, you may retrieve the results using
105  * sd_resolve_res_done(). */
106 int sd_resolve_res_query(sd_resolve *resolve, sd_resolve_query **q, const char *dname, int clazz, int type, sd_resolve_res_handler_t callback, void *userdata);
107
108 /* Issue a resolver query on the specified session. The arguments are
109  * compatible with those of libc's res_search(3). The function returns a new
110  * query object. When the query is completed, you may retrieve the results using
111  * sd_resolve_res_done(). */
112 int sd_resolve_res_search(sd_resolve *resolve, sd_resolve_query **q, const char *dname, int clazz, int type, sd_resolve_res_handler_t callback, void *userdata);
113
114 sd_resolve_query *sd_resolve_query_ref(sd_resolve_query* q);
115 sd_resolve_query *sd_resolve_query_unref(sd_resolve_query* q);
116
117 /* Returns non-zero when the query operation specified by q has been completed. */
118 int sd_resolve_query_is_done(sd_resolve_query*q);
119
120 void *sd_resolve_query_get_userdata(sd_resolve_query *q);
121 void *sd_resolve_query_set_userdata(sd_resolve_query *q, void *userdata);
122
123 sd_resolve *sd_resolve_query_get_resolve(sd_resolve_query *q);
124
125 _SD_END_DECLARATIONS;
126
127 #endif