changeset 126:fcc79370b9a8

nginx-0.0.1-2003-08-06-18:43:50 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 06 Aug 2003 14:43:50 +0000
parents 885ffb8cc32a
children 4cbe22f9907f
files src/core/ngx_alloc.c src/http/modules/ngx_http_ssi_filter.c
diffstat 2 files changed, 224 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/ngx_alloc.c
+++ b/src/core/ngx_alloc.c
@@ -59,16 +59,20 @@ void ngx_destroy_pool(ngx_pool_t *pool)
         free(l->alloc);
     }
 
-    for (p = pool, n = pool->next; /* void */; p = n, n = n->next) {
+    /* we can use pool->log so we have to free() pool after all */
+
+    for (p = pool->next; p ; p = n) {
 #if (NGX_DEBUG_ALLOC)
         ngx_log_debug(pool->log, "free: %08x" _ p);
 #endif
+        n = p->next;
         free(p);
+    }
 
-        if (n == NULL) {
-            break;
-        }
-    }
+#if (NGX_DEBUG_ALLOC)
+    ngx_log_debug(pool->log, "free: %08x" _ pool);
+#endif
+    free(pool);
     pool = NULL;
 }
 
--- a/src/http/modules/ngx_http_ssi_filter.c
+++ b/src/http/modules/ngx_http_ssi_filter.c
@@ -43,27 +43,234 @@ static int ngx_http_ssi_body_filter(ngx_
 }
 
 
-static void ngx_http_ssi_parse()
+static int ngx_http_ssi_parse()
 {
-    for ( ) {
+
+    ctx
+
+    new_hunk = 1;
+    looked = ctx->looked;
+    state = ctx->state;
+
+
+    while (p < h->last) {
+        ch = *p++;
+
         switch (state) {
+
         case ssi_start_state:
 
+            if (new_hunk) {
+                if (looked) {
+                    send looked hunk
+                }
+                new_hunk = 0;
+            }
+
             /* tight loop */
-            while (p < h->last) {
-                if (*p++ == '<') {
-                    state = ssi_comment_state;
-                    length = 1;
+            for ( ;; ) {
+
+                if (ch == '<') {
+                    state = ssi_tag_state;
+                    looked = 1;
+                    break;
+                }
+
+                if (p < h->last) {
+                    state = ssi_start_state;
+                    looked = 0;
                     break;
                 }
+
+                ch = *p++;
+            }
+
+            break;
+
+        case ssi_tag_state:
+            switch (ch) {
+            case '!':
+                state = ssi_comment0_state;
+                looked = 2;
+                break;
+
+            case '<':
+                break;
+
+            default:
+                state = ssi_start_state;
+                looked = 0;
+                break;
+            }
+
+            break;
+
+        case ssi_comment0_state:
+            switch (ch) {
+            case '-':
+                state = ssi_comment1_state;
+                looked = 3;
+                break;
+
+            case '<':
+                state = ssi_tag_state;
+                looked = 1;
+                break;
+
+            default:
+                state = ssi_start_state;
+                looked = 0;
+                break;
+            }
+
+            break;
+
+        case ssi_comment1_state:
+            switch (ch) {
+            case '-':
+                state = ssi_sharp_state;
+                looked = 4;
+                break;
+
+            case '<':
+                state = ssi_tag_state;
+                looked = 1;
+                break;
+
+            default:
+                state = ssi_start_state;
+                looked = 0;
+                break;
+            }
+
+            break;
+
+        case ssi_sharp_state:
+            switch (ch) {
+            case '#':
+                state = ssi_precommand_state;
+                looked = 0;
+                break;
+
+            case '<':
+                state = ssi_tag_state;
+                looked = 1;
+                break;
+
+            default:
+                state = ssi_start_state;
+                looked = 0;
+                break;
             }
 
-            /* fall through */
+            break;
+
+        case ssi_precommand_state:
+            switch (ch) {
+            case ' ':
+            case CR:
+            case LF:
+            case '\t':
+                break;
+
+            default:
+                ngx_test_null(ctx->command.data,
+                              ngx_palloc(r->pool, NGX_SSI_COMMAND_LEN),
+                              NGX_ERROR);
+                ctx->command.data[0] = ch;
+                ctx->command.len = 1;
+                state = ssi_command_state;
+                break;
+            }
 
-        case ssi_comment_state:
+            break;
+
+        case ssi_command_state:
+            if ((ch >= 'a' && ch =< 'z') || (ch >= 'A' && ch <= 'Z')
+                || (ch == '_') || (ch >= '0' && ch <= '9'))
+            {
+                ctx->command.data[ctx->command.len++] = ch;
+
+            } else if (ch == ' ' || ch == CR || ch == LF || ch == '\t') {
+                state = ssi_postcommand_state;
+
+#if 0
+            } else if (ch == '=') {
+                state = ssi_preexpression_state;
+#endif
+
+            } else {
+                return NGX_SSI_PARSE_INVALID_COMMAND;
+            }
+
             break;
 
+        case ssi_postcommand_state:
+            switch (ch) {
+            case ' ':
+            case CR:
+            case LF:
+            case '\t':
+                break;
+
+            case '=':
+                state = ssi_preexpression_state;
+                break;
+
+            default:
+                return NGX_SSI_PARSE_INVALID_PARAM;
+            }
+
+            break;
+
+        case ssi_preexpression_state:
+            switch (ch) {
+            case ' ':
+            case CR:
+            case LF:
+            case '\t':
+                break;
+
+            case '"':
+                state = ssi_expression_state;
+                break;
+
+            default:
+                return NGX_SSI_PARSE_INVALID_PARAM;
+            }
+
+            break;
+
+        case ssi_expression_state:
+            switch (ch) {
+            case '\':
+                state = ssi_quote_state;
+                break;
+
+            case '"':
+                state = ssi_expression_state;
+                break;
+
+            default:
+                return NGX_SSI_PARSE_INVALID_PARAM;
+            }
+
+            break;
+
+        case ssi_quote_state:
+            state = ssi_expression_state;
+
+            break;
+
+        }
     }
+
+    ctx->state = state;
+    ctx->looked = looked;
+
+    send hunk (size - looked);
+
+    return;
 }