mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-13 13:01:55 +03:00
[SSDP] add schema(Print &) const
(#6798)
* [SSDP] add `schema(Print &) const` Supercedes #2806 Make SSDP::schema(WiFiClient&) use a by-ref (reduce stack use) Add a SSDP::schema(Print&) From @Palatis' original PR: useful when using AsyncWebServer. * Use ip.toString, only export Print& schema interface Because WiFiClient inherits a Print interface, replace the ::schema(WiFiClient&) with ::schema(Print&) which is source compatible with existing code and allows the functionality requested in the initial PR. Use ip.toString() in the templates instead of breaking up the octets of the address. * Fix compile errors and backwards compatibility
This commit is contained in:
committed by
Develo
parent
9b96f53778
commit
344c4492af
@ -73,7 +73,7 @@ static const char _ssdp_packet_template[] PROGMEM =
|
|||||||
"SERVER: Arduino/1.0 UPNP/1.1 %s/%s\r\n" // _modelName, _modelNumber
|
"SERVER: Arduino/1.0 UPNP/1.1 %s/%s\r\n" // _modelName, _modelNumber
|
||||||
"USN: %s\r\n" // _uuid
|
"USN: %s\r\n" // _uuid
|
||||||
"%s: %s\r\n" // "NT" or "ST", _deviceType
|
"%s: %s\r\n" // "NT" or "ST", _deviceType
|
||||||
"LOCATION: http://%u.%u.%u.%u:%u/%s\r\n" // WiFi.localIP(), _port, _schemaURL
|
"LOCATION: http://%s:%u/%s\r\n" // WiFi.localIP(), _port, _schemaURL
|
||||||
"\r\n";
|
"\r\n";
|
||||||
|
|
||||||
static const char _ssdp_schema_template[] PROGMEM =
|
static const char _ssdp_schema_template[] PROGMEM =
|
||||||
@ -88,7 +88,7 @@ static const char _ssdp_schema_template[] PROGMEM =
|
|||||||
"<major>1</major>"
|
"<major>1</major>"
|
||||||
"<minor>0</minor>"
|
"<minor>0</minor>"
|
||||||
"</specVersion>"
|
"</specVersion>"
|
||||||
"<URLBase>http://%u.%u.%u.%u:%u/</URLBase>" // WiFi.localIP(), _port
|
"<URLBase>http://%s:%u/</URLBase>" // WiFi.localIP(), _port
|
||||||
"<device>"
|
"<device>"
|
||||||
"<deviceType>%s</deviceType>"
|
"<deviceType>%s</deviceType>"
|
||||||
"<friendlyName>%s</friendlyName>"
|
"<friendlyName>%s</friendlyName>"
|
||||||
@ -247,7 +247,7 @@ void SSDPClass::_send(ssdp_method_t method) {
|
|||||||
_uuid,
|
_uuid,
|
||||||
(method == NONE) ? "ST" : "NT",
|
(method == NONE) ? "ST" : "NT",
|
||||||
(_st_is_uuid) ? _uuid : _deviceType,
|
(_st_is_uuid) ? _uuid : _deviceType,
|
||||||
ip[0], ip[1], ip[2], ip[3], _port, _schemaURL
|
ip.toString().c_str(), _port, _schemaURL
|
||||||
);
|
);
|
||||||
|
|
||||||
_server->append(buffer, len);
|
_server->append(buffer, len);
|
||||||
@ -276,12 +276,12 @@ void SSDPClass::_send(ssdp_method_t method) {
|
|||||||
_server->send(remoteAddr, remotePort);
|
_server->send(remoteAddr, remotePort);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSDPClass::schema(WiFiClient client) {
|
void SSDPClass::schema(Print &client) const {
|
||||||
IPAddress ip = WiFi.localIP();
|
IPAddress ip = WiFi.localIP();
|
||||||
char buffer[strlen_P(_ssdp_schema_template) + 1];
|
char buffer[strlen_P(_ssdp_schema_template) + 1];
|
||||||
strcpy_P(buffer, _ssdp_schema_template);
|
strcpy_P(buffer, _ssdp_schema_template);
|
||||||
client.printf(buffer,
|
client.printf(buffer,
|
||||||
ip[0], ip[1], ip[2], ip[3], _port,
|
ip.toString().c_str(), _port,
|
||||||
_deviceType,
|
_deviceType,
|
||||||
_friendlyName,
|
_friendlyName,
|
||||||
_presentationURL,
|
_presentationURL,
|
||||||
|
@ -62,7 +62,8 @@ class SSDPClass{
|
|||||||
~SSDPClass();
|
~SSDPClass();
|
||||||
bool begin();
|
bool begin();
|
||||||
void end();
|
void end();
|
||||||
void schema(WiFiClient client);
|
void schema(WiFiClient client) const { schema((Print&)std::ref(client)); }
|
||||||
|
void schema(Print &print) const;
|
||||||
void setDeviceType(const String& deviceType) { setDeviceType(deviceType.c_str()); }
|
void setDeviceType(const String& deviceType) { setDeviceType(deviceType.c_str()); }
|
||||||
void setDeviceType(const char *deviceType);
|
void setDeviceType(const char *deviceType);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user