I am currently looking at the call flow in asterisk when a sip message reaches the client.
1. The i/o callback generates a sip request (struct sip_request) and then calls the handle_request_do function
2. The handle request function calls tje find_call function
3. The find call function find a call corresponding to the request with the help of callid
4. If the find call function cannot find the correspond call, it will check if the call can be created (Only some type of sip requests can create a call. For example, A 'BYE' cannot create a call)
5. If a call can be created, the same will be created.
6. If a call is found/created, the corresponding private structure is returned to the callee