PERFORCE change 84439 for review
soc-bushman
soc-bushman at FreeBSD.org
Wed Sep 28 08:35:04 PDT 2005
http://perforce.freebsd.org/chv.cgi?CH=84439
Change 84439 by soc-bushman at soc-bushman_stinger on 2005/09/28 15:34:40
parser completely rewritten to be similar to the nscd.conf file parser
some minor changes
Affected files ...
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/Makefile#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.8#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf.5#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/config.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/config.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/debug.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/debug.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/hashtable.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/log.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/log.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_rs_query.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_rs_query.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_ws_query.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_ws_query.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/parser.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/parser.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/protocol.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/protocol.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/query.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/query.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/singletons.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/singletons.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/src/include/nscache.h#5 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/getpwent.c#8 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/gethostnamadr.c#4 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nsdispatch.c#8 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nsparser.y#4 edit
.. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/pkg_install/info/show.c#2 integrate
.. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/pkg_install/lib/match.c#2 integrate
.. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nscache.c#8 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nscache.h#4 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nsdispatch.c#7 edit
Differences ...
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/Makefile#3 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.8#3 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.c#3 (text+ko) ====
@@ -44,6 +44,7 @@
#include "config.h"
#include "debug.h"
#include "log.h"
+#include "parser.h"
#include "query.h"
#include "singletons.h"
@@ -576,6 +577,11 @@
pthread_rwlock_unlock(&s_time_lock);
}
+void
+_nss_cache_cycle_prevention_function(void)
+{
+}
+
int
main(int argc, char *argv[])
{
@@ -651,12 +657,16 @@
error_str = NULL;
error_line = 0;
config_file = CONFIG_PATH;
- res = read_configuration(config_file, s_configuration, &error_str,
+// res = read_configuration(config_file, s_configuration, &error_str,
+// &error_line);
+ res = parse_config_file(s_configuration, config_file, &error_str,
&error_line);
if ((res != 0) && (error_str == NULL)) {
config_file = DEFAULT_CONFIG_PATH;
- res = read_configuration(config_file, s_configuration,
- &error_str, &error_line);
+ res = parse_config_file(s_configuration, config_file,
+ &error_str, &error_line);
+// res = read_configuration(config_file, s_configuration,
+// &error_str, &error_line);
}
if (res != 0) {
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf#3 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf.5#3 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.c#3 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.h#3 (text+ko) ====
@@ -34,7 +34,7 @@
#include "hashtable.h"
#include "cacheplcs.h"
-#define CACHE_HT_SIZE 256
+#define CACHE_HT_SIZE 257
enum cache_entry_t {
CET_COMMON = 0, /* cache item is atomic */
@@ -86,10 +86,10 @@
/* unique fields */
char *entry_name;
- size_t max_elemsize; /* if 0 then no check is made */
+ size_t max_elemsize; /* if 0 then no check is made */
size_t satisf_elemsize;
struct timeval max_lifetime; /* if 0 then no check is made */
- enum cache_policy_t policy; /* policy used for transformations */
+ enum cache_policy_t policy; /* policy used for transformations */
};
/* params, used for multipart entries */
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.c#3 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.h#3 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/config.c#3 (text+ko) ====
@@ -27,31 +27,40 @@
#include <assert.h>
#include <math.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "debug.h"
-#include "parser.h"
+
+#define INITIAL_ENTRIES_CAPACITY 8
+#define DEFAULT_SOCKET_PATH "/var/run/cached"
+#define DEFAULT_PIDFILE_PATH "/var/run/cached.pid"
-#define INITIAL_ENTRIES_CAPACITY 8
-#define DEFAULT_SOCKET_PATH "/var/run/cached"
-#define DEFAULT_PIDFILE_PATH "/var/run/cached.pid"
+const char *c_default_entries[6] = {
+ NSDB_PASSWD,
+ NSDB_GROUP,
+ NSDB_HOSTS,
+ NSDB_SERVICES,
+ NSDB_PROTOCOLS,
+ NSDB_RPC
+ };
static int configuration_entry_cmp(const void *, const void *);
static struct configuration_entry *create_configuration_entry(const char *,
uid_t, int, struct timeval const *, struct cache_entry_params const *);
-static void destroy_configuration_entry(struct configuration_entry *);
+/*static void destroy_configuration_entry(struct configuration_entry *);
static int add_configuration_entry(struct configuration *,
- struct configuration_entry *);
+ struct configuration_entry *);*/
-static int process_root_parser_pair(struct configuration *,
+/*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 *);
+ struct parser_group_ *, char const **, int *);*/
static int
configuration_entry_cmp(const void *e1, const void *e2)
@@ -157,7 +166,58 @@
return (retval);
}
-static void
+struct configuration_entry *
+create_def_configuration_entry(const char *name, enum cache_entry_t type)
+{
+ struct common_cache_entry_params common_params;
+ struct mp_cache_entry_params mp_params;
+ struct timeval default_timeout;
+
+ struct configuration_entry *res = NULL;
+
+ TRACE_IN(create_def_configuration_entry);
+ memset(&default_timeout, 0, sizeof(struct timeval));
+ switch (type) {
+ case CET_COMMON:
+ memset(&common_params, 0,
+ sizeof(struct common_cache_entry_params));
+ common_params.entry_type = CET_COMMON;
+ common_params.entry_name = (char *)name;
+ common_params.max_elemsize = 2048;
+ common_params.satisf_elemsize = 1024;
+ common_params.max_lifetime.tv_sec = 60 * 60 * 12;
+ common_params.policy = CPT_LRU;
+
+ default_timeout.tv_sec = DEFAULT_COMMON_ENTRY_TIMEOUT;
+
+ res = create_configuration_entry(name, -1, 0,
+ &default_timeout,
+ (struct cache_entry_params *)&common_params);
+ break;
+ case CET_MULTIPART:
+ memset(&mp_params, 0,
+ sizeof(struct mp_cache_entry_params));
+ mp_params.entry_type = CET_MULTIPART;
+ mp_params.entry_name = (char *)name;
+ mp_params.max_elemsize = 1024 * 8;
+ mp_params.max_sessions = 1024;
+ mp_params.max_lifetime.tv_sec = 60 * 60 * 12;
+
+ default_timeout.tv_sec = DEFAULT_MP_ENTRY_TIMEOUT;
+
+ res = create_configuration_entry(name, -1, 0,
+ &default_timeout,
+ (struct cache_entry_params *)&mp_params);
+ break;
+ default:
+ break;
+ }
+
+ TRACE_OUT(create_def_configuration_entry);
+ return (res);
+}
+
+void
destroy_configuration_entry(struct configuration_entry *entry)
{
TRACE_IN(destroy_configuration_entry);
@@ -171,7 +231,7 @@
TRACE_OUT(destroy_configuration_entry);
}
-static int
+int
add_configuration_entry(struct configuration *config,
struct configuration_entry *entry)
{
@@ -207,7 +267,7 @@
return (0);
}
-static int
+/*static int
process_root_parser_pair(struct configuration *config,
struct parser_pair_ *pair, char const **error_str, int *error_line)
{
@@ -486,7 +546,7 @@
free(params);
TRACE_OUT(process_parser_group);
return (res);
-}
+}*/
size_t
configuration_get_entries_size(struct configuration *config)
@@ -619,11 +679,12 @@
for (i = 0; i < config->entries_size; ++i)
destroy_configuration_entry(config->entries[i]);
- config->entries_size = 0;
+ config->entries_size = 0;
+// config->entries_size = sizeof(c_default_entries) / sizeof(char *);
TRACE_OUT(fill_configuration_defaults);
}
-int
+/*int
read_configuration(const char *fname, struct configuration *config,
char const **error_str, int *error_line)
{
@@ -677,7 +738,7 @@
destroy_parser(config_parser);
TRACE_OUT(read_configuration);
return (res);
-}
+}*/
void
destroy_configuration(struct configuration *config)
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/config.h#3 (text+ko) ====
@@ -31,9 +31,15 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <pthread.h>
+#include <nsswitch.h>
#include <unistd.h>
#include "cachelib.h"
+#define DEFAULT_COMMON_ENTRY_TIMEOUT 10
+#define DEFAULT_MP_ENTRY_TIMEOUT 60
+
+extern const char *c_default_entries[6];
+
struct configuration_entry {
struct timeval query_timeout;
struct cache_entry_params *c_params;
@@ -43,6 +49,9 @@
uid_t desired_euid;
int use_desired_euid;
+
+ int perform_actual_lookups;
+ int enabled;
};
/* the cached configuration parameters */
@@ -64,11 +73,16 @@
};
extern struct configuration *init_configuration(void);
+extern void destroy_configuration(struct configuration *);
extern void fill_configuration_defaults(struct configuration *);
-extern int read_configuration(const char *, struct configuration *,
- char const **, int *);
-extern void destroy_configuration(struct configuration *);
+/*extern int read_configuration(const char *, struct configuration *,
+ char const **, int *);*/
+extern int add_configuration_entry(struct configuration *,
+ struct configuration_entry *);
+extern struct configuration_entry *create_def_configuration_entry(
+ const char *, enum cache_entry_t);
+extern void destroy_configuration_entry(struct configuration_entry *);
extern size_t configuration_get_entries_size(struct configuration *);
extern struct configuration_entry *configuration_get_entry(
struct configuration *, size_t);
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/debug.c#3 (text+ko) ====
@@ -28,19 +28,19 @@
#include <stdio.h>
#include "debug.h"
-static int trace_level=0;
-static int trace_level_bk=0;
+static int trace_level = 0;
+static int trace_level_bk = 0;
void
__trace_in(const char *s, const char *f, int l)
{
int i;
- if (trace_level<TRACE_WANTED)
+ if (trace_level < TRACE_WANTED)
{
- for (i=0;i<trace_level;++i)
+ for (i = 0; i < trace_level; ++i)
printf("\t");
- printf("=> %s\n",s);
+ printf("=> %s\n", s);
}
++trace_level;
@@ -51,12 +51,12 @@
{
int i;
- if (trace_level<TRACE_WANTED)
+ if (trace_level < TRACE_WANTED)
{
- for (i=0;i<trace_level-1;++i)
+ for (i = 0; i < trace_level - 1; ++i)
printf("\t");
- printf("= %s: %d\n",f,l);
+ printf("= %s: %d\n", f, l);
}
}
@@ -65,12 +65,12 @@
{
int i;
- if (trace_level<TRACE_WANTED)
+ if (trace_level < TRACE_WANTED)
{
- for (i=0;i<trace_level-1;++i)
+ for (i = 0; i < trace_level - 1; ++i)
printf("\t");
- printf("= MSG %s, %s: %d\n", msg, f,l);
+ printf("= MSG %s, %s: %d\n", msg, f, l);
}
}
@@ -79,12 +79,12 @@
{
int i;
- if (trace_level<TRACE_WANTED)
+ if (trace_level < TRACE_WANTED)
{
- for (i=0;i<trace_level-1;++i)
+ for (i = 0; i < trace_level - 1; ++i)
printf("\t");
- printf("= PTR %s: %p, %s: %d\n",desc,p,f,l);
+ printf("= PTR %s: %p, %s: %d\n", desc, p, f, l);
}
}
@@ -93,12 +93,12 @@
{
int j;
- if (trace_level<TRACE_WANTED)
+ if (trace_level < TRACE_WANTED)
{
- for (j=0;j<trace_level-1;++j)
+ for (j = 0; j < trace_level - 1; ++j)
printf("\t");
- printf("= INT %s: %i, %s: %d\n",desc,i,f,l);
+ printf("= INT %s: %i, %s: %d\n",desc, i, f, l);
}
}
@@ -107,12 +107,12 @@
{
int i;
- if (trace_level<TRACE_WANTED)
+ if (trace_level < TRACE_WANTED)
{
- for (i=0;i<trace_level-1;++i)
+ for (i = 0; i < trace_level - 1; ++i)
printf("\t");
- printf("= PTR %s: '%s', %s: %d\n",desc,s,f,l);
+ printf("= STR %s: '%s', %s: %d\n", desc, s, f, l);
}
}
@@ -122,25 +122,25 @@
int i;
--trace_level;
- if (trace_level<TRACE_WANTED)
+ if (trace_level < TRACE_WANTED)
{
- for (i=0;i<trace_level;++i)
+ for (i = 0; i < trace_level; ++i)
printf("\t");
- printf("<= %s\n",s);
+ printf("<= %s\n", s);
}
}
void
__trace_on()
{
- trace_level=trace_level_bk;
- trace_level_bk=0;
+ trace_level = trace_level_bk;
+ trace_level_bk = 0;
}
void
__trace_off()
{
- trace_level_bk=trace_level;
- trace_level=1024;
+ trace_level_bk = trace_level;
+ trace_level = 1024;
}
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/debug.h#3 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/hashtable.h#3 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/log.c#3 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/log.h#3 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_rs_query.c#3 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_rs_query.h#3 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_ws_query.c#3 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_ws_query.h#3 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/parser.c#3 (text+ko) ====
@@ -24,664 +24,476 @@
* SUCH DAMAGE.
*
*/
-
+
#include <assert.h>
-#include <limits.h>
+#include <stdio.h>
#include <string.h>
+#include "config.h"
#include "debug.h"
+#include "log.h"
#include "parser.h"
-#define INITIAL_GROUPS_CAPACITY 8
-#define INITIAL_PAIRS_CAPACITY 8
+enum entry_use_type {
+ EUT_COMMON = 0,
+ EUT_MULTIPART = 1,
+ EUT_NEGATIVE = 2,
+ EUT_MAX = 3
+};
-static int add_parser_group(struct parser_ *, struct parser_group_ *);
-static int add_parser_group_pair(struct parser_group_ *,
- struct parser_pair_ *);
-static void destroy_parser_group(struct parser_group_ *);
-static void destroy_parser_pair(struct parser_pair_ *);
-static struct parser_group_ *init_parser_group(const char *, int);
-static struct parser_pair_ *init_parser_pair(const char *, const char *, int);
+static void enable_cache(struct configuration *,const char *, int);
+static struct configuration_entry *find_create_entry(struct configuration *,
+ const char *, enum entry_use_type);
+static int get_number(const char *, int, int);
+static enum cache_policy_t get_policy(const char *);
+static int get_yesno(const char *);
+static int check_cachename(const char *);
+static void check_files(struct configuration *, const char *, int);
+static void set_keep_hot_count(struct configuration *, const char *, int);
+static void set_negative_policy(struct configuration *, const char *,
+ enum cache_policy_t);
+static void set_negative_time_to_live(struct configuration *,
+ const char *, int);
+static void set_positive_policy(struct configuration *, const char *,
+ enum cache_policy_t);
+static void set_perform_actual_lookups(struct configuration *, const char *,
+ int);
+static void set_positive_time_to_live(struct configuration *,
+ const char *, int);
+static void set_suggested_size(struct configuration *, const char *,
+ enum cache_policy_t);
+static int strbreak(char *, char **, int);
-static int parser_expect_char(struct parser_ *, char);
-static int parser_expect_string(struct parser_ *, char *);
-static int parser_check_eof(struct parser_ *);
-static int parser_read_group(struct parser_ *, struct parser_group_ **);
-static int parser_read_pair(struct parser_ *, struct parser_pair_ **);
-static int parser_read_quoted_string(struct parser_ *, char **, size_t *);
-static int parser_read_string(struct parser_ *, char **, size_t *);
-static void parser_skip_spaces(struct parser_ *);
-
-
-static void
-parser_skip_spaces(struct parser_ *the_parser)
+static int
+strbreak(char *str, char **fields, int fields_size)
{
- int comment_flag;
- size_t advance;
+ char *c = str;
+ int i, num;
+
+ TRACE_IN(strbreak);
+ num = 0;
+ for (i = 0;
+ ((*fields =
+ strsep(i < fields_size ? &c : NULL, "\n\t ")) != NULL);
+ ++i)
+ if ((*(*fields)) != '\0') {
+ ++fields;
+ ++num;
+ }
- TRACE_IN(parser_skip_spaces);
- comment_flag = 0;
- do {
- if (comment_flag == 0)
- advance = strspn(the_parser->cur_pos, " \t");
- else
- advance = strcspn(the_parser->cur_pos, "\r\n");
- TRACE_INT(advance);
- the_parser->cur_pos += advance;
- switch (*the_parser->cur_pos) {
- case '#':
- comment_flag = 1;
- ++advance;
- break;
- case '\r':
- case '\n':
- TRACE_INT(the_parser->cur_line);
- comment_flag = 0;
- ++the_parser->cur_line;
- ++the_parser->cur_pos;
- ++advance;
- break;
- default:
- advance = 0;
- break;
- }
- } while (advance > 0);
- TRACE_OUT(parser_skip_spaces);
+ TRACE_OUT(strbreak);
+ return (num);
}
-static int
-parser_expect_char(struct parser_ *the_parser, char model)
+static struct configuration_entry *
+find_create_entry(struct configuration *config,
+ const char *entry_name, enum entry_use_type use_type)
{
+ struct configuration_entry *entry = NULL;
+ struct configuration_entry model;
+ enum cache_entry_t entry_type;
int res;
- TRACE_IN(parser_expect_char);
- if (*the_parser->cur_pos == '\0') {
- TRACE_OUT(parser_expect_char);
- return (PARSER_ERROR_UNEXPECTED_EOF);
- }
-
- if (*the_parser->cur_pos == model) {
- res = PARSER_SUCCESS;
- ++the_parser->cur_pos;
- } else
- res = PARSER_ERROR_UNEXPECTED_CHAR;
- TRACE_OUT(parser_expect_char);
- return (res);
-}
-
-static int
-parser_read_quoted_string(struct parser_ *the_parser, char **result,
- size_t *result_size)
-{
- char *end_quote_pos;
-
- TRACE_IN(parser_read_quoted_string);
- if (*the_parser->cur_pos == '\0') {
- TRACE_OUT(parser_read_quoted_string);
- return (PARSER_ERROR_UNEXPECTED_EOF);
+ TRACE_IN(find_create_entry);
+ memset(&model, 0, sizeof(struct configuration_entry));
+ switch (use_type) {
+ case EUT_COMMON:
+ model.name = (char *)entry_name;
+ break;
+ case EUT_MULTIPART:
+ asprintf(&model.name, "%s_mp", entry_name);
+ assert(model.name != NULL);
+ break;
+ case EUT_NEGATIVE:
+ asprintf(&model.name, "%s_neg", entry_name);
+ assert(model.name != NULL);
+ break;
+ default:
+ /* should be unreachable */
+ break;
}
- if (*the_parser->cur_pos != '"') {
- *result = NULL;
- *result_size = 0;
- TRACE_OUT(parser_read_quoted_string);
- return (PARSER_ERROR_FIRST_QUOTE_NOT_FOUND);
- }
- end_quote_pos = the_parser->cur_pos + 1 +
- strcspn(the_parser->cur_pos + 1,
- "\r\n\"");
- if (*end_quote_pos != '\"') {
- TRACE_OUT(parser_read_quoted_string);
- return (PARSER_ERROR_SECOND_QUOTE_NOT_FOUND);
+ entry = configuration_find_entry(config, &model);
+ if (entry == NULL) {
+ switch (use_type) {
+ case EUT_COMMON:
+ case EUT_NEGATIVE:
+ entry_type = CET_COMMON;
+ break;
+ case EUT_MULTIPART:
+ entry_type = CET_MULTIPART;
+ break;
+ default:
+ /* should be unreachable */
+ break;
+ }
+ entry = create_def_configuration_entry(model.name, entry_type);
+ assert( entry != NULL);
+ res = add_configuration_entry(config, entry);
+ assert(res == 0);
}
- *result = the_parser->cur_pos + 1;
- *end_quote_pos = '\0';
- *result_size = end_quote_pos - *result - 1;
-
- the_parser->cur_pos = end_quote_pos + 1;
- TRACE_OUT(parser_read_quoted_string);
- return (PARSER_SUCCESS);
+ switch (use_type) {
+ case EUT_MULTIPART:
+ case EUT_NEGATIVE:
+ free(model.name);
+ break;
+ default:
+ break;
+ }
+ TRACE_OUT(find_create_entry);
+ return (entry);
}
-static int
-parser_read_string(struct parser_ *the_parser, char **result,
- size_t *result_size)
+static void
+enable_cache(struct configuration *config, const char *entry_name, int flag)
{
- char *last_char_pos;
-
- TRACE_IN(parser_read_string);
- if (*the_parser->cur_pos == '\0') {
- TRACE_OUT(parser_read_string);
- return (PARSER_ERROR_UNEXPECTED_EOF);
- }
-
- last_char_pos = the_parser->cur_pos + strcspn(the_parser->cur_pos,
- " \r\n\t\"'");
-
- if ((*last_char_pos == '\n') || (*last_char_pos == '\r'))
- ++the_parser->cur_line;
- *last_char_pos = '\0';
- *result = the_parser->cur_pos;
- *result_size = last_char_pos - *result - 1;
-
- the_parser->cur_pos = last_char_pos + 1;
- TRACE_OUT(parser_read_string);
- return (PARSER_SUCCESS);
-}
+ struct configuration_entry *entry;
+ int i;
-static int
-parser_expect_string(struct parser_ *the_parser, char *model)
-{
- char *last_char_pos;
- char last_char_backup;
-
- TRACE_IN(parser_expect_string);
- if (*the_parser->cur_pos == '\0') {
- TRACE_OUT(parser_expect_string);
- return (PARSER_ERROR_UNEXPECTED_EOF);
+ TRACE_IN(enable_cache);
+ for (i = 0; i < EUT_MAX; ++i) {
+ entry = find_create_entry(config, entry_name, i);
+ assert(entry != NULL);
+ entry->enabled = flag;
}
-
- last_char_pos = the_parser->cur_pos + strcspn(the_parser->cur_pos,
- " \r\n\t\"'");
-
- last_char_backup = *last_char_pos;
- if ((*last_char_pos == '\n') || (*last_char_pos == '\r'))
- ++the_parser->cur_line;
- *last_char_pos = '\0';
-
- if (strcmp(the_parser->cur_pos, model) == 0) {
- the_parser->cur_pos = last_char_pos + 1;
- TRACE_OUT(parser_expect_string);
- return (PARSER_SUCCESS);
- } else {
- *last_char_pos = last_char_backup;
- TRACE_OUT(parser_expect_string);
- return (PARSER_ERROR_UNEXPECTED_STRING);
- }
+ TRACE_OUT(enable_cache);
}
-static int
-parser_check_eof(struct parser_ *the_parser)
+static void
+set_positive_time_to_live(struct configuration *config,
+ const char *entry_name, int ttl)
{
- TRACE_IN(parser_check_eof);
- TRACE_OUT(parser_check_eof);
- return (*the_parser->cur_pos == '\0' ? 1 : 0);
-}
+ struct configuration_entry *entry;
+ struct timeval lifetime;
-static int
-parser_read_pair(struct parser_ *the_parser, struct parser_pair_ **pair)
-{
- char *token1, *token2;
- size_t token1_size, token2_size;
- int res;
+ TRACE_IN(set_positive_time_to_live);
+ assert(ttl >= 0);
+ assert(entry_name != NULL);
+ memset(&lifetime, 0, sizeof(struct timeval));
+ lifetime.tv_sec = ttl;
- TRACE_IN(parser_read_pair);
- parser_skip_spaces(the_parser);
- res = parser_read_string(the_parser, &token1, &token1_size);
- if (res != PARSER_SUCCESS)
- goto fin;
+ entry = find_create_entry(config, entry_name, EUT_COMMON);
+ assert(entry->c_params->entry_type == CET_COMMON);
+ memcpy(&((struct common_cache_entry_params *)
+ entry->c_params)->max_lifetime,
+ &lifetime, sizeof(struct timeval));
+
+ entry = find_create_entry(config, entry_name, EUT_MULTIPART);
+ assert(entry->c_params->entry_type == CET_MULTIPART);
+ memcpy(&((struct mp_cache_entry_params *)entry->c_params)->max_lifetime,
+ &lifetime, sizeof(struct timeval));
- parser_skip_spaces(the_parser);
- res = parser_expect_char(the_parser, '=');
- if (res != PARSER_SUCCESS) {
- res = PARSER_ERROR_EQUALITY_EXPECTED;
- goto fin;
- }
-
- parser_skip_spaces(the_parser);
- res = parser_read_quoted_string(the_parser, &token2, &token2_size);
- if (res == PARSER_ERROR_FIRST_QUOTE_NOT_FOUND)
- res = parser_read_string(the_parser, &token2, &token2_size);
-
- if (res == PARSER_SUCCESS)
- *pair = init_parser_pair(token1, token2, the_parser->cur_line);
-
-fin:
- TRACE_OUT(parser_read_pair);
- return (res);
+ TRACE_OUT(set_positive_time_to_live);
}
-static int
-parser_read_group(struct parser_ *the_parser, struct parser_group_ **group)
+static void
+set_negative_time_to_live(struct configuration *config,
+ const char *entry_name, int nttl)
{
- struct parser_pair_ *pair;
- char *token;
- size_t token_size;
- int res;
+ struct configuration_entry *entry;
+ struct timeval lifetime;
- TRACE_IN(parser_read_group);
- parser_skip_spaces(the_parser);
- res = parser_expect_string(the_parser, "entry");
- if (res != PARSER_SUCCESS) {
- TRACE_OUT(parser_read_group);
- return (res);
- }
+ TRACE_IN(set_negative_time_to_live);
+ assert(nttl > 0);
+ assert(entry_name != NULL);
+ memset(&lifetime, 0, sizeof(struct timeval));
+ lifetime.tv_sec = nttl;
- parser_skip_spaces(the_parser);
- res = parser_read_quoted_string(the_parser, &token, &token_size);
- if (res != PARSER_SUCCESS)
- goto fin;
-
- parser_skip_spaces(the_parser);
- res = parser_expect_char(the_parser, '{');
- if (res != PARSER_SUCCESS) {
- res = PARSER_ERROR_FIRST_FIGURE_BRACE_EXPECTED;
- goto fin;
- }
-
- *group = init_parser_group(token, the_parser->cur_line);
- pair = NULL;
- do {
- if (pair != NULL)
- add_parser_group_pair(*group, pair);
-
- parser_skip_spaces(the_parser);
- res = parser_expect_char(the_parser, '}');
- if (res == PARSER_SUCCESS)
- break;
-
- res = parser_read_pair(the_parser, &pair);
- TRACE_INT(res);
- } while (res == PARSER_SUCCESS);
-
- if (res != PARSER_SUCCESS)
- destroy_parser_group(*group);
-
-fin:
- TRACE_OUT(parser_read_group);
- return (res);
+ entry = find_create_entry(config, entry_name, EUT_NEGATIVE);
+ assert(entry != NULL);
+ assert(entry->c_params->entry_type == CET_COMMON);
+ memcpy(&((struct common_cache_entry_params *)
+ entry->c_params)->max_lifetime,
+ &lifetime, sizeof(struct timeval));
+
+ TRACE_OUT(set_negative_time_to_live);
}
-void
-parser_pair_dump(struct parser_pair_ *pair)
+static void
+set_keep_hot_count(struct configuration *config,
+ const char *entry_name, int count)
{
- TRACE_IN(parser_pair_dump);
- assert(pair != NULL);
- TRACE_STR(pair->key);
- TRACE_STR(pair->value);
- TRACE_INT(pair->fline);
- TRACE_OUT(parser_pair_dump);
-}
+ struct configuration_entry *entry;
-void
-parser_group_dump(struct parser_group_ *group)
-{
- int i;
- TRACE_IN(parser_group_dump);
- assert(group != NULL);
- TRACE_STR(group->name);
- for (i = 0; i < group->pairs_size; ++i)
- parser_pair_dump(group->pairs[i]);
- TRACE_INT(group->fline);
- TRACE_OUT(parser_group_dump);
-}
-
-void
-parser_dump(struct parser_ *the_parser)
-{
- int i;
- TRACE_IN(parser_dump);
- assert(the_parser != NULL);
- parser_group_dump(the_parser->root_group);
+ TRACE_IN(set_keep_hot_count);
+ assert(count >= 0);
+ assert(entry_name != NULL);
+
+ entry = find_create_entry(config, entry_name, EUT_COMMON);
+ assert(entry != NULL);
+ assert(entry->c_params->entry_type == CET_COMMON);
+ ((struct common_cache_entry_params *)
+ entry->c_params)->max_elemsize = count;
- for (i = 0; i < the_parser->groups_size; ++i)
- parser_group_dump(the_parser->groups[i]);
- TRACE_OUT(parser_dump);
-}
+ entry = find_create_entry(config, entry_name, EUT_NEGATIVE);
+ assert(entry != NULL);
+ assert(entry->c_params->entry_type == CET_COMMON);
+ ((struct common_cache_entry_params *)
+ entry->c_params)->max_elemsize = count;
-static struct parser_group_ *
-init_parser_group(const char *group_name, int fline)
-{
- struct parser_group_ *group;
- size_t group_name_len;
-
- TRACE_IN(init_parser_group);
>>> TRUNCATED FOR MAIL (1000 lines) <<<
More information about the p4-projects
mailing list