]> bicyclesonthemoon.info Git - ott/enhance/commitdiff
Partial CGI update bacause git disagrees with me.
authorb <rowerynaksiezycu@gmail.com>
Sun, 4 Dec 2022 16:07:55 +0000 (16:07 +0000)
committerb <rowerynaksiezycu@gmail.com>
Sun, 4 Dec 2022 16:07:55 +0000 (16:07 +0000)
bluenh-cgi.c [moved from bluenhd.cpp with 100% similarity]
makefile
makefile.1.mak
nofading-cgi.c [moved from nofadingd.cpp with 100% similarity]
npb-cgi.c [moved from npbd.cpp with 100% similarity]
online-core.1.h [new file with mode: 0644]
online-core.c [new file with mode: 0644]
pal-cgi.c [moved from insertframe.c with 100% similarity]
settings-release.txt
settings.txt

similarity index 100%
rename from bluenhd.cpp
rename to bluenh-cgi.c
index 5813e480997582e35d565285d3680d0edb5531b2..0fff0b41ef51970a63e3d36315cff794ba6055f5 100644 (file)
--- a/makefile
+++ b/makefile
@@ -1,5 +1,5 @@
 # "makefile" is automatically generated from "makefile.1.mak"
-# 03.12.2022
+# 04.12.2022
 # 
 # Copyright (C) 2022  Balthasar Szczepański
 # 
@@ -90,16 +90,25 @@ npb0.h\
 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)
@@ -120,6 +129,9 @@ $(H_SUBTOOL): %.h: settings-subtool.txt subtool.h
 
 $(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 $@
@@ -132,7 +144,7 @@ f2h: f2h.c
 #      $(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
 
index 15d1f317af647cf3da124dd694fedccdbc74b515..a66bd07d999e121800bf5a8616988178252c1b7a 100644 (file)
@@ -1,5 +1,5 @@
 # "makefile" is automatically generated from "makefile.1.mak"
-# 03.12.2022
+# 04.12.2022
 # 
 # Copyright (C) 2022  Balthasar Szczepański
 # 
@@ -90,16 +90,25 @@ npb0.h\
 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)
@@ -120,6 +129,9 @@ $(H_SUBTOOL): %.h: settings-subtool.txt subtool.h
 
 $(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 $@
@@ -132,7 +144,7 @@ f2h: f2h.c
 #      $(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
 
similarity index 100%
rename from nofadingd.cpp
rename to nofading-cgi.c
similarity index 100%
rename from npbd.cpp
rename to npb-cgi.c
diff --git a/online-core.1.h b/online-core.1.h
new file mode 100644 (file)
index 0000000..eb15e33
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+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);
diff --git a/online-core.c b/online-core.c
new file mode 100644 (file)
index 0000000..3adb21c
--- /dev/null
@@ -0,0 +1,227 @@
+/*
+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
similarity index 100%
rename from insertframe.c
rename to pal-cgi.c
index 04e70c2ff2ab571ba3adb1eb3805c7829fb11110..7a10d68905d124e0d6d5b8e5c13e5ddb1b51fc1c 100644 (file)
@@ -11,8 +11,14 @@ target: release
 # 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
index 3f5212b5f343e80d117073f4a4e0390983c1ecf0..0967788b4e7683d393e00243693a0b16b665950e 100644 (file)
@@ -1,5 +1,5 @@
 # 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)