[Swfdec] 10 commits - doc/swfdec-docs.sgml doc/swfdec-sections.txt libswfdec-gtk/swfdec_gtk_loader.c libswfdec/Makefile.am libswfdec/swfdec_as_context.c libswfdec/swfdec_as_frame.c libswfdec/swfdec_buffer.c libswfdec/swfdec_debugger.c libswfdec/swfdec.h libswfdec/swfdec_loader.c libswfdec/swfdec_loader.h libswfdec/swfdec_loader_internal.h libswfdec/swfdec_player.c libswfdec/swfdec_url.c libswfdec/swfdec_url.h player/swfdebug.c player/swfdec_slow_loader.c player/swfplay.c

Benjamin Otte company at kemper.freedesktop.org
Tue Jul 31 04:32:13 PDT 2007


 doc/swfdec-docs.sgml               |    1 
 doc/swfdec-sections.txt            |   19 ++
 libswfdec-gtk/swfdec_gtk_loader.c  |   43 +----
 libswfdec/Makefile.am              |    4 
 libswfdec/swfdec.h                 |    3 
 libswfdec/swfdec_as_context.c      |    2 
 libswfdec/swfdec_as_frame.c        |    3 
 libswfdec/swfdec_buffer.c          |   12 -
 libswfdec/swfdec_debugger.c        |    2 
 libswfdec/swfdec_loader.c          |  160 ++++++++++----------
 libswfdec/swfdec_loader.h          |   10 -
 libswfdec/swfdec_loader_internal.h |    2 
 libswfdec/swfdec_player.c          |    8 -
 libswfdec/swfdec_url.c             |  293 +++++++++++++++++++++++++++++++++++++
 libswfdec/swfdec_url.h             |   47 +++++
 player/swfdebug.c                  |    3 
 player/swfdec_slow_loader.c        |   86 +++++-----
 player/swfplay.c                   |    2 
 18 files changed, 525 insertions(+), 175 deletions(-)

New commits:
diff-tree 67a997bc57fad8b87d13d1f7baaaa737398ac6e9 (from ca750ef4ead8812a0aeff906a2b48f54ad43cb37)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jul 31 13:32:41 2007 +0200

    make sure excess function parameters are st to undefined

diff --git a/libswfdec/swfdec_as_frame.c b/libswfdec/swfdec_as_frame.c
index fec2389..612ed70 100644
--- a/libswfdec/swfdec_as_frame.c
+++ b/libswfdec/swfdec_as_frame.c
@@ -552,7 +552,7 @@ swfdec_as_frame_preload (SwfdecAsFrame *
   SwfdecAsObject *object, *args;
   guint i, current_reg = 1;
   SwfdecScript *script;
-  SwfdecAsValue val = { 0, };
+  SwfdecAsValue val;
   const SwfdecAsValue *cur;
   SwfdecAsContext *context;
   SwfdecAsStackIterator iter;
@@ -606,6 +606,7 @@ swfdec_as_frame_preload (SwfdecAsFrame *
   }
 
   /* set and preload argument variables */
+  SWFDEC_AS_VALUE_SET_UNDEFINED (&val);
   cur = swfdec_as_stack_iterator_init_arguments (&iter, frame);
   for (i = 0; i < script->n_arguments; i++) {
     if (cur == NULL)
diff-tree ca750ef4ead8812a0aeff906a2b48f54ad43cb37 (from c7fb0f56f3782d11b9f438043fbc070dae1947d5)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jul 31 13:03:48 2007 +0200

    move SwfdecLoader to use a SwfdecURL instead of a char *

diff --git a/libswfdec-gtk/swfdec_gtk_loader.c b/libswfdec-gtk/swfdec_gtk_loader.c
index 69dc143..77ffd29 100644
--- a/libswfdec-gtk/swfdec_gtk_loader.c
+++ b/libswfdec-gtk/swfdec_gtk_loader.c
@@ -105,7 +105,8 @@ swfdec_gtk_loader_read_cb (GnomeVFSAsync
     gtk->handle = NULL;
     return;
   } else if (result != GNOME_VFS_OK) {
-    char *err = g_strdup_printf ("%s: %s", loader->url,
+    char *err = g_strdup_printf ("%s: %s", 
+	swfdec_url_get_url (swfdec_loader_get_url (loader)),
 	gnome_vfs_result_to_string (result));
     swfdec_loader_error (loader, err);
     g_free (err);
@@ -144,7 +145,8 @@ swfdec_gtk_loader_open_cb (GnomeVFSAsync
   SwfdecLoader *loader = loaderp;
 
   if (result != GNOME_VFS_OK) {
-    char *err = g_strdup_printf ("%s: %s", loader->url,
+    char *err = g_strdup_printf ("%s: %s",
+	swfdec_url_get_url (swfdec_loader_get_url (loader)),
 	gnome_vfs_result_to_string (result));
     swfdec_loader_error (loader, err);
     g_free (err);
@@ -155,20 +157,6 @@ swfdec_gtk_loader_open_cb (GnomeVFSAsync
   swfdec_gtk_loader_start_read (gtk);
 }
 
-static SwfdecLoader *
-swfdec_gtk_loader_new_from_uri (GnomeVFSURI *uri)
-{
-  SwfdecGtkLoader *gtk;
-
-  g_assert (uri);
-  gtk = g_object_new (SWFDEC_TYPE_GTK_LOADER, NULL);
-  gtk->guri = uri;
-  gnome_vfs_async_open_uri (&gtk->handle, uri, GNOME_VFS_OPEN_READ, 
-      GNOME_VFS_PRIORITY_DEFAULT, swfdec_gtk_loader_open_cb, gtk);
-  SWFDEC_LOADER (gtk)->url = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_PASSWORD);
-  return SWFDEC_LOADER (gtk);
-}
-
 static void
 swfdec_gtk_loader_dispose (GObject *object)
 {
@@ -190,18 +178,14 @@ swfdec_gtk_loader_dispose (GObject *obje
   G_OBJECT_CLASS (swfdec_gtk_loader_parent_class)->dispose (object);
 }
 
-static SwfdecLoader *
-swfdec_gtk_loader_load (SwfdecLoader *loader, const char *url, 
+static void
+swfdec_gtk_loader_load (SwfdecLoader *loader,
     SwfdecLoaderRequest request, const char *data, gsize data_len)
 {
   SwfdecGtkLoader *gtk = SWFDEC_GTK_LOADER (loader);
-  GnomeVFSURI *parent, *new;
 
-  /* FIXME: security! */
-  parent = gnome_vfs_uri_get_parent (gtk->guri);
-  new = gnome_vfs_uri_resolve_relative (parent, url);
-  gnome_vfs_uri_unref (parent);
-  return swfdec_gtk_loader_new_from_uri (new);
+  gnome_vfs_async_open (&gtk->handle, swfdec_url_get_url (swfdec_loader_get_url (loader)), 
+      GNOME_VFS_OPEN_READ, GNOME_VFS_PRIORITY_DEFAULT, swfdec_gtk_loader_open_cb, gtk);
 }
 
 static void
@@ -235,13 +219,16 @@ swfdec_gtk_loader_init (SwfdecGtkLoader 
 SwfdecLoader *
 swfdec_gtk_loader_new (const char *uri)
 {
-  GnomeVFSURI *guri;
+  SwfdecURL *url;
+  SwfdecLoader *loader;
 
   g_return_val_if_fail (uri != NULL, NULL);
 
-  gnome_vfs_init ();
-  guri = gnome_vfs_uri_new (uri);
-  return swfdec_gtk_loader_new_from_uri (guri);
+  url = swfdec_url_new (uri);
+  g_return_val_if_fail (url == NULL, NULL); /* FIXME */
+  loader = g_object_new (SWFDEC_TYPE_GTK_LOADER, NULL);
+  swfdec_gtk_loader_load (loader, SWFDEC_LOADER_REQUEST_DEFAULT, NULL, 0);
+  return loader;
 }
 
 #endif /* HAVE_GNOMEVFS */
diff --git a/libswfdec/swfdec_loader.c b/libswfdec/swfdec_loader.c
index aa41e59..65081d5 100644
--- a/libswfdec/swfdec_loader.c
+++ b/libswfdec/swfdec_loader.c
@@ -152,7 +152,7 @@ swfdec_loader_dispose (GObject *object)
   SwfdecLoader *loader = SWFDEC_LOADER (object);
 
   swfdec_buffer_queue_unref (loader->queue);
-  g_free (loader->url);
+  swfdec_url_free (loader->url);
   g_free (loader->error);
 
   G_OBJECT_CLASS (swfdec_loader_parent_class)->dispose (object);
@@ -196,56 +196,42 @@ swfdec_loader_init (SwfdecLoader *loader
 G_DEFINE_TYPE (SwfdecFileLoader, swfdec_file_loader, SWFDEC_TYPE_LOADER)
 
 static void
-swfdec_file_loader_dispose (GObject *object)
-{
-  SwfdecFileLoader *file_loader = SWFDEC_FILE_LOADER (object);
-
-  g_free (file_loader->dir);
-
-  G_OBJECT_CLASS (swfdec_file_loader_parent_class)->dispose (object);
-}
-
-static SwfdecLoader *
-swfdec_file_loader_load (SwfdecLoader *loader, const char *url, 
-    SwfdecLoaderRequest request, const char *data, gsize data_len)
+swfdec_file_loader_load (SwfdecLoader *loader, SwfdecLoaderRequest request, 
+    const char *data, gsize data_len)
 {
+  const SwfdecURL *url;
   SwfdecBuffer *buffer;
-  char *real_path;
-  SwfdecLoader *ret;
   GError *error = NULL;
+  char *real;
 
-  if (g_path_is_absolute (url)) {
-    SWFDEC_ERROR ("\"%s\" is an absolute path - using relative instead", url);
-    while (*url == G_DIR_SEPARATOR)
-      url++;
+  url = swfdec_loader_get_url (loader);
+  if (!g_str_equal (swfdec_url_get_protocol (url), "file")) {
+    swfdec_loader_error (loader, "Don't know how to handle other protocols than file");
+    return;
+  }
+  if (swfdec_url_get_host (url)) {
+    swfdec_loader_error (loader, "filenames cannot have hostnames");
+    return;
   }
 
-  /* FIXME: need to rework seperators on windows? */
-  real_path = g_build_filename (SWFDEC_FILE_LOADER (loader)->dir, url, NULL);
-  buffer = swfdec_buffer_new_from_file (real_path, &error);
-  ret = g_object_new (SWFDEC_TYPE_FILE_LOADER, NULL);
-  ret->url = real_path;
-  SWFDEC_FILE_LOADER (ret)->dir = g_strdup (SWFDEC_FILE_LOADER (loader)->dir);
+  /* FIXME: append query string here? */
+  real = g_strconcat ("/", swfdec_url_get_path (url), NULL);
+  buffer = swfdec_buffer_new_from_file (real, &error);
   if (buffer == NULL) {
-    swfdec_loader_error (ret, error->message);
+    swfdec_loader_error (loader, error->message);
     g_error_free (error);
   } else {
-    swfdec_loader_set_size (ret, buffer->length);
-    swfdec_loader_push (ret, buffer);
-    swfdec_loader_eof (ret);
+    swfdec_loader_set_size (loader, buffer->length);
+    swfdec_loader_push (loader, buffer);
+    swfdec_loader_eof (loader);
   }
-
-  return ret;
 }
 
 static void
 swfdec_file_loader_class_init (SwfdecFileLoaderClass *klass)
 {
-  GObjectClass *object_class = G_OBJECT_CLASS (klass);
   SwfdecLoaderClass *loader_class = SWFDEC_LOADER_CLASS (klass);
 
-  object_class->dispose = swfdec_file_loader_dispose;
-
   loader_class->load = swfdec_file_loader_load;
 }
 
@@ -269,8 +255,10 @@ swfdec_loader_load (SwfdecLoader *loader
 
   klass = SWFDEC_LOADER_GET_CLASS (loader);
   g_return_val_if_fail (klass->load != NULL, NULL);
-  ret = klass->load (loader, url, request, data, data_len);
-  g_assert (ret != NULL);
+  ret = g_object_new (G_OBJECT_CLASS_TYPE (klass), NULL);
+  ret->url = swfdec_url_new_relative (loader->url, url);
+  g_assert (ret->url);
+  klass->load (ret, request, data, data_len);
   return ret;
 }
 
@@ -321,20 +309,31 @@ swfdec_loader_new_from_file (const char 
   SwfdecBuffer *buf;
   SwfdecLoader *loader;
   GError *error = NULL;
+  char *url;
 
   g_return_val_if_fail (filename != NULL, NULL);
 
   buf = swfdec_buffer_new_from_file (filename, &error);
 
-  loader = g_object_new (SWFDEC_TYPE_FILE_LOADER, NULL);
   if (g_path_is_absolute (filename)) {
-    loader->url = g_strdup (filename);
+    url = g_strconcat ("file://", filename, NULL);
   } else {
-    char *cur = g_get_current_dir ();
-    loader->url = g_build_filename (cur, filename, NULL);
+    char *abs, *cur;
+    cur = g_get_current_dir ();
+    abs = g_build_filename (cur, filename, NULL);
     g_free (cur);
+    url = g_strconcat ("file://", abs, NULL);
+    g_free (abs);
+  }
+
+  loader = g_object_new (SWFDEC_TYPE_FILE_LOADER, NULL);
+  loader->url = swfdec_url_new (url);
+  if (loader->url == NULL) {
+    g_warning ("WTF? %s is not a valid url!", url);
+    loader->url = swfdec_url_new ("file:///");
   }
-  SWFDEC_FILE_LOADER (loader)->dir = g_path_get_dirname (loader->url);
+  g_assert (loader->url);
+  g_free (url);
   if (buf == NULL) {
     swfdec_loader_error (loader, error->message);
     g_error_free (error);
@@ -463,50 +462,59 @@ swfdec_loader_eof (SwfdecLoader *loader)
 char *
 swfdec_loader_get_filename (SwfdecLoader *loader)
 {
-  char *start, *end, *ret;
+  const SwfdecURL *url;
+  const char *path, *ext;
+  char *ret;
 
   g_return_val_if_fail (SWFDEC_IS_LOADER (loader), NULL);
-  /* every loader must set this */
-  g_return_val_if_fail (loader->url != NULL, NULL);
 
-  end = strchr (loader->url, '?');
-  if (end) {
-    char *next = NULL;
-    do {
-      start = next ? next + 1 : loader->url;
-      next = strchr (start, '/');
-    } while (next != NULL && next < end);
-  } else {
-    start = strrchr (loader->url, '/');
-    if (start == NULL) {
-      start = loader->url;
-    } else {
-      start++;
-    }
-  }
-  ret = g_filename_from_utf8 (start, end ? end - start : -1, NULL, NULL, NULL);
-  if (ret) {
-    const char *ext;
-    
-    ext = swfdec_loader_data_type_get_extension (loader->data_type);
-    if (*ext) {
-      char *dot = strrchr (ret, '.');
-      char *real;
-      guint len = dot ? strlen (dot) : G_MAXUINT;
-      if (len <= 5)
-	*dot = '\0';
-      real = g_strdup_printf ("%s.%s", ret, ext);
-      g_free (ret);
-      ret = real;
-    }
-  } else {
-    ret = g_strdup ("unknown file");
+  url = swfdec_loader_get_url (loader);
+  path = swfdec_url_get_path (url);
+  if (path) {
+    char *s = strchr (path, '/');
+    if (s)
+      path = s + 1;
+    if (path[0] == 0)
+      path = NULL;
+  }
+  if (path)
+    ret = g_filename_from_utf8 (path, -1, NULL, NULL, NULL);
+  if (ret == NULL)
+    ret = g_strdup ("unknown");
+
+  ext = swfdec_loader_data_type_get_extension (loader->data_type);
+  if (*ext) {
+    char *dot = strrchr (ret, '.');
+    char *real;
+    guint len = dot ? strlen (dot) : G_MAXUINT;
+    if (len <= 5)
+      *dot = '\0';
+    real = g_strdup_printf ("%s.%s", ret, ext);
+    g_free (ret);
+    ret = real;
   }
 
   return ret;
 }
 
 /**
+ * swfdec_loader_get_url:
+ * @loader: a #SwfdecLoader
+ *
+ * Gets the url this loader is handling. This is mostly useful for writing 
+ * subclasses of #SwfdecLoader.
+ *
+ * Returns: a #SwfdecURL describing @loader.
+ **/
+const SwfdecURL *
+swfdec_loader_get_url (SwfdecLoader *loader)
+{
+  g_return_val_if_fail (SWFDEC_IS_LOADER (loader), NULL);
+
+  return loader->url;
+}
+
+/**
  * swfdec_loader_get_data_type:
  * @loader: a #SwfdecLoader
  *
diff --git a/libswfdec/swfdec_loader.h b/libswfdec/swfdec_loader.h
index f1c5f44..9cc0a4e 100644
--- a/libswfdec/swfdec_loader.h
+++ b/libswfdec/swfdec_loader.h
@@ -22,6 +22,7 @@
 
 #include <glib-object.h>
 #include <libswfdec/swfdec_buffer.h>
+#include <libswfdec/swfdec_url.h>
 
 G_BEGIN_DECLS
 
@@ -54,8 +55,8 @@ struct _SwfdecLoader
 {
   GObject		object;
 
-  char *		url;		/* the URL for this loader in UTF-8 - must be set on creation */
   /*< private >*/
+  SwfdecURL *		url;		/* the URL for this loader in UTF-8 - must be set on creation */
   gulong		size;		/* number of bytes in stream or 0 if unknown */
   gboolean		eof;		/* if we're in EOF already */
   char *		error;		/* if there's an error (from parsing the loader) */
@@ -68,9 +69,8 @@ struct _SwfdecLoaderClass
 {
   GObjectClass		object_class;
 
-  /* loads the given URL. Must return a loader, the loader can be in the error state */
-  SwfdecLoader *      	(* load)	(SwfdecLoader *			loader, 
-					 const char *			url,
+  /* iitializes the loader. The URL will be set already. */
+  void			(* load)	(SwfdecLoader *			loader, 
 					 SwfdecLoaderRequest		request,
 					 const char *			data,
 					 gsize				data_len);
@@ -85,6 +85,8 @@ void		swfdec_loader_push		(SwfdecLoader 
 void		swfdec_loader_eof		(SwfdecLoader *		loader);
 void		swfdec_loader_error		(SwfdecLoader *		loader,
 						 const char *		error);
+const SwfdecURL *
+		swfdec_loader_get_url		(SwfdecLoader *		loader);
 void		swfdec_loader_set_size		(SwfdecLoader *		loader,
 						 gulong			size);
 gulong		swfdec_loader_get_size		(SwfdecLoader *		loader);
diff --git a/libswfdec/swfdec_loader_internal.h b/libswfdec/swfdec_loader_internal.h
index 43b5231..0b1840f 100644
--- a/libswfdec/swfdec_loader_internal.h
+++ b/libswfdec/swfdec_loader_internal.h
@@ -38,8 +38,6 @@ typedef struct _SwfdecFileLoaderClass Sw
 struct _SwfdecFileLoader
 {
   SwfdecLoader		loader;
-
-  char *		dir;		/* base directory for load operations */
 };
 
 struct _SwfdecFileLoaderClass
diff --git a/player/swfdebug.c b/player/swfdebug.c
index 88987a0..5c759db 100644
--- a/player/swfdebug.c
+++ b/player/swfdebug.c
@@ -358,7 +358,8 @@ add_variables (gpointer player)
 
   swfdec_player_set_loader_with_variables (player, loader, variables);
   if (!swfdec_player_is_initialized (player)) {
-    g_printerr ("File \"%s\" is not a file Swfdec can play\n", loader->url);
+    g_printerr ("File \"%s\" is not a file Swfdec can play\n", 
+	swfdec_url_get_url (swfdec_loader_get_url (loader)));
     g_object_unref (player);
     gtk_main_quit ();
     return FALSE;
diff --git a/player/swfdec_slow_loader.c b/player/swfdec_slow_loader.c
index 1cad9de..c568316 100644
--- a/player/swfdec_slow_loader.c
+++ b/player/swfdec_slow_loader.c
@@ -22,7 +22,7 @@
 #endif
 
 #include "swfdec_slow_loader.h"
-#include <libswfdec/swfdec_loader_internal.h>
+#include <libswfdec-gtk/swfdec-gtk.h>
 
 /*** SwfdecSlowLoader ***/
 
@@ -51,35 +51,6 @@ swfdec_slow_loader_dispose (GObject *obj
   G_OBJECT_CLASS (swfdec_slow_loader_parent_class)->dispose (object);
 }
 
-static SwfdecLoader *
-swfdec_slow_loader_load (SwfdecLoader *loader, const char *url,
-    SwfdecLoaderRequest request, const char *data, gsize data_len)
-{
-  SwfdecSlowLoader *slow = SWFDEC_SLOW_LOADER (loader);
-  SwfdecLoader *new;
-
-  new = swfdec_loader_load (slow->loader, url, request, data, data_len); 
-  if (new == NULL)
-    return NULL;
-  return swfdec_slow_loader_new (new, slow->duration / 1000);
-}
-
-static void
-swfdec_slow_loader_class_init (SwfdecSlowLoaderClass *klass)
-{
-  GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  SwfdecLoaderClass *loader_class = SWFDEC_LOADER_CLASS (klass);
-
-  object_class->dispose = swfdec_slow_loader_dispose;
-
-  loader_class->load = swfdec_slow_loader_load;
-}
-
-static void
-swfdec_slow_loader_init (SwfdecSlowLoader *slow_loader)
-{
-}
-
 static gboolean
 swfdec_slow_loader_tick (gpointer data)
 {
@@ -119,24 +90,59 @@ swfdec_slow_loader_tick (gpointer data)
   }
 }
 
+static void
+swfdec_slow_loader_initialize (SwfdecSlowLoader *slow, SwfdecLoader *loader, guint duration)
+{
+  gulong size;
+
+  slow->tick_time = 100;
+  slow->duration = duration * 1000;
+  slow->loader = loader;
+  g_signal_connect (loader, "notify", G_CALLBACK (swfdec_slow_loader_notify_cb), slow);
+  size = swfdec_loader_get_size (loader);
+  if (size)
+    swfdec_loader_set_size (SWFDEC_LOADER (slow), size);
+  slow->timeout_id = g_timeout_add (slow->tick_time, swfdec_slow_loader_tick, slow);
+}
+
+static void
+swfdec_slow_loader_load (SwfdecLoader *loader,
+    SwfdecLoaderRequest request, const char *data, gsize data_len)
+{
+  SwfdecSlowLoader *slow = SWFDEC_SLOW_LOADER (loader);
+  SwfdecLoader *new;
+
+  /* FIXME: include request and data */
+  new = swfdec_gtk_loader_new (swfdec_url_get_url (swfdec_loader_get_url (loader)));
+  swfdec_slow_loader_initialize (slow, new, slow->duration / 1000);
+}
+
+static void
+swfdec_slow_loader_class_init (SwfdecSlowLoaderClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  SwfdecLoaderClass *loader_class = SWFDEC_LOADER_CLASS (klass);
+
+  object_class->dispose = swfdec_slow_loader_dispose;
+
+  loader_class->load = swfdec_slow_loader_load;
+}
+
+static void
+swfdec_slow_loader_init (SwfdecSlowLoader *slow_loader)
+{
+}
+
 SwfdecLoader *
 swfdec_slow_loader_new (SwfdecLoader *loader, guint duration)
 {
   SwfdecSlowLoader *ret;
-  gulong size;
 
   g_return_val_if_fail (SWFDEC_IS_LOADER (loader), NULL);
   g_return_val_if_fail (duration > 0, NULL);
 
   ret = g_object_new (SWFDEC_TYPE_SLOW_LOADER, NULL);
-  ret->tick_time = 100;
-  ret->duration = duration * 1000;
-  ret->loader = loader;
-  g_signal_connect (loader, "notify", G_CALLBACK (swfdec_slow_loader_notify_cb), ret);
-  size = swfdec_loader_get_size (loader);
-  if (size)
-    swfdec_loader_set_size (SWFDEC_LOADER (ret), size);
-  ret->timeout_id = g_timeout_add (ret->tick_time, swfdec_slow_loader_tick, ret);
-
+  swfdec_slow_loader_initialize (ret, loader, duration);
   return SWFDEC_LOADER (ret);
 }
+
diff-tree c7fb0f56f3782d11b9f438043fbc070dae1947d5 (from 2e88e6e61830d57ed4c53ceb05b139bcc99c784f)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jul 31 13:00:07 2007 +0200

    append the right string here

diff --git a/libswfdec/swfdec_url.c b/libswfdec/swfdec_url.c
index 6eaef71..95f0cc3 100644
--- a/libswfdec/swfdec_url.c
+++ b/libswfdec/swfdec_url.c
@@ -151,7 +151,7 @@ swfdec_url_new_relative (const SwfdecURL
       if (slash == NULL) {
 	g_string_append (str, string);
       } else {
-	g_string_append_len (str, string, slash - string + 1); /* append '/', too */
+	g_string_append_len (str, url->path, slash - url->path + 1); /* append '/', too */
 	g_string_append (str, string);
       }
     }
diff-tree 2e88e6e61830d57ed4c53ceb05b139bcc99c784f (from 8744283c294d368b839e64efe51ca77534575164)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jul 31 12:59:47 2007 +0200

    include the right header

diff --git a/libswfdec/swfdec_url.h b/libswfdec/swfdec_url.h
index 21577a8..d3c4e24 100644
--- a/libswfdec/swfdec_url.h
+++ b/libswfdec/swfdec_url.h
@@ -17,10 +17,7 @@
  * Boston, MA  02110-1301  USA
  */
 
-#include <libswfdec/swfdec_bits.h>
-#include <libswfdec/swfdec_as_types.h>
-#include <libswfdec/swfdec_player.h>
-#include <libswfdec/swfdec_types.h>
+#include <glib-object.h>
 
 #ifndef _SWFDEC_URL_H_
 #define _SWFDEC_URL_H_
diff-tree 8744283c294d368b839e64efe51ca77534575164 (from 91f769a3564710649b4f0e1e350a3a21f95fd666)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jul 31 11:21:43 2007 +0200

    no need to document FOO_TYPE macros

diff --git a/doc/swfdec-sections.txt b/doc/swfdec-sections.txt
index 6fc137d..ccb76d4 100644
--- a/doc/swfdec-sections.txt
+++ b/doc/swfdec-sections.txt
@@ -96,9 +96,7 @@ SWFDEC_PLAYER_GET_CLASS
 <FILE>SwfdecBuffer</FILE>
 <TITLE>SwfdecBuffer</TITLE>
 SwfdecBuffer
-SWFDEC_TYPE_BUFFER
 SwfdecBufferQueue
-SWFDEC_TYPE_BUFFER_QUEUE
 swfdec_buffer_new
 swfdec_buffer_new_and_alloc
 swfdec_buffer_new_and_alloc0
diff --git a/libswfdec/swfdec_buffer.c b/libswfdec/swfdec_buffer.c
index c41a830..b79cae6 100644
--- a/libswfdec/swfdec_buffer.c
+++ b/libswfdec/swfdec_buffer.c
@@ -59,12 +59,6 @@
  * swfdec_buffer_new_from_file() without the need for a different API.
  */
 
-/**
- * SWFDEC_TYPE_BUFFER:
- *
- * #SwfdecBuffer is a boxed type for the glib type system. This macro
- * returns its type.
- **/
 GType
 swfdec_buffer_get_type (void)
 {
@@ -304,12 +298,6 @@ swfdec_buffer_unref (SwfdecBuffer * buff
  * size.
  */
 
-/**
- * SWFDEC_TYPE_BUFFER_QUEUE:
- *
- * #SwfdecBufferQueue is a boxed type for the glib type system. This macro
- * returns its type.
- **/
 GType
 swfdec_buffer_queue_get_type (void)
 {
diff-tree 91f769a3564710649b4f0e1e350a3a21f95fd666 (from 171c8efc6b01164044bc5396df36da74fe86e145)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jul 31 11:20:55 2007 +0200

    add SwfdecURL type
    
    It's unused so far, but it's documented!

diff --git a/doc/swfdec-docs.sgml b/doc/swfdec-docs.sgml
index e04ade0..0f4c82a 100644
--- a/doc/swfdec-docs.sgml
+++ b/doc/swfdec-docs.sgml
@@ -19,6 +19,7 @@
     <xi:include href="xml/SwfdecAudio.xml"/>
     <xi:include href="xml/SwfdecBuffer.xml"/>
     <xi:include href="xml/SwfdecLoader.xml"/>
+    <xi:include href="xml/SwfdecURL.xml"/>
   </chapter>
   <chapter>
     <title>Actionscript interpreter</title>
diff --git a/doc/swfdec-sections.txt b/doc/swfdec-sections.txt
index 3048a95..6fc137d 100644
--- a/doc/swfdec-sections.txt
+++ b/doc/swfdec-sections.txt
@@ -39,6 +39,23 @@ SWFDEC_LOADER_GET_CLASS
 </SECTION>
 
 <SECTION>
+<FILE>SwfdecURL</FILE>
+<TITLE>SwfdecURL</TITLE>
+SwfdecURL
+swfdec_url_copy
+swfdec_url_free
+swfdec_url_get_host
+swfdec_url_get_path
+swfdec_url_get_protocol
+swfdec_url_get_query
+swfdec_url_get_url
+swfdec_url_new
+swfdec_url_new_relative
+<SUBSECTION Standard>
+swfdec_url_get_type
+</SECTION>
+
+<SECTION>
 <FILE>SwfdecPlayer</FILE>
 <TITLE>SwfdecPlayer</TITLE>
 SwfdecPlayer
diff --git a/libswfdec/Makefile.am b/libswfdec/Makefile.am
index ae81146..2476e54 100644
--- a/libswfdec/Makefile.am
+++ b/libswfdec/Makefile.am
@@ -100,6 +100,7 @@ libswfdec_ at SWFDEC_MAJORMINOR@_la_SOURCES
 	swfdec_swf_instance.c \
 	swfdec_tag.c \
 	swfdec_text.c \
+	swfdec_url.c \
 	swfdec_utils.c \
 	swfdec_video.c \
 	swfdec_video_movie.c \
@@ -128,7 +129,8 @@ public_headers = \
 	swfdec_audio.h \
 	swfdec_buffer.h \
 	swfdec_loader.h \
-	swfdec_player.h
+	swfdec_player.h \
+	swfdec_url.h
 
 libswfdec_ at SWFDEC_MAJORMINOR@_la_LIBADD = jpeg/libjpeg.la 
 libswfdec_ at SWFDEC_MAJORMINOR@includedir = $(includedir)/swfdec- at SWFDEC_MAJORMINOR@/libswfdec
diff --git a/libswfdec/swfdec.h b/libswfdec/swfdec.h
index 3d326db..5e3055a 100644
--- a/libswfdec/swfdec.h
+++ b/libswfdec/swfdec.h
@@ -1,7 +1,7 @@
 /* Swfdec
  * Copyright (C) 2003-2006 David Schleef <ds at schleef.org>
  *		 2005-2006 Eric Anholt <eric at anholt.net>
- *		      2006 Benjamin Otte <otte at gnome.org>
+ *		 2006-2007 Benjamin Otte <otte at gnome.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -32,5 +32,6 @@
 #include <libswfdec/swfdec_enums.h>
 #include <libswfdec/swfdec_loader.h>
 #include <libswfdec/swfdec_player.h>
+#include <libswfdec/swfdec_url.h>
 
 #endif
diff --git a/libswfdec/swfdec_url.c b/libswfdec/swfdec_url.c
new file mode 100644
index 0000000..6eaef71
--- /dev/null
+++ b/libswfdec/swfdec_url.c
@@ -0,0 +1,293 @@
+/* Swfdec
+ * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <string.h>
+#include "swfdec_url.h"
+#include "swfdec_debug.h"
+
+/**
+ * SECTION:SwfdecURL
+ * @title: SwfdecURL
+ * @short_description: URL handling in Swfdec
+ * @see_also #SwfdecLoader
+ *
+ * SwfdecURL is Swfdec's way of handling URLs. You probably don't need to mess 
+ * with this type unless you want to write a #SwfdecLoader. In that case you 
+ * will want to use @swfdec_loader_get_url() to get its url and then use the 
+ * functions in this section to access it.
+ */
+
+/**
+ * SwfdecURL:
+ *
+ * this is the structure used for URLs. It is a boxed type to glib's type system
+ * and it is not reference counted. It is also a static struct in that it cannot
+ * be modified after creation.
+ */
+
+struct _SwfdecURL {
+  char *	url;			/* the complete url */
+  char *	protocol;		/* http, file, rtmp, ... */
+  char *	host;			/* can be NULL for files */
+  char *	path;	  		/* can be NULL for root path */
+  char *	query;			/* can be NULL */
+};
+
+GType
+swfdec_url_get_type (void)
+{
+  static GType type = 0;
+
+  if (!type)
+    type = g_boxed_type_register_static ("SwfdecURL", 
+       (GBoxedCopyFunc) swfdec_url_copy, (GBoxedFreeFunc) swfdec_url_free);
+
+  return type;
+}
+
+/**
+ * swfdec_url_new:
+ * @string: a full-qualified URL encoded in UTF-8
+ *
+ * Parses the given string into a URL for use in swfdec.
+ *
+ * Returns: a new #SwfdecURL or %NULL if an error was found in @string
+ **/
+SwfdecURL *
+swfdec_url_new (const char *string)
+{
+  SwfdecURL *url;
+  char *s;
+
+  g_return_val_if_fail (string != NULL, NULL);
+
+  url = g_slice_new0 (SwfdecURL);
+  url->url = g_strdup (string);
+  s = strstr (string, "://");
+  if (s == NULL) {
+    SWFDEC_ERROR ("URL %s has no protocol", string);
+    swfdec_url_free (url);
+    return NULL;
+  }
+  url->protocol = g_strndup (string, s - string);
+  string = s + 3;
+  s = strchr (string, '/');
+  if (s == NULL) {
+    url->host = g_strdup (string);
+    return url;
+  }
+  if (s != string)
+    url->host = g_strndup (string, s - string);
+  string = s + 1;
+  s = strchr (string, '?');
+  if (s == NULL) {
+    url->path = *string ? g_strdup (string) : NULL;
+    return url;
+  }
+  url->path = g_strndup (string, s - string);
+  s++;
+  if (*s)
+    url->query = g_strdup (s + 1);
+  return url;
+}
+
+/**
+ * swfdec_url_new_relative:
+ * @url: a #SwfdecURL
+ * @string: a relative or absolute URL path
+ *
+ * Parses @string into a new URL. If the given @string is a relative URL, it 
+ * uses @url to resolve it to an absolute url.
+ *
+ * Returns: a new #SwfdecURL or %NULL if an error was detected.
+ **/
+SwfdecURL *
+swfdec_url_new_relative (const SwfdecURL *url, const char *string)
+{
+  SwfdecURL *ret;
+  GString *str;
+
+  g_return_val_if_fail (url != NULL, NULL);
+  g_return_val_if_fail (string != NULL, NULL);
+
+  if (strstr (string, "://")) {
+    /* full-qualified URL */
+    return swfdec_url_new (string);
+  }
+  str = g_string_new (url->protocol);
+  g_string_append (str, "://");
+  if (url->host)
+    g_string_append (str, url->host);
+  if (string[0] == '/') {
+    /* absolute URL */
+    g_string_append (str, string);
+  } else {
+    /* relative URL */
+    g_string_append (str, "/");
+    if (url->path == NULL) {
+      g_string_append (str, string);
+    } else {
+      char *slash;
+      slash = strrchr (url->path, '/');
+      if (slash == NULL) {
+	g_string_append (str, string);
+      } else {
+	g_string_append_len (str, string, slash - string + 1); /* append '/', too */
+	g_string_append (str, string);
+      }
+    }
+  }
+  ret = swfdec_url_new (str->str);
+  g_string_free (str, TRUE);
+  return ret;
+}
+
+/**
+ * swfdec_url_copy:
+ * @url: a #SwfdecURL
+ *
+ * copies the given url.
+ *
+ * Returns: a new #SwfdecURL
+ **/
+SwfdecURL *
+swfdec_url_copy (const SwfdecURL *url)
+{
+  SwfdecURL *copy;
+
+  g_return_val_if_fail (url != NULL, NULL);
+
+  copy = g_slice_new0 (SwfdecURL);
+  copy->url = g_strdup (url->url);
+  copy->protocol = g_strdup (url->protocol);
+  copy->host = g_strdup (url->host);
+  copy->path = g_strdup (url->path);
+  copy->query = g_strdup (url->query);
+
+  return copy;
+}
+
+/**
+ * swfdec_url_free:
+ * @url: a #SwfdecURL
+ *
+ * Frees the URL and its associated ressources.
+ **/
+void
+swfdec_url_free (SwfdecURL *url)
+{
+  g_return_if_fail (url != NULL);
+
+  g_free (url->url);
+  g_free (url->protocol);
+  g_free (url->host);
+  g_free (url->path);
+  g_free (url->query);
+  g_slice_free (SwfdecURL, url);
+}
+
+/**
+ * swfdec_url_get_url:
+ * @url: a #SwfdecURL
+ *
+ * Gets the whole URL.
+ *
+ * Returns: the complete URL as string
+ **/
+const char *
+swfdec_url_get_url (const SwfdecURL *url)
+{
+  g_return_val_if_fail (url != NULL, NULL);
+
+  return url->url;
+}
+
+/**
+ * swfdec_url_get_protocol:
+ * @url: a #SwfdecURL
+ *
+ * Gets the protocol used by this URL, such as "http" or "file".
+ *
+ * Returns: the protocol used
+ **/
+const char *
+swfdec_url_get_protocol (const SwfdecURL *url)
+{
+  g_return_val_if_fail (url != NULL, NULL);
+
+  return url->protocol;
+}
+
+/**
+ * swfdec_url_get_host:
+ * @url: a #SwfdecURL
+ *
+ * Gets the host for @url. If the host includes a portnumber, it will be present
+ * in the returned string.
+ *
+ * Returns: the host or %NULL if none (typically for file URLs).
+ **/
+const char *
+swfdec_url_get_host (const SwfdecURL *url)
+{
+  g_return_val_if_fail (url != NULL, NULL);
+
+  return url->host;
+}
+
+/**
+ * swfdec_url_get_path:
+ * @url: a #SwfdecURL
+ *
+ * Gets the path associated with @url. If it contains no path, %NULL is 
+ * returned.
+ * <note>The returned path does not start with a slash. So in particular for 
+ * files, you want to prepend the slash yourself.</note>
+ *
+ * Returns: the path or %NULL if none
+ **/
+const char *
+swfdec_url_get_path (const SwfdecURL *url)
+{
+  g_return_val_if_fail (url != NULL, NULL);
+
+  return url->path;
+}
+
+/**
+ * swfdec_url_get_query:
+ * @url: a #SwfdecURL
+ *
+ * Gets the query string associated with @url. If the URL does not have a query
+ * string, %NULL is returned.
+ *
+ * Returns: Query string or %NULL
+ **/
+const char *
+swfdec_url_get_query (const SwfdecURL *url)
+{
+  g_return_val_if_fail (url != NULL, NULL);
+
+  return url->query;
+}
+
+
diff --git a/libswfdec/swfdec_url.h b/libswfdec/swfdec_url.h
new file mode 100644
index 0000000..21577a8
--- /dev/null
+++ b/libswfdec/swfdec_url.h
@@ -0,0 +1,50 @@
+/* Swfdec
+ * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#include <libswfdec/swfdec_bits.h>
+#include <libswfdec/swfdec_as_types.h>
+#include <libswfdec/swfdec_player.h>
+#include <libswfdec/swfdec_types.h>
+
+#ifndef _SWFDEC_URL_H_
+#define _SWFDEC_URL_H_
+
+G_BEGIN_DECLS
+
+typedef struct _SwfdecURL SwfdecURL;
+
+#define SWFDEC_TYPE_URL swfdec_url_get_type()
+GType			swfdec_url_get_type		(void) G_GNUC_CONST;
+
+SwfdecURL *		swfdec_url_new			(const char *		string);
+SwfdecURL *		swfdec_url_new_relative	      	(const SwfdecURL *	url,
+							 const char *		string);
+SwfdecURL *		swfdec_url_copy			(const SwfdecURL *      url);
+void			swfdec_url_free			(SwfdecURL *		url);
+
+const char *		swfdec_url_get_url		(const SwfdecURL *      url);
+const char *		swfdec_url_get_protocol		(const SwfdecURL *      url);
+const char *		swfdec_url_get_host		(const SwfdecURL *      url);
+const char *		swfdec_url_get_path		(const SwfdecURL *      url);
+const char *		swfdec_url_get_query		(const SwfdecURL *      url);
+							 
+
+G_END_DECLS
+
+#endif
diff-tree 171c8efc6b01164044bc5396df36da74fe86e145 (from 0485141a278c654dd6acb4d350628a48e7c65c78)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jul 31 11:20:25 2007 +0200

    remove code that got rid of gnome-vfs
    
    That was intended for debugging purposes only (oops)

diff --git a/player/swfplay.c b/player/swfplay.c
index 2b33456..4ebf668 100644
--- a/player/swfplay.c
+++ b/player/swfplay.c
@@ -117,8 +117,6 @@ main (int argc, char *argv[])
 #else
   loader = swfdec_gtk_loader_new (argv[1]);
 #endif
-  g_object_unref (loader);
-  loader = swfdec_loader_new_from_file (argv[1]);
   if (loader->error) {
     g_printerr ("Couldn't open file \"%s\": %s\n", argv[1], loader->error);
     g_object_unref (loader);
diff-tree 0485141a278c654dd6acb4d350628a48e7c65c78 (from d218c74a559903b86ae6e28945d9bbfe894a52cb)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jul 31 11:19:38 2007 +0200

    ignore (automatic) breakpoints during initialization

diff --git a/libswfdec/swfdec_debugger.c b/libswfdec/swfdec_debugger.c
index d9c2798..9b0fd2a 100644
--- a/libswfdec/swfdec_debugger.c
+++ b/libswfdec/swfdec_debugger.c
@@ -416,6 +416,8 @@ swfdec_debugger_step (SwfdecAsContext *c
 {
   SwfdecDebugger *debugger = SWFDEC_DEBUGGER (context);
 
+  if (context->state != SWFDEC_AS_CONTEXT_RUNNING)
+    return;
   if (!debugger->has_breakpoints)
     return;
 
diff-tree d218c74a559903b86ae6e28945d9bbfe894a52cb (from 11470f3db6cd2beaf173f0ed10ab51ea3325b001)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jul 31 11:19:20 2007 +0200

    run initialization scripts in NEW state

diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index d48ad03..f0e448f 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -1299,10 +1299,6 @@ swfdec_player_initialize (SwfdecPlayer *
     swfdec_net_connection_init_context (player, version);
     swfdec_net_stream_init_context (player, version);
     swfdec_xml_init_context (player, version);
-    if (context->state == SWFDEC_AS_CONTEXT_NEW) {
-      context->state = SWFDEC_AS_CONTEXT_RUNNING;
-      swfdec_as_object_set_constructor (player->roots->data, player->MovieClip, FALSE);
-    }
     if (version > 4) {
       SwfdecBits bits;
       SwfdecScript *script;
@@ -1312,6 +1308,10 @@ swfdec_player_initialize (SwfdecPlayer *
       swfdec_as_object_run (context->global, script);
       swfdec_script_unref (script);
     }
+    if (context->state == SWFDEC_AS_CONTEXT_NEW) {
+      context->state = SWFDEC_AS_CONTEXT_RUNNING;
+      swfdec_as_object_set_constructor (player->roots->data, player->MovieClip, FALSE);
+    }
   }
   SWFDEC_INFO ("initializing player to size %ux%u", width, height);
   player->rate = rate;
diff-tree 11470f3db6cd2beaf173f0ed10ab51ea3325b001 (from 687fb9322f3f8ef29953d523c503c341e1bc6299)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jul 31 11:19:08 2007 +0200

    allow running scripts in NEW state

diff --git a/libswfdec/swfdec_as_context.c b/libswfdec/swfdec_as_context.c
index a47028c..0d4d513 100644
--- a/libswfdec/swfdec_as_context.c
+++ b/libswfdec/swfdec_as_context.c
@@ -778,7 +778,7 @@ start:
       if (spec->add > 0)
 	swfdec_as_stack_ensure_free (context, spec->add);
     }
-    if (context->state != SWFDEC_AS_CONTEXT_RUNNING) {
+    if (context->state > SWFDEC_AS_CONTEXT_RUNNING) {
       SWFDEC_WARNING ("context not running anymore, aborting");
       goto error;
     }


More information about the Swfdec mailing list