void
swfdec_system_security_get_sandboxType (SwfdecAsContext *cx,
    SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
    SwfdecAsValue *ret)
{
  switch (swfdec_sandbox_get (SWFDEC_PLAYER (cx))->type) {
    case SWFDEC_SANDBOX_REMOTE:
      SWFDEC_AS_VALUE_SET_STRING (ret, SWFDEC_AS_STR_remote);
      break;

    case SWFDEC_SANDBOX_LOCAL_FILE:
      SWFDEC_AS_VALUE_SET_STRING (ret, SWFDEC_AS_STR_localWithFile);
      break;

    case SWFDEC_SANDBOX_LOCAL_NETWORK:
      SWFDEC_AS_VALUE_SET_STRING (ret, SWFDEC_AS_STR_localWithNetwork);
      break;

    case SWFDEC_SANDBOX_LOCAL_TRUSTED:
      SWFDEC_AS_VALUE_SET_STRING (ret, SWFDEC_AS_STR_localTrusted);
      break;

    case SWFDEC_SANDBOX_NONE:
    default:
      g_return_if_reached ();
  }
}
void
swfdec_system_query (SwfdecAsContext *cx, SwfdecAsObject *object,
    guint argc, SwfdecAsValue *argv, SwfdecAsValue *retval)
{
  SwfdecPlayer *player = SWFDEC_PLAYER (cx);
  SwfdecAsValue val;
  guint i;
  GString *server;

  if (object == NULL) {
    SWFDEC_WARNING ("no this object in Query()");
    return;
  }

  server = g_string_new ("");
  for (i = 0; i < G_N_ELEMENTS (queries); i++) {
    queries[i].get (player, &val);
    swfdec_as_object_set_variable (object, queries[i].name, &val);
    if (queries[i].name == SWFDEC_AS_STR_screenResolutionY) {
      g_string_append_printf (server, "x%d", (int) SWFDEC_AS_VALUE_GET_NUMBER (val));
    } else if (queries[i].name == SWFDEC_AS_STR_pixelAspectRatio) {
      char buffer[10];
      g_ascii_formatd (buffer, sizeof (buffer), "%.1f",
	  SWFDEC_AS_VALUE_GET_NUMBER (val));
      g_string_append (server, "&AR=");
      g_string_append (server, buffer);
    } else if (queries[i].name == SWFDEC_AS_STR_manufacturer) {
      char *s = swfdec_as_string_escape (cx, player->priv->system->server_manufacturer);
      g_string_append_printf (server, "&M=%s", s);
      g_free (s);
    } else {
      g_assert (queries[i].server_string);
      if (i > 0)
	g_string_append_c (server, '&');
      g_string_append (server, queries[i].server_string);
      g_string_append_c (server, '=');
      if (SWFDEC_AS_VALUE_IS_BOOLEAN (val)) {
	g_string_append_c (server, SWFDEC_AS_VALUE_GET_BOOLEAN (val) ? 't' : 'f');
      } else if (SWFDEC_AS_VALUE_IS_NUMBER (val)) {
	g_string_append_printf (server, "%d", (int) SWFDEC_AS_VALUE_GET_NUMBER (val));
      } else if (SWFDEC_AS_VALUE_IS_STRING (val)) {
	char *s = swfdec_as_string_escape (cx, SWFDEC_AS_VALUE_GET_STRING (val));
	g_string_append (server, s);
	g_free (s);
      } else {
	g_assert_not_reached ();
      }
    }
  }
  SWFDEC_AS_VALUE_SET_STRING (&val, swfdec_as_context_give_string (cx, g_string_free (server, FALSE)));
  swfdec_as_object_set_variable (object, SWFDEC_AS_STR_serverString, &val);
}
Beispiel #3
0
static gboolean
swfdec_amf_parse_string (SwfdecAsContext *context, SwfdecBits *bits, SwfdecAsValue *val)
{
  guint len = swfdec_bits_get_bu16 (bits);
  char *s;
  
  /* FIXME: the supplied version is likely incorrect */
  s = swfdec_bits_get_string_length (bits, len, context->version);
  if (s == NULL)
    return FALSE;
  SWFDEC_AS_VALUE_SET_STRING (val, swfdec_as_context_give_string (context, s));
  return TRUE;
}
static gboolean
swfdec_xml_socket_stream_target_parse (SwfdecStreamTarget *target,
    SwfdecStream *stream)
{
  SwfdecXmlSocket *xml = SWFDEC_XML_SOCKET (target);
  SwfdecBufferQueue *queue;
  SwfdecBuffer *buffer;
  gsize len;

  /* parse until next 0 byte or take everything */
  queue = swfdec_stream_get_queue (stream);
  while ((buffer = swfdec_buffer_queue_peek_buffer (queue))) {
    guchar *nul = memchr (buffer->data, 0, buffer->length);
    
    len = nul ? (gsize) (nul - buffer->data + 1) : buffer->length;
    g_assert (len > 0);
    swfdec_buffer_unref (buffer);
    buffer = swfdec_buffer_queue_pull (queue, len);
    swfdec_buffer_queue_push (xml->queue, buffer);
    if (nul) {
      len = swfdec_buffer_queue_get_depth (xml->queue);
      g_assert (len > 0);
      buffer = swfdec_buffer_queue_pull (xml->queue, len);
      if (!g_utf8_validate ((char *) buffer->data, len, NULL)) {
	SWFDEC_FIXME ("invalid utf8 sent through socket, what now?");
      } else {
	SwfdecAsValue val;

	SWFDEC_AS_VALUE_SET_STRING (&val, swfdec_as_context_get_string (
	      swfdec_gc_object_get_context (xml), (char *) buffer->data));
	swfdec_sandbox_use (xml->sandbox);
	swfdec_as_object_call (xml->target, SWFDEC_AS_STR_onData, 1, &val, NULL);
	swfdec_sandbox_unuse (xml->sandbox);
      }
    }
  }
  return FALSE;
}
Beispiel #5
0
void
swfdec_as_array_join (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
    SwfdecAsValue *argv, SwfdecAsValue *ret)
{
  int i;
  const char *var, *str, *sep;
  SwfdecAsValue val;

  if (object == NULL || SWFDEC_IS_MOVIE (object))
    return;

  if (argc > 0) {
    sep = swfdec_as_value_to_string (cx, &argv[0]);
  } else {
    sep = SWFDEC_AS_STR_COMMA;
  }

  // note: we don't cache length
  if (swfdec_as_array_length (object) > 0) {
    GString *string;
    swfdec_as_object_get_variable (object, SWFDEC_AS_STR_0, &val);
    str = swfdec_as_value_to_string (cx, &val);
    string = g_string_new (str);
    for (i = 1; i < swfdec_as_array_length (object); i++) {
      var = swfdec_as_integer_to_string (cx, i);
      swfdec_as_object_get_variable (object, var, &val);
      var = swfdec_as_value_to_string (cx, &val);
      g_string_append (string, sep);
      g_string_append (string, var);
    }
    str = swfdec_as_context_give_string (cx, g_string_free (string, FALSE));
  } else {
    str = SWFDEC_AS_STR_EMPTY;
  }

  SWFDEC_AS_VALUE_SET_STRING (ret, str);
}
static void
swfdec_system_player_type (SwfdecPlayer *player, SwfdecAsValue *ret)
{
  SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_context_get_string (
	SWFDEC_AS_CONTEXT (player), player->priv->system->player_type));
}
Beispiel #7
0
int
main (int argc, char **argv)
{
    char *script_filename = NULL;
    GError *error = NULL;
    SwfdecAsContext *context;
    SwfdecAsObject *array;
    SwfdecScript *script;
    SwfdecAsValue val;
    int i, ret;
    gboolean dump = FALSE;
    gboolean no_check = FALSE, only_check = FALSE;

    GOptionEntry options[] = {
        { "dump", 'd', 0, G_OPTION_ARG_NONE, &dump, "dump informative output on failure", FALSE },
        { "no-check", 0, 0, G_OPTION_ARG_NONE, &no_check, "don't check if the system is ok for running the testsuite", FALSE },
        { "self-check", 0, 0, G_OPTION_ARG_NONE, &only_check, "run a system check and exit", FALSE },
        { "player", 'p', 0, G_OPTION_ARG_STRING, &swfdec_test_plugin_name, "player to test", "NAME" },
        { "script", 's', 0, G_OPTION_ARG_STRING, &script_filename, "script to execute if not ./default.sts", "FILENAME" },
        { NULL }
    };
    GOptionContext *ctx;

    /* set the right warning levels */
    g_log_set_always_fatal (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
    /* by default get rid of the loads of warnings the tests produce */
    g_setenv ("SWFDEC_DEBUG", "2", FALSE);

    g_thread_init (NULL);
    swfdec_init ();

    ctx = g_option_context_new ("");
    g_option_context_add_main_entries (ctx, options, "options");
    g_option_context_parse (ctx, &argc, &argv, &error);
    g_option_context_free (ctx);

    if (error) {
        g_printerr ("ERROR: wrong command line arguments: %s\n", error->message);
        g_error_free (error);
        return EXIT_FAILURE;
    }

    if (only_check || !no_check) {
        gboolean result = check_system (only_check);
        if (!result) {
            g_print ("ERROR: System checked failed, aborting. Use --no-check to disable.\n");
            return 1;
        } else if (only_check) {
            return 0;
        }
    }
    g_assert (!only_check);

    /* allow env vars instead of options - eases running make check with different settings */
    if (swfdec_test_plugin_name == NULL)
        swfdec_test_plugin_name = g_strdup (g_getenv ("SWFDEC_TEST_PLAYER"));

    script = load_script (script_filename);
    g_free (script_filename);
    if (script == NULL)
        return EXIT_FAILURE;

    context = g_object_new (SWFDEC_TYPE_AS_CONTEXT, NULL);
    swfdec_as_context_startup (context);

    SWFDEC_AS_VALUE_SET_BOOLEAN (&val, dump);
    swfdec_as_object_set_variable (context->global,
                                   swfdec_as_context_get_string (context, "dump"), &val);

    swfdec_test_function_init_context (context);
    swfdec_as_context_run_init_script (context, swfdec_test_initialize,
                                       sizeof (swfdec_test_initialize), SWFDEC_TEST_VERSION);

    array = swfdec_as_array_new (context);
    if (array == NULL) {
        g_print ("ERROR: Not enough memory");
        return EXIT_FAILURE;
    }
    if (argc < 2) {
        GDir *dir;
        const char *file;
        dir = g_dir_open (".", 0, NULL);
        while ((file = g_dir_read_name (dir))) {
            if (!g_str_has_suffix (file, ".swf"))
                continue;
            SWFDEC_AS_VALUE_SET_STRING (&val, swfdec_as_context_get_string (context, file));
            swfdec_as_array_push (SWFDEC_AS_ARRAY (array), &val);
        }
        g_dir_close (dir);
    } else {
        for (i = 1; i < argc; i++) {
            SWFDEC_AS_VALUE_SET_STRING (&val, swfdec_as_context_get_string (context, argv[i]));
            swfdec_as_array_push (SWFDEC_AS_ARRAY (array), &val);
        }
    }
    SWFDEC_AS_VALUE_SET_OBJECT (&val, array);
    swfdec_as_object_set_variable (context->global,
                                   swfdec_as_context_get_string (context, "filenames"), &val);
    swfdec_as_object_run (context->global, script);
    if (swfdec_as_context_catch (context, &val)) {
        g_print ("ERROR: %s\n", swfdec_as_value_to_string (context, &val));
        ret = EXIT_FAILURE;
    } else {
        g_print ("SUCCESS\n");
        ret = EXIT_SUCCESS;
    }

    swfdec_script_unref (script);
    g_object_unref (context);

    return ret;
}