MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / parseAuthRealm

Function parseAuthRealm

Libraries/HttpClient/HttpClientSession.cpp:175–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

173
174static SC::StringSpan sliceString(SC::StringSpan text, size_t start, size_t end)
175{
176 const SC::Span<const char> bytes = text.toCharSpan();
177 if (start > end or end > bytes.sizeInBytes())
178 {
179 return SC::StringSpan(text.getEncoding());
180 }
181 return {{bytes.data() + start, end - start}, false, text.getEncoding()};
182}
183
184static size_t findAuthChallengeEnd(SC::StringSpan value, size_t start)
185{
186 const SC::Span<const char> bytes = value.toCharSpan();
187 const size_t length = bytes.sizeInBytes();
188 bool quoted = false;
189 bool escaped = false;
190
191 for (size_t idx = start; idx < length; ++idx)
192 {
193 if (quoted)
194 {
195 if (escaped)
196 {
197 escaped = false;
198 }
199 else if (bytes[idx] == '\\')
200 {
201 escaped = true;
202 }
203 else if (bytes[idx] == '"')
204 {
205 quoted = false;
206 }
207 continue;
208 }
209
210 if (bytes[idx] == '"')
211 {
212 quoted = true;
213 continue;
214 }
215
216 if (bytes[idx] != ',')
217 {
218 continue;
219 }
220
221 const size_t tokenStart = skipAuthSpaces(bytes, idx + 1, length);
222 const size_t tokenEnd = readAuthToken(bytes, tokenStart, length);
223 if (tokenStart == tokenEnd)
224 {
225 return idx;
226 }
227
228 const size_t afterToken = skipAuthSpaces(bytes, tokenEnd, length);
229 if (afterToken >= length or bytes[afterToken] != '=')
230 {
231 return idx;
232 }

Callers 1

Calls 5

skipAuthSpacesFunction · 0.85
readAuthTokenFunction · 0.85
sliceStringFunction · 0.85
StringSpanFunction · 0.85

Tested by

no test coverage detected