Porting library to OS/400

This commit is contained in:
Patrick Monnerat
2007-08-23 14:30:24 +00:00
parent 2d8dba388b
commit 557cc55f6f
18 changed files with 5133 additions and 1 deletions

245
packages/OS400/README.OS400 Normal file
View File

@@ -0,0 +1,245 @@
$Id$
Implementation notes:
This is a true OS/400 implementation, not a PASE implementation (for PASE,
use AIX implementation).
The biggest problem with OS/400 is EBCDIC. Libcurl implements an internal
conversion mechanism, but it has been designed for computers that have a
single native character set. OS/400 default native character set varies
depending on the country for which it has been localized. And more, a job
may dynamically alter its "native" character set.
Several characters that do not have fixed code in EBCDIC variants are
used in libcurl strings. As a consequence, using the existing conversion
mechanism would have lead in a localized binary library - not portable across
countries.
For this reason, and because libcurl was originally designed for ASCII based
operating systems, the current OS/400 implementation uses ASCII as internal
character set. This has been accomplished using the QADRT library and
include files, a C and system procedures ASCII wrapper library. See IBM QADRT
description for more information.
This then results in libcurl being an ASCII library: any function string
argument is taken/returned in ASCII and a C/C++ calling program built around
QADRT may use libcurl functions as on any other platform.
QADRT does not define ASCII wrappers for all C/system procedures: the
OS/400 configuration header file and an additional module (os400sys.c) define
some more of them, that are used by libcurl and that QADRT left out.
To support all the different variants of EBCDIC, non-standard wrapper
procedures have been added to libcurl on OS/400: they provide an additional
CCSID (numeric Coded Character Set ID specific to OS/400) parameter for each
string argument. String values passed to callback procedures are NOT converted,
so text gathered this way is (probably !) ASCII.
Another OS/400 problem comes from the fact that the last fixed argument of a
vararg procedure may not be of type char, unsigned char, short or unsigned
short. Enums that are internally implemented by the C compiler as one of these
types are also forbidden. Libcurl uses enums as vararg procedure tagfields...
Happily, there is a pragma forcing enums to type "int". The original libcurl
header files are thus altered during build process to use this pragma, in
order to force libcurl enums of being type int (the pragma disposition in use
before inclusion is restored before resuming the including unit compilation).
Three SSL implementations were present in libcurl. Nevertheless, none of them
is available on OS/400. To support SSL on OS/400, a fourth implementation has
been added (qssl.[ch]). There is no way to have different certificate stores
for CAs and for personal/application certificates/key. More, the SSL context
may be defined as an application identifier in the main certificate store,
or as a keyring file. As a consequence, the meaning of some fields have been
slightly altered:
_ The "certificate identifier" is taken from CURLOPT_SSLCERT if defined, else
from CURLOPT_CAINFO.
_ The certificate identifier is then used as an application identifier in the
main certificate store. If successful, this context is used.
_ If the previous step failed, the certificate identifier is used as the file
name of a keyring. CURLOPT_SSLKEYPASSWD is used here as the keyring password.
_ The default ca-bundle (CURLOPT_CAINFO) is set to the main certificate store's
keyring file name: this allows to use the system global CAs by default. (In that
case, the keyring password is safely recovered from the system... IBM dixit!)
Non-standard EBCDIC wrapper prototypes are defined in an additional header
file: ccsidcurl.h. These should be self-explanatory to an OS/400-aware
designer. CCSID 0 can be used to select the current job's CCSID.
Wrapper procedures with variable arguments are described below:
_ curl_easy_setopt_ccsid()
Variable arguments are a string pointer and a CCSID (unsigned int) for
options:
CURLOPT_CAINFO
CURLOPT_CAPATH
CURLOPT_COOKIE
CURLOPT_COOKIEFILE
CURLOPT_COOKIEJAR
CURLOPT_COOKIELIST
CURLOPT_CUSTOMREQUEST
CURLOPT_EGDSOCKET
CURLOPT_ENCODING
CURLOPT_FTPPORT
CURLOPT_FTP_ACCOUNT
CURLOPT_FTP_ALTERNATIVE_TO_USER
CURLOPT_INTERFACE
CURLOPT_KRBLEVEL
CURLOPT_NETRC_FILE
CURLOPT_POSTFIELDS
CURLOPT_PROXY
CURLOPT_PROXYUSERPWD
CURLOPT_RANDOM_FILE
CURLOPT_RANGE
CURLOPT_REFERER
CURLOPT_SSH_PRIVATE_KEYFILE
CURLOPT_SSH_PUBLIC_KEYFILE
CURLOPT_SSLCERT
CURLOPT_SSLCERTTYPE
CURLOPT_SSLENGINE
CURLOPT_SSLKEY
CURLOPT_SSLKEYPASSWD
CURLOPT_SSLKEYTYPE
CURLOPT_SSL_CIPHER_LIST
CURLOPT_URL
CURLOPT_USERAGENT
CURLOPT_USERPWD
Else it is the same as for curl_easy_setopt().
Note that CURLOPT_ERRORBUFFER is not in the list above, since it gives the
address of an (empty) character buffer, not the address of a string.
_ 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_COPYCONTENTS
CURLFORM_COPYNAME
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
in its value field, and the option field is meaningless.
It is not possible to have a string pointer and its CCSID across a function
parameter/array boundary.
Please note that CURLFORM_PTRCONTENTS and CURLFORM_BUFFERPTR are considered
unconvertible strings and thus are NOT followed by a CCSID.
_ 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 freed after
use:
CURLINFO_EFFECTIVE_URL
CURLINFO_CONTENT_TYPE
CURLINFO_FTP_ENTRY_PATH
Other options are processed like in curl_easy_getinfo().
Standard compilation environment does support neither autotools nor make;
in fact, very few common utilities are available. As a consequence, the
config-os400.h has been coded manually and the compilation scripts are
a set of shell scripts stored in subdirectory packages/OS400.
The "curl" command and the test environment are currently not supported on
OS/400.
Protocols currently implemented on OS/400:
_ HTTP
_ HTTPS
_ FTP
_ FTPS
_ FTP with secure transmission.
_ LDAP
_ DICT
_ TELNET
Compiling on OS/400:
These instructions targets people who knows about OS/400, compiling, IFS and
archive extraction. Do not ask questions about these subjects if you're not
familiar with.
_ As a prerequisite, QADRT development environment must be installed.
_ Install the curl source directory in IFS.
_ Enter shell (QSH)
_ Change current directory to the curl installation directory
_ Change current directory to ./packages/OS400
_ Edit file iniscript.sh. You may want to change tunable configuration
parameters, like debug info generation, optimisation level, listing option,
target library, etc.
_ Copy any file in the current directory to makelog (i.e.:
cp initscript.sh makelog): this is intended to create the makelog file with
an ASCII CCSID!
_ Enter the command "sh makefile.sh > makelog 2>&1'
_ Examine the makelog file to check for compilation errors.
Leaving file initscript.sh unchanged, this will produce the following OS/400
objects:
_ Library CURL. All other objects will be stored in this library.
_ Modules for all libcurl units.
_ Binding directory CURL_A, to be used at calling program link time for
statically binding the modules (specify BNDSRVPGM(QADRTTS) when creating a
program using CURL_A).
_ Service program CURL, to be used at calling program run-time when this program
has dynamically bound curl at link time.
_ Binding directory CURL. To be used to dynamically bind libcurl when linking a
calling program.
_ Source file H. It contains all the include members needed to compile a C/C++
module using libcurl, and an ILE/RPG /copy member for support in this
language.
_ Standard C/C++ libcurl include members in file H.
_ CCSIDCURL member in file H. This defines the non-standard EBCDIC wrappers for
C and C++.
_ CURL.INC member in file H. This defines everything needed by an ILE/RPG
program using libcurl.
_ LIBxxx modules and programs. Although the test environment is not supported
on OS/400, the libcurl test programs are compiled for manual tests.
Special programming consideration:
QADRT being used, the following points must be considered:
_ If static binding is used, service program QADRTTS must be linked too.
_ The EBCDIC CCSID used by QADRT is 37 by default, NOT THE JOB'S CCSID. If
another EBCDIC CCSID is required, it must be set via a locale through a call
to setlocale_a (QADRT's setlocale() ASCII wrapper) with category LC_ALL or
LC_CTYPE, or by setting environment variable QADRT_ENV_LOCALE to the locale
object path before executing the program.
_ Do not use original source include files unless you know what you are doing.
Use the installed members instead (in /QSYS.LIB/CURL.LIB/H.FILE).
ILE/RPG support:
Since 95% of the OS/400 programmers use ILE/RPG exclusively, a definition
/COPY member is provided for this language. To include all libcurl
definitions in an ILE/RPG module, line
h bnddir('CURL/CURL')
must figure in the program header, and line
d/copy curl/h,curl.inc
in the global data section of the module's source code.
No vararg procedure support exists in ILE/RPG: for this reason, the following
considerations apply:
_ Procedures curl_easy_setopt_long(), curl_easy_setopt_object(),
curl_easy_setopt_function() and curl_easy_setopt_offset() are all alias
prototypes to curl_easy_setopt(), but with different parameter lists.
_ Procedures curl_easy_getinfo_string(), curl_easy_getinfo_long(),
curl_easy_getinfo_double() and curl_easy_getinfo_slist() are all alias
prototypes to curl_easy_getinfo(), but with different parameter lists.
_ Procedures curl_multi_setopt_long(), curl_multi_setopt_object(),
curl_multi_setopt_function() and curl_multi_setopt_offset() are all alias
prototypes to curl_multi_setopt(), but with different parameter lists.
_ The prototype of procedure curl_formadd() allows specifying a pointer option
and the CURLFORM_END option. This makes possible to use an option array
without any additional definition. If some specific incompatible argument
list is used in the ILE/RPG program, the latter must define a specialised
alias. The same applies to curl_formadd_ccsid() too.
Since RPG cannot cast a long to a pointer, procedure curl_form_long_value()
is provided for that purpose: this allows storing a long value in the curl_forms
array.

1099
packages/OS400/ccsidcurl.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,65 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, 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 http://curl.haxx.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.
*
* $Id$
*
***************************************************************************/
#ifndef __CURL_CCSIDCURL_H
#define __CURL_CCSIDCURL_H
#include <curl.h>
#include <easy.h>
#include <multi.h>
CURL_EXTERN char * curl_version_ccsid(unsigned int ccsid);
CURL_EXTERN char * curl_easy_escape_ccsid(CURL * handle,
const char * string, int length,
unsigned int sccsid,
unsigned int dccsid);
CURL_EXTERN char * curl_easy_unescape_ccsid(CURL * handle, const char * string,
int length, int * outlength,
unsigned int sccsid,
unsigned int dccsid);
CURL_EXTERN struct curl_slist * curl_slist_append_ccsid(struct curl_slist * lst,
const char * data,
unsigned int ccsid);
CURL_EXTERN time_t curl_getdate_ccsid(const char * p, const time_t * unused,
unsigned int ccsid);
CURL_EXTERN curl_version_info_data * curl_version_info_ccsid(CURLversion stamp,
unsigned int csid);
CURL_EXTERN const char * curl_easy_strerror_ccsid(CURLcode error,
unsigned int ccsid);
CURL_EXTERN const char * curl_share_strerror_ccsid(CURLSHcode error,
unsigned int ccsid);
CURL_EXTERN const char * curl_multi_strerror_ccsid(CURLMcode error,
unsigned int ccsid);
CURL_EXTERN CURLcode curl_easy_getinfo_ccsid(CURL * curl, CURLINFO info, ...);
CURL_EXTERN CURLFORMcode curl_formadd_ccsid(struct curl_httppost * * httppost,
struct curl_httppost * * last_post,
...);
CURL_EXTERN char * curl_form_long_value(long value);
CURL_EXTERN int curl_formget_ccsid(struct curl_httppost * form, void * arg,
curl_formget_callback append,
unsigned int ccsid);
CURL_EXTERN CURLcode curl_easy_setopt_ccsid(CURL * curl, CURLoption tag, ...);
#endif

1518
packages/OS400/curl.inc.in Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,171 @@
#!/bin/sh
# $Id$
case "${SCRIPTDIR}" in
/*) ;;
*) SCRIPTDIR="`pwd`/${SCRIPTDIR}"
esac
while true
do case "${SCRIPTDIR}" in
*/.) SCRIPTDIR="${SCRIPTDIR%/.}";;
*) break;;
esac
done
# The script directory is supposed to be in $TOPDIR/packages/os400.
TOPDIR=`dirname "${SCRIPTDIR}"`
TOPDIR=`dirname "${TOPDIR}"`
export SCRIPTDIR TOPDIR
################################################################################
#
# Tunable configuration parameters.
#
################################################################################
TARGETLIB='CURL' # Target OS/400 program library
STATBNDDIR='CURL_A' # Static binding directory.
DYNBNDDIR='CURL' # Dynamic binding directory.
SRVPGM='CURL' # Service program.
TGTCCSID='500' # Target CCSID of objects
DEBUG='*ALL' # Debug level
OPTIMIZE='10' # Optimisation level
OUTPUT='*NONE' # Compilation output option.
TGTRLS='V5R1M0' # Target OS release
export TARGETLIB STATBNDDIR DYNBNDDIR SRVPGM TGTCCSID DEBUG OPTIMIZE OUTPUTC
export TGTRLS
################################################################################
# Need to get the version definitions.
LIBCURL_VERSION=`grep '^#define *LIBCURL_VERSION ' \
"${TOPDIR}/include/curl/curlver.h" |
sed 's/.*"\(.*\)".*/\1/'`
LIBCURL_VERSION_MAJOR=`grep '^#define *LIBCURL_VERSION_MAJOR ' \
"${TOPDIR}/include/curl/curlver.h" |
sed 's/^#define *LIBCURL_VERSION_MAJOR *\([^ ]*\).*/\1/'`
LIBCURL_VERSION_MINOR=`grep '^#define *LIBCURL_VERSION_MINOR ' \
"${TOPDIR}/include/curl/curlver.h" |
sed 's/^#define *LIBCURL_VERSION_MINOR *\([^ ]*\).*/\1/'`
LIBCURL_VERSION_PATCH=`grep '^#define *LIBCURL_VERSION_PATCH ' \
"${TOPDIR}/include/curl/curlver.h" |
sed 's/^#define *LIBCURL_VERSION_PATCH *\([^ ]*\).*/\1/'`
LIBCURL_VERSION_NUM=`grep '^#define *LIBCURL_VERSION_NUM ' \
"${TOPDIR}/include/curl/curlver.h" |
sed 's/^#define *LIBCURL_VERSION_NUM *0x\([^ ]*\).*/\1/'`
LIBCURL_TIMESTAMP=`grep '^#define *LIBCURL_TIMESTAMP ' \
"${TOPDIR}/include/curl/curlver.h" |
sed 's/.*"\(.*\)".*/\1/'`
export LIBCURL_VERSION
export LIBCURL_VERSION_MAJOR LIBCURL_VERSION_MINOR LIBCURL_VERSION_PATCH
export LIBCURL_VERSION_NUM LIBCURL_TIMESTAMP
################################################################################
#
# OS/400 specific definitions.
#
################################################################################
LIBIFSNAME="/QSYS.LIB/${TARGETLIB}.LIB"
################################################################################
#
# Procedures.
#
################################################################################
# action_needed dest [src]
#
# dest is an object to build
# if specified, src is an object on which dest depends.
#
# exit 0 (succeeds) if some action has to be taken, else 1.
action_needed()
{
[ ! -e "${1}" ] && return 0
[ "${2}" ] || return 1
[ "${1}" -ot "${2}" ] && return 0
return 1
}
# make_module module_name source_name [additional_definitions]
#
# Compile source name into ASCII module if needed.
# As side effect, append the module name to variable MODULES.
# Set LINK to "YES" if the module has been compiled.
make_module()
{
MODULES="${MODULES} ${1}"
MODIFSNAME="${LIBIFSNAME}/${1}.MODULE"
action_needed "${MODIFSNAME}" "${2}" || return 0;
# #pragma convert has to be in the source file itself, i.e.
# putting it in an include file makes it only active
# for that include file.
# Thus we build a temporary file with the pragma prepended to
# the source file and we compile that themporary file.
echo "#line 1 \"${2}\"" > __tmpsrcf.c
echo "#pragma convert(819)" >> __tmpsrcf.c
echo "#line 1" >> __tmpsrcf.c
cat "${2}" >> __tmpsrcf.c
CMD="CRTCMOD MODULE(${TARGETLIB}/${1}) SRCSTMF('__tmpsrcf.c')"
# CMD="${CMD} SYSIFCOPT(*IFS64IO) OPTION(*INCDIRFIRST *SHOWINC *SHOWSYS)"
CMD="${CMD} SYSIFCOPT(*IFS64IO) OPTION(*INCDIRFIRST)"
CMD="${CMD} LOCALETYPE(*LOCALE)"
CMD="${CMD} INCDIR('/qibm/proddata/qadrt/include'"
CMD="${CMD} '${TOPDIR}/include/curl' '${TOPDIR}/include'"
CMD="${CMD} '${TOPDIR}/packages/OS400' ${INCLUDES})"
CMD="${CMD} TGTCCSID(${TGTCCSID}) TGTRLS(${TGTRLS})"
CMD="${CMD} OUTPUT(${OUTPUT})"
CMD="${CMD} OPTIMIZE(${OPTIMIZE})"
CMD="${CMD} DBGVIEW(${DEBUG})"
if [ "${3}" ]
then CMD="${CMD} DEFINE(${3})"
fi
system "${CMD}"
rm -f __tmpsrcf.c
LINK=YES
}
# Determine DB2 object name from IFS name.
db2_name()
{
basename "${1}" |
tr '[a-z]' '[A-Z]' |
sed -e 's/\..*//' \
-e 's/^\(..........\).*/\1/'
}
# Copy IFS file replacing version info.
versioned_copy()
{
sed -e "s/@LIBCURL_VERSION@/${LIBCURL_VERSION}/g" \
-e "s/@LIBCURL_VERSION_MAJOR@/${LIBCURL_VERSION_MAJOR}/g" \
-e "s/@LIBCURL_VERSION_MINOR@/${LIBCURL_VERSION_MINOR}/g" \
-e "s/@LIBCURL_VERSION_PATCH@/${LIBCURL_VERSION_PATCH}/g" \
-e "s/@LIBCURL_VERSION_NUM@/${LIBCURL_VERSION_NUM}/g" \
-e "s/@LIBCURL_TIMESTAMP@/${LIBCURL_TIMESTAMP}/g" \
< "${1}" > "${2}"
}

View File

@@ -0,0 +1,48 @@
#!/bin/sh
#
# Installation of the include files in the OS/400 library.
#
# $Id$
SCRIPTDIR=`dirname "${0}"`
. "${SCRIPTDIR}/initscript.sh"
cd "${TOPDIR}/include"
# Create the OS/400 source program file for the include files.
SRCPF="${LIBIFSNAME}/H.FILE"
if action_needed "${SRCPF}"
then CMD="CRTSRCPF FILE(${TARGETLIB}/H) RCDLEN(112)"
CMD="${CMD} TEXT('curl: Header files')"
system "${CMD}"
fi
# Enumeration values are used as va_arg tagfields, so they MUST be
# integers.
copy_hfile()
{
sed -e '1i\
#pragma enum(int)\
' -e '$a\
#pragma enum(pop)\
' < "${2}" > "${1}"
}
# Copy the header files.
for HFILE in curl/*.h ${SCRIPTDIR}/ccsidcurl.h
do DEST="${SRCPF}/`db2_name \"${HFILE}\"`.MBR"
if action_needed "${DEST}" "${HFILE}"
then copy_hfile "${DEST}" "${HFILE}"
fi
done
# Copy the ILE/RPG include file, setting-up version number.
versioned_copy "${SCRIPTDIR}/curl.inc.in" "${SRCPF}/CURL.INC.MBR"

207
packages/OS400/make-lib.sh Normal file
View File

@@ -0,0 +1,207 @@
#!/bin/sh
#
# libcurl compilation script for the OS/400.
#
# $Id$
SCRIPTDIR=`dirname "${0}"`
. "${SCRIPTDIR}/initscript.sh"
cd "${TOPDIR}/lib"
# Create ca-bundle.h file.
if action_needed "ca-bundle.h"
then echo "/* This file is generated automatically */" > ca-bundle.h
echo "#ifndef CURL_CA_BUNDLE" >> ca-bundle.h
if [ "${CABUNDLE}" ]
then echo '#define CURL_CA_BUNDLE @CURL_CA_BUNDLE@' >> ca-bundle.h
else echo '#undef CURL_CA_BUNDLE /* unknown */' >> ca-bundle.h
fi
echo "#endif" >> ca-bundle.h
fi
# Create and compile the identification source file.
echo '#pragma comment(user, "libcurl version '"${LIBCURL_VERSION}"'")' > os400.c
echo '#pragma comment(date)' >> os400.c
echo '#pragma comment(copyright, "Copyright (C) 1998-2007 Daniel Stenberg et al. OS/400 version by P. Monnerat")' >> os400.c
make_module OS400 os400.c
LINK= # No need to rebuild service program yet.
MODULES=
# Get source list.
CSOURCES()
{
shift # Drop the equal sign.
CSOURCES="$*" # Get the file names.
}
HHEADERS()
{
shift # Drop the equal sign.
HHEADERS="$*" # Get the file names.
}
. Makefile.inc
# Compile the sources into modules.
INCLUDES="'`pwd`'"
make_module OS400SYS "${SCRIPTDIR}/os400sys.c"
make_module CCSIDCURL "${SCRIPTDIR}/ccsidcurl.c"
for SRC in ${CSOURCES}
do MODULE=`basename "${SRC}" .c |
tr '[a-z]' '[A-Z]' |
sed -e 's/^\(..........\).*/\1/'`
make_module "${MODULE}" "${SRC}"
done
# If needed, (re)create the static binding directory.
if action_needed "${LIBIFSNAME}/${STATBNDDIR}.BNDDIR"
then LINK=YES
fi
if [ "${LINK}" ]
then rm -rf "${LIBIFSNAME}/${STATBNDDIR}.BNDDIR"
CMD="CRTBNDDIR BNDDIR(${TARGETLIB}/${STATBNDDIR})"
CMD="${CMD} TEXT('LibCurl API static binding directory')"
system "${CMD}"
for MODULE in ${MODULES}
do CMD="ADDBNDDIRE BNDDIR(${TARGETLIB}/${STATBNDDIR})"
CMD="${CMD} OBJ((${TARGETLIB}/${MODULE} *MODULE))"
system "${CMD}"
done
fi
# The exportation file for service program creation must be in a DB2
# source file, so make sure it exists.
if action_needed "${LIBIFSNAME}/TOOLS.FILE"
then CMD="CRTSRCPF FILE(${TARGETLIB}/TOOLS) RCDLEN(112)"
CMD="${CMD} TEXT('curl: build tools')"
system "${CMD}"
fi
# Gather the list of symbols to export.
EXPORTS=`grep '^CURL_EXTERN[ ]' \
"${TOPDIR}"/include/curl/*.h \
"${SCRIPTDIR}/ccsidcurl.h" |
sed -e 's/^.*CURL_EXTERN[ ]\(.*\)(.*$/\1/' \
-e 's/[ ]*$//' \
-e 's/^.*[ ][ ]*//' \
-e 's/^\*//' \
-e 's/(\(.*\))/\1/'`
# Create the service program exportation file in DB2 member if needed.
BSF="${LIBIFSNAME}/TOOLS.FILE/BNDSRC.MBR"
if action_needed "${BSF}"
then LINK=YES
fi
if [ "${LINK}" ]
then echo " STRPGMEXP PGMLVL(*CURRENT) SIGNATURE('LIBCURL')" > "${BSF}"
for EXPORT in ${EXPORTS}
do echo ' EXPORT SYMBOL("'"${EXPORT}"'")' >> "${BSF}"
done
echo ' ENDPGMEXP' >> "${BSF}"
fi
# Build the service program if needed.
if action_needed "${LIBIFSNAME}/${SRVPGM}.SRVPGM"
then LINK=YES
fi
if [ "${LINK}" ]
then CMD="CRTSRVPGM SRVPGM(${TARGETLIB}/${SRVPGM})"
CMD="${CMD} SRCFILE(${TARGETLIB}/TOOLS) SRCMBR(BNDSRC)"
CMD="${CMD} MODULE(${TARGETLIB}/OS400)"
CMD="${CMD} BNDDIR(${TARGETLIB}/${STATBNDDIR})"
CMD="${CMD} BNDSRVPGM(QADRTTS)"
CMD="${CMD} TEXT('curl API library')"
CMD="${CMD} TGTRLS(${TGTRLS})"
system "${CMD}"
LINK=YES
fi
# If needed, (re)create the dynamic binding directory.
if action_needed "${LIBIFSNAME}/${DYNBNDDIR}.BNDDIR"
then LINK=YES
fi
if [ "${LINK}" ]
then rm -rf "${LIBIFSNAME}/${DYNBNDDIR}.BNDDIR"
CMD="CRTBNDDIR BNDDIR(${TARGETLIB}/${DYNBNDDIR})"
CMD="${CMD} TEXT('LibCurl API dynamic binding directory')"
system "${CMD}"
CMD="ADDBNDDIRE BNDDIR(${TARGETLIB}/${DYNBNDDIR})"
CMD="${CMD} OBJ((*LIBL/${SRVPGM} *SRVPGM))"
system "${CMD}"
fi
# Rebuild the formdata test if needed.
if [ "${TEST_FORMDATA}" ]
then MODULES=
make_module TFORMDATA formdata.c "'_FORM_DEBUG' 'CURLDEBUG'"
make_module TSTREQUAL strequal.c "'_FORM_DEBUG' 'CURLDEBUG'"
make_module TMEMDEBUG memdebug.c "'_FORM_DEBUG' 'CURLDEBUG'"
make_module TMPRINTF mprintf.c "'_FORM_DEBUG' 'CURLDEBUG'"
make_module TSTRERROR strerror.c "'_FORM_DEBUG' 'CURLDEBUG'"
# The following modules should not be needed (see comment in
# formdata.c. However, there are some unsatisfied
# external references leading in the following
# modules to be (recursively) needed.
MODULES="${MODULES} EASY STRDUP SSLGEN QSSL HOSTIP HOSTIP4 HOSTIP6"
MODULES="${MODULES} URL HASH TRANSFER GETINFO COOKIE SENDF SELECT"
MODULES="${MODULES} INET_NTOP SHARE HOSTTHRE MULTI LLIST FTP HTTP"
MODULES="${MODULES} HTTP_DIGES HTTP_CHUNK HTTP_NEGOT TIMEVAL HOSTSYN"
MODULES="${MODULES} CONNECT SOCKS PROGRESS ESCAPE INET_PTON GETENV"
MODULES="${MODULES} DICT LDAP TELNET FILE TFTP NETRC PARSEDATE"
MODULES="${MODULES} SPEEDCHECK SPLAY BASE64 SECURITY IF2IP MD5"
MODULES="${MODULES} KRB5 OS400SYS"
PGMIFSNAME="${LIBIFSNAME}/TFORMDATA.PGM"
if action_needed "${PGMIFSNAME}"
then LINK=YES
fi
if [ "${LINK}" ]
then CMD="CRTPGM PGM(${TARGETLIB}/TFORMDATA)"
CMD="${CMD} ENTMOD(QADRT/QADRTMAIN2)"
CMD="${CMD} MODULE("
for MODULE in ${MODULES}
do CMD="${CMD} ${TARGETLIB}/${MODULE}"
done
CMD="${CMD} ) BNDSRVPGM(QADRTTS)"
CMD="${CMD} TGTRLS(${TGTRLS})"
system "${CMD}"
fi
fi

View File

@@ -0,0 +1,5 @@
#!/bin/sh
#
# $Id$
#
# Not implemented yet on OS/400.

View File

@@ -0,0 +1,102 @@
#!/bin/sh
#
# tests compilation script for the OS/400.
#
# $Id$
SCRIPTDIR=`dirname "${0}"`
. "${SCRIPTDIR}/initscript.sh"
cd "${TOPDIR}/tests"
# tests directory not implemented yet.
# Process the libtest subdirectory.
cd libtest
# Get definitions from the Makefile.am file.
# The `sed' statement works as follows:
# _ Join \nl-separated lines.
# _ Retain only lines that begins with "identifier =".
# _ Turn these lines into shell variable assignments.
eval "`sed -e ': begin' \
-e '/\\\\$/{' \
-e 'N' \
-e 's/\\\\\\n/ /' \
-e 'b begin' \
-e '}' \
-e '/^[A-Za-z_][A-Za-z0-9_]*[ ]*[=]/b keep' \
-e 'd' \
-e ': keep' \
-e 's/[ ]*=[ ]*/=/' \
-e 's/=\\(.*[^ ]\\)[ ]*$/=\\"\\1\\"/' \
-e 's/\\$(\\([^)]*\\))/${\\1}/g' \
< Makefile.am`"
# Compile all programs.
# The list is found in variable "noinst_PROGRAMS"
INCLUDES="'${TOPDIR}/tests/libtest' '${TOPDIR}/lib'"
for PGM in ${noinst_PROGRAMS}
do DB2PGM=`db2_name "${PGM}"`
PGMIFSNAME="${LIBIFSNAME}/${DB2PGM}.PGM"
# Extract preprocessor symbol definitions from compilation
# options for the program.
PGMCFLAGS="`eval echo \"\\${${PGM}_CFLAGS}\"`"
PGMDEFINES=
for FLAG in ${PGMCFLAGS}
do case "${FLAG}" in
-D?*) DEFINE="`echo \"${FLAG}\" | sed 's/^..//'`"
PGMDEFINES="${PGMDEFINES} '${DEFINE}'"
;;
esac
done
# Compile all C sources for the program into modules.
PGMSOURCES="`eval echo \"\\${${PGM}_SOURCES}\"`"
LINK=
MODULES=
for SOURCE in ${PGMSOURCES}
do case "${SOURCE}" in
*.c) # Special processing for libxxx.c files: their
# module name is determined by the target
# PROGRAM name.
case "${SOURCE}" in
lib*.c) MODULE="${DB2PGM}"
;;
*) MODULE=`db2_name "${SOURCE}"`
;;
esac
make_module "${MODULE}" "${SOURCE}" "${PGMDEFINES}"
if action_needed "${PGMIFSNAME}" "${MODIFSNAME}"
then LINK=yes
fi
;;
esac
done
# Link program if needed.
if [ "${LINK}" ]
then MODULES="`echo \"${MODULES}\" |
sed \"s/[^ ][^ ]*/${TARGETLIB}\/&/g\"`"
CMD="CRTPGM PGM(${TARGETLIB}/${DB2PGM})"
CMD="${CMD} ENTMOD(QADRT/QADRTMAIN2)"
CMD="${CMD} MODULE(${MODULES})"
CMD="${CMD} BNDSRVPGM(${TARGETLIB}/${SRVPGM} QADRTTS)"
CMD="${CMD} TGTRLS(${TGTRLS})"
system "${CMD}"
fi
done

View File

@@ -0,0 +1,26 @@
#!/bin/sh
#
# curl compilation script for the OS/400.
#
# $Id$
#
# This is a shell script since make is not a standard component of OS/400.
SCRIPTDIR=`dirname "${0}"`
. "${SCRIPTDIR}/initscript.sh"
cd "${TOPDIR}"
# Create the OS/400 library if it does not exist.
if action_needed "${LIBIFSNAME}"
then CMD="CRTLIB LIB(${TARGETLIB}) TEXT('curl: multiprotocol support API')"
system "${CMD}"
fi
# Build in each directory.
for SUBDIR in include lib src tests
do "${SCRIPTDIR}/make-${SUBDIR}.sh"
done

957
packages/OS400/os400sys.c Normal file
View File

@@ -0,0 +1,957 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, 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 http://curl.haxx.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.
*
* $Id$
*
***************************************************************************/
/* OS/400 additional support. */
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <netdb.h>
#include <qadrt.h>
#include <errno.h>
#include <qsossl.h>
#include <gssapi.h>
#include <ldap.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "config-os400.h" /* Not config.h: need only some defines. */
#include "os400sys.h"
/**
*** QADRT OS/400 ASCII runtime defines only the most used procedures, but
*** but a lot of them are not supported. This module implements
*** ASCII wrappers for those that are used by libcurl, but not
*** defined by QADRT.
**/
#pragma convert(0) /* Restore EBCDIC. */
#define MIN_BYTE_GAIN 1024 /* Minimum gain when shortening a buffer. */
typedef struct {
unsigned long size; /* Buffer size. */
char * buf; /* Buffer address. */
} buffer_t;
static char * buffer_undef(localkey_t key, long size);
static char * buffer_threaded(localkey_t key, long size);
static char * buffer_unthreaded(localkey_t key, long size);
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_key_t thdkey;
static buffer_t * locbufs;
char * (* Curl_thread_buffer)(localkey_t key, long size) = buffer_undef;
static void
thdbufdestroy(void * private)
{
localkey_t i;
buffer_t * p;
if (private) {
p = (buffer_t *) private;
for (i = (localkey_t) 0; i < LK_LAST; i++) {
if (p->buf)
free(p->buf);
p++;
}
free(private);
}
}
static void
terminate(void)
{
if (Curl_thread_buffer == buffer_threaded) {
locbufs = pthread_getspecific(thdkey);
pthread_setspecific(thdkey, (void *) NULL);
pthread_key_delete(thdkey);
}
if (Curl_thread_buffer != buffer_undef) {
thdbufdestroy((void *) locbufs);
locbufs = (buffer_t *) NULL;
}
Curl_thread_buffer = buffer_undef;
}
static char *
get_buffer(buffer_t * buf, long size)
{
char * cp;
/* If `size' >= 0, make sure buffer at `buf' is at least `size'-byte long.
Return the buffer address. */
if (size < 0)
return buf->buf;
if (!buf->buf) {
if ((buf->buf = malloc(size)))
buf->size = size;
return buf->buf;
}
if ((unsigned long) size <= buf->size) {
/* Shorten the buffer only if it frees a significant byte count. This
avoids some realloc() overhead. */
if (buf->size - size < MIN_BYTE_GAIN)
return buf->buf;
}
/* Resize the buffer. */
if ((cp = realloc(buf->buf, size))) {
buf->buf = cp;
buf->size = size;
}
else if (size <= buf->size)
cp = buf->buf;
return cp;
}
static char *
buffer_unthreaded(localkey_t key, long size)
{
return get_buffer(locbufs + key, size);
}
static char *
buffer_threaded(localkey_t key, long size)
{
buffer_t * bufs;
/* Get the buffer for the given local key in the current thread, and
make sure it is at least `size'-byte long. Set `size' to < 0 to get
its address only. */
bufs = (buffer_t *) pthread_getspecific(thdkey);
if (!bufs) {
if (size < 0)
return (char *) NULL; /* No buffer yet. */
/* Allocate buffer descriptors for the current thread. */
if (!(bufs = (buffer_t *) calloc((size_t) LK_LAST, sizeof *bufs)))
return (char *) NULL;
if (pthread_setspecific(thdkey, (void *) bufs)) {
free(bufs);
return (char *) NULL;
}
}
return get_buffer(bufs + key, size);
}
static char *
buffer_undef(localkey_t key, long size)
{
/* Define the buffer system, get the buffer for the given local key in
the current thread, and make sure it is at least `size'-byte long.
Set `size' to < 0 to get its address only. */
pthread_mutex_lock(&mutex);
/* Determine if we can use pthread-specific data. */
if (Curl_thread_buffer == buffer_undef) { /* If unchanged during lock. */
if (!pthread_key_create(&thdkey, thdbufdestroy))
Curl_thread_buffer = buffer_threaded;
else if (!(locbufs = (buffer_t *) calloc((size_t) LK_LAST,
sizeof *locbufs))) {
pthread_mutex_unlock(&mutex);
return (char *) NULL;
}
else
Curl_thread_buffer = buffer_unthreaded;
atexit(terminate);
}
pthread_mutex_unlock(&mutex);
return Curl_thread_buffer(key, size);
}
int
Curl_getnameinfo_a(const struct sockaddr * sa, socklen_t salen,
char * nodename, socklen_t nodenamelen,
char * servname, socklen_t servnamelen,
int flags)
{
char * enodename;
char * eservname;
int status;
int i;
enodename = (char *) NULL;
eservname = (char *) NULL;
if (nodename && nodenamelen)
if (!(enodename = malloc(nodenamelen)))
return EAI_MEMORY;
if (servname && servnamelen)
if (!(eservname = malloc(servnamelen))) {
if (enodename)
free(enodename);
return EAI_MEMORY;
}
status = getnameinfo(sa, salen, enodename, nodenamelen,
eservname, servnamelen, flags);
if (!status) {
if (enodename) {
i = QadrtConvertE2A(nodename, enodename,
nodenamelen - 1, strlen(enodename));
nodename[i] = '\0';
}
if (eservname) {
i = QadrtConvertE2A(servname, eservname,
servnamelen - 1, strlen(eservname));
servname[i] = '\0';
}
}
if (enodename)
free(enodename);
if (eservname)
free(eservname);
return status;
}
int
Curl_getaddrinfo_a(const char * nodename, const char * servname,
const struct addrinfo * hints,
struct addrinfo * * res)
{
char * enodename;
char * eservname;
int status;
int i;
enodename = (char *) NULL;
eservname = (char *) NULL;
if (nodename) {
i = strlen(nodename);
if (!(enodename = malloc(i + 1)))
return EAI_MEMORY;
i = QadrtConvertA2E(enodename, nodename, i, i);
enodename[i] = '\0';
}
if (servname) {
i = strlen(servname);
if (!(eservname = malloc(i + 1))) {
if (enodename)
free(enodename);
return EAI_MEMORY;
}
QadrtConvertA2E(eservname, servname, i, i);
eservname[i] = '\0';
}
status = getaddrinfo(enodename, eservname, hints, res);
if (enodename)
free(enodename);
if (eservname)
free(eservname);
return status;
}
int
Curl_inet_ntoa_r_a(struct in_addr internet_address,
char * output_buffer, int output_buffer_length)
{
int rc;
int i;
char * cp;
if (!output_buffer || output_buffer_length < 16)
return inet_ntoa_r(internet_address, output_buffer, output_buffer_length);
if (!(cp = malloc(output_buffer_length + 1)))
return -1;
rc = inet_ntoa_r(internet_address, cp, output_buffer_length);
if (rc) {
free(cp);
return rc;
}
cp[output_buffer_length - 1] = '\0';
i = strlen(cp);
QadrtConvertE2A(output_buffer, cp, i, i);
output_buffer[i] = '\0';
free(cp);
return rc;
}
#ifdef USE_QSOSSL
/* ASCII wrappers for the SSL procedures. */
int
Curl_SSL_Init_Application_a(SSLInitApp * init_app)
{
int rc;
unsigned int i;
SSLInitApp ia;
if (!init_app || !init_app->applicationID || !init_app->applicationIDLen)
return SSL_Init_Application(init_app);
memcpy((char *) &ia, (char *) init_app, sizeof ia);
i = ia.applicationIDLen;
if (!(ia.applicationID = malloc(i + 1))) {
errno = ENOMEM;
return SSL_ERROR_IO;
}
QadrtConvertA2E(ia.applicationID, init_app->applicationID, i, i);
ia.applicationID[i] = '\0';
rc = SSL_Init_Application(&ia);
free(ia.applicationID);
init_app->localCertificateLen = ia.localCertificateLen;
init_app->sessionType = ia.sessionType;
return rc;
}
int
Curl_SSL_Init_a(SSLInit * init)
{
int rc;
unsigned int i;
SSLInit ia;
if (!init || (!init->keyringFileName && !init->keyringPassword))
return SSL_Init(init);
memcpy((char *) &ia, (char *) init, sizeof ia);
if (ia.keyringFileName) {
i = strlen(ia.keyringFileName);
if (!(ia.keyringFileName = malloc(i + 1))) {
errno = ENOMEM;
return SSL_ERROR_IO;
}
QadrtConvertA2E(ia.keyringFileName, init->keyringFileName, i, i);
ia.keyringFileName[i] = '\0';
}
if (ia.keyringPassword) {
i = strlen(ia.keyringPassword);
if (!(ia.keyringPassword = malloc(i + 1))) {
if (ia.keyringFileName)
free(ia.keyringFileName);
errno = ENOMEM;
return SSL_ERROR_IO;
}
QadrtConvertA2E(ia.keyringPassword, init->keyringPassword, i, i);
ia.keyringPassword[i] = '\0';
}
rc = SSL_Init(&ia);
if (ia.keyringFileName)
free(ia.keyringFileName);
if (ia.keyringPassword)
free(ia.keyringPassword);
return rc;
}
char *
Curl_SSL_Strerror_a(int sslreturnvalue, SSLErrorMsg * serrmsgp)
{
int i;
char * cp;
char * cp2;
cp = SSL_Strerror(sslreturnvalue, serrmsgp);
if (!cp)
return cp;
i = strlen(cp);
if (!(cp2 = Curl_thread_buffer(LK_SSL_ERROR, MAX_CONV_EXPANSION * i + 1)))
return cp2;
i = QadrtConvertE2A(cp2, cp, MAX_CONV_EXPANSION * i, i);
cp2[i] = '\0';
return cp2;
}
#endif /* USE_QSOSSL */
#ifdef HAVE_GSSAPI
/* ASCII wrappers for the GSSAPI procedures. */
static int
Curl_gss_convert_in_place(OM_uint32 * minor_status, gss_buffer_t buf)
{
unsigned int i;
char * t;
/* Convert `buf' in place, from EBCDIC to ASCII.
If error, release the buffer and return -1. Else return 0. */
i = buf->length;
if (i) {
if (!(t = malloc(i))) {
gss_release_buffer(minor_status, buf);
if (minor_status)
*minor_status = ENOMEM;
return -1;
}
QadrtConvertE2A(t, buf->value, i, i);
memcpy(buf->value, t, i);
free(t);
}
return 0;
}
OM_uint32
Curl_gss_import_name_a(OM_uint32 * minor_status, gss_buffer_t in_name,
gss_OID in_name_type, gss_name_t * out_name)
{
int rc;
unsigned int i;
gss_buffer_desc in;
if (!in_name || !in_name->value || !in_name->length)
return gss_import_name(minor_status, in_name, in_name_type, out_name);
memcpy((char *) &in, (char *) in_name, sizeof in);
i = in.length;
if (!(in.value = malloc(i + 1))) {
if (minor_status)
*minor_status = ENOMEM;
return GSS_S_FAILURE;
}
QadrtConvertA2E(in.value, in_name->value, i, i);
((char *) in.value)[i] = '\0';
rc = gss_import_name(minor_status, &in, in_name_type, out_name);
free(in.value);
return rc;
}
OM_uint32
Curl_gss_display_status_a(OM_uint32 * minor_status, OM_uint32 status_value,
int status_type, gss_OID mech_type,
gss_msg_ctx_t * message_context, gss_buffer_t status_string)
{
int rc;
rc = gss_display_status(minor_status, status_value, status_type,
mech_type, message_context, status_string);
if (rc != GSS_S_COMPLETE || !status_string ||
!status_string->length || !status_string->value)
return rc;
/* No way to allocate a buffer here, because it will be released by
gss_release_buffer(). The solution is to overwrite the EBCDIC buffer
with ASCII to return it. */
if (Curl_gss_convert_in_place(minor_status, status_string))
return GSS_S_FAILURE;
return rc;
}
OM_uint32
Curl_gss_init_sec_context_a(OM_uint32 * minor_status, gss_cred_id_t cred_handle,
gss_ctx_id_t * context_handle,
gss_name_t target_name, gss_OID mech_type,
gss_flags_t req_flags, OM_uint32 time_req,
gss_channel_bindings_t input_chan_bindings,
gss_buffer_t input_token,
gss_OID * actual_mech_type,
gss_buffer_t output_token, gss_flags_t * ret_flags,
OM_uint32 * time_rec)
{
int rc;
unsigned int i;
gss_buffer_desc in;
gss_buffer_t inp;
in.value = NULL;
if ((inp = input_token))
if (inp->length && inp->value) {
i = inp->length;
if (!(in.value = malloc(i + 1))) {
if (minor_status)
*minor_status = ENOMEM;
return GSS_S_FAILURE;
}
QadrtConvertA2E(in.value, input_token->value, i, i);
((char *) in.value)[i] = '\0';
in.length = i;
inp = &in;
}
rc = gss_init_sec_context(minor_status, cred_handle, context_handle,
target_name, mech_type, req_flags, time_req,
input_chan_bindings, inp, actual_mech_type,
output_token, ret_flags, time_rec);
if (in.value)
free(in.value);
if (rc != GSS_S_COMPLETE || !output_token ||
!output_token->length || !output_token->value)
return rc;
/* No way to allocate a buffer here, because it will be released by
gss_release_buffer(). The solution is to overwrite the EBCDIC buffer
with ASCII to return it. */
if (Curl_gss_convert_in_place(minor_status, output_token))
return GSS_S_FAILURE;
return rc;
}
OM_uint32
Curl_gss_delete_sec_context_a(OM_uint32 * minor_status,
gss_ctx_id_t * context_handle,
gss_buffer_t output_token)
{
int rc;
rc = gss_delete_sec_context(minor_status, context_handle, output_token);
if (rc != GSS_S_COMPLETE || !output_token ||
!output_token->length || !output_token->value)
return rc;
/* No way to allocate a buffer here, because it will be released by
gss_release_buffer(). The solution is to overwrite the EBCDIC buffer
with ASCII to return it. */
if (Curl_gss_convert_in_place(minor_status, output_token))
return GSS_S_FAILURE;
return rc;
}
#endif /* HAVE_GSSAPI */
#ifndef CURL_DISABLE_LDAP
/* ASCII wrappers for the LDAP procedures. */
void *
Curl_ldap_init_a(char * host, int port)
{
unsigned int i;
char * ehost;
void * result;
if (!host)
return (void *) ldap_init(host, port);
i = strlen(host);
if (!(ehost = malloc(i + 1)))
return (void *) NULL;
QadrtConvertA2E(ehost, host, i, i);
ehost[i] = '\0';
result = (void *) ldap_init(ehost, port);
free(ehost);
return result;
}
int
Curl_ldap_simple_bind_s_a(void * ld, char * dn, char * passwd)
{
int i;
char * edn;
char * epasswd;
edn = (char *) NULL;
epasswd = (char *) NULL;
if (dn) {
i = strlen(dn);
if (!(edn = malloc(i + 1)))
return LDAP_NO_MEMORY;
QadrtConvertA2E(edn, dn, i, i);
edn[i] = '\0';
}
if (passwd) {
i = strlen(passwd);
if (!(epasswd = malloc(i + 1))) {
if (edn)
free(edn);
return LDAP_NO_MEMORY;
}
QadrtConvertA2E(epasswd, passwd, i, i);
epasswd[i] = '\0';
}
i = ldap_simple_bind_s(ld, edn, epasswd);
if (epasswd)
free(epasswd);
if (edn)
free(edn);
return i;
}
int
Curl_ldap_search_s_a(void * ld, char * base, int scope, char * filter,
char * * attrs, int attrsonly, LDAPMessage * * res)
{
int i;
int j;
char * ebase;
char * efilter;
char * * eattrs;
int status;
ebase = (char *) NULL;
efilter = (char *) NULL;
eattrs = (char * *) NULL;
status = LDAP_SUCCESS;
if (base) {
i = strlen(base);
if (!(ebase = malloc(i + 1)))
status = LDAP_NO_MEMORY;
else {
QadrtConvertA2E(ebase, base, i, i);
ebase[i] = '\0';
}
}
if (filter && status == LDAP_SUCCESS) {
i = strlen(filter);
if (!(efilter = malloc(i + 1)))
status = LDAP_NO_MEMORY;
else {
QadrtConvertA2E(efilter, filter, i, i);
efilter[i] = '\0';
}
}
if (attrs && status == LDAP_SUCCESS) {
for (i = 0; attrs[i++];)
;
if (!(eattrs = (char * *) calloc(i, sizeof *eattrs)))
status = LDAP_NO_MEMORY;
else {
for (j = 0; attrs[j]; j++) {
i = strlen(attrs[j]);
if (!(eattrs[j] = malloc(i + 1))) {
status = LDAP_NO_MEMORY;
break;
}
QadrtConvertA2E(eattrs[j], attrs[j], i, i);
eattrs[j][i] = '\0';
}
}
}
if (status == LDAP_SUCCESS)
status = ldap_search_s(ld, ebase? ebase: "", scope,
efilter? efilter: "(objectclass=*)",
eattrs, attrsonly, res);
if (eattrs) {
for (j = 0; eattrs[j]; j++)
free(eattrs[j]);
free(eattrs);
}
if (efilter)
free(efilter);
if (ebase)
free(ebase);
return status;
}
struct berval * *
Curl_ldap_get_values_len_a(void * ld, LDAPMessage * entry, const char * attr)
{
int i;
char * cp;
struct berval * * result;
cp = (char *) NULL;
if (attr) {
i = strlen(attr);
if (!(cp = malloc(i + 1))) {
ldap_set_lderrno(ld, LDAP_NO_MEMORY, NULL,
ldap_err2string(LDAP_NO_MEMORY));
return (struct berval * *) NULL;
}
QadrtConvertA2E(cp, attr, i, i);
cp[i] = '\0';
}
result = ldap_get_values_len(ld, entry, cp);
if (cp)
free(cp);
/* Result data are binary in nature, so they haven't been converted to EBCDIC.
Therefore do not convert. */
return result;
}
char *
Curl_ldap_err2string_a(int error)
{
int i;
char * cp;
char * cp2;
cp = ldap_err2string(error);
if (!cp)
return cp;
i = strlen(cp);
if (!(cp2 = Curl_thread_buffer(LK_LDAP_ERROR, MAX_CONV_EXPANSION * i + 1)))
return cp2;
i = QadrtConvertE2A(cp2, cp, MAX_CONV_EXPANSION * i, i);
cp2[i] = '\0';
return cp2;
}
char *
Curl_ldap_get_dn_a(void * ld, LDAPMessage * entry)
{
int i;
char * cp;
char * cp2;
cp = ldap_get_dn(ld, entry);
if (!cp)
return cp;
i = strlen(cp);
if (!(cp2 = malloc(i + 1)))
return cp2;
QadrtConvertE2A(cp2, cp, i, i);
/* No way to allocate a buffer here, because it will be released by
ldap_memfree() and ldap_memalloc() does not exist. The solution is to
overwrite the EBCDIC buffer with ASCII to return it. */
strcpy(cp, cp2);
free(cp2);
return cp;
}
char *
Curl_ldap_first_attribute_a(void * ld,
LDAPMessage * entry, BerElement * * berptr)
{
int i;
char * cp;
char * cp2;
cp = ldap_first_attribute(ld, entry, berptr);
if (!cp)
return cp;
i = strlen(cp);
if (!(cp2 = malloc(i + 1)))
return cp2;
QadrtConvertE2A(cp2, cp, i, i);
/* No way to allocate a buffer here, because it will be released by
ldap_memfree() and ldap_memalloc() does not exist. The solution is to
overwrite the EBCDIC buffer with ASCII to return it. */
strcpy(cp, cp2);
free(cp2);
return cp;
}
char *
Curl_ldap_next_attribute_a(void * ld,
LDAPMessage * entry, BerElement * berptr)
{
int i;
char * cp;
char * cp2;
cp = ldap_next_attribute(ld, entry, berptr);
if (!cp)
return cp;
i = strlen(cp);
if (!(cp2 = malloc(i + 1)))
return cp2;
QadrtConvertE2A(cp2, cp, i, i);
/* No way to allocate a buffer here, because it will be released by
ldap_memfree() and ldap_memalloc() does not exist. The solution is to
overwrite the EBCDIC buffer with ASCII to return it. */
strcpy(cp, cp2);
free(cp2);
return cp;
}
#endif /* CURL_DISABLE_LDAP */

53
packages/OS400/os400sys.h Normal file
View File

@@ -0,0 +1,53 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, 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 http://curl.haxx.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.
*
* $Id$
*
***************************************************************************/
/* OS/400 additional definitions. */
#ifndef __OS400_SYS_
#define __OS400_SYS_
/* Per-thread item identifiers. */
typedef enum {
LK_SSL_ERROR,
LK_LDAP_ERROR,
LK_CURL_VERSION,
LK_VERSION_INFO,
LK_VERSION_INFO_DATA,
LK_EASY_STRERROR,
LK_SHARE_STRERROR,
LK_MULTI_STRERROR,
LK_LAST
} localkey_t;
extern char * (* Curl_thread_buffer)(localkey_t key, long size);
/* Maximum string expansion factor due to character code conversion. */
#define MAX_CONV_EXPANSION 4 /* Can deal with UTF-8. */
#endif