# "makefile" is automatically generated from "makefile.1.mak"
-# 03.12.2022
+# 04.12.2022
#
# Copyright (C) 2022 Balthasar Szczepański
#
npb1.h\
npb2.h\
npb_ong1.h\
-npb_403.h
+npb_403.h\
+nh.h
+
+CGI=\
+bluenh-cgi
+
+#C_CGI=\
+#bluenh-cgi.c
# keep these 2 lists in the same order!:
-GENERATE_FROM=
+GENERATE_FROM=\
+online-core.1.h
-TO_GENERATE=
+TO_GENERATE=\
+online-core.h
#all: 403 npb npbd npb-ong1 npbd-ong1 bluenh bluenhd insert extract seediff insertframe mremapt-1 compare nofading nofadingd
-all: enhance $(STANDALONE)
+all: enhance $(STANDALONE) $(CGI)
makefile: makefile.1.mak $(CONFIGFILE)
$(TO_GENERATE): $(GENERATE_FROM) $(CONFIGFILE)
$(CONFIGURE_CMD) --in $(GENERATE_FROM) --out $(TO_GENERATE)
+
+$(CGI): %: %.c online-core.c online-core.h $(H_PNG)
+ $(CC) $(CF) -o $@ $*.c online-core.c $(L_CGI)
$(H_PNG): %.h: %.png f2h
./f2h $* $*.png $@
# $(CC) $(CF) -o test test.c core.c $(LF)
clean:
- $(RM) -f enhance $(C_STANDALONE) $(STANDALONE) $(TO_GENERATE) f2h $(H_PNG) $(H_SUBTOOL)
+ $(RM) -f enhance $(C_STANDALONE) $(STANDALONE) $(TO_GENERATE) f2h $(H_PNG) $(H_SUBTOOL) $(CGI)
PHONY: all clean
# "makefile" is automatically generated from "makefile.1.mak"
-# 03.12.2022
+# 04.12.2022
#
# Copyright (C) 2022 Balthasar Szczepański
#
npb1.h\
npb2.h\
npb_ong1.h\
-npb_403.h
+npb_403.h\
+nh.h
+
+CGI=\
+bluenh-cgi
+
+#C_CGI=\
+#bluenh-cgi.c
# keep these 2 lists in the same order!:
-GENERATE_FROM=
+GENERATE_FROM=\
+online-core.1.h
-TO_GENERATE=
+TO_GENERATE=\
+online-core.h
#all: 403 npb npbd npb-ong1 npbd-ong1 bluenh bluenhd insert extract seediff insertframe mremapt-1 compare nofading nofadingd
-all: enhance $(STANDALONE)
+all: enhance $(STANDALONE) $(CGI)
makefile: makefile.1.mak $(CONFIGFILE)
$(TO_GENERATE): $(GENERATE_FROM) $(CONFIGFILE)
$(CONFIGURE_CMD) --in $(GENERATE_FROM) --out $(TO_GENERATE)
+
+$(CGI): %: %.c online-core.c online-core.h $(H_PNG)
+ $(CC) $(CF) -o $@ $*.c online-core.c $(L_CGI)
$(H_PNG): %.h: %.png f2h
./f2h $* $*.png $@
# $(CC) $(CF) -o test test.c core.c $(LF)
clean:
- $(RM) -f enhance $(C_STANDALONE) $(STANDALONE) $(TO_GENERATE) f2h $(H_PNG) $(H_SUBTOOL)
+ $(RM) -f enhance $(C_STANDALONE) $(STANDALONE) $(TO_GENERATE) f2h $(H_PNG) $(H_SUBTOOL) $(CGI)
PHONY: all clean
--- /dev/null
+/*
+online-core.h is autogenerated from online-core.1.h
+Common parts of the online interface
+03.12.2022
+
+Copyright (C) 2022 Balthasar Szczepański
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero 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 Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Requires cgilib (http://www.infodrom.org/projects/cgilib/)
+*/
+
+#include <stdint.h>
+#include <cgi.h>
+
+// ###C_USERAGENT: #define USERAGENT "enhance"
+
+// ###C_CP_PATH: #define CP_PATH "cp"
+// ###C_WGET_PATH: #define WGET_PATH "wget"
+// ###C_RM_PATH: #define RM_PATH "rm"
+
+// ###C_TEMP_PATH: #define TEMP_PATH "/botm/tmp/enhance"
+
+// ###C_BLUENH_PATH: #define NPB_PATH "/botm/bin/bluenh"
+// ###C_NPB_PATH: #define NPB_PATH "/botm/bin/npb"
+
+int cp (char *src, char *dst);
+int wget (char *url, char *dst);
+int rm (char *dst);
+void make_tmp_path(char *str, size_t n, unsigned int i, char *ext);
+int get_file(s_cgi *cgi, char *name, char *dest, char **path);
+int send_file (char *path, char *content_type, unsigned status);
+int send_data (const uint8_t *address, size_t size, char *content_type, unsigned status);
--- /dev/null
+/*
+online-core.c
+Common parts of the online interface
+03.12.2022
+
+Copyright (C) 2013, 2014, 2015, 2022 Balthasar Szczepański
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero 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 Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Requires cgilib (http://www.infodrom.org/projects/cgilib/)
+*/
+
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <stdint.h>
+#include <inttypes.h>
+
+#include "cgi.h"
+
+#include "online-core.h"
+
+#define FILE_CHUNK 1024
+
+
+int cp (char *src, char *dst)
+{
+ pid_t sub;
+ int r;
+
+ sub = fork();
+ if (sub == 0)
+ {
+ r = execl(CP_PATH, src, dst, (char *)0);
+ exit(r);
+ }
+ waitpid(sub, &r, 0);
+
+ return r;
+}
+
+int rm (char *dst)
+{
+ pid_t sub;
+ int r;
+
+ sub = fork();
+ if (sub == 0)
+ {
+ r = execl(RM_PATH, "-f", dst, (char *)0);
+ exit(r);
+ }
+ waitpid(sub, &r, 0);
+
+ return r;
+}
+
+int wget (char *url, char *dst)
+{
+ pid_t sub;
+ int r;
+
+ sub = fork();
+ if (sub == 0)
+ {
+ r = execl(WGET_PATH, "-q", "-t", "2", "-U", USERAGENT, "-O", dst, url, (char *)0);
+ exit(r);
+ }
+ waitpid(sub, &r, 0);
+
+ return r;
+}
+
+void make_tmp_path(char *str, size_t n, unsigned int i, char *ext)
+{
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+
+ snprintf(
+ str,
+ n,
+ "%s/%lu_%u_%llu_%lu%s",
+ TEMP_PATH,
+ (long unsigned) getpid(),
+ i,
+ (long long unsigned) (tv.tv_sec),
+ (long unsigned) (tv.tv_usec),
+ ext
+ );
+}
+
+int get_file(s_cgi *cgi, char *name, char *dest, char **path)
+{
+ char **vl;
+ char *v;
+ s_file *f;
+ int i;
+ int r;
+
+ vl = cgiGetFiles(cgi);
+ if (vl != NULL)
+ {
+ for (i=0; vl[i]!= NULL; ++i)
+ {
+ if (strcmp(vl[i], name)==0)
+ {
+ f = cgiGetFile(cgi, vl[i]);
+ if (f == NULL)
+ break;
+ if (dest != NULL)
+ {
+ r = cp(f->tmpfile, dest);
+ if (r)
+ return r;
+ *path = dest;
+ }
+ else
+ *path = f->tmpfile;
+ return 0;
+ }
+ }
+ }
+
+ if (dest == NULL)
+ return EINVAL;
+
+ v = cgiGetValue(cgi, name);
+ if (v==NULL)
+ return EINVAL;
+ r = wget(v, dest);
+ if (r)
+ return r;
+ *path = dest;
+ return 0;
+}
+
+int send_file (char *path, char *content_type, unsigned status)
+{
+ FILE *f;
+ struct stat st;
+ int64_t size;
+ size_t wr, rd, off;
+ uint8_t buffer[FILE_CHUNK];
+
+ f = fopen(path, "rb");
+ if (f == NULL)
+ return EIO;
+ fstat(fileno(f), &st);
+ size = st.st_size;
+
+ if (status != 0)
+ fprintf(stdout, "Status: %u\n", status);
+ if (content_type!=NULL)
+ fprintf(stdout, "Content-type: %s", content_type);
+ fprintf(stdout, "Content-Length: %" PRId64 "\n\n", size);
+
+ while (size>0)
+ {
+ rd = fread(buffer, 1, FILE_CHUNK, f);
+ if (rd == 0)
+ break;
+ off =0;
+ while (off < rd)
+ {
+ wr = fwrite(buffer+off, 1, rd - off, stdout);
+ if (wr == 0)
+ break;
+ off += wr;
+ }
+ if (wr == 0)
+ break;
+ size -= rd;
+ }
+
+ fclose (f);
+ return 0;
+}
+
+int send_data (const uint8_t *address, size_t size, char *content_type, unsigned status)
+{
+ size_t wr, off;
+
+ if (status != 0)
+ fprintf(stdout, "Status: %u\n", status);
+ if (content_type!=NULL)
+ fprintf(stdout, "Content-type: %s", content_type);
+ fprintf(stdout, "Content-Length: %" PRId64 "\n\n", (uint64_t)size);
+
+ off = 0;
+ while (off<size)
+ {
+ wr = size - off;
+ if (wr > FILE_CHUNK)
+ wr = FILE_CHUNK;
+ wr = fwrite(address +off, 1, wr, stdout);
+ if (wr == 0)
+ break;
+ off += wr;
+ }
+
+ return 0;
+}
+
+
+
+
+
+
+
+
\ No newline at end of file
# alternatively, copy configure.pl to source directory.
configure: /botm/bin/config/configure.pl
+useragent: ENHANCE!ment tool (http://1190.bicyclesonthemoon.info/enhance)
+bin_path: /botm/bin/enhance
+tmp_path: /botm/tmp/enhance
+
+cp: /usr/bin/cp
rm: /usr/bin/rm
+wget: /usr/bin/wget
CC: gcc
CF: -g -Wall
# settings.txt
-# 12.11.2022
+# 04.12.2022
#
# Copyright (C) 2022 Balthasar Szczepański
#
_C_DEFINE_STR: #define $0 "@_ESCAPE($1)"
# _C_INCLUDE_STR: #include "@_ESCAPE($0)"
+_bin_bluenh_path = @_PATH($bin_path, bluenh)
+_bin_npb_path = @_PATH($bin_path, npb)
MAKE_CONFIGURE = CONFIGURE = $configure
MAKE_TARGET = TARGET = $target
MAKE_RM = RM =$rm
-
MAKE_CC = CC =$CC
MAKE_CF = CF =$CF
MAKE_L_IL = L_IL =$L_IL
MAKE_L_CGI = L_CGI=$L_CGI
+
+C_USERAGENT = @_C_DEFINE_STR(USERAGENT, $useragent)
+
+C_CP_PATH = @_C_DEFINE_STR(CP_PATH, $cp)
+C_WGET_PATH = @_C_DEFINE_STR(WGET_PATH, $wget)
+C_RM_PATH = @_C_DEFINE_STR(RM_PATH, $rm)
+
+C_TEMP_PATH = @_C_DEFINE_STR(TEMP_PATH, $_tmp_path)
+
+C_BLUENH_PATH = @_C_DEFINE_STR(BLUENH_PATH, $_bin_bluenh_path)
+C_NPB_PATH = @_C_DEFINE_STR(NPB_PATH, $_bin_npb_path)