summaryrefslogtreecommitdiff
path: root/plugins/common
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2016-06-26 08:39:49 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2016-06-26 08:39:49 +0200
commit29a7aef998e975b42401cfa96d1b750d91eadf06 (patch)
treeeda2bdff398789ea2358cc39986dd1f7ee9d027a /plugins/common
parent4e10e30c2f99d552239871aa1b27a08a6c18f1a4 (diff)
Imported Upstream version 0.23.2upstream/0.23.2
Diffstat (limited to 'plugins/common')
-rw-r--r--plugins/common/Makefile20
-rw-r--r--plugins/common/RESTSupport.vala49
-rw-r--r--plugins/common/SqliteSupport.vala76
-rw-r--r--plugins/common/VersionNumber.vala50
4 files changed, 49 insertions, 146 deletions
diff --git a/plugins/common/Makefile b/plugins/common/Makefile
new file mode 100644
index 0000000..90714a0
--- /dev/null
+++ b/plugins/common/Makefile
@@ -0,0 +1,20 @@
+
+PLUGIN := libshotwell-plugin-common
+PLUGIN_DIR := common
+
+PLUGIN_PKGS := \
+ gee-0.8 \
+ libxml-2.0 \
+ libsoup-2.4 \
+ json-glib-1.0 \
+ webkit2gtk-4.0
+
+SRC_FILES := Resources.vala RESTSupport.vala
+
+PLUGIN_EXTRAFLAGS := --vapi=shotwell-plugin-common.vapi \
+ --header=shotwell-plugin-common.h
+
+PLUGIN_EXTRALINKFLAGS :=
+
+include ../Makefile.plugin.mk
+
diff --git a/plugins/common/RESTSupport.vala b/plugins/common/RESTSupport.vala
index b512fe7..d9bf2ce 100644
--- a/plugins/common/RESTSupport.vala
+++ b/plugins/common/RESTSupport.vala
@@ -4,10 +4,24 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
-extern Soup.Message soup_form_request_new_from_multipart(string uri, Soup.Multipart multipart);
-
namespace Publishing.RESTSupport {
+// Ported from librest
+// https://git.gnome.org/browse/librest/tree/rest/sha1.c?id=e412da58080eec2e771482e7e4c509b9e71477ff#n38
+
+internal const int SHA1_HMAC_LENGTH = 20;
+
+public string hmac_sha1(string key, string message) {
+ uint8 buffer[SHA1_HMAC_LENGTH];
+ size_t len = SHA1_HMAC_LENGTH;
+
+ var mac = new Hmac (ChecksumType.SHA1, key.data);
+ mac.update (message.data);
+ mac.get_digest (buffer, ref len);
+
+ return Base64.encode (buffer[0:len]);
+}
+
public abstract class Session {
private string? endpoint_url = null;
private Soup.Session soup_session = null;
@@ -109,13 +123,17 @@ public class Argument {
}
public static Argument[] sort(Argument[] inputArray) {
- FixedTreeSet<Argument> sorted_args = new FixedTreeSet<Argument>(Argument.compare);
+ Gee.TreeSet<Argument> sorted_args = new Gee.TreeSet<Argument>(Argument.compare);
foreach (Argument arg in inputArray)
sorted_args.add(arg);
return sorted_args.to_array();
}
+
+ public string to_string () {
+ return "%s=%s".printf (this.key, this.value);
+ }
}
public class Transaction {
@@ -298,7 +316,7 @@ public class Transaction {
// concatenate the REST arguments array into an HTTP formdata string
string formdata_string = "";
for (int i = 0; i < arguments.length; i++) {
- formdata_string += ("%s=%s".printf(arguments[i].key, arguments[i].value));
+ formdata_string += arguments[i].to_string ();
if (i < arguments.length - 1)
formdata_string += "&";
}
@@ -338,6 +356,11 @@ public class Transaction {
assert(get_is_executed());
return message.response_headers;
}
+
+ public Soup.Message get_message() {
+ assert(get_is_executed());
+ return message;
+ }
public void add_argument(string name, string value) {
arguments += new Argument(name, value);
@@ -437,7 +460,7 @@ public class UploadTransaction : Transaction {
image_part_header.set_content_disposition("form-data", binary_disposition_table);
Soup.Message outbound_message =
- soup_form_request_new_from_multipart(get_endpoint_url(), message_parts);
+ Soup.Form.request_new_from_multipart(get_endpoint_url(), message_parts);
// TODO: there must be a better way to iterate over a map
Gee.MapIterator<string, string> i = message_headers.map_iterator();
bool cont = i.next();
@@ -562,7 +585,7 @@ public string decimal_entity_encode(string source) {
return encoded_str_builder.str;
}
-internal abstract class BatchUploader {
+public abstract class BatchUploader {
private int current_file = 0;
private Spit.Publishing.Publishable[] publishables = null;
private Session session = null;
@@ -659,20 +682,6 @@ public string asciify_string(string s) {
return b.str;
}
-/** @brief Work-around for a problem in libgee where a TreeSet can leak references when it
- * goes out of scope; please see https://bugzilla.gnome.org/show_bug.cgi?id=695045 for more
- * details. This class merely wraps it and adds a call to clear() to the destructor.
- */
-public class FixedTreeSet<G> : Gee.TreeSet<G> {
- public FixedTreeSet(owned CompareDataFunc<G>? comp_func = null) {
- base((owned) comp_func);
- }
-
- ~FixedTreeSet() {
- clear();
- }
-}
-
public abstract class GoogleSession : Session {
public abstract string get_user_name();
public abstract string get_access_token();
diff --git a/plugins/common/SqliteSupport.vala b/plugins/common/SqliteSupport.vala
deleted file mode 100644
index 0dcc99c..0000000
--- a/plugins/common/SqliteSupport.vala
+++ /dev/null
@@ -1,76 +0,0 @@
-/* Copyright 2016 Software Freedom Conservancy Inc.
- *
- * This software is licensed under the GNU LGPL (version 2.1 or later).
- * See the COPYING file in this distribution.
- */
-
-public errordomain DatabaseError {
- ERROR,
- BACKING,
- MEMORY,
- ABORT,
- LIMITS,
- TYPESPEC
-}
-
-public abstract class ImportableDatabaseTable {
-
- protected static Sqlite.Database db;
-
- public string table_name = null;
-
- protected void set_table_name(string table_name) {
- this.table_name = table_name;
- }
-
- // This method will throw an error on an SQLite return code unless it's OK, DONE, or ROW, which
- // are considered normal results.
- protected static void throw_error(string method, int res) throws DatabaseError {
- string msg = "(%s) [%d] - %s".printf(method, res, db.errmsg());
-
- switch (res) {
- case Sqlite.OK:
- case Sqlite.DONE:
- case Sqlite.ROW:
- return;
-
- case Sqlite.PERM:
- case Sqlite.BUSY:
- case Sqlite.READONLY:
- case Sqlite.IOERR:
- case Sqlite.CORRUPT:
- case Sqlite.CANTOPEN:
- case Sqlite.NOLFS:
- case Sqlite.AUTH:
- case Sqlite.FORMAT:
- case Sqlite.NOTADB:
- throw new DatabaseError.BACKING(msg);
-
- case Sqlite.NOMEM:
- throw new DatabaseError.MEMORY(msg);
-
- case Sqlite.ABORT:
- case Sqlite.LOCKED:
- case Sqlite.INTERRUPT:
- throw new DatabaseError.ABORT(msg);
-
- case Sqlite.FULL:
- case Sqlite.EMPTY:
- case Sqlite.TOOBIG:
- case Sqlite.CONSTRAINT:
- case Sqlite.RANGE:
- throw new DatabaseError.LIMITS(msg);
-
- case Sqlite.SCHEMA:
- case Sqlite.MISMATCH:
- throw new DatabaseError.TYPESPEC(msg);
-
- case Sqlite.ERROR:
- case Sqlite.INTERNAL:
- case Sqlite.MISUSE:
- default:
- throw new DatabaseError.ERROR(msg);
- }
- }
-}
-
diff --git a/plugins/common/VersionNumber.vala b/plugins/common/VersionNumber.vala
deleted file mode 100644
index 503cd65..0000000
--- a/plugins/common/VersionNumber.vala
+++ /dev/null
@@ -1,50 +0,0 @@
-/* Copyright 2016 Software Freedom Conservancy Inc.
- *
- * This software is licensed under the GNU Lesser General Public License
- * (version 2.1 or later). See the COPYING file in this distribution.
- */
-
-namespace Utils {
-
-/**
- * A class that represents a version number in the form x.y.z and is able to compare
- * different versions.
- */
-public class VersionNumber : Object, Gee.Comparable<VersionNumber> {
- private int[] version;
-
- public VersionNumber(int[] version) {
- this.version = version;
- }
-
- public VersionNumber.from_string(string str_version, string separator = ".") {
- string[] version_items = str_version.split(separator);
- this.version = new int[version_items.length];
- for (int i = 0; i < version_items.length; i++)
- this.version[i] = int.parse(version_items[i]);
- }
-
- public string to_string() {
- string[] version_items = new string[this.version.length];
- for (int i = 0; i < this.version.length; i++)
- version_items[i] = this.version[i].to_string();
- return string.joinv(".", version_items);
- }
-
- public int compare_to(VersionNumber other) {
- int max_len = ((this.version.length > other.version.length) ?
- this.version.length : other.version.length);
- int res = 0;
- for(int i = 0; i < max_len; i++) {
- int this_v = (i < this.version.length ? this.version[i] : 0);
- int other_v = (i < other.version.length ? other.version[i] : 0);
- res = this_v - other_v;
- if (res != 0)
- break;
- }
- return res;
- }
-}
-
-}
-