Fix warnings
This commit is contained in:
parent
b9df78e449
commit
0102abeec1
|
@ -64,7 +64,7 @@ public interface TextCommand : Object {
|
|||
public interface ConversationTitlebarEntry : Object {
|
||||
public abstract string id { get; }
|
||||
public abstract double order { get; }
|
||||
public abstract ConversationTitlebarWidget get_widget(WidgetType type);
|
||||
public abstract ConversationTitlebarWidget? get_widget(WidgetType type);
|
||||
}
|
||||
|
||||
public interface ConversationTitlebarWidget : Object {
|
||||
|
@ -94,7 +94,7 @@ public abstract class MetaConversationItem : Object {
|
|||
public abstract bool requires_avatar { get; set; }
|
||||
public abstract bool requires_header { get; set; }
|
||||
|
||||
public abstract Object get_widget(WidgetType type);
|
||||
public abstract Object? get_widget(WidgetType type);
|
||||
}
|
||||
|
||||
public interface ConversationItemCollection : Object {
|
||||
|
@ -110,7 +110,7 @@ public interface MessageDisplayProvider : Object {
|
|||
}
|
||||
|
||||
public interface FileWidget : Object {
|
||||
public abstract Object get_widget(WidgetType type);
|
||||
public abstract Object? get_widget(WidgetType type);
|
||||
}
|
||||
|
||||
public interface FileDisplayProvider : Object {
|
||||
|
|
|
@ -26,7 +26,7 @@ public class Loader : Object {
|
|||
this.search_paths = app.search_path_generator.get_plugin_paths();
|
||||
}
|
||||
|
||||
public void loadAll() {
|
||||
public void loadAll() throws Error {
|
||||
if (Module.supported() == false) {
|
||||
throw new Error(-1, 0, "Plugins are not supported");
|
||||
}
|
||||
|
@ -95,4 +95,4 @@ public class Loader : Object {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,6 @@ public class ConnectionManager {
|
|||
|
||||
private class RecMutexWrap {
|
||||
public RecMutex mutex = RecMutex();
|
||||
public void lock() { mutex.lock(); }
|
||||
public void unlock() { mutex.unlock(); }
|
||||
public bool trylock() { return mutex.trylock(); }
|
||||
}
|
||||
|
|
|
@ -199,7 +199,9 @@ public class Database : Qlite.Database {
|
|||
roster = new RosterTable(this);
|
||||
settings = new SettingsTable(this);
|
||||
init({ account, jid, message, real_jid, file_transfer, conversation, avatar, entity_feature, roster, settings });
|
||||
exec("PRAGMA synchronous=0");
|
||||
try {
|
||||
exec("PRAGMA synchronous=0");
|
||||
} catch (Error e) { }
|
||||
}
|
||||
|
||||
public override void migrate(long oldVersion) {
|
||||
|
|
|
@ -35,9 +35,6 @@ public class FileManager : StreamInteractionModule, Object {
|
|||
}
|
||||
|
||||
public void send_file(string uri, Conversation conversation) {
|
||||
File file = File.new_for_path(uri);
|
||||
FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE);
|
||||
|
||||
FileTransfer file_transfer = new FileTransfer();
|
||||
file_transfer.account = conversation.account;
|
||||
file_transfer.counterpart = conversation.counterpart;
|
||||
|
@ -46,11 +43,16 @@ public class FileManager : StreamInteractionModule, Object {
|
|||
file_transfer.time = new DateTime.now_utc();
|
||||
file_transfer.local_time = new DateTime.now_utc();
|
||||
file_transfer.encryption = Encryption.NONE;
|
||||
file_transfer.file_name = file_info.get_display_name();
|
||||
file_transfer.input_stream = file.read();
|
||||
|
||||
file_transfer.mime_type = file_info.get_content_type();
|
||||
file_transfer.size = (int)file_info.get_size();
|
||||
try {
|
||||
File file = File.new_for_path(uri);
|
||||
FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE);
|
||||
file_transfer.file_name = file_info.get_display_name();
|
||||
file_transfer.mime_type = file_info.get_content_type();
|
||||
file_transfer.size = (int)file_info.get_size();
|
||||
file_transfer.input_stream = file.read();
|
||||
} catch (Error e) {
|
||||
file_transfer.state = FileTransfer.State.FAILED;
|
||||
}
|
||||
save_file(file_transfer);
|
||||
|
||||
file_transfer.persist(db);
|
||||
|
@ -90,7 +92,7 @@ public class FileManager : StreamInteractionModule, Object {
|
|||
File file = File.new_for_path(Path.build_filename(get_storage_dir(), file_transfer.path ?? file_transfer.file_name));
|
||||
try {
|
||||
file_transfer.input_stream = file.read();
|
||||
} catch (IOError e) { }
|
||||
} catch (Error e) { }
|
||||
ret.insert(0, file_transfer);
|
||||
}
|
||||
return ret;
|
||||
|
@ -123,27 +125,29 @@ public class FileManager : StreamInteractionModule, Object {
|
|||
}
|
||||
save_file(file_transfer);
|
||||
|
||||
File file = File.new_for_path(file_transfer.get_uri());
|
||||
FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE);
|
||||
file_transfer.mime_type = file_info.get_content_type();
|
||||
try {
|
||||
File file = File.new_for_path(file_transfer.get_uri());
|
||||
FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE);
|
||||
file_transfer.mime_type = file_info.get_content_type();
|
||||
} catch (Error e) { }
|
||||
|
||||
file_transfer.persist(db);
|
||||
received_file(file_transfer);
|
||||
}
|
||||
|
||||
private void save_file(FileTransfer file_transfer) {
|
||||
string filename = Random.next_int().to_string("%x") + "_" + file_transfer.file_name;
|
||||
File file = File.new_for_path(Path.build_filename(get_storage_dir(), filename));
|
||||
try {
|
||||
string filename = Random.next_int().to_string("%x") + "_" + file_transfer.file_name;
|
||||
File file = File.new_for_path(Path.build_filename(get_storage_dir(), filename));
|
||||
OutputStream os = file.create(FileCreateFlags.REPLACE_DESTINATION);
|
||||
os.splice(file_transfer.input_stream, 0);
|
||||
os.close();
|
||||
file_transfer.state = FileTransfer.State.COMPLETE;
|
||||
file_transfer.path = filename;
|
||||
file_transfer.input_stream = file.read();
|
||||
} catch (Error e) {
|
||||
file_transfer.state = FileTransfer.State.FAILED;
|
||||
}
|
||||
file_transfer.path = filename;
|
||||
file_transfer.input_stream = file.read();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -152,16 +152,18 @@ public class AvatarGenerator {
|
|||
Context rectancle_context = new Context(new ImageSurface(Format.ARGB32, width, height));
|
||||
draw_colored_rectangle(rectancle_context, hex_color, width, height);
|
||||
|
||||
Pixbuf icon_pixbuf = IconTheme.get_default().load_icon(icon, ICON_SIZE, IconLookupFlags.FORCE_SIZE);
|
||||
Surface icon_surface = cairo_surface_create_from_pixbuf(icon_pixbuf, 1, null);
|
||||
Context context = new Context(icon_surface);
|
||||
context.set_operator(Operator.IN);
|
||||
context.set_source_rgba(1, 1, 1, 1);
|
||||
context.rectangle(0, 0, width, height);
|
||||
context.fill();
|
||||
try {
|
||||
Pixbuf icon_pixbuf = IconTheme.get_default().load_icon(icon, ICON_SIZE, IconLookupFlags.FORCE_SIZE);
|
||||
Surface icon_surface = cairo_surface_create_from_pixbuf(icon_pixbuf, 1, null);
|
||||
Context context = new Context(icon_surface);
|
||||
context.set_operator(Operator.IN);
|
||||
context.set_source_rgba(1, 1, 1, 1);
|
||||
context.rectangle(0, 0, width, height);
|
||||
context.fill();
|
||||
|
||||
rectancle_context.set_source_surface(icon_surface, width / 2 - ICON_SIZE / 2, height / 2 - ICON_SIZE / 2);
|
||||
rectancle_context.paint();
|
||||
rectancle_context.set_source_surface(icon_surface, width / 2 - ICON_SIZE / 2, height / 2 - ICON_SIZE / 2);
|
||||
rectancle_context.paint();
|
||||
} catch (Error e) { warning(@"Icon $icon does not exist"); }
|
||||
|
||||
return pixbuf_get_from_surface(rectancle_context.get_target(), 0, 0, width, height);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ namespace Dino.Ui.ChatInput {
|
|||
|
||||
class EditHistory {
|
||||
|
||||
private StreamInteractor stream_interactor;
|
||||
private Conversation? conversation;
|
||||
private TextView text_input;
|
||||
|
||||
|
@ -16,7 +15,6 @@ class EditHistory {
|
|||
private HashMap<Conversation, int> indices = new HashMap<Conversation, int>(Conversation.hash_func, Conversation.equals_func);
|
||||
|
||||
public EditHistory(TextView text_input, GLib.Application application) {
|
||||
this.stream_interactor = stream_interactor;
|
||||
this.text_input = text_input;
|
||||
|
||||
text_input.key_press_event.connect(on_text_input_key_press);
|
||||
|
|
|
@ -53,7 +53,6 @@ class ChatStatePopulator : Plugins.ConversationItemPopulator, Object {
|
|||
string? new_text = null;
|
||||
if (state_ != null) {
|
||||
if (state_ == Xep.ChatStateNotifications.STATE_COMPOSING || state_ == Xep.ChatStateNotifications.STATE_PAUSED) {
|
||||
string display_name = Util.get_display_name(stream_interactor, jid, account);
|
||||
if (state_ == Xep.ChatStateNotifications.STATE_COMPOSING) {
|
||||
new_text = _("is typing...");
|
||||
} else if (state_ == Xep.ChatStateNotifications.STATE_PAUSED) {
|
||||
|
@ -95,7 +94,7 @@ public class MetaChatStateItem : Plugins.MetaConversationItem {
|
|||
this.text = text;
|
||||
}
|
||||
|
||||
public override Object get_widget(Plugins.WidgetType widget_type) {
|
||||
public override Object? get_widget(Plugins.WidgetType widget_type) {
|
||||
label = new Label("") { xalign=0, vexpand=true, visible=true };
|
||||
label.get_style_context().add_class("dim-label");
|
||||
update_text();
|
||||
|
|
|
@ -44,7 +44,7 @@ public class MetaMessageItem : Plugins.MetaConversationItem {
|
|||
public override bool requires_avatar { get; set; default=true; }
|
||||
public override bool requires_header { get; set; default=true; }
|
||||
|
||||
public override Object get_widget(Plugins.WidgetType widget_type) {
|
||||
public override Object? get_widget(Plugins.WidgetType widget_type) {
|
||||
MessageTextView text_view = new MessageTextView() { visible = true };
|
||||
text_view.add_text(message.body);
|
||||
return text_view;
|
||||
|
|
|
@ -79,9 +79,14 @@ public class ImageItem : Plugins.MetaConversationItem {
|
|||
});
|
||||
}
|
||||
|
||||
public override Object get_widget(Plugins.WidgetType widget_type) {
|
||||
public override Object? get_widget(Plugins.WidgetType widget_type) {
|
||||
Image image = new Image() { halign=Align.START, visible = true };
|
||||
Gdk.Pixbuf pixbuf = new Gdk.Pixbuf.from_file(file_transfer.get_uri());
|
||||
Gdk.Pixbuf pixbuf;
|
||||
try {
|
||||
pixbuf = new Gdk.Pixbuf.from_file(file_transfer.get_uri());
|
||||
} catch (Error error) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int max_scaled_height = MAX_HEIGHT * image.scale_factor;
|
||||
if (pixbuf.height > max_scaled_height) {
|
||||
|
@ -104,7 +109,6 @@ public class ImageItem : Plugins.MetaConversationItem {
|
|||
Util.force_color(url_label, "#eee");
|
||||
file_transfer.notify["info"].connect_after(() => { update_info(url_label, file_transfer.info); });
|
||||
update_info(url_label, file_transfer.info);
|
||||
Box url_box = builder.get_object("url_box") as Box;
|
||||
|
||||
Image copy_image = builder.get_object("copy_image") as Image;
|
||||
Util.force_css(copy_image, "*:not(:hover) { color: #eee; }");
|
||||
|
|
|
@ -51,7 +51,6 @@ public class MessageTextView : TextView {
|
|||
MatchInfo match_info;
|
||||
url_regex.match(text, 0, out match_info);
|
||||
for (; match_info.matches(); match_info.next()) {
|
||||
string? url = match_info.fetch(0);
|
||||
int start;
|
||||
int end;
|
||||
match_info.fetch_pos(0, out start, out end);
|
||||
|
|
|
@ -50,7 +50,7 @@ public class MetaSlashmeItem : Plugins.MetaConversationItem {
|
|||
public override bool requires_avatar { get; set; default=true; }
|
||||
public override bool requires_header { get; set; default=false; }
|
||||
|
||||
public override Object get_widget(Plugins.WidgetType widget_type) {
|
||||
public override Object? get_widget(Plugins.WidgetType widget_type) {
|
||||
text_view = new MessageTextView() { valign=Align.CENTER, vexpand=true, visible = true };
|
||||
|
||||
string display_name = Util.get_message_display_name(stream_interactor, message, conversation.account);
|
||||
|
@ -67,7 +67,6 @@ public class MetaSlashmeItem : Plugins.MetaConversationItem {
|
|||
}
|
||||
|
||||
private void update_style() {
|
||||
string display_name = Util.get_message_display_name(stream_interactor, message, conversation.account);
|
||||
string color = Util.get_name_hex_color(stream_interactor, conversation.account, message.real_jid ?? message.from, Util.is_dark_theme(text_view));
|
||||
nick_tag.foreground = "#" + color;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ public class FileEntry : Plugins.ConversationTitlebarEntry, Object {
|
|||
}
|
||||
|
||||
public double order { get { return 4; } }
|
||||
public Plugins.ConversationTitlebarWidget get_widget(Plugins.WidgetType type) {
|
||||
public Plugins.ConversationTitlebarWidget? get_widget(Plugins.WidgetType type) {
|
||||
if (type == Plugins.WidgetType.GTK) {
|
||||
return new FileWidget(stream_interactor) { visible=true };
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ class MenuEntry : Plugins.ConversationTitlebarEntry, Object {
|
|||
}
|
||||
|
||||
public double order { get { return 0; } }
|
||||
public Plugins.ConversationTitlebarWidget get_widget(Plugins.WidgetType type) {
|
||||
public Plugins.ConversationTitlebarWidget? get_widget(Plugins.WidgetType type) {
|
||||
if (type == Plugins.WidgetType.GTK) {
|
||||
return new MenuWidget(stream_interactor) { visible=true };
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class OccupantsEntry : Plugins.ConversationTitlebarEntry, Object {
|
|||
}
|
||||
|
||||
public double order { get { return 3; } }
|
||||
public Plugins.ConversationTitlebarWidget get_widget(Plugins.WidgetType type) {
|
||||
public Plugins.ConversationTitlebarWidget? get_widget(Plugins.WidgetType type) {
|
||||
if (type == Plugins.WidgetType.GTK) {
|
||||
return new OccupantsWidget(stream_interactor, window) { visible=true };
|
||||
}
|
||||
|
|
|
@ -92,7 +92,9 @@ public class Notifications : Object {
|
|||
}
|
||||
notifications[conversation].set_title(display_name);
|
||||
notifications[conversation].set_body(text);
|
||||
notifications[conversation].set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_conversation(stream_interactor, conversation)));
|
||||
try {
|
||||
notifications[conversation].set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_conversation(stream_interactor, conversation)));
|
||||
} catch (Error e) { }
|
||||
window.get_application().send_notification(conversation.id.to_string(), notifications[conversation]);
|
||||
active_notification_ids.add(conversation.id.to_string());
|
||||
window.urgency_hint = true;
|
||||
|
@ -102,7 +104,9 @@ public class Notifications : Object {
|
|||
private void on_received_subscription_request(Jid jid, Account account) {
|
||||
Notification notification = new Notification(_("Subscription request"));
|
||||
notification.set_body(jid.bare_jid.to_string());
|
||||
notification.set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_jid(stream_interactor, jid, account)));
|
||||
try {
|
||||
notification.set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_jid(stream_interactor, jid, account)));
|
||||
} catch (Error e) { }
|
||||
Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.CHAT);
|
||||
notification.add_button_with_target_value(_("Accept"), "app.accept-subscription", conversation.id);
|
||||
notification.add_button_with_target_value(_("Deny"), "app.deny-subscription", conversation.id);
|
||||
|
@ -119,7 +123,7 @@ public class Notifications : Object {
|
|||
return true;
|
||||
}
|
||||
|
||||
private Icon get_pixbuf_icon(Gdk.Pixbuf avatar) {
|
||||
private Icon get_pixbuf_icon(Gdk.Pixbuf avatar) throws Error {
|
||||
uint8[] buffer;
|
||||
avatar.save_to_buffer(out buffer, "png");
|
||||
return new BytesIcon(new Bytes(buffer));
|
||||
|
|
|
@ -466,7 +466,7 @@ namespace GPG {
|
|||
[CCode (cname = "gpgme_data_new_from_file")]
|
||||
public static GPGError.Error new_from_file(out Data d, string filename, int copy = 1);
|
||||
|
||||
public static Data create_from_file(string filename, int copy = 1) {
|
||||
public static Data create_from_file(string filename, int copy = 1) throws GLib.Error {
|
||||
Data data;
|
||||
throw_if_error(new_from_file(out data, filename, copy));
|
||||
return data;
|
||||
|
|
|
@ -48,8 +48,13 @@ public class FileProvider : Dino.FileProvider, Object {
|
|||
if (name == "Content-Length") content_length = val;
|
||||
});
|
||||
if (/*content_type != null && content_type.has_prefix("image") &&*/ content_length != null && int.parse(content_length) < 5000000) {
|
||||
Soup.Request request = session.request (message.body);
|
||||
FileTransfer file_transfer = new FileTransfer();
|
||||
try {
|
||||
Soup.Request request = session.request(message.body);
|
||||
file_transfer.input_stream = request.send();
|
||||
} catch (Error e) {
|
||||
return;
|
||||
}
|
||||
file_transfer.account = conversation.account;
|
||||
file_transfer.counterpart = message.counterpart;
|
||||
file_transfer.ourpart = message.ourpart;
|
||||
|
@ -57,7 +62,6 @@ public class FileProvider : Dino.FileProvider, Object {
|
|||
file_transfer.time = message.time;
|
||||
file_transfer.local_time = message.local_time;
|
||||
file_transfer.direction = message.direction;
|
||||
file_transfer.input_stream = request.send();
|
||||
file_transfer.file_name = message.body.substring(message.body.last_index_of("/") + 1);
|
||||
file_transfer.mime_type = content_type;
|
||||
file_transfer.size = int.parse(content_length);
|
||||
|
|
|
@ -21,7 +21,11 @@ public class UploadStreamModule : XmppStreamModule {
|
|||
Array<uint8> data = new Array<uint8>(false, true, 0);
|
||||
size_t len = -1;
|
||||
do {
|
||||
len = input_stream.read(buf);
|
||||
try {
|
||||
len = input_stream.read(buf);
|
||||
} catch (IOError error) {
|
||||
error_listener(stream, @"HTTP upload: IOError reading stream: $(error.message)");
|
||||
}
|
||||
data.append_vals(buf, (uint) len);
|
||||
} while(len > 0);
|
||||
|
||||
|
@ -41,7 +45,7 @@ public class UploadStreamModule : XmppStreamModule {
|
|||
}
|
||||
});
|
||||
},
|
||||
error_listener);
|
||||
(stream, error) => error_listener(stream, error));
|
||||
}
|
||||
|
||||
private delegate void OnSlotOk(XmppStream stream, string url_get, string url_put);
|
||||
|
|
|
@ -17,6 +17,7 @@ public class AccountSettingsDialog : Gtk.Dialog {
|
|||
public AccountSettingsDialog(Plugin plugin, Account account) {
|
||||
Object(use_header_bar : 1);
|
||||
this.plugin = plugin;
|
||||
this.account = account;
|
||||
|
||||
string own_b64 = plugin.db.identity.row_with(plugin.db.identity.account_id, account.id)[plugin.db.identity.identity_key_public_base64];
|
||||
fingerprint = fingerprint_from_base64(own_b64);
|
||||
|
@ -50,4 +51,4 @@ public class AccountSettingsDialog : Gtk.Dialog {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,7 +116,9 @@ public class Database : Qlite.Database {
|
|||
pre_key = new PreKeyTable(this);
|
||||
session = new SessionTable(this);
|
||||
init({identity_meta, identity, signed_pre_key, pre_key, session});
|
||||
exec("PRAGMA synchronous=0");
|
||||
try {
|
||||
exec("PRAGMA synchronous=0");
|
||||
} catch (Error e) { }
|
||||
}
|
||||
|
||||
public override void migrate(long oldVersion) {
|
||||
|
|
|
@ -18,8 +18,11 @@ public class ContactDetailsProvider : Plugins.ContactDetailsProvider, Object {
|
|||
string? key_id = stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart);
|
||||
if (key_id != null) {
|
||||
Label label = new Label("") { use_markup=true, justify=Justification.RIGHT, selectable=true, visible=true };
|
||||
Gee.List<GPG.Key> keys = GPGHelper.get_keylist(key_id);
|
||||
if (keys.size > 0) {
|
||||
Gee.List<GPG.Key>? keys = null;
|
||||
try {
|
||||
keys = GPGHelper.get_keylist(key_id);
|
||||
} catch (Error e) { }
|
||||
if (keys != null && keys.size > 0) {
|
||||
label.label = markup_colorize_id(keys[0].fpr, true);
|
||||
} else {
|
||||
label.label = _("Key not in keychain") + "\n" + markup_colorize_id(key_id, false);
|
||||
|
|
|
@ -23,7 +23,9 @@ private class EncryptionListEntry : Plugins.EncryptionListEntry, Object {
|
|||
public bool can_encrypt(Entities.Conversation conversation) {
|
||||
if (conversation.type_ == Conversation.Type.CHAT) {
|
||||
string? key_id = stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart);
|
||||
return key_id != null && GPGHelper.get_keylist(key_id).size > 0;
|
||||
try {
|
||||
return key_id != null && GPGHelper.get_keylist(key_id).size > 0;
|
||||
} catch (Error e) { return false; }
|
||||
} else if (conversation.type_ == Conversation.Type.GROUPCHAT) {
|
||||
Gee.List<Jid> muc_jids = new Gee.ArrayList<Jid>();
|
||||
Gee.List<Jid>? occupants = stream_interactor.get_module(MucManager.IDENTITY).get_occupants(conversation.counterpart, conversation.account);
|
||||
|
|
|
@ -8,19 +8,23 @@ public class InFileProcessor : IncommingFileProcessor, Object {
|
|||
}
|
||||
|
||||
public void process(FileTransfer file_transfer) {
|
||||
uint8[] buf = new uint8[256];
|
||||
Array<uint8> data = new Array<uint8>(false, true, 0);
|
||||
size_t len = -1;
|
||||
do {
|
||||
len = file_transfer.input_stream.read(buf);
|
||||
data.append_vals(buf, (uint) len);
|
||||
} while(len > 0);
|
||||
try {
|
||||
uint8[] buf = new uint8[256];
|
||||
Array<uint8> data = new Array<uint8>(false, true, 0);
|
||||
size_t len = -1;
|
||||
do {
|
||||
len = file_transfer.input_stream.read(buf);
|
||||
data.append_vals(buf, (uint) len);
|
||||
} while(len > 0);
|
||||
|
||||
uint8[] clear_data = GPGHelper.decrypt_data(data.data);
|
||||
file_transfer.input_stream = new MemoryInputStream.from_data(clear_data, GLib.free);
|
||||
file_transfer.encryption = Encryption.PGP;
|
||||
if (file_transfer.file_name.has_suffix(".pgp")) {
|
||||
file_transfer.file_name = file_transfer.file_name.substring(0, file_transfer.file_name.length - 4);
|
||||
uint8[] clear_data = GPGHelper.decrypt_data(data.data);
|
||||
file_transfer.input_stream = new MemoryInputStream.from_data(clear_data, GLib.free);
|
||||
file_transfer.encryption = Encryption.PGP;
|
||||
if (file_transfer.file_name.has_suffix(".pgp")) {
|
||||
file_transfer.file_name = file_transfer.file_name.substring(0, file_transfer.file_name.length - 4);
|
||||
}
|
||||
} catch (Error e) {
|
||||
file_transfer.state = FileTransfer.State.FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public class Manager : StreamInteractionModule, Object {
|
|||
stream_interactor.get_module(MessageProcessor.IDENTITY).pre_message_send.connect(check_encypt);
|
||||
}
|
||||
|
||||
public GPG.Key[] get_key_fprs(Conversation conversation) {
|
||||
public GPG.Key[] get_key_fprs(Conversation conversation) throws Error {
|
||||
Gee.List<string> keys = new Gee.ArrayList<string>();
|
||||
keys.add(db.get_account_key(conversation.account));
|
||||
if (conversation.type_ == Conversation.Type.GROUPCHAT) {
|
||||
|
@ -70,13 +70,17 @@ public class Manager : StreamInteractionModule, Object {
|
|||
}
|
||||
|
||||
private void check_encypt(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) {
|
||||
if (message.encryption == Encryption.PGP) {
|
||||
GPG.Key[] keys = get_key_fprs(conversation);
|
||||
Core.XmppStream? stream = stream_interactor.get_stream(conversation.account);
|
||||
if (stream != null) {
|
||||
bool encrypted = stream.get_module(Module.IDENTITY).encrypt(message_stanza, keys);
|
||||
if (!encrypted) message.marked = Entities.Message.Marked.WONTSEND;
|
||||
try {
|
||||
if (message.encryption == Encryption.PGP) {
|
||||
GPG.Key[] keys = get_key_fprs(conversation);
|
||||
Core.XmppStream? stream = stream_interactor.get_stream(conversation.account);
|
||||
if (stream != null) {
|
||||
bool encrypted = stream.get_module(Module.IDENTITY).encrypt(message_stanza, keys);
|
||||
if (!encrypted) message.marked = Entities.Message.Marked.WONTSEND;
|
||||
}
|
||||
}
|
||||
} catch (Error e) {
|
||||
message.marked = Entities.Message.Marked.WONTSEND;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,11 +16,15 @@ public class OutFileProcessor : OutgoingFileProcessor, Object {
|
|||
|
||||
public void process(Conversation conversation, FileTransfer file_transfer) {
|
||||
string uri = file_transfer.get_uri();
|
||||
GPG.Key[] keys = stream_interactor.get_module(Manager.IDENTITY).get_key_fprs(conversation);
|
||||
uint8[] enc_content = GPGHelper.encrypt_file(uri, keys, GPG.EncryptFlags.ALWAYS_TRUST);
|
||||
file_transfer.input_stream = new MemoryInputStream.from_data(enc_content, GLib.free);
|
||||
file_transfer.encryption = Encryption.PGP;
|
||||
file_transfer.server_file_name = file_transfer.server_file_name + ".pgp";
|
||||
try {
|
||||
GPG.Key[] keys = stream_interactor.get_module(Manager.IDENTITY).get_key_fprs(conversation);
|
||||
uint8[] enc_content = GPGHelper.encrypt_file(uri, keys, GPG.EncryptFlags.ALWAYS_TRUST);
|
||||
file_transfer.input_stream = new MemoryInputStream.from_data(enc_content, GLib.free);
|
||||
file_transfer.encryption = Encryption.PGP;
|
||||
file_transfer.server_file_name = file_transfer.server_file_name + ".pgp";
|
||||
} catch (Error e) {
|
||||
file_transfer.state = FileTransfer.State.FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ public class Database {
|
|||
return statement;
|
||||
}
|
||||
|
||||
public void exec(string sql) {
|
||||
public void exec(string sql) throws Error {
|
||||
ensure_init();
|
||||
if (db.exec(sql) != OK) {
|
||||
throw new Error(-1, 0, @"SQLite error: $(db.errcode()) - $(db.errmsg())");
|
||||
|
|
|
@ -102,14 +102,22 @@ public class Table {
|
|||
}
|
||||
}
|
||||
sql += @"$constraints)";
|
||||
db.exec(sql);
|
||||
try {
|
||||
db.exec(sql);
|
||||
} catch (Error e) {
|
||||
error("Qlite Error: Create table at version");
|
||||
}
|
||||
}
|
||||
|
||||
public void add_columns_for_version(long old_version, long new_version) {
|
||||
ensure_init();
|
||||
foreach (Column c in columns) {
|
||||
if (c.min_version <= new_version && c.max_version >= new_version && c.min_version > old_version) {
|
||||
db.exec(@"ALTER TABLE $name ADD COLUMN $c");
|
||||
try {
|
||||
db.exec(@"ALTER TABLE $name ADD COLUMN $c");
|
||||
} catch (Error e) {
|
||||
error("Qlite Error: Add columns for version");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,16 +138,24 @@ public class Table {
|
|||
}
|
||||
}
|
||||
if (column_deletion_required) {
|
||||
db.exec(@"ALTER TABLE $name RENAME TO _$(name)_$old_version");
|
||||
create_table_at_version(new_version);
|
||||
db.exec(@"INSERT INTO $name ($column_list) SELECT $column_list FROM _$(name)_$old_version");
|
||||
db.exec(@"DROP TABLE _$(name)_$old_version");
|
||||
try {
|
||||
db.exec(@"ALTER TABLE $name RENAME TO _$(name)_$old_version");
|
||||
create_table_at_version(new_version);
|
||||
db.exec(@"INSERT INTO $name ($column_list) SELECT $column_list FROM _$(name)_$old_version");
|
||||
db.exec(@"DROP TABLE _$(name)_$old_version");
|
||||
} catch (Error e) {
|
||||
error("Qlite Error: Delete volumns for version change");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void post() {
|
||||
foreach (string stmt in post_statements) {
|
||||
db.exec(stmt);
|
||||
try {
|
||||
db.exec(stmt);
|
||||
} catch (Error e) {
|
||||
error("Qlite Error: Post");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,8 +54,6 @@ public class StanzaReader {
|
|||
buffer_pos = 0;
|
||||
} catch (GLib.IOError e) {
|
||||
throw new XmlError.IO_ERROR("IOError in GLib: %s".printf(e.message));
|
||||
} catch (GLib.TlsError e) {
|
||||
throw new XmlError.IO_ERROR("TlsError in GLib: %s".printf(e.message));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -360,8 +360,12 @@ public class StartTlsConnectionProvider : ConnectionProvider {
|
|||
}
|
||||
|
||||
public override IOStream? connect(XmppStream stream) {
|
||||
SocketClient client = new SocketClient();
|
||||
return client.connect_to_host(srv_target.get_hostname(), srv_target.get_port());
|
||||
try {
|
||||
SocketClient client = new SocketClient();
|
||||
return client.connect_to_host(srv_target.get_hostname(), srv_target.get_port());
|
||||
} catch (Error e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public override string get_id() { return "start_tls"; }
|
||||
|
|
|
@ -37,10 +37,14 @@ public class TlsConnectionProvider : ConnectionProvider {
|
|||
|
||||
public override IOStream? connect(XmppStream stream) {
|
||||
SocketClient client = new SocketClient();
|
||||
IOStream? io_stream = client.connect_to_host(srv_target.get_hostname(), srv_target.get_port());
|
||||
io_stream = TlsClientConnection.new(io_stream, new NetworkAddress(srv_target.get_hostname(), srv_target.get_port()));
|
||||
stream.add_flag(new Tls.Flag() { finished=true });
|
||||
return io_stream;
|
||||
try {
|
||||
IOStream? io_stream = client.connect_to_host(srv_target.get_hostname(), srv_target.get_port());
|
||||
io_stream = TlsClientConnection.new(io_stream, new NetworkAddress(srv_target.get_hostname(), srv_target.get_port()));
|
||||
stream.add_flag(new Tls.Flag() { finished=true });
|
||||
return io_stream;
|
||||
} catch (Error e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public override string get_id() { return "start_tls"; }
|
||||
|
|
Loading…
Reference in a new issue