# To Header Field Parser

Purpose of this parser is to parse body of To header field. The parser can be found in file `parse_to.c` under `parser` subdirectory.

Main function is `parse_to` but there is no need to call the function explicitly. Every time the parser finds a To header field, this function will be called automatically. Result of the parser is to_body structure. Pointer to the structure will be stored in parsed field of hdr_field structure. Since the pointer is `void*`, there is a convenience macro `get_to` in file `parse_to.h` that will do the necessary type-casting and will return pointer to to_body structure.

The parser itself is a finite state machine that will parse To body according to the grammar defined in RFC3261 and store result in to_body structure.

The parser gets called automatically from function `get_hdr_field` in file `msg_parser.c`. The function first creates and initializes an instance of to_body structure, then calls `parse_to` function with the structure as a parameter and if everything went OK, puts the pointer to the structure in parsed field of hdr_field structure representing the parsed To header field.

The newly created structure will be freed when the message is being destroyed, see function `clean_hdr_field` in file `hf.c` for more details.

See to_body for detailed description of the data structure produced by this parser.