Net::SIP::Endpoint::Context(3pm) | User Contributed Perl Documentation | Net::SIP::Endpoint::Context(3pm) |
Net::SIP::Endpoint::Context - Call context for endpoint
my $ctx = Net::SIP::Endpoint::Context->new( to => .., from => .. ); my $request = $ctx->new_request(..);
This package manages the call context (from,to,call-id, recorded routes..) for a call to an Net::SIP::Endpoint. It maintains the state of the current call (local and remote cseq, current state within INVITE transaction) and handles requests and responses according to this state.
And the following optional keys:
One special ARGS can be resp40x which should point to a 401/407 SIP response containing the offer from the server for authorization. This way authorization can be fully controlled, e.g. first trying w/o authorization and then retrying with authorization credentials and the 40x response.
METHOD might be already a Net::SIP::Request object in which case it will be used unmodified. BODY might be a string or object (see constructor of Net::SIP::Request).
It will add the request to the list of active transactions within the context $self, e.g. will be prepared to get responses for it. The callback for the transaction is copied from the default callback for the context, so that it stays the same, even if the default callback changes.
It returns the created request object.
FILTER might be used to restrict the search. With key request a Net::SIP::Request object is expected and it will restrict the search to this object (e.g. it will return the object if it is outstanding). With key method a method can be specified and only requests with this method will be returned.
For details on ERROR see set_callback.
TID is the transaction ID, see method tid in Net::SIP::Packet. ENDPOINT is the endpoint managing the context $self.
RESPONSE is the response packet, LEG the leg where the packet came in and FROM the "ip:port" of the sender. ENDPOINT is the endpoint managing the context $self.
First it checks if the response matches an active transaction (which begun its life in new_request) and if not it drops the response.
Then it checks if the response came in to the right leg, e.g. if the Via header of the packet matches the Via header the leg creates. If not the packet will be dropped.
Then it checks if the method in the CSeq header of the response matches the expected method in the transaction (for INVITEs this could be either INVITE or ACK, depending on the state of the transaction). If it not matches the packet will be dropped. (All of these packet drops could be observed if you enable debugging, see Net::SIP::Debug.
If the response is for a BYE or CANCEL request the call will be closed.
If the response is the unsuccessful final response for an INVITE an ACK will be send, if it's preliminary response it will invoke the callback for the transaction.
If the response is a successful final response for an INVITE it will save the routes from the Record-Route header for future requests and create an ACK request. The transaction callback will be invoked and gets as an additional argument the created ACK request, which then can be modified by the callback. The callback should not send the ACK request by itself, it should just modify the given request and sending will be done after the callback returned.
If the response is a successful final response to a request other then INVITE it will invoke callback which should fully handle the response.
If the response code is 401 (Unauthorized) or 407 (Proxy Authentication Required) and if the context has authorization info (key auth in the constructor)) it will try to authorize the request based on the realms given in the response and if it can find authorization info for at least parts of the required realms it will redeliver the request. Otherwise it will invoke the callback with an error of EPERM.
If the response code is 300 (Multiple Choices) or 301 (moved permanently) it will invoke the callback because it cannot resolve the issue automatically. But if it's 302 (Moved Temporarily) it will rewrite the request based on the Contact header in the response and redeliver it automatically.
If the response is 305 (Use Proxy) it will take the information from Contact as the upstream proxy and insert it into the routes, so that it will use it as the next hop. Then it rewrites the request for the new routes and redelivers it.
For all other responses the callback will be invoked, e.g the issue has to be resolved by the users application.
REQUEST is the request packet, LEG the leg where the packet came in and FROM the "ip:port" of the sender. ENDPOINT is the endpoint managing the context $self.
First it checks if the sequence number of the incoming request (CSeq header) is not lower then the sequence number of the last request received. Otherwise it will drop the request.
The it checks if the sequence number is the same as for the last request. If it is higher it must be a new request, otherwise it is a retransmit or an ACK or CANCEL to an INVITE request. If it's a retransmit it will be dropped.
If the incoming request is an INVITE it will automatically deliver a response "100 Trying" and then invoke the callback, so that the application might issue "180 Ringing" responses and finally a final response, like "200 Ok".
If the incoming request is CANCEL or BYE it will issue a response "200 Closing" and close the context.
All other requests must be handled by the application, e.g. the callback will be invoked.
2023-02-04 | perl v5.36.0 |