Skip to content

Refactor string handling and Contact header logic#1679

Merged
sipsorcery merged 2 commits into
sipsorcery-org:masterfrom
paulomorgado:strings-12
Jun 8, 2026
Merged

Refactor string handling and Contact header logic#1679
sipsorcery merged 2 commits into
sipsorcery-org:masterfrom
paulomorgado:strings-12

Conversation

@paulomorgado

Copy link
Copy Markdown
Contributor

Refactored string concatenation in SIPDialogue and SIPHeader to use StringBuilder for better performance and maintainability. Updated Contact header handling in SIPTransport with a helper function and improved null checks to enhance robustness and reduce code duplication.

Comment thread src/SIPSorcery/core/SIP/SIPDialogue.cs Outdated
Comment thread src/SIPSorcery/core/SIP/SIPDialogue.cs Outdated
Comment thread src/SIPSorcery/core/SIP/SIPTransport.cs Outdated
@paulomorgado paulomorgado marked this pull request as draft June 8, 2026 09:38
@paulomorgado paulomorgado marked this pull request as ready for review June 8, 2026 10:38
@sipsorcery

Copy link
Copy Markdown
Member

Thanks for the fixes in the SIPDialogue class but this PR now contains new changes to STUN, DTLS and other classes. Can the new additions go into a separate PR.

Refactored DialogueName and SIPHeader formatting to use StringBuilder and explicit appends for efficiency and code consistency. Improved null checks and replaced string interpolation as per user preferences. Reformatted unit tests for style consistency without changing functionality.
Comment thread test/unit/core/SIP/SIPDialogueUnitTest.cs
Comment thread src/SIPSorcery/core/SIP/SIPDialogue.cs Outdated
if (RemoteUserField?.URI is { } remoteUserFieldUri && !remoteUserFieldUri.User.IsNullOrBlank())
{
dialogueName += $"R({RemoteUserField.URI.ToString()})";
dialogueNameBuilder.Append("R(").Append(RemoteUserField).Append(')');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be Append(RemoteUserField.URI) here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed! Added unit tests!

Updated SIPDialogue to use URI for remote user in DialogueName.
Added unit tests to verify DialogueName formatting for cases
with missing or present local/remote user information.
@sipsorcery sipsorcery merged commit a05a9a4 into sipsorcery-org:master Jun 8, 2026
6 checks passed
@paulomorgado paulomorgado mentioned this pull request Jun 8, 2026
@paulomorgado paulomorgado deleted the strings-12 branch June 8, 2026 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants