}
ptr = (guint8 *)&ip->data;
for (i = 1; i <= max; i ++, ptr ++) {
- lua_pushnumber (L, i);
lua_pushnumber (L, *ptr);
- lua_settable (L, -3);
+ lua_rawseti (L, -2, i);
}
}
else {
struct rspamd_lua_ip *ip = lua_check_ip (L, 1);
int max, i;
guint8 *ptr;
- char numbuf[4];
+ char numbuf[8];
if (ip != NULL) {
lua_newtable (L);
}
ptr = (guint8 *)&ip->data;
for (i = 1; i <= max; i ++, ptr ++) {
- rspamd_snprintf (numbuf, sizeof (numbuf), "%d", *ptr);
- lua_pushnumber (L, i);
- lua_pushstring (L, numbuf);
- lua_settable (L, -3);
+ if (ip->af == AF_INET) {
+ rspamd_snprintf (numbuf, sizeof (numbuf), "%d", *ptr);
+ lua_pushstring (L, numbuf);
+ lua_rawseti (L, -2, i);
+ }
+ else {
+ rspamd_snprintf (numbuf, sizeof (numbuf), "%xd", (*ptr & 0xf0) >> 4);
+ lua_pushstring (L, numbuf);
+ lua_rawseti (L, -2, i*2 - 1);
+ rspamd_snprintf (numbuf, sizeof (numbuf), "%xd", *ptr & 0x0f);
+ lua_pushstring (L, numbuf);
+ lua_rawseti (L, -2, i*2);
+ }
}
}
else {
ptr = (guint8 *)&ip->data;
ptr += max - 1;
for (i = 1; i <= max; i ++, ptr --) {
- rspamd_snprintf (numbuf, sizeof (numbuf), "%d", *ptr);
- lua_pushnumber (L, i);
- lua_pushstring (L, numbuf);
- lua_settable (L, -3);
+ if (ip->af == AF_INET) {
+ rspamd_snprintf (numbuf, sizeof (numbuf), "%d", *ptr);
+ lua_pushstring (L, numbuf);
+ lua_rawseti (L, -2, i);
+ }
+ else {
+ rspamd_snprintf (numbuf, sizeof (numbuf), "%xd", *ptr & 0x0f);
+ lua_pushstring (L, numbuf);
+ lua_rawseti (L, -2, i*2 - 1);
+ rspamd_snprintf (numbuf, sizeof (numbuf), "%xd", (*ptr & 0xf0) >> 4);
+ lua_pushstring (L, numbuf);
+ lua_rawseti (L, -2, i*2);
+ }
}
}
else {
lua_rawset (L, -3);
luaL_register (L, NULL, iplib_m);
- luaL_register (L, "ip", iplib_f);
+ luaL_register (L, "rspamd_ip", iplib_f);
lua_pop (L, 1); /* remove metatable from stack */