Use glib log functions

This commit is contained in:
fiaxh 2019-03-15 20:56:19 +01:00
parent a493269791
commit 6f6e4b97cb
16 changed files with 52 additions and 64 deletions

View file

@ -78,7 +78,7 @@ DEPENDS
${CMAKE_BINARY_DIR}/exports/dino_i18n.h ${CMAKE_BINARY_DIR}/exports/dino_i18n.h
) )
add_definitions(${VALA_CFLAGS} -DDINO_SYSTEM_PLUGIN_DIR="${PLUGIN_INSTALL_DIR}" -DDINO_SYSTEM_LIBDIR_NAME="${LIBDIR_NAME}") add_definitions(${VALA_CFLAGS} -DDINO_SYSTEM_PLUGIN_DIR="${PLUGIN_INSTALL_DIR}" -DDINO_SYSTEM_LIBDIR_NAME="${LIBDIR_NAME}" -DG_LOG_DOMAIN="libdino")
add_library(libdino SHARED ${LIBDINO_VALA_C} ${CMAKE_BINARY_DIR}/exports/dino_i18n.h) add_library(libdino SHARED ${LIBDINO_VALA_C} ${CMAKE_BINARY_DIR}/exports/dino_i18n.h)
add_dependencies(libdino dino-vapi) add_dependencies(libdino dino-vapi)
target_link_libraries(libdino xmpp-vala qlite ${LIBDINO_PACKAGES} m) target_link_libraries(libdino xmpp-vala qlite ${LIBDINO_PACKAGES} m)

View file

@ -91,7 +91,7 @@ public class AvatarManager : StreamInteractionModule, Object {
on_user_avatar_received(account, account.bare_jid, Base64.encode(buffer)); on_user_avatar_received(account, account.bare_jid, Base64.encode(buffer));
} }
} catch (Error e) { } catch (Error e) {
print("error " + e.message + "\n"); warning(e.message);
} }
} }

View file

@ -44,7 +44,6 @@ public class ConnectionManager : Object {
public Source source; public Source source;
public string? identifier; public string? identifier;
public Reconnect reconnect_recomendation { get; set; default=Reconnect.NOW; } public Reconnect reconnect_recomendation { get; set; default=Reconnect.NOW; }
public bool resource_rejected = false;
public ConnectionError(Source source, string? identifier) { public ConnectionError(Source source, string? identifier) {
this.source = source; this.source = source;
@ -110,14 +109,13 @@ public class ConnectionManager : Object {
return connection_todo; return connection_todo;
} }
public XmppStream? connect_account(Account account) { public void connect_account(Account account) {
if (!connection_todo.contains(account)) connection_todo.add(account); if (!connection_todo.contains(account)) connection_todo.add(account);
if (!connections.has_key(account)) { if (!connections.has_key(account)) {
return connect_(account); connect_(account);
} else { } else {
check_reconnect(account); check_reconnect(account);
} }
return null;
} }
public void make_offline_all() { public void make_offline_all() {
@ -139,7 +137,7 @@ public class ConnectionManager : Object {
try { try {
connections[account].stream.disconnect(); connections[account].stream.disconnect();
} catch (Error e) { } catch (Error e) {
warning(@"Error disconnecting stream $(e.message)\n"); debug("Error disconnecting stream: %s", e.message);
} }
connection_todo.remove(account); connection_todo.remove(account);
if (connections.has_key(account)) { if (connections.has_key(account)) {
@ -148,7 +146,7 @@ public class ConnectionManager : Object {
} }
} }
private XmppStream? connect_(Account account, string? resource = null) { private void connect_(Account account, string? resource = null) {
if (connections.has_key(account)) connections[account].stream.detach_modules(); if (connections.has_key(account)) connections[account].stream.detach_modules();
connection_errors.unset(account); connection_errors.unset(account);
if (resource == null) resource = account.resourcepart; if (resource == null) resource = account.resourcepart;
@ -158,7 +156,7 @@ public class ConnectionManager : Object {
stream.add_module(module); stream.add_module(module);
} }
stream.log = new XmppLog(account.bare_jid.to_string(), log_options); stream.log = new XmppLog(account.bare_jid.to_string(), log_options);
print("[%s] New connection with resource %s: %p\n".printf(account.bare_jid.to_string(), resource, stream)); debug("[%s] New connection with resource %s: %p", account.bare_jid.to_string(), resource, stream);
Connection connection = new Connection(stream, new DateTime.now_utc()); Connection connection = new Connection(stream, new DateTime.now_utc());
connections[account] = connection; connections[account] = connection;
@ -177,47 +175,35 @@ public class ConnectionManager : Object {
}); });
connect_async.begin(account, stream); connect_async.begin(account, stream);
stream_opened(account, stream); stream_opened(account, stream);
return stream;
} }
private async void connect_async(Account account, XmppStream stream) { private async void connect_async(Account account, XmppStream stream) {
try { try {
yield stream.connect(account.domainpart); yield stream.connect(account.domainpart);
} catch (Error e) { } catch (Error e) {
print(@"[$(account.bare_jid)] Error: $(e.message)\n"); debug("[%s %p] Error: %s", account.bare_jid.to_string(), stream, e.message);
change_connection_state(account, ConnectionState.DISCONNECTED); change_connection_state(account, ConnectionState.DISCONNECTED);
if (!connection_todo.contains(account)) { if (!connection_todo.contains(account)) {
return; return;
} }
StreamError.Flag? flag = stream.get_flag(StreamError.Flag.IDENTITY); StreamError.Flag? flag = stream.get_flag(StreamError.Flag.IDENTITY);
if (flag != null) { if (flag != null) {
set_connection_error(account, new ConnectionError(ConnectionError.Source.STREAM_ERROR, flag.error_type) { resource_rejected=flag.resource_rejected }); warning(@"[%s %p] Stream Error: %s", account.bare_jid.to_string(), stream, flag.error_type);
} set_connection_error(account, new ConnectionError(ConnectionError.Source.STREAM_ERROR, flag.error_type));
ConnectionError? error = connection_errors[account]; if (flag.resource_rejected) {
int wait_sec = 5;
if (error == null) {
wait_sec = 3;
} else if (error.source == ConnectionError.Source.STREAM_ERROR) {
print(@"[$(account.bare_jid)] Stream Error: $(error.identifier)\n");
if (error.resource_rejected) {
connect_(account, account.resourcepart + "-" + random_uuid()); connect_(account, account.resourcepart + "-" + random_uuid());
return; return;
} }
switch (error.reconnect_recomendation) { }
case ConnectionError.Reconnect.NOW:
wait_sec = 5; break; ConnectionError? error = connection_errors[account];
case ConnectionError.Reconnect.LATER: if (error != null && error.source == ConnectionError.Source.SASL) {
wait_sec = 60; break;
case ConnectionError.Reconnect.NEVER:
return; return;
} }
} else if (error.source == ConnectionError.Source.SASL) {
return; debug("[%s] Check reconnect in 5 sec", account.bare_jid.to_string());
} Timeout.add_seconds(5, () => {
print(@"[$(account.bare_jid)] Check reconnect in $wait_sec sec\n");
Timeout.add_seconds(wait_sec, () => {
check_reconnect(account); check_reconnect(account);
return false; return false;
}); });
@ -236,8 +222,8 @@ public class ConnectionManager : Object {
XmppStream stream = connections[account].stream; XmppStream stream = connections[account].stream;
stream.get_module(Xep.Ping.Module.IDENTITY).send_ping(stream, account.bare_jid.domain_jid, () => { stream.get_module(Xep.Ping.Module.IDENTITY).send_ping(stream, account.bare_jid.domain_jid, () => {
if (connections[account].stream != stream) return;
acked = true; acked = true;
if (connections[account].stream != stream) return;
change_connection_state(account, ConnectionState.CONNECTED); change_connection_state(account, ConnectionState.CONNECTED);
}); });
@ -247,11 +233,13 @@ public class ConnectionManager : Object {
if (connections[account].last_activity != last_activity_was) return false; if (connections[account].last_activity != last_activity_was) return false;
// Reconnect. Nothing gets through the stream. // Reconnect. Nothing gets through the stream.
print(@"[$(account.bare_jid)] Ping timeouted. Reconnecting\n"); debug("[%s %p] Ping timeouted. Reconnecting", account.bare_jid.to_string(), stream);
change_connection_state(account, ConnectionState.DISCONNECTED); change_connection_state(account, ConnectionState.DISCONNECTED);
try { try {
connections[account].stream.disconnect(); connections[account].stream.disconnect();
} catch (Error e) { } } catch (Error e) {
debug("Error disconnecting stream: %s", e.message);
}
connect_(account); connect_(account);
return false; return false;
}); });
@ -269,10 +257,10 @@ public class ConnectionManager : Object {
private void on_network_changed() { private void on_network_changed() {
if (network_is_online()) { if (network_is_online()) {
print("Network reported online\n"); debug("NetworkMonitor: Network reported online");
check_reconnects(); check_reconnects();
} else { } else {
print("Network reported offline\n"); debug("NetworkMonitor: Network reported offline");
foreach (Account account in connection_todo) { foreach (Account account in connection_todo) {
change_connection_state(account, ConnectionState.DISCONNECTED); change_connection_state(account, ConnectionState.DISCONNECTED);
} }
@ -284,17 +272,17 @@ public class ConnectionManager : Object {
change_connection_state(account, ConnectionState.DISCONNECTED); change_connection_state(account, ConnectionState.DISCONNECTED);
} }
if (suspend) { if (suspend) {
print("Device suspended\n"); debug("Login1: Device suspended");
foreach (Account account in connection_todo) { foreach (Account account in connection_todo) {
try { try {
make_offline(account); make_offline(account);
connections[account].stream.disconnect(); connections[account].stream.disconnect();
} catch (Error e) { } catch (Error e) {
warning(@"Error disconnecting stream $(e.message)\n"); debug("Error disconnecting stream %p: %s", connections[account].stream, e.message);
} }
} }
} else { } else {
print("Device un-suspend\n"); debug("Login1: Device un-suspend");
check_reconnects(); check_reconnects();
} }
} }

View file

@ -22,7 +22,7 @@ void main(string[] args) {
app.run(args); app.run(args);
loader.shutdown(); loader.shutdown();
} catch (Error e) { } catch (Error e) {
print(@"Fatal error: $(e.message)\n"); warning(@"Fatal error: $(e.message)");
} }
} }

View file

@ -166,7 +166,7 @@ public class FileItemWidgetGenerator : WidgetGenerator, Object {
try{ try{
AppInfo.launch_default_for_uri(file_transfer.get_file().get_uri(), null); AppInfo.launch_default_for_uri(file_transfer.get_file().get_uri(), null);
} catch (Error err) { } catch (Error err) {
print("Tried to open file://" + file_transfer.get_file().get_path() + " " + err.message + "\n"); info("Could not to open file://%s: %s", file_transfer.get_file().get_path(), err.message);
} }
}); });

View file

@ -83,7 +83,7 @@ public class Manager : StreamInteractionModule, FileSender, Object {
} }
}, },
(stream, error_str) => { (stream, error_str) => {
print(@"Failed getting upload url + $error_str\n"); warning("Failed getting upload url: %s", error_str);
file_transfer.state = FileTransfer.State.FAILED; file_transfer.state = FileTransfer.State.FAILED;
} }
); );

View file

@ -66,7 +66,7 @@ OPTIONS
--vapidir=${CMAKE_CURRENT_SOURCE_DIR}/vapi --vapidir=${CMAKE_CURRENT_SOURCE_DIR}/vapi
) )
add_definitions(${VALA_CFLAGS} -DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\" -DLOCALE_INSTALL_DIR=\"${LOCALE_INSTALL_DIR}\") add_definitions(${VALA_CFLAGS} -DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\" -DLOCALE_INSTALL_DIR=\"${LOCALE_INSTALL_DIR}\" -DG_LOG_DOMAIN="OMEMO")
add_library(omemo SHARED ${OMEMO_VALA_C} ${OMEMO_GRESOURCES_TARGET}) add_library(omemo SHARED ${OMEMO_VALA_C} ${OMEMO_GRESOURCES_TARGET})
add_dependencies(omemo ${GETTEXT_PACKAGE}-translations) add_dependencies(omemo ${GETTEXT_PACKAGE}-translations)
target_link_libraries(omemo libdino signal-protocol-vala ${OMEMO_PACKAGES}) target_link_libraries(omemo libdino signal-protocol-vala ${OMEMO_PACKAGES})

View file

@ -134,10 +134,10 @@ public class Manager : StreamInteractionModule, Object {
//Encryption failed - need to fetch more information //Encryption failed - need to fetch more information
if (!state.will_send_now) { if (!state.will_send_now) {
if (message.marked == Entities.Message.Marked.WONTSEND) { if (message.marked == Entities.Message.Marked.WONTSEND) {
if (Plugin.DEBUG) print(@"OMEMO: message was not sent: $state\n"); debug("message was not sent: %s", state.to_string());
message_states.unset(message); message_states.unset(message);
} else { } else {
if (Plugin.DEBUG) print(@"OMEMO: message will be delayed: $state\n"); debug("message will be delayed: %s", state.to_string());
if (state.waiting_own_sessions > 0) { if (state.waiting_own_sessions > 0) {
module.fetch_bundles((!)stream, conversation.account.bare_jid, trust_manager.get_trusted_devices(conversation.account, conversation.account.bare_jid)); module.fetch_bundles((!)stream, conversation.account.bare_jid, trust_manager.get_trusted_devices(conversation.account, conversation.account.bare_jid));
@ -175,7 +175,7 @@ public class Manager : StreamInteractionModule, Object {
} }
private void on_device_list_loaded(Account account, Jid jid, ArrayList<int32> device_list) { private void on_device_list_loaded(Account account, Jid jid, ArrayList<int32> device_list) {
if (Plugin.DEBUG) print(@"OMEMO: received device list for $(account.bare_jid) from $jid\n"); debug("received device list for %s from %s", account.bare_jid.to_string(), jid.to_string());
XmppStream? stream = stream_interactor.get_stream(account); XmppStream? stream = stream_interactor.get_stream(account);
if (stream == null) { if (stream == null) {
@ -199,7 +199,7 @@ public class Manager : StreamInteractionModule, Object {
inc++; inc++;
} }
if (inc > 0) { if (inc > 0) {
if (Plugin.DEBUG) print(@"OMEMO: new bundles $inc/$(device_list.size) for $jid\n"); debug("new bundles %i/%i for %s", inc, device_list.size, jid.to_string());
} }
//Create an entry for the jid in the account table if one does not exist already //Create an entry for the jid in the account table if one does not exist already
@ -343,7 +343,7 @@ public class Manager : StreamInteractionModule, Object {
store.pre_key_store = new BackedPreKeyStore(db, identity_id); store.pre_key_store = new BackedPreKeyStore(db, identity_id);
store.session_store = new BackedSessionStore(db, identity_id); store.session_store = new BackedSessionStore(db, identity_id);
} else { } else {
print(@"OMEMO: store for $(account.bare_jid) is not persisted!"); warning("store for %s is not persisted!", account.bare_jid.to_string());
} }
// Generated new device ID, ensure this gets added to the devicelist // Generated new device ID, ensure this gets added to the devicelist

View file

@ -19,7 +19,7 @@ private class BackedPreKeyStore : SimplePreKeyStore {
store_pre_key(row[db.pre_key.pre_key_id], Base64.decode(row[db.pre_key.record_base64])); store_pre_key(row[db.pre_key.pre_key_id], Base64.decode(row[db.pre_key.record_base64]));
} }
} catch (Error e) { } catch (Error e) {
print(@"OMEMO: Error while initializing pre key store: $(e.message)\n"); warning("Error while initializing pre key store: %s", e.message);
} }
pre_key_stored.connect(on_pre_key_stored); pre_key_stored.connect(on_pre_key_stored);

View file

@ -21,7 +21,7 @@ private class BackedSessionStore : SimpleSessionStore {
addr.device_id = 0; addr.device_id = 0;
} }
} catch (Error e) { } catch (Error e) {
print(@"OMEMO: Error while initializing session store: $(e.message)\n"); print("Error while initializing session store: %s", e.message);
} }
session_stored.connect(on_session_stored); session_stored.connect(on_session_stored);

View file

@ -19,7 +19,7 @@ private class BackedSignedPreKeyStore : SimpleSignedPreKeyStore {
store_signed_pre_key(row[db.signed_pre_key.signed_pre_key_id], Base64.decode(row[db.signed_pre_key.record_base64])); store_signed_pre_key(row[db.signed_pre_key.signed_pre_key_id], Base64.decode(row[db.signed_pre_key.record_base64]));
} }
} catch (Error e) { } catch (Error e) {
print(@"OMEMO: Error while initializing signed pre key store: $(e.message)\n"); print("Error while initializing signed pre key store: %s", e.message);
} }
signed_pre_key_stored.connect(on_signed_pre_key_stored); signed_pre_key_stored.connect(on_signed_pre_key_stored);

View file

@ -38,7 +38,7 @@ public class StreamModule : XmppStreamModule {
public void request_user_devicelist(XmppStream stream, Jid jid) { public void request_user_devicelist(XmppStream stream, Jid jid) {
if (active_devicelist_requests.add(jid)) { if (active_devicelist_requests.add(jid)) {
if (Plugin.DEBUG) print(@"OMEMO: requesting device list for $jid\n"); debug("requesting device list for %s", jid.to_string());
stream.get_module(Pubsub.Module.IDENTITY).request(stream, jid, NODE_DEVICELIST, (stream, jid, id, node) => on_devicelist(stream, jid, id, node)); stream.get_module(Pubsub.Module.IDENTITY).request(stream, jid, NODE_DEVICELIST, (stream, jid, id, node) => on_devicelist(stream, jid, id, node));
} }
} }
@ -56,7 +56,7 @@ public class StreamModule : XmppStreamModule {
} }
} }
if (!am_on_devicelist) { if (!am_on_devicelist) {
if (Plugin.DEBUG) print(@"OMEMO: Not on device list, adding id\n"); debug(@"Not on device list, adding id");
node.put_node(new StanzaNode.build("device", NS_URI).put_attribute("id", store.local_registration_id.to_string())); node.put_node(new StanzaNode.build("device", NS_URI).put_attribute("id", store.local_registration_id.to_string()));
stream.get_module(Pubsub.Module.IDENTITY).publish(stream, jid, NODE_DEVICELIST, NODE_DEVICELIST, id, node); stream.get_module(Pubsub.Module.IDENTITY).publish(stream, jid, NODE_DEVICELIST, NODE_DEVICELIST, id, node);
} }
@ -90,7 +90,7 @@ public class StreamModule : XmppStreamModule {
public void fetch_bundle(XmppStream stream, Jid jid, int device_id) { public void fetch_bundle(XmppStream stream, Jid jid, int device_id) {
if (active_bundle_requests.add(jid.bare_jid.to_string() + @":$device_id")) { if (active_bundle_requests.add(jid.bare_jid.to_string() + @":$device_id")) {
if (Plugin.DEBUG) print(@"OMEMO: Asking for bundle from $(jid.bare_jid.to_string()):$device_id\n"); debug(@"Asking for bundle from %s: %i", jid.bare_jid.to_string(), device_id);
stream.get_module(Pubsub.Module.IDENTITY).request(stream, jid.bare_jid, @"$NODE_BUNDLES:$device_id", (stream, jid, id, node) => { stream.get_module(Pubsub.Module.IDENTITY).request(stream, jid.bare_jid, @"$NODE_BUNDLES:$device_id", (stream, jid, id, node) => {
on_other_bundle_result(stream, jid, device_id, id, node); on_other_bundle_result(stream, jid, device_id, id, node);
}); });
@ -233,7 +233,7 @@ public class StreamModule : XmppStreamModule {
publish_bundles(stream, (!)signed_pre_key_record, identity_key_pair, pre_key_records, (int32) store.local_registration_id); publish_bundles(stream, (!)signed_pre_key_record, identity_key_pair, pre_key_records, (int32) store.local_registration_id);
} }
} catch (Error e) { } catch (Error e) {
if (Plugin.DEBUG) print(@"Unexpected error while publishing bundle: $(e.message)\n"); warning(@"Unexpected error while publishing bundle: $(e.message)\n");
} }
stream.get_module(IDENTITY).active_bundle_requests.remove(jid.bare_jid.to_string() + @":$(store.local_registration_id)"); stream.get_module(IDENTITY).active_bundle_requests.remove(jid.bare_jid.to_string() + @":$(store.local_registration_id)");
} }

View file

@ -159,7 +159,7 @@ public class TrustManager {
message.body = "[This message is OMEMO encrypted]"; message.body = "[This message is OMEMO encrypted]";
status.encrypted = true; status.encrypted = true;
} catch (Error e) { } catch (Error e) {
if (Plugin.DEBUG) print(@"OMEMO: Signal error while encrypting message: $(e.message)\n"); warning(@"Signal error while encrypting message: $(e.message)\n");
} }
return status; return status;
} }
@ -327,7 +327,7 @@ public class TrustManager {
break; break;
} }
} catch (Error e) { } catch (Error e) {
if (Plugin.DEBUG) print(@"OMEMO: Signal error while decrypting message: $(e.message)\n"); warning(@"Signal error while decrypting message: $(e.message)\n");
} }
} }
} }

View file

@ -24,7 +24,7 @@ namespace Dino.Plugins.OpenPgp {
if (own_key_id != null) { if (own_key_id != null) {
try { try {
own_key = GPGHelper.get_private_key(own_key_id); own_key = GPGHelper.get_private_key(own_key_id);
if (own_key == null) print("PRIV KEY NULL\n"); if (own_key == null) warning("Can't get PGP private key");
} catch (Error e) { } } catch (Error e) { }
if (own_key != null) { if (own_key != null) {
signed_status = gpg_sign("", own_key); signed_status = gpg_sign("", own_key);

View file

@ -108,7 +108,7 @@ public class RowIterator {
int r = stmt.step(); int r = stmt.step();
if (r == Sqlite.ROW) return true; if (r == Sqlite.ROW) return true;
if (r == Sqlite.DONE) return false; if (r == Sqlite.DONE) return false;
print(@"SQLite error: $(db.errcode()) - $(db.errmsg())\n"); warning(@"SQLite error: $(db.errcode()) - $(db.errmsg())");
return false; return false;
} }

View file

@ -67,7 +67,7 @@ public class XmppStream {
} }
reset_stream((!)stream); reset_stream((!)stream);
} catch (Error e) { } catch (Error e) {
stderr.printf("CONNECTION LOST?\n"); debug("[%p] Could not connect to server", this);
throw new IOStreamError.CONNECT(e.message); throw new IOStreamError.CONNECT(e.message);
} }
yield loop(); yield loop();
@ -153,7 +153,7 @@ public class XmppStream {
public XmppStream add_module(XmppStreamModule module) { public XmppStream add_module(XmppStreamModule module) {
foreach (XmppStreamModule m in modules) { foreach (XmppStreamModule m in modules) {
if (m.get_ns() == module.get_ns() && m.get_id() == module.get_id()) { if (m.get_ns() == module.get_ns() && m.get_id() == module.get_id()) {
print("[%p] Adding already added module: %s\n".printf(this, module.get_id())); warning("[%p] Adding already added module: %s\n", this, module.get_id());
return this; return this;
} }
} }
@ -221,7 +221,7 @@ public class XmppStream {
features = node; features = node;
received_features_node(this); received_features_node(this);
} else if (node.ns_uri == NS_URI && node.name == "stream" && node.pseudo) { } else if (node.ns_uri == NS_URI && node.name == "stream" && node.pseudo) {
print("disconnect\n"); debug("[%p] Server closed stream", this);
disconnect(); disconnect();
return; return;
} else if (node.ns_uri == JABBER_URI) { } else if (node.ns_uri == JABBER_URI) {