aboutsummaryrefslogtreecommitdiff
path: root/vala-xmpp/src/module
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2017-03-10 16:02:32 +0100
committerMarvin W <git@larma.de>2017-03-10 16:09:47 +0100
commit7a1aa8c806a63cfd031c082524501e26d4a181ee (patch)
tree9d7895ce184d87e329d3ad62d8cda1d10c2596d2 /vala-xmpp/src/module
parent5fc0435cc1227bf445d06a3931343020faaecd10 (diff)
downloaddino-7a1aa8c806a63cfd031c082524501e26d4a181ee.tar.gz
dino-7a1aa8c806a63cfd031c082524501e26d4a181ee.zip
Do not expose UUID lib dependency outside vala-xmpp library
Diffstat (limited to 'vala-xmpp/src/module')
-rw-r--r--vala-xmpp/src/module/iq/stanza.vala8
-rw-r--r--vala-xmpp/src/module/message/stanza.vala4
-rw-r--r--vala-xmpp/src/module/presence/stanza.vala4
-rw-r--r--vala-xmpp/src/module/roster/module.vala2
-rw-r--r--vala-xmpp/src/module/util.vala8
5 files changed, 17 insertions, 9 deletions
diff --git a/vala-xmpp/src/module/iq/stanza.vala b/vala-xmpp/src/module/iq/stanza.vala
index 99d589ff..561c5866 100644
--- a/vala-xmpp/src/module/iq/stanza.vala
+++ b/vala-xmpp/src/module/iq/stanza.vala
@@ -10,12 +10,12 @@ public class Stanza : Xmpp.Stanza {
public const string TYPE_RESULT = "result";
public const string TYPE_SET = "set";
- private Stanza(string id = UUID.generate_random_unparsed()) {
+ private Stanza(string? id = null) {
base.outgoing(new StanzaNode.build("iq"));
- this.id = id;
+ this.id = id ?? random_uuid();
}
- public Stanza.get(StanzaNode stanza_node, string id = UUID.generate_random_unparsed()) {
+ public Stanza.get(StanzaNode stanza_node, string? id = null) {
this(id);
this.type_ = TYPE_GET;
stanza.put_node(stanza_node);
@@ -29,7 +29,7 @@ public class Stanza : Xmpp.Stanza {
}
}
- public Stanza.set(StanzaNode stanza_node, string id = UUID.generate_random_unparsed()) {
+ public Stanza.set(StanzaNode stanza_node, string? id = null) {
this(id);
type_ = TYPE_SET;
stanza.put_node(stanza_node);
diff --git a/vala-xmpp/src/module/message/stanza.vala b/vala-xmpp/src/module/message/stanza.vala
index 811fbd22..8a9064a5 100644
--- a/vala-xmpp/src/module/message/stanza.vala
+++ b/vala-xmpp/src/module/message/stanza.vala
@@ -33,9 +33,9 @@ public class Stanza : Xmpp.Stanza {
}
}
- public Stanza(string id = UUID.generate_random_unparsed()) {
+ public Stanza(string? id = null) {
base.outgoing(new StanzaNode.build("message"));
- stanza.set_attribute(ATTRIBUTE_ID, id);
+ stanza.set_attribute(ATTRIBUTE_ID, id ?? random_uuid());
}
public Stanza.from_stanza(StanzaNode stanza_node, string my_jid) {
diff --git a/vala-xmpp/src/module/presence/stanza.vala b/vala-xmpp/src/module/presence/stanza.vala
index 3dc036e5..9ad8f791 100644
--- a/vala-xmpp/src/module/presence/stanza.vala
+++ b/vala-xmpp/src/module/presence/stanza.vala
@@ -80,9 +80,9 @@ public class Stanza : Xmpp.Stanza {
set { base.type_ = value; }
}
- public Stanza(string id = UUID.generate_random_unparsed()) {
+ public Stanza(string? id = null) {
stanza = new StanzaNode.build("presence");
- this.id = id;
+ this.id = id ?? random_uuid();
}
public Stanza.from_stanza(StanzaNode stanza_node, string my_jid) {
diff --git a/vala-xmpp/src/module/roster/module.vala b/vala-xmpp/src/module/roster/module.vala
index 9fa23a55..c8b09710 100644
--- a/vala-xmpp/src/module/roster/module.vala
+++ b/vala-xmpp/src/module/roster/module.vala
@@ -95,7 +95,7 @@ namespace Xmpp.Roster {
internal override string get_id() { return ID; }
private void roster_get(XmppStream stream) {
- Flag.get_flag(stream).iq_id = UUID.generate_random_unparsed();
+ Flag.get_flag(stream).iq_id = random_uuid();
StanzaNode query_node = new StanzaNode.build("query", NS_URI).add_self_xmlns();
Iq.Stanza iq = new Iq.Stanza.get(query_node, Flag.get_flag(stream).iq_id);
Iq.Module.get_module(stream).send_iq(stream, iq, new IqResponseListenerImpl());
diff --git a/vala-xmpp/src/module/util.vala b/vala-xmpp/src/module/util.vala
index 4d762883..65a9b261 100644
--- a/vala-xmpp/src/module/util.vala
+++ b/vala-xmpp/src/module/util.vala
@@ -10,4 +10,12 @@ namespace Xmpp {
string? get_resource_part(string jid) {
return jid.split("/")[1];
}
+
+ public string random_uuid() {
+ uint8[] rand = new uint8[16];
+ char[] str = new char[37];
+ UUID.generate_random(rand);
+ UUID.unparse_upper(rand, str);
+ return (string) str;
+ }
} \ No newline at end of file