diff --git a/Cargo.toml b/Cargo.toml index 2417a92eb..19e7560ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,3 +24,4 @@ sha2 = "0.8.0" rand = "0.6.5" smallvec = "0.6.9" libsqlite3-sys = "0.14.0" +reqwest = "0.9.15" diff --git a/src/constants.rs b/src/constants.rs index 6fcb73053..d00644b17 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -9,47 +9,47 @@ pub const DC_GCM_ADDDAYMARKER: usize = 0x01; pub const DC_GCL_VERIFIED_ONLY: usize = 0x01; pub const DC_GCL_ADD_SELF: usize = 0x02; -// param1 is a directory where the keys are written to +/// param1 is a directory where the keys are written to pub const DC_IMEX_EXPORT_SELF_KEYS: usize = 1; -// param1 is a directory where the keys are searched in and read from +/// param1 is a directory where the keys are searched in and read from pub const DC_IMEX_IMPORT_SELF_KEYS: usize = 2; -// param1 is a directory where the backup is written to +/// param1 is a directory where the backup is written to pub const DC_IMEX_EXPORT_BACKUP: usize = 11; -// param1 is the file with the backup to import +/// param1 is the file with the backup to import pub const DC_IMEX_IMPORT_BACKUP: usize = 12; -// id=contact +/// id=contact pub const DC_QR_ASK_VERIFYCONTACT: usize = 200; -// text1=groupname +/// text1=groupname pub const DC_QR_ASK_VERIFYGROUP: usize = 202; -// id=contact +/// id=contact pub const DC_QR_FPR_OK: usize = 210; -// id=contact +/// id=contact pub const DC_QR_FPR_MISMATCH: usize = 220; -// test1=formatted fingerprint +/// test1=formatted fingerprint pub const DC_QR_FPR_WITHOUT_ADDR: usize = 230; -// id=contact +/// id=contact pub const DC_QR_ADDR: usize = 320; -// text1=text +/// text1=text pub const DC_QR_TEXT: usize = 330; -// text1=URL +/// text1=URL pub const DC_QR_URL: usize = 332; -// text1=error string +/// text1=error string pub const DC_QR_ERROR: usize = 400; -// virtual chat showing all messages belonging to chats flagged with chats.blocked=2 +/// virtual chat showing all messages belonging to chats flagged with chats.blocked=2 pub const DC_CHAT_ID_DEADDROP: usize = 1; -// messages that should be deleted get this chat_id; the messages are deleted from the working thread later then. This is also needed as rfc724_mid should be preset as long as the message is not deleted on the server (otherwise it is downloaded again) +/// messages that should be deleted get this chat_id; the messages are deleted from the working thread later then. This is also needed as rfc724_mid should be preset as long as the message is not deleted on the server (otherwise it is downloaded again) pub const DC_CHAT_ID_TRASH: usize = 3; -// a message is just in creation but not yet assigned to a chat (eg. we may need the message ID to set up blobs; this avoids unready message to be sent and shown) +/// a message is just in creation but not yet assigned to a chat (eg. we may need the message ID to set up blobs; this avoids unready message to be sent and shown) pub const DC_CHAT_ID_MSGS_IN_CREATION: usize = 4; -// virtual chat showing all messages flagged with msgs.starred=2 +/// virtual chat showing all messages flagged with msgs.starred=2 pub const DC_CHAT_ID_STARRED: usize = 5; -// only an indicator in a chatlist +/// only an indicator in a chatlist pub const DC_CHAT_ID_ARCHIVED_LINK: usize = 6; -// only an indicator in a chatlist +/// only an indicator in a chatlist pub const DC_CHAT_ID_ALLDONE_HINT: usize = 7; -// larger chat IDs are "real" chats, their messages are "real" messages. +/// larger chat IDs are "real" chats, their messages are "real" messages. pub const DC_CHAT_ID_LAST_SPECIAL: usize = 9; pub const DC_CHAT_TYPE_UNDEFINED: usize = 0; @@ -69,13 +69,13 @@ pub const DC_STATE_OUT_PREPARING: usize = 18; pub const DC_STATE_OUT_DRAFT: usize = 19; pub const DC_STATE_OUT_PENDING: usize = 20; pub const DC_STATE_OUT_FAILED: usize = 24; -// to check if a mail was sent, use dc_msg_is_sent() +/// to check if a mail was sent, use dc_msg_is_sent() pub const DC_STATE_OUT_DELIVERED: usize = 26; pub const DC_STATE_OUT_MDN_RCVD: usize = 28; -// approx. max. lenght returned by dc_msg_get_text() +/// approx. max. lenght returned by dc_msg_get_text() pub const DC_MAX_GET_TEXT_LEN: usize = 30000; -// approx. max. lenght returned by dc_get_msg_info() +/// approx. max. lenght returned by dc_get_msg_info() pub const DC_MAX_GET_INFO_LEN: usize = 100000; pub const DC_CONTACT_ID_SELF: usize = 1; @@ -86,460 +86,360 @@ pub const DC_TEXT1_DRAFT: usize = 1; pub const DC_TEXT1_USERNAME: usize = 2; pub const DC_TEXT1_SELF: usize = 3; -/** - * Text message. - * The text of the message is set using dc_msg_set_text() - * and retrieved with dc_msg_get_text(). - */ +/// Text message. +/// The text of the message is set using dc_msg_set_text() +/// and retrieved with dc_msg_get_text(). pub const DC_MSG_TEXT: usize = 10; -/** - * Image message. - * If the image is an animated GIF, the type DC_MSG_GIF should be used. - * File, width and height are set via dc_msg_set_file(), dc_msg_set_dimension - * and retrieved via dc_msg_set_file(), dc_msg_set_dimension(). - */ +/// Image message. +/// If the image is an animated GIF, the type DC_MSG_GIF should be used. +/// File, width and height are set via dc_msg_set_file(), dc_msg_set_dimension +/// and retrieved via dc_msg_set_file(), dc_msg_set_dimension(). pub const DC_MSG_IMAGE: usize = 20; -/** - * Animated GIF message. - * File, width and height are set via dc_msg_set_file(), dc_msg_set_dimension() - * and retrieved via dc_msg_get_file(), dc_msg_get_width(), dc_msg_get_height(). - */ +/// Animated GIF message. +/// File, width and height are set via dc_msg_set_file(), dc_msg_set_dimension() +/// and retrieved via dc_msg_get_file(), dc_msg_get_width(), dc_msg_get_height(). pub const DC_MSG_GIF: usize = 21; -/** - * Message containing an Audio file. - * File and duration are set via dc_msg_set_file(), dc_msg_set_duration() - * and retrieved via dc_msg_get_file(), dc_msg_get_duration(). - */ +/// Message containing an Audio file. +/// File and duration are set via dc_msg_set_file(), dc_msg_set_duration() +/// and retrieved via dc_msg_get_file(), dc_msg_get_duration(). pub const DC_MSG_AUDIO: usize = 40; -/** - * A voice message that was directly recorded by the user. - * For all other audio messages, the type #DC_MSG_AUDIO should be used. - * File and duration are set via dc_msg_set_file(), dc_msg_set_duration() - * and retieved via dc_msg_get_file(), dc_msg_get_duration() - */ +/// A voice message that was directly recorded by the user. +/// For all other audio messages, the type #DC_MSG_AUDIO should be used. +/// File and duration are set via dc_msg_set_file(), dc_msg_set_duration() +/// and retieved via dc_msg_get_file(), dc_msg_get_duration() pub const DC_MSG_VOICE: usize = 41; -/** - * Video messages. - * File, width, height and durarion - * are set via dc_msg_set_file(), dc_msg_set_dimension(), dc_msg_set_duration() - * and retrieved via - * dc_msg_get_file(), dc_msg_get_width(), - * dc_msg_get_height(), dc_msg_get_duration(). - */ +/// Video messages. +/// File, width, height and durarion +/// are set via dc_msg_set_file(), dc_msg_set_dimension(), dc_msg_set_duration() +/// and retrieved via +/// dc_msg_get_file(), dc_msg_get_width(), +/// dc_msg_get_height(), dc_msg_get_duration(). pub const DC_MSG_VIDEO: usize = 50; -/** - * Message containing any file, eg. a PDF. - * The file is set via dc_msg_set_file() - * and retrieved via dc_msg_get_file(). - */ +/// Message containing any file, eg. a PDF. +/// The file is set via dc_msg_set_file() +/// and retrieved via dc_msg_get_file(). pub const DC_MSG_FILE: usize = 60; -/** - * @defgroup DC_LP DC_LP - * - * Flags for configuring IMAP and SMTP servers. - * These flags are optional - * and may be set together with the username, password etc. - * via dc_set_config() using the key "server_flags". - * - * @addtogroup DC_LP - * @{ - */ +// Flags for configuring IMAP and SMTP servers. +// These flags are optional +// and may be set together with the username, password etc. +// via dc_set_config() using the key "server_flags". -/** - * Force OAuth2 authorization. This flag does not skip automatic configuration. - * Before calling dc_configure() with DC_LP_AUTH_OAUTH2 set, - * the user has to confirm access at the URL returned by dc_get_oauth2_url(). - */ +/// Force OAuth2 authorization. This flag does not skip automatic configuration. +/// Before calling dc_configure() with DC_LP_AUTH_OAUTH2 set, +/// the user has to confirm access at the URL returned by dc_get_oauth2_url(). pub const DC_LP_AUTH_OAUTH2: usize = 0x2; -/** - * Force NORMAL authorization, this is the default. - * If this flag is set, automatic configuration is skipped. - */ +/// Force NORMAL authorization, this is the default. +/// If this flag is set, automatic configuration is skipped. pub const DC_LP_AUTH_NORMAL: usize = 0x4; -/** - * Connect to IMAP via STARTTLS. - * If this flag is set, automatic configuration is skipped. - */ +/// Connect to IMAP via STARTTLS. +/// If this flag is set, automatic configuration is skipped. pub const DC_LP_IMAP_SOCKET_STARTTLS: usize = 0x100; -/** - * Connect to IMAP via SSL. - * If this flag is set, automatic configuration is skipped. - */ +/// Connect to IMAP via SSL. +/// If this flag is set, automatic configuration is skipped. pub const DC_LP_IMAP_SOCKET_SSL: usize = 0x200; -/** - * Connect to IMAP unencrypted, this should not be used. - * If this flag is set, automatic configuration is skipped. - */ +/// Connect to IMAP unencrypted, this should not be used. +/// If this flag is set, automatic configuration is skipped. pub const DC_LP_IMAP_SOCKET_PLAIN: usize = 0x400; -/** - * Connect to SMTP via STARTTLS. - * If this flag is set, automatic configuration is skipped. - */ +/// Connect to SMTP via STARTTLS. +/// If this flag is set, automatic configuration is skipped. pub const DC_LP_SMTP_SOCKET_STARTTLS: usize = 0x10000; -/** - * Connect to SMTP via SSL. - * If this flag is set, automatic configuration is skipped. - */ +/// Connect to SMTP via SSL. +/// If this flag is set, automatic configuration is skipped. pub const DC_LP_SMTP_SOCKET_SSL: usize = 0x20000; -/** - * Connect to SMTP unencrypted, this should not be used. - * If this flag is set, automatic configuration is skipped. - */ +/// Connect to SMTP unencrypted, this should not be used. +/// If this flag is set, automatic configuration is skipped. pub const DC_LP_SMTP_SOCKET_PLAIN: usize = 0x40000; -// if none of these flags are set, the default is choosen +/// if none of these flags are set, the default is choosen pub const DC_LP_AUTH_FLAGS: usize = (DC_LP_AUTH_OAUTH2 | DC_LP_AUTH_NORMAL); -// if none of these flags are set, the default is choosen +/// if none of these flags are set, the default is choosen pub const DC_LP_IMAP_SOCKET_FLAGS: usize = (DC_LP_IMAP_SOCKET_STARTTLS | DC_LP_IMAP_SOCKET_SSL | DC_LP_IMAP_SOCKET_PLAIN); -// if none of these flags are set, the default is choosen +/// if none of these flags are set, the default is choosen pub const DC_LP_SMTP_SOCKET_FLAGS: usize = (DC_LP_SMTP_SOCKET_STARTTLS | DC_LP_SMTP_SOCKET_SSL | DC_LP_SMTP_SOCKET_PLAIN); -/** - * @defgroup DC_EVENT DC_EVENT - * - * These constants are used as events - * reported to the callback given to dc_context_new(). - * If you do not want to handle an event, it is always safe to return 0, - * so there is no need to add a "case" for every event. - * - * @addtogroup DC_EVENT - * @{ - */ +// These constants are used as events +// reported to the callback given to dc_context_new(). +// If you do not want to handle an event, it is always safe to return 0, +// so there is no need to add a "case" for every event. -/** - * The library-user may write an informational string to the log. - * Passed to the callback given to dc_context_new(). - * - * This event should not be reported to the end-user using a popup or something like that. - * - * @param data1 0 - * @param data2 (const char*) Info string in english language. - * Must not be free()'d or modified and is valid only until the callback returns. - * @return 0 - */ -pub const DC_EVENT_INFO: usize = 100; +#[derive(Debug, Clone, Copy)] +#[repr(u32)] +pub enum Event { + /// The library-user may write an informational string to the log. + /// Passed to the callback given to dc_context_new(). + /// This event should not be reported to the end-user using a popup or something like that. + /// @param data1 0 + /// @param data2 (const char*) Info string in english language. + /// Must not be free()'d or modified and is valid only until the callback returns. + /// @return 0 + INFO = 100, -/** - * Emitted when SMTP connection is established and login was successful. - * - * @param data1 0 - * @param data2 (const char*) Info string in english language. - * Must not be free()'d or modified and is valid only until the callback returns. - * @return 0 - */ -pub const DC_EVENT_SMTP_CONNECTED: usize = 101; + /// Emitted when SMTP connection is established and login was successful. + /// + /// @param data1 0 + /// @param data2 (const char*) Info string in english language. + /// Must not be free()'d or modified and is valid only until the callback returns. + /// @return 0 + SMTP_CONNECTED = 101, -/** - * Emitted when IMAP connection is established and login was successful. - * - * @param data1 0 - * @param data2 (const char*) Info string in english language. - * Must not be free()'d or modified and is valid only until the callback returns. - * @return 0 - */ -pub const DC_EVENT_IMAP_CONNECTED: usize = 102; + /// Emitted when IMAP connection is established and login was successful. + /// + /// @param data1 0 + /// @param data2 (const char*) Info string in english language. + /// Must not be free()'d or modified and is valid only until the callback returns. + /// @return 0 + IMAP_CONNECTED = 102, -/** - * Emitted when a message was successfully sent to the SMTP server. - * - * @param data1 0 - * @param data2 (const char*) Info string in english language. - * Must not be free()'d or modified and is valid only until the callback returns. - * @return 0 - */ -pub const DC_EVENT_SMTP_MESSAGE_SENT: usize = 103; + /// Emitted when a message was successfully sent to the SMTP server. + /// + /// @param data1 0 + /// @param data2 (const char*) Info string in english language. + /// Must not be free()'d or modified and is valid only until the callback returns. + /// @return 0 + SMTP_MESSAGE_SENT = 103, -/** - * The library-user should write a warning string to the log. - * Passed to the callback given to dc_context_new(). - * - * This event should not be reported to the end-user using a popup or something like that. - * - * @param data1 0 - * @param data2 (const char*) Warning string in english language. - * Must not be free()'d or modified and is valid only until the callback returns. - * @return 0 - */ -pub const DC_EVENT_WARNING: usize = 300; + /// The library-user should write a warning string to the log. + /// Passed to the callback given to dc_context_new(). + /// + /// This event should not be reported to the end-user using a popup or something like that. + /// + /// @param data1 0 + /// @param data2 (const char*) Warning string in english language. + /// Must not be free()'d or modified and is valid only until the callback returns. + /// @return 0 + WARNING = 300, -/** - * The library-user should report an error to the end-user. - * Passed to the callback given to dc_context_new(). - * - * As most things are asynchrounous, things may go wrong at any time and the user - * should not be disturbed by a dialog or so. Instead, use a bubble or so. - * - * However, for ongoing processes (eg. dc_configure()) - * or for functions that are expected to fail (eg. dc_continue_key_transfer()) - * it might be better to delay showing these events until the function has really - * failed (returned false). It should be sufficient to report only the _last_ error - * in a messasge box then. - * - * @param data1 0 - * @param data2 (const char*) Error string, always set, never NULL. Frequent error strings are - * localized using #DC_EVENT_GET_STRING, however, most error strings will be in english language. - * Must not be free()'d or modified and is valid only until the callback returns. - * @return 0 - */ -pub const DC_EVENT_ERROR: usize = 400; + /// The library-user should report an error to the end-user. + /// Passed to the callback given to dc_context_new(). + /// + /// As most things are asynchrounous, things may go wrong at any time and the user + /// should not be disturbed by a dialog or so. Instead, use a bubble or so. + /// + /// However, for ongoing processes (eg. dc_configure()) + /// or for functions that are expected to fail (eg. dc_continue_key_transfer()) + /// it might be better to delay showing these events until the function has really + /// failed (returned false). It should be sufficient to report only the _last_ error + /// in a messasge box then. + /// + /// @param data1 0 + /// @param data2 (const char*) Error string, always set, never NULL. Frequent error strings are + /// localized using #DC_EVENT_GET_STRING, however, most error strings will be in english language. + /// Must not be free()'d or modified and is valid only until the callback returns. + /// @return 0 + ERROR = 400, -/** - * An action cannot be performed because there is no network available. - * - * The library will typically try over after a some time - * and when dc_maybe_network() is called. - * - * Network errors should be reported to users in a non-disturbing way, - * however, as network errors may come in a sequence, - * it is not useful to raise each an every error to the user. - * For this purpose, data1 is set to 1 if the error is probably worth reporting. - * - * Moreover, if the UI detects that the device is offline, - * it is probably more useful to report this to the user - * instread of the string from data2. - * - * @param data1 (int) 1=first/new network error, should be reported the user; - * 0=subsequent network error, should be logged only - * @param data2 (const char*) Error string, always set, never NULL. - * Must not be free()'d or modified and is valid only until the callback returns. - * @return 0 - */ -pub const DC_EVENT_ERROR_NETWORK: usize = 401; + /// An action cannot be performed because there is no network available. + /// + /// The library will typically try over after a some time + /// and when dc_maybe_network() is called. + /// + /// Network errors should be reported to users in a non-disturbing way, + /// however, as network errors may come in a sequence, + /// it is not useful to raise each an every error to the user. + /// For this purpose, data1 is set to 1 if the error is probably worth reporting. + /// + /// Moreover, if the UI detects that the device is offline, + /// it is probably more useful to report this to the user + /// instread of the string from data2. + /// + /// @param data1 (int) 1=first/new network error, should be reported the user; + /// 0=subsequent network error, should be logged only + /// @param data2 (const char*) Error string, always set, never NULL. + /// Must not be free()'d or modified and is valid only until the callback returns. + /// @return 0 + ERROR_NETWORK = 401, -/** - * An action cannot be performed because the user is not in the group. - * Reported eg. after a call to - * dc_set_chat_name(), dc_set_chat_profile_image(), - * dc_add_contact_to_chat(), dc_remove_contact_from_chat(), - * dc_send_text_msg() or another sending function. - * - * @param data1 0 - * @param data2 (const char*) Info string in english language. - * Must not be free()'d or modified - * and is valid only until the callback returns. - * @return 0 - */ -pub const DC_EVENT_ERROR_SELF_NOT_IN_GROUP: usize = 410; + /// An action cannot be performed because the user is not in the group. + /// Reported eg. after a call to + /// dc_set_chat_name(), dc_set_chat_profile_image(), + /// dc_add_contact_to_chat(), dc_remove_contact_from_chat(), + /// dc_send_text_msg() or another sending function. + /// + /// @param data1 0 + /// @param data2 (const char*) Info string in english language. + /// Must not be free()'d or modified + /// and is valid only until the callback returns. + /// @return 0 + ERROR_SELF_NOT_IN_GROUP = 410, -/** - * Messages or chats changed. One or more messages or chats changed for various - * reasons in the database: - * - Messages sent, received or removed - * - Chats created, deleted or archived - * - A draft has been set - * - * @param data1 (int) chat_id for single added messages - * @param data2 (int) msg_id for single added messages - * @return 0 - */ -pub const DC_EVENT_MSGS_CHANGED: usize = 2000; + /// Messages or chats changed. One or more messages or chats changed for various + /// reasons in the database: + /// - Messages sent, received or removed + /// - Chats created, deleted or archived + /// - A draft has been set + /// + /// @param data1 (int) chat_id for single added messages + /// @param data2 (int) msg_id for single added messages + /// @return 0 + MSGS_CHANGED = 2000, -/** - * There is a fresh message. Typically, the user will show an notification - * when receiving this message. - * - * There is no extra #DC_EVENT_MSGS_CHANGED event send together with this event. - * - * @param data1 (int) chat_id - * @param data2 (int) msg_id - * @return 0 - */ -pub const DC_EVENT_INCOMING_MSG: usize = 2005; + /// There is a fresh message. Typically, the user will show an notification + /// when receiving this message. + /// + /// There is no extra #DC_EVENT_MSGS_CHANGED event send together with this event. + /// + /// @param data1 (int) chat_id + /// @param data2 (int) msg_id + /// @return 0 + INCOMING_MSG = 2005, -/** - * A single message is sent successfully. State changed from DC_STATE_OUT_PENDING to - * DC_STATE_OUT_DELIVERED, see dc_msg_get_state(). - * - * @param data1 (int) chat_id - * @param data2 (int) msg_id - * @return 0 - */ -pub const DC_EVENT_MSG_DELIVERED: usize = 2010; + /// A single message is sent successfully. State changed from DC_STATE_OUT_PENDING to + /// DC_STATE_OUT_DELIVERED, see dc_msg_get_state(). + /// + /// @param data1 (int) chat_id + /// @param data2 (int) msg_id + /// @return 0 + MSG_DELIVERED = 2010, -/** - * A single message could not be sent. State changed from DC_STATE_OUT_PENDING or DC_STATE_OUT_DELIVERED to - * DC_STATE_OUT_FAILED, see dc_msg_get_state(). - * - * @param data1 (int) chat_id - * @param data2 (int) msg_id - * @return 0 - */ -pub const DC_EVENT_MSG_FAILED: usize = 2012; + /// A single message could not be sent. State changed from DC_STATE_OUT_PENDING or DC_STATE_OUT_DELIVERED to + /// DC_STATE_OUT_FAILED, see dc_msg_get_state(). + /// + /// @param data1 (int) chat_id + /// @param data2 (int) msg_id + /// @return 0 + MSG_FAILED = 2012, -/** - * A single message is read by the receiver. State changed from DC_STATE_OUT_DELIVERED to - * DC_STATE_OUT_MDN_RCVD, see dc_msg_get_state(). - * - * @param data1 (int) chat_id - * @param data2 (int) msg_id - * @return 0 - */ -pub const DC_EVENT_MSG_READ: usize = 2015; + /// A single message is read by the receiver. State changed from DC_STATE_OUT_DELIVERED to + /// DC_STATE_OUT_MDN_RCVD, see dc_msg_get_state(). + /// + /// @param data1 (int) chat_id + /// @param data2 (int) msg_id + /// @return 0 + MSG_READ = 2015, -/** - * Chat changed. The name or the image of a chat group was changed or members were added or removed. - * Or the verify state of a chat has changed. - * See dc_set_chat_name(), dc_set_chat_profile_image(), dc_add_contact_to_chat() - * and dc_remove_contact_from_chat(). - * - * @param data1 (int) chat_id - * @param data2 0 - * @return 0 - */ -pub const DC_EVENT_CHAT_MODIFIED: usize = 2020; + /// Chat changed. The name or the image of a chat group was changed or members were added or removed. + /// Or the verify state of a chat has changed. + /// See dc_set_chat_name(), dc_set_chat_profile_image(), dc_add_contact_to_chat() + /// and dc_remove_contact_from_chat(). + /// + /// @param data1 (int) chat_id + /// @param data2 0 + /// @return 0 + CHAT_MODIFIED = 2020, -/** - * Contact(s) created, renamed, blocked or deleted. - * - * @param data1 (int) If not 0, this is the contact_id of an added contact that should be selected. - * @param data2 0 - * @return 0 - */ -pub const DC_EVENT_CONTACTS_CHANGED: usize = 2030; + /// Contact(s) created, renamed, blocked or deleted. + /// + /// @param data1 (int) If not 0, this is the contact_id of an added contact that should be selected. + /// @param data2 0 + /// @return 0 + CONTACTS_CHANGED = 2030, -/** - * Location of one or more contact has changed. - * - * @param data1 (int) contact_id of the contact for which the location has changed. - * If the locations of several contacts have been changed, - * eg. after calling dc_delete_all_locations(), this parameter is set to 0. - * @param data2 0 - * @return 0 - */ -pub const DC_EVENT_LOCATION_CHANGED: usize = 2035; + /// Location of one or more contact has changed. + /// + /// @param data1 (int) contact_id of the contact for which the location has changed. + /// If the locations of several contacts have been changed, + /// eg. after calling dc_delete_all_locations(), this parameter is set to 0. + /// @param data2 0 + /// @return 0 + LOCATION_CHANGED = 2035, -/** - * Inform about the configuration progress started by dc_configure(). - * - * @param data1 (int) 0=error, 1-999=progress in permille, 1000=success and done - * @param data2 0 - * @return 0 - */ -pub const DC_EVENT_CONFIGURE_PROGRESS: usize = 2041; + /// Inform about the configuration progress started by dc_configure(). + /// + /// @param data1 (int) 0=error, 1-999=progress in permille, 1000=success and done + /// @param data2 0 + /// @return 0 + CONFIGURE_PROGRESS = 2041, -/** - * Inform about the import/export progress started by dc_imex(). - * - * @param data1 (int) 0=error, 1-999=progress in permille, 1000=success and done - * @param data2 0 - * @return 0 - */ -pub const DC_EVENT_IMEX_PROGRESS: usize = 2051; + /// Inform about the import/export progress started by dc_imex(). + /// + /// @param data1 (int) 0=error, 1-999=progress in permille, 1000=success and done + /// @param data2 0 + /// @return 0 + IMEX_PROGRESS = 2051, -/** - * A file has been exported. A file has been written by dc_imex(). - * This event may be sent multiple times by a single call to dc_imex(). - * - * A typical purpose for a handler of this event may be to make the file public to some system - * services. - * - * @param data1 (const char*) Path and file name. - * Must not be free()'d or modified and is valid only until the callback returns. - * @param data2 0 - * @return 0 - */ -pub const DC_EVENT_IMEX_FILE_WRITTEN: usize = 2052; + /// A file has been exported. A file has been written by dc_imex(). + /// This event may be sent multiple times by a single call to dc_imex(). + /// + /// A typical purpose for a handler of this event may be to make the file public to some system + /// services. + /// + /// @param data1 (const char*) Path and file name. + /// Must not be free()'d or modified and is valid only until the callback returns. + /// @param data2 0 + /// @return 0 + IMEX_FILE_WRITTEN = 2052, -/** - * Progress information of a secure-join handshake from the view of the inviter - * (Alice, the person who shows the QR code). - * - * These events are typically sent after a joiner has scanned the QR code - * generated by dc_get_securejoin_qr(). - * - * @param data1 (int) ID of the contact that wants to join. - * @param data2 (int) Progress as: - * 300=vg-/vc-request received, typically shown as "bob@addr joins". - * 600=vg-/vc-request-with-auth received, vg-member-added/vc-contact-confirm sent, typically shown as "bob@addr verified". - * 800=vg-member-added-received received, shown as "bob@addr securely joined GROUP", only sent for the verified-group-protocol. - * 1000=Protocol finished for this contact. - * @return 0 - */ -pub const DC_EVENT_SECUREJOIN_INVITER_PROGRESS: usize = 2060; + /// Progress information of a secure-join handshake from the view of the inviter + /// (Alice, the person who shows the QR code). + /// + /// These events are typically sent after a joiner has scanned the QR code + /// generated by dc_get_securejoin_qr(). + /// + /// @param data1 (int) ID of the contact that wants to join. + /// @param data2 (int) Progress as: + /// 300=vg-/vc-request received, typically shown as "bob@addr joins". + /// 600=vg-/vc-request-with-auth received, vg-member-added/vc-contact-confirm sent, typically shown as "bob@addr verified". + /// 800=vg-member-added-received received, shown as "bob@addr securely joined GROUP", only sent for the verified-group-protocol. + /// 1000=Protocol finished for this contact. + /// @return 0 + SECUREJOIN_INVITER_PROGRESS = 2060, -/** - * Progress information of a secure-join handshake from the view of the joiner - * (Bob, the person who scans the QR code). - * - * The events are typically sent while dc_join_securejoin(), which - * may take some time, is executed. - * - * @param data1 (int) ID of the inviting contact. - * @param data2 (int) Progress as: - * 400=vg-/vc-request-with-auth sent, typically shown as "alice@addr verified, introducing myself." - * (Bob has verified alice and waits until Alice does the same for him) - * @return 0 - */ -pub const DC_EVENT_SECUREJOIN_JOINER_PROGRESS: usize = 2061; + /// Progress information of a secure-join handshake from the view of the joiner + /// (Bob, the person who scans the QR code). + /// The events are typically sent while dc_join_securejoin(), which + /// may take some time, is executed. + /// @param data1 (int) ID of the inviting contact. + /// @param data2 (int) Progress as: + /// 400=vg-/vc-request-with-auth sent, typically shown as "alice@addr verified, introducing myself." + /// (Bob has verified alice and waits until Alice does the same for him) + /// @return 0 + SECUREJOIN_JOINER_PROGRESS = 2061, -// the following events are functions that should be provided by the frontends + // the following events are functions that should be provided by the frontends + /// Requeste a localized string from the frontend. + /// @param data1 (int) ID of the string to request, one of the DC_STR_/// constants. + /// @param data2 (int) The count. If the requested string contains a placeholder for a numeric value, + /// the ui may use this value to return different strings on different plural forms. + /// @return (const char*) Null-terminated UTF-8 string. + /// The string will be free()'d by the core, + /// so it must be allocated using malloc() or a compatible function. + /// Return 0 if the ui cannot provide the requested string + /// the core will use a default string in english language then. + GET_STRING = 2091, -/** - * Requeste a localized string from the frontend. - * - * @param data1 (int) ID of the string to request, one of the DC_STR_* constants. - * @param data2 (int) The count. If the requested string contains a placeholder for a numeric value, - * the ui may use this value to return different strings on different plural forms. - * @return (const char*) Null-terminated UTF-8 string. - * The string will be free()'d by the core, - * so it must be allocated using malloc() or a compatible function. - * Return 0 if the ui cannot provide the requested string - * the core will use a default string in english language then. - */ -pub const DC_EVENT_GET_STRING: usize = 2091; + /// Request a HTTP-file or HTTPS-file from the frontend using HTTP-GET. + /// @param data1 (const char*) Null-terminated UTF-8 string containing the URL. + /// The string starts with https:// or http://. + /// Must not be free()'d or modified and is valid only until the callback returns. + /// @param data2 0 + /// @return (const char*) The content of the requested file as a null-terminated UTF-8 string; + /// Response headers, encodings etc. must be stripped. + /// Only the raw file should be returned. + /// CAVE: The string will be free()'d by the core, + /// so make sure it is allocated using malloc() or a compatible function. + /// If you cannot provide the content, just return 0 or an empty string. + HTTP_GET = 2100, -/** - * Request a HTTP-file or HTTPS-file from the frontend using HTTP-GET. - * - * @param data1 (const char*) Null-terminated UTF-8 string containing the URL. - * The string starts with https:// or http://. - * Must not be free()'d or modified and is valid only until the callback returns. - * @param data2 0 - * @return (const char*) The content of the requested file as a null-terminated UTF-8 string; - * Response headers, encodings etc. must be stripped. - * Only the raw file should be returned. - * CAVE: The string will be free()'d by the core, - * so make sure it is allocated using malloc() or a compatible function. - * If you cannot provide the content, just return 0 or an empty string. - */ -pub const DC_EVENT_HTTP_GET: usize = 2100; - -/** - * Request a HTTP-file or HTTPS-file from the frontend using HTTP-POST. - * - * @param data1 (const char*) Null-terminated UTF-8 string containing the URL. - * The string starts with https:// or http://. - * Must not be free()'d or modified and is valid only until the callback returns. - * Parameter to POST are added to the url after `?`. - * @param data2 0 - * @return (const char*) The content of the requested file as a null-terminated UTF-8 string; - * Response headers, encodings etc. must be stripped. - * Only the raw file should be returned. - * CAVE: The string will be free()'d by the core, - * so make sure it is allocated using malloc() or a compatible function. - * If you cannot provide the content, just return 0 or an empty string. - */ -pub const DC_EVENT_HTTP_POST: usize = 2110; - -/** - * @} - */ + /// Request a HTTP-file or HTTPS-file from the frontend using HTTP-POST. + /// @param data1 (const char*) Null-terminated UTF-8 string containing the URL. + /// The string starts with https:// or http://. + /// Must not be free()'d or modified and is valid only until the callback returns. + /// Parameter to POST are added to the url after `?`. + /// @param data2 0 + /// @return (const char*) The content of the requested file as a null-terminated UTF-8 string; + /// Response headers, encodings etc. must be stripped. + /// Only the raw file should be returned. + /// CAVE: The string will be free()'d by the core, + /// so make sure it is allocated using malloc() or a compatible function. + /// If you cannot provide the content, just return 0 or an empty string. + HTTP_POST = 2110, +} pub const DC_EVENT_FILE_COPIED: usize = 2055; // deprecated; pub const DC_EVENT_IS_OFFLINE: usize = 2081; // deprecated; @@ -547,23 +447,14 @@ pub const DC_ERROR_SEE_STRING: usize = 0; // deprecated; pub const DC_ERROR_SELF_NOT_IN_GROUP: usize = 1; // deprecated; pub const DC_STR_SELFNOTINGRP: usize = 21; // deprecated; -/* - * Values for dc_get|set_config("show_emails") - */ +/// Values for dc_get|set_config("show_emails") pub const DC_SHOW_EMAILS_OFF: usize = 0; pub const DC_SHOW_EMAILS_ACCEPTED_CONTACTS: usize = 1; pub const DC_SHOW_EMAILS_ALL: usize = 2; -/* - * TODO: Strings need some doumentation about used placeholders. - * - * @defgroup DC_STR DC_STR - * - * These constants are used to request strings using #DC_EVENT_GET_STRING. - * - * @addtogroup DC_STR - * @{ - */ +// TODO: Strings need some doumentation about used placeholders. +// These constants are used to request strings using #DC_EVENT_GET_STRING. + pub const DC_STR_NOMESSAGES: usize = 1; pub const DC_STR_SELF: usize = 2; pub const DC_STR_DRAFT: usize = 3; diff --git a/src/dc_chat.rs b/src/dc_chat.rs index ca3666c19..30e806d2a 100644 --- a/src/dc_chat.rs +++ b/src/dc_chat.rs @@ -1,6 +1,7 @@ use c2rust_bitfields::BitfieldStruct; use libc; +use crate::constants::Event; use crate::dc_array::*; use crate::dc_chatlist::*; use crate::dc_contact::*; @@ -61,7 +62,7 @@ pub unsafe fn dc_create_chat_by_msg_id( if 0 != send_event { (*context).cb.expect("non-null function pointer")( context, - 2000i32, + Event::MSGS_CHANGED, 0i32 as uintptr_t, 0i32 as uintptr_t, ); @@ -264,7 +265,7 @@ pub unsafe fn dc_create_chat_by_contact_id( if 0 != send_event { (*context).cb.expect("non-null function pointer")( context, - 2000i32, + Event::MSGS_CHANGED, 0i32 as uintptr_t, 0i32 as uintptr_t, ); @@ -448,7 +449,7 @@ pub unsafe fn dc_prepare_msg( let mut msg_id: uint32_t = prepare_msg_common(context, chat_id, msg); (*context).cb.expect("non-null function pointer")( context, - 2000i32, + Event::MSGS_CHANGED, (*msg).chat_id as uintptr_t, (*msg).id as uintptr_t, ); @@ -583,7 +584,7 @@ unsafe fn prepare_msg_raw( { dc_log_event( context, - 410i32, + Event::ERROR_SELF_NOT_IN_GROUP, 0i32, b"Cannot send message; self not in group.\x00" as *const u8 as *const libc::c_char, ); @@ -969,7 +970,7 @@ pub unsafe fn dc_send_msg( } (*context).cb.expect("non-null function pointer")( context, - 2000i32, + Event::MSGS_CHANGED, (*msg).chat_id as uintptr_t, (*msg).id as uintptr_t, ); @@ -1030,7 +1031,7 @@ pub unsafe fn dc_set_draft( if 0 != set_draft_raw(context, chat_id, msg) { (*context).cb.expect("non-null function pointer")( context, - 2000i32, + Event::MSGS_CHANGED, chat_id as uintptr_t, 0i32 as uintptr_t, ); @@ -1275,7 +1276,7 @@ pub unsafe fn dc_marknoticed_chat(mut context: *mut dc_context_t, mut chat_id: u sqlite3_step(update); (*context).cb.expect("non-null function pointer")( context, - 2000i32, + Event::MSGS_CHANGED, 0i32 as uintptr_t, 0i32 as uintptr_t, ); @@ -1301,7 +1302,7 @@ pub unsafe fn dc_marknoticed_all_chats(mut context: *mut dc_context_t) { sqlite3_step(update); (*context).cb.expect("non-null function pointer")( context, - 2000i32, + Event::MSGS_CHANGED, 0i32 as uintptr_t, 0i32 as uintptr_t, ); @@ -1435,7 +1436,7 @@ pub unsafe fn dc_archive_chat( sqlite3_finalize(stmt_0); (*context).cb.expect("non-null function pointer")( context, - 2000i32, + Event::MSGS_CHANGED, 0i32 as uintptr_t, 0i32 as uintptr_t, ); @@ -1487,7 +1488,7 @@ pub unsafe fn dc_delete_chat(mut context: *mut dc_context_t, mut chat_id: uint32 pending_transaction = 0i32; (*context).cb.expect("non-null function pointer")( context, - 2000i32, + Event::MSGS_CHANGED, 0i32 as uintptr_t, 0i32 as uintptr_t, ); @@ -1594,7 +1595,7 @@ pub unsafe fn dc_create_group_chat( if 0 != chat_id { (*context).cb.expect("non-null function pointer")( context, - 2000i32, + Event::MSGS_CHANGED, 0i32 as uintptr_t, 0i32 as uintptr_t, ); @@ -1659,7 +1660,7 @@ pub unsafe fn dc_add_contact_to_chat_ex( if !(dc_is_contact_in_chat(context, chat_id, 1i32 as uint32_t) == 1i32) { dc_log_event( context, - 410i32, + Event::ERROR_SELF_NOT_IN_GROUP, 0i32, b"Cannot add contact to group; self not in group.\x00" as *const u8 as *const libc::c_char, @@ -1731,14 +1732,14 @@ pub unsafe fn dc_add_contact_to_chat_ex( (*msg).id = dc_send_msg(context, chat_id, msg); (*context).cb.expect("non-null function pointer")( context, - 2000i32, + Event::MSGS_CHANGED, chat_id as uintptr_t, (*msg).id as uintptr_t, ); } (*context).cb.expect("non-null function pointer")( context, - 2020i32, + Event::MSGS_CHANGED, chat_id as uintptr_t, 0i32 as uintptr_t, ); @@ -1841,7 +1842,7 @@ pub unsafe fn dc_remove_contact_from_chat( if !(dc_is_contact_in_chat(context, chat_id, 1i32 as uint32_t) == 1i32) { dc_log_event( context, - 410i32, + Event::ERROR_SELF_NOT_IN_GROUP, 0i32, b"Cannot remove contact from chat; self not in group.\x00" as *const u8 as *const libc::c_char, @@ -1874,7 +1875,7 @@ pub unsafe fn dc_remove_contact_from_chat( (*msg).id = dc_send_msg(context, chat_id, msg); (*context).cb.expect("non-null function pointer")( context, - 2000i32, + Event::MSGS_CHANGED, chat_id as uintptr_t, (*msg).id as uintptr_t, ); @@ -1889,7 +1890,7 @@ pub unsafe fn dc_remove_contact_from_chat( if !(0 == dc_sqlite3_execute((*context).sql, q3)) { (*context).cb.expect("non-null function pointer")( context, - 2020i32, + Event::CHAT_MODIFIED, chat_id as uintptr_t, 0i32 as uintptr_t, ); @@ -1955,7 +1956,7 @@ pub unsafe fn dc_set_chat_name( } else if !(dc_is_contact_in_chat(context, chat_id, 1i32 as uint32_t) == 1i32) { dc_log_event( context, - 410i32, + Event::ERROR_SELF_NOT_IN_GROUP, 0i32, b"Cannot set chat name; self not in group\x00" as *const u8 as *const libc::c_char, @@ -1983,14 +1984,14 @@ pub unsafe fn dc_set_chat_name( (*msg).id = dc_send_msg(context, chat_id, msg); (*context).cb.expect("non-null function pointer")( context, - 2000i32, + Event::MSGS_CHANGED, chat_id as uintptr_t, (*msg).id as uintptr_t, ); } (*context).cb.expect("non-null function pointer")( context, - 2020i32, + Event::CHAT_MODIFIED, chat_id as uintptr_t, 0i32 as uintptr_t, ); @@ -2024,7 +2025,7 @@ pub unsafe fn dc_set_chat_profile_image( if !(dc_is_contact_in_chat(context, chat_id, 1i32 as uint32_t) == 1i32) { dc_log_event( context, - 410i32, + Event::ERROR_SELF_NOT_IN_GROUP, 0i32, b"Cannot set chat profile image; self not in group.\x00" as *const u8 as *const libc::c_char, @@ -2064,14 +2065,14 @@ pub unsafe fn dc_set_chat_profile_image( (*msg).id = dc_send_msg(context, chat_id, msg); (*context).cb.expect("non-null function pointer")( context, - 2000i32, + Event::MSGS_CHANGED, chat_id as uintptr_t, (*msg).id as uintptr_t, ); } (*context).cb.expect("non-null function pointer")( context, - 2020i32, + Event::CHAT_MODIFIED, chat_id as uintptr_t, 0i32 as uintptr_t, ); @@ -2200,7 +2201,7 @@ pub unsafe fn dc_forward_msgs( while i < icnt { (*context).cb.expect("non-null function pointer")( context, - 2000i32, + Event::MSGS_CHANGED, carray_get(created_db_entries, i as libc::c_uint) as uintptr_t, carray_get( created_db_entries, @@ -2451,7 +2452,7 @@ pub unsafe fn dc_add_device_msg( ); (*context).cb.expect("non-null function pointer")( context, - 2000i32, + Event::MSGS_CHANGED, chat_id as uintptr_t, msg_id as uintptr_t, ); diff --git a/src/dc_configure.rs b/src/dc_configure.rs index 974c81bc6..acbf8da06 100644 --- a/src/dc_configure.rs +++ b/src/dc_configure.rs @@ -1,6 +1,7 @@ use c2rust_bitfields::BitfieldStruct; use libc; +use crate::constants::Event; use crate::dc_array::*; use crate::dc_context::dc_context_t; use crate::dc_e2ee::*; @@ -163,7 +164,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( if !(0 != (*context).shall_stop_ongoing) { (*context).cb.expect("non-null function pointer")( context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 0i32 < 1i32 { 1i32 } else if 0i32 > 999i32 { @@ -197,7 +198,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( } else { (*context).cb.expect("non-null function pointer")( context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 10i32 < 1i32 { 1i32 } else if 10i32 > 999i32 { @@ -223,7 +224,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( } else { (*context).cb.expect("non-null function pointer")( context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 20i32 < 1i32 { 1i32 } else if 20i32 > 999i32 { @@ -261,7 +262,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( if !(0 != (*context).shall_stop_ongoing) { (*context).cb.expect("non-null function pointer")( context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 200i32 < 1i32 { 1i32 } else if 200i32 > 999i32 { @@ -289,12 +290,12 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( /* A. Search configurations from the domain used in the email-address, prefer encrypted */ if param_autoconfig.is_null() { let mut url: - *mut libc::c_char = + *mut libc::c_char = dc_mprintf(b"https://autoconfig.%s/mail/config-v1.1.xml?emailaddress=%s\x00" - as - *const u8 - as - *const libc::c_char, + as + *const u8 + as + *const libc::c_char, param_domain, param_addr_urlencoded); param_autoconfig = @@ -307,7 +308,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( .cb .expect("non-null function pointer")( context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 300i32 < 1i32 { 1i32 } else if 300i32 > 999i32 { @@ -329,12 +330,12 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( if param_autoconfig.is_null() { // the doc does not mention `emailaddress=`, however, Thunderbird adds it, see https://releases.mozilla.org/pub/thunderbird/ , which makes some sense let mut url_0: - *mut libc::c_char = + *mut libc::c_char = dc_mprintf(b"https://%s/.well-known/autoconfig/mail/config-v1.1.xml?emailaddress=%s\x00" - as - *const u8 - as - *const libc::c_char, + as + *const u8 + as + *const libc::c_char, param_domain, param_addr_urlencoded); param_autoconfig = moz_autoconfigure( @@ -348,7 +349,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( "non-null function pointer", )( context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 310i32 < 1i32 { 1i32 } else if 310i32 > 999i32 { @@ -377,16 +378,16 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( if param_autoconfig.is_null() { /* Outlook uses always SSL but different domains */ let mut url_1: - *mut libc::c_char = + *mut libc::c_char = dc_mprintf(b"https://%s%s/autodiscover/autodiscover.xml\x00" - as - *const u8 - as - *const libc::c_char, + as + *const u8 + as + *const libc::c_char, if i - == - 0i32 - { + == + 0i32 + { b"\x00" as *const u8 @@ -418,7 +419,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( "non-null function pointer", )( context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 320i32 + i * 10i32 < 1i32 { @@ -441,12 +442,12 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( _ => { if param_autoconfig.is_null() { let mut url_2: - *mut libc::c_char = + *mut libc::c_char = dc_mprintf(b"http://autoconfig.%s/mail/config-v1.1.xml?emailaddress=%s\x00" - as - *const u8 - as - *const libc::c_char, + as + *const u8 + as + *const libc::c_char, param_domain, param_addr_urlencoded); param_autoconfig = @@ -455,34 +456,36 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( param, ); free(url_2 - as - *mut libc::c_void); + as + *mut libc::c_void); if 0 != (*context) .shall_stop_ongoing { current_block = 2927484062889439186; } else { - (*context).cb.expect("non-null function pointer")(context, - 2041i32, - (if 340i32 - < - 1i32 - { - 1i32 - } else if 340i32 - > - 999i32 - { - 999i32 - } else { - 340i32 - }) - as - uintptr_t, - 0i32 - as - uintptr_t); + (*context).cb.expect("non-null function pointer")( + context, + Event::CONFIGURE_PROGRESS, + (if 340i32 + < + 1i32 + { + 1i32 + } else if 340i32 + > + 999i32 + { + 999i32 + } else { + 340i32 + }) + as + uintptr_t, + 0i32 + as + uintptr_t + ); current_block = 10778260831612459202; @@ -499,12 +502,12 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( { // do not transfer the email-address unencrypted let mut url_3: - *mut libc::c_char = + *mut libc::c_char = dc_mprintf(b"http://%s/.well-known/autoconfig/mail/config-v1.1.xml\x00" - as - *const u8 - as - *const libc::c_char, + as + *const u8 + as + *const libc::c_char, param_domain); param_autoconfig = @@ -512,36 +515,36 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( url_3, param); free(url_3 - as - *mut libc::c_void); + as + *mut libc::c_void); if 0 - != - (*context).shall_stop_ongoing - { + != + (*context).shall_stop_ongoing + { current_block = 2927484062889439186; } else { (*context).cb.expect("non-null function pointer")(context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 350i32 - < - 1i32 - { + < + 1i32 + { 1i32 } else if 350i32 - > - 999i32 - { + > + 999i32 + { 999i32 } else { 350i32 }) - as - uintptr_t, + as + uintptr_t, 0i32 - as - uintptr_t); + as + uintptr_t); current_block = 5207889489643863322; @@ -552,25 +555,25 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( 5207889489643863322; } match current_block - { + { 2927484062889439186 - => + => { } _ - => + => { /* B. If we have no configuration yet, search configuration in Thunderbird's centeral database */ if param_autoconfig.is_null() - { + { /* always SSL for Thunderbird's database */ let mut url_4: - *mut libc::c_char = + *mut libc::c_char = dc_mprintf(b"https://autoconfig.thunderbird.net/v1.1/%s\x00" - as - *const u8 - as - *const libc::c_char, + as + *const u8 + as + *const libc::c_char, param_domain); param_autoconfig = @@ -578,36 +581,36 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( url_4, param); free(url_4 - as - *mut libc::c_void); + as + *mut libc::c_void); if 0 - != - (*context).shall_stop_ongoing - { + != + (*context).shall_stop_ongoing + { current_block = 2927484062889439186; } else { (*context).cb.expect("non-null function pointer")(context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 500i32 - < - 1i32 - { + < + 1i32 + { 1i32 } else if 500i32 - > - 999i32 - { + > + 999i32 + { 999i32 } else { 500i32 }) - as - uintptr_t, + as + uintptr_t, 0i32 - as - uintptr_t); + as + uintptr_t); current_block = 2798392256336243897; @@ -618,35 +621,35 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( 2798392256336243897; } match current_block - { + { 2927484062889439186 - => + => { } _ - => + => { if !param_autoconfig.is_null() - { + { let mut r: - *mut libc::c_char = + *mut libc::c_char = dc_loginparam_get_readable(param_autoconfig); dc_log_info(context, 0i32, b"Got autoconfig: %s\x00" - as - *const u8 - as - *const libc::c_char, + as + *const u8 + as + *const libc::c_char, r); free(r + as + *mut libc::c_void); + if !(*param_autoconfig).mail_user.is_null() + { + free((*param).mail_user as *mut libc::c_void); - if !(*param_autoconfig).mail_user.is_null() - { - free((*param).mail_user - as - *mut libc::c_void); (*param).mail_user = dc_strdup_keep_null((*param_autoconfig).mail_user) @@ -818,7 +821,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( .cb .expect("non-null function pointer")( context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 600i32 < 1i32 { 1i32 } else if 600i32 > 999i32 { @@ -867,7 +870,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( .cb .expect("non-null function pointer")( context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 650i32 + username_variation * 30i32 < 1i32 { @@ -912,7 +915,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( .cb .expect("non-null function pointer")( context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 660i32 + username_variation * 30i32 < 1i32 { @@ -959,7 +962,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( .cb .expect("non-null function pointer")( context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 670i32 + username_variation * 30i32 < 1i32 { @@ -1000,7 +1003,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( "non-null function pointer", )( context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 800i32 < 1i32 { 1i32 } else if 800i32 > 999i32 { @@ -1027,25 +1030,25 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( 2927484062889439186; } else { (*context).cb.expect("non-null function pointer")(context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 850i32 - < - 1i32 - { + < + 1i32 + { 1i32 } else if 850i32 - > - 999i32 - { + > + 999i32 + { 999i32 } else { 850i32 }) - as - uintptr_t, + as + uintptr_t, 0i32 - as - uintptr_t); + as + uintptr_t); (*param).server_flags &= !(0x10000i32 | 0x20000i32 @@ -1054,19 +1057,19 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( 0x10000i32; (*param).send_port = 587i32; let mut r_3: - *mut libc::c_char = + *mut libc::c_char = dc_loginparam_get_readable(param); dc_log_info(context, 0i32, b"Trying: %s\x00" - as - *const u8 - as - *const libc::c_char, + as + *const u8 + as + *const libc::c_char, r_3); free(r_3 - as - *mut libc::c_void); + as + *mut libc::c_void); if 0 == dc_smtp_connect( (*context).smtp, param, @@ -1079,32 +1082,32 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( 2927484062889439186; } else { (*context).cb.expect("non-null function pointer")(context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 860i32 - < - 1i32 - { + < + 1i32 + { 1i32 } else if 860i32 - > - 999i32 - { + > + 999i32 + { 999i32 } else { 860i32 }) - as - uintptr_t, + as + uintptr_t, 0i32 - as - uintptr_t); + as + uintptr_t); (*param).server_flags &= !(0x10000i32 - | - 0x20000i32 - | - 0x40000i32); + | + 0x20000i32 + | + 0x40000i32); (*param).server_flags |= 0x10000i32; @@ -1112,24 +1115,24 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( .send_port = 25i32; let mut r_4: - *mut libc::c_char = + *mut libc::c_char = dc_loginparam_get_readable(param); dc_log_info(context, 0i32, b"Trying: %s\x00" - as - *const u8 - as - *const libc::c_char, + as + *const u8 + as + *const libc::c_char, r_4); free(r_4 - as - *mut libc::c_void); + as + *mut libc::c_void); if 0 - == - dc_smtp_connect((*context).smtp, - param) - { + == + dc_smtp_connect((*context).smtp, + param) + { current_block = 2927484062889439186; @@ -1157,51 +1160,51 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( .shall_stop_ongoing) { (*context).cb.expect("non-null function pointer")(context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 900i32 - < - 1i32 - { + < + 1i32 + { 1i32 } else if 900i32 - > - 999i32 - { + > + 999i32 + { 999i32 } else { 900i32 }) - as - uintptr_t, + as + uintptr_t, 0i32 - as - uintptr_t); + as + uintptr_t); flags = if 0 - != - dc_sqlite3_get_config_int((*context).sql, - b"mvbox_watch\x00" - as - *const u8 - as - *const libc::c_char, - 1i32) - || - 0 - != - dc_sqlite3_get_config_int((*context).sql, - b"mvbox_move\x00" - as - *const u8 - as - *const libc::c_char, - 1i32) - { - 0x1i32 - } else { - 0i32 - }; + != + dc_sqlite3_get_config_int((*context).sql, + b"mvbox_watch\x00" + as + *const u8 + as + *const libc::c_char, + 1i32) + || + 0 + != + dc_sqlite3_get_config_int((*context).sql, + b"mvbox_move\x00" + as + *const u8 + as + *const libc::c_char, + 1i32) + { + 0x1i32 + } else { + 0i32 + }; dc_configure_folders( context, (*context).inbox, @@ -1211,63 +1214,63 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( .shall_stop_ongoing) { (*context).cb.expect("non-null function pointer")(context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 910i32 - < - 1i32 - { + < + 1i32 + { 1i32 } else if 910i32 - > - 999i32 - { + > + 999i32 + { 999i32 } else { 910i32 }) - as - uintptr_t, + as + uintptr_t, 0i32 - as - uintptr_t); + as + uintptr_t); dc_loginparam_write(param, (*context).sql, b"configured_\x00" - as - *const u8 - as - *const libc::c_char); + as + *const u8 + as + *const libc::c_char); dc_sqlite3_set_config_int((*context).sql, b"configured\x00" - as - *const u8 - as - *const libc::c_char, + as + *const u8 + as + *const libc::c_char, 1i32); if !(0 - != - (*context).shall_stop_ongoing) - { + != + (*context).shall_stop_ongoing) + { (*context).cb.expect("non-null function pointer")(context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 920i32 - < - 1i32 - { + < + 1i32 + { 1i32 } else if 920i32 - > - 999i32 - { + > + 999i32 + { 999i32 } else { 920i32 }) - as - uintptr_t, + as + uintptr_t, 0i32 - as - uintptr_t); + as + uintptr_t); dc_ensure_secret_key_exists(context); success = @@ -1275,34 +1278,34 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( dc_log_info(context, 0i32, b"Configure completed.\x00" - as - *const u8 - as - *const libc::c_char); + as + *const u8 + as + *const libc::c_char); if !(0 - != - (*context).shall_stop_ongoing) - { + != + (*context).shall_stop_ongoing) + { (*context).cb.expect("non-null function pointer")(context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 940i32 - < - 1i32 - { + < + 1i32 + { 1i32 } else if 940i32 - > - 999i32 - { + > + 999i32 + { 999i32 } else { 940i32 }) - as - uintptr_t, + as + uintptr_t, 0i32 - as - uintptr_t); + as + uintptr_t); } } } @@ -1339,11 +1342,12 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP( free(mvbox_folder as *mut libc::c_void); (*context).cb.expect("non-null function pointer")( context, - 2041i32, + Event::CONFIGURE_PROGRESS, (if 0 != success { 1000i32 } else { 0i32 }) as uintptr_t, 0i32 as uintptr_t, ); } + pub unsafe fn dc_free_ongoing(mut context: *mut dc_context_t) { if context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint { return; @@ -1895,7 +1899,7 @@ unsafe fn read_autoconf_file( ); filecontent = (*context).cb.expect("non-null function pointer")( context, - 2100i32, + Event::HTTP_GET, url as uintptr_t, 0i32 as uintptr_t, ) as *mut libc::c_char; diff --git a/src/dc_contact.rs b/src/dc_contact.rs index a7dd61e87..f56857161 100644 --- a/src/dc_contact.rs +++ b/src/dc_contact.rs @@ -1,6 +1,7 @@ use c2rust_bitfields::BitfieldStruct; use libc; +use crate::constants::Event; use crate::dc_apeerstate::*; use crate::dc_array::*; use crate::dc_context::dc_context_t; @@ -45,7 +46,7 @@ pub unsafe fn dc_marknoticed_contact(mut context: *mut dc_context_t, mut contact sqlite3_finalize(stmt); (*context).cb.expect("non-null function pointer")( context, - 2000i32, + Event::MSGS_CHANGED, 0i32 as uintptr_t, 0i32 as uintptr_t, ); @@ -147,7 +148,7 @@ pub unsafe fn dc_create_contact( blocked = dc_is_contact_blocked(context, contact_id); (*context).cb.expect("non-null function pointer")( context, - 2030i32, + Event::CONTACTS_CHANGED, (if sth_modified == 2i32 { contact_id } else { @@ -214,7 +215,7 @@ pub unsafe fn dc_block_contact( if 0 != send_event { (*context).cb.expect("non-null function pointer")( context, - 2030i32, + Event::CONTACTS_CHANGED, 0i32 as uintptr_t, 0i32 as uintptr_t, ); @@ -579,7 +580,7 @@ pub unsafe fn dc_add_address_book( if 0 != modify_cnt { (*context).cb.expect("non-null function pointer")( context, - 2030i32, + Event::CONTACTS_CHANGED, 0i32 as uintptr_t, 0i32 as uintptr_t, ); @@ -936,7 +937,7 @@ pub unsafe fn dc_delete_contact( if !(sqlite3_step(stmt) != 101i32) { (*context).cb.expect("non-null function pointer")( context, - 2030i32, + Event::CONTACTS_CHANGED, 0i32 as uintptr_t, 0i32 as uintptr_t, ); diff --git a/src/dc_context.rs b/src/dc_context.rs index a91d79c1a..994630b52 100644 --- a/src/dc_context.rs +++ b/src/dc_context.rs @@ -1,6 +1,7 @@ use c2rust_bitfields::BitfieldStruct; use libc; +use crate::constants::Event; use crate::dc_array::*; use crate::dc_chat::*; use crate::dc_contact::*; @@ -13,7 +14,6 @@ use crate::dc_loginparam::*; use crate::dc_lot::dc_lot_t; use crate::dc_move::*; use crate::dc_msg::*; -// use crate::dc_openssl::*; use crate::dc_pgp::*; use crate::dc_receive_imf::*; use crate::dc_smtp::*; @@ -267,7 +267,7 @@ unsafe fn cb_get_config( */ unsafe fn cb_dummy( mut context: *mut dc_context_t, - mut event: libc::c_int, + mut event: Event, mut data1: uintptr_t, mut data2: uintptr_t, ) -> uintptr_t { diff --git a/src/dc_imap.rs b/src/dc_imap.rs index b8cadc3a9..cb0242b7f 100644 --- a/src/dc_imap.rs +++ b/src/dc_imap.rs @@ -1,6 +1,7 @@ use c2rust_bitfields::BitfieldStruct; use libc; +use crate::constants::Event; use crate::dc_array::*; use crate::dc_context::dc_context_t; use crate::dc_log::*; @@ -287,7 +288,7 @@ unsafe fn setup_handle_if_needed(mut imap: *mut dc_imap_t) -> libc::c_int { if 0 != dc_imap_is_error(imap, r) { dc_log_event_seq( (*imap).context, - 401i32, + Event::ERROR_NETWORK, &mut (*imap).log_connect_errors as *mut libc::c_int, b"Could not connect to IMAP-server %s:%i. (Error #%i)\x00" as *const u8 as *const libc::c_char, @@ -299,7 +300,7 @@ unsafe fn setup_handle_if_needed(mut imap: *mut dc_imap_t) -> libc::c_int { } else if 0 != (*imap).server_flags & 0x100i32 { r = mailimap_socket_starttls((*imap).etpan); if 0 != dc_imap_is_error(imap, r) { - dc_log_event_seq((*imap).context, 401i32, + dc_log_event_seq((*imap).context, Event::ERROR_NETWORK, &mut (*imap).log_connect_errors as *mut libc::c_int, b"Could not connect to IMAP-server %s:%i using STARTTLS. (Error #%i)\x00" @@ -339,7 +340,7 @@ unsafe fn setup_handle_if_needed(mut imap: *mut dc_imap_t) -> libc::c_int { if 0 != dc_imap_is_error(imap, r) { dc_log_event_seq( (*imap).context, - 401i32, + Event::ERROR_NETWORK, &mut (*imap).log_connect_errors as *mut libc::c_int, b"Could not connect to IMAP-server %s:%i using SSL. (Error #%i)\x00" as *const u8 as *const libc::c_char, @@ -405,7 +406,7 @@ unsafe fn setup_handle_if_needed(mut imap: *mut dc_imap_t) -> libc::c_int { ); dc_log_event_seq( (*imap).context, - 401i32, + Event::ERROR_NETWORK, &mut (*imap).log_connect_errors as *mut libc::c_int, b"%s\x00" as *const u8 as *const libc::c_char, msg, @@ -414,7 +415,7 @@ unsafe fn setup_handle_if_needed(mut imap: *mut dc_imap_t) -> libc::c_int { } else { dc_log_event( (*imap).context, - 102i32, + Event::IMAP_CONNECTED, 0i32, b"IMAP-login as %s ok.\x00" as *const u8 as *const libc::c_char, (*imap).imap_user, diff --git a/src/dc_imex.rs b/src/dc_imex.rs index 81365ed1d..9325c9be5 100644 --- a/src/dc_imex.rs +++ b/src/dc_imex.rs @@ -2,6 +2,7 @@ use c2rust_bitfields::BitfieldStruct; use libc; use rand::{thread_rng, Rng}; +use crate::constants::Event; use crate::dc_chat::*; use crate::dc_configure::*; use crate::dc_context::dc_context_t; @@ -707,7 +708,7 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(mut context: *mut dc_context_t, mut job ); (*context).cb.expect("non-null function pointer")( context, - 2051i32, + Event::IMEX_PROGRESS, 10i32 as uintptr_t, 0i32 as uintptr_t, ); @@ -931,7 +932,7 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(mut context: *mut dc_context_t, mut job } (*context).cb.expect("non-null function pointer")( context, - 2051i32, + Event::IMEX_PROGRESS, (if 0 != success { 1000i32 } else { 0i32 }) as uintptr_t, 0i32 as uintptr_t, ); @@ -1012,7 +1013,7 @@ unsafe fn import_backup( } (*context).cb.expect("non-null function pointer")( context, - 2051i32, + Event::IMEX_PROGRESS, permille as uintptr_t, 0i32 as uintptr_t, ); @@ -1226,7 +1227,7 @@ unsafe fn export_backup( } (*context).cb.expect("non-null function pointer")( context, - 2051i32, + Event::IMEX_PROGRESS, permille as uintptr_t, 0i32 as uintptr_t, ); @@ -1326,7 +1327,7 @@ unsafe fn export_backup( ); (*context).cb.expect("non-null function pointer")( context, - 2052i32, + Event::IMEX_FILE_WRITTEN, dest_pathNfilename as uintptr_t, 0i32 as uintptr_t, ); @@ -1582,7 +1583,7 @@ unsafe fn export_key_to_asc_file( } else { (*context).cb.expect("non-null function pointer")( context, - 2052i32, + Event::IMEX_FILE_WRITTEN, file_name as uintptr_t, 0i32 as uintptr_t, ); diff --git a/src/dc_job.rs b/src/dc_job.rs index 1c25d4518..47db307bf 100644 --- a/src/dc_job.rs +++ b/src/dc_job.rs @@ -1,6 +1,7 @@ use c2rust_bitfields::BitfieldStruct; use libc; +use crate::constants::Event; use crate::dc_chat::*; use crate::dc_configure::*; use crate::dc_context::dc_context_t; @@ -407,7 +408,7 @@ unsafe extern "C" fn dc_job_do_DC_JOB_SEND(mut context: *mut dc_context_t, mut j }; (*context).cb.expect("non-null function pointer")( context, - 2010i32, + Event::MSG_DELIVERED, chat_id as uintptr_t, (*job).foreign_id as uintptr_t, ); diff --git a/src/dc_location.rs b/src/dc_location.rs index 6b0b5c6d1..831eaa25d 100644 --- a/src/dc_location.rs +++ b/src/dc_location.rs @@ -1,6 +1,7 @@ use c2rust_bitfields::BitfieldStruct; use libc; +use crate::constants::Event; use crate::dc_array::*; use crate::dc_chat::*; use crate::dc_context::dc_context_t; @@ -105,7 +106,7 @@ pub unsafe fn dc_send_locations_to_chat( } (*context).cb.expect("non-null function pointer")( context, - 2020i32, + Event::CHAT_MODIFIED, chat_id as uintptr_t, 0i32 as uintptr_t, ); @@ -201,7 +202,7 @@ pub unsafe fn dc_set_location( if 0 != continue_streaming { (*context).cb.expect("non-null function pointer")( context, - 2035i32, + Event::LOCATION_CHANGED, 1i32 as uintptr_t, 0i32 as uintptr_t, ); @@ -299,7 +300,7 @@ pub unsafe fn dc_delete_all_locations(mut context: *mut dc_context_t) { sqlite3_step(stmt); (*context).cb.expect("non-null function pointer")( context, - 2035i32, + Event::LOCATION_CHANGED, 0i32 as uintptr_t, 0i32 as uintptr_t, ); @@ -833,7 +834,7 @@ pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOC_ENDED( dc_add_device_msg(context, chat_id, stock_str); (*context).cb.expect("non-null function pointer")( context, - 2020i32, + Event::CHAT_MODIFIED, chat_id as uintptr_t, 0i32 as uintptr_t, ); diff --git a/src/dc_log.rs b/src/dc_log.rs index a05d72cf2..e9555087f 100644 --- a/src/dc_log.rs +++ b/src/dc_log.rs @@ -1,6 +1,7 @@ use c2rust_bitfields::BitfieldStruct; use libc; +use crate::constants::Event; use crate::dc_context::dc_context_t; use crate::dc_lot::dc_lot_t; use crate::dc_tools::*; @@ -9,7 +10,7 @@ use crate::x::*; pub unsafe extern "C" fn dc_log_event( mut context: *mut dc_context_t, - mut event_code: libc::c_int, + mut event_code: Event, mut data1: libc::c_int, mut msg: *const libc::c_char, mut va: ... @@ -25,7 +26,7 @@ decide, what should be reported or done. However, these "Normal" errors are usually logged by dc_log_warning(). */ unsafe fn log_vprintf( mut context: *mut dc_context_t, - mut event: libc::c_int, + mut event: Event, mut data1: libc::c_int, mut msg_format: *const libc::c_char, mut va_0: ::std::ffi::VaList, @@ -59,7 +60,7 @@ unsafe fn log_vprintf( } pub unsafe extern "C" fn dc_log_event_seq( mut context: *mut dc_context_t, - mut event_code: libc::c_int, + mut event_code: Event, mut sequence_start: *mut libc::c_int, mut msg: *const libc::c_char, mut va_0: ... @@ -79,7 +80,7 @@ pub unsafe extern "C" fn dc_log_error( mut msg: *const libc::c_char, mut va_1: ... ) { - log_vprintf(context, 400i32, data1, msg, va_1); + log_vprintf(context, Event::ERROR, data1, msg, va_1); } pub unsafe extern "C" fn dc_log_warning( mut context: *mut dc_context_t, @@ -87,7 +88,7 @@ pub unsafe extern "C" fn dc_log_warning( mut msg: *const libc::c_char, mut va_2: ... ) { - log_vprintf(context, 300i32, data1, msg, va_2); + log_vprintf(context, Event::WARNING, data1, msg, va_2); } pub unsafe extern "C" fn dc_log_info( mut context: *mut dc_context_t, @@ -95,5 +96,5 @@ pub unsafe extern "C" fn dc_log_info( mut msg: *const libc::c_char, mut va_3: ... ) { - log_vprintf(context, 100i32, data1, msg, va_3); + log_vprintf(context, Event::INFO, data1, msg, va_3); } diff --git a/src/dc_msg.rs b/src/dc_msg.rs index b4eca8797..ddc33badb 100644 --- a/src/dc_msg.rs +++ b/src/dc_msg.rs @@ -1,6 +1,7 @@ use c2rust_bitfields::BitfieldStruct; use libc; +use crate::constants::Event; use crate::dc_chat::*; use crate::dc_contact::*; use crate::dc_context::*; @@ -610,7 +611,7 @@ pub unsafe fn dc_delete_msgs( if 0 != msg_cnt { (*context).cb.expect("non-null function pointer")( context, - 2000i32, + Event::MSGS_CHANGED, 0i32 as uintptr_t, 0i32 as uintptr_t, ); @@ -691,7 +692,7 @@ pub unsafe fn dc_markseen_msgs( if 0 != send_event { (*context).cb.expect("non-null function pointer")( context, - 2000i32, + Event::MSGS_CHANGED, 0i32 as uintptr_t, 0i32 as uintptr_t, ); @@ -1282,7 +1283,7 @@ pub unsafe fn dc_set_msg_failed( sqlite3_step(stmt); (*context).cb.expect("non-null function pointer")( context, - 2012i32, + Event::MSG_FAILED, (*msg).chat_id as uintptr_t, msg_id as uintptr_t, ); diff --git a/src/dc_oauth2.rs b/src/dc_oauth2.rs index f497d9fa1..3c5bdb04e 100644 --- a/src/dc_oauth2.rs +++ b/src/dc_oauth2.rs @@ -1,6 +1,7 @@ use c2rust_bitfields::BitfieldStruct; use libc; +use crate::constants::Event; use crate::dc_contact::*; use crate::dc_context::dc_context_t; use crate::dc_imap::dc_imap_t; @@ -264,7 +265,7 @@ pub unsafe fn dc_get_oauth2_access_token( ); json = (*context).cb.expect("non-null function pointer")( context, - 2110i32, + Event::HTTP_POST, token_url as uintptr_t, 0i32 as uintptr_t, ) as *mut libc::c_char; @@ -565,7 +566,7 @@ unsafe fn get_oauth2_addr( ); json = (*context).cb.expect("non-null function pointer")( context, - 2100i32, + Event::HTTP_GET, userinfo_url as uintptr_t, 0i32 as uintptr_t, ) as *mut libc::c_char; diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index b512a9a46..d0d4eae4b 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -1,6 +1,7 @@ use c2rust_bitfields::BitfieldStruct; use libc; +use crate::constants::Event; use crate::dc_apeerstate::*; use crate::dc_array::*; use crate::dc_chat::*; @@ -64,7 +65,7 @@ pub unsafe fn dc_receive_imf( let mut mime_in_reply_to: *mut libc::c_char = 0 as *mut libc::c_char; let mut mime_references: *mut libc::c_char = 0 as *mut libc::c_char; let mut created_db_entries: *mut carray = carray_new(16i32 as libc::c_uint); - let mut create_event_to_send: libc::c_int = 2000i32; + let mut create_event_to_send = Some(Event::MSGS_CHANGED); let mut rr_event_to_send: *mut carray = carray_new(16i32 as libc::c_uint); let mut txt_raw: *mut libc::c_char = 0 as *mut libc::c_char; dc_log_info( @@ -686,14 +687,14 @@ pub unsafe fn dc_receive_imf( chat_id, ); if chat_id == 3i32 as libc::c_uint { - create_event_to_send = 0i32 + create_event_to_send = None; } else if 0 != incoming && state == 10i32 { if 0 != from_id_blocked { - create_event_to_send = 0i32 + create_event_to_send = None; } else if 0 != chat_id_blocked { - create_event_to_send = 2000i32 + create_event_to_send = Some(Event::MSGS_CHANGED); } else { - create_event_to_send = 2005i32 + create_event_to_send = Some(Event::INCOMING_MSG); } } dc_do_heuristics_moves(context, server_folder, insert_msg_id); @@ -939,7 +940,7 @@ pub unsafe fn dc_receive_imf( } (*context).cb.expect("non-null function pointer")( context, - 2035i32, + Event::LOCATION_CHANGED, from_id as uintptr_t, 0i32 as uintptr_t, ); @@ -973,7 +974,7 @@ pub unsafe fn dc_receive_imf( free(mime_references as *mut libc::c_void); dc_array_unref(to_ids); if !created_db_entries.is_null() { - if 0 != create_event_to_send { + if let Some(create_event_to_send) = create_event_to_send { let mut i_0: size_t = 0; let mut icnt_0: size_t = carray_count(created_db_entries) as size_t; i_0 = 0i32 as size_t; @@ -999,7 +1000,7 @@ pub unsafe fn dc_receive_imf( while i_1 < icnt_1 { (*context).cb.expect("non-null function pointer")( context, - 2015i32, + Event::MSG_READ, carray_get(rr_event_to_send, i_1 as libc::c_uint) as uintptr_t, carray_get( rr_event_to_send, @@ -1384,7 +1385,7 @@ unsafe fn create_or_lookup_group( sqlite3_finalize(stmt); (*context).cb.expect("non-null function pointer")( context, - 2020i32, + Event::CHAT_MODIFIED, chat_id as uintptr_t, 0i32 as uintptr_t, ); @@ -1487,7 +1488,7 @@ unsafe fn create_or_lookup_group( if 0 != send_EVENT_CHAT_MODIFIED { (*context).cb.expect("non-null function pointer")( context, - 2020i32, + Event::CHAT_MODIFIED, chat_id as uintptr_t, 0i32 as uintptr_t, ); @@ -1625,7 +1626,7 @@ unsafe fn create_or_lookup_adhoc_group( } (*context).cb.expect("non-null function pointer")( context, - 2020i32, + Event::CHAT_MODIFIED, chat_id as uintptr_t, 0i32 as uintptr_t, ); diff --git a/src/dc_securejoin.rs b/src/dc_securejoin.rs index 12e5eb993..deb4c21fc 100644 --- a/src/dc_securejoin.rs +++ b/src/dc_securejoin.rs @@ -1,6 +1,7 @@ use c2rust_bitfields::BitfieldStruct; use libc; +use crate::constants::Event; use crate::dc_apeerstate::*; use crate::dc_array::*; use crate::dc_chat::*; @@ -221,7 +222,7 @@ pub unsafe fn dc_join_securejoin( (*context).bob_expects = 6i32; (*context).cb.expect("non-null function pointer")( context, - 2061i32, + Event::SECUREJOIN_JOINER_PROGRESS, chat_id_2_contact_id(context, contact_chat_id) as uintptr_t, 400i32 as uintptr_t, ); @@ -456,7 +457,7 @@ pub unsafe fn dc_handle_securejoin_handshake( ); (*context).cb.expect("non-null function pointer")( context, - 2060i32, + Event::SECUREJOIN_INVITER_PROGRESS, contact_id as uintptr_t, 300i32 as uintptr_t, ); @@ -544,7 +545,7 @@ pub unsafe fn dc_handle_securejoin_handshake( own_fingerprint = get_self_fingerprint(context); (*context).cb.expect("non-null function pointer")( context, - 2061i32, + Event::SECUREJOIN_JOINER_PROGRESS, contact_id as uintptr_t, 400i32 as uintptr_t, ); @@ -650,13 +651,13 @@ pub unsafe fn dc_handle_securejoin_handshake( secure_connection_established(context, contact_chat_id); (*context).cb.expect("non-null function pointer")( context, - 2030i32, + Event::CONTACTS_CHANGED, contact_id as uintptr_t, 0i32 as uintptr_t, ); (*context).cb.expect("non-null function pointer")( context, - 2060i32, + Event::SECUREJOIN_INVITER_PROGRESS, contact_id as uintptr_t, 600i32 as uintptr_t, ); @@ -699,7 +700,7 @@ pub unsafe fn dc_handle_securejoin_handshake( ); (*context).cb.expect("non-null function pointer")( context, - 2060i32, + Event::SECUREJOIN_INVITER_PROGRESS, contact_id as uintptr_t, 1000i32 as uintptr_t, ); @@ -795,7 +796,7 @@ pub unsafe fn dc_handle_securejoin_handshake( dc_scaleup_contact_origin(context, contact_id, 0x2000000i32); (*context).cb.expect("non-null function pointer")( context, - 2030i32, + Event::CONTACTS_CHANGED, 0i32 as uintptr_t, 0i32 as uintptr_t, ); @@ -865,13 +866,13 @@ pub unsafe fn dc_handle_securejoin_handshake( } else { (*context).cb.expect("non-null function pointer")( context, - 2060i32, + Event::SECUREJOIN_INVITER_PROGRESS, contact_id as uintptr_t, 800i32 as uintptr_t, ); (*context).cb.expect("non-null function pointer")( context, - 2060i32, + Event::SECUREJOIN_INVITER_PROGRESS, contact_id as uintptr_t, 1000i32 as uintptr_t, ); @@ -923,7 +924,7 @@ unsafe fn secure_connection_established( dc_add_device_msg(context, contact_chat_id, msg); (*context).cb.expect("non-null function pointer")( context, - 2020i32, + Event::CHAT_MODIFIED, contact_chat_id as uintptr_t, 0i32 as uintptr_t, ); @@ -1077,7 +1078,7 @@ pub unsafe fn dc_handle_degrade_event( free(msg as *mut libc::c_void); (*context).cb.expect("non-null function pointer")( context, - 2020i32, + Event::CHAT_MODIFIED, contact_chat_id as uintptr_t, 0i32 as uintptr_t, ); diff --git a/src/dc_smtp.rs b/src/dc_smtp.rs index d21687ebe..5ad88e412 100644 --- a/src/dc_smtp.rs +++ b/src/dc_smtp.rs @@ -1,6 +1,7 @@ use c2rust_bitfields::BitfieldStruct; use libc; +use crate::constants::Event; use crate::dc_context::dc_context_t; use crate::dc_log::*; use crate::dc_loginparam::*; @@ -81,7 +82,7 @@ pub unsafe fn dc_smtp_connect( } else if (*lp).addr.is_null() || (*lp).send_server.is_null() || (*lp).send_port == 0i32 { dc_log_event_seq( (*smtp).context, - 401i32, + Event::ERROR_NETWORK, &mut (*smtp).log_connect_errors as *mut libc::c_int, b"SMTP bad parameters.\x00" as *const u8 as *const libc::c_char, ); @@ -112,7 +113,7 @@ pub unsafe fn dc_smtp_connect( if r != MAILSMTP_NO_ERROR as libc::c_int { dc_log_event_seq( (*smtp).context, - 401i32, + Event::ERROR_NETWORK, &mut (*smtp).log_connect_errors as *mut libc::c_int, b"SMTP-Socket connection to %s:%i failed (%s)\x00" as *const u8 as *const libc::c_char, @@ -133,7 +134,7 @@ pub unsafe fn dc_smtp_connect( if r != MAILSMTP_NO_ERROR as libc::c_int { dc_log_event_seq( (*smtp).context, - 401i32, + Event::ERROR_NETWORK, &mut (*smtp).log_connect_errors as *mut libc::c_int, b"SMTP-SSL connection to %s:%i failed (%s)\x00" as *const u8 as *const libc::c_char, @@ -162,7 +163,7 @@ pub unsafe fn dc_smtp_connect( if r != MAILSMTP_NO_ERROR as libc::c_int { dc_log_event_seq( (*smtp).context, - 401i32, + Event::ERROR_NETWORK, &mut (*smtp).log_connect_errors as *mut libc::c_int, b"SMTP-helo failed (%s)\x00" as *const u8 as *const libc::c_char, mailsmtp_strerror(r), @@ -173,7 +174,7 @@ pub unsafe fn dc_smtp_connect( if r != MAILSMTP_NO_ERROR as libc::c_int { dc_log_event_seq( (*smtp).context, - 401i32, + Event::ERROR_NETWORK, &mut (*smtp).log_connect_errors as *mut libc::c_int, b"SMTP-STARTTLS failed (%s)\x00" as *const u8 as *const libc::c_char, @@ -195,7 +196,7 @@ pub unsafe fn dc_smtp_connect( if r != MAILSMTP_NO_ERROR as libc::c_int { dc_log_event_seq( (*smtp).context, - 401i32, + Event::ERROR_NETWORK, &mut (*smtp).log_connect_errors as *mut libc::c_int, b"SMTP-helo failed (%s)\x00" as *const u8 as *const libc::c_char, @@ -341,7 +342,7 @@ pub unsafe fn dc_smtp_connect( if r != MAILSMTP_NO_ERROR as libc::c_int { dc_log_event_seq( (*smtp).context, - 401i32, + Event::ERROR_NETWORK, &mut (*smtp).log_connect_errors as *mut libc::c_int, b"SMTP-login failed for user %s (%s)\x00" @@ -354,7 +355,7 @@ pub unsafe fn dc_smtp_connect( } else { dc_log_event( (*smtp).context, - 101i32, + Event::SMTP_CONNECTED, 0i32, b"SMTP-login as %s ok.\x00" as *const u8 as *const libc::c_char, @@ -492,7 +493,7 @@ pub unsafe fn dc_smtp_send_msg( } else { dc_log_event( (*smtp).context, - 103i32, + Event::SMTP_MESSAGE_SENT, 0i32, b"Message was sent to SMTP server\x00" as *const u8 as *const libc::c_char, diff --git a/src/dc_stock.rs b/src/dc_stock.rs index 2767c9649..2c638c8e4 100644 --- a/src/dc_stock.rs +++ b/src/dc_stock.rs @@ -1,6 +1,7 @@ use c2rust_bitfields::BitfieldStruct; use libc; +use crate::constants::Event; use crate::dc_contact::*; use crate::dc_context::dc_context_t; use crate::dc_lot::dc_lot_t; @@ -25,7 +26,7 @@ unsafe fn get_string( if !context.is_null() { ret = (*context).cb.expect("non-null function pointer")( context, - 2091i32, + Event::GET_STRING, id as uintptr_t, qty as uintptr_t, ) as *mut libc::c_char; diff --git a/src/lib.rs b/src/lib.rs index 6f7bbad29..d87aefad5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -78,9 +78,10 @@ mod tests { use std::os::raw::c_int; use std::ptr::NonNull; + use crate::constants::Event; use crate::dc_chat::*; use crate::dc_chatlist::*; - use crate::dc_configure::dc_configure; + use crate::dc_configure::*; use crate::dc_contact::*; use crate::dc_context::*; use crate::dc_imap::*; @@ -90,17 +91,37 @@ mod tests { }; use crate::dc_lot::*; - fn cb(ctx: *mut dc_context_t, event: c_int, data1: u64, data2: u64) -> u64 { - println!("event: {} ({}, {})", event, data1, data2); - if data2 > 10000 { - println!( - " {}", - unsafe { CStr::from_ptr(data2 as *const _) } - .to_str() - .unwrap() - ); + fn cb(_ctx: *mut dc_context_t, event: Event, data1: u64, data2: u64) -> u64 { + println!("[{:?}]", event); + + match event { + Event::HTTP_GET => { + let url = unsafe { CStr::from_ptr(data1 as *const _).to_str().unwrap() }; + + match reqwest::get(url) { + Ok(ref mut res) => { + let c_res = CString::new(res.text().unwrap()).unwrap(); + // need to use strdup to allocate the result with malloc + // so it can be `free`d later. + unsafe { libc::strdup(c_res.as_ptr()) as u64 } + } + Err(err) => { + println!("failed to download: {}: {:?}", url, err); + 0 + } + } + } + Event::INFO | Event::WARNING | Event::ERROR => { + println!( + " {}", + unsafe { CStr::from_ptr(data2 as *const _) } + .to_str() + .unwrap() + ); + 0 + } + _ => 0, } - 0 } struct Wrapper(NonNull); @@ -129,11 +150,24 @@ mod tests { dc_perform_smtp_idle(sendable_ctx.0.as_ptr()); }); - let dbfile = CString::new("../deltachat-core/build/hello.db").unwrap(); + let dbfile = CString::new("../deltachat-core/build/hello2.db").unwrap(); println!("opening dir"); dc_open(ctx, dbfile.as_ptr(), std::ptr::null()); - dc_configure(ctx); + if dc_is_configured(ctx) == 0 { + println!("configuring"); + dc_set_config( + ctx, + CString::new("addr").unwrap().as_ptr(), + CString::new("d@testrun.org").unwrap().as_ptr(), + ); + dc_set_config( + ctx, + CString::new("mail_pw").unwrap().as_ptr(), + CString::new("***").unwrap().as_ptr(), + ); + dc_configure(ctx); + } std::thread::sleep_ms(4000); diff --git a/src/types.rs b/src/types.rs index e20e5729e..68635bc46 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,6 +1,7 @@ use c2rust_bitfields::BitfieldStruct; use libc; +use crate::constants::Event; use crate::dc_context::dc_context_t; use crate::dc_imap::dc_imap_t; use crate::dc_sqlite3::dc_sqlite3_t; @@ -1352,9 +1353,8 @@ pub unsafe fn carray_get(mut array: *mut carray, mut indx: libc::c_uint) -> *mut * @param data2 depends on the event parameter * @return return 0 unless stated otherwise in the event parameter documentation */ -pub type dc_callback_t = Option< - unsafe fn(_: *mut dc_context_t, _: libc::c_int, _: uintptr_t, _: uintptr_t) -> uintptr_t, ->; +pub type dc_callback_t = + Option uintptr_t>; #[derive(Copy, Clone)] #[repr(C)]