MK_PLUGIN_STAGE_20: Accepted connection has not been assigned to worker thread
MK_PLUGIN_STAGE_30: HTTP Request received
MK_PLUGIN_STAGE_40: Object Handler
+
+ Return Values:
+ --------------
+ * MK_PLUGIN_RET_NOT_ME: Plugin will not handle this request.
+
+ * MK_PLUGIN_RET_END: Plugin has taken some action and
+ has finished the work, the handler will no take the request
+ again.
+
+ * MK_PLUGIN_RET_CONTINUE:: Plugin has taken some action and
+ will continue in the next loop.
+
MK_PLUGIN_STAGE_50: Request ended
MK_PLUGIN_STAGE_60: Connection closed
/* Monkey HTTP Daemon
* ------------------
- * Copyright (C) 2001-2008, Eduardo Silva P.
+ * Copyright (C) 2001-2010, Eduardo Silva P.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#define MK_PLUGIN_STAGE_50 ((__uint32_t) 16) /* Request ended */
#define MK_PLUGIN_STAGE_60 ((__uint32_t) 32) /* Connection closed */
-#define MK_PLUGIN_RET_CLOSE_CONX 100
-#define MK_PLUGIN_RET_OWNER 200
+#define MK_PLUGIN_RET_NOT_ME -1
+#define MK_PLUGIN_RET_OWNER 100
+#define MK_PLUGIN_RET_CLOSE_CONX 200
#define MK_PLUGIN_RET_CONTINUE 300
struct plugin_stages {
struct header_toc *next;
};
+/* Request plugin Handler, each request can be handled by
+ * several plugins, we handle list in a simple list */
+struct handler {
+ struct plugin *p;
+ struct handler *next;
+};
+
struct request {
int status;
int pipelined; /* Pipelined request */
long loop;
long bytes_to_send;
off_t bytes_offset;
+
+ /* Plugin handlers */
+ struct handler *handled_by;
};
struct header_values {
p = config->plugins->stage_40;
while(p){
ret = p->call_stage_40(cr, sr);
- if(ret == 0){
- return 0;
+ switch(ret){
+ case MK_PLUGIN_RET_NOT_ME:
+ break;
+ case MK_PLUGIN_RET_END:
+ break;
+ case MK_PLUGIN_RET_CONTINUE:
+ /* Register plugin for next loops */
+ mk_request_handler_register(sr, p);
+ break;
}
p = p->next;
}
/* Response Headers */
request->headers = mk_header_create();
+ request->handled_by = NULL;
return request;
}
cr->body_length = 0;
cr->counter_connections++;
}
+
+void mk_request_handler_register(struct request *sr, struct plugin *p)
+{
+ struct handler *new, *aux;
+
+ new = mk_mem_malloc(sizeof(struct handler));
+ new->p = p;
+ new->next = NULL;
+
+ if(!sr->handled_by){
+ sr->handled_by = new;
+ return;
+ }
+
+ aux = sr->handled_by;
+ while(aux){
+ if(!aux->next){
+ aux->next = new;
+ return;
+ }
+ aux = aux->next;
+ }
+
+ printf("\nMK_REQUEST_REGISTER_HANDLER: NEVER ASSIGNED");
+ fflush(stdout);
+}
+
+void mk_request_handler_clear(struct request *sr)
+{
+ struct handler *prev=0, *aux;
+
+ if(!sr->handled_by){
+ return;
+ }
+
+ while(sr->handled_by){
+ aux = sr->handled_by;
+ while(aux->next){
+ prev = aux;
+ aux = aux->next;
+ }
+ mk_mem_free(aux);
+ prev->next = NULL;
+ }
+
+ return;
+}