4 Copyright (C) 2006-2009 Jonathan Zarate
14 void wi_blackhole(char *url
, int len
, char *boundary
)
26 send_header(200, NULL
, mime_html
, 0);
28 "<h1>Upload Test</h1>"
29 "<form method='post' action='blackhole.cgi?_http_id=%s' encType='multipart/form-data'>"
30 "<input type='file' name='file'><input type='submit'>"
32 nvram_safe_get("http_id"));
38 cprintf("\nblackhole\n");
39 cprintf("%s<\n", boundary
);
41 if ((blen
= strlen(boundary
)) == 0) {
42 error
= "no boundary";
44 cprintf("ERROR: %s\n", error
);
48 send_header(200, NULL
, mime_html
, 0);
49 web_printf("ERROR: %s", error
);
53 if (blen
> (sizeof(buf
) - 32)) {
54 error
= "boundary is too big";
61 if (len
< ((blen
* 2) + 12)) {
62 error
= "not enough data";
68 if (!web_getline(buf
, MIN(len
, sizeof(buf
)))) {
78 if (buf
[--n
] != '\n') {
79 error
= "\\n not found";
82 if (buf
[--n
] != '\r') {
83 error
= "\\n without \\r";
89 cprintf("%s<\n", buf
);
92 if ((buf
[0] != '-') || (buf
[1] != '-') || (strcmp(buf
+ 2, boundary
) != 0)) {
93 error
= "boundary not found on first line";
101 error
= "boundary not found before reaching end of header";
108 error
= "not enough data for end boundary";
112 unlink("/tmp/blackhole");
113 /* if (len < (1*1024*1024)) f = fopen("/tmp/blackhole", "w");
117 // read half, trigger tcp reset
124 if ((n
= web_read(buf
, MIN(len
, sizeof(buf
)))) <= 0) {
127 if (f
) fwrite(buf
, n
, 1, f
);
130 tick
= time(0) - tick
;
134 error
= "not all data was read";
138 if (web_read(buf
, blen
) != blen
) {
139 error
= "error while reading end boundary";
143 cprintf(">>%s<<\n", buf
);
144 if ((strncmp(buf
, "\r\n--", 4) != 0) ||
145 (buf
[blen
- 1] != '-') || (buf
[blen
- 2] != '-')
146 || (strncmp(buf
+ 4, boundary
, blen
- 6) != 0)) {
147 error
= "end boundary not found";
153 if ((n
= web_read(buf
, MIN(len
, sizeof(buf
) - 1))) > 0) {
156 cprintf("last >>%s<<\n", buf
);
161 cprintf("len=%d\n", len
);
163 if (tick
> 0) n
= size
/ tick
;
166 send_header(200, NULL
, mime_html
, 0);
169 "Size .......: %d bytes\n"
170 "Time .......: %d seconds\n"
171 "Speed ......: %.2f kb/s | %.2f mb/s | %.2f KB/s | %.2f MB/s\n",
174 n
/ 128.0, n
/ 131072.0,
175 n
/ 1024.0, n
/ 1048576.0);
177 web_pipecmd("md5sum /tmp/blackhole", WOF_NONE
);
181 cprintf("done...\n");