Пример #1
0
/**
 * json_builder_begin_array:
 * @builder: a #JsonBuilder
 *
 * Opens a subarray inside the given @builder. When done adding members to
 * the subarray, json_builder_end_array() must be called.
 *
 * Can be called for first or only if the call is associated to an object member
 * or an array element.
 *
 * Return value: (transfer none): the #JsonBuilder, or %NULL if the call was inconsistent
 */
JsonBuilder *
json_builder_begin_array (JsonBuilder *builder)
{
  JsonArray *array;
  JsonBuilderState *state;
  JsonBuilderState *cur_state;

  g_return_val_if_fail (JSON_IS_BUILDER (builder), NULL);
  g_return_val_if_fail (builder->priv->root == NULL, NULL);
  g_return_val_if_fail (g_queue_is_empty (builder->priv->stack) || json_builder_is_valid_add_mode (builder), NULL);

  array = json_array_new ();
  cur_state = g_queue_peek_head (builder->priv->stack);
  if (cur_state)
    {
      switch (cur_state->mode)
        {
        case JSON_BUILDER_MODE_ARRAY:
          json_array_add_array_element (cur_state->data.array, json_array_ref (array));
          break;

        case JSON_BUILDER_MODE_MEMBER:
          json_object_set_array_member (cur_state->data.object, cur_state->member_name, json_array_ref (array));
          g_free (cur_state->member_name);
          cur_state->member_name = NULL;
          cur_state->mode = JSON_BUILDER_MODE_OBJECT;
          break;

        default:
          g_assert_not_reached ();
        }
    }

  state = g_slice_new (JsonBuilderState);
  state->data.array = array;
  state->mode = JSON_BUILDER_MODE_ARRAY;
  g_queue_push_head (builder->priv->stack, state);

  return builder;
}
Пример #2
0
static void client_write_deferred(struct client *client)
{
    size_t ret;

    while (!g_queue_is_empty(client->deferred_send)) {
        struct deferred_buffer *buf =
            g_queue_peek_head(client->deferred_send);

        assert(buf->size > 0);
        assert(buf->size <= client->deferred_bytes);

        ret = client_write_deferred_buffer(client, buf);
        if (ret == 0)
            break;

        if (ret < buf->size) {
            assert(client->deferred_bytes >= (size_t)ret);
            client->deferred_bytes -= ret;
            buf->size -= ret;
            memmove(buf->data, buf->data + ret, buf->size);
            break;
        } else {
            size_t decr = sizeof(*buf) -
                          sizeof(buf->data) + buf->size;

            assert(client->deferred_bytes >= decr);
            client->deferred_bytes -= decr;
            g_free(buf);
            g_queue_pop_head(client->deferred_send);
        }

        client->lastTime = time(NULL);
    }

    if (g_queue_is_empty(client->deferred_send)) {
        g_debug("[%u] buffer empty %lu", client->num,
                (unsigned long)client->deferred_bytes);
        assert(client->deferred_bytes == 0);
    }
}
Пример #3
0
static gboolean
xmms_ipc_client_write_cb (GIOChannel *iochan,
                          GIOCondition cond,
                          gpointer data)
{
	xmms_ipc_client_t *client = data;
	bool disconnect = FALSE;

	g_return_val_if_fail (client, FALSE);

	while (TRUE) {
		xmms_ipc_msg_t *msg;

		g_mutex_lock (client->lock);
		msg = g_queue_peek_head (client->out_msg);
		g_mutex_unlock (client->lock);

		if (!msg)
			break;

		if (!xmms_ipc_msg_write_transport (msg,
		                                   client->transport,
		                                   &disconnect)) {
			if (disconnect) {
				break;
			} else {
				/* try sending again later */
				return TRUE;
			}
		}

		g_mutex_lock (client->lock);
		g_queue_pop_head (client->out_msg);
		g_mutex_unlock (client->lock);

		xmms_ipc_msg_destroy (msg);
	}

	return FALSE;
}
Пример #4
0
void
next (int state, int is_skip) {
    struct hemp_playlist_entry *e;
    static int back_count = 0;
    time_t now;

    time(&now);

    gst_element_set_state (GST_ELEMENT (pipeline),
                           GST_STATE_NULL);
    if (current) {
        current->last_played = now;
        g_queue_push_tail(hotlist, current);
    }

    e = g_queue_peek_head(hotlist);
    if (e && (e->last_played + NO_REPEAT_TIME < now)) {
        current = g_queue_pop_head(hotlist);
    } else if (!g_queue_is_empty(coldlist)) {
        do {
            current = g_queue_pop_head(coldlist);
        } while (current->last_played > 0);
        /* Need to do it this way in case a coldlist entry 
         * is also on the hotlist and has already been played */
    } else if (e && is_skip) {
        current = g_queue_pop_head(hotlist); /* Never skip to silence. */
    } else {
        drop_pipeline(0);
        return;
    }

    current->start_count++;
    g_object_set (G_OBJECT (pipeline), "uri", current->uri, NULL);
    if (state == HEMP_STATE_PAUSED) {
        gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);
    } else {
        gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
    }
}
Пример #5
0
/* create a list of features from all tracks
*/
int tracks_head_features (tracker2_data_t *tracks, navlcm_feature_list_t *fs)
{   
    int i=0;
    fs->num = g_queue_get_length (tracks->data);
    if (fs->num == 0) {
        fs->el = NULL;
        return 0;
    }

    fs->el = (navlcm_feature_t*)malloc(fs->num*sizeof(navlcm_feature_t));

    for (GList *iter=g_queue_peek_head_link (tracks->data);iter;iter=iter->next) {
        track2_t *t = (track2_t*)iter->data;
        navlcm_feature_t *f = navlcm_feature_t_copy ((navlcm_feature_t*)g_queue_peek_head (t->data));
        fs->el[i] = *f;
        fs->el[i].index = i;
        fs->desc_size = f->size;
        free (f);
        i++;
    }

    return 0;
}
Пример #6
0
static void
on_tag_list_command_data_arrived (AnjutaCommand *command,
                                  GtkListStore *push_tag_model)
{
    GQueue *output;
    gchar *name;
    GtkTreeIter iter;

    output = git_raw_output_command_get_output (GIT_RAW_OUTPUT_COMMAND (command));

    while (g_queue_peek_head (output))
    {
        name = g_queue_pop_head (output);

        gtk_list_store_append (push_tag_model, &iter);
        gtk_list_store_set (push_tag_model, &iter,
                            COL_SELECTED, FALSE,
                            COL_NAME, name,
                            -1);

        g_free (name);
    }
}
Пример #7
0
void
on_status_command_data_arrived (AnjutaCommand *command, 
								AnjutaVcsStatusTreeView *tree_view)
{
	GQueue *status_queue;
	SvnStatus *status;
	gchar *path;
	
	status_queue = svn_status_command_get_status_queue (SVN_STATUS_COMMAND (command));
	
	while (g_queue_peek_head (status_queue))
	{
		status = g_queue_pop_head (status_queue);
		path = svn_status_get_path (status);
		
		anjuta_vcs_status_tree_view_add (tree_view, path, 
								  svn_status_get_vcs_status (status),
								  FALSE);
		
		svn_status_destroy (status);
		g_free (path);
	}
}
Пример #8
0
static guint64
get_buffer_level (RTPJitterBuffer * jbuf)
{
  GstBuffer *high_buf, *low_buf;
  guint64 level;

  high_buf = g_queue_peek_head (jbuf->packets);
  low_buf = g_queue_peek_tail (jbuf->packets);

  if (!high_buf || !low_buf || high_buf == low_buf) {
    level = 0;
  } else {
    guint64 high_ts, low_ts;

    high_ts = GST_BUFFER_TIMESTAMP (high_buf);
    low_ts = GST_BUFFER_TIMESTAMP (low_buf);

    if (high_ts > low_ts)
      level = high_ts - low_ts;
    else
      level = 0;
  }
  return level;
}
int
main (void)
{
  Graph *test_graph = graph_new ();

  GraphNode *a = graph_add_node (test_graph, NULL);
  GraphNode *b = graph_add_node (test_graph, NULL);
  GraphNode *c = graph_add_node (test_graph, NULL);
  GraphNode *c1 = graph_add_node (test_graph, NULL);
  GraphNode *c2 = graph_add_node (test_graph, NULL);
  GraphNode *c11 = graph_add_node (test_graph, NULL);
  GraphNode *d = graph_add_node (test_graph, NULL);

  GraphEdge *ab = graph_add_edge (test_graph, a, b, NULL);
  GraphEdge *bc = graph_add_edge (test_graph, b, c, NULL);
  GraphEdge *cd = graph_add_edge (test_graph, c, d, NULL);
  GraphEdge *da = graph_add_edge (test_graph, d, a, NULL);

  graph_add_edge (test_graph, c, c1, NULL);
  graph_add_edge (test_graph, c1, c11, NULL);
  graph_add_edge (test_graph, c, c2, NULL);

  graph_dump_by_edges (test_graph, "test_graph.dot", NULL);

  GQueue *path;
  gboolean result = graph_node_in_cycle (test_graph, a, &path);
  g_assert (result);
  g_assert (g_queue_peek_head (path) == da);
  g_assert (g_queue_peek_nth (path, 1) == cd);
  g_assert (g_queue_peek_nth (path, 2) == bc);
  g_assert (g_queue_peek_tail (path) == ab);

  g_queue_free (path);

  exit (EXIT_SUCCESS);
}
Пример #10
0
gboolean g_attrib_cancel(GAttrib *attrib, guint id)
{
	GList *l;
	struct command *cmd;

	if (attrib == NULL || attrib->queue == NULL)
		return FALSE;

	l = g_queue_find_custom(attrib->queue, GUINT_TO_POINTER(id),
							command_cmp_by_id);
	if (l == NULL)
		return FALSE;

	cmd = l->data;

	if (cmd == g_queue_peek_head(attrib->queue) && cmd->sent)
		cmd->func = NULL;
	else {
		g_queue_remove(attrib->queue, cmd);
		command_destroy(cmd);
	}

	return TRUE;
}
Пример #11
0
static gboolean can_write_data(GIOChannel *io, GIOCondition cond,
								gpointer data)
{
	struct _GAttrib *attrib = data;
	struct command *cmd;
	GError *gerr = NULL;
	gsize len;
	GIOStatus iostat;

	if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL))
		return FALSE;

	cmd = g_queue_peek_head(attrib->queue);
	if (cmd == NULL)
		return FALSE;

	iostat = g_io_channel_write_chars(io, (gchar *) cmd->pdu, cmd->len,
								&len, &gerr);
	if (iostat != G_IO_STATUS_NORMAL)
		return FALSE;

	if (cmd->expected == 0) {
		g_queue_pop_head(attrib->queue);
		command_destroy(cmd);

		return TRUE;
	}

	cmd->sent = TRUE;

	if (attrib->timeout_watch == 0)
		attrib->timeout_watch = g_timeout_add_seconds(GATT_TIMEOUT,
						disconnect_timeout, attrib);

	return FALSE;
}
Пример #12
0
static void
gum_duk_debug_session_on_write_all_ready (GObject * source_object,
                                          GAsyncResult * res,
                                          GumDukDebugSession * self)
{
  GBytes * bytes;

  if (!g_output_stream_write_all_finish (self->output, res, NULL, NULL))
    return; /* read will fail */

  g_bytes_unref (g_queue_pop_head (self->outgoing));

  bytes = g_queue_peek_head (self->outgoing);
  if (bytes != NULL)
  {
    g_output_stream_write_all_async (self->output,
        g_bytes_get_data (bytes, NULL),
        g_bytes_get_size (bytes),
        G_PRIORITY_DEFAULT,
        self->cancellable,
        (GAsyncReadyCallback) gum_duk_debug_session_on_write_all_ready,
        self);
  }
}
Пример #13
0
APULSE_EXPORT
int
pa_mainloop_iterate(pa_mainloop *m, int block, int *retval)
{
    trace_info("F %s m=%p, block=%d\n", __func__, m, block);

    int err;
    int timeout = 1000;

    if (g_queue_peek_head(m->queue))
        timeout = 10;

    err = pa_mainloop_prepare(m, timeout);
    if (err < 0)
        return err;

    err = pa_mainloop_poll(m);
    if (err < 0)
        return err;

    err = pa_mainloop_dispatch(m);

    return err;
}
Пример #14
0
static gboolean
on_response_output (GObject *pollable,
                    gpointer user_data)
{
  CockpitWebResponse *self = user_data;
  GError *error = NULL;
  const guint8 *data;
  GBytes *block;
  gssize count;
  gsize len;

  block = g_queue_peek_head (self->queue);
  if (block)
    {
      data = g_bytes_get_data (block, &len);
      g_assert (len == 0 || self->partial_offset < len);
      data += self->partial_offset;
      len -= self->partial_offset;

      if (len > 0)
        {
          count = g_pollable_output_stream_write_nonblocking (self->out, data, len,
                                                              NULL, &error);
        }
      else
        {
          count = 0;
        }

      if (count < 0)
        {
          if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
            {
              g_error_free (error);
              return TRUE;
            }

          if (!cockpit_web_should_suppress_output_error (self->logname, error))
            g_message ("%s: couldn't write web output: %s", self->logname, error->message);

          self->failed = TRUE;
          cockpit_web_response_done (self);

          g_error_free (error);
          return FALSE;
        }

      if (count == len)
        {
          g_debug ("%s: sent %d bytes", self->logname, (int)len);
          self->partial_offset = 0;
          g_queue_pop_head (self->queue);
          g_bytes_unref (block);
        }
      else
        {
          g_debug ("%s: sent %d partial", self->logname, (int)count);
          g_assert (count < len);
          self->partial_offset += count;
        }
      return TRUE;
    }
  else
    {
      g_source_destroy (self->source);
      g_source_unref (self->source);
      self->source = NULL;

      if (self->complete)
        {
          g_debug ("%s: complete flushing output", self->logname);
          g_output_stream_flush_async (G_OUTPUT_STREAM (self->out), G_PRIORITY_DEFAULT,
                                       NULL, on_output_flushed, g_object_ref (self));
        }

      return FALSE;
    }
}
Пример #15
0
/* thumbnail_thread is invoked as a separate thread to to make thumbnails. */
static gpointer
thumbnail_thread_start (gpointer data)
{
	NautilusThumbnailInfo *info = NULL;
	GdkPixbuf *pixbuf;
	time_t current_orig_mtime = 0;
	time_t current_time;
	GList *node;

	/* We loop until there are no more thumbails to make, at which point
	   we exit the thread. */
	for (;;) {
#ifdef DEBUG_THUMBNAILS
		g_message ("(Thumbnail Thread) Locking mutex\n");
#endif
		pthread_mutex_lock (&thumbnails_mutex);

		/*********************************
		 * MUTEX LOCKED
		 *********************************/

		/* Pop the last thumbnail we just made off the head of the
		   list and free it. I did this here so we only have to lock
		   the mutex once per thumbnail, rather than once before
		   creating it and once after.
		   Don't pop the thumbnail off the queue if the original file
		   mtime of the request changed. Then we need to redo the thumbnail.
		*/
		if (currently_thumbnailing &&
		    currently_thumbnailing->original_file_mtime == current_orig_mtime) {
			g_assert (info == currently_thumbnailing);
			node = g_hash_table_lookup (thumbnails_to_make_hash, info->image_uri);
			g_assert (node != NULL);
			g_hash_table_remove (thumbnails_to_make_hash, info->image_uri);
			free_thumbnail_info (info);
			g_queue_delete_link ((GQueue *)&thumbnails_to_make, node);
		}
		currently_thumbnailing = NULL;

		/* If there are no more thumbnails to make, reset the
		   thumbnail_thread_is_running flag, unlock the mutex, and
		   exit the thread. */
		if (g_queue_is_empty ((GQueue *)&thumbnails_to_make)) {
#ifdef DEBUG_THUMBNAILS
			g_message ("(Thumbnail Thread) Exiting\n");
#endif
			thumbnail_thread_is_running = FALSE;
			pthread_mutex_unlock (&thumbnails_mutex);
			pthread_exit (NULL);
		}

		/* Get the next one to make. We leave it on the list until it
		   is created so the main thread doesn't add it again while we
		   are creating it. */
		info = g_queue_peek_head ((GQueue *)&thumbnails_to_make);
		currently_thumbnailing = info;
		current_orig_mtime = info->original_file_mtime;
		/*********************************
		 * MUTEX UNLOCKED
		 *********************************/

#ifdef DEBUG_THUMBNAILS
		g_message ("(Thumbnail Thread) Unlocking mutex\n");
#endif
		pthread_mutex_unlock (&thumbnails_mutex);

		time (&current_time);

		/* Don't try to create a thumbnail if the file was modified recently.
		   This prevents constant re-thumbnailing of changing files. */ 
		if (current_time < current_orig_mtime + THUMBNAIL_CREATION_DELAY_SECS &&
		    current_time >= current_orig_mtime) {
#ifdef DEBUG_THUMBNAILS
			g_message ("(Thumbnail Thread) Skipping: %s\n",
				   info->image_uri);
#endif
			/* Reschedule thumbnailing via a change notification */
			g_timeout_add_seconds (1, thumbnail_thread_notify_file_changed,
				       g_strdup (info->image_uri));
 			continue;
		}

		/* Create the thumbnail. */
#ifdef DEBUG_THUMBNAILS
		g_message ("(Thumbnail Thread) Creating thumbnail: %s\n",
			   info->image_uri);
#endif

		pixbuf = gnome_desktop_thumbnail_factory_generate_thumbnail (thumbnail_factory,
									     info->image_uri,
									     info->mime_type);

		if (pixbuf) {
			gnome_desktop_thumbnail_factory_save_thumbnail (thumbnail_factory,
									pixbuf,
									info->image_uri,
									current_orig_mtime);
			g_object_unref (pixbuf);
		} else {
			gnome_desktop_thumbnail_factory_create_failed_thumbnail (thumbnail_factory, 
										 info->image_uri,
										 current_orig_mtime);
		}
		/* We need to call nautilus_file_changed(), but I don't think that is
		   thread safe. So add an idle handler and do it from the main loop. */
		g_idle_add_full (G_PRIORITY_HIGH_IDLE,
				 thumbnail_thread_notify_file_changed,
				 g_strdup (info->image_uri), NULL);
	}
}
Пример #16
0
static gboolean
msn_soap_connection_run(gpointer data)
{
	MsnSoapConnection *conn = data;
	MsnSoapRequest *req = g_queue_peek_head(conn->queue);

	conn->run_timer = 0;

	if (req) {
		if (conn->ssl == NULL) {
			conn->ssl = purple_ssl_connect(conn->session->account, conn->host,
				443, msn_soap_connected_cb, msn_soap_error_cb, conn);
		} else if (conn->connected) {
			int len = -1;
			char *body = xmlnode_to_str(req->message->xml, &len);
			GSList *iter;

			g_queue_pop_head(conn->queue);

			conn->buf = g_string_new("");

			g_string_append_printf(conn->buf,
				"POST /%s HTTP/1.1\r\n"
				"SOAPAction: %s\r\n"
				"Content-Type:text/xml; charset=utf-8\r\n"
				"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n"
				"Accept: */*\r\n"
				"Host: %s\r\n"
				"Content-Length: %d\r\n"
				"Connection: Keep-Alive\r\n"
				"Cache-Control: no-cache\r\n",
				req->path, req->message->action ? req->message->action : "",
				conn->host, len);

			for (iter = req->message->headers; iter; iter = iter->next) {
				g_string_append(conn->buf, (char *)iter->data);
				g_string_append(conn->buf, "\r\n");
			}

			g_string_append(conn->buf, "\r\n");
			g_string_append(conn->buf, body);

			if (req->secure && !purple_debug_is_unsafe())
				purple_debug_misc("soap", "Sending secure request.\n");
			else
				purple_debug_misc("soap", "%s\n", conn->buf->str);

			conn->handled_len = 0;
			conn->current_request = req;

			if (conn->event_handle)
				purple_input_remove(conn->event_handle);
			conn->event_handle = purple_input_add(conn->ssl->fd,
				PURPLE_INPUT_WRITE, msn_soap_write_cb, conn);
			if (!msn_soap_write_cb_internal(conn, conn->ssl->fd, PURPLE_INPUT_WRITE, TRUE)) {
				/* Not connected => reconnect and retry */
				purple_debug_info("soap", "not connected, reconnecting\n");

				conn->connected = FALSE;
				conn->current_request = NULL;
				msn_soap_connection_sanitize(conn, FALSE);

				g_queue_push_head(conn->queue, req);
				conn->run_timer = purple_timeout_add(0, msn_soap_connection_run, conn);
			}

			g_free(body);
		}
	}

	return FALSE;
}
Пример #17
0
queue_node* queue_peek_head(void)
{
	return g_queue_peek_head(queue);
}
static void
gst_insert_bin_block_pad_unlock (GstInsertBin * self)
{
  struct ChangeData *data;
  GstPad *pad;
  GstPadProbeType probetype;

again:

  data = g_queue_peek_head (&self->priv->change_queue);
  if (!data) {
    GST_OBJECT_UNLOCK (self);
    return;
  }

  if (data->action == GST_INSERT_BIN_ACTION_ADD &&
      !validate_element (self, data->element))
    goto error;

  if (data->action == GST_INSERT_BIN_ACTION_ADD) {
    if (data->sibling) {
      if (data->direction == DIRECTION_BEFORE)
        pad = get_single_pad (data->sibling, GST_PAD_SINK);
      else
        pad = get_single_pad (data->sibling, GST_PAD_SRC);
    } else {
      if (data->direction == DIRECTION_BEFORE)
        pad = (GstPad *)
            gst_proxy_pad_get_internal (GST_PROXY_PAD (self->priv->srcpad));
      else
        pad = (GstPad *)
            gst_proxy_pad_get_internal (GST_PROXY_PAD (self->priv->sinkpad));
    }

    if (!pad) {
      GST_WARNING_OBJECT (self, "Can not obtain a sibling pad to block"
          " before adding");
      goto error;
    }

    if (!is_right_direction_for_block (pad)) {
      GstPad *peer = gst_pad_get_peer (pad);

      if (peer) {
        gst_object_unref (pad);
        pad = peer;
      }
    }
  } else {
    GstPad *element_pad;

    element_pad = get_single_pad (data->element, GST_PAD_SINK);
    if (!element_pad) {
      GST_WARNING_OBJECT (self, "Can not obtain the element's sink pad");
      goto error;
    }

    if (!is_right_direction_for_block (element_pad)) {
      pad = gst_pad_get_peer (element_pad);
    } else {
      gst_object_unref (element_pad);

      element_pad = get_single_pad (data->element, GST_PAD_SRC);
      if (!element_pad) {
        GST_WARNING_OBJECT (self, "Can not obtain the element's src pad");
        goto error;
      }

      pad = gst_pad_get_peer (element_pad);
    }
    gst_object_unref (element_pad);

    if (!pad) {
      GST_WARNING_OBJECT (self, "Can not obtain a sibling pad for removing");
      goto error;
    }
  }

  if (GST_PAD_IS_SRC (pad))
    probetype = GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM;
  else
    probetype = GST_PAD_PROBE_TYPE_BLOCK_UPSTREAM;

  GST_OBJECT_UNLOCK (self);
  gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_IDLE | probetype, pad_blocked_cb,
      self, NULL);
  gst_object_unref (pad);
  return;

error:
  g_queue_pop_head (&self->priv->change_queue);
  gst_insert_bin_change_data_complete (self, data, FALSE);
  goto again;
}
static gboolean
empe_inlinepgp_encrypted_parse (EMailParserExtension *extension,
                                EMailParser *parser,
                                CamelMimePart *part,
                                GString *part_id,
                                GCancellable *cancellable,
                                GQueue *out_mail_parts)
{
	CamelCipherContext *cipher;
	CamelCipherValidity *valid;
	CamelMimePart *opart;
	CamelDataWrapper *dw;
	gchar *mime_type;
	gint len;
	GQueue work_queue = G_QUEUE_INIT;
	GList *head, *link;
	GError *local_error = NULL;

	if (g_cancellable_is_cancelled (cancellable))
		return FALSE;

	cipher = camel_gpg_context_new (e_mail_parser_get_session (parser));

	opart = camel_mime_part_new ();

	/* Decrypt the message */
	valid = camel_cipher_context_decrypt_sync (
		cipher, part, opart, cancellable, &local_error);

	if (local_error != NULL) {
		e_mail_parser_error (
			parser, out_mail_parts,
			_("Could not parse PGP message: %s"),
			local_error->message);
		g_error_free (local_error);

		e_mail_parser_parse_part_as (
			parser,
			part, part_id,
			"application/vnd.evolution.source",
			cancellable, out_mail_parts);

		g_object_unref (cipher);
		g_object_unref (opart);

		return TRUE;
	}

	dw = camel_medium_get_content ((CamelMedium *) opart);
	mime_type = camel_data_wrapper_get_mime_type (dw);

	/* this ensures to show the 'opart' as inlined, if possible */
	if (mime_type && g_ascii_strcasecmp (mime_type, "application/octet-stream") == 0) {
		const gchar *snoop;

		snoop = e_mail_part_snoop_type (opart);

		if (snoop != NULL) {
			camel_data_wrapper_set_mime_type (dw, snoop);

			/* Set the MIME type on the 'opart' itself as well.
			 * If it's "text/plain", then we want the TextPlain
			 * parser extension to treat it as "text/plain" and
			 * NOT wrap it as an attachment. */
			camel_data_wrapper_set_mime_type (
				CAMEL_DATA_WRAPPER (opart), snoop);
		}
	}

	e_mail_part_preserve_charset_in_content_type (part, opart);
	g_free (mime_type);

	/* Pass it off to the real formatter */
	len = part_id->len;
	g_string_append (part_id, ".inlinepgp_encrypted");

	g_warn_if_fail (e_mail_parser_parse_part_as (
		parser, opart, part_id,
		camel_data_wrapper_get_mime_type (dw),
		cancellable, &work_queue));

	g_string_truncate (part_id, len);

	head = g_queue_peek_head_link (&work_queue);

	for (link = head; link != NULL; link = g_list_next (link)) {
		EMailPart *mail_part = link->data;

		e_mail_part_update_validity (
			mail_part, valid,
			E_MAIL_PART_VALIDITY_ENCRYPTED |
			E_MAIL_PART_VALIDITY_PGP);
	}

	e_queue_transfer (&work_queue, out_mail_parts);

	/* Add a widget with details about the encryption, but only when
	 * the encrypted isn't itself secured, in that case it has created
	 * the button itself */
	if (!e_mail_part_is_secured (opart)) {
		EMailPart *mail_part;

		g_string_append (part_id, ".inlinepgp_encrypted.button");

		e_mail_parser_parse_part_as (
			parser, part, part_id,
			"application/vnd.evolution.widget.secure-button",
			cancellable, &work_queue);

		mail_part = g_queue_peek_head (&work_queue);
		if (mail_part != NULL)
			e_mail_part_update_validity (
				mail_part, valid,
				E_MAIL_PART_VALIDITY_ENCRYPTED |
				E_MAIL_PART_VALIDITY_PGP);

		e_queue_transfer (&work_queue, out_mail_parts);

		g_string_truncate (part_id, len);
	}

	/* Clean Up */
	camel_cipher_validity_free (valid);
	g_object_unref (opart);
	g_object_unref (cipher);

	return TRUE;
}
static gboolean
empe_mp_signed_parse (EMailParserExtension *extension,
                      EMailParser *parser,
                      CamelMimePart *part,
                      GString *part_id,
                      GCancellable *cancellable,
                      GQueue *out_mail_parts)
{
	CamelMimePart *cpart = NULL;
	CamelMultipart *multipart;
	CamelCipherContext *cipher = NULL;
	CamelContentType *content_type;
	CamelSession *session;
	guint32 validity_type;
	CamelCipherValidity *valid;
	const gchar *protocol = NULL;
	GError *local_error = NULL;
	gint i, nparts, len;
	gboolean secured;

	/* If the part is application/pgp-signature sub-part then skip it. */
	if (!CAMEL_IS_MULTIPART (part)) {
		content_type = camel_mime_part_get_content_type (part);
		if (camel_content_type_is (
			content_type, "application", "pgp-signature")) {
			return TRUE;
		}
	}

	multipart = (CamelMultipart *) camel_medium_get_content ((CamelMedium *) part);
	if (CAMEL_IS_MULTIPART_SIGNED (multipart)) {
		cpart = camel_multipart_get_part (
			multipart, CAMEL_MULTIPART_SIGNED_CONTENT);
	}

	if (cpart == NULL) {
		e_mail_parser_error (
			parser, out_mail_parts,
			_("Could not parse MIME message. "
			"Displaying as source."));
		e_mail_parser_parse_part_as (
			parser, part, part_id,
			"application/vnd.evolution.source",
			cancellable, out_mail_parts);

		return TRUE;
	}

	content_type = camel_data_wrapper_get_mime_type_field (
		CAMEL_DATA_WRAPPER (multipart));
	if (content_type != NULL)
		protocol = camel_content_type_param (content_type, "protocol");

	session = e_mail_parser_get_session (parser);
	/* FIXME: Should be done via a plugin interface */
	/* FIXME: duplicated in em-format-html-display.c */
	if (protocol != NULL) {
#ifdef ENABLE_SMIME
		if (g_ascii_strcasecmp ("application/x-pkcs7-signature", protocol) == 0
		    || g_ascii_strcasecmp ("application/pkcs7-signature", protocol) == 0) {
			cipher = camel_smime_context_new (session);
			validity_type = E_MAIL_PART_VALIDITY_SMIME;
		} else {
#endif
			if (g_ascii_strcasecmp ("application/pgp-signature", protocol) == 0) {
				cipher = camel_gpg_context_new (session);
				validity_type = E_MAIL_PART_VALIDITY_PGP;
			}
#ifdef ENABLE_SMIME
		}
#endif
	}

	if (cipher == NULL) {
		e_mail_parser_error (
			parser, out_mail_parts,
			_("Unsupported signature format"));
		e_mail_parser_parse_part_as (
			parser, part, part_id, "multipart/mixed",
			cancellable, out_mail_parts);

		return TRUE;
	}

	valid = camel_cipher_context_verify_sync (
		cipher, part, cancellable, &local_error);

	if (local_error != NULL) {
		e_mail_parser_error (
			parser, out_mail_parts,
			_("Error verifying signature: %s"),
			local_error->message);
		e_mail_parser_parse_part_as (
			parser, part, part_id, "multipart/mixed",
			cancellable, out_mail_parts);

		g_object_unref (cipher);
		g_error_free (local_error);

		return TRUE;
	}

	nparts = camel_multipart_get_number (multipart);
	secured = FALSE;
	len = part_id->len;
	for (i = 0; i < nparts; i++) {
		GQueue work_queue = G_QUEUE_INIT;
		GList *head, *link;
		CamelMimePart *subpart;

		subpart = camel_multipart_get_part (multipart, i);

		g_string_append_printf (part_id, ".signed.%d", i);

		g_warn_if_fail (e_mail_parser_parse_part (
			parser, subpart, part_id, cancellable, &work_queue));

		g_string_truncate (part_id, len);

		if (!secured)
			secured = e_mail_part_is_secured (subpart);

		head = g_queue_peek_head_link (&work_queue);

		for (link = head; link != NULL; link = g_list_next (link)) {
			EMailPart *mail_part = link->data;

			e_mail_part_update_validity (
				mail_part, valid,
				validity_type | E_MAIL_PART_VALIDITY_SIGNED);
		}

		e_queue_transfer (&work_queue, out_mail_parts);
	}

	/* Add a widget with details about the encryption, but only when
	 * the encrypted isn't itself secured, in that case it has created
	 * the button itself. */
	if (!secured) {
		GQueue work_queue = G_QUEUE_INIT;
		EMailPart *mail_part;

		g_string_append (part_id, ".signed.button");

		e_mail_parser_parse_part_as (
			parser, part, part_id,
			"application/vnd.evolution.widget.secure-button",
			cancellable, &work_queue);

		mail_part = g_queue_peek_head (&work_queue);

		if (mail_part != NULL)
			e_mail_part_update_validity (
				mail_part, valid,
				validity_type | E_MAIL_PART_VALIDITY_SIGNED);

		e_queue_transfer (&work_queue, out_mail_parts);

		g_string_truncate (part_id, len);
	}

	camel_cipher_validity_free (valid);

	g_object_unref (cipher);

	return TRUE;
}
Пример #21
0
static gboolean
dispatch_queue (CockpitSshTransport *self)
{
  GBytes *block;
  const guchar *data;
  gsize length;
  gsize want;
  int rc;

  if (self->sent_eof)
    return FALSE;
  if (self->received_close)
    return FALSE;

  for (;;)
    {
      block = g_queue_peek_head (self->queue);
      if (!block)
        return FALSE;

      data = g_bytes_get_data (block, &length);
      g_assert (self->partial <= length);

      want = length - self->partial;
      rc = ssh_channel_write (self->data->channel, data + self->partial, want);
      if (rc < 0)
        {
          if (ssh_get_error_code (self->data->session) == SSH_REQUEST_DENIED)
            {
              g_debug ("%s: couldn't write: %s", self->logname,
                       ssh_get_error (self->data->session));
              return FALSE;
            }
          else
            {
              g_warning ("%s: couldn't write: %s", self->logname,
                         ssh_get_error (self->data->session));
              close_immediately (self, "internal-error");
            }
          break;
        }

      if (rc == want)
        {
          g_debug ("%s: wrote %d bytes", self->logname, rc);
          g_queue_pop_head (self->queue);
          g_bytes_unref (block);
          self->partial = 0;
        }
      else
        {
          g_debug ("%s: wrote %d of %d bytes", self->logname, rc, (int)want);
          g_return_val_if_fail (rc < want, FALSE);
          self->partial += rc;
          if (rc == 0)
            break;
        }
    }

  return TRUE;
}
Пример #22
0
static void
end_element(
	GMarkupParseContext *ctx, 
	const gchar *name, 
	gpointer ud,
	GError **error)
{
	parse_data_t *pd = (parse_data_t*)ud;
	gint id;
	union 
	{
		gint id;
		gpointer pid;
	} start_id;
	gint ii;

	// Check to see if the first element found has been closed
	// If so, ignore any junk following it.
	if (pd->closed_top)
		return;

	for (ii = 0; ii < TAG_MAP_SZ; ii++)
	{
		if (strcmp(name, tag_map[ii].tag) == 0)
		{
			id = tag_map[ii].id;
			break;
		}
	}
	if (ii == TAG_MAP_SZ)
	{
		g_warning("Unrecognized start tag (%s)", name);
		return;
	}
	start_id.pid = g_queue_pop_head(pd->tag_stack);
	if (start_id.id != id)
		g_warning("start tag != end tag: (%s %d) %d", name, id, id);

	GValue *gval = NULL;
	GValue *current = g_queue_peek_head(pd->stack);
	GType gtype = 0;
	switch (id)
	{
		case R_SECTION:
		{
			g_queue_pop_head(pd->stack);
		} break;
	}
	if (gval)
	{
		// Get the top of the data structure stack and if it's an array
		// or dict, add the current element
		if (current == NULL)
		{
			pd->plist = gval;
			pd->closed_top = TRUE;
			return;
		}
		gtype = G_VALUE_TYPE(current);
		if (gtype == ghb_array_get_type())
		{
			ghb_array_append(current, gval);
		}
		else if (gtype == ghb_dict_get_type())
		{
			if (pd->key == NULL)
			{
				g_warning("No key for dictionary item");
				ghb_value_free(gval);
			}
			else
			{
				ghb_dict_insert(current, g_strdup(pd->key), gval);
			}
		}
		else
		{
			g_error("Invalid container type. This shouldn't happen");
		}
	}
	if (g_queue_is_empty(pd->tag_stack))
		pd->closed_top = TRUE;
}
Пример #23
0
gboolean
ide_xml_find_opening_element (const GtkTextIter *start,
                              const GtkTextIter *end,
                              GtkTextIter       *found_element_start,
                              GtkTextIter       *found_element_end)
{
  IdeXmlElementTagType tag_type;
  GQueue *element_queue;
  guint element_queue_length = 0;
  gchar *element_name = NULL;

  g_return_val_if_fail (found_element_start != NULL, FALSE);
  g_return_val_if_fail (found_element_end != NULL, FALSE);

  tag_type = ide_xml_get_element_tag_type (start, end);
  if (tag_type != IDE_XML_ELEMENT_TAG_END)
    return FALSE;

  element_name = ide_xml_get_element_name (start, end);
  if (element_name == NULL)
    return FALSE;

  element_queue = g_queue_new();
  g_queue_push_head(element_queue, element_name);

  while (g_queue_get_length (element_queue) > 0 &&
         ide_xml_find_previous_element (start, found_element_start, found_element_end))
    {
      tag_type = ide_xml_get_element_tag_type (found_element_start, found_element_end);
      if (tag_type == IDE_XML_ELEMENT_TAG_END)
        {
          element_name = ide_xml_get_element_name (found_element_start, found_element_end);
          if (element_name != NULL)
            g_queue_push_head(element_queue, element_name);
        }
      else if (tag_type == IDE_XML_ELEMENT_TAG_START)
        {
          element_name = ide_xml_get_element_name (found_element_start, found_element_end);
          if (element_name != NULL)
            {
              if(g_strcmp0 (g_queue_peek_head(element_queue), element_name) == 0)
                {
                  g_free (g_queue_pop_head (element_queue));
                  g_free (element_name);
                }
              /*Unbalanced element.Stop parsing*/
              else
                {
                  g_free (element_name);
                  goto completed;
                }
            }
        }
      start = found_element_start;
    }

completed:
  element_queue_length = g_queue_get_length (element_queue);
  g_queue_free_full (element_queue, g_free);

  return element_queue_length > 0 ? FALSE : TRUE;
}
static void
views_parser_start_element (GMarkupParseContext  *context,
                            const gchar          *element_name,
                            const gchar         **attribute_names,
                            const gchar         **attribute_values,
                            gpointer              user_data,
                            GError              **error)
{
  ViewsParserData *parser_data = user_data;
  GtkWidget *item;

  g_assert (context != NULL);
  g_assert (element_name != NULL);
  g_assert (parser_data != NULL);

  if (g_strcmp0 (element_name, "views") == 0)
    {
    }
  else if (g_strcmp0 (element_name, "view") == 0)
    {
      const gchar *name = NULL;

      if (!check_parent (context, "views", error))
        return;

      if (!g_markup_collect_attributes (element_name, attribute_names, attribute_values, error,
                                        G_MARKUP_COLLECT_STRING, "name", &name,
                                        G_MARKUP_COLLECT_INVALID))
        return;

      item = g_object_new (GB_TYPE_SHORTCUTS_VIEW,
                           "view-name", name,
                           "visible", TRUE,
                           NULL);

      g_queue_push_head (parser_data->stack, g_object_ref_sink (item));
    }
  else if (g_strcmp0 (element_name, "page") == 0)
    {
      if (!check_parent (context, "view", error))
        return;

      item = g_object_new (GB_TYPE_SHORTCUTS_PAGE,
                           "visible", TRUE,
                           NULL);
      g_queue_push_head (parser_data->stack, g_object_ref_sink (item));
    }
  else if (g_strcmp0 (element_name, "column") == 0)
    {
      GtkSizeGroup *size_group;

      if (!check_parent (context, "page", error))
        return;

      size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
      g_queue_push_head (parser_data->column_image_size_groups, size_group);

      size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
      g_queue_push_head (parser_data->column_desc_size_groups, size_group);

      item = g_object_new (GB_TYPE_SHORTCUTS_COLUMN,
                           "visible", TRUE,
                           NULL);
      g_queue_push_head (parser_data->stack, g_object_ref_sink (item));
    }
  else if (g_strcmp0 (element_name, "group") == 0)
    {
      if (!check_parent (context, "column", error))
        return;

      item = g_object_new (GB_TYPE_SHORTCUTS_GROUP,
                           "visible", TRUE,
                           NULL);
      g_queue_push_head (parser_data->stack, g_object_ref_sink (item));
    }
  else if (g_strcmp0 (element_name, "shortcut") == 0)
    {
      GtkSizeGroup *accel_size_group;
      GtkSizeGroup *desc_size_group;

      if (!check_parent (context, "group", error))
        return;

      accel_size_group = g_queue_peek_head (parser_data->column_image_size_groups);
      desc_size_group = g_queue_peek_head (parser_data->column_desc_size_groups);

      parser_data->search_item = g_object_new (GB_TYPE_SHORTCUTS_SHORTCUT,
                                               "visible", TRUE,
                                               NULL);

      item = g_object_new (GB_TYPE_SHORTCUTS_SHORTCUT,
                           "accelerator-size-group", accel_size_group,
                           "title-size-group", desc_size_group,
                           "visible", TRUE,
                           NULL);
      g_queue_push_head (parser_data->stack, g_object_ref_sink (item));
    }
  else if (g_strcmp0 (element_name, "gesture") == 0)
    {
      GtkSizeGroup *accel_size_group;
      GtkSizeGroup *desc_size_group;

      if (!check_parent (context, "group", error))
        return;

      accel_size_group = g_queue_peek_head (parser_data->column_image_size_groups);
      desc_size_group = g_queue_peek_head (parser_data->column_desc_size_groups);

      parser_data->search_item = g_object_new (GB_TYPE_SHORTCUTS_GESTURE,
                                               "visible", TRUE,
                                               NULL);

      item = g_object_new (GB_TYPE_SHORTCUTS_GESTURE,
                           "desc-size-group", desc_size_group,
                           "icon-size-group", accel_size_group,
                           "visible", TRUE,
                           NULL);
      g_queue_push_head (parser_data->stack, g_object_ref_sink (item));
    }
  else if (g_strcmp0 (element_name, "property") == 0)
    {
      const gchar *name = NULL;
      const gchar *translatable = NULL;

      item = g_queue_peek_head (parser_data->stack);

      if (item == NULL)
        {
          g_set_error (error,
                       GTK_BUILDER_ERROR,
                       GTK_BUILDER_ERROR_INVALID_TAG,
                       "Property called without a parent object");
          return;
        }

      if (!g_markup_collect_attributes (element_name, attribute_names, attribute_values, error,
                                        G_MARKUP_COLLECT_STRING, "name", &name,
                                        G_MARKUP_COLLECT_OPTIONAL | G_MARKUP_COLLECT_STRING, "translatable", &translatable,
                                        G_MARKUP_COLLECT_INVALID))
        return;

      g_free (parser_data->property_name);
      parser_data->property_name = g_strdup (name);
      parser_data->translatable = (g_strcmp0 (translatable, "yes") == 0);
    }
  else
    {
      const GSList *stack;
      const gchar *parent_name;
      const gchar *our_name;
      gint line;
      gint col;

      stack = g_markup_parse_context_get_element_stack (context);
      our_name = stack->data;
      parent_name = stack->next ? stack->next->data : "";

      g_markup_parse_context_get_position (context, &line, &col);
      g_set_error (error,
                   GTK_BUILDER_ERROR,
                   GTK_BUILDER_ERROR_INVALID_TAG,
                   "%d:%d: Unknown element <%s> found in <%s>.",
                   line, col, our_name, parent_name);
    }
}
Пример #25
0
static void
start_element(
	GMarkupParseContext *ctx, 
	const gchar *tag, 
	const gchar **attr_names,
	const gchar **attr_values,
	gpointer ud,
	GError **error)
{
	parse_data_t *pd = (parse_data_t*)ud;
	union 
	{
		gint id;
		gpointer pid;
	} id;
	gint ii;

	// Check to see if the first element found has been closed
	// If so, ignore any junk following it.
	if (pd->closed_top)
		return;

	for (ii = 0; ii < TAG_MAP_SZ; ii++)
	{
		if (strcmp(tag, tag_map[ii].tag) == 0)
		{
			id.id = tag_map[ii].id;
			break;
		}
	}
	if (ii == TAG_MAP_SZ)
	{
		g_warning("Unrecognized start tag (%s)", tag);
		return;
	}
	g_queue_push_head(pd->tag_stack, id.pid);
	GType gtype = 0;
	GValue *gval = NULL;
	GValue *current = g_queue_peek_head(pd->stack);
	switch (id.id)
	{
		case R_SECTION:
		{
			const gchar *name;

			name = lookup_attr_value("name", attr_names, attr_values);
			if (name && strcmp(name, "icons") == 0)
			{
				gval = ghb_dict_value_new();
				if (pd->key) g_free(pd->key);
				pd->key = g_strdup(name);
				g_queue_push_head(pd->stack, gval);
			}
		} break;
		case R_ICON:
		{
			gchar *filename;
			const gchar *name;

			name = lookup_attr_value("file", attr_names, attr_values);
			filename = find_file(inc_list, name);
			name = lookup_attr_value("name", attr_names, attr_values);
			if (filename && name)
			{
				ghb_rawdata_t *rd;
				GdkPixbuf *pb;
				GError *err = NULL;

				pb = gdk_pixbuf_new_from_file(filename, &err);
				if (pb == NULL)
				{
					g_warning("Failed to open icon file %s: %s", filename, err->message);
					break;
				}
				gval = ghb_dict_value_new();
				int colorspace = gdk_pixbuf_get_colorspace(pb);
				gboolean alpha = gdk_pixbuf_get_has_alpha(pb);
				int width = gdk_pixbuf_get_width(pb);
				int height = gdk_pixbuf_get_height(pb);
				int bps = gdk_pixbuf_get_bits_per_sample(pb);
				int rowstride = gdk_pixbuf_get_rowstride(pb);

				ghb_dict_insert(gval, g_strdup("colorspace"), 
								ghb_int_value_new(colorspace));
				ghb_dict_insert(gval, g_strdup("alpha"), 
								ghb_boolean_value_new(alpha));
				ghb_dict_insert(gval, g_strdup("width"), 
								ghb_int_value_new(width));
				ghb_dict_insert(gval, g_strdup("height"), 
								ghb_int_value_new(height));
				ghb_dict_insert(gval, g_strdup("bps"), 
								ghb_int_value_new(bps));
				ghb_dict_insert(gval, g_strdup("rowstride"), 
								ghb_int_value_new(rowstride));

				rd = g_malloc(sizeof(ghb_rawdata_t));
				rd->data = gdk_pixbuf_get_pixels(pb);
				rd->size = height * rowstride * bps / 8;
				GValue *data = ghb_rawdata_value_new(rd);
				ghb_dict_insert(gval, g_strdup("data"), data);

				if (pd->key) g_free(pd->key);
				pd->key = g_strdup(name);
				g_free(filename);
			}
			else
			{
				g_warning("%s:missing a requried attribute", name);
    			exit(EXIT_FAILURE);
			}
		} break;
		case R_PLIST:
		{
			gchar *filename;
			const gchar *name;

			name = lookup_attr_value("file", attr_names, attr_values);
			filename = find_file(inc_list, name);
			name = lookup_attr_value("name", attr_names, attr_values);
			if (filename && name)
			{
				gval = ghb_plist_parse_file(filename);
				if (pd->key) g_free(pd->key);
				pd->key = g_strdup(name);
				g_free(filename);
			}
			else
			{
				g_warning("%s:missing a requried attribute", name);
    			exit(EXIT_FAILURE);
			}
		} break;
		case R_STRING:
		{
			gchar *filename;
			const gchar *name;

			name = lookup_attr_value("file", attr_names, attr_values);
			filename = find_file(inc_list, name);
			name = lookup_attr_value("name", attr_names, attr_values);
			if (filename && name)
			{
				gval = read_string_from_file(filename);
				if (pd->key) g_free(pd->key);
				pd->key = g_strdup(name);
				g_free(filename);
			}
			else
			{
				g_warning("%s:missing a requried attribute", name);
    			exit(EXIT_FAILURE);
			}
		} break;
	}
	// Add the element to the current container
	if (gval)
	{ // There's an element to add
		if (current == NULL)
		{
			pd->plist = gval;
			return;
		}
		gtype = G_VALUE_TYPE(current);
		if (gtype == ghb_array_get_type())
		{
			ghb_array_append(current, gval);
		}
		else if (gtype == ghb_dict_get_type())
		{
			if (pd->key == NULL)
			{
				g_warning("No key for dictionary item");
				ghb_value_free(gval);
			}
			else
			{
				ghb_dict_insert(current, g_strdup(pd->key), gval);
			}
		}
		else
		{
			g_error("Invalid container type. This shouldn't happen");
		}
	}
}
static void
_source_notification_added_cb (MexNotificationSource *source,
                               MexNotification       *notification,
                               MexNotificationArea   *area)
{
    MexNotificationAreaPrivate *priv = GET_PRIVATE (area);
    ClutterActor *actor;
    ClutterActor *last_top_actor;
    ClutterAnimation *animation;

    actor = _make_notification_actor (notification);

    g_hash_table_insert (priv->notification_to_actor,
                         notification,
                         actor);

    clutter_container_add_actor (CLUTTER_CONTAINER (area),
                                 actor);
    mx_stack_child_set_x_fill (MX_STACK (area), actor, FALSE);
    mx_stack_child_set_y_fill (MX_STACK (area), actor, FALSE);
    mx_stack_child_set_x_align (MX_STACK (area), actor, MX_ALIGN_MIDDLE);
    mx_stack_child_set_y_align (MX_STACK (area), actor, MX_ALIGN_MIDDLE);

    /* Get the last notification since we want to fade that out */
    last_top_actor = g_queue_peek_head (priv->stack);

    g_queue_push_head (priv->stack, actor);

    clutter_container_raise_child (CLUTTER_CONTAINER (area),
                                   actor,
                                   last_top_actor);



    /* Fade out old notification */
    if (last_top_actor)
    {
        clutter_actor_animate (last_top_actor,
                               CLUTTER_EASE_OUT_QUAD,
                               350,
                               "opacity", 0x00,
                               NULL);
    }

    clutter_actor_set_opacity (actor, 0);
    animation = clutter_actor_animate (actor,
                                       CLUTTER_EASE_OUT_QUAD,
                                       350,
                                       "opacity", 0xff,
                                       NULL);

    /* Delay new notification fade in if we had an old one */
    if (last_top_actor)
    {
        ClutterTimeline *timeline;

        timeline = clutter_animation_get_timeline (animation);

        clutter_timeline_set_delay (timeline, 450);
    }

    g_object_set_data (G_OBJECT (actor),
                       "notification-area",
                       area);
    g_object_set_data (G_OBJECT (actor),
                       "notification",
                       notification);

    if (notification->duration > 0)
    {
        guint timeout_id =
            g_timeout_add_seconds (notification->duration,
                                   (GSourceFunc)_notification_timeout_cb,
                                   actor);

        g_hash_table_insert (priv->notification_to_timeout_id,
                             notification,
                             GINT_TO_POINTER (timeout_id));
    }
}
Пример #27
0
static void tx_finished(const struct ofono_error *error, int mr, void *data)
{
	struct ofono_sms *sms = data;
	struct tx_queue_entry *entry = g_queue_peek_head(sms->txq);
	gboolean ok = error->type == OFONO_ERROR_TYPE_NO_ERROR;
	enum message_state tx_state;

	DBG("tx_finished %p", entry);

	sms->flags &= ~MESSAGE_MANAGER_FLAG_TXQ_ACTIVE;

	if (ok == FALSE) {
		/* Retry again when back in online mode */
		/* Note this does not increment retry count */
		if (sms->registered == FALSE)
			return;

		tx_state = MESSAGE_STATE_FAILED;

		/* Retry done only for Network Timeout failure */
		if (error->type == OFONO_ERROR_TYPE_CMS &&
				error->error != NETWORK_TIMEOUT)
			goto next_q;

		if (!(entry->flags & OFONO_SMS_SUBMIT_FLAG_RETRY))
			goto next_q;

		entry->retry += 1;

		if (entry->retry < TXQ_MAX_RETRIES) {
			DBG("Sending failed, retry in %d secs",
					entry->retry * 5);
			sms->tx_source = g_timeout_add_seconds(entry->retry * 5,
								tx_next, sms);
			return;
		}

		DBG("Max retries reached, giving up");
		goto next_q;
	}

	if (entry->flags & OFONO_SMS_SUBMIT_FLAG_EXPOSE_DBUS)
		sms_tx_backup_remove(sms->imsi, entry->id, entry->flags,
						ofono_uuid_to_str(&entry->uuid),
						entry->cur_pdu);

	entry->cur_pdu += 1;
	entry->retry = 0;

	if (entry->flags & OFONO_SMS_SUBMIT_FLAG_REQUEST_SR)
		status_report_assembly_add_fragment(sms->sr_assembly,
							entry->uuid.uuid,
							&entry->receiver,
							mr, time(NULL),
							entry->num_pdus);

	if (entry->cur_pdu < entry->num_pdus) {
		sms->tx_source = g_timeout_add(0, tx_next, sms);
		return;
	}

	tx_state = MESSAGE_STATE_SENT;

next_q:
	sms_tx_queue_remove_entry(sms, g_queue_peek_head_link(sms->txq),
					tx_state);

	if (sms->registered == FALSE)
		return;

	if (g_queue_peek_head(sms->txq)) {
		DBG("Scheduling next");
		sms->tx_source = g_timeout_add(0, tx_next, sms);
	}
}
Пример #28
0
static void handle_read(liMemcachedCon *con) {
	int_request *cur;

	if (NULL == (cur = con->cur_req)) {
		cur = con->cur_req = g_queue_peek_head(&con->req_queue);

		if (NULL == cur) {
			/* unexpected read event, perhaps just eof */
			g_clear_error(&con->err);
			g_set_error(&con->err, LI_MEMCACHED_ERROR, LI_MEMCACHED_CONNECTION, "Connection closed: unexpected read event");
			close_con(con);
			return;
		}

		reset_item(&con->curitem);
		if (con->data) con->data->used = 0;
		if (con->line) con->line->used = 0;

		/* init read state */
		switch (cur->type) {
		case REQ_GET:
			con->get_data_size = 0;
			con->get_have_header = FALSE;
			break;
		case REQ_SET:
			break;
		}
	}

	switch (cur->type) {
	case REQ_GET:
		if (!con->get_have_header) {
			char *pos, *next;

			/* wait for header line */
			if (!try_read_line(con)) return;

			con->get_have_header = TRUE;

			if (3 == con->line->used && 0 == memcmp("END", con->line->addr, 3)) {
				/* key not found */
				if (cur->req.callback) {
					cur->req.callback(&cur->req, LI_MEMCACHED_NOT_FOUND, NULL, NULL);
				}
				con->cur_req = NULL;
				free_request(con, cur);
				return;
			}

			/* con->line is 0 terminated */

			if (0 != strncmp("VALUE ", con->line->addr, 6)) {
				g_clear_error(&con->err);
				g_set_error(&con->err, LI_MEMCACHED_ERROR, LI_MEMCACHED_CONNECTION, "Protocol error: Unexpected response for GET: '%s'", con->line->addr);
				close_con(con);
				return;
			}

			/* VALUE <key> <flags> <bytes> [<cas unique>]\r\n */

			/* <key> */
			pos = con->line->addr + 6;
			next = strchr(pos, ' ');
			if (NULL == next) goto req_get_header_error;

			con->curitem.key = g_string_new_len(pos, next - pos);

			/* <flags> */
			pos = next + 1;
			con->curitem.flags = strtoul(pos, &next, 10);
			if (' ' != *next || pos == next) goto req_get_header_error;

			/* <bytes> */
			pos = next + 1;
			con->get_data_size = g_ascii_strtoll(pos, &next, 10);
			if (pos == next) goto req_get_header_error;

			/* [<cas unique>] */
			if (' ' == *next) {
				pos = next + 1;
				con->curitem.cas = g_ascii_strtoll(pos, &next, 10);
				if (pos == next) goto req_get_header_error;
			}

			if ('\0' != *next) {
				goto req_get_header_error;
			}

			con->line->used = 0;

			goto req_get_header_done;

req_get_header_error:
			g_clear_error(&con->err);
			g_set_error(&con->err, LI_MEMCACHED_ERROR, LI_MEMCACHED_CONNECTION, "Protocol error: Couldn't parse VALUE respone: '%s'", con->line->addr);
			close_con(con);
			return;

req_get_header_done: ;
		}
		if (NULL == con->data || con->data->used < con->get_data_size) {
			/* wait for data */
			if (!try_read_data(con, con->get_data_size)) return;
		}
		/* wait for END\r\n */
		if (!try_read_line(con)) return;

		if (3 == con->line->used && 0 == memcmp("END", con->line->addr, 3)) {
			/* Move data to item */
			con->curitem.data = con->data;
			con->data = NULL;
			if (cur->req.callback) {
				cur->req.callback(&cur->req, LI_MEMCACHED_OK, &con->curitem, NULL);
			}
			reset_item(&con->curitem);
		} else {
			g_clear_error(&con->err);
			g_set_error(&con->err, LI_MEMCACHED_ERROR, LI_MEMCACHED_CONNECTION, "Protocol error: GET response not terminated with END (got '%s')", con->line->addr);
			close_con(con);
			return;
		}

		con->cur_req = NULL;
		free_request(con, cur);
		return;

	case REQ_SET:
		if (!try_read_line(con)) return;

		if (6 == con->line->used && 0 == memcmp("STORED", con->line->addr, 6)) {
			if (cur->req.callback) {
				cur->req.callback(&cur->req, LI_MEMCACHED_OK, NULL, NULL);
			}
		} else {
			g_clear_error(&con->err);
			g_set_error(&con->err, LI_MEMCACHED_ERROR, LI_MEMCACHED_CONNECTION, "Protocol error: unepxected SET response: '%s'", con->line->addr);
			close_con(con);
			return;
		}

		con->cur_req = NULL;
		free_request(con, cur);
		return;
	}
}
static void
views_parser_text (GMarkupParseContext  *context,
                   const gchar          *text,
                   gsize                 text_len,
                   gpointer              user_data,
                   GError              **error)
{
  ViewsParserData *parser_data = user_data;
  GParamSpec *pspec;
  GtkWidget *item;
  GValue value = { 0 };

  g_assert (parser_data != NULL);

  if (parser_data->property_name == NULL)
    return;

  item = g_queue_peek_head (parser_data->stack);

  if (item == NULL)
    return;

  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (item), parser_data->property_name);

  if (pspec == NULL)
    {
      g_set_error (error,
                   GTK_BUILDER_ERROR,
                   GTK_BUILDER_ERROR_INVALID_PROPERTY,
                   "No such property: %s",
                   parser_data->property_name);
      return;
    }

  if (parser_data->translatable)
    text = _(text);

  if (g_type_is_a (pspec->value_type, G_TYPE_OBJECT))
    {
      GObject *relative;

      relative = gtk_builder_get_object (parser_data->builder, text);

      if (relative == NULL)
        {
          g_set_error (error,
                       GTK_BUILDER_ERROR,
                       GTK_BUILDER_ERROR_INVALID_VALUE,
                       "Unknown object for property '%s': %s",
                       parser_data->property_name,
                       text);
          return;
        }

      g_value_init (&value, pspec->value_type);
      g_value_set_object (&value, relative);
    }
  else if (!gtk_builder_value_from_string (parser_data->builder,
                                           pspec, text, &value, error))
    return;

  if (parser_data->search_item != NULL)
    g_object_set_property (G_OBJECT (parser_data->search_item),
                           parser_data->property_name,
                           &value);
  g_object_set_property (G_OBJECT (item), parser_data->property_name, &value);
  g_value_unset (&value);
}
Пример #30
0
static void memcached_io_cb(liEventBase *watcher, int events) {
	liMemcachedCon *con = LI_CONTAINER_OF(li_event_io_from(watcher), liMemcachedCon, con_watcher);

	if (1 == g_atomic_int_get(&con->refcount) && li_event_active(&con->con_watcher)) {
		memcached_stop_io(con);
		return;
	}

	if (-1 == con->fd) {
		memcached_connect(con);
		return;
	}

	li_memcached_con_acquire(con); /* make sure con isn't freed in the middle of something */

	if (events & LI_EV_WRITE) {
		int i;
		ssize_t written, len;
		gchar *data;
		send_item *si;

		si = g_queue_peek_head(&con->out);

		for (i = 0; si && (i < 10); i++) { /* don't send more than 10 chunks */
			data = si->buf->addr + si->pos;
			len = si->len;
			written = write(li_event_io_fd(&con->con_watcher), data, len);
			if (written < 0) {
				switch (errno) {
				case EINTR:
					continue;
				case EAGAIN:
#if EWOULDBLOCK != EAGAIN
				case EWOULDBLOCK:
#endif
					goto write_eagain;
				default: /* Fatal error, connection has to be closed */
					g_clear_error(&con->err);
					g_set_error(&con->err, LI_MEMCACHED_ERROR, LI_MEMCACHED_CONNECTION, "Couldn't write socket '%s': %s",
						li_sockaddr_to_string(con->addr, con->tmpstr, TRUE)->str,
						g_strerror(errno));
					close_con(con);
					goto out;
				}
			} else {
				si->pos += written;
				si->len -= written;
				if (0 == si->len) {
					send_queue_item_free(si);
					g_queue_pop_head(&con->out);
					si = g_queue_peek_head(&con->out);
				}
			}
		}

write_eagain:
		send_queue_clean(&con->out);
	}

	if (events & LI_EV_READ) {
		do {
			handle_read(con);
		} while (con->remaining && con->remaining->used > 0);
	}

out:
	memcached_update_io(con);
	li_memcached_con_release(con);
}