| 2743 | |
| 2744 | #ifdef notyet |
| 2745 | staticfn int |
| 2746 | hooked_open(lua_State *L) |
| 2747 | { |
| 2748 | const char *mode; |
| 2749 | static boolean never = TRUE; |
| 2750 | const char *filename; |
| 2751 | int params; |
| 2752 | int hot; |
| 2753 | |
| 2754 | if (never) { |
| 2755 | if (!start_luapat()) |
| 2756 | return NHL_SBRV_FAIL; |
| 2757 | never = FALSE; |
| 2758 | } |
| 2759 | filename = luaL_checkstring(L, 1); |
| 2760 | |
| 2761 | /* Unlike io.open, we want to treat mode as non-optional. */ |
| 2762 | if (lua_gettop(L) < 2) { |
| 2763 | lua_pushstring(L, "r"); |
| 2764 | } |
| 2765 | mode = luaL_optstring(L, 2, "r"); |
| 2766 | |
| 2767 | /* sandbox checks */ |
| 2768 | /* Do we need some ud from the calling state to let this be different for |
| 2769 | each call without redoing the HO table?? Maybe for version 2. XXX */ |
| 2770 | |
| 2771 | params = lua_gettop(L)-1; /* point at first param */ |
| 2772 | nhl_pushhooked_open_table(L); |
| 2773 | hot = lua_gettop(L); |
| 2774 | |
| 2775 | if (lua_type(L, hot) == LUA_TTABLE) { |
| 2776 | int idx; |
| 2777 | for (idx = 1; |
| 2778 | lua_pushinteger(L, idx), |
| 2779 | lua_geti(L, hot, idx), |
| 2780 | !lua_isnoneornil(L, -1); |
| 2781 | ++idx) { |
| 2782 | /* top of stack is our configtbl[idx] */ |
| 2783 | switch (lua_type(L, -1)) { |
| 2784 | /* lots of options to expand this with other types XXX */ |
| 2785 | case LUA_TTABLE: { |
| 2786 | int moderv, filerv; |
| 2787 | moderv = opencheckpat(L, "modepat", params+1); |
| 2788 | if (moderv == NHL_SBRV_FAIL) |
| 2789 | return moderv; |
| 2790 | filerv = opencheckpat(L, "filepat", params); |
| 2791 | if (filerv == NHL_SBRV_FAIL) |
| 2792 | return moderv; |
| 2793 | if (filerv == moderv) { |
| 2794 | if (filerv == NHL_SBRV_DENY) |
| 2795 | return NHL_SBRV_DENY; |
| 2796 | if (filerv == NHL_SBRV_ACCEPT) |
| 2797 | goto doopen; |
| 2798 | } |
| 2799 | break; /* try next entry */ |
| 2800 | } |
| 2801 | default: |
| 2802 | return NHL_SBRV_FAIL; |
nothing calls this directly
no test coverage detected