From: Ted Lemon Date: Sat, 5 Feb 2000 17:39:24 +0000 (+0000) Subject: Handle typed variables. X-Git-Tag: V3-BETA-2-PATCH-1~329 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=11cd757b7d7dc8e0d284fb695ea5e16a93c263f4;p=thirdparty%2Fdhcp.git Handle typed variables. --- diff --git a/server/confpars.c b/server/confpars.c index cc5306402..acef6411c 100644 --- a/server/confpars.c +++ b/server/confpars.c @@ -22,7 +22,7 @@ #ifndef lint static char copyright[] = -"$Id: confpars.c,v 1.101 2000/02/02 17:10:43 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; +"$Id: confpars.c,v 1.102 2000/02/05 17:39:24 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -2164,10 +2164,13 @@ struct lease *parse_lease_declaration (cfile) "name"); strcpy (binding -> name, val); newbinding = 1; - } else if (binding -> value.data) { - data_string_forget (&binding -> value, MDL); + } else if (binding -> value) { + binding_value_dereference (&binding -> value, + MDL); newbinding = 0; } + if (!binding_value_allocate (&binding -> value, MDL)) + log_fatal ("no memory for binding value."); if (!noequal) { token = next_token (&val, cfile); @@ -2180,38 +2183,79 @@ struct lease *parse_lease_declaration (cfile) token = peek_token (&val, cfile); if (token == STRING) { - unsigned char *tuid; - token = next_token (&val, cfile); - binding -> value.len = strlen (val); /* !! */ + unsigned char *tuid; + token = next_token (&val, cfile); + binding -> value -> type = binding_data; + binding -> value -> value.data.len = strlen (val); + if (!(buffer_allocate + (&binding -> value -> value.data.buffer, + binding -> value-> value.data.len + 1, + MDL))) + log_fatal ("No memory for binding."); + strcpy ((char *) + (binding -> value -> + value.data.buffer -> data), val); + binding -> value -> value.data.data = + binding -> value -> value.data.buffer -> data; + binding -> value -> value.data.terminated = 1; + } else if (token == NUMBER_OR_NAME) { + binding -> value -> type = binding_data; + s = ((char *) + (parse_numeric_aggregate + (cfile, (unsigned char *)0, + &binding -> value -> value.data.len, + ':', 16, 8))); + if (!s) { + binding_value_dereference + (&binding -> value, MDL); + return (struct lease *)0; + } + if (binding -> value -> value.data.len) { if (!(buffer_allocate - (&binding -> value.buffer, - binding -> value.len + 1, MDL))) + (&binding -> value -> value.data.buffer, + binding -> value -> value.data.len + 1, + MDL))) log_fatal ("No memory for binding."); - strcpy ((char *) - binding -> value.buffer -> data, val); - binding -> value.data = - binding -> value.buffer -> data; - binding -> value.terminated = 1; + memcpy ((binding -> value -> + value.data.buffer -> data), s, + binding -> value -> value.data.len); + dfree (s, MDL); + binding -> value -> value.data.data = + binding -> value -> value.data.buffer -> data; + } + } else if (token == PERCENT) { + token = next_token (&val, cfile); + token = next_token (&val, cfile); + if (token != NUMBER) { + parse_warn (cfile, + "expecting decimal number."); + if (token != SEMI) + skip_to_semi (cfile); + binding_value_dereference + (&binding -> value, MDL); + return (struct lease *)0; + } + binding -> value -> type = binding_numeric; + binding -> value -> value.intval = atol (val); + } else if (token == NAME) { + token = next_token (&val, cfile); + binding -> value -> type = binding_boolean; + if (!strcasecmp (val, "true")) + binding -> value -> value.boolean = 1; + else if (!strcasecmp (val, "false")) + binding -> value -> value.boolean = 0; + else + goto badbool; } else { - s = ((char *) - (parse_numeric_aggregate - (cfile, (unsigned char *)0, - &binding -> value.len, ':', 16, 8))); - if (!s) - return (struct lease *)0; - if (binding -> value.len) { - if (!(buffer_allocate - (&binding -> value.buffer, - binding -> value.len + 1, MDL))) - log_fatal ("No memory for%s.", - " binding"); - memcpy (binding -> value.buffer -> data, - s, binding -> value.len); - dfree (s, MDL); - binding -> value.data = - binding -> value.buffer -> data; - } + badbool: + parse_warn (cfile, + "expecting a constant value."); + skip_to_semi (cfile); + binding_value_dereference (&binding -> value, + MDL); + return (struct lease *)0; } + if (newbinding) { binding -> next = lease.scope.bindings; lease.scope.bindings = binding; diff --git a/server/db.c b/server/db.c index 13d398a04..7d4c32cdc 100644 --- a/server/db.c +++ b/server/db.c @@ -22,7 +22,7 @@ #ifndef lint static char copyright[] = -"$Id: db.c,v 1.43 2000/02/01 03:19:56 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; +"$Id: db.c,v 1.44 2000/02/05 17:38:17 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -169,31 +169,65 @@ int write_lease (lease) } } for (b = lease -> scope.bindings; b; b = b -> next) { - if (b -> value.data) { - if (db_printable_len (b -> value.data, - b -> value.len)) { + if (!b -> value) + continue; + if (b -> value -> type == binding_data) { + if (b -> value -> value.data.data) { + if (db_printable_len (b -> value -> value.data.data, + b -> value -> value.data.len)) { errno = 0; fprintf (db_file, "\n set %s = \"%.*s\";", b -> name, - (int)b -> value.len, b -> value.data); - } else { + (int)b -> value -> value.data.len, + b -> value -> value.data.data); + if (errno) { + ++errors; + } + } else { errno = 0; fprintf (db_file, "\n set %s = ", b -> name); if (errno) { - ++errors; + ++errors; } - for (i = 0; i < b -> value.len; i++) { - errno = 0; - fprintf (db_file, "%2.2x%s", - b -> value.data [i], - i + 1 == b -> value.len - ? "" : ":"); - if (errno) { - ++errors; - } + for (i = 0; i < b -> value -> value.data.len; i++) + { + errno = 0; + fprintf (db_file, "%2.2x%s", + b -> value -> value.data.data [i], + i + 1 == b -> value -> value.data.len + ? "" : ":"); + if (errno) { + ++errors; + } } + errno = 0; putc (';', db_file); + } } + } else if (b -> value -> type == binding_numeric) { + errno = 0; + fprintf (db_file, "\n set %s = %%%ld;", + b -> name, b -> value -> value.intval); + if (errno) { + ++errors; + } + } else if (b -> value -> type == binding_boolean) { + errno = 0; + fprintf (db_file, "\n set %s = %s;", + b -> name, + b -> value -> value.intval ? "true" : "false"); + if (errno) { + ++errors; + } + } else if (b -> value -> type == binding_dns) { + log_error ("%s: persistent dns values not supported.", + b -> name); + } else if (b -> value -> type == binding_function) { + log_error ("%s: persistent functions not supported.", + b -> name); + } else { + log_error ("%s: unknown binding type %d", + b -> name, b -> value -> type); } } if (lease -> client_hostname &&