From 420b06b4da98d8e42ecd5545c99ef0e97c8468d0 Mon Sep 17 00:00:00 2001 From: zhangyong Date: Wed, 13 Dec 2023 11:04:13 +0800 Subject: [PATCH] fix(coap-4.3): fix coap-4.30 printf to os_kprintf. --- .../libcoap-v4.3.0/examples/coap-client.c | 42 +++++++++---------- .../libcoap-v4.3.0/examples/coap-server.c | 14 +++---- .../examples/contiki/coap-observer.c | 6 +-- .../libcoap-v4.3.0/examples/contiki/server.c | 4 +- .../coap/libcoap-v4.3.0/examples/getopt.c | 4 +- .../libcoap-v4.3.0/examples/lwip/server.c | 4 +- .../coap/libcoap-v4.3.0/src/coap_debug.c | 8 ++-- .../protocols/coap/libcoap-v4.3.0/src/net.c | 4 +- 8 files changed, 43 insertions(+), 43 deletions(-) diff --git a/components/net/protocols/coap/libcoap-v4.3.0/examples/coap-client.c b/components/net/protocols/coap/libcoap-v4.3.0/examples/coap-client.c index 88384dd17..0a2917250 100644 --- a/components/net/protocols/coap/libcoap-v4.3.0/examples/coap-client.c +++ b/components/net/protocols/coap/libcoap-v4.3.0/examples/coap-client.c @@ -201,7 +201,7 @@ static int append_to_output(const uint8_t *data, size_t len) { if (NULL == (file = fopen((char *)output_file.s, "w"))) { - printf("fopen\r\n"); + os_kprintf("fopen\r\n"); return -1; } } @@ -212,9 +212,9 @@ static int append_to_output(const uint8_t *data, size_t len) for (int i = 0; i < len; i++) { if (data[i] == '\n') - printf("\r\n"); + os_kprintf("\r\n"); else - printf("%c", data[i]); + os_kprintf("%c", data[i]); } } else @@ -300,7 +300,7 @@ static int resolve_address(const coap_str_const_t *server, struct sockaddr *dst) if (ret != 0) { - printf("getaddrinfo: %s\r\n", gai_strerror(ret)); + os_kprintf("getaddrinfo: %s\r\n", gai_strerror(ret)); return -1; } @@ -458,17 +458,17 @@ static coap_response_t message_handler(coap_session_t *session COAP_UNUSED, /* check if an error was signaled and output payload if so */ if (COAP_RESPONSE_CLASS(rcv_code) >= 4) { - printf("%d.%02d", COAP_RESPONSE_CLASS(rcv_code), rcv_code & 0x1F); + os_kprintf("%d.%02d", COAP_RESPONSE_CLASS(rcv_code), rcv_code & 0x1F); if (coap_get_data_large(received, &len, &databuf, &offset, &total)) { - printf(" "); + os_kprintf(" "); while (len--) { - printf("%c", isprint(*databuf) ? *databuf : '.'); + os_kprintf("%c", isprint(*databuf) ? *databuf : '.'); databuf++; } } - printf("\r\n"); + os_kprintf("\r\n"); } } @@ -487,7 +487,7 @@ static void usage(const char *program, const char *version) if (p) program = ++p; - printf("%s v%s -- a small CoAP implementation\r\n" + os_kprintf("%s v%s -- a small CoAP implementation\r\n" "Copyright (C) 2010-2021 Olaf Bergmann and others\r\n\r\n" "%s\r\n" "%s\r\n", @@ -495,8 +495,8 @@ static void usage(const char *program, const char *version) version, lib_version, coap_string_tls_version(buffer, sizeof(buffer))); - printf("%s\r\n", coap_string_tls_support(buffer, sizeof(buffer))); - printf("\r\n" + os_kprintf("%s\r\n", coap_string_tls_support(buffer, sizeof(buffer))); + os_kprintf("\r\n" "Usage: %s [-a addr] [-b [num,]size] [-e text] [-f file] [-l loss]\r\n" "\t\t[-m method] [-o file] [-p port] [-r] [-s duration] [-t type]\r\n" "\t\t[-v num] [-w] [-A type] [-B seconds] [-H hoplimit] [-K interval]\r\n" @@ -553,7 +553,7 @@ static void usage(const char *program, const char *version) "\t-U \t\tNever include Uri-Host or Uri-Port options\r\n", program, wait_seconds); - printf("PSK Options (if supported by underlying (D)TLS library)\r\n" + os_kprintf("PSK Options (if supported by underlying (D)TLS library)\r\n" "\t-h match_hint_file\r\n" "\t \t\tThis is a file that contains one or more lines of\r\n" "\t \t\treceived Identity Hints to match to use different\r\n" @@ -601,7 +601,7 @@ static void usage(const char *program, const char *version) "\t \t\tUsing the -C or -R options will will trigger the\r\n" "\t \t\tvalidation of the server certificate unless overridden\r\n" "\t \t\tby the -n option\n"); - printf("Examples:\r\n" + os_kprintf("Examples:\r\n" "\tcoap_client -m get coap://[::1]/\r\n" "\tcoap_client -m get coap://[::1]/.well-known/core\r\n" "\tcoap_client -m get coap+tcp://[::1]/.well-known/core\r\n" @@ -1502,7 +1502,7 @@ static coap_session_t *get_session(coap_context_t *ctx, s = getaddrinfo(local_addr, local_port, &hints, &result); if (s != 0) { - printf("getaddrinfo: %s\r\n", gai_strerror(s)); + os_kprintf("getaddrinfo: %s\r\n", gai_strerror(s)); return NULL; } @@ -1605,7 +1605,7 @@ int coap_client(int argc, char **argv) block_mode = strtoul(coap_optarg, NULL, 0); if (!(block_mode & COAP_BLOCK_USE_LIBCOAP)) { - printf("Block mode must include COAP_BLOCK_USE_LIBCOAP (1)\r\n"); + os_kprintf("Block mode must include COAP_BLOCK_USE_LIBCOAP (1)\r\n"); return (-1); } break; @@ -1632,7 +1632,7 @@ int coap_client(int argc, char **argv) if (!output_file.s) { - printf("cannot set output file: insufficient memory\r\n"); + os_kprintf("cannot set output file: insufficient memory\r\n"); return (-1); } else @@ -1660,7 +1660,7 @@ int coap_client(int argc, char **argv) case 'P': if (!cmdline_proxy(coap_optarg)) { - printf("error specifying proxy address\r\n"); + os_kprintf("error specifying proxy address\r\n"); return (-1); } break; @@ -1698,7 +1698,7 @@ int coap_client(int argc, char **argv) break; case 'H': if (!cmdline_hop_limit(coap_optarg)) - printf("Hop Limit has to be > 0 and < 256\n"); + os_kprintf("Hop Limit has to be > 0 and < 256\n"); break; #if defined(COAP_4_3_0_WITH_MBEDTLS) case 'n': @@ -1752,7 +1752,7 @@ int coap_client(int argc, char **argv) if (res < 0) { - printf("failed to resolve address\r\n"); + os_kprintf("failed to resolve address\r\n"); return (-1); } @@ -1936,7 +1936,7 @@ static void coap_client_task(void *param) coap_client(param_argc, param_argv); coap_param_free(); client_task = NULL; - printf("\r\nExit coap client task!\r\n"); + os_kprintf("\r\nExit coap client task!\r\n"); } static int coap_client_entry(int argc, char **argv) @@ -1950,7 +1950,7 @@ static int coap_client_entry(int argc, char **argv) } while (client_task != NULL) { - printf("Wait for the last task ending!\n"); + os_kprintf("Wait for the last task ending!\n"); os_task_msleep(1 * 1000); } param_argv = malloc(sizeof(char *) * argc); diff --git a/components/net/protocols/coap/libcoap-v4.3.0/examples/coap-server.c b/components/net/protocols/coap/libcoap-v4.3.0/examples/coap-server.c index f8c8ee401..6c0e2d9b8 100644 --- a/components/net/protocols/coap/libcoap-v4.3.0/examples/coap-server.c +++ b/components/net/protocols/coap/libcoap-v4.3.0/examples/coap-server.c @@ -2290,7 +2290,7 @@ static void usage(const char *program, const char *version) if (p) program = ++p; - printf("%s v%s -- a small CoAP implementation\r\n" + os_kprintf("%s v%s -- a small CoAP implementation\r\n" "(c) 2010,2011,2015-2021 Olaf Bergmann and others\r\n\r\n" "%s\r\n" "%s\r\n", @@ -2298,8 +2298,8 @@ static void usage(const char *program, const char *version) version, lib_version, coap_string_tls_version(buffer, sizeof(buffer))); - printf("%s\r\n", coap_string_tls_support(buffer, sizeof(buffer))); - printf("\r\n" + os_kprintf("%s\r\n", coap_string_tls_support(buffer, sizeof(buffer))); + os_kprintf("\r\n" "Usage: %s [-d max] [-e] [-g group] [-G group_if] [-l loss] [-p port]\r\n" "\t\t[-v num] [-A address] [-L value] [-N]\r\n" "\t\t[-P scheme://address[:port],name1[,name2..]]\r\n" @@ -2338,7 +2338,7 @@ static void usage(const char *program, const char *version) "\t \t\tevery fifth response will still be sent as a confirmable\r\n" "\t \t\tresponse (RFC 7641 requirement)\r\n", program); - printf("\t-P scheme://address[:port],name1[,name2[,name3..]]\tScheme, address,\r\n" + os_kprintf("\t-P scheme://address[:port],name1[,name2[,name3..]]\tScheme, address,\r\n" "\t \t\toptional port of how to connect to the next proxy server\r\n" "\t \t\tand one or more names (comma separated) that this proxy\r\n" "\t \t\tserver is known by. If the hostname of the incoming proxy\r\n" @@ -2378,7 +2378,7 @@ static void usage(const char *program, const char *version) "\t \t\t-s followed by -i\r\n" "\t-u user\t\tUser identity for pre-shared key mode (only used if\r\n" "\t \t\toption -P is set)\r\n"); - printf("PKI Options (if supported by underlying (D)TLS library)\r\n" + os_kprintf("PKI Options (if supported by underlying (D)TLS library)\r\n" "\tNote: If any one of '-c certfile', '-j keyfile' or '-C cafile' is in\r\n" "\tPKCS11 URI naming format (pkcs11: prefix), then any remaining non\r\n" "\tPKCS11 URI file definitions have to be in DER, not PEM, format.\r\n" @@ -3214,7 +3214,7 @@ static void coap_server_task(void *param) coap_server(param_argc, param_argv); coap_param_free(); server_task = NULL; - printf("\r\nExit coap server task!\r\n"); + os_kprintf("\r\nExit coap server task!\r\n"); } static int coap_server_entry(int argc, char **argv) @@ -3228,7 +3228,7 @@ static int coap_server_entry(int argc, char **argv) while (server_task != NULL) { os_task_msleep(1 * 1000); - printf("Wait for the last task ending!\n"); + os_kprintf("Wait for the last task ending!\n"); } param_argv = malloc(sizeof(char *) * argc); if (param_argv == NULL) diff --git a/components/net/protocols/coap/libcoap-v4.3.0/examples/contiki/coap-observer.c b/components/net/protocols/coap/libcoap-v4.3.0/examples/contiki/coap-observer.c index 2bab1abfa..5be1ff49b 100644 --- a/components/net/protocols/coap/libcoap-v4.3.0/examples/contiki/coap-observer.c +++ b/components/net/protocols/coap/libcoap-v4.3.0/examples/contiki/coap-observer.c @@ -65,13 +65,13 @@ void init_coap() uip_ds6_addr_add(&listen_addr.addr, 0, ADDR_AUTOCONF); uip_debug_lladdr_print(&uip_lladdr); - printf("\r\n"); + os_kprintf("\r\n"); uip_debug_ipaddr_print(&listen_addr.addr); - printf("\r\n"); + os_kprintf("\r\n"); #endif /* WITH_CONTIKI */ #ifdef WITH_CONTIKI - printf("tentative address: [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n", + os_kprintf("tentative address: [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n", listen_addr.addr.u8[0], listen_addr.addr.u8[1], listen_addr.addr.u8[2], diff --git a/components/net/protocols/coap/libcoap-v4.3.0/examples/contiki/server.c b/components/net/protocols/coap/libcoap-v4.3.0/examples/contiki/server.c index 047f2c16a..823bef73e 100644 --- a/components/net/protocols/coap/libcoap-v4.3.0/examples/contiki/server.c +++ b/components/net/protocols/coap/libcoap-v4.3.0/examples/contiki/server.c @@ -74,9 +74,9 @@ void init_coap_server(coap_context_t **ctx) uip_ds6_defrt_add(&gw_addr, 0); PRINTLLADDR(&uip_lladdr); - printf("\r\n"); + os_kprintf("\r\n"); PRINT6ADDR(&listen_addr.addr); - printf("\r\n"); + os_kprintf("\r\n"); *ctx = coap_new_context(&listen_addr); diff --git a/components/net/protocols/coap/libcoap-v4.3.0/examples/getopt.c b/components/net/protocols/coap/libcoap-v4.3.0/examples/getopt.c index bebe68661..2f8c1debb 100644 --- a/components/net/protocols/coap/libcoap-v4.3.0/examples/getopt.c +++ b/components/net/protocols/coap/libcoap-v4.3.0/examples/getopt.c @@ -39,7 +39,7 @@ static int coap_getopt(int argc, char *argv[], char *opts) coap_optopt = c = argv[coap_optind][sp]; if (c == ':' || NULL == (cp = strchr(opts, c))) { - printf(": illegal option -- %c\r\n", c); + os_kprintf(": illegal option -- %c\r\n", c); if (argv[coap_optind][++sp] == '\0') { coap_optind++; @@ -53,7 +53,7 @@ static int coap_getopt(int argc, char *argv[], char *opts) coap_optarg = &argv[coap_optind++][sp + 1]; else if (++coap_optind >= argc) { - printf(": option requires an argument -- %c\r\n", c); + os_kprintf(": option requires an argument -- %c\r\n", c); sp = 1; return '?'; } diff --git a/components/net/protocols/coap/libcoap-v4.3.0/examples/lwip/server.c b/components/net/protocols/coap/libcoap-v4.3.0/examples/lwip/server.c index 0886e75db..447b57ca7 100644 --- a/components/net/protocols/coap/libcoap-v4.3.0/examples/lwip/server.c +++ b/components/net/protocols/coap/libcoap-v4.3.0/examples/lwip/server.c @@ -60,7 +60,7 @@ int main(int argc, char **argv) lwip_init(); - printf("TCP/IP initialized.\n"); + os_kprintf("TCP/IP initialized.\n"); netif_add(&netif, &ipaddr, &netmask, &gw, NULL, tapif_init, ethernet_input); netif.flags |= NETIF_FLAG_ETHARP; @@ -74,7 +74,7 @@ int main(int argc, char **argv) server_coap_init(); - printf("Applications started.\n"); + os_kprintf("Applications started.\n"); while (1) { diff --git a/components/net/protocols/coap/libcoap-v4.3.0/src/coap_debug.c b/components/net/protocols/coap/libcoap-v4.3.0/src/coap_debug.c index b09e8d007..167839249 100644 --- a/components/net/protocols/coap/libcoap-v4.3.0/src/coap_debug.c +++ b/components/net/protocols/coap/libcoap-v4.3.0/src/coap_debug.c @@ -531,7 +531,7 @@ COAP_STATIC_INLINE int is_binary(int content_format) { \ if (use_fprintf_for_show_pdu) \ { \ - printf("%s", outbuf); \ + os_kprintf("%s", outbuf); \ } \ else \ { \ @@ -1014,17 +1014,17 @@ void coap_log_impl(coap_log_t level, const char *format, ...) coap_ticks(&now); len = print_timestamp(timebuf, sizeof(timebuf), now); if (len) - printf("%.*s ", (int)len, timebuf); + os_kprintf("%.*s ", (int)len, timebuf); if (level <= COAP_LOG_CIPHERS) - printf("%s ", loglevels[level]); + os_kprintf("%s ", loglevels[level]); va_start(ap, format); vfprintf(log_fd, format, ap); va_end(ap); fflush(log_fd); } - printf("\r\n"); + os_kprintf("\r\n"); } static struct packet_num_interval diff --git a/components/net/protocols/coap/libcoap-v4.3.0/src/net.c b/components/net/protocols/coap/libcoap-v4.3.0/src/net.c index 24d8d1047..93d49d927 100644 --- a/components/net/protocols/coap/libcoap-v4.3.0/src/net.c +++ b/components/net/protocols/coap/libcoap-v4.3.0/src/net.c @@ -3935,7 +3935,7 @@ static void coap_retransmittimer_restart(coap_context_t *ctx) if (ctx->timer_configured) { - printf("clearing\n"); + os_kprintf("clearing\n"); sys_untimeout(coap_retransmittimer_execute, (void *)ctx); ctx->timer_configured = 0; } @@ -3963,7 +3963,7 @@ static void coap_retransmittimer_restart(coap_context_t *ctx) delay = 0; } - printf("scheduling for %d ticks\n", delay); + os_kprintf("scheduling for %d ticks\n", delay); sys_timeout(delay, coap_retransmittimer_execute, (void *)ctx); ctx->timer_configured = 1; } -- Gitee