Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Internet/TFTP/tftp.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern "C" {
#endif

#include <stdint.h>
#include <stdio.h>

#define F_APP_TFTP
#define __TFTP_DEBUG__
Expand Down
38 changes: 36 additions & 2 deletions Internet/httpServer/httpParser.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "socket.h"
#include "httpParser.h"
Expand Down Expand Up @@ -126,12 +127,13 @@ void find_http_uri_type(
*/
void parse_http_request(
st_http_request * request, /**< request to be returned */
uint8_t * buf /**< pointer to be parsed */
uint8_t * buf, /**< pointer to be parsed */
size_t buf_len
)
{
char * nexttok;
nexttok = strtok((char*)buf," ");
if(!nexttok)
if(nexttok == NULL)
{
request->METHOD = METHOD_ERR;
return;
Expand Down Expand Up @@ -163,7 +165,39 @@ void parse_http_request(
request->METHOD = METHOD_ERR;
return;
}

//check for uri length, if ok copy
size_t l = strlen(nexttok);
if(l >= MAX_URI_SIZE){
request->METHOD = METHOD_ERR;
return;
}
strcpy((char *)request->URI, nexttok);

//nexttok = strtok(NULL,"\0");

// --- Extract POST body and Content-Length ---
if(request->METHOD == METHOD_POST) {
char *cl = strstr((char*)nexttok, "Content-Length:");
if(cl) {
cl += strlen("Content-Length:");
while(*cl == ' ') cl++;
request->post_content_length = atoi(cl);
} else {
request->post_content_length = 0;
}
char *body = strstr((char*)nexttok, "\r\n\r\n");
if (body) {
body += 4;
int offset = body - (char*)buf;
int available = buf_len - offset;
request->post_body_ptr = body;
request->post_body_length = (available > 0) ? available : 0;
} else {
request->post_body_ptr = NULL;
request->post_body_length = 0;
}
}
}

#ifdef _OLD_
Expand Down
12 changes: 8 additions & 4 deletions Internet/httpServer/httpParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,23 @@ static const char ERROR_REQUEST_PAGE[] = "HTTP/1.1 400 OK\r\nContent-Type: text
@brief Structure of HTTP REQUEST
*/

//#define MAX_URI_SIZE 1461
#define MAX_URI_SIZE 512


// the whole size of st_http_request must be less than DATA_BUF_SIZE (DATA_BUF_SIZE = 2048)
#define MAX_URI_SIZE 256
typedef struct _st_http_request
{
uint8_t METHOD; /**< request method(METHOD_GET...). */
uint8_t TYPE; /**< request type(PTYPE_HTML...). */
uint8_t URI[MAX_URI_SIZE]; /**< request file name. */
uint8_t URI[MAX_URI_SIZE]; /**< request file name. */
size_t post_content_length; /**< in POST request Content-Length */
size_t post_body_length; /**< in POST request body length */
uint8_t * post_body_ptr; /**< in POST pointer to body */
}st_http_request;

// HTTP Parsing functions
void unescape_http_url(char * url); /* convert escape character to ascii */
void parse_http_request(st_http_request *, uint8_t *); /* parse request from peer */
void parse_http_request(st_http_request *, uint8_t *, size_t); /* parse request from peer */
void find_http_uri_type(uint8_t *, uint8_t *); /* find MIME type of a file */
void make_http_response_head(char *, char, uint32_t); /* make response header */
uint8_t * get_http_param_value(char* uri, char* param_name); /* get the user-specific parameter value */
Expand Down
Loading