/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
int iface_init(int i) {
struct sockaddr_nl addr;
int on = 1;
-
+
if ((fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE)) < 0) {
daemon_log(LOG_ERR, "socket(PF_NETLINK): %s", strerror(errno));
goto fail;
daemon_log(LOG_ERR, "bind(): %s", strerror(errno));
goto fail;
}
-
+
if (setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)) < 0) {
daemon_log(LOG_ERR, "SO_PASSCRED: %s", strerror(errno));
goto fail;
}
ifindex = i;
-
+
return fd;
-
+
fail:
if (fd >= 0) {
close(fd);
fd = -1;
}
-
+
return -1;
}
if (ifi->ifi_family != AF_UNSPEC || (int) ifi->ifi_index != ifindex)
return 0;
-
+
if (n->nlmsg_type == RTM_DELLINK) {
daemon_log(LOG_ERR, "Interface vanished.");
return -1;
}
assert(n->nlmsg_type == RTM_NEWLINK);
-
+
if ((ifi->ifi_flags & IFF_LOOPBACK) ||
(ifi->ifi_flags & IFF_NOARP) ||
ifi->ifi_type != ARPHRD_ETHER) {
int l;
uint32_t address = 0;
Address *i;
-
+
ifa = NLMSG_DATA(n);
if (ifa->ifa_family != AF_INET || (int) ifa->ifa_index != ifindex)
memcpy(&address, RTA_DATA(a), sizeof(uint32_t));
break;
}
-
+
a = RTA_NEXT(a, l);
}
static int process_response(int wait_for_done, unsigned seq) {
assert(fd >= 0);
-
+
do {
size_t bytes;
ssize_t r;
struct msghdr msghdr;
struct cmsghdr *cmsghdr;
struct ucred *ucred;
- struct iovec iov;
+ struct iovec iov;
struct nlmsghdr *p = (struct nlmsghdr *) replybuf;
-
+
memset(&iov, 0, sizeof(iov));
- iov.iov_base = replybuf;
+ iov.iov_base = replybuf;
iov.iov_len = sizeof(replybuf);
memset(&msghdr, 0, sizeof(msghdr));
msghdr.msg_name = (void*) NULL;
- msghdr.msg_namelen = 0;
- msghdr.msg_iov = &iov;
- msghdr.msg_iovlen = 1;
- msghdr.msg_control = cred_msg;
- msghdr.msg_controllen = sizeof(cred_msg);
+ msghdr.msg_namelen = 0;
+ msghdr.msg_iov = &iov;
+ msghdr.msg_iovlen = 1;
+ msghdr.msg_control = cred_msg;
+ msghdr.msg_controllen = sizeof(cred_msg);
msghdr.msg_flags = 0;
-
+
if ((r = recvmsg(fd, &msghdr, 0)) < 0) {
daemon_log(LOG_ERR, "recvmsg() failed: %s", strerror(errno));
return -1;
}
if (!(cmsghdr = CMSG_FIRSTHDR(&msghdr)) || cmsghdr->cmsg_type != SCM_CREDENTIALS) {
- daemon_log(LOG_WARNING, "No sender credentials received, ignoring data.");
+ daemon_log(LOG_WARNING, "No sender credentials received, ignoring data.");
return -1;
}
ucred = (struct ucred*) CMSG_DATA(cmsghdr);
-
+
if (ucred->uid != 0)
return -1;
bytes = (size_t) r;
-
+
for (; bytes > 0; p = NLMSG_NEXT(p, bytes)) {
if (!NLMSG_OK(p, bytes) || bytes < sizeof(struct nlmsghdr) || bytes < p->nlmsg_len) {
assert(fd >= 0);
assert(state);
-
+
memset(&req, 0, sizeof(req));
n = (struct nlmsghdr*) req;
n->nlmsg_len = NLMSG_LENGTH(sizeof(*ifi));
if (process_response(1, 0) < 0)
return -1;
-
+
n->nlmsg_type = RTM_GETADDR;
n->nlmsg_len = NLMSG_LENGTH(sizeof(*ifa));
n->nlmsg_seq = ++seq;
ifa = NLMSG_DATA(n);
ifa->ifa_family = AF_INET;
ifa->ifa_index = ifindex;
-
+
if (send(fd, n, n->nlmsg_len, 0) < 0) {
daemon_log(LOG_ERR, "send(): %s", strerror(errno));
return -1;
return -1;
*state = addresses ? STATE_SLEEPING : STATE_START;
-
+
return 0;
}
assert(fd >= 0);
b = !!addresses;
-
+
if (process_response(0, 0) < 0)
return -1;
*event = EVENT_ROUTABLE_ADDR_UNCONFIGURED;
else if (!b && addresses)
*event = EVENT_ROUTABLE_ADDR_CONFIGURED;
-
+
return 0;
}
void iface_done(void) {
Address *a;
-
+
if (fd >= 0) {
close(fd);
fd = -1;
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
char buf[AVAHI_DOMAIN_NAME_MAX*3], *e, *t, *p;
assert(b);
-
+
if (!(e = getenv("AVAHI_BROWSE_DOMAINS")))
return;
static void parse_domain_file(AvahiDomainBrowser *b) {
FILE *f;
char buf[AVAHI_DOMAIN_NAME_MAX];
-
+
assert(b);
if (!(f = avahi_xdg_config_open("avahi/browse-domains")))
return;
-
-
+
+
while (fgets(buf, sizeof(buf)-1, f)) {
char domain[AVAHI_DOMAIN_NAME_MAX];
buf[strcspn(buf, "\n\r")] = 0;
-
+
if (avahi_normalize_name(buf, domain, sizeof(domain)))
b->static_browse_domains = avahi_string_list_add(b->static_browse_domains, domain);
}
AvahiLookupFlags flags,
AvahiDomainBrowserCallback callback,
void *userdata) {
-
+
AvahiDomainBrowser *db = NULL;
DBusMessage *message = NULL, *reply = NULL;
DBusError error;
}
db->static_browse_domains = avahi_string_list_reverse(db->static_browse_domains);
-
+
if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "DomainBrowserNew"))) {
avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
goto fail;
}
}
-
+
dbus_message_unref(message);
dbus_message_unref(reply);
-
+
return db;
fail:
if (db)
avahi_domain_browser_free(db);
-
+
if (message)
dbus_message_unref(message);
int avahi_domain_browser_free (AvahiDomainBrowser *b) {
AvahiClient *client;
int r = AVAHI_OK;
-
+
assert(b);
assert(b->ref >= 1);
if (--(b->ref) >= 1)
return AVAHI_OK;
-
+
client = b->client;
if (b->path && avahi_client_is_connected(b->client))
if (b->defer_timeout)
b->client->poll_api->timeout_free(b->defer_timeout);
-
+
avahi_string_list_free(b->static_browse_domains);
avahi_free(b->path);
avahi_free(b);
assert(client);
assert(message);
-
+
dbus_error_init (&error);
if (!(path = dbus_message_get_path(message)))
switch (event) {
case AVAHI_BROWSER_NEW:
case AVAHI_BROWSER_REMOVE:
-
+
if (!dbus_message_get_args(
message, &error,
DBUS_TYPE_INT32, &interface,
}
break;
-
+
case AVAHI_BROWSER_CACHE_EXHAUSTED:
case AVAHI_BROWSER_ALL_FOR_NOW:
break;
case AVAHI_BROWSER_FAILURE: {
char *etxt;
-
+
if (!dbus_message_get_args(
message, &error,
DBUS_TYPE_STRING, &etxt,
fprintf(stderr, "Failed to parse browser event.\n");
goto fail;
}
-
+
avahi_client_set_errno(db->client, avahi_error_dbus_to_number(etxt));
break;
}
/* We had this entry already in the static entries */
return DBUS_HANDLER_RESULT_HANDLED;
}
-
+
db->callback(db, (AvahiIfIndex) interface, (AvahiProtocol) protocol, event, domain, (AvahiLookupResultFlags) flags, db->userdata);
return DBUS_HANDLER_RESULT_HANDLED;
AvahiIfIndex interface,
AvahiProtocol protocol,
const char *domain,
- AvahiLookupFlags flags,
+ AvahiLookupFlags flags,
AvahiServiceTypeBrowserCallback callback,
void *userdata) {
-
+
AvahiServiceTypeBrowser *b = NULL;
DBusMessage *message = NULL, *reply = NULL;
DBusError error;
avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "ServiceTypeBrowserNew"))) {
avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
i_interface = (int32_t) interface;
i_protocol = (int32_t) protocol;
u_flags = (uint32_t) flags;
return b;
fail:
-
+
if (dbus_error_is_set(&error)) {
avahi_client_set_dbus_error(client, &error);
dbus_error_free(&error);
if (b)
avahi_service_type_browser_free(b);
-
+
if (message)
dbus_message_unref(message);
assert(client);
assert(message);
-
+
dbus_error_init (&error);
if (!(path = dbus_message_get_path(message)))
domain = b->domain;
interface = b->interface;
protocol = b->protocol;
-
+
switch (event) {
case AVAHI_BROWSER_NEW:
case AVAHI_BROWSER_REMOVE:
goto fail;
}
break;
-
+
case AVAHI_BROWSER_CACHE_EXHAUSTED:
case AVAHI_BROWSER_ALL_FOR_NOW:
break;
case AVAHI_BROWSER_FAILURE: {
char *etxt;
-
+
if (!dbus_message_get_args(
message, &error,
DBUS_TYPE_STRING, &etxt,
fprintf(stderr, "Failed to parse browser event.\n");
goto fail;
}
-
+
avahi_client_set_errno(b->client, avahi_error_dbus_to_number(etxt));
break;
}
AvahiProtocol protocol,
const char *type,
const char *domain,
- AvahiLookupFlags flags,
+ AvahiLookupFlags flags,
AvahiServiceBrowserCallback callback,
void *userdata) {
-
+
AvahiServiceBrowser *b = NULL;
DBusMessage *message = NULL, *reply = NULL;
DBusError error;
avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
b->client = client;
b->callback = callback;
b->userdata = userdata;
avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
if (domain && domain[0])
if (!(b->domain = avahi_strdup(domain))) {
avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "ServiceBrowserNew"))) {
avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
dbus_message_unref(message);
dbus_message_unref(reply);
-
+
return b;
fail:
if (b)
avahi_service_browser_free(b);
-
+
if (message)
dbus_message_unref(message);
switch (event) {
case AVAHI_BROWSER_NEW:
case AVAHI_BROWSER_REMOVE:
-
+
if (!dbus_message_get_args (
message, &error,
DBUS_TYPE_INT32, &interface,
case AVAHI_BROWSER_FAILURE: {
char *etxt;
-
+
if (!dbus_message_get_args(
message, &error,
DBUS_TYPE_STRING, &etxt,
fprintf(stderr, "Failed to parse browser event.\n");
goto fail;
}
-
+
avahi_client_set_errno(b->client, avahi_error_dbus_to_number(etxt));
break;
}
AvahiLookupFlags flags,
AvahiRecordBrowserCallback callback,
void *userdata) {
-
+
AvahiRecordBrowser *b = NULL;
DBusMessage *message = NULL, *reply = NULL;
DBusError error;
avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
b->client = client;
b->callback = callback;
b->userdata = userdata;
avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "RecordBrowserNew"))) {
avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
dbus_message_unref(message);
dbus_message_unref(reply);
-
+
return b;
fail:
if (b)
avahi_record_browser_free(b);
-
+
if (message)
dbus_message_unref(message);
for (j = 0; j < 5; j++)
dbus_message_iter_next(&iter);
-
+
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_BYTE)
goto fail;
dbus_message_iter_get_fixed_array(&sub, &rdata, &rdata_size);
dbus_message_iter_next(&iter);
-
+
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32)
goto fail;
dbus_message_iter_get_basic(&iter, &flags);
-
+
break;
}
case AVAHI_BROWSER_FAILURE: {
char *etxt;
-
+
if (!dbus_message_get_args(
message, &error,
DBUS_TYPE_STRING, &etxt,
fprintf(stderr, "Failed to parse browser event.\n");
goto fail;
}
-
+
avahi_client_set_errno(b->client, avahi_error_dbus_to_number(etxt));
break;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
int avahi_nss_support(void) {
int b = 0;
-
+
#ifdef HAVE_DLOPEN
static const char * const libs[] = {
"libnss_mdns.so.2",
"libnss_mdns4.so.2",
"libnss_mdns6.so.2",
NULL };
-
+
const char * const *l;
-
+
for (l = libs; *l; l++) {
void *dl;
-
+
if ((dl = dlopen(*l, RTLD_LAZY))) {
b = 1;
dlclose(dl);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
const char *domain,
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
void *userdata) {
-
+
printf ("DOMAIN-BROWSER: Callback on %p, interface (%d), protocol (%d), event (%d), domain (%s), data (%s)\n", (void*) b, interface, protocol, event, domain ? domain : "NULL", (char*)userdata);
}
AvahiStringList *txt,
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
void *userdata) {
-
+
char addr[64];
char *txtr;
if (event == AVAHI_RESOLVER_FAILURE) {
const char *domain,
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
void *userdata) {
-
+
AvahiServiceResolver *sr;
printf ("SERVICE-BROWSER: Callback on %p, interface (%d), protocol (%d), event (%d), name (%s), type (%s), domain (%s), data (%s)\n", (void*) b, interface, protocol, event, name ? name : "NULL", type, domain ? domain : "NULL", (char*)userdata);
const char *domain,
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
void *userdata) {
-
+
printf ("SERVICE-TYPE-BROWSER: Callback on %p, interface (%d), protocol (%d), event (%d), type (%s), domain (%s), data (%s)\n", (void*) b, interface, protocol, event, type ? type : "NULL", domain ? domain : "NULL", (char*)userdata);
}
const char *name,
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
void *userdata) {
-
+
char addr[64];
if (event == AVAHI_RESOLVER_FAILURE) {
printf ("ADDRESS-RESOLVER: Callback on AddressResolver, timed out.\n");
const AvahiAddress *a,
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
void *userdata) {
-
+
AvahiClient *client;
AvahiAddressResolver *ar;
char addr[64];
-
+
if (event == AVAHI_RESOLVER_FAILURE) {
printf ("HOST-NAME-RESOLVER: Callback on HostNameResolver, timed out.\n");
return;
simple_poll = avahi_simple_poll_new();
poll_api = avahi_simple_poll_get(simple_poll);
-
+
if (!(avahi = avahi_client_new(poll_api, 0, avahi_client_callback, "omghai2u", &error))) {
fprintf(stderr, "Client failed: %s\n", avahi_strerror(error));
goto fail;
ret = avahi_client_get_host_name_fqdn (avahi);
printf("FQDN: %s (Error Return: %s)\n", ret, ret ? "OK" : avahi_strerror(avahi_client_errno(avahi)));
-
+
cookie = avahi_client_get_local_service_cookie(avahi);
printf("Local service cookie: %u (Error Return: %s)\n", cookie, cookie != AVAHI_SERVICE_COOKIE_INVALID ? "OK" : avahi_strerror(avahi_client_errno(avahi)));
printf("Creating entry group: %s\n", group ? "OK" : avahi_strerror(avahi_client_errno (avahi)));
assert(group);
-
+
printf("Sucessfully created entry group %p\n", (void*) group);
printf("%s\n", avahi_strerror(avahi_entry_group_add_service (group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, "Lathiat's Site", "_http._tcp", NULL, NULL, 80, "foo=bar", NULL)));
avahi_entry_group_commit (group);
domain = avahi_domain_browser_new (avahi, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, NULL, AVAHI_DOMAIN_BROWSER_BROWSE, 0, avahi_domain_browser_callback, "omghai3u");
-
+
if (domain == NULL)
printf ("Failed to create domain browser object\n");
else
avahi_simple_poll_loop(simple_poll);
printf("terminating...\n");
-
+
fail:
if (avahi)
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AVAHI_CLIENT_S_RUNNING = AVAHI_SERVER_RUNNING, /**< Server state: RUNNING */
AVAHI_CLIENT_S_COLLISION = AVAHI_SERVER_COLLISION, /**< Server state: COLLISION */
AVAHI_CLIENT_FAILURE = 100, /**< Some kind of error happened on the client side */
- AVAHI_CLIENT_CONNECTING = 101 /**< We're still connecting. This state is only entered when AVAHI_CLIENT_NO_FAIL has been passed to avahi_client_new() and the daemon is not yet available. */
+ AVAHI_CLIENT_CONNECTING = 101 /**< We're still connecting. This state is only entered when AVAHI_CLIENT_NO_FAIL has been passed to avahi_client_new() and the daemon is not yet available. */
} AvahiClientState;
typedef enum {
const char* avahi_client_get_host_name_fqdn (AvahiClient*);
/** Get state */
-AvahiClientState avahi_client_get_state(AvahiClient *client);
+AvahiClientState avahi_client_get_state(AvahiClient *client);
/** @{ \name Error Handling */
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
int r = AVAHI_OK;
int32_t state;
AvahiClient *client;
-
+
dbus_error_init(&error);
assert(group);
client = group->client;
-
+
if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, group->path, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "GetState"))) {
r = avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
if (!(reply = dbus_connection_send_with_reply_and_block(client->bus, message, -1, &error)) ||
dbus_error_is_set (&error)) {
r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
goto fail;
}
-
+
if (!dbus_message_get_args(reply, &error, DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID) ||
dbus_error_is_set (&error)) {
r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
dbus_message_unref(reply);
return state;
-
+
fail:
if (dbus_error_is_set(&error)) {
r = avahi_client_set_dbus_error(client, &error);
avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
group->client = client;
group->callback = callback;
group->userdata = userdata;
group->state_valid = 0;
group->path = NULL;
AVAHI_LLIST_PREPEND(AvahiEntryGroup, groups, client->groups, group);
-
+
if (!(message = dbus_message_new_method_call(
AVAHI_DBUS_NAME,
AVAHI_DBUS_PATH_SERVER,
avahi_client_set_errno (client, AVAHI_ERR_DBUS_ERROR);
goto fail;
}
-
+
if (!(group->path = avahi_strdup (path))) {
/* FIXME: We don't remove the object on the server side */
avahi_client_set_errno(client, state);
goto fail;
}
-
+
avahi_entry_group_set_state(group, (AvahiEntryGroupState) state);
dbus_message_unref(message);
if (group)
avahi_entry_group_free(group);
-
+
if (message)
dbus_message_unref(message);
if (reply)
dbus_message_unref(reply);
-
+
return NULL;
}
DBusError error;
int r = AVAHI_OK;
AvahiClient *client;
-
+
dbus_error_init(&error);
assert(group);
client = group->client;
-
+
if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, group->path, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, method))) {
r = avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
if (!(reply = dbus_connection_send_with_reply_and_block(client->bus, message, -1, &error)) ||
dbus_error_is_set (&error)) {
r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
goto fail;
}
-
+
if (!dbus_message_get_args(reply, &error, DBUS_TYPE_INVALID) ||
dbus_error_is_set (&error)) {
r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
dbus_message_unref(reply);
return AVAHI_OK;
-
+
fail:
if (dbus_error_is_set(&error)) {
r = avahi_client_set_dbus_error(client, &error);
int avahi_entry_group_free(AvahiEntryGroup *group) {
AvahiClient *client = group->client;
int r = AVAHI_OK;
-
+
assert(group);
-
+
if (group->path && avahi_client_is_connected(client))
r = entry_group_simple_method_call(group, "Free");
-
+
AVAHI_LLIST_REMOVE(AvahiEntryGroup, groups, client->groups, group);
avahi_free(group->path);
int avahi_entry_group_commit(AvahiEntryGroup *group) {
int ret;
assert(group);
-
+
if (!group->path || !avahi_client_is_connected(group->client))
return avahi_client_set_errno(group->client, AVAHI_ERR_BAD_STATE);
int avahi_entry_group_reset(AvahiEntryGroup *group) {
int ret;
assert(group);
-
+
if (!group->path || !avahi_client_is_connected(group->client))
return avahi_client_set_errno(group->client, AVAHI_ERR_BAD_STATE);
if ((ret = entry_group_simple_method_call(group, "Reset")) < 0)
return ret;
-
+
group->state_valid = 0;
return ret;
}
if (group->state_valid)
return group->state;
-
+
return retrieve_state(group);
}
AvahiClient* avahi_entry_group_get_client (AvahiEntryGroup *group) {
assert(group);
-
+
return group->client;
}
int r = AVAHI_OK;
int b;
AvahiClient *client;
-
+
assert(group);
client = group->client;
return avahi_client_set_errno(group->client, AVAHI_ERR_BAD_STATE);
dbus_error_init(&error);
-
+
if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, group->path, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "IsEmpty"))) {
r = avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
if (!(reply = dbus_connection_send_with_reply_and_block(client->bus, message, -1, &error)) ||
dbus_error_is_set (&error)) {
r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
goto fail;
}
-
+
if (!dbus_message_get_args(reply, &error, DBUS_TYPE_BOOLEAN, &b, DBUS_TYPE_INVALID) ||
dbus_error_is_set (&error)) {
r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
dbus_message_unref(reply);
return !!b;
-
+
fail:
if (dbus_error_is_set(&error)) {
r = avahi_client_set_dbus_error(client, &error);
static int append_rdata(DBusMessage *message, const void *rdata, size_t size) {
DBusMessageIter iter, sub;
-
+
assert(message);
-
+
dbus_message_iter_init_append(message, &iter);
-
+
if (!(dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING, &sub)) ||
!(dbus_message_iter_append_fixed_array(&sub, DBUS_TYPE_BYTE, &rdata, size)) ||
!(dbus_message_iter_close_container(&iter, &sub)))
return -1;
-
+
return 0;
}
/* Reverse the string list, so that we can pass it in-order to the server */
txt = avahi_string_list_reverse(txt);
-
+
if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "ay", &sub))
goto fail;
for (p = txt; p != NULL; p = p->next) {
DBusMessageIter sub2;
const uint8_t *data = p->text;
-
+
if (!(dbus_message_iter_open_container(&sub, DBUS_TYPE_ARRAY, "y", &sub2)) ||
!(dbus_message_iter_append_fixed_array(&sub2, DBUS_TYPE_BYTE, &data, p->size)) ||
!(dbus_message_iter_close_container(&sub, &sub2)))
const char *host,
uint16_t port,
AvahiStringList *txt) {
-
+
DBusMessage *message = NULL, *reply = NULL;
int r = AVAHI_OK;
DBusError error;
if (!host)
host = "";
-
+
dbus_error_init(&error);
-
+
if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, group->path, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddService"))) {
r = avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
r = avahi_client_set_errno(group->client, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
if (!(reply = dbus_connection_send_with_reply_and_block(client->bus, message, -1, &error)) ||
dbus_error_is_set (&error)) {
r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
goto fail;
}
-
+
if (!dbus_message_get_args(reply, &error, DBUS_TYPE_INVALID) ||
dbus_error_is_set (&error)) {
r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
return AVAHI_OK;
fail:
-
+
if (dbus_error_is_set(&error)) {
r = avahi_client_set_dbus_error(client, &error);
dbus_error_free(&error);
const char *host,
uint16_t port,
...) {
-
+
va_list va;
int r;
AvahiStringList *txt;
domain = "";
dbus_error_init(&error);
-
+
if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, group->path, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddServiceSubtype"))) {
r = avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
r = avahi_client_set_errno(group->client, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
if (!(reply = dbus_connection_send_with_reply_and_block(client->bus, message, -1, &error)) ||
dbus_error_is_set (&error)) {
r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
goto fail;
}
-
+
if (!dbus_message_get_args(reply, &error, DBUS_TYPE_INVALID) ||
dbus_error_is_set (&error)) {
r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
return AVAHI_OK;
fail:
-
+
if (dbus_error_is_set(&error)) {
r = avahi_client_set_dbus_error(client, &error);
dbus_error_free(&error);
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiPublishFlags flags,
- const char *name,
- const char *type,
- const char *domain,
+ const char *name,
+ const char *type,
+ const char *domain,
...) {
va_list va;
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiPublishFlags flags,
- const char *name,
- const char *type,
- const char *domain,
+ const char *name,
+ const char *type,
+ const char *domain,
AvahiStringList *txt) {
DBusMessage *message = NULL, *reply = NULL;
if (!domain)
domain = "";
-
+
dbus_error_init(&error);
-
+
if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, group->path, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "UpdateServiceTxt"))) {
r = avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
goto fail;
}
-
+
if (!dbus_message_get_args(reply, &error, DBUS_TYPE_INVALID) ||
dbus_error_is_set (&error)) {
r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
return AVAHI_OK;
fail:
-
+
if (dbus_error_is_set(&error)) {
r = avahi_client_set_dbus_error(client, &error);
dbus_error_free(&error);
return avahi_client_set_errno(group->client, AVAHI_ERR_BAD_STATE);
dbus_error_init(&error);
-
+
if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, group->path, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddAddress"))) {
r = avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
i_interface = (int32_t) interface;
i_protocol = (int32_t) protocol;
u_flags = (uint32_t) flags;
-
+
if (!avahi_address_snprint (s_address, sizeof (s_address), a))
{
r = avahi_client_set_errno(client, AVAHI_ERR_INVALID_ADDRESS);
r = avahi_client_set_errno(group->client, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
if (!(reply = dbus_connection_send_with_reply_and_block(client->bus, message, -1, &error)) ||
dbus_error_is_set (&error)) {
r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
goto fail;
}
-
+
if (!dbus_message_get_args(reply, &error, DBUS_TYPE_INVALID) ||
dbus_error_is_set (&error)) {
r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
return AVAHI_OK;
fail:
-
+
if (dbus_error_is_set(&error)) {
r = avahi_client_set_dbus_error(client, &error);
dbus_error_free(&error);
return avahi_client_set_errno(group->client, AVAHI_ERR_BAD_STATE);
dbus_error_init(&error);
-
+
if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, group->path, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddRecord"))) {
r = avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
i_interface = (int32_t) interface;
i_protocol = (int32_t) protocol;
u_flags = (uint32_t) flags;
-
+
if (!dbus_message_append_args(
message,
DBUS_TYPE_INT32, &i_interface,
r = avahi_client_set_errno(group->client, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
if (!(reply = dbus_connection_send_with_reply_and_block(client->bus, message, -1, &error)) ||
dbus_error_is_set (&error)) {
r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
goto fail;
}
-
+
if (!dbus_message_get_args(reply, &error, DBUS_TYPE_INVALID) ||
dbus_error_is_set (&error)) {
r = avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
return AVAHI_OK;
fail:
-
+
if (dbus_error_is_set(&error)) {
r = avahi_client_set_dbus_error(client, &error);
dbus_error_free(&error);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
char *version_string, *host_name, *host_name_fqdn, *domain_name;
uint32_t local_service_cookie;
int local_service_cookie_valid;
-
+
AvahiClientCallback callback;
void *userdata;
-
+
AVAHI_LLIST_HEAD(AvahiEntryGroup, groups);
AVAHI_LLIST_HEAD(AvahiDomainBrowser, domain_browsers);
AVAHI_LLIST_HEAD(AvahiServiceBrowser, service_browsers);
struct AvahiDomainBrowser {
int ref;
-
+
char *path;
AvahiClient *client;
AvahiDomainBrowserCallback callback;
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AvahiPublishFlags flags /**< Usually 0, unless you know what you do */,
const char *name /**< The name for the new service. Must be valid service name. i.e. a string shorter than 63 characters and valid UTF-8. May not be NULL. */,
const char *type /**< The service type for the new service, such as _http._tcp. May not be NULL. */,
- const char *domain /**< The domain to register this domain in. We recommend to pass NULL here, to let the daemon decide */,
+ const char *domain /**< The domain to register this domain in. We recommend to pass NULL here, to let the daemon decide */,
const char *host /**< The host this services is residing on. We recommend to pass NULL here, the daemon will than automatically insert the local host name in that case */,
uint16_t port /**< The IP port number of this service */,
...) AVAHI_GCC_SENTINEL;
AvahiIfIndex interface /**< The interface this service is announced on. This should match the value passed to the original avahi_entry_group_add_service() call. */,
AvahiProtocol protocol /**< The protocol this service is announced with. This should match the value passed to the original avahi_entry_group_add_service() call. */,
AvahiPublishFlags flags /**< Only != 0 if you really know what you do */,
- const char *name /**< The name of the service, as passed to avahi_entry_group_add_service(). May not be NULL. */,
- const char *type /**< The type of the service, as passed to avahi_entry_group_add_service(). May not be NULL. */,
- const char *domain /**< The domain this service resides is, as passed to avahi_entry_group_add_service(). May be NULL. */,
+ const char *name /**< The name of the service, as passed to avahi_entry_group_add_service(). May not be NULL. */,
+ const char *type /**< The type of the service, as passed to avahi_entry_group_add_service(). May not be NULL. */,
+ const char *domain /**< The domain this service resides is, as passed to avahi_entry_group_add_service(). May be NULL. */,
...) AVAHI_GCC_SENTINEL;
/** Update a TXT record for an existing service. Similar to avahi_entry_group_update_service_txt() but takes an AvahiStringList for the TXT strings, instead of a NULL terminated list of arguments. */
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiPublishFlags flags,
- const char *name,
- const char *type,
- const char *domain,
+ const char *name,
+ const char *type,
+ const char *domain,
AvahiStringList *strlst);
/** \cond fulldocs */
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
assert(client);
assert(message);
-
+
dbus_error_init (&error);
if (!(path = dbus_message_get_path(message)))
uint16_t port;
DBusMessageIter iter, sub;
AvahiAddress a;
-
+
if (!dbus_message_get_args(
message, &error,
DBUS_TYPE_INT32, &interface,
DBUS_TYPE_UINT16, &port,
DBUS_TYPE_INVALID) ||
dbus_error_is_set (&error)) {
-
+
fprintf(stderr, "Failed to parse resolver event.\n");
goto fail;
}
-
+
dbus_message_iter_init(message, &iter);
-
+
for (j = 0; j < 9; j++)
dbus_message_iter_next(&iter);
-
+
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_ARRAY) {
fprintf(stderr, "Error parsing service resolving message\n");
goto fail;
}
-
+
strlst = NULL;
dbus_message_iter_recurse(&iter, &sub);
-
+
for (;;) {
DBusMessageIter sub2;
int at;
const uint8_t *k;
int n;
-
+
if ((at = dbus_message_iter_get_arg_type(&sub)) == DBUS_TYPE_INVALID)
break;
-
+
assert(at == DBUS_TYPE_ARRAY);
-
+
if (dbus_message_iter_get_element_type(&sub) != DBUS_TYPE_BYTE) {
fprintf(stderr, "Error parsing service resolving message\n");
goto fail;
}
-
+
dbus_message_iter_recurse(&sub, &sub2);
k = NULL; n = 0;
dbus_message_iter_get_fixed_array(&sub2, &k, &n);
if (k && n > 0)
strlst = avahi_string_list_add_arbitrary(strlst, k, n);
-
+
dbus_message_iter_next(&sub);
}
}
dbus_message_iter_get_basic(&iter, &flags);
-
+
assert(address);
if (address[0] == 0)
address = NULL;
else
avahi_address_parse(address, (AvahiProtocol) aprotocol, &a);
-
+
r->callback(r, (AvahiIfIndex) interface, (AvahiProtocol) protocol, AVAHI_RESOLVER_FOUND, name, type, domain, host, address ? &a : NULL, port, strlst, (AvahiLookupResultFlags) flags, r->userdata);
-
+
avahi_string_list_free(strlst);
break;
}
-
+
case AVAHI_RESOLVER_FAILURE: {
char *etxt;
-
+
if (!dbus_message_get_args(
message, &error,
DBUS_TYPE_STRING, &etxt,
fprintf(stderr, "Failed to parse resolver event.\n");
goto fail;
}
-
+
avahi_client_set_errno(r->client, avahi_error_dbus_to_number(etxt));
r->callback(r, r->interface, r->protocol, event, r->name, r->type, r->domain, NULL, NULL, 0, NULL, 0, r->userdata);
break;
return DBUS_HANDLER_RESULT_HANDLED;
-
+
fail:
dbus_error_free (&error);
avahi_string_list_free(strlst);
int32_t i_interface, i_protocol, i_aprotocol;
uint32_t u_flags;
char *path;
-
+
assert(client);
assert(type);
if (!name)
name = "";
-
+
dbus_error_init (&error);
if (!avahi_client_is_connected(client)) {
r->name = r->type = r->domain = NULL;
r->interface = interface;
r->protocol = protocol;
-
+
AVAHI_LLIST_PREPEND(AvahiServiceResolver, service_resolvers, client->service_resolvers, r);
if (name && name[0])
avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
-
+
+
if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "ServiceResolverNew"))) {
avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
dbus_message_unref(message);
dbus_message_unref(reply);
return r;
-
+
fail:
if (dbus_error_is_set(&error)) {
if (r)
avahi_service_resolver_free(r);
-
+
if (message)
dbus_message_unref(message);
if (reply)
dbus_message_unref(reply);
-
+
return NULL;
}
assert(client);
assert(message);
-
+
dbus_error_init (&error);
if (!(path = dbus_message_get_path(message)))
uint32_t flags;
char *name, *address;
AvahiAddress a;
-
+
if (!dbus_message_get_args(
message, &error,
DBUS_TYPE_INT32, &interface,
fprintf(stderr, "Failed to parse resolver event.\n");
goto fail;
}
-
+
assert(address);
if (!avahi_address_parse(address, (AvahiProtocol) aprotocol, &a)) {
fprintf(stderr, "Failed to parse address\n");
goto fail;
}
-
+
r->callback(r, (AvahiIfIndex) interface, (AvahiProtocol) protocol, AVAHI_RESOLVER_FOUND, name, &a, (AvahiLookupResultFlags) flags, r->userdata);
break;
}
-
+
case AVAHI_RESOLVER_FAILURE: {
char *etxt;
-
+
if (!dbus_message_get_args(
message, &error,
DBUS_TYPE_STRING, &etxt,
fprintf(stderr, "Failed to parse resolver event.\n");
goto fail;
}
-
+
avahi_client_set_errno(r->client, avahi_error_dbus_to_number(etxt));
r->callback(r, r->interface, r->protocol, event, r->host_name, NULL, 0, r->userdata);
break;
}
return DBUS_HANDLER_RESULT_HANDLED;
-
+
fail:
dbus_error_free (&error);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
int32_t i_interface, i_protocol, i_aprotocol;
uint32_t u_flags;
char *path;
-
+
assert(client);
assert(name);
r->interface = interface;
r->protocol = protocol;
r->host_name = NULL;
-
+
AVAHI_LLIST_PREPEND(AvahiHostNameResolver, host_name_resolvers, client->host_name_resolvers, r);
if (!(r->host_name = avahi_strdup(name))) {
dbus_message_unref(reply);
return r;
-
+
fail:
if (dbus_error_is_set(&error)) {
if (r)
avahi_host_name_resolver_free(r);
-
+
if (message)
dbus_message_unref(message);
assert(client);
assert(message);
-
+
dbus_error_init (&error);
if (!(path = dbus_message_get_path(message)))
uint32_t flags;
char *name, *address;
AvahiAddress a;
-
+
if (!dbus_message_get_args(
message, &error,
DBUS_TYPE_INT32, &interface,
fprintf(stderr, "Failed to parse resolver event.\n");
goto fail;
}
-
+
assert(address);
if (!avahi_address_parse(address, (AvahiProtocol) aprotocol, &a)) {
fprintf(stderr, "Failed to parse address\n");
goto fail;
}
-
+
r->callback(r, (AvahiIfIndex) interface, (AvahiProtocol) protocol, AVAHI_RESOLVER_FOUND, &a, name, (AvahiLookupResultFlags) flags, r->userdata);
break;
}
case AVAHI_RESOLVER_FAILURE: {
char *etxt;
-
+
if (!dbus_message_get_args(
message, &error,
DBUS_TYPE_STRING, &etxt,
fprintf(stderr, "Failed to parse resolver event.\n");
goto fail;
}
-
+
avahi_client_set_errno(r->client, avahi_error_dbus_to_number(etxt));
r->callback(r, r->interface, r->protocol, event, &r->address, NULL, 0, r->userdata);
break;
}
return DBUS_HANDLER_RESULT_HANDLED;
-
+
fail:
dbus_error_free (&error);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
AvahiIfIndex interface,
AvahiProtocol protocol,
const AvahiAddress *a,
- AvahiLookupFlags flags,
+ AvahiLookupFlags flags,
AvahiAddressResolverCallback callback,
void *userdata) {
r->interface = interface;
r->protocol = protocol;
r->address = *a;
-
+
AVAHI_LLIST_PREPEND(AvahiAddressResolver, address_resolvers, client->address_resolvers, r);
if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "AddressResolverNew"))) {
avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
goto fail;
}
-
+
if (!(r->path = avahi_strdup(path))) {
/* FIXME: We don't remove the object on the server side */
dbus_message_unref(reply);
return r;
-
+
fail:
if (dbus_error_is_set(&error)) {
if (r)
avahi_address_resolver_free(r);
-
+
if (message)
dbus_message_unref(message);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
assert(p);
printf("Dumping %lu bytes from %p:\n", (unsigned long) size, p);
-
+
while (size > 0) {
unsigned i;
- for (i = 0; i < 16; i++) {
+ for (i = 0; i < 16; i++) {
if (i < size)
printf("%02x ", c[i]);
else
else
printf(" ");
}
-
+
printf("\n");
c += 16;
if (size <= 16)
break;
-
+
size -= 16;
}
}
const AvahiPoll *poll_api;
AvahiClient *client;
AvahiRecordBrowser *r;
-
+
simple_poll = avahi_simple_poll_new();
assert(simple_poll);
-
+
poll_api = avahi_simple_poll_get(simple_poll);
assert(poll_api);
-
+
client = avahi_client_new(poll_api, 0, NULL, NULL, NULL);
assert(client);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
const AvahiPoll *poll_api;
AvahiClient *client;
AvahiServiceResolver *r;
-
+
simple_poll = avahi_simple_poll_new();
assert(simple_poll);
-
+
poll_api = avahi_simple_poll_get(simple_poll);
assert(poll_api);
-
+
client = avahi_client_new(poll_api, 0, NULL, NULL, NULL);
assert(client);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
FILE *f;
f = avahi_xdg_config_open("foo");
-
+
if (f)
fclose(f);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
"gurke ###",
NULL
};
-
+
char *r = NULL;
int i, j, k;
for (k = 0; test_strings[k]; k++) {
printf(">>>>>%s<<<<\n", test_strings[k]);
-
+
for (j = 0; j < 2; j++) {
-
+
for (i = 0; i <= 100; i++) {
char *n;
-
+
n = i == 0 ? avahi_strdup(test_strings[k]) : (j ? avahi_alternative_service_name(r) : avahi_alternative_host_name(r));
avahi_free(r);
r = n;
assert(avahi_is_valid_service_name(n));
else
assert(avahi_is_valid_host_name(n));
-
+
printf("%s\n", r);
}
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
char *e;
e = strchr(c, 0) - 1;
-
+
while (e >= c) {
if (avahi_utf8_valid(c))
break;
-
+
assert(*e & 128);
*e = 0;
if (!avahi_is_valid_host_name(s))
return NULL;
-
+
if ((e = strrchr(s, '-'))) {
const char *p;
e++;
-
+
for (p = e; *p; p++)
if (!isdigit(*p)) {
e = NULL;
}
drop_incomplete_utf8(c);
-
+
r = avahi_strdup_printf("%s-%s", c, m);
avahi_free(c);
avahi_free(m);
-
+
} else {
char *c;
return NULL;
drop_incomplete_utf8(c);
-
+
r = avahi_strdup_printf("%s-2", c);
avahi_free(c);
}
if (!avahi_is_valid_service_name(s))
return NULL;
-
+
if ((e = strstr(s, " #"))) {
const char *n, *p;
e += 2;
-
+
while ((n = strstr(e, " #")))
e = n + 2;
if (e && (*e == '0' || *e == 0))
e = NULL;
}
-
+
if (e) {
char *c, *m;
size_t l;
}
drop_incomplete_utf8(c);
-
+
r = avahi_strdup_printf("%s #%s", c, m);
avahi_free(c);
avahi_free(m);
if (!(c = avahi_strndup(s, AVAHI_LABEL_MAX-1-3)))
return NULL;
-
+
drop_incomplete_utf8(c);
-
+
r = avahi_strdup_printf("%s #2", c);
avahi_free(c);
}
assert(avahi_is_valid_service_name(r));
-
+
return r;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
static void watch_callback(AvahiWatch *avahi_watch, AVAHI_GCC_UNUSED int fd, AvahiWatchEvent events, void *userdata) {
DBusWatch *dbus_watch = userdata;
-
+
assert(avahi_watch);
assert(dbus_watch);
static dbus_bool_t update_watch(const AvahiPoll *poll_api, DBusWatch *dbus_watch) {
AvahiWatch *avahi_watch;
dbus_bool_t b;
-
+
assert(dbus_watch);
avahi_watch = dbus_watch_get_data(dbus_watch);
b = dbus_watch_get_enabled(dbus_watch);
-
+
if (b && !avahi_watch) {
if (!(avahi_watch = poll_api->watch_new(
return FALSE;
dbus_watch_set_data(dbus_watch, avahi_watch, NULL);
-
+
} else if (!b && avahi_watch) {
-
+
poll_api->watch_free(avahi_watch);
dbus_watch_set_data(dbus_watch, NULL, NULL);
} else if (avahi_watch) {
-
+
/* Update flags */
poll_api->watch_update(avahi_watch, dbus_watch_get_flags(dbus_watch));
}
static dbus_bool_t add_watch(DBusWatch *dbus_watch, void *userdata) {
ConnectionData *d = userdata;
-
+
assert(dbus_watch);
assert(d);
static void remove_watch(DBusWatch *dbus_watch, void *userdata) {
ConnectionData *d = userdata;
AvahiWatch *avahi_watch;
-
+
assert(dbus_watch);
assert(d);
static void watch_toggled(DBusWatch *dbus_watch, void *userdata) {
ConnectionData *d = userdata;
-
+
assert(dbus_watch);
assert(d);
if (--t->ref <= 0) {
if (t->avahi_timeout)
t->poll_api->timeout_free(t->avahi_timeout);
-
+
avahi_free(t);
}
}
static void update_timeout(TimeoutData *timeout) {
assert(timeout);
assert(timeout->ref >= 1);
-
+
if (dbus_timeout_get_enabled(timeout->dbus_timeout)) {
struct timeval tv;
avahi_elapse_time(&tv, dbus_timeout_get_interval(timeout->dbus_timeout), 0);
static void timeout_callback(AvahiTimeout *avahi_timeout, void *userdata) {
TimeoutData *timeout = userdata;
-
+
assert(avahi_timeout);
assert(timeout);
if (timeout->avahi_timeout)
update_timeout(timeout);
-
+
timeout_data_unref(timeout);
}
if ((b = dbus_timeout_get_enabled(dbus_timeout)))
avahi_elapse_time(&tv, dbus_timeout_get_interval(dbus_timeout), 0);
-
+
if (!(timeout->avahi_timeout = d->poll_api->timeout_new(
d->poll_api,
b ? &tv : NULL,
static void dispatch_status(AVAHI_GCC_UNUSED DBusConnection *connection, DBusDispatchStatus new_status, void *userdata) {
ConnectionData *d = userdata;
-
+
if (new_status == DBUS_DISPATCH_DATA_REMAINS)
request_dispatch(d, 1);
}
int avahi_dbus_connection_glue(DBusConnection *c, const AvahiPoll *poll_api) {
ConnectionData *d = NULL;
-
+
assert(c);
assert(poll_api);
d->poll_api = poll_api;
d->connection = c;
d->ref = 1;
-
+
if (!(d->dispatch_timeout = poll_api->timeout_new(poll_api, NULL, dispatch_timeout_callback, d)))
goto fail;
-
+
if (!(dbus_connection_set_watch_functions(c, add_watch, remove_watch, watch_toggled, connection_data_ref(d), (DBusFreeFunction)connection_data_unref)))
goto fail;
request_dispatch(d, 1);
connection_data_unref(d);
-
+
return 0;
fail:
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AVAHI_DBUS_ERR_IS_PATTERN,
AVAHI_DBUS_ERR_COLLISION,
AVAHI_DBUS_ERR_INVALID_RECORD,
-
+
AVAHI_DBUS_ERR_INVALID_SERVICE_NAME,
AVAHI_DBUS_ERR_INVALID_SERVICE_TYPE,
AVAHI_DBUS_ERR_INVALID_PORT,
AVAHI_DBUS_ERR_TOO_MANY_OBJECTS,
AVAHI_DBUS_ERR_TOO_MANY_ENTRIES,
AVAHI_DBUS_ERR_OS,
-
+
AVAHI_DBUS_ERR_ACCESS_DENIED,
AVAHI_DBUS_ERR_INVALID_OPERATION,
AVAHI_DBUS_ERR_DBUS_ERROR,
AVAHI_DBUS_ERR_INVALID_INTERFACE,
AVAHI_DBUS_ERR_INVALID_PROTOCOL,
AVAHI_DBUS_ERR_INVALID_FLAGS,
-
+
AVAHI_DBUS_ERR_NOT_FOUND,
AVAHI_DBUS_ERR_INVALID_CONFIG,
AVAHI_DBUS_ERR_VERSION_MISMATCH,
AVAHI_DBUS_ERR_DNS_SERVFAIL,
AVAHI_DBUS_ERR_DNS_NXDOMAIN,
AVAHI_DBUS_ERR_DNS_NOTIMP,
-
+
AVAHI_DBUS_ERR_DNS_REFUSED,
AVAHI_DBUS_ERR_DNS_YXDOMAIN,
AVAHI_DBUS_ERR_DNS_YXRRSET,
for (m = error_map; m->dbus_error; m++)
if (strcmp(m->dbus_error, s) == 0)
return m->avahi_error;
-
+
return AVAHI_ERR_DBUS_ERROR;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
const char *p;
size_t size;
char name[64], type[AVAHI_DOMAIN_NAME_MAX], domain[AVAHI_DOMAIN_NAME_MAX];
-
+
printf("%s\n", s = avahi_normalize_name_strdup("foo.foo\\046."));
avahi_free(s);
printf("%s\n", s = avahi_normalize_name_strdup("foo.foo\\.foo."));
avahi_free(s);
-
+
printf("%s\n", s = avahi_normalize_name_strdup("fo\\\\o\\..f oo."));
avahi_free(s);
avahi_service_name_split(t, name, sizeof(name), type, sizeof(type), domain, sizeof(domain));
printf("name: <%s>; type: <%s>; domain <%s>\n", name, type, domain);
-
+
avahi_service_name_join(t, sizeof(t), NULL, "_http._tcp", "one.two\\. .local");
printf("<%s>\n", t);
size = sizeof(r);
s = r;
-
+
printf("escaped: <%s>\n", avahi_escape_label(t, strlen(t), &s, &size));
p = r;
assert(!avahi_is_valid_service_type_generic("_foo._bar.waldo"));
assert(!avahi_is_valid_service_type_strict("_foo._bar.waldo"));
assert(!avahi_is_valid_service_subtype("_foo._bar.waldo"));
-
+
assert(!avahi_is_valid_service_type_generic(""));
assert(!avahi_is_valid_service_type_strict(""));
assert(!avahi_is_valid_service_subtype(""));
assert(!avahi_is_valid_fqdn("192.168.50.1"));
assert(!avahi_is_valid_fqdn("::1"));
assert(!avahi_is_valid_fqdn(".192.168.50.1."));
-
+
return 0;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
char *avahi_unescape_label(const char **name, char *dest, size_t size) {
unsigned i = 0;
char *d;
-
+
assert(dest);
assert(size > 0);
assert(name);
d = dest;
-
+
for (;;) {
if (i >= size)
return NULL;
(*name)++;
break;
}
-
+
if (**name == 0)
break;
-
+
if (**name == '\\') {
/* Escaped character */
if (**name == 0)
/* Ending NUL */
return NULL;
-
+
else if (**name == '\\' || **name == '.') {
/* Escaped backslash or dot */
*(d++) = *((*name) ++);
int n;
/* Escaped literal ASCII character */
-
+
if (!isdigit(*(*name+1)) || !isdigit(*(*name+2)))
return NULL;
if (n > 255 || n == 0)
return NULL;
-
+
*(d++) = (char) n;
i++;
(*name) += 3;
} else
return NULL;
-
+
} else {
/* Normal character */
-
+
*(d++) = *((*name) ++);
i++;
}
if (*src == '.' || *src == '\\') {
/* Dot or backslash */
-
+
if (*ret_size < 3)
return NULL;
-
+
*((*ret_name) ++) = '\\';
*((*ret_name) ++) = *src;
(*ret_size) -= 2;
-
+
} else if (
*src == '_' ||
*src == '-' ||
(*src >= 'A' && *src <= 'Z')) {
/* Proper character */
-
+
if (*ret_size < 2)
return NULL;
-
+
*((*ret_name)++) = *src;
(*ret_size) --;
-
+
} else {
/* Everything else */
*((*ret_name) ++) = '0' + (char) ((uint8_t) *src / 100);
*((*ret_name) ++) = '0' + (char) (((uint8_t) *src / 10) % 10);
*((*ret_name) ++) = '0' + (char) ((uint8_t) *src % 10);
-
+
(*ret_size) -= 4;
}
char *avahi_normalize_name(const char *s, char *ret_s, size_t size) {
int empty = 1;
char *r;
-
+
assert(s);
assert(ret_s);
assert(size > 0);
return NULL;
}
-
+
if (!empty) {
if (size < 1)
return NULL;
-
+
*(r++) = '.';
size--;
-
+
} else
empty = 0;
-
+
avahi_escape_label(label, strlen(label), &r, &size);
}
if (a == b)
return 1;
-
+
for (;;) {
char ca[AVAHI_LABEL_MAX], cb[AVAHI_LABEL_MAX], *r;
if (strcasecmp(ca, cb))
return 0;
-
+
if (!*a && !*b)
return 1;
}
if (strlen(label) <= 2 || label[0] != '_')
return 0;
-
+
} while (*t);
return 1;
return 0;
/* Application name */
-
+
if (!(avahi_unescape_label(&t, label, sizeof(label))))
return 0;
return 0;
/* _tcp or _udp boilerplate */
-
+
if (!(avahi_unescape_label(&t, label, sizeof(label))))
return 0;
if (*t)
return 0;
-
+
return 1;
}
return NULL;
/* Subtype name */
-
+
if (!(avahi_unescape_label(&t, label, sizeof(label))))
return NULL;
return NULL;
/* String "_sub" */
-
+
if (!(avahi_unescape_label(&t, label, sizeof(label))))
return NULL;
return NULL;
ret = t;
-
+
/* Application name */
if (!(avahi_unescape_label(&t, label, sizeof(label))))
if (!*t)
return NULL;
-
+
/* _tcp or _udp boilerplate */
-
+
if (!(avahi_unescape_label(&t, label, sizeof(label))))
return NULL;
/* Explicitly allow the root domain name */
if (is_first && label[0] == 0 && *t == 0)
return 1;
-
+
is_first = 0;
-
+
if (label[0] == 0)
return 0;
-
+
} while (*t);
return 1;
if (strlen(t) >= AVAHI_LABEL_MAX || !*t)
return 0;
-
+
return 1;
}
unsigned avahi_domain_hash(const char *s) {
unsigned hash = 0;
-
+
while (*s) {
char c[AVAHI_LABEL_MAX], *p, *r;
char escaped_name[AVAHI_LABEL_MAX*4];
char normalized_type[AVAHI_DOMAIN_NAME_MAX];
char normalized_domain[AVAHI_DOMAIN_NAME_MAX];
-
+
assert(p);
/* Validity checks */
-
+
if ((name && !avahi_is_valid_service_name(name)))
return AVAHI_ERR_INVALID_SERVICE_NAME;
if (!avahi_is_valid_service_type_generic(type))
return AVAHI_ERR_INVALID_SERVICE_TYPE;
-
+
if (!avahi_is_valid_domain_name(domain))
return AVAHI_ERR_INVALID_DOMAIN_NAME;
/* Preparation */
-
+
if (name) {
size_t l = sizeof(escaped_name);
char *e = escaped_name, *r;
return AVAHI_ERR_INVALID_DOMAIN_NAME;
/* Concatenation */
-
+
snprintf(p, size, "%s%s%s.%s", name ? escaped_name : "", name ? "." : "", normalized_type, normalized_domain);
return AVAHI_OK;
static size_t strlcpy(char *dest, const char *src, size_t n) {
assert(dest);
assert(src);
-
+
if (n > 0) {
strncpy(dest, src, n-1);
dest[n-1] = 0;
}
-
+
return strlen(src);
}
DOMAIN
} state;
int type_empty = 1, domain_empty = 1;
-
+
assert(p);
assert(type);
assert(type_size > 0);
state = NAME;
} else
state = TYPE;
-
+
*type = *domain = 0;
-
+
while (*p) {
char buf[64];
-
+
if (!(avahi_unescape_label(&p, buf, sizeof(buf))))
return -1;
if (!type_empty) {
if (!type_size)
return AVAHI_ERR_NO_MEMORY;
-
+
*(type++) = '.';
type_size --;
} else
type_empty = 0;
-
+
if (!(avahi_escape_label(buf, strlen(buf), &type, &type_size)))
return AVAHI_ERR_NO_MEMORY;
break;
- }
+ }
state = DOMAIN;
/* fall through */
if (!domain_empty) {
if (!domain_size)
return AVAHI_ERR_NO_MEMORY;
-
+
*(domain++) = '.';
domain_size --;
} else
/* Make sure that the name is not an IP address */
if (!(avahi_normalize_name(t, normalized, sizeof(normalized))))
return 0;
-
+
if (avahi_address_parse(normalized, AVAHI_PROTO_UNSPEC, &a))
return 0;
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AVAHI_C_DECL_BEGIN
/** Error codes used by avahi */
-enum {
+enum {
AVAHI_OK = 0, /**< OK */
AVAHI_ERR_FAILURE = -1, /**< Generic error code */
AVAHI_ERR_BAD_STATE = -2, /**< Object was in a bad state */
AVAHI_ERR_DNS_YXRRSET = -42,
AVAHI_ERR_DNS_NXRRSET = -43,
AVAHI_ERR_DNS_NOTAUTH = -44, /**< DNS Error: Not authorized */
- AVAHI_ERR_DNS_NOTZONE = -45,
+ AVAHI_ERR_DNS_NOTZONE = -45,
AVAHI_ERR_INVALID_RDATA = -46, /**< Invalid RDATA */
AVAHI_ERR_INVALID_DNS_CLASS = -47, /**< Invalid DNS class */
AVAHI_ERR_INVALID_DNS_TYPE = -48, /**< Invalid DNS type */
AVAHI_ERR_NOT_SUPPORTED = -49, /**< Not supported */
-
+
AVAHI_ERR_NOT_PERMITTED = -50, /**< Operation not permitted */
AVAHI_ERR_INVALID_ARGUMENT = -51, /**< Invalid argument */
AVAHI_ERR_IS_EMPTY = -52, /**< Is empty */
AVAHI_ERR_NO_CHANGE = -53, /**< The requested operation is invalid because it is redundant */
-
+
/****
**** IF YOU ADD A NEW ERROR CODE HERE, PLEASE DON'T FORGET TO ADD
**** IT TO THE STRING ARRAY IN avahi_strerror() IN error.c AND
****
**** Also remember to update the MAX value below.
****/
-
+
AVAHI_ERR_MAX = -54
};
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
static void oom(void) AVAHI_GCC_NORETURN;
static void oom(void) {
-
+
static const char msg[] = "Out of memory, aborting ...\n";
const char *n = msg;
while (strlen(n) > 0) {
ssize_t r;
-
+
if ((r = write(2, n, strlen(n))) < 0)
break;
/* Default implementation for avahi_calloc() */
static void *xcalloc(size_t nmemb, size_t size) {
void *p;
-
+
if (size == 0 || nmemb == 0)
return NULL;
if (size <= 0)
return NULL;
-
+
if (!allocator)
return xmalloc(size);
if (!p)
return;
-
+
if (!allocator) {
free(p);
return;
char *avahi_strdup(const char *s) {
char *r;
size_t size;
-
+
if (!s)
return NULL;
char *r;
size_t size;
const char *p;
-
+
if (!s)
return NULL;
for (p = s, size = 0;
size < max && *p;
p++, size++);
-
+
if (!(r = avahi_new(char, size+1)))
return NULL;
char *avahi_strdup_vprintf(const char *fmt, va_list ap) {
size_t len = 80;
char *buf;
-
+
assert(fmt);
if (!(buf = avahi_malloc(len)))
va_list ap;
assert(fmt);
-
+
va_start(ap, fmt);
s = avahi_strdup_vprintf(fmt, ap);
va_end(ap);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
return NULL;
n->data = data;
-
+
AVAHI_LLIST_PREPEND(AvahiRList, rlist, r, n);
return r;
}
AvahiRList* avahi_rlist_remove_by_link(AvahiRList *r, AvahiRList *n) {
assert(n);
-
+
AVAHI_LLIST_REMOVE(AvahiRList, rlist, r, n);
avahi_free(n);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
int idx;
struct pollfd pollfd;
-
+
AvahiWatchCallback callback;
void *userdata;
int enabled;
struct timeval expiry;
-
+
AvahiTimeoutCallback callback;
void *userdata;
-
+
AVAHI_LLIST_FIELDS(AvahiTimeout, timeouts);
};
return;
s->wakeup_issued = 0;
-
+
for(;;)
if (read(s->wakeup_pipe[0], &c, sizeof(c)) != sizeof(c))
break;
static int set_nonblock(int fd) {
int n;
-
+
assert(fd >= 0);
if ((n = fcntl(fd, F_GETFL)) < 0)
static AvahiWatch* watch_new(const AvahiPoll *api, int fd, AvahiWatchEvent event, AvahiWatchCallback callback, void *userdata) {
AvahiWatch *w;
AvahiSimplePoll *s;
-
+
assert(api);
assert(fd >= 0);
assert(callback);
/* If there is a background thread running the poll() for us, tell it to exit the poll() */
avahi_simple_poll_wakeup(s);
-
+
w->simple_poll = s;
w->dead = 0;
if (w->idx == -1)
return;
-
+
w->simple_poll->rebuild_pollfds = 1;
}
/* If there is a background thread running the poll() for us, tell it to exit the poll() */
avahi_simple_poll_wakeup(w->simple_poll);
-
+
remove_pollfd(w);
-
+
w->dead = 1;
w->simple_poll->n_watches --;
w->simple_poll->watch_req_cleanup = 1;
if (!w->dead)
w->simple_poll->n_watches --;
-
+
avahi_free(w);
}
static AvahiTimeout* timeout_new(const AvahiPoll *api, const struct timeval *tv, AvahiTimeoutCallback callback, void *userdata) {
AvahiTimeout *t;
AvahiSimplePoll *s;
-
+
assert(api);
assert(callback);
/* If there is a background thread running the poll() for us, tell it to exit the poll() */
avahi_simple_poll_wakeup(s);
-
+
t->simple_poll = s;
t->dead = 0;
if ((t->enabled = !!tv))
t->expiry = *tv;
-
+
t->callback = callback;
t->userdata = userdata;
/* If there is a background thread running the poll() for us, tell it to exit the poll() */
avahi_simple_poll_wakeup(t->simple_poll);
-
+
if ((t->enabled = !!tv))
t->expiry = *tv;
}
set_nonblock(s->wakeup_pipe[0]);
set_nonblock(s->wakeup_pipe[1]);
-
+
s->api.userdata = s;
s->api.watch_new = watch_new;
s->api.timeout_new = timeout_new;
s->api.timeout_free = timeout_free;
s->api.timeout_update = timeout_update;
-
+
s->pollfds = NULL;
s->max_pollfds = s->n_pollfds = 0;
s->rebuild_pollfds = 1;
s->quit = 0;
s->n_watches = 0;
s->events_valid = 0;
-
+
s->watch_req_cleanup = 0;
s->timeout_req_cleanup = 0;
s->state = STATE_INIT;
s->wakeup_issued = 0;
-
+
avahi_simple_poll_set_func(s, NULL, NULL);
AVAHI_LLIST_HEAD_INIT(AvahiWatch, s->watches);
cleanup_timeouts(s, 1);
cleanup_watches(s, 1);
assert(s->n_watches == 0);
-
+
avahi_free(s->pollfds);
if (s->wakeup_pipe[0] >= 0)
if (s->wakeup_pipe[1] >= 0)
close(s->wakeup_pipe[1]);
-
+
avahi_free(s);
}
static int rebuild(AvahiSimplePoll *s) {
AvahiWatch *w;
int idx;
-
+
assert(s);
if (s->n_watches+1 > s->max_pollfds) {
struct pollfd *n;
s->max_pollfds = s->n_watches + 10;
-
+
if (!(n = avahi_realloc(s->pollfds, sizeof(struct pollfd) * s->max_pollfds)))
return -1;
s->pollfds = n;
}
-
+
s->pollfds[0].fd = s->wakeup_pipe[0];
s->pollfds[0].events = POLLIN;
s->pollfds[0].revents = 0;
idx = 1;
-
+
for (w = s->watches; w; w = w->watches_next) {
if(w->dead)
assert(s);
for (t = s->timeouts; t; t = t->timeouts_next) {
-
+
if (t->dead || !t->enabled)
continue;
-
+
if (!n || avahi_timeval_compare(&t->expiry, &n->expiry) < 0)
n = t;
}
int avahi_simple_poll_prepare(AvahiSimplePoll *s, int timeout) {
AvahiTimeout *next_timeout;
-
+
assert(s);
assert(s->state == STATE_INIT || s->state == STATE_DISPATCHED || s->state == STATE_FAILURE);
s->state = STATE_PREPARING;
-
+
/* Clear pending wakeup requests */
clear_wakeup(s);
timeout = 0;
goto finish;
}
-
+
gettimeofday(&now, NULL);
usec = avahi_timeval_diff(&next_timeout->expiry, &now);
int avahi_simple_poll_run(AvahiSimplePoll *s) {
assert(s);
assert(s->state == STATE_PREPARED || s->state == STATE_FAILURE);
-
+
s->state = STATE_RUNNING;
if (s->poll_func(s->pollfds, s->n_pollfds, s->prepared_timeout, s->poll_func_userdata) < 0) {
s->state = STATE_FAILURE;
return -1;
}
-
+
/* The poll events are now valid again */
s->events_valid = 1;
-
+
/* Update state */
s->state = STATE_RAN;
return 0;
s->state = STATE_DISPATCHING;
/* We execute only on callback in every iteration */
-
+
/* Check whether the wakeup time has been reached now */
if ((next_timeout = find_next_timeout(s))) {
-
+
if (next_timeout->expiry.tv_sec == 0 && next_timeout->expiry.tv_usec == 0) {
/* Just a shortcut so that we don't need to call gettimeofday() */
timeout_callback(next_timeout);
goto finish;
}
-
+
if (avahi_age(&next_timeout->expiry) >= 0) {
/* Timeout elapsed */
/* Look for some kind of I/O event */
for (w = s->watches; w; w = w->watches_next) {
-
+
if (w->dead)
continue;
-
+
assert(w->idx >= 0);
assert(w->idx < s->n_pollfds);
-
+
if (s->pollfds[w->idx].revents != 0) {
w->callback(w, w->pollfd.fd, s->pollfds[w->idx].revents, w->userdata);
goto finish;
if ((r = avahi_simple_poll_dispatch(s)) != 0)
return r;
-
+
return 0;
}
const AvahiPoll* avahi_simple_poll_get(AvahiSimplePoll *s) {
assert(s);
-
+
return &s->api;
}
int r;
assert(s);
-
+
for (;;)
if ((r = avahi_simple_poll_iterate(s, -1)) != 0)
if (r >= 0 || errno != EINTR)
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
if (!(n = avahi_malloc(sizeof(AvahiStringList) + size)))
return NULL;
-
+
n->next = l;
n->size = size;
int avahi_string_list_parse(const void* data, size_t size, AvahiStringList **ret) {
const uint8_t *c;
AvahiStringList *r = NULL;
-
+
assert(data);
assert(ret);
c = data;
while (size > 0) {
size_t k;
-
+
k = *(c++);
size--;
if (k > 0) { /* Ignore empty strings */
AvahiStringList *n;
- if (!(n = avahi_string_list_add_arbitrary(r, c, k)))
+ if (!(n = avahi_string_list_add_arbitrary(r, c, k)))
goto fail; /* OOM */
r = n;
}
-
+
c += k;
size -= k;
}
*ret = r;
-
+
return 0;
fail:
return NULL;
l = avahi_string_list_reverse(l);
-
+
for (n = l; n; n = n->next) {
if (n != l)
*(e++) = ' ';
}
l = avahi_string_list_reverse(l);
-
+
*e = 0;
return t;
l = avahi_string_list_reverse(l);
c = data;
-
+
for (n = l; size > 1 && n; n = n->next) {
size_t k;
if ((k = n->size) == 0)
/* Skip empty strings */
continue;
-
+
if (k > 255)
/* Truncate strings at 255 characters */
k = 255;
-
+
if (k > size-1)
/* Make sure this string fits in */
k = size-1;
*(c++) = (uint8_t) k;
memcpy(c, n->text, k);
c += k;
-
+
used += 1 + k;
size -= 1 + k;
}
-
+
l = avahi_string_list_reverse(l);
if (used == 0 && size > 0) {
-
+
/* Empty lists are treated specially. To comply with
* section 6.1 of the DNS-SD spec, we return a single
* empty string (i.e. a NUL byte)*/
*(uint8_t*) data = 0;
used = 1;
}
-
+
} else {
AvahiStringList *n;
for (n = l; n; n = n->next) {
size_t k;
-
+
if ((k = n->size) == 0)
continue;
-
+
if (k > 255)
k = 255;
-
+
used += 1+k;
}
va_start(va, r);
r = avahi_string_list_add_many_va(r, va);
va_end(va);
-
+
return r;
}
AvahiStringList *avahi_string_list_add_vprintf(AvahiStringList *l, const char *format, va_list va) {
size_t len = 80;
AvahiStringList *r;
-
+
assert(format);
if (!(r = avahi_malloc(sizeof(AvahiStringList) + len)))
int n;
AvahiStringList *nr;
va_list va2;
-
+
va_copy(va2, va);
n = vsnprintf((char*) r->text, len, format, va2);
va_end(va2);
r = nr;
}
-
+
r->next = l;
- r->size = strlen((char*) r->text);
+ r->size = strlen((char*) r->text);
return r;
}
AvahiStringList *avahi_string_list_add_printf(AvahiStringList *l, const char *format, ...) {
va_list va;
-
+
assert(format);
va_start(va, format);
l = avahi_string_list_add_vprintf(l, format, va);
va_end(va);
- return l;
+ return l;
}
AvahiStringList *avahi_string_list_find(AvahiStringList *l, const char *key) {
size_t n;
-
+
assert(key);
n = strlen(key);
return avahi_string_list_add(l, key);
n = strlen(key);
-
+
if (!(l = avahi_string_list_add_anonymous(l, n + 1 + size)))
return NULL;
int avahi_string_list_get_pair(AvahiStringList *l, char **key, char **value, size_t *size) {
char *e;
-
+
assert(l);
if (!(e = memchr(l->text, '=', l->size))) {
- if (key)
+ if (key)
if (!(*key = avahi_strdup((char*) l->text)))
return -1;
return -1;
e++; /* Advance after '=' */
-
+
n = l->size - (e - (char*) l->text);
-
+
if (value) {
if (!(*value = avahi_memdup(e, n+1))) {
AvahiStringList *f;
char *value = NULL, *end = NULL;
uint32_t ret;
-
+
if (!(f = avahi_string_list_find(l, AVAHI_SERVICE_COOKIE)))
return AVAHI_SERVICE_COOKIE_INVALID;
}
avahi_free(value);
-
+
return ret;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AvahiUsec avahi_age(const struct timeval *a) {
struct timeval now;
-
+
assert(a);
gettimeofday(&now, NULL);
time_t now;
int r;
-
+
now = time(NULL);
pthread_mutex_lock(&mutex);
timestamp = now;
last_rand = rand();
}
-
+
r = last_rand;
-
+
pthread_mutex_unlock(&mutex);
/* We use the same jitter for 10 seconds. That way our
* time events elapse in bursts which has the advantage that
* packet data can be aggregated better */
-
+
avahi_timeval_add(tv, (AvahiUsec) (jitter*1000.0*r/(RAND_MAX+1.0)));
}
-
+
return tv;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
assert(avahi_utf8_valid("hallo"));
assert(!avahi_utf8_valid("üxknürz"));
assert(avahi_utf8_valid("üxknürz"));
-
+
return 0;
}
(((Char) & 0xFFFFF800) != 0xD800) && \
((Char) < 0xFDD0 || (Char) > 0xFDEF) && \
((Char) & 0xFFFE) != 0xFFFE)
-
-
+
+
#define CONTINUATION_CHAR \
do { \
if ((*(const unsigned char *)p & 0xc0) != 0x80) /* 10xxxxxx */ \
{
if (*(const unsigned char *)p < 128)
/* done */;
- else
+ else
{
const char *last;
-
+
last = p;
if ((*(const unsigned char *)p & 0xe0) == 0xc0) /* 110xxxxx */
{
}
else
goto error;
-
+
p++;
CONTINUATION_CHAR;
TWO_REMAINING:
CONTINUATION_CHAR;
p++;
CONTINUATION_CHAR;
-
+
if ( (val < min))
goto error;
if ( (!UNICODE_VALID(val)))
goto error;
- }
-
+ }
+
continue;
-
+
error:
return NULL;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
if (event & AVAHI_WATCH_IN) {
ssize_t r;
char c;
-
+
if ((r = read(fd, &c, 1)) <= 0) {
fprintf(stderr, "read() failed: %s\n", r < 0 ? strerror(errno) : "EOF");
api->watch_free(w);
api = avahi_threaded_poll_get(threaded_poll);
assert(api);
#endif
-
+
api->watch_new(api, 0, AVAHI_WATCH_IN, callback, NULL);
avahi_elapse_time(&tv, 1000, 0);
fprintf(stderr, "... stupid stuff is done.\n");
avahi_threaded_poll_free(threaded_poll);
-
+
#endif
-
+
return 0;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
struct AvahiPoll {
/** Some abstract user data usable by the provider of the API */
- void* userdata;
+ void* userdata;
/** Create a new watch for the specified file descriptor and for
* the specified events. The API will call the callback function
/** Update the absolute expiration time for a timeout, If tv is
* NULL, the timeout is disabled. It is safe to call this function from an AvahiTimeoutCallback */
void (*timeout_update)(AvahiTimeout *, const struct timeval *tv);
-
+
/** Free a timeout. It is safe to call this function from an AvahiTimeoutCallback */
void (*timeout_free)(AvahiTimeout *t);
};
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
ASSERT_SW_OKAY(sw_ipv4_address_init_from_name(&a, "heise.de"));
ASSERT_NOT_NULL(sw_ipv4_address_name(a, t, sizeof(t)));
printf("%s\n", t);
-
+
ASSERT_SW_OKAY(sw_ipv4_address_init_from_this_host(&a));
ASSERT_NOT_NULL(sw_ipv4_address_name(a, t, sizeof(t)));
printf("%s\n", t);
ASSERT_SW_OKAY(sw_ipv4_address_decompose(a, &a1, &a2, &a3, &a4));
printf("%i.%i.%i.%i\n", a1, a2, a3, a4);
-
+
return 0;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
assert(name);
AVAHI_WARN_LINKAGE;
-
+
if (!(he = gethostbyname(name)))
return SW_E_UNKNOWN;
-
+
self->m_addr = *(uint32_t*) he->h_addr;
return SW_OKAY;
}
assert(self);
AVAHI_WARN_LINKAGE;
-
+
/* This is so fucked up ... */
memset(&sa, 0, sizeof(sa));
close(fd);
self->m_addr = sa.sin_addr.s_addr;
-
+
return SW_OKAY;
}
AVAHI_WARN_LINKAGE;
/* This is ridiculous ... */
-
+
return SW_OKAY;
}
if (len < INET_ADDRSTRLEN)
return NULL;
-
+
if (!(inet_ntop(AF_INET, &self.m_addr, name, len)))
return NULL;
-
+
return name;
}
uint32_t a;
AVAHI_WARN_LINKAGE;
-
+
a = ntohl(self.m_addr);
-
+
assert(a1);
assert(a2);
assert(a3);
*a2 = (uint8_t) (a >> 16);
*a3 = (uint8_t) (a >> 8);
*a4 = (uint8_t) (a);
-
+
return SW_OKAY;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
case SW_DISCOVERY_BROWSE_INVALID:
fprintf(stderr, "some kind of failure happened: %s\n", domain);
break;
-
+
default:
abort();
}
int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
sw_discovery discovery;
sw_discovery_oid oid;
-
+
ASSERT_SW_OKAY(sw_discovery_init(&discovery));
ASSERT_SW_OKAY(sw_discovery_browse_domains(discovery, 0, reply, NULL, &oid));
-
+
ASSERT_SW_OKAY(sw_discovery_run(discovery));
-
+
return 0;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
sw_discovery_oid oid_index;
int thread_fd, main_fd;
-
+
pthread_t thread;
int thread_running;
switch (error) {
case AVAHI_OK:
return SW_OKAY;
-
+
case AVAHI_ERR_NO_MEMORY:
return SW_E_MEM;
}
char command;
assert(fd >= 0);
-
+
if ((r = read(fd, &command, 1)) != 1) {
fprintf(stderr, __FILE__": read() failed: %s\n", r < 0 ? strerror(errno) : "EOF");
return -1;
static int poll_func(struct pollfd *ufds, unsigned int nfds, int timeout, void *userdata) {
sw_discovery self = userdata;
int ret;
-
+
assert(self);
-
+
ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
ret = poll(ufds, nfds, timeout);
ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
sigfillset(&mask);
pthread_sigmask(SIG_BLOCK, &mask, NULL);
-
+
self->thread = pthread_self();
self->thread_running = 1;
break;
/* fprintf(stderr, "Command: %c\n", command); */
-
+
switch (command) {
case COMMAND_POLL: {
for (;;) {
errno = 0;
-
+
if ((ret = avahi_simple_poll_run(self->simple_poll)) < 0) {
-
+
if (errno == EINTR)
continue;
-
+
fprintf(stderr, __FILE__": avahi_simple_poll_run() failed: %s\n", strerror(errno));
}
break;
}
-
+
ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
-
+
if (write_command(self->thread_fd, ret < 0 ? COMMAND_POLL_FAILED : COMMAND_POLL_DONE) < 0)
break;
-
+
break;
}
case COMMAND_QUIT:
return NULL;
}
-
+
}
return NULL;
while (self->oid_index >= OID_MAX)
self->oid_index -= OID_MAX;
-
+
if (self->oid_table[self->oid_index].type == OID_UNUSED) {
self->oid_table[self->oid_index].type = type;
self->oid_table[self->oid_index].discovery = self;
assert(OID_GET_INDEX(&self->oid_table[self->oid_index]) == self->oid_index);
-
+
return self->oid_index ++;
}
}
/* No free entry found */
-
+
return (sw_discovery_oid) -1;
}
if (self->oid_table[oid].type == OID_UNUSED)
return NULL;
-
+
return &self->oid_table[oid];
}
static service_data* service_data_new(sw_discovery self) {
service_data *sdata;
-
+
assert(self);
if (!(sdata = avahi_new0(service_data, 1)))
return NULL;
AVAHI_LLIST_PREPEND(service_data, services, self->services, sdata);
-
+
return sdata;
-
+
}
static void service_data_free(sw_discovery self, service_data* sdata) {
assert(sdata);
AVAHI_LLIST_REMOVE(service_data, services, self->services, sdata);
-
+
avahi_free(sdata->name);
avahi_free(sdata->regtype);
avahi_free(sdata->domain);
static void client_callback(AvahiClient *s, AvahiClientState state, void* userdata) {
sw_discovery self = userdata;
sw_discovery_oid oid;
-
+
assert(s);
assert(self);
discovery_ref(self);
-
+
for (oid = 0; oid < OID_MAX; oid++) {
switch (self->oid_table[oid].type) {
sw_result result = SW_E_UNKNOWN;
pthread_mutexattr_t mutex_attr;
int error;
-
+
assert(self);
-
+
AVAHI_WARN_LINKAGE;
*self = NULL;
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0)
goto fail;
-
+
if (!(*self = avahi_new(struct _sw_discovery, 1))) {
result = SW_E_MEM;
goto fail;
memset((*self)->oid_table, 0, sizeof((*self)->oid_table));
(*self)->oid_index = 0;
-
+
(*self)->thread_running = 0;
AVAHI_LLIST_HEAD_INIT(service_info, (*self)->services);
result = map_error(error);
goto fail;
}
-
+
/* Start simple poll */
if (avahi_simple_poll_prepare((*self)->simple_poll, -1) < 0)
goto fail;
/* Queue an initial POLL command for the thread */
if (write_command((*self)->main_fd, COMMAND_POLL) < 0)
goto fail;
-
+
if (pthread_create(&(*self)->thread, NULL, thread_func, *self) != 0)
goto fail;
(*self)->thread_running = 1;
-
+
return SW_OKAY;
fail:
if (write_command(self->main_fd, COMMAND_QUIT) < 0)
return -1;
-
+
avahi_simple_poll_wakeup(self->simple_poll);
-
+
ASSERT_SUCCESS(pthread_join(self->thread, NULL));
self->thread_running = 0;
return 0;
while (self->services)
service_data_free(self, self->services);
-
+
avahi_free(self);
}
sw_result sw_discovery_fina(sw_discovery self) {
assert(self);
-
+
AVAHI_WARN_LINKAGE;
stop_thread(self);
discovery_unref(self);
-
+
return SW_OKAY;
}
sw_result sw_discovery_run(sw_discovery self) {
assert(self);
-
+
AVAHI_WARN_LINKAGE;
return sw_salt_run((sw_salt) self);
sw_result sw_discovery_stop_run(sw_discovery self) {
assert(self);
-
+
AVAHI_WARN_LINKAGE;
return sw_salt_stop_run((sw_salt) self);
int sw_discovery_socket(sw_discovery self) {
assert(self);
-
+
AVAHI_WARN_LINKAGE;
return self->main_fd;
sw_result sw_discovery_read_socket(sw_discovery self) {
sw_result result = SW_E_UNKNOWN;
-
+
assert(self);
discovery_ref(self);
ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
-
+
/* Cleanup notification socket */
if (read_command(self->main_fd) != COMMAND_POLL_DONE)
goto finish;
-
+
if (avahi_simple_poll_dispatch(self->simple_poll) < 0)
goto finish;
/* Request the poll */
if (write_command(self->main_fd, COMMAND_POLL) < 0)
goto finish;
-
+
result = SW_OKAY;
-
+
finish:
ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
discovery_unref(self);
-
+
return result;
}
sw_result sw_discovery_salt(sw_discovery self, sw_salt *salt) {
assert(self);
assert(salt);
-
+
AVAHI_WARN_LINKAGE;
*salt = (sw_salt) self;
-
+
return SW_OKAY;
}
if (!((sw_discovery) self)->thread_running)
return SW_E_UNKNOWN;
-
+
memset(&p, 0, sizeof(p));
p.fd = ((sw_discovery) self)->main_fd;
p.events = POLLIN;
if ((r = poll(&p, 1, msec ? (int) *msec : -1)) < 0) {
-
+
/* Don't treat EINTR as error */
if (errno == EINTR)
return SW_OKAY;
-
+
return SW_E_UNKNOWN;
-
+
} else if (r == 0) {
-
+
/* Timeoout */
return SW_OKAY;
} else {
/* Success */
-
+
if (p.revents != POLLIN)
return SW_E_UNKNOWN;
if ((result = sw_discovery_read_socket((sw_discovery) self)) != SW_OKAY)
return result;
}
-
+
return SW_OKAY;
}
AVAHI_WARN_LINKAGE;
assert(self);
-
+
for (;;)
if ((ret = sw_salt_step(self, NULL)) != SW_OKAY)
return ret;
sw_result sw_salt_unlock(sw_salt self) {
assert(self);
-
+
AVAHI_WARN_LINKAGE;
ASSERT_SUCCESS(pthread_mutex_unlock(&((sw_discovery) self)->salt_mutex));
sw_discovery_publish_reply reply;
assert(data);
-
+
reply = (sw_discovery_publish_reply) data->reply;
-
+
reply(data->discovery,
OID_GET_INDEX(data),
status,
static int reg_create_service(oid_data *data) {
int ret;
const char *real_type;
-
+
assert(data);
real_type = avahi_get_type_from_subtype(data->service_data->regtype);
-
+
if ((ret = avahi_entry_group_add_service_strlst(
data->object,
data->service_data->interface,
data->service_data->port,
data->service_data->txt)) < 0)
return ret;
-
+
if (real_type) {
/* Create a subtype entry */
/* We've not been setup completely */
if (!data->object)
return;
-
+
switch (state) {
case AVAHI_CLIENT_FAILURE:
reg_report_status(data, SW_DISCOVERY_PUBLISH_INVALID);
break;
-
+
case AVAHI_CLIENT_S_RUNNING: {
int ret;
reg_report_status(data, SW_DISCOVERY_PUBLISH_INVALID);
return;
}
-
+
break;
}
-
+
case AVAHI_CLIENT_S_COLLISION:
case AVAHI_CLIENT_S_REGISTERING:
case AVAHI_ENTRY_GROUP_FAILURE:
reg_report_status(data, SW_DISCOVERY_PUBLISH_INVALID);
break;
-
+
}
}
sw_result result = SW_E_UNKNOWN;
service_data *sdata;
AvahiStringList *txt = NULL;
-
+
assert(self);
assert(name);
assert(type);
assert(reply);
assert(oid);
-
+
AVAHI_WARN_LINKAGE;
if (text_record && text_record_len > 0)
if (avahi_client_get_state(self->client) == AVAHI_CLIENT_S_RUNNING) {
int error;
-
+
if ((error = reg_create_service(data)) < 0) {
result = map_error(error);
goto finish;
finish:
ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
-
- if (result != SW_OKAY)
+
+ if (result != SW_OKAY)
if (*oid != (sw_discovery_oid) -1)
sw_discovery_cancel(self, *oid);
case AVAHI_BROWSER_FAILURE:
reply(data->discovery, OID_GET_INDEX(data), SW_DISCOVERY_BROWSE_INVALID, interface, NULL, NULL, domain, data->extra);
break;
-
+
case AVAHI_BROWSER_CACHE_EXHAUSTED:
case AVAHI_BROWSER_ALL_FOR_NOW:
break;
sw_discovery_browse_reply reply,
sw_opaque extra,
sw_discovery_oid * oid) {
-
+
oid_data *data;
AvahiIfIndex ifindex;
sw_result result = SW_E_UNKNOWN;
-
+
assert(self);
assert(reply);
assert(oid);
-
+
AVAHI_WARN_LINKAGE;
if ((*oid = oid_alloc(self, OID_DOMAIN_BROWSER)) == (sw_discovery_oid) -1)
assert(data);
data->reply = (sw_result (*)(void)) reply;
data->extra = extra;
-
+
ifindex = interface_index == 0 ? AVAHI_IF_UNSPEC : (AvahiIfIndex) interface_index;
ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
-
+
if (!(data->object = avahi_domain_browser_new(self->client, ifindex, AVAHI_PROTO_INET, NULL, AVAHI_DOMAIN_BROWSER_BROWSE, 0, domain_browser_callback, data))) {
result = map_error(avahi_client_errno(self->client));
goto finish;
finish:
ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
-
+
if (result != SW_OKAY)
if (*oid != (sw_discovery_oid) -1)
sw_discovery_cancel(self, *oid);
oid_data* data = userdata;
sw_discovery_resolve_reply reply;
-
+
assert(r);
assert(data);
sw_ipv4_address_init_from_saddr(&addr, a->data.ipv4.address);
host_name = add_trailing_dot(host_name, host_name_fixed, sizeof(host_name_fixed));
-
+
if ((p = avahi_new0(uint8_t, (l = avahi_string_list_serialize(txt, NULL, 0))+1)))
avahi_string_list_serialize(txt, p, l);
case AVAHI_RESOLVER_FAILURE:
/* Apparently there is no way in HOWL to inform about failed resolvings ... */
-
+
avahi_warn("A service failed to resolve in the HOWL compatiblity layer of Avahi which is used by '%s'. "
"Since the HOWL API doesn't offer any means to inform the application about this, we have to ignore the failure. "
"Please fix your application to use the native API of Avahi!",
oid_data *data;
AvahiIfIndex ifindex;
sw_result result = SW_E_UNKNOWN;
-
+
assert(self);
assert(name);
assert(type);
assert(reply);
assert(oid);
-
+
AVAHI_WARN_LINKAGE;
if ((*oid = oid_alloc(self, OID_SERVICE_RESOLVER)) == (sw_discovery_oid) -1)
assert(data);
data->reply = (sw_result (*)(void)) reply;
data->extra = extra;
-
+
ifindex = interface_index == 0 ? AVAHI_IF_UNSPEC : (AvahiIfIndex) interface_index;
ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
-
+
if (!(data->object = avahi_service_resolver_new(self->client, ifindex, AVAHI_PROTO_INET, name, type, domain, AVAHI_PROTO_INET, 0, service_resolver_callback, data))) {
result = map_error(avahi_client_errno(self->client));
goto finish;
}
result = SW_OKAY;
-
+
finish:
ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
-
+
if (result != SW_OKAY)
if (*oid != (sw_discovery_oid) -1)
sw_discovery_cancel(self, *oid);
oid_data* data = userdata;
char type_fixed[AVAHI_DOMAIN_NAME_MAX], domain_fixed[AVAHI_DOMAIN_NAME_MAX];
sw_discovery_browse_reply reply;
-
+
assert(b);
assert(data);
case AVAHI_BROWSER_FAILURE:
reply(data->discovery, OID_GET_INDEX(data), SW_DISCOVERY_BROWSE_INVALID, interface, name, type, domain, data->extra);
break;
-
+
case AVAHI_BROWSER_CACHE_EXHAUSTED:
case AVAHI_BROWSER_ALL_FOR_NOW:
break;
oid_data *data;
AvahiIfIndex ifindex;
sw_result result = SW_E_UNKNOWN;
-
+
assert(self);
assert(type);
assert(reply);
assert(oid);
-
+
AVAHI_WARN_LINKAGE;
if ((*oid = oid_alloc(self, OID_SERVICE_BROWSER)) == (sw_discovery_oid) -1)
assert(data);
data->reply = (sw_result (*)(void)) reply;
data->extra = extra;
-
+
ifindex = interface_index == 0 ? AVAHI_IF_UNSPEC : (AvahiIfIndex) interface_index;
ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
-
+
if (!(data->object = avahi_service_browser_new(self->client, ifindex, AVAHI_PROTO_INET, type, domain, 0, service_browser_callback, data))) {
result = map_error(avahi_client_errno(self->client));
goto finish;
}
result = SW_OKAY;
-
+
finish:
ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
-
+
if (result != SW_OKAY)
if (*oid != (sw_discovery_oid) -1)
sw_discovery_cancel(self, *oid);
sw_result sw_discovery_cancel(sw_discovery self, sw_discovery_oid oid) {
oid_data *data;
- assert(self);
+ assert(self);
AVAHI_WARN_LINKAGE;
case OID_SERVICE_BROWSER:
avahi_service_browser_free(data->object);
break;
-
+
case OID_SERVICE_RESOLVER:
avahi_service_resolver_free(data->object);
break;
-
+
case OID_DOMAIN_BROWSER:
avahi_domain_browser_free(data->object);
break;
-
+
case OID_ENTRY_GROUP:
avahi_entry_group_free(data->object);
break;
-
+
case OID_UNUSED:
;
}
}
oid_release(self, oid);
-
+
return SW_OKAY;
}
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
#ifdef __cplusplus
extern "C"
{
-#endif
+#endif
struct _sw_corby_buffer;
void HOWL_API
sw_corby_buffer_reset(
sw_corby_buffer self);
-
+
sw_result HOWL_API
sw_corby_buffer_set_octets(
sw_octets octets,
sw_size_t size);
-
+
sw_octets HOWL_API
sw_corby_buffer_octets(
sw_corby_buffer self);
-
-
+
+
sw_size_t HOWL_API
sw_corby_buffer_bytes_used(
sw_corby_buffer self);
-
+
sw_size_t HOWL_API
sw_corby_buffer_size(
sw_corby_buffer self);
-
+
sw_result HOWL_API
sw_corby_buffer_put_int8(
sw_corby_buffer self,
sw_const_octets val,
sw_size_t size);
-
+
sw_result HOWL_API
sw_corby_buffer_put_sized_octets(
sw_corby_buffer self,
sw_const_octets val,
sw_uint32 len);
-
+
sw_result HOWL_API
sw_corby_buffer_put_cstring(
sw_corby_buffer_put_pad(
sw_corby_buffer self,
sw_corby_buffer_pad pad);
-
+
sw_result HOWL_API
sw_corby_buffer_get_int8(
sw_octets * val,
sw_uint32 * size,
sw_uint8 endian);
-
+
sw_result HOWL_API
sw_corby_buffer_get_zerocopy_sized_octets(
sw_octets * val,
sw_uint32 * size,
sw_uint8 endian);
-
+
sw_result HOWL_API
sw_corby_buffer_get_sized_octets(
sw_string * val,
sw_uint32 * len,
sw_uint8 endian);
-
-
+
+
sw_result HOWL_API
sw_corby_buffer_get_zerocopy_cstring(
sw_corby_buffer self,
sw_string * val,
sw_uint32 * len,
sw_uint8 endian);
-
+
sw_result HOWL_API
sw_corby_buffer_get_cstring(
sw_string val,
sw_uint32 * len,
sw_uint8 endian);
-
-
+
+
sw_result HOWL_API
sw_corby_buffer_get_object(
sw_corby_buffer self,
struct _sw_corby_object ** object,
sw_uint8 endian);
-
+
#ifdef __cplusplus
}
-#endif
+#endif
#endif
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
#ifdef __cplusplus
extern "C"
{
-#endif
+#endif
struct _sw_corby_channel;
typedef struct _sw_corby_channel * sw_corby_channel;
#ifdef __cplusplus
}
-#endif
+#endif
#endif
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
/*
- * protocol tags. the only standard one is TAG_INTERNET_IIOP.
+ * protocol tags. the only standard one is TAG_INTERNET_IIOP.
* the others are proprietary pandora corby protocols.
- */
+ */
#define SW_TAG_INTERNET_IOP 0
#define SW_TAG_UIOP 250
#define SW_TAG_MIOP 251
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
#ifdef __cplusplus
}
-#endif
+#endif
#endif
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
sw_result HOWL_API
sw_corby_object_fina(
sw_corby_object self);
-
+
sw_result HOWL_API
sw_corby_object_start_request(
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
#ifdef __cplusplus
extern "C"
{
-#endif
+#endif
struct _sw_corby_orb;
sw_const_string tag,
sw_string addr,
sw_port * port);
-
+
sw_result HOWL_API
sw_corby_orb_protocol_to_url(
#ifdef __cplusplus
}
-#endif
+#endif
#endif
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
/*
* For backwards compatibility
*/
-#define sw_discovery_publish_host_id sw_discovery_oid
+#define sw_discovery_publish_host_id sw_discovery_oid
#define sw_discovery_publish_id sw_discovery_oid
#define sw_discovery_browse_id sw_discovery_oid
#define sw_discovery_resolve_id sw_discovery_oid
sw_discovery_publish_status status,
sw_opaque extra);
-typedef sw_result
+typedef sw_result
(HOWL_API *sw_discovery_browse_reply)(
sw_discovery session,
sw_discovery_oid oid,
sw_const_string fullname,
sw_uint16 rrtype,
sw_uint16 rrclass,
- sw_uint16 rrdatalen,
+ sw_uint16 rrdatalen,
sw_const_octets rrdata,
sw_uint32 ttl,
- sw_opaque extra);
+ sw_opaque extra);
/*
sw_const_string fullname,
sw_uint16 rrtype,
sw_uint16 rrclass,
- sw_discovery_query_record_reply reply,
+ sw_discovery_query_record_reply reply,
sw_opaque extra,
sw_discovery_oid * oid);
sw_discovery_cancel(
sw_discovery self,
sw_discovery_oid oid);
-
+
/* ----------------------------------------------------------
*
* ----------------------------------------------------------
*/
-
+
sw_result HOWL_API
sw_discovery_run(
sw_result HOWL_API
sw_discovery_stop_run(
sw_discovery self);
-
+
int HOWL_API
sw_discovery_socket(
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
sw_bool HOWL_API
sw_ipv4_address_is_any(
sw_ipv4_address self);
-
+
sw_saddr HOWL_API
sw_ipv4_address_saddr(
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
#ifdef __cplusplus
extern "C"
{
-#endif
+#endif
#define SW_LOG_WARNING 1 << 0
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
#ifdef __cplusplus
extern "C"
{
-#endif
+#endif
#if defined(__VXWORKS__)
* for little endian platforms.
*
* The macro WORDS_BIGENDIAN will be defined
- * by autoconf. If you are using Howl on
+ * by autoconf. If you are using Howl on
* a platform that doesn't have autoconf, define
* SW_ENDIAN directly
* --------------------------------------------------------
sw_strcasecmp(
sw_const_string arg1,
sw_const_string arg2);
-
+
extern sw_int32
sw_strncasecmp(
sw_const_string arg1,
sw_const_string arg2,
sw_len n);
-
+
extern sw_string
sw_strtok_r(
sw_string arg1,
sw_const_string arg2,
sw_string * lasts);
-
+
# define sw_memset(ARG1, ARG2, ARG3) memset((char*) ARG1, ARG2, ARG3)
# define sw_memcpy(ARG1, ARG2, ARG3) memcpy((char*) ARG1, (char*) ARG2, ARG3)
# define sw_memcmp(ARG1, ARG2, ARG3) memcmp((char*) ARG1, ARG2, ARG3)
/*
* Obsolete types and macros.
- *
+ *
* These are here for backwards compatibility, but will
* be removed in the future
*/
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
#ifdef __cplusplus
extern "C"
{
-#endif
+#endif
typedef enum _sw_socket_event
{
SW_SOCKET_READ = (1 << 0),
SW_SOCKET_WRITE = (1 << 1),
- SW_SOCKET_OOB = (1 << 2)
+ SW_SOCKET_OOB = (1 << 2)
} sw_socket_event;
sw_salt salt,
struct _sw_network_interface * netif,
sw_opaque extra);
-
+
typedef sw_opaque sw_signal_handler;
typedef sw_result
(HOWL_API *sw_signal_handler_func)(
sw_salt * self,
int argc,
char ** argv);
-
-
+
+
sw_result HOWL_API
sw_salt_fina(
sw_salt self);
-
+
sw_result HOWL_API
sw_salt_register_socket(
sw_salt self,
sw_salt_unregister_socket(
sw_salt self,
struct _sw_socket * socket);
-
-
+
+
sw_result HOWL_API
sw_salt_register_timer(
sw_salt self,
sw_timer_handler handler,
sw_timer_handler_func func,
sw_opaque extra);
-
-
+
+
sw_result HOWL_API
sw_salt_unregister_timer(
sw_salt self,
sw_result HOWL_API
sw_salt_stop_run(
sw_salt self);
-
+
#define SW_FALSE 0
#define SW_TRUE 1
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
#ifdef __cplusplus
extern "C"
{
-#endif
+#endif
struct _sw_signal;
#ifdef __cplusplus
}
-#endif
+#endif
#endif
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
#ifdef __cplusplus
extern "C"
{
-#endif
+#endif
struct _sw_socket;
sw_result HOWL_API
sw_multicast_socket_init(
sw_socket * self);
-
-
+
+
sw_result HOWL_API
sw_socket_fina(
sw_socket self);
sw_socket_listen(
sw_socket self,
int qsize);
-
-
+
+
sw_result HOWL_API
sw_socket_connect(
sw_socket self,
sw_ipv4_address address,
sw_port port);
-
-
+
+
sw_result HOWL_API
sw_socket_accept(
sw_socket self,
sw_socket * socket);
-
-
+
+
sw_result HOWL_API
sw_socket_send(
sw_socket self,
sw_ipv4_address to,
sw_port port);
-
+
sw_result HOWL_API
sw_socket_recv(
sw_socket self,
sw_socket_set_blocking_mode(
sw_socket self,
sw_bool blocking_mode);
-
-
+
+
sw_result HOWL_API
sw_socket_set_options(
sw_socket self,
sw_socket_options options);
-
+
sw_ipv4_address HOWL_API
sw_socket_ipv4_address(
sw_result HOWL_API
sw_socket_options_init(
sw_socket_options * self);
-
+
sw_result HOWL_API
sw_socket_options_fina(
sw_socket_options self);
-
+
sw_result HOWL_API
sw_socket_options_set_debug(
sw_socket_options self,
sw_bool val);
-
+
sw_result HOWL_API
sw_socket_options_set_nodelay(
sw_socket_options self,
sw_bool val);
-
-
+
+
sw_result HOWL_API
sw_socket_options_set_dontroute(
sw_socket_options self,
sw_bool val);
-
-
+
+
sw_result HOWL_API
sw_socket_options_set_keepalive(
sw_socket_options self,
sw_socket_options self,
sw_bool onoff,
sw_uint32 linger);
-
-
+
+
sw_result HOWL_API
sw_socket_options_set_reuseaddr(
sw_socket_options self,
sw_socket_options_set_rcvbuf(
sw_socket_options self,
sw_uint32 val);
-
-
+
+
sw_result HOWL_API
sw_socket_options_set_sndbuf(
sw_socket_options self,
int
-sw_socket_error_code(void);
+sw_socket_error_code(void);
#define SW_E_SOCKET_BASE 0x80000200
#ifdef __cplusplus
}
-#endif
+#endif
#endif
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
#ifdef __cplusplus
extern "C"
{
-#endif
+#endif
struct _sw_timer;
#ifdef __cplusplus
}
-#endif
+#endif
#endif
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
sw_result err = SW_OKAY;
sw_discovery_cancel(discovery, oid);
-
+
fprintf(stderr, "resolve reply: 0x%x %s %s %s %s %d\n", interface_index, name, type, domain, sw_ipv4_address_name(address, name_buf, 16), port);
if ((text_record_len > 0) && (text_record) && (*text_record != '\0'))
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
sw_const_string fullname,
sw_uint16 rrtype,
sw_uint16 rrclass,
- sw_uint16 rrdatalen,
+ sw_uint16 rrdatalen,
sw_const_octets rrdata,
sw_uint32 ttl,
sw_opaque extra)
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
+ * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
sw_result err = SW_OKAY;
sw_discovery_cancel(discovery, oid);
-
+
fprintf(stderr, "resolve reply: 0x%x %s %s %s %s %d\n", interface_index, name, type, domain, sw_ipv4_address_name(address, name_buf, 16), port);
if ((text_record_len > 0) && (text_record) && (*text_record != '\0'))
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
char key[255];
uint8_t val[255];
sw_ulong val_len;
-
+
ASSERT_SW_OKAY(sw_text_record_init(&r));
ASSERT_SW_OKAY(sw_text_record_add_string(r, "foo=bar"));
ASSERT_SW_OKAY(sw_text_record_add_string(r, "waldo=baz"));
-
+
ASSERT_SW_OKAY(sw_text_record_fina(r));
return 0;
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
static size_t strlcpy(char *dest, const char *src, size_t n) {
assert(dest);
assert(src);
-
+
if (n > 0) {
strncpy(dest, src, n-1);
dest[n-1] = 0;
}
-
+
return strlen(src);
}
assert(self);
AVAHI_WARN_LINKAGE;
-
+
if (!(*self = avahi_new(struct _sw_text_record, 1))) {
*self = NULL;
return SW_E_UNKNOWN;
}
-
+
(*self)->strlst = NULL;
(*self)->buffer = NULL;
(*self)->buffer_size = 0;
(*self)->buffer_valid = 0;
-
+
return SW_OKAY;
}
sw_const_string string) {
AvahiStringList *n;
-
+
assert(self);
assert(string);
AVAHI_WARN_LINKAGE;
-
+
if (!(n = avahi_string_list_add(self->strlst, string)))
return SW_E_UNKNOWN;
assert(self);
assert(key);
-
+
AVAHI_WARN_LINKAGE;
if (!(n = avahi_string_list_add_pair(self->strlst, key, val)))
assert(self);
assert(key);
assert(len || !val);
-
+
AVAHI_WARN_LINKAGE;
if (!(n = avahi_string_list_add_pair_arbitrary(self->strlst, key, val, len)))
return 0;
self->buffer_size = avahi_string_list_serialize(self->strlst, NULL, 0);
-
+
if (!(self->buffer = avahi_realloc(self->buffer, self->buffer_size + 1)))
return -1;
-
+
avahi_string_list_serialize(self->strlst, self->buffer, self->buffer_size);
self->buffer_valid = 1;
assert(self);
AVAHI_WARN_LINKAGE;
-
+
if (rebuild(self) < 0)
return (uint32_t) -1;
struct _sw_text_record_iterator {
AvahiStringList *strlst, *index;
-
+
};
sw_result sw_text_record_iterator_init(
assert(self);
AVAHI_WARN_LINKAGE;
-
+
if (!(*self = avahi_new(struct _sw_text_record_iterator, 1))) {
*self = NULL;
return SW_E_UNKNOWN;
}
(*self)->index = (*self)->strlst = avahi_string_list_reverse(txt);
-
+
return SW_OKAY;
}
avahi_string_list_free(self->strlst);
avahi_free(self);
-
+
return SW_OKAY;
}
char *mkey = NULL, *mvalue = NULL;
size_t msize = 0;
-
+
assert(self);
assert(key);
-
+
AVAHI_WARN_LINKAGE;
if (!self->index)
memset(val, 0, SW_TEXT_RECORD_MAX_LEN);
memcpy(val, mvalue, msize);
*val_len = msize;
-
+
avahi_free(mkey);
avahi_free(mvalue);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AVAHI_WARN_UNSUPPORTED_ABORT;
}
-AVAHI_GCC_NORETURN
+AVAHI_GCC_NORETURN
sw_time sw_time_sub(
AVAHI_GCC_UNUSED sw_time self,
AVAHI_GCC_UNUSED sw_time y) {
AVAHI_WARN_UNSUPPORTED_ABORT;
}
-AVAHI_GCC_NORETURN
+AVAHI_GCC_NORETURN
sw_int32 sw_time_cmp(
AVAHI_GCC_UNUSED sw_time self,
AVAHI_GCC_UNUSED sw_time y) {
return SW_E_NO_IMPL;
}
-AVAHI_GCC_NORETURN
+AVAHI_GCC_NORETURN
sw_ipv4_address sw_socket_ipv4_address(AVAHI_GCC_UNUSED sw_socket self) {
AVAHI_WARN_UNSUPPORTED_ABORT;
}
-AVAHI_GCC_NORETURN
+AVAHI_GCC_NORETURN
sw_port sw_socket_port(AVAHI_GCC_UNUSED sw_socket self) {
AVAHI_WARN_UNSUPPORTED_ABORT;
}
-AVAHI_GCC_NORETURN
+AVAHI_GCC_NORETURN
sw_sockdesc_t sw_socket_desc(AVAHI_GCC_UNUSED sw_socket self) {
AVAHI_WARN_UNSUPPORTED_ABORT;
}
return SW_E_NO_IMPL;
}
-AVAHI_GCC_NORETURN
+AVAHI_GCC_NORETURN
int sw_socket_error_code(void) {
AVAHI_WARN_UNSUPPORTED_ABORT;
}
return SW_E_NO_IMPL;
}
-AVAHI_GCC_NORETURN
+AVAHI_GCC_NORETURN
sw_corby_orb_delegate sw_corby_orb_get_delegate(AVAHI_GCC_UNUSED sw_corby_orb self) {
AVAHI_WARN_UNSUPPORTED_ABORT;
}
sw_result sw_corby_buffer_fina(AVAHI_GCC_UNUSED sw_corby_buffer self) {
AVAHI_WARN_UNSUPPORTED;
return SW_E_NO_IMPL;
-}
+}
void sw_corby_buffer_reset(AVAHI_GCC_UNUSED sw_corby_buffer self) {
AVAHI_WARN_UNSUPPORTED;
AVAHI_WARN_UNSUPPORTED;
return SW_E_NO_IMPL;
}
-
+
sw_result sw_corby_buffer_put_cstring(
AVAHI_GCC_UNUSED sw_corby_buffer self,
AVAHI_GCC_UNUSED sw_const_string val) {
AVAHI_WARN_UNSUPPORTED;
return SW_E_NO_IMPL;
}
-
+
sw_result sw_corby_buffer_get_uint16(
AVAHI_GCC_UNUSED sw_corby_buffer self,
AVAHI_GCC_UNUSED sw_uint16 * val,
AVAHI_WARN_UNSUPPORTED;
return SW_E_NO_IMPL;
}
-
+
sw_result sw_corby_buffer_get_int32(
AVAHI_GCC_UNUSED sw_corby_buffer self,
AVAHI_GCC_UNUSED sw_int32 * val,
AVAHI_WARN_UNSUPPORTED;
return SW_E_NO_IMPL;
}
-
+
sw_result sw_corby_channel_start_reply(
AVAHI_GCC_UNUSED sw_corby_channel self,
AVAHI_GCC_UNUSED struct _sw_corby_buffer ** buffer,
AVAHI_GCC_UNUSED sw_corby_channel_delegate delegate) {
AVAHI_WARN_UNSUPPORTED;
return SW_E_NO_IMPL;
-}
+}
-AVAHI_GCC_NORETURN
+AVAHI_GCC_NORETURN
sw_corby_channel_delegate sw_corby_channel_get_delegate(
AVAHI_GCC_UNUSED sw_corby_channel self) {
AVAHI_WARN_UNSUPPORTED_ABORT;
AVAHI_WARN_UNSUPPORTED;
}
-AVAHI_GCC_NORETURN
+AVAHI_GCC_NORETURN
sw_opaque sw_corby_channel_get_app_data(AVAHI_GCC_UNUSED sw_corby_channel self) {
AVAHI_WARN_UNSUPPORTED_ABORT;
}
AVAHI_WARN_UNSUPPORTED;
return SW_E_NO_IMPL;
}
-
+
sw_result sw_corby_object_recv(
AVAHI_GCC_UNUSED sw_corby_object self,
AVAHI_GCC_UNUSED sw_corby_message * message,
AVAHI_GCC_UNUSED sw_text_record_string_iterator self) {
AVAHI_WARN_UNSUPPORTED;
return SW_E_NO_IMPL;
-}
+}
sw_result sw_text_record_string_iterator_next(
AVAHI_GCC_UNUSED sw_text_record_string_iterator self,
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
struct _DNSServiceRef_t {
int n_ref;
-
+
AvahiSimplePoll *simple_poll;
int thread_fd, main_fd;
int thread_running;
pthread_mutex_t mutex;
-
+
void *context;
DNSServiceBrowseReply service_browser_callback;
DNSServiceResolveReply service_resolver_callback;
switch (error) {
case AVAHI_OK :
return kDNSServiceErr_NoError;
-
+
case AVAHI_ERR_BAD_STATE :
return kDNSServiceErr_BadState;
-
+
case AVAHI_ERR_INVALID_HOST_NAME:
case AVAHI_ERR_INVALID_DOMAIN_NAME:
case AVAHI_ERR_INVALID_TTL:
case AVAHI_ERR_INVALID_INTERFACE:
case AVAHI_ERR_INVALID_PROTOCOL:
return kDNSServiceErr_BadInterfaceIndex;
-
+
case AVAHI_ERR_INVALID_FLAGS:
return kDNSServiceErr_BadFlags;
-
+
case AVAHI_ERR_NOT_FOUND:
return kDNSServiceErr_NoSuchName;
-
+
case AVAHI_ERR_VERSION_MISMATCH:
return kDNSServiceErr_Incompatible;
static int type_info_parse(struct type_info *i, const char *t) {
char *token = NULL;
-
+
assert(i);
assert(t);
if (*t == 0)
break;
-
+
l = strcspn(t, ",");
if (l <= 0)
goto fail;
-
+
token = avahi_strndup(t, l);
if (!token)
token = NULL;
} else {
char *fst;
-
+
/* This is not the first token, hence a subtype */
if (!(fst = avahi_strdup_printf("%s._sub.%s", token, i->type)))
if (i->type)
return 0;
-
+
fail:
type_info_free(i);
avahi_free(token);
char command;
assert(fd >= 0);
-
+
if ((r = read(fd, &command, 1)) != 1) {
fprintf(stderr, __FILE__": read() failed: %s\n", r < 0 ? strerror(errno) : "EOF");
return -1;
static int poll_func(struct pollfd *ufds, unsigned int nfds, int timeout, void *userdata) {
DNSServiceRef sdref = userdata;
int ret;
-
+
assert(sdref);
-
+
ASSERT_SUCCESS(pthread_mutex_unlock(&sdref->mutex));
/* fprintf(stderr, "pre-syscall\n"); */
ret = poll(ufds, nfds, timeout);
/* fprintf(stderr, "post-syscall\n"); */
-
+
ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex));
return ret;
sigfillset(&mask);
pthread_sigmask(SIG_BLOCK, &mask, NULL);
-
+
sdref->thread = pthread_self();
sdref->thread_running = 1;
break;
/* fprintf(stderr, "Command: %c\n", command); */
-
+
switch (command) {
case COMMAND_POLL: {
for (;;) {
errno = 0;
-
+
if ((ret = avahi_simple_poll_run(sdref->simple_poll)) < 0) {
if (errno == EINTR)
continue;
-
+
fprintf(stderr, __FILE__": avahi_simple_poll_run() failed: %s\n", strerror(errno));
}
if (write_command(sdref->thread_fd, ret < 0 ? COMMAND_POLL_FAILED : COMMAND_POLL_DONE) < 0)
break;
-
+
break;
}
case COMMAND_QUIT:
return NULL;
}
-
+
}
return NULL;
/* Queue an initial POLL command for the thread */
if (write_command(sdref->main_fd, COMMAND_POLL) < 0)
goto fail;
-
+
if (pthread_create(&sdref->thread, NULL, thread_func, sdref) != 0)
goto fail;
sdref->thread_running = 1;
-
+
return sdref;
fail:
static void sdref_free(DNSServiceRef sdref) {
assert(sdref);
-
+
if (sdref->thread_running) {
ASSERT_SUCCESS(write_command(sdref->main_fd, COMMAND_QUIT));
avahi_simple_poll_wakeup(sdref->simple_poll);
avahi_free(sdref->service_host);
type_info_free(&sdref->type_info);
-
+
avahi_string_list_free(sdref->service_txt);
-
+
avahi_free(sdref);
}
int DNSSD_API DNSServiceRefSockFD(DNSServiceRef sdref) {
AVAHI_WARN_LINKAGE;
-
+
if (!sdref || sdref->n_ref <= 0)
return -1;
if (!sdref || sdref->n_ref <= 0)
return kDNSServiceErr_BadParam;
-
+
sdref_ref(sdref);
ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex));
-
+
/* Cleanup notification socket */
if (read_command(sdref->main_fd) != COMMAND_POLL_DONE)
goto finish;
-
+
if (avahi_simple_poll_dispatch(sdref->simple_poll) < 0)
goto finish;
/* Request the poll */
if (write_command(sdref->main_fd, COMMAND_POLL) < 0)
goto finish;
-
+
ret = kDNSServiceErr_NoError;
-
+
finish:
ASSERT_SUCCESS(pthread_mutex_unlock(&sdref->mutex));
-
+
sdref_unref(sdref);
return ret;
type = add_trailing_dot(type, type_fixed, sizeof(type_fixed));
domain = add_trailing_dot(domain, domain_fixed, sizeof(domain_fixed));
-
+
switch (event) {
case AVAHI_BROWSER_NEW:
sdref->service_browser_callback(sdref, kDNSServiceFlagsAdd, interface, kDNSServiceErr_NoError, name, type, domain, sdref->context);
case AVAHI_BROWSER_FAILURE:
sdref->service_browser_callback(sdref, 0, interface, map_error(avahi_client_errno(sdref->client)), NULL, NULL, NULL, sdref->context);
break;
-
+
case AVAHI_BROWSER_CACHE_EXHAUSTED:
case AVAHI_BROWSER_ALL_FOR_NOW:
break;
static void generic_client_callback(AvahiClient *s, AvahiClientState state, void* userdata) {
DNSServiceRef sdref = userdata;
int error = kDNSServiceErr_Unknown;
-
+
assert(s);
assert(sdref);
assert(sdref->n_ref >= 1);
DNSServiceRef sdref = NULL;
AvahiIfIndex ifindex;
struct type_info type_info;
-
+
AVAHI_WARN_LINKAGE;
if (!ret_sdref || !regtype)
}
type_info_init(&type_info);
-
+
if (type_info_parse(&type_info, regtype) < 0 || type_info.n_subtypes > 1) {
type_info_free(&type_info);
return kDNSServiceErr_Unsupported;
} else
regtype = type_info.subtypes ? (char*) type_info.subtypes->text : type_info.type;
-
+
if (!(sdref = sdref_new())) {
type_info_free(&type_info);
return kDNSServiceErr_Unknown;
sdref->service_browser_callback = callback;
ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex));
-
+
if (!(sdref->client = avahi_client_new(avahi_simple_poll_get(sdref->simple_poll), 0, generic_client_callback, sdref, &error))) {
ret = map_error(error);
goto finish;
}
ifindex = interface == kDNSServiceInterfaceIndexAny ? AVAHI_IF_UNSPEC : (AvahiIfIndex) interface;
-
+
if (!(sdref->service_browser = avahi_service_browser_new(sdref->client, ifindex, AVAHI_PROTO_UNSPEC, regtype, domain, 0, service_browser_callback, sdref))) {
ret = map_error(avahi_client_errno(sdref->client));
goto finish;
}
-
+
ret = kDNSServiceErr_NoError;
*ret_sdref = sdref;
-
+
finish:
ASSERT_SUCCESS(pthread_mutex_unlock(&sdref->mutex));
-
+
if (ret != kDNSServiceErr_NoError)
DNSServiceRefDeallocate(sdref);
assert(ret == AVAHI_OK);
strcat(full_name, ".");
-
+
sdref->service_resolver_callback(sdref, 0, interface, kDNSServiceErr_NoError, full_name, host_name, htons(port), l, (unsigned char*) p, sdref->context);
avahi_free(p);
sdref->service_resolver_callback = callback;
ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex));
-
+
if (!(sdref->client = avahi_client_new(avahi_simple_poll_get(sdref->simple_poll), 0, generic_client_callback, sdref, &error))) {
ret = map_error(error);
goto finish;
}
ifindex = interface == kDNSServiceInterfaceIndexAny ? AVAHI_IF_UNSPEC : (AvahiIfIndex) interface;
-
+
if (!(sdref->service_resolver = avahi_service_resolver_new(sdref->client, ifindex, AVAHI_PROTO_UNSPEC, name, regtype, domain, AVAHI_PROTO_UNSPEC, 0, service_resolver_callback, sdref))) {
ret = map_error(avahi_client_errno(sdref->client));
goto finish;
}
-
+
ret = kDNSServiceErr_NoError;
*ret_sdref = sdref;
-
+
finish:
ASSERT_SUCCESS(pthread_mutex_unlock(&sdref->mutex));
-
+
if (ret != kDNSServiceErr_NoError)
DNSServiceRefDeallocate(sdref);
int DNSSD_API DNSServiceConstructFullName (
char *fullName,
- const char *service,
+ const char *service,
const char *regtype,
const char *domain) {
if (avahi_service_name_join(fullName, kDNSServiceMaxDomainName, service, regtype, domain) < 0)
return -1;
-
+
return 0;
}
case AVAHI_BROWSER_FAILURE:
sdref->domain_browser_callback(sdref, 0, interface, map_error(avahi_client_errno(sdref->client)), domain, sdref->context);
break;
-
+
case AVAHI_BROWSER_CACHE_EXHAUSTED:
case AVAHI_BROWSER_ALL_FOR_NOW:
break;
sdref->domain_browser_callback = callback;
ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex));
-
+
if (!(sdref->client = avahi_client_new(avahi_simple_poll_get(sdref->simple_poll), 0, generic_client_callback, sdref, &error))) {
ret = map_error(error);
goto finish;
}
ifindex = interface == kDNSServiceInterfaceIndexAny ? AVAHI_IF_UNSPEC : (AvahiIfIndex) interface;
-
+
if (!(sdref->domain_browser = avahi_domain_browser_new(sdref->client, ifindex, AVAHI_PROTO_UNSPEC, "local",
flags == kDNSServiceFlagsRegistrationDomains ? AVAHI_DOMAIN_BROWSER_REGISTER : AVAHI_DOMAIN_BROWSER_BROWSE,
0, domain_browser_callback, sdref))) {
ret = map_error(avahi_client_errno(sdref->client));
goto finish;
}
-
+
ret = kDNSServiceErr_NoError;
*ret_sdref = sdref;
-
+
finish:
ASSERT_SUCCESS(pthread_mutex_unlock(&sdref->mutex));
-
+
if (ret != kDNSServiceErr_NoError)
DNSServiceRefDeallocate(sdref);
regtype = add_trailing_dot(sdref->type_info.type, regtype_fixed, sizeof(regtype_fixed));
domain = add_trailing_dot(sdref->service_domain, domain_fixed, sizeof(domain_fixed));
-
+
sdref->service_register_callback(
sdref, 0, error,
sdref->service_name_chosen ? sdref->service_name_chosen : sdref->service_name,
static int reg_create_service(DNSServiceRef sdref) {
int ret;
AvahiStringList *l;
-
+
assert(sdref);
assert(sdref->n_ref >= 1);
/* We've not been setup completely */
if (!sdref->entry_group)
return;
-
+
switch (state) {
case AVAHI_CLIENT_FAILURE:
reg_report_error(sdref, kDNSServiceErr_Unknown);
if (!sdref->service_name_chosen) {
assert(sdref->service_name);
-
+
if (!(sdref->service_name_chosen = avahi_strdup(sdref->service_name))) {
reg_report_error(sdref, kDNSServiceErr_NoMemory);
return;
}
}
-
+
/* Register the service */
if ((ret = reg_create_service(sdref)) < 0) {
reg_report_error(sdref, map_error(ret));
return;
}
-
+
break;
}
-
+
case AVAHI_CLIENT_S_COLLISION:
case AVAHI_CLIENT_S_REGISTERING:
/* Remove our entry */
avahi_entry_group_reset(sdref->entry_group);
-
+
break;
case AVAHI_CLIENT_CONNECTING:
case AVAHI_ENTRY_GROUP_COLLISION: {
char *n;
int ret;
-
+
/* Remove our entry */
avahi_entry_group_reset(sdref->entry_group);
reg_report_error(sdref, map_error(ret));
return;
}
-
+
break;
}
/* Inform the user */
reg_report_error(sdref, map_error(avahi_client_errno(sdref->client)));
break;
-
+
}
}
DNSServiceRef *ret_sdref,
DNSServiceFlags flags,
uint32_t interface,
- const char *name,
+ const char *name,
const char *regtype,
- const char *domain,
- const char *host,
+ const char *domain,
+ const char *host,
uint16_t port,
uint16_t txtLen,
- const void *txtRecord,
- DNSServiceRegisterReply callback,
+ const void *txtRecord,
+ DNSServiceRegisterReply callback,
void *context) {
DNSServiceErrorType ret = kDNSServiceErr_Unknown;
if (!ret_sdref || !regtype)
return kDNSServiceErr_BadParam;
*ret_sdref = NULL;
-
+
if (!txtRecord) {
txtLen = 1;
txtRecord = "";
return kDNSServiceErr_Unsupported;
}
- if (txtLen > 0)
+ if (txtLen > 0)
if (avahi_string_list_parse(txtRecord, txtLen, &txt) < 0)
return kDNSServiceErr_Invalid;
avahi_string_list_free(txt);
return kDNSServiceErr_Invalid;
}
-
+
if (!(sdref = sdref_new())) {
avahi_string_list_free(txt);
type_info_free(&type_info);
sdref->service_txt = txt;
/* Some OOM checking would be cool here */
-
+
ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex));
-
+
if (!(sdref->client = avahi_client_new(avahi_simple_poll_get(sdref->simple_poll), 0, reg_client_callback, sdref, &error))) {
ret = map_error(error);
goto finish;
goto finish;
}
-
+
if ((error = reg_create_service(sdref)) < 0) {
ret = map_error(error);
goto finish;
}
}
-
+
ret = kDNSServiceErr_NoError;
*ret_sdref = sdref;
-
+
finish:
ASSERT_SUCCESS(pthread_mutex_unlock(&sdref->mutex));
-
+
if (ret != kDNSServiceErr_NoError)
DNSServiceRefDeallocate(sdref);
DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord(
DNSServiceRef sdref,
- DNSRecordRef rref,
+ DNSRecordRef rref,
DNSServiceFlags flags,
uint16_t rdlen,
const void *rdata,
return kDNSServiceErr_Unsupported;
}
- if (rdlen > 0)
+ if (rdlen > 0)
if (avahi_string_list_parse(rdata, rdlen, &txt) < 0)
return kDNSServiceErr_Invalid;
sdref->type_info.type,
sdref->service_domain,
sdref->service_txt) < 0) {
-
+
ret = map_error(avahi_client_errno(sdref->client));
goto finish;
}
avahi_string_list_free(txt);
ret = kDNSServiceErr_NoError;
-
+
finish:
ASSERT_SUCCESS(pthread_mutex_unlock(&sdref->mutex));
-
+
return ret;
}
*
* Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without
+ * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* Flag for signifying that a query or registration should be performed exclusively via multicast DNS,
* even for a name in a domain (e.g. foo.apple.com.) that would normally imply unicast DNS.
*/
-
+
kDNSServiceFlagsReturnCNAME = 0x800
/* Flag for returning CNAME records in the DNSServiceQueryRecord call. CNAME records are
* normally followed without indicating to the client that there was a CNAME record.
*/
-/*
+/*
* Constants for specifying an interface index
*
* Specific interface indexes are identified via a 32-bit unsigned integer returned
* by the if_nametoindex() family of calls.
- *
+ *
* If the client passes 0 for interface index, that means "do the right thing",
* which (at present) means, "if the name is in an mDNS local multicast domain
* (e.g. 'local.', '254.169.in-addr.arpa.', '{8,9,A,B}.E.F.ip6.arpa.') then multicast
* on all applicable interfaces, otherwise send via unicast to the appropriate
* DNS server." Normally, most clients will use 0 for interface index to
* automatically get the default sensible behaviour.
- *
+ *
* If the client passes a positive interface index, then for multicast names that
* indicates to do the operation only on that one interface. For unicast names the
* interface index is ignored unless kDNSServiceFlagsForceMulticast is also set.
- *
+ *
* If the client passes kDNSServiceInterfaceIndexLocalOnly when registering
* a service, then that service will be found *only* by other local clients
* on the same machine that are browsing using kDNSServiceInterfaceIndexLocalOnly
* running on the same machine, this allows the client to advertise that service
* in a way such that it does not inadvertently appear in service lists on
* all the other machines on the network.
- *
+ *
* If the client passes kDNSServiceInterfaceIndexLocalOnly when browsing
* then it will find *all* records registered on that same local machine.
* Clients explicitly wishing to discover *only* LocalOnly services can
/* DNSServiceEnumerateDomains() Parameters:
*
*
- * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
+ * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
* then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
* and the enumeration operation will run indefinitely until the client
* terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
/* DNSServiceRegister() Parameters:
*
- * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
+ * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
* then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
* and the registration will remain active indefinitely until the client
* terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
/* DNSServiceBrowse() Parameters:
*
- * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
+ * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
* then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
* and the browse operation will run indefinitely until the client
* terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
/* DNSServiceResolve() Parameters
*
- * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
+ * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
* then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
* and the resolve operation will run indefinitely until the client
* terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
/* DNSServiceQueryRecord() Parameters:
*
- * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
+ * sdRef: A pointer to an uninitialized DNSServiceRef. If the call succeeds
* then it initializes the DNSServiceRef, returns kDNSServiceErr_NoError,
* and the query operation will run indefinitely until the client
* terminates it by passing this DNSServiceRef to DNSServiceRefDeallocate().
* calls by this user that do not specify an explicit domain will browse and
* register in this wide-area domain in addition to .local. In addition, this
* domain will be returned as a Browse domain via domain enumeration calls.
- *
+ *
*
* Parameters:
*
(
DNSServiceFlags flags,
const char *domain
- );
-
+ );
+
#endif //__APPLE_API_PRIVATE
// Some C compiler cleverness. We can make the compiler check certain things for us,
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AVAHI_WARN_LINKAGE;
assert(txtref);
-
+
/* Apple's API design is flawed in so many ways, including the
* fact that it isn't compatible with 64 bit processors. To work
* around this we need some magic here which involves allocating
TXTRecordInternal *t;
AVAHI_WARN_LINKAGE;
-
+
assert(txtref);
t = INTERNAL_PTR(txtref);
if (!t)
static int make_sure_fits_in(TXTRecordInternal *t, size_t size) {
uint8_t *n;
size_t nsize;
-
+
assert(t);
if (t->size + size <= t->max_size)
if (nsize > 0xFFFF)
return -1;
-
+
if (!(n = avahi_realloc(t->malloc_buffer, nsize)))
return -1;
if (!t->malloc_buffer && t->size)
memcpy(n, t->buffer, t->size);
-
+
t->buffer = t->malloc_buffer = n;
t->max_size = nsize;
/* Key longer than buffer */
if (key_len > t->size - i - 1)
break;
-
+
if (key_len <= *p &&
strncmp(key, (char*) p+1, key_len) == 0 &&
(key_len == *p || p[1+key_len] == '=')) {
found = 1;
} else {
/* Skip to next */
-
+
i += *p +1;
p += *p +1;
}
DNSServiceErrorType DNSSD_API TXTRecordSetValue(
TXTRecordRef *txtref,
const char *key,
- uint8_t length,
+ uint8_t length,
const void *value) {
TXTRecordInternal *t;
if (n > 0xFF)
return kDNSServiceErr_Invalid;
-
+
if (make_sure_fits_in(t, 1 + n) < 0)
return kDNSServiceErr_NoMemory;
*(p++) = (uint8_t) n;
t->size ++;
-
+
memcpy(p, key, l);
p += l;
t->size += l;
key_len = strlen(key);
assert(key_len <= 0xFF);
-
+
p = buffer;
i = 0;
/* Key longer than buffer */
if (key_len > size - i - 1)
return NULL;
-
+
if (key_len <= *p &&
strncmp(key, (const char*) p+1, key_len) == 0 &&
(key_len == *p || p[1+key_len] == '=')) {
/* Key matches, so let's return it */
return p;
- }
+ }
/* Skip to next */
i += *p +1;
const uint8_t *p;
size_t n, l;
-
+
AVAHI_WARN_LINKAGE;
assert(key);
if (*key == 0 || strchr(key, '=') || strlen(key) > 0xFF) /* Empty or invalid key */
return NULL;
-
+
assert(buffer);
if (!(p = find_key(buffer, size, key)))
if (n <= 0)
goto fail;
-
+
assert(*p == '=');
p++;
n--;
if (value_len)
*value_len = n;
-
+
return p;
fail:
if (value_len)
*value_len = 0;
-
+
return NULL;
}
if (!size)
return 0;
-
+
assert(buffer);
-
+
p = buffer;
i = 0;
-
+
while (i < size) {
/* Does the item fit in? */
size_t i;
unsigned n = 0;
DNSServiceErrorType ret = kDNSServiceErr_Invalid;
-
+
AVAHI_WARN_LINKAGE;
if (!size)
p = buffer;
i = 0;
-
+
while (i < size) {
/* Does the item fit in? */
strncpy(key, (const char*) p + 1, l);
key[l] = 0;
-
+
if (d) {
if (value_len)
*value_len = *p - l - 1;
if (value_len)
*value_len = 0;
- return ret;
+ return ret;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AVAHI_GCC_UNUSED void *context) {
AVAHI_WARN_UNSUPPORTED;
-
+
return kDNSServiceErr_Unsupported;
}
AVAHI_GCC_UNUSED void *context) {
AVAHI_WARN_UNSUPPORTED;
-
+
return kDNSServiceErr_Unsupported;
}
AVAHI_GCC_UNUSED const void *rdata) {
AVAHI_WARN_UNSUPPORTED;
-
+
return kDNSServiceErr_Unsupported;
}
DNSServiceErrorType DNSSD_API DNSServiceCreateConnection(AVAHI_GCC_UNUSED DNSServiceRef *sdRef) {
AVAHI_WARN_UNSUPPORTED;
-
+
return kDNSServiceErr_Unsupported;
}
AVAHI_GCC_UNUSED uint32_t ttl) {
AVAHI_WARN_UNSUPPORTED;
-
+
return kDNSServiceErr_Unsupported;
}
AVAHI_GCC_UNUSED DNSServiceFlags flags) {
AVAHI_WARN_UNSUPPORTED;
-
+
return kDNSServiceErr_Unsupported;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/* Yes, I know, this is not portable. But who cares? It's for
* cosmetics only, anyway. */
-
+
pthread_mutex_lock(&mutex);
if (exe_name[0] == 0) {
int k;
-
+
if ((k = readlink("/proc/self/exe", exe_name, sizeof(exe_name)-1)) < 0)
snprintf(exe_name, sizeof(exe_name), "(unknown)");
else {
char *slash;
-
+
assert((size_t) k <= sizeof(exe_name)-1);
exe_name[k] = 0;
-
+
if ((slash = strrchr(exe_name, '/')))
memmove(exe_name, slash+1, strlen(slash)+1);
}
}
-
+
pthread_mutex_unlock(&mutex);
return exe_name;
char msg[512] = "*** WARNING *** ";
va_list ap;
size_t n;
-
+
assert(fmt);
-
+
va_start(ap, fmt);
n = strlen(msg);
vsnprintf(msg + n, sizeof(msg) - n, fmt, ap);
va_end(ap);
-
+
fprintf(stderr, "%s\n", msg);
openlog(avahi_exe_name(), LOG_PID, LOG_USER);
void avahi_warn_linkage(void) {
int w;
-
+
pthread_mutex_lock(&linkage_mutex);
w = linkage_warning;
linkage_warning = 1;
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AVAHI_LLIST_REMOVE(AvahiAnnouncer, by_interface, a->interface->announcers, a);
AVAHI_LLIST_REMOVE(AvahiAnnouncer, by_entry, a->entry->announcers, a);
-
+
avahi_free(a);
}
}
} else {
- if (a->time_event)
+ if (a->time_event)
avahi_time_event_update(a->time_event, tv);
else
a->time_event = avahi_time_event_new(a->server->time_event_queue, tv, elapse_announce, a);
assert(!g->dead);
/* Check whether all group members have been probed */
-
- if (g->state != AVAHI_ENTRY_GROUP_REGISTERING || g->n_probing > 0)
+
+ if (g->state != AVAHI_ENTRY_GROUP_REGISTERING || g->n_probing > 0)
return;
avahi_s_entry_group_change_state(g, AVAHI_ENTRY_GROUP_ESTABLISHED);
if (g->dead)
return;
-
+
for (e = g->entries; e; e = e->by_group_next) {
AvahiAnnouncer *a;
-
+
for (a = e->announcers; a; a = a->by_entry_next) {
-
+
if (a->state != AVAHI_WAITING)
continue;
-
+
a->state = AVAHI_ANNOUNCING;
if (immediately) {
/* Shortcut */
-
+
a->n_iteration = 1;
next_state(a);
} else {
assert(a->entry->group);
avahi_s_entry_group_check_probed(a->entry->group, 1);
-
+
} else if (a->state == AVAHI_PROBING) {
if (a->n_iteration >= 4) {
/* Probing done */
-
+
if (a->entry->group) {
assert(a->entry->group->n_probing);
a->entry->group->n_probing--;
}
-
+
if (a->entry->group && a->entry->group->state == AVAHI_ENTRY_GROUP_REGISTERING)
a->state = AVAHI_WAITING;
else {
struct timeval tv;
avahi_interface_post_probe(a->interface, a->entry->record, 0);
-
+
avahi_elapse_time(&tv, AVAHI_PROBE_INTERVAL_MSEC, 0);
set_timeout(a, &tv);
-
+
a->n_iteration++;
}
} else {
struct timeval tv;
avahi_elapse_time(&tv, a->sec_delay*1000, AVAHI_ANNOUNCEMENT_JITTER_MSEC);
-
+
if (a->n_iteration < 10)
a->sec_delay *= 2;
-
+
set_timeout(a, &tv);
}
}
static AvahiAnnouncer *get_announcer(AvahiServer *s, AvahiEntry *e, AvahiInterface *i) {
AvahiAnnouncer *a;
-
+
assert(s);
assert(e);
assert(i);
static void go_to_initial_state(AvahiAnnouncer *a) {
AvahiEntry *e;
struct timeval tv;
-
+
assert(a);
e = a->entry;
a->state = AVAHI_ANNOUNCING;
else
a->state = AVAHI_WAITING;
-
+
} else
a->state = AVAHI_ESTABLISHED;
if (a->state == AVAHI_PROBING && e->group)
e->group->n_probing++;
- if (a->state == AVAHI_PROBING)
+ if (a->state == AVAHI_PROBING)
set_timeout(a, avahi_elapse_time(&tv, 0, AVAHI_PROBE_JITTER_MSEC));
- else if (a->state == AVAHI_ANNOUNCING)
+ else if (a->state == AVAHI_ANNOUNCING)
set_timeout(a, avahi_elapse_time(&tv, 0, AVAHI_ANNOUNCEMENT_JITTER_MSEC));
else
set_timeout(a, NULL);
/* We don't want duplicate announcers */
if (get_announcer(s, e, i))
- return;
+ return;
if ((!(a = avahi_new(AvahiAnnouncer, 1)))) {
avahi_log_error(__FILE__": Out of memory.");
return;
}
-
+
a->server = s;
a->interface = i;
a->entry = e;
void avahi_announce_interface(AvahiServer *s, AvahiInterface *i) {
AvahiEntry *e;
-
+
assert(s);
assert(i);
static void announce_walk_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, void* userdata) {
AvahiEntry *e = userdata;
-
+
assert(m);
assert(i);
assert(e);
void avahi_announce_group(AvahiServer *s, AvahiSEntryGroup *g) {
AvahiEntry *e;
-
+
assert(s);
assert(g);
if (!(a = get_announcer(s, e, i)))
return 0;
-
+
return
a->state == AVAHI_ANNOUNCING ||
a->state == AVAHI_ESTABLISHED ||
if (!(a = get_announcer(s, e, i)))
return 0;
-
+
return
a->state == AVAHI_PROBING ||
(a->state == AVAHI_WAITING && (e->flags & AVAHI_PUBLISH_UNIQUE));
void avahi_entry_return_to_initial_state(AvahiServer *s, AvahiEntry *e, AvahiInterface *i) {
AvahiAnnouncer *a;
-
+
assert(s);
assert(e);
assert(i);
static AvahiRecord *make_goodbye_record(AvahiRecord *r) {
AvahiRecord *g;
-
+
assert(r);
if (!(g = avahi_record_copy(r)))
return NULL; /* OOM */
-
+
assert(g->ref == 1);
g->ttl = 0;
static int is_duplicate_entry(AvahiServer *s, AvahiEntry *e) {
AvahiEntry *i;
-
+
assert(s);
assert(e);
if (!avahi_record_equal_no_ttl(i->record, e->record))
continue;
-
+
return 1;
}
static void send_goodbye_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, void* userdata) {
AvahiEntry *e = userdata;
AvahiRecord *g;
-
+
assert(m);
assert(i);
assert(e);
if (is_duplicate_entry(m->server, e))
return;
-
+
if (!(g = make_goodbye_record(e->record)))
return; /* OOM */
-
+
avahi_interface_post_response(i, g, e->flags & AVAHI_PUBLISH_UNIQUE, NULL, 1);
avahi_record_unref(g);
}
static void reannounce(AvahiAnnouncer *a) {
AvahiEntry *e;
struct timeval tv;
-
+
assert(a);
e = a->entry;
/* Because we might change state we decrease the probing counter first */
if (a->state == AVAHI_PROBING && a->entry->group)
a->entry->group->n_probing--;
-
+
if (a->state == AVAHI_PROBING ||
(a->state == AVAHI_WAITING && (e->flags & AVAHI_PUBLISH_UNIQUE) && !(e->flags & AVAHI_PUBLISH_NO_PROBE)))
/* We were probing or waiting after probe, so we restart probing from the beginning here */
-
+
a->state = AVAHI_PROBING;
else if (a->state == AVAHI_WAITING)
a->state = AVAHI_WAITING;
else if (e->flags & AVAHI_PUBLISH_NO_ANNOUNCE)
-
+
/* No announcer needed */
a->state = AVAHI_ESTABLISHED;
else {
-
+
/* Ok, let's restart announcing */
a->state = AVAHI_ANNOUNCING;
- }
-
+ }
+
/* Now let's increase the probing counter again */
if (a->state == AVAHI_PROBING && e->group)
e->group->n_probing++;
-
+
a->n_iteration = 1;
a->sec_delay = 1;
if (a->state == AVAHI_PROBING)
set_timeout(a, avahi_elapse_time(&tv, 0, AVAHI_PROBE_JITTER_MSEC));
- else if (a->state == AVAHI_ANNOUNCING)
+ else if (a->state == AVAHI_ANNOUNCING)
set_timeout(a, avahi_elapse_time(&tv, 0, AVAHI_ANNOUNCEMENT_JITTER_MSEC));
else
set_timeout(a, NULL);
static void reannounce_walk_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, void* userdata) {
AvahiEntry *e = userdata;
AvahiAnnouncer *a;
-
+
assert(m);
assert(i);
assert(e);
avahi_interface_monitor_walk(s->monitor, e->interface, e->protocol, reannounce_walk_callback, e);
}
-
+
void avahi_goodbye_interface(AvahiServer *s, AvahiInterface *i, int send_goodbye, int remove) {
assert(s);
assert(i);
if (send_goodbye)
if (i->announcing) {
AvahiEntry *e;
-
+
for (e = s->entries; e; e = e->entries_next)
if (!e->dead)
send_goodbye_callback(s->monitor, i, e);
void avahi_goodbye_entry(AvahiServer *s, AvahiEntry *e, int send_goodbye, int remove) {
assert(s);
assert(e);
-
+
if (send_goodbye)
if (!e->dead)
avahi_interface_monitor_walk(s->monitor, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, send_goodbye_callback, e);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AvahiSimplePoll *simple_poll;
simple_poll = avahi_simple_poll_new();
-
+
avahi_server_config_init(&config);
config.publish_hinfo = 0;
config.publish_addresses = 0;
config.publish_domain = 0;
config.use_ipv6 = 0;
config.enable_reflector = 1;
-
+
server = avahi_server_new(avahi_simple_poll_get(simple_poll), &config, NULL, NULL, &error);
avahi_server_config_free(&config);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
static void dump_timeout_callback(AvahiTimeout *timeout, void* userdata) {
struct timeval tv;
-
+
AvahiServer *avahi = userdata;
avahi_server_dump(avahi, dump_line, NULL);
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
AVAHI_GCC_UNUSED void* userdata) {
char *t;
-
+
assert(r);
if (record) {
static void create_entries(int new_name);
static void entry_group_callback(AVAHI_GCC_UNUSED AvahiServer *s, AVAHI_GCC_UNUSED AvahiSEntryGroup *g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void* userdata) {
- avahi_log_debug("entry group state: %i", state);
+ avahi_log_debug("entry group state: %i", state);
if (state == AVAHI_ENTRY_GROUP_COLLISION) {
remove_entries();
static void server_callback(AvahiServer *s, AvahiServerState state, AVAHI_GCC_UNUSED void* userdata) {
server = s;
- avahi_log_debug("server state: %i", state);
-
+ avahi_log_debug("server state: %i", state);
+
if (state == AVAHI_SERVER_RUNNING) {
avahi_log_debug("Server startup complete. Host name is <%s>. Service cookie is %u", avahi_server_get_host_name_fqdn(s), avahi_server_get_local_service_cookie(s));
create_entries(0);
remove_entries();
- if (!group)
+ if (!group)
group = avahi_s_entry_group_new(server, entry_group_callback, NULL);
assert(avahi_s_entry_group_is_empty(group));
-
+
if (!service_name)
service_name = avahi_strdup("Test Service");
else if (new_name) {
avahi_free(service_name);
service_name = n;
}
-
+
if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, service_name, "_http._tcp", NULL, NULL, 80, "foo", NULL) < 0) {
avahi_log_error("Failed to add HTTP service");
goto fail;
r = avahi_record_new_full("cname.local", AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_CNAME, AVAHI_DEFAULT_TTL);
r->data.cname.name = avahi_strdup("cocaine.local");
-
+
if (avahi_server_add(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, r) < 0) {
avahi_record_unref(r);
avahi_log_error("Failed to add CNAME record");
const AvahiAddress *a,
uint16_t port,
AvahiStringList *txt,
- AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
+ AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
AVAHI_GCC_UNUSED void* userdata) {
if (event != AVAHI_RESOLVER_FOUND)
avahi_log_debug("SR: (%i.%i) <%s> as %s in <%s> [%s]", iface, protocol, name, service_type, domain_name, resolver_event_to_string(event));
else {
char t[AVAHI_ADDRESS_STR_MAX], *s;
-
+
avahi_address_snprint(t, sizeof(t), a);
s = avahi_string_list_to_string(txt);
uint16_t port,
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
AVAHI_GCC_UNUSED void* userdata) {
-
+
char t[AVAHI_ADDRESS_STR_MAX] = "n/a";
-
+
if (a)
avahi_address_snprint(t, sizeof(t), a);
simple_poll = avahi_simple_poll_new();
poll_api = avahi_simple_poll_get(simple_poll);
-
+
avahi_server_config_init(&config);
avahi_address_parse("192.168.50.1", AVAHI_PROTO_UNSPEC, &config.wide_area_servers[0]);
server = avahi_server_new(poll_api, &config, server_callback, NULL, &error);
avahi_server_config_free(&config);
-
+
k = avahi_key_new("_http._tcp.0pointer.de", AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR);
r = avahi_s_record_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, k, 0, record_browser_callback, NULL);
avahi_key_unref(k);
avahi_s_dns_server_browser_free(dsb);
if (group)
- avahi_s_entry_group_free(group);
+ avahi_s_entry_group_free(group);
if (server)
avahi_server_free(server);
avahi_simple_poll_free(simple_poll);
avahi_free(service_name);
-
+
return 0;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AvahiSHostNameResolver *host_name_resolver;
AvahiAddress address;
AvahiLookupResultFlags flags;
-
+
AVAHI_LLIST_FIELDS(AvahiDNSServerInfo, info);
};
struct AvahiSDNSServerBrowser {
AvahiServer *server;
-
+
AvahiSRecordBrowser *record_browser;
AvahiSDNSServerBrowserCallback callback;
void* userdata;
AvahiLookupFlags user_flags;
unsigned n_info;
-
+
AVAHI_LLIST_FIELDS(AvahiSDNSServerBrowser, browser);
AVAHI_LLIST_HEAD(AvahiDNSServerInfo, info);
};
static AvahiDNSServerInfo* get_server_info(AvahiSDNSServerBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiRecord *r) {
AvahiDNSServerInfo *i;
-
+
assert(b);
assert(r);
avahi_record_unref(i->srv_record);
if (i->host_name_resolver)
avahi_s_host_name_resolver_free(i->host_name_resolver);
-
+
AVAHI_LLIST_REMOVE(AvahiDNSServerInfo, info, b->info, i);
assert(b->n_info >= 1);
b->n_info--;
-
+
avahi_free(i);
}
const AvahiAddress *a,
AvahiLookupResultFlags flags,
void* userdata) {
-
+
AvahiDNSServerInfo *i = userdata;
-
+
assert(r);
assert(host_name);
assert(i);
switch (event) {
case AVAHI_RESOLVER_FOUND: {
i->address = *a;
-
+
i->browser->callback(
i->browser,
i->interface,
AvahiRecord *record,
AvahiLookupResultFlags flags,
void* userdata) {
-
+
AvahiSDNSServerBrowser *b = userdata;
assert(rr);
switch (event) {
case AVAHI_BROWSER_NEW: {
AvahiDNSServerInfo *i;
-
+
assert(record);
assert(record->key->type == AVAHI_DNS_TYPE_SRV);
if (get_server_info(b, interface, protocol, record))
return;
-
+
if (b->n_info >= 10)
return;
-
+
if (!(i = avahi_new(AvahiDNSServerInfo, 1)))
return; /* OOM */
-
+
i->browser = b;
i->interface = interface;
i->protocol = protocol;
b->user_flags,
host_name_resolver_callback, i);
i->flags = flags;
-
+
AVAHI_LLIST_PREPEND(AvahiDNSServerInfo, info, b->info, i);
-
+
b->n_info++;
break;
}
case AVAHI_BROWSER_REMOVE: {
AvahiDNSServerInfo *i;
-
+
assert(record);
assert(record->key->type == AVAHI_DNS_TYPE_SRV);
if (!(i = get_server_info(b, interface, protocol, record)))
return;
-
+
if (!i->host_name_resolver)
b->callback(
b,
i->srv_record->data.srv.port,
i->flags | flags,
b->userdata);
-
+
server_info_free(b, i);
break;
}
0,
flags,
b->userdata);
-
+
break;
}
}
"_domain._udp",
"_dns-update._udp"
};
-
+
AvahiSDNSServerBrowser *b;
AvahiKey *k = NULL;
char n[AVAHI_DOMAIN_NAME_MAX];
int r;
-
+
assert(server);
assert(callback);
avahi_server_set_errno(server, r);
return NULL;
}
-
+
if (!(b = avahi_new(AvahiSDNSServerBrowser, 1))) {
avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
return NULL;
}
-
+
b->server = server;
b->callback = callback;
b->userdata = userdata;
AVAHI_LLIST_HEAD_INIT(AvahiDNSServerInfo, b->info);
AVAHI_LLIST_PREPEND(AvahiSDNSServerBrowser, browser, server->dns_server_browsers, b);
-
+
if (!(k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV))) {
avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
if (!(b->record_browser = avahi_s_record_browser_new(server, interface, protocol, k, flags, record_browser_callback, b)))
goto fail;
-
+
avahi_key_unref(k);
return b;
if (k)
avahi_key_unref(k);
-
+
avahi_s_dns_server_browser_free(b);
return NULL;
}
while (b->info)
server_info_free(b, b->info);
-
+
AVAHI_LLIST_REMOVE(AvahiSDNSServerBrowser, browser, b->server->dns_server_browsers, b);
if (b->record_browser)
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
struct AvahiSDomainBrowser {
int ref;
-
+
AvahiServer *server;
-
+
AvahiSRecordBrowser *record_browser;
AvahiDomainBrowserType type;
AvahiTimeEvent *defer_event;
int all_for_now_scheduled;
-
+
AVAHI_LLIST_FIELDS(AvahiSDomainBrowser, browser);
};
AvahiRecord *record,
AvahiLookupResultFlags flags,
void* userdata) {
-
+
AvahiSDomainBrowser *b = userdata;
char *n = NULL;
b->all_for_now_scheduled = 1;
return;
}
-
+
/* Filter flags */
flags &= AVAHI_LOOKUP_RESULT_CACHED | AVAHI_LOOKUP_RESULT_MULTICAST | AVAHI_LOOKUP_RESULT_WIDE_AREA;
AvahiStringList *l;
/* Filter out entries defined statically */
-
+
for (l = b->server->config.browse_domains; l; l = l->next)
if (avahi_domain_equal((char*) l->text, n))
return;
}
-
+
}
-
+
b->callback(b, interface, protocol, event, n, flags, b->userdata);
}
static void defer_callback(AvahiTimeEvent *e, void *userdata) {
AvahiSDomainBrowser *b = userdata;
AvahiStringList *l;
-
+
assert(e);
assert(b);
inc_ref(b);
for (l = b->server->config.browse_domains; l; l = l->next) {
-
+
/* Check whether this object still exists outside our own
* stack frame */
if (b->ref <= 1)
break;
-
+
b->callback(b, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_BROWSER_NEW, (char*) l->text, AVAHI_LOOKUP_RESULT_STATIC, b->userdata);
}
if (b->ref > 1) {
/* If the ALL_FOR_NOW event has already been scheduled, execute it now */
-
- if (b->all_for_now_scheduled)
+
+ if (b->all_for_now_scheduled)
b->callback(b, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_BROWSER_ALL_FOR_NOW, NULL, 0, b->userdata);
}
-
+
/* Decrease ref counter */
avahi_s_domain_browser_free(b);
}
"dr",
"lb"
};
-
+
AvahiSDomainBrowser *b;
AvahiKey *k = NULL;
char n[AVAHI_DOMAIN_NAME_MAX];
int r;
-
+
assert(server);
assert(callback);
avahi_server_set_errno(server, r);
return NULL;
}
-
+
if (!(b = avahi_new(AvahiSDomainBrowser, 1))) {
avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
return NULL;
avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
if (!(b->record_browser = avahi_s_record_browser_new(server, interface, protocol, k, flags, record_browser_callback, b)))
goto fail;
-
+
avahi_key_unref(k);
if (type == AVAHI_DOMAIN_BROWSER_BROWSE && b->server->config.browse_domains)
b->defer_event = avahi_time_event_new(server->time_event_queue, NULL, defer_callback, b);
-
+
return b;
-
+
fail:
-
+
if (k)
avahi_key_unref(k);
-
+
avahi_s_domain_browser_free(b);
-
+
return NULL;
}
assert(b->ref >= 1);
if (--b->ref > 0)
return;
-
+
AVAHI_LLIST_REMOVE(AvahiSDomainBrowser, browser, b->server->domain_browsers, b);
if (b->record_browser)
if (b->defer_event)
avahi_time_event_free(b->defer_event);
-
+
avahi_free(b);
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AvahiRecord *record,
AvahiLookupResultFlags flags,
void* userdata) {
-
+
AvahiSServiceTypeBrowser *b = userdata;
assert(rr);
if (record) {
char type[AVAHI_DOMAIN_NAME_MAX], domain[AVAHI_DOMAIN_NAME_MAX];
-
+
assert(record->key->type == AVAHI_DNS_TYPE_PTR);
if (avahi_service_name_split(record->data.ptr.name, NULL, 0, type, sizeof(type), domain, sizeof(domain)) < 0) {
AvahiLookupFlags flags,
AvahiSServiceTypeBrowserCallback callback,
void* userdata) {
-
+
AvahiSServiceTypeBrowser *b;
AvahiKey *k = NULL;
char n[AVAHI_DOMAIN_NAME_MAX];
int r;
-
+
assert(server);
assert(callback);
avahi_server_set_errno(server, r);
return NULL;
}
-
+
if (!(b = avahi_new(AvahiSServiceTypeBrowser, 1))) {
avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
return NULL;
}
-
+
b->server = server;
b->callback = callback;
b->userdata = userdata;
b->record_browser = NULL;
-
+
AVAHI_LLIST_PREPEND(AvahiSServiceTypeBrowser, browser, server->service_type_browsers, b);
if (!(b->domain_name = avahi_normalize_name_strdup(domain))) {
avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
if (!(k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR))) {
avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
if (!(b->record_browser = avahi_s_record_browser_new(server, interface, protocol, k, flags, record_browser_callback, b)))
goto fail;
-
+
avahi_key_unref(k);
return b;
avahi_key_unref(k);
avahi_s_service_type_browser_free(b);
-
+
return NULL;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AvahiServer *server;
char *domain_name;
char *service_type;
-
+
AvahiSRecordBrowser *record_browser;
AvahiSServiceBrowserCallback callback;
AvahiRecord *record,
AvahiLookupResultFlags flags,
void* userdata) {
-
+
AvahiSServiceBrowser *b = userdata;
assert(rr);
/* Filter flags */
flags &= AVAHI_LOOKUP_RESULT_CACHED | AVAHI_LOOKUP_RESULT_MULTICAST | AVAHI_LOOKUP_RESULT_WIDE_AREA;
-
+
if (record) {
char service[AVAHI_LABEL_MAX], type[AVAHI_DOMAIN_NAME_MAX], domain[AVAHI_DOMAIN_NAME_MAX];
}
b->callback(b, interface, protocol, event, service, type, domain, flags, b->userdata);
-
+
} else
b->callback(b, interface, protocol, event, NULL, b->service_type, b->domain_name, flags, b->userdata);
AvahiKey *k = NULL;
char n[AVAHI_DOMAIN_NAME_MAX];
int r;
-
+
assert(server);
assert(callback);
assert(service_type);
avahi_server_set_errno(server, r);
return NULL;
}
-
+
if (!(b = avahi_new(AvahiSServiceBrowser, 1))) {
avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
return NULL;
}
-
+
b->server = server;
b->domain_name = b->service_type = NULL;
b->callback = callback;
b->userdata = userdata;
b->record_browser = NULL;
-
+
AVAHI_LLIST_PREPEND(AvahiSServiceBrowser, browser, server->service_browsers, b);
if (!(b->domain_name = avahi_normalize_name_strdup(domain)) ||
avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
if (!(k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR))) {
avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
if (!(b->record_browser = avahi_s_record_browser_new(server, interface, protocol, k, flags, record_browser_callback, b)))
goto fail;
if (k)
avahi_key_unref(k);
-
+
avahi_s_service_browser_free(b);
return NULL;
}
if (b->record_browser)
avahi_s_record_browser_free(b->record_browser);
-
+
avahi_free(b->domain_name);
avahi_free(b->service_type);
avahi_free(b);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
struct AvahiSRBLookup {
AvahiSRecordBrowser *record_browser;
-
+
unsigned ref;
AvahiIfIndex interface;
AvahiProtocol protocol;
AvahiLookupFlags flags;
-
+
AvahiKey *key;
AvahiWideAreaLookup *wide_area;
AvahiMulticastLookup *multicast;
AvahiRList *cname_lookups;
-
+
AVAHI_LLIST_FIELDS(AvahiSRBLookup, lookups);
};
AvahiKey *key) {
AvahiSRBLookup *l;
-
+
assert(b);
assert(AVAHI_IF_VALID(interface));
assert(AVAHI_PROTO_VALID(protocol));
if (b->n_lookups >= AVAHI_LOOKUPS_PER_BROWSER_MAX)
/* We don't like cyclic CNAMEs */
return NULL;
-
+
if (!(l = avahi_new(AvahiSRBLookup, 1)))
return NULL;
-
+
l->ref = 1;
l->record_browser = b;
l->interface = interface;
l->flags = flags;
transport_flags_from_domain(b->server, &l->flags, key->name);
-
+
AVAHI_LLIST_PREPEND(AvahiSRBLookup, lookups, b->lookups, l);
b->n_lookups ++;
-
+
return l;
}
avahi_wide_area_lookup_free(l->wide_area);
l->wide_area = NULL;
}
-
+
if (l->multicast) {
avahi_multicast_lookup_free(l->multicast);
l->multicast = NULL;
lookup_unref(l->cname_lookups->data);
l->cname_lookups = avahi_rlist_remove_by_link(l->cname_lookups, l->cname_lookups);
}
-
+
avahi_key_unref(l->key);
avahi_free(l);
}
AvahiProtocol protocol,
AvahiLookupFlags flags,
AvahiKey *key) {
-
+
AvahiSRBLookup *l;
-
+
assert(b);
for (l = b->lookups; l; l = l->lookups_next) {
AvahiLookupResultFlags flags,
AvahiRecord *r,
void *userdata) {
-
+
AvahiSRBLookup *l = userdata;
AvahiSRecordBrowser *b;
return;
lookup_ref(l);
-
+
switch (event) {
case AVAHI_BROWSER_NEW:
assert(r);
-
+
if (r->key->clazz == AVAHI_DNS_CLASS_IN &&
r->key->type == AVAHI_DNS_TYPE_CNAME)
/* It's a CNAME record, so let's follow it. We only follow it on wide area DNS! */
AvahiSRBLookup *l = userdata;
AvahiSRecordBrowser *b;
-
+
assert(e);
assert(l);
return;
lookup_ref(l);
-
+
switch (event) {
case AVAHI_BROWSER_NEW:
assert(r);
-
+
if (r->key->clazz == AVAHI_DNS_CLASS_IN &&
r->key->type == AVAHI_DNS_TYPE_CNAME)
/* It's a CNAME record, so let's follow it. We allow browsing on both multicast and wide area. */
if (avahi_server_is_record_local(b->server, interface, protocol, r))
flags |= AVAHI_LOOKUP_RESULT_LOCAL;
-
+
b->callback(b, interface, protocol, event, r, flags, b->userdata);
}
break;
assert(!(l->flags & AVAHI_LOOKUP_USE_WIDE_AREA) != !(l->flags & AVAHI_LOOKUP_USE_MULTICAST));
assert(!l->wide_area && !l->multicast);
-
+
if (l->flags & AVAHI_LOOKUP_USE_WIDE_AREA) {
if (!(l->wide_area = avahi_wide_area_lookup_new(l->record_browser->server->wide_area_lookup_engine, l->key, lookup_wide_area_callback, l)))
return -1;
-
+
} else {
assert(l->flags & AVAHI_LOOKUP_USE_MULTICAST);
static int lookup_scan_cache(AvahiSRBLookup *l) {
int n = 0;
-
+
assert(l);
assert(!(l->flags & AVAHI_LOOKUP_USE_WIDE_AREA) != !(l->flags & AVAHI_LOOKUP_USE_MULTICAST));
-
+
if (l->flags & AVAHI_LOOKUP_USE_WIDE_AREA) {
n = (int) avahi_wide_area_scan_cache(l->record_browser->server->wide_area_lookup_engine, l->key, lookup_wide_area_callback, l);
-
+
} else {
assert(l->flags & AVAHI_LOOKUP_USE_MULTICAST);
n = (int) avahi_multicast_lookup_engine_scan_cache(l->record_browser->server->multicast_lookup_engine, l->interface, l->protocol, l->key, lookup_multicast_callback, l);
static AvahiSRBLookup* lookup_add(AvahiSRecordBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiLookupFlags flags, AvahiKey *key) {
AvahiSRBLookup *l;
-
+
assert(b);
assert(!b->dead);
if (l->record_browser->dead)
return 0;
-
+
lookup_ref(l);
-
+
/* Browse the cache for the root request */
n = lookup_scan_cache(l);
if ((l->flags & AVAHI_LOOKUP_USE_MULTICAST) || n == 0)
/* We do no start a query if the cache contained entries and we're on wide area */
-
+
if (lookup_start(l) < 0)
n = -1;
}
static void lookup_handle_cname(AvahiSRBLookup *l, AvahiIfIndex interface, AvahiProtocol protocol, AvahiLookupFlags flags, AvahiRecord *r) {
AvahiKey *k;
AvahiSRBLookup *n;
-
+
assert(l);
assert(r);
assert(r->key->type == AVAHI_DNS_TYPE_CNAME);
k = avahi_key_new(r->data.ptr.name, l->record_browser->key->clazz, l->record_browser->key->type);
- n = lookup_add(l->record_browser, interface, protocol, flags, k);
+ n = lookup_add(l->record_browser, interface, protocol, flags, k);
avahi_key_unref(k);
if (!n) {
avahi_key_equal(n->key, k))
break;
}
-
+
avahi_key_unref(k);
if (rl) {
b, b->interface, b->protocol, AVAHI_BROWSER_FAILURE, NULL,
b->flags & AVAHI_LOOKUP_USE_WIDE_AREA ? AVAHI_LOOKUP_RESULT_WIDE_AREA : AVAHI_LOOKUP_RESULT_MULTICAST,
b->userdata);
-
+
browser_cancel(b);
return;
}
-
+
/* Tell the client that we're done with the cache */
b->callback(
b, b->interface, b->protocol, AVAHI_BROWSER_CACHE_EXHAUSTED, NULL,
/* If we do wide area lookups and the the cache contained
* entries, we assume that it is complete, and tell the user
* so by firing ALL_FOR_NOW. */
-
+
b->callback(b, b->interface, b->protocol, AVAHI_BROWSER_ALL_FOR_NOW, NULL, AVAHI_LOOKUP_RESULT_WIDE_AREA, b->userdata);
}
}
AvahiLookupFlags flags,
AvahiSRecordBrowserCallback callback,
void* userdata) {
-
+
AvahiSRecordBrowser *b;
assert(server);
AVAHI_CHECK_VALIDITY_RETURN_NULL(server, !avahi_key_is_pattern(key), AVAHI_ERR_IS_PATTERN);
AVAHI_CHECK_VALIDITY_RETURN_NULL(server, avahi_key_is_valid(key), AVAHI_ERR_INVALID_KEY);
AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST), AVAHI_ERR_INVALID_FLAGS);
- AVAHI_CHECK_VALIDITY_RETURN_NULL(server, !(flags & AVAHI_LOOKUP_USE_WIDE_AREA) || !(flags & AVAHI_LOOKUP_USE_MULTICAST), AVAHI_ERR_INVALID_FLAGS);
-
+ AVAHI_CHECK_VALIDITY_RETURN_NULL(server, !(flags & AVAHI_LOOKUP_USE_WIDE_AREA) || !(flags & AVAHI_LOOKUP_USE_MULTICAST), AVAHI_ERR_INVALID_FLAGS);
+
if (!(b = avahi_new(AvahiSRecordBrowser, 1))) {
avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
return NULL;
}
-
+
b->dead = 0;
b->server = server;
b->interface = interface;
b->n_lookups = 0;
AVAHI_LLIST_HEAD_INIT(AvahiSRBLookup, b->lookups);
b->root_lookup = NULL;
-
+
AVAHI_LLIST_PREPEND(AvahiSRecordBrowser, browser, server->record_browsers, b);
/* The currently cached entries are scanned a bit later, and than we will start querying, too */
b->defer_time_event = avahi_time_event_new(server->time_event_queue, NULL, defer_callback, b);
assert(b->defer_time_event);
-
+
return b;
}
assert(b);
browser_cancel(b);
-
+
AVAHI_LLIST_REMOVE(AvahiSRecordBrowser, browser, b->server->record_browsers, b);
avahi_key_unref(b->key);
-
+
avahi_free(b);
}
void avahi_browser_cleanup(AvahiServer *server) {
AvahiSRecordBrowser *b;
AvahiSRecordBrowser *n;
-
+
assert(server);
while (server->need_browser_cleanup) {
server->need_browser_cleanup = 0;
-
+
for (b = server->record_browsers; b; b = n) {
n = b->browser_next;
-
+
if (b->dead)
avahi_s_record_browser_destroy(b);
}
- }
+ }
if (server->wide_area_lookup_engine)
avahi_wide_area_cleanup(server->wide_area_lookup_engine);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AvahiIfIndex interface;
AvahiProtocol protocol;
AvahiLookupFlags flags;
-
+
AvahiTimeEvent *defer_time_event;
AvahiSRecordBrowserCallback callback;
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/* Remove from linked list */
AVAHI_LLIST_REMOVE(AvahiCacheEntry, entry, c->entries, e);
-
+
if (e->time_event)
avahi_time_event_free(e->time_event);
avahi_multicast_lookup_engine_notify(c->server->multicast_lookup_engine, c->interface, e->record, AVAHI_BROWSER_REMOVE);
-
+
avahi_record_unref(e->record);
-
+
avahi_free(e);
assert(c->n_entries >= 1);
avahi_log_error(__FILE__": Out of memory.");
return NULL; /* OOM */
}
-
+
c->server = server;
c->interface = iface;
c->n_entries = 0;
c->last_rand_timestamp = 0;
-
+
return c;
}
while (c->entries)
remove_entry(c, c->entries);
assert(c->n_entries == 0);
-
+
avahi_hashmap_free(c->hashmap);
-
+
avahi_free(c);
}
assert(k);
assert(!avahi_key_is_pattern(k));
-
+
return avahi_hashmap_lookup(c->hashmap, k);
}
void* avahi_cache_walk(AvahiCache *c, AvahiKey *pattern, AvahiCacheWalkCallback cb, void* userdata) {
void* ret;
-
+
assert(c);
assert(pattern);
assert(cb);
-
+
if (avahi_key_is_pattern(pattern)) {
AvahiCacheEntry *e, *n;
-
+
for (e = c->entries; e; e = n) {
n = e->entry_next;
-
+
if (avahi_key_pattern_match(pattern, e->record->key))
if ((ret = cb(c, pattern, e, userdata)))
return ret;
}
-
+
} else {
AvahiCacheEntry *e, *n;
for (e = lookup_key(c, pattern); e; e = n) {
n = e->by_key_next;
-
+
if ((ret = cb(c, pattern, e, userdata)))
return ret;
}
AvahiCacheEntry *e = userdata;
/* char *txt; */
unsigned percent = 0;
-
+
assert(t);
assert(e);
case AVAHI_CACHE_REPLACE_FINAL:
remove_entry(e->cache, e);
-
+
e = NULL;
/* avahi_log_debug("Removing entry from cache due to expiration (%s)", txt); */
break;
-
+
case AVAHI_CACHE_VALID:
case AVAHI_CACHE_POOF:
e->state = AVAHI_CACHE_EXPIRY1;
percent = 85;
break;
-
+
case AVAHI_CACHE_EXPIRY1:
e->state = AVAHI_CACHE_EXPIRY2;
percent = 90;
e->state = AVAHI_CACHE_EXPIRY3;
percent = 95;
break;
-
+
case AVAHI_CACHE_EXPIRY3:
e->state = AVAHI_CACHE_EXPIRY_FINAL;
percent = 100;
/* Request a cache update if we are subscribed to this entry */
if (avahi_querier_shall_refresh_cache(e->cache->interface, e->record->key))
avahi_interface_post_query(e->cache->interface, e->record->key, 0, NULL);
-
+
/* Check again later */
next_expiry(e->cache, e, percent);
-
+
}
/* avahi_free(txt); */
static void update_time_event(AvahiCache *c, AvahiCacheEntry *e) {
assert(c);
assert(e);
-
+
if (e->time_event)
avahi_time_event_update(e->time_event, &e->expiry);
else
static void next_expiry(AvahiCache *c, AvahiCacheEntry *e, unsigned percent) {
AvahiUsec usec, left, right;
time_t now;
-
+
assert(c);
assert(e);
assert(percent > 0 && percent <= 100);
-
+
usec = (AvahiUsec) e->record->ttl * 10000;
left = usec * percent;
}
usec = left + (AvahiUsec) ((double) (right-left) * c->last_rand / (RAND_MAX+1.0));
-
+
e->expiry = e->timestamp;
avahi_timeval_add(&e->expiry, usec);
-
+
/* g_message("wake up in +%lu seconds", e->expiry.tv_sec - e->timestamp.tv_sec); */
-
+
update_time_event(c, e);
}
static void expire_in_one_second(AvahiCache *c, AvahiCacheEntry *e, AvahiCacheEntryState state) {
assert(c);
assert(e);
-
+
e->state = state;
gettimeofday(&e->expiry, NULL);
avahi_timeval_add(&e->expiry, 1000000); /* 1s */
void avahi_cache_update(AvahiCache *c, AvahiRecord *r, int cache_flush, const AvahiAddress *a) {
/* char *txt; */
-
+
assert(c);
assert(r && r->ref >= 1);
/* This is an update request */
if ((first = lookup_key(c, r->key))) {
-
+
if (cache_flush) {
/* For unique entries drop all entries older than one second */
expire_in_one_second(c, e, AVAHI_CACHE_REPLACE_FINAL);
}
}
-
+
/* Look for exactly the same entry */
for (e = first; e; e = e->by_key_next)
if (avahi_record_equal_no_ttl(e->record, r))
break;
}
-
+
if (e) {
-
+
/* avahi_log_debug("found matching cache entry"); */
/* We need to update the hash table key if we replace the
* record */
if (e->by_key_prev == NULL)
avahi_hashmap_replace(c->hashmap, r->key, e);
-
+
/* Update the record */
avahi_record_unref(e->record);
e->record = avahi_record_ref(r);
/* avahi_log_debug("cache: updating %s", txt); */
-
+
} else {
/* No entry found, therefore we create a new one */
-
+
/* avahi_log_debug("cache: couldn't find matching cache entry for %s", txt); */
if (c->n_entries >= AVAHI_CACHE_ENTRIES_MAX)
/* Notify subscribers */
avahi_multicast_lookup_engine_notify(c->server->multicast_lookup_engine, c->interface, e->record, AVAHI_BROWSER_NEW);
- }
-
+ }
+
e->origin = *a;
e->timestamp = now;
next_expiry(c, e, 80);
if (!(t = avahi_record_to_string(e->record)))
continue; /* OOM */
-
+
dump_data->callback(t, dump_data->userdata);
avahi_free(t);
}
int avahi_cache_entry_half_ttl(AvahiCache *c, AvahiCacheEntry *e) {
struct timeval now;
unsigned age;
-
+
assert(c);
assert(e);
age = (unsigned) (avahi_timeval_diff(&now, &e->timestamp)/1000000);
/* avahi_log_debug("age: %lli, ttl/2: %u", age, e->record->ttl); */
-
+
return age >= e->record->ttl/2;
}
default:
;
}
-
+
return NULL;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
struct timeval expiry;
int cache_flush;
int poof_num;
-
+
AvahiAddress origin;
AvahiCacheEntryState state;
struct AvahiCache {
AvahiServer *server;
-
+
AvahiInterface *interface;
-
+
AvahiHashmap *hashmap;
AVAHI_LLIST_HEAD(AvahiCacheEntry, entries);
* records of the specified key. The specified address is */
void avahi_cache_start_poof(AvahiCache *c, AvahiKey *key, const AvahiAddress *a);
-/* Stop a previously started POOF algorithm for a record. (Used for response suppresions records */
+/* Stop a previously started POOF algorithm for a record. (Used for response suppresions records */
void avahi_cache_stop_poof(AvahiCache *c, AvahiRecord *record, const AvahiAddress *a);
void avahi_cache_flush(AvahiCache *c);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
static void dump_timeout_callback(AvahiTimeout *timeout, AVAHI_GCC_UNUSED void* userdata) {
struct timeval tv;
-
+
avahi_server_dump(avahi, dump_line, NULL);
avahi_elapse_time(&tv, 5000, 0);
avahi_s_entry_group_reset(group);
else
group = avahi_s_entry_group_new(avahi, entry_group_callback, NULL);
-
- avahi_server_add_service(avahi, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, "_http._tcp", NULL, NULL, 80, "foo", NULL);
+
+ avahi_server_add_service(avahi, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, "_http._tcp", NULL, NULL, 80, "foo", NULL);
avahi_s_entry_group_commit(group);
try++;
static void rename_timeout_callback(AvahiTimeout *timeout, AVAHI_GCC_UNUSED void *userdata) {
struct timeval tv;
-
- if (access("flag", F_OK) == 0) {
+
+ if (access("flag", F_OK) == 0) {
create_service("New - Bonjour Service Name");
return;
}
avahi_server_dump(avahi, dump_line, NULL);
} else if (state == AVAHI_SERVER_COLLISION) {
char *n;
-
+
n = avahi_alternative_host_name(avahi_server_get_host_name(s));
avahi_log_warn("Host name conflict, retrying with <%s>", n);
avahi_server_set_host_name(s, n);
/* Evil, but the conformace test requires that*/
create_service("gurke");
-
+
avahi_simple_poll_loop(simple_poll);
-
+
if (group)
- avahi_s_entry_group_free(group);
+ avahi_s_entry_group_free(group);
avahi_server_free(avahi);
avahi_simple_poll_free(simple_poll);
-
+
return 0;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AvahiProtocol protocol,
const char *domain,
AvahiDNSServerType type,
- AvahiProtocol aprotocol, /**< Address protocol for the DNS server */
+ AvahiProtocol aprotocol, /**< Address protocol for the DNS server */
AvahiLookupFlags flags, /**< Lookup flags. */
AvahiSDNSServerBrowserCallback callback,
void* userdata);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
assert(avahi_dns_packet_consume_name(p, t, sizeof(t)) == 0);
avahi_log_debug(">%s<", t);
assert(avahi_domain_equal(a, t));
-
+
assert(avahi_dns_packet_consume_name(p, t, sizeof(t)) == 0);
avahi_log_debug(">%s<", t);
assert(avahi_domain_equal(b, t));
assert(avahi_dns_packet_consume_name(p, t, sizeof(t)) == 0);
avahi_log_debug(">%s<", t);
assert(avahi_domain_equal(d, t));
-
+
avahi_dns_packet_free(p);
/* RDATA PARSING AND SERIALIZATION */
-
+
/* Create an AvahiRecord with some usful data */
r = avahi_record_new_full("foobar.local", AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_HINFO, AVAHI_DEFAULT_TTL);
assert(r);
avahi_free(m);
avahi_record_unref(r);
-
+
return 0;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
if (max_size < AVAHI_DNS_PACKET_HEADER_SIZE)
max_size = AVAHI_DNS_PACKET_HEADER_SIZE;
-
+
if (!(p = avahi_malloc(sizeof(AvahiDnsPacket) + max_size)))
return p;
-
+
p->size = p->rindex = AVAHI_DNS_PACKET_HEADER_SIZE;
p->max_size = max_size;
p->name_table = NULL;
if (!(p = avahi_dns_packet_new(mtu)))
return NULL;
-
+
avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_FLAGS, AVAHI_DNS_FLAGS(0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
return p;
}
if (!(p = avahi_dns_packet_new(mtu)))
return NULL;
-
+
avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_FLAGS, AVAHI_DNS_FLAGS(1, 0, aa, 0, 0, 0, 0, 0, 0, 0));
return p;
}
saved_rindex = p->rindex;
p->rindex = AVAHI_DNS_PACKET_HEADER_SIZE;
-
+
for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_QDCOUNT); n > 0; n--) {
AvahiKey *k;
int unicast_response;
(avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_FLAGS) & AVAHI_DNS_FLAG_OPCODE));
return r;
-}
+}
void avahi_dns_packet_free(AvahiDnsPacket *p) {
if (p->name_table)
avahi_hashmap_free(p->name_table);
-
+
avahi_free(p);
}
void avahi_dns_packet_set_field(AvahiDnsPacket *p, unsigned idx, uint16_t v) {
assert(p);
assert(idx < AVAHI_DNS_PACKET_HEADER_SIZE);
-
+
((uint16_t*) AVAHI_DNS_PACKET_DATA(p))[idx] = htons(v);
}
assert(idx < AVAHI_DNS_PACKET_HEADER_SIZE);
avahi_dns_packet_set_field(p, idx, avahi_dns_packet_get_field(p, idx) + 1);
-}
+}
static void name_table_cleanup(void *key, void *value, void *user_data) {
AvahiDnsPacket *p = user_data;
-
+
if ((uint8_t*) value >= AVAHI_DNS_PACKET_DATA(p) + p->size)
avahi_hashmap_remove(p->name_table, key);
}
uint8_t* avahi_dns_packet_append_name(AvahiDnsPacket *p, const char *name) {
uint8_t *d, *saved_ptr = NULL;
size_t saved_size;
-
+
assert(p);
assert(name);
saved_size = p->size;
saved_ptr = avahi_dns_packet_extend(p, 0);
-
+
while (*name) {
uint8_t* prev;
const char *pname;
char label[64], *u;
-
+
/* Check whether we can compress this name. */
if (p->name_table && (prev = avahi_hashmap_lookup(p->name_table, name))) {
unsigned idx;
-
+
assert(prev >= AVAHI_DNS_PACKET_DATA(p));
idx = (unsigned) (prev - AVAHI_DNS_PACKET_DATA(p));
}
pname = name;
-
+
if (!(avahi_unescape_label(&name, label, sizeof(label))))
goto fail;
if (!(d = avahi_dns_packet_extend(p, 1)))
goto fail;
-
+
*d = 0;
return saved_ptr;
uint8_t* avahi_dns_packet_append_uint16(AvahiDnsPacket *p, uint16_t v) {
uint8_t *d;
assert(p);
-
+
if (!(d = avahi_dns_packet_extend(p, sizeof(uint16_t))))
return NULL;
-
+
d[0] = (uint8_t) (v >> 8);
d[1] = (uint8_t) v;
return d;
if (!(d = avahi_dns_packet_extend(p, sizeof(uint32_t))))
return NULL;
-
+
d[0] = (uint8_t) (v >> 24);
d[1] = (uint8_t) (v >> 16);
d[2] = (uint8_t) (v >> 8);
uint8_t* avahi_dns_packet_append_string(AvahiDnsPacket *p, const char *s) {
uint8_t* d;
size_t k;
-
+
assert(p);
assert(s);
if ((k = strlen(s)) >= 255)
k = 255;
-
+
if (!(d = avahi_dns_packet_extend(p, k+1)))
return NULL;
uint8_t *avahi_dns_packet_extend(AvahiDnsPacket *p, size_t l) {
uint8_t *d;
-
+
assert(p);
if (p->size+l > p->max_size)
return NULL;
-
+
d = AVAHI_DNS_PACKET_DATA(p) + p->size;
p->size += l;
-
+
return d;
}
return -1;
flags = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_FLAGS);
-
+
if (flags & AVAHI_DNS_FLAG_OPCODE)
return -1;
if (avahi_dns_packet_check_valid(p) < 0)
return -1;
-
+
flags = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_FLAGS);
-
+
if (flags & AVAHI_DNS_FLAG_RCODE)
return -1;
int avahi_dns_packet_is_query(AvahiDnsPacket *p) {
assert(p);
-
+
return !(avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_FLAGS) & AVAHI_DNS_FLAG_QR);
}
unsigned label_ptr;
int i;
assert(p && ret_name && l);
-
+
for (i = 0; i < AVAHI_DNS_LABELS_MAX; i++) {
uint8_t n;
if (l < 1)
return -1;
*ret_name = 0;
-
+
return ret;
-
+
} else if (n <= 63) {
/* Uncompressed label */
idx++;
if (!compressed)
ret++;
-
+
if (idx + n > p->size)
return -1;
return -1;
idx += n;
-
+
if (!compressed)
ret += n;
} else if ((n & 0xC0) == 0xC0) {
if (!compressed)
ret += 2;
-
+
compressed = 1;
} else
return -1;
int avahi_dns_packet_consume_name(AvahiDnsPacket *p, char *ret_name, size_t l) {
int r;
-
+
if ((r = consume_labels(p, p->rindex, ret_name, l)) < 0)
return -1;
d = (uint8_t*) (AVAHI_DNS_PACKET_DATA(p) + p->rindex);
*ret_v = (d[0] << 24) | (d[1] << 16) | (d[2] << 8) | d[3];
p->rindex += sizeof(uint32_t);
-
+
return 0;
}
assert(p);
assert(ret_data);
assert(l > 0);
-
+
if (p->rindex + l > p->size)
return -1;
int avahi_dns_packet_consume_string(AvahiDnsPacket *p, char *ret_string, size_t l) {
size_t k;
-
+
assert(p);
assert(ret_string);
assert(l > 0);
memcpy(ret_string, AVAHI_DNS_PACKET_DATA(p)+p->rindex+1, l-1);
ret_string[l-1] = 0;
-
+
p->rindex += 1+k;
return 0;
const void* avahi_dns_packet_get_rptr(AvahiDnsPacket *p) {
assert(p);
-
+
if (p->rindex > p->size)
return NULL;
static int parse_rdata(AvahiDnsPacket *p, AvahiRecord *r, uint16_t rdlength) {
char buf[AVAHI_DOMAIN_NAME_MAX];
const void* start;
-
+
assert(p);
assert(r);
start = avahi_dns_packet_get_rptr(p);
-
+
switch (r->key->type) {
case AVAHI_DNS_TYPE_PTR:
case AVAHI_DNS_TYPE_CNAME:
case AVAHI_DNS_TYPE_NS:
-
+
if (avahi_dns_packet_consume_name(p, buf, sizeof(buf)) < 0)
return -1;
r->data.ptr.name = avahi_strdup(buf);
break;
-
+
case AVAHI_DNS_TYPE_SRV:
-
+
if (avahi_dns_packet_consume_uint16(p, &r->data.srv.priority) < 0 ||
avahi_dns_packet_consume_uint16(p, &r->data.srv.weight) < 0 ||
avahi_dns_packet_consume_uint16(p, &r->data.srv.port) < 0 ||
avahi_dns_packet_consume_name(p, buf, sizeof(buf)) < 0)
return -1;
-
+
r->data.srv.name = avahi_strdup(buf);
break;
if (avahi_dns_packet_consume_string(p, buf, sizeof(buf)) < 0)
return -1;
-
+
r->data.hinfo.cpu = avahi_strdup(buf);
-
+
if (avahi_dns_packet_consume_string(p, buf, sizeof(buf)) < 0)
return -1;
-
+
r->data.hinfo.os = avahi_strdup(buf);
break;
if (rdlength > 0) {
if (avahi_string_list_parse(avahi_dns_packet_get_rptr(p), rdlength, &r->data.txt.string_list) < 0)
return -1;
-
+
if (avahi_dns_packet_skip(p, rdlength) < 0)
return -1;
} else
r->data.txt.string_list = NULL;
-
+
break;
case AVAHI_DNS_TYPE_A:
if (avahi_dns_packet_consume_bytes(p, &r->data.a.address, sizeof(AvahiIPv4Address)) < 0)
return -1;
-
+
break;
case AVAHI_DNS_TYPE_AAAA:
/* avahi_log_debug("aaaa"); */
-
+
if (avahi_dns_packet_consume_bytes(p, &r->data.aaaa.address, sizeof(AvahiIPv6Address)) < 0)
return -1;
-
+
break;
-
+
default:
/* avahi_log_debug("generic"); */
-
+
if (rdlength > 0) {
r->data.generic.data = avahi_memdup(avahi_dns_packet_get_rptr(p), rdlength);
- r->data.generic.size = rdlength;
-
+ r->data.generic.size = rdlength;
+
if (avahi_dns_packet_skip(p, rdlength) < 0)
return -1;
}
/* Check if we read enough data */
if ((const uint8_t*) avahi_dns_packet_get_rptr(p) - (const uint8_t*) start != rdlength)
return -1;
-
+
return 0;
}
if (ret_cache_flush)
*ret_cache_flush = !!(class & AVAHI_DNS_CACHE_FLUSH);
class &= ~AVAHI_DNS_CACHE_FLUSH;
-
+
if (!(r = avahi_record_new_full(name, class, type, ttl)))
goto fail;
-
+
if (parse_rdata(p, r, rdlength) < 0)
goto fail;
if (!avahi_record_is_valid(r))
goto fail;
-
+
return r;
fail:
*ret_unicast_response = !!(class & AVAHI_DNS_UNICAST_RESPONSE);
class &= ~AVAHI_DNS_UNICAST_RESPONSE;
-
+
if (!(k = avahi_key_new(name, class, type)))
return NULL;
uint8_t* avahi_dns_packet_append_key(AvahiDnsPacket *p, AvahiKey *k, int unicast_response) {
uint8_t *t;
size_t size;
-
+
assert(p);
assert(k);
size = p->size;
-
+
if (!(t = avahi_dns_packet_append_name(p, k->name)) ||
!avahi_dns_packet_append_uint16(p, k->type) ||
!avahi_dns_packet_append_uint16(p, k->clazz | (unicast_response ? AVAHI_DNS_UNICAST_RESPONSE : 0))) {
static int append_rdata(AvahiDnsPacket *p, AvahiRecord *r) {
assert(p);
assert(r);
-
+
switch (r->key->type) {
-
+
case AVAHI_DNS_TYPE_PTR:
case AVAHI_DNS_TYPE_CNAME:
case AVAHI_DNS_TYPE_NS:
-
+
if (!(avahi_dns_packet_append_name(p, r->data.ptr.name)))
return -1;
-
+
break;
case AVAHI_DNS_TYPE_SRV:
if (!avahi_dns_packet_append_bytes(p, &r->data.a.address, sizeof(r->data.a.address)))
return -1;
-
+
break;
case AVAHI_DNS_TYPE_AAAA:
-
+
if (!avahi_dns_packet_append_bytes(p, &r->data.aaaa.address, sizeof(r->data.aaaa.address)))
return -1;
-
+
break;
-
+
default:
if (r->data.generic.size)
if (append_rdata(p, r) < 0)
goto fail;
-
+
size = avahi_dns_packet_extend(p, 0) - start;
assert(size <= AVAHI_DNS_RDATA_MAX);
l[0] = (uint8_t) ((uint16_t) size >> 8);
l[1] = (uint8_t) ((uint16_t) size);
-
+
return t;
assert(p);
assert(p->size <= p->max_size);
-
+
return p->max_size - p->size;
}
int avahi_rdata_parse(AvahiRecord *record, const void* rdata, size_t size) {
int ret;
AvahiDnsPacket p;
-
+
assert(record);
assert(rdata);
-
+
p.data = (void*) rdata;
p.max_size = p.size = size;
p.rindex = 0;
ret = parse_rdata(&p, record, size);
assert(!p.name_table);
-
+
return ret;
}
size_t avahi_rdata_serialize(AvahiRecord *record, void *rdata, size_t max_size) {
int ret;
AvahiDnsPacket p;
-
+
assert(record);
assert(rdata);
assert(max_size > 0);
if (ret < 0)
return (size_t) -1;
-
+
return p.size;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
char *p, *d;
s[strcspn(s, ".")] = 0;
-
- for (p = s, d = s; *p; p++)
+
+ for (p = s, d = s; *p; p++)
if ((*p >= 'a' && *p <= 'z') ||
(*p >= 'A' && *p <= 'Z') ||
(*p >= '0' && *p <= '9') ||
#ifdef __linux__
static int load_lsb_distrib_id(char *ret_s, size_t size) {
FILE *f;
-
+
assert(ret_s);
assert(size > 0);
*ret_s = 0;
avahi_log_warn("System host name is set to 'localhost'. This is not a suitable mDNS host name, looking for alternatives.");
}
-
+
if (*ret_s == 0) {
/* No hostname was set, so let's take the OS name */
{
/* Try uname() second */
struct utsname utsname;
-
+
if (uname(&utsname) >= 0) {
snprintf(ret_s, size, "%s", utsname.sysname);
strip_bad_chars(ret_s);
}
if (size >= AVAHI_LABEL_MAX)
- ret_s[AVAHI_LABEL_MAX-1] = 0;
-
+ ret_s[AVAHI_LABEL_MAX-1] = 0;
+
return ret_s;
}
if ((r = strcmp(ca, cb)))
return r;
-
+
if (!*a && !*b)
return 0;
}
if (*domain == 0)
return 0;
-
+
if (avahi_domain_equal(domain, suffix))
return 1;
r = avahi_unescape_label(&domain, dummy, sizeof(dummy));
assert(r);
- }
+ }
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AVAHI_C_DECL_BEGIN
/** Return the local host name. */
-char *avahi_get_host_name(char *ret_s, size_t size);
+char *avahi_get_host_name(char *ret_s, size_t size);
/** Return the local host name. avahi_free() the result! */
char *avahi_get_host_name_strdup(void);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
if (g->register_time_event)
avahi_time_event_free(g->register_time_event);
-
+
AVAHI_LLIST_REMOVE(AvahiSEntryGroup, groups, s->groups, g);
avahi_free(g);
}
if (s->need_group_cleanup) {
AvahiSEntryGroup *g, *next;
-
+
for (g = s->groups; g; g = next) {
next = g->groups_next;
-
+
if (g->dead)
avahi_entry_group_free(s, g);
}
if (s->need_entry_cleanup) {
AvahiEntry *e, *next;
-
+
for (e = s->entries; e; e = next) {
next = e->entries_next;
-
+
if (e->dead)
avahi_entry_free(s, e);
}
static int check_record_conflict(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, AvahiRecord *r, AvahiPublishFlags flags) {
AvahiEntry *e;
-
+
assert(s);
assert(r);
if (!(flags & AVAHI_PUBLISH_UNIQUE) && !(e->flags & AVAHI_PUBLISH_UNIQUE))
continue;
-
+
if ((flags & AVAHI_PUBLISH_ALLOW_MULTIPLE) && (e->flags & AVAHI_PUBLISH_ALLOW_MULTIPLE) )
continue;
AvahiRecord *r) {
AvahiEntry *e;
-
+
assert(s);
assert(r);
!g ||
(g->state != AVAHI_ENTRY_GROUP_ESTABLISHED && g->state != AVAHI_ENTRY_GROUP_REGISTERING) ||
(flags & AVAHI_PUBLISH_UPDATE), AVAHI_ERR_BAD_STATE);
-
+
if (flags & AVAHI_PUBLISH_UPDATE) {
AvahiRecord *old_record;
int is_first = 1;
-
+
/* Update and existing record */
/* Find the first matching entry */
/* If we were the first entry in the list, we need to update the key */
if (is_first)
avahi_hashmap_replace(s->entries_by_key, e->record->key, e);
-
+
avahi_record_unref(old_record);
} else {
AvahiEntry *t;
/* Add a new record */
-
+
if (check_record_conflict(s, interface, protocol, r, flags) < 0) {
avahi_server_set_errno(s, AVAHI_ERR_COLLISION);
return NULL;
avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
return NULL;
}
-
+
e->server = s;
e->record = avahi_record_ref(r);
e->group = g;
e->protocol = protocol;
e->flags = flags;
e->dead = 0;
-
+
AVAHI_LLIST_HEAD_INIT(AvahiAnnouncer, e->announcers);
-
+
AVAHI_LLIST_PREPEND(AvahiEntry, entries, s->entries, e);
-
+
/* Insert into hash table indexed by name */
t = avahi_hashmap_lookup(s->entries_by_key, e->record->key);
AVAHI_LLIST_PREPEND(AvahiEntry, by_key, t, e);
avahi_hashmap_replace(s->entries_by_key, e->record->key, t);
-
+
/* Insert into group list */
if (g)
- AVAHI_LLIST_PREPEND(AvahiEntry, by_group, g->entries, e);
-
+ AVAHI_LLIST_PREPEND(AvahiEntry, by_group, g->entries, e);
+
avahi_announce_entry(s, e);
}
if (!*e)
*e = g ? g->entries : s->entries;
-
+
while (*e && (*e)->dead)
*e = g ? (*e)->by_group_next : (*e)->entries_next;
-
+
if (!*e)
return NULL;
int avahi_server_dump(AvahiServer *s, AvahiDumpCallback callback, void* userdata) {
AvahiEntry *e;
-
+
assert(s);
assert(callback);
if (e->dead)
continue;
-
+
if (!(t = avahi_record_to_string(e->record)))
return avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
-
+
snprintf(ln, sizeof(ln), "%s ; iface=%i proto=%i", t, e->interface, e->protocol);
avahi_free(t);
AvahiRecord *r;
AvahiEntry *e;
-
+
assert(s);
assert(dest);
avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
return NULL;
}
-
+
r->data.ptr.name = avahi_normalize_name_strdup(dest);
e = server_add_internal(s, g, interface, protocol, flags, r);
avahi_record_unref(r);
return e;
}
-
+
int avahi_server_add_ptr(
AvahiServer *s,
AvahiSEntryGroup *g,
int ret = AVAHI_OK;
AvahiEntry *entry = NULL, *reverse = NULL;
AvahiRecord *r;
-
+
assert(s);
assert(a);
AVAHI_CHECK_VALIDITY(s, !name || avahi_is_valid_fqdn(name), AVAHI_ERR_INVALID_HOST_NAME);
/* Prepare the host naem */
-
+
if (!name)
name = s->host_name_fqdn;
else {
transport_flags_from_domain(s, &flags, name);
AVAHI_CHECK_VALIDITY(s, flags & AVAHI_PUBLISH_USE_MULTICAST, AVAHI_ERR_NOT_SUPPORTED);
-
+
/* Create the A/AAAA record */
-
+
if (a->proto == AVAHI_PROTO_INET) {
if (!(r = avahi_record_new_full(name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_A, AVAHI_DEFAULT_TTL_HOST_NAME))) {
ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
goto finish;
}
-
+
r->data.a.address = a->data.ipv4;
-
+
} else {
assert(a->proto == AVAHI_PROTO_INET6);
-
+
if (!(r = avahi_record_new_full(name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_AAAA, AVAHI_DEFAULT_TTL_HOST_NAME))) {
ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
goto finish;
}
-
+
r->data.aaaa.address = a->data.ipv6;
}
-
+
entry = server_add_internal(s, g, interface, protocol, (flags & ~ AVAHI_PUBLISH_NO_REVERSE) | AVAHI_PUBLISH_UNIQUE | AVAHI_PUBLISH_ALLOW_MULTIPLE, r);
avahi_record_unref(r);
}
/* Create the reverse lookup entry */
-
+
if (!(flags & AVAHI_PUBLISH_NO_REVERSE)) {
char reverse_n[AVAHI_DOMAIN_NAME_MAX];
avahi_reverse_lookup_name(a, reverse_n, sizeof(reverse_n));
-
+
if (!(reverse = server_add_ptr_internal(s, g, interface, protocol, flags | AVAHI_PUBLISH_UNIQUE, AVAHI_DEFAULT_TTL_HOST_NAME, reverse_n, name))) {
ret = avahi_server_errno(s);
goto finish;
}
}
-
+
finish:
if (ret != AVAHI_OK && !(flags & AVAHI_PUBLISH_UPDATE)) {
AvahiRecord *r;
AvahiEntry *e;
-
+
assert(s);
if (!(r = avahi_record_new_full(name ? name : s->host_name_fqdn, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_TXT, ttl))) {
avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
return NULL;
}
-
+
r->data.txt.string_list = strlst;
e = server_add_internal(s, g, interface, protocol, flags, r);
avahi_record_unref(r);
AvahiRecord *r = NULL;
int ret = AVAHI_OK;
AvahiEntry *srv_entry = NULL, *txt_entry = NULL, *ptr_entry = NULL, *enum_entry = NULL;
-
+
assert(s);
assert(type);
assert(name);
transport_flags_from_domain(s, &flags, domain);
AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, flags & AVAHI_PUBLISH_USE_MULTICAST, AVAHI_ERR_NOT_SUPPORTED);
-
+
if (!(h = avahi_normalize_name_strdup(host))) {
ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
goto fail;
}
/* Add service enumeration PTR record */
-
+
if (!(ptr_entry = server_add_ptr_internal(s, g, interface, protocol, 0, AVAHI_DEFAULT_TTL, ptr_name, svc_name))) {
ret = avahi_server_errno(s);
goto fail;
}
/* Add SRV record */
-
+
if (!(r = avahi_record_new_full(svc_name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV, AVAHI_DEFAULT_TTL_HOST_NAME))) {
ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
goto fail;
}
-
+
r->data.srv.priority = 0;
r->data.srv.weight = 0;
r->data.srv.port = port;
if (!(flags & AVAHI_PUBLISH_NO_COOKIE))
strlst = add_magic_cookie(s, strlst);
-
+
txt_entry = server_add_txt_strlst_nocopy(s, g, interface, protocol, AVAHI_PUBLISH_UNIQUE, AVAHI_DEFAULT_TTL, svc_name, strlst);
strlst = NULL;
}
/* Add service type enumeration record */
-
+
if (!(enum_entry = server_add_ptr_internal(s, g, interface, protocol, 0, AVAHI_DEFAULT_TTL, enum_ptr, ptr_name))) {
ret = avahi_server_errno(s);
goto fail;
if (enum_entry)
avahi_entry_free(s, enum_entry);
}
-
+
avahi_string_list_free(strlst);
avahi_free(h);
-
+
return ret;
}
va_list va;
int ret;
-
+
va_start(va, port);
ret = server_add_service_strlst_nocopy(s, g, interface, protocol, flags, name, type, domain, host, port, avahi_string_list_new_va(va));
va_end(va);
-
+
return ret;
}
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiPublishFlags flags,
- const char *name,
- const char *type,
- const char *domain,
+ const char *name,
+ const char *type,
+ const char *domain,
AvahiStringList *strlst) {
char svc_name[AVAHI_DOMAIN_NAME_MAX];
int ret = AVAHI_OK;
AvahiEntry *e;
-
+
assert(s);
assert(type);
assert(name);
/* Add TXT record */
if (!(flags & AVAHI_PUBLISH_NO_COOKIE))
strlst = add_magic_cookie(s, strlst);
-
+
e = server_add_txt_strlst_nocopy(s, g, interface, protocol, AVAHI_PUBLISH_UNIQUE | AVAHI_PUBLISH_UPDATE, AVAHI_DEFAULT_TTL, svc_name, strlst);
strlst = NULL;
if (!e)
ret = avahi_server_errno(s);
-
+
fail:
-
+
avahi_string_list_free(strlst);
-
+
return ret;
}
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiPublishFlags flags,
- const char *name,
- const char *type,
- const char *domain,
+ const char *name,
+ const char *type,
+ const char *domain,
AvahiStringList *strlst) {
return server_update_service_txt_strlst_nocopy(s, g, interface, protocol, flags, name, type, domain, avahi_string_list_copy(strlst));
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiPublishFlags flags,
- const char *name,
- const char *type,
- const char *domain,
+ const char *name,
+ const char *type,
+ const char *domain,
...) {
va_list va;
int ret;
-
+
va_start(va, domain);
ret = server_update_service_txt_strlst_nocopy(s, g, interface, protocol, flags, name, type, domain, avahi_string_list_new_va(va));
va_end(va);
-
+
return ret;
}
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiPublishFlags flags,
- const char *name,
- const char *type,
- const char *domain,
+ const char *name,
+ const char *type,
+ const char *domain,
const char *subtype) {
int ret = AVAHI_OK;
char svc_name[AVAHI_DOMAIN_NAME_MAX], ptr_name[AVAHI_DOMAIN_NAME_MAX];
-
+
assert(name);
assert(type);
assert(subtype);
goto fail;
fail:
-
+
return ret;
}
k++;
pl--;
}
-
+
b = !b;
sl--;
AvahiEntry *e;
char t[AVAHI_DOMAIN_NAME_MAX], normalized_d[AVAHI_DOMAIN_NAME_MAX], *n;
-
+
AvahiRecord *r;
-
+
assert(s);
assert(name);
AVAHI_CHECK_VALIDITY_RETURN_NULL(s, port != 0, AVAHI_ERR_INVALID_PORT);
AVAHI_CHECK_VALIDITY_RETURN_NULL(s, avahi_is_valid_fqdn(name), AVAHI_ERR_INVALID_HOST_NAME);
AVAHI_CHECK_VALIDITY_RETURN_NULL(s, !domain || avahi_is_valid_domain_name(domain), AVAHI_ERR_INVALID_DOMAIN_NAME);
-
+
if (!domain)
domain = s->domain_name;
avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
return NULL;
}
-
+
AVAHI_ASSERT_TRUE(avahi_normalize_name(domain, normalized_d, sizeof(normalized_d)));
snprintf(t, sizeof(t), "%s.%s", type == AVAHI_DNS_SERVER_RESOLVE ? "_domain._udp" : "_dns-update._udp", normalized_d);
-
+
if (!(r = avahi_record_new_full(t, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV, AVAHI_DEFAULT_TTL_HOST_NAME))) {
avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
avahi_free(n);
return NULL;
}
-
+
r->data.srv.priority = 0;
r->data.srv.weight = 0;
r->data.srv.port = port;
transport_flags_from_domain(s, &flags, domain);
AVAHI_CHECK_VALIDITY(s, flags & AVAHI_PUBLISH_USE_MULTICAST, AVAHI_ERR_NOT_SUPPORTED);
-
+
if (address->proto == AVAHI_PROTO_INET) {
hexstring(h, sizeof(h), &address->data, sizeof(AvahiIPv4Address));
snprintf(n, sizeof(n), "ip-%s.%s", h, domain);
if (!r)
return avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
-
+
a_entry = server_add_internal(s, g, interface, protocol, AVAHI_PUBLISH_UNIQUE | AVAHI_PUBLISH_ALLOW_MULTIPLE, r);
avahi_record_unref(r);
if (!a_entry)
return avahi_server_errno(s);
-
+
if (!(s_entry = server_add_dns_server_name(s, g, interface, protocol, flags, domain, type, n, port))) {
if (!(flags & AVAHI_PUBLISH_UPDATE))
avahi_entry_free(s, a_entry);
/* If the entry group was established for a time longer then
* 5s, reset the establishment trial counter */
-
+
if (avahi_age(&g->established_at) > 5000000)
g->n_register_try = 0;
} else if (g->state == AVAHI_ENTRY_GROUP_REGISTERING) {
g->register_time_event = NULL;
}
}
-
+
if (state == AVAHI_ENTRY_GROUP_ESTABLISHED)
/* If the entry group is now established, remember the time
* this happened */
-
+
gettimeofday(&g->established_at, NULL);
-
+
g->state = state;
-
+
if (g->callback)
g->callback(g->server, g, state, g->userdata);
}
AvahiSEntryGroup *avahi_s_entry_group_new(AvahiServer *s, AvahiSEntryGroupCallback callback, void* userdata) {
AvahiSEntryGroup *g;
-
+
assert(s);
if (!(g = avahi_new(AvahiSEntryGroup, 1))) {
avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
return NULL;
}
-
+
g->server = s;
g->callback = callback;
g->userdata = userdata;
void avahi_s_entry_group_free(AvahiSEntryGroup *g) {
AvahiEntry *e;
-
+
assert(g);
assert(g->server);
}
g->dead = 1;
-
+
g->server->need_group_cleanup = 1;
g->server->need_entry_cleanup = 1;
avahi_time_event_free(g->register_time_event);
g->register_time_event = NULL;
-
+
/* Holdoff time passed, so let's start probing */
entry_group_commit_real(g);
}
int avahi_s_entry_group_commit(AvahiSEntryGroup *g) {
struct timeval now;
-
+
assert(g);
assert(!g->dead);
/* Holdoff time has not yet passed, so let's wait */
assert(!g->register_time_event);
g->register_time_event = avahi_time_event_new(g->server->time_event_queue, &g->register_time, entry_group_register_time_event_callback, g);
-
+
avahi_s_entry_group_change_state(g, AVAHI_ENTRY_GROUP_REGISTERING);
}
void avahi_s_entry_group_reset(AvahiSEntryGroup *g) {
AvahiEntry *e;
assert(g);
-
+
for (e = g->entries; e; e = e->by_group_next) {
if (!e->dead) {
avahi_goodbye_entry(g->server, e, 1, 1);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
int n;
assert(fd >= 0);
-
+
if ((n = fcntl(fd, F_GETFD)) < 0)
return -1;
int avahi_set_nonblock(int fd) {
int n;
-
+
assert(fd >= 0);
if ((n = fcntl(fd, F_GETFL)) < 0)
int avahi_wait_for_write(int fd) {
fd_set fds;
int r;
-
+
FD_ZERO(&fds);
FD_SET(fd, &fds);
-
+
if ((r = select(fd+1, NULL, &fds, NULL, NULL)) < 0)
return -1;
-
+
assert(r > 0);
return 0;
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
for (n = 0; n < 1000; n ++)
avahi_hashmap_insert(m, avahi_strdup_printf("key %u", n), avahi_strdup_printf("value %u", n));
-
+
printf("%s\n", (const char*) avahi_hashmap_lookup(m, "bla"));
avahi_hashmap_replace(m, avahi_strdup("bla"), avahi_strdup("#3"));
t = (const char*) avahi_hashmap_lookup(m, "bla");
printf("%s\n", t ? t : "(null)");
-
+
avahi_hashmap_free(m);
return 0;
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AvahiHashFunc hash_func;
AvahiEqualFunc equal_func;
AvahiFreeFunc key_free_func, value_free_func;
-
+
Entry *entries[HASH_MAP_SIZE];
AVAHI_LLIST_HEAD(Entry, entries_list);
};
Entry *e;
idx = m->hash_func(key) % HASH_MAP_SIZE;
-
+
for (e = m->entries[idx]; e; e = e->bucket_next)
if (m->equal_func(key, e->key))
return e;
AvahiHashmap* avahi_hashmap_new(AvahiHashFunc hash_func, AvahiEqualFunc equal_func, AvahiFreeFunc key_free_func, AvahiFreeFunc value_free_func) {
AvahiHashmap *m;
-
+
assert(hash_func);
assert(equal_func);
m->value_free_func = value_free_func;
AVAHI_LLIST_HEAD_INIT(Entry, m->entries_list);
-
+
return m;
}
while (m->entries_list)
entry_free(m, m->entries_list, 0);
-
+
avahi_free(m);
}
void* avahi_hashmap_lookup(AvahiHashmap *m, const void *key) {
Entry *e;
-
+
assert(m);
if (!(e = entry_get(m, key)))
m->key_free_func(key);
if (m->value_free_func)
m->value_free_func(value);
-
+
return 1;
}
idx = m->hash_func(key) % HASH_MAP_SIZE;
AVAHI_LLIST_PREPEND(Entry, bucket, m->entries[idx], e);
-
+
return 0;
}
e->key = key;
e->value = value;
-
+
return 1;
}
idx = m->hash_func(key) % HASH_MAP_SIZE;
AVAHI_LLIST_PREPEND(Entry, bucket, m->entries[idx], e);
-
+
return 0;
}
void avahi_hashmap_remove(AvahiHashmap *m, const void *key) {
Entry *e;
-
+
assert(m);
if (!(e = entry_get(m, key)))
unsigned hash = 0;
assert(p);
-
+
for (; *p; p++)
hash = 31 * hash + *p;
assert(p);
assert(q);
-
+
return strcmp(p, q) == 0;
}
const int *i = data;
assert(i);
-
+
return (unsigned) *i;
}
assert(_a);
assert(_b);
-
+
return *_a == *_b;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
uint8_t req[1024];
/* Issue a wild dump NETLINK request */
-
+
memset(&req, 0, sizeof(req));
n = (struct nlmsghdr*) req;
n->nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg));
AvahiInterfaceMonitor *m = userdata;
/* This routine is called for every RTNETLINK response packet */
-
+
assert(m);
assert(n);
assert(m->osdep.netlink == nl);
if (n->nlmsg_type == RTM_NEWLINK) {
/* A new interface appeared or an existing one has been modified */
-
+
struct ifinfomsg *ifinfomsg = NLMSG_DATA(n);
AvahiHwInterface *hw;
struct rtattr *a = NULL;
* interface appears, but when it changes, too */
if (!(hw = avahi_interface_monitor_get_hw_interface(m, ifinfomsg->ifi_index)))
-
+
/* No object found, so let's create a new
* one. avahi_hw_interface_new() will call
* avahi_interface_new() internally twice for IPv4 and
hw->mac_address_size = RTA_PAYLOAD(a);
if (hw->mac_address_size > AVAHI_MAC_ADDRESS_MAX)
hw->mac_address_size = AVAHI_MAC_ADDRESS_MAX;
-
+
memcpy(hw->mac_address, RTA_DATA(a), hw->mac_address_size);
break;
-
+
default:
;
}
/* Update any associated RRs of this interface. (i.e. the
* _workstation._tcp record containing the MAC address) */
avahi_hw_interface_update_rrs(hw, 0);
-
+
} else if (n->nlmsg_type == RTM_DELLINK) {
/* An interface has been removed */
/* Free our object */
avahi_hw_interface_free(hw, 0);
-
+
} else if (n->nlmsg_type == RTM_NEWADDR || n->nlmsg_type == RTM_DELADDR) {
/* An address has been added, modified or removed */
-
+
struct ifaddrmsg *ifaddrmsg = NLMSG_DATA(n);
AvahiInterface *i;
struct rtattr *a = NULL;
switch(a->rta_type) {
case IFA_ADDRESS:
/* Fill in address data */
-
+
if ((raddr.proto == AVAHI_PROTO_INET6 && RTA_PAYLOAD(a) != 16) ||
(raddr.proto == AVAHI_PROTO_INET && RTA_PAYLOAD(a) != 4))
return;
default:
;
}
-
+
a = RTA_NEXT(a, l);
}
/* Update any associated RRs, like A or AAAA for our new/removed address */
avahi_interface_update_rrs(i, 0);
-
+
} else if (n->nlmsg_type == NLMSG_DONE) {
/* This wild dump request ended, so let's see what we do next */
-
+
if (m->osdep.list == LIST_IFACE) {
/* Mmmm, interfaces have been wild dumped already, so
* let's go on with wild dumping the addresses */
-
+
if (netlink_list_items(m->osdep.netlink, RTM_GETADDR, &m->osdep.query_addr_seq) < 0) {
avahi_log_warn("NETLINK: Failed to list addrs: %s", strerror(errno));
m->osdep.list = LIST_DONE;
/* Tell the user that the wild dump is complete */
avahi_log_info("Network interface enumeration completed.");
}
-
+
} else if (n->nlmsg_type == NLMSG_ERROR &&
(n->nlmsg_seq == m->osdep.query_link_seq || n->nlmsg_seq == m->osdep.query_addr_seq)) {
struct nlmsgerr *e = NLMSG_DATA (n);
/* Some kind of error happened. Let's just tell the user and
* ignore it otherwise */
-
+
if (e->error)
avahi_log_warn("NETLINK: Failed to browse: %s", strerror(-e->error));
}
assert(m);
/* Initialize our own data */
-
+
m->osdep.netlink = NULL;
m->osdep.query_addr_seq = m->osdep.query_link_seq = 0;
/* Let's handle netlink events until we are done with wild
* dumping */
-
+
while (!m->list_complete)
if (!avahi_netlink_work(m->osdep.netlink, 1) == 0)
break;
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
struct AvahiInterfaceMonitorOSDep {
AvahiNetlink *netlink;
-
+
unsigned query_addr_seq, query_link_seq;
-
+
enum {
LIST_IFACE,
LIST_ADDR,
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
#include "iface-pfroute.h"
#include "util.h"
-static int bitcount (unsigned int n)
-{
+static int bitcount (unsigned int n)
+{
int count=0 ;
while (n)
{
AvahiHwInterface *hw;
struct if_msghdr *ifm = (struct if_msghdr *)rtm;
struct sockaddr_dl *sdl = (struct sockaddr_dl *)(ifm + 1);
-
+
if (sdl->sdl_family != AF_LINK)
return;
-
+
if (ifm->ifm_addrs == 0 && ifm->ifm_index > 0) {
if (!(hw = avahi_interface_monitor_get_hw_interface(m, (AvahiIfIndex) ifm->ifm_index)))
return;
avahi_hw_interface_free(hw, 0);
return;
}
-
+
if (!(hw = avahi_interface_monitor_get_hw_interface(m, ifm->ifm_index)))
if (!(hw = avahi_hw_interface_new(m, (AvahiIfIndex) ifm->ifm_index)))
return; /* OOM */
-
+
hw->flags_ok =
(ifm->ifm_flags & IFF_UP) &&
(!m->server->config.use_iff_running || (ifm->ifm_flags & IFF_RUNNING)) &&
!(ifm->ifm_flags & IFF_LOOPBACK) &&
(ifm->ifm_flags & IFF_MULTICAST) &&
(m->server->config.allow_point_to_point || !(ifm->ifm_flags & IFF_POINTOPOINT));
-
+
avahi_free(hw->name);
hw->name = avahi_strndup(sdl->sdl_data, sdl->sdl_nlen);
-
+
hw->mtu = ifm->ifm_data.ifi_mtu;
-
+
hw->mac_address_size = sdl->sdl_alen;
if (hw->mac_address_size > AVAHI_MAC_ADDRESS_MAX)
hw->mac_address_size = AVAHI_MAC_ADDRESS_MAX;
-
+
memcpy(hw->mac_address, sdl->sdl_data + sdl->sdl_nlen, hw->mac_address_size);
-
+
/* { */
/* char mac[256]; */
/* avahi_log_debug("======\n name: %s\n index:%d\n mtu:%d\n mac:%s\n flags_ok:%d\n======", */
/* avahi_format_mac_address(mac, sizeof(mac), hw->mac_address, hw->mac_address_size), */
/* hw->flags_ok); */
/* } */
-
+
avahi_hw_interface_check_relevant(hw);
avahi_hw_interface_update_rrs(hw, 0);
}
return;
raddr.proto = avahi_af_to_proto(sa->sa_family);
-
+
for(cp = cp0, i = 0; i < RTAX_MAX; i++)
{
if (!(ifam->ifam_addrs & (1<<i)))
continue;
sa = (struct sockaddr *)cp;
#ifdef HAVE_SYS_SYSCTL_H
- if (sa->sa_len == 0)
+ if (sa->sa_len == 0)
continue;
#endif
switch(sa->sa_family) {
return;
avahi_interface_address_free(addriface);
}
-
+
avahi_interface_check_relevant(iface);
avahi_interface_update_rrs(iface, 0);
}
{
assert(m);
assert(rtm);
-
+
if (rtm->rtm_version != RTM_VERSION) {
avahi_log_warn("routing message version %d not understood",
rtm->rtm_version);
}
m->osdep.pfroute->fd = fd;
- if (!(m->osdep.pfroute->watch = m->server->poll_api->watch_new(m->server->poll_api,
- m->osdep.pfroute->fd,
- AVAHI_WATCH_IN,
- socket_event,
+ if (!(m->osdep.pfroute->watch = m->server->poll_api->watch_new(m->server->poll_api,
+ m->osdep.pfroute->fd,
+ AVAHI_WATCH_IN,
+ socket_event,
m))) {
avahi_log_error(__FILE__": Failed to create watch.");
goto fail;
}
-
+
return 0;
fail:
if (m->osdep.pfroute) {
if (m->osdep.pfroute->watch)
m->server->poll_api->watch_free(m->osdep.pfroute->watch);
-
+
if (fd >= 0)
close(fd);
-
+
m->osdep.pfroute = NULL;
}
if (m->osdep.pfroute) {
if (m->osdep.pfroute->watch)
m->server->poll_api->watch_free(m->osdep.pfroute->watch);
-
+
if (m->osdep.pfroute->fd >= 0)
close(m->osdep.pfroute->fd);
index = if_nametoindex(lifreq->lifr_name);
if (!(hw = avahi_interface_monitor_get_hw_interface(m, (AvahiIfIndex) index))) {
- if (!(hw = avahi_hw_interface_new(m, (AvahiIfIndex) index)))
+ if (!(hw = avahi_hw_interface_new(m, (AvahiIfIndex) index)))
return; /* OOM */
hw->flags_ok =
return; /* OOM */
addriface->global_scope = 1;
-
+
avahi_hw_interface_check_relevant(hw);
avahi_hw_interface_update_rrs(hw, 0);
}
struct rt_msghdr *rtm;
assert(m);
-
+
retry2:
mib[0] = CTL_NET;
mib[1] = PF_ROUTE;
rtm = (struct rt_msghdr *)next;
parse_rtmsg(rtm, m);
}
-
+
m->list_complete = 1;
avahi_interface_monitor_check_relevant(m);
avahi_interface_monitor_update_rrs(m, 0);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
#else
typedef struct AvahiInterfaceMonitorOSDep AvahiInterfaceMonitorOSDep;
struct AvahiInterfaceMonitorOSDep {
-
+
unsigned query_addr_seq, query_link_seq;
-
+
enum {
LIST_IFACE,
LIST_ADDR,
char *name;
AvahiIfIndex index;
int flags_ok;
-
+
unsigned mtu;
uint8_t mac_address[AVAHI_MAC_ADDRESS_MAX];
AVAHI_LLIST_FIELDS(AvahiInterface, interface);
AVAHI_LLIST_FIELDS(AvahiInterface, by_hardware);
-
+
AvahiProtocol protocol;
int announcing;
AvahiAddress local_mcast_address;
unsigned prefix_len;
int global_scope;
-
+
AvahiSEntryGroup *entry_group;
};
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
struct AvahiLegacyUnicastReflectSlot {
AvahiServer *server;
-
+
uint16_t id, original_id;
AvahiAddress address;
uint16_t port;
AvahiSEntryGroup *group;
int dead;
-
+
AvahiPublishFlags flags;
AvahiRecord *record;
AvahiIfIndex interface;
AVAHI_LLIST_FIELDS(AvahiEntry, entries);
AVAHI_LLIST_FIELDS(AvahiEntry, by_key);
AVAHI_LLIST_FIELDS(AvahiEntry, by_group);
-
+
AVAHI_LLIST_HEAD(AvahiAnnouncer, announcers);
};
AvahiSEntryGroupCallback callback;
unsigned n_probing;
-
+
unsigned n_register_try;
struct timeval register_time;
AvahiTimeEvent *register_time_event;
struct timeval established_at;
-
+
AVAHI_LLIST_FIELDS(AvahiSEntryGroup, groups);
AVAHI_LLIST_HEAD(AvahiEntry, entries);
};
struct AvahiServer {
const AvahiPoll *poll_api;
-
+
AvahiInterfaceMonitor *monitor;
AvahiServerConfig config;
AvahiHashmap *entries_by_key;
AVAHI_LLIST_HEAD(AvahiSEntryGroup, groups);
-
+
AVAHI_LLIST_HEAD(AvahiSRecordBrowser, record_browsers);
AvahiHashmap *record_browser_hashmap;
AVAHI_LLIST_HEAD(AvahiSHostNameResolver, host_name_resolvers);
AVAHI_LLIST_HEAD(AvahiSDNSServerBrowser, dns_server_browsers);
int need_entry_cleanup, need_group_cleanup, need_browser_cleanup;
-
+
AvahiTimeEventQueue *time_event_queue;
-
+
char *host_name, *host_name_fqdn, *domain_name;
int fd_ipv4, fd_ipv6,
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiPublishFlags flags,
- uint32_t ttl,
- const char *name,
+ uint32_t ttl,
+ const char *name,
const char *dest);
#define AVAHI_CHECK_VALIDITY(server, expression, error) { \
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
void avahi_log_ap(AvahiLogLevel level, const char*format, va_list ap) {
char txt[256];
-
+
vsnprintf(txt, sizeof(txt), format, ap);
-
+
if (log_function)
log_function(level, txt);
else
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/** Callback prototype for AvahiSHostNameResolver events */
typedef void (*AvahiSHostNameResolverCallback)(
AvahiSHostNameResolver *r,
- AvahiIfIndex interface,
+ AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiResolverEvent event, /**< Resolving event */
const char *host_name, /**< Host name which should be resolved. May differ in case from the query */
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiResolverEvent event,
- const AvahiAddress *a,
+ const AvahiAddress *a,
const char *host_name, /**< A host name for the specified address, if one was found, i.e. event == AVAHI_RESOLVER_FOUND */
AvahiLookupResultFlags flags, /**< Lookup flags */
void* userdata);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
int dead;
AvahiKey *key, *cname_key;
-
+
AvahiMulticastLookupCallback callback;
void *userdata;
AvahiIfIndex interface;
AvahiProtocol protocol;
-
+
int queriers_added;
AvahiTimeEvent *all_for_now_event;
-
+
AVAHI_LLIST_FIELDS(AvahiMulticastLookup, lookups);
AVAHI_LLIST_FIELDS(AvahiMulticastLookup, by_key);
};
AvahiKey *key,
AvahiMulticastLookupCallback callback,
void *userdata) {
-
+
AvahiMulticastLookup *l, *t;
struct timeval tv;
-
+
assert(e);
assert(AVAHI_IF_VALID(interface));
assert(AVAHI_PROTO_VALID(protocol));
/* Issue the ALL_FOR_NOW event one second after the querier was initially created */
l->all_for_now_event = avahi_time_event_new(e->server->time_event_queue, &tv, all_for_now_callback, l);
-
+
return l;
}
assert(l);
lookup_stop(l);
-
+
t = avahi_hashmap_lookup(l->engine->lookups_by_key, l->key);
AVAHI_LLIST_REMOVE(AvahiMulticastLookup, by_key, t, l);
if (t)
if (l->cname_key)
avahi_key_unref(l->cname_key);
-
+
avahi_free(l);
}
void avahi_multicast_lookup_engine_cleanup(AvahiMulticastLookupEngine *e) {
AvahiMulticastLookup *l, *n;
assert(e);
-
+
while (e->cleanup_dead) {
e->cleanup_dead = 0;
-
+
for (l = e->lookups; l; l = n) {
n = l->lookups_next;
-
+
if (l->dead)
lookup_destroy(l);
}
cbdata->userdata);
cbdata->n_found ++;
-
+
return NULL;
}
assert(cbdata);
cbdata->interface = i;
-
+
avahi_cache_walk(i->cache, cbdata->key, scan_cache_callback, cbdata);
if (cbdata->cname_key)
avahi_cache_walk(i->cache, cbdata->cname_key, scan_cache_callback, cbdata);
-
+
cbdata->interface = NULL;
}
AvahiKey *key,
AvahiMulticastLookupCallback callback,
void *userdata) {
-
+
struct cbdata cbdata;
-
+
assert(e);
assert(key);
assert(callback);
cbdata.userdata = userdata;
cbdata.interface = NULL;
cbdata.n_found = 0;
-
+
avahi_interface_monitor_walk(e->server->monitor, interface, protocol, scan_interface_callback, &cbdata);
-
+
if (cbdata.cname_key)
avahi_key_unref(cbdata.cname_key);
void avahi_multicast_lookup_engine_new_interface(AvahiMulticastLookupEngine *e, AvahiInterface *i) {
AvahiMulticastLookup *l;
-
+
assert(e);
assert(i);
for (l = e->lookups; l; l = l->lookups_next) {
-
+
if (l->dead || !l->callback)
continue;
void avahi_multicast_lookup_engine_notify(AvahiMulticastLookupEngine *e, AvahiInterface *i, AvahiRecord *record, AvahiBrowserEvent event) {
AvahiMulticastLookup *l;
-
+
assert(e);
assert(record);
assert(i);
if (l->dead || !l->callback)
continue;
-
+
if ((key = avahi_key_new_cname(l->key))) {
if (avahi_key_equal(record->key, key))
l->callback(e, i->hardware->index, i->protocol, event, AVAHI_LOOKUP_RESULT_MULTICAST, record, l->userdata);
AvahiMulticastLookupEngine *avahi_multicast_lookup_engine_new(AvahiServer *s) {
AvahiMulticastLookupEngine *e;
-
+
assert(s);
-
+
e = avahi_new(AvahiMulticastLookupEngine, 1);
e->server = s;
e->cleanup_dead = 0;
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
struct iovec iov;
struct nlmsghdr *p;
char cred_msg[CMSG_SPACE(sizeof(struct ucred))];
-
+
assert(nl);
iov.iov_base = nl->buffer;
if ((bytes = recvmsg(nl->fd, &smsg, 0)) < 0) {
if (errno == EAGAIN || errno == EINTR)
return 0;
-
+
avahi_log_error(__FILE__": recvmsg() failed: %s", strerror(errno));
return -1;
}
return -1;
p = (struct nlmsghdr *) nl->buffer;
-
+
assert(nl->callback);
-
+
for (; bytes > 0; p = NLMSG_NEXT(p, bytes)) {
if (!NLMSG_OK(p, (size_t) bytes)) {
avahi_log_warn(__FILE__": packet truncated");
return -1;
}
-
+
nl->callback(nl, p, nl->userdata);
}
-
+
return 0;
}
avahi_log_error(__FILE__": socket(PF_NETLINK): %s", strerror(errno));
return NULL;
}
-
+
memset(&addr, 0, sizeof(addr));
addr.nl_family = AF_NETLINK;
addr.nl_groups = groups;
avahi_log_error(__FILE__": Failed to create watch.");
goto fail;
}
-
+
return nl;
fail:
if (nl->fd >= 0)
close(nl->fd);
-
+
avahi_free(nl->buffer);
avahi_free(nl);
}
int avahi_netlink_send(AvahiNetlink *nl, struct nlmsghdr *m, unsigned *ret_seq) {
assert(nl);
assert(m);
-
+
m->nlmsg_seq = nl->seq++;
m->nlmsg_flags |= NLM_F_ACK;
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
assert(n->parent->right == NULL);
}
-
+
if (n->parent) {
int a = POINTER_TO_INT(n->parent->data), b = POINTER_TO_INT(n->data);
if (a > b) {
assert(q->n_nodes == q2->n_nodes);
printf("%i\n", POINTER_TO_INT(((AvahiPrioQueueNode*)q2->root->data)->data));
-
+
avahi_prio_queue_remove(q, q2->root->data);
avahi_prio_queue_remove(q2, q2->root);
}
-
+
/* prev = 0; */
/* while (q->root) { */
/* int v = GPOINTER_TO_INT(q->root->data); */
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
if (!(q = avahi_new(AvahiPrioQueue, 1)))
return NULL; /* OOM */
-
+
q->root = q->last = NULL;
q->n_nodes = 0;
q->compare = compare;
-
+
return q;
}
for (r = 0; r < y; r++) {
assert(n);
-
+
if ((x >> (y-r-1)) & 1)
n = n->right;
else
if (a->parent == b) {
/* B is parent of A */
-
+
p = b->parent;
b->parent = a;
a->right->parent = a;
if ((b->right = r))
b->right->parent = b;
-
+
} else {
if ((b->right = a->right))
b->right->parent = b;
}
} else if (b->parent == a) {
/* A ist parent of B */
-
+
p = a->parent;
a->parent = b;
}
} else {
AvahiPrioQueueNode *apl = NULL, *bpl = NULL;
-
+
/* Swap parents */
ap = a->parent;
bp = b->parent;
apl = ap->left;
if (bp)
bpl = bp->left;
-
+
if ((a->parent = bp)) {
if (bpl == b)
bp->left = a;
- else
+ else
bp->right = a;
} else
q->root = a;
-
+
if ((b->parent = ap)) {
if (apl == a)
ap->left = b;
q->root = b;
/* Swap children */
- l = a->left;
- r = a->right;
+ l = a->left;
+ r = a->right;
if ((a->left = b->left))
a->left->parent = a;
if ((b->right = r))
b->right->parent = b;
}
-
+
/* Swap siblings */
ap = a->prev; an = a->next;
bp = b->prev; bn = b->next;
if ((b->prev = ap))
b->prev->next = b;
-
+
} else if (b->next == a) {
/* B is predecessor of A */
a->next = b;
if ((a->prev = bp))
a->prev->next = a;
-
+
if ((a->next = bn))
a->next->prev = a;
else
q->last = a;
-
+
if ((b->prev = ap))
b->prev->next = b;
-
+
if ((b->next = an))
b->next->prev = b;
else
if (!(n = avahi_new(AvahiPrioQueueNode, 1)))
return NULL; /* OOM */
-
+
n->queue = q;
n->data = data;
if (q->last) {
assert(q->root);
assert(q->n_nodes);
-
+
n->y = q->last->y;
n->x = q->last->x+1;
q->last->next = n;
n->prev = q->last;
-
+
assert(n->y > 0);
n->parent = get_node_at_xy(q, n->x/2, n->y-1);
} else {
assert(!q->root);
assert(!q->n_nodes);
-
+
n->y = n->x = 0;
q->root = n;
n->prev = n->parent = NULL;
assert(!n->right);
q->last = n->prev;
-
+
if (n->prev) {
n->prev->next = NULL;
assert(n->parent);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
struct AvahiProbeJob {
AvahiProbeScheduler *scheduler;
AvahiTimeEvent *time_event;
-
+
int chosen; /* Use for packet assembling */
int done;
struct timeval delivery;
AvahiRecord *record;
-
+
AVAHI_LLIST_FIELDS(AvahiProbeJob, jobs);
};
static AvahiProbeJob* job_new(AvahiProbeScheduler *s, AvahiRecord *record, int done) {
AvahiProbeJob *pj;
-
+
assert(s);
assert(record);
avahi_log_error(__FILE__": Out of memory");
return NULL; /* OOM */
}
-
+
pj->scheduler = s;
pj->record = avahi_record_ref(record);
pj->time_event = NULL;
avahi_log_error(__FILE__": Out of memory");
return NULL;
}
-
+
s->interface = i;
s->time_event_queue = i->monitor->server->time_event_queue;
AVAHI_LLIST_HEAD_INIT(AvahiProbeJob, s->jobs);
AVAHI_LLIST_HEAD_INIT(AvahiProbeJob, s->history);
-
+
return s;
}
void avahi_probe_scheduler_clear(AvahiProbeScheduler *s) {
assert(s);
-
+
while (s->jobs)
job_free(s, s->jobs);
while (s->history)
job_free(s, s->history);
}
-
+
static int packet_add_probe_query(AvahiProbeScheduler *s, AvahiDnsPacket *p, AvahiProbeJob *pj) {
size_t size;
AvahiKey *k;
assert(pj);
assert(!pj->chosen);
-
+
/* Estimate the size for this record */
size =
avahi_key_get_estimate_size(pj->record->key) +
/* Create the probe query */
if (!(k = avahi_key_new(pj->record->key->name, pj->record->key->clazz, AVAHI_DNS_TYPE_ANY)))
return 0; /* OOM */
-
+
b = !!avahi_dns_packet_append_key(p, k, 0);
assert(b);
/* Does the record match the probe? */
if (k->clazz != pj->record->key->clazz || !avahi_domain_equal(k->name, pj->record->key->name))
continue;
-
+
/* This job wouldn't fit in */
if (avahi_record_get_estimate_size(pj->record) > avahi_dns_packet_space(p))
break;
}
avahi_key_unref(k);
-
+
return 1;
}
if (!(p = avahi_dns_packet_new_query(s->interface->hardware->mtu)))
return; /* OOM */
n = 1;
-
+
/* Add the import probe */
if (!packet_add_probe_query(s, p, pj)) {
size_t size;
avahi_key_get_estimate_size(pj->record->key) +
avahi_record_get_estimate_size(pj->record) +
AVAHI_DNS_PACKET_HEADER_SIZE;
-
+
if (!(p = avahi_dns_packet_new_query(size + AVAHI_DNS_PACKET_EXTRA_SIZE)))
return; /* OOM */
avahi_dns_packet_free(p);
return; /* OOM */
}
-
+
b = avahi_dns_packet_append_key(p, k, 0) && avahi_dns_packet_append_record(p, pj->record, 0, 0);
avahi_key_unref(k);
avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_QDCOUNT, 1);
avahi_interface_send_packet(s->interface, p);
} else
- avahi_log_warn("Probe record too large, cannot send");
-
+ avahi_log_warn("Probe record too large, cannot send");
+
avahi_dns_packet_free(p);
job_mark_done(s, pj);
if (pj->chosen)
continue;
-
+
if (!packet_add_probe_query(s, p, pj))
break;
-
+
n++;
}
/* Unmark all following jobs */
for (; pj; pj = pj->jobs_next)
pj->chosen = 0;
-
+
break;
}
job_mark_done(s, pj);
-
+
n ++;
}
-
+
avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_NSCOUNT, n);
/* Send it now */
for (pj = s->jobs; pj; pj = pj->jobs_next) {
assert(!pj->done);
-
+
if (avahi_record_equal_no_ttl(pj->record, record))
return pj;
}
static AvahiProbeJob* find_history_job(AvahiProbeScheduler *s, AvahiRecord *record) {
AvahiProbeJob *pj;
-
+
assert(s);
assert(record);
job_free(s, pj);
return NULL;
}
-
+
return pj;
}
}
int avahi_probe_scheduler_post(AvahiProbeScheduler *s, AvahiRecord *record, int immediately) {
AvahiProbeJob *pj;
struct timeval tv;
-
+
assert(s);
assert(record);
assert(!avahi_key_is_pattern(record->key));
/* Create a new job and schedule it */
if (!(pj = job_new(s, record, 0)))
return 0; /* OOM */
-
+
pj->delivery = tv;
pj->time_event = avahi_time_event_new(s->time_event_queue, &pj->delivery, elapse_callback, pj);
-
+
/* avahi_log_debug("Accepted new probe job."); */
return 1;
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AvahiProtocol protocol, /**< A protocol family to attach this record to. One of the AVAHI_PROTO_xxx constants. Use AVAHI_PROTO_UNSPEC to make this record available on all protocols (wich means on both IPv4 and IPv6). */
AvahiPublishFlags flags, /**< Special flags for this record */
AvahiRecord *r /**< The record to add. This function increases the reference counter of this object. */);
-
+
/** Add an IP address mapping to the server. This will add both the
* host-name-to-address and the reverse mapping to the server. See
* avahi_server_add() for more information. If adding one of the RRs
AvahiPublishFlags flags,
const char *name, /**< Service name, e.g. "Lennart's Files" */
const char *type, /**< DNS-SD type, e.g. "_http._tcp" */
- const char *domain,
+ const char *domain,
const char *host, /**< Host name where this servcie resides, or NULL if on the local host */
uint16_t port, /**< Port number of the service */
... /**< Text records, terminated by NULL */) AVAHI_GCC_SENTINEL;
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiPublishFlags flags,
- const char *name,
- const char *type,
- const char *domain,
+ const char *name,
+ const char *type,
+ const char *domain,
AvahiStringList *strlst);
/** Update the TXT record for a service with the NULL termonate list of strings */
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiPublishFlags flags,
- const char *name,
- const char *type,
- const char *domain,
+ const char *name,
+ const char *type,
+ const char *domain,
...) AVAHI_GCC_SENTINEL;
/** Check if there is a service locally defined and return the entry group it is attached to. Returns NULL if the service isn't local*/
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
service_browser2 = avahi_s_service_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, SERVICE_TYPE, DOMAIN, 0, sb_callback, NULL);
assert(service_browser2);
-
+
poll_api->timeout_free(timeout);
}
int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
struct timeval tv;
AvahiServerConfig config;
-
+
simple_poll = avahi_simple_poll_new();
assert(simple_poll);
-
+
poll_api = avahi_simple_poll_get(simple_poll);
assert(poll_api);
avahi_address_parse("192.168.50.1", AVAHI_PROTO_UNSPEC, &config.wide_area_servers[0]);
config.n_wide_area_servers = 1;
config.enable_wide_area = 1;
-
+
server = avahi_server_new(poll_api, &config, NULL, NULL, NULL);
assert(server);
avahi_server_config_free(&config);
service_browser1 = avahi_s_service_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, SERVICE_TYPE, DOMAIN, 0, sb_callback, NULL);
assert(service_browser1);
-
+
poll_api->timeout_new(poll_api, avahi_elapse_time(&tv, 10000, 0), create_second_service_browser, NULL);
poll_api->timeout_new(poll_api, avahi_elapse_time(&tv, 60000, 0), quit, NULL);
-
+
for (;;)
if (avahi_simple_poll_iterate(simple_poll, -1) != 0)
break;
avahi_server_free(server);
avahi_simple_poll_free(simple_poll);
-
+
return 0;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
unsigned post_id;
int post_id_valid;
-
+
AVAHI_LLIST_FIELDS(AvahiQuerier, queriers);
};
avahi_key_unref(q->key);
avahi_time_event_free(q->time_event);
-
+
avahi_free(q);
}
static void querier_elapse_callback(AVAHI_GCC_UNUSED AvahiTimeEvent *e, void *userdata) {
AvahiQuerier *q = userdata;
struct timeval tv;
-
+
assert(q);
if (q->n_used <= 0) {
/* The queue accepted our query. We store the query id here,
* that allows us to drop the query at a later point if the
* query is very short-lived. */
-
+
q->post_id_valid = 1;
}
q->sec_delay *= 2;
-
+
if (q->sec_delay >= 60*60) /* 1h */
q->sec_delay = 60*60;
-
+
avahi_elapse_time(&tv, q->sec_delay*1000, 0);
avahi_time_event_update(q->time_event, &tv);
}
void avahi_querier_add(AvahiInterface *i, AvahiKey *key, struct timeval *ret_ctime) {
AvahiQuerier *q;
struct timeval tv;
-
+
assert(i);
assert(key);
-
+
if ((q = avahi_hashmap_lookup(i->queriers_by_key, key))) {
-
+
/* Someone is already browsing for records of this RR key */
q->n_used++;
/* No one is browsing for this RR key, so we add a new querier */
if (!(q = avahi_new(AvahiQuerier, 1)))
return; /* OOM */
-
+
q->key = avahi_key_ref(key);
q->interface = i;
q->n_used = 1;
void avahi_querier_remove_for_all(AvahiServer *s, AvahiIfIndex idx, AvahiProtocol protocol, AvahiKey *key) {
assert(s);
assert(key);
-
+
avahi_interface_monitor_walk(s->monitor, idx, protocol, remove_querier_callback, key);
}
static void add_querier_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, void* userdata) {
struct cbdata *cbdata = userdata;
-
+
assert(m);
assert(i);
assert(cbdata);
void avahi_querier_add_for_all(AvahiServer *s, AvahiIfIndex idx, AvahiProtocol protocol, AvahiKey *key, struct timeval *ret_ctime) {
struct cbdata cbdata;
-
+
assert(s);
assert(key);
if (ret_ctime)
ret_ctime->tv_sec = ret_ctime->tv_usec = 0;
-
+
avahi_interface_monitor_walk(s->monitor, idx, protocol, add_querier_callback, &cbdata);
}
int avahi_querier_shall_refresh_cache(AvahiInterface *i, AvahiKey *key) {
AvahiQuerier *q;
-
+
assert(i);
assert(key);
/* This key is currently not subscribed at all, so no cache
* refresh is needed */
return 0;
-
+
if (q->n_used <= 0) {
/* If this is an entry nobody references right now, don't
* consider it "existing". */
-
+
/* Remove this querier since it is referenced by nobody
* and the cached data will soon be out of date */
avahi_querier_free(q);
/* Tell the cache that no refresh is needed */
return 0;
-
+
} else {
struct timeval tv;
void avahi_querier_free_all(AvahiInterface *i) {
assert(i);
- while (i->queriers)
+ while (i->queriers)
avahi_querier_free(i->queriers);
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
struct AvahiQueryJob {
unsigned id;
int n_posted;
-
+
AvahiQueryScheduler *scheduler;
AvahiTimeEvent *time_event;
-
+
int done;
struct timeval delivery;
* entries) most of the time, but this might be a wrong
* assumption, especially on setups where traffic reflection is
* involved. */
-
+
AVAHI_LLIST_FIELDS(AvahiQueryJob, jobs);
};
static AvahiQueryJob* job_new(AvahiQueryScheduler *s, AvahiKey *key, int done) {
AvahiQueryJob *qj;
-
+
assert(s);
assert(key);
avahi_log_error(__FILE__": Out of memory");
return NULL;
}
-
+
qj->scheduler = s;
qj->key = avahi_key_ref(key);
qj->time_event = NULL;
qj->n_posted = 1;
qj->id = s->next_id++;
-
- if ((qj->done = done))
+
+ if ((qj->done = done))
AVAHI_LLIST_PREPEND(AvahiQueryJob, jobs, s->history, qj);
else
AVAHI_LLIST_PREPEND(AvahiQueryJob, jobs, s->jobs, qj);
avahi_log_error(__FILE__": Out of memory");
return NULL; /* OOM */
}
-
+
s->interface = i;
s->time_event_queue = i->monitor->server->time_event_queue;
s->next_id = 0;
-
+
AVAHI_LLIST_HEAD_INIT(AvahiQueryJob, s->jobs);
AVAHI_LLIST_HEAD_INIT(AvahiQueryJob, s->history);
AVAHI_LLIST_HEAD_INIT(AvahiKnownAnswer, s->known_answers);
void avahi_query_scheduler_clear(AvahiQueryScheduler *s) {
assert(s);
-
+
while (s->jobs)
job_free(s, s->jobs);
while (s->history)
static void* known_answer_walk_callback(AvahiCache *c, AvahiKey *pattern, AvahiCacheEntry *e, void* userdata) {
AvahiQueryScheduler *s = userdata;
AvahiKnownAnswer *ka;
-
+
assert(c);
assert(pattern);
assert(e);
if (avahi_cache_entry_half_ttl(c, e))
return NULL;
-
+
if (!(ka = avahi_new0(AvahiKnownAnswer, 1))) {
avahi_log_error(__FILE__": Out of memory");
return NULL;
}
-
+
ka->scheduler = s;
ka->record = avahi_record_ref(e->record);
/* Add all matching known answers to the list */
avahi_cache_walk(s->interface->cache, qj->key, known_answer_walk_callback, s);
-
+
job_mark_done(s, qj);
return 1;
assert(p);
n = 0;
-
+
while ((ka = s->known_answers)) {
int too_large = 0;
if (!too_large)
n++;
}
-
+
avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_ANCOUNT, n);
avahi_interface_send_packet(s->interface, p);
avahi_dns_packet_free(p);
}
assert(!s->known_answers);
-
+
if (!(p = avahi_dns_packet_new_query(s->interface->hardware->mtu)))
return; /* OOM */
-
+
b = packet_add_query_job(s, p, qj);
assert(b); /* An query must always fit in */
n = 1;
for (qj = s->jobs; qj; qj = qj->jobs_next) {
assert(!qj->done);
-
+
if (avahi_key_equal(qj->key, key))
return qj;
}
static AvahiQueryJob* find_history_job(AvahiQueryScheduler *s, AvahiKey *key) {
AvahiQueryJob *qj;
-
+
assert(s);
assert(key);
job_free(s, qj);
return NULL;
}
-
+
return qj;
}
}
int avahi_query_scheduler_post(AvahiQueryScheduler *s, AvahiKey *key, int immediately, unsigned *ret_id) {
struct timeval tv;
AvahiQueryJob *qj;
-
+
assert(s);
assert(key);
if ((qj = find_history_job(s, key)))
return 0;
-
+
avahi_elapse_time(&tv, immediately ? 0 : AVAHI_QUERY_DEFER_MSEC, 0);
if ((qj = find_scheduled_job(s, key))) {
}
qj->n_posted++;
-
+
} else {
if (!(qj = job_new(s, key, 0)))
return 0; /* OOM */
-
+
qj->delivery = tv;
qj->time_event = avahi_time_event_new(s->time_event_queue, &qj->delivery, elapse_callback, qj);
}
if (ret_id)
*ret_id = qj->id;
-
+
return 1;
}
void avahi_query_scheduler_incoming(AvahiQueryScheduler *s, AvahiKey *key) {
AvahiQueryJob *qj;
-
+
assert(s);
assert(key);
if (!(qj = find_history_job(s, key)))
if (!(qj = job_new(s, key, 1)))
return; /* OOM */
-
+
gettimeofday(&qj->delivery, NULL);
job_set_elapse_time(s, qj, AVAHI_QUERY_HISTORY_MSEC, 0);
}
int avahi_query_scheduler_withdraw_by_id(AvahiQueryScheduler *s, unsigned id) {
AvahiQueryJob *qj;
-
+
assert(s);
/* Very short lived queries can withdraw an already scheduled item
for (qj = s->jobs; qj; qj = qj->jobs_next) {
assert(!qj->done);
-
+
if (qj->id == id) {
/* Entry found */
* case since there should exist only one querier per
* key, but there are exceptions, notably reflected
* traffic.) */
-
+
job_free(s, qj);
return 1;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
struct AvahiSAddressResolver {
AvahiServer *server;
AvahiAddress address;
-
+
AvahiSRecordBrowser *record_browser;
AvahiSAddressResolverCallback callback;
static void finish(AvahiSAddressResolver *r, AvahiResolverEvent event) {
assert(r);
-
+
if (r->time_event) {
avahi_time_event_free(r->time_event);
r->time_event = NULL;
static void time_event_callback(AvahiTimeEvent *e, void *userdata) {
AvahiSAddressResolver *r = userdata;
-
+
assert(e);
assert(r);
AvahiRecord *record,
AvahiLookupResultFlags flags,
void* userdata) {
-
+
AvahiSAddressResolver *r = userdata;
assert(rr);
assert(r);
switch (event) {
- case AVAHI_BROWSER_NEW:
+ case AVAHI_BROWSER_NEW:
assert(record);
assert(record->key->type == AVAHI_DNS_TYPE_PTR);
-
+
if (r->interface > 0 && interface != r->interface)
return;
-
+
if (r->protocol != AVAHI_PROTO_UNSPEC && protocol != r->protocol)
return;
-
+
if (r->interface <= 0)
r->interface = interface;
-
+
if (r->protocol == AVAHI_PROTO_UNSPEC)
r->protocol = protocol;
-
+
if (!r->ptr_record) {
r->ptr_record = avahi_record_ref(record);
r->flags = flags;
-
+
finish(r, AVAHI_RESOLVER_FOUND);
}
break;
-
+
case AVAHI_BROWSER_REMOVE:
assert(record);
assert(record->key->type == AVAHI_DNS_TYPE_PTR);
-
+
if (r->ptr_record && avahi_record_equal_no_ttl(record, r->ptr_record)) {
avahi_record_unref(r->ptr_record);
r->ptr_record = NULL;
r->flags = flags;
-
+
/** Look for a replacement */
avahi_s_record_browser_restart(r->record_browser);
start_timeout(r);
}
break;
-
+
case AVAHI_BROWSER_CACHE_EXHAUSTED:
case AVAHI_BROWSER_ALL_FOR_NOW:
break;
AvahiLookupFlags flags,
AvahiSAddressResolverCallback callback,
void* userdata) {
-
+
AvahiSAddressResolver *r;
AvahiKey *k;
char n[AVAHI_DOMAIN_NAME_MAX];
AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_PROTO_VALID(protocol), AVAHI_ERR_INVALID_PROTOCOL);
AVAHI_CHECK_VALIDITY_RETURN_NULL(server, address->proto == AVAHI_PROTO_INET || address->proto == AVAHI_PROTO_INET6, AVAHI_ERR_INVALID_PROTOCOL);
AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST), AVAHI_ERR_INVALID_FLAGS);
-
+
avahi_reverse_lookup_name(address, n, sizeof(n));
if (!(k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR))) {
avahi_key_unref(k);
return NULL;
}
-
+
r->server = server;
r->address = *address;
r->callback = callback;
r->retry_with_multicast = 1;
}
}
-
+
r->record_browser = avahi_s_record_browser_new(server, interface, protocol, k, flags, record_browser_callback, r);
if (!r->record_browser) {
}
start_timeout(r);
-
+
return r;
}
if (r->key)
avahi_key_unref(r->key);
-
+
avahi_free(r);
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
struct AvahiSHostNameResolver {
AvahiServer *server;
char *host_name;
-
+
AvahiSRecordBrowser *record_browser_a;
AvahiSRecordBrowser *record_browser_aaaa;
switch (event) {
case AVAHI_RESOLVER_FOUND: {
AvahiAddress a;
-
+
assert(r->address_record);
-
+
switch (r->address_record->key->type) {
case AVAHI_DNS_TYPE_A:
a.proto = AVAHI_PROTO_INET;
a.data.ipv4 = r->address_record->data.a.address;
break;
-
+
case AVAHI_DNS_TYPE_AAAA:
a.proto = AVAHI_PROTO_INET6;
a.data.ipv6 = r->address_record->data.aaaa.address;
break;
-
+
default:
abort();
}
break;
}
-
+
case AVAHI_RESOLVER_FAILURE:
-
+
r->callback(r, r->interface, r->protocol, event, r->host_name, NULL, r->flags, r->userdata);
break;
}
static void time_event_callback(AvahiTimeEvent *e, void *userdata) {
AvahiSHostNameResolver *r = userdata;
-
+
assert(e);
assert(r);
AvahiRecord *record,
AvahiLookupResultFlags flags,
void* userdata) {
-
+
AvahiSHostNameResolver *r = userdata;
-
+
assert(rr);
assert(r);
if (r->interface > 0 && interface != r->interface)
return;
-
+
if (r->protocol != AVAHI_PROTO_UNSPEC && protocol != r->protocol)
return;
-
+
if (r->interface <= 0)
r->interface = interface;
-
+
if (r->protocol == AVAHI_PROTO_UNSPEC)
r->protocol = protocol;
-
+
if (!r->address_record) {
r->address_record = avahi_record_ref(record);
r->flags = flags;
-
+
finish(r, AVAHI_RESOLVER_FOUND);
}
r->flags = flags;
-
+
/** Look for a replacement */
if (r->record_browser_aaaa)
avahi_s_record_browser_restart(r->record_browser_aaaa);
if (r->record_browser_a)
avahi_s_record_browser_restart(r->record_browser_a);
-
+
start_timeout(r);
}
case AVAHI_BROWSER_FAILURE:
/* Stop browsers */
-
+
if (r->record_browser_aaaa)
avahi_s_record_browser_free(r->record_browser_aaaa);
if (r->record_browser_a)
r->record_browser_a = r->record_browser_aaaa = NULL;
r->flags = flags;
-
+
finish(r, AVAHI_RESOLVER_FAILURE);
break;
}
AvahiLookupFlags flags,
AvahiSHostNameResolverCallback callback,
void* userdata) {
-
+
AvahiSHostNameResolver *r;
AvahiKey *k;
-
+
assert(server);
assert(host_name);
assert(callback);
avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
return NULL;
}
-
+
r->server = server;
r->host_name = avahi_normalize_name_strdup(host_name);
r->callback = callback;
if (!r->record_browser_a)
goto fail;
- }
+ }
if (aprotocol == AVAHI_PROTO_INET6 || aprotocol == AVAHI_PROTO_UNSPEC) {
k = avahi_key_new(host_name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_AAAA);
assert(r->record_browser_aaaa || r->record_browser_a);
start_timeout(r);
-
+
return r;
fail:
if (r->address_record)
avahi_record_unref(r->address_record);
-
+
avahi_free(r->host_name);
avahi_free(r);
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AvahiRecord *srv_record, *txt_record, *address_record;
AvahiLookupResultFlags srv_flags, txt_flags, address_flags;
-
+
AvahiSServiceResolverCallback callback;
void* userdata;
AvahiLookupFlags user_flags;
static void finish(AvahiSServiceResolver *r, AvahiResolverEvent event) {
AvahiLookupResultFlags flags;
-
+
assert(r);
if (r->time_event) {
r->txt_flags |
r->srv_flags |
r->address_flags;
-
+
switch (event) {
case AVAHI_RESOLVER_FAILURE:
-
+
r->callback(
r,
r->interface,
case AVAHI_RESOLVER_FOUND: {
AvahiAddress a;
-
+
assert(event == AVAHI_RESOLVER_FOUND);
-
+
assert(r->srv_record);
if (r->address_record) {
a.proto = AVAHI_PROTO_INET;
a.data.ipv4 = r->address_record->data.a.address;
break;
-
+
case AVAHI_DNS_TYPE_AAAA:
a.proto = AVAHI_PROTO_INET6;
a.data.ipv6 = r->address_record->data.aaaa.address;
break;
-
+
default:
assert(0);
}
}
-
+
r->callback(
r,
r->interface,
static void time_event_callback(AvahiTimeEvent *e, void *userdata) {
AvahiSServiceResolver *r = userdata;
-
+
assert(e);
assert(r);
AvahiRecord *record,
AvahiLookupResultFlags flags,
void* userdata) {
-
+
AvahiSServiceResolver *r = userdata;
assert(rr);
case AVAHI_BROWSER_NEW: {
int changed = 0;
assert(record);
-
+
if (r->interface > 0 && interface > 0 && interface != r->interface)
return;
-
+
if (r->protocol != AVAHI_PROTO_UNSPEC && protocol != AVAHI_PROTO_UNSPEC && protocol != r->protocol)
return;
-
+
if (r->interface <= 0)
r->interface = interface;
-
+
if (r->protocol == AVAHI_PROTO_UNSPEC)
r->protocol = protocol;
-
+
switch (record->key->type) {
case AVAHI_DNS_TYPE_SRV:
if (!r->srv_record) {
r->srv_record = avahi_record_ref(record);
changed = 1;
-
+
if (r->record_browser_a) {
avahi_s_record_browser_free(r->record_browser_a);
r->record_browser_a = NULL;
}
-
+
if (r->record_browser_aaaa) {
avahi_s_record_browser_free(r->record_browser_aaaa);
r->record_browser_aaaa = NULL;
AvahiKey *k = avahi_key_new(r->srv_record->data.srv.name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_A);
r->record_browser_a = avahi_s_record_browser_new(r->server, r->interface, r->protocol, k, r->user_flags & ~(AVAHI_LOOKUP_NO_TXT|AVAHI_LOOKUP_NO_ADDRESS), record_browser_callback, r);
avahi_key_unref(k);
- }
-
+ }
+
if (r->address_protocol == AVAHI_PROTO_INET6 || r->address_protocol == AVAHI_PROTO_UNSPEC) {
AvahiKey *k = avahi_key_new(r->srv_record->data.srv.name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_AAAA);
r->record_browser_aaaa = avahi_s_record_browser_new(r->server, r->interface, r->protocol, k, r->user_flags & ~(AVAHI_LOOKUP_NO_TXT|AVAHI_LOOKUP_NO_ADDRESS), record_browser_callback, r);
}
}
break;
-
+
case AVAHI_DNS_TYPE_TXT:
assert(!(r->user_flags & AVAHI_LOOKUP_NO_TXT));
changed = 1;
}
break;
-
+
case AVAHI_DNS_TYPE_A:
case AVAHI_DNS_TYPE_AAAA:
changed = 1;
}
break;
-
+
default:
abort();
}
break;
}
-
+
case AVAHI_BROWSER_REMOVE:
assert(record);
switch (record->key->type) {
case AVAHI_DNS_TYPE_SRV:
-
+
if (r->srv_record && avahi_record_equal_no_ttl(record, r->srv_record)) {
avahi_record_unref(r->srv_record);
r->srv_record = NULL;
avahi_s_record_browser_free(r->record_browser_a);
r->record_browser_a = NULL;
}
-
+
if (r->record_browser_aaaa) {
avahi_s_record_browser_free(r->record_browser_aaaa);
r->record_browser_aaaa = NULL;
}
-
+
/** Look for a replacement */
avahi_s_record_browser_restart(r->record_browser_srv);
start_timeout(r);
}
-
+
break;
-
+
case AVAHI_DNS_TYPE_TXT:
-
+
assert(!(r->user_flags & AVAHI_LOOKUP_NO_TXT));
-
+
if (r->txt_record && avahi_record_equal_no_ttl(record, r->txt_record)) {
avahi_record_unref(r->txt_record);
r->txt_record = NULL;
-
+
/** Look for a replacement */
avahi_s_record_browser_restart(r->record_browser_txt);
start_timeout(r);
}
break;
-
+
case AVAHI_DNS_TYPE_A:
case AVAHI_DNS_TYPE_AAAA:
-
+
assert(!(r->user_flags & AVAHI_LOOKUP_NO_ADDRESS));
-
+
if (r->address_record && avahi_record_equal_no_ttl(record, r->address_record)) {
avahi_record_unref(r->address_record);
r->address_record = NULL;
-
+
/** Look for a replacement */
if (r->record_browser_aaaa)
avahi_s_record_browser_restart(r->record_browser_aaaa);
start_timeout(r);
}
break;
-
+
default:
abort();
}
break;
case AVAHI_BROWSER_FAILURE:
-
+
if (rr == r->record_browser_a && r->record_browser_aaaa) {
/* We were looking for both AAAA and A, and the other query is still living, so we'll not die */
avahi_s_record_browser_free(r->record_browser_a);
}
/* Hmm, everything's lost, tell the user */
-
+
if (r->record_browser_srv)
avahi_s_record_browser_free(r->record_browser_srv);
if (r->record_browser_txt)
AvahiLookupFlags flags,
AvahiSServiceResolverCallback callback,
void* userdata) {
-
+
AvahiSServiceResolver *r;
AvahiKey *k;
char n[AVAHI_DOMAIN_NAME_MAX];
int ret;
-
+
assert(server);
assert(type);
assert(callback);
avahi_server_set_errno(server, ret);
return NULL;
}
-
+
if (!(r = avahi_new(AvahiSServiceResolver, 1))) {
avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
return NULL;
}
-
+
r->server = server;
r->service_name = avahi_strdup(name);
r->service_type = avahi_normalize_name_strdup(type);
k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_TXT);
r->record_browser_txt = avahi_s_record_browser_new(server, interface, protocol, k, flags & ~(AVAHI_LOOKUP_NO_TXT|AVAHI_LOOKUP_NO_ADDRESS), record_browser_callback, r);
avahi_key_unref(k);
-
+
if (!r->record_browser_txt) {
avahi_s_service_resolver_free(r);
return NULL;
}
start_timeout(r);
-
+
return r;
}
if (r->time_event)
avahi_time_event_free(r->time_event);
-
+
if (r->record_browser_srv)
avahi_s_record_browser_free(r->record_browser_srv);
if (r->record_browser_txt)
avahi_record_unref(r->txt_record);
if (r->address_record)
avahi_record_unref(r->address_record);
-
+
avahi_free(r->service_name);
avahi_free(r->service_type);
avahi_free(r->domain_name);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
struct AvahiResponseJob {
AvahiResponseScheduler *scheduler;
AvahiTimeEvent *time_event;
-
+
AvahiResponseJobState state;
struct timeval delivery;
int flush_cache;
AvahiAddress querier;
int querier_valid;
-
+
AVAHI_LLIST_FIELDS(AvahiResponseJob, jobs);
};
static AvahiResponseJob* job_new(AvahiResponseScheduler *s, AvahiRecord *record, AvahiResponseJobState state) {
AvahiResponseJob *rj;
-
+
assert(s);
assert(record);
avahi_log_error(__FILE__": Out of memory");
return NULL;
}
-
+
rj->scheduler = s;
rj->record = avahi_record_ref(record);
rj->time_event = NULL;
rj->flush_cache = 0;
rj->querier_valid = 0;
-
- if ((rj->state = state) == AVAHI_SCHEDULED)
+
+ if ((rj->state = state) == AVAHI_SCHEDULED)
AVAHI_LLIST_PREPEND(AvahiResponseJob, jobs, s->jobs, rj);
else if (rj->state == AVAHI_DONE)
AVAHI_LLIST_PREPEND(AvahiResponseJob, jobs, s->history, rj);
avahi_log_error(__FILE__": Out of memory");
return NULL;
}
-
+
s->interface = i;
s->time_event_queue = i->monitor->server->time_event_queue;
-
+
AVAHI_LLIST_HEAD_INIT(AvahiResponseJob, s->jobs);
AVAHI_LLIST_HEAD_INIT(AvahiResponseJob, s->history);
AVAHI_LLIST_HEAD_INIT(AvahiResponseJob, s->suppressed);
void avahi_response_scheduler_clear(AvahiResponseScheduler *s) {
assert(s);
-
+
while (s->jobs)
job_free(s, s->jobs);
while (s->history)
static void enumerate_aux_records_callback(AVAHI_GCC_UNUSED AvahiServer *s, AvahiRecord *r, int flush_cache, void* userdata) {
AvahiResponseJob *rj = userdata;
-
+
assert(r);
assert(rj);
* auxilliary packets, too */
avahi_server_enumerate_aux_records(s->interface->monitor->server, s->interface, rj->record, enumerate_aux_records_callback, rj);
job_mark_done(s, rj);
-
+
return 1;
}
/* Try to fill up packet with more responses, if available */
while (s->jobs) {
-
+
if (!packet_add_response_job(s, p, s->jobs))
break;
-
+
n++;
}
-
+
} else {
size_t size;
-
+
avahi_dns_packet_free(p);
/* OK, the packet was too small, so create one that fits */
assert(rj);
- if (rj->state == AVAHI_DONE || rj->state == AVAHI_SUPPRESSED)
+ if (rj->state == AVAHI_DONE || rj->state == AVAHI_SUPPRESSED)
job_free(rj->scheduler, rj); /* Lets drop this entry */
else
send_response_packet(rj->scheduler, rj);
for (rj = s->jobs; rj; rj = rj->jobs_next) {
assert(rj->state == AVAHI_SCHEDULED);
-
+
if (avahi_record_equal_no_ttl(rj->record, record))
return rj;
}
static AvahiResponseJob* find_history_job(AvahiResponseScheduler *s, AvahiRecord *record) {
AvahiResponseJob *rj;
-
+
assert(s);
assert(record);
/* Check whether this entry is outdated */
/* avahi_log_debug("history age: %u", (unsigned) (avahi_age(&rj->delivery)/1000)); */
-
+
if (avahi_age(&rj->delivery)/1000 > AVAHI_RESPONSE_HISTORY_MSEC) {
/* it is outdated, so let's remove it */
job_free(s, rj);
return NULL;
}
-
+
return rj;
}
}
static AvahiResponseJob* find_suppressed_job(AvahiResponseScheduler *s, AvahiRecord *record, const AvahiAddress *querier) {
AvahiResponseJob *rj;
-
+
assert(s);
assert(record);
assert(querier);
for (rj = s->suppressed; rj; rj = rj->jobs_next) {
assert(rj->state == AVAHI_SUPPRESSED);
assert(rj->querier_valid);
-
+
if (avahi_record_equal_no_ttl(rj->record, record) &&
avahi_address_cmp(&rj->querier, querier) == 0) {
/* Check whether this entry is outdated */
AvahiResponseJob *rj;
struct timeval tv;
/* char *t; */
-
+
assert(s);
assert(record);
}
avahi_elapse_time(&tv, immediately ? 0 : AVAHI_RESPONSE_DEFER_MSEC, immediately ? 0 : AVAHI_RESPONSE_JITTER_MSEC);
-
+
if ((rj = find_scheduled_job(s, record))) {
/* avahi_log_debug("Response suppressed by local duplicate suppression (scheduled)"); */
/* Create a new job and schedule it */
if (!(rj = job_new(s, record, AVAHI_SCHEDULED)))
return 0; /* OOM */
-
+
rj->delivery = tv;
rj->time_event = avahi_time_event_new(s->time_event_queue, &rj->delivery, elapse_callback, rj);
rj->flush_cache = flush_cache;
/* This function is called whenever an incoming response was
* receieved. We drop scheduled responses which match here. The
* keyword is "DUPLICATE ANSWER SUPPRESION". */
-
+
if ((rj = find_scheduled_job(s, record))) {
if ((!rj->flush_cache || flush_cache) && /* flush cache bit was set correctly */
rj->flush_cache = flush_cache;
rj->querier_valid = 0;
-
+
gettimeofday(&rj->delivery, NULL);
job_set_elapse_time(s, rj, AVAHI_RESPONSE_HISTORY_MSEC, 0);
}
void avahi_response_scheduler_suppress(AvahiResponseScheduler *s, AvahiRecord *record, const AvahiAddress *querier) {
AvahiResponseJob *rj;
-
+
assert(s);
assert(record);
assert(querier);
if ((rj = find_scheduled_job(s, record))) {
-
+
if (rj->querier_valid && avahi_address_cmp(querier, &rj->querier) == 0 && /* same originator */
avahi_record_is_goodbye(record) == avahi_record_is_goodbye(rj->record) && /* both goodbye packets, or both not */
record->ttl >= rj->record->ttl/2) { /* sensible TTL */
/* Let's update the old entry */
avahi_record_unref(rj->record);
rj->record = avahi_record_ref(record);
-
+
} else {
/* Create a new entry */
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
enum {
AVAHI_DNS_TYPE_ANY = 0xFF, /**< Special query type for requesting all records */
AVAHI_DNS_TYPE_OPT = 41, /**< EDNS0 option */
- AVAHI_DNS_TYPE_TKEY = 249,
- AVAHI_DNS_TYPE_TSIG = 250,
+ AVAHI_DNS_TYPE_TKEY = 249,
+ AVAHI_DNS_TYPE_TSIG = 250,
AVAHI_DNS_TYPE_IXFR = 251,
AVAHI_DNS_TYPE_AXFR = 252
};
typedef struct AvahiRecord {
int ref; /**< Reference counter */
AvahiKey *key; /**< Reference to the query key of this record */
-
+
uint32_t ttl; /**< DNS TTL of this record */
union {
-
+
struct {
void* data;
uint16_t size;
} generic; /**< Generic record data for unknown types */
-
+
struct {
uint16_t priority;
uint16_t weight;
} aaaa; /**< Data for AAAA records */
} data; /**< Record data */
-
+
} AvahiRecord;
/** Create a new AvahiKey object. The reference counter will be set to 1. */
/** Check whether two AvahiKey object contain the same
* data. AVAHI_DNS_CLASS_ANY/AVAHI_DNS_TYPE_ANY are treated like any
* other class/type. */
-int avahi_key_equal(const AvahiKey *a, const AvahiKey *b);
+int avahi_key_equal(const AvahiKey *a, const AvahiKey *b);
/** Return a numeric hash value for a key for usage in hash tables. */
unsigned avahi_key_hash(const AvahiKey *k);
/** Create a textual representation of the specified record, similar
* in style to BIND zone file data. avahi_free() the result! */
-char *avahi_record_to_string(const AvahiRecord *r);
+char *avahi_record_to_string(const AvahiRecord *r);
/** Check whether two records are equal (regardless of the TTL */
int avahi_record_equal_no_ttl(const AvahiRecord *a, const AvahiRecord *b);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
avahi_log_error("avahi_new() failed.");
return NULL;
}
-
+
AVAHI_LLIST_HEAD_INIT(AvahiRecordListItem, l->read);
AVAHI_LLIST_HEAD_INIT(AvahiRecordListItem, l->unread);
assert(l);
assert(i);
- if (i->read)
+ if (i->read)
AVAHI_LLIST_REMOVE(AvahiRecordListItem, items, l->read, i);
else
AVAHI_LLIST_REMOVE(AvahiRecordListItem, items, l->unread, i);
-
+
avahi_record_unref(i->record);
avahi_free(i);
}
void avahi_record_list_flush(AvahiRecordList *l) {
assert(l);
-
+
while (l->read)
item_free(l, l->read);
while (l->unread)
return NULL;
assert(!i->read);
-
+
r = avahi_record_ref(i->record);
if (ret_unicast_response)
*ret_unicast_response = i->unicast_response;
AVAHI_LLIST_PREPEND(AvahiRecordListItem, items, l->read, i);
i->read = 1;
-
+
return r;
}
assert(l);
assert(r);
-
+
for (i = l->read; i; i = i->items_next)
if (avahi_record_equal_no_ttl(i->record, r))
return i;
void avahi_record_list_push(AvahiRecordList *l, AvahiRecord *r, int flush_cache, int unicast_response, int auxiliary) {
AvahiRecordListItem *i;
-
+
assert(l);
assert(r);
avahi_log_error("avahi_new() failed.");
return;
}
-
+
i->unicast_response = unicast_response;
i->flush_cache = flush_cache;
i->auxiliary = auxiliary;
i->read = 0;
l->all_flush_cache = l->all_flush_cache && flush_cache;
-
+
AVAHI_LLIST_PREPEND(AvahiRecordListItem, items, l->unread, i);
}
int avahi_record_list_is_empty(AvahiRecordList *l) {
assert(l);
-
+
return !l->unread && !l->read;
}
assert(l);
/* Return TRUE if all entries in this list have flush_cache set */
-
+
return l->all_flush_cache;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
struct timeval now;
gettimeofday(&now, NULL);
-
+
/* Check if expired */
if (avahi_timeval_compare(&now, &e->expiry) >= 0) {
update_timeout(q);
return;
- }
+ }
}
avahi_log_debug(__FILE__": Strange, expiration_event() called, but nothing really happened.");
if (!(q->prioq = avahi_prio_queue_new(compare)))
goto oom;
- if (!(q->timeout = poll_api->timeout_new(poll_api, NULL, expiration_event, q)))
+ if (!(q->timeout = poll_api->timeout_new(poll_api, NULL, expiration_event, q)))
goto oom;
-
+
return q;
oom:
if (q->prioq)
avahi_prio_queue_free(q->prioq);
}
-
+
return NULL;
}
void avahi_time_event_queue_free(AvahiTimeEventQueue *q) {
AvahiTimeEvent *e;
-
+
assert(q);
while ((e = time_event_queue_root(q)))
avahi_prio_queue_free(q->prioq);
q->poll_api->timeout_free(q->timeout);
-
+
avahi_free(q);
}
const struct timeval *timeval,
AvahiTimeEventCallback callback,
void* userdata) {
-
+
AvahiTimeEvent *e;
-
+
assert(q);
assert(callback);
assert(userdata);
avahi_log_error(__FILE__": Out of memory");
return NULL; /* OOM */
}
-
+
e->queue = q;
e->callback = callback;
e->userdata = userdata;
e->expiry.tv_sec = 0;
e->expiry.tv_usec = 0;
}
-
+
fix_expiry_time(e);
-
+
e->last_run.tv_sec = 0;
e->last_run.tv_usec = 0;
e->expiry = *timeval;
fix_expiry_time(e);
avahi_prio_queue_shuffle(e->queue->prioq, e->node);
-
+
update_timeout(e->queue);
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
static void server_callback(AvahiServer *s, AvahiServerState state, AVAHI_GCC_UNUSED void* userdata) {
- avahi_log_debug("server state: %i", state);
-
+ avahi_log_debug("server state: %i", state);
+
if (state == AVAHI_SERVER_RUNNING) {
int ret;
-
+
group = avahi_s_entry_group_new(s, NULL, NULL);
assert(group);
AvahiServer *s = userdata;
avahi_log_debug("modifying");
-
+
ret = avahi_server_update_service_txt(s, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, "foo", "_http._tcp", NULL, "test2", NULL);
assert(ret == AVAHI_OK);
}
simple_poll = avahi_simple_poll_new();
assert(simple_poll);
-
+
poll_api = avahi_simple_poll_get(simple_poll);
assert(poll_api);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
assert(p);
printf("Dumping %lu bytes from %p:\n", (unsigned long) size, p);
-
+
while (size > 0) {
unsigned i;
- for (i = 0; i < 16; i++) {
+ for (i = 0; i < 16; i++) {
if (i < size)
printf("%02x ", c[i]);
else
else
printf(" ");
}
-
+
printf("\n");
c += 16;
if (size <= 16)
break;
-
+
size -= 16;
}
}
assert(r);
assert(l > 0);
assert(mac);
-
+
if (size <= 0) {
*r = 0;
return r;
}
-
+
for (i = 0; i < size; i++) {
if (l < 3)
break;
-
+
*(t++) = hex[*mac >> 4];
*(t++) = hex[*mac & 0xF];
*(t++) = ':';
l -= 3;
-
+
mac++;
}
*(t-1) = 0;
else
*r = 0;
-
+
return r;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
struct AvahiWideAreaCacheEntry {
AvahiWideAreaLookupEngine *engine;
-
+
AvahiRecord *record;
struct timeval timestamp;
struct timeval expiry;
AvahiTimeEvent *time_event;
-
+
AVAHI_LLIST_FIELDS(AvahiWideAreaCacheEntry, by_key);
AVAHI_LLIST_FIELDS(AvahiWideAreaCacheEntry, cache);
};
struct AvahiWideAreaLookup {
AvahiWideAreaLookupEngine *engine;
int dead;
-
+
uint32_t id; /* effectively just an uint16_t, but we need it as an index for a hash table */
AvahiTimeEvent *time_event;
AvahiKey *key, *cname_key;
-
+
int n_send;
AvahiDnsPacket *packet;
AvahiWatch *watch_ipv4, *watch_ipv6;
uint16_t next_id;
-
+
/* Cache */
AVAHI_LLIST_HEAD(AvahiWideAreaCacheEntry, cache);
AvahiHashmap *cache_by_key;
static AvahiWideAreaLookup* find_lookup(AvahiWideAreaLookupEngine *e, uint16_t id) {
AvahiWideAreaLookup *l;
int i = (int) id;
-
+
assert(e);
if (!(l = avahi_hashmap_lookup(e->lookups_by_id, &i)))
return NULL;
-
+
assert(l->id == id);
if (l->dead)
return NULL;
-
+
return l;
}
static int send_to_dns_server(AvahiWideAreaLookup *l, AvahiDnsPacket *p) {
AvahiAddress *a;
-
+
assert(l);
assert(p);
a = &l->engine->dns_servers[l->engine->current_dns_server];
l->dns_server_used = *a;
-
+
if (a->proto == AVAHI_PROTO_INET) {
if (l->engine->fd_ipv4 < 0)
return -1;
-
+
return avahi_send_dns_packet_ipv4(l->engine->fd_ipv4, AVAHI_IF_UNSPEC, p, NULL, &a->data.ipv4, AVAHI_DNS_PORT);
-
+
} else {
assert(a->proto == AVAHI_PROTO_INET6);
if (l->engine->fd_ipv6 < 0)
return -1;
-
+
return avahi_send_dns_packet_ipv6(l->engine->fd_ipv6, AVAHI_IF_UNSPEC, p, NULL, &a->data.ipv6, AVAHI_DNS_PORT);
}
}
static void lookup_stop(AvahiWideAreaLookup *l) {
assert(l);
-
+
l->callback = NULL;
if (l->time_event) {
/* There is no other DNS server, fail */
l->n_send = 1000;
}
-
+
if (l->n_send >= 6) {
avahi_log_warn(__FILE__": Query timed out.");
avahi_server_set_errno(l->engine->server, AVAHI_ERR_TIMEOUT);
AvahiKey *key,
AvahiWideAreaLookupCallback callback,
void *userdata) {
-
+
struct timeval tv;
AvahiWideAreaLookup *l, *t;
uint8_t *p;
break; /* This ID is not yet used. */
l->id = e->next_id++;
-
+
/* We keep the packet around in case we need to repeat our query */
l->packet = avahi_dns_packet_new(0);
p = avahi_dns_packet_append_key(l->packet, key, 0);
assert(p);
-
+
avahi_dns_packet_set_field(l->packet, AVAHI_DNS_FIELD_QDCOUNT, 1);
if (send_to_dns_server(l, l->packet) < 0) {
}
l->n_send = 1;
-
+
l->time_event = avahi_time_event_new(e->server->time_event_queue, avahi_elapse_time(&tv, 500, 0), sender_timeout_callback, l);
avahi_hashmap_insert(e->lookups_by_id, &l->id, l);
avahi_hashmap_replace(e->lookups_by_key, avahi_key_ref(l->key), t);
AVAHI_LLIST_PREPEND(AvahiWideAreaLookup, lookups, e->lookups, l);
-
+
return l;
}
static void lookup_destroy(AvahiWideAreaLookup *l) {
AvahiWideAreaLookup *t;
assert(l);
-
+
lookup_stop(l);
t = avahi_hashmap_lookup(l->engine->lookups_by_key, l->key);
avahi_hashmap_remove(l->engine->lookups_by_key, l->key);
AVAHI_LLIST_REMOVE(AvahiWideAreaLookup, lookups, l->engine->lookups, l);
-
+
avahi_hashmap_remove(l->engine->lookups_by_id, &l->id);
avahi_dns_packet_free(l->packet);
if (l->cname_key)
avahi_key_unref(l->cname_key);
-
+
avahi_free(l);
}
while (e->cleanup_dead) {
e->cleanup_dead = 0;
-
+
for (l = e->lookups; l; l = n) {
n = l->lookups_next;
-
+
if (l->dead)
lookup_destroy(l);
}
static void expiry_event(AvahiTimeEvent *te, void *userdata) {
AvahiWideAreaCacheEntry *e = userdata;
-
+
assert(te);
assert(e);
static AvahiWideAreaCacheEntry* find_record_in_cache(AvahiWideAreaLookupEngine *e, AvahiRecord *r) {
AvahiWideAreaCacheEntry *c;
-
+
assert(e);
assert(r);
static void run_callbacks(AvahiWideAreaLookupEngine *e, AvahiRecord *r) {
AvahiWideAreaLookup *l;
-
+
assert(e);
assert(r);
for (l = avahi_hashmap_lookup(e->lookups_by_key, r->key); l; l = l->by_key_next) {
if (l->dead || !l->callback)
continue;
-
+
l->callback(e, AVAHI_BROWSER_NEW, AVAHI_LOOKUP_RESULT_WIDE_AREA, r, l->userdata);
}
-
+
if (r->key->clazz == AVAHI_DNS_CLASS_IN && r->key->type == AVAHI_DNS_TYPE_CNAME) {
/* It's a CNAME record, so we have to scan the all lookups to see if one matches */
if (l->dead || !l->callback)
continue;
-
+
if ((key = avahi_key_new_cname(l->key))) {
if (avahi_key_equal(r->key, key))
l->callback(e, AVAHI_BROWSER_NEW, AVAHI_LOOKUP_RESULT_WIDE_AREA, r, l->userdata);
static void add_to_cache(AvahiWideAreaLookupEngine *e, AvahiRecord *r) {
AvahiWideAreaCacheEntry *c;
int is_new;
-
+
assert(e);
assert(r);
if (e->cache_n_entries >= CACHE_ENTRIES_MAX)
/* Eventually we should improve the caching algorithm here */
goto finish;
-
+
c = avahi_new(AvahiWideAreaCacheEntry, 1);
c->engine = e;
c->time_event = NULL;
}
c->record = avahi_record_ref(r);
-
+
gettimeofday(&c->timestamp, NULL);
c->expiry = c->timestamp;
avahi_timeval_add(&c->expiry, r->ttl * 1000000);
c->time_event = avahi_time_event_new(e->server->time_event_queue, &c->expiry, expiry_event, c);
finish:
-
+
if (is_new)
run_callbacks(e, r);
}
int i, r;
AvahiBrowserEvent final_event = AVAHI_BROWSER_ALL_FOR_NOW;
-
+
assert(e);
assert(p);
/* Skip over the question */
for (i = (int) avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_QDCOUNT); i > 0; i--) {
AvahiKey *k;
-
+
if (!(k = avahi_dns_packet_consume_key(p, NULL))) {
avahi_log_warn(__FILE__": Wide area response packet too short or invalid while reading question key. (Maybe a UTF-8 problem?)");
avahi_server_set_errno(e->server, AVAHI_ERR_INVALID_PACKET);
}
finish:
-
+
if (l && !l->dead) {
if (l->callback)
l->callback(e, final_event, AVAHI_LOOKUP_RESULT_WIDE_AREA, NULL, l->userdata);
static void socket_event(AVAHI_GCC_UNUSED AvahiWatch *w, int fd, AVAHI_GCC_UNUSED AvahiWatchEvent events, void *userdata) {
AvahiWideAreaLookupEngine *e = userdata;
AvahiDnsPacket *p = NULL;
-
+
if (fd == e->fd_ipv4)
p = avahi_recv_dns_packet_ipv4(e->fd_ipv4, NULL, NULL, NULL, NULL, NULL);
else {
AvahiWideAreaLookupEngine *avahi_wide_area_engine_new(AvahiServer *s) {
AvahiWideAreaLookupEngine *e;
-
+
assert(s);
e = avahi_new(AvahiWideAreaLookupEngine, 1);
if (e->fd_ipv4 >= 0)
close(e->fd_ipv4);
-
+
avahi_free(e);
return NULL;
}
/* Create watches */
e->watch_ipv4 = e->watch_ipv6 = NULL;
-
+
if (e->fd_ipv4 >= 0)
e->watch_ipv4 = s->poll_api->watch_new(e->server->poll_api, e->fd_ipv4, AVAHI_WATCH_IN, socket_event, e);
if (e->fd_ipv6 >= 0)
void avahi_wide_area_engine_free(AvahiWideAreaLookupEngine *e) {
assert(e);
-
+
avahi_wide_area_clear_cache(e);
while (e->lookups)
lookup_destroy(e->lookups);
-
+
avahi_hashmap_free(e->cache_by_key);
avahi_hashmap_free(e->lookups_by_id);
avahi_hashmap_free(e->lookups_by_key);
if (e->fd_ipv6 >= 0)
close(e->fd_ipv6);
-
+
if (e->fd_ipv4 >= 0)
close(e->fd_ipv4);
assert(e);
if (a) {
- for (e->n_dns_servers = 0; n > 0 && e->n_dns_servers < AVAHI_WIDE_AREA_SERVERS_MAX; a++, n--)
+ for (e->n_dns_servers = 0; n > 0 && e->n_dns_servers < AVAHI_WIDE_AREA_SERVERS_MAX; a++, n--)
if ((a->proto == AVAHI_PROTO_INET && e->fd_ipv4 >= 0) || (a->proto == AVAHI_PROTO_INET6 && e->fd_ipv6 >= 0))
e->dns_servers[e->n_dns_servers++] = *a;
} else {
assert(n == 0);
e->n_dns_servers = 0;
}
-
+
e->current_dns_server = 0;
avahi_wide_area_clear_cache(e);
void avahi_wide_area_cache_dump(AvahiWideAreaLookupEngine *e, AvahiDumpCallback callback, void* userdata) {
AvahiWideAreaCacheEntry *c;
-
+
assert(e);
assert(callback);
callback(";; WIDE AREA CACHE ;;; ", userdata);
-
+
for (c = e->cache; c; c = c->cache_next) {
char *t = avahi_record_to_string(c->record);
callback(t, userdata);
AvahiWideAreaCacheEntry *c;
AvahiKey *cname_key;
unsigned n = 0;
-
+
assert(e);
assert(key);
assert(callback);
callback(e, AVAHI_BROWSER_NEW, AVAHI_LOOKUP_RESULT_WIDE_AREA|AVAHI_LOOKUP_RESULT_CACHED, c->record, userdata);
n++;
}
-
+
avahi_key_unref(cname_key);
}
}
-
+
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
int ret = 0;
cap_t caps;
static cap_value_t cap_values[] = { CAP_SYS_CHROOT, CAP_SETUID, CAP_SETGID };
-
+
/* Let's reduce our caps to the minimum set and tell Linux to keep
* them across setuid(). This is called before we drop
* privileges. */
-
+
caps = cap_init();
assert(caps);
cap_clear(caps);
cap_set_flag(caps, CAP_EFFECTIVE, 3, cap_values, CAP_SET);
cap_set_flag(caps, CAP_PERMITTED, 3, cap_values, CAP_SET);
-
+
if (cap_set_proc(caps) < 0) {
avahi_log_error("cap_set_proc() failed: %s", strerror(errno));
ret = -1;
/* Reduce our caps to the bare minimum and tell Linux not to keep
* them across setuid(). This is called after we drop
* privileges. */
-
+
/* No longer retain caps across setuid() */
if (prctl(PR_SET_KEEPCAPS, 0, 0, 0, 0) < 0) {
avahi_log_error("prctl(PR_SET_KEEPCAPS) failed: %s", strerror(errno));
caps = cap_init();
assert(caps);
cap_clear(caps);
-
+
if (cap_set_proc(caps) < 0) {
avahi_log_error("cap_set_proc() failed: %s", strerror(errno));
ret = -1;
}
cap_free(caps);
-
+
return ret;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
} cmsg;
/* Send a file descriptor over the socket */
-
+
memset(&iov, 0, sizeof(iov));
memset(&msg, 0, sizeof(msg));
memset(&cmsg, 0, sizeof(cmsg));
-
- iov.iov_base = &dummy;
+
+ iov.iov_base = &dummy;
iov.iov_len = sizeof(dummy);
-
+
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_name = NULL;
msg.msg_control = &cmsg;
msg.msg_controllen = sizeof(cmsg);
msg.msg_flags = 0;
-
+
cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(int));
cmsg.hdr.cmsg_level = SOL_SOCKET;
cmsg.hdr.cmsg_type = SCM_RIGHTS;
memset(&iov, 0, sizeof(iov));
memset(&msg, 0, sizeof(msg));
memset(&cmsg, 0, sizeof(cmsg));
-
+
iov.iov_base = &dummy;
iov.iov_len = sizeof(dummy);
-
+
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_name = NULL;
msg.msg_control = cmsg.buf;
msg.msg_controllen = sizeof(cmsg);
msg.msg_flags = 0;
-
+
cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(int));
cmsg.hdr.cmsg_level = SOL_SOCKET;
cmsg.hdr.cmsg_type = SCM_RIGHTS;
*((int*) CMSG_DATA(&cmsg.hdr)) = -1;
-
+
if (recvmsg(fd, &msg, 0) <= 0) {
avahi_log_error("recvmsg() failed: %s", strerror(errno));
return -1;
errno = EINVAL;
return -1;
}
-
+
if (!(h = CMSG_FIRSTHDR(&msg))) {
avahi_log_error("recvmsg() sent no fd.");
errno = EINVAL;
return *((int*)CMSG_DATA(h));
}
}
-
+
static int helper_main(int fd) {
int ret = 1;
assert(fd >= 0);
* mind that this code is security sensitive! */
avahi_log_debug(__FILE__": chroot() helper started");
-
+
for (;;) {
uint8_t command;
ssize_t r;
/* EOF? */
if (r == 0)
break;
-
+
avahi_log_error(__FILE__": read() failed: %s", strerror(errno));
goto fail;
}
avahi_log_error(__FILE__": write() failed: %s\n", strerror(errno));
goto fail;
}
-
+
break;
}
goto fail;
close(payload);
-
+
break;
}
case AVAHI_CHROOT_UNLINK_SOCKET:
case AVAHI_CHROOT_UNLINK_PID: {
uint8_t c = AVAHI_CHROOT_SUCCESS;
-
+
unlink(unlink_file_name_table[(int) command]);
if (write(fd, &c, sizeof(c)) != sizeof(c)) {
avahi_log_error(__FILE__": write() failed: %s\n", strerror(errno));
goto fail;
}
-
+
break;
}
-
+
default:
avahi_log_error(__FILE__": Unknown command %02x.", command);
break;
}
ret = 0;
-
+
fail:
avahi_log_debug(__FILE__": chroot() helper exiting with return value %i", ret);
-
+
return ret;
}
pid_t pid;
assert(helper_fd < 0);
-
+
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sock) < 0) {
avahi_log_error("socketpair() failed: %s", strerror(errno));
return -1;
}
-
+
if ((pid = fork()) < 0) {
close(sock[0]);
close(sock[1]);
} else if (pid == 0) {
setsid();
-
+
/* Drop all remaining capabilities */
avahi_caps_drop_all();
avahi_set_proc_title(argv0, "%s: chroot helper", argv0);
daemon_retval_done();
-
+
close(sock[0]);
helper_main(sock[1]);
_exit(0);
if (helper_fd >= 0) {
uint8_t command;
-
+
for (command = 2; command < AVAHI_CHROOT_MAX; command++)
if (get_file_name_table[(int) command] &&
strcmp(fname, get_file_name_table[(int) command]) == 0)
}
assert(get_file_name_table[(int) command]);
-
+
if (write(helper_fd, &command, sizeof(command)) < 0) {
avahi_log_error("write() failed: %s\n", strerror(errno));
return -1;
if (helper_fd >= 0) {
uint8_t c, command;
ssize_t r;
-
+
for (command = 2; command < AVAHI_CHROOT_MAX; command++)
if (unlink_file_name_table[(int) command] &&
strcmp(fname, unlink_file_name_table[(int) command]) == 0)
avahi_log_error("read() failed: %s\n", r < 0 ? strerror(errno) : "EOF");
return -1;
}
-
+
return 0;
-
+
} else
-
+
return unlink(fname);
-
+
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
dbus_connection_unregister_object_path(server->bus, i->path);
avahi_free(i->path);
}
-
+
AVAHI_LLIST_REMOVE(AsyncAddressResolverInfo, async_address_resolvers, i->client->async_address_resolvers, i);
i->client->n_objects--;
void avahi_dbus_async_address_resolver_callback(AvahiSAddressResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const AvahiAddress *address, const char *host_name, AvahiLookupResultFlags flags, void* userdata) {
AsyncAddressResolverInfo *i = userdata;
DBusMessage *reply;
-
+
assert(r);
assert(i);
reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, avahi_dbus_map_resolve_signal_name(event));
-
+
if (event == AVAHI_RESOLVER_FOUND) {
char t[AVAHI_ADDRESS_STR_MAX], *pt = t;
int32_t i_interface, i_protocol, i_aprotocol;
i_protocol = (int32_t) protocol;
i_aprotocol = (int32_t) address->proto;
u_flags = (uint32_t) flags;
-
+
dbus_message_append_args(
reply,
DBUS_TYPE_INT32, &i_interface,
avahi_dbus_append_server_error(reply);
}
- dbus_message_set_destination(reply, i->client->name);
+ dbus_message_set_destination(reply, i->client->name);
dbus_connection_send(server->bus, reply, NULL);
dbus_message_unref(reply);
}
assert(c);
assert(m);
assert(i);
-
+
dbus_error_init(&error);
avahi_log_debug(__FILE__": interface=%s, path=%s, member=%s",
/* Introspection */
if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
return avahi_dbus_handle_introspect(c, m, "AddressResolver.introspect");
-
+
/* Access control */
- if (strcmp(dbus_message_get_sender(m), i->client->name))
+ if (strcmp(dbus_message_get_sender(m), i->client->name))
return avahi_dbus_respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
-
+
if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, "Free")) {
if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
avahi_dbus_async_address_resolver_free(i);
return avahi_dbus_respond_ok(c, m);
}
-
+
avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
fail:
if (dbus_error_is_set(&error))
dbus_error_free(&error);
-
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
void avahi_dbus_async_host_name_resolver_callback(AvahiSHostNameResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const char *host_name, const AvahiAddress *a, AvahiLookupResultFlags flags, void* userdata) {
AsyncHostNameResolverInfo *i = userdata;
DBusMessage *reply;
-
+
assert(r);
assert(i);
reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_HOST_NAME_RESOLVER, avahi_dbus_map_resolve_signal_name(event));
-
+
if (event == AVAHI_RESOLVER_FOUND) {
char t[AVAHI_ADDRESS_STR_MAX], *pt = t;
int32_t i_interface, i_protocol, i_aprotocol;
i_protocol = (int32_t) protocol;
i_aprotocol = (int32_t) a->proto;
u_flags = (uint32_t) flags;
-
+
dbus_message_append_args(
reply,
DBUS_TYPE_INT32, &i_interface,
avahi_dbus_append_server_error(reply);
}
- dbus_message_set_destination(reply, i->client->name);
+ dbus_message_set_destination(reply, i->client->name);
dbus_connection_send(server->bus, reply, NULL);
dbus_message_unref(reply);
}
assert(c);
assert(m);
assert(i);
-
+
dbus_error_init(&error);
avahi_log_debug(__FILE__": interface=%s, path=%s, member=%s",
/* Introspection */
if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
return avahi_dbus_handle_introspect(c, m, "HostNameResolver.introspect");
-
+
/* Access control */
- if (strcmp(dbus_message_get_sender(m), i->client->name))
+ if (strcmp(dbus_message_get_sender(m), i->client->name))
return avahi_dbus_respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
-
+
if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_HOST_NAME_RESOLVER, "Free")) {
if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
avahi_dbus_async_host_name_resolver_free(i);
return avahi_dbus_respond_ok(c, m);
}
-
+
avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
fail:
if (dbus_error_is_set(&error))
dbus_error_free(&error);
-
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
dbus_connection_unregister_object_path(server->bus, i->path);
avahi_free(i->path);
}
-
+
AVAHI_LLIST_REMOVE(AsyncServiceResolverInfo, async_service_resolvers, i->client->async_service_resolvers, i);
i->client->n_objects--;
const AvahiAddress *a,
uint16_t port,
AvahiStringList *txt,
- AvahiLookupResultFlags flags,
+ AvahiLookupResultFlags flags,
void* userdata) {
AsyncServiceResolverInfo *i = userdata;
DBusMessage *reply;
-
+
assert(r);
assert(i);
reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_SERVICE_RESOLVER, avahi_dbus_map_resolve_signal_name(event));
-
+
if (event == AVAHI_RESOLVER_FOUND) {
char t[AVAHI_ADDRESS_STR_MAX], *pt = t;
int32_t i_interface, i_protocol, i_aprotocol;
uint32_t u_flags;
-
+
assert(host_name);
/* avahi_log_debug(__FILE__": [%s] Successfully resolved service <%s.%s.%s>", i->path, name, type, domain); */
-
+
if (a)
avahi_address_snprint(t, sizeof(t), a);
else
i_interface = (int32_t) interface;
i_protocol = (int32_t) protocol;
- if (a)
+ if (a)
i_aprotocol = (int32_t) a->proto;
- else
+ else
i_aprotocol = AVAHI_PROTO_UNSPEC;
u_flags = (uint32_t) flags;
avahi_dbus_append_server_error(reply);
}
- dbus_message_set_destination(reply, i->client->name);
+ dbus_message_set_destination(reply, i->client->name);
dbus_connection_send(server->bus, reply, NULL);
dbus_message_unref(reply);
}
assert(c);
assert(m);
assert(i);
-
+
dbus_error_init(&error);
avahi_log_debug(__FILE__": interface=%s, path=%s, member=%s",
/* Introspection */
if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
return avahi_dbus_handle_introspect(c, m, "ServiceResolver.introspect");
-
+
/* Access control */
- if (strcmp(dbus_message_get_sender(m), i->client->name))
+ if (strcmp(dbus_message_get_sender(m), i->client->name))
return avahi_dbus_respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
-
+
if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVICE_RESOLVER, "Free")) {
if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
avahi_dbus_async_service_resolver_free(i);
return avahi_dbus_respond_ok(c, m);
}
-
+
avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
fail:
if (dbus_error_is_set(&error))
dbus_error_free(&error);
-
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
dbus_connection_unregister_object_path(server->bus, i->path);
avahi_free(i->path);
}
-
+
AVAHI_LLIST_REMOVE(DomainBrowserInfo, domain_browsers, i->client->domain_browsers, i);
i->client->n_objects--;
assert(c);
assert(m);
assert(i);
-
+
dbus_error_init(&error);
avahi_log_debug(__FILE__": interface=%s, path=%s, member=%s",
/* Introspection */
if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
return avahi_dbus_handle_introspect(c, m, "DomainBrowser.introspect");
-
+
/* Access control */
- if (strcmp(dbus_message_get_sender(m), i->client->name))
+ if (strcmp(dbus_message_get_sender(m), i->client->name))
return avahi_dbus_respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
-
+
if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "Free")) {
if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
avahi_dbus_domain_browser_free(i);
return avahi_dbus_respond_ok(c, m);
-
+
}
-
+
avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
fail:
if (dbus_error_is_set(&error))
dbus_error_free(&error);
-
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
DBusMessage *m;
int32_t i_interface, i_protocol;
uint32_t u_flags;
-
+
assert(b);
assert(i);
DBUS_TYPE_INVALID);
} else if (event == AVAHI_BROWSER_FAILURE)
avahi_dbus_append_server_error(m);
-
- dbus_message_set_destination(m, i->client->name);
+
+ dbus_message_set_destination(m, i->client->name);
dbus_connection_send(server->bus, m, NULL);
dbus_message_unref(m);
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
i->client->n_objects--;
assert(i->client->n_objects >= 0);
-
+
avahi_free(i);
}
DBusMessage *m;
int32_t t;
const char *e;
-
+
assert(s);
assert(g);
assert(i);
m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "StateChanged");
-
+
t = (int32_t) state;
if (state == AVAHI_ENTRY_GROUP_FAILURE)
e = avahi_error_number_to_dbus(avahi_server_errno(s));
e = AVAHI_DBUS_ERR_COLLISION;
else
e = AVAHI_DBUS_ERR_OK;
-
+
dbus_message_append_args(
m,
DBUS_TYPE_INT32, &t,
DBUS_TYPE_STRING, &e,
DBUS_TYPE_INVALID);
- dbus_message_set_destination(m, i->client->name);
+ dbus_message_set_destination(m, i->client->name);
dbus_connection_send(server->bus, m, NULL);
dbus_message_unref(m);
}
assert(c);
assert(m);
assert(i);
-
+
dbus_error_init(&error);
avahi_log_debug(__FILE__": interface=%s, path=%s, member=%s",
/* Introspection */
if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
return avahi_dbus_handle_introspect(c, m, "EntryGroup.introspect");
-
+
/* Access control */
- if (strcmp(dbus_message_get_sender(m), i->client->name))
+ if (strcmp(dbus_message_get_sender(m), i->client->name))
return avahi_dbus_respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
-
+
if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "Free")) {
if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
avahi_dbus_entry_group_free(i);
return avahi_dbus_respond_ok(c, m);
-
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "Commit")) {
if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
if (avahi_s_entry_group_commit(i->entry_group) < 0)
return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL);
-
+
return avahi_dbus_respond_ok(c, m);
-
-
+
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "Reset")) {
-
+
if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
avahi_log_warn("Error parsing EntryGroup::Reset message");
goto fail;
avahi_s_entry_group_reset(i->entry_group);
i->n_entries = 0;
return avahi_dbus_respond_ok(c, m);
-
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "IsEmpty")) {
if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
}
return avahi_dbus_respond_boolean(c, m, !!avahi_s_entry_group_is_empty(i->entry_group));
-
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "GetState")) {
AvahiEntryGroupState state;
-
+
if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
avahi_log_warn("Error parsing EntryGroup::GetState message");
goto fail;
state = avahi_s_entry_group_get_state(i->entry_group);
return avahi_dbus_respond_int32(c, m, (int32_t) state);
-
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddService")) {
int32_t interface, protocol;
uint32_t flags;
char *type, *name, *domain, *host;
uint16_t port;
AvahiStringList *strlst = NULL;
-
+
if (!dbus_message_get_args(
m, &error,
DBUS_TYPE_INT32, &interface,
DBUS_TYPE_STRING, &type,
DBUS_TYPE_STRING, &domain,
DBUS_TYPE_STRING, &host,
- DBUS_TYPE_UINT16, &port,
+ DBUS_TYPE_UINT16, &port,
DBUS_TYPE_INVALID) ||
!type || !name ||
avahi_dbus_read_strlst(m, 8, &strlst) < 0) {
if (!(flags & AVAHI_PUBLISH_UPDATE))
i->n_entries ++;
-
+
avahi_string_list_free(strlst);
-
+
return avahi_dbus_respond_ok(c, m);
-
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddServiceSubtype")) {
int32_t interface, protocol;
uint32_t flags;
char *type, *name, *domain, *subtype;
-
+
if (!dbus_message_get_args(
m, &error,
DBUS_TYPE_INT32, &interface,
if (domain && !*domain)
domain = NULL;
- if (avahi_server_add_service_subtype(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, (AvahiPublishFlags) flags, name, type, domain, subtype) < 0)
+ if (avahi_server_add_service_subtype(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, (AvahiPublishFlags) flags, name, type, domain, subtype) < 0)
return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL);
if (!(flags & AVAHI_PUBLISH_UPDATE))
i->n_entries ++;
-
+
return avahi_dbus_respond_ok(c, m);
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "UpdateServiceTxt")) {
uint32_t flags;
char *type, *name, *domain;
AvahiStringList *strlst;
-
+
if (!dbus_message_get_args(
m, &error,
DBUS_TYPE_INT32, &interface,
}
avahi_string_list_free(strlst);
-
+
return avahi_dbus_respond_ok(c, m);
-
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddAddress")) {
int32_t interface, protocol;
uint32_t flags;
char *name, *address;
AvahiAddress a;
-
+
if (!dbus_message_get_args(
m, &error,
DBUS_TYPE_INT32, &interface,
if (!(flags & AVAHI_PUBLISH_UPDATE) && i->n_entries >= ENTRIES_PER_ENTRY_GROUP_MAX)
return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_ENTRIES, NULL);
-
+
if (!(avahi_address_parse(address, AVAHI_PROTO_UNSPEC, &a)))
return avahi_dbus_respond_error(c, m, AVAHI_ERR_INVALID_ADDRESS, NULL);
if (!(flags & AVAHI_PUBLISH_UPDATE))
i->n_entries ++;
-
+
return avahi_dbus_respond_ok(c, m);
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddRecord")) {
int32_t interface, protocol;
char *name;
void *rdata;
AvahiRecord *r;
-
+
if (!dbus_message_get_args(
m, &error,
DBUS_TYPE_INT32, &interface,
avahi_record_unref (r);
return avahi_dbus_respond_error(c, m, AVAHI_ERR_INVALID_RDATA, NULL);
}
-
+
if (avahi_server_add(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, (AvahiPublishFlags) flags, r) < 0) {
avahi_record_unref (r);
return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL);
if (!(flags & AVAHI_PUBLISH_UPDATE))
i->n_entries ++;
-
- avahi_record_unref (r);
+
+ avahi_record_unref (r);
return avahi_dbus_respond_ok(c, m);
- }
-
-
+ }
+
+
avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
fail:
if (dbus_error_is_set(&error))
dbus_error_free(&error);
-
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
char *path;
int n_entries;
-
+
AVAHI_LLIST_FIELDS(EntryGroupInfo, entry_groups);
};
char *name;
unsigned current_id;
int n_objects;
-
+
AVAHI_LLIST_FIELDS(Client, clients);
AVAHI_LLIST_HEAD(EntryGroupInfo, entry_groups);
AVAHI_LLIST_HEAD(SyncHostNameResolverInfo, sync_host_name_resolvers);
const AvahiAddress *a,
uint16_t port,
AvahiStringList *txt,
- AvahiLookupResultFlags flags,
+ AvahiLookupResultFlags flags,
void* userdata);
void avahi_dbus_async_service_resolver_free(AsyncServiceResolverInfo *i);
const AvahiAddress *a,
uint16_t port,
AvahiStringList *txt,
- AvahiLookupResultFlags flags,
+ AvahiLookupResultFlags flags,
void* userdata);
DBusHandlerResult avahi_dbus_msg_async_service_resolver_impl(DBusConnection *c, DBusMessage *m, void *userdata);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
static void dbus_disconnect(void);
static void client_free(Client *c) {
-
+
assert(server);
assert(c);
while (c->async_host_name_resolvers)
avahi_dbus_async_host_name_resolver_free(c->async_host_name_resolvers);
-
+
while (c->sync_address_resolvers)
avahi_dbus_sync_address_resolver_free(c->sync_address_resolvers);
avahi_dbus_record_browser_free(c->record_browsers);
assert(c->n_objects == 0);
-
+
avahi_free(c->name);
AVAHI_LLIST_REMOVE(Client, clients, server->clients, c);
avahi_free(c);
if (server->n_clients >= CLIENTS_MAX)
return NULL;
-
+
/* If not existent yet, create a new entry */
client = avahi_new(Client, 1);
client->id = server->current_id++;
client->name = avahi_strdup(name);
client->current_id = 0;
client->n_objects = 0;
-
+
AVAHI_LLIST_HEAD_INIT(EntryGroupInfo, client->entry_groups);
AVAHI_LLIST_HEAD_INIT(SyncHostNameResolverInfo, client->sync_host_name_resolvers);
AVAHI_LLIST_HEAD_INIT(AsyncHostNameResolverInfo, client->async_host_name_resolvers);
server->n_clients++;
assert(server->n_clients > 0);
-
+
return client;
}
if (server->reconnect) {
avahi_log_warn("Disconnected from D-Bus, trying to reconnect in %ims...", RECONNECT_MSEC);
-
+
dbus_disconnect();
-
+
avahi_elapse_time(&tv, RECONNECT_MSEC, 0);
-
+
if (server->reconnect_timeout)
server->poll_api->timeout_update(server->reconnect_timeout, &tv);
else
avahi_log_warn("Disconnected from D-Bus, exiting.");
raise(SIGQUIT);
}
-
+
return DBUS_HANDLER_RESULT_HANDLED;
-
+
} else if (dbus_message_is_signal(m, DBUS_INTERFACE_DBUS, "NameAcquired")) {
char *name;
/* avahi_log_info(__FILE__": name acquired (%s)", name); */
return DBUS_HANDLER_RESULT_HANDLED;
-
+
} else if (dbus_message_is_signal(m, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
char *name, *old, *new;
Client *client;
if ((client = client_get(name, FALSE))) {
- avahi_log_debug(__FILE__": client %s vanished.", name);
+ avahi_log_debug(__FILE__": client %s vanished.", name);
client_free(client);
}
}
fail:
if (dbus_error_is_set(&error))
dbus_error_free(&error);
-
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
return avahi_dbus_handle_introspect(c, m, "Server.introspect");
-
+
else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetHostName")) {
if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
}
return avahi_dbus_respond_string(c, m, avahi_server_get_host_name(avahi_server));
-
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "SetHostName")) {
char *name;
-
+
if (!dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) {
avahi_log_warn("Error parsing Server::SetHostName message");
goto fail;
}
-
- if (avahi_server_set_host_name(avahi_server, name) < 0)
+
+ if (avahi_server_set_host_name(avahi_server, name) < 0)
return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL);
avahi_log_info("Changing host name to '%s'.", name);
-
+
return avahi_dbus_respond_ok(c, m);
-
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetDomainName")) {
if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
avahi_log_warn("Error parsing Server::GetHostNameFqdn message");
goto fail;
}
-
+
return avahi_dbus_respond_string(c, m, avahi_server_get_host_name_fqdn(avahi_server));
-
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "IsNSSSupportAvailable")) {
if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) {
avahi_log_warn("Error parsing Server::IsNSSSupportAvailable message");
}
return avahi_dbus_respond_boolean(c, m, nss_support);
-
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetVersionString")) {
if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) {
avahi_log_warn("Error parsing Server::GetVersionString message");
goto fail;
}
-
+
return avahi_dbus_respond_string(c, m, PACKAGE_STRING);
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetAPIVersion")) {
avahi_log_warn("Error parsing Server::GetAPIVersion message");
goto fail;
}
-
+
return avahi_dbus_respond_uint32(c, m, AVAHI_DBUS_API_VERSION);
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetState")) {
AvahiServerState state;
-
+
if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) {
avahi_log_warn("Error parsing Server::GetState message");
goto fail;
}
-
+
state = avahi_server_get_state(avahi_server);
return avahi_dbus_respond_int32(c, m, (int32_t) state);
avahi_log_warn("Error parsing Server::GetLocalServiceCookie message");
goto fail;
}
-
+
return avahi_dbus_respond_uint32(c, m, avahi_server_get_local_service_cookie(avahi_server));
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetNetworkInterfaceNameByIndex")) {
int32_t idx;
char name[IF_NAMESIZE];
-
+
if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INT32, &idx, DBUS_TYPE_INVALID))) {
avahi_log_warn("Error parsing Server::GetNetworkInterfaceNameByIndex message");
goto fail;
snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
return avahi_dbus_respond_error(c, m, AVAHI_ERR_OS, txt);
}
-
+
return avahi_dbus_respond_string(c, m, name);
#endif
-
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetNetworkInterfaceIndexByName")) {
char *n;
int32_t idx;
-
+
if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) {
avahi_log_warn("Error parsing Server::GetNetworkInterfaceIndexByName message");
goto fail;
snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
return avahi_dbus_respond_error(c, m, AVAHI_ERR_OS, txt);
}
-
+
return avahi_dbus_respond_int32(c, m, idx);
#endif
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetAlternativeHostName")) {
char *n, * t;
-
+
if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) {
avahi_log_warn("Error parsing Server::GetAlternativeHostName message");
goto fail;
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetAlternativeServiceName")) {
char *n, *t;
-
+
if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) {
avahi_log_warn("Error parsing Server::GetAlternativeServiceName message");
goto fail;
avahi_free(t);
return DBUS_HANDLER_RESULT_HANDLED;
-
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "EntryGroupNew")) {
Client *client;
EntryGroupInfo *i;
if (disable_user_service_publishing)
return avahi_dbus_respond_error(c, m, AVAHI_ERR_NOT_PERMITTED, NULL);
-
+
if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
avahi_log_warn("Too many clients, client request failed.");
return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
i->n_entries = 0;
AVAHI_LLIST_PREPEND(EntryGroupInfo, entry_groups, client->entry_groups, i);
client->n_objects++;
-
+
if (!(i->entry_group = avahi_s_entry_group_new(avahi_server, avahi_dbus_entry_group_callback, i))) {
avahi_dbus_entry_group_free(i);
return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL);
i->path = avahi_strdup_printf("/Client%u/EntryGroup%u", client->id, i->id);
dbus_connection_register_object_path(c, i->path, &vtable, i);
return avahi_dbus_respond_path(c, m, i->path);
-
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ResolveHostName")) {
Client *client;
int32_t interface, protocol, aprotocol;
uint32_t flags;
char *name;
SyncHostNameResolverInfo *i;
-
+
if (!dbus_message_get_args(
m, &error,
DBUS_TYPE_INT32, &interface,
avahi_dbus_sync_host_name_resolver_free(i);
return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL);
}
-
+
return DBUS_HANDLER_RESULT_HANDLED;
-
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ResolveAddress")) {
Client *client;
int32_t interface, protocol;
char *address;
SyncAddressResolverInfo *i;
AvahiAddress a;
-
+
if (!dbus_message_get_args(
m, &error,
DBUS_TYPE_INT32, &interface,
DBUS_TYPE_INT32, &protocol,
DBUS_TYPE_STRING, &address,
- DBUS_TYPE_UINT32, &flags,
+ DBUS_TYPE_UINT32, &flags,
DBUS_TYPE_INVALID) || !address) {
avahi_log_warn("Error parsing Server::ResolveAddress message");
goto fail;
avahi_dbus_sync_address_resolver_free(i);
return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL);
}
-
+
return DBUS_HANDLER_RESULT_HANDLED;
-
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "DomainBrowserNew")) {
Client *client;
DomainBrowserInfo *i;
int32_t interface, protocol, type;
uint32_t flags;
char *domain;
-
+
if (!dbus_message_get_args(
m, &error,
DBUS_TYPE_INT32, &interface,
int32_t interface, protocol;
uint32_t flags;
char *domain;
-
+
if (!dbus_message_get_args(
m, &error,
DBUS_TYPE_INT32, &interface,
avahi_dbus_service_type_browser_free(i);
return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL);
}
-
+
i->path = avahi_strdup_printf("/Client%u/ServiceTypeBrowser%u", client->id, i->id);
dbus_connection_register_object_path(c, i->path, &vtable, i);
return avahi_dbus_respond_path(c, m, i->path);
-
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ServiceBrowserNew")) {
Client *client;
ServiceBrowserInfo *i;
int32_t interface, protocol;
uint32_t flags;
char *domain, *type;
-
+
if (!dbus_message_get_args(
m, &error,
DBUS_TYPE_INT32, &interface,
i->path = avahi_strdup_printf("/Client%u/ServiceBrowser%u", client->id, i->id);
dbus_connection_register_object_path(c, i->path, &vtable, i);
return avahi_dbus_respond_path(c, m, i->path);
-
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ResolveService")) {
Client *client;
int32_t interface, protocol, aprotocol;
uint32_t flags;
char *name, *type, *domain;
SyncServiceResolverInfo *i;
-
+
if (!dbus_message_get_args(
m, &error,
DBUS_TYPE_INT32, &interface,
avahi_log_warn("Too many clients, client request failed.");
return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
}
-
+
if (client->n_objects >= OBJECTS_PER_CLIENT_MAX) {
avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
if (!*name)
name = NULL;
-
+
i = avahi_new(SyncServiceResolverInfo, 1);
i->client = client;
i->message = dbus_message_ref(m);
avahi_dbus_sync_service_resolver_free(i);
return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL);
}
-
+
return DBUS_HANDLER_RESULT_HANDLED;
-
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ServiceResolverNew")) {
Client *client;
int32_t interface, protocol, aprotocol;
avahi_log_warn("Error parsing Server::ServiceResolverNew message");
goto fail;
}
-
+
if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
avahi_log_warn(__FILE__": Too many clients, client request failed.");
return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
if (!*name)
name = NULL;
-
+
i = avahi_new(AsyncServiceResolverInfo, 1);
i->id = ++client->current_id;
i->client = client;
}
/* avahi_log_debug(__FILE__": [%s], new service resolver for <%s.%s.%s>", i->path, name, type, domain); */
-
+
i->path = avahi_strdup_printf("/Client%u/ServiceResolver%u", client->id, i->id);
dbus_connection_register_object_path(c, i->path, &vtable, i);
return avahi_dbus_respond_path(c, m, i->path);
NULL,
NULL
};
-
+
if (!dbus_message_get_args(
m, &error,
DBUS_TYPE_INT32, &interface,
avahi_log_warn("Error parsing Server::HostNameResolverNew message");
goto fail;
}
-
+
if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
avahi_log_warn(__FILE__": Too many clients, client request failed.");
return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
NULL,
NULL
};
-
+
if (!dbus_message_get_args(
m, &error,
DBUS_TYPE_INT32, &interface,
i->path = avahi_strdup_printf("/Client%u/AddressResolver%u", client->id, i->id);
dbus_connection_register_object_path(c, i->path, &vtable, i);
return avahi_dbus_respond_path(c, m, i->path);
-
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "RecordBrowserNew")) {
Client *client;
RecordBrowserInfo *i;
char *name;
uint16_t type, clazz;
AvahiKey *key;
-
+
if (!dbus_message_get_args(
m, &error,
DBUS_TYPE_INT32, &interface,
goto fail;
}
- if (!avahi_is_valid_domain_name(name))
+ if (!avahi_is_valid_domain_name(name))
return avahi_dbus_respond_error(c, m, AVAHI_ERR_INVALID_DOMAIN_NAME, NULL);
if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
}
avahi_key_unref(key);
-
+
i->path = avahi_strdup_printf("/Client%u/RecordBrowser%u", client->id, i->id);
dbus_connection_register_object_path(c, i->path, &vtable, i);
return avahi_dbus_respond_path(c, m, i->path);
fail:
if (dbus_error_is_set(&error))
dbus_error_free(&error);
-
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
DBusMessage *m;
int32_t t;
const char *e;
-
+
if (!server || !server->bus)
return;
e = avahi_error_number_to_dbus(avahi_server_errno(avahi_server));
else
e = AVAHI_DBUS_ERR_OK;
-
+
dbus_message_append_args(m, DBUS_TYPE_INT32, &t, DBUS_TYPE_STRING, &e, DBUS_TYPE_INVALID);
dbus_connection_send(server->bus, m, NULL);
dbus_message_unref(m);
dbus_error_init(&error);
-#ifdef HAVE_DBUS_BUS_GET_PRIVATE
+#ifdef HAVE_DBUS_BUS_GET_PRIVATE
if (!(server->bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error))) {
assert(dbus_error_is_set(&error));
avahi_log_error("dbus_bus_get_private(): %s", error.message);
if (!(a = getenv("DBUS_SYSTEM_BUS_ADDRESS")) || !*a)
a = DBUS_SYSTEM_BUS_DEFAULT_ADDRESS;
-
+
if (!(server->bus = dbus_connection_open_private(a, &error))) {
assert(dbus_error_is_set(&error));
avahi_log_error("dbus_bus_open_private(): %s", error.message);
}
}
#endif
-
+
if (avahi_dbus_connection_glue(server->bus, server->poll_api) < 0) {
avahi_log_error("avahi_dbus_connection_glue() failed");
goto fail;
}
dbus_connection_set_exit_on_disconnect(server->bus, FALSE);
-
+
if (dbus_bus_request_name(
server->bus,
AVAHI_DBUS_NAME,
avahi_log_error("dbus_connection_add_filter() failed");
goto fail;
}
-
+
dbus_bus_add_match(server->bus, "type='signal',""interface='" DBUS_INTERFACE_DBUS "'", &error);
if (dbus_error_is_set(&error)) {
avahi_log_error("dbus_bus_add_match(): %s", error.message);
goto fail;
}
-
+
if (!(dbus_connection_register_object_path(server->bus, AVAHI_DBUS_PATH_SERVER, &server_vtable, NULL))) {
avahi_log_error("dbus_connection_register_object_path() failed");
goto fail;
while (server->clients)
client_free(server->clients);
-
+
assert(server->n_clients == 0);
if (server->bus) {
goto fail;
avahi_log_warn("WARNING: Failed to contact D-Bus daemon, retrying in %ims.", RECONNECT_MSEC);
-
+
avahi_elapse_time(&tv, RECONNECT_MSEC, 0);
server->reconnect_timeout = server->poll_api->timeout_new(server->poll_api, &tv, reconnect_callback, NULL);
}
-
+
return 0;
fail:
if (server->reconnect_timeout)
server->poll_api->timeout_free(server->reconnect_timeout);
-
+
avahi_free(server);
server = NULL;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
assert(c);
assert(m);
assert(i);
-
+
dbus_error_init(&error);
avahi_log_debug(__FILE__": interface=%s, path=%s, member=%s",
/* Introspection */
if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
return avahi_dbus_handle_introspect(c, m, "RecordBrowser.introspect");
-
+
/* Access control */
- if (strcmp(dbus_message_get_sender(m), i->client->name))
+ if (strcmp(dbus_message_get_sender(m), i->client->name))
return avahi_dbus_respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
-
+
if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_RECORD_BROWSER, "Free")) {
if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
avahi_dbus_record_browser_free(i);
return avahi_dbus_respond_ok(c, m);
-
+
}
-
+
avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
fail:
if (dbus_error_is_set(&error))
dbus_error_free(&error);
-
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
AvahiRecord *record,
AvahiLookupResultFlags flags,
void* userdata) {
-
+
RecordBrowserInfo *i = userdata;
DBusMessage *m = NULL;
int32_t i_interface, i_protocol;
uint32_t u_flags;
-
+
assert(b);
assert(i);
uint8_t rdata[0xFFFF];
size_t size;
assert(record);
-
+
if (!(dbus_message_append_args(
m,
DBUS_TYPE_INT32, &i_interface,
DBUS_TYPE_UINT16, &record->key->type,
DBUS_TYPE_INVALID)))
goto fail;
-
+
if ((size = avahi_rdata_serialize(record, rdata, sizeof(rdata))) == (size_t) -1 ||
avahi_dbus_append_rdata(m, rdata, size) < 0) {
avahi_log_debug(__FILE__": Failed to append rdata");
dbus_message_unref(m);
return;
}
-
+
dbus_message_append_args(
m,
DBUS_TYPE_UINT32, &u_flags,
DBUS_TYPE_INVALID);
-
+
} else if (event == AVAHI_BROWSER_FAILURE)
avahi_dbus_append_server_error(m);
-
- dbus_message_set_destination(m, i->client->name);
+
+ dbus_message_set_destination(m, i->client->name);
dbus_connection_send(server->bus, m, NULL);
dbus_message_unref(m);
return;
-
+
fail:
if (m)
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
dbus_connection_unregister_object_path(server->bus, i->path);
avahi_free(i->path);
}
-
+
AVAHI_LLIST_REMOVE(ServiceBrowserInfo, service_browsers, i->client->service_browsers, i);
i->client->n_objects--;
assert(c);
assert(m);
assert(i);
-
+
dbus_error_init(&error);
avahi_log_debug(__FILE__": interface=%s, path=%s, member=%s",
/* Introspection */
if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
return avahi_dbus_handle_introspect(c, m, "ServiceBrowser.introspect");
-
+
/* Access control */
- if (strcmp(dbus_message_get_sender(m), i->client->name))
+ if (strcmp(dbus_message_get_sender(m), i->client->name))
return avahi_dbus_respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
-
+
if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, "Free")) {
if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
avahi_dbus_service_browser_free(i);
return avahi_dbus_respond_ok(c, m);
-
+
}
-
+
avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
fail:
if (dbus_error_is_set(&error))
dbus_error_free(&error);
-
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
DBusMessage *m;
int32_t i_interface, i_protocol;
uint32_t u_flags;
-
+
assert(b);
assert(i);
if (avahi_dbus_is_our_own_service(i->client, interface, protocol, name, type, domain) > 0)
flags |= AVAHI_LOOKUP_RESULT_OUR_OWN;
}
-
+
i_interface = (int32_t) interface;
i_protocol = (int32_t) protocol;
u_flags = (uint32_t) flags;
-
+
if (event == AVAHI_BROWSER_NEW || event == AVAHI_BROWSER_REMOVE) {
assert(name);
assert(type);
assert(domain);
-
+
dbus_message_append_args(
m,
DBUS_TYPE_INT32, &i_interface,
DBUS_TYPE_INVALID);
} else if (event == AVAHI_BROWSER_FAILURE)
avahi_dbus_append_server_error(m);
-
- dbus_message_set_destination(m, i->client->name);
+
+ dbus_message_set_destination(m, i->client->name);
dbus_connection_send(server->bus, m, NULL);
dbus_message_unref(m);
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
dbus_connection_unregister_object_path(server->bus, i->path);
avahi_free(i->path);
}
-
+
AVAHI_LLIST_REMOVE(ServiceTypeBrowserInfo, service_type_browsers, i->client->service_type_browsers, i);
i->client->n_objects--;
assert(c);
assert(m);
assert(i);
-
+
dbus_error_init(&error);
avahi_log_debug(__FILE__": interface=%s, path=%s, member=%s",
/* Introspection */
if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
return avahi_dbus_handle_introspect(c, m, "ServiceTypeBrowser.introspect");
-
+
/* Access control */
- if (strcmp(dbus_message_get_sender(m), i->client->name))
+ if (strcmp(dbus_message_get_sender(m), i->client->name))
return avahi_dbus_respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
-
+
if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "Free")) {
if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
avahi_dbus_service_type_browser_free(i);
return avahi_dbus_respond_ok(c, m);
-
+
}
-
+
avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
fail:
if (dbus_error_is_set(&error))
dbus_error_free(&error);
-
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
DBusMessage *m;
int32_t i_interface, i_protocol;
uint32_t u_flags;
-
+
assert(b);
assert(i);
DBUS_TYPE_INVALID);
} else if (event == AVAHI_BROWSER_FAILURE)
avahi_dbus_append_server_error(m);
-
- dbus_message_set_destination(m, i->client->name);
+
+ dbus_message_set_destination(m, i->client->name);
dbus_connection_send(server->bus, m, NULL);
dbus_message_unref(m);
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
void avahi_dbus_sync_address_resolver_callback(AvahiSAddressResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const AvahiAddress *address, const char *host_name, AvahiLookupResultFlags flags, void* userdata) {
SyncAddressResolverInfo *i = userdata;
-
+
assert(r);
assert(address);
assert(i);
i_protocol = (int32_t) protocol;
i_aprotocol = (int32_t) address->proto;
u_flags = (uint32_t) flags;
-
+
reply = dbus_message_new_method_return(i->message);
dbus_message_append_args(
reply,
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
void avahi_dbus_sync_host_name_resolver_callback(AvahiSHostNameResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const char *host_name, const AvahiAddress *a, AvahiLookupResultFlags flags, void* userdata) {
SyncHostNameResolverInfo *i = userdata;
-
+
assert(r);
assert(host_name);
assert(i);
i_protocol = (int32_t) protocol;
i_aprotocol = (int32_t) a->proto;
u_flags = (uint32_t) flags;
-
+
reply = dbus_message_new_method_return(i->message);
dbus_message_append_args(
reply,
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
const AvahiAddress *a,
uint16_t port,
AvahiStringList *txt,
- AvahiLookupResultFlags flags,
+ AvahiLookupResultFlags flags,
void* userdata) {
-
+
SyncServiceResolverInfo *i = userdata;
-
+
assert(r);
assert(i);
int32_t i_interface, i_protocol, i_aprotocol;
uint32_t u_flags;
DBusMessage *reply;
-
+
assert(host_name);
if (!name)
name = "";
- if (a)
+ if (a)
avahi_address_snprint(t, sizeof(t), a);
else
t[0] = 0;
if (avahi_dbus_is_our_own_service(i->client, interface, protocol, name, type, domain) > 0)
flags |= AVAHI_LOOKUP_RESULT_OUR_OWN;
-
+
i_interface = (int32_t) interface;
i_protocol = (int32_t) protocol;
- if (a)
+ if (a)
i_aprotocol = (int32_t) a->proto;
- else
+ else
i_aprotocol = AVAHI_PROTO_UNSPEC;
u_flags = (uint32_t) flags;
DBUS_TYPE_INVALID);
avahi_dbus_append_string_list(reply, txt);
-
+
dbus_message_append_args(
reply,
DBUS_TYPE_UINT32, &u_flags,
dbus_message_unref(reply);
} else {
assert(event == AVAHI_RESOLVER_FAILURE);
-
+
avahi_dbus_respond_error(server->bus, i->message, avahi_server_errno(avahi_server), NULL);
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
if (!text)
text = avahi_strerror(error);
-
+
reply = dbus_message_new_error(m, avahi_error_number_to_dbus(error), text);
dbus_connection_send(c, reply, NULL);
dbus_message_unref(reply);
avahi_log_debug(__FILE__": Responding error '%s' (%i)", text, error);
-
+
return DBUS_HANDLER_RESULT_HANDLED;
}
dbus_message_append_args(reply, DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID);
dbus_connection_send(c, reply, NULL);
dbus_message_unref(reply);
-
+
return DBUS_HANDLER_RESULT_HANDLED;
}
dbus_message_append_args(reply, DBUS_TYPE_INT32, &i, DBUS_TYPE_INVALID);
dbus_connection_send(c, reply, NULL);
dbus_message_unref(reply);
-
+
return DBUS_HANDLER_RESULT_HANDLED;
}
dbus_message_append_args(reply, DBUS_TYPE_UINT32, &u, DBUS_TYPE_INVALID);
dbus_connection_send(c, reply, NULL);
dbus_message_unref(reply);
-
+
return DBUS_HANDLER_RESULT_HANDLED;
}
dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &b, DBUS_TYPE_INVALID);
dbus_connection_send(c, reply, NULL);
dbus_message_unref(reply);
-
+
return DBUS_HANDLER_RESULT_HANDLED;
}
reply = dbus_message_new_method_return(m);
dbus_connection_send(c, reply, NULL);
dbus_message_unref(reply);
-
+
return DBUS_HANDLER_RESULT_HANDLED;
}
dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID);
dbus_connection_send(c, reply, NULL);
dbus_message_unref(reply);
-
+
return DBUS_HANDLER_RESULT_HANDLED;
}
const char *t;
t = avahi_error_number_to_dbus(avahi_server_errno(avahi_server));
-
+
dbus_message_append_args(
reply,
DBUS_TYPE_STRING, &t,
char *buf = NULL;
assert(fname);
-
+
#ifdef ENABLE_CHROOT
fd = avahi_chroot_helper_get_fd(fname);
#else
close(fd);
return buf;
-
+
fail:
if (fd >= 0)
close(fd);
-
+
if (buf)
avahi_free(buf);
return NULL;
-
+
}
DBusHandlerResult avahi_dbus_handle_introspect(DBusConnection *c, DBusMessage *m, const char *fname) {
char *contents, *path;
DBusError error;
-
+
assert(c);
assert(m);
assert(fname);
path = avahi_strdup_printf("%s/%s", AVAHI_DBUS_INTROSPECTION_DIR, fname);
contents = file_get_contents(path);
avahi_free(path);
-
+
if (!contents) {
avahi_log_error("Failed to load introspection data.");
goto fail;
}
-
+
avahi_dbus_respond_string(c, m, contents);
avahi_free(contents);
-
+
return DBUS_HANDLER_RESULT_HANDLED;
fail:
if (dbus_error_is_set(&error))
dbus_error_free(&error);
-
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
void avahi_dbus_append_string_list(DBusMessage *reply, AvahiStringList *txt) {
AvahiStringList *p;
DBusMessageIter iter, sub;
-
+
assert(reply);
dbus_message_iter_init_append(reply, &iter);
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "ay", &sub);
-
+
for (p = txt; p; p = p->next) {
DBusMessageIter sub2;
const uint8_t *data = p->text;
-
+
dbus_message_iter_open_container(&sub, DBUS_TYPE_ARRAY, "y", &sub2);
- dbus_message_iter_append_fixed_array(&sub2, DBUS_TYPE_BYTE, &data, p->size);
+ dbus_message_iter_append_fixed_array(&sub2, DBUS_TYPE_BYTE, &data, p->size);
dbus_message_iter_close_container(&sub, &sub2);
-
+
}
dbus_message_iter_close_container(&iter, &sub);
}
uint8_t *k;
assert(m);
-
+
dbus_message_iter_init(m, &iter);
for (j = 0; j < idx; j++)
dbus_message_iter_next(&iter);
-
+
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_BYTE)
goto fail;
*rdata = k;
*size = n;
-
+
return 0;
-
+
fail:
avahi_log_warn("Error parsing data");
assert(m);
assert(l);
-
+
dbus_message_iter_init(m, &iter);
for (j = 0; j < idx; j++)
dbus_message_iter_next(&iter);
-
+
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_ARRAY)
goto fail;
dbus_message_iter_recurse(&iter, &sub);
-
+
for (;;) {
int at, n;
const uint8_t *k;
DBusMessageIter sub2;
-
+
if ((at = dbus_message_iter_get_arg_type(&sub)) == DBUS_TYPE_INVALID)
break;
-
+
assert(at == DBUS_TYPE_ARRAY);
-
+
if (dbus_message_iter_get_element_type(&sub) != DBUS_TYPE_BYTE)
goto fail;
dbus_message_iter_recurse(&sub, &sub2);
-
+
k = (const uint8_t*) "";
n = 0;
dbus_message_iter_get_fixed_array(&sub2, &k, &n);
if (!k)
k = (const uint8_t*) "";
-
+
strlst = avahi_string_list_add_arbitrary(strlst, k, n);
-
+
dbus_message_iter_next(&sub);
}
*l = strlst;
-
+
return 0;
-
+
fail:
avahi_log_warn("Error parsing TXT data");
int avahi_dbus_append_rdata(DBusMessage *message, const void *rdata, size_t size) {
DBusMessageIter iter, sub;
-
+
assert(message);
-
+
dbus_message_iter_init_append(message, &iter);
-
+
if (!(dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING, &sub)) ||
!(dbus_message_iter_append_fixed_array(&sub, DBUS_TYPE_BYTE, &rdata, size)) ||
!(dbus_message_iter_close_container(&iter, &sub)))
return -1;
-
+
return 0;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
for (i = split; *i; i++)
printf("<%s> ", *i);
-
+
avahi_strfreev(split);
printf("\n");
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
FILE *fo;
AvahiIniFileGroup *group = NULL;
unsigned line;
-
+
assert(fname);
if (!(fo = fopen(fname, "r"))) {
avahi_log_error("Failed to open file '%s': %s", fname, strerror(errno));
return NULL;
}
-
+
f = avahi_new(AvahiIniFile, 1);
AVAHI_LLIST_HEAD_INIT(AvahiIniFileGroup, f->groups);
f->n_groups = 0;
while (!feof(fo)) {
char ln[256], *s, *e;
AvahiIniFilePair *pair;
-
+
if (!(fgets(ln, sizeof(ln), fo)))
break;
line++;
-
+
s = ln + strspn(ln, " \t");
s[strcspn(s, "\r\n")] = 0;
if (*s == '[') {
/* new group */
-
+
if (!(e = strchr(s, ']'))) {
avahi_log_error("Unclosed group header in %s:%u: <%s>", fname, line, s);
goto fail;
}
*e = 0;
-
+
group = avahi_new(AvahiIniFileGroup, 1);
group->name = avahi_strdup(s+1);
group->n_pairs = 0;
AVAHI_LLIST_HEAD_INIT(AvahiIniFilePair, group->pairs);
-
+
AVAHI_LLIST_PREPEND(AvahiIniFileGroup, groups, f->groups, group);
f->n_groups++;
} else {
avahi_log_error("Missing assignment in %s:%u: <%s>", fname, line, s);
goto fail;
}
-
+
if (!group) {
avahi_log_error("Assignment outside group in %s:%u <%s>", fname, line, s);
goto fail;
}
-
+
/* Split the key and the value */
*(e++) = 0;
-
+
pair = avahi_new(AvahiIniFilePair, 1);
pair->key = avahi_strdup(s);
pair->value = avahi_strdup(e);
-
+
AVAHI_LLIST_PREPEND(AvahiIniFilePair, pairs, group->pairs, pair);
group->n_pairs++;
}
}
-
+
fclose(fo);
-
+
return f;
fail:
while ((g = f->groups)) {
AvahiIniFilePair *p;
-
+
while ((p = g->pairs)) {
avahi_free(p->key);
avahi_free(p->value);
if (!p)
return;
-
+
for (i = p; *i; i++)
avahi_free(*i);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
argv_size = endptr - argv_buffer[0];
/* Make a copy of environ */
-
+
new_environ = avahi_malloc(sizeof(char*) * (i + 1));
for (i = 0; environ[i]; i++)
new_environ[i] = avahi_strdup(environ[i]);
environ = new_environ;
#endif
-}
+}
void avahi_set_proc_title(const char *name, const char *fmt,...) {
#ifdef HAVE_SETPROCTITLE
#elif __linux__
size_t l;
va_list ap;
-
+
if (!argv_buffer)
return;
-
+
va_start(ap, fmt);
vsnprintf(argv_buffer[0], argv_size, fmt, ap);
va_end(ap);
l = strlen(argv_buffer[0]);
-
+
memset(argv_buffer[0] + l, 0, argv_size - l);
argv_buffer[1] = NULL;
#endif
if (name)
prctl(PR_SET_NAME, (unsigned long) name, 0, 0, 0);
-
+
#endif
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
case AVAHI_ENTRY_GROUP_FAILURE:
avahi_log_notice ("Failed to establish static host name \"%s\": %s.", h->host, avahi_strerror (avahi_server_errno (s)));
break;
-
+
case AVAHI_ENTRY_GROUP_UNCOMMITED:
case AVAHI_ENTRY_GROUP_REGISTERING:
;
static StaticHost *static_host_new(void) {
StaticHost *s;
-
+
s = avahi_new(StaticHost, 1);
s->group = NULL;
avahi_s_entry_group_free (s->group);
avahi_free(s->host);
-
+
avahi_free(s);
}
assert(host);
assert(a);
-
+
for (h = hosts; h; h = h->hosts_next)
if (!strcmp(h->host, host) && !avahi_address_cmp(a, &h->address))
return h;
int err;
const AvahiServerConfig *config;
config = avahi_server_get_config(avahi_server);
-
+
p = (h->address.proto == AVAHI_PROTO_INET && config->publish_a_on_ipv6) ||
(h->address.proto == AVAHI_PROTO_INET6 && config->publish_aaaa_on_ipv4) ? AVAHI_PROTO_UNSPEC : h->address.proto;
-
+
if ((err = avahi_server_add_address(avahi_server, h->group, AVAHI_IF_UNSPEC, p, 0, h->host, &h->address)) < 0) {
avahi_log_error ("Static host name %s: avahi_server_add_address failure: %s", h->host, avahi_strerror(err));
return;
if (h->group)
avahi_s_entry_group_reset (h->group);
}
-
+
void static_hosts_add_to_server(void) {
StaticHost *h;
}
current_iteration++;
-
+
while (!feof(f)) {
unsigned int len;
char ln[256], *s;
/* Skip past any more spaces */
s += strspn(s, " \t");
-
+
/* Anything left? */
if (*s != 0) {
avahi_log_error ("%s:%d: Junk on the end of the line!", filename, line);
for (h = hosts; h; h = next) {
next = h->hosts_next;
-
+
if (h->iteration != current_iteration) {
avahi_log_info("Static hostname %s vanished, removing.", h->host);
static_host_free(h);
}
fail:
-
+
fclose(f);
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
assert(i);
avahi_free(i->address);
-
+
AVAHI_LLIST_REMOVE(DNSServerInfo, servers, servers, i);
avahi_free(i);
}
static DNSServerInfo* new_server_info(AvahiIfIndex interface, AvahiProtocol protocol, const char *address) {
DNSServerInfo *i;
-
+
assert(address);
i = avahi_new(DNSServerInfo, 1);
i->address = avahi_strdup(address);
AVAHI_LLIST_PREPEND(DNSServerInfo, servers, servers, i);
-
+
return i;
}
int n;
assert(fd >= 0);
-
+
if ((n = fcntl(fd, F_GETFD)) < 0)
return -1;
daemon_log(LOG_ERR, "fcntl(): %s", strerror(errno));
goto fail;
}
-
+
memset(&sa, 0, sizeof(sa));
sa.sun_family = AF_UNIX;
strncpy(sa.sun_path, AVAHI_SOCKET, sizeof(sa.sun_path)-1);
}
return fd;
-
+
fail:
if (fd >= 0)
close(fd);
static char *concat_dns_servers(AvahiIfIndex interface) {
DNSServerInfo *i;
char *r = NULL;
-
+
for (i = servers; i; i = i->servers_next)
if (i->interface == interface || interface <= 0) {
DNSServerInfo *j;
if (j != i)
continue;
-
+
if (!r)
t = avahi_strdup(i->address);
else
static void set_env(const char *name, const char *value) {
char **e;
size_t l;
-
+
assert(name);
assert(value);
/* Search for the variable */
if (strlen(*e) < l+1)
continue;
-
+
if (strncmp(*e, name, l) != 0 || (*e)[l] != '=')
continue;
assert(interface > 0);
- if (!if_indextoname(interface, name))
+ if (!if_indextoname(interface, name))
return;
-
+
p = concat_dns_servers(interface);
set_env(ENV_INTERFACE_DNS_SERVERS, p ? p : "");
- avahi_free(p);
+ avahi_free(p);
p = concat_dns_servers(-1);
set_env(ENV_DNS_SERVERS, p ? p : "");
- avahi_free(p);
+ avahi_free(p);
set_env(ENV_INTERFACE, name);
-
+
snprintf(ia, sizeof(ia), "%i", (int) interface);
snprintf(pa, sizeof(pa), "%i", (int) protocol);
AvahiProtocol protocol;
int i_interface, i_protocol, port;
char a[AVAHI_ADDRESS_STR_MAX];
-
- assert(state == BROWSING);
+
+ assert(state == BROWSING);
if (*l != '<' && *l != '>') {
daemon_log(LOG_ERR, "Avahi sent us an invalid browsing line: %s", l);
} else {
DNSServerInfo *i;
- if (port == 53)
+ if (port == 53)
if ((i = get_server_info(interface, protocol, a))) {
daemon_log(LOG_INFO, "DNS Server %s removed (interface: %i.%s)", a, interface, avahi_proto_to_string(protocol));
server_info_free(i);
}
}
-
+
return 0;
}
static int do_connect(void) {
int fd = -1;
-
+
if ((fd = open_socket()) < 0)
goto fail;
fail:
if (fd >= 0)
close(fd);
-
+
return -1;
}
AvahiProtocol protocol = servers->protocol;
char *address = avahi_strdup(servers->address);
server_info_free(servers);
-
+
run_script(0, interface, protocol, address);
avahi_free(address);
}
static int parse_command_line(int argc, char *argv[]) {
int c;
-
+
static const struct option long_options[] = {
{ "help", no_argument, NULL, 'h' },
{ "daemonize", no_argument, NULL, 'D' },
fprintf(stderr, "Too many arguments\n");
return -1;
}
-
+
return 0;
}
size_t buflen = 0;
AVAHI_LLIST_HEAD_INIT(DNSServerInfo, servers);
-
+
daemon_signal_init(SIGINT, SIGTERM, SIGCHLD, SIGHUP, 0);
/* Allocate some memory for our environment variables */
putenv(avahi_strdup(ENV_INTERFACE"="));
putenv(avahi_strdup(ENV_DNS_SERVERS"="));
putenv(avahi_strdup(ENV_INTERFACE_DNS_SERVERS"="));
-
+
if ((fd = do_connect()) < 0)
goto finish;
case SIGCHLD:
waitpid(-1, NULL, WNOHANG);
break;
-
+
case SIGHUP:
daemon_log(LOG_INFO, "Refreshing DNS Server list");
-
+
close(fd);
free_dns_server_info_list();
-
+
if ((fd = do_connect()) < 0)
goto finish;
-
+
break;
}
-
+
} else if (FD_ISSET(fd, &rfds)) {
ssize_t r;
char *n;
if (buflen >= sizeof(buf)-1) {
/* The incoming line is horribly long */
buf[sizeof(buf)-1] = 0;
-
+
if (new_line(buf) < 0)
goto finish;
-
+
buflen = 0;
}
}
}
-
+
finish:
free_dns_server_info_list();
if (fd >= 0)
close(fd);
-
+
daemon_signal_done();
if (ret != 0 && daemonize)
daemon_retval_send(1);
-
+
return ret;
}
daemon_pid_file_ident = daemon_log_ident = argv0;
daemon_pid_file_proc = pid_file_proc;
-
+
if (parse_command_line(argc, argv) < 0)
goto finish;
if (daemonize) {
daemon_retval_init();
-
+
if ((pid = daemon_fork()) < 0)
goto finish;
else if (pid != 0) {
r = 0;
} else if (command == DAEMON_HELP) {
help(stdout, argv0);
-
+
r = 0;
} else if (command == DAEMON_VERSION) {
printf("%s "PACKAGE_VERSION"\n", argv0);
-
+
r = 0;
} else if (command == DAEMON_KILL) {
if (daemon_pid_file_kill_wait(SIGTERM, 5) < 0) {
daemon_log(LOG_WARNING, "Failed to kill daemon: %s", strerror(errno));
goto finish;
}
-
+
r = 0;
} else if (command == DAEMON_REFRESH) {
if (daemon_pid_file_kill(SIGHUP) < 0) {
if (daemonize)
daemon_retval_done();
-
+
if (wrote_pid_file)
daemon_pid_file_remove();
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
if (event & AVAHI_WATCH_IN) {
ssize_t r;
char c;
-
+
if ((r = read(fd, &c, 1)) <= 0) {
fprintf(stderr, "read() failed: %s\n", r < 0 ? strerror(errno) : "EOF");
api->watch_free(w);
int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
AvahiGLibPoll *g;
struct timeval tv;
-
+
g = avahi_glib_poll_new(NULL, G_PRIORITY_DEFAULT);
assert(g);
g_main_loop_unref(loop);
avahi_glib_poll_free(g);
-
+
return 0;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
struct AvahiWatch {
AvahiGLibPoll *glib_poll;
int dead;
-
+
GPollFD pollfd;
int pollfd_added;
-
+
AvahiWatchCallback callback;
void *userdata;
AvahiTimeoutCallback callback;
void *userdata;
-
+
AVAHI_LLIST_FIELDS(AvahiTimeout, timeouts);
};
gboolean timeout_req_cleanup;
gboolean watch_req_cleanup;
-
+
AVAHI_LLIST_HEAD(AvahiWatch, watches);
AVAHI_LLIST_HEAD(AvahiTimeout, timeouts);
};
static AvahiWatch* watch_new(const AvahiPoll *api, int fd, AvahiWatchEvent events, AvahiWatchCallback callback, void *userdata) {
AvahiWatch *w;
AvahiGLibPoll *g;
-
+
assert(api);
assert(fd >= 0);
assert(callback);
if (!(w = avahi_new(AvahiWatch, 1)))
return NULL;
-
+
w->glib_poll = g;
w->pollfd.fd = fd;
w->pollfd.events = map_events_to_glib(events);
g_source_remove_poll(&w->glib_poll->source, &w->pollfd);
w->pollfd_added = FALSE;
}
-
+
w->dead = TRUE;
w->glib_poll->timeout_req_cleanup = TRUE;
}
static AvahiTimeout* timeout_new(const AvahiPoll *api, const struct timeval *tv, AvahiTimeoutCallback callback, void *userdata) {
AvahiTimeout *t;
AvahiGLibPoll *g;
-
+
assert(api);
assert(callback);
if (!(t = avahi_new(AvahiTimeout, 1)))
return NULL;
-
+
t->glib_poll = g;
t->dead = FALSE;
if ((t->enabled = !!tv))
t->expiry = *tv;
-
+
t->callback = callback;
t->userdata = userdata;
static void timeout_update(AvahiTimeout *t, const struct timeval *tv) {
assert(t);
assert(!t->dead);
-
+
if ((t->enabled = !!tv))
t->expiry = *tv;
}
assert(g);
for (t = g->timeouts; t; t = t->timeouts_next) {
-
+
if (t->dead || !t->enabled)
continue;
-
+
if (!n || avahi_timeval_compare(&t->expiry, &n->expiry) < 0)
n = t;
}
if (g->timeout_req_cleanup)
cleanup_timeouts(g, 0);
-
+
if ((next_timeout = find_next_timeout(g))) {
GTimeVal now;
struct timeval tvnow;
g_source_get_current_time(source, &now);
tvnow.tv_sec = now.tv_sec;
tvnow.tv_usec = now.tv_usec;
-
+
usec = avahi_timeval_diff(&next_timeout->expiry, &tvnow);
if (usec <= 0) {
*timeout = (gint) (usec / 1000);
} else
*timeout = -1;
-
+
return FALSE;
}
g_source_get_current_time(source, &now);
tvnow.tv_sec = now.tv_sec;
tvnow.tv_usec = now.tv_usec;
-
+
if (avahi_timeval_compare(&next_timeout->expiry, &tvnow) <= 0)
return TRUE;
}
for (w = g->watches; w; w = w->watches_next)
if (w->pollfd.revents > 0)
return TRUE;
-
+
return FALSE;
}
AvahiGLibPoll* g = (AvahiGLibPoll*) source;
AvahiWatch *w;
AvahiTimeout *next_timeout;
-
+
g_assert(g);
if ((next_timeout = find_next_timeout(g))) {
g_source_get_current_time(source, &now);
tvnow.tv_sec = now.tv_sec;
tvnow.tv_usec = now.tv_usec;
-
+
if (avahi_timeval_compare(&next_timeout->expiry, &tvnow) < 0) {
start_timeout_callback(next_timeout);
return TRUE;
}
}
-
+
for (w = g->watches; w; w = w->watches_next)
if (w->pollfd.revents > 0) {
assert(w->callback);
AvahiGLibPoll *avahi_glib_poll_new(GMainContext *context, gint priority) {
AvahiGLibPoll *g;
-
+
static GSourceFuncs source_funcs = {
prepare_func,
check_func,
g_main_context_ref(g->context = context ? context : g_main_context_default());
g->api.userdata = g;
-
+
g->api.watch_new = watch_new;
g->api.watch_free = watch_free;
g->api.watch_update = watch_update;
g->api.watch_get_events = watch_get_events;
-
+
g->api.timeout_new = timeout_new;
g->api.timeout_free = timeout_free;
g->api.timeout_update = timeout_update;
g->watch_req_cleanup = FALSE;
g->timeout_req_cleanup = FALSE;
-
+
AVAHI_LLIST_HEAD_INIT(AvahiWatch, g->watches);
AVAHI_LLIST_HEAD_INIT(AvahiTimeout, g->timeouts);
-
+
g_source_attach(&g->source, g->context);
g_source_set_priority(&g->source, priority);
g_source_set_can_recurse(&g->source, FALSE);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
static int set_nonblock(int fd) {
int n;
-
+
assert(fd >= 0);
if ((n = fcntl(fd, F_GETFL)) < 0)
static void watch_callback(AvahiWatch *w, int fd, AvahiWatchEvent event, AVAHI_GCC_UNUSED void *userdata) {
int s;
ssize_t l;
-
+
assert(w);
assert(fd == pipe_fds[0]);
assert(event == AVAHI_WATCH_IN);
int sigint_install(AvahiSimplePoll *spoll) {
struct sigaction sa;
const AvahiPoll *p;
-
+
assert(spoll);
assert(!simple_poll);
assert(pipe_fds[0] == -1 && pipe_fds[1] == -1);
close_pipe_fds();
return -1;
}
-
+
if (sigaction(SIGTERM, &sa, &old_sigterm_sa) < 0) {
sigaction(SIGINT, &old_sigint_sa, NULL);
fprintf(stderr, "sigaction() failed: %s\n", strerror(errno));
p = avahi_simple_poll_get(spoll);
watch = p->watch_new(p, pipe_fds[0], AVAHI_WATCH_IN, watch_callback, NULL);
assert(watch);
-
+
simple_poll = spoll;
return 0;
}
void sigint_uninstall(void) {
-
+
if (!simple_poll)
return;
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
data.dptr = NULL;
data.dsize = 0;
-
+
if ((loc = setlocale(LC_MESSAGES, NULL))) {
char k[256];
-
+
snprintf(k, sizeof(k), "%s[%s]", name, loc);
key.dptr = k;
key.dsize = strlen(k);
if (!data.dptr) {
char l[32], *e;
snprintf(l, sizeof(l), "%s", loc);
-
+
if ((e = strchr(l, '@'))) {
*e = 0;
snprintf(k, sizeof(k), "%s[%s]", name, l);
avahi_free(buffer);
buffer = avahi_strndup(data.dptr, data.dsize);
free(data.dptr);
-
+
return buffer;
-
+
fail:
return name;
char *stdb_getent(void) {
datum key;
-
+
if (init() < 0)
return NULL;
for (;;) {
-
+
if (!enum_key) {
#ifdef HAVE_GDBM
key = gdbm_firstkey(gdbm_file);
} else {
key.dptr = enum_key;
key.dsize = strlen(enum_key);
-
+
#ifdef HAVE_GDBM
key = gdbm_nextkey(gdbm_file, key);
#endif
avahi_free(enum_key);
enum_key = NULL;
-
+
if (!key.dptr)
return NULL;
-
+
enum_key = avahi_strndup(key.dptr, key.dsize);
free(key.dptr);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
struct sockaddr_storage sa;
socklen_t salen;
uint16_t port;
-
+
if ((s = socket(PF_INET6, SOCK_STREAM, 0)) < 0) {
if (errno == EAFNOSUPPORT)
s = socket(PF_INET, SOCK_STREAM, 0);
-
+
if (s < 0) {
perror("socket()");
return 1;
/* ... hic sunt leones ... */
sleep(60);
-
+
return 0;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
case AVAHI_RESOLVER_FOUND: {
char a[AVAHI_ADDRESS_STR_MAX], *t;
-
+
fprintf(stderr, "Service '%s' of type '%s' in domain '%s':\n", name, type, domain);
-
+
avahi_address_snprint(a, sizeof(a), address);
t = avahi_string_list_to_string(txt);
fprintf(stderr,
!!(flags & AVAHI_LOOKUP_RESULT_WIDE_AREA),
!!(flags & AVAHI_LOOKUP_RESULT_MULTICAST),
!!(flags & AVAHI_LOOKUP_RESULT_CACHED));
-
+
avahi_free(t);
}
}
const char *domain,
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
void* userdata) {
-
+
AvahiClient *c = userdata;
assert(b);
switch (event) {
case AVAHI_BROWSER_FAILURE:
-
+
fprintf(stderr, "(Browser) %s\n", avahi_strerror(avahi_client_errno(avahi_service_browser_get_client(b))));
avahi_simple_poll_quit(simple_poll);
return;
if (!(avahi_service_resolver_new(c, interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, 0, resolve_callback, c)))
fprintf(stderr, "Failed to resolve service '%s': %s\n", name, avahi_strerror(avahi_client_errno(c)));
-
+
break;
case AVAHI_BROWSER_REMOVE:
fprintf(stderr, "Failed to create client: %s\n", avahi_strerror(error));
goto fail;
}
-
+
/* Create the service browser */
if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_http._tcp", NULL, 0, browse_callback, client))) {
fprintf(stderr, "Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(client)));
/* Run the main loop */
avahi_simple_poll_loop(simple_poll);
-
+
ret = 0;
-
+
fail:
-
+
/* Cleanup things */
if (sb)
avahi_service_browser_free(sb);
-
+
if (client)
avahi_client_free(client);
* End user applications should *not* use this API and should use
* the D-Bus or C APIs, please see
* client-browse-services.c and glib-integration.c
- *
+ *
* I repeat, you probably do *not* want to use this example.
*/
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
AvahiStringList *txt,
AvahiLookupResultFlags flags,
AVAHI_GCC_UNUSED void* userdata) {
-
+
assert(r);
/* Called whenever a service has been resolved successfully or timed out */
case AVAHI_RESOLVER_FOUND: {
char a[AVAHI_ADDRESS_STR_MAX], *t;
-
+
fprintf(stderr, "(Resolver) Service '%s' of type '%s' in domain '%s':\n", name, type, domain);
-
+
avahi_address_snprint(a, sizeof(a), address);
t = avahi_string_list_to_string(txt);
fprintf(stderr,
avahi_free(t);
}
}
-
+
avahi_s_service_resolver_free(r);
}
const char *domain,
AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
void* userdata) {
-
+
AvahiServer *s = userdata;
assert(b);
switch (event) {
case AVAHI_BROWSER_FAILURE:
-
+
fprintf(stderr, "(Browser) %s\n", avahi_strerror(avahi_server_errno(server)));
avahi_simple_poll_quit(simple_poll);
return;
function we free it. If the server is terminated before
the callback function is called the server will free
the resolver for us. */
-
+
if (!(avahi_s_service_resolver_new(s, interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, 0, resolve_callback, s)))
fprintf(stderr, "Failed to resolve service '%s': %s\n", name, avahi_strerror(avahi_server_errno(s)));
-
+
break;
case AVAHI_BROWSER_REMOVE:
avahi_address_parse("192.168.50.1", AVAHI_PROTO_UNSPEC, &config.wide_area_servers[0]);
config.n_wide_area_servers = 1;
config.enable_wide_area = 1;
-
+
/* Allocate a new server */
server = avahi_server_new(avahi_simple_poll_get(simple_poll), &config, NULL, NULL, &error);
fprintf(stderr, "Failed to create server: %s\n", avahi_strerror(error));
goto fail;
}
-
+
/* Create the service browser */
if (!(sb = avahi_s_service_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_http._tcp", NULL, 0, browse_callback, server))) {
fprintf(stderr, "Failed to create service browser: %s\n", avahi_strerror(avahi_server_errno(server)));
goto fail;
}
-
+
/* Run the main loop */
avahi_simple_poll_loop(simple_poll);
-
+
ret = 0;
-
+
fail:
-
+
/* Cleanup things */
if (sb)
avahi_s_service_browser_free(sb);
-
+
if (server)
avahi_server_free(server);
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/* Called whenever the entry group state changes */
switch (state) {
-
+
case AVAHI_ENTRY_GROUP_ESTABLISHED:
/* The entry group has been established successfully */
case AVAHI_ENTRY_GROUP_COLLISION: {
char *n;
-
+
/* A service name collision happened. Let's pick a new name */
n = avahi_alternative_service_name(name);
avahi_free(name);
name = n;
-
+
fprintf(stderr, "Service name collision, renaming service to '%s'\n", name);
-
+
/* And recreate the services */
create_services(s);
break;
}
-
+
case AVAHI_ENTRY_GROUP_FAILURE :
fprintf(stderr, "Entry group failure: %s\n", avahi_strerror(avahi_server_errno(s)));
-
+
/* Some kind of failure happened while we were registering our services */
avahi_simple_poll_quit(simple_poll);
break;
fprintf(stderr, "avahi_entry_group_new() failed: %s\n", avahi_strerror(avahi_server_errno(s)));
goto fail;
}
-
+
fprintf(stderr, "Adding service '%s'\n", name);
/* Create some random TXT data */
case AVAHI_SERVER_RUNNING:
/* The serve has startup successfully and registered its host
* name on the network, so it's time to create our services */
-
+
if (!group)
create_services(s);
case AVAHI_SERVER_COLLISION: {
char *n;
int r;
-
+
/* A host name collision happened. Let's pick a new name for the server */
n = avahi_alternative_host_name(avahi_server_get_host_name(s));
fprintf(stderr, "Host name collision, retrying with '%s'\n", n);
r = avahi_server_set_host_name(s, n);
avahi_free(n);
-
+
if (r < 0) {
fprintf(stderr, "Failed to set new host name: %s\n", avahi_strerror(r));
-
+
avahi_simple_poll_quit(simple_poll);
return;
}
/* Fall through */
case AVAHI_SERVER_REGISTERING:
-
+
/* Let's drop our registered services. When the server is back
* in AVAHI_SERVER_RUNNING state we will register them
* again with the new host name. */
break;
case AVAHI_SERVER_FAILURE:
-
+
/* Terminate on failure */
-
+
fprintf(stderr, "Server failure: %s\n", avahi_strerror(avahi_server_errno(s)));
avahi_simple_poll_quit(simple_poll);
break;
AvahiServer *server = NULL;
int error;
int ret = 1;
-
+
/* Initialize the pseudo-RNG */
srand(time(NULL));
fprintf(stderr, "Failed to create simple poll object.\n");
goto fail;
}
-
+
name = avahi_strdup("MegaPrinter");
/* Let's set the host name for this server. */
avahi_server_config_init(&config);
config.host_name = avahi_strdup("gurkiman");
config.publish_workstation = 0;
-
+
/* Allocate a new server */
server = avahi_server_new(avahi_simple_poll_get(simple_poll), &config, server_callback, NULL, &error);
/* Run the main loop */
avahi_simple_poll_loop(simple_poll);
-
+
ret = 0;
-
+
fail:
-
+
/* Cleanup things */
if (server)
avahi_simple_poll_free(simple_poll);
avahi_free(name);
-
+
return ret;
}
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi is distributed in the hope that it will be useful, but 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.
-
+
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
GMainLoop *loop = userdata;
g_message ("GLIB API Timeout reached, quitting main loop!");
-
+
/* Quit the application */
g_main_loop_quit (loop);
goto fail;
}
-
+
/* Make a call to get the version string from the daemon */
version = avahi_client_get_version_string (client);
goto fail;
}
-
+
g_message ("Avahi Server Version: %s", version);
/* Start the GLIB Main Loop */