--- /dev/null
+/**
+ * © 2008 by David ‘Bombe’ Roden <bombe@pterodactylus.net>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "ED2KLink.h"
+
+static int getDigits(size_t number) {
+ int digits = 0;
+ do {
+ number /= 10;
+ digits++;
+ } while (number);
+ return digits;
+}
+
+ED2KLink::ED2KLink(const char* filename, const size_t size, const void* hash) {
+ this->filename = (char*) malloc(strlen(filename));
+ this->hash = malloc(16);
+
+ strcpy(this->filename, filename);
+ memcpy(this->hash, hash, 16);
+ this->size = size;
+
+ this->link = (char*) calloc(13 + (strlen(filename) + 1) + 1 + getDigits(size) + 1 + 32 + 2, 1);
+ sprintf(this->link, "ed2k://|file|%s|%u|", filename, size);
+ for (int i = 0; i < 16; i++) {
+ sprintf(this->link + strlen(this->link), "%02x", *((int*) this->hash + i));
+ }
+ sprintf(this->link + strlen(this->link), "|/");
+}
+
+ED2KLink::~ED2KLink() {
+ if (link) {
+ free(link);
+ }
+ if (filename) {
+ free(filename);
+ }
+ if (hash) {
+ free(hash);
+ }
+}
+
--- /dev/null
+/**
+ * © 2008 by David ‘Bombe’ Roden <bombe@pterodactylus.net>
+ */
+
+#pragma once
+
+class ED2KLink {
+
+public:
+ ED2KLink(const char* filename, const size_t size, const void* hash);
+ ~ED2KLink();
+
+ const char* getLink();
+ const char* getFilename();
+ const size_t getSize();
+ const void* getHash();
+
+private:
+ char* link;
+ char* filename;
+ size_t size;
+ void* hash;
+};
+