static SoupAuth * record_auth_for_uri (SoupAuthManagerPrivate *priv, SoupURI *uri, SoupAuth *auth, gboolean prior_auth_failed) { SoupAuthHost *host; SoupAuth *old_auth; const char *path; char *auth_info, *old_auth_info; GSList *pspace, *p; host = get_auth_host_for_uri (priv, uri); auth_info = soup_auth_get_info (auth); if (!host->auth_realms) { host->auth_realms = soup_path_map_new (g_free); host->auths = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); } /* Record where this auth realm is used. */ pspace = soup_auth_get_protection_space (auth, uri); for (p = pspace; p; p = p->next) { path = p->data; old_auth_info = soup_path_map_lookup (host->auth_realms, path); if (old_auth_info) { if (!strcmp (old_auth_info, auth_info)) continue; soup_path_map_remove (host->auth_realms, path); } soup_path_map_add (host->auth_realms, path, g_strdup (auth_info)); } soup_auth_free_protection_space (auth, pspace); /* Now, make sure the auth is recorded. (If there's a * pre-existing good auth, we keep that rather than the new one, * since the old one might already be authenticated.) */ old_auth = g_hash_table_lookup (host->auths, auth_info); if (old_auth && (old_auth != auth || !prior_auth_failed)) { g_free (auth_info); return old_auth; } else { g_hash_table_insert (host->auths, auth_info, g_object_ref (auth)); return auth; } }
/** * soup_auth_domain_covers: * @domain: a #SoupAuthDomain * @msg: a #SoupMessage * * Checks if @domain requires @msg to be authenticated (according to * its paths and filter function). This does not actually look at * whether @msg *is* authenticated, merely whether or not is needs to * be. * * This is used by #SoupServer internally and is probably of no use to * anyone else. * * Return value: %TRUE if @domain requires @msg to be authenticated **/ gboolean soup_auth_domain_covers (SoupAuthDomain *domain, SoupMessage *msg) { SoupAuthDomainPrivate *priv = SOUP_AUTH_DOMAIN_GET_PRIVATE (domain); const char *path; path = soup_message_get_uri (msg)->path; if (!soup_path_map_lookup (priv->paths, path)) return FALSE; if (priv->filter && !priv->filter (domain, msg, priv->filter_data)) return FALSE; else return TRUE; }
static SoupServerHandler * soup_server_get_handler (SoupServer *server, const char *path) { SoupServerPrivate *priv; SoupServerHandler *hand; g_return_val_if_fail (SOUP_IS_SERVER (server), NULL); priv = SOUP_SERVER_GET_PRIVATE (server); if (path) { hand = soup_path_map_lookup (priv->handlers, path); if (hand) return hand; if (!strcmp (path, "*")) return NULL; } return priv->default_handler; }
static SoupAuth * lookup_auth (SoupAuthManagerPrivate *priv, SoupMessage *msg) { SoupAuthHost *host; const char *path, *realm; host = get_auth_host_for_uri (priv, soup_message_get_uri (msg)); if (!host->auth_realms && !make_auto_ntlm_auth (priv, host)) return NULL; path = soup_message_get_uri (msg)->path; if (!path) path = "/"; realm = soup_path_map_lookup (host->auth_realms, path); if (realm) return g_hash_table_lookup (host->auths, realm); else return NULL; }
/** * soup_server_remove_handler: * @server: a #SoupServer * @path: the toplevel path for the handler * * Removes the handler registered at @path. **/ void soup_server_remove_handler (SoupServer *server, const char *path) { SoupServerPrivate *priv; SoupServerHandler *hand; g_return_if_fail (SOUP_IS_SERVER (server)); priv = SOUP_SERVER_GET_PRIVATE (server); if (!path || !*path || !strcmp (path, "/")) { if (priv->default_handler) { unregister_handler (priv->default_handler); free_handler (priv->default_handler); priv->default_handler = NULL; } return; } hand = soup_path_map_lookup (priv->handlers, path); if (hand && !strcmp (path, hand->path)) { unregister_handler (hand); soup_path_map_remove (priv->handlers, path); } }