text
stringlengths
0
357
}
ret = dc_get_filename(pathNfilename);
cleanup:
free(pathNfilename);
return ret? ret : dc_strdup(NULL);
}
/**
* Get mime type of the file. If there is not file, an empty string is returned.
* If there is no associated mime type with the file, the function guesses on; if
* in doubt, `application/octet-stream` is returned. NULL is never returned.
*
* @memberof dc_msg_t
* @param msg The message object.
* @return String containing the mime type. Must be free()'d after usage. NULL is never returned.
*/
char* dc_msg_get_filemime(const dc_msg_t* msg)
{
char* ret = NULL;
char* file = NULL;
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
goto cleanup;
}
ret = dc_param_get(msg->param, DC_PARAM_MIMETYPE, NULL);
if (ret==NULL) {
file = dc_param_get(msg->param, DC_PARAM_FILE, NULL);
if (file==NULL) {
goto cleanup;
}
dc_msg_guess_msgtype_from_suffix(file, NULL, &ret);
if (ret==NULL) {
ret = dc_strdup("application/octet-stream");
}
}
cleanup:
free(file);
return ret? ret : dc_strdup(NULL);
}
/**
* Get the size of the file. Returns the size of the file associated with a
* message, if applicable.
*
* Typically, this is used to show the size of document messages, eg. a PDF.
*
* @memberof dc_msg_t
* @param msg The message object.
* @return File size in bytes, 0 if not applicable or on errors.
*/
uint64_t dc_msg_get_filebytes(const dc_msg_t* msg)
{
uint64_t ret = 0;
char* file = NULL;
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
goto cleanup;
}
file = dc_param_get(msg->param, DC_PARAM_FILE, NULL);
if (file==NULL) {
goto cleanup;
}
ret = dc_get_filebytes(msg->context, file);
cleanup:
free(file);
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,
* 0 is returned.
*
* Often the aspect ratio is the more interesting thing. You can calculate
* this using dc_msg_get_width() / dc_msg_get_height().
*
* See also dc_msg_get_duration().
*
* @memberof dc_msg_t
* @param msg The message object.
* @return Width in pixels, if applicable. 0 otherwise or if unknown.
*/
int dc_msg_get_width(const dc_msg_t* msg)
{
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
return 0;
}
return dc_param_get_int(msg->param, DC_PARAM_WIDTH, 0);
}