1 /* MIME handling backends multiplexing */
13 #include "main/module.h"
14 #include "mime/backend/common.h"
15 #include "mime/mime.h"
16 #include "util/file.h"
17 #include "util/memory.h"
18 #include "util/string.h"
21 /* Backends dynamic area: */
23 #include "mime/backend/default.h"
24 #include "mime/backend/mailcap.h"
25 #include "mime/backend/mimetypes.h"
27 static const struct mime_backend
*const mime_backends
[] = {
28 &default_mime_backend
,
30 &mailcap_mime_backend
,
32 #ifdef CONFIG_MIMETYPES
33 &mimetypes_mime_backend
,
40 get_content_type_backends(unsigned char *extension
)
42 const struct mime_backend
*backend
;
45 foreach_module (backend
, mime_backends
, i
) {
46 if (backend
->get_content_type
) {
47 unsigned char *content_type
;
49 content_type
= backend
->get_content_type(extension
);
50 if (content_type
) return content_type
;
58 get_mime_handler_backends(unsigned char *ctype
, int have_x
)
60 const struct mime_backend
*backend
;
63 foreach_module (backend
, mime_backends
, i
) {
64 if (backend
->get_mime_handler
) {
65 struct mime_handler
*handler
;
67 handler
= backend
->get_mime_handler(ctype
, have_x
);
68 if (handler
) return handler
;
76 get_next_path_filename(unsigned char **path_ptr
, unsigned char separator
)
78 unsigned char *path
= *path_ptr
;
79 unsigned char *filename
= path
;
82 /* Extract file from path */
83 while (*path
&& *path
!= separator
)
86 filenamelen
= path
- filename
;
88 /* If not at end of string skip separator */
94 if (filenamelen
> 0) {
95 unsigned char *tmp
= memacpy(filename
, filenamelen
);
97 if (!tmp
) return NULL
;
98 filename
= expand_tilde(tmp
);
107 struct mime_handler
*
108 init_mime_handler(unsigned char *program
, unsigned char *description
,
109 unsigned char *backend_name
, int ask
, int block
)
111 int programlen
= strlen(program
);
112 struct mime_handler
*handler
;
114 handler
= mem_calloc(1, sizeof(*handler
) + programlen
);
115 if (!handler
) return NULL
;
117 memcpy(handler
->program
, program
, programlen
);
119 handler
->description
= empty_string_or_(description
);
120 handler
->backend_name
= backend_name
;
121 handler
->block
= block
;