Il giorno sab 7 nov 2026 alle ore 12:57 Samuel Thibault
<[email protected]> ha scritto:
>
> Ah, that's because they are normally coming from httpfs.c. Then rather
> move them out of httpfs.c into a separate .c file that you can then link
> into test_httpfs rather than duplicate the definitions.
>
> Samuel

Hello Samuel, I think I have addressed what you asked for.

The patch is attached to this email.

Thank you,

Gianluca
diff --git a/Makefile.am b/Makefile.am
index 262425d..27d2588 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,9 @@
 
 bin_PROGRAMS=httpfs
 
-httpfs_LDADD=$(LIBS) -lhurdbugaddr -lnetfs -lfshelp -lpthread -lports -liohelp -lshouldbeinlibc
+HTTPFS_SHARED_LIBS = -lxml2 -lpthread -lnetfs -lfshelp -lports -liohelp -lshouldbeinlibc -lhurdbugaddr
+
+httpfs_LDADD = $(HTTPFS_SHARED_LIBS) $(LIBS)
 httpfs_SOURCES=httpfs.c \
 	netfs.c \
 	args.c \
@@ -10,5 +12,14 @@ httpfs_SOURCES=httpfs.c \
 	parsehtml.c \
 	extract.c \
 	node.c \
-	httpfs.h
+	httpfs.h \
+	globals.c \
+	globals.h
 INCLUDES = -I@includedir@
+
+SUBDIRS = . tests
+
+tests:
+	$(MAKE) check
+
+.PHONY: tests
diff --git a/Makefile.in b/Makefile.in
deleted file mode 100644
index d8a9ce2..0000000
--- a/Makefile.in
+++ /dev/null
@@ -1,357 +0,0 @@
-# Makefile.in generated automatically by automake 1.4-p4 from Makefile.am
-
-# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
-# This Makefile.in is free software; the Free Software Foundation
-# gives unlimited permission to copy and/or distribute it,
-# with or without modifications, as long as this notice is preserved.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
-# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-# PARTICULAR PURPOSE.
-
-
-SHELL = @SHELL@
-
-srcdir = @srcdir@
-top_srcdir = @top_srcdir@
-VPATH = @srcdir@
-prefix = @prefix@
-exec_prefix = @exec_prefix@
-
-bindir = @bindir@
-sbindir = @sbindir@
-libexecdir = @libexecdir@
-datadir = @datadir@
-sysconfdir = @sysconfdir@
-sharedstatedir = @sharedstatedir@
-localstatedir = @localstatedir@
-libdir = @libdir@
-infodir = @infodir@
-mandir = @mandir@
-includedir = @includedir@
-oldincludedir = /usr/include
-
-DESTDIR =
-
-pkgdatadir = $(datadir)/@PACKAGE@
-pkglibdir = $(libdir)/@PACKAGE@
-pkgincludedir = $(includedir)/@PACKAGE@
-
-top_builddir = .
-
-ACLOCAL = @ACLOCAL@
-AUTOCONF = @AUTOCONF@
-AUTOMAKE = @AUTOMAKE@
-AUTOHEADER = @AUTOHEADER@
-
-INSTALL = @INSTALL@
-INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
-INSTALL_DATA = @INSTALL_DATA@
-INSTALL_SCRIPT = @INSTALL_SCRIPT@
-transform = @program_transform_name@
-
-NORMAL_INSTALL = :
-PRE_INSTALL = :
-POST_INSTALL = :
-NORMAL_UNINSTALL = :
-PRE_UNINSTALL = :
-POST_UNINSTALL = :
-CC = @CC@
-MAKEINFO = @MAKEINFO@
-PACKAGE = @PACKAGE@
-VERSION = @VERSION@
-
-bin_PROGRAMS = httpfs
-
-httpfs_LDADD = -lhurdbugaddr -lnetfs -lfshelp -lthreads -lports -liohelp -lxml2 -lshouldbeinlibc
-httpfs_SOURCES = httpfs.c 	netfs.c 	args.c 	http.c 	parsehtml.c 	extract.c 	node.c 	httpfs.h
-
-INCLUDES = -I@includedir@
-ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
-CONFIG_CLEAN_FILES = 
-PROGRAMS =  $(bin_PROGRAMS)
-
-
-DEFS = @DEFS@ -I. -I$(srcdir) 
-CPPFLAGS = @CPPFLAGS@
-LDFLAGS = @LDFLAGS@
-LIBS = @LIBS@
-httpfs_OBJECTS =  httpfs.o netfs.o args.o http.o parsehtml.o extract.o \
-node.o
-httpfs_DEPENDENCIES = 
-httpfs_LDFLAGS = 
-CFLAGS = @CFLAGS@
-COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-CCLD = $(CC)
-LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
-DIST_COMMON =  README AUTHORS COPYING ChangeLog INSTALL Makefile.am \
-Makefile.in NEWS aclocal.m4 configure configure.in install-sh missing \
-mkinstalldirs
-
-
-DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
-
-TAR = tar
-GZIP_ENV = --best
-DEP_FILES =  .deps/args.P .deps/extract.P .deps/http.P .deps/httpfs.P \
-.deps/netfs.P .deps/node.P .deps/parsehtml.P
-SOURCES = $(httpfs_SOURCES)
-OBJECTS = $(httpfs_OBJECTS)
-
-all: all-redirect
-.SUFFIXES:
-.SUFFIXES: .S .c .o .s
-$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) 
-	cd $(top_srcdir) && $(AUTOMAKE) --gnu Makefile
-
-Makefile: $(srcdir)/Makefile.in  $(top_builddir)/config.status $(BUILT_SOURCES)
-	cd $(top_builddir) \
-	  && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status
-
-$(ACLOCAL_M4):  configure.in 
-	cd $(srcdir) && $(ACLOCAL)
-
-config.status: $(srcdir)/configure.in $(CONFIG_STATUS_DEPENDENCIES)
-	$(SHELL) ./config.status --recheck
-$(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES)
-	cd $(srcdir) && $(AUTOCONF)
-
-mostlyclean-binPROGRAMS:
-
-clean-binPROGRAMS:
-	-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
-
-distclean-binPROGRAMS:
-
-maintainer-clean-binPROGRAMS:
-
-install-binPROGRAMS: $(bin_PROGRAMS)
-	@$(NORMAL_INSTALL)
-	$(mkinstalldirs) $(DESTDIR)$(bindir)
-	@list='$(bin_PROGRAMS)'; for p in $$list; do \
-	  if test -f $$p; then \
-	    echo "  $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \
-	     $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
-	  else :; fi; \
-	done
-
-uninstall-binPROGRAMS:
-	@$(NORMAL_UNINSTALL)
-	list='$(bin_PROGRAMS)'; for p in $$list; do \
-	  rm -f $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
-	done
-
-.s.o:
-	$(COMPILE) -c $<
-
-.S.o:
-	$(COMPILE) -c $<
-
-mostlyclean-compile:
-	-rm -f *.o core *.core
-
-clean-compile:
-
-distclean-compile:
-	-rm -f *.tab.c
-
-maintainer-clean-compile:
-
-httpfs: $(httpfs_OBJECTS) $(httpfs_DEPENDENCIES)
-	@rm -f httpfs
-	$(LINK) $(httpfs_LDFLAGS) $(httpfs_OBJECTS) $(httpfs_LDADD) $(LIBS)
-
-tags: TAGS
-
-ID: $(HEADERS) $(SOURCES) $(LISP)
-	list='$(SOURCES) $(HEADERS)'; \
-	unique=`for i in $$list; do echo $$i; done | \
-	  awk '    { files[$$0] = 1; } \
-	       END { for (i in files) print i; }'`; \
-	here=`pwd` && cd $(srcdir) \
-	  && mkid -f$$here/ID $$unique $(LISP)
-
-TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) $(LISP)
-	tags=; \
-	here=`pwd`; \
-	list='$(SOURCES) $(HEADERS)'; \
-	unique=`for i in $$list; do echo $$i; done | \
-	  awk '    { files[$$0] = 1; } \
-	       END { for (i in files) print i; }'`; \
-	test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
-	  || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags  $$unique $(LISP) -o $$here/TAGS)
-
-mostlyclean-tags:
-
-clean-tags:
-
-distclean-tags:
-	-rm -f TAGS ID
-
-maintainer-clean-tags:
-
-distdir = $(PACKAGE)-$(VERSION)
-top_distdir = $(distdir)
-
-# This target untars the dist file and tries a VPATH configuration.  Then
-# it guarantees that the distribution is self-contained by making another
-# tarfile.
-distcheck: dist
-	-rm -rf $(distdir)
-	GZIP=$(GZIP_ENV) $(TAR) zxf $(distdir).tar.gz
-	mkdir $(distdir)/=build
-	mkdir $(distdir)/=inst
-	dc_install_base=`cd $(distdir)/=inst && pwd`; \
-	cd $(distdir)/=build \
-	  && ../configure --srcdir=.. --prefix=$$dc_install_base \
-	  && $(MAKE) $(AM_MAKEFLAGS) \
-	  && $(MAKE) $(AM_MAKEFLAGS) dvi \
-	  && $(MAKE) $(AM_MAKEFLAGS) check \
-	  && $(MAKE) $(AM_MAKEFLAGS) install \
-	  && $(MAKE) $(AM_MAKEFLAGS) installcheck \
-	  && $(MAKE) $(AM_MAKEFLAGS) dist
-	-rm -rf $(distdir)
-	@banner="$(distdir).tar.gz is ready for distribution"; \
-	dashes=`echo "$$banner" | sed s/./=/g`; \
-	echo "$$dashes"; \
-	echo "$$banner"; \
-	echo "$$dashes"
-dist: distdir
-	-chmod -R a+r $(distdir)
-	GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir)
-	-rm -rf $(distdir)
-dist-all: distdir
-	-chmod -R a+r $(distdir)
-	GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir)
-	-rm -rf $(distdir)
-distdir: $(DISTFILES)
-	-rm -rf $(distdir)
-	mkdir $(distdir)
-	-chmod 777 $(distdir)
-	here=`cd $(top_builddir) && pwd`; \
-	top_distdir=`cd $(distdir) && pwd`; \
-	distdir=`cd $(distdir) && pwd`; \
-	cd $(top_srcdir) \
-	  && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu Makefile
-	@for file in $(DISTFILES); do \
-	  d=$(srcdir); \
-	  if test -d $$d/$$file; then \
-	    cp -pr $$d/$$file $(distdir)/$$file; \
-	  else \
-	    test -f $(distdir)/$$file \
-	    || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
-	    || cp -p $$d/$$file $(distdir)/$$file || :; \
-	  fi; \
-	done
-
-DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
-
--include $(DEP_FILES)
-
-mostlyclean-depend:
-
-clean-depend:
-
-distclean-depend:
-	-rm -rf .deps
-
-maintainer-clean-depend:
-
-%.o: %.c
-	@echo '$(COMPILE) -c $<'; \
-	$(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
-	@-cp .deps/$(*F).pp .deps/$(*F).P; \
-	tr ' ' '\012' < .deps/$(*F).pp \
-	  | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
-	    >> .deps/$(*F).P; \
-	rm .deps/$(*F).pp
-
-%.lo: %.c
-	@echo '$(LTCOMPILE) -c $<'; \
-	$(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
-	@-sed -e 's/^\([^:]*\)\.o[ 	]*:/\1.lo \1.o :/' \
-	  < .deps/$(*F).pp > .deps/$(*F).P; \
-	tr ' ' '\012' < .deps/$(*F).pp \
-	  | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
-	    >> .deps/$(*F).P; \
-	rm -f .deps/$(*F).pp
-info-am:
-info: info-am
-dvi-am:
-dvi: dvi-am
-check-am: all-am
-check: check-am
-installcheck-am:
-installcheck: installcheck-am
-install-exec-am: install-binPROGRAMS
-install-exec: install-exec-am
-
-install-data-am:
-install-data: install-data-am
-
-install-am: all-am
-	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
-install: install-am
-uninstall-am: uninstall-binPROGRAMS
-uninstall: uninstall-am
-all-am: Makefile $(PROGRAMS)
-all-redirect: all-am
-install-strip:
-	$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
-installdirs:
-	$(mkinstalldirs)  $(DESTDIR)$(bindir)
-
-
-mostlyclean-generic:
-
-clean-generic:
-
-distclean-generic:
-	-rm -f Makefile $(CONFIG_CLEAN_FILES)
-	-rm -f config.cache config.log stamp-h stamp-h[0-9]*
-
-maintainer-clean-generic:
-mostlyclean-am:  mostlyclean-binPROGRAMS mostlyclean-compile \
-		mostlyclean-tags mostlyclean-depend mostlyclean-generic
-
-mostlyclean: mostlyclean-am
-
-clean-am:  clean-binPROGRAMS clean-compile clean-tags clean-depend \
-		clean-generic mostlyclean-am
-
-clean: clean-am
-
-distclean-am:  distclean-binPROGRAMS distclean-compile distclean-tags \
-		distclean-depend distclean-generic clean-am
-
-distclean: distclean-am
-	-rm -f config.status
-
-maintainer-clean-am:  maintainer-clean-binPROGRAMS \
-		maintainer-clean-compile maintainer-clean-tags \
-		maintainer-clean-depend maintainer-clean-generic \
-		distclean-am
-	@echo "This command is intended for maintainers to use;"
-	@echo "it deletes files that may require special tools to rebuild."
-
-maintainer-clean: maintainer-clean-am
-	-rm -f config.status
-
-.PHONY: mostlyclean-binPROGRAMS distclean-binPROGRAMS clean-binPROGRAMS \
-maintainer-clean-binPROGRAMS uninstall-binPROGRAMS install-binPROGRAMS \
-mostlyclean-compile distclean-compile clean-compile \
-maintainer-clean-compile tags mostlyclean-tags distclean-tags \
-clean-tags maintainer-clean-tags distdir mostlyclean-depend \
-distclean-depend clean-depend maintainer-clean-depend info-am info \
-dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
-install-exec install-data-am install-data install-am install \
-uninstall-am uninstall all-redirect all-am all installdirs \
-mostlyclean-generic distclean-generic clean-generic \
-maintainer-clean-generic clean mostlyclean distclean maintainer-clean
-
-
-# Tell versions [3.59,3.63) of GNU make to not export all variables.
-# Otherwise a system limit (for SysV at least) may be exceeded.
-.NOEXPORT:
diff --git a/args.c b/args.c
index ccb7b8b..f07cc87 100644
--- a/args.c
+++ b/args.c
@@ -24,7 +24,7 @@
 
 #include <hurd/netfs.h>
 
-#include "httpfs.h"
+#include "globals.h"
 
 /* Argument Parsing --Variables */
 const char *argp_program_version="Http Translator Version 0.1";
diff --git a/configure.in b/configure.in
index 8de56fb..0643c19 100644
--- a/configure.in
+++ b/configure.in
@@ -6,12 +6,44 @@ AC_PROG_CC
 
 PKG_CHECK_MODULES(HTTPFS, libxml-2.0)
 
+HTTPFS_SHARED_LIBS="-lxml2 -lpthread -lnetfs -lfshelp -lports -liohelp -lshouldbeinlibc -lhurdbugaddr"
+AC_SUBST([HTTPFS_SHARED_LIBS])
+
+# Optional test suite integration (auto-enabled if dependencies are found)
+AC_ARG_ENABLE([test],
+    AS_HELP_STRING([--enable-test], [Enable test compilation (cmocka and libmicrohttpd) [default=auto]]),
+    [enable_test=$enableval],
+    [enable_test=auto])
+
+have_test=no
+AS_IF([test "x$enable_test" != "xno"], [
+    PKG_CHECK_MODULES([MHD], [libmicrohttpd >= 0.9.0], [
+        PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.1.0], [
+            have_test=yes
+        ], [
+            AS_IF([test "x$enable_test" = "xyes"], [
+                AC_MSG_ERROR([cmocka not found, but --enable-test was requested.])
+            ])
+        ])
+    ], [
+        AS_IF([test "x$enable_test" = "xyes"], [
+            AC_MSG_ERROR([libmicrohttpd not found, but --enable-test was requested.])
+        ])
+    ])
+])
+
+AM_CONDITIONAL([ENABLE_TESTS], [test "x$have_test" = "xyes"])
+
 CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 $HTTPFS_CFLAGS"
 LIBS="$LIBS $HTTPFS_LIBS"
 
 AC_SUBST(LIBS)
+AC_SUBST([CMOCKA_CFLAGS])
+AC_SUBST([CMOCKA_LIBS])
+
 AM_CONFIG_HEADER(config.h)
 
 AC_OUTPUT(
-	Makefile
+    Makefile
+    tests/Makefile
 )
diff --git a/extract.c b/extract.c
index 6930343..1795ddf 100644
--- a/extract.c
+++ b/extract.c
@@ -25,7 +25,7 @@
 #include<stdlib.h>
 #include<unistd.h>
 
-#include"httpfs.h"
+#include "globals.h"
 
 int check_dups(char *name,char *parent)
 {
diff --git a/globals.c b/globals.c
new file mode 100644
index 0000000..8cfd1f2
--- /dev/null
+++ b/globals.c
@@ -0,0 +1,38 @@
+/*
+ * httpfs global definitions
+ *
+ * Copyright (C) 2026 Free Software Foundation, Inc.
+ * This file is part of the GNU Hurd.
+ * 
+ * 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 2, 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, write to the Free Software
+ * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "globals.h"
+
+ /* global configuration parameters */
+unsigned short port;
+int debug_flag;
+int mode;
+int no_of_slashes = 0;
+char *url, *conn_req;
+char *ip_addr;
+char *dir_tok[25];
+struct files *list_of_entries = NULL, *this_entry;
+
+struct httpfs *httpfs;		/* filesystem global pointer */
+volatile struct mapped_time_value *httpfs_maptime;
+
+char *netfs_server_name    = HTTPFS_SERVER_NAME;
+char *netfs_server_version = HTTPFS_SERVER_VERSION;
diff --git a/globals.h b/globals.h
new file mode 100644
index 0000000..d019103
--- /dev/null
+++ b/globals.h
@@ -0,0 +1,63 @@
+/*
+ * httpfs global definitions
+ *
+ * Copyright (C) 2026 Free Software Foundation, Inc.
+ * This file is part of the GNU Hurd.
+ * 
+ * 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 2, 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, write to the Free Software
+ * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __GLOBALS_H__
+#define __GLOBALS_H__
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
+
+#include "httpfs.h"
+
+/* declaration of global configuration parameters */
+extern int debug_flag;
+extern volatile struct mapped_time_value *httpfs_maptime;
+
+/* Protocol requirements */
+extern char *url, *conn_req;
+extern unsigned short port;
+extern char *ip_addr;
+
+/* set translator to a file or directory indicate it in mode
+ * mode accepted as command line argument */
+extern int mode;
+
+/* no of / in the url indicates the level of directory to go into the web server * cannot move to a top level directory from the given url 
+ * eg: www.xyz/file/temp/ is the url from here we cannot show the contents of 
+ * the root directory / of file/ directory
+ * only contents of temp/ and its subdirectories can be supported */
+extern int no_of_slashes;
+
+/* if the url points to particular file explicitly given store here 
+ * else assume it to be index.html 
+ * like www.gnu.org/gpl.html and www.gnu.org/  no file given so index.html */
+extern char *dir_tok[25];
+
+extern struct files *list_of_entries,*this_entry;
+
+/* global pointer to the filesystem */
+extern struct httpfs *httpfs;
+
+#define HTTPFS_SERVER_NAME    PACKAGE
+#define HTTPFS_SERVER_VERSION VERSION
+
+#endif /* __GLOBALS_H__ */
diff --git a/http.c b/http.c
index a81706c..50184c0 100644
--- a/http.c
+++ b/http.c
@@ -29,7 +29,7 @@
 #include <malloc.h>
 #include <stddef.h>
 
-#include "httpfs.h"
+#include "globals.h"
 
 #include <hurd/hurd_types.h>
 #include <hurd/netfs.h>
diff --git a/httpfs.c b/httpfs.c
index a3c1b0d..2da7f0d 100644
--- a/httpfs.c
+++ b/httpfs.c
@@ -27,23 +27,7 @@
 
 #include <hurd/netfs.h>
 
-#include "httpfs.h"
-
-/* global configuration parameters */
-unsigned short port;
-int debug_flag;
-int mode;
-int no_of_slashes = 0;
-char *url, *conn_req;
-char *ip_addr;
-char *dir_tok[25];
-struct files *list_of_entries = NULL, *this_entry;
-
-struct httpfs *httpfs;		/* filesystem global pointer */
-volatile struct mapped_time_value *httpfs_maptime;
-
-char *netfs_server_name    = HTTPFS_SERVER_NAME;
-char *netfs_server_version = HTTPFS_SERVER_VERSION;
+#include "globals.h"
 
 int
 main (int argc, char **argv)
diff --git a/httpfs.h b/httpfs.h
index e3c7a25..3b54e48 100644
--- a/httpfs.h
+++ b/httpfs.h
@@ -25,34 +25,6 @@
 
 #include "config.h"
 
-#define HTTPFS_SERVER_NAME    PACKAGE
-#define HTTPFS_SERVER_VERSION VERSION
-
-/* declaration of global configuration parameters */
-extern int debug_flag;
-extern volatile struct mapped_time_value *httpfs_maptime;
-
-/* Protocol requirements */
-extern char *url,*conn_req;
-extern unsigned short port;
-extern char *ip_addr;
-
-/* set translator to a file or directory indicate it in mode
- * mode accepted as command line argument */
-extern int mode;
-
-/* no of / in the url indicates the level of directory to go into the web server * cannot move to a top level directory from the given url 
- * eg: www.xyz/file/temp/ is the url from here we cannot show the contents of 
- * the root directory / of file/ directory
- * only contents of temp/ and its subdirectories can be supported */
-extern int no_of_slashes;
-
-/* if the url points to particular file explicitly given store here 
- * else assume it to be index.html 
- * like www.gnu.org/gpl.html and www.gnu.org/  no file given so index.html */
-extern char *dir_tok[25];
-
-
 /* handle all initial parameter parsing */
 error_t httpfs_parse_args (int argc, char **argv);
 
@@ -65,7 +37,6 @@ struct files {
 	int f_size; /* size */
 	struct files *next; /* linked list */
 };
-extern struct files *list_of_entries,*this_entry;
 
 /* private data per `struct node' */
 struct netnode {
@@ -102,9 +73,6 @@ struct httpfs {
 	ino_t next_inode;
 };
 
-/* global pointer to the filesystem */
-extern struct httpfs *httpfs;
-
 /* parse the html stream to extract file names and dir names and other info 
  * html parser is required to extract <a href=".."> tags
  * this tags gives file names or directory names in web server
diff --git a/netfs.c b/netfs.c
index 9914cf3..0b49d93 100644
--- a/netfs.c
+++ b/netfs.c
@@ -30,7 +30,7 @@
 #include <sys/stat.h>
 #include <sys/socket.h>
 
-#include "httpfs.h"  
+#include "globals.h"  
 
 #include <hurd/hurd_types.h>
 #include <hurd/netfs.h>
diff --git a/node.c b/node.c
index cda6054..f32590f 100644
--- a/node.c
+++ b/node.c
@@ -20,7 +20,7 @@
 #include <stdlib.h>
 #include <errno.h>
 
-#include "httpfs.h"
+#include "globals.h"
 
 #include <hurd/hurd_types.h>
 #include <hurd/netfs.h>
diff --git a/parsehtml.c b/parsehtml.c
index 549572e..3bd202f 100644
--- a/parsehtml.c
+++ b/parsehtml.c
@@ -28,7 +28,7 @@
 #include <libxml/HTMLtree.h>
 #include <libxml/SAX.h>
 
-#include "httpfs.h"
+#include "globals.h"
 
 #define MAXBUF 4096
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..2823d0a
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,8 @@
+check_PROGRAMS = test_httpfs
+
+test_httpfs_SOURCES = test_httpfs.c ../http.c ../parsehtml.c ../node.c ../extract.c ../netfs.c ../args.c ../globals.c
+test_httpfs_CFLAGS = -I$(top_srcdir) $(CMOCKA_CFLAGS)
+test_httpfs_LDFLAGS = -Wl,--wrap=gethostbyname -Wl,--export-dynamic
+test_httpfs_LDADD = $(CMOCKA_LIBS) $(MHD_LIBS) $(HTTPFS_SHARED_LIBS)
+
+TESTS = $(check_PROGRAMS)
diff --git a/tests/test_httpfs.c b/tests/test_httpfs.c
new file mode 100644
index 0000000..bd2d65b
--- /dev/null
+++ b/tests/test_httpfs.c
@@ -0,0 +1,87 @@
+/*
+ * httpfs unit tests
+ *
+ * Copyright (C) 2026 Free Software Foundation, Inc.
+ * This file is part of the GNU Hurd.
+ * 
+ * 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 2, 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, write to the Free Software
+ * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <netdb.h>
+#include <microhttpd.h>
+#include <curl/curl.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include "globals.h"
+
+struct hostent *__wrap_gethostbyname(const char *name) {
+    assert_non_null(name);
+
+    if (strcmp(name, "www.example.com") == 0) {
+        return (struct hostent *)mock();
+    }
+
+    return (struct hostent *)mock();
+}
+
+/* http.c unit tests */
+static void test_lookup_host_1(void **state) {
+    (void) state;
+
+    struct hostent mock_hostent;
+    memset(&mock_hostent, 0, sizeof(mock_hostent));
+    mock_hostent.h_name = "www.example.com";
+
+    will_return(__wrap_gethostbyname, &mock_hostent);
+
+    struct hostent *result = NULL;
+    int ret = lookup_host("www.example.com", &result);
+
+    assert_int_equal(ret, 0);
+    assert_non_null(result);
+    assert_string_equal(result->h_name, "www.example.com");
+}
+
+static void test_lookup_host_2(void **state) {
+    (void) state;
+
+    will_return(__wrap_gethostbyname, NULL);
+
+    struct hostent *result = NULL;
+    int ret = lookup_host("invalid.url", &result);
+
+    assert_int_equal(ret, EINVAL);
+    assert_null(result);
+}
+
+int main(void) {
+    const struct CMUnitTest tests[] = {
+        cmocka_unit_test(test_lookup_host_1),
+        cmocka_unit_test(test_lookup_host_2),
+    };
+
+    return cmocka_run_group_tests(tests, NULL, NULL);
+}

Reply via email to