Skip to content

Commit

Permalink
Reimplement and remove apache licensed bits of code.
Browse files Browse the repository at this point in the history
 * Reimplement the various bits of the hash table that were
   still based on the apache apr code. Use different algorithms
   for hashing, lookup and other stuff.
 * Use this as an opportunity to cleanup that code and make
   it more legible.

https://bugzilla.redhat.com/show_bug.cgi?id=725905
  • Loading branch information
Stef Walter committed Jul 27, 2011
1 parent 3bb86b7 commit 308a776
Show file tree
Hide file tree
Showing 12 changed files with 578 additions and 722 deletions.
22 changes: 1 addition & 21 deletions COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,4 @@ OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.




================================================================================
PORTIONS COPYRIGHT:

Copyright 2000-2004 The Apache Software Foundation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
DAMAGE.
2 changes: 1 addition & 1 deletion p11-kit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ MODULE_SRCS = \
util.c util.h \
conf.c conf.h \
debug.c debug.h \
hash.c hash.h \
hashmap.c hashmap.h \
modules.c \
pin.c \
proxy.c \
Expand Down
50 changes: 25 additions & 25 deletions p11-kit/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,16 @@ read_config_file (const char* filename, int flags)
}

int
_p11_conf_merge_defaults (hash_t *ht, hash_t *defaults)
_p11_conf_merge_defaults (hashmap *map, hashmap *defaults)
{
hash_iter_t hi;
hashiter iter;
void *key;
void *value;

hash_iterate (defaults, &hi);
while (hash_next (&hi, &key, &value)) {
hash_iterate (defaults, &iter);
while (hash_next (&iter, &key, &value)) {
/* Only override if not set */
if (hash_get (ht, key))
if (hash_get (map, key))
continue;
key = strdup (key);
if (key == NULL) {
Expand All @@ -228,7 +228,7 @@ _p11_conf_merge_defaults (hash_t *ht, hash_t *defaults)
errno = ENOMEM;
return -1;
}
if (!hash_set (ht, key, value)) {
if (!hash_set (map, key, value)) {
free (key);
free (value);
errno = ENOMEM;
Expand All @@ -241,12 +241,12 @@ _p11_conf_merge_defaults (hash_t *ht, hash_t *defaults)
return 0;
}

hash_t*
hashmap *
_p11_conf_parse_file (const char* filename, int flags)
{
char *name;
char *value;
hash_t *ht = NULL;
hashmap *map = NULL;
char *data;
char *next;
char *end;
Expand All @@ -261,8 +261,8 @@ _p11_conf_parse_file (const char* filename, int flags)
if (!data)
return NULL;

ht = hash_create (hash_string_hash, hash_string_equal, free, free);
if (ht == NULL) {
map = hash_create (hash_string_hash, hash_string_equal, free, free);
if (map == NULL) {
free (data);
errno = ENOMEM;
return NULL;
Expand Down Expand Up @@ -308,7 +308,7 @@ _p11_conf_parse_file (const char* filename, int flags)

debug ("config value: %s: %s", name, value);

if (!hash_set (ht, name, value)) {
if (!hash_set (map, name, value)) {
free (name);
free (value);
error = ENOMEM;
Expand All @@ -319,12 +319,12 @@ _p11_conf_parse_file (const char* filename, int flags)
free (data);

if (error != 0) {
hash_free (ht);
ht = NULL;
hash_free (map);
map = NULL;
errno = error;
}

return ht;
return map;
}

static char*
Expand Down Expand Up @@ -355,7 +355,7 @@ expand_user_path (const char *path)
}

static int
user_config_mode (hash_t *config, int defmode)
user_config_mode (hashmap *config, int defmode)
{
const char *mode;

Expand All @@ -377,13 +377,13 @@ user_config_mode (hash_t *config, int defmode)
}
}

hash_t*
hashmap *
_p11_conf_load_globals (const char *system_conf, const char *user_conf,
int *user_mode)
{
hash_t *config = NULL;
hash_t *uconfig = NULL;
hash_t *result = NULL;
hashmap *config = NULL;
hashmap *uconfig = NULL;
hashmap *result = NULL;
char *path = NULL;
int error = 0;
int mode;
Expand Down Expand Up @@ -459,10 +459,10 @@ _p11_conf_load_globals (const char *system_conf, const char *user_conf,
}

static int
load_config_from_file (const char *configfile, const char *name, hash_t *configs)
load_config_from_file (const char *configfile, const char *name, hashmap *configs)
{
hash_t *config;
hash_t *prev;
hashmap *config;
hashmap *prev;
char *key;
int error = 0;

Expand Down Expand Up @@ -498,7 +498,7 @@ load_config_from_file (const char *configfile, const char *name, hash_t *configs
}

static int
load_configs_from_directory (const char *directory, hash_t *configs)
load_configs_from_directory (const char *directory, hashmap *configs)
{
struct dirent *dp;
struct stat st;
Expand Down Expand Up @@ -566,10 +566,10 @@ load_configs_from_directory (const char *directory, hash_t *configs)
return count;
}

hash_t*
hashmap *
_p11_conf_load_modules (int mode, const char *system_dir, const char *user_dir)
{
hash_t *configs;
hashmap *configs;
char *path;
int error = 0;

Expand Down
12 changes: 6 additions & 6 deletions p11-kit/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#ifndef __CONF_H__
#define __CONF_H__

#include "hash.h"
#include "hashmap.h"

enum {
CONF_IGNORE_MISSING = 0x01,
Expand All @@ -51,19 +51,19 @@ enum {

typedef void (*conf_error_func) (const char *message);

int _p11_conf_merge_defaults (hash_t *config,
hash_t *defaults);
int _p11_conf_merge_defaults (hashmap *config,
hashmap *defaults);

/* Returns a hash of char *key -> char *value */
hash_t* _p11_conf_parse_file (const char *filename,
hashmap * _p11_conf_parse_file (const char *filename,
int flags);

/* Returns a hash of char *key -> char *value */
hash_t* _p11_conf_load_globals (const char *system_conf, const char *user_conf,
hashmap * _p11_conf_load_globals (const char *system_conf, const char *user_conf,
int *user_mode);

/* Returns a hash of char* name -> hash_t *config */
hash_t* _p11_conf_load_modules (int user_mode, const char *system_dir,
hashmap * _p11_conf_load_modules (int user_mode, const char *system_dir,
const char *user_dir);

#endif /* __CONF_H__ */
Loading

0 comments on commit 308a776

Please sign in to comment.