const HParsedToken* act_wks(const HParseResult *p) { dns_rr_wks_t *wks = H_ALLOC(dns_rr_wks_t); wks->address = H_FIELD_UINT(0); wks->protocol = H_FIELD_UINT(1); wks->len = H_FIELD_SEQ(2)->used; wks->bit_map = h_arena_malloc(p->arena, sizeof(uint8_t)*wks->len); for (size_t i=0; i<wks->len; ++i) wks->bit_map[i] = H_INDEX_UINT(p->ast, 2, i); return H_MAKE(dns_rr_wks_t, wks); }
static HParsedToken *act_segment(const HParseResult *p, void *user) { DNP3_Segment *s = H_ALLOC(DNP3_Segment); s->fin = H_FIELD_UINT(0, 0); s->fir = H_FIELD_UINT(0, 1); s->seq = H_FIELD_UINT(0, 2); HCountedArray *a = H_FIELD_SEQ(1); s->len = a->used; s->payload = h_arena_malloc(p->arena, s->len); assert(s->payload != NULL); for(size_t i=0; i<s->len; i++) { s->payload[i] = H_CAST_UINT(a->elements[i]); } return H_MAKE(DNP3_Segment, s); }
const HParsedToken *act_base64(const HParseResult *p) { assert(p->ast->token_type == TT_SEQUENCE); assert(p->ast->seq->used == 2); assert(p->ast->seq->elements[0]->token_type == TT_SEQUENCE); HParsedToken *res = H_MAKE_SEQ(); // concatenate base64_3 blocks HCountedArray *seq = H_FIELD_SEQ(0); for(size_t i=0; i<seq->used; i++) h_seq_append(res, seq->elements[i]); // append one trailing base64_2 or _1 block const HParsedToken *tok = h_seq_index(p->ast, 1); if(tok->token_type == TT_SEQUENCE) h_seq_append(res, tok); return res; }