Note that this document was written before implementing the actual decompression API; there are some subtle differences between what is set out here and what has been actually implemented.


New Decompression API


This document describes the names and arguments to the functions which will implement the new decompression API.


decomp_get_dlabel(js_string *compressed, int compressed_offset)


Uncompress a dlabel from a compressed string, generating a js_string object which will store the decompressed dlabel


Input


compressed: The compressed string

compressed_offset: The offset from the beginning of the string where the compressed dlabel begins


Output


The output of this function is a newly created js_string object which contains the decompressed dlabel.  If there was any problem decompressing the dlabel in question, this routine will return a 0.


decomp_append_dlabel(js_string *compressed, js_string *uncompressed, int compressed_offset);


Get a dlabel from the compressed string, appending the uncompressed dlabel to the uncompressed string.


Input


compressed: The compressed string

uncompressed: The partially decompressed string

compressed_offset: Where in the string to look (0 is the top of the string, 1 is the second byte of the string, etc.)


Output


The length of the decompressed dlabel; JS_ERROR if there was an error decompressing



decomp_get_rddata(js_string *compressed, js_string *uncompressed, int compressed_offset, int type, int rdlength)


Get the rddata from the compressed string, decompressing any dlabels as needed, and append the data to the uncompressed string.


Input


compressed: The compressed string

uncompressed: The partially decompressed string

compressed_offset: Where in the string to look (0 is the top of the string, 1 is the second byte of the string, etc.)

type: The type of resource record (1 for A, 2 for NS, etc.)

rdlength: The rdlength this resource record should have


Output


JS_ERROR on error, JS_SUCCESS if there was no problem processing (decompressing as needed)


Increase offset by rdlength after running this.



decomp_get_type_etc(js_string *compressed, js_string *uncompressed, int compressed_offset)


Get the resource record type (and some other data) from the compressed string, and copy the data over to the uncompressed string.


Input


compressed: The compressed string

uncompressed: The partially decompressed string

compressed_offset: Where in the string to look (0 is the top of the string, 1 is the second byte of the string, etc.)


Output


JS_ERROR on error;  RR type (0-65536) on success


Increase offset by eight bytes after running this.



decomp_get_rdlength(js_string *compressed, js_string *uncompressed, int compressed_offset)


Get the resource record rdlength from the compressed string, and copy the data over to the uncompressed string.


Input


compressed: The compressed string

uncompressed: The partially decompressed string

compressed_offset: Where in the string to look (0 is the top of the string, 1 is the second byte of the string, etc.)


Output


JS_ERROR on error, RDLENGTH (0-65536) on success


decomp_get_header(js_string *compressed, js_string *uncompressed)


Get the 12 byte header for a DNS packet; making sure that qdcount (bytes 5 and 6 in big endian format) is 0 or one; and that there are no answers if qdcount is 0.


Input


compressed: The compressed string

uncompressed: The empty uncompressed string (returns error if string is not empty)


Output


The total number of answers; -2 if there are no questions and no answers; JS_ERROR (-1) on error



decomp_get_question(js_string *compressed, js_string *uncompressed)


Get the question from the DNS packet; it is assumed that the question starts on the 13th byte.

Note that this routine does not attempt to decompress the dlabel; it makes no sense to do so.


Input


compressed: The compressed string

uncompressed:  The compressed string with only 12 bytes in it (returns error if string does not have 12 bytes)


Output


The length of the question; JS_ERROR on fatal error parsing question.



decomp_init(int log_level)


Initialize the decompression code; set up the RRs, and set the log_level global variable in the decompression code.