Commit 3e163171 authored by Thomas Milius's avatar Thomas Milius
Browse files

Replace start due to concept change

parent d993ad19
......@@ -47,9 +47,10 @@
typedef struct {
char *name;
unsigned long flags;
unsigned long usage_counter;
} http_other_method;
http_other_method http_other_methods[256];
http_other_method http_other_methods[128];
static int http_generate_request(Session *ses, _kernel_swi_regs *r);
static Session *http_new_session(_kernel_swi_regs *r);
......@@ -61,83 +62,140 @@ 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++) {
for (i=0; i < 128; i++) {
http_other_methods[i].name=NULL;
http_other_methods[i].flags=0;
http_other_methods[i].usage_counter=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;
}
}
}
/* Mark reserved methods as used */
http_other_methods[0].usage_counter=1;
/* Mark HTTP standard methods as used */
http_other_methods[method_HTTP_GET].usage_counter=1;
http_other_methods[method_HTTP_HEAD].usage_counter=1;
http_other_methods[method_HTTP_POST].usage_counter=1;
http_other_methods[method_HTTP_PUT].usage_counter=1;
http_other_methods[method_HTTP_OPTIONS].usage_counter=1;
http_other_methods[method_HTTP_TRACE].usage_counter=1;
http_other_methods[method_HTTP_DELETE].usage_counter=1;
}
/* Called at finalization of module */
void http_start_cleanup(void)
{
int i;
for (i=0; i < 128; 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;
http_other_methods[i].usage_counter=0;
}
}
/*************************************************************/
/* _kernel_oserror http_register_method (_kernel_swi_regs *r) */
/*************************************************************/
/*************************************************************/
/* Must be called by application to register a certain non */
/* standard HTTP method. The values in the registers are: */
/* r0 = Pointer to 0 delimited HTTP method name */
/* r1 = Method flags */
/* On exit: */
/* r2 = method to use or -1 in case that there is no */
/* method number available or parameters are invalid */
/*************************************************************/
_kernel_oserror *http_register_method(_kernel_swi_regs *r)
{
int i;
int first_unused_method;
int string_length;
/* Warning: Should not run in parallel!
But how to ensure this at multicore environment? */
if (r == NULL) return NULL;
/* Indicates failure. */
r->r[2]=-1;
if (r->r[0] != NULL) {
first_unused_method=-1;
i=0;
while (i < 128) {
if (first_unused_method == -1 &&
http_other_methods[i].usage_counter == 0) {
/* Note first unused method in case that the requested
method doesn't already exists */
first_unused_method=i;
}
else if (http_other_methods[i].usage_counter > 0 &&
http_other_methods[i].name != NULL &&
http_other_methods[i].flags == (unsigned long) r->r[1] &&
strcmp(http_other_methods[i].name, (char *) r->r[0]) == 0) {
/* Method already exists */
/* And is used now by an additional application */
http_other_methods[i].usage_counter++;
r->r[2]=i;
return NULL;
}
i++;
}
if (first_unused_method != -1) {
/* Method doesn't exists yet and there is a free method we can use for it. */
string_length=strlen((char *) r->r[0]);
if (string_length > 0) {
if ((http_other_methods[first_unused_method].name=malloc(string_length + 1)) != NULL) {
http_other_methods[first_unused_method].usage_counter=1;
strcpy(http_other_methods[first_unused_method].name, (char *) r->r[0]);
http_other_methods[first_unused_method].flags=(unsigned long) r->r[1];
r->r[2]=first_unused_method;
}
}
}
fclose(other_methods);
}
return NULL;
}
/* Called at end of module */
void http_start_cleanup(void)
/*************************************************************/
/* _kernel_oserror http_deregister_method (_kernel_swi_regs *r) */
/*************************************************************/
/*************************************************************/
/* Must be called by application to deregister a certain non */
/* standard HTTP method previously registered with */
/* http_register_method. The values in the registers are: */
/* r0 = Pointer to 0 delimited HTTP method name */
/* r1 = Method Flags */
/*************************************************************/
_kernel_oserror *http_deregister_method(_kernel_swi_regs *r)
{
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;
}
int i;
/* Warning: Should not run in parallel!
But how to ensure this at multicore environment? */
if (r != NULL &&
r->r[0] != NULL) {
i=0;
while (i < 128) {
if (http_other_methods[i].usage_counter > 0 &&
http_other_methods[i].name != NULL &&
http_other_methods[i].flags == r->r[1] &&
strcmp(http_other_methods[i].name, (char *) r->r[0]) == 0) {
http_other_methods[i].usage_counter--;
if (http_other_methods[i].usage_counter == 0) {
/* Can be used for other methods now. */
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;
}
return NULL;
}
i++;
}
}
return NULL;
}
/*************************************************************/
......@@ -483,7 +541,7 @@ static const char *http_method_text(const int method)
case method_HTTP_TRACE: return "TRACE";
case method_HTTP_DELETE: return "DELETE";
default: {
if (method < 256) return http_other_methods[method].name;
if (method < 128) return http_other_methods[method].name;
else return NULL;
}
}
......@@ -520,7 +578,7 @@ static int http_validate_user_supplied_data(Session *ses)
if (ses->method == method_HTTP_GET || ses->method == method_HTTP_HEAD ||
(ses->method < 256 &&
(ses->method < 128 &&
(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
......@@ -564,7 +622,7 @@ static int http_validate_user_supplied_data(Session *ses)
}
if (ses->method == method_HTTP_PUT || ses->method == method_HTTP_POST ||
(ses->method < 256 &&
(ses->method < 128 &&
(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