Commit 1afc5049 authored by Thomas Milius's avatar Thomas Milius
Browse files

Replace start because of minor changes and style as requested.

parent 8a009e55
...@@ -47,9 +47,9 @@ ...@@ -47,9 +47,9 @@
#define HTTP_OTHER_METHOD_FLAG_MASK_TYPE 3 #define HTTP_OTHER_METHOD_FLAG_MASK_TYPE 3
typedef struct { typedef struct {
char *name; char *name;
unsigned long flags; unsigned long flags;
unsigned long usage_counter; unsigned long usage_counter;
} http_other_method; } http_other_method;
http_other_method http_other_methods[128]; http_other_method http_other_methods[128];
...@@ -64,38 +64,38 @@ static _kernel_oserror *http_start_main(_kernel_swi_regs *r); ...@@ -64,38 +64,38 @@ static _kernel_oserror *http_start_main(_kernel_swi_regs *r);
/* Called at start of module */ /* Called at start of module */
void http_start_init(void) void http_start_init(void)
{ {
int i; int i;
for (i=0; i < 128; i++) { for (i=0; i < 128; i++) {
http_other_methods[i].name=NULL; http_other_methods[i].name=NULL;
http_other_methods[i].flags=0; http_other_methods[i].flags=0;
http_other_methods[i].usage_counter=0; http_other_methods[i].usage_counter=0;
} }
/* Mark reserved methods as used */ /* Mark reserved methods as used */
http_other_methods[0].usage_counter=1; http_other_methods[0].usage_counter=1;
/* Mark HTTP standard methods as used */ /* Mark HTTP standard methods as used */
http_other_methods[method_HTTP_GET].usage_counter=1; http_other_methods[method_HTTP_GET].usage_counter=1;
http_other_methods[method_HTTP_HEAD].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_POST].usage_counter=1;
http_other_methods[method_HTTP_PUT].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_OPTIONS].usage_counter=1;
http_other_methods[method_HTTP_TRACE].usage_counter=1; http_other_methods[method_HTTP_TRACE].usage_counter=1;
http_other_methods[method_HTTP_DELETE].usage_counter=1; http_other_methods[method_HTTP_DELETE].usage_counter=1;
} }
/* Called at finalization of module */ /* Called at finalization of module */
void http_start_cleanup(void) void http_start_cleanup(void)
{ {
int i; int i;
for (i=0; i < 128; i++) { for (i=0; i < 128; i++) {
if (http_other_methods[i].name != NULL) { if (http_other_methods[i].name != NULL) {
free(http_other_methods[i].name); free(http_other_methods[i].name);
http_other_methods[i].name=NULL; http_other_methods[i].name=NULL;
} }
http_other_methods[i].flags=0; http_other_methods[i].flags=0;
http_other_methods[i].usage_counter=0; http_other_methods[i].usage_counter=0;
} }
} }
/*************************************************************/ /*************************************************************/
...@@ -112,53 +112,48 @@ for (i=0; i < 128; i++) { ...@@ -112,53 +112,48 @@ for (i=0; i < 128; i++) {
/*************************************************************/ /*************************************************************/
_kernel_oserror *http_register_method(_kernel_swi_regs *r) _kernel_oserror *http_register_method(_kernel_swi_regs *r)
{ {
int i; int i;
int first_unused_method; int first_unused_method;
int string_length; int string_length;
/* Warning: Should not run in parallel! /* Warning: Should not run in parallel!
But how to ensure this at multicore environment? */ But how to ensure this at multicore environment? */
if (r == NULL) return make_error(HTTP_GENERAL_ERROR, 0); /* Indicates failure. */
/* Indicates failure. */ r->r[2]=-1;
r->r[2]=-1; if (r->r[0] == NULL) return make_error(HTTP_BAD_PARAMETER, 0);
if (r->r[0] != NULL) { first_unused_method=-1;
first_unused_method=-1; i=0;
i=0; while (i < 128) {
while (i < 128) { if (first_unused_method == -1 &&
if (first_unused_method == -1 && http_other_methods[i].usage_counter == 0) {
http_other_methods[i].usage_counter == 0) { /* Note first unused method in case that the requested
/* Note first unused method in case that the requested method doesn't already exists */
method doesn't already exists */ first_unused_method=i;
first_unused_method=i; }
} else if (http_other_methods[i].usage_counter > 0 &&
else if (http_other_methods[i].usage_counter > 0 && http_other_methods[i].name != NULL &&
http_other_methods[i].name != NULL && http_other_methods[i].flags == (unsigned long) r->r[1] &&
http_other_methods[i].flags == (unsigned long) r->r[1] && strcmp(http_other_methods[i].name, (char *) r->r[0]) == 0) {
strcmp(http_other_methods[i].name, (char *) r->r[0]) == 0) { /* Method already exists */
/* Method already exists */ /* And is used now by an additional application */
/* And is used now by an additional application */ http_other_methods[i].usage_counter++;
http_other_methods[i].usage_counter++; r->r[2]=i;
r->r[2]=i; return NULL;
return NULL; }
} i++;
i++; }
} if (first_unused_method == -1) return make_error(HTTP_NO_RESOURCES, 0);
if (first_unused_method != -1) { /* Method doesn't exists yet and there is a free method we can use for it. */
/* Method doesn't exists yet and there is a free method we can use for it. */ string_length=strlen((char *) r->r[0]);
string_length=strlen((char *) r->r[0]); if (string_length > 0) {
if (string_length > 0) { if ((http_other_methods[first_unused_method].name=malloc(string_length + 1)) != NULL) {
if ((http_other_methods[first_unused_method].name=malloc(string_length + 1)) != NULL) { http_other_methods[first_unused_method].usage_counter=1;
http_other_methods[first_unused_method].usage_counter=1; strcpy(http_other_methods[first_unused_method].name, (char *) r->r[0]);
strcpy(http_other_methods[first_unused_method].name, (char *) r->r[0]); http_other_methods[first_unused_method].flags=(unsigned long) r->r[1];
http_other_methods[first_unused_method].flags=(unsigned long) r->r[1]; r->r[2]=first_unused_method;
r->r[2]=first_unused_method; }
} }
} return NULL;
return NULL;
}
else return make_error(HTTP_NO_RESOURCES, 0);
}
else return make_error(HTTP_BAD_PARAMETER, 0);
} }
/*************************************************************/ /*************************************************************/
...@@ -173,34 +168,31 @@ else return make_error(HTTP_BAD_PARAMETER, 0); ...@@ -173,34 +168,31 @@ else return make_error(HTTP_BAD_PARAMETER, 0);
/*************************************************************/ /*************************************************************/
_kernel_oserror *http_deregister_method(_kernel_swi_regs *r) _kernel_oserror *http_deregister_method(_kernel_swi_regs *r)
{ {
int i; int i;
/* Warning: Should not run in parallel! /* Warning: Should not run in parallel!
But how to ensure this at multicore environment? */ But how to ensure this at multicore environment? */
if (r == NULL) return make_error(HTTP_GENERAL_ERROR,0); if (r->r[0] == NULL) return make_error(HTTP_BAD_PARAMETER,0);
if (r->r[0] != NULL) { i=0;
i=0; while (i < 128) {
while (i < 128) { if (http_other_methods[i].usage_counter > 0 &&
if (http_other_methods[i].usage_counter > 0 && http_other_methods[i].name != NULL &&
http_other_methods[i].name != NULL && http_other_methods[i].flags == r->r[1] &&
http_other_methods[i].flags == r->r[1] && strcmp(http_other_methods[i].name, (char *) r->r[0]) == 0) {
strcmp(http_other_methods[i].name, (char *) r->r[0]) == 0) { http_other_methods[i].usage_counter--;
http_other_methods[i].usage_counter--; if (http_other_methods[i].usage_counter == 0) {
if (http_other_methods[i].usage_counter == 0) { /* Can be used for other methods now. */
/* Can be used for other methods now. */ if (http_other_methods[i].name != NULL) {
if (http_other_methods[i].name != NULL) { free(http_other_methods[i].name);
free(http_other_methods[i].name); http_other_methods[i].name=NULL;
http_other_methods[i].name=NULL; }
} http_other_methods[i].flags=0;
http_other_methods[i].flags=0; }
return NULL;
}
i++;
} }
return NULL; return make_error(HTTP_METHOD_UNSUPPORTED,0);
}
i++;
}
return make_error(HTTP_METHOD_UNSUPPORTED,0);
}
else return make_error(HTTP_BAD_PARAMETER,0);
} }
/*************************************************************/ /*************************************************************/
......
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