/* Copyright (C) agentzh */
#ifndef DDEBUG
#define DDEBUG 0
#endif
#include "ddebug.h"
#include "ngx_http_drizzle_module.h"
#include "ngx_http_drizzle_upstream.h"
#include "ngx_http_drizzle_keepalive.h"
#include "ngx_http_drizzle_processor.h"
#include "ngx_http_drizzle_util.h"
enum {
ngx_http_drizzle_default_port = 3306
};
static void ngx_http_upstream_drizzle_cleanup(void *data);
static ngx_int_t ngx_http_upstream_drizzle_init(ngx_conf_t *cf,
ngx_http_upstream_srv_conf_t *uscf);
static ngx_int_t ngx_http_upstream_drizzle_init_peer(ngx_http_request_t *r,
ngx_http_upstream_srv_conf_t *uscf);
static ngx_int_t ngx_http_upstream_drizzle_get_peer(ngx_peer_connection_t *pc,
void *data);
static void ngx_http_upstream_drizzle_free_peer(ngx_peer_connection_t *pc,
void *data, ngx_uint_t state);
/* just a work-around to override the default u->output_filter */
static ngx_int_t ngx_http_drizzle_output_filter(void *data, ngx_chain_t *in);
void *
ngx_http_upstream_drizzle_create_srv_conf(ngx_conf_t *cf)
{
ngx_pool_cleanup_t *cln;
ngx_http_upstream_drizzle_srv_conf_t *conf;
dd("drizzle create srv conf");
conf = ngx_pcalloc(cf->pool,
sizeof(ngx_http_upstream_drizzle_srv_conf_t));
if (conf == NULL) {
return NULL;
}
/* set by ngx_pcalloc:
* conf->peers = NULL
* conf->current = 0
* conf->servers = NULL
* conf->single = 0
* conf->max_cached = 0
* conf->overflow = 0 (drizzle_keepalive_overflow_ignore)
*/
conf->pool = cf->pool;
cln = ngx_pool_cleanup_add(cf->pool, 0);
(void) drizzle_create(&conf->drizzle);
cln->handler = ngx_http_upstream_drizzle_cleanup;
cln->data = &conf->drizzle;
drizzle_add_options(&conf->drizzle, DRIZZLE_NON_BLOCKING);
/* we use 0 timeout for the underlying poll event model
* used by libdrizzle itself. */
drizzle_set_timeout(&conf->drizzle, 0);
return conf;
}
/* mostly based on ngx_http_upstream_server in
* ngx_http_upstream.c of nginx 0.8.30.
* Copyright (C) Igor Sysoev */
char *
ngx_http_upstream_drizzle_server(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf)
{
ngx_http_upstream_drizzle_srv_conf_t *dscf = conf;
ngx_http_upstream_drizzle_server_t *ds;
ngx_str_t *value;
ngx_url_t u;
ngx_uint_t i, j;
ngx_http_upstream_srv_conf_t *uscf;
ngx_str_t protocol;
ngx_str_t charset;
u_char *p;
size_t len;
dd("entered drizzle_server directive handler...");
uscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_upstream_module);
if (dscf->servers == NULL) {
dscf->servers = ngx_array_create(cf->pool, 4,
sizeof(ngx_http_upstream_drizzle_server_t));
if (dscf->servers == NULL) {
return NGX_CONF_ERROR;
}
uscf->servers = dscf->servers;
}
ds = ngx_array_push(dscf->servers);
if (ds == NULL) {
return NGX_CONF_ERROR;
}
ngx_memzero(ds, sizeof(ngx_http_upstream_drizzle_server_t));
value = cf->args->elts;
/* parse the first name:port argument */
ngx_memzero(&u, sizeof(ngx_url_t));
u.url = value[1];
u.default_port = ngx_http_drizzle_default_port;
if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
if (u.err) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"drizzle: %s in upstream \"%V\"", u.err, &u.url);
}
return NGX_CONF_ERROR;
}
ds->addrs = u.addrs;
ds->naddrs = u.naddrs;
ds->port = u.port;
ds->protocol = ngx_http_drizzle_protocol;
/* parse various options */
for (i = 2; i < cf->args->nelts; i++) {
if (ngx_strncmp(value[i].data, "dbname=", sizeof("dbname=") - 1)
== 0)
{
ds->dbname.len = value[i].len - (sizeof("dbname=") - 1);
if (ds->dbname.len >= DRIZZLE_MAX_DB_SIZE) {
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
"drizzle: \"dbname\" value too large in upstream \"%V\""
" (at most %d bytes)",
dscf->peers->name,
(int) DRIZZLE_MAX_DB_SIZE);
return NGX_CONF_ERROR;
}
ds->dbname.data = &value[i].data[sizeof("dbname=") - 1];
continue;
}
if (ngx_strncmp(value[i].data, "user=", sizeof("user=") - 1)
== 0)
{
ds->user.len = value[i].len - (sizeof("user=") - 1);
if (ds->user.len >= DRIZZLE_MAX_USER_SIZE) {
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
"drizzle: \"user\" value too large in upstream \"%V\""
" (at most %d bytes)",
dscf->peers->name,
(int) DRIZZLE_MAX_USER_SIZE);
return NGX_CONF_ERROR;
}
ds->user.data = &value[i].data[sizeof("user=") - 1];
continue;
}
if (ngx_strncmp(value[i].data, "password=", sizeof("password=") - 1)
== 0)
{
ds->password.len = value[i].len - (sizeof("password=") - 1);
if (ds->password.len >= DRIZZLE_MAX_PASSWORD_SIZE) {
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
"drizzle: \"password\" value too large in upstream "
"\"%V\" (at most %d bytes)",
dscf->peers->name,
(int) DRIZZLE_MAX_PASSWORD_SIZE);
return NGX_CONF_ERROR;
}
ds->password.data = &value[i].data[sizeof("password=") - 1];
continue;
}
if (ngx_strncmp(value[i].data, "protocol=", sizeof("protocol=") - 1)
== 0)
{
protocol.len = value[i].len - (sizeof("protocol=") - 1);
protocol.data = &value[i].data[sizeof("protocol=") - 1];
switch (protocol.len) {
case 5:
if (ngx_http_drizzle_strcmp_const(protocol.data, "mysql") == 0)
{
ds->protocol = ngx_http_mysql_protocol;
} else {
continue;
}
break;
case 7:
if (ngx_http_drizzle_strcmp_const(protocol.data,
"drizzle") != 0)
{
continue;
}
break;
default:
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"drizzle: invalid protocol \"%V\""
" in drizzle_server", &protocol);
return NGX_CONF_ERROR;
}
continue;
}
if (ngx_strncmp(value[i].data, "charset=", sizeof("charset=") - 1)
== 0)
{
charset.len = value[i].len - (sizeof("charset=") - 1);
charset.data = &value[i].data[sizeof("charset=") - 1];
dd("charset: %.*s", (int) charset.len, charset.data);
if (charset.len == 0) {
continue;
}
for (j = 0; j < charset.len; j++) {
if (charset.data[j] == '\'') {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"bad charste value \"%V\" in"
" drizzle_server", &charset);
return NGX_CONF_ERROR;
}
}
len = sizeof("set names ''") - 1 + charset.len;
p = ngx_palloc(cf->pool, len);
if (p == NUL
没有合适的资源?快使用搜索试试~ 我知道了~
drizzle-nginx-module-master.zip_drizzle_keepalive_nginx_nginx my
共47个文件
t:14个
h:11个
c:9个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 104 浏览量
2022-09-24
20:44:48
上传
评论
收藏 90KB ZIP 举报
温馨提示
nginx第三方插件,用于连接mysql数据库,提升nginx连接mysql的性能,
资源推荐
资源详情
资源评论
收起资源包目录
drizzle-nginx-module-master.zip (47个子文件)
drizzle-nginx-module-master
config 3KB
valgrind.suppress 5KB
t
000_init.t 2KB
methods.t 10KB
timeout.t 4KB
bugs.t 1KB
status.t 7KB
errors.t 3KB
sanity.t 11KB
keepalive.t 12KB
charset
000_init.t 2KB
methods.t 10KB
timeout.t 2KB
errors.t 4KB
sanity.t 12KB
keepalive.t 11KB
README.markdown 32KB
src
ngx_http_drizzle_keepalive.h 2KB
ngx_http_drizzle_upstream.c 28KB
ngx_http_drizzle_processor.h 465B
ngx_http_drizzle_quoting.h 904B
ngx_http_drizzle_module.h 2KB
ngx_http_drizzle_util.h 1KB
ngx_http_drizzle_handler.h 535B
resty_dbd_stream.h 2KB
ngx_http_drizzle_processor.c 15KB
ngx_http_drizzle_util.c 26KB
ngx_http_drizzle_keepalive.c 11KB
ngx_http_drizzle_module.c 16KB
ngx_http_drizzle_quoting.c 975B
ngx_http_drizzle_checker.c 794B
ngx_http_drizzle_checker.h 573B
ddebug.h 3KB
ngx_http_drizzle_handler.c 18KB
ngx_http_drizzle_output.h 678B
ngx_http_drizzle_output.c 20KB
ngx_http_drizzle_upstream.h 4KB
README 29KB
doc
design 765B
HttpDrizzleModule.wiki 29KB
.gitignore 620B
util
wiki2pod.pl 3KB
ngx-links 1KB
update-readme.sh 98B
ctags 157B
build.sh 1KB
Changes 2KB
共 47 条
- 1
资源评论
weixin_42651887
- 粉丝: 76
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功