Skip to content

Commit

Permalink
[mms-lib] Use g_build_filename to build filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
monich committed Jul 29, 2020
1 parent 92cdbc2 commit 754e0ed
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 35 deletions.
13 changes: 6 additions & 7 deletions mms-lib/src/mms_attachment_image.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2020 Jolla Ltd.
* Copyright (C) 2013-2020 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -59,13 +59,12 @@ mms_attachment_image_prepare_filename(
image->attachment.file_name = image->attachment.original_file;
} else {
char* dir = g_path_get_dirname(image->attachment.original_file);
char* subdir = g_strconcat(dir, "/" MMS_RESIZE_DIR, NULL);
char* fname = g_path_get_basename(image->attachment.original_file);
char* subdir = g_build_filename(dir, MMS_RESIZE_DIR, NULL);
g_mkdir_with_parents(subdir, MMS_DIR_PERM);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
image->resized = g_strconcat(subdir, "/",
g_basename(image->attachment.original_file), NULL);
G_GNUC_END_IGNORE_DEPRECATIONS;
image->resized = g_build_filename(subdir, fname, NULL);
g_free(dir);
g_free(fname);
g_free(subdir);
}
return image->resized;
Expand Down
6 changes: 3 additions & 3 deletions mms-lib/src/mms_dispatcher.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2018 Jolla Ltd.
* Copyright (C) 2013-2018 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2020 Jolla Ltd.
* Copyright (C) 2013-2020 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -800,7 +800,7 @@ mms_dispatcher_finalize(
{
MMSTask* task;
const char* root_dir = disp->settings->config->root_dir;
char* msg_dir = g_strconcat(root_dir, "/" MMS_MESSAGE_DIR "/", NULL);
char* msg_dir = g_build_filename(root_dir, MMS_MESSAGE_DIR, NULL);
GVERBOSE_("");
mms_handler_remove_callback(disp->handler, disp->handler_done_id);
mms_connman_remove_callback(disp->cm, disp->connman_done_id);
Expand Down
8 changes: 4 additions & 4 deletions mms-lib/src/mms_file_util.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2020 Jolla Ltd.
* Copyright (C) 2013-2020 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -108,7 +108,7 @@ mms_create_file(
int fd = -1;
int err = g_mkdir_with_parents(dir, MMS_DIR_PERM);
if (!err || errno == EEXIST) {
char* fname = g_strconcat(dir, "/", file, NULL);
char* fname = g_build_filename(dir, file, NULL);
fd = open(fname, O_CREAT|O_RDWR|O_TRUNC|O_BINARY, MMS_FILE_PERM);
if (fd < 0) {
MMS_ERROR(error, MMS_LIB_ERROR_IO,
Expand Down Expand Up @@ -140,7 +140,7 @@ mms_write_file(
int err = g_mkdir_with_parents(dir, MMS_DIR_PERM);
if (!err || errno == EEXIST) {
GError* error = NULL;
char* fname = g_strconcat(dir, "/", file, NULL);
char* fname = g_build_filename(dir, file, NULL);
unlink(fname);
if (g_file_set_contents(fname, data, size, &error)) {
GVERBOSE("Created %s", fname);
Expand Down
16 changes: 8 additions & 8 deletions mms-lib/src/mms_file_util.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2015 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2020 Jolla Ltd.
* Copyright (C) 2013-2020 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand All @@ -13,8 +13,8 @@
*
*/

#ifndef JOLLA_MMS_FILE_UTIL_H
#define JOLLA_MMS_FILE_UTIL_H
#ifndef SAILFISH_MMS_FILE_UTIL_H
#define SAILFISH_MMS_FILE_UTIL_H

#include "mms_lib_types.h"

Expand Down Expand Up @@ -86,14 +86,14 @@ mms_file_decode(
GError** error);

#define mms_message_dir(config,id) \
(g_strconcat((config)->root_dir, "/" MMS_MESSAGE_DIR "/" , id, NULL))
(g_build_filename((config)->root_dir, MMS_MESSAGE_DIR, id, NULL))
#define mms_task_dir(task) \
mms_message_dir(task_config(task),(task)->id)
#define mms_task_file(task,file) \
(g_strconcat(task_config(task)->root_dir, "/" MMS_MESSAGE_DIR "/" , \
(task)->id, "/", file, NULL))
(g_build_filename(task_config(task)->root_dir, MMS_MESSAGE_DIR, \
(task)->id, file, NULL))

#endif /* JOLLA_MMS_FILE_UTIL_H */
#endif /* SAILFISH_MMS_FILE_UTIL_H */

/*
* Local Variables:
Expand Down
4 changes: 2 additions & 2 deletions mms-lib/src/mms_task.c
Expand Up @@ -359,10 +359,10 @@ mms_task_make_id(
{
if (!task->id || !task->id[0]) {
const char* root_dir = task_config(task)->root_dir;
char* msgdir = g_strconcat(root_dir, "/", MMS_MESSAGE_DIR, NULL);
char* msgdir = g_build_filename(root_dir, MMS_MESSAGE_DIR, NULL);
int err = g_mkdir_with_parents(msgdir, MMS_DIR_PERM);
if (!err || errno == EEXIST) {
char* tmpl = g_strconcat(msgdir, "/XXXXXX" , NULL);
char* tmpl = g_build_filename(msgdir, "XXXXXX", NULL);
char* taskdir = g_mkdtemp_full(tmpl, MMS_DIR_PERM);
if (taskdir) {
g_free(task->id);
Expand Down
8 changes: 4 additions & 4 deletions mms-lib/src/mms_task_decode.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2020 Jolla Ltd.
* Copyright (C) 2013-2020 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -122,7 +122,7 @@ mms_task_decode_part(
orig_file = mms_task_decode_add_file_name(part_files, default_name);
g_free(default_name);

part->orig = g_strconcat(dir, "/", orig_file, NULL);
part->orig = g_build_filename(dir, orig_file, NULL);
if (rename(part->file, part->orig) == 0) {
GError* error = NULL;
if (!mms_file_decode(part->orig, part->file, enc, &error)) {
Expand Down Expand Up @@ -202,7 +202,7 @@ mms_task_decode_retrieve_conf(
break;
}

msg->parts_dir = g_strconcat(dir, "/" , MMS_PARTS_DIR, NULL);
msg->parts_dir = g_build_filename(dir, MMS_PARTS_DIR, NULL);
for (i=0, entry = pdu->attachments; entry; entry = entry->next, i++) {
struct mms_attachment* attach = entry->data;
const char* name = attach->content_location ?
Expand Down
8 changes: 4 additions & 4 deletions mms-lib/src/mms_task_encode.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2020 Jolla Ltd.
* Copyright (C) 2013-2020 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -426,13 +426,13 @@ mms_task_encode_generate_path(
}

/* Most likely the very first check would succeed */
path = g_strconcat(dir, "/", file, NULL);
path = g_build_filename(dir, file, NULL);
if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
for (i=0; i<100; i++) {
char* newfile = g_strconcat("_", file, NULL);
g_free(tmpfile);
g_free(path);
path = g_strconcat(dir, "/", newfile, NULL);
path = g_build_filename(dir, newfile, NULL);
file = tmpfile = newfile;
if (!g_file_test(path, G_FILE_TEST_IS_REGULAR)) break;
}
Expand Down
6 changes: 3 additions & 3 deletions mms-lib/src/mms_task_notification.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2017 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2020 Jolla Ltd.
* Copyright (C) 2013-2020 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -93,7 +93,7 @@ mms_task_notification_done(
GDEBUG(" Database id: %s", id);
if (task->id) {
char* olddir = mms_task_dir(task);
char* file = g_strconcat(olddir, "/"
char* file = g_build_filename(olddir,
MMS_NOTIFICATION_IND_FILE, NULL);
/* Replace fake id with the real one */
g_free(task->id);
Expand Down

0 comments on commit 754e0ed

Please sign in to comment.