]> mj.ucw.cz Git - libucw.git/blobdiff - lib/conf.c
conf2: insert a node into a list as soon as possible instead of at the end
[libucw.git] / lib / conf.c
index 8168eb0cb34463149a28d00e3d8418d5b3456b85..50c3511a293d5a83ffd2f8a20c82c692426609dd 100644 (file)
@@ -1,8 +1,8 @@
 /*
- *     Sherlock Library -- Reading of configuration files
+ *     UCW Library -- Reading of configuration files
  *
  *     (c) 2001 Robert Spalek <robert@ucw.cz>
- *     (c) 2003 Martin Mares <mj@ucw.cz>
+ *     (c) 2003--2005 Martin Mares <mj@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
@@ -46,12 +46,28 @@ cfg_malloc(uns size)
        return mp_alloc(cfpool, size);
 }
 
+void *
+cfg_malloc_zero(uns size)
+{
+       return mp_alloc_zero(cfpool, size);
+}
+
 byte *
 cfg_strdup(byte *s)
 {
        return mp_strdup(cfpool, s);
 }
 
+byte *
+cfg_printf(char *fmt, ...)
+{
+       va_list args;
+       va_start(args, fmt);
+       byte *res = mp_vprintf(cfpool, fmt, args);
+       va_end(args);
+       return res;
+}
+
 void cf_register(struct cfitem *items)
 {
        if(items[0].type!=CT_SECTION && items[0].type!=CT_INCOMPLETE_SECTION)
@@ -106,6 +122,7 @@ static const struct unit units[] = {
        { 0, 0, 0 }
 };
 
+#if 0
 static const struct unit *cf_lookup_unit(byte *value, byte *end, char **msg)
 {
        if (end && *end) {
@@ -202,6 +219,46 @@ byte *cf_parse_double(byte *value, double *varp)
        return msg;
 }
 
+byte *
+cf_parse_ip(byte **p, u32 *varp)
+{
+  while (Cspace(**p))
+    (*p)++;
+  if (!**p)
+    return "Missing IP address";
+  uns x = 0;
+  if (**p == '0' && *(*p + 1) | 32 == 'X')
+    {
+      errno = 0;
+      x = strtoul(*p + 2, (char **)p, 16);
+      if (errno == ERANGE || x > 0xffffffff)
+        goto error;
+    }
+  else
+    for (uns i = 0; i < 4; i++)
+      {
+        if (i)
+          {
+            while (Cspace(**p))
+              (*p)++;
+            if (*(*p)++ != '.')
+              goto error;
+          }
+        while (Cspace(**p))
+          (*p)++;
+        errno = 0;
+        uns y = strtoul(*p, (char **)p, 10);
+        if (errno == ERANGE || y > 255)
+          goto error;
+        x = (x << 8) + y;
+      }
+  *varp = x;
+  return NULL;
+error:
+  return "Invalid IP address";
+}
+#endif
+
 byte *cf_set_item(byte *sect, byte *name, byte *value)
 {
        struct cfitem *item;