nginx插件iconv

  • g4_152546
    了解作者
  • 22.8KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-25 11:11
    上传日期
nginx插件iconv插件源码包,用于转换编码格式,分享出来,也希望有大神能告诉我如何将这个源码编译成so文件,供nginx的loadmodule使用
iconv-nginx-module-master.zip
  • iconv-nginx-module-master
  • t
  • sanity.t
    8.8KB
  • bugs.t
    8.8KB
  • src
  • ddebug.h
    2.6KB
  • ngx_http_iconv_module.c
    19.5KB
  • util
  • update-readme.sh
    98B
  • build.sh
    1KB
  • releng
    247B
  • wiki2pod.pl
    3.1KB
  • .DS_Store
    6KB
  • valgrind.suppress
    2.1KB
  • README.markdown
    5.1KB
  • config
    3.3KB
  • .gitignore
    597B
内容介绍
#ifndef DDEBUG #define DDEBUG 0 #endif #include "ddebug.h" #include <ndk.h> #include <iconv.h> #include <ngx_config.h> #include <ngx_core.h> #include <ngx_http.h> static ngx_int_t iconv_buf_size; static ngx_int_t max_iconv_bufs; static ngx_uint_t ngx_http_iconv_filter_used = 0; typedef struct { size_t buf_size; ngx_flag_t enabled; u_char *from; u_char *to; } ngx_http_iconv_loc_conf_t; typedef struct { ngx_str_t uc; /* unfinished character */ } ngx_http_iconv_ctx_t; static ngx_int_t ngx_http_iconv_filter_pre(ngx_conf_t *cf); static ngx_int_t ngx_http_iconv_filter_init(ngx_conf_t *cf); static ngx_int_t ngx_http_iconv_header_filter(ngx_http_request_t *r); static ngx_int_t ngx_http_iconv_body_filter(ngx_http_request_t *r, ngx_chain_t *in); static ngx_int_t ngx_http_iconv_filter_convert(ngx_http_request_t *r, ngx_http_iconv_ctx_t *ctx, ngx_chain_t *in, ngx_chain_t **out); static ngx_int_t ngx_http_do_iconv(ngx_http_request_t *r, ngx_chain_t **c, void *data, size_t len, u_char *from, u_char *to, size_t *conv_bytes, size_t *rest_bytes); static ngx_int_t ngx_http_iconv_merge_chain_link(ngx_http_request_t *r, ngx_http_iconv_ctx_t *ctx, ngx_chain_t *in, ngx_chain_t **out); static char *ngx_http_iconv_conf_handler(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char *ngx_http_set_iconv_conf_handler(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static ngx_int_t ngx_http_set_iconv_handler(ngx_http_request_t *r, ngx_str_t *res, ngx_http_variable_value_t *v); static void *ngx_http_iconv_create_loc_conf(ngx_conf_t *cf); static char *ngx_http_iconv_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child); static void ngx_http_iconv_discard_body(ngx_chain_t *in); static ngx_command_t ngx_http_iconv_commands[] = { { ngx_string("set_iconv"), NGX_HTTP_LOC_CONF|NGX_CONF_TAKE4, ngx_http_set_iconv_conf_handler, NGX_HTTP_LOC_CONF_OFFSET, 0, NULL }, { ngx_string("iconv_buffer_size"), NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, ngx_conf_set_size_slot, NGX_HTTP_LOC_CONF_OFFSET, offsetof(ngx_http_iconv_loc_conf_t, buf_size), NULL }, { ngx_string("iconv_filter"), NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, ngx_http_iconv_conf_handler, NGX_HTTP_LOC_CONF_OFFSET, 0, NULL }, ngx_null_command }; static ngx_http_module_t ngx_http_iconv_module_ctx = { ngx_http_iconv_filter_pre, /* preconfiguration */ ngx_http_iconv_filter_init, /* postconfiguration */ NULL, /* create main configuration */ NULL, /* init main configuration */ NULL, /* create server configuration */ NULL, /* merge server configuration */ ngx_http_iconv_create_loc_conf, /* create location configuration */ ngx_http_iconv_merge_loc_conf /* merge location configuration */ }; ngx_module_t ngx_http_iconv_module = { NGX_MODULE_V1, &ngx_http_iconv_module_ctx, /* module context */ ngx_http_iconv_commands, /* module directives */ NGX_HTTP_MODULE, /* module type */ NULL, /* init maseter */ NULL, /* init module */ NULL, /* init process */ NULL, /* init thread */ NULL, /* exit thread */ NULL, /* exit process */ NULL, /* exit master */ NGX_MODULE_V1_PADDING }; static ngx_http_output_header_filter_pt ngx_http_next_header_filter; static ngx_http_output_body_filter_pt ngx_http_next_body_filter; static ngx_int_t ngx_http_iconv_filter_pre(ngx_conf_t *cf) { ngx_http_iconv_filter_used = 0; return NGX_OK; } static ngx_int_t ngx_http_iconv_filter_init(ngx_conf_t *cf) { if (ngx_http_iconv_filter_used) { ngx_http_next_header_filter = ngx_http_top_header_filter; ngx_http_top_header_filter = ngx_http_iconv_header_filter; ngx_http_next_body_filter = ngx_http_top_body_filter; ngx_http_top_body_filter = ngx_http_iconv_body_filter; } return NGX_OK; } static ngx_int_t ngx_http_iconv_header_filter(ngx_http_request_t *r) { ngx_http_iconv_loc_conf_t *ilcf; ngx_http_iconv_ctx_t *ctx; ilcf = ngx_http_get_module_loc_conf(r, ngx_http_iconv_module); if (!ilcf->enabled) { return ngx_http_next_header_filter(r); } if (r->http_version < NGX_HTTP_VERSION_10) { ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, "iconv does not support HTTP < 1.0 yet"); return ngx_http_next_header_filter(r); } if (r->http_version == NGX_HTTP_VERSION_10) { r->keepalive = 0; } iconv_buf_size = ilcf->buf_size; r->filter_need_in_memory = 1; ngx_http_clear_content_length(r); ctx = ngx_http_get_module_ctx(r, ngx_http_iconv_module); if (ctx == NULL) { dd("create new context"); /* * set by ngx_pcalloc() * ctx->uc->len = 0 * ctx->uc->data = NULL */ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_iconv_module)); if (ctx == NULL) { return NGX_ERROR; } ngx_http_set_ctx(r, ctx, ngx_http_iconv_module); } return ngx_http_next_header_filter(r); } static ngx_int_t ngx_http_iconv_body_filter(ngx_http_request_t *r, ngx_chain_t *in) { ngx_chain_t *ncl, *nncl; ngx_http_iconv_ctx_t *ctx; ngx_int_t rc; ctx = ngx_http_get_module_ctx(r, ngx_http_iconv_module); if (ctx == NULL) { return ngx_http_next_body_filter(r, in); } if (in == NULL) { dd("XXX in is NULL"); return ngx_http_next_body_filter(r, in); } if (in->buf->last == in->buf->pos) { dd("pass 0 size buf to next body filter"); return ngx_http_next_body_filter(r, in); } dd("create new chain link"); if (ngx_http_iconv_merge_chain_link(r, ctx, in, &ncl) == NGX_ERROR) { return NGX_ERROR; } dd("discard previous chain link"); ngx_http_iconv_discard_body(in); dd("start to convert"); rc = ngx_http_iconv_filter_convert(r, ctx, ncl, &nncl); if (rc == NGX_ERROR) { dd("iconv convertion error"); return NGX_ERROR; } if (nncl == NULL) { dd ("nncl is NULL"); return NGX_OK; } dd("pass to next body filter->\n%.*s", (int) (ncl->buf->last - ncl->buf->pos), ncl->buf->pos); dd("nncl: len: %d, sync: %d, last_buf: %d, flush: %d, next: %p", (int) (nncl->buf->last - nncl->buf->pos), nncl->buf->sync, nncl->buf->last_buf, nncl->buf->flush, nncl->next); return ngx_http_next_body_filter(r, nncl); } static ngx_int_t ngx_http_iconv_merge_chain_link(ngx_http_request_t *r, ngx_http_iconv_ctx_t *ctx, ngx_chain_t *in, ngx_chain_t **out) { ngx_chain_t *cl, *ncl; ngx_buf_t *buf; size_t len = 0; for (cl = in; cl; cl = cl->next) { buf = cl->buf; len += buf->last - buf->pos; dd("len: %d", (int) len); dd("sync: %d, last_buf: %d, flush: %d, memory: %d, in-file: %d, " "temp: %d", (int) buf->sync, (int) buf->last_buf, (int) buf->flush, (int) buf->memory, (int) buf->in_file, (int) buf->temporary); } len += ctx->uc.len; /* requires C99 */ dd("XXX count buffer length: %zu", len); ncl = ngx_alloc_chain_link(r->pool); if (ncl == NULL) { return NGX_ERROR; } buf = ngx_create_temp_buf(r->pool, len); if (buf == NULL) { return NGX_ERROR; } ncl->buf
评论
    相关推荐
    • nginx
      nginx
    • NGINX
      伺服器NGINX ¿是es NGINX吗? 服务器/代理服务器反向代理协议,电子软件。 Nginx Plus的商业发行版已经发行。 ¿Que se diferencia con apache吗? 紧急情况下的一般使用情况,请按以下步骤操作。 豆蔻 El ...
    • nginx1.17
      nginx1.17,部署静态页面访问,支持前后端分离部署开发。
    • nginx安装包
      nginx安装包,用于liux环境下安装,nginx安装包,用于liux环境下安装,
    • nginx 1.5.0
      很不错的nginx,使用方便,而且很强大
    • NGINX
      NGINX DESCRIPCIÓN: 虚拟主机,NGINX和crearemos varios虚拟主机,可在以下区域使用: ÍNDICE: - - - 参考: 秘鲁学术交流会
    • nginx
      111111111111111111111
    • nginx1.9.4
      nginx安装包记录,留档防止误删找不到资源,nginx默认是不能访问root下面的文件夹的。
    • Nginx
      Nginx
    • nginx安装包
      nginx安装包含使用说明...............................