fix: Normalize bare LF to CRLF for non-compliant SIP devices#31
Merged
Conversation
Some PBX devices send SIP headers terminated with bare \n instead of \r\n as required by RFC 3261. This causes sipgo's parser to fail. Add a transport-layer CRLF normalizer that wraps UDP/TCP connections to fix bare LF before sipgo processes the data.
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR introduces CRLF normalization for SIP traffic handling non-compliant devices. A new normalizer detects and converts bare Changes
Sequence DiagramsequenceDiagram
participant Client
participant crlfPacketConn
participant SIPServer as SIP Server
Client->>crlfPacketConn: SendData (with bare \n)
crlfPacketConn->>crlfPacketConn: ReadFrom (receive packet)
crlfPacketConn->>crlfPacketConn: normalizeCRLF (convert \n to \r\n)
crlfPacketConn->>SIPServer: ReadFrom (normalized data)
SIPServer->>SIPServer: Parse SIP message
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
\ninstead of\r\n(ref: sipgo#292)net.PacketConn(UDP) andnet.Listener/net.Conn(TCP) to normalize line endings before sipgo's parser processes themDetails
Some PBX devices terminate SIP headers with only
\ninstead of the\r\nrequired by RFC 3261 Section 7. Since sipgo's parser strictly requires CRLF, these messages fail to parse. Rather than forking sipgo, this fix intercepts raw bytes at the transport layer and normalizes bare\nto\r\nbefore they reach the parser.Files changed:
pkg/sip/crlf_normalizer.go— normalizer function +crlfPacketConn,crlfListener,crlfConnwrapperspkg/sip/crlf_normalizer_test.go— unit tests, integration tests over real sockets, benchmarkspkg/sip/custom_server.go—ListenAndServeUDPandListenAndServeTCPnow use wrapped connections viaServeUDP/ServeTCPTest plan
normalizeCRLFcovering: correct CRLF, bare LF, mixed, empty, leading LF, full SIP messageTestCRLFPacketConn)TestCRLFConn)Summary by CodeRabbit
Bug Fixes
Tests