]> bicyclesonthemoon.info Git - ott/enhance/commitdiff
Everything is ready!
authorb <b@0d794883-4e4e-4f65-aa7a-0e7f5947bab5>
Mon, 30 Dec 2013 19:20:20 +0000 (19:20 +0000)
committerb <b@0d794883-4e4e-4f65-aa7a-0e7f5947bab5>
Mon, 30 Dec 2013 19:20:20 +0000 (19:20 +0000)
git-svn-id: svn://botcastle1b/npb@19 0d794883-4e4e-4f65-aa7a-0e7f5947bab5

npb.htm
npbd
npbd.cpp

diff --git a/npb.htm b/npb.htm
index 38eab71097932fcb7208f9a385042c7fb71d53b2..b137293f5941359a7d8e683fa65c78578232f215 100644 (file)
--- a/npb.htm
+++ b/npb.htm
@@ -7,7 +7,7 @@
        <body>
                <h1>It's NewpixbOTTification time!</h1>
                <form method="get" action="/cgi/npb/npbd">
-                       NewpixbOTTify by URL (not ready!)<br>
+                       NewpixbOTTify by URL<br>
                        URL:
                        <input type="text" name="inpix" value="http://">
                        <input type="submit" value="NewpixbOTTify!">
diff --git a/npbd b/npbd
index acaa15dc3a8ad8f720c0861090e3bbcc8e6ae730..a25865a71467959749d529e9756dee480e3dc873 100755 (executable)
Binary files a/npbd and b/npbd differ
index 831d80b45a28ce7319b6d1314123f16b418433d3..41d06f71f5eb81534a6da5def21c63bad53925e2 100644 (file)
--- a/npbd.cpp
+++ b/npbd.cpp
 
 #include <cgi.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <unistd.h>
 #include <sys/wait.h>
+#include <sys/stat.h>
 
 #define WGET_PATH "/usr/bin/wget"
 #define NPB_PATH  "./npb"
+#define RM_PATH   "/bin/rm"
 
 int main (int argc, char *argv[]);
+void mustard(int mustard);
+
+FILE *pix;
+unsigned char buf[1024];
+char url[1024];
+char path[256];
+//char cmd[1024];
+s_cgi *cgi;
+int t;
+pid_t sub;
+struct stat st;
+unsigned long p;
+unsigned short q;
+
 int main (int argc, char *argv[])
 {
-       FILE *pix;
-       char url[1024];
-       char path[256];
-       //char cmd[1024];
-       s_cgi *cgi;
-       int t;
-       pid_t sub;
        
        cgi=cgiInit();
        sprintf(url,"%s",cgiGetValue(cgi,"inpix"));
@@ -38,31 +48,56 @@ int main (int argc, char *argv[])
        if(sub==0)
        {
                t=execl(WGET_PATH,WGET_PATH,"-q","-O",path,url,(char *)0);
-               return t;
+               exit(t);
        }
        waitpid(sub,&t,0);
-       if(t)return t;
+       if(t)mustard(t);
        
        sub=fork();
        if(sub==0)
        {
                t=execl(NPB_PATH,NPB_PATH,path,path,"q",(char *)0);
-               return t;
+               exit(t);
        }
        waitpid(sub,&t,0);
+       if(t)mustard(t);
        
-       printf("Content-type: text/html\n\n");
-       printf("<html><head><title>It's NewpixbOTTification time!</title></head><body>");
-       printf("<h1>It's NewpixbOTTification time!</h1>");
-       printf("%s<br>",path);
-       printf("%s<br>",url);
-       printf("%d<br>",t);
-       printf("%lu<br>",(unsigned long)sub);
-       printf("</body></html>\n");
-       
+       pix=fopen(path,"rb");
+       if(pix==NULL)
+               mustard(123);
+       fstat(fileno(pix),&st);
+       p=st.st_size/1024;
+       q=st.st_size%1024;
        
-       
-       //npbpix=fopen("/var/tmp/test","wb");
-       //fclose(npbpix);
-       return 0;
+       printf("Content-Length: %lu\n",(unsigned long)(st.st_size));
+       printf("Content-type: image/png\n\n");
+       for(unsigned long i=0;i<p;++i)
+       {
+               fread(buf,1,1024,pix);
+               fwrite(buf,1,1024,stdout);
+       }
+       if(q!=0)
+       {
+               fread(buf,1,q,pix);
+               fwrite(buf,1,q,pix);
+       }
+       fclose(pix);
+       fflush(stdout);
+       mustard(0);//no mustard
+}
+
+void mustard(int mustard)
+{
+       if(mustard)
+       {
+               cgiRedirect("/pro/npb/mpb.png");
+       }
+       sub=fork();
+       if(sub==0)
+       {
+               t=execl(RM_PATH,RM_PATH,"-f",path,(char *)0);
+               exit(t);
+       }
+       waitpid(sub,&t,0);
+       exit(mustard);
 }
\ No newline at end of file