]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: Add scaffolding for downloader
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 10 Mar 2021 15:09:31 +0000 (15:09 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 10 Mar 2021 15:09:31 +0000 (15:09 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/libpakfire/downloader.c [new file with mode: 0644]
src/libpakfire/include/pakfire/downloader.h [new file with mode: 0644]

index 3a8ff8e59e99b13a1432c626c7968ee334e53134..801fa517f32f8c997f37e061431677c2b914187d 100644 (file)
@@ -261,6 +261,7 @@ libpakfire_la_SOURCES = \
        src/libpakfire/archive.c \
        src/libpakfire/db.c \
        src/libpakfire/dist.c \
+       src/libpakfire/downloader.c \
        src/libpakfire/errno.c \
        src/libpakfire/execute.c \
        src/libpakfire/file.c \
@@ -292,6 +293,7 @@ pkginclude_HEADERS += \
        src/libpakfire/include/pakfire/constants.h \
        src/libpakfire/include/pakfire/db.h \
        src/libpakfire/include/pakfire/dist.h \
+       src/libpakfire/include/pakfire/downloader.h \
        src/libpakfire/include/pakfire/errno.h \
        src/libpakfire/include/pakfire/execute.h \
        src/libpakfire/include/pakfire/file.h \
diff --git a/src/libpakfire/downloader.c b/src/libpakfire/downloader.c
new file mode 100644 (file)
index 0000000..a158fac
--- /dev/null
@@ -0,0 +1,74 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2021 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include <pakfire/downloader.h>
+#include <pakfire/pakfire.h>
+#include <pakfire/types.h>
+
+struct pakfire_downloader {
+       Pakfire pakfire;
+       int nrefs;
+};
+
+static void pakfire_downloader_free(struct pakfire_downloader* downloader) {
+       pakfire_unref(downloader->pakfire);
+       free(downloader);
+}
+
+int pakfire_downloader_create(struct pakfire_downloader** downloader, Pakfire pakfire) {
+       struct pakfire_downloader* d = calloc(1, sizeof(*d));
+       if (!d)
+               return ENOMEM;
+
+       // Store reference to Pakfire
+       d->pakfire = pakfire_ref(pakfire);
+
+       // Initialize reference counting
+       d->nrefs = 1;
+
+       *downloader = d;
+
+       return 0;
+}
+
+struct pakfire_downloader* pakfire_downloader_ref(struct pakfire_downloader* downloader) {
+       ++downloader->nrefs;
+
+       return downloader;
+}
+
+struct pakfire_downloader* pakfire_downloader_unref(struct pakfire_downloader* downloader) {
+       if (--downloader->nrefs > 0)
+               return downloader;
+
+       pakfire_downloader_free(downloader);
+       return NULL;
+}
+
+int pakfire_downloader_add(struct pakfire_downloader* downloader, const char* url) {
+       return 0;
+}
+
+int pakfire_downloader_run(struct pakfire_downloader* downloader) {
+       return 0;
+}
diff --git a/src/libpakfire/include/pakfire/downloader.h b/src/libpakfire/include/pakfire/downloader.h
new file mode 100644 (file)
index 0000000..88d02f9
--- /dev/null
@@ -0,0 +1,41 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2021 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#ifndef PAKFIRE_DOWNLOADER_H
+#define PAKFIRE_DOWNLOADER_H
+
+#ifdef PAKFIRE_PRIVATE
+
+#include <pakfire/types.h>
+
+struct pakfire_downloader;
+
+int pakfire_downloader_create(struct pakfire_downloader** downloader, Pakfire pakfire);
+
+struct pakfire_downloader* pakfire_downloader_ref(struct pakfire_downloader* downloader);
+struct pakfire_downloader* pakfire_downloader_unref(struct pakfire_downloader* downloader);
+
+int pakfire_downloader_add(struct pakfire_downloader* downloader, const char* url);
+
+int pakfire_downloader_run(struct pakfire_downloader* downloader);
+
+#endif
+
+#endif /* PAKFIRE_DOWNLOADER_H */