miniroon-header.c (1495B)
1 #include <skalibs/strerr.h> 2 3 #include "netstring.h" 4 #include "miniroon-header.h" 5 6 void set_header_version(miniroon_header *header, const bytebuffer source) { 7 if(strbbcmp(source, "capv0") == 0) { 8 header->version = V0; 9 } else { 10 strerr_dief1x(111, "Unhandled miniroon version"); 11 } 12 } 13 14 void set_header_action(miniroon_header *header, const bytebuffer source) { 15 if(strbbcmp(source, "revoke") == 0) { 16 header->action = REVOKE; 17 } else if(strbbcmp(source, "invoke") == 0) { 18 header->action = INVOKE; 19 } else if(strbbcmp(source, "invoke-once") == 0) { 20 header->action = INVOKE_ONCE; 21 } else { 22 strerr_dief1x(111, "Unhandled miniroon action"); 23 } 24 } 25 26 void parse_header(miniroon_header *header, const bytebuffer source) { 27 dbg_print_bb1("Got header", source); 28 netstring_chunk c; 29 netstring_chunk_init(&c, source); 30 31 if(!netstring_chunk_next(&c)) { 32 strerr_dief1x(111, "Mising version in miniroon header"); 33 } 34 dbg_print_bb1("Header > Version", c.inner); 35 set_header_version(header, c.inner); 36 37 if(!netstring_chunk_next(&c)) { 38 strerr_dief1x(111, "Mising ID in miniroon header"); 39 } 40 dbg_print_bb1("Header > ID", c.inner); 41 header->id = c.inner; 42 43 if(!netstring_chunk_next(&c)) { 44 strerr_dief1x(111, "Mising action in miniroon header"); 45 } 46 dbg_print_bb1("Header > Action", c.inner); 47 set_header_action(header, c.inner); 48 49 if(netstring_chunk_next(&c)) { 50 strerr_dief1x(111, "Extraneous data in miniroon header"); 51 } 52 53 } 54 55 /* vim: sts=2 sw=2 et 56 */