From ae806395abc8c1f3f4a6e1055fe4655aa82d3e78 Mon Sep 17 00:00:00 2001 From: Patrick Monnerat Date: Fri, 11 Aug 2023 00:30:17 +0200 Subject: [PATCH] test1554: check translatable string options in OS400 wrapper This test runs a perl script that checks all string options are properly translated by the OS400 character code conversion wrapper. It also verifies these options are listed in alphanumeric order in the wrapper switch statement. Closes #11650 --- packages/OS400/README.OS400 | 27 ++--- packages/OS400/ccsidcurl.c | 11 ++- tests/check-translatable-options.pl | 147 ++++++++++++++++++++++++++++ tests/data/Makefile.inc | 2 +- tests/data/test1544 | 24 +++++ 5 files changed, 196 insertions(+), 15 deletions(-) create mode 100755 tests/check-translatable-options.pl create mode 100644 tests/data/test1544 diff --git a/packages/OS400/README.OS400 b/packages/OS400/README.OS400 index efaf05972..59627d7bd 100644 --- a/packages/OS400/README.OS400 +++ b/packages/OS400/README.OS400 @@ -48,6 +48,7 @@ _ curl_easy_setopt_ccsid() Variable arguments are a string pointer and a CCSID (unsigned int) for options: CURLOPT_ABSTRACT_UNIX_SOCKET + CURLOPT_ACCEPT_ENCODING CURLOPT_ALTSVC CURLOPT_AWS_SIGV4 CURLOPT_CAINFO @@ -56,17 +57,19 @@ options: CURLOPT_COOKIEFILE CURLOPT_COOKIEJAR CURLOPT_COOKIELIST - CURLOPT_COPYPOSTFIELDS CURLOPT_CRLFILE CURLOPT_CUSTOMREQUEST CURLOPT_DEFAULT_PROTOCOL + CURLOPT_DNS_INTERFACE + CURLOPT_DNS_LOCAL_IP4 + CURLOPT_DNS_LOCAL_IP6 CURLOPT_DNS_SERVERS CURLOPT_DOH_URL CURLOPT_EGDSOCKET - CURLOPT_ENCODING CURLOPT_FTPPORT CURLOPT_FTP_ACCOUNT CURLOPT_FTP_ALTERNATIVE_TO_USER + CURLOPT_HAPROXY_CLIENT_IP CURLOPT_HSTS CURLOPT_INTERFACE CURLOPT_ISSUERCERT @@ -88,6 +91,7 @@ options: CURLOPT_PROXY_CAINFO CURLOPT_PROXY_CAPATH CURLOPT_PROXY_CRLFILE + CURLOPT_PROXY_ISSUERCERT CURLOPT_PROXY_KEYPASSWD CURLOPT_PROXY_PINNEDPUBLICKEY CURLOPT_PROXY_SERVICE_NAME @@ -105,7 +109,7 @@ options: CURLOPT_REDIR_PROTOCOLS_STR CURLOPT_REFERER CURLOPT_REQUEST_TARGET - CURLOPT_RTSP_SESSION_UID + CURLOPT_RTSP_SESSION_ID CURLOPT_RTSP_STREAM_URI CURLOPT_RTSP_TRANSPORT CURLOPT_SASL_AUTHZID @@ -122,6 +126,7 @@ options: CURLOPT_SSLKEY CURLOPT_SSLKEYTYPE CURLOPT_SSL_CIPHER_LIST + CURLOPT_SSL_EC_CURVES CURLOPT_TLS13_CIPHERS CURLOPT_TLSAUTH_PASSWORD CURLOPT_TLSAUTH_TYPE @@ -145,13 +150,13 @@ CCSID conversion result length. _ curl_formadd_ccsid() In the variable argument list, string pointers should be followed by a (long) CCSID for the following options: - CURLFORM_FILENAME - CURLFORM_CONTENTTYPE CURLFORM_BUFFER - CURLFORM_FILE - CURLFORM_FILECONTENT + CURLFORM_CONTENTTYPE CURLFORM_COPYCONTENTS CURLFORM_COPYNAME + CURLFORM_FILE + CURLFORM_FILECONTENT + CURLFORM_FILENAME CURLFORM_PTRNAME If taken from an argument array, an additional array entry must follow each entry containing one of the above option. This additional entry holds the CCSID @@ -165,19 +170,19 @@ _ curl_easy_getinfo_ccsid() The following options are followed by a 'char * *' and a CCSID. Unlike curl_easy_getinfo(), the value returned in the pointer should be released with curl_free() after use: - CURLINFO_EFFECTIVE_URL CURLINFO_CONTENT_TYPE + CURLINFO_EFFECTIVE_URL CURLINFO_FTP_ENTRY_PATH + CURLINFO_LOCAL_IP + CURLINFO_PRIMARY_IP CURLINFO_REDIRECT_URL CURLINFO_REFERER - CURLINFO_PRIMARY_IP CURLINFO_RTSP_SESSION_ID - CURLINFO_LOCAL_IP CURLINFO_SCHEME Likewise, the following options are followed by a struct curl_slist * * and a CCSID. - CURLINFO_SSL_ENGINES CURLINFO_COOKIELIST + CURLINFO_SSL_ENGINES Lists returned should be released with curl_slist_free_all() after use. Option CURLINFO_CERTINFO is followed by a struct curl_certinfo * * and a CCSID. Returned structures should be freed with curl_certinfo_free_all() diff --git a/packages/OS400/ccsidcurl.c b/packages/OS400/ccsidcurl.c index c59617ef5..48f1f5fbd 100644 --- a/packages/OS400/ccsidcurl.c +++ b/packages/OS400/ccsidcurl.c @@ -1076,7 +1076,11 @@ curl_easy_setopt_ccsid(CURL *easy, CURLoption tag, ...) switch(tag) { + /* BEGIN TRANSLATABLE STRING OPTIONS */ + /* Keep option symbols in alphanumeric order and retain the BEGIN/END + armor comments. */ case CURLOPT_ABSTRACT_UNIX_SOCKET: + case CURLOPT_ACCEPT_ENCODING: case CURLOPT_ALTSVC: case CURLOPT_AWS_SIGV4: case CURLOPT_CAINFO: @@ -1088,16 +1092,16 @@ curl_easy_setopt_ccsid(CURL *easy, CURLoption tag, ...) case CURLOPT_CRLFILE: case CURLOPT_CUSTOMREQUEST: case CURLOPT_DEFAULT_PROTOCOL: - case CURLOPT_DNS_SERVERS: case CURLOPT_DNS_INTERFACE: case CURLOPT_DNS_LOCAL_IP4: case CURLOPT_DNS_LOCAL_IP6: + case CURLOPT_DNS_SERVERS: case CURLOPT_DOH_URL: case CURLOPT_EGDSOCKET: - case CURLOPT_ENCODING: case CURLOPT_FTPPORT: case CURLOPT_FTP_ACCOUNT: case CURLOPT_FTP_ALTERNATIVE_TO_USER: + case CURLOPT_HAPROXY_CLIENT_IP: case CURLOPT_HSTS: case CURLOPT_INTERFACE: case CURLOPT_ISSUERCERT: @@ -1119,6 +1123,7 @@ curl_easy_setopt_ccsid(CURL *easy, CURLoption tag, ...) case CURLOPT_PROXY_CAINFO: case CURLOPT_PROXY_CAPATH: case CURLOPT_PROXY_CRLFILE: + case CURLOPT_PROXY_ISSUERCERT: case CURLOPT_PROXY_KEYPASSWD: case CURLOPT_PROXY_PINNEDPUBLICKEY: case CURLOPT_PROXY_SERVICE_NAME: @@ -1164,7 +1169,7 @@ curl_easy_setopt_ccsid(CURL *easy, CURLoption tag, ...) case CURLOPT_USERNAME: case CURLOPT_USERPWD: case CURLOPT_XOAUTH2_BEARER: - case CURLOPT_HAPROXY_CLIENT_IP: + /* END TRANSLATABLE STRING OPTIONS */ s = va_arg(arg, char *); ccsid = va_arg(arg, unsigned int); diff --git a/tests/check-translatable-options.pl b/tests/check-translatable-options.pl new file mode 100755 index 000000000..3830e5d6e --- /dev/null +++ b/tests/check-translatable-options.pl @@ -0,0 +1,147 @@ +#!/usr/bin/env perl +#*************************************************************************** +# _ _ ____ _ +# Project ___| | | | _ \| | +# / __| | | | |_) | | +# | (__| |_| | _ <| |___ +# \___|\___/|_| \_\_____| +# +# Copyright (C) Daniel Stenberg, , 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 +# +# +########################################################################### +# +# Check the OS/400 translating wrapper properly handles all translatable +# string options. + +use strict; +use warnings; + +my $root=$ARGV[0] || "."; +my $incdir = "$root/include/curl"; +my $os400dir = "$root/packages/OS400"; +my $errcount = 0; + +# Scan header file for string option definitions. +sub scan_header { + my ($f)=@_; + my $line = ""; + my $incomment = 0; + my @stringopts; + + open(my $h, "<", "$f"); + while(<$h>) { + s/^\s*(.*?)\s*$/$1/; # Trim. + # Remove multi-line comment trail. + if($incomment) { + if($_ !~ /.*?\*\/\s*(.*)$/) { + next; + } + $_ = $1; + $incomment = 0; + } + if($line ne "") { + # Unfold line. + $_ = "$line $1"; + $line = ""; + } + if($_ =~ /^(.*)\\$/) { + $line = "$1 "; + next; + } + # Remove comments. + while($_ =~ /^(.*?)\/\*.*?\*\/(.*)$/) { + $_ = "$1 $2"; + } + if($_ =~ /^(.*)\/\*/) { + $_ = "$1 "; + $incomment = 1; + } + s/^\s*(.*?)\s*$/$1/; # Trim again. + # Ignore preprocessor directives and blank lines. + if($_ =~ /^(?:#|$)/) { + next; + } + # Handle lines that may be continued as if they were folded. + if($_ !~ /[;,{}]$/ || $_ =~ /[^)],$/) { + # Folded line. + $line = $_; + next; + } + # Keep string options only. + if($_ =~ /CURLOPT(?:DEPRECATED)?\s*\(\s*([^, \t]+)\s*,\s*CURLOPTTYPE_STRINGPOINT/) { + push(@stringopts, $1); + } + } + close $h; + return @stringopts; +} + +# Scan packages/OS400/ccsidcurl.c for translatable string option cases. +sub scan_wrapper_for_strings { + my ($f)=@_; + my $inarmor = 0; + my @stringopts; + + open(my $h, "<", "$f"); + while(<$h>) { + if($_ =~ /(BEGIN|END) TRANSLATABLE STRING OPTIONS/) { + $inarmor = $1 eq "BEGIN"; + } + elsif($inarmor && $_ =~ /case\s+([^:]+):/) { + push(@stringopts, $1); + } + } + close $h; + return @stringopts; +} + +# Get tranlatable string options from header file. +my @stringdefs = scan_header("$incdir/curl.h"); + +# Get translated string options. +my @stringrefs = scan_wrapper_for_strings("$os400dir/ccsidcurl.c"); + +# Lists should be equal: check differences. +my %diff; +@diff{@stringdefs} = 0..$#stringdefs; +delete @diff{@stringrefs}; + +foreach(keys %diff) { + print "$_ is not translated\n"; + delete $diff{$_}; + $errcount++; +} + +@diff{@stringrefs} = 0..$#stringrefs; +delete @diff{@stringdefs}; + +foreach(keys %diff) { + print "translated option $_ does not exist\n"; + $errcount++; +} + +# Check translated string option cases are sorted alphanumerically. +foreach(my $i = 1; $i < $#stringrefs; $i++) { + if($stringrefs[$i] lt $stringrefs[$i - 1]) { + print("Translated string options are not sorted (" . $stringrefs[$i - 1] . + "/" . $stringrefs[$i] . ")\n"); + $errcount++; + last; + } +} + +exit !!$errcount; diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc index 542943812..e13e4a73d 100644 --- a/tests/data/Makefile.inc +++ b/tests/data/Makefile.inc @@ -192,7 +192,7 @@ test1508 test1509 test1510 test1511 test1512 test1513 test1514 test1515 \ test1516 test1517 test1518 test1519 test1520 test1521 test1522 test1523 \ test1524 test1525 test1526 test1527 test1528 test1529 test1530 test1531 \ test1532 test1533 test1534 test1535 test1536 test1537 test1538 test1539 \ -test1540 test1542 test1543 \ +test1540 test1542 test1543 test1544 \ \ test1550 test1551 test1552 test1553 test1554 test1555 test1556 test1557 \ test1558 test1559 test1560 test1561 test1562 test1563 test1564 test1565 \ diff --git a/tests/data/test1544 b/tests/data/test1544 new file mode 100644 index 000000000..861c4fbfc --- /dev/null +++ b/tests/data/test1544 @@ -0,0 +1,24 @@ + + + +source analysis + + + +# +# Client-side + + +none + + + +Verify all string options are translated by OS/400 wrapper + + + +%SRCDIR/check-translatable-options.pl %SRCDIR/.. + + + +