43 std::function<
void(
const char* entry,
ProtocolRole role)> cb) {
44 if ( !cb)
return false;
46 enum CollectState { LOOKING, IN_SOURCE, IN_SINK } state = LOOKING;
48 const char* endSource =
"</Source>";
49 const char* endSink =
"</Sink>";
54 int len = in.readBytes(buf,
sizeof(buf));
56 for (
int i = 0; i < len; ++i) {
57 char c = (char)buf[i];
58 if (state == LOOKING) {
59 static Str openBuf(16);
64 if (openBuf.
indexOf(
"<Source") >= 0) {
71 if (openBuf.
indexOf(
"<Sink") >= 0) {
78 }
else if (state == IN_SOURCE) {
79 if (c == endSource[matchPos]) {
81 if (endSource[matchPos] ==
'\0') {
93 for (
int k = 0; k < matchPos; ++k) token.
add(endSource[k]);
105 }
else if (state == IN_SINK) {
106 if (c == endSink[matchPos]) {
108 if (endSink[matchPos] ==
'\0') {
120 for (
int k = 0; k < matchPos; ++k) token.
add(endSink[k]);
136 if (state == IN_SOURCE) {
140 }
else if (state == IN_SINK) {
Heap-backed string utility used throughout tiny_dlna.
Definition: Str.h:27
int length() const
Current length (int)
Definition: Str.h:57
bool isEmpty() const
True if empty.
Definition: Str.h:54
void trim()
Trim spaces on both ends.
Definition: Str.h:235
int indexOf(const char *substr, int start=0) const
Index of substring from position (or -1)
Definition: Str.h:214
Str substring(int start, int end) const
Return substring [start,end) as a new Str.
Definition: Str.h:293
void add(const char *append)
Append C-string (ignored if nullptr)
Definition: Str.h:96
void clear()
Clear contents (size -> 0)
Definition: Str.h:93
const char * c_str() const
C-string pointer to internal buffer.
Definition: Str.h:88
Streaming parser for ConnectionManager::GetProtocolInfo results.
Definition: XMLProtocolInfoParser.h:28
static bool parse(Stream &in, std::function< void(const char *entry, ProtocolRole role)> cb)
Definition: XMLProtocolInfoParser.h:41
Definition: Allocator.h:13
ProtocolRole
Role to indicate whether a protocolInfo entry is a Source or a Sink.
Definition: DLNACommon.h:26