1 /*
2 ** Lua binding: fcdb
3 */
4 
5 #include "tolua.h"
6 
7 #ifndef __cplusplus
8 #include <stdlib.h>
9 #endif
10 #ifdef __cplusplus
11  extern "C" int tolua_bnd_takeownership (lua_State* L); // from tolua_map.c
12 #else
13  int tolua_bnd_takeownership (lua_State* L); /* from tolua_map.c */
14 #endif
15 #include <string.h>
16 
17 /* Exported function */
18 TOLUA_API int tolua_fcdb_open (lua_State* tolua_S);
19 LUALIB_API int luaopen_fcdb (lua_State* tolua_S);
20 
21 #ifdef HAVE_CONFIG_H
22 #include <fc_config.h>
23 #endif
24 #include "luascript_types.h"
25 #include "api_fcdb_auth.h"
26 #include "api_fcdb_base.h"
27 #include "script_fcdb.h"
28 
29 /* function to register type */
tolua_reg_types(lua_State * tolua_S)30 static void tolua_reg_types (lua_State* tolua_S)
31 {
32  tolua_usertype(tolua_S,"Connection");
33 }
34 
35 /* function: api_auth_get_username */
tolua_fcdb_auth_get_username00(lua_State * tolua_S)36 static int tolua_fcdb_auth_get_username00(lua_State* tolua_S)
37 {
38 #ifndef TOLUA_RELEASE
39  tolua_Error tolua_err;
40  if (
41  !tolua_isusertype(tolua_S,1,"Connection",0,&tolua_err) ||
42  !tolua_isnoobj(tolua_S,2,&tolua_err)
43  )
44  goto tolua_lerror;
45  else
46 #endif
47  {
48   lua_State* L =  tolua_S;
49   Connection* pconn = ((Connection*)  tolua_tousertype(tolua_S,1,0));
50  {
51   const char* tolua_ret = (const char*)  api_auth_get_username(L,pconn);
52  tolua_pushstring(tolua_S,(const char*)tolua_ret);
53  }
54  }
55  return 1;
56 #ifndef TOLUA_RELEASE
57  tolua_lerror:
58  tolua_error(tolua_S,"#ferror in function 'get_username'.",&tolua_err);
59  return 0;
60 #endif
61 }
62 
63 /* function: api_auth_get_ipaddr */
tolua_fcdb_auth_get_ipaddr00(lua_State * tolua_S)64 static int tolua_fcdb_auth_get_ipaddr00(lua_State* tolua_S)
65 {
66 #ifndef TOLUA_RELEASE
67  tolua_Error tolua_err;
68  if (
69  !tolua_isusertype(tolua_S,1,"Connection",0,&tolua_err) ||
70  !tolua_isnoobj(tolua_S,2,&tolua_err)
71  )
72  goto tolua_lerror;
73  else
74 #endif
75  {
76   lua_State* L =  tolua_S;
77   Connection* pconn = ((Connection*)  tolua_tousertype(tolua_S,1,0));
78  {
79   const char* tolua_ret = (const char*)  api_auth_get_ipaddr(L,pconn);
80  tolua_pushstring(tolua_S,(const char*)tolua_ret);
81  }
82  }
83  return 1;
84 #ifndef TOLUA_RELEASE
85  tolua_lerror:
86  tolua_error(tolua_S,"#ferror in function 'get_ipaddr'.",&tolua_err);
87  return 0;
88 #endif
89 }
90 
91 /* function: api_auth_set_password */
tolua_fcdb_auth_set_password00(lua_State * tolua_S)92 static int tolua_fcdb_auth_set_password00(lua_State* tolua_S)
93 {
94 #ifndef TOLUA_RELEASE
95  tolua_Error tolua_err;
96  if (
97  !tolua_isusertype(tolua_S,1,"Connection",0,&tolua_err) ||
98  !tolua_isstring(tolua_S,2,0,&tolua_err) ||
99  !tolua_isnoobj(tolua_S,3,&tolua_err)
100  )
101  goto tolua_lerror;
102  else
103 #endif
104  {
105   lua_State* L =  tolua_S;
106   Connection* pconn = ((Connection*)  tolua_tousertype(tolua_S,1,0));
107   const char* password = ((const char*)  tolua_tostring(tolua_S,2,0));
108  {
109   bool tolua_ret = (bool)  api_auth_set_password(L,pconn,password);
110  tolua_pushboolean(tolua_S,(bool)tolua_ret);
111  }
112  }
113  return 1;
114 #ifndef TOLUA_RELEASE
115  tolua_lerror:
116  tolua_error(tolua_S,"#ferror in function 'set_password'.",&tolua_err);
117  return 0;
118 #endif
119 }
120 
121 /* function: api_auth_get_password */
tolua_fcdb_auth_get_password00(lua_State * tolua_S)122 static int tolua_fcdb_auth_get_password00(lua_State* tolua_S)
123 {
124 #ifndef TOLUA_RELEASE
125  tolua_Error tolua_err;
126  if (
127  !tolua_isusertype(tolua_S,1,"Connection",0,&tolua_err) ||
128  !tolua_isnoobj(tolua_S,2,&tolua_err)
129  )
130  goto tolua_lerror;
131  else
132 #endif
133  {
134   lua_State* L =  tolua_S;
135   Connection* pconn = ((Connection*)  tolua_tousertype(tolua_S,1,0));
136  {
137   const char* tolua_ret = (const char*)  api_auth_get_password(L,pconn);
138  tolua_pushstring(tolua_S,(const char*)tolua_ret);
139  }
140  }
141  return 1;
142 #ifndef TOLUA_RELEASE
143  tolua_lerror:
144  tolua_error(tolua_S,"#ferror in function 'get_password'.",&tolua_err);
145  return 0;
146 #endif
147 }
148 
149 /* function: api_fcdb_option */
tolua_fcdb_fcdb_option00(lua_State * tolua_S)150 static int tolua_fcdb_fcdb_option00(lua_State* tolua_S)
151 {
152 #ifndef TOLUA_RELEASE
153  tolua_Error tolua_err;
154  if (
155  !tolua_isstring(tolua_S,1,0,&tolua_err) ||
156  !tolua_isnoobj(tolua_S,2,&tolua_err)
157  )
158  goto tolua_lerror;
159  else
160 #endif
161  {
162   lua_State* L =  tolua_S;
163   const char* name = ((const char*)  tolua_tostring(tolua_S,1,0));
164  {
165   const char* tolua_ret = (const char*)  api_fcdb_option(L,name);
166  tolua_pushstring(tolua_S,(const char*)tolua_ret);
167  }
168  }
169  return 1;
170 #ifndef TOLUA_RELEASE
171  tolua_lerror:
172  tolua_error(tolua_S,"#ferror in function 'option'.",&tolua_err);
173  return 0;
174 #endif
175 }
176 
177 /* Open lib function */
luaopen_fcdb(lua_State * tolua_S)178 LUALIB_API int luaopen_fcdb (lua_State* tolua_S)
179 {
180  tolua_open(tolua_S);
181  tolua_reg_types(tolua_S);
182  tolua_module(tolua_S,NULL,0);
183  tolua_beginmodule(tolua_S,NULL);
184  tolua_module(tolua_S,"auth",0);
185  tolua_beginmodule(tolua_S,"auth");
186  tolua_function(tolua_S,"get_username",tolua_fcdb_auth_get_username00);
187  tolua_function(tolua_S,"get_ipaddr",tolua_fcdb_auth_get_ipaddr00);
188  tolua_function(tolua_S,"set_password",tolua_fcdb_auth_set_password00);
189  tolua_function(tolua_S,"get_password",tolua_fcdb_auth_get_password00);
190  tolua_endmodule(tolua_S);
191  tolua_module(tolua_S,"fcdb",0);
192  tolua_beginmodule(tolua_S,"fcdb");
193  tolua_module(tolua_S,"status",0);
194  tolua_beginmodule(tolua_S,"status");
195  tolua_constant(tolua_S,"ERROR",FCDB_ERROR);
196  tolua_constant(tolua_S,"TRUE",FCDB_SUCCESS_TRUE);
197  tolua_constant(tolua_S,"FALSE",FCDB_SUCCESS_FALSE);
198  tolua_endmodule(tolua_S);
199  tolua_function(tolua_S,"option",tolua_fcdb_fcdb_option00);
200  tolua_endmodule(tolua_S);
201 
202  { /* begin embedded lua code */
203  static unsigned char B[] = {
204   10,102, 99,100, 98, 91, 34,112, 97,114, 97,109, 34, 93, 32,
205   61, 32,123, 10, 72, 79, 83, 84, 32, 61, 32, 34,104,111,115,
206  116, 34, 44, 10, 85, 83, 69, 82, 32, 61, 32, 34,117,115,101,
207  114, 34, 44, 10, 80, 79, 82, 84, 32, 61, 32, 34,112,111,114,
208  116, 34, 44, 10, 80, 65, 83, 83, 87, 79, 82, 68, 32, 61, 32,
209   34,112, 97,115,115,119,111,114,100, 34, 44, 10, 68, 65, 84,
210   65, 66, 65, 83, 69, 32, 61, 32, 34,100, 97,116, 97, 98, 97,
211  115,101, 34, 44, 10, 84, 65, 66, 76, 69, 95, 85, 83, 69, 82,
212   32, 61, 32, 34,116, 97, 98,108,101, 95,117,115,101,114, 34,
213   44, 10, 84, 65, 66, 76, 69, 95, 76, 79, 71, 32, 61, 32, 34,
214  116, 97, 98,108,101, 95,108,111,103, 34, 44, 10, 66, 65, 67,
215   75, 69, 78, 68, 32, 61, 32, 34, 98, 97, 99,107,101,110,100,
216   34, 10,125,32
217  };
218  if (luaL_loadbuffer(tolua_S,(char*)B,sizeof(B),"tolua: embedded Lua code") == LUA_OK)
219  lua_pcall(tolua_S,0,LUA_MULTRET,0);
220  } /* end of embedded lua code */
221 
222  tolua_endmodule(tolua_S);
223  return 1;
224 }
225 /* Open tolua function */
tolua_fcdb_open(lua_State * tolua_S)226 TOLUA_API int tolua_fcdb_open (lua_State* tolua_S)
227 {
228  lua_pushcfunction(tolua_S, luaopen_fcdb);
229  lua_pushstring(tolua_S, "fcdb");
230  lua_call(tolua_S, 1, 0);
231  return 1;
232 }
233