Skip to content

Commit

Permalink
Portability issues
Browse files Browse the repository at this point in the history
  • Loading branch information
monich committed Feb 26, 2014
1 parent b3b57c5 commit b8604a2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions mms-lib/include/mms_lib_types.h
Expand Up @@ -38,6 +38,11 @@
# define O_BINARY (0)
#endif

#ifdef __linux__
# define HAVE_MAGIC
# define HAVE_REALPATH
#endif

/* Static configuration, chosen at startup and never changing since then */
typedef struct mms_config {
const char* root_dir; /* Root directory for storing MMS files */
Expand Down
12 changes: 11 additions & 1 deletion mms-lib/src/mms_attachment.c
Expand Up @@ -16,7 +16,9 @@
#include "mms_file_util.h"
#include "mms_codec.h"

#include <magic.h>
#ifdef HAVE_MAGIC
# include <magic.h>
#endif

/* Logging */
#define MMS_LOG_MODULE_NAME mms_attachment_log
Expand Down Expand Up @@ -85,6 +87,7 @@ mms_attachment_get_path(
const char* file,
GError** error)
{
#ifdef HAVE_REALPATH
char* path = g_malloc(PATH_MAX);
if (realpath(file, path)) {
if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
Expand All @@ -98,6 +101,9 @@ mms_attachment_get_path(
MMS_ERROR(error, MMS_LIB_ERROR_IO, "%s: %s\n", file, strerror(errno));
}
return NULL;
#else
return g_strdup(file);
#endif
}

gboolean
Expand Down Expand Up @@ -226,6 +232,7 @@ mms_attachment_new(
const char* ct[4];
int n;

#ifdef HAVE_MAGIC
magic_t magic = magic_open(MAGIC_MIME_TYPE);
if (magic) {
if (magic_load(magic, NULL) == 0) {
Expand All @@ -239,6 +246,7 @@ mms_attachment_new(
mms_file_is_smil(path)) {
content_type = SMIL_CONTENT_TYPE;
}
#endif

if (!content_type) {
MMS_WARN("No mime type for %s", path);
Expand All @@ -261,7 +269,9 @@ mms_attachment_new(
ct[n++] = NULL;
at->content_type = mms_unparse_http_content_type((char**)ct);

#ifdef HAVE_MAGIC
if (magic) magic_close(magic);
#endif
}

at->content_location = g_path_get_basename(path);
Expand Down
6 changes: 3 additions & 3 deletions mms-lib/src/mms_codec.c
Expand Up @@ -1771,7 +1771,7 @@ static gboolean encode_utf8_string(struct file_buffer *fb,
if (ptr == NULL)
return FALSE;

*ptr++ = 106 /* UTF-8 */ | 0x80;
*ptr++ = (guint8) (106 /* UTF-8 */ | 0x80);
if ((*text)[0] & 0x80) *ptr++ = QUOTE;
strcpy(ptr, *text);

Expand Down Expand Up @@ -2132,8 +2132,8 @@ static gboolean mms_encode_send_req_part_header(struct mms_attachment *part,

memcpy(ptr, &cd_val, cd_len);
ptr += cd_len;
*ptr++ = 0x82; /* Inline = <Octet 130> */
*ptr++ = WSP_PARAMETER_TYPE_FILENAME_DEFUNCT | 0x80;
*ptr++ = (guint8) 0x82; /* Inline = <Octet 130> */
*ptr++ = (guint8) (WSP_PARAMETER_TYPE_FILENAME_DEFUNCT | 0x80);
strcpy(ptr, part->content_location);
ptr[cloc_len] = 0;
}
Expand Down

0 comments on commit b8604a2

Please sign in to comment.