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-2025 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.5.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  //TLS-secured connection?
381  if(context->tlsInitCallback != NULL)
382  {
383  //Register TLS initialization callback
384  error = httpClientRegisterTlsInitCallback(&context->httpClientContext,
385  acmeDnsClientInitTlsContext, context);
386  }
387 #endif
388  //Check status code
389  if(!error)
390  {
391  //Select HTTP protocol version
392  error = httpClientSetVersion(&context->httpClientContext,
394  }
395 
396  //Check status code
397  if(!error)
398  {
399  //Set timeout value for blocking operations
400  error = httpClientSetTimeout(&context->httpClientContext,
401  context->timeout);
402  }
403 
404  //Check status code
405  if(!error)
406  {
407  //Bind the HTTP client to the relevant network interface
408  error = httpClientBindToInterface(&context->httpClientContext,
409  context->interface);
410  }
411 
412  //Check status code
413  if(!error)
414  {
415  //Establish HTTP connection
416  context->state = ACME_DNS_CLIENT_STATE_CONNECTING;
417  }
418  }
419  else if(context->state == ACME_DNS_CLIENT_STATE_CONNECTING)
420  {
421  //Establish HTTP connection
422  error = httpClientConnect(&context->httpClientContext, serverIpAddr,
423  serverPort);
424 
425  //Check status code
426  if(error == NO_ERROR)
427  {
428  //The HTTP connection is established
429  context->state = ACME_DNS_CLIENT_STATE_CONNECTED;
430  }
431  }
432  else if(context->state == ACME_DNS_CLIENT_STATE_CONNECTED)
433  {
434  //The client is connected to the ACME-DNS server
435  break;
436  }
437  else
438  {
439  //Invalid state
440  error = ERROR_WRONG_STATE;
441  }
442  }
443 
444  //Failed to establish connection with the ACME-DNS server?
445  if(error != NO_ERROR && error != ERROR_WOULD_BLOCK)
446  {
447  //Clean up side effects
448  httpClientClose(&context->httpClientContext);
449  //Update ACME-DNS client state
450  context->state = ACME_DNS_CLIENT_STATE_DISCONNECTED;
451  }
452 
453  //Return status code
454  return error;
455 }
456 
457 
458 /**
459  * @brief Register endpoint
460  * @param[in] context Pointer to the ACME-DNS client context
461  * @return Error code
462  **/
463 
465 {
466  error_t error;
467  size_t n;
468 
469  //Initialize status code
470  error = NO_ERROR;
471 
472  //Perform HTTP request
473  while(!error)
474  {
475  //Check ACME-DNS client state
476  if(context->state == ACME_DNS_CLIENT_STATE_CONNECTED)
477  {
478  //Format the POST request (register endpoint)
479  error = acmeDnsClientFormatRegisterRequest(context);
480 
481  //Check status code
482  if(!error)
483  {
484  //Update ACME-DNS client state
485  context->state = ACME_DNS_CLIENT_STATE_SEND_HEADER;
486  }
487  }
488  else if(context->state == ACME_DNS_CLIENT_STATE_SEND_HEADER)
489  {
490  //Send HTTP request header
491  error = httpClientWriteHeader(&context->httpClientContext);
492 
493  //Check status code
494  if(!error)
495  {
496  //Update ACME-DNS client state
497  context->state = ACME_DNS_CLIENT_STATE_RECEIVE_HEADER;
498  }
499  }
500  else if(context->state == ACME_DNS_CLIENT_STATE_RECEIVE_HEADER)
501  {
502  //Receive HTTP response header
503  error = httpClientReadHeader(&context->httpClientContext);
504 
505  //Check status code
506  if(!error)
507  {
508  //Update ACME-DNS client state
509  context->state = ACME_DNS_CLIENT_STATE_PARSE_HEADER;
510  }
511  }
512  else if(context->state == ACME_DNS_CLIENT_STATE_PARSE_HEADER)
513  {
514  //Retrieve HTTP status code
515  context->statusCode = httpClientGetStatus(&context->httpClientContext);
516 
517  //Flush the receive buffer
518  context->bufferLen = 0;
519  context->bufferPos = 0;
520 
521  //Update ACME-DNS client state
522  context->state = ACME_DNS_CLIENT_STATE_RECEIVE_BODY;
523  }
524  else if(context->state == ACME_DNS_CLIENT_STATE_RECEIVE_BODY)
525  {
526  //Receive HTTP response body
527  if(context->bufferLen < ACME_DNS_CLIENT_BUFFER_SIZE)
528  {
529  //Receive more data
530  error = httpClientReadBody(&context->httpClientContext,
531  context->buffer + context->bufferLen,
532  ACME_DNS_CLIENT_BUFFER_SIZE - context->bufferLen, &n, 0);
533 
534  //Check status code
535  if(error == NO_ERROR)
536  {
537  //Advance data pointer
538  context->bufferLen += n;
539  }
540  else if(error == ERROR_END_OF_STREAM)
541  {
542  //The end of the response body has been reached
543  error = NO_ERROR;
544 
545  //Update ACME-DNS client state
546  context->state = ACME_DNS_CLIENT_STATE_CLOSE_BODY;
547  }
548  else
549  {
550  //Just for sanity
551  }
552  }
553  else
554  {
555  //Update ACME-DNS client state
556  context->state = ACME_DNS_CLIENT_STATE_CLOSE_BODY;
557  }
558  }
559  else if(context->state == ACME_DNS_CLIENT_STATE_CLOSE_BODY)
560  {
561  //Close HTTP response body
562  error = httpClientCloseBody(&context->httpClientContext);
563 
564  //Check status code
565  if(!error)
566  {
567  //Update ACME-DNS client state
568  context->state = ACME_DNS_CLIENT_STATE_PARSE_BODY;
569  }
570  }
571  else if(context->state == ACME_DNS_CLIENT_STATE_PARSE_BODY)
572  {
573  //Properly terminate the body with a NULL character
574  context->buffer[context->bufferLen] = '\0';
575 
576  //Debug message
577  TRACE_DEBUG("HTTP response body (%" PRIuSIZE " bytes):\r\n", context->bufferLen);
578  TRACE_DEBUG("%s\r\n\r\n", context->buffer);
579 
580  //Parse the body of the HTTP response
581  error = acmeDnsClientParseRegisterResponse(context);
582 
583  //The HTTP transaction is complete
584  context->state = ACME_DNS_CLIENT_STATE_CONNECTED;
585  break;
586  }
587  else
588  {
589  //Invalid state
590  error = ERROR_WRONG_STATE;
591  }
592  }
593 
594  //Return status code
595  return error;
596 }
597 
598 
599 /**
600  * @brief Update endpoint
601  * @param[in] context Pointer to the ACME-DNS client context
602  * @param[in] txt NULL-terminated string that contains the value of the TXT record
603  * @return Error code
604  **/
605 
607 {
608  error_t error;
609  size_t n;
610 
611  //Initialize status code
612  error = NO_ERROR;
613 
614  //Perform HTTP request
615  while(!error)
616  {
617  //Check ACME-DNS client state
618  if(context->state == ACME_DNS_CLIENT_STATE_CONNECTED)
619  {
620  //Format the POST request (update endpoint)
621  error = acmeDnsClientFormatUpdateRequest(context, txt);
622 
623  //Check status code
624  if(!error)
625  {
626  //Update ACME-DNS client state
627  context->state = ACME_DNS_CLIENT_STATE_SEND_HEADER;
628  }
629  }
630  else if(context->state == ACME_DNS_CLIENT_STATE_SEND_HEADER)
631  {
632  //Send HTTP request header
633  error = httpClientWriteHeader(&context->httpClientContext);
634 
635  //Check status code
636  if(!error)
637  {
638  //Debug message
639  TRACE_DEBUG("HTTP request body (%" PRIuSIZE " bytes):\r\n", context->bufferLen);
640  TRACE_DEBUG("%s\r\n\r\n", context->buffer);
641 
642  //Point to the first byte of the body
643  context->bufferPos = 0;
644 
645  //Send HTTP request body
646  context->state = ACME_DNS_CLIENT_STATE_SEND_BODY;
647  }
648  }
649  else if(context->state == ACME_DNS_CLIENT_STATE_SEND_BODY)
650  {
651  //Send HTTP request body
652  if(context->bufferPos < context->bufferLen)
653  {
654  //Send more data
655  error = httpClientWriteBody(&context->httpClientContext,
656  context->buffer + context->bufferPos,
657  context->bufferLen - context->bufferPos, &n, 0);
658 
659  //Check status code
660  if(!error)
661  {
662  //Advance data pointer
663  context->bufferPos += n;
664  }
665  }
666  else
667  {
668  //Update HTTP request state
669  context->state = ACME_DNS_CLIENT_STATE_RECEIVE_HEADER;
670  }
671  }
672  else if(context->state == ACME_DNS_CLIENT_STATE_RECEIVE_HEADER)
673  {
674  //Receive HTTP response header
675  error = httpClientReadHeader(&context->httpClientContext);
676 
677  //Check status code
678  if(!error)
679  {
680  //Update ACME-DNS client state
681  context->state = ACME_DNS_CLIENT_STATE_PARSE_HEADER;
682  }
683  }
684  else if(context->state == ACME_DNS_CLIENT_STATE_PARSE_HEADER)
685  {
686  //Retrieve HTTP status code
687  context->statusCode = httpClientGetStatus(&context->httpClientContext);
688 
689  //Flush the receive buffer
690  context->bufferLen = 0;
691  context->bufferPos = 0;
692 
693  //Update ACME-DNS client state
694  context->state = ACME_DNS_CLIENT_STATE_RECEIVE_BODY;
695  }
696  else if(context->state == ACME_DNS_CLIENT_STATE_RECEIVE_BODY)
697  {
698  //Receive HTTP response body
699  if(context->bufferLen < ACME_DNS_CLIENT_BUFFER_SIZE)
700  {
701  //Receive more data
702  error = httpClientReadBody(&context->httpClientContext,
703  context->buffer + context->bufferLen,
704  ACME_DNS_CLIENT_BUFFER_SIZE - context->bufferLen, &n, 0);
705 
706  //Check status code
707  if(error == NO_ERROR)
708  {
709  //Advance data pointer
710  context->bufferLen += n;
711  }
712  else if(error == ERROR_END_OF_STREAM)
713  {
714  //The end of the response body has been reached
715  error = NO_ERROR;
716 
717  //Update ACME-DNS client state
718  context->state = ACME_DNS_CLIENT_STATE_CLOSE_BODY;
719  }
720  else
721  {
722  //Just for sanity
723  }
724  }
725  else
726  {
727  //Update ACME-DNS client state
728  context->state = ACME_DNS_CLIENT_STATE_CLOSE_BODY;
729  }
730  }
731  else if(context->state == ACME_DNS_CLIENT_STATE_CLOSE_BODY)
732  {
733  //Close HTTP response body
734  error = httpClientCloseBody(&context->httpClientContext);
735 
736  //Check status code
737  if(!error)
738  {
739  //Update ACME-DNS client state
740  context->state = ACME_DNS_CLIENT_STATE_PARSE_BODY;
741  }
742  }
743  else if(context->state == ACME_DNS_CLIENT_STATE_PARSE_BODY)
744  {
745  //Properly terminate the body with a NULL character
746  context->buffer[context->bufferLen] = '\0';
747 
748  //Debug message
749  TRACE_DEBUG("HTTP response body (%" PRIuSIZE " bytes):\r\n", context->bufferLen);
750  TRACE_DEBUG("%s\r\n\r\n", context->buffer);
751 
752  //Parse the body of the HTTP response
753  error = acmeDnsClientParseUpdateResponse(context);
754 
755  //The HTTP transaction is complete
756  context->state = ACME_DNS_CLIENT_STATE_CONNECTED;
757  break;
758  }
759  else
760  {
761  //Invalid state
762  error = ERROR_WRONG_STATE;
763  }
764  }
765 
766  //Return status code
767  return error;
768 }
769 
770 
771 /**
772  * @brief Gracefully disconnect from the ACME-DNS server
773  * @param[in] context Pointer to the ACME-DNS client context
774  * @return Error code
775  **/
776 
778 {
779  error_t error;
780 
781  //Make sure the ACME-DNS client context is valid
782  if(context == NULL)
784 
785  //Initialize status code
786  error = NO_ERROR;
787 
788  //Gracefully disconnect from the ACME-DNS server
789  while(!error)
790  {
791  //Check ACME-DNS client state
792  if(context->state == ACME_DNS_CLIENT_STATE_CONNECTED)
793  {
794  //Gracefully shutdown HTTP connection
795  context->state = ACME_DNS_CLIENT_STATE_DISCONNECTING;
796  }
797  else if(context->state == ACME_DNS_CLIENT_STATE_DISCONNECTING)
798  {
799  //Gracefully shutdown HTTP connection
800  error = httpClientDisconnect(&context->httpClientContext);
801 
802  //Check status code
803  if(error == NO_ERROR)
804  {
805  //Close HTTP connection
806  httpClientClose(&context->httpClientContext);
807  //Update ACME-DNS client state
808  context->state = ACME_DNS_CLIENT_STATE_DISCONNECTED;
809  }
810  }
811  else if(context->state == ACME_DNS_CLIENT_STATE_DISCONNECTED)
812  {
813  //The client is disconnected from the ACME-DNS server
814  break;
815  }
816  else
817  {
818  //Invalid state
819  error = ERROR_WRONG_STATE;
820  }
821  }
822 
823  //Failed to gracefully disconnect from the ACME-DNS server?
824  if(error != NO_ERROR && error != ERROR_WOULD_BLOCK)
825  {
826  //Close HTTP connection
827  httpClientClose(&context->httpClientContext);
828  //Update ACME-DNS client state
829  context->state = ACME_DNS_CLIENT_STATE_DISCONNECTED;
830  }
831 
832  //Return status code
833  return error;
834 }
835 
836 
837 /**
838  * @brief Close the connection with the ACME-DNS server
839  * @param[in] context Pointer to the ACME-DNS client context
840  * @return Error code
841  **/
842 
844 {
845  //Make sure the ACME-DNS client context is valid
846  if(context == NULL)
848 
849  //Close HTTP connection
850  httpClientClose(&context->httpClientContext);
851  //Update ACME-DNS client state
852  context->state = ACME_DNS_CLIENT_STATE_DISCONNECTED;
853 
854  //Successful processing
855  return NO_ERROR;
856 }
857 
858 
859 /**
860  * @brief Release ACME-DNS client context
861  * @param[in] context Pointer to the ACME-DNS client context
862  **/
863 
865 {
866  //Make sure the ACME-DNS client context is valid
867  if(context != NULL)
868  {
869  //Release HTTP client context
870  httpClientDeinit(&context->httpClientContext);
871 
872  //Clear ACME-DNS client context
873  osMemset(context, 0, sizeof(AcmeDnsClientContext));
874  }
875 }
876 
877 #endif
#define ACME_DNS_CLIENT_MAX_PASSWORD_LEN
error_t httpClientDisconnect(HttpClientContext *context)
Gracefully disconnect from the HTTP server.
Definition: http_client.c:2202
error_t httpClientCloseBody(HttpClientContext *context)
Close HTTP request or response body.
Definition: http_client.c:2065
error_t(* AcmeDnsClientTlsInitCallback)(AcmeDnsClientContext *context, TlsContext *tlsContext)
TLS initialization callback function.
error_t httpClientBindToInterface(HttpClientContext *context, NetInterface *interface)
Bind the HTTP client to a particular network interface.
Definition: http_client.c:297
@ 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:1699
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:168
@ ACME_DNS_CLIENT_STATE_CONNECTING
@ ERROR_END_OF_STREAM
Definition: error.h:211
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:171
@ ERROR_WRONG_STATE
Definition: error.h:210
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:2298
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
error_t httpClientWriteHeader(HttpClientContext *context)
Write HTTP request header.
Definition: http_client.c:1065
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, void *param)
Register TLS initialization callback function.
Definition: http_client.c:118
#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:196
error_t httpClientClose(HttpClientContext *context)
Close the connection with the HTTP server.
Definition: http_client.c:2277
@ 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:1565
error_t httpClientReadHeader(HttpClientContext *context)
Read HTTP response header.
Definition: http_client.c:1425
#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:119
@ ACME_DNS_CLIENT_STATE_PARSE_HEADER
char char_t
Definition: compiler_port.h:55
error_t httpClientConnect(HttpClientContext *context, const IpAddr *serverIpAddr, uint16_t serverPort)
Establish a connection with the specified HTTP server.
Definition: http_client.c:320
#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:1188
error_t acmeDnsClientBindToInterface(AcmeDnsClientContext *context, NetInterface *interface)
Bind the ACME-DNS client to a particular network interface.
error_t acmeDnsClientInitTlsContext(HttpClientContext *httpClientContext, TlsContext *tlsContext, void *param)
TLS initialization.
@ 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:138
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:210
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