当前位置: 首页 > news >正文

ngx_conf_read_token - events

file_size = ngx_file_size(&cf->conf_file->file.info);

获取 配置文件的大小


此时

file_size=364


    for ( ;; ) {

        if (b->pos >= b->last) {

 此时

b->pos  =0x5cd4701487e4
b->last  =0x5cd47014893c
b->start=0x5cd4701487d0

条件不成立


ch = *b->pos++;

从缓冲区的当前处理位置获取 一个字符,然后指针后移为下一个字符的处理做准备


此时

ch=(换行符)


配置文件 nginx.conf
worker_processes  1;

events {
    worker_connections  1024;
}


http {
    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

这次处理到第一行的末尾 分号之后的换行符 


        if (ch == LF) {
            cf->conf_file->line++;

            if (sharp_comment) {
                sharp_comment = 0;
            }
        }

此时 条件成立


此时

line=1 变为 line=2  进入第二行
sharp_comment=0 条件不成立


        if (sharp_comment) {
            continue;
        }

此时

sharp_comment=0


        if (quoted) {
            quoted = 0;
            continue;
        }

此时

quoted=0


 if (need_space) {

此时

need_space=0


if (last_space) {

此时

last_space=1


            start = b->pos - 1;
            start_line = cf->conf_file->line;

更新 单词开始位置的记录


此时

start_line=2


            if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {
                continue;
            }

上一个字符是分隔符,这次还是分隔符,跳过这个字符的后续处理

进入下一次循环,处理下一个字符


    for ( ;; ) {

        if (b->pos >= b->last) {

此时

b->pos  =0x64b74246e7e5
b->last  =0x64b74246e93c
b->start=0x64b74246e7d0

条件不成立


ch = *b->pos++;

此时

ch=(换行符)

第二行是一个空行,只有一个换行符


 

        if (ch == LF) {
            cf->conf_file->line++;

            if (sharp_comment) {
                sharp_comment = 0;
            }
        }

此时

line=2 变为 line=3  进入第三行
sharp_comment=0 条件不成立


        if (sharp_comment) {
            continue;
        }

 

此时

sharp_comment=0


 

        if (quoted) {
            quoted = 0;
            continue;
        }

此时

quoted=0


 

if (need_space) {

此时

need_space=0


 

if (last_space) {

此时

last_space=1


 

            start = b->pos - 1;
            start_line = cf->conf_file->line;

此时

start_line=3 


            if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {
                continue;
            }

 此时 条件成立,进入下一次循环


 

    for ( ;; ) {

        if (b->pos >= b->last) {

此时

b->pos  =0x64b74246e7e6
b->last  =0x64b74246e93c
b->start=0x64b74246e7d0

条件不成立


 

ch = *b->pos++;

此时

ch=e


        if (ch == LF) {
            cf->conf_file->line++;

            if (sharp_comment) {
                sharp_comment = 0;
            }
        }

 此时

条件不成立


 

        if (sharp_comment) {
            continue;
        }

此时

sharp_comment=0


 

        if (quoted) {
            quoted = 0;
            continue;
        }

此时

quoted=0


if (need_space) {

 此时

need_space=0


 

if (last_space) {

此时

last_space=1


 

            start = b->pos - 1;
            start_line = cf->conf_file->line;

此时

start_line=3


 

            if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {
                continue;
            }

此时

条件不成立


 

switch (ch) {

进入这个分支 

            default:
                last_space = 0;

 进入下一次循环

    for ( ;; ) {

        if (b->pos >= b->last) {

此时

b->pos  =0x64b74246e7e7
b->last  =0x64b74246e93c
b->start=0x64b74246e7d0

条件不成立


 

ch = *b->pos++;

此时

ch=v


 

        if (ch == LF) {
            cf->conf_file->line++;

            if (sharp_comment) {
                sharp_comment = 0;
            }
        }

此时

条件不成立


 

        if (sharp_comment) {
            continue;
        }

此时

sharp_comment=0


 

        if (quoted) {
            quoted = 0;
            continue;
        }

此时

quoted=0


 

if (need_space) {

此时

need_space=0 


 

if (last_space) {

此时

last_space=0


 

        } else {
            if (ch == '{' && variable) {
                continue;
            }

            variable = 0;

            if (ch == '\\') {
                quoted = 1;
                continue;
            }

            if (ch == '$') {
                variable = 1;
                continue;
            }

此时 条件不成立


            if (d_quoted) {
                if (ch == '"') {
                    d_quoted = 0;
                    need_space = 1;
                    found = 1;
                }

            } else if (s_quoted) {
                if (ch == '\'') {
                    s_quoted = 0;
                    need_space = 1;
                    found = 1;
                }

            } else if (ch == ' ' || ch == '\t' || ch == CR || ch == LF
                       || ch == ';' || ch == '{')
            {
                last_space = 1;
                found = 1;
            }

 此时

d_quoted=0
s_quoted=0

条件不成立


 

if (found) {

此时 

found=0


 重复以上逻辑

接下来

ch=e

ch=n

ch=t

ch=s


ch= (空格)

 


        if (ch == LF) {
            cf->conf_file->line++;

            if (sharp_comment) {
                sharp_comment = 0;
            }
        }

        if (sharp_comment) {
            continue;
        }

        if (quoted) {
            quoted = 0;
            continue;
        }

        if (need_space) {

此时

sharp_comment=0 

quoted=0 

need_space=0

以上条件不成立


 

if (last_space) {

last_space=0 


 

       } else {
            if (ch == '{' && variable) {
                continue;
            }

            variable = 0;

            if (ch == '\\') {
                quoted = 1;
                continue;
            }

            if (ch == '$') {
                variable = 1;
                continue;
            }

            if (d_quoted) {
                if (ch == '"') {
                    d_quoted = 0;
                    need_space = 1;
                    found = 1;
                }

            } else if (s_quoted) {
                if (ch == '\'') {
                    s_quoted = 0;
                    need_space = 1;
                    found = 1;
                }

此时 

d_quoted=0
s_quoted=0

条件不成立


 

            } else if (ch == ' ' || ch == '\t' || ch == CR || ch == LF
                       || ch == ';' || ch == '{')
            {
                last_space = 1;
                found = 1;
            }

此时

ch= 空格

last_space = 1 标记此次字符是分隔符

found = 1; 表示找到了一个单词


 

            if (found) {

此时

found=1


 

                word = ngx_array_push(cf->args);
                if (word == NULL) {
                    return NGX_ERROR;
                }

获取新元素


                word->data = ngx_pnalloc(cf->pool, b->pos - 1 - start + 1);
                if (word->data == NULL) {
                    return NGX_ERROR;
                }

为单词分配内存

 


                for (dst = word->data, src = start, len = 0;
                     src < b->pos - 1;
                     len++)
                {
                    if (*src == '\\') {
                        switch (src[1]) {
                        case '"':
                        case '\'':
                        case '\\':
                            src++;
                            break;

                        case 't':
                            *dst++ = '\t';
                            src += 2;
                            continue;

                        case 'r':
                            *dst++ = '\r';
                            src += 2;
                            continue;

                        case 'n':
                            *dst++ = '\n';
                            src += 2;
                            continue;
                        }

                    }
                    *dst++ = *src++;
                }
                *dst = '\0';
                word->len = len;

复制单词到 word

此时

word->data=events
word->len=6

 


                if (ch == ';') {
                    return NGX_OK;
                }

                if (ch == '{') {
                    return NGX_CONF_BLOCK_START;
                }

                found = 0;

此时 条件不成立

found 重置为0


进入下一次循环

ch={

        if (ch == LF) {
            cf->conf_file->line++;

            if (sharp_comment) {
                sharp_comment = 0;
            }
        }

        if (sharp_comment) {
            continue;
        }

        if (quoted) {
            quoted = 0;
            continue;
        }

        if (need_space) {

 此时

sharp_comment=0

quoted=0

need_space=0

以上条件不成立


 

if (last_space) {

此时

last_space=1


            start = b->pos - 1;
            start_line = cf->conf_file->line;

            if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {
                continue;
            }

 此时

条件不成立


 

switch (ch) {

进入以下分支

            case '{':
                if (cf->args->nelts == 0) {
                    ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                       "unexpected \"%c\"", ch);
                    return NGX_ERROR;
                }

                if (ch == '{') {
                    return NGX_CONF_BLOCK_START;
                }

                return NGX_OK;

此时

cf->args->nelts=1

返回 NGX_CONF_BLOCK_START

表示此次以 { 为结束

相关文章:

  • CMake set_source_files_properties用法详解
  • 机械革命 无界15X MT7922 debian12 蓝牙无法使用的研究
  • 【NLP】 18. Tokenlisation 分词 BPE, WordPiece, Unigram/SentencePiece
  • 【navicat16版本安装】
  • 基于FPGA的智能垃圾桶设计-超声波测距模块-人体感应模块-舵机模块 仿真通过
  • 服务器远程端口详解
  • MySQL与Oracle深度对比
  • 如何在英文学术写作中正确使用标点符号?
  • JavaScript 基础特性
  • XAMPP 下载、部署及使用入门
  • [redis进阶一]redis的持久化(2)AOF篇章
  • 设计模式(结构型)-桥接模式
  • Keil创建自定义的STM32标准库工程
  • jetpack之lifecycle的原理分析
  • 4.13学习总结
  • rag相关的技术
  • CSS 列表样式学习笔记
  • Spring Security 权限配置详解
  • 【5G-A学习】ISAC通信感知一体化学习小记
  • Elasticsearch搜索引擎 3(DSL)
  • 中国纪检监察刊文:力戒形式主义官僚主义关键是要坚持实事求是
  • 广西百色“致富果”:高品质芒果直供香港,带动近五千户增收
  • 河南:响鼓重锤对违规吃喝问题露头就打、反复敲打、人人喊打
  • 俄方代表团抵达土耳其,俄乌直接谈判有望于当地时间上午重启
  • 习近平复信中国丹麦商会负责人
  • 免签国+1,中乌(兹别克斯坦)互免签证协定6月生效