Arduino DLNA Server
Loading...
Searching...
No Matches
DLNAControlPointRequestParser.h
Go to the documentation of this file.
1#pragma once
2
4#include "dlna/Schedule.h"
5#include "dlna/Scheduler.h"
6
7namespace tiny_dlna {
8
16 public:
18 DlnaLogger.log(DlnaLogLevel::Debug, "Raw UDP packet: %s", req.data.c_str());
19 if (req.data.startsWith("NOTIFY")) {
20 return parseNotifyReply(req);
21 } else if (req.data.startsWith("HTTP/1.1 200 OK")) {
22 return parseMSearchReply(req);
23 } else if (req.data.startsWith("M-SEARCH")) {
24 DlnaLogger.log(DlnaLogLevel::Debug, "M-SEARCH request ignored");
25 } else {
26 DlnaLogger.log(DlnaLogLevel::Info, "Not handled: %s", req.data);
27 }
28 return nullptr;
29 }
30
31 protected:
33 MSearchReplyCP* result = new MSearchReplyCP();
34 // Accept different common header capitalizations
35 parse(req.data, "Location:", result->location);
36 parse(req.data, "USN:", result->usn);
37 parse(req.data, "ST:", result->search_target);
38 // Debug: log parsed fields to help diagnose missing Location/ST
39 DlnaLogger.log(DlnaLogLevel::Info,
40 "parseMSearchReply parsed -> LOCATION='%s' USN='%s' ST='%s'",
41 result->location.c_str(), result->usn.c_str(),
42 result->search_target.c_str());
43 return result;
44 }
45
47 NotifyReplyCP* result = new NotifyReplyCP();
48 parse(req.data, "NOTIFY:", result->delivery_path);
49 parse(req.data, "NTS:", result->nts);
50 parse(req.data, "NT:", result->search_target);
51 parse(req.data, "Location:", result->location);
52 parse(req.data, "USN:", result->usn);
53 parse(req.data, "Host:", result->delivery_host_and_port);
54 parse(req.data, "SID:", result->subscription_id);
55 parse(req.data, "SEQ:", result->event_key);
56 parse(req.data, "<e:propertyset", result->xml, "</e:propertyset>");
57 return result;
58 }
59
60 // Case-insensitive parse: searches for tag regardless of capitalization
61 bool parse(Str& in, const char* tag, Str& result, const char* end = "\r\n") {
62 result.clearAll();
63 // create lower-case copies for case-insensitive search using std::string
64 Str sin = in.c_str();
65 Str stag = tag;
66 sin.toLowerCase();
67 stag.toLowerCase();
68
69 int start_pos = sin.indexOf(stag.c_str());
70 if (start_pos >= 0) {
71 // find end position in the original buffer to preserve casing
72 int end_pos = sin.indexOf(end, start_pos);
73 start_pos += strlen(tag);
74 if (end_pos < 0) end_pos = in.indexOf("\n", start_pos);
75 if (end_pos >= 0) {
76 result.substrView(in.c_str(), start_pos, end_pos);
77 //DlnaLogger.log(DlnaLogLevel::Debug, "%s substrView (%d,%d)->%s", tag, start_pos, end_pos, result.c_str());
78 result.trim();
79 return true;
80 }
81 }
82 return false;
83 }
84};
85
86} // namespace tiny_dlna
Translates DLNA UDP Requests to Schedule so that we can schedule a reply.
Definition: DLNAControlPointRequestParser.h:15
MSearchReplyCP * parseMSearchReply(RequestData &req)
Definition: DLNAControlPointRequestParser.h:32
Schedule * parse(RequestData &req)
Definition: DLNAControlPointRequestParser.h:17
NotifyReplyCP * parseNotifyReply(RequestData &req)
Definition: DLNAControlPointRequestParser.h:46
bool parse(Str &in, const char *tag, Str &result, const char *end="\r\n")
Definition: DLNAControlPointRequestParser.h:61
Processing at control point to handle a MSearchReply from the device.
Definition: Schedule.h:148
Str usn
Definition: Schedule.h:152
Str location
Definition: Schedule.h:151
Str search_target
Definition: Schedule.h:153
Represents a notification/notify reply scheduled for control-point processing.
Definition: Schedule.h:189
Str delivery_host_and_port
Definition: Schedule.h:193
Str xml
Definition: Schedule.h:197
Str event_key
Definition: Schedule.h:196
Str subscription_id
Definition: Schedule.h:195
Str delivery_path
Definition: Schedule.h:194
Str nts
Definition: Schedule.h:192
Heap-backed string utility used throughout tiny_dlna.
Definition: Str.h:27
void toLowerCase()
Lowercase in-place.
Definition: Str.h:312
void clearAll()
Clear contents (legacy alias)
Definition: Str.h:159
bool startsWith(const char *prefix) const
True if starts with prefix (case-sensitive)
Definition: Str.h:206
void trim()
Trim spaces on both ends.
Definition: Str.h:235
void substrView(StrView &from, int start, int end)
Assign substring view from StrView [start,end)
Definition: Str.h:69
int indexOf(const char *substr, int start=0) const
Index of substring from position (or -1)
Definition: Str.h:214
const char * c_str() const
C-string pointer to internal buffer.
Definition: Str.h:88
Definition: Allocator.h:13
Provides information of the received UDP which consists of the (xml) data and the peer address and po...
Definition: IUDPService.h:22
Str data
Definition: IUDPService.h:23
An individual Schedule (to send out UDP messages)
Definition: Schedule.h:18