static void xmms_normalize_destroy (xmms_xform_t *xform) { xmms_normalize_data_t *data; xmms_config_property_t *cfgv; int i; g_return_if_fail (xform); data = xmms_xform_private_data_get (xform); g_return_if_fail (data); compress_free (data->compress); for (i = 0; i < G_N_ELEMENTS (config_params); i++) { cfgv = xmms_xform_config_lookup (xform, config_params[i].key); xmms_config_property_callback_remove (cfgv, xmms_normalize_config_changed, data); } g_free (data); }
/** * @brief Compress data using the bzip engine. * @param input a managed string containing the data to be compressed. * @return NULL on failure, or a pointer to the head of the compressed data on success. */ compress_t * compress_bzip(stringer_t *input) { uint64_t out; compress_head_t *head; compress_t *result = NULL; // This represents the maximum amount of space the compressed block could end up using. out = ((double)st_length_get(input) * 1.10L) + 1024; // Allocate a buffer to hold the result and the working memory buffer. if (!(head = (compress_head_t *)(result = compress_alloc(out)))) { log_info("Unable to allocate the compression buffers."); return NULL; } // Setup the header. head->engine = COMPRESS_ENGINE_BZIP; head->length.original = st_length_get(input); head->hash.original = hash_adler32(st_data_get(input), st_length_get(input)); // Perform the compression. if (BZ2_bzBuffToBuffCompress_d(compress_body_data(result), (unsigned int *)&out, st_data_get(input), st_length_get(input), 9, 0, 0) != BZ_OK) { log_info("Unable to compress the buffer."); compress_free(result); return NULL; } head->length.compressed = out; head->hash.compressed = hash_adler32(compress_body_data(result), out); #ifdef MAGMA_PEDANTIC stringer_t *verify; if (!(verify = decompress_bzip(result))) { log_info("Verification failed!"); compress_free(result); return NULL; } st_free(verify); #endif return result; }
/** * @brief Store a mail message, with its meta-information in the database, and the contents persisted to disk. * @note The stored message is always compressed, but only encrypted if the user's public key is suppplied. * @param usernum the numerical id of the user to which the message belongs. * @param pubkey if not NULL, a public key that will be used to encrypt the message for the intended user. * @param foldernum the folder # that will contain the message. * @param status a pointer to the status flags value for the message, which will be updated if the message is to be encrypted. * @param signum the spam signature for the message. * @param sigkey the spam key for the message. * @param message a managed string containing the raw body of the message. * @return 0 on failure, or the newly inserted id of the message in the database on success. * */ uint64_t mail_store_message(uint64_t usernum, stringer_t *pubkey, uint64_t foldernum, uint32_t *status, uint64_t signum, uint64_t sigkey, stringer_t *message) { chr_t *path; cryptex_t *encrypted = NULL; compress_t *reduced; uint64_t messagenum; int64_t transaction, ret; size_t write_len; uint8_t fflags = FMESSAGE_OPT_COMPRESSED; uchr_t *write_data; bool_t store_result; // Compress the message. if (!(reduced = compress_lzo(message))) { log_error("An error occurred while attempting to compress a message with %zu bytes.", st_length_get(message)); return 0; } // Next, encrypt the message if necessary. if (pubkey) { *status |= MAIL_STATUS_ENCRYPTED; if (!(encrypted = ecies_encrypt(pubkey, ECIES_PUBLIC_BINARY, reduced, compress_total_length(reduced)))) { log_pedantic("Unable to decrypt mail message."); compress_free(reduced); return 0; } compress_free(reduced); write_data = (uchr_t *)encrypted; write_len = cryptex_total_length(encrypted); fflags |= FMESSAGE_OPT_ENCRYPTED; } else { write_data = (uchr_t *)reduced; write_len = compress_total_length(reduced); } // Begin the transaction. if ((transaction = tran_start()) < 0) { log_error("Could not start a transaction. {start = %li}", transaction); if (encrypted) { cryptex_free(encrypted); } else { compress_free(reduced); } return 0; } // Insert a record into the database. if ((messagenum = mail_db_insert_message(usernum, foldernum, *status, st_length_int(message), signum, sigkey, transaction)) == 0) { log_pedantic("Could not create a record in the database. mail_db_insert_message = 0"); tran_rollback(transaction); if (encrypted) { cryptex_free(encrypted); } else { compress_free(reduced); } return 0; } // Now attempt to save everything to disk. store_result = mail_store_message_data(messagenum, fflags, write_data, write_len, &path); if (encrypted) { cryptex_free(encrypted); } else { compress_free(reduced); } // If storage failed, fail out. if (!store_result || !path) { log_pedantic("Failed to store user's message to disk."); tran_rollback(transaction); if (path) { unlink(path); ns_free(path); } return 0; } // Commit the transaction. if ((ret = tran_commit(transaction))) { log_error("Could not commit the transaction. { commit = %li }", ret); unlink(path); ns_free(path); return 0; } ns_free(path); return messagenum; }