Пример #1
0
/* CURLMOPT_SOCKETFUNCTION */
static int curl_socketfunction_cb(CURL *easy, curl_socket_t s, int action, void *cbp, void *sockp)
{
	g_debug("%s e %p s %i what %i cbp %p sockp %p", __PRETTY_FUNCTION__, easy, s, action, cbp, sockp);

	struct session_socket *info = (struct session_socket*) sockp;
	struct session *session;
	curl_easy_getinfo(easy, CURLOPT_PRIVATE, &session);

#ifdef DEBUG
	const char *action_str[]={ "none", "IN", "OUT", "INOUT", "REMOVE"};
#endif

	g_debug("socket callback: s=%d e=%p what=%s ", s, easy, action_str[action]);

	if( action == CURL_POLL_REMOVE )
	{
		session_info_free(info);
	} else
	{
		if( !info )
		{
			g_debug("Adding data: %s", action_str[action]);
			info = g_malloc0(sizeof(struct session_socket));
			session_set_socket(session, info, s, action);
			curl_multi_assign(curl_runtime.multi, s, info);
		} else
		{
			g_debug("Changing action from %s to %s", action_str[info->action], action_str[action]);
			session_set_socket(session, info, s, action);
		}
	}
	return 0;
}
Пример #2
0
void
meta_window_release_saved_state (const MetaWindowSessionInfo *info)
{
  /* We don't want to use the same saved state again for another
   * window.
   */
  window_info_list = g_slist_remove (window_info_list, info);

  session_info_free ((MetaWindowSessionInfo*) info);
}
Пример #3
0
/* FIXME this isn't very robust against bogus session files */
static void
start_element_handler  (GMarkupParseContext *context,
                        const gchar         *element_name,
                        const gchar        **attribute_names,
                        const gchar        **attribute_values,
                        gpointer             user_data,
                        GError             **error)
{
  ParseData *pd;

  pd = user_data;

  if (strcmp (element_name, "consortium_session") == 0)
    {
      /* Get previous ID */
      int i;      

      i = 0;
      while (attribute_names[i])
        {
          const char *name;
          const char *val;
          
          name = attribute_names[i];
          val = attribute_values[i];

          if (pd->previous_id)
            {
              g_set_error (error,
                           G_MARKUP_ERROR,
                       G_MARKUP_ERROR_PARSE,
                           _("<consortium_session> attribute seen but we already have the session ID"));
              return;
            }
          
          if (strcmp (name, "id") == 0)
            {
              pd->previous_id = decode_text_from_utf8 (val);
            }
          else
            {
              g_set_error (error,
                           G_MARKUP_ERROR,
                           G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
                           _("Unknown attribute %s on <%s> element"),
                           name, "consortium_session");
              return;
            }
          
          ++i;
        }
    }
  else if (strcmp (element_name, "window") == 0)
    {
      int i;
      
      if (pd->info)
        {
          g_set_error (error,
                       G_MARKUP_ERROR,
                       G_MARKUP_ERROR_PARSE,
                       _("nested <window> tag"));
          return;
        }
      
      pd->info = session_info_new ();

      i = 0;
      while (attribute_names[i])
        {
          const char *name;
          const char *val;
          
          name = attribute_names[i];
          val = attribute_values[i];
          
          if (strcmp (name, "id") == 0)
            {
              if (*val)
                pd->info->id = decode_text_from_utf8 (val);
            }
          else if (strcmp (name, "class") == 0)
            {
              if (*val)
                pd->info->res_class = decode_text_from_utf8 (val);
            }
          else if (strcmp (name, "name") == 0)
            {
              if (*val)
                pd->info->res_name = decode_text_from_utf8 (val);
            }
          else if (strcmp (name, "title") == 0)
            {
              if (*val)
                pd->info->title = g_strdup (val);
            }
          else if (strcmp (name, "role") == 0)
            {
              if (*val)
                pd->info->role = decode_text_from_utf8 (val);
            }
          else if (strcmp (name, "type") == 0)
            {
              if (*val)
                pd->info->type = window_type_from_string (val);
            }
          else if (strcmp (name, "stacking") == 0)
            {
              if (*val)
                {
                  pd->info->stack_position = atoi (val);
                  pd->info->stack_position_set = TRUE;
                }
            }
          else
            {
              g_set_error (error,
                           G_MARKUP_ERROR,
                           G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
                           _("Unknown attribute %s on <%s> element"),
                           name, "window");
              session_info_free (pd->info);
              pd->info = NULL;
              return;
            }
          
          ++i;
        }
    }
  else if (strcmp (element_name, "workspace") == 0)
    {
      int i;

      i = 0;
      while (attribute_names[i])
        {
          const char *name;

          name = attribute_names[i];
          
          if (strcmp (name, "index") == 0)
            {
              pd->info->workspace_indices =
                g_slist_prepend (pd->info->workspace_indices,
                                 GINT_TO_POINTER (atoi (attribute_values[i])));
            }
          else
            {
              g_set_error (error,
                           G_MARKUP_ERROR,
                           G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
                           _("Unknown attribute %s on <%s> element"),
                           name, "window");
              session_info_free (pd->info);
              pd->info = NULL;
              return;
            }
          
          ++i;
        }
    }
  else if (strcmp (element_name, "sticky") == 0)
    {
      pd->info->on_all_workspaces = TRUE;
      pd->info->on_all_workspaces_set = TRUE;
    }
  else if (strcmp (element_name, "minimized") == 0)
    {
      pd->info->minimized = TRUE;
      pd->info->minimized_set = TRUE;
    }
  else if (strcmp (element_name, "maximized") == 0)
    {
      int i;

      i = 0;
      pd->info->maximized = TRUE;
      pd->info->maximized_set = TRUE;
      while (attribute_names[i])
        {
          const char *name;
          const char *val;

          name = attribute_names[i];
          val = attribute_values[i];

          if (strcmp (name, "saved_x") == 0)
            {
              if (*val)
                {
                  pd->info->saved_rect.x = atoi (val);
                  pd->info->saved_rect_set = TRUE;
                }
            }
          else if (strcmp (name, "saved_y") == 0)
            {
              if (*val)
                {
                  pd->info->saved_rect.y = atoi (val);
                  pd->info->saved_rect_set = TRUE;
                }
            }
          else if (strcmp (name, "saved_width") == 0)
            {
              if (*val)
                {
                  pd->info->saved_rect.width = atoi (val);
                  pd->info->saved_rect_set = TRUE;
                }
            }
          else if (strcmp (name, "saved_height") == 0)
            {
              if (*val)
                {
                  pd->info->saved_rect.height = atoi (val);
                  pd->info->saved_rect_set = TRUE;
                }
            }
          else
            {
              g_set_error (error,
                           G_MARKUP_ERROR,
                           G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
                           _("Unknown attribute %s on <%s> element"),
                           name, "maximized");
              return;
            }

          ++i;
        }

      if (pd->info->saved_rect_set)
        meta_topic (META_DEBUG_SM, "Saved unmaximized size %d,%d %dx%d \n",
                    pd->info->saved_rect.x,
                    pd->info->saved_rect.y,
                    pd->info->saved_rect.width,
                    pd->info->saved_rect.height);
    }  
  else if (strcmp (element_name, "geometry") == 0)
    {
      int i;

      pd->info->geometry_set = TRUE;
      
      i = 0;
      while (attribute_names[i])
        {
          const char *name;
          const char *val;
          
          name = attribute_names[i];
          val = attribute_values[i];
          
          if (strcmp (name, "x") == 0)
            {
              if (*val)
                pd->info->rect.x = atoi (val);
            }
          else if (strcmp (name, "y") == 0)
            {
              if (*val)
                pd->info->rect.y = atoi (val);
            }
          else if (strcmp (name, "width") == 0)
            {
              if (*val)
                pd->info->rect.width = atoi (val);
            }
          else if (strcmp (name, "height") == 0)
            {
              if (*val)
                pd->info->rect.height = atoi (val);
            }
          else if (strcmp (name, "gravity") == 0)
            {
              if (*val)
                pd->info->gravity = window_gravity_from_string (val);
            }
          else
            {
              g_set_error (error,
                           G_MARKUP_ERROR,
                           G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
                           _("Unknown attribute %s on <%s> element"),
                           name, "geometry");
              return;
            }
          
          ++i;
        }

      meta_topic (META_DEBUG_SM, "Loaded geometry %d,%d %dx%d gravity %s\n",
                  pd->info->rect.x,
                  pd->info->rect.y,
                  pd->info->rect.width,
                  pd->info->rect.height,
                  meta_gravity_to_string (pd->info->gravity));
    }
  else
    {
      g_set_error (error,
                   G_MARKUP_ERROR,
                   G_MARKUP_ERROR_UNKNOWN_ELEMENT,
                   _("Unknown element %s"),
                   element_name);
      return;
    }
}
Пример #4
0
static char*
load_state (const char *previous_save_file)
{
  GMarkupParseContext *context;
  GError *error;
  ParseData parse_data;
  char *text;
  gsize length;
  char *session_file;

  session_file = g_strconcat (g_get_user_config_dir (),
                              G_DIR_SEPARATOR_S "consortium"
                              G_DIR_SEPARATOR_S "sessions" G_DIR_SEPARATOR_S,
                              previous_save_file,
                              NULL);

  error = NULL;
  if (!g_file_get_contents (session_file,
                            &text,
                            &length,
                            &error))
    {
      char *canonical_session_file = session_file;

      /* Maybe they were doing it the old way, with ~/.consortium */
      session_file = g_strconcat (g_get_home_dir (),
                                  G_DIR_SEPARATOR_S ".consortium"
                                  G_DIR_SEPARATOR_S "sessions"
                                  G_DIR_SEPARATOR_S,
                                  previous_save_file,
                                  NULL);
      
      if (!g_file_get_contents (session_file,
                                &text,
                                &length,
                                NULL))
        {
          /* oh, just give up */

          g_error_free (error);
          g_free (session_file);
          g_free (canonical_session_file);
          return NULL;
        }

      g_free (canonical_session_file);
    }

  meta_topic (META_DEBUG_SM, "Parsing saved session file %s\n", session_file);
  g_free (session_file);
  session_file = NULL;
  
  parse_data.info = NULL;
  parse_data.previous_id = NULL;
  
  context = g_markup_parse_context_new (&consortium_session_parser,
                                        0, &parse_data, NULL);

  error = NULL;
  if (!g_markup_parse_context_parse (context,
                                     text,
                                     length,
                                     &error))
    goto error;
  
  
  error = NULL;
  if (!g_markup_parse_context_end_parse (context, &error))
    goto error;

  g_markup_parse_context_free (context);

  goto out;

 error:
  
  meta_warning (_("Failed to parse saved session file: %s\n"),
                error->message);
  g_error_free (error);

  if (parse_data.info)
    session_info_free (parse_data.info);

  g_free (parse_data.previous_id);
  parse_data.previous_id = NULL;
  
 out:
  
  g_free (text);

  return parse_data.previous_id;
}