Exemplo n.º 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);
}
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;
}