INNER CODE UNIT · Python
parse_sip_headers
arnonym/ha-plugins · ha-sip/src/account.py:157
def parse_sip_headers(whole_msg: str, header_names: List[str]) -> Dict[str, Optional[str]]:
result: Dict[str, Optional[str]] = {name: None for name in header_names}
for line in whole_msg.split('\r\n'):
if not line.strip():
break # End of headers
for name in header_names:
if line.lower().startswith(name.lower() + ':'):
result[name] = line.split(':', 1)[1].strip()
return result
@staticmethod
def log_all_sip_headers(account_index: int, whole_msg: str) -> None:
log(account_index, 'Available SIP headers:')
for line in whole_msg.split('\r\n'):
if not line.strip():
break # End of headers
if ':' in line:
name, value = line.split(':', 1)