Beispiel #1
0
static void
swfdec_load_object_stream_target_close (SwfdecStreamTarget *target,
    SwfdecStream *stream)
{
  SwfdecLoadObject *load_object = SWFDEC_LOAD_OBJECT (target);
  char *text;

  // get text
  text = swfdec_buffer_queue_pull_text (swfdec_stream_get_queue (stream), load_object->version);

  /* break reference to the loader */
  swfdec_stream_set_target (stream, NULL);
  load_object->loader = NULL;
  g_object_unref (stream);

  /* call finish */
  swfdec_sandbox_use (load_object->sandbox);
  if (text != NULL) {
    load_object->finish (load_object->target, 
	swfdec_as_context_give_string (swfdec_gc_object_get_context (load_object->target), text));
  } else {
    load_object->finish (load_object->target, SWFDEC_AS_STR_EMPTY);
  }
  swfdec_sandbox_unuse (load_object->sandbox);

  /* unroot */
  swfdec_player_unroot (SWFDEC_PLAYER (
	swfdec_gc_object_get_context (load_object->sandbox)), load_object);
}
Beispiel #2
0
static void
swfdec_load_object_load (SwfdecPlayer *player, gboolean allow, gpointer obj)
{
  SwfdecLoadObject *load = SWFDEC_LOAD_OBJECT (obj);

  if (!allow) {
    SWFDEC_WARNING ("SECURITY: no access to %s from %s",
	load->url, swfdec_url_get_url (load->sandbox->url));

    /* call finish */
    swfdec_sandbox_use (load->sandbox);
    load->finish (load->target, NULL);
    swfdec_sandbox_unuse (load->sandbox);

    /* unroot */
    swfdec_player_unroot (player, load);
    return;
  }

  load->loader = swfdec_player_load_with_headers (player, load->url,
      load->buffer, load->header_count, (const char **)load->header_names,
      (const char **)load->header_values);

  swfdec_stream_set_target (SWFDEC_STREAM (load->loader), SWFDEC_STREAM_TARGET (load));
  swfdec_loader_set_data_type (load->loader, SWFDEC_LOADER_DATA_TEXT);
}
static void
swfdec_xml_socket_stream_target_open (SwfdecStreamTarget *target, 
    SwfdecStream *stream)
{
  SwfdecXmlSocket *xml = SWFDEC_XML_SOCKET (target);
  SwfdecAsValue value;

  xml->open = TRUE;
  SWFDEC_AS_VALUE_SET_BOOLEAN (&value, TRUE);
  swfdec_sandbox_use (xml->sandbox);
  swfdec_as_object_call (xml->target, SWFDEC_AS_STR_onConnect, 1, &value, NULL);
  swfdec_sandbox_unuse (xml->sandbox);
}
Beispiel #4
0
static gboolean
swfdec_load_object_stream_target_parse (SwfdecStreamTarget *target,
    SwfdecStream *stream)
{
  SwfdecLoader *loader = SWFDEC_LOADER (stream);
  SwfdecLoadObject *load_object = SWFDEC_LOAD_OBJECT (target);

  if (load_object->progress != NULL) {
    swfdec_sandbox_use (load_object->sandbox);
    load_object->progress (load_object->target,
	swfdec_loader_get_loaded (loader), swfdec_loader_get_size (loader));
    swfdec_sandbox_unuse (load_object->sandbox);
  }
  return FALSE;
}
static void
swfdec_xml_socket_stream_target_close (SwfdecStreamTarget *target,
    SwfdecStream *stream)
{
  SwfdecXmlSocket *xml = SWFDEC_XML_SOCKET (target);

  if (swfdec_buffer_queue_get_depth (xml->queue)) {
    SWFDEC_FIXME ("data left in socket, what now?");
  }

  swfdec_sandbox_use (xml->sandbox);
  swfdec_as_object_call (xml->target, SWFDEC_AS_STR_onClose, 0, NULL, NULL);
  swfdec_sandbox_unuse (xml->sandbox);

  swfdec_xml_socket_ensure_closed (xml);
}
static void
swfdec_xml_socket_stream_target_error (SwfdecStreamTarget *target,
    SwfdecStream *stream)
{
  SwfdecXmlSocket *xml = SWFDEC_XML_SOCKET (target);

  swfdec_sandbox_use (xml->sandbox);
  if (xml->open) {
    SWFDEC_FIXME ("is onClose emitted on error?");
    swfdec_as_object_call (xml->target, SWFDEC_AS_STR_onClose, 0, NULL, NULL);
  } else {
    SwfdecAsValue value;

    SWFDEC_AS_VALUE_SET_BOOLEAN (&value, FALSE);
    swfdec_as_object_call (xml->target, SWFDEC_AS_STR_onConnect, 1, &value, NULL);
  }
  swfdec_sandbox_unuse (xml->sandbox);

  swfdec_xml_socket_ensure_closed (xml);
}
Beispiel #7
0
static void
swfdec_load_object_stream_target_error (SwfdecStreamTarget *target,
    SwfdecStream *stream)
{
  SwfdecLoader *loader = SWFDEC_LOADER (stream);
  SwfdecLoadObject *load_object = SWFDEC_LOAD_OBJECT (target);

  /* break reference to the loader */
  swfdec_stream_set_target (SWFDEC_STREAM (loader), NULL);
  load_object->loader = NULL;
  g_object_unref (loader);

  /* call finish */
  swfdec_sandbox_use (load_object->sandbox);
  load_object->finish (load_object->target, NULL);
  swfdec_sandbox_unuse (load_object->sandbox);

  /* unroot */
  swfdec_player_unroot (SWFDEC_PLAYER (
	swfdec_gc_object_get_context (load_object->sandbox)), load_object);
}
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;
}