欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > ngx_conf_read_token - events

ngx_conf_read_token - events

2025/4/17 1:40:39 来源:https://blog.csdn.net/weixin_41812346/article/details/147191806  浏览:    关键词: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

表示此次以 { 为结束

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词