~singpolyma/cheogram

f4401d2033d7d3a165fcf70e8b8317185e13493d — Stephen Paul Weber 3 years ago d283db7
Allow calls from blocked caller id
2 files changed, 19 insertions(+), 2 deletions(-)

M Main.hs
M Util.hs
M Main.hs => Main.hs +2 -2
@@ 1246,11 1246,11 @@ mapToBackend backendHost (JID { jidNode = Nothing }) = parseJID backendHost
mapLocalpartToBackend backendHost localpart
	| Just ('+', tel) <- T.uncons localpart',
	  T.all isDigit tel = result
	| Just _ <- parsePhoneContext localpart = result
	| Just _ <- parsePhoneContext localpart' = result
	| otherwise = Nothing
	where
	-- Unescape local and strip any @suffix in case this is a tel-like SIP uri
	(localpart', _) = T.breakOn (s"@") $ unescapeJid localpart
	localpart' = sanitizeTelCandidate $ fst $ T.breakOn (s"@") $ unescapeJid localpart
	result = parseJID (localpart' ++ s"@" ++ backendHost)

localpartToURI localpart

M Util.hs => Util.hs +17 -0
@@ 67,6 67,23 @@ unescapeJid txt = fromString result
			("20", ' '), ("22", '"'), ("26", '&'), ("27", '\''), ("2f", '/'), ("3a", ':'), ("3c", '<'), ("3e", '>'), ("40", '@'), ("5c", '\\')
		]

-- To handle blocked callers, etc
sanitizeTelCandidate :: Text -> Text
sanitizeTelCandidate candidate
	| T.length candidate < 3 =
		s"13;phone-context=anonymous.phone-context.soprani.ca"
	| candidate == s"Restricted" =
		s"14;phone-context=anonymous.phone-context.soprani.ca"
	| candidate == s"anonymous" =
		s"15;phone-context=anonymous.phone-context.soprani.ca"
	| candidate == s"Anonymous" =
		s"16;phone-context=anonymous.phone-context.soprani.ca"
	| candidate == s"unavailable" =
		s"17;phone-context=anonymous.phone-context.soprani.ca"
	| candidate == s"Unavailable" =
		s"18;phone-context=anonymous.phone-context.soprani.ca"
	| otherwise = candidate

parsePhoneContext :: Text -> Maybe (Text, Text)
parsePhoneContext txt = hush $ Atto.parseOnly (
		(,) <$> Atto.takeWhile isDigit <* Atto.string (s";phone-context=") <*> Atto.takeTill (Atto.inClass " ;")