2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2014-01-14 18:18:43 +01:00
|
|
|
#ifndef foosdresolvehfoo
|
|
|
|
#define foosdresolvehfoo
|
2014-01-06 13:41:59 +01:00
|
|
|
|
|
|
|
/***
|
2014-01-11 15:51:30 +01:00
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
2014-01-06 13:41:59 +01:00
|
|
|
|
2014-01-11 15:51:30 +01:00
|
|
|
systemd is distributed in the hope that it will be useful, but
|
2014-01-06 13:41:59 +01:00
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
2014-01-11 15:51:30 +01:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
2014-01-06 13:41:59 +01:00
|
|
|
***/
|
|
|
|
|
2018-10-05 07:40:44 +02:00
|
|
|
/* 'struct addrinfo' needs _GNU_SOURCE */
|
|
|
|
#ifndef _GNU_SOURCE
|
|
|
|
#define _GNU_SOURCE 1
|
|
|
|
#endif
|
|
|
|
|
2015-10-24 23:42:56 +02:00
|
|
|
#include <inttypes.h>
|
2014-01-06 13:41:59 +01:00
|
|
|
#include <netdb.h>
|
2015-10-24 23:42:56 +02:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/types.h>
|
2014-01-27 20:12:14 +01:00
|
|
|
|
2014-04-29 15:44:31 +02:00
|
|
|
#include "sd-event.h"
|
2015-11-18 22:46:33 +01:00
|
|
|
|
2015-10-24 23:42:56 +02:00
|
|
|
#include "_sd-common.h"
|
2014-01-11 15:51:30 +01:00
|
|
|
|
|
|
|
_SD_BEGIN_DECLARATIONS;
|
|
|
|
|
2014-04-29 15:44:31 +02:00
|
|
|
/* An opaque sd-resolve session structure */
|
2014-01-15 18:21:29 +01:00
|
|
|
typedef struct sd_resolve sd_resolve;
|
2014-01-06 13:41:59 +01:00
|
|
|
|
2014-04-29 15:44:31 +02:00
|
|
|
/* An opaque sd-resolve query structure */
|
2014-01-15 18:21:29 +01:00
|
|
|
typedef struct sd_resolve_query sd_resolve_query;
|
2014-01-06 13:41:59 +01:00
|
|
|
|
2014-04-29 15:44:31 +02:00
|
|
|
/* A callback on completion */
|
|
|
|
typedef int (*sd_resolve_getaddrinfo_handler_t)(sd_resolve_query *q, int ret, const struct addrinfo *ai, void *userdata);
|
|
|
|
typedef int (*sd_resolve_getnameinfo_handler_t)(sd_resolve_query *q, int ret, const char *host, const char *serv, void *userdata);
|
2018-11-28 16:28:53 +01:00
|
|
|
typedef _sd_destroy_t sd_resolve_destroy_t;
|
2014-04-29 15:44:31 +02:00
|
|
|
|
|
|
|
enum {
|
2018-05-22 09:36:08 +02:00
|
|
|
SD_RESOLVE_GET_HOST = 1 << 0,
|
|
|
|
SD_RESOLVE_GET_SERVICE = 1 << 1,
|
|
|
|
SD_RESOLVE_GET_BOTH = SD_RESOLVE_GET_HOST | SD_RESOLVE_GET_SERVICE,
|
2014-04-29 15:44:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
int sd_resolve_default(sd_resolve **ret);
|
|
|
|
|
|
|
|
/* Allocate a new sd-resolve session. */
|
2014-01-27 20:12:14 +01:00
|
|
|
int sd_resolve_new(sd_resolve **ret);
|
2014-01-06 13:41:59 +01:00
|
|
|
|
2014-04-29 15:44:31 +02:00
|
|
|
/* Free a sd-resolve session. This destroys all attached
|
2014-03-25 04:14:28 +01:00
|
|
|
* sd_resolve_query objects automatically. */
|
2014-01-27 20:12:14 +01:00
|
|
|
sd_resolve* sd_resolve_unref(sd_resolve *resolve);
|
2014-04-29 15:44:31 +02:00
|
|
|
sd_resolve* sd_resolve_ref(sd_resolve *resolve);
|
2014-01-27 20:12:14 +01:00
|
|
|
|
2014-04-29 15:44:31 +02:00
|
|
|
/* Return the UNIX file descriptor to poll() for events on. Use this
|
2014-01-27 20:12:14 +01:00
|
|
|
* function to integrate sd-resolve with your custom main loop. */
|
|
|
|
int sd_resolve_get_fd(sd_resolve *resolve);
|
|
|
|
|
2014-04-29 15:44:31 +02:00
|
|
|
/* Return the poll() events (a combination of flags like POLLIN,
|
2014-01-27 20:12:14 +01:00
|
|
|
* POLLOUT, ...) to check for. */
|
|
|
|
int sd_resolve_get_events(sd_resolve *resolve);
|
2014-01-06 13:41:59 +01:00
|
|
|
|
2014-04-29 15:44:31 +02:00
|
|
|
/* Return the poll() timeout to pass. Returns (uint64_t) -1 as
|
2014-03-25 04:14:28 +01:00
|
|
|
* timeout if no timeout is needed. */
|
2014-01-27 20:12:14 +01:00
|
|
|
int sd_resolve_get_timeout(sd_resolve *resolve, uint64_t *timeout_usec);
|
2014-01-06 13:41:59 +01:00
|
|
|
|
2014-04-29 15:44:31 +02:00
|
|
|
/* Process pending responses. After this function is called, you can
|
2014-01-27 20:12:14 +01:00
|
|
|
* get the next completed query object(s) using
|
|
|
|
* sd_resolve_get_next(). */
|
|
|
|
int sd_resolve_process(sd_resolve *resolve);
|
|
|
|
|
2014-04-29 15:44:31 +02:00
|
|
|
/* Wait for a resolve event to complete. */
|
2014-01-27 20:12:14 +01:00
|
|
|
int sd_resolve_wait(sd_resolve *resolve, uint64_t timeout_usec);
|
2014-01-06 13:41:59 +01:00
|
|
|
|
2014-04-29 15:44:31 +02:00
|
|
|
int sd_resolve_get_tid(sd_resolve *resolve, pid_t *tid);
|
|
|
|
|
2016-02-16 19:33:36 +01:00
|
|
|
int sd_resolve_attach_event(sd_resolve *resolve, sd_event *e, int64_t priority);
|
2014-04-29 15:44:31 +02:00
|
|
|
int sd_resolve_detach_event(sd_resolve *resolve);
|
|
|
|
sd_event *sd_resolve_get_event(sd_resolve *resolve);
|
|
|
|
|
|
|
|
/* Issue a name-to-address query on the specified session. The
|
2014-03-25 04:14:28 +01:00
|
|
|
* arguments are compatible with those of libc's
|
2014-01-06 13:41:59 +01:00
|
|
|
* getaddrinfo(3). The function returns a new query object. When the
|
2014-03-25 04:14:28 +01:00
|
|
|
* query is completed, you may retrieve the results using
|
2014-01-27 20:12:14 +01:00
|
|
|
* sd_resolve_getaddrinfo_done(). */
|
2014-04-29 15:44:31 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
/* Issue an address-to-name query on the specified session. The
|
2014-03-25 04:14:28 +01:00
|
|
|
* arguments are compatible with those of libc's
|
2014-01-06 13:41:59 +01:00
|
|
|
* getnameinfo(3). The function returns a new query object. When the
|
2014-03-25 04:14:28 +01:00
|
|
|
* query is completed, you may retrieve the results using
|
2014-01-14 18:18:43 +01:00
|
|
|
* sd_resolve_getnameinfo_done(). Set gethost (resp. getserv) to non-zero
|
2014-01-06 13:41:59 +01:00
|
|
|
* if you want to query the hostname (resp. the service name). */
|
2014-04-29 15:44:31 +02:00
|
|
|
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);
|
2014-01-06 13:41:59 +01:00
|
|
|
|
2018-12-04 09:29:54 +01:00
|
|
|
sd_resolve_query *sd_resolve_query_ref(sd_resolve_query *q);
|
|
|
|
sd_resolve_query *sd_resolve_query_unref(sd_resolve_query *q);
|
2014-04-29 15:44:31 +02:00
|
|
|
|
|
|
|
/* Returns non-zero when the query operation specified by q has been completed. */
|
2018-12-04 09:29:54 +01:00
|
|
|
int sd_resolve_query_is_done(sd_resolve_query *q);
|
2014-04-29 15:44:31 +02:00
|
|
|
|
|
|
|
void *sd_resolve_query_get_userdata(sd_resolve_query *q);
|
|
|
|
void *sd_resolve_query_set_userdata(sd_resolve_query *q, void *userdata);
|
2018-11-03 16:56:58 +01:00
|
|
|
int sd_resolve_query_get_destroy_callback(sd_resolve_query *q, sd_resolve_destroy_t *destroy_callback);
|
|
|
|
int sd_resolve_query_set_destroy_callback(sd_resolve_query *q, sd_resolve_destroy_t destroy_callback);
|
2018-11-03 17:05:16 +01:00
|
|
|
int sd_resolve_query_get_floating(sd_resolve_query *q);
|
|
|
|
int sd_resolve_query_set_floating(sd_resolve_query *q, int b);
|
2014-04-29 15:44:31 +02:00
|
|
|
|
|
|
|
sd_resolve *sd_resolve_query_get_resolve(sd_resolve_query *q);
|
2014-01-06 13:41:59 +01:00
|
|
|
|
tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.
With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.
The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).
This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.
Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:
#define _cleanup_(function) __attribute__((cleanup(function)))
Or similar, to make the gcc feature easier to use.
Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.
See #2008.
2015-11-27 19:13:45 +01:00
|
|
|
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_resolve, sd_resolve_unref);
|
|
|
|
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_resolve_query, sd_resolve_query_unref);
|
|
|
|
|
2014-01-11 15:51:30 +01:00
|
|
|
_SD_END_DECLARATIONS;
|
|
|
|
|
2014-01-06 13:41:59 +01:00
|
|
|
#endif
|