mirror of https://github.com/alibaba/tengine.git

7 changed files with 2735 additions and 4 deletions
-
11auto/modules
-
8auto/options
-
10auto/sources
-
23src/http/modules/ngx_http_dyups.h
-
88src/http/modules/ngx_http_dyups_lua.c
-
19src/http/modules/ngx_http_dyups_lua.h
-
2580src/http/modules/ngx_http_dyups_module.c
@ -0,0 +1,23 @@ |
|||
/* |
|||
* Copyright (C) 2010-2014 Alibaba Group Holding Limited |
|||
*/ |
|||
|
|||
|
|||
#ifndef _NGX_HTTP_DYUPS_H_INCLUDE_ |
|||
#define _NGX_HTTP_DYUPS_H_INCLUDE_ |
|||
|
|||
|
|||
#include <ngx_config.h> |
|||
#include <ngx_core.h> |
|||
|
|||
|
|||
ngx_int_t ngx_dyups_update_upstream(ngx_str_t *name, ngx_buf_t *buf, |
|||
ngx_str_t *rv); |
|||
|
|||
ngx_int_t ngx_dyups_delete_upstream(ngx_str_t *name, ngx_str_t *rv); |
|||
|
|||
|
|||
extern ngx_flag_t ngx_http_dyups_api_enable; |
|||
|
|||
|
|||
#endif |
@ -0,0 +1,88 @@ |
|||
/* |
|||
* Copyright (C) 2010-2014 Alibaba Group Holding Limited |
|||
*/ |
|||
|
|||
|
|||
#include <ngx_http.h> |
|||
#include <ngx_http_dyups.h> |
|||
#include <ngx_http_dyups_lua.h> |
|||
|
|||
|
|||
static int ngx_http_dyups_lua_register(lua_State *L); |
|||
static int ngx_http_lua_update_upstream(lua_State *L); |
|||
static int ngx_http_lua_delete_upstream(lua_State *L); |
|||
|
|||
|
|||
static int |
|||
ngx_http_lua_update_upstream(lua_State *L) |
|||
{ |
|||
size_t size; |
|||
ngx_int_t status; |
|||
ngx_str_t name, rv; |
|||
ngx_buf_t buf; |
|||
|
|||
if (lua_gettop(L) != 2) { |
|||
return luaL_error(L, "exactly 2 arguments expected"); |
|||
} |
|||
|
|||
name.data = (u_char *) luaL_checklstring(L, 1, &name.len); |
|||
buf.pos = buf.start = (u_char *) luaL_checklstring(L, 2, &size); |
|||
buf.last = buf.end = buf.pos + size; |
|||
|
|||
status = ngx_dyups_update_upstream(&name, &buf, &rv); |
|||
|
|||
lua_pushinteger(L, (lua_Integer) status); |
|||
lua_pushlstring(L, (char *) rv.data, rv.len); |
|||
|
|||
return 2; |
|||
} |
|||
|
|||
|
|||
static int |
|||
ngx_http_lua_delete_upstream(lua_State *L) |
|||
{ |
|||
ngx_int_t status; |
|||
ngx_str_t name, rv; |
|||
|
|||
if (lua_gettop(L) != 1) { |
|||
return luaL_error(L, "exactly 1 argument expected"); |
|||
} |
|||
|
|||
name.data = (u_char *) luaL_checklstring(L, 1, &name.len); |
|||
|
|||
status = ngx_dyups_delete_upstream(&name, &rv); |
|||
|
|||
lua_pushinteger(L, (lua_Integer) status); |
|||
lua_pushlstring(L, (char *) rv.data, rv.len); |
|||
|
|||
return 2; |
|||
} |
|||
|
|||
|
|||
static int |
|||
ngx_http_dyups_lua_register(lua_State *L) |
|||
{ |
|||
lua_createtable(L, 0, 1); |
|||
|
|||
lua_pushcfunction(L, ngx_http_lua_update_upstream); |
|||
lua_setfield(L, -2, "update"); |
|||
|
|||
lua_pushcfunction(L, ngx_http_lua_delete_upstream); |
|||
lua_setfield(L, -2, "delete"); |
|||
|
|||
return 1; |
|||
} |
|||
|
|||
|
|||
ngx_int_t |
|||
ngx_http_dyups_lua_preload(ngx_conf_t *cf) |
|||
{ |
|||
if (ngx_http_lua_add_package_preload(cf, "ngx.dyups", |
|||
ngx_http_dyups_lua_register) |
|||
!= NGX_OK) |
|||
{ |
|||
return NGX_ERROR; |
|||
} |
|||
|
|||
return NGX_OK; |
|||
} |
@ -0,0 +1,19 @@ |
|||
/* |
|||
* Copyright (C) 2010-2014 Alibaba Group Holding Limited |
|||
*/ |
|||
|
|||
|
|||
#ifndef _NGX_HTTP_DYUPS_LUA_H_INCLUDE_ |
|||
#define _NGX_HTTP_DYUPS_LUA_H_INCLUDE_ |
|||
|
|||
#include <ngx_config.h> |
|||
#include <ngx_core.h> |
|||
#include <ngx_http_lua_api.h> |
|||
#include <lualib.h> |
|||
#include <lauxlib.h> |
|||
|
|||
|
|||
ngx_int_t ngx_http_dyups_lua_preload(ngx_conf_t *cf); |
|||
|
|||
|
|||
#endif |
2580
src/http/modules/ngx_http_dyups_module.c
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue