X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=blobdiff_plain;f=npb-cgi.c;h=27049dd425df6d29e236372b58cd3b16e7317b24;hb=a4cc26155549eee6def832da05a6f641f92cd6ae;hp=d155c7a3cf864ac024d5bbe3ba41d56c36dc9761;hpb=930d0d94f8d683ad9823e542b0a00d3a41c660e5;p=ott%2Fenhance
diff --git a/npb-cgi.c b/npb-cgi.c
index d155c7a..27049dd 100644
--- a/npb-cgi.c
+++ b/npb-cgi.c
@@ -1,134 +1,181 @@
-// // //Download images and add
- // // Newpixbots to them! (or Megans)
- // //
- // // Requires cgilib
-// // //line 146 of cgi.h
- // // must be changed
- // // from "extern }"
- // // to "}"
-// // //
- // // ~~bicyclesonthemoon
+/*
+npb-cgi.c
+Download images and add Newpixbots to them! (or Megans)
+05.12.2022
+
+Copyright (C) 2013, 2014, 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 .
+
+Requires cgilib (http://www.infodrom.org/projects/cgilib/)
+*/
-#include
#include
-#include
+#include
#include
-#include
+#include
#include
-#include
+#include
+#include
-#define WGET_PATH "/usr/bin/wget"
-#define NPB_PATH "./npb"
-#define MEG_PATH "./403"
-#define RM_PATH "/bin/rm"
-#define LOG_PATH "/eizm/log/npb/npb.log"
-#define LOG_PATH2 "/eizm/log/npb/403.log"
-#define USERAGENT "NewpixbOTTification\x20(1190.bicyclesonthemoon.dnsd.info/npb/npb.htm)"
-#define USERAGENT2 "403fication\x20(1190.bicyclesonthemoon.dnsd.info/npb/403.htm)"
-#define MSTD_PATH "/pro/npb/mpb.png"
-#define MSTD_PATH2 "/pro/npb/503.png"
+#include
-int main (int argc, char *argv[]);
-void mustard(int mustard);
+#include "online-core.h"
+#include "mpb.h"
+#include "mpb_503.h"
-FILE *pix;
-unsigned char buf[1024];
-char url[1024];
-char path[256];
-char method[256];
-s_cgi *cgi;
-int t;
-pid_t sub;
-struct stat st;
-unsigned long p;
-unsigned short q;
-char **up;
-bool meg=false;
+
+int npb (
+ char *inpix, char *outpix,
+ uint_fast8_t remove_border, uint_fast32_t remove_border_width,
+ uint_fast8_t new_border, uint_fast32_t new_border_width,
+ uint_fast8_t external_border, uint_fast32_t external_border_width,
+ uint_fast8_t corners, uint_fast8_t ong1, uint8_t t403
+);
int main (int argc, char *argv[])
{
- cgi=cgiInit();
+ s_cgi *cgi;
+ char in_tmp[256];
+ char out_tmp[256];
+ char *in_path;
+ char *t;
+ uint_fast8_t remove_border, new_border, external_border, corners, ong1;
+ uint_fast32_t remove_border_width, new_border_width, external_border_width;
+ uint_fast8_t t403 = 0;
- sprintf(path,"%s",(getenv("PATH_INFO")!=NULL)?(getenv("PATH_INFO")):"");
- if(strcmp(path,"/403")==0)
- {
- meg=true;
- //mustard(0);
- }
+ int r=0;
+ int r1=0;
+ int r2=0;
+ int r3=0;
- up=cgiGetFiles(cgi);
- if (up)
- {
- sprintf(path,"%s",cgiGetFile(cgi,up[0])->tmpfile);
- sprintf(url,"%s",cgiGetFile(cgi,up[0])->filename);
- }
- else
- {
- sprintf(url,"%s",(cgiGetValue(cgi,"inpix")!=NULL)?(cgiGetValue(cgi,"inpix")):"");
- sprintf(path,"/var/tmp/%lu",(unsigned long)getpid());
+ do {
+ make_tmp_path(in_tmp, 256, 0, "");
+ make_tmp_path(out_tmp, 256, 1, ".png");
+
+ cgi=cgiInit();
- //Why is there no spawnl() in linux?
- sub=fork();
- if(sub==0)
+ r = get_file(cgi,"inpix2", in_tmp, &in_path);
+ if (r)
+ r = get_file(cgi,"inpix", in_tmp, &in_path);
+ if (r)
+ break;
+
+ remove_border = (cgiGetValue(cgi, "r")!=NULL) ? 1 : 0;
+ external_border = (cgiGetValue(cgi, "e")!=NULL) ? 1 : 0;
+ new_border = (cgiGetValue(cgi, "b")!=NULL) ? 1 : 0;
+ corners = (cgiGetValue(cgi, "c")!=NULL) ? 1 : 0;
+ ong1 = (cgiGetValue(cgi, "o")!=NULL) ? 1 : 0;
+ t403 = (cgiGetValue(cgi, "4")!=NULL) ? 1 : 0;
+
+ if (remove_border)
{
- t=execl(WGET_PATH,WGET_PATH,"-q","-t","2","-U",meg?USERAGENT2:USERAGENT,"-O",path,url,(char *)0);
- exit(t);
+ t = cgiGetValue(cgi, "rw");
+ if (t != NULL)
+ sscanf(t,"%"SCNuFAST32, &remove_border_width);
+ else
+ remove_border_width = 0;
}
- waitpid(sub,&t,0);
- if(t)mustard(t);
- }
-
- sub=fork();
- if(sub==0)
- {
- t=execl(meg?MEG_PATH:NPB_PATH,meg?MEG_PATH:NPB_PATH,path,path,"q",(char *)0);
- exit(t);
- }
- waitpid(sub,&t,0);
- if(t)mustard(t);
-
- pix=fopen(path,"rb");
- if(pix==NULL)
- mustard(123);
- fstat(fileno(pix),&st);
- p=st.st_size/1024;
- q=st.st_size%1024;
-
- printf("Content-Length: %lu\n",(unsigned long)(st.st_size));
- printf("Content-type: image/png\n\n");
- for(unsigned long i=0;i