chiark / gitweb /
networkd: add and expose per-link LLMNR config option
[elogind.git] / src / systemd / sd-resolve.h
index 2779db036b60f22a56f15cf5b7073301408deb0d..36cedcd6b593715f71ec76f28b2d200e5367787d 100644 (file)
@@ -6,7 +6,7 @@
 /***
   This file is part of systemd.
 
-  Copyright 2005-2008 Lennart Poettering
+  Copyright 2005-2014 Lennart Poettering
 
   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
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netdb.h>
+
 #include "_sd-common.h"
+#include "sd-event.h"
 
 _SD_BEGIN_DECLARATIONS;
 
-/** \mainpage
- *
- * \section moo Method of operation
- *
- * To use sd-resolve allocate an sd_resolve object with
- * sd_resolve_new(). This will spawn a number of worker threads (or processes, depending on what is available) which
- * are subsequently used to process the queries the controlling
- * program issues via sd_resolve_getaddrinfo() and
- * sd_resolve_getnameinfo(). Use sd_resolve_free() to shut down the worker
- * threads/processes.
- *
- * Since sd-resolve may fork off new processes you have to make sure that
- * your program is not irritated by spurious SIGCHLD signals.
- */
-
-/** An opaque sd-resolve session structure */
+/* An opaque sd-resolve session structure */
 typedef struct sd_resolve sd_resolve;
 
-/** An opaque sd-resolve query structure */
+/* An opaque sd-resolve query structure */
 typedef struct sd_resolve_query sd_resolve_query;
 
-/** Allocate a new sd-resolve session with n_proc worker processes/threads */
-sd_resolve* sd_resolve_new(unsigned n_proc);
+/* 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);
+typedef int (*sd_resolve_res_handler_t)(sd_resolve_query* q, int ret, unsigned char *answer, void *userdata);
+
+enum {
+        SD_RESOLVE_GET_HOST = 1ULL,
+        SD_RESOLVE_GET_SERVICE = 2ULL,
+        SD_RESOLVE_GET_BOTH = 3ULL
+};
+
+int sd_resolve_default(sd_resolve **ret);
+
+/* Allocate a new sd-resolve session. */
+int sd_resolve_new(sd_resolve **ret);
+
+/* Free a sd-resolve session. This destroys all attached
+ * sd_resolve_query objects automatically. */
+sd_resolve* sd_resolve_unref(sd_resolve *resolve);
+sd_resolve* sd_resolve_ref(sd_resolve *resolve);
+
+/* Return the UNIX file descriptor to poll() for events on. Use this
+ * function to integrate sd-resolve with your custom main loop. */
+int sd_resolve_get_fd(sd_resolve *resolve);
+
+/* Return the poll() events (a combination of flags like POLLIN,
+ * POLLOUT, ...) to check for. */
+int sd_resolve_get_events(sd_resolve *resolve);
+
+/* Return the poll() timeout to pass. Returns (uint64_t) -1 as
+ * timeout if no timeout is needed. */
+int sd_resolve_get_timeout(sd_resolve *resolve, uint64_t *timeout_usec);
 
-/** Free a sd-resolve session. This destroys all attached
- * sd_resolve_query objects automatically */
-void sd_resolve_free(sd_resolve *resolve);
+/* Process pending responses. After this function is called, you can
+ * get the next completed query object(s) using
+ * sd_resolve_get_next(). */
+int sd_resolve_process(sd_resolve *resolve);
 
-/** Return the UNIX file descriptor to select() for readability
- * on. Use this function to integrate sd-resolve with your custom main
- * loop. */
-int sd_resolve_fd(sd_resolve *resolve);
+/* Wait for a resolve event to complete. */
+int sd_resolve_wait(sd_resolve *resolve, uint64_t timeout_usec);
 
-/** Process pending responses. After this function is called you can
- * get the next completed query object(s) using sd_resolve_get_next(). If
- * block is non-zero wait until at least one response has been
- * processed. If block is zero, process all pending responses and
- * return. */
-int sd_resolve_wait(sd_resolve *resolve, int block);
+int sd_resolve_get_tid(sd_resolve *resolve, pid_t *tid);
 
-/** Issue a name to address query on the specified session. The
- * arguments are compatible with the ones of libc's
+int sd_resolve_attach_event(sd_resolve *resolve, sd_event *e, int priority);
+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
+ * arguments are compatible with those of libc's
  * getaddrinfo(3). The function returns a new query object. When the
- * query is completed you may retrieve the results using
- * sd_resolve_getaddrinfo_done().*/
-sd_resolve_query* sd_resolve_getaddrinfo(sd_resolve *resolve, const char *node, const char *service, const struct addrinfo *hints);
-
-/** Retrieve the results of a preceding sd_resolve_getaddrinfo()
- * call. Returns a addrinfo structure and a return value compatible
- * with libc's getaddrinfo(3). The query object q is destroyed by this
- * call and may not be used any further. Make sure to free the
- * returned addrinfo structure with sd_resolve_freeaddrinfo() and not
- * libc's freeaddrinfo(3)! If the query is not completed yet EAI_AGAIN
- * is returned.*/
-int sd_resolve_getaddrinfo_done(sd_resolve *resolve, sd_resolve_query* q, struct addrinfo **ret_res);
-
-/** Issue an address to name query on the specified session. The
- * arguments are compatible with the ones of libc's
+ * query is completed, you may retrieve the results using
+ * sd_resolve_getaddrinfo_done(). */
+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
+ * arguments are compatible with those of libc's
  * getnameinfo(3). The function returns a new query object. When the
- * query is completed you may retrieve the results using
+ * query is completed, you may retrieve the results using
  * sd_resolve_getnameinfo_done(). Set gethost (resp. getserv) to non-zero
  * if you want to query the hostname (resp. the service name). */
-sd_resolve_query* sd_resolve_getnameinfo(sd_resolve *resolve, const struct sockaddr *sa, socklen_t salen, int flags, int gethost, int getserv);
-
-/** Retrieve the results of a preceding sd_resolve_getnameinfo()
- * call. Returns the hostname and the service name in ret_host and
- * ret_serv. The query object q is destroyed by this call and may not
- * be used any further. If the query is not completed yet EAI_AGAIN is
- * returned. */
-int sd_resolve_getnameinfo_done(sd_resolve *resolve, sd_resolve_query* q, char *ret_host, size_t hostlen, char *ret_serv, size_t servlen);
-
-/** Issue a resolveer query on the specified session. The arguments are
- * compatible with the ones of libc's res_query(3). The function returns a new
- * query object. When the query is completed you may retrieve the results using
- * sd_resolve_res_done().  */
-sd_resolve_query* sd_resolve_res_query(sd_resolve *resolve, const char *dname, int class, int type);
-
-/** Issue an resolveer query on the specified session. The arguments are
- * compatible with the ones of libc's res_search(3). The function returns a new
- * query object. When the query is completed you may retrieve the results using
- * sd_resolve_res_done().  */
-sd_resolve_query* sd_resolve_res_search(sd_resolve *resolve, const char *dname, int class, int type);
-
-/** Retrieve the results of a preceding sd_resolve_res_query() or
- * resolve_res_search call.  The query object q is destroyed by this
- * call and may not be used any further. Returns a pointer to the
- * answer of the res_query call. If the query is not completed yet
- * -EAGAIN is returned, on failure -errno is returned, otherwise the
- * length of answer is returned. Make sure to free the answer is a
- * call to sd_resolve_freeanswer(). */
-int sd_resolve_res_done(sd_resolve *resolve, sd_resolve_query* q, unsigned char **answer);
-
-/** Return the next completed query object. If no query has been
- * completed yet, return NULL. Please note that you need to run
- * sd_resolve_wait() before this function will return sensible data.  */
-sd_resolve_query* sd_resolve_get_next(sd_resolve *resolve);
-
-/** Return the number of query objects (completed or not) attached to
- * this session */
-int sd_resolve_get_n_queries(sd_resolve *resolve);
-
-/** Cancel a currently running query. q is is destroyed by this call
- * and may not be used any futher. */
-void sd_resolve_cancel(sd_resolve *resolve, sd_resolve_query* q);
-
-/** Free the addrinfo structure as returned by
- * sd_resolve_getaddrinfo_done(). Make sure to use this functions instead
- * of the libc's freeaddrinfo()! */
-void sd_resolve_freeaddrinfo(struct addrinfo *ai);
-
-/** Returns non-zero when the query operation specified by q has been completed */
-int sd_resolve_isdone(sd_resolve *resolve, sd_resolve_query*q);
-
-/** Assign some opaque userdata with a query object */
-void sd_resolve_setuserdata(sd_resolve *resolve, sd_resolve_query *q, void *userdata);
-
-/** Return userdata assigned to a query object. Use
- * sd_resolve_setuserdata() to set this data. If no data has been set
- * prior to this call it returns NULL. */
-void* sd_resolve_getuserdata(sd_resolve *resolve, sd_resolve_query *q);
+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);
+
+/* Issue a resolver query on the specified session. The arguments are
+ * compatible with those of libc's res_query(3). The function returns a new
+ * query object. When the query is completed, you may retrieve the results using
+ * sd_resolve_res_done(). */
+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);
+
+/* Issue a resolver query on the specified session. The arguments are
+ * compatible with those of libc's res_search(3). The function returns a new
+ * query object. When the query is completed, you may retrieve the results using
+ * sd_resolve_res_done(). */
+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);
+
+sd_resolve_query *sd_resolve_query_ref(sd_resolve_query* q);
+sd_resolve_query *sd_resolve_query_unref(sd_resolve_query* q);
+
+/* Returns non-zero when the query operation specified by q has been completed. */
+int sd_resolve_query_is_done(sd_resolve_query*q);
+
+void *sd_resolve_query_get_userdata(sd_resolve_query *q);
+void *sd_resolve_query_set_userdata(sd_resolve_query *q, void *userdata);
+
+sd_resolve *sd_resolve_query_get_resolve(sd_resolve_query *q);
 
 _SD_END_DECLARATIONS;