]> bicyclesonthemoon.info Git - ott/enhance/blob - bluenh-cgi.c
Online bluenh seems to work ok.
[ott/enhance] / bluenh-cgi.c
1 /*
2 bluenh-cgi.c is autogenerated from bluenh-cgi.1.c
3 Online interface for npb
4 04.12.2022
5
6 Copyright (C) 2013, 2014, 2022  Balthasar SzczepaƄski
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as
10 published by the Free Software Foundation, either version 3 of the
11 License, or (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU Affero General Public License for more details.
17
18 You should have received a copy of the GNU Affero General Public License
19 along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 Requires cgilib (http://www.infodrom.org/projects/cgilib/)
22 */
23
24 #include <stdio.h>
25 #include <stdint.h>
26 #include <unistd.h>
27 #include <stdlib.h>
28 #include <sys/wait.h>
29
30 #include <cgi.h>
31
32 #include "online-core.h"
33 #include "nh.h"
34
35 int bluenh (char *inpix, char *outpix, unsigned a, unsigned b, unsigned c, unsigned d, unsigned e, unsigned f);
36
37 int main (int argc, char *argv[])
38 {
39         s_cgi *cgi;
40         char in_tmp[256];
41         char out_tmp[256];
42         char *in_path;
43         char *t;
44         unsigned a, b, c, d, e, f;
45         
46         int r=0;
47         int r1=0;
48         int r2=0;
49         int r3=0;
50         
51         do {
52                 make_tmp_path(in_tmp, 256, 0, "");
53                 make_tmp_path(out_tmp, 256, 1, ".png");
54                 
55                 cgi=cgiInit();
56                 
57                 r = get_file(cgi,"inpix", in_tmp, &in_path);
58                 if (r)
59                         break;
60                 
61                 t = cgiGetValue(cgi, "a");
62                 if (t != NULL)
63                         sscanf(t,"%u",&a);
64                 else
65                         a = 0;
66                 
67                 t = cgiGetValue(cgi, "b");
68                 if (t != NULL)
69                         sscanf(t,"%u",&b);
70                 else
71                         b = 0;
72                 
73                 t = cgiGetValue(cgi, "c");
74                 if (t != NULL)
75                         sscanf(t,"%u",&c);
76                 else
77                         c = 0;
78                 
79                 t = cgiGetValue(cgi, "d");
80                 if (t != NULL)
81                         sscanf(t,"%u",&d);
82                 else
83                         d = 0;
84                 
85                 t = cgiGetValue(cgi, "e");
86                 if (t != NULL)
87                         sscanf(t,"%u",&e);
88                 else
89                         e = 0;
90                 
91                 t = cgiGetValue(cgi, "f");
92                 if (t != NULL)
93                         sscanf(t,"%u",&f);
94                 else
95                         f = 0;
96                 
97                 r = bluenh(in_path, out_tmp, a, b, c, d, e, f);
98                 if (r)
99                         break;
100                 
101                 r1 = send_file(out_tmp, "image/png", 0);
102         } while (0);
103         if (r)
104         {
105                 r1 = send_data(nh, nh_size, "image/png", 500);
106         }
107         r2 = rm(in_tmp);
108         r3 = rm(out_tmp);
109         if (r)
110                 return r;
111         if (r1)
112                 return r1;
113         if (r2)
114                 return r2;
115         if (r3)
116                 return r3;
117         return 0;
118 }
119
120 int bluenh (char *inpix, char *outpix, unsigned a, unsigned b, unsigned c, unsigned d, unsigned e, unsigned f)
121 {
122         char ca[4];
123         char cb[4];
124         char cc[4];
125         char cd[4];
126         char ce[4];
127         char cf[4];
128         
129         pid_t sub;
130         int r;
131         
132         snprintf(ca, 4, "%u", a);
133         snprintf(cb, 4, "%u", b);
134         snprintf(cc, 4, "%u", c);
135         snprintf(cd, 4, "%u", d);
136         snprintf(ce, 4, "%u", e);
137         snprintf(cf, 4, "%u", f);
138         
139         sub = fork();
140         if (sub == 0)
141         {
142                 r = execl(BLUENH_PATH, BLUENH_PATH, inpix, outpix, ca, cb, cc, cd, ce, cf, (char *)0);
143                 exit(r);
144         }
145         waitpid(sub, &r, 0);
146         return r;
147 }