Kitxuuu's picture
Add files using upload-large-folder tool
f4637db verified
raw
history blame
24.4 kB
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)