示例#1
0
static EPublishUri *
migrateURI (const gchar *xml, xmlDocPtr doc)
{
	GConfClient *client;
	GSList *uris, *l, *events = NULL;
	xmlChar *location, *enabled, *frequency, *username;
	xmlNodePtr root, p;
	EPublishUri *uri;
	gchar *password, *temp;
	EUri *euri;

	client = gconf_client_get_default ();
	uris = gconf_client_get_list (client, "/apps/evolution/calendar/publish/uris", GCONF_VALUE_STRING, NULL);
	l = uris;
	while (l && l->data) {
		gchar *str = l->data;
		if (strcmp (xml, str) == 0) {
			uris = g_slist_remove (uris, str);
			g_free (str);
		}
		l = g_slist_next (l);
	}

	uri = g_new0 (EPublishUri, 1);

	root = doc->children;
	location = xmlGetProp (root, (const unsigned char *)"location");
	enabled = xmlGetProp (root, (const unsigned char *)"enabled");
	frequency = xmlGetProp (root, (const unsigned char *)"frequency");
	username = xmlGetProp (root, (const unsigned char *)"username");

	euri = e_uri_new ((const char *)location);

	if (!euri) {
		g_warning ("Could not form the uri for %s \n", location);
		goto cleanup;
	}

	if (euri->user)
		g_free (euri->user);

	euri->user = g_strdup ((const char *)username);

	temp = e_uri_to_string (euri, FALSE);
	uri->location = g_strdup_printf ("dav://%s", strstr (temp, "//") + 2);
	g_free (temp);
	e_uri_free (euri);

	if (enabled != NULL)
		uri->enabled = atoi ((char *)enabled);
	if (frequency != NULL)
		uri->publish_frequency = atoi ((char *)frequency);
	uri->publish_format = URI_PUBLISH_AS_FB;

	password = e_passwords_get_password ("Calendar", (char *)location);
	if (password) {
		e_passwords_forget_password ("Calendar", (char *)location);
		e_passwords_add_password (uri->location, password);
		e_passwords_remember_password ("Calendar", uri->location);
	}

	for (p = root->children; p != NULL; p = p->next) {
		xmlChar *uid = xmlGetProp (p, (const unsigned char *)"uid");
		if (strcmp ((char *)p->name, "source") == 0) {
			events = g_slist_append (events, uid);
		} else {
			g_free (uid);
		}
	}
	uri->events = events;

	uris = g_slist_prepend (uris, e_publish_uri_to_xml (uri));
	gconf_client_set_list (client, "/apps/evolution/calendar/publish/uris", GCONF_VALUE_STRING, uris, NULL);
	g_slist_foreach (uris, (GFunc) g_free, NULL);
	g_slist_free (uris);
	g_object_unref (client);

cleanup:
	xmlFree (location);
	xmlFree (enabled);
	xmlFree (frequency);
	xmlFree (username);
	xmlFreeDoc (doc);

	return uri;
}
示例#2
0
gboolean eee_account_auth(EeeAccount *self)
{
    GError *err = NULL;
    guint32 flags = E_PASSWORDS_REMEMBER_FOREVER | E_PASSWORDS_SECRET;
    GConfClient *gconf;
    gboolean remember = TRUE;
    char *fail_msg = "";
    char *password;
    int retry_limit = 3;
    gboolean rs;
    char *key;

    if (!eee_account_connect(self))
    {
        return FALSE;
    }
    if (self->priv->is_authorized)
    {
        return TRUE;
    }

    key = g_strdup_printf("eee://%s", self->name);
    password = e_passwords_get_password(EEE_PASSWORD_COMPONENT, key);

    while (retry_limit--)
    {
        if (password == NULL)
        {
            gconf = gconf_client_get_default();
            char *path = g_strdup_printf(EEE_KEY "accounts/%s/remember_password", self->name);
            remember = gconf_client_get_bool(gconf, path, NULL);
            char *prompt = g_strdup_printf("%sEnter password for your 3e calendar account: %s.", fail_msg, self->name);
            // key must have uri format or unpatched evolution segfaults in
            // ep_get_password_keyring()
            password = e_passwords_ask_password(prompt, EEE_PASSWORD_COMPONENT, key, prompt, flags, &remember, NULL);
            gconf_client_set_bool(gconf, path, remember, NULL);
            g_free(path);
            g_object_unref(gconf);
            g_free(prompt);
            if (password == NULL)
            {
                goto err;
            }
        }

        rs = ESClient_authenticate(self->priv->conn, self->name, password, &err);
        g_free(password);
        password = NULL;
        if (!err && rs == TRUE)
        {
            self->priv->is_authorized = TRUE;
            g_free(key);
            return TRUE;
        }

        if (err)
        {
            g_warning("** EEE ** Authentization failed for user '%s'. (%d:%s)", self->name, err->code, err->message);
            if (err->code == ES_XMLRPC_ERROR_AUTH_FAILED)
            {
                g_clear_error(&err);
                fail_msg = "Invalid password. ";
            }
            else
            {
                g_clear_error(&err);
                goto err;
            }
        }
        else
        {
            g_warning("** EEE ** Authentization failed for user '%s' without error.", self->name);
            fail_msg = "Invalid password. ";
        }

        e_passwords_forget_password(EEE_PASSWORD_COMPONENT, key);
        flags |= E_PASSWORDS_REPROMPT;
    }

err:
    g_free(key);
    return FALSE;
}
示例#3
0
static EPublishUri *
migrateURI (const gchar *xml,
            xmlDocPtr doc)
{
	GSettings *settings;
	GSList *events = NULL;
	gchar **set_uris;
	GPtrArray *uris_array;
	xmlChar *location, *enabled, *frequency, *username;
	xmlNodePtr root, p;
	EPublishUri *uri;
	gchar *password, *temp;
	SoupURI *soup_uri;
	gint ii;
	gboolean found = FALSE;

	uri = g_new0 (EPublishUri, 1);

	root = doc->children;
	location = xmlGetProp (root, (const guchar *)"location");
	enabled = xmlGetProp (root, (const guchar *)"enabled");
	frequency = xmlGetProp (root, (const guchar *)"frequency");
	username = xmlGetProp (root, (const guchar *)"username");

	soup_uri = soup_uri_new ((gchar *) location);

	if (soup_uri == NULL) {
		g_warning ("Could not form the uri for %s \n", location);
		goto cleanup;
	}

	soup_uri_set_user (soup_uri, (gchar *) username);

	temp = soup_uri_to_string (soup_uri, FALSE);
	uri->location = g_strdup_printf ("dav://%s", strstr (temp, "//") + 2);
	g_free (temp);

	soup_uri_free (soup_uri);

	if (enabled != NULL)
		uri->enabled = atoi ((gchar *) enabled);
	if (frequency != NULL)
		uri->publish_frequency = atoi ((gchar *) frequency);
	uri->publish_format = URI_PUBLISH_AS_FB;

	password = e_passwords_get_password ((gchar *) location);
	if (password) {
		e_passwords_forget_password ((gchar *) location);
		e_passwords_add_password (uri->location, password);
		e_passwords_remember_password (uri->location);
	}

	for (p = root->children; p != NULL; p = p->next) {
		xmlChar *uid = xmlGetProp (p, (const guchar *)"uid");
		if (strcmp ((gchar *) p->name, "source") == 0) {
			events = g_slist_append (events, uid);
		} else {
			g_free (uid);
		}
	}
	uri->events = events;

	uris_array = g_ptr_array_new_full (3, g_free);

	settings = g_settings_new (PC_SETTINGS_ID);
	set_uris = g_settings_get_strv (settings, PC_SETTINGS_URIS);

	for (ii = 0; set_uris && set_uris[ii]; ii++) {
		const gchar *str = set_uris[ii];
		if (!found && g_str_equal (xml, str)) {
			found = TRUE;
			g_ptr_array_add (uris_array, e_publish_uri_to_xml (uri));
		} else {
			g_ptr_array_add (uris_array, g_strdup (str));
		}
	}

	g_strfreev (set_uris);

	/* this should not happen, right? */
	if (!found)
		g_ptr_array_add (uris_array, e_publish_uri_to_xml (uri));
	g_ptr_array_add (uris_array, NULL);

	g_settings_set_strv (settings, PC_SETTINGS_URIS, (const gchar * const *) uris_array->pdata);

	g_ptr_array_free (uris_array, TRUE);
	g_object_unref (settings);

cleanup:
	xmlFree (location);
	xmlFree (enabled);
	xmlFree (frequency);
	xmlFree (username);
	xmlFreeDoc (doc);

	return uri;
}