This function is ~1350 lines of code long and does multiple tasks:
- some missing validation of tokens found by zbx_token_find() (previously substitute_simple_macros() used to search macros all by itself!);
- gathers and caches data necessary to get macro values;
- handles all possible macro contexts and all supported macros;
- substitutes macros with values.
- cut down the size to 200-300 lines of code;
- move all necessary context + token type + macro validation to zbx_token_find() or other helper functions;
- store information about supported macros in easily manageable data structures instead of code logic;