From 7a1aa8c806a63cfd031c082524501e26d4a181ee Mon Sep 17 00:00:00 2001 From: Marvin W Date: Fri, 10 Mar 2017 16:02:32 +0100 Subject: Do not expose UUID lib dependency outside vala-xmpp library --- client/CMakeLists.txt | 2 - client/src/service/connection_manager.vala | 2 +- client/src/service/message_manager.vala | 2 +- vala-xmpp/CMakeLists.txt | 3 +- vala-xmpp/src/core/stanza_writer.vala | 2 - vala-xmpp/src/module/iq/stanza.vala | 8 ++-- vala-xmpp/src/module/message/stanza.vala | 4 +- vala-xmpp/src/module/presence/stanza.vala | 4 +- vala-xmpp/src/module/roster/module.vala | 2 +- vala-xmpp/src/module/util.vala | 8 ++++ vala-xmpp/vapi/uuid.vapi | 60 ++++++++++++++++++++++++++ vapi/uuid.vapi | 68 ------------------------------ 12 files changed, 81 insertions(+), 84 deletions(-) create mode 100644 vala-xmpp/vapi/uuid.vapi delete mode 100644 vapi/uuid.vapi diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index ac42ecff..1ce8c1ee 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -1,7 +1,6 @@ find_package(Vala REQUIRED) find_package(PkgConfig REQUIRED) find_package(GPGME REQUIRED) -find_package(LIBUUID REQUIRED) include(${VALA_USE_FILE}) include(GlibCompileResourcesSupport) @@ -127,7 +126,6 @@ SOURCES PACKAGES ${CLIENT_PACKAGES} gpgme - uuid vala-xmpp qlite GRESOURCES diff --git a/client/src/service/connection_manager.vala b/client/src/service/connection_manager.vala index 91664af5..75155e98 100644 --- a/client/src/service/connection_manager.vala +++ b/client/src/service/connection_manager.vala @@ -136,7 +136,7 @@ public class ConnectionManager { print(@"recovering in $wait_sec\n"); Timeout.add_seconds(wait_sec, () => { if (stream_error_flag.resource_rejected) { - connect_(account, account.resourcepart + "-" + UUID.generate_random_unparsed()); + connect_(account, account.resourcepart + "-" + random_uuid()); } else { connect_(account); } diff --git a/client/src/service/message_manager.vala b/client/src/service/message_manager.vala index 054db518..ec7a35c8 100644 --- a/client/src/service/message_manager.vala +++ b/client/src/service/message_manager.vala @@ -141,7 +141,7 @@ public class MessageManager : StreamInteractionModule, Object { private Entities.Message create_out_message(string text, Conversation conversation) { Entities.Message message = new Entities.Message(); - message.stanza_id = UUID.generate_random_unparsed(); + message.stanza_id = random_uuid(); message.account = conversation.account; message.body = text; message.time = new DateTime.now_utc(); 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 + * + * 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]); +} diff --git a/vapi/uuid.vapi b/vapi/uuid.vapi deleted file mode 100644 index 038fcc33..00000000 --- a/vapi/uuid.vapi +++ /dev/null @@ -1,68 +0,0 @@ -/* libuuid Vala Bindings - * Copyright 2014 Evan Nemerson - * - * 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]); - - public static string generate_random_unparsed() { - uint8[] rand = new uint8[16]; - char[] str = new char[37]; - generate_random(rand); - unparse_upper(rand, str); - return (string) str; - } -} -- cgit v1.2.3-54-g00ecf