start implementation of binary parsing
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 5 Jul 2008 21:40:17 +0000 (23:40 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 5 Jul 2008 21:40:17 +0000 (23:40 +0200)
CollectionReader.cpp

index f58e5bc..ade7622 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <stdlib.h>
 #include <string.h>
 
 #include <stdlib.h>
 #include <string.h>
+#include <stdint.h>
 #include "CollectionReader.h"
 #include "GlobalSettings.h"
 
 #include "CollectionReader.h"
 #include "GlobalSettings.h"
 
@@ -67,6 +68,54 @@ ED2KLink* CollectionReader::getNextLink() {
                free(line);
                return ed2kLink;
        } else {
                free(line);
                return ed2kLink;
        } else {
+               /* read header */
+               if (!ensureBufferCapacity(4)) {
+                       return NULL;
+               }
+               uint32_t headerTagCount = 0;
+               growingBuffer.read(&headerTagCount, 4);
+               GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] will read %d header tags.\n", __FILE__, __LINE__, headerTagCount);
+               for (uint32_t headerTagIndex = 0; headerTagIndex < headerTagCount; headerTagIndex++) {
+                       uint8_t tagType = 0;
+                       if (!ensureBufferCapacity(1)) {
+                               return NULL;
+                       }
+                       growingBuffer.read(&tagType, 1);
+                       GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] read tag type %d.\n", __FILE__, __LINE__, tagType);
+                       if (tagType == 0x02) {
+                               uint16_t unknown = 0;
+                               if (!ensureBufferCapacity(2)) {
+                                       return NULL;
+                               }
+                               growingBuffer.read(&unknown, 2);
+                               uint8_t tagName = 0;
+                               if (!ensureBufferCapacity(1)) {
+                                       return NULL;
+                               }
+                               growingBuffer.read(&tagName, 1);
+                               GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] read tag name %d.\n", __FILE__, __LINE__, tagName);
+                               uint16_t tagLength = 0;
+                               if (!ensureBufferCapacity(2)) {
+                                       return NULL;
+                               }
+                               growingBuffer.read(&tagLength, 2);
+                               GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] read tag length %d.\n", __FILE__, __LINE__, tagLength);
+                               char* tagValue = (char*) malloc(tagLength + 1);
+                               if (!ensureBufferCapacity(tagLength)) {
+                                       return NULL;
+                               }
+                               growingBuffer.read(tagValue, tagLength);
+                               tagValue[tagLength] = '\0';
+                               if (tagName == 0x01) {
+                                       GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] read FT_FILENAME: “%s”.\n", __FILE__, __LINE__, tagValue);
+                               } else if (tagName == 0x31) {
+                                       GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] read FT_COLLECTIONAUTHOR: “%s”.\n", __FILE__, __LINE__, tagValue);
+                               } else {
+                                       GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] unknown tag: “%s”.\n", __FILE__, __LINE__, tagValue);
+                               }
+                       } else if (tagType == 0x07) {
+                       }
+               }
        }
        return NULL;
 }
        }
        return NULL;
 }