[tracker/wip/carlosg/remote-module-reduction: 1/3] libtracker-sparql: Port remote TrackerSparqlConnection to new http helpers
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/remote-module-reduction: 1/3] libtracker-sparql: Port remote TrackerSparqlConnection to new http helpers
- Date: Sun, 24 Apr 2022 11:58:43 +0000 (UTC)
commit 6eec60afefff51b157a32b9cd99b78d32b5a4811
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Apr 23 14:18:26 2022 +0200
libtracker-sparql: Port remote TrackerSparqlConnection to new http helpers
Remove the direct soup dependency by using TrackerHttpClient, that deals
with soup itself. This also means the remote connection objects can move
to the main library code, instead of being built as standalone modules.
In consequence, the older remote modules are no longer built, and their
loading infrastructure removed.
docs/reference/libtracker-sparql/meson.build | 2 +-
src/libtracker-sparql/meson.build | 64 -----------
src/libtracker-sparql/remote/meson.build | 5 +
src/libtracker-sparql/remote/tracker-remote.vala | 129 ++++++-----------------
src/libtracker-sparql/remote/tracker-remote.vapi | 15 +++
src/libtracker-sparql/tracker-backend.vala | 5 +
src/libtracker-sparql/tracker-remote-module.c | 82 --------------
7 files changed, 57 insertions(+), 245 deletions(-)
---
diff --git a/docs/reference/libtracker-sparql/meson.build b/docs/reference/libtracker-sparql/meson.build
index e52cd5235..759f188bf 100644
--- a/docs/reference/libtracker-sparql/meson.build
+++ b/docs/reference/libtracker-sparql/meson.build
@@ -61,7 +61,7 @@ docs_name = 'Tracker'
hotdoc.generate_doc(docs_name,
project_version: tracker_version,
languages: [ 'c', 'python', 'javascript' ],
- gi_c_sources: [libtracker_sparql_c_sources, libtracker_sparql_c_public_headers,
libtracker_sparql_remote_c_sources],
+ gi_c_sources: [libtracker_sparql_c_sources, libtracker_sparql_c_public_headers],
gi_sources: [tracker_sparql_gir[0].full_path()],
sitemap: 'sitemap.txt',
index: 'index.md',
diff --git a/src/libtracker-sparql/meson.build b/src/libtracker-sparql/meson.build
index 9192fccfe..24952b7d2 100644
--- a/src/libtracker-sparql/meson.build
+++ b/src/libtracker-sparql/meson.build
@@ -102,7 +102,6 @@ libtracker_sparql_private = static_library('tracker-sparql-private',
'core/libtracker-data.vapi',
'direct/tracker-direct.vapi',
'tracker-backend.vala',
- 'tracker-remote-module.c',
tracker_gresources,
c_args: [
@@ -151,69 +150,6 @@ tracker_sparql_dep = declare_dependency(
dependencies: [glib, gio],
)
-libtracker_sparql_remote_c_sources = files(
- 'remote/tracker-remote-statement.c',
- 'tracker-serializer.c',
- 'tracker-serializer-json.c',
- 'tracker-serializer-trig.c',
- 'tracker-serializer-turtle.c',
- 'tracker-serializer-xml.c',
-)
-
-libtracker_sparql_remote_vala_sources = files(
- 'remote/tracker-remote.vapi',
- 'remote/tracker-json-cursor.vala',
- 'remote/tracker-xml-cursor.vala',
- 'remote/tracker-remote.vala',
-)
-
-if libsoup2.found()
- libtracker_remote_soup2 = shared_module('tracker-remote-soup2',
- libtracker_sparql_remote_c_sources, libtracker_sparql_remote_vala_sources,
- dependencies: [json_glib, libxml2, tracker_common_dep, tracker_sparql_dep,
- tracker_sparql_vapi_dep, tracker_data_dep, libsoup2],
- c_args: tracker_c_args + [
- '-include', 'config.h',
- '-include', 'libtracker-sparql/tracker-private.h',
- ],
- vala_args: [
- '--debug',
- '--pkg', 'posix',
- # FIXME: Meson has code to add --target-glib automatically, but it
- # doesn't seem to work here.
- '--target-glib', glib_required,
- '--define=SOUP2',
- ],
- install: true,
- install_dir: tracker_internal_libs_dir,
- name_suffix: 'so',
- )
- libtracker_sparql_modules += libtracker_remote_soup2
-endif
-
-if libsoup3.found()
- libtracker_remote_soup3 = shared_module('tracker-remote-soup3',
- libtracker_sparql_remote_c_sources, libtracker_sparql_remote_vala_sources,
- dependencies: [json_glib, libxml2, tracker_common_dep, tracker_sparql_dep,
- tracker_sparql_vapi_dep, tracker_data_dep, libsoup3],
- c_args: tracker_c_args + [
- '-include', 'config.h',
- '-include', 'libtracker-sparql/tracker-private.h',
- ],
- vala_args: [
- '--debug',
- '--pkg', 'posix',
- # FIXME: Meson has code to add --target-glib automatically, but it
- # doesn't seem to work here.
- '--target-glib', glib_required,
- ],
- install: true,
- install_dir: tracker_internal_libs_dir,
- name_suffix: 'so',
- )
- libtracker_sparql_modules += libtracker_remote_soup3
-endif
-
pkg.generate(libtracker_sparql,
description: 'Tracker : A SPARQL triple store library',
requires: [glib, gio, gobject],
diff --git a/src/libtracker-sparql/remote/meson.build b/src/libtracker-sparql/remote/meson.build
index ca137b85e..3d9e0c653 100644
--- a/src/libtracker-sparql/remote/meson.build
+++ b/src/libtracker-sparql/remote/meson.build
@@ -1,5 +1,10 @@
remote_files = files(
'tracker-http.c',
+ 'tracker-remote-statement.c',
+ 'tracker-remote.vapi',
+ 'tracker-json-cursor.vala',
+ 'tracker-xml-cursor.vala',
+ 'tracker-remote.vala',
)
module_sources = files('tracker-http-module.c')
diff --git a/src/libtracker-sparql/remote/tracker-remote.vala
b/src/libtracker-sparql/remote/tracker-remote.vala
index 71a1d3965..aef5325c6 100644
--- a/src/libtracker-sparql/remote/tracker-remote.vala
+++ b/src/libtracker-sparql/remote/tracker-remote.vala
@@ -18,117 +18,48 @@
*
* Author: Carlos Garnacho <carlosg gnome org>
*/
-[CCode (cname = "PACKAGE_VERSION")]
-extern const string PACKAGE_VERSION;
-
public class Tracker.Remote.Connection : Tracker.Sparql.Connection {
-
- internal Soup.Session _session;
+ internal HttpClient _client;
internal string _base_uri;
- const string XML_TYPE = "application/sparql-results+xml";
- const string JSON_TYPE = "application/sparql-results+json";
- const string TTL_TYPE = "text/turtle";
- const string TRIG_TYPE = "application/trig";
- const string USER_AGENT = "Tracker/" + PACKAGE_VERSION + "
(https://gitlab.gnome.org/GNOME/tracker/issues/; tracker-list lists gnome org) Tracker/" + PACKAGE_VERSION;
-
public Connection (string base_uri) {
Object ();
_base_uri = base_uri;
- _session = new Soup.Session ();
- }
-
- private Soup.Message create_describe_request (string sparql, RdfFormat format) {
- var uri = _base_uri + "?query=" + GLib.Uri.escape_string (sparql, null, false);
- var message = new Soup.Message ("GET", uri);
-#if SOUP2
- var headers = message.request_headers;
-#else
- var headers = message.get_request_headers();
-#endif
-
- headers.append ("User-Agent", USER_AGENT);
-
- if (format == RdfFormat.TURTLE)
- headers.append ("Accept", TTL_TYPE);
- else if (format == RdfFormat.TRIG)
- headers.append ("Accept", TRIG_TYPE);
-
- return message;
+ _client = new HttpClient();
}
- private Soup.Message create_request (string sparql) {
- var uri = _base_uri + "?query=" + GLib.Uri.escape_string (sparql, null, false);
- var message = new Soup.Message ("GET", uri);
-#if SOUP2
- var headers = message.request_headers;
-#else
- var headers = message.get_request_headers();
-#endif
-
- headers.append ("User-Agent", USER_AGENT);
- headers.append ("Accept", JSON_TYPE);
- headers.append ("Accept", XML_TYPE);
+ private Sparql.Cursor create_cursor (GLib.InputStream stream, SerializerFormat format) throws
GLib.Error, Sparql.Error {
+ var buffer = new uchar[20 * 1024 * 1024];
+ size_t len;
+ stream.read_all (buffer, out len, null);
- return message;
- }
-
- private Sparql.Cursor create_cursor (Soup.Message message, string document) throws GLib.Error,
Sparql.Error {
-#if SOUP2
- var status_code = message.status_code;
- var headers = message.response_headers;
-#else
- var status_code = message.get_status();
- var headers = message.get_response_headers();
-#endif
-
- if (status_code != Soup.Status.OK) {
- throw new Sparql.Error.UNSUPPORTED ("Unhandled status code %u, document is: %s",
- status_code, document);
- }
-
- var content_type = headers.get_content_type (null);
- long length = document.length;
-
- if (content_type == JSON_TYPE) {
- return new Tracker.Remote.JsonCursor (document, length);
- } else if (content_type == XML_TYPE) {
- return new Tracker.Remote.XmlCursor (document, length);
+ if (format == SerializerFormat.JSON) {
+ return new Tracker.Remote.JsonCursor ((string) buffer, (long) len);
+ } else if (format == SerializerFormat.XML) {
+ return new Tracker.Remote.XmlCursor ((string) buffer, (long) len);
} else {
- throw new Sparql.Error.UNSUPPORTED ("Unknown content type '%s', document is: %s",
content_type, document);
+ throw new Sparql.Error.UNSUPPORTED ("Unparseable content type, document is: %s",
(string) buffer);
}
}
public override Sparql.Cursor query (string sparql, Cancellable? cancellable) throws GLib.Error,
Sparql.Error, IOError {
- var message = create_request (sparql);
-
-#if SOUP2
- _session.send_message (message);
- var data = (string) message.response_body.flatten ().data;
-#else
- var body = _session.send_and_read (message);
- var data = (string) body.get_data();
-#endif
+ uint flags =
+ (1 << SerializerFormat.JSON) |
+ (1 << SerializerFormat.XML);
+ SerializerFormat format;
+ var istream = _client.send_message (_base_uri, sparql, flags, cancellable, out format);
- if (data == null || data == "")
- throw new Sparql.Error.UNSUPPORTED ("Empty response");
-
- if (cancellable != null && cancellable.is_cancelled ())
- throw new IOError.CANCELLED ("Operation was cancelled");
-
- return create_cursor (message, (string) data);
+ return create_cursor (istream, format);
}
public async override Sparql.Cursor query_async (string sparql, Cancellable? cancellable) throws
GLib.Error, Sparql.Error, IOError {
- var message = create_request (sparql);
+ uint flags =
+ (1 << SerializerFormat.JSON) |
+ (1 << SerializerFormat.XML);
+ SerializerFormat format;
+ var istream = yield _client.send_message_async (_base_uri, sparql, flags, cancellable, out
format);
-#if SOUP2
- yield _session.send_async (message, cancellable);
- return create_cursor (message, (string) message.response_body.flatten ().data);
-#else
- var body = yield _session.send_and_read_async (message, GLib.Priority.DEFAULT, cancellable);
- return create_cursor (message, (string) body.get_data());
-#endif
+ return create_cursor (istream, format);
}
public override Sparql.Statement? query_statement (string sparql, GLib.Cancellable? cancellable =
null) throws Sparql.Error {
@@ -143,11 +74,13 @@ public class Tracker.Remote.Connection : Tracker.Sparql.Connection {
}
public async override GLib.InputStream serialize_async (SerializeFlags flags, RdfFormat format,
string sparql, GLib.Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError,
GLib.DBusError {
- var message = create_describe_request (sparql, format);
-#if SOUP2
- return yield _session.send_async (message, cancellable);
-#else
- return yield _session.send_async (message, GLib.Priority.DEFAULT, cancellable);
-#endif
+ uint formats = 0;
+ if (format == RdfFormat.TURTLE)
+ formats = 1 << SerializerFormat.TTL;
+ else if (format == RdfFormat.TRIG)
+ formats = 1 << SerializerFormat.TRIG;
+
+ SerializerFormat unused;
+ return yield _client.send_message_async (_base_uri, sparql, formats, cancellable, out unused);
}
}
diff --git a/src/libtracker-sparql/remote/tracker-remote.vapi
b/src/libtracker-sparql/remote/tracker-remote.vapi
index caf018b41..d266470e1 100644
--- a/src/libtracker-sparql/remote/tracker-remote.vapi
+++ b/src/libtracker-sparql/remote/tracker-remote.vapi
@@ -3,4 +3,19 @@ namespace Tracker {
class Remote.Statement : Sparql.Statement {
public Statement (Sparql.Connection conn, string query) throws Sparql.Error;
}
+
+ [CCode (cheader_filename = "libtracker-sparql/remote/tracker-http.h")]
+ class HttpClient : GLib.Object {
+ public HttpClient ();
+ public async GLib.InputStream send_message_async (string uri, string query, uint formats,
GLib.Cancellable? cancellable, out SerializerFormat format) throws GLib.Error;
+ public GLib.InputStream send_message (string uri, string query, uint formats,
GLib.Cancellable? cancellable, out SerializerFormat format) throws GLib.Error;
+ }
+
+ [CCode (cheader_filename = "libtracker-sparql/tracker-enums-private.h")]
+ enum SerializerFormat {
+ JSON,
+ XML,
+ TTL,
+ TRIG,
+ }
}
diff --git a/src/libtracker-sparql/tracker-backend.vala b/src/libtracker-sparql/tracker-backend.vala
index af1102d5a..f2d497f6a 100644
--- a/src/libtracker-sparql/tracker-backend.vala
+++ b/src/libtracker-sparql/tracker-backend.vala
@@ -82,3 +82,8 @@ public static async Tracker.Sparql.Connection tracker_sparql_connection_new_asyn
yield conn.init_async (Priority.DEFAULT, cancellable);
return conn;
}
+
+public static Tracker.Sparql.Connection tracker_sparql_connection_remote_new (string uri_base) {
+ Tracker.get_debug_flags ();
+ return new Tracker.Remote.Connection (uri_base);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]