diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2016-02-12 15:24:55 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2016-02-12 15:24:55 +0000 |
commit | 554dba974cf161ac4df8d520a3024f1ba8e21c30 (patch) | |
tree | 689a3f27d31e45e1b0aef005c312ef1e27551230 /bus | |
parent | 610ff8d9646c1bb944bc5e56f22750f1754b308e (diff) | |
download | dbus-554dba974cf161ac4df8d520a3024f1ba8e21c30.tar.gz |
Revert "Add new functions _dbus_hash_table_to_array() and _dbus_hash_table_from_array() from related activation code."
This reverts commit 610ff8d9646c1bb944bc5e56f22750f1754b308e.
This change was intended for 1.11.
Diffstat (limited to 'bus')
-rw-r--r-- | bus/activation.c | 94 |
1 files changed, 92 insertions, 2 deletions
diff --git a/bus/activation.c b/bus/activation.c index 8ca3292d..7b1ab063 100644 --- a/bus/activation.c +++ b/bus/activation.c @@ -729,6 +729,9 @@ update_directory (BusActivation *activation, static dbus_bool_t populate_environment (BusActivation *activation) { + DBusString key; + DBusString value; + int i; char **environment; dbus_bool_t retval = FALSE; @@ -737,7 +740,50 @@ populate_environment (BusActivation *activation) if (environment == NULL) return FALSE; - retval = _dbus_hash_table_from_array (activation->environment, environment, '='); + if (!_dbus_string_init (&key)) + { + dbus_free_string_array (environment); + return FALSE; + } + + if (!_dbus_string_init (&value)) + { + _dbus_string_free (&key); + dbus_free_string_array (environment); + return FALSE; + } + + for (i = 0; environment[i] != NULL; i++) + { + if (!_dbus_string_append (&key, environment[i])) + break; + + if (_dbus_string_split_on_byte (&key, '=', &value)) + { + char *hash_key, *hash_value; + + if (!_dbus_string_steal_data (&key, &hash_key)) + break; + + if (!_dbus_string_steal_data (&value, &hash_value)) + break; + + if (!_dbus_hash_table_insert_string (activation->environment, + hash_key, hash_value)) + break; + } + _dbus_string_set_length (&key, 0); + _dbus_string_set_length (&value, 0); + } + + if (environment[i] != NULL) + goto out; + + retval = TRUE; +out: + + _dbus_string_free (&key); + _dbus_string_free (&value); dbus_free_string_array (environment); return retval; @@ -1553,7 +1599,51 @@ activation_find_entry (BusActivation *activation, static char ** bus_activation_get_environment (BusActivation *activation) { - return _dbus_hash_table_to_array (activation->environment, '='); + char **environment; + int i, length; + DBusString entry; + DBusHashIter iter; + + length = _dbus_hash_table_get_n_entries (activation->environment); + + environment = dbus_new0 (char *, length + 1); + + if (environment == NULL) + return NULL; + + i = 0; + _dbus_hash_iter_init (activation->environment, &iter); + + if (!_dbus_string_init (&entry)) + { + dbus_free_string_array (environment); + return NULL; + } + + while (_dbus_hash_iter_next (&iter)) + { + const char *key, *value; + + key = (const char *) _dbus_hash_iter_get_string_key (&iter); + value = (const char *) _dbus_hash_iter_get_value (&iter); + + if (!_dbus_string_append_printf (&entry, "%s=%s", key, value)) + break; + + if (!_dbus_string_steal_data (&entry, environment + i)) + break; + i++; + } + + _dbus_string_free (&entry); + + if (i != length) + { + dbus_free_string_array (environment); + environment = NULL; + } + + return environment; } dbus_bool_t |