From 0594ac9ba0f38944ef810b5ac48a2067b1ce5a09 Mon Sep 17 00:00:00 2001
From: Joel Grunbaum <joelgrun@gmail.com>
Date: Tue, 11 Jan 2022 08:00:10 +0000
Subject: [PATCH] Copied libcurl's ftp example
---
bom.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
bom.hpp | 10 ++++++++++
2 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/bom.cpp b/bom.cpp
new file mode 100644
index 0000000..79c7d66
--- /dev/null
+++ b/bom.cpp
@@ -0,0 +1,49 @@
+#include "bom.hpp"
+
+#include "book.hpp"
+#include <cstddef>
+#include <cstdio>
+#include <curl/curl.h>
+#include <stdio.h>
+#include <string>
+#include <unordered_map>
+
+namespace bom
+{
+
+static size_t my_fwrite(void* buffer, size_t size, size_t nmemb, void* stream)
+{
+ FILE* out = (FILE*)stream;
+ if (!out) {
+ out = tmpfile();
+ if (!out) {
+ return -1;
+ }
+ }
+ return fwrite(buffer, size, nmemb, out);
+}
+void updateBom(std::unordered_map<std::string, book::Book>& bs)
+{
+ CURL* curl;
+ CURLcode res;
+ FILE* f{NULL};
+ curl_global_init(CURL_GLOBAL_DEFAULT);
+ curl = curl_easy_init();
+ if (curl) {
+ curl_easy_setopt(curl, CURLOPT_URL,
+ "ftp://ftp.bom.gov.au/anon/gen/fwo/IDN60920.xml");
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, &f);
+ curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ if (CURLE_OK != res) {
+ fprintf(stderr, "Curl failed: %d\n", res);
+ }
+ }
+ if (f) {
+ fclose(f);
+ }
+ curl_global_cleanup();
+}
+} // namespace bom
diff --git a/bom.hpp b/bom.hpp
new file mode 100644
index 0000000..5439ef0
--- /dev/null
+++ b/bom.hpp
@@ -0,0 +1,10 @@
+#pragma once
+
+#include "book.hpp"
+#include <string>
+#include <unordered_map>
+
+namespace bom
+{
+void updateBom(std::unordered_map<std::string, book::Book>& bs);
+}
--
Gitblit v1.10.0