]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/systemd/sd-resolve.h
tree-wide: remove Emacs lines from all files
[thirdparty/systemd.git] / src / systemd / sd-resolve.h
1 #ifndef foosdresolvehfoo
2 #define foosdresolvehfoo
3
4 /***
5 This file is part of systemd.
6
7 Copyright 2005-2014 Lennart Poettering
8
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 ***/
22
23 #include <inttypes.h>
24 #include <netdb.h>
25 #include <sys/socket.h>
26 #include <sys/types.h>
27
28 #include "sd-event.h"
29
30 #include "_sd-common.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
44 enum {
45 SD_RESOLVE_GET_HOST = UINT64_C(1),
46 SD_RESOLVE_GET_SERVICE = UINT64_C(2),
47 SD_RESOLVE_GET_BOTH = UINT64_C(3),
48 };
49
50 int sd_resolve_default(sd_resolve **ret);
51
52 /* Allocate a new sd-resolve session. */
53 int sd_resolve_new(sd_resolve **ret);
54
55 /* Free a sd-resolve session. This destroys all attached
56 * sd_resolve_query objects automatically. */
57 sd_resolve* sd_resolve_unref(sd_resolve *resolve);
58 sd_resolve* sd_resolve_ref(sd_resolve *resolve);
59
60 /* Return the UNIX file descriptor to poll() for events on. Use this
61 * function to integrate sd-resolve with your custom main loop. */
62 int sd_resolve_get_fd(sd_resolve *resolve);
63
64 /* Return the poll() events (a combination of flags like POLLIN,
65 * POLLOUT, ...) to check for. */
66 int sd_resolve_get_events(sd_resolve *resolve);
67
68 /* Return the poll() timeout to pass. Returns (uint64_t) -1 as
69 * timeout if no timeout is needed. */
70 int sd_resolve_get_timeout(sd_resolve *resolve, uint64_t *timeout_usec);
71
72 /* Process pending responses. After this function is called, you can
73 * get the next completed query object(s) using
74 * sd_resolve_get_next(). */
75 int sd_resolve_process(sd_resolve *resolve);
76
77 /* Wait for a resolve event to complete. */
78 int sd_resolve_wait(sd_resolve *resolve, uint64_t timeout_usec);
79
80 int sd_resolve_get_tid(sd_resolve *resolve, pid_t *tid);
81
82 int sd_resolve_attach_event(sd_resolve *resolve, sd_event *e, int priority);
83 int sd_resolve_detach_event(sd_resolve *resolve);
84 sd_event *sd_resolve_get_event(sd_resolve *resolve);
85
86 /* Issue a name-to-address query on the specified session. The
87 * arguments are compatible with those of libc's
88 * getaddrinfo(3). The function returns a new query object. When the
89 * query is completed, you may retrieve the results using
90 * sd_resolve_getaddrinfo_done(). */
91 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);
92
93 /* Issue an address-to-name query on the specified session. The
94 * arguments are compatible with those of libc's
95 * getnameinfo(3). The function returns a new query object. When the
96 * query is completed, you may retrieve the results using
97 * sd_resolve_getnameinfo_done(). Set gethost (resp. getserv) to non-zero
98 * if you want to query the hostname (resp. the service name). */
99 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);
100
101 sd_resolve_query *sd_resolve_query_ref(sd_resolve_query* q);
102 sd_resolve_query *sd_resolve_query_unref(sd_resolve_query* q);
103
104 /* Returns non-zero when the query operation specified by q has been completed. */
105 int sd_resolve_query_is_done(sd_resolve_query*q);
106
107 void *sd_resolve_query_get_userdata(sd_resolve_query *q);
108 void *sd_resolve_query_set_userdata(sd_resolve_query *q, void *userdata);
109
110 sd_resolve *sd_resolve_query_get_resolve(sd_resolve_query *q);
111
112 _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_resolve, sd_resolve_unref);
113 _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_resolve_query, sd_resolve_query_unref);
114
115 _SD_END_DECLARATIONS;
116
117 #endif