]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
cnversion stuff
authorMiek Gieben <miekg@NLnetLabs.nl>
Tue, 9 Aug 2005 10:20:17 +0000 (10:20 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Tue, 9 Aug 2005 10:20:17 +0000 (10:20 +0000)
lua/lua-rns.c
lua/rns-lib.lua
lua/rns.lua

index 7b7d07713978fd02287e19178ae5c7d3b70ed4fa..0deaadc4d15e3441c21fa760b936e215c0198b61 100644 (file)
@@ -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();
 
index cb31be5ccd23c730bc8635685d7cdbd3e7a49d00..3099794ee08501f05cece24d389ee2fa05776c01 100644 (file)
@@ -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
 
index 812ea796f408115adde28a8e0e6b00dd4d334f43..ae57570fb8a8e5ca16e642724ad5238d944c28b0 100644 (file)
@@ -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)