8caa5b969895f979d70d3cb1a4be44f6d56a0b35
[project/luci.git] / libs / 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
23 #define NIXIO_BUFFERSIZE 8192
24
25 typedef struct nixio_socket {
26         int fd;
27         int domain;
28         int type;
29         int protocol;
30 } nixio_sock;
31
32 typedef struct nixio_address {
33         int family;
34         char host[128];
35         int port;
36 } nixio_addr;
37
38 int nixio__perror(lua_State *L);
39 int nixio__pstatus(lua_State *L, int condition);
40
41 #ifndef __WINNT__
42
43 #define NIXIO_API extern
44
45 #include <sys/types.h>
46 #include <sys/socket.h>
47 #include <arpa/inet.h>
48 #include <netinet/in.h>
49 #include <netinet/tcp.h>
50 #include <net/if.h>
51 #include <sys/un.h>
52 #include <netdb.h>
53 #include <poll.h>
54 #include <sys/stat.h>
55 #include <errno.h>
56
57 #define NIXIO_SEP "/"
58 #define NIXIO_PATHSEP ":"
59
60 #define nixio__perror_s nixio__perror
61 #define nixio__pstatus_s nixio__pstatus
62
63 int nixio__check_group(lua_State *L, int idx);
64 int nixio__check_user(lua_State *L, int idx);
65
66 typedef struct stat nixio_stat_t;
67
68 #else /* __WINNT__ */
69
70 #define NIXIO_API extern __declspec(dllexport)
71 #define NIXIO_SEP "\\"
72 #define NIXIO_PATHSEP ";"
73 #include "mingw-compat.h"
74
75 typedef struct _stati64 nixio_stat_t;
76
77 #endif
78
79 nixio_sock* nixio__checksock(lua_State *L);
80 int nixio__checksockfd(lua_State *L);
81 int nixio__checkfd(lua_State *L, int ud);
82 int nixio__tofd(lua_State *L, int ud);
83 int nixio__nulliter(lua_State *L);
84
85 int nixio__addr_parse(nixio_addr *addr, struct sockaddr *saddr);
86 int nixio__addr_write(nixio_addr *addr, struct sockaddr *saddr);
87
88 int nixio__check_mode(lua_State *L, int idx, int def);
89 int nixio__mode_write(int mode, char *modestr);
90
91 int nixio__push_stat(lua_State *L, nixio_stat_t *buf);
92
93 /* Module functions */
94 void nixio_open_file(lua_State *L);
95 void nixio_open_socket(lua_State *L);
96 void nixio_open_sockopt(lua_State *L);
97 void nixio_open_bind(lua_State *L);
98 void nixio_open_address(lua_State *L);
99 void nixio_open_poll(lua_State *L);
100 void nixio_open_io(lua_State *L);
101 void nixio_open_splice(lua_State *L);
102 void nixio_open_process(lua_State *L);
103 void nixio_open_syslog(lua_State *L);
104 void nixio_open_bit(lua_State *L);
105 void nixio_open_bin(lua_State *L);
106 void nixio_open_fs(lua_State *L);
107 void nixio_open_user(lua_State *L);
108 void nixio_open_tls_crypto(lua_State *L);
109 void nixio_open_tls_context(lua_State *L);
110 void nixio_open_tls_socket(lua_State *L);
111
112 /* Method functions */
113
114 #endif /* NIXIO_H_ */