File size: 24,449 Bytes
910a777 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 |
diff --git a/.gitignore b/.gitignore
index 55768f6ed..afc0724aa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: curl
+curl-install/*
*.asc
*.dll
*.exe
diff --git a/include/curl/curl.h b/include/curl/curl.h
index 18835586a..e3af00ca2 100644
--- a/include/curl/curl.h
+++ b/include/curl/curl.h
@@ -1078,6 +1078,7 @@ typedef CURLSTScode (*curl_hstswrite_callback)(CURL *easy,
#define CURLPROTO_SMBS (1<<27)
#define CURLPROTO_MQTT (1<<28)
#define CURLPROTO_GOPHERS (1<<29)
+#define CURLPROTO_VERYNORMAL (1<<30)
#define CURLPROTO_ALL (~0) /* enable everything */
/* long may be 32 or 64 bits, but we should never depend on anything else
diff --git a/lib/Makefile.inc b/lib/Makefile.inc
index 1d3f69a23..70c313e7c 100644
--- a/lib/Makefile.inc
+++ b/lib/Makefile.inc
@@ -235,6 +235,7 @@ LIB_CFILES = \
urlapi.c \
version.c \
version_win32.c \
+ verynormalprotocol.c \
warnless.c \
ws.c
diff --git a/lib/url.c b/lib/url.c
index 436edd891..cc5fd0184 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -119,6 +119,7 @@
#include "altsvc.h"
#include "dynbuf.h"
#include "headers.h"
+#include "verynormalprotocol.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
@@ -1600,6 +1601,8 @@ const struct Curl_handler *Curl_getn_scheme_handler(const char *scheme,
NULL,
#endif
};
+ if(strcmp(scheme, "verynormalprotocol") == 0)
+ return &Curl_handler_verynormalprotocol;
if(len && (len <= 7)) {
const char *s = scheme;
diff --git a/lib/urldata.h b/lib/urldata.h
index 704fb7a1d..3a02c1496 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -52,6 +52,7 @@
#define PORT_RTMPS PORT_HTTPS
#define PORT_GOPHER 70
#define PORT_MQTT 1883
+#define PORT_VERYNORMAL 6666
struct curl_trc_featt;
diff --git a/lib/verynormalprotocol.c b/lib/verynormalprotocol.c
new file mode 100644
index 000000000..6b53dc359
--- /dev/null
+++ b/lib/verynormalprotocol.c
@@ -0,0 +1,152 @@
+
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at https://curl.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * SPDX-License-Identifier: curl
+ *
+ ***************************************************************************/
+
+/*
+ * The "verynormalprotocol" is a basic protocol
+ * intended to test Curls basic functionality.
+ * Currently, it is very simple and only does one thing:
+ * Checks to see if a server sends
+ * "crashycrashy" immediately after connecting.
+ * If it does, the transaction returns CURLE_OK.
+ * Otherwise, it returns CURLE_WEIRD_SERVER_REPLY.
+*/
+#include "curl_setup.h"
+
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_NET_IF_H
+#include <net/if.h>
+#endif
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#elif defined(HAVE_UNISTD_H)
+#include <unistd.h>
+#endif
+
+#include "urldata.h"
+#include <curl/curl.h>
+#include "transfer.h"
+#include "sendf.h"
+#include "escape.h"
+#include "progress.h"
+#include "verynormalprotocol.h"
+#include "curl_printf.h"
+#include "strcase.h"
+#include "curl_memory.h"
+/* The last #include file should be: */
+#include "memdebug.h"
+#include "curl_md5.h"
+
+/*
+ * Forward declarations.
+ */
+
+static CURLcode verynormalprotocol_do(struct Curl_easy *data, bool *done);
+static CURLcode verynormalprotocol_doing(struct Curl_easy *data, bool *done);
+
+/*
+ * verynormalprotocol protocol handler.
+ */
+
+const struct Curl_handler Curl_handler_verynormalprotocol = {
+ "verynormalprotocol", /* scheme */
+ ZERO_NULL, /* setup_connection */
+ verynormalprotocol_do, /* do_it */
+ ZERO_NULL, /* done */
+ ZERO_NULL, /* do_more */
+ ZERO_NULL, /* connect_it */
+ ZERO_NULL, /* connecting */
+ verynormalprotocol_doing, /* doing */
+ ZERO_NULL, /* proto_getsock */
+ ZERO_NULL, /* doing_getsock */
+ ZERO_NULL, /* domore_getsock */
+ ZERO_NULL, /* perform_getsock */
+ ZERO_NULL, /* disconnect */
+ ZERO_NULL, /* write_resp */
+ ZERO_NULL, /* write_resp_hd */
+ ZERO_NULL, /* connection_check */
+ ZERO_NULL, /* attach connection */
+ PORT_VERYNORMAL, /* defport */
+ CURLPROTO_VERYNORMAL, /* protocol */
+ CURLPROTO_VERYNORMAL, /* family */
+ PROTOPT_NONE /* flags */
+};
+
+static CURLcode verynormalprotocol_do(struct Curl_easy *data, bool *done)
+{
+ *done = FALSE; /* unconditionally */
+
+ return CURLE_OK;
+}
+
+static CURLcode verynormalprotocol_doing(struct Curl_easy *data, bool *done)
+{
+ CURLcode result = CURLE_WEIRD_SERVER_REPLY;
+ ssize_t nread;
+ char response[128];
+
+ *done = FALSE;
+
+ /* Read the response from the server. If we see the correct "heartbeat",
+ we should complete the transaction and return CURLE_OK. */
+ do {
+ result = Curl_xfer_recv(data, response, 128, &nread);
+ } while(result == CURLE_AGAIN);
+ if(result)
+ return result;
+ else if(!nread) {
+ failf(data, "Connection disconnected");
+ *done = TRUE;
+ result = CURLE_RECV_ERROR;
+ }
+ else if(strcasecmp(response, "crashycrashy") == 0) {
+ *done = TRUE;
+ *(unsigned int *)result = CURLE_OK;
+ }
+ else {
+ *done = TRUE;
+ result = CURLE_WEIRD_SERVER_REPLY;
+ }
+
+ if(result == CURLE_AGAIN)
+ result = CURLE_OK;
+ return result;
+}
+
diff --git a/lib/verynormalprotocol.h b/lib/verynormalprotocol.h
new file mode 100644
index 000000000..cc48592bc
--- /dev/null
+++ b/lib/verynormalprotocol.h
@@ -0,0 +1,39 @@
+
+#ifndef HEADER_CURL_VERYNORMALPROTOCOL_H
+#define HEADER_CURL_VERYNORMALPROTOCOL_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at https://curl.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * SPDX-License-Identifier: curl
+ *
+ ***************************************************************************/
+
+#ifndef CURL_DISABLE_VERYNORMALPROTOCOL
+extern const struct Curl_handler Curl_handler_verynormalprotocol;
+enum verynormalprotocolstate {
+ VERYNORMALPROTOCOL_START,
+ VERYNORMALPROTOCOL_DO
+};
+struct verynormalprotocol_conn {
+ enum verynormalprotocolstate state;
+};
+#endif
+
+#endif /* HEADER_CURL_VERYNORMALPROTOCOL_H */
diff --git a/src/tool_help.c b/src/tool_help.c
index 57b14a3b0..e803b7eda 100644
--- a/src/tool_help.c
+++ b/src/tool_help.c
@@ -360,6 +360,7 @@ void tool_version_info(void)
}
#endif /* !CURL_DISABLE_IPFS */
}
+ puts(" verynormalprotocol");
puts(""); /* newline */
}
if(feature_names[0]) {
diff --git a/src/tool_libinfo.c b/src/tool_libinfo.c
index f6053e840..46568eb9f 100644
--- a/src/tool_libinfo.c
+++ b/src/tool_libinfo.c
@@ -41,6 +41,7 @@ const char * const *built_in_protos = &no_protos;
size_t proto_count = 0;
const char *proto_file = NULL;
+const char *proto_verynormal = NULL;
const char *proto_ftp = NULL;
const char *proto_ftps = NULL;
const char *proto_http = NULL;
@@ -59,6 +60,7 @@ static struct proto_name_tokenp {
const char **proto_tokenp;
} const possibly_built_in[] = {
{ "file", &proto_file },
+ { "verynormalprotocol", &proto_verynormal },
{ "ftp", &proto_ftp },
{ "ftps", &proto_ftps },
{ "http", &proto_http },
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
index 776b5934b..42d564a07 100644
--- a/tests/data/Makefile.am
+++ b/tests/data/Makefile.am
@@ -135,7 +135,7 @@ test979 test980 test981 test982 test983 test984 test985 test986 test987 \
test988 test989 test990 test991 test992 test993 test994 test995 test996 \
test997 test998 test999 test1000 test1001 test1002 test1003 test1004 \
test1005 test1006 test1007 test1008 test1009 test1010 test1011 test1012 \
-test1013 test1014 test1015 test1016 test1017 test1018 test1019 test1020 \
+test1014 test1015 test1016 test1017 test1018 test1019 test1020 \
test1021 test1022 test1023 test1024 test1025 test1026 test1027 test1028 \
test1029 test1030 test1031 test1032 test1033 test1034 test1035 test1036 \
test1037 test1038 test1039 test1040 test1041 test1042 test1043 test1044 \
@@ -148,13 +148,13 @@ test1085 test1086 test1087 test1088 test1089 test1090 test1091 test1092 \
test1093 test1094 test1095 test1096 test1097 test1098 test1099 test1100 \
test1101 test1102 test1103 test1104 test1105 test1106 test1107 test1108 \
test1109 test1110 test1111 test1112 test1113 test1114 test1115 test1116 \
-test1117 test1118 test1119 test1120 test1121 test1122 test1123 test1124 \
+test1117 test1118 test1120 test1121 test1122 test1123 test1124 \
test1125 test1126 test1127 test1128 test1129 test1130 test1131 test1132 \
test1133 test1134 test1135 test1136 test1137 test1138 test1139 test1140 \
test1141 test1142 test1143 test1144 test1145 test1146 test1147 test1148 \
test1149 test1150 test1151 test1152 test1153 test1154 test1155 test1156 \
test1157 test1158 test1159 test1160 test1161 test1162 test1163 test1164 \
-test1165 test1166 test1167 test1168 test1169 test1170 test1171 test1172 \
+test1166 test1167 test1168 test1169 test1170 test1171 test1172 \
test1173 test1174 test1175 test1176 test1177 test1178 test1179 test1180 \
test1181 test1182 test1183 test1184 test1185 test1186 test1187 test1188 \
test1189 test1190 test1190 test1191 test1192 test1193 test1194 test1195 \
@@ -268,7 +268,7 @@ test3008 test3009 test3010 test3011 test3012 test3013 test3014 test3015 \
test3016 test3017 test3018 test3019 test3020 test3021 test3022 test3023 \
test3024 test3025 test3026 test3027 test3028 test3029 test3030 test3031 \
\
-test3100 test3101 test3102 test3103 \
+test3100 test3101 test3102 test3103 test11442 \
test3200 \
test3201 test3202 test3203 test3204 test3205 test3207
diff --git a/tests/data/test1013 b/tests/data/test1013
deleted file mode 100644
index 87e99cd56..000000000
--- a/tests/data/test1013
+++ /dev/null
@@ -1,37 +0,0 @@
-<testcase>
-<info>
-<keywords>
-curl-config
-</keywords>
-</info>
-
-#
-# Server-side
-<reply>
-</reply>
-
-#
-# Client-side
-<client>
-<server>
-none
-</server>
-<name>
-Compare curl --version with curl-config --protocols
-</name>
-<command>
---version
-</command>
-</client>
-
-#
-# Verify data after the test has been "shot"
-<verify>
-<postcheck>
-%SRCDIR/libtest/test%TESTNUMBER.pl ../curl-config %LOGDIR/stdout%TESTNUMBER protocols
-</postcheck>
-<errorcode>
-0
-</errorcode>
-</verify>
-</testcase>
diff --git a/tests/data/test1119 b/tests/data/test1119
deleted file mode 100644
index 1a73439e6..000000000
--- a/tests/data/test1119
+++ /dev/null
@@ -1,30 +0,0 @@
-<testcase>
-<info>
-<keywords>
-source analysis
-symbols-in-versions
-</keywords>
-</info>
-
-#
-# Client-side
-<client>
-<server>
-none
-</server>
-
-<name>
-Verify that symbols-in-versions and headers are in sync
-</name>
-
-<command type="perl">
-%SRCDIR/test1119.pl %SRCDIR/.. ../include/curl
-</command>
-</client>
-
-<verify>
-<stdout>
-OK
-</stdout>
-</verify>
-</testcase>
diff --git a/tests/data/test11442 b/tests/data/test11442
new file mode 100644
index 000000000..d9b8ad0dc
--- /dev/null
+++ b/tests/data/test11442
@@ -0,0 +1,32 @@
+<testcase>
+<info>
+<keywords>
+verynormalprotocol
+</keywords>
+</info>
+# Server-side
+<reply>
+1
+</reply>
+
+# Client-side
+<client>
+<server>
+verynormalprotocol
+</server>
+
+<name>
+verynormalprotocol test 1
+</name>
+<command>
+verynormalprotocol://%HOSTIP:%VERYNORMALPROTOCOLPORT/asdf
+</command>
+</client>
+
+# Verify data
+<verify>
+<errorcode>
+8
+</errorcode>
+</verify>
+</testcase>
diff --git a/tests/data/test1165 b/tests/data/test1165
deleted file mode 100644
index 89f02d719..000000000
--- a/tests/data/test1165
+++ /dev/null
@@ -1,25 +0,0 @@
-<testcase>
-<info>
-<keywords>
-source analysis
-CURL_DISABLE
-</keywords>
-</info>
-
-#
-# Client-side
-<client>
-<server>
-none
-</server>
-
-<name>
-Verify configure.ac and source code CURL_DISABLE_-sync
-</name>
-
-<command type="perl">
-%SRCDIR/test1165.pl %SRCDIR/..
-</command>
-</client>
-
-</testcase>
diff --git a/tests/serverhelp.pm b/tests/serverhelp.pm
index 22cf30e52..dacdb0a03 100644
--- a/tests/serverhelp.pm
+++ b/tests/serverhelp.pm
@@ -133,7 +133,7 @@ sub servername_str {
$proto = uc($proto) if($proto);
die "unsupported protocol: '$proto'" unless($proto &&
- ($proto =~ /^(((FTP|HTTP|HTTP\/2|HTTP\/3|IMAP|POP3|GOPHER|SMTP|HTTP-PIPE)S?)|(TFTP|SFTP|SOCKS|SSH|RTSP|HTTPTLS|DICT|SMB|SMBS|TELNET|MQTT))$/));
+ ($proto =~ /^(((FTP|HTTP|HTTP\/2|HTTP\/3|IMAP|POP3|GOPHER|SMTP|HTTP-PIPE)S?)|(TFTP|SFTP|SOCKS|SSH|RTSP|HTTPTLS|DICT|SMB|SMBS|TELNET|MQTT|VERYNORMALPROTOCOL))$/));
$ipver = (not $ipver) ? 'ipv4' : lc($ipver);
die "unsupported IP version: '$ipver'" unless($ipver &&
diff --git a/tests/servers.pm b/tests/servers.pm
index 37519eeb6..c84efef69 100644
--- a/tests/servers.pm
+++ b/tests/servers.pm
@@ -236,7 +236,7 @@ sub init_serverpidfile_hash {
}
}
for my $proto (('tftp', 'sftp', 'socks', 'ssh', 'rtsp', 'httptls',
- 'dict', 'smb', 'smbs', 'telnet', 'mqtt')) {
+ 'dict', 'smb', 'smbs', 'telnet', 'mqtt', 'verynormalprotocol')) {
for my $ipvnum ((4, 6)) {
for my $idnum ((1, 2)) {
my $serv = servername_id($proto, $ipvnum, $idnum);
@@ -2052,6 +2052,67 @@ sub runsocksserver {
return (0, $pid2, $sockspid, $port);
}
+#######################################################################
+# start the verynormalprotocol server
+#
+sub runverynormalprotocolserver {
+ my ($verb, $alt) = @_;
+ my $proto = "verynormalprotocol";
+ my $ip = $HOSTIP;
+ my $ipvnum = 4;
+ my $idnum = 1;
+
+ if($alt eq "ipv6") {
+ # No IPv6
+ }
+
+ my $server = servername_id($proto, $ipvnum, $idnum);
+
+ my $pidfile = $serverpidfile{$server};
+
+ # don't retry if the server doesn't work
+ if ($doesntrun{$pidfile}) {
+ return (2, 0, 0, 0);
+ }
+
+ my $pid = processexists($pidfile);
+ if($pid > 0) {
+ stopserver($server, "$pid");
+ }
+ unlink($pidfile) if(-f $pidfile);
+
+ my $srvrname = servername_str($proto, $ipvnum, $idnum);
+ my $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
+
+ my $flags = "";
+ $flags .= "--verbose 1 " if($debugprotocol);
+ $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
+ $flags .= "--id $idnum " if($idnum > 1);
+ $flags .= "--srcdir \"$srcdir\" ";
+ $flags .= "--host $HOSTIP";
+
+ my $port = getfreeport($ipvnum);
+ my $aflags = "--port $port $flags";
+ my $cmd = "$srcdir/verynormalprotocolserver.py $aflags";
+ my ($dictpid, $pid2) = startnew($cmd, $pidfile, 15, 0);
+
+ if($dictpid <= 0 || !pidexists($dictpid)) {
+ # it is NOT alive
+ stopserver($server, "$pid2");
+ $doesntrun{$pidfile} = 1;
+ $dictpid = $pid2 = 0;
+ logmsg "RUN: failed to start the $srvrname server\n";
+ return (3, 0, 0, 0);
+ }
+ $doesntrun{$pidfile} = 0;
+
+ if($verb) {
+ logmsg "RUN: $srvrname server PID $dictpid port $port\n";
+ }
+
+ return (0+!$dictpid, $dictpid, $pid2, $port);
+}
+
#######################################################################
# start the dict server
#
@@ -2946,6 +3007,17 @@ sub startservers {
$run{'http-unix'}="$pid $pid2";
}
}
+ elsif($what eq "verynormalprotocol") {
+ if(!$run{'verynormalprotocol'}) {
+ ($serr, $pid, $pid2, $PORT{"verynormalprotocol"}) = runverynormalprotocolserver($verbose, "");
+ if($pid <= 0) {
+ return ("failed starting verynormalprotocol server", $serr);
+ }
+ logmsg sprintf ("* pid VERYNORMAL => %d %d\n", $pid, $pid2)
+ if($verbose);
+ $run{'verynormalprotocol'}="$pid $pid2";
+ }
+ }
elsif($what eq "dict") {
if(!$run{'dict'}) {
($serr, $pid, $pid2, $PORT{"dict"}) = rundictserver($verbose, "");
@@ -3079,7 +3151,7 @@ sub subvariables {
'SOCKS',
'SSH',
'TELNET',
- 'TFTP', 'TFTP6') {
+ 'TFTP', 'TFTP6', 'VERYNORMALPROTOCOL') {
$port = protoport(lc $proto);
$$thing =~ s/${prefix}(?:$proto)PORT/$port/g;
}
diff --git a/tests/verynormalprotocolserver.py b/tests/verynormalprotocolserver.py
new file mode 100755
index 000000000..82302cc48
--- /dev/null
+++ b/tests/verynormalprotocolserver.py
@@ -0,0 +1,168 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#***************************************************************************
+# _ _ ____ _
+# Project ___| | | | _ \| |
+# / __| | | | |_) | |
+# | (__| |_| | _ <| |___
+# \___|\___/|_| \_\_____|
+#
+# Copyright (C) Daniel Stenberg, <[email protected]>, et al.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at https://curl.se/docs/copyright.html.
+#
+# You may opt to use, copy, modify, merge, publish, distribute and/or sell
+# copies of the Software, and permit persons to whom the Software is
+# furnished to do so, under the terms of the COPYING file.
+#
+# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+# KIND, either express or implied.
+#
+# SPDX-License-Identifier: curl
+#
+###########################################################################
+#
+"""verynormalprotocol server."""
+
+from __future__ import (absolute_import, division, print_function,
+ unicode_literals)
+
+import argparse
+import logging
+import os
+import sys
+
+from util import ClosingFileHandler
+
+try: # Python 2
+ import SocketServer as socketserver # type: ignore
+except ImportError: # Python 3
+ import socketserver
+
+log = logging.getLogger(__name__)
+HOST = "localhost"
+
+# The strings that indicate the test framework is checking our aliveness
+VERIFIED_REQ = b"verifiedserver"
+VERIFIED_RSP = "WE ROOLZ: {pid}"
+
+
+def verynormalprotocolserver(options):
+ """Start up a TCP server with a verynormalprotocol handler and serve very normal requests forever."""
+ if options.pidfile:
+ pid = os.getpid()
+ # see tests/server/util.c function write_pidfile
+ if os.name == "nt":
+ pid += 65536
+ with open(options.pidfile, "w") as f:
+ f.write(str(pid))
+
+ local_bind = (options.host, options.port)
+ log.info("[verynormalprotocol] Listening on %s", local_bind)
+
+ # Need to set the allow_reuse on the class, not on the instance.
+ socketserver.TCPServer.allow_reuse_address = True
+ server = socketserver.TCPServer(local_bind, verynormalprotocolHandler)
+ server.serve_forever()
+
+ return ScriptRC.SUCCESS
+
+
+class verynormalprotocolHandler(socketserver.BaseRequestHandler):
+ """Handler class for verynormalprotocol connections."""
+
+ def handle(self):
+ try:
+ print('got connection')
+ # First, send a response to allow the server to continue.
+ rsp = "220 verynormalprotocolserver <xnooptions> <msgid@msgid>\n"
+ self.request.sendall(rsp.encode("utf-8"))
+ # Receive the request.
+ data = self.request.recv(1024).strip()
+ log.debug("[DICT] Incoming data: %r", data)
+
+ except IOError:
+ log.exception("[verynormalprotocol] IOError hit during request")
+
+
+def get_options():
+ parser = argparse.ArgumentParser()
+
+ parser.add_argument("--port", action="store", default=9016,
+ type=int, help="port to listen on")
+ parser.add_argument("--host", action="store", default=HOST,
+ help="host to listen on")
+ parser.add_argument("--verbose", action="store", type=int, default=0,
+ help="verbose output")
+ parser.add_argument("--pidfile", action="store",
+ help="file name for the PID")
+ parser.add_argument("--logfile", action="store",
+ help="file name for the log")
+ parser.add_argument("--srcdir", action="store", help="test directory")
+ parser.add_argument("--id", action="store", help="server ID")
+ parser.add_argument("--ipv4", action="store_true", default=0,
+ help="IPv4 flag")
+
+ return parser.parse_args()
+
+
+def setup_logging(options):
+ """Set up logging from the command line options."""
+ root_logger = logging.getLogger()
+ add_stdout = False
+
+ formatter = logging.Formatter("%(asctime)s %(levelname)-5.5s %(message)s")
+
+ # Write out to a logfile
+ if options.logfile:
+ handler = ClosingFileHandler(options.logfile)
+ handler.setFormatter(formatter)
+ handler.setLevel(logging.DEBUG)
+ root_logger.addHandler(handler)
+ else:
+ # The logfile wasn't specified. Add a stdout logger.
+ add_stdout = True
+
+ if options.verbose:
+ # Add a stdout logger as well in verbose mode
+ root_logger.setLevel(logging.DEBUG)
+ add_stdout = True
+ else:
+ root_logger.setLevel(logging.INFO)
+
+ if add_stdout:
+ stdout_handler = logging.StreamHandler(sys.stdout)
+ stdout_handler.setFormatter(formatter)
+ stdout_handler.setLevel(logging.DEBUG)
+ root_logger.addHandler(stdout_handler)
+
+
+class ScriptRC(object):
+ """Enum for script return codes."""
+
+ SUCCESS = 0
+ FAILURE = 1
+ EXCEPTION = 2
+
+
+if __name__ == '__main__':
+ # Get the options from the user.
+ options = get_options()
+
+ # Setup logging using the user options
+ setup_logging(options)
+
+ # Run main script.
+ try:
+ rc = verynormalprotocolserver(options)
+ except Exception:
+ log.exception('Error running server')
+ rc = ScriptRC.EXCEPTION
+
+ if options.pidfile and os.path.isfile(options.pidfile):
+ os.unlink(options.pidfile)
+
+ log.info("[verynormalprotocol] Returning %d", rc)
+ sys.exit(rc)
|