diff options
author | Dan Winship <danw@src.gnome.org> | 2003-09-22 20:10:45 +0000 |
---|---|---|
committer | Dan Winship <danw@src.gnome.org> | 2003-09-22 20:10:45 +0000 |
commit | 7b6bfba5f54a53516348413c24b358b70788a142 (patch) | |
tree | 92fa87e481dda9f4c690a983955195162ab9d121 /libsoup/soup-misc.c | |
parent | ed203a51133ed83ba407b0d6b537e0559f86ae87 (diff) | |
download | libsoup-7b6bfba5f54a53516348413c24b358b70788a142.tar.gz |
Move RESPONSE_BLOCK_SIZE #define here from soup-private.h
* libsoup/soup-message-io.c: Move RESPONSE_BLOCK_SIZE #define here
from soup-private.h
* libsoup/soup-misc.c (soup_load_config, etc): Remove all this.
(soup_set_security_policy, soup_get_security_policy): Remove,
since the GNUTLS backend doesn't actually implement it.
(soup_set_ssl_ca_dir, soup_get_ssl_ca_dir): Likewise
* libsoup/soup-misc.h: sync to soup-misc.c. Don't #include extra
stuff.
* libsoup/soup-types.h (SOUP_MAKE_TYPE): Move this here from
soup-private.h
* libsoup/soup-ssl.h: Merge soup_ssl_get_iochannel and
soup_ssl_get_server_iochannel into a single function that takes a
SoupSSLType.
* libsoup/soup-gnutls.c: Remove soup_get_ssl_ca_dir() reference.
(soup_ssl_get_iochannel): Renamed from soup_gnutls_get_iochannel.
(soup_gnutls_set_security_policy): Gone
* libsoup/soup-gnutls.h
* libsoup/soup-ssl.c: Gone; soup-ssl.h is the #include file for
soup-gnutls.c now
* libsoup/soup-socket.c: Move soup_sockaddr_max
#define here from soup-private.h
(soup_socket_start_ssl): Update for new soup_ssl_get_iochannel
prototype.
* libsoup/soup-private.h: Gone
* libsoup/soup-address.c: Fix #includes for soup-private.h and
soup-misc.h changes
* libsoup/soup-auth-digest.c: Likewise
* libsoup/soup-auth.c: Likewise
* libsoup/soup-connection-ntlm.c: Likewise
* libsoup/soup-connection.c: Likewise
* libsoup/soup-dns.c: Likewise
* libsoup/soup-gnutls.c: Likewise
* libsoup/soup-headers.c: Likewise
* libsoup/soup-message-client-io.c: Likewise
* libsoup/soup-message-handlers.c: Likewise
* libsoup/soup-message-io.c: Likewise
* libsoup/soup-message-server-io.c: Likewise
* libsoup/soup-message.c: Likewise
* libsoup/soup-server-message.c: Likewise
* libsoup/soup-server.c: Likewise
* libsoup/soup-session.c: Likewise
* libsoup/soup-socket.c: Likewise
* tests/auth-test.c: Likewise
Diffstat (limited to 'libsoup/soup-misc.c')
-rw-r--r-- | libsoup/soup-misc.c | 317 |
1 files changed, 13 insertions, 304 deletions
diff --git a/libsoup/soup-misc.c b/libsoup/soup-misc.c index b5e81fbc..63b77f6c 100644 --- a/libsoup/soup-misc.c +++ b/libsoup/soup-misc.c @@ -1,47 +1,14 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* - * soup-misc.c: Miscellaneous settings and configuration file handling. + * soup-misc.c: Miscellaneous functions * Copyright (C) 2000-2003, Ximian, Inc. */ #include <ctype.h> #include <string.h> -#include <stdio.h> -#include <stdlib.h> #include "soup-misc.h" -#include "soup-private.h" - -gboolean soup_initialized = FALSE; - -static SoupSecurityPolicy ssl_security_level = SOUP_SECURITY_DOMESTIC; - -/** - * soup_set_security_policy: - * @policy: the %SoupSecurityPolicy to use. - * - * Set the security policy for all secure SSL connections. The security policy - * dictates which algorithms and encryption levels can be used in order to - * conform to your country's security legislation. - */ -void -soup_set_security_policy (SoupSecurityPolicy policy) -{ - ssl_security_level = policy; -} - -/** - * soup_get_security_policy: - * - * Return value: The security policy to use for secure SSL connections. - */ -SoupSecurityPolicy -soup_get_security_policy (void) -{ - return ssl_security_level; -} - guint soup_str_case_hash (gconstpointer key) @@ -60,8 +27,8 @@ gboolean soup_str_case_equal (gconstpointer v1, gconstpointer v2) { - const gchar *string1 = v1; - const gchar *string2 = v2; + const char *string1 = v1; + const char *string2 = v2; return g_strcasecmp (string1, string2) == 0; } @@ -229,8 +196,8 @@ soup_base64_encode_step (const guchar *in, * * Return value: The Base-64 encoded string representing @text. */ -gchar * -soup_base64_encode (const gchar *text, gint inlen) +char * +soup_base64_encode (const char *text, int inlen) { unsigned char *out; int state = 0, outlen; @@ -330,12 +297,12 @@ soup_base64_decode_step (const guchar *in, return outptr - out; } -gchar * -soup_base64_decode (const gchar *text, - gint *out_len) +char * +soup_base64_decode (const char *text, + int *out_len) { - gchar *ret; - gint inlen, state = 0, save = 0; + char *ret; + int inlen, state = 0, save = 0; inlen = strlen (text); ret = g_malloc0 (inlen); @@ -345,238 +312,7 @@ soup_base64_decode (const gchar *text, return ret; } -#define ALLOW_UNLESS_DENIED TRUE -#define DENY_UNLESS_ALLOWED FALSE - -static gboolean allow_policy = ALLOW_UNLESS_DENIED; -static GSList *allow_tokens = NULL; -static GSList *deny_tokens = NULL; - -static void -soup_config_security_policy (gchar *key, gchar *value) -{ - switch (toupper (value [0])) { - case 'D': - if (!g_strcasecmp (&value [1], "OMESTIC")) - soup_set_security_policy (SOUP_SECURITY_DOMESTIC); - break; - case 'E': - if (!g_strcasecmp (&value [1], "XPORT")) - soup_set_security_policy (SOUP_SECURITY_EXPORT); - break; - case 'F': - if (!g_strcasecmp (&value [1], "RANCE")) - soup_set_security_policy (SOUP_SECURITY_FRANCE); - break; - } -} - -static void -soup_config_ssl_ca_file (gchar *key, gchar *value) -{ - soup_set_ssl_ca_file (value); -} - -static void -soup_config_ssl_ca_directory (gchar *key, gchar *value) -{ - soup_set_ssl_ca_dir (value); -} - -static void -soup_config_ssl_certificate (gchar *key, gchar *value) -{ - gint idx; - - idx = strcspn (value, " \t"); - if (!idx) return; - - value [idx] = '\0'; - - idx += strspn (value + idx + 1, " \t"); - if (!idx) return; - - soup_set_ssl_cert_files (value, value + idx); -} - -typedef void (*SoupConfigFunc) (gchar *key, gchar *value); - -struct SoupConfigFuncs { - gchar *key; - SoupConfigFunc func; -} soup_config_funcs [] = { - { "security-policy", soup_config_security_policy }, - { "ssl-ca-file", soup_config_ssl_ca_file }, - { "ssl-ca-directory", soup_config_ssl_ca_directory }, - { "ssl-certificate", soup_config_ssl_certificate }, - { NULL } -}; - -static void -soup_config_reset_allow_deny (void) -{ - GSList *iter; - - for (iter = allow_tokens; iter; iter = iter->next) g_free (iter->data); - for (iter = deny_tokens; iter; iter = iter->next) g_free (iter->data); - - g_slist_free (allow_tokens); - g_slist_free (deny_tokens); - - allow_tokens = deny_tokens = NULL; -} - -static gboolean -soup_config_allow_deny (gchar *key) -{ - GSList **list; - gchar **iter, **split; - - key = g_strchomp (key); - - if (!g_strncasecmp (key, "allow", 5)) list = &allow_tokens; - else if (!g_strncasecmp (key, "deny", 4)) list = &deny_tokens; - else return FALSE; - - iter = split = g_strsplit (key, " ", 0); - if (!split || !split [1]) return TRUE; - - while (*(++iter)) { - if (!g_strcasecmp (iter [0], "all")) { - GSList *iter; - allow_policy = (*list == allow_tokens); - for (iter = *list; iter; iter = iter->next) - g_free (iter->data); - g_slist_free (*list); - *list = NULL; - *list = g_slist_prepend (*list, NULL); - break; - } - - *list = g_slist_prepend (*list, g_strdup (iter [0])); - } - - g_strfreev (split); - return TRUE; -} - -static gboolean -soup_config_token_allowed (gchar *key) -{ - gboolean allow; - GSList *list; - - list = (allow_policy == ALLOW_UNLESS_DENIED) ? deny_tokens:allow_tokens; - allow = (allow_policy == ALLOW_UNLESS_DENIED) ? TRUE : FALSE; - - if (!list) return allow; - - for (; list; list = list->next) - if (!list->data || - !g_strncasecmp (key, - (gchar *) list->data, - strlen ((gchar *) list->data))) - return !allow; - - return allow; -} - -static void -soup_load_config_internal (gchar *config_file, gboolean admin) -{ - struct SoupConfigFuncs *funcs; - FILE *cfg; - char buf[128]; - - cfg = fopen (config_file, "r"); - if (!cfg) return; - - if (admin) soup_config_reset_allow_deny(); - - while (fgets (buf, sizeof (buf), cfg)) { - char *key, *value, *iter, *iter2, **split; - - iter = g_strstrip (buf); - if (!*iter || *iter == '#') continue; - - iter2 = strchr (iter, '#'); - if (iter2) *iter2 = '\0'; - - if (admin && soup_config_allow_deny (iter)) continue; - - if (!admin && !soup_config_token_allowed (iter)) { - g_warning ("Configuration item \"%s\" in file \"%s\" " - "disallowed by system configuration.\n", - iter, - config_file); - continue; - } - - split = g_strsplit (g_strchomp (iter), "=", 2); - - if (!split) continue; - if (!split[1] || split[2]) { - g_strfreev (split); - continue; - } - - key = g_strchomp (split[0]); - value = g_strchug (split[1]); - - for (funcs = soup_config_funcs; funcs && funcs->key; funcs++) - if (!g_strcasecmp (key, funcs->key)) { - funcs->func (key, value); - break; - } - - g_strfreev (split); - } -} - -/** - * soup_load_config: - * @config_file: The file to load configuration from. If NULL, load from .souprc - * in user's home directory. - * - * Load the Soup configuration from file. First attempt to load the system - * configuration from SYSCONFDIR/souprc, then from either the config file name - * passed in config_file, or from .souprc in the user's home directory. - * - * The first time a message is sent using Soup, the configuration is loaded from - * the system souprc file, and the user's souprc file. - * - * soup_load_config can be called multiple times. Each time settings will be - * reset and reread from scratch. - */ -void -soup_load_config (gchar *config_file) -{ - /* Reset values */ - if (soup_initialized) { - soup_set_security_policy (SOUP_SECURITY_DOMESTIC); - } - -#ifdef SYSCONFDIR - /* Load system global config */ - soup_load_config_internal (SYSCONFDIR G_DIR_SEPARATOR_S "souprc", - TRUE); -#endif - - /* Load requested file or user local config */ - if (!config_file) { - gchar *dfile = g_strconcat (g_get_home_dir(), - G_DIR_SEPARATOR_S ".souprc", - NULL); - soup_load_config_internal (dfile, FALSE); - g_free (dfile); - } else - soup_load_config_internal (config_file, FALSE); - - soup_initialized = TRUE; -} - static char *ssl_ca_file = NULL; -static char *ssl_ca_dir = NULL; static char *ssl_cert_file = NULL; static char *ssl_key_file = NULL; @@ -588,7 +324,7 @@ static char *ssl_key_file = NULL; * peers. */ void -soup_set_ssl_ca_file (const gchar *ca_file) +soup_set_ssl_ca_file (const char *ca_file) { g_free (ssl_ca_file); @@ -596,21 +332,6 @@ soup_set_ssl_ca_file (const gchar *ca_file) } /** - * soup_set_ca_dir - * @ca_dir: the directory containing CA certificate files - * - * Specify a directory containing CA certificates to be used to verify - * peers. - */ -void -soup_set_ssl_ca_dir (const gchar *ca_dir) -{ - g_free (ssl_ca_dir); - - ssl_ca_dir = g_strdup (ca_dir); -} - -/** * soup_set_ssl_cert_files * @cert_file: the file containing the SSL client certificate * @key_file: the file containing the SSL private key @@ -619,7 +340,7 @@ soup_set_ssl_ca_dir (const gchar *ca_dir) * authentication with the HTTP server */ void -soup_set_ssl_cert_files (const gchar *cert_file, const gchar *key_file) +soup_set_ssl_cert_files (const char *cert_file, const char *key_file) { g_free (ssl_cert_file); g_free (ssl_key_file); @@ -641,18 +362,6 @@ soup_get_ssl_ca_file (void) } /** - * soup_get_ca_dir - * - * Return value: A directory containing CA certificates to be used to verify - * peers. - */ -const char * -soup_get_ssl_ca_dir (void) -{ - return ssl_ca_dir; -} - -/** * soup_get_ssl_cert_files * @cert_file: the file containing the SSL client certificate * @key_file: the file containing the SSL private key @@ -661,7 +370,7 @@ soup_get_ssl_ca_dir (void) * authentication with the HTTP server */ void -soup_get_ssl_cert_files (const gchar **cert_file, const gchar **key_file) +soup_get_ssl_cert_files (const char **cert_file, const char **key_file) { if (cert_file) *cert_file = ssl_cert_file; |