Esempio n. 1
0
AvahiNetlink *avahi_netlink_new(const AvahiPoll *poll_api, uint32_t groups, void (*cb) (AvahiNetlink *nl, struct nlmsghdr *n, void* userdata), void* userdata) {
    int fd = -1;
    struct sockaddr_nl addr;
    AvahiNetlink *nl = NULL;

    assert(poll_api);
    assert(cb);

    if ((fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE)) < 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;
    addr.nl_pid = getpid();

    if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
        avahi_log_error(__FILE__": bind(): %s", strerror(errno));
        goto fail;
    }

    if (!(nl = avahi_new(AvahiNetlink, 1))) {
        avahi_log_error(__FILE__": avahi_new() failed.");
        goto fail;
    }

    nl->poll_api = poll_api;
    nl->fd = fd;
    nl->seq = 0;
    nl->callback = cb;
    nl->userdata = userdata;

    if (!(nl->buffer = avahi_new(uint8_t, nl->buffer_length = 64*1024))) {
        avahi_log_error(__FILE__": avahi_new() failed.");
        goto fail;
    }

    if (!(nl->watch = poll_api->watch_new(poll_api, fd, AVAHI_WATCH_IN, socket_event, nl))) {
        avahi_log_error(__FILE__": Failed to create watch.");
        goto fail;
    }
    
    return nl;

fail:

    if (fd >= 0)
        close(fd);

    if (nl) {
        avahi_free(nl->buffer);
        avahi_free(nl);
    }

    return NULL;
}
Esempio n. 2
0
void DNSSD_API TXTRecordCreate(
    TXTRecordRef *txtref,
    uint16_t length,
    void *buffer) {

    TXTRecordInternal *t;

    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
     * our own memory. Please, Apple, do your homework next time
     * before designing an API! */

    if ((t = avahi_new(TXTRecordInternal, 1))) {
        t->buffer = buffer;
        t->max_size = buffer ? length : (size_t)0;
        t->size = 0;
        t->malloc_buffer = NULL;
    }

    /* If we were unable to allocate memory, we store a NULL pointer
     * and return a NoMemory error later, is somewhat unclean, but
     * should work. */
    INTERNAL_PTR(txtref) = t;
}
Esempio n. 3
0
static AvahiLLMNRQueryJob *job_new(AvahiLLMNRQueryScheduler *s, AvahiLLMNRQuery *lq) {
    AvahiLLMNRQueryJob *qj;

    assert(s);
    assert(lq);

    if(!(qj = avahi_new(AvahiLLMNRQueryJob, 1)))
        return NULL;

    qj->scheduler = s;
    qj->lq = lq;

    /* Set lq parameters */
    lq->post_id_valid = 1;
    lq->post_id = s->next_id++;

    /* qj parameters */
    qj->n_sent = 0;
    qj->prev_scheduled = 0;
    qj->time_event = NULL;

    /* Prepend in Lists */
    AVAHI_LLIST_PREPEND(AvahiLLMNRQueryJob, jobs_by_scheduler, s->jobs, qj);
    AVAHI_LLIST_PREPEND(AvahiLLMNRQueryJob, jobs_by_interface, s->i->llmnr.queryjobs, qj);

    /*Just prepare dns packet, don't send it */
    avahi_prepare_llmnr_query_job_packet(qj);

    return qj;
}
Esempio n. 4
0
static dbus_bool_t add_timeout(DBusTimeout *dbus_timeout, void *userdata) {
    TimeoutData *timeout;
    ConnectionData *d = userdata;
    struct timeval tv;
    dbus_bool_t b;

    assert(dbus_timeout);
    assert(d);

    if (!(timeout = avahi_new(TimeoutData, 1)))
        return FALSE;

    timeout->dbus_timeout = dbus_timeout;
    timeout->poll_api = d->poll_api;
    timeout->ref = 1;

    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,
              timeout_callback,
              timeout))) {
        avahi_free(timeout);
        return FALSE;
    }

    dbus_timeout_set_data(dbus_timeout, timeout, (DBusFreeFunction) timeout_data_unref);
    return TRUE;
}
Esempio n. 5
0
static ServiceInfo *add_service(Config *c, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain) {
    ServiceInfo *i;

    i = avahi_new(ServiceInfo, 1);

    if (c->resolve) {
        if (!(i->resolver = avahi_service_resolver_new(client, interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, 0, service_resolver_callback, i))) {
            avahi_free(i);
            fprintf(stderr, ("Failed to resolve service '%s' of type '%s' in domain '%s': %s\n"), name, type, domain, avahi_strerror(avahi_client_errno(client)));
            return NULL;
        }

        n_resolving++;
    } else
        i->resolver = NULL;

    i->interface = interface;
    i->protocol = protocol;
    i->name = avahi_strdup(name);
    i->type = avahi_strdup(type);
    i->domain = avahi_strdup(domain);
    i->config = c;

    AVAHI_LLIST_PREPEND(ServiceInfo, info, services, i);

    return i;
}
Esempio n. 6
0
AvahiCache *avahi_cache_new(AvahiServer *server, AvahiInterface *iface) {
    AvahiCache *c;
    assert(server);

    if (!(c = avahi_new(AvahiCache, 1))) {
        avahi_log_error(__FILE__": Out of memory.");
        return NULL; /* OOM */
    }

    c->server = server;
    c->interface = iface;

    if (!(c->hashmap = avahi_hashmap_new((AvahiHashFunc) avahi_key_hash, (AvahiEqualFunc) avahi_key_equal, NULL, NULL))) {
        avahi_log_error(__FILE__": Out of memory.");
        avahi_free(c);
        return NULL; /* OOM */
    }

    AVAHI_LLIST_HEAD_INIT(AvahiCacheEntry, c->entries);
    c->n_entries = 0;

    c->last_rand_timestamp = 0;

    return c;
}
Esempio n. 7
0
static void new_verifier(AvahiServer *s, AvahiInterface *i, AvahiEntry *e) {
    AvahiLLMNREntryVerify *ev;

    assert(s);
    assert(i);
    assert(e);
    assert(!e->dead);
    assert(e->type == AVAHI_ENTRY_LLMNR);

    if( !avahi_interface_match (i, e->interface, e->protocol) ||
        !i->llmnr.verifying ||
        !avahi_entry_is_commited(e) )
    /* start verifying rr's only when group has been commited */
        return;

    if(get_verifier(s, i, e))
        return;

    if(!(ev = avahi_new(AvahiLLMNREntryVerify, 1)))
        return;

    ev->s= s;
    ev->interface = i;
    ev->e = e;
    ev->lq = NULL;

    AVAHI_LLIST_PREPEND(AvahiLLMNREntryVerify, by_interface, i->llmnr.verifiers, ev);
    AVAHI_LLIST_PREPEND(AvahiLLMNREntryVerify, by_entry, e->proto.llmnr.verifiers, ev);

    set_state(ev);
}
Esempio n. 8
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);

    s = api->userdata;
    assert(s);

    if (!(w = avahi_new(AvahiWatch, 1)))
        return NULL;

    /* 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;

    w->pollfd.fd = fd;
    w->pollfd.events = event;
    w->pollfd.revents = 0;

    w->callback = callback;
    w->userdata = userdata;

    w->idx = -1;
    s->rebuild_pollfds = 1;

    AVAHI_LLIST_PREPEND(AvahiWatch, watches, s->watches, w);
    s->n_watches++;

    return w;
}
Esempio n. 9
0
int avahi_hashmap_replace(AvahiHashmap *m, void *key, void *value) {
    unsigned idx;
    Entry *e;

    assert(m);

    if ((e = entry_get(m, key))) {
        if (m->key_free_func)
            m->key_free_func(e->key);
        if (m->value_free_func)
            m->value_free_func(e->value);

        e->key = key;
        e->value = value;
            
        return 1;
    }

    if (!(e = avahi_new(Entry, 1)))
        return -1;

    e->hashmap = m;
    e->key = key;
    e->value = value;

    AVAHI_LLIST_PREPEND(Entry, entries, m->entries_list, e);

    idx = m->hash_func(key) % HASH_MAP_SIZE;
    AVAHI_LLIST_PREPEND(Entry, bucket, m->entries[idx], e);
        
    return 0;
}
Esempio n. 10
0
static AvahiTimeout* timeout_new(const AvahiPoll *api, const struct timeval *tv, AvahiTimeoutCallback callback, void *userdata) {
    AvahiTimeout *t;
    AvahiSimplePoll *s;

    assert(api);
    assert(callback);

    s = api->userdata;
    assert(s);

    if (!(t = avahi_new(AvahiTimeout, 1)))
        return NULL;

    /* 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;

    AVAHI_LLIST_PREPEND(AvahiTimeout, timeouts, s->timeouts, t);
    return t;
}
Esempio n. 11
0
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;
    g->dead = 0;
    g->state = AVAHI_ENTRY_GROUP_UNCOMMITED;
    g->n_probing = 0;
    g->n_register_try = 0;
    g->register_time_event = NULL;
    g->register_time.tv_sec = 0;
    g->register_time.tv_usec = 0;
    AVAHI_LLIST_HEAD_INIT(AvahiEntry, g->entries);

    AVAHI_LLIST_PREPEND(AvahiSEntryGroup, groups, s->groups, g);
    return g;
}
Esempio n. 12
0
static void new_announcer(AvahiServer *s, AvahiInterface *i, AvahiEntry *e) {
    AvahiAnnouncer *a;

    assert(s);
    assert(i);
    assert(e);
    assert(!e->dead);

    if (!avahi_interface_match(i, e->interface, e->protocol) || !i->announcing || !avahi_entry_is_commited(e))
        return;

    /* We don't want duplicate announcers */
    if (get_announcer(s, e, i))
        return;

    if ((!(a = avahi_new(AvahiAnnouncer, 1)))) {
        avahi_log_error(__FILE__": Out of memory.");
        return;
    }

    a->server = s;
    a->interface = i;
    a->entry = e;
    a->time_event = NULL;

    AVAHI_LLIST_PREPEND(AvahiAnnouncer, by_interface, i->announcers, a);
    AVAHI_LLIST_PREPEND(AvahiAnnouncer, by_entry, e->announcers, a);

    go_to_initial_state(a);
}
Esempio n. 13
0
static AvahiResponseJob* job_new(AvahiResponseScheduler *s, AvahiRecord *record, AvahiResponseJobState state) {
    AvahiResponseJob *rj;
    
    assert(s);
    assert(record);

    if (!(rj = avahi_new(AvahiResponseJob, 1))) {
        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) 
        AVAHI_LLIST_PREPEND(AvahiResponseJob, jobs, s->jobs, rj);
    else if (rj->state == AVAHI_DONE)
        AVAHI_LLIST_PREPEND(AvahiResponseJob, jobs, s->history, rj);
    else  /* rj->state == AVAHI_SUPPRESSED */
        AVAHI_LLIST_PREPEND(AvahiResponseJob, jobs, s->suppressed, rj);

    return rj;
}
Esempio n. 14
0
static AvahiTimeout* timeout_new(const AvahiPoll *api, const struct timeval *tv, AvahiTimeoutCallback callback, void *userdata) {
    AvahiTimeout *t;
    AvahiGLibPoll *g;

    assert(api);
    assert(callback);

    g = api->userdata;
    assert(g);

    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;

    AVAHI_LLIST_PREPEND(AvahiTimeout, timeouts, g->timeouts, t);

    return t;
}
Esempio n. 15
0
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);

    g = api->userdata;
    assert(g);

    if (!(w = avahi_new(AvahiWatch, 1)))
        return NULL;

    w->glib_poll = g;
    w->pollfd.fd = fd;
    w->pollfd.events = map_events_to_glib(events);
    w->pollfd.revents = 0;
    w->callback = callback;
    w->userdata = userdata;
    w->dead = FALSE;

    g_source_add_poll(&g->source, &w->pollfd);
    w->pollfd_added = TRUE;

    AVAHI_LLIST_PREPEND(AvahiWatch, watches, g->watches, w);

    return w;
}
Esempio n. 16
0
AvahiLLMNRQuery* avahi_llmnr_query_add(AvahiInterface *i, AvahiKey *key, AvahiLLMNRQueryType type, AvahiLLMNRQueryCallback callback, void *userdata) {
	AvahiLLMNRQuery *lq;
	int c;

	/* Engine maintains a hashmap of 'AvahiLLMNRQuery' objects by id */
	AvahiLLMNRLookupEngine *e = i->monitor->server->llmnr.llmnr_lookup_engine;
	
	assert(i);	
	assert(key);
	assert(callback);

	if(!(lq = avahi_new(AvahiLLMNRQuery, 1)))
		return NULL;

	/* Initialize parameters */
	lq->dead = 0;
	lq->key = avahi_key_ref(key);
	lq->type = type;
	lq->interface = i;
	lq->callback = callback;
	lq->post_id_valid = 0;
	lq->post_id = 0;
	lq->userdata = userdata;

	/* Initialize record lists for this query object */
	lq->c_bit_set = avahi_record_list_new();
	lq->c_bit_clear = avahi_record_list_new();

	c = avahi_record_list_is_empty(lq->c_bit_set);
	assert(c);
	assert(lq->c_bit_clear);
	
	/* Set ID */
	/* KEEP IT 32 BIT for HASHMAP */
	for (;; e->next_id++)
		if(!(find_query(e, e->next_id)))
			break;

	lq->id = e->next_id++;
	
	/* AvahiLLMNRLookupEngine hashmap of queries by ID, 
	'engine-AvahiLLMNRQuery'. (lq->id and lq) */
	avahi_hashmap_insert(e->queries_by_id, &(lq->id), lq);

	/* Schedule this LLMNR query. This will create an 
	'AvahiLLMNRQueryJob' for this query and will issue
	further queries there only. im0 */
	if(!avahi_interface_post_llmnr_query(i, lq, 0)) 
		return NULL;

	return lq;
	
}
Esempio n. 17
0
static void add_to_cache(AvahiWideAreaLookupEngine *e, AvahiRecord *r) {
    AvahiWideAreaCacheEntry *c;
    int is_new;
    
    assert(e);
    assert(r);

    if ((c = find_record_in_cache(e, r))) {
        is_new = 0;

        /* Update the existing entry */
        avahi_record_unref(c->record);
    } else {
        AvahiWideAreaCacheEntry *t;

        is_new = 1;

        /* Enforce cache size */
        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;

        AVAHI_LLIST_PREPEND(AvahiWideAreaCacheEntry, cache, e->cache, c);

        /* Add the new entry to the cache entry hash table */
        t = avahi_hashmap_lookup(e->cache_by_key, r->key);
        AVAHI_LLIST_PREPEND(AvahiWideAreaCacheEntry, by_key, t, c);
        avahi_hashmap_replace(e->cache_by_key, avahi_key_ref(r->key), t);

        e->cache_n_entries ++;
    }

    c->record = avahi_record_ref(r);
    
    gettimeofday(&c->timestamp, NULL);
    c->expiry = c->timestamp;
    avahi_timeval_add(&c->expiry, r->ttl * 1000000);

    if (c->time_event)
        avahi_time_event_update(c->time_event, &c->expiry);
    else
        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);
}
Esempio n. 18
0
static StaticHost *static_host_new(void) {
    StaticHost *s;
    
    s = avahi_new(StaticHost, 1);

    s->group = NULL;
    s->host = NULL;
    s->ip = NULL;

    AVAHI_LLIST_PREPEND(StaticHost, hosts, hosts, s);

    return s;
}
Esempio n. 19
0
static DNSServerInfo* new_server_info(AvahiIfIndex interface, AvahiProtocol protocol, const char *address) {
    DNSServerInfo *i;

    assert(address);

    i = avahi_new(DNSServerInfo, 1);
    i->interface = interface;
    i->protocol = protocol;
    i->address = avahi_strdup(address);

    AVAHI_LLIST_PREPEND(DNSServerInfo, servers, servers, i);

    return i;
}
Esempio n. 20
0
AvahiWideAreaLookupEngine *avahi_wide_area_engine_new(AvahiServer *s) {
    AvahiWideAreaLookupEngine *e;
    
    assert(s);

    e = avahi_new(AvahiWideAreaLookupEngine, 1);
    e->server = s;
    e->cleanup_dead = 0;

    /* Create sockets */
    e->fd_ipv4 = s->config.use_ipv4 ? avahi_open_unicast_socket_ipv4() : -1;
    e->fd_ipv6 = s->config.use_ipv6 ? avahi_open_unicast_socket_ipv6() : -1;

    if (e->fd_ipv4 < 0 && e->fd_ipv6 < 0) {
        avahi_log_error(__FILE__": Failed to create wide area sockets: %s", strerror(errno));

        if (e->fd_ipv6 >= 0)
            close(e->fd_ipv6);

        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)
        e->watch_ipv6 = s->poll_api->watch_new(e->server->poll_api, e->fd_ipv6, AVAHI_WATCH_IN, socket_event, e);

    e->n_dns_servers = e->current_dns_server = 0;
    e->next_id = (uint16_t) rand();

    /* Initialize cache */
    AVAHI_LLIST_HEAD_INIT(AvahiWideAreaCacheEntry, e->cache);
    e->cache_by_key = avahi_hashmap_new((AvahiHashFunc) avahi_key_hash, (AvahiEqualFunc) avahi_key_equal, (AvahiFreeFunc) avahi_key_unref, NULL);
    e->cache_n_entries = 0;

    /* Initialize lookup list */
    e->lookups_by_id = avahi_hashmap_new((AvahiHashFunc) avahi_int_hash, (AvahiEqualFunc) avahi_int_equal, NULL, NULL);
    e->lookups_by_key = avahi_hashmap_new((AvahiHashFunc) avahi_key_hash, (AvahiEqualFunc) avahi_key_equal, (AvahiFreeFunc) avahi_key_unref, NULL);
    AVAHI_LLIST_HEAD_INIT(AvahiWideAreaLookup, e->lookups);

    return e;
}
Esempio n. 21
0
static void avahi_reverify(AvahiLLMNREntryVerify *ev) {
    AvahiEntry *e;
    AvahiVerifierData *vdata;

    assert(ev);

    if (!(vdata = avahi_new(AvahiVerifierData, 1)))
        return;

    e = ev->e;

    if (e->group)
        assert(e->group->type == AVAHI_GROUP_LLMNR);

    /* Group has not been commited yet, nothing to reverify*/
    if(e->group && (e->group->state = AVAHI_ENTRY_GROUP_LLMNR_UNCOMMITED || e->group->state == AVAHI_ENTRY_GROUP_LLMNR_COLLISION))
        return;

    /* STATE == AVAHI_VERIFYING : Free the lq object and if entry belongs to
    a group decrease the n_verifying counter. NEW STATE : _VERIFYING*/
    if (ev->state == AVAHI_VERIFYING) {
        if (e->group)
            e->group->proto.llmnr.n_verifying--;

    } else if ((ev->state == AVAHI_ESTABLISHED) && (e->flags & AVAHI_PUBLISH_UNIQUE) && !(e->flags & AVAHI_PUBLISH_NO_VERIFY))
        /* _ESTABLISHED but _VERIFY again*/
        ev->state = AVAHI_VERIFYING;

    else
        ev->state = AVAHI_ESTABLISHED;

    /* New state has been decided */

    if(ev->state == AVAHI_VERIFYING) {

        vdata->ev = ev;
        vdata->address = NULL;
        vdata->t_bit = 0;

        /* Start the queries */
        avahi_llmnr_query_add(ev->interface, e->record->key, AVAHI_LLMNR_UNIQUENESS_VERIFICATION_QUERY, query_callback, vdata);

        /* Increase the counter if it belongs to a group */
        if(e->group)
            e->group->proto.llmnr.n_verifying++;

    } else
        if (e->group)
            check_established(e->group);
}
Esempio n. 22
0
AvahiLLMNRQueryScheduler *avahi_llmnr_query_scheduler_new(AvahiInterface *i) {
    AvahiLLMNRQueryScheduler *s;
    assert(i);

    if(!(s = avahi_new(AvahiLLMNRQueryScheduler, 1)))
        return NULL;

    s->i = i;
    s->time_event_queue = i->monitor->server->time_event_queue;
    s->next_id = 1;
    AVAHI_LLIST_HEAD_INIT(AvahiLLMNRQueryJob, s->jobs);

    return s;
}
Esempio n. 23
0
AvahiSimplePoll *avahi_simple_poll_new(void) {
    AvahiSimplePoll *s;

    if (!(s = avahi_new(AvahiSimplePoll, 1)))
        return NULL;

    if (pipe(s->wakeup_pipe) < 0) {
        avahi_free(s);
        return NULL;
    }

    set_nonblock(s->wakeup_pipe[0]);
    set_nonblock(s->wakeup_pipe[1]);

    s->api.userdata = s;

    s->api.watch_new = watch_new;
    s->api.watch_free = watch_free;
    s->api.watch_update = watch_update;
    s->api.watch_get_events = watch_get_events;

    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->prepared_timeout = 0;

    s->state = STATE_INIT;

    s->wakeup_issued = 0;

    avahi_simple_poll_set_func(s, NULL, NULL);

    AVAHI_LLIST_HEAD_INIT(AvahiWatch, s->watches);
    AVAHI_LLIST_HEAD_INIT(AvahiTimeout, s->timeouts);

    return s;
}
Esempio n. 24
0
static StaticServiceGroup *static_service_group_new(char *filename) {
    StaticServiceGroup *g;
    assert(filename);

    g = avahi_new(StaticServiceGroup, 1);
    g->filename = avahi_strdup(filename);
    g->mtime = 0;
    g->name = g->chosen_name = NULL;
    g->replace_wildcards = 0;
    g->entry_group = NULL;

    AVAHI_LLIST_HEAD_INIT(StaticService, g->services);
    AVAHI_LLIST_PREPEND(StaticServiceGroup, groups, groups, g);

    return g;
}
Esempio n. 25
0
AvahiSRecordBrowser *avahi_s_record_browser_new(
    AvahiServer *server,
    AvahiIfIndex interface,
    AvahiProtocol protocol,
    AvahiKey *key,
    AvahiLookupFlags flags,
    AvahiSRecordBrowserCallback callback,
    void* userdata) {

    AvahiSRecordBrowser *b;

    assert(server);
    assert(key);
    assert(callback);

    AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_IF_VALID(interface), AVAHI_ERR_INVALID_INTERFACE);
    AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_PROTO_VALID(protocol), AVAHI_ERR_INVALID_PROTOCOL);
    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);

    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->protocol = protocol;
    b->key = avahi_key_ref(key);
    b->flags = flags;
    b->callback = callback;
    b->userdata = userdata;
    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;
}
Esempio n. 26
0
AvahiProbeScheduler *avahi_probe_scheduler_new(AvahiInterface *i) {
    AvahiProbeScheduler *s;

    assert(i);

    if (!(s = avahi_new(AvahiProbeScheduler, 1))) {
        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;
}
static StaticService *static_service_new(StaticServiceGroup *group) {
    StaticService *s;
    
    assert(group);
    s = avahi_new(StaticService, 1);
    s->group = group;

    s->type = s->host_name = s->domain_name = NULL;
    s->port = 0;
    s->protocol = AVAHI_PROTO_UNSPEC;

    s->txt_records = NULL;
    s->subtypes = NULL;

    AVAHI_LLIST_PREPEND(StaticService, services, group->services, s);

    return s;
}
Esempio n. 28
0
AvahiQueryScheduler *avahi_query_scheduler_new(AvahiInterface *i) {
    AvahiQueryScheduler *s;
    assert(i);

    if (!(s = avahi_new(AvahiQueryScheduler, 1))) {
        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);

    return s;
}
ServiceInfo* NetworkServicesProviderAvahi::addServiceInfo(
    AvahiIfIndex interface, 
    AvahiProtocol protocol, 
    const char* name, 
    const char* type, 
    const char* domain) 
{
    ServiceInfo* i;

    m_currentService = i = avahi_new(ServiceInfo, 1);

    if (!(i->resolver = avahi_service_resolver_new(
        m_avahiClient,
        interface, 
        protocol, 
        name, 
        type, 
        domain, 
        AVAHI_PROTO_UNSPEC, 
        (AvahiLookupFlags)0, 
        &serviceResolverCallback, 
        static_cast<void*>(i)))) 
    {
        avahi_free(i);
        LOG_ERROR("Failed to resolve service '%s' of type '%s' in domain '%s': %s\n", 
            name, type, domain, avahi_strerror(avahi_client_errno(m_avahiClient)));
        return 0;
    }

    m_resolving++;

    i->interface = interface;
    i->protocol = protocol;
    i->name = avahi_strdup(name);
    i->type = avahi_strdup(type);
    i->domain = avahi_strdup(domain);
    i->provider = this;
    i->notify = false;

    AVAHI_LLIST_PREPEND(ServiceInfo, info, m_services, i);

    return i;
}
Esempio n. 30
0
static void set_state(AvahiLLMNREntryVerify *ev) {
    AvahiEntry *e;
    assert(ev);

    e = ev->e;
    assert(e->type == AVAHI_ENTRY_LLMNR);

    if((e->flags & AVAHI_PUBLISH_UNIQUE) && !(e->flags & AVAHI_PUBLISH_NO_VERIFY))
        ev->state = AVAHI_VERIFYING;

    else
        ev->state = AVAHI_ESTABLISHED;

    if(ev->state == AVAHI_VERIFYING) {
        /* Structure to send in AvahiLLMNRQuery*/
        struct AvahiVerifierData *vdata;

        vdata = avahi_new(AvahiVerifierData, 1);
        /* Fill AvahiLLMNREntryVerify*/
        vdata->ev = ev;

        /* Both these fields are filled by handle_response*/
        vdata->address = NULL;

        /* If we get the response with t bit clear we don't touch this entry*/
        /* If we get the response with t bit set we set it so bt edfault keep it zero.*/
        vdata->t_bit = 0;

        /* Initiate Query */
        ev->lq = avahi_llmnr_query_add(ev->interface, e->record->key, AVAHI_LLMNR_UNIQUENESS_VERIFICATION_QUERY, query_callback, vdata);

        /* Increase n_verify */
        if(e->group) {
            assert(e->group->type == AVAHI_GROUP_LLMNR);
            e->group->proto.llmnr.n_verifying++;
        }

    } else { /*ev->state == AVAHI_ESTABLISHED */
        if (ev->e->group)
            check_established(ev->e->group);
    }
}