acme_dns_client.c
Go to the documentation of this file.
1 /**
2  * @file acme_dns_client.c
3  * @brief ACME-DNS client
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2019-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneACME Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL ACME_DNS_TRACE_LEVEL
33 
34 //Dependencies
37 #include "debug.h"
38 
39 //Check TCP/IP stack configuration
40 #if (ACME_DNS_CLIENT_SUPPORT == ENABLED)
41 
42 
43 /**
44  * @brief Initialize ACME-DNS client context
45  * @param[in] context Pointer to the ACME-DNS client context
46  * @return Error code
47  **/
48 
50 {
51  error_t error;
52 
53  //Make sure the ACME-DNS client context is valid
54  if(context == NULL)
56 
57  //Clear ACME-DNS client context
58  osMemset(context, 0, sizeof(AcmeDnsClientContext));
59 
60  //Initialize HTTP client context
61  error = httpClientInit(&context->httpClientContext);
62  //Any error to report?
63  if(error)
64  return error;
65 
66  //Initialize ACME-DNS client state
67  context->state = ACME_DNS_CLIENT_STATE_DISCONNECTED;
68  //Default timeout
69  context->timeout = ACME_DNS_CLIENT_DEFAULT_TIMEOUT;
70 
71  //Successful initialization
72  return NO_ERROR;
73 }
74 
75 
76 #if (ACME_DNS_CLIENT_TLS_SUPPORT == ENABLED)
77 
78 /**
79  * @brief Register TLS initialization callback function
80  * @param[in] context Pointer to the ACME-DNS client context
81  * @param[in] callback TLS initialization callback function
82  * @return Error code
83  **/
84 
87 {
88  //Make sure the ACME-DNS client context is valid
89  if(context == NULL)
91 
92  //Save callback function
93  context->tlsInitCallback = callback;
94 
95  //Successful processing
96  return NO_ERROR;
97 }
98 
99 #endif
100 
101 
102 /**
103  * @brief Set communication timeout
104  * @param[in] context Pointer to the ACME-DNS client context
105  * @param[in] timeout Timeout value, in milliseconds
106  * @return Error code
107  **/
108 
110  systime_t timeout)
111 {
112  //Make sure the ACME-DNS client context is valid
113  if(context == NULL)
115 
116  //Save timeout value
117  context->timeout = timeout;
118 
119  //Successful processing
120  return NO_ERROR;
121 }
122 
123 
124 /**
125  * @brief Set the domain name of the ACME-DNS server
126  * @param[in] context Pointer to the ACME-DNS client context
127  * @param[in] host NULL-terminated string containing the host name
128  * @return Error code
129  **/
130 
132  const char_t *host)
133 {
134  //Check parameters
135  if(context == NULL || host == NULL)
137 
138  //Make sure the length of the host name is acceptable
140  return ERROR_INVALID_LENGTH;
141 
142  //Save host name
143  osStrcpy(context->serverName, host);
144 
145  //Successful processing
146  return NO_ERROR;
147 }
148 
149 
150 /**
151  * @brief Set user name
152  * @param[in] context Pointer to the ACME-DNS client context
153  * @param[in] username NULL-terminated string containing the user name
154  * @return Error code
155  **/
156 
158  const char_t *username)
159 {
160  //Check parameters
161  if(context == NULL || username == NULL)
163 
164  //Make sure the length of the user name is acceptable
166  return ERROR_INVALID_LENGTH;
167 
168  //Save user name
169  osStrcpy(context->username, username);
170 
171  //Successful processing
172  return NO_ERROR;
173 }
174 
175 
176 /**
177  * @brief Set password
178  * @param[in] context Pointer to the ACME-DNS client context
179  * @param[in] password NULL-terminated string containing the password
180  * @return Error code
181  **/
182 
184  const char_t *password)
185 {
186  //Check parameters
187  if(context == NULL || password == NULL)
189 
190  //Make sure the length of the password is acceptable
192  return ERROR_INVALID_LENGTH;
193 
194  //Save password
195  osStrcpy(context->password, password);
196 
197  //Successful processing
198  return NO_ERROR;
199 }
200 
201 
202 /**
203  * @brief Set sub domain
204  * @param[in] context Pointer to the ACME-DNS client context
205  * @param[in] subDomain NULL-terminated string containing the sub domain
206  * @return Error code
207  **/
208 
210  const char_t *subDomain)
211 {
212  //Check parameters
213  if(context == NULL || subDomain == NULL)
215 
216  //Make sure the length of the sub domain is acceptable
218  return ERROR_INVALID_LENGTH;
219 
220  //Save sub domain
221  osStrcpy(context->subDomain, subDomain);
222 
223  //Successful processing
224  return NO_ERROR;
225 }
226 
227 
228 /**
229  * @brief Get user name
230  * @param[in] context Pointer to the ACME-DNS client context
231  * @return NULL-terminated string containing the user name
232  **/
233 
235 {
236  const char_t *username;
237 
238  //Make sure the ACME-DNS client context is valid
239  if(context != NULL)
240  {
241  username = context->username;
242  }
243  else
244  {
245  username = NULL;
246  }
247 
248  //Return the user name
249  return username;
250 }
251 
252 
253 /**
254  * @brief Get password
255  * @param[in] context Pointer to the ACME-DNS client context
256  * @return NULL-terminated string containing the password
257  **/
258 
260 {
261  const char_t *password;
262 
263  //Make sure the ACME-DNS client context is valid
264  if(context != NULL)
265  {
266  password = context->password;
267  }
268  else
269  {
270  password = NULL;
271  }
272 
273  //Return the password
274  return password;
275 }
276 
277 
278 /**
279  * @brief Get sub domain
280  * @param[in] context Pointer to the ACME-DNS client context
281  * @return NULL-terminated string containing the sub domain
282  **/
283 
285 {
286  const char_t *subDomain;
287 
288  //Make sure the ACME-DNS client context is valid
289  if(context != NULL)
290  {
291  subDomain = context->subDomain;
292  }
293  else
294  {
295  subDomain = NULL;
296  }
297 
298  //Return the sub domain
299  return subDomain;
300 }
301 
302 
303 /**
304  * @brief Get full domain
305  * @param[in] context Pointer to the ACME-DNS client context
306  * @return NULL-terminated string containing the full domain
307  **/
308 
310 {
311  const char_t *fullDomain;
312 
313  //Make sure the ACME-DNS client context is valid
314  if(context != NULL)
315  {
316  fullDomain = context->fullDomain;
317  }
318  else
319  {
320  fullDomain = NULL;
321  }
322 
323  //Return the full domain
324  return fullDomain;
325 }
326 
327 
328 /**
329  * @brief Bind the ACME-DNS client to a particular network interface
330  * @param[in] context Pointer to the ACME-DNS client context
331  * @param[in] interface Network interface to be used
332  * @return Error code
333  **/
334 
336  NetInterface *interface)
337 {
338  //Make sure the ACME-DNS client context is valid
339  if(context == NULL)
341 
342  //Explicitly associate the ACME-DNS client with the specified interface
343  context->interface = interface;
344 
345  //Successful processing
346  return NO_ERROR;
347 }
348 
349 
350 /**
351  * @brief Establish a connection with the specified ACME-DNS server
352  * @param[in] context Pointer to the ACME-DNS client context
353  * @param[in] serverIpAddr IP address of the ACME-DNS server to connect to
354  * @param[in] serverPort Port number
355  * @return Error code
356  **/
357 
359  const IpAddr *serverIpAddr, uint16_t serverPort)
360 {
361  error_t error;
362 
363  //Initialize status code
364  error = NO_ERROR;
365 
366  //Make sure the ACME-DNS client context is valid
367  if(context == NULL)
369 
370  //Establish connection with the HTTP server
371  while(!error)
372  {
373  //Check ACME-DNS client state
374  if(context->state == ACME_DNS_CLIENT_STATE_DISCONNECTED)
375  {
376  //Save the TCP port number to be used
377  context->serverPort = serverPort;
378 
379 #if (ACME_DNS_CLIENT_TLS_SUPPORT == ENABLED)
380  //Register TLS initialization callback
381  error = httpClientRegisterTlsInitCallback(&context->httpClientContext,
382  context->tlsInitCallback);
383 #endif
384  //Check status code
385  if(!error)
386  {
387  //Select HTTP protocol version
388  error = httpClientSetVersion(&context->httpClientContext,
390  }
391 
392  //Check status code
393  if(!error)
394  {
395  //Set timeout value for blocking operations
396  error = httpClientSetTimeout(&context->httpClientContext,
397  context->timeout);
398  }
399 
400  //Check status code
401  if(!error)
402  {
403  //Bind the HTTP client to the relevant network interface
404  error = httpClientBindToInterface(&context->httpClientContext,
405  context->interface);
406  }
407 
408  //Check status code
409  if(!error)
410  {
411  //Establish HTTP connection
412  context->state = ACME_DNS_CLIENT_STATE_CONNECTING;
413  }
414  }
415  else if(context->state == ACME_DNS_CLIENT_STATE_CONNECTING)
416  {
417  //Establish HTTP connection
418  error = httpClientConnect(&context->httpClientContext, serverIpAddr,
419  serverPort);
420 
421  //Check status code
422  if(error == NO_ERROR)
423  {
424  //The HTTP connection is established
425  context->state = ACME_DNS_CLIENT_STATE_CONNECTED;
426  }
427  }
428  else if(context->state == ACME_DNS_CLIENT_STATE_CONNECTED)
429  {
430  //The client is connected to the ACME-DNS server
431  break;
432  }
433  else
434  {
435  //Invalid state
436  error = ERROR_WRONG_STATE;
437  }
438  }
439 
440  //Failed to establish connection with the ACME-DNS server?
441  if(error != NO_ERROR && error != ERROR_WOULD_BLOCK)
442  {
443  //Clean up side effects
444  httpClientClose(&context->httpClientContext);
445  //Update ACME-DNS client state
446  context->state = ACME_DNS_CLIENT_STATE_DISCONNECTED;
447  }
448 
449  //Return status code
450  return error;
451 }
452 
453 
454 /**
455  * @brief Register endpoint
456  * @param[in] context Pointer to the ACME-DNS client context
457  * @return Error code
458  **/
459 
461 {
462  error_t error;
463  size_t n;
464 
465  //Initialize status code
466  error = NO_ERROR;
467 
468  //Perform HTTP request
469  while(!error)
470  {
471  //Check ACME-DNS client state
472  if(context->state == ACME_DNS_CLIENT_STATE_CONNECTED)
473  {
474  //Format the POST request (register endpoint)
475  error = acmeDnsClientFormatRegisterRequest(context);
476 
477  //Check status code
478  if(!error)
479  {
480  //Update ACME-DNS client state
481  context->state = ACME_DNS_CLIENT_STATE_SEND_HEADER;
482  }
483  }
484  else if(context->state == ACME_DNS_CLIENT_STATE_SEND_HEADER)
485  {
486  //Send HTTP request header
487  error = httpClientWriteHeader(&context->httpClientContext);
488 
489  //Check status code
490  if(!error)
491  {
492  //Update ACME-DNS client state
493  context->state = ACME_DNS_CLIENT_STATE_RECEIVE_HEADER;
494  }
495  }
496  else if(context->state == ACME_DNS_CLIENT_STATE_RECEIVE_HEADER)
497  {
498  //Receive HTTP response header
499  error = httpClientReadHeader(&context->httpClientContext);
500 
501  //Check status code
502  if(!error)
503  {
504  //Update ACME-DNS client state
505  context->state = ACME_DNS_CLIENT_STATE_PARSE_HEADER;
506  }
507  }
508  else if(context->state == ACME_DNS_CLIENT_STATE_PARSE_HEADER)
509  {
510  //Retrieve HTTP status code
511  context->statusCode = httpClientGetStatus(&context->httpClientContext);
512 
513  //Flush the receive buffer
514  context->bufferLen = 0;
515  context->bufferPos = 0;
516 
517  //Update ACME-DNS client state
518  context->state = ACME_DNS_CLIENT_STATE_RECEIVE_BODY;
519  }
520  else if(context->state == ACME_DNS_CLIENT_STATE_RECEIVE_BODY)
521  {
522  //Receive HTTP response body
523  if(context->bufferLen < ACME_DNS_CLIENT_BUFFER_SIZE)
524  {
525  //Receive more data
526  error = httpClientReadBody(&context->httpClientContext,
527  context->buffer + context->bufferLen,
528  ACME_DNS_CLIENT_BUFFER_SIZE - context->bufferLen, &n, 0);
529 
530  //Check status code
531  if(error == NO_ERROR)
532  {
533  //Advance data pointer
534  context->bufferLen += n;
535  }
536  else if(error == ERROR_END_OF_STREAM)
537  {
538  //The end of the response body has been reached
539  error = NO_ERROR;
540 
541  //Update ACME-DNS client state
542  context->state = ACME_DNS_CLIENT_STATE_CLOSE_BODY;
543  }
544  else
545  {
546  //Just for sanity
547  }
548  }
549  else
550  {
551  //Update ACME-DNS client state
552  context->state = ACME_DNS_CLIENT_STATE_CLOSE_BODY;
553  }
554  }
555  else if(context->state == ACME_DNS_CLIENT_STATE_CLOSE_BODY)
556  {
557  //Close HTTP response body
558  error = httpClientCloseBody(&context->httpClientContext);
559 
560  //Check status code
561  if(!error)
562  {
563  //Update ACME-DNS client state
564  context->state = ACME_DNS_CLIENT_STATE_PARSE_BODY;
565  }
566  }
567  else if(context->state == ACME_DNS_CLIENT_STATE_PARSE_BODY)
568  {
569  //Properly terminate the body with a NULL character
570  context->buffer[context->bufferLen] = '\0';
571 
572  //Debug message
573  TRACE_DEBUG("HTTP response body (%" PRIuSIZE " bytes):\r\n", context->bufferLen);
574  TRACE_DEBUG("%s\r\n\r\n", context->buffer);
575 
576  //Parse the body of the HTTP response
577  error = acmeDnsClientParseRegisterResponse(context);
578 
579  //The HTTP transaction is complete
580  context->state = ACME_DNS_CLIENT_STATE_CONNECTED;
581  break;
582  }
583  else
584  {
585  //Invalid state
586  error = ERROR_WRONG_STATE;
587  }
588  }
589 
590  //Return status code
591  return error;
592 }
593 
594 
595 /**
596  * @brief Update endpoint
597  * @param[in] context Pointer to the ACME-DNS client context
598  * @param[in] txt NULL-terminated string that contains the value of the TXT record
599  * @return Error code
600  **/
601 
603 {
604  error_t error;
605  size_t n;
606 
607  //Initialize status code
608  error = NO_ERROR;
609 
610  //Perform HTTP request
611  while(!error)
612  {
613  //Check ACME-DNS client state
614  if(context->state == ACME_DNS_CLIENT_STATE_CONNECTED)
615  {
616  //Format the POST request (update endpoint)
617  error = acmeDnsClientFormatUpdateRequest(context, txt);
618 
619  //Check status code
620  if(!error)
621  {
622  //Update ACME-DNS client state
623  context->state = ACME_DNS_CLIENT_STATE_SEND_HEADER;
624  }
625  }
626  else if(context->state == ACME_DNS_CLIENT_STATE_SEND_HEADER)
627  {
628  //Send HTTP request header
629  error = httpClientWriteHeader(&context->httpClientContext);
630 
631  //Check status code
632  if(!error)
633  {
634  //Debug message
635  TRACE_DEBUG("HTTP request body (%" PRIuSIZE " bytes):\r\n", context->bufferLen);
636  TRACE_DEBUG("%s\r\n\r\n", context->buffer);
637 
638  //Point to the first byte of the body
639  context->bufferPos = 0;
640 
641  //Send HTTP request body
642  context->state = ACME_DNS_CLIENT_STATE_SEND_BODY;
643  }
644  }
645  else if(context->state == ACME_DNS_CLIENT_STATE_SEND_BODY)
646  {
647  //Send HTTP request body
648  if(context->bufferPos < context->bufferLen)
649  {
650  //Send more data
651  error = httpClientWriteBody(&context->httpClientContext,
652  context->buffer + context->bufferPos,
653  context->bufferLen - context->bufferPos, &n, 0);
654 
655  //Check status code
656  if(!error)
657  {
658  //Advance data pointer
659  context->bufferPos += n;
660  }
661  }
662  else
663  {
664  //Update HTTP request state
665  context->state = ACME_DNS_CLIENT_STATE_RECEIVE_HEADER;
666  }
667  }
668  else if(context->state == ACME_DNS_CLIENT_STATE_RECEIVE_HEADER)
669  {
670  //Receive HTTP response header
671  error = httpClientReadHeader(&context->httpClientContext);
672 
673  //Check status code
674  if(!error)
675  {
676  //Update ACME-DNS client state
677  context->state = ACME_DNS_CLIENT_STATE_PARSE_HEADER;
678  }
679  }
680  else if(context->state == ACME_DNS_CLIENT_STATE_PARSE_HEADER)
681  {
682  //Retrieve HTTP status code
683  context->statusCode = httpClientGetStatus(&context->httpClientContext);
684 
685  //Flush the receive buffer
686  context->bufferLen = 0;
687  context->bufferPos = 0;
688 
689  //Update ACME-DNS client state
690  context->state = ACME_DNS_CLIENT_STATE_RECEIVE_BODY;
691  }
692  else if(context->state == ACME_DNS_CLIENT_STATE_RECEIVE_BODY)
693  {
694  //Receive HTTP response body
695  if(context->bufferLen < ACME_DNS_CLIENT_BUFFER_SIZE)
696  {
697  //Receive more data
698  error = httpClientReadBody(&context->httpClientContext,
699  context->buffer + context->bufferLen,
700  ACME_DNS_CLIENT_BUFFER_SIZE - context->bufferLen, &n, 0);
701 
702  //Check status code
703  if(error == NO_ERROR)
704  {
705  //Advance data pointer
706  context->bufferLen += n;
707  }
708  else if(error == ERROR_END_OF_STREAM)
709  {
710  //The end of the response body has been reached
711  error = NO_ERROR;
712 
713  //Update ACME-DNS client state
714  context->state = ACME_DNS_CLIENT_STATE_CLOSE_BODY;
715  }
716  else
717  {
718  //Just for sanity
719  }
720  }
721  else
722  {
723  //Update ACME-DNS client state
724  context->state = ACME_DNS_CLIENT_STATE_CLOSE_BODY;
725  }
726  }
727  else if(context->state == ACME_DNS_CLIENT_STATE_CLOSE_BODY)
728  {
729  //Close HTTP response body
730  error = httpClientCloseBody(&context->httpClientContext);
731 
732  //Check status code
733  if(!error)
734  {
735  //Update ACME-DNS client state
736  context->state = ACME_DNS_CLIENT_STATE_PARSE_BODY;
737  }
738  }
739  else if(context->state == ACME_DNS_CLIENT_STATE_PARSE_BODY)
740  {
741  //Properly terminate the body with a NULL character
742  context->buffer[context->bufferLen] = '\0';
743 
744  //Debug message
745  TRACE_DEBUG("HTTP response body (%" PRIuSIZE " bytes):\r\n", context->bufferLen);
746  TRACE_DEBUG("%s\r\n\r\n", context->buffer);
747 
748  //Parse the body of the HTTP response
749  error = acmeDnsClientParseUpdateResponse(context);
750 
751  //The HTTP transaction is complete
752  context->state = ACME_DNS_CLIENT_STATE_CONNECTED;
753  break;
754  }
755  else
756  {
757  //Invalid state
758  error = ERROR_WRONG_STATE;
759  }
760  }
761 
762  //Return status code
763  return error;
764 }
765 
766 
767 /**
768  * @brief Gracefully disconnect from the ACME-DNS server
769  * @param[in] context Pointer to the ACME-DNS client context
770  * @return Error code
771  **/
772 
774 {
775  error_t error;
776 
777  //Make sure the ACME-DNS client context is valid
778  if(context == NULL)
780 
781  //Initialize status code
782  error = NO_ERROR;
783 
784  //Gracefully disconnect from the ACME-DNS server
785  while(!error)
786  {
787  //Check ACME-DNS client state
788  if(context->state == ACME_DNS_CLIENT_STATE_CONNECTED)
789  {
790  //Gracefully shutdown HTTP connection
791  context->state = ACME_DNS_CLIENT_STATE_DISCONNECTING;
792  }
793  else if(context->state == ACME_DNS_CLIENT_STATE_DISCONNECTING)
794  {
795  //Gracefully shutdown HTTP connection
796  error = httpClientDisconnect(&context->httpClientContext);
797 
798  //Check status code
799  if(error == NO_ERROR)
800  {
801  //Close HTTP connection
802  httpClientClose(&context->httpClientContext);
803  //Update ACME-DNS client state
804  context->state = ACME_DNS_CLIENT_STATE_DISCONNECTED;
805  }
806  }
807  else if(context->state == ACME_DNS_CLIENT_STATE_DISCONNECTED)
808  {
809  //The client is disconnected from the ACME-DNS server
810  break;
811  }
812  else
813  {
814  //Invalid state
815  error = ERROR_WRONG_STATE;
816  }
817  }
818 
819  //Failed to gracefully disconnect from the ACME-DNS server?
820  if(error != NO_ERROR && error != ERROR_WOULD_BLOCK)
821  {
822  //Close HTTP connection
823  httpClientClose(&context->httpClientContext);
824  //Update ACME-DNS client state
825  context->state = ACME_DNS_CLIENT_STATE_DISCONNECTED;
826  }
827 
828  //Return status code
829  return error;
830 }
831 
832 
833 /**
834  * @brief Close the connection with the ACME-DNS server
835  * @param[in] context Pointer to the ACME-DNS client context
836  * @return Error code
837  **/
838 
840 {
841  //Make sure the ACME-DNS client context is valid
842  if(context == NULL)
844 
845  //Close HTTP connection
846  httpClientClose(&context->httpClientContext);
847  //Update ACME-DNS client state
848  context->state = ACME_DNS_CLIENT_STATE_DISCONNECTED;
849 
850  //Successful processing
851  return NO_ERROR;
852 }
853 
854 
855 /**
856  * @brief Release ACME-DNS client context
857  * @param[in] context Pointer to the ACME-DNS client context
858  **/
859 
861 {
862  //Make sure the ACME-DNS client context is valid
863  if(context != NULL)
864  {
865  //Release HTTP client context
866  httpClientDeinit(&context->httpClientContext);
867 
868  //Clear ACME-DNS client context
869  osMemset(context, 0, sizeof(AcmeDnsClientContext));
870  }
871 }
872 
873 #endif
#define ACME_DNS_CLIENT_MAX_PASSWORD_LEN
error_t httpClientDisconnect(HttpClientContext *context)
Gracefully disconnect from the HTTP server.
Definition: http_client.c:2149
error_t httpClientCloseBody(HttpClientContext *context)
Close HTTP request or response body.
Definition: http_client.c:2012
error_t httpClientBindToInterface(HttpClientContext *context, NetInterface *interface)
Bind the HTTP client to a particular network interface.
Definition: http_client.c:246
@ ERROR_WOULD_BLOCK
Definition: error.h:96
error_t acmeDnsClientSetHost(AcmeDnsClientContext *context, const char_t *host)
Set the domain name of the ACME-DNS server.
IP network address.
Definition: ip.h:90
const char_t * acmeDnsClientGetFullDomain(AcmeDnsClientContext *context)
Get full domain.
error_t httpClientReadBody(HttpClientContext *context, void *data, size_t size, size_t *received, uint_t flags)
Read HTTP response body.
Definition: http_client.c:1646
error_t acmeDnsClientSetSubDomain(AcmeDnsClientContext *context, const char_t *subDomain)
Set sub domain.
ACME-DNS client.
error_t acmeDnsClientDisconnect(AcmeDnsClientContext *context)
Gracefully disconnect from the ACME-DNS server.
const char_t * acmeDnsClientGetSubDomain(AcmeDnsClientContext *context)
Get sub domain.
@ ACME_DNS_CLIENT_STATE_DISCONNECTED
#define osStrlen(s)
Definition: os_port.h:165
@ ACME_DNS_CLIENT_STATE_CONNECTING
@ ERROR_END_OF_STREAM
Definition: error.h:210
Helper functions for ACME-DNS client.
@ ACME_DNS_CLIENT_STATE_SEND_BODY
const char_t * acmeDnsClientGetUsername(AcmeDnsClientContext *context)
Get user name.
error_t httpClientSetVersion(HttpClientContext *context, HttpVersion version)
Set the HTTP protocol version to be used.
Definition: http_client.c:162
@ ERROR_WRONG_STATE
Definition: error.h:209
error_t acmeDnsClientRegister(AcmeDnsClientContext *context)
Register endpoint.
error_t acmeDnsClientParseRegisterResponse(AcmeDnsClientContext *context)
Parse HTTP response (register endpoint)
void httpClientDeinit(HttpClientContext *context)
Release HTTP client context.
Definition: http_client.c:2245
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
error_t httpClientWriteHeader(HttpClientContext *context)
Write HTTP request header.
Definition: http_client.c:1014
error_t
Error codes.
Definition: error.h:43
const char_t * acmeDnsClientGetPassword(AcmeDnsClientContext *context)
Get password.
@ ACME_DNS_CLIENT_STATE_RECEIVE_HEADER
error_t httpClientRegisterTlsInitCallback(HttpClientContext *context, HttpClientTlsInitCallback callback)
Register TLS initialization callback function.
Definition: http_client.c:111
#define NetInterface
Definition: net.h:36
@ ACME_DNS_CLIENT_STATE_CONNECTED
error_t httpClientSetTimeout(HttpClientContext *context, systime_t timeout)
Set communication timeout.
Definition: http_client.c:187
error_t httpClientClose(HttpClientContext *context)
Close the connection with the HTTP server.
Definition: http_client.c:2224
@ ERROR_INVALID_LENGTH
Definition: error.h:111
error_t acmeDnsClientFormatUpdateRequest(AcmeDnsClientContext *context, const char_t *txt)
Format HTTP request body (update endpoint)
#define ACME_DNS_CLIENT_BUFFER_SIZE
error_t httpClientInit(HttpClientContext *context)
Initialize HTTP client context.
Definition: http_client.c:66
error_t acmeDnsClientParseUpdateResponse(AcmeDnsClientContext *context)
Parse HTTP response (update endpoint)
uint_t httpClientGetStatus(HttpClientContext *context)
Retrieve the HTTP status code of the response.
Definition: http_client.c:1512
error_t httpClientReadHeader(HttpClientContext *context)
Read HTTP response header.
Definition: http_client.c:1372
#define AcmeDnsClientContext
uint32_t systime_t
System time.
@ ACME_DNS_CLIENT_STATE_DISCONNECTING
error_t acmeDnsClientSetUsername(AcmeDnsClientContext *context, const char_t *username)
Set user name.
error_t acmeDnsClientFormatRegisterRequest(AcmeDnsClientContext *context)
Format HTTP request body (register endpoint)
#define TRACE_DEBUG(...)
Definition: debug.h:107
@ ACME_DNS_CLIENT_STATE_PARSE_HEADER
char char_t
Definition: compiler_port.h:48
error_t httpClientConnect(HttpClientContext *context, const IpAddr *serverIpAddr, uint16_t serverPort)
Establish a connection with the specified HTTP server.
Definition: http_client.c:269
#define ACME_DNS_CLIENT_DEFAULT_TIMEOUT
#define ACME_DNS_CLIENT_MAX_HOST_LEN
@ ACME_DNS_CLIENT_STATE_RECEIVE_BODY
uint8_t n
@ HTTP_VERSION_1_1
Definition: http_common.h:63
error_t httpClientWriteBody(HttpClientContext *context, const void *data, size_t length, size_t *written, uint_t flags)
Write HTTP request body.
Definition: http_client.c:1137
error_t acmeDnsClientBindToInterface(AcmeDnsClientContext *context, NetInterface *interface)
Bind the ACME-DNS client to a particular network interface.
error_t(* AcmeDnsClientTlsInitCallback)(HttpClientContext *context, TlsContext *tlsContext)
TLS initialization callback function.
@ ACME_DNS_CLIENT_STATE_CLOSE_BODY
#define ACME_DNS_CLIENT_MAX_SUB_DOMAIN_LEN
error_t acmeDnsClientSetPassword(AcmeDnsClientContext *context, const char_t *password)
Set password.
#define PRIuSIZE
@ ACME_DNS_CLIENT_STATE_PARSE_BODY
error_t acmeDnsClientInit(AcmeDnsClientContext *context)
Initialize ACME-DNS client context.
#define osMemset(p, value, length)
Definition: os_port.h:135
error_t acmeDnsClientConnect(AcmeDnsClientContext *context, const IpAddr *serverIpAddr, uint16_t serverPort)
Establish a connection with the specified ACME-DNS server.
error_t acmeDnsClientUpdate(AcmeDnsClientContext *context, const char_t *txt)
Update endpoint.
@ ACME_DNS_CLIENT_STATE_SEND_HEADER
error_t acmeDnsClientSetTimeout(AcmeDnsClientContext *context, systime_t timeout)
Set communication timeout.
error_t acmeDnsClientRegisterTlsInitCallback(AcmeDnsClientContext *context, AcmeDnsClientTlsInitCallback callback)
Register TLS initialization callback function.
#define osStrcpy(s1, s2)
Definition: os_port.h:207
void acmeDnsClientDeinit(AcmeDnsClientContext *context)
Release ACME-DNS client context.
error_t acmeDnsClientClose(AcmeDnsClientContext *context)
Close the connection with the ACME-DNS server.
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
#define ACME_DNS_CLIENT_MAX_USERNAME_LEN