3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include <sys/socket.h>
32 unsigned char color_font
;
33 unsigned char color_bg
;
38 setcolor (color_font
, color_bg
);
42 int http_proto (char *data
, int len
)
53 if (!strncmp (data
, "html", len
)) {
54 printf ("<WEB PAGE>\n");
58 if (!strncmp (data
, "/html", len
)) {
59 printf ("\n<END OF WEB>\n");
63 if (!strncmp (data
, "br", len
)) {
68 if (!strncmp (data
, "h1", len
)) {
74 if (!strncmp (data
, "/h1", len
)) {
80 if (!strncmp (data
, "p", len
)) {
85 if (!strncmp (data
, "/p", len
)) {
90 if (!strncmp (data
, "hr", len
)) {
103 if (!strncmp (data
, "a href", 6)) {
109 if (!strncmp (data
, "/a", len
)) {
118 int http_handler (char *data
, int len
)
127 /* start of html tag */
131 if (data
[i
] == '>') {
136 if (!(tag_s
&& tag_e
)) {
142 if (tag_s
&& tag_e
) {
143 http_proto (data
+tag_s
+1, tag_e
-tag_s
-1);
155 int http_request (char *address
, unsigned address_len
, char *dir
, unsigned dir_len
)
159 Accept: text/xml,text/html;text/plain
160 Accept-Charset: ISO-8859-2,utf-8
162 Connection: keep-alive*/
164 char *buf
= (char *) malloc (sizeof (char) * 200240); // Read buffer
167 memcpy (buf
, "GET ", 4);
168 memcpy (buf
+4, dir
, dir_len
);
169 memcpy (buf
+4+dir_len
, " HTTP/1.1\r\nHost: www.", 21);
170 memcpy (buf
+25+dir_len
, address
, address_len
);
171 memcpy (buf
+25+dir_len
+address_len
, "\r\nAccept: */*\r\nAccept-Charset: ISO-8859-2,utf-8\r\nKeep-Alive: 300\r\nConnection: Keep-Alive\r\n\r\n", 92);
173 unsigned len
= 117+dir_len
+address_len
;
176 int ret
= send (sock
, buf
, len
, 0);
181 ret
= recv (sock
, buf
+buf_len
, 1024, 0);
182 printf ("ret: %d : %d\n", ret
, buf_len
);
188 if (buf_len
>= 200240) {
189 printf ("WEB page is too big\n");
199 char *r
= strstr (buf
, "Content-Length: ");
211 memcpy (num
, r
+16, x
);
219 puts ("ERROR 404 - Page not found\n");
225 for (p
= 0; p
< buf_len
; p
++) {
227 if (buf
[p
+1] == '\r')
228 /*if (buf[p+2] == '\n')
229 if (buf[p+3] == '\r') */{
234 printf ("len: %d\n", len
);
239 printf ("WEB PAGE is loaded\n");
244 http_handler (buf
+(buf_len
-len
), len
);