-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
新增 url 规格化(与原项目不同,不会自动添加协议) 新增特殊域名支持(如 '工业和信息化部.中国') 新增安装脚本(然而部署并没有变简单多少)
- Loading branch information
1 parent
c274c98
commit fbb10dc
Showing
8 changed files
with
901 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#/bin/sh | ||
BASE=$(dirname $(readlink -f ${0})) | ||
cp "${BASE}/ourl/config.sample.lua" "${BASE}/ourl/config.lua" | ||
cd "${BASE}/lib/hashids" && make | ||
cd "${BASE}/lib/idna" && make linux | ||
mv "${BASE}/lib/idna/idna.so" "${BASE}" | ||
cd ${BASE} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# This Makefile is based on lua-zlib's Makefile. Thanks to the lua-zlib developers. | ||
# Inform the location to intall the modules | ||
PREFIX ?= /usr/local/openresty | ||
LUAPATH ?= $(PREFIX)/lualib | ||
LUACPATH ?= $(PREFIX)/lualib | ||
INCDIR ?= -I$(PREFIX)/luajit/include/luajit-2.1 | ||
LIBDIR ?= -L$(PREFIX)/luajit/lib | ||
|
||
# For Mac OS X: set the system version | ||
MACOSX_VERSION = 10.4 | ||
|
||
CMOD = idna.so | ||
OBJS = idna.o | ||
|
||
LIBS = -lidn -lluajit-5.1 | ||
WARN = -Wall -pedantic | ||
|
||
BSD_CFLAGS = -O2 -fPIC $(WARN) $(INCDIR) $(DEFS) | ||
BSD_LDFLAGS = -O -shared -fPIC $(LIBDIR) | ||
|
||
LNX_CFLAGS = -O2 -fPIC $(WARN) $(INCDIR) $(DEFS) | ||
LNX_LDFLAGS = -O -shared -fPIC $(LIBDIR) | ||
|
||
MAC_ENV = env MACOSX_DEPLOYMENT_TARGET='$(MACVER)' | ||
MAC_CFLAGS = -O2 -fPIC -fno-common $(WARN) $(INCDIR) $(DEFS) | ||
MAC_LDFLAGS = -bundle -undefined dynamic_lookup -fPIC $(LIBDIR) | ||
|
||
CC = gcc | ||
LD = $(MYENV) gcc | ||
CFLAGS = $(MYCFLAGS) | ||
LDFLAGS = $(MYLDFLAGS) | ||
|
||
.PHONY: all clean install none linux bsd macosx | ||
|
||
all: | ||
@echo "Usage: $(MAKE) <platform>" | ||
@echo " * linux" | ||
@echo " * bsd" | ||
@echo " * macosx" | ||
|
||
install: $(CMOD) | ||
cp $(CMOD) $(LUACPATH) | ||
|
||
uninstall: | ||
rm $(LUACPATH)/$(CMOD) | ||
|
||
linux: | ||
@$(MAKE) $(CMOD) MYCFLAGS="$(LNX_CFLAGS)" MYLDFLAGS="$(LNX_LDFLAGS)" INCDIR="$(INCDIR)" LIBDIR="$(LIBDIR)" DEFS="$(DEFS)" | ||
|
||
bsd: | ||
@$(MAKE) $(CMOD) MYCFLAGS="$(BSD_CFLAGS)" MYLDFLAGS="$(BSD_LDFLAGS)" INCDIR="$(INCDIR)" LIBDIR="$(LIBDIR)" DEFS="$(DEFS)" | ||
|
||
macosx: | ||
@$(MAKE) $(CMOD) MYCFLAGS="$(MAC_CFLAGS)" MYLDFLAGS="$(MAC_LDFLAGS)" MYENV="$(MAC_ENV)" INCDIR="$(INCDIR)" LIBDIR="$(LIBDIR)" DEFS="$(DEFS)" | ||
|
||
clean: | ||
rm -f $(OBJS) $(CMOD) | ||
|
||
.c.o: | ||
$(CC) -c $(CFLAGS) $(DEFS) $(INCDIR) -o $@ $< | ||
|
||
$(CMOD): $(OBJS) | ||
$(LD) $(LDFLAGS) $(LIBDIR) $(OBJS) $(LIBS) -o $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright 2014 Masatoshi Teruya. All rights reserved. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
* | ||
* idna.c | ||
* lua-idna | ||
* | ||
* Created by Masatoshi Teruya on 14/12/06. | ||
* | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <lua.h> | ||
#include <lauxlib.h> | ||
#include <stringprep.h> | ||
#include <idna.h> | ||
|
||
#define lstate_fn2tbl(L,k,v) do{ \ | ||
lua_pushstring(L,k); \ | ||
lua_pushcfunction(L,v); \ | ||
lua_rawset(L,-3); \ | ||
}while(0) | ||
|
||
#define pdealloc(p) free((void*)p) | ||
|
||
static int encode_lua( lua_State *L ) | ||
{ | ||
const char *src = luaL_checkstring( L, 1 ); | ||
char *dest = NULL; | ||
int rc = idna_to_ascii_8z( src, &dest, 0 ); | ||
|
||
if( rc == IDNA_SUCCESS ){ | ||
lua_pushstring( L, dest ); | ||
pdealloc( dest ); | ||
return 1; | ||
} | ||
|
||
// got error | ||
lua_pushnil( L ); | ||
lua_pushstring( L, idna_strerror( rc ) ); | ||
|
||
return 2; | ||
} | ||
|
||
|
||
static int decode_lua( lua_State *L ) | ||
{ | ||
const char *src = luaL_checkstring( L, 1 ); | ||
char *dest = NULL; | ||
int rc = idna_to_unicode_8z8z( src, &dest, 0 ); | ||
|
||
if( rc == IDNA_SUCCESS ){ | ||
lua_pushstring( L, dest ); | ||
pdealloc( dest ); | ||
return 1; | ||
} | ||
|
||
// got error | ||
lua_pushnil( L ); | ||
lua_pushstring( L, idna_strerror( rc ) ); | ||
|
||
return 2; | ||
} | ||
|
||
|
||
LUALIB_API int luaopen_idna( lua_State *L ) | ||
{ | ||
lua_createtable( L, 0, 2 ); | ||
lstate_fn2tbl( L, "encode", encode_lua ); | ||
lstate_fn2tbl( L, "decode", decode_lua ); | ||
|
||
return 1; | ||
} | ||
|
||
|
Oops, something went wrong.