Lines Matching +full:- +full:ttext +full:- +full:segment
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3 /* coap-client -- simple CoAP client
5 * Copyright (C) 2010--2023 Olaf Bergmann <bergmann@tzi.org> and others
7 * SPDX-License-Identifier: BSD-2-Clause
108 static char *ca_file = NULL; /* CA for cert_file - for cert checking in PEM,
118 static int verify_peer_cert = 1; /* PKI granularity - by default set */
169 if (!output_file.s || (output_file.length && output_file.s[0] == '-')) { in append_to_output()
174 return -1; in append_to_output()
181 len -= written; in append_to_output()
193 /* add a newline before closing if no option '-o' was specified */ in close_output()
220 memcpy(tracked_tokens[tracked_tokens_count].token->s, token, tokenlen); in track_new_token()
246 if (tracked_tokens_count-i > 1) { in track_flush_token()
249 (tracked_tokens_count-i-1) * sizeof(tracked_tokens[0])); in track_flush_token()
251 tracked_tokens_count--; in track_flush_token()
284 memcpy(&the_token.s[the_token.length - tokenlen], token, tokenlen); in coap_new_request()
461 while (len--) { in message_handler()
490 fprintf(stderr, "%s v%s -- a small CoAP implementation\n" in usage()
491 "Copyright (C) 2010-2023 Olaf Bergmann <bergmann@tzi.org> and others\n\n" in usage()
498 "Usage: %s [-a addr] [-b [num,]size] [-e text] [-f file] [-l loss]\n" in usage()
499 "\t\t[-m method] [-o file] [-p port] [-r] [-s duration] [-t type]\n" in usage()
500 "\t\t[-v num] [-w] [-A type] [-B seconds]\n" in usage()
501 "\t\t[-E oscore_conf_file[,seq_file]] [-G count] [-H hoplimit]\n" in usage()
502 "\t\t[-K interval] [-N] [-O num,text] [-P scheme://address[:port]\n" in usage()
503 "\t\t[-T token] [-U] [-V num] [-X size]\n" in usage()
504 "\t\t[[-h match_hint_file] [-k key] [-u user]]\n" in usage()
505 "\t\t[[-c certfile] [-j keyfile] [-n] [-C cafile]\n" in usage()
506 "\t\t[-J pkcs11_pin] [-M raw_pk] [-R trust_casfile]\n" in usage()
507 "\t\t[-S match_pki_sni_file]] URI\n" in usage()
510 "\t-a addr\t\tThe local interface address to use\n" in usage()
511 "\t-b [num,]size\tBlock size to be used in GET/PUT/POST requests\n" in usage()
515 "\t-e text\t\tInclude text as payload (use percent-encoding for\n" in usage()
516 "\t \t\tnon-ASCII characters)\n" in usage()
517 "\t-f file\t\tFile to send with PUT/POST (use '-' for STDIN)\n" in usage()
518 "\t-l list\t\tFail to send some datagrams specified by a comma\n" in usage()
521 "\t-l loss%%\tRandomly fail to send datagrams with the specified\n" in usage()
522 "\t \t\tprobability - 100%% all datagrams, 0%% no datagrams\n" in usage()
523 "\t-m method\tRequest method (get|put|post|delete|fetch|patch|ipatch),\n" in usage()
525 "\t-o file\t\tOutput received data to this file (use '-' for STDOUT)\n" in usage()
526 "\t-p port\t\tSend from the specified port\n" in usage()
527 "\t-r \t\tUse reliable protocol (TCP or TLS); requires TCP support\n" in usage()
528 "\t-s duration\tSubscribe to / Observe resource for given duration\n" in usage()
530 "\t-t type\t\tContent format for given resource for PUT/POST\n" in usage()
531 "\t-v num \t\tVerbosity level (default 4, maximum is 8) for general\n" in usage()
533 "\t-w \t\tAppend a newline to received data\n" in usage()
534 "\t-A type\t\tAccepted media type\n" in usage()
535 "\t-B seconds\tBreak operation after waiting given seconds\n" in usage()
537 "\t-E oscore_conf_file[,seq_file]\n" in usage()
539 "\t \t\tcoap-oscore-conf(5) for definitions.\n" in usage()
542 "\t-G count\tRepeat the Request 'count' times with a second delay\n" in usage()
545 "\t-H hoplimit\tSet the Hop Limit count to hoplimit for proxies. Must\n" in usage()
548 "\t-K interval\tSend a ping after interval seconds of inactivity\n" in usage()
549 "\t-L value\tSum of one or more COAP_BLOCK_* flag valuess for block\n" in usage()
552 "\t-N \t\tSend NON-confirmable message\n" in usage()
553 "\t-O num,text\tAdd option num with contents text to request. If the\n" in usage()
554 "\t \t\ttext begins with 0x, then the hex text (two [0-9a-f] per\n" in usage()
556 "\t-P scheme://address[:port]\n" in usage()
558 "\t \t\tconnect to a CoAP proxy (automatically adds Proxy-Uri\n" in usage()
561 "\t-T token\tDefine the initial starting token (up to 24 characters)\n" in usage()
562 "\t-U \t\tNever include Uri-Host or Uri-Port options\n" in usage()
563 "\t-V num \t\tVerbosity level (default 3, maximum is 7) for (D)TLS\n" in usage()
565 "\t-X size\t\tMaximum message size to use for TCP based connections\n" in usage()
566 "\t \t\t(default is 8388864). Maximum value of 2^32 -1\n" in usage()
570 "\t-h match_hint_file\n" in usage()
573 "\t \t\tuser identity and associated pre-shared key (PSK) (comma\n" in usage()
574 "\t \t\tseparated) instead of the '-k key' and '-u user'\n" in usage()
577 "\t \t\tNote: -k and -u still need to be defined for the default\n" in usage()
579 "\t-k key \t\tPre-shared key for the specified user identity\n" in usage()
580 "\t-u user\t\tUser identity to send for pre-shared key mode\n" in usage()
582 "\tNote: If any one of '-c certfile', '-j keyfile' or '-C cafile' is in\n" in usage()
585 "\tOtherwise all of '-c certfile', '-j keyfile' or '-C cafile' are in\n" in usage()
587 "\t-c certfile\tPEM file or PKCS11 URI for the certificate. The private\n" in usage()
589 "\t \t\tURI. If not, the private key is defined by '-j keyfile'\n" in usage()
590 "\t-j keyfile\tPEM file or PKCS11 URI for the private key for the\n" in usage()
591 "\t \t\tcertificate in '-c certfile' if the parameter is\n" in usage()
592 "\t \t\tdifferent from certfile in '-c certfile'\n" in usage()
593 "\t-n \t\tDisable remote peer certificate checking\n" in usage()
594 "\t-C cafile\tPEM file or PKCS11 URI for the CA certificate that was\n" in usage()
599 "\t \t\tUsing the -C or -R options will trigger the\n" in usage()
601 "\t \t\tby the -n option\n" in usage()
602 "\t-J pkcs11_pin\tThe user pin to unlock access to the PKCS11 token\n" in usage()
603 "\t-M rpk_file\tRaw Public Key (RPK) PEM file or PKCS11 URI that\n" in usage()
606 "\t \t\t'-C cafile' or '-R trust_casfile' are not required\n" in usage()
607 "\t-R trust_casfile\n" in usage()
612 "\t \t\tUsing '-R trust_casfile' disables common CA mutual\n" in usage()
614 "\t \t\t'-C cafile'.\n" in usage()
615 "\t \t\tUsing the -C or -R options will will trigger the\n" in usage()
617 "\t \t\tby the -n option\n" in usage()
621 "\tcoap-client -m get coap://[::1]/\n" in usage()
622 "\tcoap-client -m get coap://[::1]/.well-known/core\n" in usage()
623 "\tcoap-client -m get coap+tcp://[::1]/.well-known/core\n" in usage()
624 "\tcoap-client -m get coap://%%2Funix%%2Fdomain%%2Fpath%%2Fdgram/.well-known/core\n" in usage()
625 "\tcoap-client -m get coap+tcp://%%2Funix%%2Fdomain%%2Fpath%%2Fstream/.well-known/core\n" in usage()
626 "\tcoap-client -m get coaps://[::1]/.well-known/core\n" in usage()
627 "\tcoap-client -m get coaps+tcp://[::1]/.well-known/core\n" in usage()
628 "\tcoap-client -m get coaps://%%2Funix%%2Fdomain%%2Fpath%%2Fdtls/.well-known/core\n" in usage()
629 "\tcoap-client -m get coaps+tcp://%%2Funix%%2Fdomain%%2Fpath%%2Ftls/.well-known/core\n" in usage()
630 "\tcoap-client -m get -T cafe coap://[::1]/time\n" in usage()
631 "\techo -n 1000 | coap-client -m put -T cafe coap://[::1]/time -f -\n" in usage()
646 { 40, "link-format" }, in cmdline_content_type()
647 { 40, "application/link-format" }, in cmdline_content_type()
651 { 42, "octet-stream" }, in cmdline_content_type()
652 { 42, "application/octet-stream" }, in cmdline_content_type()
678 coap_log_warn("W: unknown content-format '%s'\n",arg); in cmdline_content_type()
716 if (fstat(fileno(f), &statbuf) == -1) { in read_file_mem()
815 * This function returns 0 on success or -1 on error.
818 * @param create_uri_opts Flags that indicate whether Uri-Host and
819 * Uri-Port should be suppressed.
820 * @return 0 on success, -1 otherwise
826 /* create Proxy-Uri from argument */ in cmdline_uri()
830 return -1; in cmdline_uri()
838 } else { /* split arg into Uri-* options */ in cmdline_uri()
841 return -1; in cmdline_uri()
848 return -1; in cmdline_uri()
857 return -1; in cmdline_uri()
873 size = size * 10 + (*arg++ - '0'); in cmdline_blocksize()
879 /* Random access selection - only handle single response */ in cmdline_blocksize()
896 block.szx = (coap_fls(size >> 4) - 1) & 0x07; in cmdline_blocksize()
903 * Block1, Block2, Q-Block1 or Q-Block2 depending on method. */
968 * param c The hex digit to convert. Must be in [0-9A-Fa-f].
976 return c - 'a' + 10; in hex2char()
978 return c - 'A' + 10; in hex2char()
980 return c - '0'; in hex2char()
989 * param[in] src The null-terminated hex string to convert.
1004 return p - dst; in convert_hex_string()
1012 num = num * 10 + (*arg - '0'); in cmdline_option()
1027 } else { /* null-terminated character string */ in cmdline_option()
1046 coap_log_warn("%s is not a supported CoAP Proxy-Scheme\n", arg); in cmdline_option()
1064 * Decodes percent-encoded characters while copying the string @p seg
1066 * ensure that the percent-encodings are correct (i.e. the character
1071 * @param seg The segment to decode and copy.
1078 while (length--) { in decode_segment()
1084 length -= 2; in decode_segment()
1095 * Runs through the given path (or query) segment and checks if
1096 * percent-encodings are correct. This function returns @c -1 on error
1107 return -1; in check_segment()
1110 length -= 2; in check_segment()
1115 --length; in check_segment()
1129 buf->s = (unsigned char *)coap_malloc(len); in cmdline_input()
1130 if (!buf->s) in cmdline_input()
1133 buf->length = len; in cmdline_input()
1134 decode_segment((unsigned char *)text, strlen(text), buf->s); in cmdline_input()
1148 if (filename[0] == '-' && !filename[1]) { /* read from stdin */ in cmdline_input_from_file()
1149 buf->length = 20000; in cmdline_input_from_file()
1150 buf->s = (unsigned char *)coap_malloc(buf->length); in cmdline_input_from_file()
1151 if (!buf->s) in cmdline_input_from_file()
1169 buf->length = statbuf.st_size; in cmdline_input_from_file()
1170 buf->s = (unsigned char *)coap_malloc(buf->length); in cmdline_input_from_file()
1171 if (!buf->s) { in cmdline_input_from_file()
1177 len = fread(buf->s, 1, buf->length, inputfile); in cmdline_input_from_file()
1179 if (len < 0 || ((size_t)len < buf->length)) { in cmdline_input_from_file()
1182 coap_free(buf->s); in cmdline_input_from_file()
1183 buf->length = 0; in cmdline_input_from_file()
1184 buf->s = NULL; in cmdline_input_from_file()
1187 buf->length = len; in cmdline_input_from_file()
1228 /* Need at least one byte for the pre-shared key */ in cmdline_read_key()
1229 coap_log_crit("Invalid Pre-Shared Key specified\n"); in cmdline_read_key()
1230 return -1; in cmdline_read_key()
1259 valid_ihs.ih_list[valid_ihs.count].hint_match = strndup(cp, tcp-cp); in cmdline_read_hint_check()
1264 coap_new_bin_const((const uint8_t *)cp, tcp-cp); in cmdline_read_hint_check()
1301 snprintf(lhint, sizeof(lhint), "%.*s", (int)hint->length, hint->s); in verify_ih_callback()
1346 * requirements - see 'man coap_encryption'. in setup_pki()
1368 memcpy(client_sni, uri.host.s, min(uri.host.length, sizeof(client_sni)-1)); in setup_pki()
1421 min(uri.host.length, sizeof(client_sni) - 1)); in setup_psk()
1479 /* Non-encrypted session */ in open_session()
1523 "/tmp/coap-client.%d", (int)getpid()); in get_session()
1554 for (info = info_list; info != NULL; info = info->next) { in get_session()
1555 session = open_session(ctx, proto, &info->addr, dst, in get_session()
1566 bind_addr.size = dst->size; in get_session()
1567 bind_addr.addr.sa.sa_family = dst->addr.sa.sa_family; in get_session()
1583 int result = -1; in main()
1594 ssize_t user_length = -1, key_length = 0; in main()
1613 … "a:b:c:e:f:h:j:k:l:m:no:p:rs:t:u:v:wA:B:C:E:G:H:J:K:L:M:NO:P:R:T:UV:X:")) != -1) { in main()
1616 strncpy(node_str, optarg, NI_MAXHOST - 1); in main()
1617 node_str[NI_MAXHOST - 1] = '\0'; in main()
1659 strncpy(port_str, optarg, NI_MAXSERV - 1); in main()
1660 port_str[NI_MAXSERV - 1] = '\0'; in main()
1748 fprintf(stderr, "'-G count' has to be > 0 and < 256\n"); in main()
1794 coap_log_crit("Invalid pre-shared key specified\n"); in main()
1818 proto = info_list->proto; in main()
1819 memcpy(&dst, &info_list->addr, sizeof(dst)); in main()
1862 * [Option '-T token' is used to seed a different value] in main()
1909 repeat_count--; in main()
1940 wait_ms -= result; in main()
1959 obs_ms -= result; in main()
1965 repeat_ms -= (unsigned)result; in main()
1990 repeat_count--; in main()