#include "http.h"
#include <rtl_printf.h>
#include "lwip/tcp.h"
#include <string.h>
#include "fs.h"
#include <linux/module.h>
#include <linux/kernel.h>
Include dependency graph for http.c:
Go to the source code of this file.
Data Structures | |
struct | http_state |
Functions | |
void | conn_err (void *arg, err_t err) |
void | close_conn (struct tcp_pcb *pcb, struct http_state *hs) |
void | send_data (struct tcp_pcb *pcb, struct http_state *hs) |
err_t | http_poll (void *arg, struct tcp_pcb *pcb) |
err_t | http_sent (void *arg, struct tcp_pcb *pcb, u16_t len) |
err_t | http_recv (void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) |
err_t | http_accept (void *arg, struct tcp_pcb *pcb, err_t err) |
void | httpd_init (void) |
int | init_module (void) |
void | cleanup_module (void) |
|
Definition at line 254 of file http.c.
00254 {
00255 printk("\nHTTP Daemon removed\n");
00256
00257 }
|
|
Definition at line 66 of file http.c. References mem_free(), NULL, tcp_arg(), tcp_close(), tcp_recv(), and tcp_sent(). Referenced by http_recv(), and http_sent().
|
Here is the call graph for this function:
|
Definition at line 57 of file http.c. References err_t, and mem_free(). Referenced by http_accept().
00058 { 00059 struct http_state *hs; 00060 00061 hs = arg; 00062 mem_free(hs); 00063 } |
Here is the call graph for this function:
|
Definition at line 200 of file http.c. References conn_err(), ERR_MEM, ERR_OK, err_t, http_poll(), http_recv(), mem_malloc(), NULL, tcp_arg(), tcp_err(), tcp_poll(), and tcp_recv(). Referenced by httpd_init().
00201 { 00202 struct http_state *hs; 00203 00204 /* Allocate memory for the structure that holds the state of the 00205 connection. */ 00206 hs = mem_malloc(sizeof(struct http_state)); 00207 00208 if(hs == NULL) { 00209 rtl_printf("http_accept: Out of memory\n"); 00210 return ERR_MEM; 00211 } 00212 00213 /* Initialize the structure. */ 00214 hs->file = NULL; 00215 hs->left = 0; 00216 00217 /* Tell TCP that this is the structure we wish to be passed for our 00218 callbacks. */ 00219 tcp_arg(pcb, hs); 00220 00221 /* Tell TCP that we wish to be informed of incoming data by a call 00222 to the http_recv() function. */ 00223 tcp_recv(pcb, http_recv); 00224 00225 tcp_err(pcb, conn_err); 00226 00227 tcp_poll(pcb, http_poll, 10); 00228 return ERR_OK; 00229 } |
Here is the call graph for this function:
|
Definition at line 101 of file http.c. References ERR_OK, NULL, send_data(), and tcp_close(). Referenced by http_accept().
00102 { 00103 if(arg == NULL) { 00104 /* printf("Null, close\n");*/ 00105 tcp_close(pcb); 00106 } else { 00107 send_data(pcb, (struct http_state *)arg); 00108 } 00109 00110 return ERR_OK; 00111 } |
Here is the call graph for this function:
|
Definition at line 130 of file http.c. References close_conn(), fs_file::data, data, ERR_OK, err_t, fs_open(), http_sent(), fs_file::len, NULL, pbuf::payload, pbuf_free(), send_data(), tcp_recved(), tcp_sent(), and pbuf::tot_len. Referenced by http_accept().
00131 { 00132 int i, j; 00133 char *data; 00134 char fname[40]; 00135 struct fs_file file; 00136 struct http_state *hs; 00137 00138 hs = arg; 00139 00140 if(err == ERR_OK && p != NULL) { 00141 00142 /* Inform TCP that we have taken the data. */ 00143 tcp_recved(pcb, p->tot_len); 00144 00145 if(hs->file == NULL) { 00146 data = p->payload; 00147 00148 if(strncmp(data, "GET ", 4) == 0) { 00149 for(i = 0; i < 40; i++) { 00150 if(((char *)data + 4)[i] == ' ' || 00151 ((char *)data + 4)[i] == '\r' || 00152 ((char *)data + 4)[i] == '\n') { 00153 ((char *)data + 4)[i] = 0; 00154 } 00155 } 00156 i = 0; 00157 do { 00158 fname[i] = "/http"[i]; 00159 i++; 00160 } while(fname[i - 1] != 0 && i < 40); 00161 i--; 00162 j = 0; 00163 do { 00164 fname[i] = ((char *)data + 4)[j]; 00165 j++; 00166 i++; 00167 } while(fname[i - 1] != 0 && i < 40); 00168 pbuf_free(p); 00169 00170 if(!fs_open(fname, &file)) { 00171 fs_open("/http/index.html", &file); 00172 // fs_open("/index.shtml", &file); 00173 } 00174 hs->file = file.data; 00175 hs->left = file.len; 00176 00177 send_data(pcb, hs); 00178 00179 /* Tell TCP that we wish be to informed of data that has been 00180 successfully sent by a call to the http_sent() function. */ 00181 tcp_sent(pcb, http_sent); 00182 } else { 00183 close_conn(pcb, hs); 00184 } 00185 } else { 00186 pbuf_free(p); 00187 } 00188 } 00189 00190 00191 00192 if(err == ERR_OK && p == NULL) { 00193 00194 close_conn(pcb, hs); 00195 } 00196 return ERR_OK; 00197 } |
Here is the call graph for this function:
|
Definition at line 114 of file http.c. References close_conn(), ERR_OK, send_data(), and u16_t. Referenced by http_recv().
00115 { 00116 struct http_state *hs; 00117 00118 hs = arg; 00119 00120 if(hs->left > 0) { 00121 send_data(pcb, hs); 00122 } else { 00123 close_conn(pcb, hs); 00124 } 00125 00126 return ERR_OK; 00127 } |
Here is the call graph for this function:
|
Definition at line 232 of file http.c. References http_accept(), IP_ADDR_ANY, tcp_accept(), tcp_bind(), tcp_listen(), and tcp_new(). Referenced by init_module().
00233 { 00234 struct tcp_pcb *pcb; 00235 00236 pcb = tcp_new(); 00237 tcp_bind(pcb, IP_ADDR_ANY, 80); 00238 pcb = tcp_listen(pcb); 00239 tcp_accept(pcb, http_accept); 00240 } |
Here is the call graph for this function:
|
Definition at line 245 of file http.c. References httpd_init().
00245 { 00246 00247 printk("\nHTTP Daemon inserted\n"); 00248 00249 httpd_init(); 00250 return 0; 00251 } |
Here is the call graph for this function:
|
Definition at line 77 of file http.c. References ERR_OK, err_t, http_state::file, http_state::left, len, tcp_sndbuf, tcp_write(), and u16_t. Referenced by http_poll(), http_recv(), and http_sent().
00078 { 00079 err_t err; 00080 u16_t len; 00081 00082 /* We cannot send more data than space avaliable in the send 00083 buffer. */ 00084 if(tcp_sndbuf(pcb) < hs->left) { 00085 len = tcp_sndbuf(pcb); 00086 } else { 00087 len = hs->left; 00088 } 00089 00090 err = tcp_write(pcb, hs->file, len, 0); 00091 00092 if(err == ERR_OK) { 00093 hs->file += len; 00094 hs->left -= len; 00095 } 00096 } |
Here is the call graph for this function: