diff --git a/src/file.cc b/src/file.cc index 05ebe19..1654764 100644 --- a/src/file.cc +++ b/src/file.cc @@ -1,6 +1,8 @@ #include "file.h" #include +#include +#include File::File() {} @@ -14,6 +16,7 @@ cmark_node * File::fetch(const std::string& path) std::stringstream contents; network.fetchFile(path, &contents); return parser.parseStream(contents); + return NULL; } void File::free(cmark_node *node) diff --git a/src/md-parser.cc b/src/md-parser.cc index d8a8db9..2fcb425 100644 --- a/src/md-parser.cc +++ b/src/md-parser.cc @@ -19,11 +19,9 @@ cmark_node * Parser::parseFile(const std::string &filePath) if( ( file = fopen(filePath.c_str(), "r" ) ) != NULL ) { cmark_node *doc; - // TODO: Copy/paste cmark_parse_file() content to here, allowing me to add extensions to the parser. doc = cmark_parse_file(file, options); fclose(file); - return doc; } return NULL; diff --git a/src/network.cc b/src/network.cc index 5d3813d..4f2e63d 100644 --- a/src/network.cc +++ b/src/network.cc @@ -4,10 +4,21 @@ // Connect to IPFS daemon Network::Network() -: client("localhost", 5001) +: client(NULL) { + try { + client = new ipfs::Client("localhost", 5001); + } catch (const std::exception& e) { + std::cerr << e.what() << std::endl; + // Something else + client = NULL; + } catch (...) { + std::cerr << "Something else!?" << std::endl; + client = NULL; + } } void Network::fetchFile(const std::string& path, std::iostream* response) { - client.FilesGet(path, response); + if (client != NULL) + client->FilesGet(path, response); } \ No newline at end of file diff --git a/src/network.h b/src/network.h index efaab61..9c8ee06 100644 --- a/src/network.h +++ b/src/network.h @@ -13,9 +13,9 @@ class Network { public: Network(); - + void fetchFile(const std::string& path, std::iostream* response); private: - ipfs::Client client; + ipfs::Client *client; }; #endif \ No newline at end of file