static int lua_proto_get_eof_packet (lua_State *L) { size_t packet_len; const char *packet_str = luaL_checklstring(L, 1, &packet_len); network_mysqld_eof_packet_t *eof_packet; network_packet packet; GString s; int err = 0; s.str = (char *)packet_str; s.len = packet_len; packet.data = &s; packet.offset = 0; eof_packet = network_mysqld_eof_packet_new(); err = err || network_mysqld_proto_get_eof_packet(&packet, eof_packet); if (err) { network_mysqld_eof_packet_free(eof_packet); luaL_error(L, "%s: network_mysqld_proto_get_eof_packet() failed", G_STRLOC); return 0; } lua_newtable(L); LUA_EXPORT_INT(eof_packet, server_status); LUA_EXPORT_INT(eof_packet, warnings); network_mysqld_eof_packet_free(eof_packet); return 1; }
static int lua_sigar_netif_get_info(lua_State *L) { lua_sigar_netif_t *netif = (lua_sigar_netif_t *)luaL_checkudata(L, 1, "sigar_netif"); int err; const char *if_name = netif->netifs->netifs.data[netif->ndx]; sigar_net_interface_config_t usage; if (SIGAR_OK != (err = sigar_net_interface_config_get(netif->netifs->sigar, if_name, &usage))) { lua_pushnil(L); lua_pushstring(L, strerror(err)); return 2; } lua_newtable(L); #define DATA \ (&(usage)) LUA_EXPORT_STR(DATA, name); LUA_EXPORT_STR(DATA, type); LUA_EXPORT_ADDRESS(DATA, hwaddr); LUA_EXPORT_ADDRESS(DATA, address); LUA_EXPORT_ADDRESS(DATA, destination); LUA_EXPORT_ADDRESS(DATA, broadcast); LUA_EXPORT_ADDRESS(DATA, netmask); LUA_EXPORT_INT(DATA, flags); LUA_EXPORT_INT(DATA, mtu); LUA_EXPORT_INT(DATA, metric); #undef DATA return 1; }
/** * transform the OK packet of a COM_STMT_PREPARE result into a table */ static int lua_proto_get_stmt_prepare_ok_packet (lua_State *L) { size_t packet_len; const char *packet_str = luaL_checklstring(L, 1, &packet_len); network_mysqld_stmt_prepare_ok_packet_t *cmd; network_packet packet; GString s; int err = 0; s.str = (char *)packet_str; s.len = packet_len; packet.data = &s; packet.offset = 0; cmd = network_mysqld_stmt_prepare_ok_packet_new(); err = err || network_mysqld_proto_get_stmt_prepare_ok_packet(&packet, cmd); if (err) { network_mysqld_stmt_prepare_ok_packet_free(cmd); luaL_error(L, "%s: network_mysqld_proto_get_stmt_prepare_ok_packet() failed", G_STRLOC); return 0; } lua_newtable(L); LUA_EXPORT_INT(cmd, stmt_id); LUA_EXPORT_INT(cmd, num_columns); LUA_EXPORT_INT(cmd, num_params); LUA_EXPORT_INT(cmd, warnings); network_mysqld_stmt_prepare_ok_packet_free(cmd); return 1; }
int lua_sigar_swap_get(lua_State *L) { sigar_t *s = *(sigar_t **)luaL_checkudata(L, 1, "sigar"); sigar_swap_t swap; sigar_swap_get(s, &swap); lua_newtable(L); #define DATA \ (&(swap)) LUA_EXPORT_INT(DATA, total); LUA_EXPORT_INT(DATA, used); LUA_EXPORT_INT(DATA, free); LUA_EXPORT_INT(DATA, page_in); LUA_EXPORT_INT(DATA, page_out); #undef DATA return 1; }
static int lua_proto_get_response_packet (lua_State *L) { size_t packet_len; const char *packet_str = luaL_checklstring(L, 1, &packet_len); guint32 server_capabilities = luaL_checkint(L, 2); network_mysqld_auth_response *auth_response; network_packet packet; GString s; int err = 0; s.str = (char *)packet_str; s.len = packet_len; packet.data = &s; packet.offset = 0; auth_response = network_mysqld_auth_response_new(server_capabilities); err = err || network_mysqld_proto_get_auth_response(&packet, auth_response); if (err) { network_mysqld_auth_response_free(auth_response); luaL_error(L, "%s: network_mysqld_proto_get_auth_response() failed", G_STRLOC); return 0; } lua_newtable(L); LUA_EXPORT_INT_TO(auth_response, client_capabilities, "capabilities"); LUA_EXPORT_INT(auth_response, server_capabilities); LUA_EXPORT_INT(auth_response, max_packet_size); LUA_EXPORT_INT(auth_response, charset); LUA_EXPORT_STR(auth_response, username); LUA_EXPORT_STR_TO(auth_response, auth_plugin_data, "response"); LUA_EXPORT_STR(auth_response, auth_plugin_name); LUA_EXPORT_STR(auth_response, database); network_mysqld_auth_response_free(auth_response); return 1; }
static int lua_proto_get_masterinfo_string (lua_State *L) { size_t packet_len; const char *packet_str = luaL_checklstring(L, 1, &packet_len); network_mysqld_masterinfo_t *info; network_packet packet; GString s; int err = 0; s.str = (char *)packet_str; s.len = packet_len; packet.data = &s; packet.offset = 0; info = network_mysqld_masterinfo_new(); err = err || network_mysqld_masterinfo_get(&packet, info); if (err) { network_mysqld_masterinfo_free(info); luaL_error(L, "%s: network_mysqld_masterinfo_get() failed", G_STRLOC); return 0; } lua_newtable(L); LUA_EXPORT_INT(info, master_lines); LUA_EXPORT_STR(info, master_log_file); LUA_EXPORT_INT(info, master_log_pos); LUA_EXPORT_STR(info, master_host); LUA_EXPORT_STR(info, master_user); LUA_EXPORT_STR(info, master_password); LUA_EXPORT_INT(info, master_port); LUA_EXPORT_INT(info, master_connect_retry); LUA_EXPORT_INT(info, master_ssl); LUA_EXPORT_STR(info, master_ssl_ca); LUA_EXPORT_STR(info, master_ssl_capath); LUA_EXPORT_STR(info, master_ssl_cert); LUA_EXPORT_STR(info, master_ssl_cipher); LUA_EXPORT_STR(info, master_ssl_key); if (info->master_lines >= 15) { LUA_EXPORT_INT(info, master_ssl_verify_server_cert); } network_mysqld_masterinfo_free(info); return 1; }
static int lua_sigar_who_get_who(lua_State *L) { lua_sigar_who_t *who = (lua_sigar_who_t *)luaL_checkudata(L, 1, "sigar_who"); int ndx = luaL_checkint(L, 2); if (ndx - 1 < 0 || ndx - 1 >= who->who.number) { luaL_error(L, ".who[%d] out of range: 1..%d", ndx, who->who.number); } lua_newtable(L); #define DATA \ (&(who->who.data[ndx - 1])) LUA_EXPORT_STR(DATA, user); LUA_EXPORT_STR(DATA, device); LUA_EXPORT_STR(DATA, host); LUA_EXPORT_INT(DATA, time); #undef DATA return 1; }
static int lua_proto_get_challenge_packet (lua_State *L) { size_t packet_len; const char *packet_str = luaL_checklstring(L, 1, &packet_len); network_mysqld_auth_challenge *auth_challenge; network_packet packet; GString s; int err = 0; s.str = (char *)packet_str; s.len = packet_len; packet.data = &s; packet.offset = 0; auth_challenge = network_mysqld_auth_challenge_new(); err = err || network_mysqld_proto_get_auth_challenge(&packet, auth_challenge); if (err) { network_mysqld_auth_challenge_free(auth_challenge); luaL_error(L, "%s: network_mysqld_proto_get_auth_challenge() failed", G_STRLOC); return 0; } lua_newtable(L); LUA_EXPORT_INT(auth_challenge, protocol_version); LUA_EXPORT_INT(auth_challenge, server_version); LUA_EXPORT_INT(auth_challenge, thread_id); LUA_EXPORT_INT(auth_challenge, capabilities); LUA_EXPORT_INT(auth_challenge, charset); LUA_EXPORT_INT(auth_challenge, server_status); LUA_EXPORT_STR_TO(auth_challenge, auth_plugin_data, "challenge"); LUA_EXPORT_STR(auth_challenge, auth_plugin_name); network_mysqld_auth_challenge_free(auth_challenge); return 1; }
int lua_sigar_mem_get(lua_State *L) { sigar_t *s = *(sigar_t **)luaL_checkudata(L, 1, "sigar"); sigar_mem_t mem; sigar_mem_get(s, &mem); lua_newtable(L); #define DATA \ (&(mem)) LUA_EXPORT_INT(DATA, ram); LUA_EXPORT_INT(DATA, total); LUA_EXPORT_INT(DATA, used); LUA_EXPORT_INT(DATA, free); LUA_EXPORT_INT(DATA, actual_used); LUA_EXPORT_INT(DATA, actual_free); LUA_EXPORT_DOUBLE(DATA, used_percent); LUA_EXPORT_DOUBLE(DATA, free_percent); #undef DATA return 1; }
static int lua_sigar_netif_get_usage(lua_State *L) { lua_sigar_netif_t *netif = (lua_sigar_netif_t *)luaL_checkudata(L, 1, "sigar_netif"); int err; const char *if_name = netif->netifs->netifs.data[netif->ndx]; sigar_net_interface_stat_t usage; if (SIGAR_OK != (err = sigar_net_interface_stat_get(netif->netifs->sigar, if_name, &usage))) { lua_pushnil(L); lua_pushstring(L, strerror(err)); return 2; } lua_newtable(L); #define DATA \ (&(usage)) LUA_EXPORT_INT(DATA, rx_packets); LUA_EXPORT_INT(DATA, rx_bytes); LUA_EXPORT_INT(DATA, rx_errors); LUA_EXPORT_INT(DATA, rx_overruns); LUA_EXPORT_INT(DATA, rx_dropped); LUA_EXPORT_INT(DATA, rx_frame); LUA_EXPORT_INT(DATA, tx_packets); LUA_EXPORT_INT(DATA, tx_bytes); LUA_EXPORT_INT(DATA, tx_errors); LUA_EXPORT_INT(DATA, tx_overruns); LUA_EXPORT_INT(DATA, tx_dropped); LUA_EXPORT_INT(DATA, tx_collisions); LUA_EXPORT_INT(DATA, tx_carrier); LUA_EXPORT_INT(DATA, speed); #undef DATA return 1; }
/** * get the stmt-id from the com-stmt-execute packet */ static int lua_proto_get_stmt_execute_packet (lua_State *L) { size_t packet_len; const char *packet_str = luaL_checklstring(L, 1, &packet_len); int param_count = luaL_checkint(L, 2); network_mysqld_stmt_execute_packet_t *cmd; network_packet packet; GString s; int err = 0; s.str = (char *)packet_str; s.len = packet_len; packet.data = &s; packet.offset = 0; cmd = network_mysqld_stmt_execute_packet_new(); err = err || network_mysqld_proto_get_stmt_execute_packet(&packet, cmd, param_count); if (err) { network_mysqld_stmt_execute_packet_free(cmd); luaL_error(L, "%s: network_mysqld_proto_get_stmt_execute_packet() failed", G_STRLOC); return 0; } lua_newtable(L); LUA_EXPORT_INT(cmd, stmt_id); LUA_EXPORT_INT(cmd, flags); LUA_EXPORT_INT(cmd, iteration_count); LUA_EXPORT_BOOL(cmd, new_params_bound); if (cmd->new_params_bound) { guint i; lua_newtable(L); for (i = 0; i < cmd->params->len; i++) { network_mysqld_type_t *param = g_ptr_array_index(cmd->params, i); lua_newtable(L); lua_pushnumber(L, param->type); lua_setfield(L, -2, "type"); if (param->is_null) { lua_pushnil(L); } else { const char *const_s; char *_s; gsize s_len; guint64 _i; gboolean is_unsigned; double d; switch (param->type) { case MYSQL_TYPE_BLOB: case MYSQL_TYPE_MEDIUM_BLOB: case MYSQL_TYPE_LONG_BLOB: case MYSQL_TYPE_STRING: case MYSQL_TYPE_VARCHAR: case MYSQL_TYPE_VAR_STRING: if (0 != network_mysqld_type_get_string_const(param, &const_s, &s_len)) { return luaL_error(L, "%s: _get_string_const() failed for type = %d", G_STRLOC, param->type); } lua_pushlstring(L, const_s, s_len); break; case MYSQL_TYPE_TINY: case MYSQL_TYPE_SHORT: case MYSQL_TYPE_LONG: case MYSQL_TYPE_LONGLONG: if (0 != network_mysqld_type_get_int(param, &_i, &is_unsigned)) { return luaL_error(L, "%s: _get_int() failed for type = %d", G_STRLOC, param->type); } lua_pushinteger(L, _i); break; case MYSQL_TYPE_DOUBLE: case MYSQL_TYPE_FLOAT: if (0 != network_mysqld_type_get_double(param, &d)) { return luaL_error(L, "%s: _get_double() failed for type = %d", G_STRLOC, param->type); } lua_pushnumber(L, d); break; case MYSQL_TYPE_DATETIME: case MYSQL_TYPE_TIMESTAMP: case MYSQL_TYPE_DATE: case MYSQL_TYPE_TIME: _s = NULL; s_len = 0; if (0 != network_mysqld_type_get_string(param, &_s, &s_len)) { return luaL_error(L, "%s: _get_string() failed for type = %d", G_STRLOC, param->type); } lua_pushlstring(L, _s, s_len); if (NULL != _s) g_free(_s); break; default: luaL_error(L, "%s: can't decode type %d yet", G_STRLOC, param->type); /* we don't have that value yet */ break; } } lua_setfield(L, -2, "value"); lua_rawseti(L, -2, i + 1); } lua_setfield(L, -2, "params"); } network_mysqld_stmt_execute_packet_free(cmd); return 1; }