Commit bd350f0f authored by Thomas Milius's avatar Thomas Milius
Browse files

Replace start. New structure to handle user defined methods added and according evaluation of it

parent 0fec4390
......@@ -37,6 +37,19 @@
#include "URLclient.h"
#include "security.h"
#include "connect.h"
#include "start.h"
#define HTTP_OTHER_METHOD_FLAG_TYPE_USER 0
#define HTTP_OTHER_METHOD_FLAG_TYPE_POST 1
#define HTTP_OTHER_METHOD_FLAG_TYPE_GET 2
#define HTTP_OTHER_METHOD_FLAG_MASK_TYPE 3
typedef struct {
char *name;
unsigned long flags;
} http_other_method;
http_other_method http_other_methods[256];
static int http_generate_request(Session *ses, _kernel_swi_regs *r);
static Session *http_new_session(_kernel_swi_regs *r);
......@@ -45,6 +58,88 @@ static const char *http_method_text(const int);
static int http_parse_url(Session *ses, char *proxy);
static _kernel_oserror *http_start_main(_kernel_swi_regs *r);
/* Called at start of module */
void http_start_init(void)
{
char map_line[64];
char *position;
char *previous_position;
int i;
unsigned int other_method;
int string_length;
FILE *other_methods;
for (i=0; i < 256; i++) {
http_other_methods[i].name=NULL;
http_other_methods[i].flags=0;
}
map_line[63]='\0';
if ((other_methods=fopen("Choices:WWW.AcornHTTP.UsrMthds", "r")) != NULL) {
while (!feof(other_methods)) {
if (fgets(map_line, 63, other_methods) != NULL) {
/* Exclude comment lines */
if (map_line[0] != '|') {
/* At beginning of the line there should be the method number */
if ((position=strchr(map_line, '=')) != NULL) {
*position='\0';
if ((other_method=atoi(map_line)) < 256) {
previous_position=position + 1;
if ((position=strchr(previous_position, ',')) != NULL) {
/* Optionally followed by flags which are separated by a , from method name */
*position='\0';
http_other_methods[other_method].flags=atol(previous_position);
previous_position=position + 1;
}
string_length=strlen(previous_position);
while (string_length > 0) {
if (*(previous_position + string_length - 1) != '\r' &&
*(previous_position + string_length - 1) != '\n') {
break;
}
else {
*(previous_position + string_length - 1)='\0';
string_length--;
}
}
if (http_other_methods[other_method].name != NULL) {
free(http_other_methods[other_method].name);
http_other_methods[other_method].name=NULL;
http_other_methods[other_method].flags=0;
}
if (string_length > 0) {
if ((http_other_methods[other_method].name=malloc(string_length + 1)) != NULL) {
strcpy(http_other_methods[other_method].name, previous_position);
}
else {
http_other_methods[other_method].flags=0;
}
}
else {
http_other_methods[other_method].flags=0;
}
}
}
}
}
}
fclose(other_methods);
}
}
/* Called at end of module */
void http_start_cleanup(void)
{
int i;
for (i=0; i < 256; i++) {
if (http_other_methods[i].name != NULL) {
free(http_other_methods[i].name);
http_other_methods[i].name=NULL;
}
http_other_methods[i].flags=0;
}
}
/*************************************************************/
/* _kernel_oserror http_start(_kernel_swi_regs *r) */
/*************************************************************/
......@@ -387,8 +482,10 @@ static const char *http_method_text(const int method)
case method_HTTP_OPTIONS: return "OPTIONS";
case method_HTTP_TRACE: return "TRACE";
case method_HTTP_DELETE: return "DELETE";
default:
return NULL;
default: {
if (method < 256) return http_other_methods[method].name;
else return NULL;
}
}
}
......@@ -422,7 +519,9 @@ static int http_validate_user_supplied_data(Session *ses)
}
if (ses->method == method_HTTP_GET || ses->method == method_HTTP_HEAD) {
if (ses->method == method_HTTP_GET || ses->method == method_HTTP_HEAD ||
(ses->method < 256 &&
(http_other_methods[ses->method].flags & HTTP_OTHER_METHOD_FLAG_MASK_TYPE) == HTTP_OTHER_METHOD_FLAG_TYPE_GET)) {
/* ... and add any other HTTP methods that MUST NOT include an entity
* body along with the request
*/
......@@ -464,7 +563,9 @@ static int http_validate_user_supplied_data(Session *ses)
ses->data_len = 0; /* Forcibly ignore the extra data */
}
if (ses->method == method_HTTP_PUT || ses->method == method_HTTP_POST) {
if (ses->method == method_HTTP_PUT || ses->method == method_HTTP_POST ||
(ses->method < 256 &&
(http_other_methods[ses->method].flags & HTTP_OTHER_METHOD_FLAG_MASK_TYPE) == HTTP_OTHER_METHOD_FLAG_TYPE_POST)) {
/* ... and add any other HTTP methods that MUST include an entity
* body along with the request
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment