]> mj.ucw.cz Git - libucw.git/blobdiff - lib/object.c
tiny bugfix
[libucw.git] / lib / object.c
index 47024c11eaaa7ce6f26f08544a475e6c4ca7f62c..6091d1d75ed20edcfdea7ac8f6b828026263b3bf 100644 (file)
@@ -1,14 +1,15 @@
 /*
  *     Sherlock Library -- Object Functions
  *
- *     (c) 1997--2003 Martin Mares <mj@ucw.cz>
+ *     (c) 1997--2004 Martin Mares <mj@ucw.cz>
+ *     (c) 2004 Robert Spalek <robert@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
  */
 
 #include "lib/lib.h"
-#include "lib/pools.h"
+#include "lib/mempool.h"
 #include "lib/fastbuf.h"
 #include "lib/object.h"
 
@@ -56,62 +57,6 @@ obj_new(struct mempool *pool)
   return o;
 }
 
-int
-obj_read(struct fastbuf *f, struct odes *o)
-{
-  byte buf[MAX_ATTR_SIZE];
-
-  while (bgets(f, buf, sizeof(buf)))
-    {
-      if (!buf[0])
-       return 1;
-      obj_add_attr(o, buf[0], buf+1);
-    }
-  return 0;
-}
-
-void
-obj_read_multi(struct fastbuf *f, struct odes *o)
-{
-  /* Read a multi-part object ending with either EOF or a NUL character */
-  byte buf[MAX_ATTR_SIZE];
-  while (bpeekc(f) > 0 && bgets(f, buf, sizeof(buf)))
-    if (buf[0])
-      obj_add_attr(o, buf[0], buf+1);
-}
-
-void
-obj_write(struct fastbuf *f, struct odes *d)
-{
-  for(struct oattr *a=d->attrs; a; a=a->next)
-    for(struct oattr *b=a; b; b=b->same)
-      {
-       byte *z;
-       bputc(f, a->attr);
-       for(z = b->val; *z; z++)
-         if (*z >= ' ' || *z == '\t')
-           bputc(f, *z);
-         else
-           {
-             bputc(f, '?');
-             log(L_ERROR, "obj_dump: Found non-ASCII characters (URL might be %s)", obj_find_aval(d, 'U'));
-           }
-       ASSERT(z - b->val <= MAX_ATTR_SIZE-2);
-       bputc(f, '\n');
-      }
-}
-
-void
-obj_write_nocheck(struct fastbuf *f, struct odes *d)
-{
-  for(struct oattr *a=d->attrs; a; a=a->next)
-    for(struct oattr *b=a; b; b=b->same)
-      {
-       bputc(f, a->attr);
-       bputsn(f, b->val);
-      }
-}
-
 struct oattr *
 obj_find_attr(struct odes *o, uns x)
 {
@@ -169,7 +114,6 @@ byte *
 obj_find_aval(struct odes *o, uns x)
 {
   struct oattr *a = obj_find_attr(o, x);
-
   return a ? a->val : NULL;
 }
 
@@ -212,17 +156,13 @@ obj_set_attr_num(struct odes *o, uns a, uns v)
 }
 
 static inline struct oattr *
-obj_add_attr_internal(struct odes *o, uns x, byte *v, uns just_ref)
+obj_add_attr_internal(struct odes *o, struct oattr *b)
 {
-  struct oattr *a, *b;
+  struct oattr *a;
 
-  if (just_ref)
-    b = oa_new_ref(o, x, v);
-  else
-    b = oa_new(o, x, v);
-  if (!(a = o->cached_attr) || a->attr != x)
+  if (!(a = o->cached_attr) || a->attr != b->attr)
     {
-      if (!(a = obj_find_attr(o, x)))
+      if (!(a = obj_find_attr(o, b->attr)))
        {
          b->next = o->attrs;
          o->attrs = b;
@@ -240,13 +180,13 @@ obj_add_attr_internal(struct odes *o, uns x, byte *v, uns just_ref)
 struct oattr *
 obj_add_attr(struct odes *o, uns x, byte *v)
 {
-  return obj_add_attr_internal(o, x, v, 0);
+  return obj_add_attr_internal(o, oa_new(o, x, v));
 }
 
 struct oattr *
 obj_add_attr_ref(struct odes *o, uns x, byte *v)
 {
-  return obj_add_attr_internal(o, x, v, 1);
+  return obj_add_attr_internal(o, oa_new_ref(o, x, v));
 }
 
 struct oattr *