Author: adrian.chadd
Date: Tue Apr 21 02:26:23 2009
New Revision: 13965

Modified:
    branches/LUSCA_HEAD/tools/Makefile.am
    branches/LUSCA_HEAD/tools/cossdump.c

Log:
Hack the cossdump program to start using the reusable code rather than  
copy/pasted stuff of its own.



Modified: branches/LUSCA_HEAD/tools/Makefile.am
==============================================================================
--- branches/LUSCA_HEAD/tools/Makefile.am       (original)
+++ branches/LUSCA_HEAD/tools/Makefile.am       Tue Apr 21 02:26:23 2009
@@ -34,7 +34,7 @@
  cachemgr__CGIEXT__SOURCES = cachemgr.c
  cachemgr__CGIEXT__CFLAGS =  
-DDEFAULT_CACHEMGR_CONFIG=\"$(DEFAULT_CACHEMGR_CONFIG)\" $(AM_CFLAGS)

-LDADD = -L../lib -lmiscutil $(XTRA_LIBS)
+LDADD = -L../lib -L../libsqdebug -L../libsqtlv -L../libcore -lsqdebug  
-lsqtlv -lcore -lmiscutil $(XTRA_LIBS)

  EXTRA_DIST = \
        cachemgr.conf

Modified: branches/LUSCA_HEAD/tools/cossdump.c
==============================================================================
--- branches/LUSCA_HEAD/tools/cossdump.c        (original)
+++ branches/LUSCA_HEAD/tools/cossdump.c        Tue Apr 21 02:26:23 2009
@@ -12,9 +12,6 @@
  #if HAVE_UNISTD_H
  #include <unistd.h>
  #endif
-#if HAVE_ASSERT_H
-#include <assert.h>
-#endif
  #if HAVE_STRING_H
  #include <string.h>
  #endif
@@ -26,6 +23,12 @@
  #endif

  #include "../libcore/kb.h"
+#include "../libcore/varargs.h"
+
+#include "../libsqdebug/debug.h"
+
+#include "../libsqtlv/tlv.h"
+
  #include "../libsqstore/store_mgr.h"

  #include "../src/defines.h"
@@ -33,26 +36,6 @@
  #include "../libhttp/HttpHeaderType.h"
  #include "../src/enums.h"

-
-struct _tlv;
-typedef struct _tlv tlv;
-
-struct _tlv {
-    char type;
-    int length;
-    void *value;
-    tlv *next;
-};
-
-#undef debug
-#define        debug(a, b)     printf
-
-#define        MEM_TLV sizeof(tlv)
-#define        memAllocate(a)  malloc(a)
-#define        memFree(a, b)   free(a)
-#define xmalloc(a) malloc(a)
-#define xfree(a) free(a)
-
  #ifndef PRId64
  #ifdef _SQUID_MSWIN_          /* Windows native port using MSVCRT */
  #define PRId64 "I64d"
@@ -73,115 +56,14 @@
  #define strto_off_t strtol
  #endif

-static tlv **
-storeSwapTLVAdd(int type, const void *ptr, size_t len, tlv ** tail)
-{
-    tlv *t = memAllocate(MEM_TLV);
-    t->type = (char) type;
-    t->length = (int) len;
-    t->value = xmalloc(len);
-    xmemcpy(t->value, ptr, len);
-    *tail = t;
-    return &t->next;           /* return new tail pointer */
-}
-
-#if UNUSED_CODE
-static void
-storeSwapTLVFree(tlv * n)
-{
-    tlv *t;
-    while ((t = n) != NULL) {
-       n = t->next;
-       xfree(t->value);
-       memFree(t, MEM_TLV);
-    }
-}
-#endif
-
-#if UNUSED_CODE
-static char *
-storeSwapMetaPack(tlv * tlv_list, int *length)
-{
-    int buflen = 0;
-    tlv *t;
-    int j = 0;
-    char *buf;
-    assert(length != NULL);
-    buflen++;                  /* STORE_META_OK */
-    buflen += sizeof(int);     /* size of header to follow */
-    for (t = tlv_list; t; t = t->next)
-       buflen += sizeof(char) + sizeof(int) + t->length;
-    buflen++;                  /* STORE_META_END */
-    buf = xmalloc(buflen);
-    buf[j++] = (char) STORE_META_OK;
-    xmemcpy(&buf[j], &buflen, sizeof(int));
-    j += sizeof(int);
-    for (t = tlv_list; t; t = t->next) {
-       buf[j++] = (char) t->type;
-       xmemcpy(&buf[j], &t->length, sizeof(int));
-       j += sizeof(int);
-       xmemcpy(&buf[j], t->value, t->length);
-       j += t->length;
-    }
-    buf[j++] = (char) STORE_META_END;
-    assert((int) j == buflen);
-    *length = buflen;
-    return buf;
-}
-#endif
-
-static tlv *
-storeSwapMetaUnpack(const char *buf, int *hdr_len)
-{
-    tlv *TLV;                  /* we'll return this */
-    tlv **T = &TLV;
-    char type;
-    int length;
-    int buflen;
-    int j = 0;
-    assert(buf != NULL);
-    assert(hdr_len != NULL);
-    if (buf[j++] != (char) STORE_META_OK)
-       return NULL;
-    xmemcpy(&buflen, &buf[j], sizeof(int));
-    j += sizeof(int);
-    /*
-     * sanity check on 'buflen' value.  It should be at least big
-     * enough to hold one type and one length.
-     */
-    if (buflen <= (sizeof(char) + sizeof(int)))
-           return NULL;
-    while (buflen - j > (sizeof(char) + sizeof(int))) {
-       type = buf[j++];
-       /* VOID is reserved, but allow some slack for new types.. */
-       if (type <= STORE_META_VOID || type > STORE_META_END + 10) {
-           debug(20, 0) ("storeSwapMetaUnpack: bad type (%d)!\n", type);
-           break;
-       }
-       xmemcpy(&length, &buf[j], sizeof(int));
-       if (length < 0 || length > (1 << 16)) {
-           debug(20, 0) ("storeSwapMetaUnpack: insane length (%d)!\n", length);
-           break;
-       }
-       j += sizeof(int);
-       if (j + length > buflen) {
-           debug(20, 0) ("storeSwapMetaUnpack: overflow!\n");
-           debug(20, 0) ("\ttype=%d, length=%d, buflen=%d, offset=%d\n",
-               type, length, buflen, (int) j);
-           break;
-       }
-       T = storeSwapTLVAdd(type, &buf[j], (size_t) length, T);
-       j += length;
-    }
-    *hdr_len = buflen;
-    return TLV;
-}
-
-
  #define       STRIPESIZE 1048576
  #define       BLOCKSIZE 1024
  #define BLKBITS 10

+
+/* normally in libiapp .. */
+int shutting_down = 0;
+
  static void
  parse_stripe(int stripeid, char *buf, int len, int blocksize)
  {
@@ -194,11 +76,13 @@
      while (j < len) {
        l = NULL;
        bl = 0;
-       tlv_list = storeSwapMetaUnpack(&buf[j], &bl);
+       tlv_list = tlv_unpack(&buf[j], &bl, STORE_META_END + 10);
        if (tlv_list == NULL) {
            printf("  Object: NULL\n");
            return;
        }
+       /* XXX need to make sure the first entry in the list is type  
STORE_META_OK ? (an "int" type) */
+
        printf("  Object: (filen %d) hdr size %d\n", j / blocksize + (stripeid 
*  
STRIPESIZE / blocksize), bl);
        for (t = tlv_list; t; t = t->next) {
            switch (t->type) {
@@ -221,6 +105,8 @@
        tmp = j / blocksize;
        tmp = (tmp + 1) * blocksize;
        j = tmp;
+
+       tlv_free(tlv_list);
      }
  }

@@ -233,6 +119,10 @@
      unsigned int numstripes = 0;
      int blocksize = BLOCKSIZE;
      int blksize_bits;
+
+    /* Setup the debugging library */
+    _db_init("ALL,1");
+    _db_set_stderr_debug(1);

      if (argc < 4) {
        printf("Usage: %s <path to COSS datafile> <blocksize> <number of  
stripes>\n", argv[0]);

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to