Do not expose UUID lib dependency outside vala-xmpp library

This commit is contained in:
Marvin W 2017-03-10 16:02:32 +01:00
parent 5fc0435cc1
commit 7a1aa8c806
No known key found for this signature in database
GPG Key ID: 072E9235DB996F2A
11 changed files with 21 additions and 24 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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();

View File

@ -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

View File

@ -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;
}

View File

@ -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);

View File

@ -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) {

View File

@ -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) {

View File

@ -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());

View File

@ -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;
}
}

View File

@ -57,12 +57,4 @@ namespace UUID {
// 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;
}
}