diff --git a/config.h.in b/config.h.in index b8af0d74..f719fe92 100644 --- a/config.h.in +++ b/config.h.in @@ -34,6 +34,10 @@ #undef HAVE_PAM_PAM_APPL_H +// String functions +#undef HAVE_STRLCPY + + // Random number support #undef HAVE_SYS_RANDOM_H #undef HAVE_ARC4RANDOM diff --git a/configure b/configure index a4da30b1..a78dd50e 100755 --- a/configure +++ b/configure @@ -1473,6 +1473,119 @@ fi } # ac_fn_c_try_compile +# ac_fn_c_try_link LINENO +# ----------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_link () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext conftest$ac_exeext + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + test -x conftest$ac_exeext + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information + # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would + # interfere with the next link command; also delete a directory that is + # left behind by Apple's compiler. We do this before executing the actions. + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_link + +# ac_fn_c_check_func LINENO FUNC VAR +# ---------------------------------- +# Tests whether FUNC exists, setting the cache variable VAR accordingly +ac_fn_c_check_func () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +/* Define $2 to an innocuous variant, in case declares $2. + For example, HP-UX 11i declares gettimeofday. */ +#define $2 innocuous_$2 + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $2 (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $2 + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char $2 (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined __stub_$2 || defined __stub___$2 +choke me +#endif + +int +main () +{ +return $2 (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_c_check_func + # ac_fn_c_try_cpp LINENO # ---------------------- # Try to preprocess conftest.$ac_ext, and return whether this succeeded. @@ -1673,119 +1786,6 @@ $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_compile - -# ac_fn_c_try_link LINENO -# ----------------------- -# Try to link conftest.$ac_ext, and return whether this succeeded. -ac_fn_c_try_link () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - rm -f conftest.$ac_objext conftest$ac_exeext - if { { ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_link") 2>conftest.err - ac_status=$? - if test -s conftest.err; then - grep -v '^ *+' conftest.err >conftest.er1 - cat conftest.er1 >&5 - mv -f conftest.er1 conftest.err - fi - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - test -x conftest$ac_exeext - }; then : - ac_retval=0 -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_retval=1 -fi - # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information - # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would - # interfere with the next link command; also delete a directory that is - # left behind by Apple's compiler. We do this before executing the actions. - rm -rf conftest.dSYM conftest_ipa8_conftest.oo - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - as_fn_set_status $ac_retval - -} # ac_fn_c_try_link - -# ac_fn_c_check_func LINENO FUNC VAR -# ---------------------------------- -# Tests whether FUNC exists, setting the cache variable VAR accordingly -ac_fn_c_check_func () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 -$as_echo_n "checking for $2... " >&6; } -if eval \${$3+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -/* Define $2 to an innocuous variant, in case declares $2. - For example, HP-UX 11i declares gettimeofday. */ -#define $2 innocuous_$2 - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $2 (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $2 - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $2 (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$2 || defined __stub___$2 -choke me -#endif - -int -main () -{ -return $2 (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - eval "$3=yes" -else - eval "$3=no" -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -fi -eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - -} # ac_fn_c_check_func cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. @@ -3415,6 +3415,19 @@ fi +for ac_func in strlcpy +do : + ac_fn_c_check_func "$LINENO" "strlcpy" "ac_cv_func_strlcpy" +if test "x$ac_cv_func_strlcpy" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_STRLCPY 1 +_ACEOF + +fi +done + + + ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -5572,3 +5585,6 @@ if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: PAPPL is currently under active development but is not yet usable." >&5 +$as_echo "$as_me: WARNING: PAPPL is currently under active development but is not yet usable." >&2;} diff --git a/configure.ac b/configure.ac index 41cf8299..e94a564c 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ dnl -dnl Configuration script for LPrint, a Label Printer Application +dnl Configuration script for the Printer Application Framework dnl dnl Copyright © 2019-2020 by Michael R Sweet dnl @@ -106,6 +106,10 @@ else fi +dnl String functions... +AC_CHECK_FUNCS(strlcpy) + + dnl Random number support... AC_CHECK_HEADER(sys/random.h, AC_DEFINE([HAVE_SYS_RANDOM_H], 1, [Have header?])) AC_CHECK_FUNCS(arc4random getrandom gnutls_rnd) @@ -342,3 +346,5 @@ AC_ARG_WITH(ldflags, [ --with-ldflags=... Specify additional LDFLAGS ], dnl Generate the Makefile... AC_OUTPUT(Makedefs) + +AC_MSG_WARN([PAPPL is currently under active development but is not yet usable.]) diff --git a/pappl/base-private.h b/pappl/base-private.h new file mode 100644 index 00000000..5bf029f2 --- /dev/null +++ b/pappl/base-private.h @@ -0,0 +1,60 @@ +// +// Private base definitions for the Printer Application Framework +// +// Copyright © 2019-2020 by Michael R Sweet. +// +// Licensed under Apache License v2.0. See the file "LICENSE" for more +// information. +// + +#ifndef _PAPPL_BASE_PRIVATE_H_ +# define _PAPPL_BASE_PRIVATE_H_ + + +// +// Include necessary headers... +// + +# include +# include +# include +# include +# include +# include +# include "base.h" + +extern char **environ; + + +// +// Macros... +// + +# ifdef DEBUG +# define _PAPPL_DEBUG(...) fprintf(stderr, __VA_ARGS__) +# else +# define _PAPPL_DEBUG(...) +# endif // DEBUG + +# define _PAPPL_LOOKUP_STRING(bit,strings) _papplLookupString(bit, sizeof(strings) / sizeof(strings[0]), strings) +# define _PAPPL_LOOKUP_VALUE(keyword,strings) _papplLookupValue(keyword, sizeof(strings) / sizeof(strings[0]), strings) + +# ifndef HAVE_STRLCPY +# define strlcpy(dst,src,dstsize) _pappl_strlcpy(dst,src,dstsize) +# endif // !HAVE_STRLCPY + + +// +// Utility functions... +// + +# ifndef HAVE_STRLCPY +extern size_t _pappl_strlcpy(char *dst, const char *src, size_t dstsize) _PAPPL_EXTERN; +# endif // !HAVE_STRLCPY +extern void _papplCopyAttributes(ipp_t *to, ipp_t *from, cups_array_t *ra, ipp_tag_t group_tag, int quickcopy) _PAPPL_PRIVATE; +extern unsigned _papplGetRand(void) _PAPPL_PRIVATE; +extern const char *_papplLookupString(unsigned bit, size_t num_strings, const char * const *strings) _PAPPL_PRIVATE; +extern unsigned _papplLookupValue(const char *keyword, size_t num_strings, const char * const *strings) _PAPPL_PRIVATE; + + +#endif // !_PAPPL_BASE_PRIVATE_H_ diff --git a/pappl/base.h b/pappl/base.h index 584b1136..14895f7f 100644 --- a/pappl/base.h +++ b/pappl/base.h @@ -44,17 +44,6 @@ # endif // CUPS_VERSION_MAJOR == 2 && CUPS_VERSION_MINOR < 3 -// -// Debug macro... -// - -# ifdef DEBUG -# define _PAPPL_DEBUG(...) fprintf(stderr, __VA_ARGS__) -# else -# define _PAPPL_DEBUG(...) -# endif // DEBUG - - // // Visibility and other annotations... // diff --git a/pappl/client-private.h b/pappl/client-private.h index bd5ec504..f82d99fb 100644 --- a/pappl/client-private.h +++ b/pappl/client-private.h @@ -15,6 +15,7 @@ // Include necessary headers... // +# include "base-private.h" # include "client.h" # include "log.h" diff --git a/pappl/device.c b/pappl/device.c index 933ee486..02cf37d2 100644 --- a/pappl/device.c +++ b/pappl/device.c @@ -12,7 +12,7 @@ // Include necessary headers... // -#include +#include "base-private.h" #include "device.h" #include #ifdef HAVE_LIBUSB diff --git a/pappl/job-private.h b/pappl/job-private.h index ecbbe80f..42244024 100644 --- a/pappl/job-private.h +++ b/pappl/job-private.h @@ -15,6 +15,7 @@ // Include necessary headers... // +# include "base-private.h" # include "job.h" # include "log.h" # include diff --git a/pappl/lookup.c b/pappl/lookup.c index c07f1255..7a969040 100644 --- a/pappl/lookup.c +++ b/pappl/lookup.c @@ -14,6 +14,34 @@ #include "pappl-private.h" +// +// '_pappl_strlcpy()' - Safely copy a C string. +// + +#ifndef HAVE_STRLCPY +size_t +_pappl_strlcpy(char *dst, // I - Destination buffer + const char *src, // I - Source string + size_t dstsize) // I - Destination size +{ + size_t srclen = strlen(src); // Length of source string + + + // Copy up to dstsize - 1 bytes + dstsize --; + + if (srclen > dstsize) + srclen = dstsize; + + memmove(dst, src, srclen); + + dst[srclen] = '\0'; + + return (srclen); +} +#endif // !HAVE_STRLCPY + + // // '_papplLookupString()' - Lookup the string value for a bit. // diff --git a/pappl/pappl-private.h b/pappl/pappl-private.h index e87e8796..12b4f91b 100644 --- a/pappl/pappl-private.h +++ b/pappl/pappl-private.h @@ -21,31 +21,4 @@ # include "printer-private.h" # include "job-private.h" -# include -# include -# include -# include -# include - -extern char **environ; - - -// -// Macros... -// - -# define _PAPPL_LOOKUP_STRING(bit,strings) _papplLookupString(bit, sizeof(strings) / sizeof(strings[0]), strings) -# define _PAPPL_LOOKUP_VALUE(keyword,strings) _papplLookupValue(keyword, sizeof(strings) / sizeof(strings[0]), strings) - - -// -// Utility functions... -// - -extern void _papplCopyAttributes(ipp_t *to, ipp_t *from, cups_array_t *ra, ipp_tag_t group_tag, int quickcopy) _PAPPL_PRIVATE; -extern unsigned _papplGetRand(void) _PAPPL_PRIVATE; -extern const char *_papplLookupString(unsigned bit, size_t num_strings, const char * const *strings) _PAPPL_PRIVATE; -extern unsigned _papplLookupValue(const char *keyword, size_t num_strings, const char * const *strings) _PAPPL_PRIVATE; - - #endif // !_PAPPL_PAPPL_PRIVATE_H_ diff --git a/pappl/printer-private.h b/pappl/printer-private.h index 902a5a80..78bee232 100644 --- a/pappl/printer-private.h +++ b/pappl/printer-private.h @@ -15,7 +15,7 @@ // Include necessary headers... // -# include "config.h" +# include "base-private.h" # include "printer.h" # include "log.h" # ifdef __APPLE__ diff --git a/pappl/snmp-private.h b/pappl/snmp-private.h index 3c18149e..8b938c98 100644 --- a/pappl/snmp-private.h +++ b/pappl/snmp-private.h @@ -17,8 +17,8 @@ // Include necessary headers. // -#include "base.h" -#include +# include "base-private.h" +# include // diff --git a/pappl/system-private.h b/pappl/system-private.h index 0edf2cfa..e2e437f1 100644 --- a/pappl/system-private.h +++ b/pappl/system-private.h @@ -15,6 +15,7 @@ // Include necessary headers... // +# include "base-private.h" # include "system.h" # include # include diff --git a/xcode/config.h b/xcode/config.h index 756638ef..9a5a4845 100644 --- a/xcode/config.h +++ b/xcode/config.h @@ -34,6 +34,10 @@ /* #undef HAVE_PAM_PAM_APPL_H */ +// String functions +#define HAVE_STRLCPY 1 + + // Random number support #define HAVE_SYS_RANDOM_H 1 #define HAVE_ARC4RANDOM 1 diff --git a/xcode/pappl.xcodeproj/project.pbxproj b/xcode/pappl.xcodeproj/project.pbxproj index 09ded484..7be58c46 100644 --- a/xcode/pappl.xcodeproj/project.pbxproj +++ b/xcode/pappl.xcodeproj/project.pbxproj @@ -51,6 +51,8 @@ 27EFC5EE241C85E00082CEA3 /* lookup.c in Sources */ = {isa = PBXBuildFile; fileRef = 27EFC5ED241C85DF0082CEA3 /* lookup.c */; }; 27EFC5F1241DB8390082CEA3 /* snmp-private.h in Headers */ = {isa = PBXBuildFile; fileRef = 27EFC5EF241DB8380082CEA3 /* snmp-private.h */; }; 27EFC5F2241DB8390082CEA3 /* snmp.c in Sources */ = {isa = PBXBuildFile; fileRef = 27EFC5F0241DB8390082CEA3 /* snmp.c */; }; + 27EFC5F4241E72920082CEA3 /* base-private.h in Headers */ = {isa = PBXBuildFile; fileRef = 27EFC5F3241E72910082CEA3 /* base-private.h */; }; + 27EFC5F6241E72AE0082CEA3 /* libpam.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 27EFC5F5241E72AE0082CEA3 /* libpam.tbd */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -102,6 +104,8 @@ 27EFC5ED241C85DF0082CEA3 /* lookup.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = lookup.c; path = ../pappl/lookup.c; sourceTree = ""; }; 27EFC5EF241DB8380082CEA3 /* snmp-private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "snmp-private.h"; path = "../pappl/snmp-private.h"; sourceTree = ""; }; 27EFC5F0241DB8390082CEA3 /* snmp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = snmp.c; path = ../pappl/snmp.c; sourceTree = ""; }; + 27EFC5F3241E72910082CEA3 /* base-private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "base-private.h"; path = "../pappl/base-private.h"; sourceTree = ""; }; + 27EFC5F5241E72AE0082CEA3 /* libpam.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libpam.tbd; path = usr/lib/libpam.tbd; sourceTree = SDKROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -109,6 +113,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 27EFC5F6241E72AE0082CEA3 /* libpam.tbd in Frameworks */, 27EFC5EB2415EC540082CEA3 /* libpng16.a in Frameworks */, 27EFC5EC2415EC540082CEA3 /* libusb-1.0.a in Frameworks */, 27EFC5E92415EBD70082CEA3 /* libjpeg.a in Frameworks */, @@ -146,6 +151,7 @@ isa = PBXGroup; children = ( 27905C66240D8896001D2A90 /* base.h */, + 27EFC5F3241E72910082CEA3 /* base-private.h */, 27905C6E240D8896001D2A90 /* client.h */, 27905C8D240D9067001D2A90 /* client-private.h */, 27905C6C240D8896001D2A90 /* client.c */, @@ -187,6 +193,7 @@ 27EFC5D42415EB550082CEA3 /* Frameworks */ = { isa = PBXGroup; children = ( + 27EFC5F5241E72AE0082CEA3 /* libpam.tbd */, 27EFC5E62415EBD70082CEA3 /* libjpeg.a */, 27EFC5E72415EBD70082CEA3 /* libpng16.a */, 27EFC5E52415EBD70082CEA3 /* libusb-1.0.a */, @@ -216,6 +223,7 @@ 27905C8F240D9067001D2A90 /* log.h in Headers */, 27905C7A240D8896001D2A90 /* pappl.h in Headers */, 27EFC5F1241DB8390082CEA3 /* snmp-private.h in Headers */, + 27EFC5F4241E72920082CEA3 /* base-private.h in Headers */, 27905C75240D8896001D2A90 /* printer.h in Headers */, 27905C7C240D8896001D2A90 /* system.h in Headers */, 27905C92240D9067001D2A90 /* client-private.h in Headers */,