aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/http-files/src/manager.vala12
-rw-r--r--xmpp-vala/CMakeLists.txt1
-rw-r--r--xmpp-vala/src/core/xmpp_log.vala127
-rw-r--r--xmpp-vala/src/core/xmpp_stream.vala122
4 files changed, 137 insertions, 125 deletions
diff --git a/plugins/http-files/src/manager.vala b/plugins/http-files/src/manager.vala
index 5b804a00..f398b700 100644
--- a/plugins/http-files/src/manager.vala
+++ b/plugins/http-files/src/manager.vala
@@ -33,16 +33,22 @@ public class Manager : StreamInteractionModule, Object {
}
public bool is_upload_available(Account account) {
- return max_file_sizes.has_key(account);
+ lock (max_file_sizes) {
+ return max_file_sizes.has_key(account);
+ }
}
public int? get_max_file_size(Account account) {
- return max_file_sizes[account];
+ lock (max_file_sizes) {
+ return max_file_sizes[account];
+ }
}
private void on_stream_negotiated(Account account, Core.XmppStream stream) {
stream_interactor.module_manager.get_module(account, UploadStreamModule.IDENTITY).feature_available.connect((stream, max_file_size) => {
- max_file_sizes[account] = max_file_size;
+ lock (max_file_sizes) {
+ max_file_sizes[account] = max_file_size;
+ }
upload_available(account);
});
}
diff --git a/xmpp-vala/CMakeLists.txt b/xmpp-vala/CMakeLists.txt
index 80e665e2..54bd3886 100644
--- a/xmpp-vala/CMakeLists.txt
+++ b/xmpp-vala/CMakeLists.txt
@@ -13,6 +13,7 @@ SOURCES
"src/core/stanza_node.vala"
"src/core/stanza_reader.vala"
"src/core/stanza_writer.vala"
+ "src/core/xmpp_log.vala"
"src/core/xmpp_stream.vala"
"src/module/bind.vala"
diff --git a/xmpp-vala/src/core/xmpp_log.vala b/xmpp-vala/src/core/xmpp_log.vala
new file mode 100644
index 00000000..7cfbf92f
--- /dev/null
+++ b/xmpp-vala/src/core/xmpp_log.vala
@@ -0,0 +1,127 @@
+using Gee;
+
+namespace Xmpp.Core {
+
+public class XmppLog {
+ protected const string ANSI_COLOR_END = "\x1b[0m";
+ protected const string ANSI_COLOR_WHITE = "\x1b[37;1m";
+
+ class NodeLogDesc {
+ public string? name;
+ private string? ns_uri;
+ private string? val;
+ private Map<string, string?> attrs = new HashMap<string, string?>();
+ private NodeLogDesc? inner;
+
+ public NodeLogDesc(string desc) {
+ string d = desc;
+
+ if (d.contains("[")) {
+ int start = d.index_of("[");
+ int end = d.index_of("]");
+ string attrs = d.substring(start + 1, end - start - 1);
+ d = d.substring(0, start) + d.substring(end + 1);
+ foreach (string attr in attrs.split(",")) {
+ if (attr.contains("=")) {
+ string key = attr.substring(0, attr.index_of("="));
+ string val = attr.substring(attr.index_of("=") + 1);
+ this.attrs[key] = val;
+ } else {
+ this.attrs[attr] = null;
+ }
+ }
+ }
+ if (d.contains(":") && d.index_of("{") == 0 && d.index_of("}") != -1) {
+ int end = d.index_of("}");
+ this.ns_uri = d.substring(1, end - 2);
+ d = d.substring(end + 2);
+ }
+ if (d.contains(".")) {
+ inner = new NodeLogDesc(d.substring(d.index_of(".") + 1));
+ d = d.substring(0, d.index_of("."));
+ } else if (d.contains("=")) {
+ this.val = d.substring(d.index_of("="));
+ d = d.substring(0, d.index_of("="));
+ }
+
+ if (d != "") this.name = d;
+ }
+
+ public bool matches(StanzaNode node) {
+ if (name != null && node.name != name) return false;
+ if (ns_uri != null && node.ns_uri != ns_uri) return false;
+ if (val != null && node.val != val) return false;
+ foreach (var pair in attrs.entries) {
+ if (pair.value == null && node.get_attribute(pair.key) == null) return false;
+ else if (pair.value != null && pair.value != node.get_attribute(pair.key)) return false;
+ }
+ if (inner == null) return true;
+ foreach (StanzaNode snode in node.get_all_subnodes()) {
+ if (((!)inner).matches(snode)) return true;
+ }
+ return false;
+ }
+ }
+
+ private bool use_ansi;
+ private bool hide_ns = true;
+ private string ident;
+ private string desc;
+ private Gee.List<NodeLogDesc> descs = new ArrayList<NodeLogDesc>();
+
+ public XmppLog(string? ident = null, string? desc = null) {
+ this.ident = ident ?? "";
+ this.desc = desc ?? "";
+ this.use_ansi = is_atty(stderr.fileno());
+ while (this.desc.contains(";")) {
+ string opt = this.desc.substring(0, this.desc.index_of(";"));
+ this.desc = this.desc.substring(opt.length + 1);
+ switch (opt) {
+ case "ansi": use_ansi = true; break;
+ case "no-ansi": use_ansi = false; break;
+ case "hide-ns": hide_ns = true; break;
+ case "show-ns": hide_ns = false; break;
+ }
+ }
+ if (desc != "") {
+ foreach (string d in this.desc.split("|")) {
+ descs.add(new NodeLogDesc(d));
+ }
+ }
+ }
+
+ public virtual bool should_log_node(StanzaNode node) {
+ if (ident == "" || desc == "") return false;
+ if (desc == "all") return true;
+ foreach (var desc in descs) {
+ if (desc.matches(node)) return true;
+ }
+ return false;
+ }
+
+ public virtual bool should_log_str(string str) {
+ if (ident == "" || desc == "") return false;
+ if (desc == "all") return true;
+ foreach (var desc in descs) {
+ if (desc.name == "#text") return true;
+ }
+ return false;
+ }
+
+ public void node(string what, StanzaNode node) {
+ if (should_log_node(node)) {
+ stderr.printf("%sXMPP %s [%s]%s\n%s\n", ANSI_COLOR_WHITE, what, ident, ANSI_COLOR_END, use_ansi ? node.to_ansi_string(hide_ns) : node.to_string());
+ }
+ }
+
+ public void str(string what, string str) {
+ if (should_log_str(str)) {
+ stderr.printf("%sXMPP %s [%s]%s\n%s\n", ANSI_COLOR_WHITE, what, ident, ANSI_COLOR_END, str);
+ }
+ }
+
+ [CCode (cname = "isatty")]
+ private static extern bool is_atty(int fd);
+}
+
+}
diff --git a/xmpp-vala/src/core/xmpp_stream.vala b/xmpp-vala/src/core/xmpp_stream.vala
index 682639a8..715e7832 100644
--- a/xmpp-vala/src/core/xmpp_stream.vala
+++ b/xmpp-vala/src/core/xmpp_stream.vala
@@ -10,128 +10,6 @@ public errordomain IOStreamError {
}
-public class XmppLog {
- protected const string ANSI_COLOR_END = "\x1b[0m";
- protected const string ANSI_COLOR_WHITE = "\x1b[37;1m";
-
- class NodeLogDesc {
- public string? name;
- private string? ns_uri;
- private string? val;
- private Map<string, string?> attrs = new HashMap<string, string?>();
- private NodeLogDesc? inner;
-
- public NodeLogDesc(string desc) {
- string d = desc;
-
- if (d.contains("[")) {
- int start = d.index_of("[");
- int end = d.index_of("]");
- string attrs = d.substring(start + 1, end - start - 1);
- d = d.substring(0, start) + d.substring(end + 1);
- foreach (string attr in attrs.split(",")) {
- if (attr.contains("=")) {
- string key = attr.substring(0, attr.index_of("="));
- string val = attr.substring(attr.index_of("=") + 1);
- this.attrs[key] = val;
- } else {
- this.attrs[attr] = null;
- }
- }
- }
- if (d.contains(":") && d.index_of("{") == 0 && d.index_of("}") != -1) {
- int end = d.index_of("}");
- this.ns_uri = d.substring(1, end - 2);
- d = d.substring(end + 2);
- }
- if (d.contains(".")) {
- inner = new NodeLogDesc(d.substring(d.index_of(".") + 1));
- d = d.substring(0, d.index_of("."));
- } else if (d.contains("=")) {
- this.val = d.substring(d.index_of("="));
- d = d.substring(0, d.index_of("="));
- }
-
- if (d != "") this.name = d;
- }
-
- public bool matches(StanzaNode node) {
- if (name != null && node.name != name) return false;
- if (ns_uri != null && node.ns_uri != ns_uri) return false;
- if (val != null && node.val != val) return false;
- foreach (var pair in attrs.entries) {
- if (pair.value == null && node.get_attribute(pair.key) == null) return false;
- else if (pair.value != null && pair.value != node.get_attribute(pair.key)) return false;
- }
- if (inner == null) return true;
- foreach (StanzaNode snode in node.get_all_subnodes()) {
- if (((!)inner).matches(snode)) return true;
- }
- return false;
- }
- }
-
- private bool use_ansi;
- private bool hide_ns = true;
- private string ident;
- private string desc;
- private ArrayList<NodeLogDesc> descs = new ArrayList<NodeLogDesc>();
-
- public XmppLog(string? ident = null, string? desc = null) {
- this.ident = ident ?? "";
- this.desc = desc ?? "";
- this.use_ansi = is_atty(stderr.fileno());
- while (this.desc.contains(";")) {
- string opt = this.desc.substring(0, this.desc.index_of(";"));
- this.desc = this.desc.substring(opt.length + 1);
- switch (opt) {
- case "ansi": use_ansi = true; break;
- case "no-ansi": use_ansi = false; break;
- case "hide-ns": hide_ns = true; break;
- case "show-ns": hide_ns = false; break;
- }
- }
- if (desc != "") {
- foreach (string d in this.desc.split("|")) {
- descs.add(new NodeLogDesc(d));
- }
- }
- }
-
- public virtual bool should_log_node(StanzaNode node) {
- if (ident == "" || desc == "") return false;
- if (desc == "all") return true;
- foreach (var desc in descs) {
- if (desc.matches(node)) return true;
- }
- return false;
- }
-
- public virtual bool should_log_str(string str) {
- if (ident == "" || desc == "") return false;
- if (desc == "all") return true;
- foreach (var desc in descs) {
- if (desc.name == "#text") return true;
- }
- return false;
- }
-
- public void node(string what, StanzaNode node) {
- if (should_log_node(node)) {
- stderr.printf("%sXMPP %s [%s]%s\n%s\n", ANSI_COLOR_WHITE, what, ident, ANSI_COLOR_END, use_ansi ? node.to_ansi_string(hide_ns) : node.to_string());
- }
- }
-
- public void str(string what, string str) {
- if (should_log_str(str)) {
- stderr.printf("%sXMPP %s [%s]%s\n%s\n", ANSI_COLOR_WHITE, what, ident, ANSI_COLOR_END, str);
- }
- }
-
- [CCode (cname = "isatty")]
- private static extern bool is_atty(int fd);
-}
-
public class XmppStream {
private static string NS_URI = "http://etherx.jabber.org/streams";