From: Miek Gieben Date: Tue, 9 Aug 2005 10:20:17 +0000 (+0000) Subject: cnversion stuff X-Git-Tag: release-1.0.0~344 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5ae617e66c0d9244aecf49703ff94bfb31eb7bbf;p=thirdparty%2Fldns.git cnversion stuff --- diff --git a/lua/lua-rns.c b/lua/lua-rns.c index 7b7d0771..0deaadc4 100644 --- a/lua/lua-rns.c +++ b/lua/lua-rns.c @@ -45,8 +45,8 @@ char *VERSION = "lua-rns 0.1"; void usage(FILE *f, char *progname) { - fprintf(f, "Synopsis: %s lua-file\n", progname); - fprintf(f, " Useless bunch of other options\n"); + fprintf(f, "Synopsis: %s lua-script\n", progname); + fprintf(f, " No options are defined (yet)\n"); } void @@ -169,12 +169,44 @@ l_pkt_print(lua_State *L) /* ============ - EXAMPLES + CONVERSION ============ */ +static int +l_pkt2string(lua_State *L) +{ + ldns_buffer *b; + luaL_Buffer lua_b; + ldns_pkt *p = (ldns_pkt *)lua_touserdata(L, 1); + + b = ldns_buffer_new(LDNS_MAX_PACKETLEN); + luaL_buffinit(L,&lua_b); + + if (ldns_pkt2buffer_wire(b, p) != LDNS_STATUS_OK) { + ldns_buffer_free(b); + return 0; + } + printf("how is this comming along %d\n", ldns_buffer_capacity(b)); + + /* this is a memcpy??? */ + luaL_addlstring(&lua_b, + ldns_buffer_begin(b), + ldns_buffer_capacity(b) + ); + /* I hope so */ + ldns_buffer_free(b); + + luaL_pushresult(&lua_b); + return 1; +} + +/* +============ + EXAMPLES +============ +*/ -/* Example test function which doesn't call ldns stuff yet */ static int l_average(lua_State *L) { @@ -214,6 +246,8 @@ register_ldns_functions(void) lua_register(L, "l_pkt_get_rr", l_pkt_get_rr); lua_register(L, "l_pkt_set_rr", l_pkt_set_rr); lua_register(L, "l_pkt_rr_count", l_pkt_rr_count); + /* CONVERSIONs */ + lua_register(L, "l_pkt2string", l_pkt2string); } int @@ -233,6 +267,7 @@ main(int argc, char *argv[]) lua_baselibopen(L); luaopen_math(L); luaopen_io(L); + luaopen_string(L); register_ldns_functions(); diff --git a/lua/rns-lib.lua b/lua/rns-lib.lua index cb31be5c..3099794e 100644 --- a/lua/rns-lib.lua +++ b/lua/rns-lib.lua @@ -7,7 +7,7 @@ LDNS_SECTION_ANY = 4 LDNS_SECTION_ANY_NOQUESTION = 5 -- dofile (filename) --- swap 2 rrs in a pkt -- +-- transpose 2 rrs in a pkt -- function lua_transpose_rr(pkt, n1, n2) print("[info] [RR] transpose", n1, n2) local rr_n1 = l_pkt_get_rr(pkt, n1) @@ -20,20 +20,35 @@ function lua_transpose_rr_random(pkt) local total = l_pkt_rr_count(pkt) - 1 local rn1 = math.random(0, total) local rn2 = math.random(0, total) - lua_swap_rr(pkt, rn1, rn2) + lua_transpose_rr(pkt, rn1, rn2) end --- substiture, add, remove +-- substitute, add, remove + +-- add an rr to the end of a pkt -- +function lua_add_rr(pkt, r) + print("[info] [RR] add", "end") + -- special case of insert ... +end + +-- remove an rr from the end of a pkt -- +function lua_remove_rr(pkt, n) + print("[info] [RR] remove", "end") +end + +-- convert a ldns_buffer to a string in lua +function lua_buf_to_string(buf) +end --------------------------------- --- these are more higher level -- +-- higher level -- --------------------------------- -- reverse all the rrs in a pkt -- function lua_reverse_pkt(pkt) local total = l_pkt_rr_count(pkt) - 1 for i=0, (total / 2) do - lua_swap_rr(pkt, i, total - i) + lua_transpose_rr(pkt, i, total - i) end end diff --git a/lua/rns.lua b/lua/rns.lua index 812ea796..ae57570f 100644 --- a/lua/rns.lua +++ b/lua/rns.lua @@ -19,7 +19,18 @@ lua_reverse_pkt(pkt) l_pkt_print(pkt) -- now do it at random -lua_swap_rr_random(pkt) +lua_transpose_rr_random(pkt) -- print again l_pkt_print(pkt) + + +print("Hallo en nu dan") + +spkt = l_pkt2string(pkt) + +len = string.len(spkt) + +print(len) + +print(spkt)