~singpolyma/cheogram-sip

Reply to all IQs as required by RFC
Import asterisk config changes from production
Handle Session Terminate When in Propose State

If a person calls us, we can make a proposal to have the phones ring.
But if they hang up, we're currently just sending them the session
terminate, when they don't actually have a session.

And so they ignore that, and the phone keeps ringing.

Similarly, if there are no resources online, the person on the other end
may hear it ring for a bit and then they'll stop for some reason.

Later, when the user comes back online, they'll be sent the messages
they missed while they were gone, including the session proposal, and
the phone will start to ring for them, no matter how long ago the phone
call was.

If they answer it, it'll be an error.
Not ideal, altogether.

Now, when the other side hangs up and we're still in the proposal state,
we retract the proposal, which means it will stop ringing in the online
case, and the user will know the phone call ended in the offline case.
Fix Hlint Suggestions

I basically just did what it asked me to, besides adjusting their
suggestions to our formatting.
Fix GHC Warnings

We have warnings turned on, so we may as well get to a clean base-state.
All of these type signatures came from the compiler's warning text
itself.
Similarly, the imports were listed as redundant.

Then there were a few name shadowings, mostly "s" and "init".

Finally, there were some unused variables from the pattern matches.
Update Base

The version of base specified isn't available on my system, so when I
updated it (and a few other libraries when they also errored) it now
seems to have built fine.

So it must be fine!
Use type=chat so that carbons will relay to all target resources

It turns out that the Carbons spec says you should only use carbons for "IM
like" things, such as messages of type=chat or with a body.  So there was a case
where if you had XEP0353-supporting clients connected but they had a lower
priority than other clients that were connected, the server would send those
clients the proposal message and carbons would not kick in and nothing would
ring.

So now we use type=chat. Even though it's not a chat, it's not in the context of
your chat, it's just an inbound phone call. But that's a moral question and in
practise this is also what Conversations does and it fixes the problem.

Thanks so much to psycotica0 for all of the investigation work that lead to this
fix.
Change Suggested Repo Name in README

Obviously the user can name their repo whatever they want, but I figured
we may as well suggest a more intuitive name ;)
Instead of crash on bad stanza, at least log it
Fallback to direct initiate when no Jingle Message Initation support

Check for a message initiation supporting resource, if none then send to the
most available resource.

TODO: Should only send to most available resource that supports jingle rtp audio.
Support inbound SIP MESSAGE
Log bad calls for fail2ban to find, fix default extensions
Use SIP From instead of raw SIPURI
Error payload is often last

Asterisk seems to care about the payload being <error/> and not just the
type="error", which is probably a bug in asterisk, but this whole thing is a
workaround for missing asterisk stuff so here we are.
Initial commit

This code is garbage and will have to be rewritten.

When paired with the Asterisk setup, inbound calls to sip:some%40jid@server.tld
end up as working Jingle calls (tested only with Conversations) to the target
JID.

Declining the call, hanging up, and errors from calling bad JIDs all are handled.