Merge pull request #563 from cshore/pull-request-app-uhttpd
[project/luci.git] / libs / luci-lib-nixio / src / nixio.h
1 #ifndef NIXIO_H_
2 #define NIXIO_H_
3
4 #define NIXIO_OOM "out of memory"
5
6 #define NIXIO_META "nixio.socket"
7 #define NIXIO_FILE_META "nixio.file"
8 #define NIXIO_GLOB_META "nixio.glob"
9 #define NIXIO_DIR_META "nixio.dir"
10 #define _FILE_OFFSET_BITS 64
11
12 #define NIXIO_PUSH_CONSTANT(x) \
13         lua_pushinteger(L, x); \
14         lua_setfield(L, -2, #x);
15
16 /* uClibc: broken as always */
17 #define _LARGEFILE_SOURCE
18
19 #include <lua.h>
20 #include <lualib.h>
21 #include <lauxlib.h>
22 #include <luaconf.h>
23
24 #define NIXIO_BUFFERSIZE 8192
25
26 typedef struct nixio_socket {
27         int fd;
28         int domain;
29         int type;
30         int protocol;
31 } nixio_sock;
32
33 typedef struct nixio_address {
34         int family;
35         char host[128];
36         int port;
37         int prefix;
38 } nixio_addr;
39
40 int nixio__perror(lua_State *L);
41 int nixio__pstatus(lua_State *L, int condition);
42
43 #if defined(LUA_NUMBER_DOUBLE) || defined(LNUM_DOUBLE) || defined(LNUM_LDOUBLE)
44 #define NIXIO_DOUBLE 1
45 #define nixio__checknumber luaL_checknumber
46 #define nixio__pushnumber  lua_pushnumber
47 #define nixio__optnumber   luaL_optnumber
48 #else
49 #define nixio__checknumber luaL_checkinteger
50 #define nixio__pushnumber  lua_pushinteger
51 #define nixio__optnumber   luaL_optinteger
52 #endif
53
54
55 #ifndef __WINNT__
56
57 #define NIXIO_API extern
58
59 #include <sys/types.h>
60 #include <sys/socket.h>
61 #include <arpa/inet.h>
62 #include <netinet/in.h>
63 #include <netinet/tcp.h>
64 #include <sys/un.h>
65 #include <netdb.h>
66 #include <poll.h>
67 #include <sys/stat.h>
68 #include <errno.h>
69
70 #define NIXIO_SEP "/"
71 #define NIXIO_PATHSEP ":"
72
73 #define nixio__perror_s nixio__perror
74 #define nixio__pstatus_s nixio__pstatus
75
76 int nixio__check_group(lua_State *L, int idx);
77 int nixio__check_user(lua_State *L, int idx);
78
79 typedef struct stat nixio_stat_t;
80
81 #else /* __WINNT__ */
82
83 #define NIXIO_API extern __declspec(dllexport)
84 #define NIXIO_SEP "\\"
85 #define NIXIO_PATHSEP ";"
86 #include "mingw-compat.h"
87
88 typedef struct _stati64 nixio_stat_t;
89
90 #endif
91
92 nixio_sock* nixio__checksock(lua_State *L);
93 int nixio__checksockfd(lua_State *L);
94 int nixio__checkfd(lua_State *L, int ud);
95 int nixio__tofd(lua_State *L, int ud);
96 int nixio__nulliter(lua_State *L);
97
98 int nixio__addr_parse(nixio_addr *addr, struct sockaddr *saddr);
99 int nixio__addr_write(nixio_addr *addr, struct sockaddr *saddr);
100
101 int nixio__check_mode(lua_State *L, int idx, int def);
102 int nixio__mode_write(int mode, char *modestr);
103
104 int nixio__push_stat(lua_State *L, nixio_stat_t *buf);
105
106 const char nixio__bin2hex[16];
107
108 /* Module functions */
109 void nixio_open_file(lua_State *L);
110 void nixio_open_socket(lua_State *L);
111 void nixio_open_sockopt(lua_State *L);
112 void nixio_open_bind(lua_State *L);
113 void nixio_open_address(lua_State *L);
114 void nixio_open_protoent(lua_State *L);
115 void nixio_open_poll(lua_State *L);
116 void nixio_open_io(lua_State *L);
117 void nixio_open_splice(lua_State *L);
118 void nixio_open_process(lua_State *L);
119 void nixio_open_syslog(lua_State *L);
120 void nixio_open_bit(lua_State *L);
121 void nixio_open_bin(lua_State *L);
122 void nixio_open_fs(lua_State *L);
123 void nixio_open_user(lua_State *L);
124
125 #ifndef NO_TLS
126 void nixio_open_tls_crypto(lua_State *L);
127 void nixio_open_tls_context(lua_State *L);
128 void nixio_open_tls_socket(lua_State *L);
129 #endif
130
131 /* Method functions */
132
133 #endif /* NIXIO_H_ */