3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
4 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
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
;
37 setcolor (color_font
, color_bg
);
40 int http_proto (char *data
, int len
)
51 if (!strncmp (data
, "html", len
)) {
52 printf ("<WEB PAGE>\n");
56 if (!strncmp (data
, "/html", len
)) {
57 printf ("\n<END OF WEB>\n");
61 if (!strncmp (data
, "br", len
)) {
66 if (!strncmp (data
, "h1", len
)) {
72 if (!strncmp (data
, "/h1", len
)) {
78 if (!strncmp (data
, "p", len
)) {
83 if (!strncmp (data
, "/p", len
)) {
88 if (!strncmp (data
, "hr", len
)) {
101 if (!strncmp (data
, "a href", 6)) {
107 if (!strncmp (data
, "/a", len
)) {
116 int http_handler (char *data
, int len
)
125 /* start of html tag */
129 if (data
[i
] == '>') {
134 if (!(tag_s
&& tag_e
)) {
140 if (tag_s
&& tag_e
) {
141 http_proto (data
+tag_s
+1, tag_e
-tag_s
-1);
153 int http_request (char *address
, unsigned address_len
, char *dir
, unsigned dir_len
)
157 Accept: text/xml,text/html;text/plain
158 Accept-Charset: ISO-8859-2,utf-8
160 Connection: keep-alive*/
162 char *buf
= (char *) malloc (sizeof (char) * 10240); // Read buffer
165 memcpy (buf
, "GET ", 4);
166 memcpy (buf
+4, dir
, dir_len
);
167 memcpy (buf
+4+dir_len
, " HTTP/1.1\r\nHost: www.", 21);
168 memcpy (buf
+25+dir_len
, address
, address_len
);
169 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);
171 unsigned len
= 117+dir_len
+address_len
;
174 int ret
= send (sock
, buf
, len
, 0);
179 ret
= recv (sock
, buf
+buf_len
, 512, 0);
180 printf ("ret: %d\n", ret
);
186 if (buf_len
>= 10240) {
187 printf ("WEB page is too big\n");
198 memcpy (str
, buf
, buf_len
);
203 char *r
= strstr (str
, "Content-Length: ");
215 memcpy (num
, r
+16, x
);
223 puts ("ERROR 404 - Page not found\n");
231 printf ("WEB PAGE is loaded\n");
236 http_handler (buf
+(buf_len
-len
), len
);