예제 #1
0
GPtrArray*
meta0_utils_list_to_array(GSList *list)
{
	GSList *l;
	GPtrArray *result = NULL;

	EXTRA_ASSERT(list != NULL);

	result = meta0_utils_array_create();

	for (l=list; l ;l=l->next) {
		guint16 *p, *max;
		struct meta0_info_s *m0i;

		if (!(m0i = l->data))
			continue;

		gchar url[STRLEN_ADDRINFO];
		grid_addrinfo_to_string(&(m0i->addr), url, sizeof(url));

		p = (guint16*) m0i->prefixes;
		max = (guint16*) (m0i->prefixes + m0i->prefixes_size);
		for (; p<max; p++)
			meta0_utils_array_add(result, (guint8*)p, url);
	}

	return result;
}
예제 #2
0
static GError*
_load_from_base(struct sqlx_sqlite3_s *sq3, GPtrArray **result)
{
	GError *err = NULL;
	GPtrArray *array;
	sqlite3_stmt *stmt;
	int rc;
	guint count = 0;

	sqlite3_prepare_debug(rc, sq3->db, "SELECT prefix,addr,ROWID FROM meta1",
			-1, &stmt, NULL);
	if (rc != SQLITE_OK && rc != SQLITE_DONE)
		return SQLITE_GERROR(sq3->db, rc);

	array = meta0_utils_array_create();

	for (;;) {
		rc = sqlite3_step(stmt);
		if (rc == SQLITE_ROW) {
			gint64 rowid;
			const guint8 *prefix, *url;
			gsize prefix_len;

			prefix_len = sqlite3_column_bytes(stmt, 0);
			prefix = sqlite3_column_blob(stmt, 0);
			url = sqlite3_column_text(stmt, 1);
			rowid = sqlite3_column_int64(stmt, 2);

			if (prefix_len != 2)
				GRID_WARN("Invalid prefix for URL [%s] ROWID %"G_GINT64_FORMAT,
						url, rowid);
			else {
				meta0_utils_check_url_from_base((gchar**)&url);
				meta0_utils_array_add(array, prefix, (gchar*)url);
				count ++;
			}
		}
		else if (rc == SQLITE_DONE || rc == SQLITE_OK)
			break;
		else if (rc == SQLITE_BUSY)
			sleep(1);
		else {
			err = SQLITE_GERROR(sq3->db, rc);
			break;
		}
	}

	sqlite3_finalize_debug(rc, stmt);

	if (!err) {
		*result = array;
		GRID_INFO("Reloaded %u prefixes in %p (%u)",
				count, array, array->len);
	}

	return err;
}
예제 #3
0
GError*
meta1_prefixes_manage_all(struct meta1_prefixes_set_s *m1ps,
		const gchar *local_url)
{
	gint32 i32;
	guint16 u16;

	EXTRA_ASSERT(m1ps != NULL);

	g_mutex_lock(&m1ps->lock);
	memset(m1ps->cache, ~0, 8192);
	if (m1ps->by_prefix)
		meta0_utils_array_clean(m1ps->by_prefix);
	m1ps->by_prefix = meta0_utils_array_create();
	for (i32=0; i32<65536 ;i32++) {
		u16 = i32;
		meta0_utils_array_add(m1ps->by_prefix, (guint8*)(&u16), local_url);
	}
	g_mutex_unlock(&m1ps->lock);

	return NULL;
}