mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-06 03:50:08 +02:00
Merge pull request #396 from deltachat/cleanup4
remove untidy and incomplete mediainfo functions
This commit is contained in:
commit
6ee43a7ccb
8 changed files with 4 additions and 148 deletions
|
@ -470,8 +470,6 @@ void stress_functions(dc_context_t* context)
|
|||
assert( DC_PARAM_HEIGHT == 'h' );
|
||||
assert( DC_PARAM_DURATION == 'd' );
|
||||
assert( DC_PARAM_MIMETYPE == 'm' );
|
||||
assert( DC_PARAM_AUTHORNAME == 'N' );
|
||||
assert( DC_PARAM_TRACKNAME == 'n' );
|
||||
assert( DC_PARAM_FORWARDED == 'a' );
|
||||
assert( DC_PARAM_UNPROMOTED == 'U' );
|
||||
|
||||
|
|
|
@ -44,8 +44,7 @@ dc_lot_t* dc_lot_new()
|
|||
/**
|
||||
* Frees an object containing a set of parameters.
|
||||
* If the set object contains strings, the strings are also freed with this function.
|
||||
* Set objects are created eg. by dc_chatlist_get_summary(), dc_msg_get_summary or by
|
||||
* dc_msg_get_mediainfo().
|
||||
* Set objects are created eg. by dc_chatlist_get_summary() or dc_msg_get_summary().
|
||||
*
|
||||
* @memberof dc_lot_t
|
||||
* @param set The object to free.
|
||||
|
|
|
@ -376,16 +376,7 @@ static struct mailmime* build_body_file(const dc_msg_t* msg, const char* base_na
|
|||
suffix? suffix : "dat");
|
||||
}
|
||||
else if (msg->type==DC_MSG_AUDIO) {
|
||||
char* author = dc_param_get(msg->param, DC_PARAM_AUTHORNAME, NULL);
|
||||
char* title = dc_param_get(msg->param, DC_PARAM_TRACKNAME, NULL);
|
||||
if (author && author[0] && title && title[0] && suffix) {
|
||||
filename_to_send = dc_mprintf("%s - %s.%s", author, title, suffix); /* the separator ` - ` is used on the receiver's side to construct the information; we avoid using ID3-scanners for security purposes */
|
||||
}
|
||||
else {
|
||||
filename_to_send = dc_get_filename(pathNfilename);
|
||||
}
|
||||
free(author);
|
||||
free(title);
|
||||
filename_to_send = dc_get_filename(pathNfilename);
|
||||
}
|
||||
else if (msg->type==DC_MSG_IMAGE || msg->type==DC_MSG_GIF) {
|
||||
if (base_name==NULL) {
|
||||
|
|
|
@ -989,16 +989,6 @@ static void do_add_single_file_part(dc_mimeparser_t* parser, int msg_type, int m
|
|||
}
|
||||
}
|
||||
|
||||
/* split author/title from the original filename (if we do it from the real filename, we'll also get numbers appended by dc_get_fine_pathNfilename()) */
|
||||
if (msg_type==DC_MSG_AUDIO) {
|
||||
char* author = NULL, *title = NULL;
|
||||
dc_msg_get_authorNtitle_from_filename(desired_filename, &author, &title);
|
||||
dc_param_set(part->param, DC_PARAM_AUTHORNAME, author);
|
||||
dc_param_set(part->param, DC_PARAM_TRACKNAME, title);
|
||||
free(author);
|
||||
free(title);
|
||||
}
|
||||
|
||||
do_add_single_part(parser, part);
|
||||
part = NULL;
|
||||
|
||||
|
@ -1584,8 +1574,6 @@ void dc_mimeparser_parse(dc_mimeparser_t* mimeparser, const char* body_not_termi
|
|||
if (part->type==DC_MSG_AUDIO) {
|
||||
if (dc_mimeparser_lookup_optional_field(mimeparser, "Chat-Voice-Message")) {
|
||||
part->type = DC_MSG_VOICE;
|
||||
dc_param_set(part->param, DC_PARAM_AUTHORNAME, NULL); /* remove unneeded information */
|
||||
dc_param_set(part->param, DC_PARAM_TRACKNAME, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
117
src/dc_msg.c
117
src/dc_msg.c
|
@ -440,65 +440,6 @@ cleanup:
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get real author and title.
|
||||
*
|
||||
* The information is returned by a dc_lot_t object with the following fields:
|
||||
*
|
||||
* - dc_lot_t::text1: Author of the media. For voice messages, this is the sender.
|
||||
* For music messages, the information are read from the filename. NULL if unknown.
|
||||
* - dc_lot_t::text2: Title of the media. For voice messages, this is the date.
|
||||
* For music messages, the information are read from the filename. NULL if unknown.
|
||||
*
|
||||
* Currently, we do not read ID3 and such at this stage, the needed libraries are too complicated and oversized.
|
||||
* However, this is no big problem, as the sender usually sets the filename in a way we expect it.
|
||||
*
|
||||
* @memberof dc_msg_t
|
||||
* @param msg The message object.
|
||||
* @return Media information as an dc_lot_t object. Must be freed using dc_lot_unref(). NULL is never returned.
|
||||
*/
|
||||
dc_lot_t* dc_msg_get_mediainfo(const dc_msg_t* msg)
|
||||
{
|
||||
dc_lot_t* ret = dc_lot_new();
|
||||
char* pathNfilename = NULL;
|
||||
dc_contact_t* contact = NULL;
|
||||
|
||||
if (msg==NULL || msg->magic!=DC_MSG_MAGIC || msg->context==NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (msg->type==DC_MSG_VOICE)
|
||||
{
|
||||
if ((contact = dc_get_contact(msg->context, msg->from_id))==NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
ret->text1 = dc_strdup((contact->name&&contact->name[0])? contact->name : contact->addr);
|
||||
ret->text2 = dc_stock_str(msg->context, DC_STR_VOICEMESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret->text1 = dc_param_get(msg->param, DC_PARAM_AUTHORNAME, NULL);
|
||||
ret->text2 = dc_param_get(msg->param, DC_PARAM_TRACKNAME, NULL);
|
||||
if (ret->text1 && ret->text1[0] && ret->text2 && ret->text2[0]) {
|
||||
goto cleanup;
|
||||
}
|
||||
free(ret->text1); ret->text1 = NULL;
|
||||
free(ret->text2); ret->text2 = NULL;
|
||||
|
||||
pathNfilename = dc_param_get(msg->param, DC_PARAM_FILE, NULL);
|
||||
if (pathNfilename==NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
dc_msg_get_authorNtitle_from_filename(pathNfilename, &ret->text1, &ret->text2);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
free(pathNfilename);
|
||||
dc_contact_unref(contact);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get width of image or video. The width is returned in pixels.
|
||||
* If the width is unknown or if the associated file is no image or video file,
|
||||
|
@ -966,38 +907,6 @@ cleanup:
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extracts AUTHOR and TITLE from a path.
|
||||
* Ideally, the path is something like `/path/AUTHOR - TITLE.mp3`.
|
||||
* If the separator ` - ` is not preset, the whole name (without suffix) is used as TITLE and AUTHOR is NULL.
|
||||
*
|
||||
* @private @memberof dc_msg_t
|
||||
* @param pathNfilename Path to extract AUTHOR and TITLE from.
|
||||
* @param[out] ret_author If present, AUTHOR is copied here, must be free()'d then.
|
||||
* NULL if you're not interested in this value.
|
||||
* @param[out] ret_title If present, TITLE is copied here, must be free()'d then.
|
||||
* NULL if you're not interested in this value.
|
||||
* @return None.
|
||||
*/
|
||||
void dc_msg_get_authorNtitle_from_filename(const char* pathNfilename, char** ret_author, char** ret_title)
|
||||
{
|
||||
char* author = NULL;
|
||||
char* title = NULL;
|
||||
char* p = NULL;
|
||||
|
||||
dc_split_filename(pathNfilename, &title, NULL);
|
||||
p = strstr(title, " - ");
|
||||
if (p) {
|
||||
*p = 0;
|
||||
author = title;
|
||||
title = dc_strdup(&p[3]);
|
||||
}
|
||||
|
||||
if (ret_author) { *ret_author = author; } else { free(author); }
|
||||
if (ret_title) { *ret_title = title; } else { free(title); }
|
||||
}
|
||||
|
||||
|
||||
char* dc_msg_get_summarytext_by_raw(int type, const char* text, dc_param_t* param, int approx_characters, dc_context_t* context)
|
||||
{
|
||||
/* get a summary text, result must be free()'d, never returns NULL. */
|
||||
|
@ -1024,10 +933,7 @@ char* dc_msg_get_summarytext_by_raw(int type, const char* text, dc_param_t* para
|
|||
break;
|
||||
|
||||
case DC_MSG_AUDIO:
|
||||
if ((value=dc_param_get(param, DC_PARAM_TRACKNAME, NULL))==NULL) { /* although we send files with "author - title" in the filename, existing files may follow other conventions, so this lookup is neccessary */
|
||||
pathNfilename = dc_param_get(param, DC_PARAM_FILE, "ErrFilename");
|
||||
dc_msg_get_authorNtitle_from_filename(pathNfilename, NULL, &value);
|
||||
}
|
||||
value = dc_param_get(param, DC_PARAM_FILE, "ErrFilename");
|
||||
label = dc_stock_str(context, DC_STR_AUDIO);
|
||||
ret = dc_mprintf("%s: %s", label, value);
|
||||
break;
|
||||
|
@ -1199,27 +1105,6 @@ void dc_msg_set_duration(dc_msg_t* msg, int duration)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the media information associated with message object.
|
||||
* Typically this is the author and the trackname of an audio or video associated using dc_msg_set_file().
|
||||
* This does not alter any information in the database; this may be done by dc_send_msg() later.
|
||||
*
|
||||
* @memberof dc_msg_t
|
||||
* @param msg The message object.
|
||||
* @param author Author or artist. NULL if you don't know or don't care.
|
||||
* @param trackname Trackname or title. NULL if you don't know or don't care.
|
||||
* @return None.
|
||||
*/
|
||||
void dc_msg_set_mediainfo(dc_msg_t* msg, const char* author, const char* trackname)
|
||||
{
|
||||
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
|
||||
return;
|
||||
}
|
||||
dc_param_set(msg->param, DC_PARAM_AUTHORNAME, author);
|
||||
dc_param_set(msg->param, DC_PARAM_TRACKNAME, trackname);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Late filing information to a message.
|
||||
* In contrast to the dc_msg_set_*() functions, this function really stores the information in the database.
|
||||
|
|
|
@ -94,7 +94,6 @@ int dc_msg_is_increation (const dc_msg_t*);
|
|||
char* dc_msg_get_summarytext_by_raw (int type, const char* text, dc_param_t*, int approx_bytes, dc_context_t*); /* the returned value must be free()'d */
|
||||
void dc_msg_save_param_to_disk (dc_msg_t*);
|
||||
void dc_msg_guess_msgtype_from_suffix (const char* pathNfilename, int* ret_msgtype, char** ret_mime);
|
||||
void dc_msg_get_authorNtitle_from_filename (const char* pathNfilename, char** ret_author, char** ret_title);
|
||||
|
||||
#define DC_MSG_NEEDS_ATTACHMENT(a) ((a)==DC_MSG_IMAGE || (a)==DC_MSG_GIF || (a)==DC_MSG_AUDIO || (a)==DC_MSG_VOICE || (a)==DC_MSG_VIDEO || (a)==DC_MSG_FILE)
|
||||
|
||||
|
|
|
@ -48,8 +48,6 @@ typedef struct dc_param_t
|
|||
#define DC_PARAM_HEIGHT 'h' /* for msgs */
|
||||
#define DC_PARAM_DURATION 'd' /* for msgs */
|
||||
#define DC_PARAM_MIMETYPE 'm' /* for msgs */
|
||||
#define DC_PARAM_AUTHORNAME 'N' /* for msgs: name of author or artist */
|
||||
#define DC_PARAM_TRACKNAME 'n' /* for msgs: name of author or artist */
|
||||
#define DC_PARAM_GUARANTEE_E2EE 'c' /* for msgs: incoming: message is encryoted, outgoing: guarantee E2EE or the message is not send */
|
||||
#define DC_PARAM_ERRONEOUS_E2EE 'e' /* for msgs: decrypted with validation errors or without mutual set, if neither 'c' nor 'e' are preset, the messages is only transport encrypted */
|
||||
#define DC_PARAM_FORCE_PLAINTEXT 'u' /* for msgs: force unencrypted message, either DC_FP_ADD_AUTOCRYPT_HEADER (1), DC_FP_NO_AUTOCRYPT_HEADER (2) or 0 */
|
||||
|
|
|
@ -500,7 +500,6 @@ char* dc_msg_get_file (const dc_msg_t*);
|
|||
char* dc_msg_get_filename (const dc_msg_t*);
|
||||
char* dc_msg_get_filemime (const dc_msg_t*);
|
||||
uint64_t dc_msg_get_filebytes (const dc_msg_t*);
|
||||
dc_lot_t* dc_msg_get_mediainfo (const dc_msg_t*);
|
||||
int dc_msg_get_width (const dc_msg_t*);
|
||||
int dc_msg_get_height (const dc_msg_t*);
|
||||
int dc_msg_get_duration (const dc_msg_t*);
|
||||
|
@ -518,7 +517,6 @@ void dc_msg_set_text (dc_msg_t*, const char* text);
|
|||
void dc_msg_set_file (dc_msg_t*, const char* file, const char* filemime);
|
||||
void dc_msg_set_dimension (dc_msg_t*, int width, int height);
|
||||
void dc_msg_set_duration (dc_msg_t*, int duration);
|
||||
void dc_msg_set_mediainfo (dc_msg_t*, const char* author, const char* trackname);
|
||||
void dc_msg_latefiling_mediasize (dc_msg_t*, int width, int height, int duration);
|
||||
|
||||
|
||||
|
@ -559,7 +557,7 @@ int dc_contact_is_verified (dc_contact_t*);
|
|||
* @class dc_lot_t
|
||||
*
|
||||
* An object containing a set of values. The meaning of the values is defined by the function returning the set object.
|
||||
* Set objects are created eg. by dc_chatlist_get_summary(), dc_msg_get_summary() or by dc_msg_get_mediainfo().
|
||||
* Set objects are created eg. by dc_chatlist_get_summary() or dc_msg_get_summary().
|
||||
*
|
||||
* NB: _Lot_ is used in the meaning _heap_ here.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue