Net::S...Request(3pm)

๐Ÿ’– Net::S...Request โ€” aka the SIP request wrangler ๐Ÿ’–

okay so bestie, this is Net::SIP::Request, a lil User Contributed Perl Documentation moment. It's the class you reach for when you've got SIP request packets and you need to, like, do stuff with them. ๐ŸŽ€


โœจ NAME โœจ

Net::SIP::Request โ€” handling SIP request packets. that's the whole vibe. requests. handled. ๐Ÿ’…


๐ŸŒธ SYNOPSIS ๐ŸŒธ

my $req = Net::SIP::Request->new( 'INVITE',... );
my $ack = $req->create_ack();

literally two lines and you're already out here making ACKs. iconic. ๐Ÿ‘‘


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

So Net::SIP::Request is a subclass of Net::SIP::Packet โ€” like, it inherited the whole Packet family's genetics and then got its own extra personality. ๐Ÿงฌ

What's it bring to the table? Methods to:

  • create responses to requests ๐Ÿ’Œ
  • authorize requests ๐Ÿ”

that's it, that's the job. no cap.


๐Ÿ”ฅ EXAMPLES ๐Ÿ”ฅ

okay this is the part where it all clicks, so pay attention bestie:

# create INVITE request
my $invite = Net::SIP::Request->new(
      'INVITE', 'sip:you@example.com',
      { from => ..., to => ... },
      Net::SIP::SDP->new( ... )
);

# somehow send request and retrieve response $resp
...
if ( $resp->code eq '401' or $resp->code eq '407' ) {
      # need to authorize request
      $invite->authorize( $resp, [ username, password ] );

      # somehow send again and retrieve response $resp
      ...
}

if ( $resp->code ~m{^[2345]\d\d} ) {
      # got final response, send ACK
      my $ack = $invite->create_ack( $resp );

      # somehow send $ack
      ...
}

so you build the INVITE, you send it (the ... is you, doing the sending, no judgment ๐Ÿ™ˆ), and then:

  • got a 401 or 407? that's the server being like "authorize first pls" โ€” hit it with authorize and try again ๐Ÿ’ช
  • got a final response matching ^[2345]\d\d? slay, that's final โ€” build your ACK with create_ack and yeet it back. โœ…

๐ŸŽ€ CONSTRUCTOR ๐ŸŽ€

Inherited from Net::SIP::Packet. See there. ๐Ÿ‘€ (it's not keeping secrets, it's just literally the parent's constructor)


๐Ÿ’… METHODS ๐Ÿ’…

  • method โ€” gets you the method of the request. like, which one is it. the method. that one. ๐Ÿ“ฎ
  • uri โ€” gets you the URI part of the request. ๐Ÿ—บ๏ธ
  • set_uri ( STRING ) โ€” sets the URI of the request to STRING. boom, changed. โœจ
  • set_cseq ( NUMBER ) โ€” sets the sequence number of the "CSeq" header to NUMBER. (yes the original says "if", we all know it means "of", moving on ๐Ÿซถ)
  • create_ack ( RESPONSE ) โ€” returns a Net::SIP::Request object for an ACK request, for that specific situation where Net::SIP::Response RESPONSE was the reply you got for packet $self. it's giving "okay noted, acknowledging." ๐Ÿ“ฌ
  • create_cancel โ€” returns a Net::SIP::Request object that cancels the request in $self. the โœ‹ "actually, never mind" of SIP.
  • create_response ( CODE, [MSG,] [ \%HEADER, BODY ] ) โ€” returns a Net::SIP::Response packet for the received request $self, with the numerical code CODE and text message MSG. the response's header gets based on the request, but you can add to it or override it with %HEADER. ๐Ÿง

and here's the cute part: if MSG isn't given (like, the argument is missing, or the second argument is already the %HEADER), then a builtin message for the code gets used instead. no MSG, no problem. ๐Ÿ’–

for all the deets on %HEADER and BODY, go look at new_from_parts in Net::SIP::Packet.

  • authorize ( RESPONSE, AUTH ) โ€” tries to authorize request $self based on the info in RESPONSE (which is a 401 or 407 "Authorization required" response, so you know it's that kind of party) plus AUTH. ๐Ÿ”โœจ

and AUTH can be any of these three shapes, depending on your situation:

  • [ user,pass ] โ€” when one global authorization info exists for all realms ๐ŸŒ
  • { realm1 => [ user1,pass1 ], realm2 => [ user2,pass2 ],... } โ€” when you've got different credentials for different realms ๐Ÿ—‚๏ธ
  • a callback, callback(realm)->[user,pass] โ€” when you want to compute it on the fly ๐Ÿช„

the realms that need authorizing get read straight out of RESPONSE, so you don't have to go hunting.

โš ๏ธ heads up: the request $self gets modified in-place. no copy, no undo. if a modification actually happened โ€” like, if (parts of) the authorization requests could be resolved โ€” it returns TRUE, otherwise FALSE.

also important, no cap: this only supports RFC2617 with md5 and empty qop or qop 'auth'. it does NOT do md5-sess or qops like 'auth-int'. so don't come at it with those, it will not eat. ๐Ÿ’€

๐Ÿ‘‘ THE SIGN-OFF ๐Ÿ‘‘

and that's the page, bestie! ๐Ÿซถ this was perl v5.40.1, dated 2025-12-07, brought to you by the User Contributed Perl Documentation girlies. go forth and handle those requests. periodt. ๐Ÿ’œ๐ŸŒˆ

๐Ÿ“ฆ where this page comes from