结构化 SipParser 实装 + RFC 4475 合规驱动测试(叠加 PR #3) - #4
Draft
lixuanqun wants to merge 2 commits into
Draft
Conversation
SipParser - 手写字节级状态机,零正则、零分配优化(除字符串) - 自动识别 Request / Response(前 4 字节 'SIP/' 判定) - Request-Line: Method SP Request-URI SP SIP-Version CRLF - Status-Line: SIP-Version SP Status-Code SP Reason-Phrase CRLF - Header 块:RFC 3261 §7.3.1 LWS folding(SP/HTAB 续行合并为单 SP) - Body framing:按 Content-Length 取字节;缺失则取剩余字节(UDP) - 输出:SipMessage(headers 为 RawHeader,URI 暂用 OpaqueUri 保真) SipCodecException 增强 - 新增 category(kebab-case 稳定分类,匹配 fixture manifest) - 新增 offset(字节偏移,便于诊断) - Category 常量:malformed-start-line / malformed-header / unknown-version / bad-content-length / truncated / unsupported-uri-scheme / encode-failure Uri.asWire() - sealed Uri 接口新增 asWire() 用于无损回写 - OpaqueUri.asWire():scheme + ':' + schemeSpecificPart - SipUri.asWire():完整重建 sip:[user[:pass]@]host[:port][;params][?headers] SipParserTest(8 个单测) - 覆盖:基本 OPTIONS 请求、200 OK 响应、LWS folding、 Content-Length body framing、缺 SIP-Version、未知版本、 Content-Length 超出、截断输入 替换旧的 SipParserContractTest(断言 UnsupportedOperationException)。 Co-authored-by: li xuanqun <793005378@qq.com>
ParserConformanceTest(在 sip-compliance-tests) - 每个 accept fixture 喂给 SipParser.parse(byte[]),断言: · 版本、body length、header count · request 的 method 与 request-URI(asWire 回写) · response 的 status 与 reason - 每个 structural reject fixture 必须抛 SipCodecException, 且 category 与 manifest 声明一致 manifest schema 扩展 - FixtureExpectation.Reject 新增 phase 字段(默认 'structural') - 用于标注哪个解析层负责拒绝。typed-header / transaction / dialog 阶段的 reject fixture 在当前结构化测试中被过滤 新增 fixtures - rfc4475/3.1.1.10-transports:多种 Via transport(含 UNKNOWN) - rfc4475/3.1.2.3-ncl:负 Content-Length(structural 必拒) 调整:badinv01 的 phase 标为 typed-header(结构化解析器 检测不到 Via 值里的额外分隔符;该 fixture 会随 typed header parsing 落地后自动加入 gate) torture/README.md 更新 parser.phase 字段说明。 完整 mvn verify:9 模块 SUCCESS,35 tests 全绿 (sip-message 10 + sip-codec 8 + compliance 17 + parser-conformance 9 - 1 skipped) Co-authored-by: li xuanqun <793005378@qq.com>
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.
概述
Phase 2b 落地:把骨架里的
SipParser从UnsupportedOperationException变成真正能跑的结构化解析器,并让 RFC 4475 fixture 接入合规闸门。实装内容
SipParser(手写字节级状态机)输入:
byte[]/String/ByteBuffer输出:
SipMessage(sealed:SipRequest|SipResponse)特点
RawHeader(字符串),typed 解析留给后续 PR 增量做OpaqueUri(scheme, schemeSpecificPart)无损保留,未来加SipUriParser时切到SipUri,call site 不变SipCodecException增强Category常量(与 fixture manifest 的error.category完全对齐):malformed-start-linemalformed-headerunknown-versionbad-content-lengthtruncatedunsupported-uri-schemeencode-failureUri.asWire()sealed Uri接口新增asWire()方法,用于无损回写到 Request-Line。OpaqueUri.asWire()=scheme + ":" + schemeSpecificPartSipUri.asWire()= 完整重建sip:[user[:pass]@]host[:port][;params][?headers]这样测试可以断言:解析→回写后 URI 字符串完全等于源 fixture 声明的 URI。
ParserConformanceTest(合规驱动)每个 accept fixture 自动验证:
body.length= 实际帧字节数asWire()回写值)每个 structural reject fixture 自动验证:
SipParser.parse()必须抛SipCodecExceptionexception.category()必须等于 manifest 的error.categoryManifest schema 扩展:
parser.phaseFixtureExpectation.Reject增加phase字段(默认structural)。用于标注哪个解析层负责拒绝。
structuraltyped-headertransactiondialogbadinv01因此被标为typed-header(结构化解析器看不出 Via 值里;;,;,,的语义错),等 typed header 解析落地后自动并入 gate。新增 RFC 4475 fixtures
3.1.1.10-transports— 五种 Via transport(UDP/SCTP/TLS/UNKNOWN/TCP),验证多 Via 保序解析3.1.2.3-ncl— Content-Length: -999,结构化bad-content-length必拒测试矩阵
合规模块分布:
Accept fixtures 现已全部 byte-exact 通过 parser:
self-test/simple-optionsself-test/simple-200-okself-test/invite-with-sdprfc4475/3.1.1.6-lwsdisp<之间无 LWSrfc4475/3.1.1.9-semiurirfc4475/3.1.1.10-transportsReject fixtures 在 structural phase 通过:
self-test/missing-sip-versionmalformed-start-linerfc4475/3.1.2.3-nclbad-content-length下一步(Phase 2c+)
依此 PR 之上可继续叠加:
badinv01自动加入 gateSipEncoder实装 + roundtrip 测试SipUriParser切换OpaqueUri→SipUri合并顺序:#2 → #3 → 本 PR。