Added redirect function to httpd

pull/30/head
Jeroen Domburg 10 years ago
parent a01c02245f
commit 645b320558
  1. 17
      user/httpd.c
  2. 1
      user/httpd.h

@ -110,6 +110,7 @@ int httpdUrlDecode(char *val, int valLen, char *ret, int retLen) {
}
//Find a specific arg in a string of get- or post-data.
//Returns len of arg or -1 if not found.
int ICACHE_FLASH_ATTR httpdFindArg(char *line, char *arg, char *buff, int buffLen) {
char *p, *e;
int len;
@ -128,7 +129,7 @@ int ICACHE_FLASH_ATTR httpdFindArg(char *line, char *arg, char *buff, int buffLe
if (p!=NULL) p+=1;
}
os_printf("Finding %s in %s: Not found :/\n", arg, line);
return 0; //not found
return -1; //not found
}
static const char *httpNotFoundHeader="HTTP/1.0 404 Not Found\r\nServer: esp8266-httpd/0.1\r\nContent-Type: text/plain\r\n\r\nNot Found.\r\n";
@ -160,6 +161,20 @@ void ICACHE_FLASH_ATTR httpdRedirect(HttpdConnData *conn, char *newUrl) {
espconn_sent(conn->conn, buff, l);
}
int ICACHE_FLASH_ATTR cgiRedirect(HttpdConnData *connData) {
int len;
char buff[1024];
if (connData->conn==NULL) {
//Connection aborted. Clean up.
return HTTPD_CGI_DONE;
}
httpdRedirect(connData, (char*)connData->cgiArg);
return HTTPD_CGI_DONE;
}
static void ICACHE_FLASH_ATTR httpdSentCb(void *arg) {
int r;
HttpdConnData *conn=httpdFindConnData(arg);

@ -36,6 +36,7 @@ typedef struct {
const void *cgiArg;
} HttpdBuiltInUrl;
int ICACHE_FLASH_ATTR cgiRedirect(HttpdConnData *connData);
void ICACHE_FLASH_ATTR httpdRedirect(HttpdConnData *conn, char *newUrl);
int httpdUrlDecode(char *val, int valLen, char *ret, int retLen);
int ICACHE_FLASH_ATTR httpdFindArg(char *line, char *arg, char *buff, int buffLen);

Loading…
Cancel
Save