2 * Copyright (C) 2006-2007 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
25 #include "swfdec_loader_internal.h"
26 #include "swfdec_buffer.h"
27 #include "swfdec_debug.h"
28 #include "swfdec_player_internal.h"
33 * This is a #SwfdecLoader that can load content from files. This symbol is
34 * exported so you can subclass your own loaders from it and have automatic
38 G_DEFINE_TYPE (SwfdecFileLoader
, swfdec_file_loader
, SWFDEC_TYPE_LOADER
)
41 swfdec_file_loader_load (SwfdecLoader
*loader
, SwfdecPlayer
*player
,
42 const char *url_string
, SwfdecBuffer
*buffer
, guint header_count
,
43 const char **header_names
, const char **header_values
)
45 SwfdecStream
*stream
= SWFDEC_STREAM (loader
);
47 char *real
, *unescape
, *concat
;
50 if (swfdec_url_path_is_relative (url_string
)) {
51 url
= swfdec_url_new_relative (swfdec_player_get_base_url (player
), url_string
);
53 url
= swfdec_url_new (url_string
);
56 swfdec_stream_error (stream
, "%s is an invalid URL", url_string
);
59 swfdec_loader_set_url (loader
, swfdec_url_get_url (url
));
60 if (!g_str_equal (swfdec_url_get_protocol (url
), "file")) {
61 swfdec_stream_error (stream
, "Don't know how to handle this protocol");
62 swfdec_url_free (url
);
65 if (swfdec_url_get_host (url
)) {
66 swfdec_stream_error (stream
, "filenames cannot have hostnames");
67 swfdec_url_free (url
);
71 unescape
= g_uri_unescape_string (swfdec_url_get_path (url
), NULL
);
72 /* Swfdec ignores query strings, just like Flash 9.0.124.0 and onwards.
73 * Might be a useful quirk to have though */
75 if (swfdec_url_get_query (url
)) {
76 concat
= g_strconcat ("/", unescape
, "?", swfdec_url_get_query (url
), NULL
);
78 concat
= g_strconcat ("/", unescape
, NULL
);
81 concat
= g_strconcat ("/", unescape
, NULL
);
84 real
= g_filename_from_utf8 (concat
, -1, NULL
, NULL
, &error
);
87 swfdec_stream_error (stream
, "%s", error
->message
);
89 swfdec_url_free (url
);
92 buffer
= swfdec_buffer_new_from_file (real
, &error
);
95 swfdec_stream_error (stream
, "%s", error
->message
);
98 swfdec_loader_set_size (loader
, buffer
->length
);
99 swfdec_stream_open (stream
);
100 swfdec_stream_push (stream
, buffer
);
101 swfdec_stream_close (stream
);
103 swfdec_url_free (url
);
107 swfdec_file_loader_class_init (SwfdecFileLoaderClass
*klass
)
109 SwfdecLoaderClass
*loader_class
= SWFDEC_LOADER_CLASS (klass
);
111 loader_class
->load
= swfdec_file_loader_load
;
115 swfdec_file_loader_init (SwfdecFileLoader
*loader
)