]> Joshua Wise's Git repositories - netwatch.git/blame - net/http/fs.c
Fix LICENSE.
[netwatch.git] / net / http / fs.c
CommitLineData
6f9272bd
JW
1/*
2 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25 * OF SUCH DAMAGE.
26 *
27 * This file is part of the lwIP TCP/IP stack.
28 *
29 * Author: Adam Dunkels <adam@sics.se>
30 *
31 */
32#include "lwip/def.h"
33#include "fs.h"
34#include "fsdata.h"
35#include "fsdata.c"
923ea2c2 36#include <io.h>
9343e933
JW
37#include <minilib.h>
38#include <paging.h>
39#include <output.h>
6f9272bd
JW
40
41/*-----------------------------------------------------------------------------------*/
42
923ea2c2 43void handle_regs(struct fs_file *file)
6f9272bd 44{
8ba7e5b2 45 static char buf[2048];
6f9272bd
JW
46
47 sprintf(buf,
48 "<html><head><title>Registers</title></head><body>"
49 "<p>At the time you requested this page, the system's registers were:</p>"
50 "<tt><pre>"
51 "%%eax: 0x%08x %%ebx: 0x%08x %%ecx: 0x%08x %%edx: 0x%08x\n"
52 "%%ebp: 0x%08x %%esi: 0x%08x %%edi: 0x%08x %%esp: 0x%08x\n"
53 "%%cr0: 0x%08x %%cr3: 0x%08x %%eip: 0x%08x %%eflags: 0x%08x\n"
54 "</pre></tt></body></html>",
55 *(unsigned long*)0xAFFD0,
56 *(unsigned long*)0xAFFDC,
57 *(unsigned long*)0xAFFD4,
58 *(unsigned long*)0xAFFD8,
59 *(unsigned long*)0xAFFE4,
60 *(unsigned long*)0xAFFE8,
61 *(unsigned long*)0xAFFEC,
62 *(unsigned long*)0xAFFE0,
63 *(unsigned long*)0xAFFFC,
64 *(unsigned long*)0xAFFF8,
65 *(unsigned long*)0xAFFF0,
66 *(unsigned long*)0xAFFF4);
67
68
69 file->data = buf;
923ea2c2
JW
70 file->len = strlen(buf)-1;
71}
72
9343e933
JW
73void handle_backtrace(struct fs_file *file)
74{
8ba7e5b2
JP
75 static char buf[2048];
76 static char buf2[64];
9343e933
JW
77 int i = 10;
78 unsigned long *pebp, *peip;
79 unsigned long ebp;
80 unsigned long cr3;
81
82 strcpy(buf, "<html><head><title>Backtrace</title></head><body><tt><pre>");
83 ebp = *(unsigned long *)0xAFFE4;
84 cr3 = *(unsigned long *)0xAFFF8;
85
86 sprintf(buf2, "0x%08x, from\n", *(unsigned long*)0xAFFF0);
87 strcat(buf, buf2);
88
89 /* I never thought I'd do this again. */
90 while ((peip = demap(cr3, ebp+4)) != 0x0 && i--)
91 {
92 sprintf(buf2, "0x%08x, from\n", *peip);
93 strcat(buf, buf2);
94 pebp = demap(cr3, ebp);
95 if (!pebp)
96 {
97 strcat(buf, "&lt;unreadable %ebp&gt;\n");
98 break;
99 }
100 if (ebp >= *pebp && *pebp)
101 {
102 strcat(buf, "&lt;recursive %ebp&gt;\n");
103 break;
104 }
105 ebp = *pebp;
106 }
107 if (i == -1)
108 strcat(buf, "...\n");
109 else
110 strcat(buf, "&lt;root&gt;");
111 strcat(buf, "</pre></tt></body></html>");
112
113 file->data = buf;
114 file->len = strlen(buf)-1;
115}
116
923ea2c2
JW
117void handle_reboot(struct fs_file *file)
118{
119 outb(0xCF9, 0x4);
120 file->data = "So long!";
121 file->len = 8;
6f9272bd
JW
122}
123
124
125/*-----------------------------------------------------------------------------------*/
126int
127fs_open(const char *name, struct fs_file *file)
128{
129 const struct fsdata_file *f;
130
131 /* /registers.html is CGI */
132 if (!strcmp(name, "/registers.html"))
133 {
923ea2c2
JW
134 handle_regs(file);
135 return 1;
136 }
9343e933
JW
137 if (!strcmp(name, "/backtrace.html"))
138 {
139 handle_backtrace(file);
140 return 1;
141 }
923ea2c2
JW
142 if (!strcmp(name, "/reboot"))
143 {
144 handle_reboot(file);
6f9272bd
JW
145 return 1;
146 }
147
148 for(f = FS_ROOT;
149 f != NULL;
150 f = f->next) {
151 if (!strcmp(name, (const char*)f->name)) {
152 file->data = f->data;
923ea2c2 153 file->len = f->len-1;
6f9272bd
JW
154 return 1;
155 }
156 }
157 file->data = "You clown...";
158 file->len = 9;
159 return 0;
160}
161/*-----------------------------------------------------------------------------------*/
This page took 0.04138 seconds and 4 git commands to generate.