Extract the request method (such as `INVITE`, `REGISTER`, `OPTIONS`, or `BYE`) from a SIP message.
Overview
The plan is simple:
Scan forward to the first space.
Check that every character before it is an uppercase letter (A-Z).
Copy the method into the output buffer, staying within its size limit.
Why it matters
SIP gateways sit on the public internet, exposed to untrusted input.
Rejecting a malformed method right at the entry point is cheap. Skipping that check can be expensive.
Lesson
Why this matters
SIP is the protocol behind every VoIP call and WebRTC signalling exchange. (SIP stands for Session Initiation Protocol; it sets up and tears down voice and video sessions.)
SIP looks almost exactly like HTTP. Both have:
A request line
Headers
A blank line
An optional body
The bug surface is similar too. The first place to get input validation right is the request line.
Here we extract just the method. Later modules can pull out the URI and the Via chain.