[Swfdec] 8 commits - configure.ac doc/swfdec-sections.txt libswfdec/swfdec_loader.c libswfdec/swfdec_player.c libswfdec/swfdec_player.h libswfdec/swfdec_player_internal.h libswfdec/swfdec_root_movie.c libswfdec/swfdec_scriptable.c libswfdec/swfdec_scriptable.h libswfdec/swfdec_script.c player/swfdebug.c player/swfplay.c test/various

Benjamin Otte company at kemper.freedesktop.org
Sat Feb 17 04:36:49 PST 2007


 configure.ac                       |    2 -
 doc/swfdec-sections.txt            |    1 
 libswfdec/swfdec_loader.c          |    6 ++-
 libswfdec/swfdec_player.c          |   35 ++++++++++++++++++++---
 libswfdec/swfdec_player.h          |    4 ++
 libswfdec/swfdec_player_internal.h |    3 +
 libswfdec/swfdec_root_movie.c      |    2 -
 libswfdec/swfdec_script.c          |   23 ++++++++++++++-
 libswfdec/swfdec_scriptable.c      |   56 +++++++++++++++++++++++++++++++++++++
 libswfdec/swfdec_scriptable.h      |    3 +
 player/swfdebug.c                  |    4 +-
 player/swfplay.c                   |    4 +-
 test/various/urlencode.c           |    5 ++-
 13 files changed, 135 insertions(+), 13 deletions(-)

New commits:
diff-tree 86ceb1bdea1ecee5bff104a29c07351bf78454c1 (from b34773aabe26a4fecb2e4293722a7c11fb81f870)
Author: Benjamin Otte <otte at gnome.org>
Date:   Sat Feb 17 13:32:41 2007 +0100

    apparently / doesn't get escaped either

diff --git a/libswfdec/swfdec_loader.c b/libswfdec/swfdec_loader.c
index 29ca92c..49d7642 100644
--- a/libswfdec/swfdec_loader.c
+++ b/libswfdec/swfdec_loader.c
@@ -394,7 +394,7 @@ swfdec_loader_get_filename (SwfdecLoader
 }
 
 /* if speed ever gets an issue, use a 256 byte array instead of strchr */
-static const char *urlencode_unescaped="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.";
+static const char *urlencode_unescaped="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_./";
 static void
 swfdec_urlencode_append_string (GString *str, const char *s)
 {
diff --git a/test/various/urlencode.c b/test/various/urlencode.c
index 1e35644..0899b00 100644
--- a/test/various/urlencode.c
+++ b/test/various/urlencode.c
@@ -33,9 +33,9 @@ Test tests[] = {
   { "a=b", { "a" }, { "b" }, 1 },
   { "a=b&c=d", { "a", "c" }, { "b", "d" }, 2 },
   { "owned=Your+Mom", { "owned" }, { "Your Mom" }, 1 },
-  { "numbers=0123456789&uppercase=ABCDEFGHIJKLMNOPQRSTUVWXYZ&lowercase=abcdefghijklmnopqrstuvwxyz&special+chars=.-_", 
+  { "numbers=0123456789&uppercase=ABCDEFGHIJKLMNOPQRSTUVWXYZ&lowercase=abcdefghijklmnopqrstuvwxyz&special+chars=.-_/", 
     { "numbers", "uppercase", "lowercase", "special chars" }, 
-    { "0123456789", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz", ".-_" }, 4 }
+    { "0123456789", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz", ".-_/" }, 4 }
 };
 
 #define ERROR(...) G_STMT_START { \
diff-tree b34773aabe26a4fecb2e4293722a7c11fb81f870 (from b17cfe355c47b978935f2225917089e832253cef)
Author: Benjamin Otte <otte at gnome.org>
Date:   Sat Feb 17 12:54:23 2007 +0100

    implement --variables or -v flag to provide Flash variables

diff --git a/player/swfdebug.c b/player/swfdebug.c
index 63af21d..e1f0cbd 100644
--- a/player/swfdebug.c
+++ b/player/swfdebug.c
@@ -307,11 +307,13 @@ main (int argc, char *argv[])
   SwfdecPlayer *player;
   GError *error = NULL;
   gboolean use_image = FALSE;
+  char *variables = NULL;
 
   GOptionEntry options[] = {
     { "scale", 's', 0, G_OPTION_ARG_INT, &ret, "scale factor", "PERCENT" },
     { "image", 'i', 0, G_OPTION_ARG_NONE, &use_image, "use an intermediate image surface for drawing", NULL },
     { "break", 'b', 0, G_OPTION_ARG_NONE, &do_break, "break at the beginning of every script", NULL },
+    { "variables", 'v', 0, G_OPTION_ARG_STRING, &variables, "variables to pass to player", "VAR=NAME[&VAR=NAME..]" },
     { NULL }
   };
   GOptionContext *ctx;
@@ -346,7 +348,7 @@ main (int argc, char *argv[])
   if (do_break)
     g_signal_connect (player, "script-added", G_CALLBACK (do_break_cb), NULL);
   view_swf (player, scale, use_image);
-  swfdec_player_set_loader (player, loader);
+  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", argv[1]);
     g_object_unref (player);
diff --git a/player/swfplay.c b/player/swfplay.c
index 94d82f1..6941529 100644
--- a/player/swfplay.c
+++ b/player/swfplay.c
@@ -90,6 +90,7 @@ main (int argc, char *argv[])
   GError *error = NULL;
   gboolean use_image = FALSE, no_sound = FALSE;
   gboolean trace = FALSE;
+  char *variables = NULL;
   GtkWidget *window;
 
   GOptionEntry options[] = {
@@ -99,6 +100,7 @@ main (int argc, char *argv[])
     { "scale", 's', 0, G_OPTION_ARG_INT, &ret, "scale factor", "PERCENT" },
     { "speed", 0, 0, G_OPTION_ARG_INT, &speed, "replay speed (will deactivate sound)", "PERCENT" },
     { "trace", 't', 0, G_OPTION_ARG_NONE, &trace, "print trace output to stdout", NULL },
+    { "variables", 'v', 0, G_OPTION_ARG_STRING, &variables, "variables to pass to player", "VAR=NAME[&VAR=NAME..]" },
     { NULL }
   };
   GOptionContext *ctx;
@@ -136,7 +138,7 @@ main (int argc, char *argv[])
   if (delay) 
     loader = swfdec_slow_loader_new (loader, delay);
 
-  swfdec_player_set_loader (player, loader);
+  swfdec_player_set_loader_with_variables (player, loader, variables);
   /* FIXME add smarter "not my file" detection */
   if (!swfdec_player_is_initialized (player) && delay == 0) {
     g_printerr ("File \"%s\" is not a file Swfdec can play\n", argv[1]);
diff-tree b17cfe355c47b978935f2225917089e832253cef (from be155c9ea8089329611a96e8255dd128dbf37684)
Author: Benjamin Otte <otte at gnome.org>
Date:   Sat Feb 17 12:44:53 2007 +0100

    use swfdec_scriptable_set_variables if variables are set on the loader

diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index cbdac1b..2255771 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -870,9 +870,11 @@ swfdec_player_add_level_from_loader (Swf
 
   movie = swfdec_movie_new_for_player (player, depth);
   root = SWFDEC_ROOT_MOVIE (movie);
+  root->player = player;
   root->loader = loader;
+  if (variables)
+    swfdec_scriptable_set_variables (SWFDEC_SCRIPTABLE (movie), variables);
   swfdec_loader_set_target (root->loader, SWFDEC_LOADER_TARGET (root));
-  root->player = player;
   found = g_list_find_custom (player->roots, movie, swfdec_movie_compare_depths);
   if (found) {
     SWFDEC_DEBUG ("remove existing movie _level%u", depth);
@@ -1017,7 +1019,7 @@ swfdec_player_set_loader_with_variables 
   g_return_if_fail (player->roots == NULL);
   g_return_if_fail (SWFDEC_IS_LOADER (loader));
 
-  movie = swfdec_player_add_level_from_loader (player, 0, loader, NULL);
+  movie = swfdec_player_add_level_from_loader (player, 0, loader, variables);
   swfdec_loader_parse (loader);
 }
 
diff-tree be155c9ea8089329611a96e8255dd128dbf37684 (from 22b97a21348c7488830a599f1e0c4605e16367d0)
Author: Benjamin Otte <otte at gnome.org>
Date:   Sat Feb 17 12:44:39 2007 +0100

    add swfdec_scriptable_set_variables to set variables on the scriptable's JSObject

diff --git a/libswfdec/swfdec_scriptable.c b/libswfdec/swfdec_scriptable.c
index d1ff8da..f48c9be 100644
--- a/libswfdec/swfdec_scriptable.c
+++ b/libswfdec/swfdec_scriptable.c
@@ -23,6 +23,7 @@
 
 #include "swfdec_scriptable.h"
 #include "swfdec_debug.h"
+#include "swfdec_loader_internal.h"
 #include "js/jsapi.h"
 
 G_DEFINE_ABSTRACT_TYPE (SwfdecScriptable, swfdec_scriptable, G_TYPE_OBJECT)
@@ -154,3 +155,58 @@ swfdec_scriptable_from_jsval (JSContext 
     return NULL;
   return JS_GetPrivate (cx, object);
 }
+
+/**
+ * swfdec_scriptable_set_variables:
+ * @script: a #SwfdecScriptable
+ * @variables: variables to set on @script in application-x-www-form-urlencoded 
+ *             format
+ * 
+ * Verifies @variables to be encoded correctly and sets them as string 
+ * properties on the JSObject of @script.
+ **/
+void
+swfdec_scriptable_set_variables (SwfdecScriptable *script, const char *variables)
+{
+  JSObject *object;
+
+  g_return_if_fail (SWFDEC_IS_SCRIPTABLE (script));
+  g_return_if_fail (variables != NULL);
+
+  object = swfdec_scriptable_get_object (script);
+  while (*variables) {
+    char *name, *value;
+    JSString *string;
+    jsval val;
+
+    if (!swfdec_urldecode_one (variables, &name, &value, &variables)) {
+      SWFDEC_WARNING ("variables invalid at \"%s\"", variables);
+      break;
+    }
+    if (*variables != '&' && *variables != '\0') {
+      SWFDEC_WARNING ("variables not delimited with & at \"%s\"", variables);
+      g_free (name);
+      g_free (value);
+      break;
+    }
+    variables++;
+    string = JS_NewStringCopyZ (script->jscx, value);
+    if (string == NULL) {
+      g_free (name);
+      g_free (value);
+      SWFDEC_ERROR ("could not create string");
+      break;
+    }
+    val = STRING_TO_JSVAL (string);
+    if (!JS_SetProperty (script->jscx, object, name, &val)) {
+      g_free (name);
+      g_free (value);
+      SWFDEC_ERROR ("error setting property \"%s\"", name);
+      break;
+    }
+    SWFDEC_DEBUG ("Set variable \"%s\" to \"%s\"", name, value);
+    g_free (name);
+    g_free (value);
+  }
+}
+
diff --git a/libswfdec/swfdec_scriptable.h b/libswfdec/swfdec_scriptable.h
index 45190c4..0f57f11 100644
--- a/libswfdec/swfdec_scriptable.h
+++ b/libswfdec/swfdec_scriptable.h
@@ -61,6 +61,9 @@ gpointer		swfdec_scriptable_from_jsval	(
 							 jsval			val,
 							 GType			type);
 
+void			swfdec_scriptable_set_variables	(SwfdecScriptable *	script,
+							 const char *		variables);
+
 
 G_END_DECLS
 #endif
diff-tree 22b97a21348c7488830a599f1e0c4605e16367d0 (from 04a4777c1006f689e038ca48aa967456882f9f79)
Author: Benjamin Otte <otte at gnome.org>
Date:   Sat Feb 17 12:41:46 2007 +0100

    test unescaped chars

diff --git a/test/various/urlencode.c b/test/various/urlencode.c
index 6555675..1e35644 100644
--- a/test/various/urlencode.c
+++ b/test/various/urlencode.c
@@ -32,7 +32,10 @@ typedef struct {
 Test tests[] = {
   { "a=b", { "a" }, { "b" }, 1 },
   { "a=b&c=d", { "a", "c" }, { "b", "d" }, 2 },
-  { "owned=Your+Mom", { "owned" }, { "Your Mom" }, 1 }
+  { "owned=Your+Mom", { "owned" }, { "Your Mom" }, 1 },
+  { "numbers=0123456789&uppercase=ABCDEFGHIJKLMNOPQRSTUVWXYZ&lowercase=abcdefghijklmnopqrstuvwxyz&special+chars=.-_", 
+    { "numbers", "uppercase", "lowercase", "special chars" }, 
+    { "0123456789", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz", ".-_" }, 4 }
 };
 
 #define ERROR(...) G_STMT_START { \
diff-tree 04a4777c1006f689e038ca48aa967456882f9f79 (from a9cde2bc0e6cb770a79c9edd392a07ebbfd997cc)
Author: Benjamin Otte <otte at gnome.org>
Date:   Sat Feb 17 12:41:35 2007 +0100

    add -_. to nonescaped chars in x-www-form-urlencoded

diff --git a/libswfdec/swfdec_loader.c b/libswfdec/swfdec_loader.c
index 70027be..29ca92c 100644
--- a/libswfdec/swfdec_loader.c
+++ b/libswfdec/swfdec_loader.c
@@ -393,12 +393,14 @@ swfdec_loader_get_filename (SwfdecLoader
   return ret;
 }
 
+/* if speed ever gets an issue, use a 256 byte array instead of strchr */
+static const char *urlencode_unescaped="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.";
 static void
 swfdec_urlencode_append_string (GString *str, const char *s)
 {
   g_assert (s != NULL);
   while (*s) {
-    if (g_ascii_isalnum (*s))
+    if (strchr (urlencode_unescaped, *s))
       g_string_append_c (str, *s);
     else if (*s == ' ')
       g_string_append_c (str, '+');
@@ -414,7 +416,7 @@ swfdec_urldecode_one_string (const char 
   GString *ret = g_string_new ("");
 
   while (*s) {
-    if (g_ascii_isalnum (*s)) {
+    if (strchr (urlencode_unescaped, *s)) {
       g_string_append_c (ret, *s);
     } else if (*s == '+') {
       g_string_append_c (ret, ' ');
diff-tree a9cde2bc0e6cb770a79c9edd392a07ebbfd997cc (from 826758e8e3b45a7dd7f55d5e7891659da30d4daf)
Author: Benjamin Otte <otte at gnome.org>
Date:   Sat Feb 17 12:19:02 2007 +0100

    add missing print function for GetURL2

diff --git a/libswfdec/swfdec_script.c b/libswfdec/swfdec_script.c
index 9a9dd75..1439882 100644
--- a/libswfdec/swfdec_script.c
+++ b/libswfdec/swfdec_script.c
@@ -1823,6 +1823,27 @@ swfdec_action_print_define_function (gui
 }
 
 static char *
+swfdec_action_print_get_url2 (guint action, const guint8 *data, guint len)
+{
+  guint method;
+
+  if (len != 1) {
+    SWFDEC_ERROR ("GetURL2 requires 1 byte of data, not %u", len);
+    return NULL;
+  }
+  method = data[0] >> 6;
+  if (method == 3) {
+    SWFDEC_ERROR ("GetURL method 3 invalid");
+    method = 0;
+  }
+  if (method) {
+    SWFDEC_ERROR ("FIXME: implement encoding variables using %s", method == 1 ? "GET" : "POST");
+  }
+  return g_strdup_printf ("GetURL2%s%s%s", method == 0 ? "" : (method == 1 ? " GET" : " POST"),
+      data[0] & 2 ? " LoadTarget" : "", data[0] & 1 ? " LoadVariables" : "");
+}
+
+static char *
 swfdec_action_print_get_url (guint action, const guint8 *data, guint len)
 {
   SwfdecBits bits;
@@ -2134,7 +2155,7 @@ static const SwfdecActionSpec actions[25
   /* version 4 */
   [0x96] = { "Push", swfdec_action_print_push, 0, -1, { NULL, swfdec_action_push, swfdec_action_push, swfdec_action_push, swfdec_action_push } },
   [0x99] = { "Jump", swfdec_action_print_jump, 0, 0, { NULL, swfdec_action_jump, swfdec_action_jump, swfdec_action_jump, swfdec_action_jump } },
-  [0x9a] = { "GetURL2", NULL, 2, 0, { NULL, swfdec_action_get_url2, swfdec_action_get_url2, swfdec_action_get_url2, swfdec_action_get_url2 } },
+  [0x9a] = { "GetURL2", swfdec_action_print_get_url2, 2, 0, { NULL, swfdec_action_get_url2, swfdec_action_get_url2, swfdec_action_get_url2, swfdec_action_get_url2 } },
   /* version 5 */
   [0x9b] = { "DefineFunction", swfdec_action_print_define_function, 0, -1, { NULL, NULL, swfdec_action_define_function, swfdec_action_define_function, swfdec_action_define_function } },
   /* version 4 */
diff-tree 826758e8e3b45a7dd7f55d5e7891659da30d4daf (from d33393b8767f81772dee644af8bc7143e766e4bb)
Author: Benjamin Otte <otte at gnome.org>
Date:   Sat Feb 17 11:18:54 2007 +0100

    Add swfdec_player_set_loader_with_variables stub
    
    Also update configure.ac for updated API

diff --git a/configure.ac b/configure.ac
index 301a83a..2c45bf2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,7 +29,7 @@ if test x$SWFDEC_CVS = xyes ; then
   AS_COMPILER_FLAG(-Werror, GLOBAL_CFLAGS="$GLOBAL_CFLAGS -Werror")
 fi
 
-SWFDEC_LIBVERSION="1:1:0"
+SWFDEC_LIBVERSION="1:2:0"
 AC_SUBST(SWFDEC_LIBVERSION)
 AM_PROG_LIBTOOL
 
diff --git a/doc/swfdec-sections.txt b/doc/swfdec-sections.txt
index 3a93f97..43457d5 100644
--- a/doc/swfdec-sections.txt
+++ b/doc/swfdec-sections.txt
@@ -40,6 +40,7 @@ swfdec_init
 swfdec_player_new
 swfdec_player_new_from_file
 swfdec_player_set_loader
+swfdec_player_set_loader_with_variables
 swfdec_player_is_initialized
 swfdec_player_get_rate
 swfdec_player_get_image_size
diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index 4b29d28..cbdac1b 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -862,7 +862,7 @@ swfdec_player_invalidate (SwfdecPlayer *
 
 SwfdecRootMovie *
 swfdec_player_add_level_from_loader (SwfdecPlayer *player, guint depth,
-    SwfdecLoader *loader)
+    SwfdecLoader *loader, const char *variables)
 {
   SwfdecMovie *movie;
   SwfdecRootMovie *root;
@@ -979,12 +979,37 @@ swfdec_player_new (void)
  *
  * Sets the loader for the main data. This function only works if no loader has 
  * been set on @player yet.
+ * For details, see swfdec_player_set_loader_with_variables().
+ **/
+void
+swfdec_player_set_loader (SwfdecPlayer *player, SwfdecLoader *loader)
+{
+  g_return_if_fail (SWFDEC_IS_PLAYER (player));
+  g_return_if_fail (player->roots == NULL);
+  g_return_if_fail (SWFDEC_IS_LOADER (loader));
+
+  swfdec_player_set_loader_with_variables (player, loader, NULL);
+}
+
+/**
+ * swfdec_player_set_loader_with_variables:
+ * @player: a #SwfdecPlayer
+ * @loader: the loader to use for this player. Takes ownership of the given loader.
+ * @variables: a string that is checked to be in 'application/x-www-form-urlencoded'
+ *             syntax describing the arguments to set on the new player or NULL for
+ *             none.
+ *
+ * Sets the loader for the main data. This function only works if no loader has 
+ * been set on @player yet.
+ * If the @variables are set and validate, they will be set as properties on the 
+ * root movie. 
  * <note>If you want to capture events during the setup process, you want to 
  * connect your signal handlers before calling swfdec_player_set_loader() and
  * not use conveniencse functions such as swfdec_player_new_from_file().</note>
  **/
 void
-swfdec_player_set_loader (SwfdecPlayer *player, SwfdecLoader *loader)
+swfdec_player_set_loader_with_variables (SwfdecPlayer *player, SwfdecLoader *loader,
+    const char *variables)
 {
   SwfdecRootMovie *movie;
 
@@ -992,7 +1017,7 @@ swfdec_player_set_loader (SwfdecPlayer *
   g_return_if_fail (player->roots == NULL);
   g_return_if_fail (SWFDEC_IS_LOADER (loader));
 
-  movie = swfdec_player_add_level_from_loader (player, 0, loader);
+  movie = swfdec_player_add_level_from_loader (player, 0, loader, NULL);
   swfdec_loader_parse (loader);
 }
 
diff --git a/libswfdec/swfdec_player.h b/libswfdec/swfdec_player.h
index b960d9b..437d3ee 100644
--- a/libswfdec/swfdec_player.h
+++ b/libswfdec/swfdec_player.h
@@ -52,6 +52,10 @@ SwfdecPlayer *	swfdec_player_new_from_fi
 						 GError **	error);
 void		swfdec_player_set_loader	(SwfdecPlayer *	player,
 						 SwfdecLoader *	loader);
+void		swfdec_player_set_loader_with_variables 
+						(SwfdecPlayer *	player,
+						 SwfdecLoader *	loader,
+						 const char *	variables);
 
 gboolean	swfdec_player_is_initialized	(SwfdecPlayer *	player);
 guint		swfdec_player_get_next_event  	(SwfdecPlayer *	player);
diff --git a/libswfdec/swfdec_player_internal.h b/libswfdec/swfdec_player_internal.h
index 2da8ecc..2d2c6f9 100644
--- a/libswfdec/swfdec_player_internal.h
+++ b/libswfdec/swfdec_player_internal.h
@@ -128,7 +128,8 @@ void		swfdec_player_stop_all_sounds	(Swf
 SwfdecRootMovie *	swfdec_player_add_level_from_loader 
 						(SwfdecPlayer *		player,
 						 guint			depth,
-						 SwfdecLoader *		loader);
+						 SwfdecLoader *		loader,
+						 const char *		variables);
 void		swfdec_player_remove_level	(SwfdecPlayer *		player,
 						 guint			depth);
 void		swfdec_player_launch		(SwfdecPlayer *         player,
diff --git a/libswfdec/swfdec_root_movie.c b/libswfdec/swfdec_root_movie.c
index 9121560..473b49b 100644
--- a/libswfdec/swfdec_root_movie.c
+++ b/libswfdec/swfdec_root_movie.c
@@ -195,7 +195,7 @@ swfdec_root_movie_load (SwfdecRootMovie 
       } else {
 	SwfdecLoader *loader = swfdec_loader_load (root->loader, url);
 	if (loader) {
-	  SwfdecRootMovie *added = swfdec_player_add_level_from_loader (root->player, depth, loader);
+	  SwfdecRootMovie *added = swfdec_player_add_level_from_loader (root->player, depth, loader, NULL);
 	  swfdec_player_add_action (root->player, SWFDEC_MOVIE (added),
 	      swfdec_root_movie_do_parse, NULL);
 	} else {


More information about the Swfdec mailing list