Ejemplo n.º 1
0
/**
 * Free an XML node.
 *
 * This is the user-visible routine that can succeed only if the node is
 * not part of a tree structure.
 */
void
xnode_free(xnode_t *xn)
{
	etree_t t;

	xnode_check(xn);
	etree_init_root(&t, xn, TRUE, offsetof(xnode_t, node));
	g_assert(etree_is_standalone(&t, xn));

	switch (xn->type) {
	case XNODE_T_COMMENT:
		HFREE_NULL(xn->u.c.text);
		break;
	case XNODE_T_TEXT:
		HFREE_NULL(xn->u.t.text);
		break;
	case XNODE_T_PI:
		atom_str_free_null(&xn->u.pi.name);
		HFREE_NULL(xn->u.pi.target);
		break;
	case XNODE_T_ELEMENT:
		atom_str_free_null(&xn->u.e.name);
		atom_str_free_null(&xn->u.e.ns_uri);
		nv_table_free_null(&xn->u.e.ns);
		xattr_table_free_null(&xn->u.e.attrs);
		break;
	case XNODE_T_MAX:
		g_assert_not_reached();
	}

	xn->magic = 0;
	WFREE(xn);
}
Ejemplo n.º 2
0
void
magnet_resource_free(struct magnet_resource **res_ptr)
{
	struct magnet_resource *res = *res_ptr;

	if (res) {
		GSList *sl;

		atom_str_free_null(&res->display_name);
		atom_sha1_free_null(&res->sha1);
		atom_tth_free_null(&res->tth);
		atom_str_free_null(&res->parq_id);
		atom_str_free_null(&res->guid);
		atom_str_free_null(&res->vendor);

		for (sl = res->sources; sl != NULL; sl = g_slist_next(sl)) {
			struct magnet_source *ms = sl->data;
			magnet_source_free(&ms);
		}
		gm_slist_free_null(&res->sources);

		for (sl = res->searches; sl != NULL; sl = g_slist_next(sl)) {
			const char *s = sl->data;
			atom_str_free_null(&s);
		}
		gm_slist_free_null(&res->searches);
		wfree(res, sizeof *res);
		*res_ptr = NULL;
	}
}
Ejemplo n.º 3
0
/**
 * Free an attribute key/value.
 */
static void
xattr_free(struct xattr *xa)
{
	g_assert(xa != NULL);

	atom_str_free_null(&xa->uri);
	atom_str_free_null(&xa->local);
	HFREE_NULL(xa->value);
	WFREE(xa);
}
Ejemplo n.º 4
0
/**
 * Free service description.
 */
static void
upnp_service_free(upnp_service_t *usd)
{
	upnp_service_check(usd);

	atom_str_free_null(&usd->control_url);
	atom_str_free_null(&usd->scpd_url);
	nv_table_free_null(&usd->api);
	usd->magic = 0;
	WFREE(usd);
}
Ejemplo n.º 5
0
/**
 * Free a SOAP request.
 */
static void
soap_rpc_free(soap_rpc_t *sr)
{
	soap_rpc_check(sr);

	atom_str_free_null(&sr->url);
	atom_str_free_null(&sr->action);
	cq_cancel(&sr->delay_ev);
	http_async_cancel_null(&sr->ha);
	header_free_null(&sr->header);
	pmsg_free_null(&sr->mb);
	HFREE_NULL(sr->reply_data);

	sr->magic = 0;
	WFREE(sr);
}
Ejemplo n.º 6
0
static void
destroy_entry(struct st_entry *entry)
{
	g_assert(entry != NULL);

	atom_str_free_null(&entry->string);
	shared_file_unref(&entry->sf);
	WFREE(entry);
}
Ejemplo n.º 7
0
/**
 * Free watchdog.
 */
static void
wd_free(watchdog_t *wd)
{
	watchdog_check(wd);
	
	wd_sleep(wd);
	atom_str_free_null(&wd->name);
	WFREE(wd);
}
Ejemplo n.º 8
0
/**
 * Free an UPnP control request.
 */
static void
upnp_ctrl_free(upnp_ctrl_t *ucd)
{
	upnp_ctrl_check(ucd);
	g_assert(NULL == ucd->sr);

	atom_str_free_null(&ucd->action);
	ucd->magic = 0;
	WFREE(ucd);
}
Ejemplo n.º 9
0
static void
uhc_free(struct uhc **ptr)
{
	if (*ptr) {
		struct uhc *uu = *ptr;
		atom_str_free_null(&uu->host);
		WFREE(uu);
		*ptr = NULL;
	}
}
Ejemplo n.º 10
0
void
magnet_source_free(struct magnet_source **ms_ptr)
{
	struct magnet_source *ms = *ms_ptr;
	
	if (ms) {
		atom_str_free_null(&ms->hostname);
		atom_str_free_null(&ms->path);
		atom_str_free_null(&ms->url);
		atom_sha1_free_null(&ms->sha1);
		atom_tth_free_null(&ms->tth);
		atom_guid_free_null(&ms->guid);
		if (ms->proxies) {
			free_proxies_list(ms->proxies);
			ms->proxies = NULL;
		}
		wfree(ms, sizeof *ms);
		*ms_ptr = NULL;
	}
}
Ejemplo n.º 11
0
static void
node_data_free(gpointer value)
{
	struct node_data *data = value;

	atom_str_free_null(&data->user_agent);
	WFREE_NULL(data->host, data->host_size);
	WFREE_NULL(data->info, data->info_size);
	nid_unref(data->node_id);
	WFREE(data);
}
Ejemplo n.º 12
0
/**
 * Dispose of current URL atom, if defined.
 * When `discard' is set, we remove the current URL physically from our cache.
 */
static void
gwc_clear_current_url(bool discard)
{
    if (gwc_current_url == NULL)
        return;

    if (discard)
        gwc_forget_url(gwc_current_url);

    atom_str_free_null(&gwc_current_url);
}
Ejemplo n.º 13
0
/**
 * Clear all the upload stats data structure.
 */
static G_GNUC_COLD void
upload_stats_free_all(void)
{
	if (upload_stats_list) {
		struct ul_stats *s;

		while (NULL != (s = hash_list_head(upload_stats_list))) {
			hash_list_remove(upload_stats_list, s);
			atom_str_free_null(&s->pathname);
			atom_str_free_null(&s->filename);
			if (s->sha1)
				g_hash_table_remove(upload_stats_by_sha1, s->sha1);
			atom_sha1_free_null(&s->sha1);
			WFREE(s);
		}
		hash_list_free(&upload_stats_list);
		gm_hash_table_destroy_null(&upload_stats_by_sha1);
	}
	dirty = TRUE;
}
Ejemplo n.º 14
0
/**
 * Record given string magnet resource at the supplied location.
 */
static void
magnet_resource_set_string(const char **p, const char *str)
{
	const char *atom;

	g_return_if_fail(p);
	g_return_if_fail(str);

	atom = atom_str_get(str);
	atom_str_free_null(p);
	*p = atom;
}
Ejemplo n.º 15
0
void
magnet_set_display_name(struct magnet_resource *res, const char *name)
{
	const char *atom;

	g_return_if_fail(res);
	g_return_if_fail(name);

	atom = atom_str_get(name);
	atom_str_free_null(&res->display_name);
	res->display_name = atom;
}
Ejemplo n.º 16
0
static void
free_upload_data(const void *unused_key, void *value, void *unused_data)
{
	struct upload_data *data = value;

	(void) unused_key;
	(void) unused_data;
	g_assert(data->us);
	g_assert(data->filename);

	data->us = NULL;
	atom_str_free_null(&data->filename);
	WFREE(data);
}
Ejemplo n.º 17
0
/**
 * Dispose of header formatting context.
 */
void
header_fmt_free(header_fmt_t **hf_ptr)
{
	header_fmt_t *hf = *hf_ptr;

	if (hf) {
		header_fmt_check(hf);

		str_destroy_null(&hf->header);
		atom_str_free_null(&hf->sep);
		hf->magic = 0;
		WFREE(hf);
		*hf_ptr = NULL;
	}
}
Ejemplo n.º 18
0
/**
 * Ensures that we have a valid `gwc_current_url' or pick a new one.
 * Also force change a the current URL after too many uses.
 *
 * @return TRUE if we got a valid URL.
 */
static bool
gwc_check_current_url(void)
{
    if (gwc_current_url == NULL || gwc_current_reused >= MAX_GWC_REUSE) {
        /*
         * `gwc_current_url' must be an atom since we may replace the value
         * in the cache at any time: we could be using a cache even after
         * its entry has been superseded.
         */
        const char *ptr = gwc_pick();

        atom_str_free_null(&gwc_current_url);
        gwc_current_url = ptr == NULL ? NULL : atom_str_get(ptr);
        gwc_current_reused = 0;
    } else
        gwc_current_reused++;

    return gwc_current_url != NULL;
}
Ejemplo n.º 19
0
static void
adns_cache_free_entry(adns_cache_t *cache, unsigned i)
{
	adns_cache_entry_t *entry;

	g_assert(cache);
	g_assert(i < G_N_ELEMENTS(cache->entries));

	entry = cache->entries[i];
	if (entry) {
		g_assert(i == entry->id);
		g_assert(entry->hostname);
		g_assert(entry->n > 0);

		atom_str_free_null(&entry->hostname);
		wfree(entry, adns_cache_entry_size(entry->n));
		cache->entries[i] = NULL;
	}
}
Ejemplo n.º 20
0
/**
 * Terminate host browsing.
 */
void
browse_host_dl_free(struct browse_ctx **ptr)
{
	struct browse_ctx *bc = *ptr;

	if (bc) {	
		atom_str_free_null(&bc->vendor);
		if (bc->rx) {
			rx_free(bc->rx);
			bc->rx = NULL;
		}
		if (!bc->closed) {
			search_dissociate_browse(bc->sh, bc->owner);
		}
		HFREE_NULL(bc->data);
		WFREE(bc);
		*ptr = NULL;
	}
}
Ejemplo n.º 21
0
/**
 * Updates vendor, version and info column.
 */
static void
nodes_gui_update_node_info(struct node_data *data, gnet_node_info_t *info)
{
    gnet_node_status_t status;

    g_assert(info != NULL);

    if (data == NULL)
        data = find_node(info->node_id);

	g_assert(NULL != data);
	g_assert(data->node_id == info->node_id);

    if (guc_node_get_status(info->node_id, &status)) {
		str_bprintf(data->version, sizeof data->version, "%u.%u",
				info->proto_major, info->proto_minor);
		atom_str_free_null(&data->user_agent);
		data->user_agent = info->vendor ? atom_str_get(info->vendor) : NULL;
		data->country = info->country;
	}
}
Ejemplo n.º 22
0
static void
file_object_free(struct file_object * const fo)
{
    g_return_if_fail(fo);
    file_object_check(fo);
    g_return_if_fail(1 == fo->ref_count);

    if (fo->removed) {
        const struct file_object *xfo;

        xfo = hikset_lookup(file_object_mode_get_table(fo->accmode),
                            fo->pathname);
        g_assert(xfo != fo);
    } else {
        file_object_remove(fo);
    }

    fd_close(&fo->fd);
    atom_str_free_null(&fo->pathname);
    fo->magic = 0;
    WFREE(fo);
}
Ejemplo n.º 23
0
/**
 * Free the callout queue and all contained event objects.
 */
static void
cq_free(cqueue_t *cq)
{
	cevent_t *ev;
	cevent_t *ev_next;
	int i;
	struct chash *ch;

	cqueue_check(cq);

	if (cq->cq_current != NULL) {
		s_carp("%s(): %squeue \"%s\" still within cq_clock()", G_STRFUNC,
			CSUBQUEUE_MAGIC == cq->cq_magic ? "sub" : "", cq->cq_name);
	}

	mutex_lock(&cq->cq_lock);

	for (ch = cq->cq_hash, i = 0; i < HASH_SIZE; i++, ch++) {
		for (ev = ch->ch_head; ev; ev = ev_next) {
			ev_next = ev->ce_bnext;
			ev->ce_magic = 0;
			WFREE(ev);
		}
	}

	if (cq->cq_periodic) {
		hset_foreach_remove(cq->cq_periodic, cq_free_periodic, NULL);
		hset_free_null(&cq->cq_periodic);
	}

	if (cq->cq_idle) {
		hset_foreach_remove(cq->cq_idle, cq_free_idle, cq);
		hset_free_null(&cq->cq_idle);
	}

	XFREE_NULL(cq->cq_hash);
	atom_str_free_null(&cq->cq_name);

	/*
	 * Unlocking the cq->cq_lock mutex (taken above) prevents a loud warning in
	 * mutex_destroy() in case the mutex was already locked by our thread,
	 * meaning we were already in cq_clock().  In that situation however,
	 * we already warned upon entry, and therefore there is no need for a
	 * second warning.
	 *
	 * If the mutex was not taken and someone else attempts to grab it at that
	 * stage, there will be a slight window which fortunately will be loudly
	 * detected by mutex_destroy(), as a case of a mutex being destroyed
	 * whilst owned by another thread.
	 *
	 * No valid application code should attempt to sneak in at this stage to
	 * grab that mutex anyway, so our logic is safe and we will be copiously
	 * warned if something unexpected happens.
	 *		--RAM, 2012-12-04.
	 */

	mutex_unlock(&cq->cq_lock);
	mutex_destroy(&cq->cq_lock);
	mutex_destroy(&cq->cq_idle_lock);

	/*
	 * If freeing a sub-queue, the object is a bit larger than a queue,
	 * and we have more cleanup to do...
	 */

	if (CSUBQUEUE_MAGIC == cq->cq_magic) {
		cq_subqueue_free((struct csubqueue *) cq);
	} else {
		cq->cq_magic = 0;
		WFREE(cq);
	}
}
Ejemplo n.º 24
0
/**
 * Locate statistics structure for the file.
 *
 * If a SHA1 is given, we search by SHA1. Otherwise we search by (name, size)
 * and if the record is missing the SHA1, probably because it was not
 * available at the time of insertion, then it is added to the structure
 * and recorded as such.
 */
static struct ul_stats *
upload_stats_find(const struct sha1 *sha1, const char *pathname, guint64 size)
{
	struct ul_stats *s = NULL;

	if (upload_stats_list) {
		static const struct ul_stats zero_stats;
		struct ul_stats key;
		gconstpointer orig_key;

		g_assert(upload_stats_by_sha1);

		if (sha1) {
			s = g_hash_table_lookup(upload_stats_by_sha1, sha1);
			if (s)
				goto done;		/* Found it by SHA1 */
		}

		key = zero_stats;
		key.pathname = atom_str_get(pathname);
		key.size = size;

		if (hash_list_find(upload_stats_list, &key, &orig_key))
			s = deconstify_gpointer(orig_key);
		atom_str_free_null(&key.pathname);

		if (s && sha1) {
			/* Was missing from the by-SHA1 table */
			if (NULL == s->sha1) {
				/* SHA1 was unknown */

				s->sha1 = atom_sha1_get(sha1);
			} else {
				/* SHA1 changed, file was modified */
				struct ul_stats *old =
					g_hash_table_lookup(upload_stats_by_sha1, s->sha1);

				g_assert(old == s);		/* Must be the same filename entry */

				g_hash_table_remove(upload_stats_by_sha1, s->sha1);
				atom_sha1_free(s->sha1);
				s->sha1 = atom_sha1_get(sha1);
			}
			gm_hash_table_insert_const(upload_stats_by_sha1, s->sha1, s);
		}
	}

done:

	/* We guarantee the SHA1 is present in the record if known */
	g_assert(!(s && sha1) || s->sha1);

	/* Postcondition: if we return something, it must be "correct" */
	if (s != NULL) {
		g_assert(atom_is_str(s->pathname));
		g_assert(atom_is_str(s->filename));
		g_assert(s->norm >= 0.0);
	}

	return s;
}
Ejemplo n.º 25
0
/**
 * Destroy a GHC.
 */
static void
ghc_free(struct ghc *ghc)
{
	atom_str_free_null(&ghc->url);
	WFREE(ghc);
}
Ejemplo n.º 26
0
/**
 * Free a namesize structure.
 */
void
namesize_free(namesize_t *ns)
{
	atom_str_free_null(&ns->name);
	WFREE(ns);
}
Ejemplo n.º 27
0
/**
 * Add new URL to cache, possibly pushing off an older one if cache is full.
 *
 * @return TRUE if the URL was added, FALSE otherwise.
 */
static bool
gwc_add(const char *new_url)
{
    const char *url_atom;
    const char *old_url;
    char *url, *ret;

    url = h_strdup(new_url); /* url_normalize() can modify the URL */

    ret = url_normalize(url, URL_POLICY_GWC_RULES);
    if (!ret) {
        g_warning("%s(): ignoring bad web cache URL \"%s\"",
                  G_STRFUNC, new_url);
        HFREE_NULL(url);
        return FALSE;
    }
    if (ret != url) {
        HFREE_NULL(url);
        url = ret;
    }

    /*
     * Don't add duplicates to the cache.
     */

    if (
        hset_contains(gwc_known_url, url) ||
        hset_contains(gwc_failed_url, url)
    ) {
        HFREE_NULL(url);
        return FALSE;
    }

    /*
     * OK, record new entry at the `gwc_url_slot'.
     */

    if (++gwc_url_slot >= MAX_GWC_URLS)
        gwc_url_slot = 0;

    g_assert(url != NULL);
    url_atom = atom_str_get(url);
    HFREE_NULL(url);

    /*
     * Expire any entry present at the slot we're about to write into.
     */

    old_url = gwc_url[gwc_url_slot].url;

    if (old_url != NULL) {
        g_assert(hset_contains(gwc_known_url, old_url));
        hset_remove(gwc_known_url, old_url);
        atom_str_free_null(&old_url);
        gwc_url[gwc_url_slot].url = NULL;
    }

    hset_insert(gwc_known_url, url_atom);

    gwc_url[gwc_url_slot].url = url_atom;
    gwc_url[gwc_url_slot].stamp = 0;
    gwc_file_dirty = TRUE;

    if (GNET_PROPERTY(bootstrap_debug)) {
        g_debug("%s(): loaded GWC URL %s", G_STRFUNC, url_atom);
    }

    return TRUE;
}