Arduino DLNA Server
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DLNAControlPointRequestParser.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "IUDPService.h"
4 #include "Schedule.h"
5 #include "Scheduler.h"
6 
7 namespace tiny_dlna {
8 
16  public:
18  if (req.data.startsWith("NOTIFY")) {
19  return parseNotifyReply(req);
20  } else if (req.data.startsWith("HTTP/1.1 200 OK")) {
21  return parseMSearchReply(req);
22  } else if (req.data.startsWith("M-SEARCH")) {
23  DlnaLogger.log(DlnaDebug, "M-SEARCH request ignored");
24  } else {
25  DlnaLogger.log(DlnaInfo, "Not handled: %s", req.data);
26  }
27  return nullptr;
28  }
29 
30  protected:
32  MSearchReplyCP* result = new MSearchReplyCP();
33  parse(req.data, "LOCATION:", result->location);
34  parse(req.data, "USN:", result->usn);
35  parse(req.data, "ST:", result->search_target);
36  return result;
37  }
38 
40  NotifyReplyCP* result = new NotifyReplyCP();
41  parse(req.data, "NOTIFY:", result->delivery_path);
42  parse(req.data, "NTS:", result->nts);
43  parse(req.data, "NT:", result->search_target);
44  parse(req.data, "Location:", result->location);
45  if (result->location.isEmpty()){
46  parse(req.data, "LOCATION:", result->location);
47  }
48  parse(req.data, "USN:", result->usn);
49  parse(req.data, "Host:", result->delivery_host_and_port);
50  if (result->delivery_host_and_port.isEmpty()){
51  parse(req.data, "HOST:", result->delivery_host_and_port);
52  }
53 
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  bool parse(Str& in, const char* tag, Str& result, const char* end = "\r\n") {
61  result.clearAll();
62  int start_pos = in.indexOf(tag);
63  if (start_pos >= 0) {
64  int end_pos = in.indexOf(end, start_pos);
65  start_pos += strlen(tag);
66  if (end_pos < 0) end_pos = in.indexOf("\n", start_pos);
67  if (end_pos >= 0) {
68  result.substrView(in.c_str(), start_pos, end_pos);
69  DlnaLogger.log(DlnaDebug, "%s substrView (%d,%d)->%s", tag, start_pos, end_pos,
70  result.c_str());
71 
72  result.trim();
73  return true;
74  }
75  }
76  return false;
77  }
78 };
79 
80 } // 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:31
Schedule * parse(RequestData &req)
Definition: DLNAControlPointRequestParser.h:17
NotifyReplyCP * parseNotifyReply(RequestData &req)
Definition: DLNAControlPointRequestParser.h:39
bool parse(Str &in, const char *tag, Str &result, const char *end="\r\n")
Definition: DLNAControlPointRequestParser.h:60
void log(DlnaLogLevel current_level, const char *fmt...)
Print log message.
Definition: Logger.h:40
Processing at control point to handle a MSearchReply from the device.
Definition: Schedule.h:121
Str usn
Definition: Schedule.h:125
Str location
Definition: Schedule.h:124
Str search_target
Definition: Schedule.h:126
Definition: Schedule.h:135
Str delivery_host_and_port
Definition: Schedule.h:139
Str xml
Definition: Schedule.h:143
Str event_key
Definition: Schedule.h:142
Str subscription_id
Definition: Schedule.h:141
Str delivery_path
Definition: Schedule.h:140
Str nts
Definition: Schedule.h:138
virtual void substrView(StrView &from, int start, int end)
copies a substring into the current string
Definition: StrView.h:486
virtual bool isEmpty()
checks if the string is empty
Definition: StrView.h:376
virtual void clearAll()
Definition: StrView.h:552
virtual int indexOf(const char c, int start=0)
Definition: StrView.h:269
virtual bool startsWith(const char *str)
checks if the string starts with the indicated substring
Definition: StrView.h:179
virtual void trim()
remove leading and traling spaces
Definition: StrView.h:513
String implementation which keeps the data on the heap. We grow the allocated memory only if the copy...
Definition: Str.h:22
const char * c_str()
provides the string value as const char*
Definition: Str.h:188
Definition: Allocator.h:6
@ DlnaDebug
Definition: Logger.h:16
@ DlnaInfo
Definition: Logger.h:16
LoggerClass DlnaLogger
Definition: Logger.cpp:5
Provides information of the received UDP which consists of the (xml) data and the peer address and po...
Definition: IUDPService.h:23
Str data
Definition: IUDPService.h:24
An individual Schedule (to send out UDP messages)
Definition: Schedule.h:17