• nginx 日志模块


    ngx_http_log_module.c

    数据结构

    typedef struct {
    void **main_conf;
    void **srv_conf;
    void **loc_conf;
    } ngx_http_conf_ctx_t;

    typedef struct ngx_http_log_op_s ngx_http_log_op_t;

    typedef u_char *(*ngx_http_log_op_run_pt) (ngx_http_request_t *r, u_char *buf,
    ngx_http_log_op_t *op);

    typedef size_t (*ngx_http_log_op_getlen_pt) (ngx_http_request_t *r,
    uintptr_t data);


    struct ngx_http_log_op_s {
    size_t len;
    ngx_http_log_op_getlen_pt getlen;
    ngx_http_log_op_run_pt run;
    uintptr_t data;
    };


    typedef struct {
    ngx_str_t name;
    ngx_array_t *flushes;
    ngx_array_t *ops; /* array of ngx_http_log_op_t */
    } ngx_http_log_fmt_t;


    typedef struct {
    ngx_array_t formats; /* array of ngx_http_log_fmt_t */
    ngx_uint_t combined_used; /* unsigned combined_used:1 */
    } ngx_http_log_main_conf_t;

    typedef struct {
    u_char *start;
    u_char *pos;
    u_char *last;

    ngx_event_t *event;
    ngx_msec_t flush;
    ngx_int_t gzip;
    } ngx_http_log_buf_t;


    typedef struct {
    ngx_array_t *lengths;
    ngx_array_t *values;
    } ngx_http_log_script_t;


    typedef struct {
    ngx_open_file_t *file;
    ngx_http_log_script_t *script;
    time_t disk_full_time;
    time_t error_log_time;
    ngx_http_log_fmt_t *format;
    } ngx_http_log_t;


    typedef struct {
    ngx_array_t *logs; /* array of ngx_http_log_t */

    ngx_open_file_cache_t *open_file_cache;
    time_t open_file_cache_valid;
    ngx_uint_t open_file_cache_min_uses;

    ngx_uint_t off; /* unsigned off:1 */
    } ngx_http_log_loc_conf_t;

    typedef struct {
    ngx_str_t name;
    size_t len;
    ngx_http_log_op_run_pt run;
    } ngx_http_log_var_t;

    typedef struct {
    ngx_str_t name;
    void *(*create_conf)(ngx_cycle_t *cycle);
    char *(*init_conf)(ngx_cycle_t *cycle, void *conf);
    } ngx_core_module_t;

    typedef struct {
    ngx_int_t (*preconfiguration)(ngx_conf_t *cf);
    ngx_int_t (*postconfiguration)(ngx_conf_t *cf);

    void *(*create_main_conf)(ngx_conf_t *cf);
    char *(*init_main_conf)(ngx_conf_t *cf, void *conf);

    void *(*create_srv_conf)(ngx_conf_t *cf); char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev, void *conf);

    void *(*create_loc_conf)(ngx_conf_t *cf);
    char *(*merge_loc_conf)(ngx_conf_t *cf, void *prev, void *conf);
    } ngx_http_module_t;

    static ngx_http_module_t ngx_http_log_module_ctx = {
    NULL, /* preconfiguration */
    ngx_http_log_init, /* postconfiguration */

    ngx_http_log_create_main_conf, /* create main configuration */
    NULL, /* init main configuration */

    NULL, /* create server configuration */
    NULL, /* merge server configuration */

    ngx_http_log_create_loc_conf, /* create location configuration */
    ngx_http_log_merge_loc_conf /* merge location configuration */
    };

    #define NGX_MODULE_V1 0, 0, 0, 0, 0, 0, 1
    #define NGX_MODULE_V1_PADDING 0, 0, 0, 0, 0, 0, 0, 0

    struct ngx_module_s {
    ngx_uint_t ctx_index;
    ngx_uint_t index;

    ngx_uint_t spare0;
    ngx_uint_t spare1;
    ngx_uint_t spare2;
    ngx_uint_t spare3;

    ngx_uint_t version;

    void *ctx;
    ngx_command_t *commands;
    ngx_uint_t type;

    ngx_int_t (*init_master)(ngx_log_t *log);
    ngx_int_t (*init_module)(ngx_cycle_t *cycle);

    ngx_int_t (*init_process)(ngx_cycle_t *cycle);
    ngx_int_t (*init_thread)(ngx_cycle_t *cycle);
    void (*exit_thread)(ngx_cycle_t *cycle);
    void (*exit_process)(ngx_cycle_t *cycle);

    void (*exit_master)(ngx_cycle_t *cycle);

    uintptr_t spare_hook0;
    uintptr_t spare_hook1;
    uintptr_t spare_hook2;
    uintptr_t spare_hook3;
    uintptr_t spare_hook4;
    uintptr_t spare_hook5;
    uintptr_t spare_hook6;
    uintptr_t spare_hook7;
    };

    struct ngx_command_s {
    ngx_str_t name;
    ngx_uint_t type;
    char *(*set)(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
    ngx_uint_t conf;
    ngx_uint_t offset;
    void *post;
    };

    http:

    typedef struct {
    ngx_array_t servers; /* ngx_http_core_srv_conf_t */

    ngx_http_phase_engine_t phase_engine;

    ngx_hash_t headers_in_hash;

    ngx_hash_t variables_hash;
    ngx_array_t variables; /* ngx_http_variable_t */ ngx_uint_t ncaptures;

    ngx_uint_t server_names_hash_max_size;
    ngx_uint_t server_names_hash_bucket_size;

    ngx_uint_t variables_hash_max_size; ngx_uint_t variables_hash_bucket_size;

    ngx_hash_keys_arrays_t *variables_keys;

    ngx_array_t *ports;
    ngx_uint_t try_files; /* unsigned try_files:1 */

    ngx_http_phase_t phases[NGX_HTTP_LOG_PHASE + 1];
    } ngx_http_core_main_conf_t;

    typedef struct {
    unsigned len:28;

    unsigned valid:1;
    unsigned no_cacheable:1;
    unsigned not_found:1;
    unsigned escape:1;

    u_char *data;
    } ngx_variable_value_t;

    struct ngx_buf_s {
    u_char *pos;
    u_char *last;
    off_t file_pos;
    off_t file_last;

    u_char *start; /* start of buffer */
    u_char *end; /* end of buffer */ ngx_buf_tag_t tag;
    ngx_file_t *file;
    ngx_buf_t *shadow;


    /* the buf's content could be changed */
    unsigned temporary:1;

    /*
    * the buf's content is in a memory cache or in a read only memory
    * and must not be changed
    */
    unsigned memory:1;

    /* the buf's content is mmap()ed and must not be changed */
    unsigned mmap:1;

    unsigned recycled:1;
    unsigned in_file:1;
    unsigned flush:1;
    unsigned sync:1;
    unsigned last_buf:1;
    unsigned last_in_chain:1;

    unsigned last_shadow:1;
    unsigned temp_file:1;

    /* STUB */ int num;
    };

    struct ngx_chain_s {
    ngx_buf_t *buf;
    ngx_chain_t *next;
    };

  • 相关阅读:
    IE9不能在线打开InfoPath表单的解决办法
    在Word中使用Quick Parts功能
    .NET WinForm程序在Windows7下实现玻璃效果和任务栏进度条效果
    如何对已经发布过的InfoPath模板进行修改
    .NET WinForm中给DataGridView自定义ToolTip并设置ToolTip的样式
    有关SharePoint Client Object应用的笔记
    解决VS 2010中编译程序时弹出"Type universe cannot resolve assembly"的错误
    SharePoint客户端对象模型"(400) Bad Request"错误
    C# Method Attribute and Reflection
    .NET WinForm下一个支持更新ProgressBar进度的DataGridView导出数据到Excel的类
  • 原文地址:https://www.cnblogs.com/andyhe/p/3214720.html
Copyright © 2020-2023  润新知