From 937d3b37e3f8840230d66b2ba0e0467ed5db0de5 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Wed, 20 Nov 2024 19:10:14 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20doxygen=20from=20@=20pschatzma?= =?UTF-8?q?nn/arduino-audio-tools@444e8966e83c129b08e3b759534da1bc0049d4b5?= =?UTF-8?q?=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _http_request_8h_source.html | 439 ++++++++++++++++++----------------- _i_c_y_stream_8h_source.html | 2 +- _u_r_l_stream_8h_source.html | 6 +- 3 files changed, 226 insertions(+), 221 deletions(-) diff --git a/_http_request_8h_source.html b/_http_request_8h_source.html index c11869b37..3a4ee54b7 100644 --- a/_http_request_8h_source.html +++ b/_http_request_8h_source.html @@ -184,215 +184,220 @@
132  }
133 
134  size_t readBytesUntil(char terminator, char *buffer, size_t length) {
-
135  return client_ptr->readBytesUntil(terminator, buffer, length);
-
136  }
-
137 
-
138  // read the reply data up to the next new line. For Chunked data we provide
-
139  // the full chunk!
-
140  virtual int readln(uint8_t *str, int len, bool incl_nl = true) {
-
141  if (reply_header.isChunked()) {
-
142  return chunk_reader.readln(*client_ptr, str, len);
-
143  } else {
-
144  return chunk_reader.readlnInternal(*client_ptr, str, len, incl_nl);
-
145  }
-
146  }
-
147 
-
148  // provides the head information of the reply
-
149  virtual HttpReplyHeader &reply() { return reply_header; }
-
150 
-
152  virtual HttpRequestHeader &header() { return request_header; }
-
153 
-
155  virtual void setAgent(const char *agent) { this->agent = agent; }
-
156 
-
157  virtual void setConnection(const char *connection) {
-
158  this->connection = connection;
-
159  }
-
160 
-
161  virtual void setAcceptsEncoding(const char *enc) {
-
162  this->accept_encoding = enc;
-
163  }
-
164 
-
165  virtual void setAcceptMime(const char *mime) { this->accept = mime; }
+
135  TRACED();
+
136  return client_ptr->readBytesUntil(terminator, buffer, length);
+
137  }
+
138 
+
139  // read the reply data up to the next new line. For Chunked data we provide
+
140  // the full chunk!
+
141  virtual int readln(uint8_t *str, int len, bool incl_nl = true) {
+
142  TRACED();
+
143  if (reply_header.isChunked()) {
+
144  return chunk_reader.readln(*client_ptr, str, len);
+
145  } else {
+
146  return chunk_reader.readlnInternal(*client_ptr, str, len, incl_nl);
+
147  }
+
148  }
+
149 
+
150  // provides the head information of the reply
+
151  virtual HttpReplyHeader &reply() { return reply_header; }
+
152 
+
154  virtual HttpRequestHeader &header() { return request_header; }
+
155 
+
157  virtual void setAgent(const char *agent) { this->agent = agent; }
+
158 
+
159  virtual void setConnection(const char *connection) {
+
160  this->connection = connection;
+
161  }
+
162 
+
163  virtual void setAcceptsEncoding(const char *enc) {
+
164  this->accept_encoding = enc;
+
165  }
166 
-
167  size_t contentLength() {
-
168  const char *len_str = reply().get(CONTENT_LENGTH);
-
169  int len = 0;
-
170  if (len_str != nullptr) {
-
171  len = atoi(len_str);
-
172  } else {
-
173  LOGI("no CONTENT_LENGTH found in reply");
-
174  }
-
175  return len;
-
176  }
-
177 
-
180  bool isReady() { return is_ready; }
-
181 
-
183  void addRequestHeader(const char *header, const char *value) {
-
184  request_header.put(header, value);
-
185  }
-
186 
-
187  Client &client() { return *client_ptr; }
+
167  virtual void setAcceptMime(const char *mime) { this->accept = mime; }
+
168 
+
169  size_t contentLength() {
+
170  const char *len_str = reply().get(CONTENT_LENGTH);
+
171  int len = 0;
+
172  if (len_str != nullptr) {
+
173  len = atoi(len_str);
+
174  } else {
+
175  LOGI("no CONTENT_LENGTH found in reply");
+
176  }
+
177  return len;
+
178  }
+
179 
+
182  bool isReady() { return is_ready; }
+
183 
+
185  void addRequestHeader(const char *header, const char *value) {
+
186  request_header.put(header, value);
+
187  }
188 
-
189  // process http request and reads the reply_header from the server
-
190  virtual int process(MethodID action, Url &url, const char *mime,
-
191  const char *data, int lenData = -1) {
-
192  int len = lenData;
-
193  if (data != nullptr && len <= 0) {
-
194  len = strlen(data);
-
195  }
-
196  processBegin(action, url, mime, len);
-
197  // posting data parameter
-
198  if (len > 0 && data != nullptr) {
-
199  LOGI("Writing data: %d bytes", len);
-
200  client_ptr->write((const uint8_t *)data, len);
-
201  LOGD("%s", data);
-
202  }
-
203  return processEnd();
-
204  }
-
205 
-
206  // process http request and reads the reply_header from the server
-
207  virtual int process(MethodID action, Url &url, const char *mime,
-
208  Stream &stream, int len = -1) {
-
209  if (!processBegin(action, url, mime, len))
-
210  return -1;
-
211  processWrite(stream);
-
212  return processEnd();
-
213  }
-
214 
-
216  virtual bool processBegin(MethodID action, Url &url, const char *mime,
-
217  int lenData = -1) {
-
218  TRACED();
-
219  int len = lenData;
-
220  is_ready = false;
-
221  if (client_ptr == nullptr) {
-
222  LOGE("The client has not been defined");
-
223  return false;
-
224  }
-
225  if (http_connect_callback) {
-
226  http_connect_callback(*this, url, request_header);
-
227  }
-
228  if (!this->connected()) {
-
229  LOGI("process connecting to host %s port %d", url.host(), url.port());
-
230  int is_connected = connect(url.host(), url.port(), clientTimeout);
-
231  if (!is_connected) {
-
232  LOGE("Connect failed");
-
233  return false;
-
234  }
-
235  } else {
-
236  LOGI("process is already connected");
-
237  }
-
238 
-
239 #if defined(ESP32) && defined(ARDUINO)
-
240  LOGI("Free heap: %u", (unsigned)ESP.getFreeHeap());
-
241 #endif
-
242 
-
243  reply_header.setProcessed();
+
189  Client &client() { return *client_ptr; }
+
190 
+
191  // process http request and reads the reply_header from the server
+
192  virtual int process(MethodID action, Url &url, const char *mime,
+
193  const char *data, int lenData = -1) {
+
194  int len = lenData;
+
195  if (data != nullptr && len <= 0) {
+
196  len = strlen(data);
+
197  }
+
198  processBegin(action, url, mime, len);
+
199  // posting data parameter
+
200  if (len > 0 && data != nullptr) {
+
201  LOGI("Writing data: %d bytes", len);
+
202  client_ptr->write((const uint8_t *)data, len);
+
203  LOGD("%s", data);
+
204  }
+
205  return processEnd();
+
206  }
+
207 
+
208  // process http request and reads the reply_header from the server
+
209  virtual int process(MethodID action, Url &url, const char *mime,
+
210  Stream &stream, int len = -1) {
+
211  if (!processBegin(action, url, mime, len))
+
212  return -1;
+
213  processWrite(stream);
+
214  return processEnd();
+
215  }
+
216 
+
218  virtual bool processBegin(MethodID action, Url &url, const char *mime,
+
219  int lenData = -1) {
+
220  TRACED();
+
221  int len = lenData;
+
222  is_ready = false;
+
223  if (client_ptr == nullptr) {
+
224  LOGE("The client has not been defined");
+
225  return false;
+
226  }
+
227  if (http_connect_callback) {
+
228  http_connect_callback(*this, url, request_header);
+
229  }
+
230  if (!this->connected()) {
+
231  LOGI("process connecting to host %s port %d", url.host(), url.port());
+
232  int is_connected = connect(url.host(), url.port(), clientTimeout);
+
233  if (!is_connected) {
+
234  LOGE("Connect failed");
+
235  return false;
+
236  }
+
237  } else {
+
238  LOGI("process is already connected");
+
239  }
+
240 
+
241 #if defined(ESP32) && defined(ARDUINO)
+
242  LOGI("Free heap: %u", (unsigned)ESP.getFreeHeap());
+
243 #endif
244 
-
245  host_name = url.host();
-
246  request_header.setValues(action, url.path());
-
247  if (lenData > 0) {
-
248  request_header.put(CONTENT_LENGTH, lenData);
-
249  }
-
250  request_header.put(HOST_C, host_name);
-
251  request_header.put(CONNECTION, connection);
-
252  request_header.put(USER_AGENT, agent);
-
253  request_header.put(ACCEPT_ENCODING, accept_encoding);
-
254  request_header.put(ACCEPT, accept);
-
255  request_header.put(CONTENT_TYPE, mime);
-
256  request_header.write(*client_ptr);
-
257 
-
258  return true;
-
259  }
-
260 
-
262  virtual void processWrite(Stream &stream) {
-
263  uint8_t buffer[CHUNK_SIZE];
-
264  int total = 0;
-
265  int total_written = 0;
-
266  while (*client_ptr && stream.available() > 0) {
-
267  int result_len = stream.readBytes(buffer, CHUNK_SIZE);
-
268  total += result_len;
-
269  int written = write(buffer, result_len);
-
270  total_written += written;
-
271  LOGI("--> Bytes read %d vs written %d", result_len, written);
-
272  delay(1);
-
273  }
-
274  client_ptr->flush();
-
275  LOGI("Total bytes read %d vs written %d", total, total_written);
-
276  }
-
277 
-
280  size_t write(const uint8_t *data, size_t len) override {
-
281  size_t result = 0;
-
282  if (isChunked()) {
-
283  client_ptr->println(len);
-
284  if (len > 0) {
-
285  result = client_ptr->write(data, len);
-
286  }
-
287  client_ptr->println();
-
288  } else {
-
289  result = client_ptr->write(data, len);
-
290  }
-
291  return result;
-
292  }
-
293 
-
295  virtual int processEnd() {
-
296  // if sending is chunked we terminate with an empty chunk
-
297  if (isChunked()) {
-
298  write(nullptr, 0);
-
299  }
-
300  LOGI("Request written ... waiting for reply");
-
301  // Commented out because this breaks the RP2040 W
-
302  // client_ptr->flush();
-
303  reply_header.read(*client_ptr);
-
304 
-
305  // if we use chunked tranfer we need to read the first chunked length
-
306  if (reply_header.isChunked()) {
-
307  chunk_reader.open(*client_ptr);
-
308  };
-
309 
-
310  // wait for data
-
311  is_ready = true;
-
312  return reply_header.statusCode();
-
313  }
-
314 
-
316  void setOnConnectCallback(void (*callback)(
-
317  HttpRequest &request, Url &url, HttpRequestHeader &request_header)) {
-
318  http_connect_callback = callback;
-
319  }
-
320 
-
322  void setTimeout(int timeoutMs) { clientTimeout = timeoutMs; }
-
323 
-
325  bool isChunked() { return request_header.isChunked(); }
-
326 
-
327  protected:
-
328  Client *client_ptr = nullptr;
-
329  Url url;
-
330  HttpRequestHeader request_header;
-
331  HttpReplyHeader reply_header;
-
332  HttpChunkReader chunk_reader = HttpChunkReader(reply_header);
-
333  const char *agent = nullptr;
-
334  const char *host_name = nullptr;
-
335  const char *connection = CON_KEEP_ALIVE;
-
336  const char *accept = ACCEPT_ALL;
-
337  const char *accept_encoding = IDENTITY;
-
338  bool is_ready = false;
-
339  int32_t clientTimeout = URL_CLIENT_TIMEOUT; // 60000;
-
340  void (*http_connect_callback)(HttpRequest &request, Url &url,
-
341  HttpRequestHeader &request_header) = nullptr;
-
342 
-
343  // opens a connection to the indicated host
-
344  virtual int connect(const char *ip, uint16_t port, int32_t timeout) {
-
345  client_ptr->setTimeout(timeout / 1000); // client timeout is in seconds!
-
346  request_header.setTimeout(timeout);
-
347  reply_header.setTimeout(timeout);
-
348  int is_connected = this->client_ptr->connect(ip, port);
-
349  LOGI("is connected %s with timeout %d", is_connected ? "true" : "false", (int)timeout);
-
350  return is_connected;
-
351  }
-
352 };
-
353 
-
354 } // namespace audio_tools
-
355 
-
356 #endif
+
245  reply_header.setProcessed();
+
246 
+
247  host_name = url.host();
+
248  request_header.setValues(action, url.path());
+
249  if (lenData > 0) {
+
250  request_header.put(CONTENT_LENGTH, lenData);
+
251  }
+
252  request_header.put(HOST_C, host_name);
+
253  request_header.put(CONNECTION, connection);
+
254  request_header.put(USER_AGENT, agent);
+
255  request_header.put(ACCEPT_ENCODING, accept_encoding);
+
256  request_header.put(ACCEPT, accept);
+
257  request_header.put(CONTENT_TYPE, mime);
+
258  request_header.write(*client_ptr);
+
259 
+
260  return true;
+
261  }
+
262 
+
264  virtual void processWrite(Stream &stream) {
+
265  uint8_t buffer[CHUNK_SIZE];
+
266  int total = 0;
+
267  int total_written = 0;
+
268  while (*client_ptr && stream.available() > 0) {
+
269  int result_len = stream.readBytes(buffer, CHUNK_SIZE);
+
270  total += result_len;
+
271  int written = write(buffer, result_len);
+
272  total_written += written;
+
273  LOGI("--> Bytes read %d vs written %d", result_len, written);
+
274  delay(1);
+
275  }
+
276  client_ptr->flush();
+
277  LOGI("Total bytes read %d vs written %d", total, total_written);
+
278  }
+
279 
+
282  size_t write(const uint8_t *data, size_t len) override {
+
283  TRACED();
+
284  size_t result = 0;
+
285  if (isChunked()) {
+
286  if (len > 0) {
+
287  client_ptr->println(len, HEX);
+
288  result = client_ptr->write(data, len);
+
289  client_ptr->println();
+
290  }
+
291  } else {
+
292  result = client_ptr->write(data, len);
+
293  }
+
294  return result;
+
295  }
+
296 
+
298  virtual int processEnd() {
+
299  TRACED();
+
300  // if sending is chunked we terminate with an empty chunk
+
301  if (isChunked()) {
+
302  write(nullptr, 0);
+
303  }
+
304  LOGI("Request written ... waiting for reply");
+
305  // Commented out because this breaks the RP2040 W
+
306  // client_ptr->flush();
+
307  reply_header.read(*client_ptr);
+
308 
+
309  // if we use chunked tranfer we need to read the first chunked length
+
310  if (reply_header.isChunked()) {
+
311  chunk_reader.open(*client_ptr);
+
312  };
+
313 
+
314  // wait for data
+
315  is_ready = true;
+
316  return reply_header.statusCode();
+
317  }
+
318 
+
320  void setOnConnectCallback(void (*callback)(
+
321  HttpRequest &request, Url &url, HttpRequestHeader &request_header)) {
+
322  http_connect_callback = callback;
+
323  }
+
324 
+
326  void setTimeout(int timeoutMs) { clientTimeout = timeoutMs; }
+
327 
+
329  bool isChunked() { return request_header.isChunked(); }
+
330 
+
331  protected:
+
332  Client *client_ptr = nullptr;
+
333  Url url;
+
334  HttpRequestHeader request_header;
+
335  HttpReplyHeader reply_header;
+
336  HttpChunkReader chunk_reader = HttpChunkReader(reply_header);
+
337  const char *agent = nullptr;
+
338  const char *host_name = nullptr;
+
339  const char *connection = CON_KEEP_ALIVE;
+
340  const char *accept = ACCEPT_ALL;
+
341  const char *accept_encoding = IDENTITY;
+
342  bool is_ready = false;
+
343  int32_t clientTimeout = URL_CLIENT_TIMEOUT; // 60000;
+
344  void (*http_connect_callback)(HttpRequest &request, Url &url,
+
345  HttpRequestHeader &request_header) = nullptr;
+
346 
+
347  // opens a connection to the indicated host
+
348  virtual int connect(const char *ip, uint16_t port, int32_t timeout) {
+
349  TRACED();
+
350  client_ptr->setTimeout(timeout / 1000); // client timeout is in seconds!
+
351  request_header.setTimeout(timeout);
+
352  reply_header.setTimeout(timeout);
+
353  int is_connected = this->client_ptr->connect(ip, port);
+
354  LOGI("is connected %s with timeout %d", is_connected ? "true" : "false", (int)timeout);
+
355  return is_connected;
+
356  }
+
357 };
+
358 
+
359 } // namespace audio_tools
+
360 
+
361 #endif
Base class for all Streams. It relies on write(const uint8_t *buffer, size_t size) and readBytes(uint...
Definition: BaseStream.h:34
Definition: NoArduino.h:139
Http might reply with chunks. So we need to dechunk the data. see https://en.wikipedia....
Definition: HttpChunkReader.h:14
@@ -403,24 +408,24 @@
Reading and Writing of Http Replys.
Definition: HttpHeader.h:448
Reading and writing of Http Requests.
Definition: HttpHeader.h:389
Simple API to process get, put, post, del http requests I tried to use Arduino HttpClient,...
Definition: HttpRequest.h:26
-
void setTimeout(int timeoutMs)
Defines the client timeout in ms.
Definition: HttpRequest.h:322
-
bool isChunked()
we are sending the data chunked
Definition: HttpRequest.h:325
+
void setTimeout(int timeoutMs)
Defines the client timeout in ms.
Definition: HttpRequest.h:326
+
bool isChunked()
we are sending the data chunked
Definition: HttpRequest.h:329
virtual int post(Url &url, const char *mime, Stream &data, int len=-1)
http post
Definition: HttpRequest.h:80
virtual int get(Url &url, const char *acceptMime=nullptr, const char *data=nullptr, int len=-1)
http get
Definition: HttpRequest.h:105
-
virtual int processEnd()
Ends the http request processing and returns the status code.
Definition: HttpRequest.h:295
-
virtual HttpRequestHeader & header()
provides access to the request header
Definition: HttpRequest.h:152
+
virtual int processEnd()
Ends the http request processing and returns the status code.
Definition: HttpRequest.h:298
+
virtual HttpRequestHeader & header()
provides access to the request header
Definition: HttpRequest.h:154
virtual int put(Url &url, const char *mime, const char *data, int len=-1)
http put
Definition: HttpRequest.h:86
-
virtual void processWrite(Stream &stream)
Writes (Posts) the data of the indicated stream after calling processBegin.
Definition: HttpRequest.h:262
-
virtual void setAgent(const char *agent)
Defines the agent.
Definition: HttpRequest.h:155
+
virtual void processWrite(Stream &stream)
Writes (Posts) the data of the indicated stream after calling processBegin.
Definition: HttpRequest.h:264
+
virtual void setAgent(const char *agent)
Defines the agent.
Definition: HttpRequest.h:157
void end() override
same as end()
Definition: HttpRequest.h:62
-
size_t write(const uint8_t *data, size_t len) override
Definition: HttpRequest.h:280
-
virtual bool processBegin(MethodID action, Url &url, const char *mime, int lenData=-1)
starts http request processing
Definition: HttpRequest.h:216
+
size_t write(const uint8_t *data, size_t len) override
Definition: HttpRequest.h:282
+
virtual bool processBegin(MethodID action, Url &url, const char *mime, int lenData=-1)
starts http request processing
Definition: HttpRequest.h:218
virtual int put(Url &url, const char *mime, Stream &data, int len=-1)
http put
Definition: HttpRequest.h:92
virtual int head(Url &url, const char *acceptMime=nullptr, const char *data=nullptr, int len=-1)
http head
Definition: HttpRequest.h:113
virtual int post(Url &url, const char *mime, const char *data, int len=-1)
http post
Definition: HttpRequest.h:74
-
void setOnConnectCallback(void(*callback)(HttpRequest &request, Url &url, HttpRequestHeader &request_header))
Callback which allows you to add additional paramters dynamically.
Definition: HttpRequest.h:316
-
bool isReady()
Definition: HttpRequest.h:180
-
void addRequestHeader(const char *header, const char *value)
Adds/Updates a request header.
Definition: HttpRequest.h:183
+
void setOnConnectCallback(void(*callback)(HttpRequest &request, Url &url, HttpRequestHeader &request_header))
Callback which allows you to add additional paramters dynamically.
Definition: HttpRequest.h:320
+
bool isReady()
Definition: HttpRequest.h:182
+
void addRequestHeader(const char *header, const char *value)
Adds/Updates a request header.
Definition: HttpRequest.h:185
virtual int del(Url &url, const char *mime=nullptr, const char *data=nullptr, int len=-1)
http del
Definition: HttpRequest.h:98
Definition: NoArduino.h:125
Represents the content of a URL as Stream. We use the WiFi.h API.
Definition: URLStream.h:26
diff --git a/_i_c_y_stream_8h_source.html b/_i_c_y_stream_8h_source.html index 2b21da9bf..b584948a3 100644 --- a/_i_c_y_stream_8h_source.html +++ b/_i_c_y_stream_8h_source.html @@ -206,7 +206,7 @@
Abstract Base class for all URLStream implementations.
Definition: AbstractURLStream.h:11
Definition: NoArduino.h:139
Simple API to process get, put, post, del http requests I tried to use Arduino HttpClient,...
Definition: HttpRequest.h:26
-
virtual HttpRequestHeader & header()
provides access to the request header
Definition: HttpRequest.h:152
+
virtual HttpRequestHeader & header()
provides access to the request header
Definition: HttpRequest.h:154
Icecast/Shoutcast Audio Stream which splits the data into metadata and audio data....
Definition: ICYStream.h:22
virtual HttpRequest & httpRequest() override
provides access to the HttpRequest
Definition: ICYStream.h:131
virtual size_t readBytes(uint8_t *data, size_t len) override
reads the audio bytes
Definition: ICYStream.h:90
diff --git a/_u_r_l_stream_8h_source.html b/_u_r_l_stream_8h_source.html index a13e31933..3cc9f4128 100644 --- a/_u_r_l_stream_8h_source.html +++ b/_u_r_l_stream_8h_source.html @@ -477,9 +477,9 @@
HttpHeader & clear()
clears the data
Definition: HttpHeader.h:94
Reading and writing of Http Requests.
Definition: HttpHeader.h:389
Simple API to process get, put, post, del http requests I tried to use Arduino HttpClient,...
Definition: HttpRequest.h:26
-
virtual HttpRequestHeader & header()
provides access to the request header
Definition: HttpRequest.h:152
-
void setOnConnectCallback(void(*callback)(HttpRequest &request, Url &url, HttpRequestHeader &request_header))
Callback which allows you to add additional paramters dynamically.
Definition: HttpRequest.h:316
-
bool isReady()
Definition: HttpRequest.h:180
+
virtual HttpRequestHeader & header()
provides access to the request header
Definition: HttpRequest.h:154
+
void setOnConnectCallback(void(*callback)(HttpRequest &request, Url &url, HttpRequestHeader &request_header))
Callback which allows you to add additional paramters dynamically.
Definition: HttpRequest.h:320
+
bool isReady()
Definition: HttpRequest.h:182
virtual const char * c_str()
provides the string value as const char*
Definition: StrView.h:379
Definition: NoArduino.h:125
Represents the content of a URL as Stream. We use the WiFi.h API.
Definition: URLStream.h:26