/** * soup_auth_update: * @auth: a #SoupAuth * @msg: the #SoupMessage @auth is being updated for * @auth_header: the WWW-Authenticate/Proxy-Authenticate header * * Updates @auth with the information from @msg and @auth_header, * possibly un-authenticating it. As with soup_auth_new(), this is * normally only used by #SoupSession. * * Return value: %TRUE if @auth is still a valid (but potentially * unauthenticated) #SoupAuth. %FALSE if something about @auth_params * could not be parsed or incorporated into @auth at all. **/ gboolean soup_auth_update (SoupAuth *auth, SoupMessage *msg, const char *auth_header) { GHashTable *params; const char *scheme, *realm; gboolean was_authenticated, success; g_return_val_if_fail (SOUP_IS_AUTH (auth), FALSE); g_return_val_if_fail (SOUP_IS_MESSAGE (msg), FALSE); g_return_val_if_fail (auth_header != NULL, FALSE); scheme = soup_auth_get_scheme_name (auth); if (g_ascii_strncasecmp (auth_header, scheme, strlen (scheme)) != 0) return FALSE; params = soup_header_parse_param_list (auth_header + strlen (scheme)); if (!params) params = g_hash_table_new (NULL, NULL); realm = g_hash_table_lookup (params, "realm"); if (realm && auth->realm && strcmp (realm, auth->realm) != 0) { soup_header_free_param_list (params); return FALSE; } was_authenticated = soup_auth_is_authenticated (auth); success = SOUP_AUTH_GET_CLASS (auth)->update (auth, msg, params); if (was_authenticated != soup_auth_is_authenticated (auth)) g_object_notify (G_OBJECT (auth), SOUP_AUTH_IS_AUTHENTICATED); soup_header_free_param_list (params); return success; }
/** * soup_auth_authenticate: * @auth: a #SoupAuth * @username: the username provided by the user or client * @password: the password provided by the user or client * * Call this on an auth to authenticate it; normally this will cause * the auth's message to be requeued with the new authentication info. **/ void soup_auth_authenticate (SoupAuth *auth, const char *username, const char *password) { gboolean was_authenticated; g_return_if_fail (SOUP_IS_AUTH (auth)); g_return_if_fail (username != NULL); g_return_if_fail (password != NULL); was_authenticated = soup_auth_is_authenticated (auth); SOUP_AUTH_GET_CLASS (auth)->authenticate (auth, username, password); if (was_authenticated != soup_auth_is_authenticated (auth)) g_object_notify (G_OBJECT (auth), SOUP_AUTH_IS_AUTHENTICATED); }
static void soup_auth_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { SoupAuth *auth = SOUP_AUTH (object); SoupAuthPrivate *priv = SOUP_AUTH_GET_PRIVATE (object); switch (prop_id) { case PROP_SCHEME_NAME: g_value_set_string (value, soup_auth_get_scheme_name (auth)); break; case PROP_REALM: if (auth->realm) g_free (auth->realm); g_value_set_string (value, soup_auth_get_realm (auth)); break; case PROP_HOST: if (priv->host) g_free (priv->host); g_value_set_string (value, soup_auth_get_host (auth)); break; case PROP_IS_FOR_PROXY: g_value_set_boolean (value, priv->proxy); break; case PROP_IS_AUTHENTICATED: g_value_set_boolean (value, soup_auth_is_authenticated (auth)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void authenticate_auth (SoupAuthManager *manager, SoupAuth *auth, SoupMessage *msg, gboolean prior_auth_failed, gboolean proxy, gboolean can_interact) { SoupAuthManagerPrivate *priv = manager->priv; SoupURI *uri; if (proxy) { SoupMessageQueue *queue; SoupMessageQueueItem *item; queue = soup_session_get_queue (priv->session); item = soup_message_queue_lookup (queue, msg); if (item) { uri = soup_connection_get_proxy_uri (item->conn); soup_message_queue_item_unref (item); } else uri = NULL; if (!uri) return; } else uri = soup_message_get_uri (msg); /* If a password is specified explicitly in the URI, use it * even if the auth had previously already been authenticated. */ if (uri->password && uri->user) { soup_auth_authenticate (auth, uri->user, uri->password); soup_uri_set_password (uri, NULL); soup_uri_set_user (uri, NULL); } else if (!soup_auth_is_authenticated (auth) && can_interact) { g_signal_emit (manager, signals[AUTHENTICATE], 0, msg, auth, prior_auth_failed); } }