PERFORCE change 81635 for review

soc-bushman soc-bushman at FreeBSD.org
Mon Aug 8 07:46:08 GMT 2005


http://perforce.freebsd.org/chv.cgi?CH=81635

Change 81635 by soc-bushman at soc-bushman_stinger on 2005/08/08 07:46:01

	cached in working condition, cachelib is going to be multipart

Affected files ...

.. //depot/projects/soc2005/nsswitch_cached/cached/Makefile#3 edit
.. //depot/projects/soc2005/nsswitch_cached/cached/cached.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/cached/config.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/cached/config.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/cached/debug.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/cached/debug.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/cached/log.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/cached/log.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/cached/protocol.c#2 edit
.. //depot/projects/soc2005/nsswitch_cached/cached/protocol.h#2 edit
.. //depot/projects/soc2005/nsswitch_cached/cached/query.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/cached/query.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/cached/singletons.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/cached/singletons.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/cachelib_test/Makefile#2 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/cachelib_test/cachelib.c#2 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/cachelib_test/cachelib_test.c#2 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/cachelib_test/hashfuncs.c#2 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/cachelib_test/hashfuncs.h#2 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/cachelib_test/hashtable.c#2 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/cachelib_test/hashtable.h#2 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/cachelib_test/include/cachelib.h#2 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/cachelib_test/policies.c#2 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/cachelib_test/policies.h#2 edit

Differences ...

==== //depot/projects/soc2005/nsswitch_cached/cached/Makefile#3 (text+ko) ====

@@ -4,10 +4,10 @@
 PROGNAME=cached
 MAN=
 
-SRCS=cached.c debug.c log.c config.c query.c singletons.c protocol.c
+SRCS=cached.c debug.c log.c config.c query.c singletons.c protocol.c parser.c
 CFLAGS+= -I${.CURDIR}/../
 WARNS?=2
-LDADD+=${.CURDIR}/../cachelib/libcachelib.a
+LDADD+=${.CURDIR}/../cachelib/libcachelib.a -lm
 STRIP=
 
 .include <bsd.prog.mk>

==== //depot/projects/soc2005/nsswitch_cached/cached/cached.c#3 (text+ko) ====

@@ -27,14 +27,28 @@
 static cache
 init_cache_(struct configuration *config)
 {
-	struct cache_params	params;
+	struct cache_params					params;
 	cache	retval;
+		
+	struct configuration_entry	*config_entry;
+	size_t	size, i;
 	
 	TRACE_IN(init_cache_);
+	
 	memset(&params, 0, sizeof(struct cache_params));		
-	params.num_levels = 2;
+	params.num_levels = 2;	
+	retval = init_cache(&params);
 	
-	retval = init_cache(&params);
+/*	memset(&entry_params, 0, sizeof(struct common_cache_entry_params));
+	entry_params.entry_type = CEL_COMMON;
+	entry_params.entry_name = "users";
+	entry_params.policy = CPT_FIFO;
+	register_cache_entry(retval, (struct cache_entry_params *)&entry_params);*/
+	size = configuration_get_entries_size(config);
+	for (i = 0; i < size; ++i) {
+		config_entry = configuration_get_entry(config, i);
+		register_cache_entry(retval, config_entry->c_params);
+	}
 	
 	TRACE_OUT(init_cache_);
 	return (retval);
@@ -118,12 +132,15 @@
 	struct sockaddr	addr;
 	size_t			addr_len;
 	int				fd;
+	int				res;
 		
 	TRACE_IN(accept_connection);
 	addr_len = sizeof(struct sockaddr);
 	fd = accept(event_data->ident, &addr, &addr_len);
 	if (fd == -1) {
 		/* do something */
+		TRACE_POINT();
+		return;
 	}
 	
 	qstate = init_query_state(fd, sizeof(int));
@@ -133,7 +150,9 @@
 		NOTE_LOWAT, qstate->kevent_watermark, qstate);
 	EV_SET(&eventlist[1], fd, EVFILT_TIMER, EV_ADD | EV_ONESHOT,
 		0, config->query_timeout, qstate);
-	kevent(env->queue, eventlist, 2, NULL, 0, &timeout);	
+	res = kevent(env->queue, eventlist, 2, NULL, 0, &timeout);	
+	TRACE_INT(res);
+	TRACE_INT(fd);
 	
 	TRACE_OUT(accept_connection);
 }
@@ -142,25 +161,54 @@
 process_socket_event(struct kevent *event_data, struct runtime_env *env,
 	struct configuration *config)
 {
-	struct kevent	eventlist[1];
+	struct kevent	eventlist[2];
 	struct timespec	timeout;
 	int				nevents;
+	int				res;
+	struct query_state	*qstate;
 		
 	TRACE_IN(process_socket_event);
 	memset(&timeout, 0, sizeof(struct timespec));
+	TRACE_INT(event_data->ident);
 	EV_SET(&eventlist[0], event_data->ident, EVFILT_TIMER, EV_DELETE,
 		0, 0, NULL);
 	nevents = kevent(env->queue, eventlist, 1, NULL, 0, &timeout);
 	if (nevents == -1) {
 		if (errno == ENOENT) {
 			/* the timer is already handling this event */
+			TRACE_POINT();
+			TRACE_OUT(process_socket_event);
 			return;
 		} else {
 			/* some other error happened */
+			TRACE_POINT();
+			TRACE_OUT(process_socket_event);
 			return;
 		}
 	}
 	
+	qstate = (struct query_state *)event_data->udata;
+	do {
+		res = qstate->process_func(qstate);
+	} while ((qstate->kevent_watermark == 0) && 
+			(qstate->process_func != NULL) &&
+			(res == 0));
+
+	TRACE_INT(qstate->kevent_watermark);
+	TRACE_PTR(qstate->process_func);
+	if ((qstate->process_func == NULL) || (res != 0)) {
+		destroy_query_state(qstate);
+		TRACE_POINT();
+		TRACE_OUT(process_socket_event);
+		return;
+	}
+	
+	EV_SET(&eventlist[0], event_data->ident, qstate->kevent_filter,
+		EV_ADD | EV_ONESHOT, NOTE_LOWAT, qstate->kevent_watermark, qstate);
+	EV_SET(&eventlist[1], event_data->ident, EVFILT_TIMER, EV_ADD | EV_ONESHOT,
+		0, config->query_timeout, qstate);	
+	kevent(env->queue, eventlist, 2, NULL, 0, &timeout);
+		
 	TRACE_OUT(process_socket_event);
 }
 
@@ -221,6 +269,9 @@
 
 int main(int argc, char *argv[])
 {
+	char const	*error_str;
+	int			error_line;
+	int			res;
 	/* startup output */
 	print_version_info();	
 
@@ -228,6 +279,16 @@
 	s_configuration = init_configuration();
 	fill_configuration_defaults(s_configuration);
 	
+	error_str = NULL;
+	error_line = 0;
+	res = read_configuration("cached.conf", s_configuration, &error_str, &error_line);
+	if (res != 0) {
+		printf("error in configuration file(%s, %d): %s\n", "cached.conf", 
+			error_line, error_str);
+		destroy_configuration(s_configuration);
+		return (-1);
+	}
+	
 	/* cache initialization */
 	s_cache = init_cache_(s_configuration);
 	

==== //depot/projects/soc2005/nsswitch_cached/cached/config.c#3 (text+ko) ====

@@ -1,12 +1,385 @@
 #include "config.h"
 
 #include <assert.h>
+#include <math.h>
 #include <stdlib.h>
 #include <string.h>
 #include "debug.h"
+#include "parser.h"
 
+#define INITIAL_ENTRIES_CAPACITY 8
 #define DEFAULT_SOCKET_PATH "/tmp/cached"
 
+static	int		configuration_entry_cmp(const void *, const void *);
+static	struct configuration_entry *create_configuration_entry(const char *,
+	uid_t, int, struct cache_entry_params const *);
+static	void	destroy_configuration_entry(struct configuration_entry *);
+static	int		add_configuration_entry(struct configuration *,
+	struct configuration_entry *);
+		
+static	int		process_root_parser_pair(struct configuration *, struct parser_pair_ *, char const **, int *);
+static	int		process_parser_common_group_pair(struct common_cache_entry_params *, struct parser_pair_ *, char const **, int *);
+static	int		process_parser_mp_group_pair(struct mp_cache_entry_params *, struct parser_pair_ *, char const **, int *);
+static	int		process_parser_group(struct configuration *, struct parser_group_ *, char const **, int *);
+
+static int
+configuration_entry_cmp(const void *e1, const void *e2)
+{
+	struct configuration_entry	*entry1;
+	struct configuration_entry	*entry2;
+	int res;
+	
+	entry1 = (struct configuration_entry *)e1;
+	entry2 = (struct configuration_entry *)e2;
+	
+	res = strcmp(entry1->name, entry2->name);
+	if (res == 0) {
+		if ((entry1->use_desired_euid == 0) && (entry2->use_desired_euid != 0))
+			return (-1);
+		else if ((entry1->use_desired_euid != 0) && (entry2->use_desired_euid == 0))
+			return (1);
+		else if ((entry1->use_desired_euid != 0) && (entry2->use_desired_euid != 0))
+			return (entry1->desired_euid - entry2->desired_euid);
+		else
+			return (0);
+	}
+	
+	return (res);
+}
+
+static struct configuration_entry *
+create_configuration_entry(const char *name, uid_t desired_euid, int use_desired_euid,
+	struct cache_entry_params const *params)
+{
+	struct configuration_entry	*retval;
+	size_t	size;
+	
+	TRACE_IN(create_configuration_entry);
+	assert(name != NULL);
+	
+	switch (params->entry_type) {
+	case CEL_COMMON:
+		size = sizeof(struct common_cache_entry_params);
+	break;
+	case CEL_MULTIPART:
+		size = sizeof(struct mp_cache_entry_params);
+	break;
+	default:
+		assert(0);
+		TRACE_OUT(create_configuration_entry);
+		return (NULL);
+	}
+
+	retval = (struct configuration_entry *)malloc(sizeof(struct configuration_entry));
+	assert(retval != NULL);
+	memset(retval, 0, sizeof(struct configuration_entry));
+		
+	retval->c_params = (struct cache_entry_params *)malloc(size);
+	assert(retval->c_params != NULL);
+	memcpy(retval->c_params, params, size);
+	
+	size = strlen(name);
+	retval->name = (char *)malloc(size + 1);
+	assert(retval->name != NULL);
+	memset(retval->name, 0, size + 1);
+	strncpy(retval->name, name, size);
+	
+	if (use_desired_euid == 0)
+		retval->c_params->entry_name = retval->name;
+	else {
+		size = strlen(name) + floor(log(desired_euid)) + 1;
+		retval->c_params->entry_name = (char *)malloc(size + 1);
+		assert(retval->c_params->entry_name != NULL);
+		memset(retval->c_params->entry_name, 0, size + 1);
+		snprintf(retval->c_params->entry_name, size, "%s_%d", name, desired_euid);
+	}
+
+	retval->desired_euid = desired_euid;
+	retval->use_desired_euid = use_desired_euid;
+	
+	TRACE_OUT(create_configuration_entry);
+	return (retval);
+}
+
+static void
+destroy_configuration_entry(struct configuration_entry *entry)
+{
+	TRACE_IN(destroy_configuration_entry);
+	assert(entry != NULL);
+	free(entry->name);
+	if (entry->use_desired_euid != 0)
+		free(entry->c_params->entry_name);
+	free(entry->c_params);
+	free(entry);
+	TRACE_OUT(destroy_configuration_entry);
+}
+
+static int
+add_configuration_entry(struct configuration *config,
+	struct configuration_entry *entry)
+{
+	TRACE_IN(add_configuration_entry);
+	if (config->entries_size == config->entries_capacity) {
+		struct configuration_entry	**new_entries;
+			
+		config->entries_capacity *= 2;
+		new_entries = (struct configuration_entry **)malloc(
+			sizeof(struct configuration_entry *) * config->entries_capacity);
+		assert(new_entries != NULL);
+		memset(new_entries, 0, sizeof(struct configuration_entry *) * 
+			config->entries_capacity);
+		memcpy(new_entries, config->entries, sizeof(struct configuration_entry *) *
+			config->entries_size);
+		
+		free(config->entries);
+		config->entries = new_entries;
+	}
+	
+	config->entries[config->entries_size++] = entry;	
+	qsort(config->entries, config->entries_size, sizeof(struct configuration_entry *),
+		configuration_entry_cmp);
+		
+	TRACE_OUT(add_configuration_entry);
+	return (0);
+}
+
+static int
+process_root_parser_pair(struct configuration *config, struct parser_pair_ *pair,
+	char const **error_str, int *error_line)
+{
+	char	*endp;
+	long	l;
+	size_t	size;
+	int		res;
+	
+	TRACE_IN(process_root_parser_pair);
+	assert(config != NULL);
+	assert(pair != NULL);
+	
+	res = 0;
+	if (strcmp(pair->key, "socket_path") == 0) {
+		free(config->socket_path);
+
+		size = strlen(pair->value);
+		config->socket_path = (char *)malloc(size + 1);
+		memset(config->socket_path, 0, size + 1);
+		strncpy(config->socket_path, pair->value, size);
+	} else if (strcmp(pair->key, "query_timeout") == 0) {
+		l = strtol(pair->value, &endp, 10);
+		if ((*endp == '\0') && (l >= 0))
+			config->query_timeout = l;
+		else {
+			*error_str = "query timeout must be a positive integer";
+			*error_line = pair->fline;
+			res = -1;
+		}
+	} else {
+		*error_str = "unknown parameter";
+		*error_line = pair->fline;
+		res = -1;
+	}
+	
+	TRACE_OUT(process_root_parser_pair);
+	return (res);
+}
+
+static int
+process_parser_common_group_pair(struct common_cache_entry_params *params,
+	struct parser_pair_ *pair, char const **error_str, int *error_line)
+{
+	char	*endp;
+	long	l;
+	int		res;
+		
+	TRACE_IN(process_parser_common_group_pair);
+	res = 0;
+	if (strcmp(pair->key, "policy") == 0) {
+		if (strcmp(pair->value, "fifo") == 0) {
+			params->policy = CPT_FIFO;
+		} else if (strcmp(pair->value, "lru") == 0) {
+			params->policy = CPT_LRU;
+		} else if (strcmp(pair->value, "lfu") == 0) {
+			params->policy = CPT_LFU;
+		} else {
+			*error_str = "policy must be one of 'fifo', 'lru' or 'lfu' values";
+			*error_line = pair->fline;
+			res = -1;
+		}
+	} else if (strcmp(pair->key, "max_lifetime") == 0) {
+		l = strtol(pair->value, &endp, 10);
+		if ((*endp == '\0') && (l >= 0)) {
+			params->max_lifetime.tv_sec = l;
+		} else {
+			*error_str = "max_lifetime must be a positive integer";
+			*error_line = pair->fline;
+			res = -1;
+		}
+	} else if (strcmp(pair->key, "max_elemsize") == 0) {
+		l = strtol(pair->value, &endp, 10);
+		if ((*endp == '\0') && (l >= 0)) {
+			params->max_elemsize = l;
+		} else {
+			*error_str = "max_elemsize must be a positive integer";
+			*error_line = pair->fline;
+			res = -1;
+		}
+	} else {
+		*error_str = "unexpected parameter";
+		*error_line = pair->fline;
+		res = -1;
+	}
+
+	TRACE_OUT(process_parser_common_group_pair);	
+	return (res);
+}
+
+static int
+process_parser_mp_group_pair(struct mp_cache_entry_params *params, 
+	struct parser_pair_ *pair, char const **error_str, int *error_line)
+{
+	int	res;
+	
+	TRACE_IN(process_parser_mp_group_pair);
+	res = -1;
+	TRACE_OUT(process_parser_mp_group_pair);
+	
+	return (res);
+}
+
+static int
+process_parser_group(struct configuration *config, struct parser_group_ *group,
+	char const **error_str, int *error_line)
+{
+	char	*endp;
+	long	l;
+	
+	struct configuration_entry	*config_entry;
+	struct cache_entry_params	*params;
+	uid_t	desired_euid;
+	int		use_desired_euid;
+	
+	struct parser_pair_	*pair;
+	size_t	size, i;
+	int res;
+	
+	TRACE_IN(process_parser_group);
+	assert(config != NULL);
+	assert(group != NULL);
+	
+	res = 0;
+	params = NULL;
+	desired_euid = -1;
+	use_desired_euid = 0;
+	size = parser_group_get_pairs_size(group);
+	if (size > 1) {
+		pair = parser_group_get_pair(group, 0);
+		if (strcmp(pair->key, "type") == 0) {
+			TRACE_STR(pair->value);
+			if (strcmp(pair->value, "common") == 0) {
+				params = (struct cache_entry_params *)malloc(sizeof(
+					struct common_cache_entry_params));
+				assert(params != NULL);
+				memset(params, 0, sizeof(struct common_cache_entry_params));
+					
+				params->entry_type = CEL_COMMON;
+			} else if (strcmp(pair->value, "multipart") == 0) {
+				params = (struct cache_entry_params *)malloc(sizeof(
+					struct mp_cache_entry_params));
+				assert(params != NULL);
+				memset(params, 0, sizeof(struct mp_cache_entry_params));
+					
+				params->entry_type = CEL_MULTIPART;
+			} else {
+				*error_str = "entry type must be one of 'common' and 'multipart' values";
+				*error_line = pair->fline;
+				res = -1;
+				goto fin;
+			}
+		} else {
+			*error_str = "'type' parameter expected";
+			*error_line = pair->fline;
+			res = -1;
+			goto fin;
+		}
+		
+		for (i = 1; i < size; ++i) {
+			pair = parser_group_get_pair(group, i);
+			if (params->entry_type == CEL_COMMON) {
+				res = process_parser_common_group_pair((struct common_cache_entry_params *)params, 
+					pair, error_str, error_line);
+			} else {
+				res = process_parser_mp_group_pair((struct mp_cache_entry_params *)params, 
+					pair, error_str, error_line);
+			}
+					
+			if (res != 0) {
+				if (strcmp(pair->key, "euid") == 0) {
+					l = strtol(pair->value, &endp, 10);
+					if ((*endp != '\0') && (l >= 0)) {
+						desired_euid = l;
+						use_desired_euid = 1;
+					} else {
+						*error_str = "euid parameter must be a positive integer";
+						*error_line = pair->fline;
+						res = -1;
+						goto fin;
+					}
+				} else
+					goto fin;
+			}
+		}
+
+		config_entry = create_configuration_entry(group->name, desired_euid, use_desired_euid, params);
+		res = add_configuration_entry(config, config_entry);
+		if (res != 0) {
+			*error_str = "duplicate entry";
+			*error_line = group->fline;
+		}
+	} else {
+		*error_str = "at least entry type ('common' or 'multipart') must be specified";
+		*error_line = group->fline;
+		res = -1;
+	}
+	
+fin:
+	free(params);
+	TRACE_OUT(process_parser_group);
+	return (res);
+}
+
+size_t
+configuration_get_entries_size(struct configuration *config)
+{
+	TRACE_IN(configuration_get_entries_size);
+	assert(config != NULL);
+	TRACE_OUT(configuration_get_entries_size);
+	return (config->entries_size);
+}
+
+struct configuration_entry *
+configuration_get_entry(struct configuration *config, size_t index)
+{
+	TRACE_IN(configuration_get_entry);
+	assert(config != NULL);
+	assert(index < config->entries_size);
+	TRACE_OUT(configuration_get_entry);
+	return (config->entries[index]);
+}
+
+struct configuration_entry *
+configuration_find_entry(struct configuration *config,
+	struct configuration_entry const *model)
+{
+	struct configuration_entry	**retval;
+		
+	TRACE_IN(configuration_find_entry);
+	retval = bsearch(model, config->entries, config->entries_size,
+		sizeof(struct configuration_entry *), configuration_entry_cmp);
+	TRACE_OUT(configuration_find_entry);
+		
+	return ((retval != NULL) ? *retval : NULL);
+}
+	
 struct configuration *
 init_configuration(void)
 {
@@ -16,15 +389,22 @@
 	retval = (struct configuration *)malloc(sizeof(struct configuration));
 	assert(retval != NULL);
 	memset(retval, 0, sizeof(struct configuration));
-	TRACE_OUT(init_configuration);
-		
+	
+	retval->entries_capacity = INITIAL_ENTRIES_CAPACITY;
+	retval->entries = (struct configuration_entry **)malloc(
+		sizeof(struct configuration_entry *) * retval->entries_capacity);
+	assert(retval->entries != NULL);
+	memset(retval->entries, 0, sizeof(struct configuration_entry *) *
+		retval->entries_capacity);		
+	
+	TRACE_OUT(init_configuration);	
 	return (retval);
 }
 
 void
 fill_configuration_defaults(struct configuration *config)
 {
-	size_t	def_sockpath_len;
+	size_t	def_sockpath_len, i;
 	
 	TRACE_IN(fill_configuration_defaults);
 	assert(config != NULL);
@@ -42,24 +422,77 @@
 	config->force_unlink = 1;
 	
 	config->query_timeout = 8000;
-	
+
+	for (i = 0; i < config->entries_size; ++i)
+		destroy_configuration_entry(config->entries[i]);		
+	config->entries_size = 0;		
 	TRACE_OUT(fill_configuration_defaults);
 }
 
 int
-read_configuration(const char *fname, struct configuration *config)
+read_configuration(const char *fname, struct configuration *config, 
+	char const **error_str, int *error_line)
 {
+	parser	config_parser;
+	struct parser_pair_ *pair;
+	struct parser_group_ *group;
+	size_t	size, i;
+	int		res;
+	
 	TRACE_IN(read_configuration);
+	config_parser = init_parser(fname);
+	if (config_parser == NULL) {
+		TRACE_POINT();
+		TRACE_OUT(read_configuration);
+		return (-1);
+	}
+
+	res = parser_process(config_parser);
+	parser_dump(config_parser);
+	if (res == PARSER_SUCCESS) {
+		for (i = 0; i < config->entries_size; ++i)
+			destroy_configuration_entry(config->entries[i]);		
+		config->entries_size = 0;
+		
+		size = parser_group_get_pairs_size(get_parser_root_group(config_parser));
+		for (i = 0; i < size; ++i) {
+			pair = parser_group_get_pair(get_parser_root_group(config_parser), i);
+			res = process_root_parser_pair(config, pair, error_str, error_line);
+			if (res != 0)
+				goto fin;
+		}
+		
+		size = parser_get_groups_size(config_parser);
+		for (i = 0; i < size; ++i) {
+			group = parser_get_group(config_parser, i);
+			res = process_parser_group(config, group, error_str, error_line);
+			if ( res != 0)
+				goto fin;
+		}
+	} else {
+		*error_str = get_parser_error_str(res);
+		*error_line = config_parser->cur_line;
+		TRACE_STR(get_parser_error_str(res));		
+	}
+
+fin:	
+	destroy_parser(config_parser);
 	TRACE_OUT(read_configuration);
-	return (-1);
+	return (res);
 }
 
 void
 destroy_configuration(struct configuration *config)
 {
+	int	i;
 	TRACE_IN(destroy_configuration);
 	assert(config != NULL);
 	free(config->socket_path);
+	
+	for (i = 0; i < config->entries_size; ++i)
+		destroy_configuration_entry(config->entries[i]);
+	free(config->entries);
+	
 	free(config);
 	TRACE_OUT(destroy_configuration);
 }

==== //depot/projects/soc2005/nsswitch_cached/cached/config.h#3 (text+ko) ====

@@ -1,20 +1,40 @@
 #ifndef __CACHED_CONFIG_H__
 #define __CACHED_CONFIG_H__
 
+#include <cachelib/include/cachelib.h>
 #include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
 
+struct configuration_entry {
+	char	*name;
+	
+	uid_t	desired_euid;
+	int		use_desired_euid;
+	
+	struct cache_entry_params	*c_params;
+};
+
 /* the cached configuration parameters */
 struct configuration {
 	char	*socket_path;	
 	mode_t	socket_mode;
-	int		force_unlink;
+	int		force_unlink;	
+	int		query_timeout;
 	
-	int		query_timeout;
+	struct configuration_entry	**entries;
+	size_t	entries_capacity;
+	size_t	entries_size;
 };
 
 struct configuration	*init_configuration(void);
 void	fill_configuration_defaults(struct configuration *);
-int		read_configuration(const char *, struct configuration *);
+int		read_configuration(const char *, struct configuration *, char const **, int *);
 void	destroy_configuration(struct configuration *);
+	
+size_t	configuration_get_entries_size(struct configuration *);
+struct configuration_entry	*configuration_get_entry(struct configuration *, size_t);
+struct configuration_entry	*configuration_find_entry(struct configuration *,
+	struct configuration_entry const *);
 
 #endif

==== //depot/projects/soc2005/nsswitch_cached/cached/debug.c#3 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/cached/debug.h#3 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/cached/log.c#3 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/cached/log.h#3 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/cached/protocol.c#2 (text+ko) ====

@@ -73,6 +73,7 @@
 init_cache_write_request(struct cache_write_request *write_request)
 {
 	TRACE_IN(init_cache_write_request);
+	memset(write_request, 0, sizeof(struct cache_write_request));
 	TRACE_OUT(init_cache_write_request);
 }
 
@@ -80,6 +81,9 @@
 finalize_cache_write_request(struct cache_write_request *write_request)
 {
 	TRACE_IN(finalize_cache_write_request);
+	free(write_request->entry);
+	free(write_request->cache_key);
+	free(write_request->data);
 	TRACE_OUT(finalize_cache_write_request);
 }
 
@@ -96,6 +100,7 @@
 init_cache_write_response(struct cache_write_response *write_response)
 {
 	TRACE_IN(init_cache_write_response);
+	memset(write_response, 0, sizeof(struct cache_write_response));
 	TRACE_OUT(init_cache_write_response);
 }
 
@@ -119,6 +124,7 @@
 init_cache_read_request(struct cache_read_request *read_request)
 {
 	TRACE_IN(init_cache_read_request);
+	memset(read_request, 0, sizeof(struct cache_read_request));
 	TRACE_OUT(init_cache_read_request);
 }
 
@@ -126,6 +132,8 @@
 finalize_cache_read_request(struct cache_read_request *read_request)
 {
 	TRACE_IN(finalize_cache_read_request);
+	free(read_request->entry);
+	free(read_request->cache_key);
 	TRACE_OUT(finalize_cache_read_request);
 }
 
@@ -142,6 +150,7 @@
 init_cache_read_response(struct cache_read_response *read_response)
 {
 	TRACE_IN(init_cache_read_response);
+	memset(read_response, 0, sizeof(struct cache_read_response));
 	TRACE_OUT(init_cache_read_response);
 }
 
@@ -149,6 +158,7 @@
 finalize_cache_read_response(struct cache_read_response *read_response)
 {
 	TRACE_IN(finalize_cache_read_response);
+	free(read_response->data);
 	TRACE_OUT(finalize_cache_read_response);
 }
 
@@ -165,6 +175,7 @@
 init_cache_transform_request(struct cache_transform_request *transform_request)
 {
 	TRACE_IN(init_cache_transform_request);
+	memset(transform_request, 0, sizeof(struct cache_transform_request));
 	TRACE_OUT(init_cache_transform_request);
 }
 
@@ -172,6 +183,7 @@
 finalize_cache_transform_request(struct cache_transform_request *transform_request)
 {
 	TRACE_IN(finalize_cache_transform_request);
+	free(transform_request->entry);
 	TRACE_OUT(finalize_cache_transform_request);
 }
 
@@ -188,6 +200,7 @@
 init_cache_transform_response(struct cache_transform_response *transform_response)
 {
 	TRACE_IN(init_cache_transform_request);
+	memset(transform_response, 0, sizeof(struct cache_transform_response));
 	TRACE_OUT(init_cache_transform_request);
 }
 

==== //depot/projects/soc2005/nsswitch_cached/cached/protocol.h#2 (text+ko) ====

@@ -6,7 +6,7 @@
 struct cache_write_request
 {
 	size_t	entry_length;
-	char	*entry;			// ignored if entry_length is 0
+	char	*entry;
 
 	size_t	cache_key_length;
 	char	*cache_key;
@@ -23,7 +23,7 @@
 struct cache_read_request
 {
 	size_t	entry_length;
-	char	*entry;			// ignored if error_code is 0
+	char	*entry;
 
 	size_t	cache_key_length;
 	char	*cache_key;
@@ -33,8 +33,8 @@
 {
 	int		error_code;
 
-	size_t	data_size;		// ignored if error_code is 0
-	void	*data;			// ignored if error_code is 0
+	size_t	data_size;		// ignored if error_code is not 0
+	void	*data;			// ignored if error_code is not 0
 };
 
 struct cache_transform_request

==== //depot/projects/soc2005/nsswitch_cached/cached/query.c#3 (text+ko) ====

@@ -1,4 +1,5 @@
 #include "query.h"
+#include <cachelib/include/cachelib.h>
 #include <sys/socket.h>
 #include <sys/time.h>
 #include <sys/types.h>
@@ -8,6 +9,7 @@
 #include <string.h>
 #include "debug.h"
 #include "log.h"
+#include "singletons.h"
 
 static	int		on_query_startup(struct query_state *);
 static	void	on_query_destroy(struct query_state *);
@@ -19,9 +21,9 @@
 	
 static	int		on_read_request_read1(struct query_state *);
 static	int		on_read_request_read2(struct query_state *);
-//static	int		on_read_request_process(struct query_state *);
-//static	int		on_read_response_write1(struct query_state *);
-//static	int		on_read_response_write2(struct query_state *);
+static	int		on_read_request_process(struct query_state *);
+static	int		on_read_response_write1(struct query_state *);
+static	int		on_read_response_write2(struct query_state *);
 	
 static	int		on_transform_request_read1(struct query_state *);
 //static	int		on_transform_request_process(struct query_state *);
@@ -69,6 +71,10 @@
 	qstate->euid = cmsg.creds.cmcred_euid;
 	qstate->pid = cmsg.creds.cmcred_pid;
 	
+	TRACE_INT(qstate->uid);
+	TRACE_INT(qstate->euid);
+	TRACE_INT(qstate->pid);
+	
 	switch (elem_type) {
 	case CET_WRITE_REQUEST:
 		qstate->process_func = on_write_request_read1;
@@ -116,6 +122,7 @@
 		result += qstate->read_func(qstate, &write_request->data_size, sizeof(size_t));
 		
 		if (result != sizeof(size_t) * 3) {
+			TRACE_INT(result);
 			TRACE_OUT(on_write_request_read1);
 			return (-1);
 		}
@@ -162,6 +169,7 @@
 	result += qstate->read_func(qstate, write_request->data, write_request->data_size);
 	
 	if (result != qstate->kevent_watermark) {
+		TRACE_INT(result);
 		TRACE_OUT(on_write_request_read2);
 		return (-1);
 	}
@@ -175,9 +183,34 @@
 static	int
 on_write_request_process(struct query_state *qstate)
 {
+	struct cache_write_request	*write_request;
+	struct cache_write_response	*write_response;
+	cache_entry c_entry;
+	
 	TRACE_IN(on_write_request_process);
 	init_comm_element(&qstate->response, CET_WRITE_RESPONSE);
+	write_response = get_cache_write_response(&qstate->response);
+	write_request = get_cache_write_request(&qstate->request);
 	
+	TRACE_INT(write_request->entry_length);
+	TRACE_STR(write_request->entry);
+	TRACE_INT(write_request->cache_key_length);
+	TRACE_STR(write_request->cache_key);
+	TRACE_INT(write_request->data_size);
+	
+	c_entry = find_cache_entry(s_cache, write_request->entry);
+	if (c_entry != NULL) {
+		TRACE_POINT();
+		write_response->error_code = cache_write(c_entry, write_request->cache_key,
+		write_request->data, write_request->data_size);
+	} else {
+		TRACE_POINT();
+		write_response->error_code = -1;
+	}
+	
+	TRACE_INT(write_response->error_code);
+	
+	qstate->kevent_filter = EVFILT_WRITE;
 	qstate->kevent_watermark = sizeof(int);
 	qstate->process_func = on_write_response_write1;
 	TRACE_OUT(on_write_request_process);
@@ -221,10 +254,17 @@
 		result += qstate->read_func(qstate, &read_request->cache_key_length, sizeof(size_t));
 		
 		if (result != sizeof(size_t) * 2) {
+			TRACE_INT(result);
 			TRACE_OUT(on_read_request_read1);
 			return (-1);
 		}
 		
+		if ((read_request->entry_length == 0) ||
+			(read_request->cache_key_length == 0)) {
+			TRACE_OUT(on_read_request_read1);
+			return (-1);
+		}
+		
 		read_request->entry = (char *)malloc(read_request->entry_length + 1);
 		assert(read_request->entry != NULL);
 		memset(read_request->entry, 0, read_request->entry_length + 1);
@@ -245,7 +285,136 @@
 static int
 on_read_request_read2(struct query_state *qstate)
 {
-	return (-1);
+	struct cache_read_request	*read_request;
+	ssize_t	result;
+
+	TRACE_IN(on_read_request_read2);
+	read_request = get_cache_read_request(&qstate->request);
+
+	result = qstate->read_func(qstate, read_request->entry, 
+		read_request->entry_length);
+	result += qstate->read_func(qstate, read_request->cache_key, 
+		read_request->cache_key_length);
+	
+	if (result != qstate->kevent_watermark) {
+		TRACE_INT(result);
+		TRACE_OUT(on_read_request_read2);
+		return (-1);		
+	}
+	
+	qstate->kevent_watermark = 0;
+	qstate->process_func = on_read_request_process;

>>> TRUNCATED FOR MAIL (1000 lines) <<<


More information about the p4-projects mailing list