aboutsummaryrefslogtreecommitdiff
path: root/vala-xmpp
diff options
context:
space:
mode:
Diffstat (limited to 'vala-xmpp')
-rw-r--r--vala-xmpp/CMakeLists.txt3
-rw-r--r--vala-xmpp/src/core/stanza_writer.vala2
-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
-rw-r--r--vala-xmpp/vapi/uuid.vapi60
8 files changed, 79 insertions, 12 deletions
diff --git a/vala-xmpp/CMakeLists.txt b/vala-xmpp/CMakeLists.txt
index 3278d9c2..e7be66ae 100644
--- a/vala-xmpp/CMakeLists.txt
+++ b/vala-xmpp/CMakeLists.txt
@@ -64,10 +64,11 @@ SOURCES
"src/module/xep/0280_message_carbons.vala"
"src/module/xep/0333_chat_markers.vala"
"src/module/xep/pixbuf_storage.vala"
+CUSTOM_VAPIS
+ "${CMAKE_CURRENT_SOURCE_DIR}/vapi/uuid.vapi"
PACKAGES
${ENGINE_PACKAGES}
gpgme
- uuid
GENERATE_VAPI
vala-xmpp
GENERATE_HEADER
diff --git a/vala-xmpp/src/core/stanza_writer.vala b/vala-xmpp/src/core/stanza_writer.vala
index 625f42e2..26524d7b 100644
--- a/vala-xmpp/src/core/stanza_writer.vala
+++ b/vala-xmpp/src/core/stanza_writer.vala
@@ -2,8 +2,6 @@ namespace Xmpp.Core {
public class StanzaWriter {
private OutputStream output;
- private NamespaceState ns_state = new NamespaceState();
-
public StanzaWriter.for_stream(OutputStream output) {
this.output = output;
}
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
diff --git a/vala-xmpp/vapi/uuid.vapi b/vala-xmpp/vapi/uuid.vapi
new file mode 100644
index 00000000..991917a7
--- /dev/null
+++ b/vala-xmpp/vapi/uuid.vapi
@@ -0,0 +1,60 @@
+/* libuuid Vala Bindings
+ * Copyright 2014 Evan Nemerson <evan@nemerson.com>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+[CCode (cheader_filename = "uuid.h", lower_case_cprefix = "uuid_")]
+namespace UUID {
+ [CCode (cname = "int", has_type_id = false)]
+ public enum Variant {
+ NCS,
+ DCE,
+ MICROSOFT,
+ OTHER
+ }
+
+ [CCode (cname = "int", has_type_id = false)]
+ public enum Type {
+ DCE_TIME,
+ DCE_RANDOM
+ }
+
+ public static void clear ([CCode (array_length = false)] uint8 uu[16]);
+ public static void copy (uint8 dst[16], uint8 src[16]);
+
+ public static void generate ([CCode (array_length = false)] uint8 @out[16]);
+ public static void generate_random ([CCode (array_length = false)] uint8 @out[16]);
+ public static void generate_time ([CCode (array_length = false)] uint8 @out[16]);
+ public static void generate_time_safe ([CCode (array_length = false)] uint8 @out[16]);
+
+ public static bool is_null ([CCode (array_length = false)] uint8 uu[16]);
+
+ public static int parse (string in, [CCode (array_length = false)] uint8 uu[16]);
+
+ public static void unparse ([CCode (array_length = false)] uint8 uu[16], [CCode (array_length = false)] char @out[37]);
+ public static void unparse_lower ([CCode (array_length = false)] uint8 uu[16], [CCode (array_length = false)] char @out[37]);
+ public static void unparse_upper ([CCode (array_length = false)] uint8 uu[16], [CCode (array_length = false)] char @out[37]);
+
+// public static time_t time ([CCode (array_length = false)] uint8 uu[16], out Posix.timeval ret_tv);
+ public static UUID.Type type ([CCode (array_length = false)] uint8 uu[16]);
+ public static UUID.Variant variant ([CCode (array_length = false)] uint8 uu[16]);
+}