diff --git a/.gitignore b/.gitignore index c23cd852..872dd938 100644 --- a/.gitignore +++ b/.gitignore @@ -1,24 +1,68 @@ -config.cache +# generic files to ignore +# backup files (*~) and vim swap file (.swp), MacOS dir file (.DS_Store) +*~ +*.lock +*.DS_Store +.*.swp +*.out +*.bak +*.zip +*.patch + +# except this file +!.gitignore + +# from autoreconf -i +compile config.guess -config.h -config.h.in -config.log -config.status config.sub -configure install-sh +missing +depcomp +ylwrap +test-driver +autom4te.cache +m4 +aclocal.m4 +config.cache +config.h.in configure -libtool ltconfig ltmain.sh -.deps -.libs -stamp-h* -aclocal.m4 -Makefile Makefile.in + +# from configure +config.h +config.status +config.log +Makefile +Makefile.PL +stamp-h* +libtool +.deps pilot-link.m4 pilot-link.pc pilot-link-pp.pc tags -autom4te.cache +include/pi-md5.h +include/pi-version.h +doc/xml/catalog.xml +doc/xml/docbook.xsl +doc/doxygen.cfg +bindings/Python/setup*.py + +# from make / cc / gcc +*.o +*.la +*.lo +*.so +.libs +src/pilot-* +!src/*.c +!src/*.h +!src/*.pl +src/parsedate.c +tests/*-test + +# from make install +dist diff --git a/README b/README index f5d90a68..eee373c8 100644 --- a/README +++ b/README @@ -14,7 +14,7 @@ Bugs and requests...: https://github.com/desrod/pilot-link/issues Code contributions..: https://github.com/desrod/pilot-link/pulls?q=is:pr If you are unwilling to use GitHub, you may instead contact me, David A. -Desrosiers, project maintainer, via email at . +Desrosiers, project maintainer, via email at . We used to be reachable on Internet Relay Chat, "irc", at irc.pilot-link.org in the channel #pilot-link. I used the name "setuid" there, and there were a @@ -43,7 +43,7 @@ List archive........: https://web.archive.org/web/2015/http://lists.pilot-link.o The architecture of pilot-link ------------------------------ -There are several core parts of pilot-link: +There are several core parts of pilot-link: The libraries ------------- @@ -79,7 +79,7 @@ There are several core parts of pilot-link: your favorite language of choice. Currently, pilot-link includes language "bindings" in Perl, Python, Java, and Tcl. This means you can use those languages, instead of C directly, to talk to your Palm - handheld device and communicate with it. + handheld device and communicate with it. Want to write a Java application that uses pilot-link's libraries? Simple! Just use the Java bindings. @@ -120,6 +120,24 @@ Building pilot-link on Linux/Unix systems options. Please make sure you use the --help option to "./configure" to make sure you're enabling all of the options you wish to use. + You will also need to have your development environment set up, which + will require such tools as automake, autoconf, libtool, some system + headers, and others to be properly installed and configured on your + machine first. If you are running a current Linux or Unix system, + these common tools are probably packaged for you. + You also need to satisfy the dependencies of these libraries: + libusb, libbluetooth, libpopt and byacc + On Debian systems you can therefore execute: + $ sudo apt install build-essential automake libtool-bin + $ sudo apt install libusb-dev libbluetooth-dev libpopt-dev byacc + + If you are using a GIT version of pilot-link, e.g. from + https://github.com/desrod/pilot-link/, you will have to run + 'sh ./autogen.sh' first, from the top-level directory, which will + create and bootstrap the "./configure" script for you. On modern systems + you may alternatively use 'autoupdate' and 'autoreconf -i -s' to + create the "./configure" script. + If you have downloaded this code from the website, or as a tarball, simply unpack the tarball and run "./configure" in the top-level directory with your specific arguments. "./configure --help" will @@ -134,12 +152,12 @@ Building pilot-link on Linux/Unix systems software. $ make - + After the source builds, feel free to play around in the 'src' - subdirectory, CAREFULLY. 'dlpsh' and 'pilot-xfer' are probably the - most useful programs for you, and also the safest to use + subdirectory, CAREFULLY. 'pilot-dlpsh' and 'pilot-xfer' are probably + the most useful programs for you, and also the safest to use non-destructively. - + Once you have determined that pilot-link works and suits your needs by testing with these programs, switch to the super user, typically "root", to install the conduits, libraries, docs, and headers @@ -157,17 +175,7 @@ Building pilot-link on Linux/Unix systems # make install - If you are using a CVS version of pilot-link, you will have to run - 'sh ./autogen.sh' instead, from the top-level directory, which will - create and bootstrap the "./configure" script for you. - - You will also need to have your development environment set up, which - will require such tools as automake, autoconf, libtool, some system - headers, and others to be properly installed and configured on your - machine first. If you are running a current Linux or Unix system, - these common tools are probably packaged for you. - -Building pilot-link on OS/2 +Building pilot-link on OS/2 --------------------------- pilot-link on OS/2 only supports serial devices. USB is unsupported @@ -179,17 +187,17 @@ Building pilot-link on OS/2 The steps are fairly straightforward. - Run the os2configure.cmd script in the top-level directory. - + Run the os2configure.cmd script in the top-level directory. + Run make -f Makefile.os2 - + Play around, CAREFULLY. pilot-xfer is probably the most useful program for you, and also the safest of all to use non-destructively. Also dlpsh is a good app to use to poke around in your Palm device. - + Run 'make install' if you you have tested thoroughly and are sure pilot-link works well for you. - + Note on pilot-debug: This program is a work-in-progress, and requires Tcl 7.5 (or greater) and optionally Tk 4.1 (or greater) and/or Readline 2.0. You'll need to modify Makefile to to use Readline 2.0, @@ -261,15 +269,15 @@ Building pilot-link on Apple OSX/Darwin first. The syntax to test pilot-link on OSX for USB devices is as follows: - -p usb: [arguments..] + -p usb: [arguments..] - One example of this is as follows: + One example of this is as follows: pilot-xfer --port usb: --list This should list the record and resource databases found on your Palm handheld device. - + Building pilot-link on Cygwin under Windows ------------------------------------------- @@ -277,12 +285,44 @@ Building pilot-link on Cygwin under Windows COM1 through the Cygwin virtual serial port bridging. +Basic use of pilot-link conduits +-------------------------------- + + On modern systems you probably use a USB connection to your Palm device. + For this it is recommended to use the standard Linux kernel modules + "usbserial" and "visor", which usually must be loaded first. On Debian + systems i.e. this looks as follows: + + $ sudo modprobe -a usbserial visor + + Then you can use all pilot-link commands, always with specifying a port. + Note that you must press the HotSync button on your device, before + invoking the command within few seconds at maximum. + On Debian systems i.e. type: + + $ -p /dev/ttyUSB1 [options..] [arguments..] + + Some rare devices may prefer `ttyUSB0`. + For special cases and details see the chapter below. + + +USB Notes +--------- + + Please see doc/README.usb for more detailed information on + configuring your system to use USB-enabled Palm handheld devices + using the standard Linux "visor" kernel module. + + If you would like to try the new libusb code, please see + doc/README.libusb for details on how to get that working properly. + + Some usage notes about pilot-link --------------------------------- - + read-ical and sync-ical will only run if you have ical-2.x installed and in the path. - + sync-plan is a full syncronization program, though it has some interesting quirks and requirements. You must run netplan from plan-1.6.1 (probably available at @@ -293,16 +333,16 @@ Some usage notes about pilot-link moment. Sync-plan leaves a file, that has a name starting with "pilothash", in the current directory. This file must be present for all future syncs between that plan database and that Palm. - + As sync-plan is a work in progress, please contact me with any problems. - + The default connection rate is 9600 baud. You are welcome to try higher baud rates (19200, 38400, or 57600) by setting the PILOTRATE environment variable, but various machines have various limitations. (Be careful about 38400 on a Linux box if you've been using setserial to change the multiplier.) - + pilot-mail (which requires a Palm with the new Mail application, as well as sendmail and/or a POP3 server) is still in the experimental stage. Run with an argument of '-H' for help. While I don't expect @@ -314,34 +354,14 @@ Some usage notes about pilot-link If you wish, you may easily change the default settings (pop host, password, etc.) for pilot-mail by editing the top of pilot-mail.c, as well as by setting the environment variables indicated in its help. - + Scott Grosch's "validate" program is included, and can be made via 'make validate', but it may not be of use to anyone but Scott. -Debugging notes ---------------- - - Please see doc/README.debugging for more detailed information - describing how to debug pilot-link's core protocols and interfaces. - Debugging pilot-link will allow us to make pilot-link work better on - new devices and with new applications. - - -USB Notes ---------- - - Please see doc/README.usb for more detailed information on - configuring your system to use USB-enabled Palm handheld devices - using the standard Linux "visor" kernel module. - - If you would like to try the new libusb code, please see - doc/README.libusb for details on how to get that working properly. - - FreeBSD Notes ------------- - + Please see doc/README.freebsd for more detailed information on setting up pilot-link to work with FreeBSD systems. In FreeBSD, you may have to set your ACLOCAL_FLAGS="-I /usr/local/share/aclocal/" @@ -360,32 +380,41 @@ FreeBSD Notes Embedding information --------------------- - + As of 0.5.0, the headers in pilot-link have been rearranged slightly so that it should be easier and more reliable to use the libpisock.a library in external applications. - + If you want to use the pilot-link portability layer (configured via autoconf), then include pi-source.h. Otherwise, do not touch this file, as it sets up a mildly complex environment. - + For all normal operations, simply include the obvious files (pi-file - for pdb and .prc file access, pi-dlp for DLP sync functions, etc.). + for pdb and .prc file access, pi-dlp for DLP sync functions, etc.). pi-macros contains the portable byte-access routines. +Debugging notes +--------------- + + Please see doc/README.debugging for more detailed information + describing how to debug pilot-link's core protocols and interfaces. + Debugging pilot-link will allow us to make pilot-link work better on + new devices and with new applications. + + Reporting Bugs -------------- - + Please visit https://github.com/desrod/pilot-link/issues to report any bugs you find with pilot-link. From there, any issue reported can be - updated, audited, commented on, and resolved. You can also attach + updated, audited, commented on, and resolved. You can also attach other relevant items to each bug report, to help the team solve the issues or add the features you have requested. - - PLEASE NOTE + + PLEASE NOTE ----------- - + Please check the existing issues in the system FIRST before reporting your bug. There may be an identical report from another user that matches your issue. If @@ -415,7 +444,7 @@ License notes language bindings (Perl, Python, Java, and Tcl) are licensed for use under the LGPL. For more information, please see COPYING.LIB included in this source tree. - + All contained source is the copyright of its author(s). Please see the copyright notices in the individual files for more information on their individual copyrights. diff --git a/configure.ac b/configure.ac index 71459d08..8a77a25d 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,8 @@ # This is free software, licensed under the GNU Public License V2. # See the file COPYING for details. -AC_INIT(include/pi-version.h.in) +AC_INIT +AC_CONFIG_SRCDIR([include/pi-version.h.in]) AC_CONFIG_MACRO_DIR([m4]) dnl Initialize maintainer mode @@ -15,7 +16,7 @@ AC_PREFIX_DEFAULT(/usr/local) dnl ****************************** dnl Limit to a specific ac version dnl ****************************** -AC_PREREQ(2.53) +AC_PREREQ([2.71]) AM_CONFIG_HEADER(config.h) AM_CONFIG_HEADER(include/pi-md5.h) @@ -24,7 +25,7 @@ dnl Pilot Link Version dnl ****************************** PILOT_LINK_VERS=0 PILOT_LINK_MAJOR=13 -PILOT_LINK_MINOR=0 +PILOT_LINK_MINOR=1 PILOT_LINK_PATCH= AC_SUBST(PILOT_LINK_VERS) @@ -40,12 +41,12 @@ dnl Please see the following URL for details: dnl http://sources.redhat.com/autobook/autobook/autobook_91.html dnl ****************************** PISOCK_CURRENT=10 -PISOCK_REVISION=0 PISOCK_AGE=1 +PISOCK_REVISION=0 AC_SUBST(PISOCK_CURRENT) -AC_SUBST(PISOCK_REVISION) AC_SUBST(PISOCK_AGE) +AC_SUBST(PISOCK_REVISION) dnl ****************************** @@ -53,18 +54,18 @@ dnl Pilot Link Sync Library Version dnl libpisync.so dnl ****************************** PISYNC_CURRENT=1 -PISYNC_REVISION=3 PISYNC_AGE=0 +PISYNC_REVISION=3 AC_SUBST(PISYNC_CURRENT) -AC_SUBST(PISYNC_REVISION) AC_SUBST(PISYNC_AGE) +AC_SUBST(PISYNC_REVISION) dnl Eat -Werror so configure will run properly, if the user provided it enable_werror=no save_CFLAGS="$CFLAGS" -CFLAGS=$(echo $save_CFLAGS | sed -e s/-Werror//g) -CXXFLAGS=$(echo $save_CXXFLAGS | sed -e s/-Werror//g) +CFLAGS=$(echo "$save_CFLAGS" | sed -e 's/-Werror[^=]//g') +CXXFLAGS=$(echo "$save_CXXFLAGS" | sed -e 's/-Werror[^=]//g') if test "x$CFLAGS" != "x$save_CFLAGS"; then dnl -Werror was set; treat it as implicit --enable-werror below enable_werror="yes" @@ -73,7 +74,7 @@ fi dnl Check host type AC_CANONICAL_HOST -AC_CANONICAL_SYSTEM +AC_CANONICAL_TARGET AC_DEFINE_UNQUOTED(HOST_OS, "$host", [Host type]) AM_INIT_AUTOMAKE(pilot-link, [$VERSION]) @@ -155,12 +156,45 @@ AM_CONDITIONAL(GIT_BUILD,[test -d "${srcdir}/.git"]) dnl ****************************** dnl Pilot Link Checks dnl ****************************** -AC_HEADER_STDC +m4_warn([obsolete], +[The preprocessor macro `STDC_HEADERS' is obsolete. + Except in unusual embedded environments, you can safely include all + ISO C90 headers unconditionally.])dnl +# Autoupdate added the next two lines to ensure that your configure +# script's behavior did not change. They are probably safe to remove. +AC_CHECK_INCLUDES_DEFAULT +AC_PROG_EGREP + AC_C_CONST -AC_HEADER_TIME +m4_warn([obsolete], +[Update your code to rely only on HAVE_SYS_TIME_H, +then remove this warning and the obsolete code below it. +All current systems provide time.h; it need not be checked for. +Not all systems provide sys/time.h, but those that do, all allow +you to include it and time.h simultaneously.])dnl +AC_CHECK_HEADERS_ONCE([sys/time.h]) +# Obsolete code to be removed. +if test $ac_cv_header_sys_time_h = yes; then + AC_DEFINE([TIME_WITH_SYS_TIME],[1],[Define to 1 if you can safely include both + and . This macro is obsolete.]) +fi +# End of obsolete code. + AC_STRUCT_TM AC_PROG_GCC_TRADITIONAL -AC_TYPE_SIGNAL +m4_warn([obsolete], +[your code may safely assume C89 semantics that RETSIGTYPE is void. +Remove this warning and the `AC_CACHE_CHECK' when you adjust the code.])dnl +AC_CACHE_CHECK([return type of signal handlers],[ac_cv_type_signal],[AC_COMPILE_IFELSE( +[AC_LANG_PROGRAM([#include +#include +], + [return *(signal (0, 0)) (0) == 1;])], + [ac_cv_type_signal=int], + [ac_cv_type_signal=void])]) +AC_DEFINE_UNQUOTED([RETSIGTYPE],[$ac_cv_type_signal],[Define as the return type of signal handlers + (`int' or `void').]) + AC_CHECK_HEADERS( dirent.h errno.h fcntl.h inttypes.h memory.h netdb.h \ @@ -195,10 +229,8 @@ AC_CHECK_LIB(inet, main, [LIBS="$LIBS -linet"]) AC_CACHE_CHECK([for cispeed and cospeed members of struct termios], ac_cv_termios_cspeed, - [AC_TRY_COMPILE( - [#include ], [int main(void) { - struct termios t;t.c_ispeed=t.c_ospeed=0;}], - ac_cv_termios_cspeed=yes,ac_cv_termios_cspeed=no)]) + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [[int main(void) { + struct termios t;t.c_ispeed=t.c_ospeed=0;}]])],[ac_cv_termios_cspeed=yes],[ac_cv_termios_cspeed=no])]) if test $ac_cv_termios_cspeed = yes; then AC_DEFINE(TERMIOS_CSPEED, 1, [Define if we have termios(3) support]) @@ -293,7 +325,7 @@ usb_type= usb_libs= AC_ARG_ENABLE(libusb, - AC_HELP_STRING([--enable-libusb Enable usage of libusb]), + AS_HELP_STRING([--enable-libusb Enable usage of libusb]), if test "x$enableval" != "xno" ; then AC_CHECK_LIB(usb, usb_open, [have_libusb=yes;],[have_libusb=no]) fi @@ -348,8 +380,7 @@ have_bluez=no use_bluez=auto AC_ARG_WITH(bluez, - AC_HELP_STRING([--with-bluez], - [Enable use of BlueZ]), + AS_HELP_STRING([--with-bluez],[Enable use of BlueZ]), [use_bluez="$withval"]) if test "$use_bluez" != "no" ; then PKG_CHECK_MODULES([BLUEZ],[bluez],[ @@ -392,11 +423,8 @@ if test "x$enable_conduits" != "xno"; then dnl Determine if system popt is good enough save_LIBS="$LIBS" AC_CHECK_HEADER(popt.h, - AC_CHECK_DECL(POPT_BIT_SET, - AC_CHECK_LIB(popt, poptStrippedArgv,, - [with_included_popt="yes"]), - [with_included_popt="yes"], - [#include ]), + AC_CHECK_LIB(popt, poptStrippedArgv,, + [with_included_popt="yes"]), [with_included_popt="yes"] ) LIBS="$save_LIBS" @@ -448,7 +476,7 @@ AC_CHECK_LIB( AC_CHECK_FUNC(iconv, [ AC_CHECK_FUNCS(gnu_get_libc_version) AC_MSG_CHECKING(if system iconv handles CP1252) - AC_TRY_RUN([ + AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include #include #include @@ -474,11 +502,11 @@ int main (int argc, char **argv) exit (1); exit (0); -}], AC_MSG_RESULT(yes); have_iconv=yes, [AC_MSG_RESULT(no);], AC_MSG_RESULT(not cross compiling);)])]) +}]])],[AC_MSG_RESULT(yes); have_iconv=yes],[AC_MSG_RESULT(no);],[AC_MSG_RESULT(not cross compiling);])])]) -dnl ## Fixed AC_TRY_RUN warning, missing third argument. -DD 22/01/2002 +dnl ## Fixed AC_RUN_IFELSE([AC_LANG_SOURCE([[]])],[],[],[]) warning, missing third argument. -DD 22/01/2002 dnl -dnl AC_TRY_RUN is a macro that's basically like an if-then-else structure. If +dnl AC_RUN_IFELSE([AC_LANG_SOURCE([[]])],[],[],[]) is a macro that's basically like an if-then-else structure. If dnl the test program (whose text is the first argument) succeeds, the second dnl argument is executed; if the test fails, the third argument is executed; and dnl if autoconf knows it is cross-compiling for another machine and therefore @@ -705,8 +733,7 @@ dnl ************************************* AM_CONDITIONAL(BUILD_XML,[test ! -d "{$srcdir}/.git"]) # if test -d "${srcdir}/.git" ; then -AC_ARG_ENABLE([xsltproc], [AC_HELP_STRING([--enable-xsltproc], - [Use xsltproc to build documentation [default=no]])], +AC_ARG_ENABLE([xsltproc], [AS_HELP_STRING([--enable-xsltproc],[Use xsltproc to build documentation [default=no]])], [enable_xsltproc="$enableval"], [enable_xsltproc=no]) if test x"$enable_xsltproc" = x"yes"; then @@ -770,7 +797,7 @@ if test "x$GCC" = "xyes" -a "x$enable_werror" = "xyes"; then CFLAGS="$CFLAGS -Werror" fi -AC_OUTPUT([ +AC_CONFIG_FILES([ Makefile pilot-link.m4 pilot-link.pc @@ -799,6 +826,7 @@ AC_OUTPUT([ tests/Makefile darwin/Makefile ]) +AC_OUTPUT AC_MSG_RESULT([ Options detected/selected diff --git a/libpisock/dlp.c b/libpisock/dlp.c index d37bfd56..f839f7b1 100644 --- a/libpisock/dlp.c +++ b/libpisock/dlp.c @@ -1,4 +1,4 @@ -/* +/* * $Id$ * * dlp.c: Palm DLP protocol @@ -11,7 +11,7 @@ * under the terms of the GNU Library General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. - * + * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library @@ -45,7 +45,7 @@ #define DLP_RESPONSE_DATA(res, arg, offset) &res->argv[arg]->data[offset] #define get_date(ptr) (dlp_ptohdate((ptr))) -#define set_date(ptr,val) (dlp_htopdate((val),(ptr))) +#define set_date(ptr, val) (dlp_htopdate((val), (ptr))) #define RequireDLPVersion(sd,major,minor) \ if (pi_version(sd) < (((major)<<8) | (minor))) \ @@ -61,7 +61,7 @@ /* Define prototypes */ #ifdef PI_DEBUG static void record_dump (unsigned long recID, unsigned int recIndex, - int flags, int catID, const char *data, int data_len); + int flags, int catID, const char *data, int data_len); #endif char *dlp_errorlist[] = { @@ -89,8 +89,7 @@ char *dlp_errorlist[] = { "Bad argument size" }; -/* Look at "Error codes" in VFSMgr.h in the Palm SDK for their - implementation */ +/* Look at "Error codes" in VFSMgr.h in the Palm SDK for their implementation */ char * vfs_errorlist[] = { "No error", "Buffer Overflow", @@ -115,8 +114,7 @@ char * vfs_errorlist[] = { "Name truncated" }; -/* Look at "Error codes" in ExpansionMgr.h in the Palm SDK for their - implementation */ +/* Look at "Error codes" in ExpansionMgr.h in the Palm SDK for their implementation */ char * exp_errorlist[] = { "No error", "Unsupported Operation", @@ -143,17 +141,17 @@ static int dlp_version_minor = PI_DLP_VERSION_MINOR; #ifdef PI_DEBUG #define Trace(name) \ - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP sd=%d %s\n", sd, #name)); - #ifdef __GNUC__ - #define TraceX(name,format,...) \ - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP sd=%d %s " #format "\n", sd, #name, __VA_ARGS__)); - #else - #define TraceX(name,format,...) \ - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP sd=%d %s\n", sd, #name)); - #endif + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP sd=%d %s\n", sd, #name)); + #ifdef __GNUC__ + #define TraceX(name, format, ...) \ + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP sd=%d %s " #format "\n", sd, #name, __VA_ARGS__)); + #else + #define TraceX(name, format, ...) \ + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP sd=%d %s\n", sd, #name)); + #endif #else #define Trace(name) - #define TraceX(name,format,...) + #define TraceX(name, format, ...) #endif #ifdef PI_DEBUG @@ -161,18 +159,18 @@ static void record_dump (unsigned long recID, unsigned int recIndex, int flags, int catID, const char *data, int data_len) { LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " ID: 0x%8.8lX, Index: %u, Category: %d\n" - " Flags:%s%s%s%s%s%s (0x%2.2X), and %d bytes:\n", - (unsigned long) recID, - recIndex, - catID, - (flags & dlpRecAttrDeleted) ? " Deleted" : "", - (flags & dlpRecAttrDirty) ? " Dirty" : "", - (flags & dlpRecAttrBusy) ? " Busy" : "", - (flags & dlpRecAttrSecret) ? " Secret" : "", - (flags & dlpRecAttrArchived) ? " Archive" : "", - (!flags) ? " None" : "", - flags, data_len)); + " ID: 0x%8.8lX, Index: %u, Category: %d\n" + " Flags:%s%s%s%s%s%s (0x%2.2X), and %d bytes:\n", + (unsigned long) recID, + recIndex, + catID, + (flags & dlpRecAttrDeleted) ? " Deleted" : "", + (flags & dlpRecAttrDirty) ? " Dirty" : "", + (flags & dlpRecAttrBusy) ? " Busy" : "", + (flags & dlpRecAttrSecret) ? " Secret" : "", + (flags & dlpRecAttrArchived) ? " Archive" : "", + (!flags) ? " None" : "", + flags, data_len)); pi_dumpdata(data, (size_t)data_len); } #endif @@ -195,15 +193,15 @@ dlp_set_protocol_version(int major, int minor) * Returns: char* to error text string * ***************************************************************************/ -char +char *dlp_strerror(int error) { if (error < 0) error = -error; - - if ((unsigned int) error >= (sizeof(dlp_errorlist)/(sizeof(char *)))) + + if ((unsigned int) error >= (sizeof(dlp_errorlist) / (sizeof(char *)))) return "Unknown error"; - + return dlp_errorlist[error]; } @@ -220,10 +218,10 @@ char * ***************************************************************************/ struct dlpArg -*dlp_arg_new (int argID, size_t len) +*dlp_arg_new (int argID, size_t len) { struct dlpArg *arg; - + arg = (struct dlpArg *)malloc(sizeof (struct dlpArg)); if (arg != NULL) { @@ -237,8 +235,8 @@ struct dlpArg arg = NULL; } } - } - + } + return arg; } @@ -284,13 +282,13 @@ dlp_arg_len (int argc, struct dlpArg **argv) for (i = 0; i < argc; i++) { struct dlpArg *arg = argv[i]; - + /* FIXME: shapiro: should these be < or <= ??? */ if (arg->len < PI_DLP_ARG_TINY_LEN && - (arg->id_ & (PI_DLP_ARG_FLAG_SHORT | PI_DLP_ARG_FLAG_LONG)) == 0) + (arg->id_ & (PI_DLP_ARG_FLAG_SHORT | PI_DLP_ARG_FLAG_LONG)) == 0) len += 2; else if (arg->len < PI_DLP_ARG_SHORT_LEN && - (arg->id_ & PI_DLP_ARG_FLAG_LONG) == 0) + (arg->id_ & PI_DLP_ARG_FLAG_LONG) == 0) len += 4; else len += 6; @@ -306,7 +304,7 @@ dlp_arg_len (int argc, struct dlpArg **argv) * * Function: dlp_request_new * - * Summary: creates a new dlpRequest instance + * Summary: creates a new dlpRequest instance * * Parameters: dlpFunction command, number of dlpArgs, lengths of dlpArgs * data member @@ -315,13 +313,12 @@ dlp_arg_len (int argc, struct dlpArg **argv) * ***************************************************************************/ struct dlpRequest* -dlp_request_new (enum dlpFunctions cmd, int argc, ...) +dlp_request_new (enum dlpFunctions cmd, int argc, ...) { struct dlpRequest *req; va_list ap; - int i, - j; - + int i, j; + req = (struct dlpRequest *)malloc (sizeof (struct dlpRequest)); if (req != NULL) { @@ -336,7 +333,7 @@ dlp_request_new (enum dlpFunctions cmd, int argc, ...) return NULL; } } - + va_start (ap, argc); for (i = 0; i < argc; i++) { size_t len; @@ -355,8 +352,8 @@ dlp_request_new (enum dlpFunctions cmd, int argc, ...) } va_end (ap); } - - return req; + + return req; } @@ -377,9 +374,8 @@ dlp_request_new_with_argid (enum dlpFunctions cmd, int argid, int argc, ...) { struct dlpRequest *req; va_list ap; - int i, - j; - + int i, j; + req = (struct dlpRequest *) malloc (sizeof (struct dlpRequest)); if (req != NULL) { @@ -400,7 +396,7 @@ dlp_request_new_with_argid (enum dlpFunctions cmd, int argid, int argc, ...) size_t len; len = va_arg (ap, size_t); - req->argv[i] = dlp_arg_new (argid + i, len); + req->argv[i] = dlp_arg_new(argid + i, len); if (req->argv[i] == NULL) { for (j = 0; j < i; j++) dlp_arg_free(req->argv[j]); @@ -421,7 +417,7 @@ dlp_request_new_with_argid (enum dlpFunctions cmd, int argid, int argc, ...) * * Function: dlp_response_new * - * Summary: creates a new dlpResponse instance + * Summary: creates a new dlpResponse instance * * Parameters: dlpFunction command, number of dlpArg instances * @@ -429,10 +425,10 @@ dlp_request_new_with_argid (enum dlpFunctions cmd, int argid, int argc, ...) * ***************************************************************************/ struct dlpResponse -*dlp_response_new (enum dlpFunctions cmd, int argc) +*dlp_response_new (enum dlpFunctions cmd, int argc) { struct dlpResponse *res; - + res = (struct dlpResponse *) malloc (sizeof (struct dlpResponse)); if (res != NULL) { @@ -454,7 +450,7 @@ struct dlpResponse memset(res->argv, 0, sizeof (struct dlpArg *) * argc); } } - + return res; } @@ -480,7 +476,7 @@ dlp_response_read (struct dlpResponse **res, int sd) ssize_t bytes; size_t len; pi_buffer_t *dlp_buf; - + dlp_buf = pi_buffer_new (DLP_BUF_SIZE); if (dlp_buf == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -494,21 +490,21 @@ dlp_response_read (struct dlpResponse **res, int sd) /* packet is probably incomplete */ #ifdef DEBUG LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "dlp_response_read: response too short (%d bytes)\n", - bytes)); + "dlp_response_read: response too short (%d bytes)\n", + bytes)); if (bytes) pi_dumpdata(dlp_buf->data, (size_t)dlp_buf->used); #endif return pi_set_error(sd, PI_ERR_DLP_COMMAND); } - response = dlp_response_new ((enum dlpFunctions)(dlp_buf->data[0] & 0x7f), dlp_buf->data[1]); + response = dlp_response_new((enum dlpFunctions)(dlp_buf->data[0] & 0x7f), dlp_buf->data[1]); *res = response; /* note that in case an error occurs, we do not deallocate the response since callers already do it under all circumstances */ if (response == NULL) { - pi_buffer_free (dlp_buf); + pi_buffer_free(dlp_buf); return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); } @@ -530,20 +526,20 @@ dlp_response_read (struct dlpResponse **res, int sd) contents. We need to report that the data is too large to be transferred. */ - pi_buffer_free (dlp_buf); + pi_buffer_free(dlp_buf); return pi_set_error(sd, PI_ERR_DLP_DATASIZE); } - len = get_long (&buf[2]); + len = get_long(&buf[2]); buf += 6; } else if (get_byte(buf) & PI_DLP_ARG_FLAG_SHORT) { - len = get_short (&buf[2]); + len = get_short(&buf[2]); buf += 4; } else { argid = get_byte(buf); len = get_byte(&buf[1]); buf += 2; } - + response->argv[i] = dlp_arg_new (argid, len); if (response->argv[i] == NULL) { pi_buffer_free (dlp_buf); @@ -553,7 +549,7 @@ dlp_response_read (struct dlpResponse **res, int sd) buf += len; } - pi_buffer_free (dlp_buf); + pi_buffer_free(dlp_buf); return response->argc ? response->argv[0]->len : 0; } @@ -576,35 +572,35 @@ dlp_request_write (struct dlpRequest *req, int sd) unsigned char *exec_buf, *buf; int i; size_t len; - - len = dlp_arg_len (req->argc, req->argv) + 2; + + len = dlp_arg_len(req->argc, req->argv) + 2; exec_buf = (unsigned char *) malloc (sizeof (unsigned char) * len); if (exec_buf == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - set_byte (&exec_buf[PI_DLP_OFFSET_CMD], req->cmd); - set_byte (&exec_buf[PI_DLP_OFFSET_ARGC], req->argc); + set_byte(&exec_buf[PI_DLP_OFFSET_CMD], req->cmd); + set_byte(&exec_buf[PI_DLP_OFFSET_ARGC], req->argc); - buf = &exec_buf[PI_DLP_OFFSET_ARGV]; + buf = &exec_buf[PI_DLP_OFFSET_ARGV]; for (i = 0; i < req->argc; i++) { struct dlpArg *arg = req->argv[i]; short argid = arg->id_; - + if (arg->len < PI_DLP_ARG_TINY_LEN && - (argid & (PI_DLP_ARG_FLAG_SHORT | PI_DLP_ARG_FLAG_LONG)) == 0) { + (argid & (PI_DLP_ARG_FLAG_SHORT | PI_DLP_ARG_FLAG_LONG)) == 0) { set_byte(&buf[0], argid | PI_DLP_ARG_FLAG_TINY); set_byte(&buf[1], arg->len); memcpy(&buf[2], arg->data, arg->len); - buf += arg->len + 2; + buf += arg->len + 2; } else if (arg->len < PI_DLP_ARG_SHORT_LEN && - (argid & PI_DLP_ARG_FLAG_LONG) == 0) { + (argid & PI_DLP_ARG_FLAG_LONG) == 0) { set_byte(&buf[0], argid | PI_DLP_ARG_FLAG_SHORT); set_byte(&buf[1], 0); set_short(&buf[2], arg->len); memcpy (&buf[4], arg->data, arg->len); - buf += arg->len + 4; + buf += arg->len + 4; } else { set_byte (&buf[0], argid | PI_DLP_ARG_FLAG_LONG); set_byte(&buf[1], 0); @@ -672,13 +668,13 @@ dlp_request_free (struct dlpRequest *req) * ***************************************************************************/ void -dlp_response_free (struct dlpResponse *res) +dlp_response_free (struct dlpResponse *res) { int i; if (res == NULL) return; - + if (res->argv != NULL) { for (i = 0; i < res->argc; i++) { if (res->argv[i] != NULL) @@ -687,7 +683,7 @@ dlp_response_free (struct dlpResponse *res) free (res->argv); } - free (res); + free (res); } @@ -710,16 +706,16 @@ dlp_exec(int sd, struct dlpRequest *req, struct dlpResponse **res) if ((result = dlp_request_write (req, sd)) < req->argc) { LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "DLP sd:%i dlp_request_write returned %i\n", - sd, result)); + "DLP sd:%i dlp_request_write returned %i\n", + sd, result)); errno = -EIO; return result; } if ((bytes = dlp_response_read (res, sd)) < 0) { LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "DLP sd:%i dlp_response_read returned %i\n", - sd, bytes)); + "DLP sd:%i dlp_response_read returned %i\n", + sd, bytes)); errno = -EIO; return bytes; } @@ -737,8 +733,8 @@ dlp_exec(int sd, struct dlpRequest *req, struct dlpResponse **res) errno = -ENOMSG; LOG((PI_DBG_DLP, PI_DBG_LVL_DEBUG, - "dlp_exec: result CMD 0x%02x doesn't match requested cmd 0x%02x\n", - (unsigned)((*res)->cmd), (unsigned)req->cmd)); + "dlp_exec: result CMD 0x%02x doesn't match requested cmd 0x%02x\n", + (unsigned)((*res)->cmd), (unsigned)req->cmd)); return pi_set_error(sd, PI_ERR_DLP_COMMAND); } @@ -754,11 +750,11 @@ dlp_exec(int sd, struct dlpRequest *req, struct dlpResponse **res) return bytes; } -/* These conversion functions are strictly for use within the DLP layer. +/* These conversion functions are strictly for use within the DLP layer. This particular date/time format does not occur anywhere else within the Palm or its communications. */ -/* Notice: +/* Notice: The dates in the DLP protocol are expressed as absolute dates/times, without any time zone information. For example if a file was created on the device at 19:32:48, the time members will be 19, 32 and 48. @@ -773,11 +769,11 @@ dlp_ptohdate(const unsigned char *data) struct tm t; /* Seems like year comes back as all zeros if the date is "empty" - (but other fields can vary). And mktime() chokes on 1900 B.C. + (but other fields can vary). And mktime() chokes on 1900 B.C. (result of 0 minus 1900), returning -1, which the higher level code can't deal with (passes it straight on to utime(), which simply leaves the file's timestamp "as-is"). - + So, since year 0 appears to mean "no date", we'll return an odd number that works out to precisely one day before the start of the Palm's clock (thus little chance of being run into by any @@ -789,18 +785,17 @@ dlp_ptohdate(const unsigned char *data) earlier than it was supposed to report. You can verify this with the following: - perl -e '$date=localtime(0x83D8FE00); print $date,"\n"' + perl -e '$date=localtime(0x83D8FE00); print $date,"\n"' - return (time_t) 0x83D8FE00; // Wed Dec 30 16:00:00 1903 GMT + return (time_t) 0x83D8FE00; // Wed Dec 30 16:00:00 1903 GMT - Here are others, depending on what your system requirements are: + Here are others, depending on what your system requirements are: - return (time_t) 0x83D96E80; // Thu Dec 31 00:00:00 1903 GMT - return (time_t) 0x00007080; // Thu Jan 1 00:00:00 1970 GMT + return (time_t) 0x83D96E80; // Thu Dec 31 00:00:00 1903 GMT + return (time_t) 0x00007080; // Thu Jan 1 00:00:00 1970 GMT - Palm's own Conduit Development Kit references using 1/1/1904, - so that's what we'll use here until something else breaks - it. + Palm's own Conduit Development Kit references using 1/1/1904, + so that's what we'll use here until something else breaks it. */ return (time_t) 0x83DAC000; /* Fri Jan 1 00:00:00 1904 GMT */ @@ -821,18 +816,18 @@ dlp_ptohdate(const unsigned char *data) void dlp_htopdate(time_t time_interval, unsigned char *data) { /* @+ptrnegate@ */ - int year; + int year; const struct tm *t; /* Fri Jan 1 00:00:00 1904 GMT */ - time_t palm_epoch = 0x83DAC000; + time_t palm_epoch = 0x83DAC000; if (time_interval == palm_epoch) { memset(data, 0, 8); return; } - t = localtime(&time_interval); + t = localtime(&time_interval); ASSERT(t != NULL); year = t->tm_year + 1900; @@ -850,7 +845,7 @@ dlp_htopdate(time_t time_interval, unsigned char *data) int dlp_GetSysDateTime(int sd, time_t *t) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; @@ -860,37 +855,37 @@ dlp_GetSysDateTime(int sd, time_t *t) req = dlp_request_new(dlpFuncGetSysDateTime, 0); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - + result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { *t = dlp_ptohdate((const unsigned char *)DLP_RESPONSE_DATA (res, 0, 0)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP GetSysDateTime %s", ctime(t))); + "DLP GetSysDateTime %s", ctime(t))); } dlp_response_free(res); - + return result; } int dlp_SetSysDateTime(int sd, time_t t) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_SetSysDateTime,"time=0x%08lx",t); + TraceX(dlp_SetSysDateTime, "time=0x%08lx", t); pi_reset_errors(sd); req = dlp_request_new(dlpFuncSetSysDateTime, 1, 8); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - + dlp_htopdate(t, (unsigned char *)DLP_REQUEST_DATA(req, 0, 0)); result = dlp_exec(sd, req, &res); @@ -904,12 +899,12 @@ dlp_SetSysDateTime(int sd, time_t t) int dlp_ReadStorageInfo(int sd, int cardno, struct CardInfo *c) { - int result; + int result; size_t len1, len2; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_ReadStorageInfo,"cardno=%d",cardno); + TraceX(dlp_ReadStorageInfo, "cardno=%d", cardno); pi_reset_errors(sd); req = dlp_request_new(dlpFuncReadStorageInfo, 1, 2); @@ -924,11 +919,11 @@ dlp_ReadStorageInfo(int sd, int cardno, struct CardInfo *c) dlp_request_free(req); if (result > 0) { - c->more = get_byte(DLP_RESPONSE_DATA(res, 0, 0)) - || (get_byte(DLP_RESPONSE_DATA(res, 0, 3)) > 1); + c->more = get_byte(DLP_RESPONSE_DATA(res, 0, 0)) + || (get_byte(DLP_RESPONSE_DATA(res, 0, 3)) > 1); c->card = get_byte(DLP_RESPONSE_DATA(res, 0, 5)); c->version = get_byte(DLP_RESPONSE_DATA(res, 0, 6)); - c->creation = get_date((const unsigned char *)DLP_RESPONSE_DATA(res, 0, 8)); + c->creation = get_date((const unsigned char *)DLP_RESPONSE_DATA(res, 0, 8)); c->romSize = get_long(DLP_RESPONSE_DATA(res, 0, 16)); c->ramSize = get_long(DLP_RESPONSE_DATA(res, 0, 20)); c->ramFree = get_long(DLP_RESPONSE_DATA(res, 0, 24)); @@ -938,36 +933,35 @@ dlp_ReadStorageInfo(int sd, int cardno, struct CardInfo *c) c->name[len1] = '\0'; len2 = get_byte(DLP_RESPONSE_DATA(res, 0, 29)); - memcpy(c->manufacturer, DLP_RESPONSE_DATA(res, 0, 30 + len1), - len2); + memcpy(c->manufacturer, DLP_RESPONSE_DATA(res, 0, 30 + len1), len2); c->manufacturer[len2] = '\0'; LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP Read Cardno: %d, Card Version: %d, Creation time: %s", - c->card, c->version, ctime(&c->creation))); + "DLP Read Cardno: %d, Card Version: %d, Creation time: %s", + c->card, c->version, ctime(&c->creation))); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Total ROM: %lu, Total RAM: %lu, Free RAM: %lu\n", - c->romSize, c->ramSize, c->ramFree)); + " Total ROM: %lu, Total RAM: %lu, Free RAM: %lu\n", + c->romSize, c->ramSize, c->ramFree)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Card name: '%s'\n", c->name)); + " Card name: '%s'\n", c->name)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Manufacturer name: '%s'\n", c->manufacturer)); + " Manufacturer name: '%s'\n", c->manufacturer)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " More: %s\n", c->more ? "Yes" : "No")); + " More: %s\n", c->more ? "Yes" : "No")); } dlp_response_free (res); - + return result; } int dlp_ReadSysInfo(int sd, struct SysInfo *s) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + Trace(dlp_ReadSysInfo); pi_reset_errors(sd); @@ -977,7 +971,7 @@ dlp_ReadSysInfo(int sd, struct SysInfo *s) set_short (DLP_REQUEST_DATA (req, 0, 0), dlp_version_major); set_short (DLP_REQUEST_DATA (req, 0, 2), dlp_version_minor); - + result = dlp_exec(sd, req, &res); dlp_request_free (req); @@ -987,23 +981,22 @@ dlp_ReadSysInfo(int sd, struct SysInfo *s) s->locale = get_long (DLP_RESPONSE_DATA (res, 0, 4)); /* The 8th byte is a filler byte */ s->prodIDLength = get_byte (DLP_RESPONSE_DATA (res, 0, 9)); - memcpy(s->prodID, DLP_RESPONSE_DATA(res, 0, 10), - s->prodIDLength); + memcpy(s->prodID, DLP_RESPONSE_DATA(res, 0, 10), s->prodIDLength); if (res->argc > 1) { /* response added in DLP 1.2 */ pi_socket_t *ps = find_pi_socket(sd); s->dlpMajorVersion = - get_short (DLP_RESPONSE_DATA (res, 1, 0)); + get_short (DLP_RESPONSE_DATA (res, 1, 0)); s->dlpMinorVersion = - get_short (DLP_RESPONSE_DATA (res, 1, 2)); + get_short (DLP_RESPONSE_DATA (res, 1, 2)); s->compatMajorVersion = - get_short (DLP_RESPONSE_DATA (res, 1, 4)); + get_short (DLP_RESPONSE_DATA (res, 1, 4)); s->compatMinorVersion = - get_short (DLP_RESPONSE_DATA (res, 1, 6)); + get_short (DLP_RESPONSE_DATA (res, 1, 6)); s->maxRecSize = - get_long (DLP_RESPONSE_DATA (res, 1, 8)); + get_long (DLP_RESPONSE_DATA (res, 1, 8)); /* update socket information */ ps->dlpversion = (s->dlpMajorVersion << 8) | s->dlpMinorVersion; @@ -1017,37 +1010,35 @@ dlp_ReadSysInfo(int sd, struct SysInfo *s) } LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadSysInfo ROM Ver=0x%8.8lX Locale=0x%8.8lX\n", - s->romVersion, s->locale)); + "DLP ReadSysInfo ROM Ver=0x%8.8lX Locale=0x%8.8lX\n", + s->romVersion, s->locale)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Product ID=0x%8.8lX\n", s->prodID)); + " Product ID=0x%8.8lX\n", s->prodID)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " DLP Major Ver=0x%4.4lX DLP Minor Ver=0x%4.4lX\n", - s->dlpMajorVersion, s->dlpMinorVersion)); + " DLP Major Ver=0x%4.4lX DLP Minor Ver=0x%4.4lX\n", + s->dlpMajorVersion, s->dlpMinorVersion)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Compat Major Ver=0x%4.4lX Compat Minor Vers=0x%4.4lX\n", - s->compatMajorVersion, s->compatMinorVersion)); + " Compat Major Ver=0x%4.4lX Compat Minor Vers=0x%4.4lX\n", + s->compatMajorVersion, s->compatMinorVersion)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Max Rec Size=%ld\n", s->maxRecSize)); + " Max Rec Size=%ld\n", s->maxRecSize)); } dlp_response_free (res); - + return result; } int dlp_ReadDBList(int sd, int cardno, int flags, int start, pi_buffer_t *info) { - int result, - i, - count; + int result, i, count; struct dlpRequest *req; struct dlpResponse *res; unsigned char *p; struct DBInfo db; - TraceX(dlp_ReadDBList,"cardno=%d flags=0x%04x start=%d",cardno,flags,start); + TraceX(dlp_ReadDBList, "cardno=%d flags=0x%04x start=%d", cardno, flags, start); pi_reset_errors(sd); req = dlp_request_new (dlpFuncReadDBList, 1, 4); @@ -1055,7 +1046,7 @@ dlp_ReadDBList(int sd, int cardno, int flags, int start, pi_buffer_t *info) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); pi_buffer_clear (info); - + /* 'multiple' only supported in DLP 1.2 and above */ if (pi_version(sd) < 0x0102) flags &= ~dlpDBListMultiple; @@ -1067,7 +1058,7 @@ dlp_ReadDBList(int sd, int cardno, int flags, int start, pi_buffer_t *info) result = dlp_exec (sd, req, &res); dlp_request_free(req); - + if (result > 0) { p = (unsigned char *)DLP_RESPONSE_DATA(res, 0, 0); db.more = get_byte(p + 2); @@ -1080,47 +1071,45 @@ dlp_ReadDBList(int sd, int cardno, int flags, int start, pi_buffer_t *info) else db.miscFlags = 0; - db.flags = get_short(p + 6); - db.type = get_long(p + 8); + db.flags = get_short(p + 6); + db.type = get_long(p + 8); db.creator = get_long(p + 12); db.version = get_short(p + 16); db.modnum = get_long(p + 18); db.createDate = get_date(p + 22); db.modifyDate = get_date(p + 30); db.backupDate = get_date(p + 38); - db.index = get_short(p + 46); + db.index = get_short(p + 46); memset(db.name, 0, sizeof(db.name)); strncpy(db.name, (char *)(p + 48), 32); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadDBList Name: '%s', Version: %d, More: %s\n", - db.name, db.version, db.more ? "Yes" : "No")); + "DLP ReadDBList Name: '%s', Version: %d, More: %s\n", + db.name, db.version, db.more ? "Yes" : "No")); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Creator: '%s'", printlong(db.creator))); + " Creator: '%s'", printlong(db.creator))); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Type: '%s' Flags: %s%s%s%s%s%s%s%s%s%s", - printlong(db.type), - (db.flags & dlpDBFlagResource) ? "Resource " : "", - (db.flags & dlpDBFlagReadOnly) ? "ReadOnly " : "", - (db.flags & dlpDBFlagAppInfoDirty) ? - "AppInfoDirty " : "", - (db.flags & dlpDBFlagBackup) ? "Backup " : "", - (db.flags & dlpDBFlagReset) ? "Reset " : "", - (db.flags & dlpDBFlagNewer) ? "Newer " : "", - (db.flags & dlpDBFlagCopyPrevention) ? - "CopyPrevention " : "", - (db.flags & dlpDBFlagStream) ? "Stream " : "", - (db.flags & dlpDBFlagOpen) ? "Open " : "", - (!db.flags) ? "None" : "")); + " Type: '%s' Flags: %s%s%s%s%s%s%s%s%s%s", + printlong(db.type), + (db.flags & dlpDBFlagResource) ? "Resource " : "", + (db.flags & dlpDBFlagReadOnly) ? "ReadOnly " : "", + (db.flags & dlpDBFlagAppInfoDirty) ? "AppInfoDirty " : "", + (db.flags & dlpDBFlagBackup) ? "Backup " : "", + (db.flags & dlpDBFlagReset) ? "Reset " : "", + (db.flags & dlpDBFlagNewer) ? "Newer " : "", + (db.flags & dlpDBFlagCopyPrevention) ? "CopyPrevention " : "", + (db.flags & dlpDBFlagStream) ? "Stream " : "", + (db.flags & dlpDBFlagOpen) ? "Open " : "", + (!db.flags) ? "None" : "")); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, " (0x%2.2X)\n", db.flags)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Modnum: %ld, Index: %d, Creation date: 0x%08lx, %s", - db.modnum, db.index, db.createDate, ctime(&db.createDate))); + " Modnum: %ld, Index: %d, Creation date: 0x%08lx, %s", + db.modnum, db.index, db.createDate, ctime(&db.createDate))); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Modification date: 0x%08lx, %s", db.modifyDate, ctime(&db.modifyDate))); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Backup date: 0x%08lx, %s", db.backupDate, ctime(&db.backupDate))); + " Modification date: 0x%08lx, %s", db.modifyDate, ctime(&db.modifyDate))); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, + " Backup date: 0x%08lx, %s", db.backupDate, ctime(&db.backupDate))); if (pi_buffer_append(info, &db, sizeof(db)) == NULL) { result = pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -1141,14 +1130,12 @@ dlp_ReadDBList(int sd, int cardno, int flags, int start, pi_buffer_t *info) int dlp_FindDBInfo(int sd, int cardno, int start, const char *dbname, - unsigned long type, unsigned long creator, - struct DBInfo *info) + unsigned long type, unsigned long creator, struct DBInfo *info) { - int i, - j; + int i, j; pi_buffer_t *buf; - TraceX(dlp_FindDBInfo,"cardno=%d start=%d",cardno,start); + TraceX(dlp_FindDBInfo, "cardno=%d start=%d", cardno, start); pi_reset_errors(sd); buf = pi_buffer_new (sizeof (struct DBInfo)); @@ -1161,8 +1148,8 @@ dlp_FindDBInfo(int sd, int cardno, int start, const char *dbname, for (j=0; j < (int)(buf->used / sizeof(struct DBInfo)); j++) { memcpy (info, buf->data + j * sizeof(struct DBInfo), sizeof(struct DBInfo)); if ((!dbname || strcmp(info->name, dbname) == 0) - && (!type || info->type == type) - && (!creator || info->creator == creator)) + && (!type || info->type == type) + && (!creator || info->creator == creator)) goto found; i = info->index + 1; } @@ -1175,8 +1162,8 @@ dlp_FindDBInfo(int sd, int cardno, int start, const char *dbname, for (j=0; j < (int)(buf->used / sizeof(struct DBInfo)); j++) { memcpy (info, buf->data + j * sizeof(struct DBInfo), sizeof(struct DBInfo)); if ((!dbname || strcmp(info->name, dbname) == 0) - && (!type || info->type == type) - && (!creator || info->creator == creator)) + && (!type || info->type == type) + && (!creator || info->creator == creator)) { info->index |= 0x1000; goto found; @@ -1206,7 +1193,7 @@ dlp_FindDBInfo(int sd, int cardno, int start, const char *dbname, ***************************************************************************/ static void dlp_decode_finddb_response(struct dlpResponse *res, int *cardno, unsigned long *localid, - int *dbhandle, struct DBInfo *info, struct DBSizeInfo *size) + int *dbhandle, struct DBInfo *info, struct DBSizeInfo *size) { int arg, argid; for (arg = 0; arg < res->argc; arg++) { @@ -1221,88 +1208,62 @@ dlp_decode_finddb_response(struct dlpResponse *res, int *cardno, unsigned long * if (info) { info->more = 0; - info->miscFlags = - get_byte(DLP_RESPONSE_DATA(res, arg, 11)); - info->flags = - get_short(DLP_RESPONSE_DATA(res, arg, 12)); - info->type = - get_long(DLP_RESPONSE_DATA(res, arg, 14)); - info->creator = - get_long(DLP_RESPONSE_DATA(res, arg, 18)); - info->version = - get_short(DLP_RESPONSE_DATA(res, arg, 22)); - info->modnum = - get_long(DLP_RESPONSE_DATA(res, arg, 24)); + info->miscFlags = get_byte(DLP_RESPONSE_DATA(res, arg, 11)); + info->flags = get_short(DLP_RESPONSE_DATA(res, arg, 12)); + info->type = get_long(DLP_RESPONSE_DATA(res, arg, 14)); + info->creator = get_long(DLP_RESPONSE_DATA(res, arg, 18)); + info->version = get_short(DLP_RESPONSE_DATA(res, arg, 22)); + info->modnum = get_long(DLP_RESPONSE_DATA(res, arg, 24)); info->createDate = - get_date((const unsigned char *)DLP_RESPONSE_DATA(res, arg, 28)); + get_date((const unsigned char *)DLP_RESPONSE_DATA(res, arg, 28)); info->modifyDate = - get_date((const unsigned char *)DLP_RESPONSE_DATA(res, arg, 36)); + get_date((const unsigned char *)DLP_RESPONSE_DATA(res, arg, 36)); info->backupDate = - get_date((const unsigned char *)DLP_RESPONSE_DATA(res, arg, 44)); - info->index = - get_short(DLP_RESPONSE_DATA(res, arg, 52)); + get_date((const unsigned char *)DLP_RESPONSE_DATA(res, arg, 44)); + info->index = get_short(DLP_RESPONSE_DATA(res, arg, 52)); strncpy(info->name, DLP_RESPONSE_DATA(res, arg, 54), 32); info->name[32] = '\0'; LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP FindDB Name: '%s', " - "Version: %d, More: %s\n", - info->name, info->version, - info->more ? "Yes" : "No")); + "DLP FindDB Name: '%s', " + "Version: %d, More: %s\n", + info->name, info->version, + info->more ? "Yes" : "No")); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, + " Creator: '%s'", printlong(info->creator))); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Creator: '%s'", printlong(info->creator))); + " Type: '%s' Flags: %s%s%s%s%s%s%s%s%s%s", + printlong(info->type), + (info->flags & dlpDBFlagResource) ? "Resource " : "", + (info->flags & dlpDBFlagReadOnly) ? "ReadOnly " : "", + (info->flags & dlpDBFlagAppInfoDirty) ? "AppInfoDirty " : "", + (info->flags & dlpDBFlagBackup) ? "Backup " : "", + (info->flags & dlpDBFlagReset) ? "Reset " : "", + (info->flags & dlpDBFlagNewer) ? "Newer " : "", + (info->flags & dlpDBFlagCopyPrevention) ? "CopyPrevention " : "", + (info->flags & dlpDBFlagStream) ? "Stream " : "", + (info->flags & dlpDBFlagOpen) ? "Open " : "", + (!info->flags) ? "None" : "")); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Type: '%s' Flags: %s%s%s%s%s%s%s%s%s%s", - printlong(info->type), - (info->flags & dlpDBFlagResource) ? - "Resource " : "", - (info->flags & dlpDBFlagReadOnly) ? - "ReadOnly " : "", - (info->flags & dlpDBFlagAppInfoDirty) ? - "AppInfoDirty " : "", - (info->flags & dlpDBFlagBackup) ? - "Backup " : "", - (info->flags & dlpDBFlagReset) ? - "Reset " : "", - (info->flags & dlpDBFlagNewer) ? - "Newer " : "", - (info->flags & dlpDBFlagCopyPrevention) ? - "CopyPrevention " : "", - (info->flags & dlpDBFlagStream) ? - "Stream " : "", - (info->flags & dlpDBFlagOpen) ? - "Open " : "", - (!info->flags) ? "None" : "")); + " (0x%2.2X)\n", info->flags)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " (0x%2.2X)\n", info->flags)); + " Modnum: %ld, Index: %d, Creation date: %s", + info->modnum, info->index, ctime(&info->createDate))); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Modnum: %ld, Index: %d, " - "Creation date: %s", - info->modnum, info->index, - ctime(&info->createDate))); + " Modification date: %s", ctime(&info->modifyDate))); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Modification date: %s", - ctime(&info->modifyDate))); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Backup date: %s", - ctime(&info->backupDate))); + " Backup date: %s", ctime(&info->backupDate))); } } else if (argid == 1) { if (size) { - size->numRecords = - get_long(DLP_RESPONSE_DATA(res, arg, 0)); - size->totalBytes = - get_long(DLP_RESPONSE_DATA(res, arg, 4)); - size->dataBytes = - get_long(DLP_RESPONSE_DATA(res, arg, 8)); - size->appBlockSize = - get_long(DLP_RESPONSE_DATA(res, arg, 12)); - size->sortBlockSize = - get_long(DLP_RESPONSE_DATA(res, arg, 16)); - size->maxRecSize = - get_long(DLP_RESPONSE_DATA(res, arg, 20)); + size->numRecords = get_long(DLP_RESPONSE_DATA(res, arg, 0)); + size->totalBytes = get_long(DLP_RESPONSE_DATA(res, arg, 4)); + size->dataBytes = get_long(DLP_RESPONSE_DATA(res, arg, 8)); + size->appBlockSize = get_long(DLP_RESPONSE_DATA(res, arg, 12)); + size->sortBlockSize = get_long(DLP_RESPONSE_DATA(res, arg, 16)); + size->maxRecSize = get_long(DLP_RESPONSE_DATA(res, arg, 20)); } } } @@ -1310,14 +1271,14 @@ dlp_decode_finddb_response(struct dlpResponse *res, int *cardno, unsigned long * int dlp_FindDBByName (int sd, int cardno, PI_CONST char *name, unsigned long *localid, - int *dbhandle, struct DBInfo *info, struct DBSizeInfo *size) + int *dbhandle, struct DBInfo *info, struct DBSizeInfo *size) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; int flags = 0; - - TraceX(dlp_FindDBByName,"cardno=%d name='%s'",cardno,name); + + TraceX(dlp_FindDBByName, "cardno=%d name='%s'", cardno, name); pi_reset_errors(sd); if (pi_version(sd) < 0x0102) @@ -1337,26 +1298,26 @@ dlp_FindDBByName (int sd, int cardno, PI_CONST char *name, unsigned long *locali strcpy(DLP_REQUEST_DATA(req, 0, 2), name); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); if (result > 0) dlp_decode_finddb_response(res, NULL, localid, dbhandle, info, size); - + dlp_response_free(res); - - return result; + + return result; } int dlp_FindDBByOpenHandle (int sd, int dbhandle, int *cardno, - unsigned long *localid, struct DBInfo *info, struct DBSizeInfo *size) + unsigned long *localid, struct DBInfo *info, struct DBSizeInfo *size) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; int flags = 0; - + Trace(dlp_FindDBByOpenHandle); pi_reset_errors(sd); @@ -1382,27 +1343,27 @@ dlp_FindDBByOpenHandle (int sd, int dbhandle, int *cardno, result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) dlp_decode_finddb_response(res, cardno, localid, NULL, info, size); - + dlp_response_free(res); - - return result; + + return result; } int dlp_FindDBByTypeCreator (int sd, unsigned long type, unsigned long creator, - int start, int latest, int *cardno, unsigned long *localid, - int *dbhandle, struct DBInfo *info, struct DBSizeInfo *size) + int start, int latest, int *cardno, unsigned long *localid, + int *dbhandle, struct DBInfo *info, struct DBSizeInfo *size) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; int flags = 0, search_flags = 0; - - TraceX(dlp_FindDBByTypeCreator,"type='%4.4s' creator='%4.4s' start=%d latest=%d", - (const char *)&type,(const char *)&creator,start,latest); + + TraceX(dlp_FindDBByTypeCreator, "type='%4.4s' creator='%4.4s' start=%d latest=%d", + (const char *)&type, (const char *)&creator, start, latest); pi_reset_errors(sd); if (pi_version(sd) < 0x0102) @@ -1415,40 +1376,38 @@ dlp_FindDBByTypeCreator (int sd, unsigned long type, unsigned long creator, if (cardno || localid || dbhandle || info) flags |= dlpFindDBOptFlagGetAttributes; if (size) - flags |= (dlpFindDBOptFlagGetSize | - dlpFindDBOptFlagMaxRecSize); - + flags |= (dlpFindDBOptFlagGetSize | dlpFindDBOptFlagMaxRecSize); if (start) search_flags |= dlpFindDBSrchFlagNewSearch; if (latest) search_flags |= dlpFindDBSrchFlagOnlyLatest; - + set_byte(DLP_REQUEST_DATA(req, 0, 0), flags); set_byte(DLP_REQUEST_DATA(req, 0, 1), search_flags); set_long(DLP_REQUEST_DATA(req, 0, 2), type); set_long(DLP_REQUEST_DATA(req, 0, 6), creator); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); - + if (result > 0) dlp_decode_finddb_response(res, cardno, localid, dbhandle, info, size); - + dlp_response_free(res); - - return result; + + return result; } int dlp_OpenDB(int sd, int cardno, int mode, PI_CONST char *name, int *dbhandle) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_OpenDB,"'%s'",name); + TraceX(dlp_ OpenDB, "'%s'", name); pi_reset_errors(sd); req = dlp_request_new(dlpFuncOpenDB, 1, 2 + strlen(name) + 1); @@ -1460,29 +1419,28 @@ dlp_OpenDB(int sd, int cardno, int mode, PI_CONST char *name, int *dbhandle) strcpy(DLP_REQUEST_DATA(req, 0, 2), name); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); - + if (result > 0) { *dbhandle = get_byte(DLP_RESPONSE_DATA(res, 0, 0)); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "-> dlp_OpenDB dbhandle=%d\n", *dbhandle)); + "-> dlp_OpenDB dbhandle=%d\n", *dbhandle)); } - + dlp_response_free(res); - + return result; } int dlp_DeleteDB(int sd, int card, const char *name) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_DeleteDB,"%s",name); + TraceX(dlp_DeleteDB, "%s", name); pi_reset_errors(sd); req = dlp_request_new(dlpFuncDeleteDB, 1, 2 + (strlen(name) + 1)); @@ -1494,23 +1452,23 @@ dlp_DeleteDB(int sd, int card, const char *name) strcpy(DLP_REQUEST_DATA(req, 0, 2), name); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_CreateDB(int sd, unsigned long creator, unsigned long type, int cardno, - int flags, unsigned int version, const char *name, int *dbhandle) + int flags, unsigned int version, const char *name, int *dbhandle) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_CreateDB,"'%s' type='%4.4s' creator='%4.4s' flags=0x%04x version=%d", - name,(const char *)&type,(const char *)&creator,flags,version); + TraceX(dlp_CreateDB, "'%s' type='%4.4s' creator='%4.4s' flags=0x%04x version=%d", + name, (const char *)&type, (const char *)&creator, flags, version); pi_reset_errors(sd); req = dlp_request_new(dlpFuncCreateDB, 1, 14 + (strlen(name) + 1)); @@ -1526,16 +1484,15 @@ dlp_CreateDB(int sd, unsigned long creator, unsigned long type, int cardno, strcpy(DLP_REQUEST_DATA(req, 0, 14), name); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); - + if (result > 0 && dbhandle) { *dbhandle = get_byte(DLP_RESPONSE_DATA(res, 0, 0)); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP CreateDB Handle=%d\n", *dbhandle)); + "DLP CreateDB Handle=%d\n", *dbhandle)); } - + dlp_response_free(res); return result; @@ -1544,7 +1501,7 @@ dlp_CreateDB(int sd, unsigned long creator, unsigned long type, int cardno, int dlp_CloseDB(int sd, int dbhandle) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; @@ -1558,17 +1515,17 @@ dlp_CloseDB(int sd, int dbhandle) set_byte(DLP_REQUEST_DATA(req, 0, 0), (unsigned char) dbhandle); result = dlp_exec(sd, req, &res); - - dlp_request_free(req); + + dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_CloseDB_All(int sd) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; @@ -1580,28 +1537,28 @@ dlp_CloseDB_All(int sd) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); result = dlp_exec(sd, req, &res); - - dlp_request_free(req); + + dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_CallApplication(int sd, unsigned long creator, unsigned long type, - int action, size_t length, const void *data, - unsigned long *retcode, pi_buffer_t *retbuf) + int action, size_t length, const void *data, + unsigned long *retcode, pi_buffer_t *retbuf) { - int result, - version = pi_version(sd), - previous_honor_rx_timeout, - no_rx_timeout = 0; + int result; + int version = pi_version(sd); + int previous_honor_rx_timeout; + int no_rx_timeout = 0; size_t data_len; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_CallApplication,"type='%4.4s' creator='%4.4s' action=0x%04x dataLength=%d", - (const char *)&type,(const char *)&creator,action,(int)length); + TraceX(dlp_CallApplication, "type='%4.4s' creator='%4.4s' action=0x%04x dataLength=%d", + (const char *)&type, (const char *)&creator, action, (int)length); pi_reset_errors(sd); if (retbuf) pi_buffer_clear(retbuf); @@ -1618,7 +1575,7 @@ dlp_CallApplication(int sd, unsigned long creator, unsigned long type, if (length + 22 > DLP_BUF_SIZE) { LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "DLP CallApplication: data too large (>64k)")); + "DLP CallApplication: data too large (>64k)")); pi_set_error(sd, PI_ERR_DLP_DATASIZE); return -131; } @@ -1639,31 +1596,31 @@ dlp_CallApplication(int sd, unsigned long creator, unsigned long type, data_len = sizeof(no_rx_timeout); pi_setsockopt(sd, PI_LEVEL_SOCK, PI_SOCK_HONOR_RX_TIMEOUT, - &no_rx_timeout, &data_len); + &no_rx_timeout, &data_len); result = dlp_exec(sd, req, &res); pi_setsockopt(sd, PI_LEVEL_SOCK, PI_SOCK_HONOR_RX_TIMEOUT, - &previous_honor_rx_timeout, &data_len); + &previous_honor_rx_timeout, &data_len); dlp_request_free(req); if (result > 0) { data_len = res->argv[0]->len - 16; - + if (retcode) *retcode = get_long(DLP_RESPONSE_DATA(res, 0, 0)); if (retbuf) pi_buffer_append(retbuf, DLP_RESPONSE_DATA(res, 0, 16), data_len); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP CallApplication Result: %lu (0x%08lx), " - "and %d bytes:\n", - get_long(DLP_RESPONSE_DATA(res, 0, 0)), - get_long(DLP_RESPONSE_DATA(res, 0, 0)), - data_len)); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 16), + "DLP CallApplication Result: %lu (0x%08lx), " + "and %d bytes:\n", + get_long(DLP_RESPONSE_DATA(res, 0, 0)), + get_long(DLP_RESPONSE_DATA(res, 0, 0)), + data_len)); + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, + pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 16), (size_t)data_len)); } @@ -1671,7 +1628,7 @@ dlp_CallApplication(int sd, unsigned long creator, unsigned long type, if (length + 8 > DLP_BUF_SIZE) { LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "DLP CallApplication: data too large (>64k)")); + "DLP CallApplication: data too large (>64k)")); pi_set_error(sd, PI_ERR_DLP_DATASIZE); return -131; } @@ -1687,12 +1644,12 @@ dlp_CallApplication(int sd, unsigned long creator, unsigned long type, data_len = sizeof(no_rx_timeout); pi_setsockopt(sd, PI_LEVEL_SOCK, PI_SOCK_HONOR_RX_TIMEOUT, - &no_rx_timeout, &data_len); + &no_rx_timeout, &data_len); result = dlp_exec(sd, req, &res); pi_setsockopt(sd, PI_LEVEL_SOCK, PI_SOCK_HONOR_RX_TIMEOUT, - &previous_honor_rx_timeout, &data_len); + &previous_honor_rx_timeout, &data_len); dlp_request_free(req); @@ -1702,17 +1659,17 @@ dlp_CallApplication(int sd, unsigned long creator, unsigned long type, *retcode = get_short(DLP_RESPONSE_DATA(res, 0, 2)); if (retbuf) pi_buffer_append(retbuf, DLP_RESPONSE_DATA(res, 0, 6), data_len); - + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP CallApplication Action: %d Result:" - " %u (0x%04x), and %d bytes:\n", - (int)get_short(DLP_RESPONSE_DATA(res, 0, 0)), - (unsigned int)get_short(DLP_RESPONSE_DATA(res, 0, 2)), - (unsigned int)get_short(DLP_RESPONSE_DATA(res, 0, 2)), - data_len)); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 6), - (size_t)data_len)); + "DLP CallApplication Action: %d Result:" + " %u (0x%04x), and %d bytes:\n", + (int)get_short(DLP_RESPONSE_DATA(res, 0, 0)), + (unsigned int)get_short(DLP_RESPONSE_DATA(res, 0, 2)), + (unsigned int)get_short(DLP_RESPONSE_DATA(res, 0, 2)), + data_len)); + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, + pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 6), + (size_t)data_len)); } } @@ -1723,7 +1680,7 @@ dlp_CallApplication(int sd, unsigned long creator, unsigned long type, int dlp_ResetSystem(int sd) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; @@ -1736,20 +1693,20 @@ dlp_ResetSystem(int sd) if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - dlp_request_free(req); + dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_AddSyncLogEntry(int sd, char *entry) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_AddSyncLogEntry,"%s",entry); + TraceX(dlp_AddSyncLogEntry, "%s", entry); pi_reset_errors(sd); req = dlp_request_new(dlpFuncAddSyncLogEntry, 1, strlen(entry) + 1); @@ -1757,15 +1714,15 @@ dlp_AddSyncLogEntry(int sd, char *entry) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); strcpy(DLP_REQUEST_DATA(req, 0, 0), entry); - + result = dlp_exec(sd, req, &res); - dlp_request_free(req); + dlp_request_free(req); dlp_response_free(res); if (result > 0) { LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP AddSyncLogEntry Entry: \n %s\n", entry)); + "DLP AddSyncLogEntry Entry: \n %s\n", entry)); } return result; @@ -1774,7 +1731,7 @@ dlp_AddSyncLogEntry(int sd, char *entry) int dlp_ReadOpenDBInfo(int sd, int dbhandle, int *records) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; @@ -1786,7 +1743,7 @@ dlp_ReadOpenDBInfo(int sd, int dbhandle, int *records) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); set_byte(DLP_REQUEST_DATA(req, 0, 0), dbhandle); - + result = dlp_exec(sd, req, &res); dlp_request_free(req); @@ -1794,26 +1751,26 @@ dlp_ReadOpenDBInfo(int sd, int dbhandle, int *records) if (result > 0) { if (records) *records = get_short(DLP_RESPONSE_DATA(res, 0, 0)); - + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadOpenDBInfo %d records\n", - get_short(DLP_RESPONSE_DATA(res, 0, 0)))); + "DLP ReadOpenDBInfo %d records\n", + get_short(DLP_RESPONSE_DATA(res, 0, 0)))); } - + dlp_response_free(res); - + return result; } int -dlp_SetDBInfo (int sd, int dbhandle, int flags, int clearFlags, - unsigned int version, time_t createDate, time_t modifyDate, - time_t backupDate, unsigned long type, unsigned long creator) +dlp_SetDBInfo(int sd, int dbhandle, int flags, int clearFlags, + unsigned int version, time_t createDate, time_t modifyDate, + time_t backupDate, unsigned long type, unsigned long creator) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + Trace(dlp_SetDBInfo); pi_reset_errors(sd); @@ -1834,23 +1791,23 @@ dlp_SetDBInfo (int sd, int dbhandle, int flags, int clearFlags, set_date((unsigned char *)DLP_REQUEST_DATA(req, 0, 24), backupDate); set_long(DLP_REQUEST_DATA(req, 0, 32), type); set_long(DLP_REQUEST_DATA(req, 0, 36), creator); - + result = dlp_exec(sd, req, &res); dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_MoveCategory(int sd, int handle, int fromcat, int tocat) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_MoveCategory,"from %d to %d",fromcat,tocat); + TraceX(dlp_MoveCategory, "from %d to %d", fromcat, tocat); pi_reset_errors(sd); req = dlp_request_new(dlpFuncMoveCategory, 1, 4); @@ -1864,13 +1821,13 @@ dlp_MoveCategory(int sd, int handle, int fromcat, int tocat) result = dlp_exec(sd, req, &res); - dlp_request_free(req); + dlp_request_free(req); dlp_response_free(res); if (result >= 0) { LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP MoveCategory Handle: %d, From: %d, To: %d\n", - handle, fromcat, tocat)); + "DLP MoveCategory Handle: %d, From: %d, To: %d\n", + handle, fromcat, tocat)); } return result; @@ -1879,22 +1836,22 @@ dlp_MoveCategory(int sd, int handle, int fromcat, int tocat) int dlp_OpenConduit(int sd) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; Trace(dlp_OpenConduit); pi_reset_errors(sd); - + req = dlp_request_new(dlpFuncOpenConduit, 0); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); result = dlp_exec(sd, req, &res); - dlp_request_free(req); + dlp_request_free(req); dlp_response_free(res); - + /* if this was not done yet, this will read and cache the DLP version that the Palm is running. We need this when reading responses during record/resource transfers */ @@ -1907,7 +1864,7 @@ dlp_OpenConduit(int sd) int dlp_EndOfSync(int sd, int status) { - int result; + int result; pi_socket_t *ps; struct dlpRequest *req; struct dlpResponse *res; @@ -1929,10 +1886,10 @@ dlp_EndOfSync(int sd, int status) result = dlp_exec(sd, req, &res); - dlp_request_free(req); + dlp_request_free(req); dlp_response_free(res); - /* Messy code to set end-of-sync flag on socket + /* Messy code to set end-of-sync flag on socket so pi_close won't do it for us */ if (result == 0) ps->state = PI_SOCK_CONN_END; @@ -1962,16 +1919,16 @@ dlp_AbortSync(int sd) int dlp_WriteUserInfo(int sd, const struct PilotUser *User) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; int len; - + Trace(dlp_WriteUserInfo); pi_reset_errors(sd); len = strlen (User->username) + 1; - + req = dlp_request_new (dlpFuncWriteUserInfo, 1, 22 + len); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -1988,50 +1945,43 @@ dlp_WriteUserInfo(int sd, const struct PilotUser *User) dlp_request_free (req); dlp_response_free (res); - + return result; } int dlp_ReadUserInfo(int sd, struct PilotUser *User) { - int result; + int result; size_t userlen; struct dlpRequest *req; struct dlpResponse *res; - + Trace(dlp_ReadUserInfo); pi_reset_errors(sd); req = dlp_request_new (dlpFuncReadUserInfo, 0); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - + result = dlp_exec (sd, req, &res); dlp_request_free (req); if (result > 0) { - User->userID = - get_long(DLP_RESPONSE_DATA (res, 0, 0)); - User->viewerID = - get_long(DLP_RESPONSE_DATA (res, 0, 4)); - User->lastSyncPC = - get_long(DLP_RESPONSE_DATA (res, 0, 8)); + User->userID = get_long(DLP_RESPONSE_DATA (res, 0, 0)); + User->viewerID = get_long(DLP_RESPONSE_DATA (res, 0, 4)); + User->lastSyncPC = get_long(DLP_RESPONSE_DATA (res, 0, 8)); User->successfulSyncDate = - get_date((const unsigned char *)DLP_RESPONSE_DATA (res, 0, 12)); + get_date((const unsigned char *)DLP_RESPONSE_DATA (res, 0, 12)); User->lastSyncDate = - get_date((const unsigned char *)DLP_RESPONSE_DATA (res, 0, 20)); - userlen = - get_byte(DLP_RESPONSE_DATA (res, 0, 28)); - User->passwordLength = - get_byte(DLP_RESPONSE_DATA (res, 0, 29)); - - memcpy(User->username, - DLP_RESPONSE_DATA (res, 0, 30), userlen); + get_date((const unsigned char *)DLP_RESPONSE_DATA (res, 0, 20)); + userlen = get_byte(DLP_RESPONSE_DATA (res, 0, 28)); + User->passwordLength = get_byte(DLP_RESPONSE_DATA (res, 0, 29)); + + memcpy(User->username, DLP_RESPONSE_DATA (res, 0, 30), userlen); memcpy(User->password, - DLP_RESPONSE_DATA (res, 0, 30 + userlen), - User->passwordLength); + DLP_RESPONSE_DATA (res, 0, 30 + userlen), User->passwordLength); if (userlen < sizeof(User->username)) User->username[userlen] = '\0'; @@ -2039,26 +1989,25 @@ dlp_ReadUserInfo(int sd, struct PilotUser *User) User->password[User->passwordLength] = '\0'; LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadUserInfo UID=0x%8.8lX VID=0x%8.8lX " - "PCID=0x%8.8lX\n", - User->userID, User->viewerID, User->lastSyncPC)); + "DLP ReadUserInfo UID=0x%8.8lX VID=0x%8.8lX PCID=0x%8.8lX\n", + User->userID, User->viewerID, User->lastSyncPC)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Last Sync=%s Last Successful Sync=%s", - ctime (&User->lastSyncDate), - ctime (&User->successfulSyncDate))); + " Last Sync=%s Last Successful Sync=%s", + ctime (&User->lastSyncDate), + ctime (&User->successfulSyncDate))); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " Username=%s\n", User->username)); + " Username=%s\n", User->username)); } - + dlp_response_free (res); - + return result; } int dlp_ReadNetSyncInfo(int sd, struct NetSyncInfo *i) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; @@ -2078,40 +2027,40 @@ dlp_ReadNetSyncInfo(int sd, struct NetSyncInfo *i) if (result >= 0) { size_t str_offset = 24; - + i->lanSync = get_byte(DLP_RESPONSE_DATA(res, 0, 0)); - + i->hostName[0] = '\0'; - memcpy(i->hostName, DLP_RESPONSE_DATA(res, 0, str_offset), - get_short(DLP_RESPONSE_DATA(res, 0, 18))); + memcpy(i->hostName, DLP_RESPONSE_DATA(res, 0, str_offset), + get_short(DLP_RESPONSE_DATA(res, 0, 18))); str_offset += get_short(DLP_RESPONSE_DATA(res, 0, 18)); i->hostAddress[0] = '\0'; - memcpy(i->hostAddress, DLP_RESPONSE_DATA(res, 0, str_offset), - get_short(DLP_RESPONSE_DATA(res, 0, 20))); + memcpy(i->hostAddress, DLP_RESPONSE_DATA(res, 0, str_offset), + get_short(DLP_RESPONSE_DATA(res, 0, 20))); str_offset += get_short(DLP_RESPONSE_DATA(res, 0, 20)); i->hostSubnetMask[0] = '\0'; - memcpy(i->hostSubnetMask, DLP_RESPONSE_DATA(res, 0, str_offset), - get_short(DLP_RESPONSE_DATA(res, 0, 22))); + memcpy(i->hostSubnetMask, DLP_RESPONSE_DATA(res, 0, str_offset), + get_short(DLP_RESPONSE_DATA(res, 0, 22))); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadNetSyncInfo Active: %d\n", i->lanSync ? 1 : 0)); + "DLP ReadNetSyncInfo Active: %d\n", i->lanSync ? 1 : 0)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " PC hostname: '%s', address '%s', mask '%s'\n", - i->hostName, i->hostAddress, i->hostSubnetMask)); + " PC hostname: '%s', address '%s', mask '%s'\n", + i->hostName, i->hostAddress, i->hostSubnetMask)); } dlp_response_free(res); - + return result; } int dlp_WriteNetSyncInfo(int sd, const struct NetSyncInfo *i) { - int result, - str_offset = 24; + int result; + int str_offset = 24; struct dlpRequest *req; struct dlpResponse *res; @@ -2122,14 +2071,13 @@ dlp_WriteNetSyncInfo(int sd, const struct NetSyncInfo *i) return pi_set_error(sd, PI_ERR_DLP_UNSUPPORTED); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadNetSyncInfo Active: %d\n", i->lanSync ? 1 : 0)); + "DLP ReadNetSyncInfo Active: %d\n", i->lanSync ? 1 : 0)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " PC hostname: '%s', address '%s', mask '%s'\n", - i->hostName, i->hostAddress, i->hostSubnetMask)); + " PC hostname: '%s', address '%s', mask '%s'\n", + i->hostName, i->hostAddress, i->hostSubnetMask)); - req = dlp_request_new(dlpFuncWriteNetSyncInfo, 1, - 24 + strlen(i->hostName) + - strlen(i->hostAddress) + strlen(i->hostSubnetMask) + 3); + req = dlp_request_new(dlpFuncWriteNetSyncInfo, 1, 24 + strlen(i->hostName) + + strlen(i->hostAddress) + strlen(i->hostSubnetMask) + 3); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -2155,7 +2103,7 @@ dlp_WriteNetSyncInfo(int sd, const struct NetSyncInfo *i) dlp_request_free(req); dlp_response_free(res); - + return result; } @@ -2163,10 +2111,8 @@ dlp_WriteNetSyncInfo(int sd, const struct NetSyncInfo *i) int dlp_RPC(int sd, struct RPC_params *p, unsigned long *result) { - int i, - err = 0; - long D0 = 0, - A0 = 0; + int i, err = 0; + long D0 = 0, A0 = 0; unsigned char *c; pi_buffer_t *dlp_buf; @@ -2224,10 +2170,8 @@ dlp_RPC(int sd, struct RPC_params *p, unsigned long *result) c = dlp_buf->data + 18; for (i = p->args - 1; i >= 0; i--) { if (p->param[i].byRef && p->param[i].data) - memcpy(p->param[i].data, c + 2, - p->param[i].size); - c += 2 + ((p->param[i].size + 1) & - (unsigned)~1); + memcpy(p->param[i].data, c + 2, p->param[i].size); + c += 2 + ((p->param[i].size + 1) & (unsigned)~1); } } } @@ -2250,18 +2194,17 @@ dlp_RPC(int sd, struct RPC_params *p, unsigned long *result) int -dlp_ReadFeature(int sd, unsigned long creator, int num, - unsigned long *feature) +dlp_ReadFeature(int sd, unsigned long creator, int num, unsigned long *feature) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_ReadFeature,"creator='%4.4s' num=%d",(const char *)&creator,num); + TraceX(dlp_ReadFeature, "creator='%4.4s' num=%d", (const char *)&creator, num); pi_reset_errors(sd); if (pi_version(sd) < 0x0101) { - struct RPC_params p; + struct RPC_params p; int val; unsigned long errCode; @@ -2276,24 +2219,19 @@ dlp_ReadFeature(int sd, unsigned long creator, int num, if (val < 0) { LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadFeature Error: %s (%d)\n", - dlp_errorlist[-val], val)); - + "DLP ReadFeature Error: %s (%d)\n", dlp_errorlist[-val], val)); return val; } - + if (errCode) { LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadFeature FtrGet error 0x%8.8lX\n", - res)); + "DLP ReadFeature FtrGet error 0x%8.8lX\n", res)); pi_set_palmos_error(sd, (int)errCode); return pi_set_error(sd, PI_ERR_DLP_PALMOS); } LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " DLP ReadFeature Feature: 0x%8.8lX\n", - (unsigned long) *feature)); - + " DLP ReadFeature Feature: 0x%8.8lX\n", (unsigned long) *feature)); return 0; } @@ -2309,16 +2247,13 @@ dlp_ReadFeature(int sd, unsigned long creator, int num, result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { if (feature) - *feature = (unsigned long) - get_long(DLP_RESPONSE_DATA(res, 0, 0)); - + *feature = (unsigned long)get_long(DLP_RESPONSE_DATA(res, 0, 0)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadFeature Feature: 0x%8.8lX\n", - (unsigned long) - get_long(DLP_RESPONSE_DATA(res, 0, 0)))); + "DLP ReadFeature Feature: 0x%8.8lX\n", + (unsigned long)get_long(DLP_RESPONSE_DATA(res, 0, 0)))); } dlp_response_free(res); @@ -2331,21 +2266,16 @@ int dlp_GetROMToken(int sd, unsigned long token, void *buffer, size_t *size) { unsigned long result; - struct RPC_params p; - int val; unsigned long buffer_ptr; Trace(dlp_GetROMToken); pi_reset_errors(sd); - + #ifdef DLP_TRACE - if (dlp_trace) { - fprintf(stderr, - " Wrote: Token: '%s'\n", - printlong(token)); - } + if (dlp_trace) + fprintf(stderr, " Wrote: Token: '%s'\n", printlong(token)); #endif PackRPC(&p, 0xa340, RPC_IntReply, /* sysTrapHwrGetROMToken */ @@ -2353,57 +2283,49 @@ dlp_GetROMToken(int sd, unsigned long token, void *buffer, size_t *size) RPC_Long(token), RPC_LongPtr(&buffer_ptr), RPC_ShortPtr(size), RPC_End); - + val = dlp_RPC(sd, &p, &result); #ifdef DLP_TRACE if (dlp_trace) { - if (val < 0) - fprintf(stderr, - "Result: Error: %s (%d)\n", - dlp_errorlist[-val], val); - else if (result) - fprintf(stderr, - "FtrGet error 0x%8.8lX\n", - (unsigned long) result); - else - fprintf(stderr, - " Read: Buffer Ptr: 0x%8.8lX Size: %d\n", - (unsigned long) buffer_ptr, *size); + if (val < 0) + fprintf(stderr, "Result: Error: %s (%d)\n", + dlp_errorlist[-val], val); + else if (result) + fprintf(stderr, "FtrGet error 0x%8.8lX\n", + (unsigned long) result); + else + fprintf(stderr, " Read: Buffer Ptr: 0x%8.8lX Size: %d\n", + (unsigned long) buffer_ptr, *size); } -#endif +#endif if (buffer) { ((unsigned char *)buffer)[*size] = 0; PackRPC(&p, 0xa026, RPC_IntReply, /* sysTrapMemMove */ - RPC_Ptr(buffer, *size), - RPC_Long(buffer_ptr), - RPC_Long((unsigned long) *size), - RPC_End); + RPC_Ptr(buffer, *size), + RPC_Long(buffer_ptr), + RPC_Long((unsigned long) *size), + RPC_End); val = dlp_RPC(sd, &p, &result); } #ifdef DLP_TRACE if (dlp_trace) { - if (val < 0) - fprintf(stderr, - "Result: Error: %s (%d)\n", - dlp_errorlist[-val], val); - else if (result) - fprintf(stderr, - "FtrGet error 0x%8.8lX\n", - (unsigned long) result); - else - fprintf(stderr, - " Read: Buffer: %s\n", buffer); + if (val < 0) + fprintf(stderr, "Result: Error: %s (%d)\n", dlp_errorlist[-val], val); + else if (result) + fprintf(stderr, "FtrGet error 0x%8.8lX\n", (unsigned long) result); + else + fprintf(stderr, " Read: Buffer: %s\n", buffer); } -#endif +#endif if (val < 0) return val; - + if (result) return -((int)result); @@ -2413,8 +2335,8 @@ dlp_GetROMToken(int sd, unsigned long token, void *buffer, size_t *size) int dlp_ResetLastSyncPC(int sd) { - int err; - struct PilotUser User; + int err; + struct PilotUser User; Trace(dlp_ResetLastSyncPC); @@ -2429,7 +2351,7 @@ dlp_ResetLastSyncPC(int sd) int dlp_ResetDBIndex(int sd, int dbhandle) { - int result; + int result; pi_socket_t *ps; struct dlpRequest *req; struct dlpResponse *res; @@ -2449,25 +2371,24 @@ dlp_ResetDBIndex(int sd, int dbhandle) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); set_byte(DLP_REQUEST_DATA(req, 0, 0), dbhandle); - + result = dlp_exec(sd, req, &res); - dlp_request_free(req); + dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_ReadRecordIDList(int sd, int dbhandle, int sort, int start, int max, - recordid_t * IDs, int *count) + recordid_t * IDs, int *count) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_ReadRecordIDList,"sort=%d start=%d max=%d", - sort,start,max); + TraceX(dlp_ReadRecordIDList, "sort=%d start=%d max=%d", sort, start, max); pi_reset_errors(sd); req = dlp_request_new(dlpFuncReadRecordIDList, 1, 6); @@ -2485,24 +2406,22 @@ dlp_ReadRecordIDList(int sd, int dbhandle, int sort, int start, int max, if (result > 0) { int ret, i; - + ret = get_short(DLP_RESPONSE_DATA(res, 0, 0)); for (i = 0; i < ret; i++) - IDs[i] = - get_long(DLP_RESPONSE_DATA(res, 0, 2 + (i * 4))); + IDs[i] = get_long(DLP_RESPONSE_DATA(res, 0, 2 + (i * 4))); if (count) *count = ret; LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadRecordIDList %d IDs:\n", ret)); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 2), - (size_t)(ret * 4))); + "DLP ReadRecordIDList %d IDs:\n", ret)); + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, + pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 2), (size_t)(ret * 4))); } dlp_response_free(res); - + return result; } @@ -2510,7 +2429,7 @@ int dlp_WriteRecord(int sd, int dbhandle, int flags, recordid_t recID, int catID, const void *data, size_t length, recordid_t *pNewRecID) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; @@ -2536,7 +2455,7 @@ dlp_WriteRecord(int sd, int dbhandle, int flags, recordid_t recID, } else { if ((length + 8) > DLP_BUF_SIZE) { LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "DLP WriteRecord: data too large (>64k)")); + "DLP WriteRecord: data too large (>64k)")); return PI_ERR_DLP_DATASIZE; } @@ -2562,28 +2481,27 @@ dlp_WriteRecord(int sd, int dbhandle, int flags, recordid_t recID, *pNewRecID = get_long(DLP_RESPONSE_DATA(res, 0, 0)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP WriteRecord Record ID: 0x%8.8lX\n", - get_long(DLP_RESPONSE_DATA(res, 0, 0)))); + "DLP WriteRecord Record ID: 0x%8.8lX\n", + get_long(DLP_RESPONSE_DATA(res, 0, 0)))); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - record_dump( + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, record_dump( get_long(DLP_RESPONSE_DATA(res, 0, 0)), /* recID */ 0xffff, /* index */ flags, catID, (const char *)data, (int)length)); } - + dlp_response_free(res); - + return result; } int dlp_DeleteRecord(int sd, int dbhandle, int all, recordid_t recID) { - int result, - flags = all ? 0x80 : 0; + int result; + int flags = all ? 0x80 : 0; struct dlpRequest *req; struct dlpResponse *res; @@ -2599,21 +2517,21 @@ dlp_DeleteRecord(int sd, int dbhandle, int all, recordid_t recID) set_long(DLP_REQUEST_DATA(req, 0, 2), recID); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_DeleteCategory(int sd, int dbhandle, int category) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_DeleteCategory,"category=%d",category); + TraceX(dlp_DeleteCategory, "category=%d", category); pi_reset_errors(sd); if (pi_version(sd) < 0x0101) { @@ -2622,16 +2540,15 @@ dlp_DeleteCategory(int sd, int dbhandle, int category) recordid_t id_; LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP DeleteCategory Emulating with: Handle: %d, " - "Category: %d\n", - dbhandle, category & 0xff)); + "DLP DeleteCategory Emulating with: Handle: %d, Category: %d\n", + dbhandle, category & 0xff)); for (i = 0; - (result = dlp_ReadRecordByIndex(sd, dbhandle, i, NULL, &id_, - &attr, &cat)) >= 0; i++) { + (result = dlp_ReadRecordByIndex(sd, dbhandle, i, NULL, &id_, &attr, &cat)) >= 0; + i++) { if (cat != category - || (attr & dlpRecAttrDeleted) - || (attr & dlpRecAttrArchived)) + || (attr & dlpRecAttrDeleted) + || (attr & dlpRecAttrArchived)) continue; result = dlp_DeleteRecord(sd, dbhandle, 0, id_); if (result < 0) @@ -2642,15 +2559,15 @@ dlp_DeleteCategory(int sd, int dbhandle, int category) return result; } else { int flags = 0x40; - + req = dlp_request_new(dlpFuncDeleteRecord, 1, 6); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - + set_byte(DLP_REQUEST_DATA(req, 0, 0), dbhandle); set_byte(DLP_REQUEST_DATA(req, 0, 1), flags); set_long(DLP_REQUEST_DATA(req, 0, 2), category & 0xff); - + result = dlp_exec(sd, req, &res); dlp_request_free(req); @@ -2662,15 +2579,15 @@ dlp_DeleteCategory(int sd, int dbhandle, int category) int dlp_ReadResourceByType(int sd, int dbhandle, unsigned long type, int resID, - pi_buffer_t *buffer, int *resindex) + pi_buffer_t *buffer, int *resindex) { - int result, - data_len; + int result; + int data_len; struct dlpRequest *req; struct dlpResponse *res; int maxBufferSize = pi_maxrecsize(sd) - RECORD_READ_SAFEGUARD_SIZE; - TraceX(dlp_ReadResourceByType,"type='%4.4s' resID=%d",(const char *)&type,resID); + TraceX(dlp_ReadResourceByType, "type='%4.4s' resID=%d", (const char *)&type, resID); pi_reset_errors(sd); req = dlp_request_new_with_argid(dlpFuncReadResource, 0x21, 1, 12); @@ -2687,15 +2604,14 @@ dlp_ReadResourceByType(int sd, int dbhandle, unsigned long type, int resID, result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { data_len = res->argv[0]->len - 10; if (resindex) *resindex = get_short(DLP_RESPONSE_DATA(res, 0, 6)); if (buffer) { pi_buffer_clear (buffer); - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), - (size_t)data_len); + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), (size_t)data_len); /* Some devices such as the Tungsten TX, Treo 650 and Treo 700p lock up if you try to read the entire record if the ** record is almost at the maximum record size. The following mitigates this and allows the record @@ -2713,9 +2629,9 @@ dlp_ReadResourceByType(int sd, int dbhandle, unsigned long type, int resID, set_short(DLP_REQUEST_DATA(req, 0, 10), RECORD_READ_SAFEGUARD_SIZE); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); - + if (result > 0) { data_len = res->argv[0]->len - 10; /* number of bytes returned by the second read... */ pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), (size_t)data_len); @@ -2724,35 +2640,33 @@ dlp_ReadResourceByType(int sd, int dbhandle, unsigned long type, int resID, } } } - + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadResourceByType Type: '%s', ID: %d, " - "Index: %d, and %d bytes:\n", - printlong(type), resID, - get_short(DLP_RESPONSE_DATA(res, 0, 6)),(size_t)data_len)); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 10),(size_t)data_len)); + "DLP ReadResourceByType Type: '%s', ID: %d, " + "Index: %d, and %d bytes:\n", + printlong(type), resID, + get_short(DLP_RESPONSE_DATA(res, 0, 6)), (size_t)data_len)); + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, + pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 10), (size_t)data_len)); } else { data_len = result; } dlp_response_free(res); - + return data_len; } int dlp_ReadResourceByIndex(int sd, int dbhandle, unsigned int resindex, pi_buffer_t *buffer, - unsigned long *type, int *resID) + unsigned long *type, int *resID) { - int result, - data_len, - large = 0; + int result, data_len, large = 0; struct dlpRequest *req; struct dlpResponse *res; int maxBufferSize = pi_maxrecsize(sd) - RECORD_READ_SAFEGUARD_SIZE; - TraceX(dlp_ReadResourceByIndex,"resindex=%d",resindex); + TraceX(dlp_ReadResourceByIndex, "resindex=%d", resindex); pi_reset_errors(sd); /* TapWave (DLP 1.4) implements a 'large' version of dlpFuncReadResource, @@ -2783,7 +2697,7 @@ dlp_ReadResourceByIndex(int sd, int dbhandle, unsigned int resindex, pi_buffer_t result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { data_len = res->argv[0]->len - (large ? 12 : 10); if (type) @@ -2792,8 +2706,7 @@ dlp_ReadResourceByIndex(int sd, int dbhandle, unsigned int resindex, pi_buffer_t *resID = get_short(DLP_RESPONSE_DATA(res, 0, 4)); if (buffer) { pi_buffer_clear (buffer); - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, large ? 12 : 10), - (size_t)data_len); + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, large ? 12 : 10), (size_t)data_len); /* Some devices such as the Tungsten TX, Treo 650 and Treo 700p lock up if you try to read the entire record if the ** record is almost at the maximum record size. The following mitigates this and allows the record @@ -2808,49 +2721,47 @@ dlp_ReadResourceByIndex(int sd, int dbhandle, unsigned int resindex, pi_buffer_t set_short(DLP_REQUEST_DATA(req, 0, 2), resindex); set_short(DLP_REQUEST_DATA(req, 0, 4), maxBufferSize); /* Offset in record */ set_short(DLP_REQUEST_DATA(req, 0, 6), RECORD_READ_SAFEGUARD_SIZE); - + result = dlp_exec(sd, req, &res); - + dlp_request_free(req); - + if (result > 0) { data_len = res->argv[0]->len - (large ? 12 : 10); /* number of bytes returned by the second read... */ - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, large ? 12 : 10), - (size_t)data_len); + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, large ? 12 : 10), (size_t)data_len); data_len += maxBufferSize; /* ...that add up to the bytes received in the first read */ } } - } + } } LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadResourceByIndex Type: '%s', ID: %d, " - "Index: %d, and %d bytes:\n", - printlong(get_long(DLP_RESPONSE_DATA(res, 0, 0))), - get_short(DLP_RESPONSE_DATA(res, 0, 4)), - resindex, data_len)); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - pi_dumpdata(DLP_RESPONSE_DATA(res, 0, (large ? 12 : 10)), - (size_t)data_len)); + "DLP ReadResourceByIndex Type: '%s', ID: %d, " + "Index: %d, and %d bytes:\n", + printlong(get_long(DLP_RESPONSE_DATA(res, 0, 0))), + get_short(DLP_RESPONSE_DATA(res, 0, 4)), + resindex, data_len)); + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, + pi_dumpdata(DLP_RESPONSE_DATA(res, 0, (large ? 12 : 10)), + (size_t)data_len)); } else { data_len = result; } dlp_response_free(res); - + return data_len; } int dlp_WriteResource(int sd, int dbhandle, unsigned long type, int resID, - const void *data, size_t length) + const void *data, size_t length) { - int result, - large = 0; + int result, large = 0; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_WriteResource,"'%4.4s' #%d",(const char *)&type,resID); + TraceX(dlp_WriteResource, "'%4.4s' #%d", (const char *)&type, resID); pi_reset_errors(sd); /* TapWave (DLP 1.4) implements a 'large' version of dlpFuncWriteResource, @@ -2858,7 +2769,7 @@ dlp_WriteResource(int sd, int dbhandle, unsigned long type, int resID, */ if (pi_version(sd) >= 0x0104) { req = dlp_request_new_with_argid(dlpFuncWriteResourceEx, - PI_DLP_ARG_FIRST_ID | PI_DLP_ARG_FLAG_LONG, 1, 12 + length); + PI_DLP_ARG_FIRST_ID | PI_DLP_ARG_FLAG_LONG, 1, 12 + length); large = 1; } else { if (length > 0xffff) @@ -2867,8 +2778,7 @@ dlp_WriteResource(int sd, int dbhandle, unsigned long type, int resID, } if (req == NULL) { LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "DLP sd:%i large:%i dlp_request_new failed\n", - sd, large)); + "DLP sd:%i large:%i dlp_request_new failed\n", sd, large)); return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); } @@ -2893,16 +2803,14 @@ dlp_WriteResource(int sd, int dbhandle, unsigned long type, int resID, int -dlp_DeleteResource(int sd, int dbhandle, int all, unsigned long restype, - int resID) +dlp_DeleteResource(int sd, int dbhandle, int all, unsigned long restype, int resID) { - int result, - flags = all ? 0x80 : 0; + int result, flags = all ? 0x80 : 0; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_DeleteResource,"restype='%4.4s' resID=%d all=%d", - (const char *)&restype,resID,all); + TraceX(dlp_DeleteResource, "restype='%4.4s' resID=%d all=%d", + (const char *)&restype, resID, all); pi_reset_errors(sd); req = dlp_request_new(dlpFuncDeleteResource, 1, 8); @@ -2915,22 +2823,21 @@ dlp_DeleteResource(int sd, int dbhandle, int all, unsigned long restype, set_short(DLP_REQUEST_DATA(req, 0, 6), resID); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_ReadAppBlock(int sd, int dbhandle, int offset, int reqbytes, pi_buffer_t *retbuf) { - int result, - data_len; + int result, data_len; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_ReadAppBlock,"offset=%d reqbytes=%ld",offset,reqbytes); + TraceX(dlp_ReadAppBlock, "offset=%d reqbytes=%ld", offset, reqbytes); pi_reset_errors(sd); if (retbuf) @@ -2948,53 +2855,49 @@ dlp_ReadAppBlock(int sd, int dbhandle, int offset, int reqbytes, pi_buffer_t *re result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result >= 0) { if (result < 2) data_len = PI_ERR_DLP_COMMAND; else { data_len = res->argv[0]->len - 2; if (retbuf && data_len) - pi_buffer_append(retbuf, DLP_RESPONSE_DATA(res, 0, 2), - (size_t)data_len); - + pi_buffer_append(retbuf, DLP_RESPONSE_DATA(res, 0, 2), (size_t)data_len); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP ReadAppBlock %d bytes\n", data_len)); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 2), - (size_t)data_len)); + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, + pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 2), (size_t)data_len)); } } else { data_len = result; } dlp_response_free(res); - + return data_len; } int -dlp_WriteAppBlock(int sd, int dbhandle, const /* @unique@ */ void *data, - size_t length) +dlp_WriteAppBlock(int sd, int dbhandle, const /* @unique@ */ void *data, size_t length) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_WriteAppBlock,"length=%ld",length); + TraceX(dlp_WriteAppBlock, "length=%ld", length); pi_reset_errors(sd); req = dlp_request_new(dlpFuncWriteAppBlock, 1, 4 + length); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - + set_byte(DLP_REQUEST_DATA(req, 0, 0), dbhandle); set_byte(DLP_REQUEST_DATA(req, 0, 1), 0); set_short(DLP_REQUEST_DATA(req, 0, 2), length); if (length + 10 > DLP_BUF_SIZE) { - LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "DLP WriteAppBlock: data too large (>64k)")); + LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, "DLP WriteAppBlock: data too large (>64k)")); pi_set_error(sd, PI_ERR_DLP_DATASIZE); return -131; } @@ -3012,12 +2915,11 @@ dlp_WriteAppBlock(int sd, int dbhandle, const /* @unique@ */ void *data, int dlp_ReadSortBlock(int sd, int dbhandle, int offset, int reqbytes, pi_buffer_t *retbuf) { - int result, - data_len; + int result, data_len; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_ReadSortBlock,"offset=%d reqbytes=%d",offset,reqbytes); + TraceX(dlp_ReadSortBlock, "offset=%d reqbytes=%d", offset, reqbytes); pi_reset_errors(sd); if (retbuf) @@ -3035,40 +2937,37 @@ dlp_ReadSortBlock(int sd, int dbhandle, int offset, int reqbytes, pi_buffer_t *r result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result >= 0) { if (result < 2) data_len = PI_ERR_DLP_COMMAND; else { data_len = res->argv[0]->len - 2; if (retbuf) - pi_buffer_append(retbuf, DLP_RESPONSE_DATA(res, 0, 2), - (size_t)data_len); - + pi_buffer_append(retbuf, DLP_RESPONSE_DATA(res, 0, 2), (size_t)data_len); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadSortBlock %d bytes\n", data_len)); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 2), - (size_t)data_len)); + "DLP ReadSortBlock %d bytes\n", data_len)); + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, + pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 2), (size_t)data_len)); } } else { data_len = result; } dlp_response_free(res); - + return data_len; } int -dlp_WriteSortBlock(int sd, int dbhandle, const /* @unique@ */ void *data, - size_t length) +dlp_WriteSortBlock(int sd, int dbhandle, const /* @unique@ */ void *data, size_t length) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_WriteSortBlock,"length=%ld",length); + TraceX(dlp_WriteSortBlock, "length=%ld", length); pi_reset_errors(sd); req = dlp_request_new(dlpFuncWriteSortBlock, 1, 4 + length); @@ -3080,8 +2979,8 @@ dlp_WriteSortBlock(int sd, int dbhandle, const /* @unique@ */ void *data, set_short(DLP_REQUEST_DATA(req, 0, 2), length); if (length + 10 > DLP_BUF_SIZE) { - LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "DLP WriteSortBlock: data too large (>64k)")); + LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, + "DLP WriteSortBlock: data too large (>64k)")); pi_set_error(sd, PI_ERR_DLP_DATASIZE); return -131; } @@ -3098,7 +2997,7 @@ dlp_WriteSortBlock(int sd, int dbhandle, const /* @unique@ */ void *data, int dlp_CleanUpDatabase(int sd, int dbhandle) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; @@ -3112,17 +3011,17 @@ dlp_CleanUpDatabase(int sd, int dbhandle) set_byte(DLP_REQUEST_DATA(req, 0, 0), dbhandle); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_ResetSyncFlags(int sd, int dbhandle) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; @@ -3136,37 +3035,32 @@ dlp_ResetSyncFlags(int sd, int dbhandle) set_byte(DLP_REQUEST_DATA(req, 0, 0), dbhandle); result = dlp_exec(sd, req, &res); - + dlp_request_free(req); dlp_response_free(res); - + return result; } int dlp_ReadNextRecInCategory(int sd, int dbhandle, int category, - pi_buffer_t *buffer, recordid_t *recuid, int *recindex, - int *attr) + pi_buffer_t *buffer, recordid_t *recuid, int *recindex, int *attr) { - int result, - data_len, - flags; + int result, data_len, flags; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_ReadNextRecInCategory,"category=%d",category); + TraceX(dlp_ReadNextRecInCategory, "category=%d", category); pi_reset_errors(sd); if (pi_version(sd) < 0x0101) { /* Emulate for PalmOS 1.0 */ - int cat, - rec; + int cat, rec; pi_socket_t *ps; LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadNextRecInCategory Emulating with: Handle: %d, " - "Category: %d\n", - dbhandle, category)); + "DLP ReadNextRecInCategory Emulating with: Handle: %d, Category: %d\n", + dbhandle, category)); if ((ps = find_pi_socket(sd)) == 0) { errno = ESRCH; @@ -3176,8 +3070,7 @@ dlp_ReadNextRecInCategory(int sd, int dbhandle, int category, for (;;) { /* Fetch next modified record (in any category) */ rec = dlp_ReadRecordByIndex(sd, dbhandle, - ps->dlprecord, 0, 0, - 0, &cat); + ps->dlprecord, 0, 0, 0, &cat); if (rec < 0) break; @@ -3188,8 +3081,7 @@ dlp_ReadNextRecInCategory(int sd, int dbhandle, int category, } rec = dlp_ReadRecordByIndex(sd, dbhandle, - ps->dlprecord, buffer, - recuid, attr, &cat); + ps->dlprecord, buffer, recuid, attr, &cat); if (rec >= 0) { if (recindex) @@ -3211,7 +3103,7 @@ dlp_ReadNextRecInCategory(int sd, int dbhandle, int category, return rec; } - + req = dlp_request_new(dlpFuncReadNextRecInCategory, 1, 2); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -3233,17 +3125,14 @@ dlp_ReadNextRecInCategory(int sd, int dbhandle, int category, *attr = get_byte(DLP_RESPONSE_DATA(res, 0, 8)); if (buffer) { pi_buffer_clear (buffer); - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), - (size_t)data_len); + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), (size_t)data_len); } flags = get_byte(DLP_RESPONSE_DATA(res, 0, 8)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadNextRecInCategory ID: 0x%8.8lX, " - "Index: %d, Category: %d\n" + "DLP ReadNextRecInCategory ID: 0x%8.8lX, Index: %d, Category: %d\n" " Flags: %s%s%s%s%s%s (0x%2.2X) and %d bytes:\n", - (unsigned long) get_long(DLP_RESPONSE_DATA(res, - 0, 0)), + (unsigned long) get_long(DLP_RESPONSE_DATA(res, 0, 0)), get_short(DLP_RESPONSE_DATA(res, 0, 4)), (int) get_byte(DLP_RESPONSE_DATA(res, 0, 9)), (flags & dlpRecAttrDeleted) ? " Deleted" : "", @@ -3253,48 +3142,45 @@ dlp_ReadNextRecInCategory(int sd, int dbhandle, int category, (flags & dlpRecAttrArchived) ? " Archive" : "", (!flags) ? " None" : "", flags, data_len)); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 10), - (size_t)data_len)); + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, + pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 10), (size_t)data_len)); } else { data_len = result; } dlp_response_free(res); - + return data_len; } int dlp_ReadAppPreference(int sd, unsigned long creator, int prefID, int backup, - int maxsize, void *buffer, size_t *size, int *version) + int maxsize, void *buffer, size_t *size, int *version) { - int result, - data_len; + int result, data_len; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_ReadAppPreference,"creator='%4.4s' prefID=%d backup=%d maxsize=%d", - (const char *)creator,prefID,backup,maxsize); + TraceX(dlp_ReadAppPreference, "creator='%4.4s' prefID=%d backup=%d maxsize=%d", + (const char *)creator, prefID, backup, maxsize); pi_reset_errors(sd); if (pi_version(sd) < 0x0101) { /* Emulate on PalmOS 1.0 */ - int db; + int db; pi_buffer_t *buf; LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadAppPreference Emulating with: Creator: '%s', " - "Id: %d, Size: %d, Backup: %d\n", - printlong(creator), prefID, - buffer ? maxsize : 0, backup ? 0x80 : 0)); + "DLP ReadAppPreference Emulating with: Creator: '%s', " + "Id: %d, Size: %d, Backup: %d\n", + printlong(creator), prefID, buffer ? maxsize : 0, backup ? 0x80 : 0)); result = dlp_OpenDB(sd, 0, dlpOpenRead, "System Preferences", &db); if (result < 0) return result; buf = pi_buffer_new (1024); - + result = dlp_ReadResourceByType(sd, db, creator, prefID, buf,NULL); if (result < 0) { @@ -3328,7 +3214,7 @@ dlp_ReadAppPreference(int sd, unsigned long creator, int prefID, int backup, dlp_CloseDB(sd, db); return result; } - + req = dlp_request_new(dlpFuncReadAppPreference, 1, 10); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -3342,7 +3228,7 @@ dlp_ReadAppPreference(int sd, unsigned long creator, int prefID, int backup, result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { data_len = get_short(DLP_RESPONSE_DATA(res, 0, 4)); if (version) @@ -3352,18 +3238,16 @@ dlp_ReadAppPreference(int sd, unsigned long creator, int prefID, int backup, if (size && buffer) *size = data_len; /* Size returned */ if (buffer) - memcpy(buffer, DLP_RESPONSE_DATA(res, 0, 6), - (size_t)data_len); + memcpy(buffer, DLP_RESPONSE_DATA(res, 0, 6), (size_t)data_len); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadAppPref Version: %d, " - "Total size: %d, Read %d bytes:\n", - get_short(DLP_RESPONSE_DATA(res, 0, 0)), - get_short(DLP_RESPONSE_DATA(res, 0, 2)), - get_short(DLP_RESPONSE_DATA(res, 0, 4)))); - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 6), - (size_t)data_len)); + "DLP ReadAppPref Version: %d, " + "Total size: %d, Read %d bytes:\n", + get_short(DLP_RESPONSE_DATA(res, 0, 0)), + get_short(DLP_RESPONSE_DATA(res, 0, 2)), + get_short(DLP_RESPONSE_DATA(res, 0, 4)))); + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, + pi_dumpdata(DLP_RESPONSE_DATA(res, 0, 6), (size_t)data_len)); } else { data_len = result; } @@ -3375,35 +3259,30 @@ dlp_ReadAppPreference(int sd, unsigned long creator, int prefID, int backup, int dlp_WriteAppPreference(int sd, unsigned long creator, int prefID, int backup, - int version, const void *buffer, size_t size) + int version, const void *buffer, size_t size) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_WriteAppPreference,"creator='%4.4s' prefID=%d backup=%d version=%d size=%ld", - (const char *)&creator,prefID,backup,version,size); + TraceX(dlp_WriteAppPreference, "creator='%4.4s' prefID=%d backup=%d version=%d size=%ld", + (const char *)&creator, prefID, backup, version, size); pi_reset_errors(sd); if (pi_version(sd) < 0x0101) { /* Emulate on PalmOS 1.0 */ - int db, - err1, - err2; + int db, err1, err2; - if ((result = dlp_OpenDB(sd, 0, dlpOpenWrite, "System Preferences", - &db)) < 0) + if ((result = dlp_OpenDB(sd, 0, dlpOpenWrite, "System Preferences", &db)) < 0) return result; if (buffer && size) { unsigned char dlp_buf[DLP_BUF_SIZE]; memcpy(dlp_buf + 2, buffer, size); set_short(dlp_buf, version); - result = dlp_WriteResource(sd, db, creator, prefID, dlp_buf, - size); + result = dlp_WriteResource(sd, db, creator, prefID, dlp_buf, size); } else { - result = dlp_WriteResource(sd, db, creator, prefID, NULL, - 0); + result = dlp_WriteResource(sd, db, creator, prefID, NULL, 0); } err1 = pi_error(sd); err2 = pi_palmos_error(sd); @@ -3432,7 +3311,7 @@ dlp_WriteAppPreference(int sd, unsigned long creator, int prefID, int backup, if ((size + 12) > DLP_BUF_SIZE) { LOG((PI_DBG_DLP, PI_DBG_LVL_ERR, - "DLP WriteAppPreferenceV2: data too large (>64k)")); + "DLP WriteAppPreferenceV2: data too large (>64k)")); return PI_ERR_DLP_DATASIZE; } memcpy(DLP_REQUEST_DATA(req, 0, 12), buffer, size); @@ -3447,46 +3326,44 @@ dlp_WriteAppPreference(int sd, unsigned long creator, int prefID, int backup, int dlp_ReadNextModifiedRecInCategory(int sd, int dbhandle, int category, - pi_buffer_t *buffer, recordid_t *recID, - int *recindex, int *attr) + pi_buffer_t *buffer, recordid_t *recID, int *recindex, int *attr) { - int result, - data_len; + int result, data_len; struct dlpRequest *req; struct dlpResponse *res; - TraceX(dlp_ReadNextModifiedRecInCategory,"category=%d",category); + TraceX(dlp_ReadNextModifiedRecInCategory, "category=%d", category); pi_reset_errors(sd); if (pi_version(sd) < 0x0101) { /* Emulate for PalmOS 1.0 */ - int cat; + int cat; LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ReadNextModifiedRecInCategory" - " Emulating with: Handle: %d, Category: %d\n", - dbhandle, category)); + "DLP ReadNextModifiedRecInCategory" + " Emulating with: Handle: %d, Category: %d\n", + dbhandle, category)); do { /* Fetch next modified record (in any category) */ result = dlp_ReadNextModifiedRec(sd, dbhandle, buffer, - recID, recindex, attr, &cat); + recID, recindex, attr, &cat); /* If none found, reset modified pointer so that - another search on a different (or the same!) category - will start from the beginning */ + another search on a different (or the same!) category + will start from the beginning */ /* Working on same assumption as ReadNextRecInCat, - elide this: - if (r < 0) - dlp_ResetDBIndex(sd, fHandle); + elide this: + if (r < 0) + dlp_ResetDBIndex(sd, fHandle); */ /* Loop until we fail to get a record or a record - is found in the proper category */ + is found in the proper category */ } while (result >= 0 && cat != category); - + return result; } @@ -3513,12 +3390,10 @@ dlp_ReadNextModifiedRecInCategory(int sd, int dbhandle, int category, if (buffer) { pi_buffer_clear (buffer); - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), - (size_t)data_len); + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), (size_t)data_len); } - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - record_dump( + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, record_dump( get_long(DLP_RESPONSE_DATA(res, 0, 0)), /* recID */ get_short(DLP_RESPONSE_DATA(res, 0, 4)), /* index */ get_byte(DLP_RESPONSE_DATA(res, 0, 8)), /* flags */ @@ -3535,26 +3410,25 @@ dlp_ReadNextModifiedRecInCategory(int sd, int dbhandle, int category, int dlp_ReadNextModifiedRec(int sd, int dbhandle, pi_buffer_t *buffer, recordid_t * recID, - int *recindex, int *attr, int *category) + int *recindex, int *attr, int *category) { - int result, - data_len; + int result, data_len; struct dlpRequest *req; struct dlpResponse *res; Trace(dlp_ReadNextModifiedRec); pi_reset_errors(sd); - + req = dlp_request_new (dlpFuncReadNextModifiedRec, 1, 1); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); set_byte(DLP_REQUEST_DATA(req, 0, 0), dbhandle); - + result = dlp_exec (sd, req, &res); dlp_request_free(req); - + if (result >= 0) { data_len = res->argv[0]->len -10; if (recID) @@ -3568,12 +3442,10 @@ dlp_ReadNextModifiedRec(int sd, int dbhandle, pi_buffer_t *buffer, recordid_t * if (buffer) { pi_buffer_clear (buffer); - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), - (size_t)data_len); + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), (size_t)data_len); } - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - record_dump( + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, record_dump( get_long(DLP_RESPONSE_DATA(res, 0, 0)), /* recID */ get_short(DLP_RESPONSE_DATA(res, 0, 4)), /* index */ get_byte(DLP_RESPONSE_DATA(res, 0, 8)), /* flags */ @@ -3584,20 +3456,20 @@ dlp_ReadNextModifiedRec(int sd, int dbhandle, pi_buffer_t *buffer, recordid_t * } dlp_response_free(res); - + return data_len; } int dlp_ReadRecordById(int sd, int dbhandle, recordid_t recuid, pi_buffer_t *buffer, - int *recindex, int *attr, int *category) + int *recindex, int *attr, int *category) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; int maxBufferSize = pi_maxrecsize(sd) - RECORD_READ_SAFEGUARD_SIZE; - TraceX(dlp_ReadRecordById,"recuid=0x%08lx",recuid); + TraceX(dlp_ReadRecordById, "recuid=0x%08lx", recuid); pi_reset_errors(sd); req = dlp_request_new(dlpFuncReadRecord, 1, 10); @@ -3606,14 +3478,14 @@ dlp_ReadRecordById(int sd, int dbhandle, recordid_t recuid, pi_buffer_t *buffer, set_byte(DLP_REQUEST_DATA(req, 0, 0), dbhandle); set_byte(DLP_REQUEST_DATA(req, 0, 1), 0); - set_long(DLP_REQUEST_DATA(req, 0, 2), recuid); + set_long(DLP_REQUEST_DATA(req, 0, 2), recuid); set_short(DLP_REQUEST_DATA(req, 0, 6), 0); /* Offset into record */ set_short(DLP_REQUEST_DATA(req, 0, 8), buffer ? maxBufferSize : 0); /* length to return */ result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { result = res->argv[0]->len - 10; if (recindex) @@ -3624,8 +3496,7 @@ dlp_ReadRecordById(int sd, int dbhandle, recordid_t recuid, pi_buffer_t *buffer, *category = get_byte(DLP_RESPONSE_DATA(res, 0, 9)); if (buffer) { pi_buffer_clear (buffer); - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), - (size_t)result); + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), (size_t)result); /* Some devices such as the Tungsten TX, Treo 650 and Treo 700p lock up if you try to read the entire record if the ** record is almost at the maximum record size. The following mitigates this and allows the record @@ -3637,7 +3508,7 @@ dlp_ReadRecordById(int sd, int dbhandle, recordid_t recuid, pi_buffer_t *buffer, if (req != NULL) { set_byte(DLP_REQUEST_DATA(req, 0, 0), dbhandle); set_byte(DLP_REQUEST_DATA(req, 0, 1), 0); - set_long(DLP_REQUEST_DATA(req, 0, 2), recuid); + set_long(DLP_REQUEST_DATA(req, 0, 2), recuid); set_short(DLP_REQUEST_DATA(req, 0, 6), maxBufferSize); /* Offset into record */ set_short(DLP_REQUEST_DATA(req, 0, 8), buffer ? RECORD_READ_SAFEGUARD_SIZE : 0); /* length to return */ @@ -3646,39 +3517,36 @@ dlp_ReadRecordById(int sd, int dbhandle, recordid_t recuid, pi_buffer_t *buffer, if (result > 0) { result = res->argv[0]->len - 10; - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), - (size_t)result); + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, 10), (size_t)result); result += maxBufferSize; } } } } - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - record_dump( + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, record_dump( get_long(DLP_RESPONSE_DATA(res, 0, 0)), /* recID */ get_short(DLP_RESPONSE_DATA(res, 0, 4)), /* index */ get_byte(DLP_RESPONSE_DATA(res, 0, 8)), /* flags */ get_byte(DLP_RESPONSE_DATA(res, 0, 9)), /* catID */ DLP_RESPONSE_DATA(res, 0, 10), result)); } - + dlp_response_free(res); - + return result; } int dlp_ReadRecordByIndex(int sd, int dbhandle, int recindex, pi_buffer_t *buffer, - recordid_t * recuid, int *attr, int *category) + recordid_t * recuid, int *attr, int *category) { - int result, - large = 0; + int result, large = 0; struct dlpRequest *req; struct dlpResponse *res; int maxBufferSize = pi_maxrecsize(sd) - RECORD_READ_SAFEGUARD_SIZE; - TraceX(dlp_ReadRecordByIndex,"recindex=%d",recindex); + TraceX(dlp_ReadRecordByIndex, "recindex=%d", recindex); pi_reset_errors(sd); /* TapWave (DLP 1.4) implements a 'large' version of dlpFuncReadRecord, @@ -3708,7 +3576,7 @@ dlp_ReadRecordByIndex(int sd, int dbhandle, int recindex, pi_buffer_t *buffer, } result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { result = res->argv[0]->len - (large ? 14 : 10); if (recuid) @@ -3719,8 +3587,7 @@ dlp_ReadRecordByIndex(int sd, int dbhandle, int recindex, pi_buffer_t *buffer, *category = get_byte(DLP_RESPONSE_DATA(res, 0, large ? 13 : 9)); if (buffer) { pi_buffer_clear (buffer); - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, large ? 14 : 10), - (size_t)result); + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, large ? 14 : 10), (size_t)result); /* Some devices such as the Tungsten TX, Treo 650 and Treo 700p lock up if you try to read the entire record if the ** record is almost at the maximum record size. The following mitigates this and allows the record @@ -3741,17 +3608,15 @@ dlp_ReadRecordByIndex(int sd, int dbhandle, int recindex, pi_buffer_t *buffer, if (result > 0) { result = res->argv[0]->len - (large ? 14 : 10); - pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, large ? 14 : 10), - (size_t)result); - + pi_buffer_append (buffer, DLP_RESPONSE_DATA(res, 0, large ? 14 : 10), (size_t)result); + result += maxBufferSize; } } } } - CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, - record_dump( + CHECK(PI_DBG_DLP, PI_DBG_LVL_DEBUG, record_dump( get_long(DLP_RESPONSE_DATA(res, 0, 0)), /* recUID */ get_short(DLP_RESPONSE_DATA(res, 0, 4)), /* index */ get_byte(DLP_RESPONSE_DATA(res, 0, large ? 12 : 8)), /* flags */ @@ -3760,17 +3625,17 @@ dlp_ReadRecordByIndex(int sd, int dbhandle, int recindex, pi_buffer_t *buffer, } dlp_response_free(res); - + return result; } int dlp_ExpSlotEnumerate(int sd, int *numSlots, int *slotRefs) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); Trace(dlp_ExpSlotEnumerate); pi_reset_errors(sd); @@ -3782,29 +3647,24 @@ dlp_ExpSlotEnumerate(int sd, int *numSlots, int *slotRefs) result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { int slots, i; slots = get_short(DLP_RESPONSE_DATA (res, 0, 0)); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ExpSlotEnumerate %d\n", slots)); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP ExpSlotEnumerate %d\n", slots)); if (slots) { for (i = 0; i < slots && i < *numSlots; i++) { - slotRefs[i] = - get_short(DLP_RESPONSE_DATA (res, 0, - 2 + (2 * i))); - - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " %d Slot-Refnum %d\n", i, slotRefs[i])); + slotRefs[i] = get_short(DLP_RESPONSE_DATA (res, 0, 2 + (2 * i))); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, " %d Slot-Refnum %d\n", i, slotRefs[i])); } } *numSlots = slots; } - + dlp_response_free(res); return result; @@ -3813,12 +3673,12 @@ dlp_ExpSlotEnumerate(int sd, int *numSlots, int *slotRefs) int dlp_ExpCardPresent(int sd, int slotRef) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; RequireDLPVersion(sd,1,2); - TraceX(dlp_ExpCardPresent,"slotRef=%d",slotRef); + TraceX(dlp_ExpCardPresent, "slotRef=%d", slotRef); pi_reset_errors(sd); req = dlp_request_new (dlpFuncExpCardPresent, 1, 2); @@ -3836,15 +3696,14 @@ dlp_ExpCardPresent(int sd, int slotRef) } int -dlp_ExpCardInfo(int sd, int slotRef, unsigned long *flags, int *numStrings, - char **strings) +dlp_ExpCardInfo(int sd, int slotRef, unsigned long *flags, int *numStrings, char **strings) { int result; struct dlpRequest* req; struct dlpResponse* res; RequireDLPVersion(sd,1,2); - TraceX(dlp_ExpCardInfo,"slotRef=%d",slotRef); + TraceX(dlp_ExpCardInfo, "slotRef=%d", slotRef); pi_reset_errors(sd); req = dlp_request_new (dlpFuncExpCardInfo, 1, 2); @@ -3856,7 +3715,7 @@ dlp_ExpCardInfo(int sd, int slotRef, unsigned long *flags, int *numStrings, result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { *flags = get_long(DLP_RESPONSE_DATA (res, 0, 0)); *numStrings = get_byte(DLP_RESPONSE_DATA (res, 0, 4)); @@ -3876,8 +3735,8 @@ dlp_ExpCardInfo(int sd, int slotRef, unsigned long *flags, int *numStrings, } LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP ExpCardInfo flags: 0x%08lx numStrings: %d\n", - *flags, *numStrings)); + "DLP ExpCardInfo flags: 0x%08lx numStrings: %d\n", + *flags, *numStrings)); } dlp_response_free(res); @@ -3886,70 +3745,64 @@ dlp_ExpCardInfo(int sd, int slotRef, unsigned long *flags, int *numStrings, } int -dlp_VFSGetDefaultDir(int sd, int volRefNum, const char *type, char *dir, - int *len) +dlp_VFSGetDefaultDir(int sd, int volRefNum, const char *type, char *dir, int *len) { int result, buflen; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSGetDefaultDir,"volRefNum=%d",volRefNum); + TraceX(dlp_VFSGetDefaultDir, "volRefNum=%d", volRefNum); pi_reset_errors(sd); - - req = dlp_request_new(dlpFuncVFSGetDefaultDir, - 1, 2 + (strlen(type) + 1)); + + req = dlp_request_new(dlpFuncVFSGetDefaultDir, 1, 2 + (strlen(type) + 1)); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); set_short(DLP_REQUEST_DATA(req, 0, 0), volRefNum); strcpy(DLP_REQUEST_DATA(req, 0, 2), type); - + result = dlp_exec(sd, req, &res); dlp_request_free(req); - + if (result > 0) { buflen = get_short(DLP_RESPONSE_DATA (res, 0, 0)); - + if (*len < buflen + 1) result = pi_set_error(sd, PI_ERR_DLP_BUFSIZE); else { if (buflen) - strncpy(dir, DLP_RESPONSE_DATA (res, 0, 2), - (size_t)buflen); + strncpy(dir, DLP_RESPONSE_DATA (res, 0, 2), (size_t)buflen); else dir[0] = '\0'; - + *len = buflen; - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "Default dir is %s\n", dir)); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "Default dir is %s\n", dir)); } } - + dlp_response_free(res); - + return result; } int dlp_VFSImportDatabaseFromFile(int sd, int volRefNum, const char *path, - int *cardno, unsigned long *localid) + int *cardno, unsigned long *localid) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSImportDatabaseFromFile,"volRefNum=%d path='%s'",volRefNum,path); + TraceX(dlp_VFSImportDatabaseFromFile, "volRefNum=%d path='%s'", volRefNum,path); pi_reset_errors(sd); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "Import file <%s>%d\n", path)); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "Import file <%s>%d\n", path)); - req = dlp_request_new(dlpFuncVFSImportDatabaseFromFile, - 1, 2 + (strlen(path) + 1)); + req = dlp_request_new(dlpFuncVFSImportDatabaseFromFile, 1, 2 + (strlen(path) + 1)); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -3964,34 +3817,33 @@ dlp_VFSImportDatabaseFromFile(int sd, int volRefNum, const char *path, if (cardno) *cardno = get_short(DLP_RESPONSE_DATA (res, 0, 0)); if (localid) - *localid = get_short(DLP_RESPONSE_DATA (res, 0, 2)); + *localid = get_short(DLP_RESPONSE_DATA (res, 0, 2)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "Database imported as: cardNo:%d dbID:%d\n", - get_short(DLP_RESPONSE_DATA (res, 0, 0)), - get_short(DLP_RESPONSE_DATA (res, 0, 2)))); + "Database imported as: cardNo:%d dbID:%d\n", + get_short(DLP_RESPONSE_DATA (res, 0, 0)), + get_short(DLP_RESPONSE_DATA (res, 0, 2)))); } - + dlp_response_free(res); return result; } int -dlp_VFSExportDatabaseToFile(int sd, int volRefNum, const char *path, - int cardno, unsigned int localid) +dlp_VFSExportDatabaseToFile(int sd, int volRefNum, const char *path, + int cardno, unsigned int localid) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; RequireDLPVersion(sd,1,2); TraceX(dlp_VFSExportDatabaseToFile,"cardno=%d localid=0x%08lx volRefNum=%d path='%s'", - cardno,(long)localid,volRefNum,path); + cardno, (long)localid, volRefNum, path); pi_reset_errors(sd); - req = dlp_request_new(dlpFuncVFSExportDatabaseToFile, - 1, 8 + (strlen(path) + 1)); + req = dlp_request_new(dlpFuncVFSExportDatabaseToFile, 1, 8 + (strlen(path) + 1)); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -4011,12 +3863,12 @@ dlp_VFSExportDatabaseToFile(int sd, int volRefNum, const char *path, int dlp_VFSFileCreate(int sd, int volRefNum, const char *name) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileCreate,"volRefNum=%d name='%s'",volRefNum,name); + TraceX(dlp_VFSFileCreate, "volRefNum=%d name='%s'", volRefNum,name); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileCreate, 1, 2 + (strlen(name) + 1)); @@ -4035,16 +3887,14 @@ dlp_VFSFileCreate(int sd, int volRefNum, const char *name) } int -dlp_VFSFileOpen(int sd, int volRefNum, const char *path, int openMode, - FileRef *fileRef) +dlp_VFSFileOpen(int sd, int volRefNum, const char *path, int openMode, FileRef *fileRef) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileOpen,"volRefNum=%d mode=0x%04x path='%s'", - volRefNum,openMode,path); + TraceX(dlp_VFSFileOpen,"volRefNum=%d mode=0x%04x path='%s'", volRefNum, openMode, path); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileOpen, 1, 4 + (strlen (path) + 1)); @@ -4058,14 +3908,12 @@ dlp_VFSFileOpen(int sd, int volRefNum, const char *path, int openMode, result = dlp_exec (sd, req, &res); dlp_request_free (req); - + if (result > 0) { *fileRef = get_long(DLP_RESPONSE_DATA (res, 0, 0)); - - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "OpenFileRef: 0x%x\n", *fileRef)); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "OpenFileRef: 0x%x\n", *fileRef)); } - + dlp_response_free(res); return result; @@ -4074,12 +3922,12 @@ dlp_VFSFileOpen(int sd, int volRefNum, const char *path, int openMode, int dlp_VFSFileClose(int sd, FileRef fileRef) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileClose,"fileRef=%ld",fileRef); + TraceX(dlp_VFSFileClose, "fileRef=%ld", fileRef); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileClose, 1, 4); @@ -4092,9 +3940,8 @@ dlp_VFSFileClose(int sd, FileRef fileRef) dlp_request_free (req); dlp_response_free (res); - - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "Closed FileRef: %x\n", fileRef)); + + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "Closed FileRef: %x\n", fileRef)); return result; } @@ -4102,17 +3949,16 @@ dlp_VFSFileClose(int sd, FileRef fileRef) int dlp_VFSFileWrite(int sd, FileRef fileRef, const void *data, size_t len) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res = NULL; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileWrite,"fileRef=%ld len=%ld",(long)fileRef,(long)len); + TraceX(dlp_VFSFileWrite, "fileRef=%ld len=%ld", (long)fileRef, (long)len); pi_reset_errors(sd); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "Write to FileRef: %x bytes %d\n", fileRef, len)); - + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "Write to FileRef: %x bytes %d\n", fileRef, len)); + req = dlp_request_new (dlpFuncVFSFileWrite, 1, 8); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -4128,8 +3974,7 @@ dlp_VFSFileWrite(int sd, FileRef fileRef, const void *data, size_t len) int bytes = pi_write (sd, data, len); result = bytes; if (result < (int)len) { - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "send failed %d\n", result)); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "send failed %d\n", result)); } else { dlp_response_free (res); res = NULL; @@ -4139,10 +3984,10 @@ dlp_VFSFileWrite(int sd, FileRef fileRef, const void *data, size_t len) if (result > 0) { pi_set_palmos_error(sd, get_short(DLP_RESPONSE_DATA (res, 0, 2))); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "send success (%d) res 0x%04x!\n", len, pi_palmos_error(sd))); + "send success (%d) res 0x%04x!\n", len, pi_palmos_error(sd))); result = bytes; } - } + } } dlp_response_free (res); @@ -4153,7 +3998,7 @@ dlp_VFSFileWrite(int sd, FileRef fileRef, const void *data, size_t len) int dlp_VFSFileRead(int sd, FileRef fileRef, pi_buffer_t *data, size_t len) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; size_t bytes = 0; @@ -4161,7 +4006,7 @@ dlp_VFSFileRead(int sd, FileRef fileRef, pi_buffer_t *data, size_t len) size_t opt_size = sizeof(int); RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileRead,"fileRef=%ld len=%ld",(long)fileRef,(long)len); + TraceX(dlp_VFSFileRead, "fileRef=%ld len=%ld", (long)fileRef, (long)len); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileRead, 1, 8); @@ -4176,7 +4021,7 @@ dlp_VFSFileRead(int sd, FileRef fileRef, pi_buffer_t *data, size_t len) */ pi_setsockopt(sd, PI_LEVEL_PADP, PI_PADP_FREEZE_TXID, &freeze_txid, &opt_size); - result = dlp_exec (sd, req, &res); + result = dlp_exec (sd, req, &res); dlp_request_free (req); @@ -4193,8 +4038,8 @@ dlp_VFSFileRead(int sd, FileRef fileRef, pi_buffer_t *data, size_t len) } while (result > 0 && len > 0); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "dlp_VFSFileRead: read %u bytes (last pi_read was %d)\n", - (unsigned)bytes, result)); + "dlp_VFSFileRead: read %u bytes (last pi_read was %d)\n", + (unsigned)bytes, result)); if (result >= 0) result = bytes; @@ -4211,21 +4056,21 @@ dlp_VFSFileRead(int sd, FileRef fileRef, pi_buffer_t *data, size_t len) int dlp_VFSFileDelete(int sd, int volRefNum, const char *path) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileDelete,"volRefNum=%d path='%s'",volRefNum,path); + TraceX(dlp_VFSFileDelete, "volRefNum=%d path='%s'", volRefNum,path); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileDelete, 1, 2 + (strlen (path) + 1)); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - + set_short (DLP_REQUEST_DATA (req, 0, 0), volRefNum); strcpy (DLP_REQUEST_DATA (req, 0, 2), path); - + result = dlp_exec (sd, req, &res); dlp_request_free (req); @@ -4235,20 +4080,18 @@ dlp_VFSFileDelete(int sd, int volRefNum, const char *path) } int -dlp_VFSFileRename(int sd, int volRefNum, const char *path, - const char *newname) +dlp_VFSFileRename(int sd, int volRefNum, const char *path, const char *newname) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileRename,"volRefNum=%d file '%s' renamed '%s'", - volRefNum,path,rename); + TraceX(dlp_VFSFileRename, "volRefNum=%d file '%s' renamed '%s'", volRefNum, path, rename); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileRename, - 1, 4 + (strlen (path) + 1) + (strlen (newname) + 1)); + 1, 4 + (strlen (path) + 1) + (strlen (newname) + 1)); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); @@ -4256,7 +4099,7 @@ dlp_VFSFileRename(int sd, int volRefNum, const char *path, set_short (DLP_REQUEST_DATA (req, 0, 2), 2); strcpy (DLP_REQUEST_DATA (req, 0, 4), path); strcpy (DLP_REQUEST_DATA (req, 0, 4 + (strlen(path) + 1)), newname); - + result = dlp_exec (sd, req, &res); dlp_request_free (req); @@ -4268,22 +4111,22 @@ dlp_VFSFileRename(int sd, int volRefNum, const char *path, int dlp_VFSFileEOF(int sd, FileRef fileRef) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileEOF,"fileRef=%ld",fileRef); + TraceX(dlp_VFSFileEOF, "fileRef=%ld", fileRef); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileEOF, 1, 4); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - + set_long (DLP_REQUEST_DATA (req, 0, 0), fileRef); - + result = dlp_exec (sd, req, &res); - + dlp_request_free (req); dlp_response_free (res); @@ -4293,12 +4136,12 @@ dlp_VFSFileEOF(int sd, FileRef fileRef) int dlp_VFSFileTell(int sd, FileRef fileRef,int *position) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileTell,"fileRef=%ld",fileRef); + TraceX(dlp_VFSFileTell, "fileRef=%ld", fileRef); pi_reset_errors(sd); req = dlp_request_new(dlpFuncVFSFileTell, 1, 4); @@ -4308,13 +4151,13 @@ dlp_VFSFileTell(int sd, FileRef fileRef,int *position) set_long (DLP_REQUEST_DATA (req, 0, 0), fileRef); result = dlp_exec (sd, req, &res); - + dlp_request_free (req); if (result > 0) { *position = get_long (DLP_RESPONSE_DATA (res, 0, 0)); } - + dlp_response_free (res); return result; @@ -4324,28 +4167,28 @@ int dlp_VFSFileGetAttributes (int sd, FileRef fileRef, unsigned long *attributes) { int result; - struct dlpRequest *req; + struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileGetAttributes,"fileRef=%ld",fileRef); + TraceX(dlp_VFSFileGetAttributes, "fileRef=%ld", fileRef); pi_reset_errors(sd); - + req = dlp_request_new (dlpFuncVFSFileGetAttributes, 1, 4); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); set_long (DLP_REQUEST_DATA (req, 0, 0), fileRef); - + result = dlp_exec (sd, req, &res); - + dlp_request_free (req); if (result > 0) { *attributes = get_long (DLP_RESPONSE_DATA (res, 0, 0)); } - dlp_response_free(res); + dlp_response_free(res); return result; } @@ -4354,12 +4197,11 @@ int dlp_VFSFileSetAttributes(int sd, FileRef fileRef, unsigned long attributes) { int result; - struct dlpRequest *req; + struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileSetAttributes,"fileRef=%ld attributes=0x%08lx", - fileRef,attributes); + TraceX(dlp_VFSFileSetAttributes, "fileRef=%ld attributes=0x%08lx", fileRef, attributes); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileSetAttributes, 1, 8); @@ -4368,7 +4210,7 @@ dlp_VFSFileSetAttributes(int sd, FileRef fileRef, unsigned long attributes) set_long (DLP_REQUEST_DATA (req, 0, 0), fileRef); set_long (DLP_REQUEST_DATA (req, 0, 4), attributes); - + result = dlp_exec (sd, req, &res); dlp_request_free (req); @@ -4381,11 +4223,11 @@ int dlp_VFSFileGetDate(int sd, FileRef fileRef, int which, time_t *date) { int result; - struct dlpRequest *req; + struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileGetDate,"fileRef=%ld which=%d",fileRef,which); + TraceX(dlp_VFSFileGetDate, "fileRef=%ld which=%d", fileRef, which); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileGetDate, 1, 6); @@ -4398,17 +4240,16 @@ dlp_VFSFileGetDate(int sd, FileRef fileRef, int which, time_t *date) result = dlp_exec (sd, req, &res); dlp_request_free (req); - + if (result > 0) { *date = get_long (DLP_RESPONSE_DATA (res, 0, 0)) - 2082852000; - + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "Requested date(%d): %d / %x calc %d / %x\n",which, - get_long(DLP_RESPONSE_DATA (res, 0, 0)), - get_long(DLP_RESPONSE_DATA (res, 0, 0)), - *date,*date)); + "Requested date(%d): %d / %x calc %d / %x\n", which, + get_long(DLP_RESPONSE_DATA (res, 0, 0)), + get_long(DLP_RESPONSE_DATA (res, 0, 0)), *date, *date)); } - + dlp_response_free (res); return result; @@ -4420,10 +4261,10 @@ dlp_VFSFileSetDate(int sd, FileRef fileRef, int which, time_t date) int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileSetDate,"fileRef=%ld which=%d date=0x%08lx", - (long)fileRef,which,(long)date); + TraceX(dlp_VFSFileSetDate, "fileRef=%ld which=%d date=0x%08lx", + (long)fileRef, which, (long)date); pi_reset_errors(sd); req = dlp_request_new(dlpFuncVFSFileSetDate, 1, 10); @@ -4437,7 +4278,7 @@ dlp_VFSFileSetDate(int sd, FileRef fileRef, int which, time_t date) result = dlp_exec (sd, req, &res); dlp_request_free (req); - dlp_response_free (res); + dlp_response_free (res); return result; } @@ -4445,12 +4286,12 @@ dlp_VFSFileSetDate(int sd, FileRef fileRef, int which, time_t date) int dlp_VFSDirCreate(int sd, int volRefNum, const char *path) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSDirCreate,"volRefNum=%d path='%s'",volRefNum,path); + TraceX(dlp_VFSDirCreate, "volRefNum=%d path='%s'", volRefNum, path); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSDirCreate, 1, 2 + (strlen(path) + 1)); @@ -4459,7 +4300,7 @@ dlp_VFSDirCreate(int sd, int volRefNum, const char *path) set_short (DLP_REQUEST_DATA (req, 0, 0), volRefNum); strcpy (DLP_REQUEST_DATA (req, 0, 2), path); - + result = dlp_exec (sd, req, &res); dlp_request_free (req); @@ -4469,20 +4310,16 @@ dlp_VFSDirCreate(int sd, int volRefNum, const char *path) } int -dlp_VFSDirEntryEnumerate(int sd, FileRef dirRefNum, - unsigned long *dirIterator, int *maxDirItems, struct VFSDirInfo *data) +dlp_VFSDirEntryEnumerate(int sd, FileRef dirRefNum, + unsigned long *dirIterator, int *maxDirItems, struct VFSDirInfo *data) { - unsigned int result, - entries, - from, - at, - slen, - count; + int result; + unsigned int entries, from, at, slen, count; struct dlpRequest *req; struct dlpResponse *res; RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSDirEntryEnumerate,"dirRef=%ld",dirRefNum); + TraceX(dlp_VFSDirEntryEnumerate, "dirRef=%ld", dirRefNum); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSDirEntryEnumerate, 1, 12); @@ -4494,28 +4331,22 @@ dlp_VFSDirEntryEnumerate(int sd, FileRef dirRefNum, set_long (DLP_REQUEST_DATA (req, 0, 8), 8 + *maxDirItems * (4 + vfsMAXFILENAME)); result = dlp_exec (sd, req, &res); - + dlp_request_free (req); - + if (result > 0) { - if (result) { - *dirIterator = get_long (DLP_RESPONSE_DATA (res, 0, 0)); - entries = get_long (DLP_RESPONSE_DATA (res, 0, 4)); - } else { - *dirIterator = vfsIteratorStop; - entries = 0; - } + *dirIterator = get_long (DLP_RESPONSE_DATA (res, 0, 0)); + entries = get_long (DLP_RESPONSE_DATA (res, 0, 4)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "%d results returnd (ilterator: %d)\n", entries, - *dirIterator)); - + "%d results returnd (ilterator: %d)\n", entries, *dirIterator)); + from = 8; count = 0; - + for (at = 0; at < entries; at++) { if (*maxDirItems > at) { - data[at].attr = + data[at].attr = get_long(DLP_RESPONSE_DATA (res, 0, from)); /* fix for Sony sims (and probably devices too): they return @@ -4527,38 +4358,39 @@ dlp_VFSDirEntryEnumerate(int sd, FileRef dirRefNum, data[at].attr >>= 16; strncpy (data[at].name, - DLP_RESPONSE_DATA(res, 0, from + 4), - vfsMAXFILENAME); + DLP_RESPONSE_DATA(res, 0, from + 4), vfsMAXFILENAME); data[at].name[vfsMAXFILENAME-1] = 0; count++; } - + /* Zero terminated string. Strings that have an even length will be null terminated and have a pad byte. */ slen = strlen (DLP_RESPONSE_DATA(res, 0, from + 4)) + 1; if (slen & 1) slen++; /* make even stringlen + NULL */ - + /* 6 = 4 (attr) + 1 (NULL) -+ 1 (PADDING) */ from += slen + 4; } *maxDirItems = count; + } else { + *dirIterator = (unsigned long)vfsIteratorStop; + entries = 0; } - + dlp_response_free (res); - return result; + return result; } int -dlp_VFSVolumeFormat(int sd, unsigned char flags, - int fsLibRef, struct VFSSlotMountParam *param) +dlp_VFSVolumeFormat(int sd, unsigned char flags, int fsLibRef, struct VFSSlotMountParam *param) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); Trace(dlp_VFSVolumeFormat); pi_reset_errors(sd); @@ -4569,17 +4401,16 @@ dlp_VFSVolumeFormat(int sd, unsigned char flags, /* FIXME check sizes, list the mount params properly */ set_short(DLP_REQUEST_DATA(req, 0, 0), fsLibRef); - set_short(DLP_REQUEST_DATA(req, 0, 2), - sizeof(struct VFSSlotMountParam)); + set_short(DLP_REQUEST_DATA(req, 0, 2), sizeof(struct VFSSlotMountParam)); set_byte(DLP_REQUEST_DATA(req, 0, 4), flags); set_byte(DLP_REQUEST_DATA(req, 0, 4), 0); /* unused */ set_short(DLP_REQUEST_DATA(req, 0, 6), param->vfsMountParam.volRefNum); - set_short(DLP_REQUEST_DATA(req, 0, 8), param->vfsMountParam.reserved); + set_short(DLP_REQUEST_DATA(req, 0, 8), param->vfsMountParam.reserved); set_long(DLP_REQUEST_DATA(req, 0, 10), param->vfsMountParam.mountClass); set_short(DLP_REQUEST_DATA(req, 0, 14), param->slotLibRefNum); - set_short(DLP_REQUEST_DATA(req, 0, 16), param->slotRefNum); - + set_short(DLP_REQUEST_DATA(req, 0, 16), param->slotRefNum); + result = dlp_exec(sd, req, &res); dlp_request_free(req); @@ -4594,7 +4425,7 @@ dlp_VFSVolumeEnumerate(int sd, int *numVols, int *volRefs) int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); Trace(dlp_VFSVolumeEnumerate); pi_reset_errors(sd); @@ -4603,26 +4434,21 @@ dlp_VFSVolumeEnumerate(int sd, int *numVols, int *volRefs) if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - result = dlp_exec (sd, req, &res); - - dlp_request_free (req); + result = dlp_exec(sd, req, &res); + + dlp_request_free(req); if (result > 0) { int vols, i; - vols = get_short (DLP_RESPONSE_DATA (res, 0, 0)); + vols = get_short(DLP_RESPONSE_DATA (res, 0, 0)); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP VFSVolumeEnumerate %d\n", vols)); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP VFSVolumeEnumerate %d\n", vols)); if (vols) { for (i = 0; i < vols && i < *numVols; i++) { - volRefs[i] = - get_short (DLP_RESPONSE_DATA (res, - 0, 2 + (2 * i))); - - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - " %d Volume-Refnum %d\n", i, volRefs[i])); + volRefs[i] = get_short(DLP_RESPONSE_DATA (res, 0, 2 + (2 * i))); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, " %d Volume-Refnum %d\n", i, volRefs[i])); } } *numVols = vols; @@ -4630,7 +4456,7 @@ dlp_VFSVolumeEnumerate(int sd, int *numVols, int *volRefs) else *numVols = 0; - dlp_response_free (res); + dlp_response_free(res); return result; } @@ -4638,12 +4464,12 @@ dlp_VFSVolumeEnumerate(int sd, int *numVols, int *volRefs) int dlp_VFSVolumeInfo(int sd, int volRefNum, struct VFSInfo *volInfo) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSVolumeInfo,"volRefNum=%d",volRefNum); + TraceX(dlp_VFSVolumeInfo, "volRefNum=%d", volRefNum); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSVolumeInfo, 1, 2); @@ -4652,68 +4478,66 @@ dlp_VFSVolumeInfo(int sd, int volRefNum, struct VFSInfo *volInfo) set_short (DLP_REQUEST_DATA(req, 0, 0), volRefNum); - result = dlp_exec (sd, req, &res); + result = dlp_exec(sd, req, &res); + + dlp_request_free(req); - dlp_request_free (req); - if (result > 0) { volInfo->attributes = get_long (DLP_RESPONSE_DATA (res, 0, 0)); - volInfo->fsType = get_long (DLP_RESPONSE_DATA (res, 0, 4)); + volInfo->fsType = get_long (DLP_RESPONSE_DATA (res, 0, 4)); volInfo->fsCreator = get_long (DLP_RESPONSE_DATA (res, 0, 8)); volInfo->mountClass = get_long (DLP_RESPONSE_DATA (res, 0, 12)); volInfo->slotLibRefNum = get_short (DLP_RESPONSE_DATA (res, 0, 16)); volInfo->slotRefNum = get_short (DLP_RESPONSE_DATA (res, 0, 18)); volInfo->mediaType = get_long (DLP_RESPONSE_DATA (res, 0, 20)); - volInfo->reserved = get_long (DLP_RESPONSE_DATA (res, 0, 24)); + volInfo->reserved = get_long (DLP_RESPONSE_DATA (res, 0, 24)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "VFSVolumeInfo: fstype '%s' ", printlong(volInfo->fsType))); - + "VFSVolumeInfo: fstype '%s' ", printlong(volInfo->fsType))); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "fscreator: '%s'\nSlotlibref %d Slotref %d\n", - printlong(volInfo->fsCreator), - volInfo->slotLibRefNum, - volInfo->slotRefNum)); - + "fscreator: '%s'\nSlotlibref %d Slotref %d\n", + printlong(volInfo->fsCreator), + volInfo->slotLibRefNum, + volInfo->slotRefNum)); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "Media: '%s'\n", printlong(volInfo->mediaType))); + "Media: '%s'\n", printlong(volInfo->mediaType))); } - + dlp_response_free(res); - + return result; } int dlp_VFSVolumeGetLabel(int sd, int volRefNum, int *len, char *name) { - int result; - struct dlpRequest *req; + int result; + struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSVolumeGetLabel,"volRefNum=%d",volRefNum); + TraceX(dlp_VFSVolumeGetLabel, "volRefNum=%d", volRefNum); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSVolumeGetLabel, 1, 2); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - set_short (DLP_REQUEST_DATA (req, 0, 0), volRefNum); - - result = dlp_exec (sd, req, &res); - - dlp_request_free (req); + set_short(DLP_REQUEST_DATA (req, 0, 0), volRefNum); + + result = dlp_exec(sd, req, &res); + + dlp_request_free(req); if (result > 0) { - strncpy(name, DLP_RESPONSE_DATA(res, 0, 0), - (size_t)(*len - 1)); + strncpy(name, DLP_RESPONSE_DATA(res, 0, 0), (size_t)(*len - 1)); *len = strlen(name); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP VFSVolumeGetLabel %s\n", name)); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP VFSVolumeGetLabel %s\n", name)); } - + dlp_response_free(res); return result; @@ -4722,62 +4546,60 @@ dlp_VFSVolumeGetLabel(int sd, int volRefNum, int *len, char *name) int dlp_VFSVolumeSetLabel(int sd, int volRefNum, const char *name) { - int result; - struct dlpRequest *req; + int result; + struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSVolumeSetLabel,"volRefNum=%d name='%s'",volRefNum,name); + TraceX(dlp_VFSVolumeSetLabel, "volRefNum=%d name='%s'", volRefNum,name); pi_reset_errors(sd); - req = dlp_request_new (dlpFuncVFSVolumeSetLabel, 1, - 2 + (strlen(name) + 1)); + req = dlp_request_new (dlpFuncVFSVolumeSetLabel, 1, 2 + (strlen(name) + 1)); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - set_short (DLP_REQUEST_DATA (req, 0, 0), volRefNum); - strcpy (DLP_REQUEST_DATA (req, 0, 2), name); + set_short(DLP_REQUEST_DATA (req, 0, 0), volRefNum); + strcpy(DLP_REQUEST_DATA (req, 0, 2), name); - result = dlp_exec (sd, req, &res); + result = dlp_exec(sd, req, &res); - dlp_response_free (res); - dlp_request_free (req); + dlp_response_free(res); + dlp_request_free(req); return result; } int -dlp_VFSVolumeSize(int sd, int volRefNum, long *volSizeUsed, - long *volSizeTotal) +dlp_VFSVolumeSize(int sd, int volRefNum, long *volSizeUsed, long *volSizeTotal) { - int result; - struct dlpRequest *req; + int result; + struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSVolumeSize,"volRefNum=%d",volRefNum); + TraceX(dlp_VFSVolumeSize, "volRefNum=%d", volRefNum); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSVolumeSize, 1, 2); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - set_short (DLP_REQUEST_DATA (req, 0, 0), volRefNum); + set_short(DLP_REQUEST_DATA (req, 0, 0), volRefNum); - result = dlp_exec (sd, req, &res); + result = dlp_exec(sd, req, &res); + + dlp_request_free(req); - dlp_request_free (req); - if (result > 0) { *volSizeUsed = get_long (DLP_RESPONSE_DATA (res, 0, 0)); *volSizeTotal = get_long (DLP_RESPONSE_DATA (res, 0, 4)); - + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP VFS Volume Size total: %d used: %d\n", - *volSizeTotal, *volSizeUsed)); + "DLP VFS Volume Size total: %d used: %d\n", + *volSizeTotal, *volSizeUsed)); } - dlp_response_free (res); + dlp_response_free(res); return result; } @@ -4785,27 +4607,26 @@ dlp_VFSVolumeSize(int sd, int volRefNum, long *volSizeUsed, int dlp_VFSFileSeek(int sd, FileRef fileRef, int origin, int offset) { - int result; - struct dlpRequest *req; + int result; + struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileSeek,"fileRef=%ld origin=%d offset=%d", - fileRef,origin,offset); + TraceX(dlp_VFSFileSeek, "fileRef=%ld origin=%d offset=%d", fileRef, origin, offset); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileSeek, 1, 10); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - set_long (DLP_REQUEST_DATA (req, 0, 0), fileRef); - set_short (DLP_REQUEST_DATA (req, 0, 4), origin); - set_long (DLP_REQUEST_DATA (req, 0, 6), offset); + set_long(DLP_REQUEST_DATA (req, 0, 0), fileRef); + set_short(DLP_REQUEST_DATA (req, 0, 4), origin); + set_long(DLP_REQUEST_DATA (req, 0, 6), offset); - result = dlp_exec (sd, req, &res); + result = dlp_exec(sd, req, &res); - dlp_request_free (req); - dlp_response_free (res); + dlp_request_free(req); + dlp_response_free(res); return result; } @@ -4813,12 +4634,12 @@ dlp_VFSFileSeek(int sd, FileRef fileRef, int origin, int offset) int dlp_VFSFileResize(int sd, FileRef fileRef, int newSize) { - int result; - struct dlpRequest *req; + int result; + struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileResize,"fileRef=%ld newSize=%d",fileRef,newSize); + TraceX(dlp_VFSFileResize, "fileRef=%ld newSize=%d", fileRef, newSize); pi_reset_errors(sd); req = dlp_request_new(dlpFuncVFSFileResize, 1, 8); @@ -4827,44 +4648,42 @@ dlp_VFSFileResize(int sd, FileRef fileRef, int newSize) set_long(DLP_REQUEST_DATA(req, 0, 0), fileRef); set_long(DLP_REQUEST_DATA(req, 0, 4), newSize); - + result = dlp_exec(sd, req, &res); - dlp_request_free (req); - dlp_response_free (res); - + dlp_request_free(req); + dlp_response_free(res); + return result; } int dlp_VFSFileSize(int sd, FileRef fileRef, int *size) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1,2); - TraceX(dlp_VFSFileSize,"fileRef=%ld",fileRef); + TraceX(dlp_VFSFileSize, "fileRef=%ld", fileRef); pi_reset_errors(sd); req = dlp_request_new (dlpFuncVFSFileSize, 1, 4); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - set_long (DLP_REQUEST_DATA (req, 0, 0), fileRef); - - result = dlp_exec (sd, req, &res); - - dlp_request_free (req); - - if (result > 0) { - *size = get_long (DLP_RESPONSE_DATA (res, 0, 0)); + set_long(DLP_REQUEST_DATA (req, 0, 0), fileRef); - LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP VFS File Size: %d\n", *size)); + result = dlp_exec(sd, req, &res); + + dlp_request_free(req); + + if (result > 0) { + *size = get_long(DLP_RESPONSE_DATA (res, 0, 0)); + LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, "DLP VFS File Size: %d\n", *size)); } - - dlp_response_free (res); + + dlp_response_free(res); return result; } @@ -4872,33 +4691,32 @@ dlp_VFSFileSize(int sd, FileRef fileRef, int *size) int dlp_ExpSlotMediaType(int sd, int slotNum, unsigned long *mediaType) { - int result; + int result; struct dlpRequest *req; struct dlpResponse *res; - + RequireDLPVersion(sd,1, 4); - TraceX(dlp_ExpSlotMediaType,"slotNum=%d",slotNum); + TraceX(dlp_ExpSlotMediaType, "slotNum=%d", slotNum); pi_reset_errors(sd); - req = dlp_request_new (dlpFuncExpSlotMediaType, 1, 2); + req = dlp_request_new(dlpFuncExpSlotMediaType, 1, 2); if (req == NULL) return pi_set_error(sd, PI_ERR_GENERIC_MEMORY); - set_short (DLP_REQUEST_DATA (req, 0, 0), slotNum); + set_short(DLP_REQUEST_DATA (req, 0, 0), slotNum); - result = dlp_exec (sd, req, &res); + result = dlp_exec(sd, req, &res); - dlp_request_free (req); + dlp_request_free(req); if (result > 0) { - *mediaType = get_long (DLP_RESPONSE_DATA (res, 0, 0)); + *mediaType = get_long(DLP_RESPONSE_DATA (res, 0, 0)); LOG((PI_DBG_DLP, PI_DBG_LVL_INFO, - "DLP Media Type for slot %d: %4.4s\n", - slotNum, mediaType)); + "DLP Media Type for slot %d: %4.4s\n", slotNum, mediaType)); } - dlp_response_free (res); + dlp_response_free(res); return result; } diff --git a/src/pilot-dlpsh.c b/src/pilot-dlpsh.c index afbe5da4..24982059 100644 --- a/src/pilot-dlpsh.c +++ b/src/pilot-dlpsh.c @@ -389,7 +389,7 @@ int time_fn(int sd, int argc, const char *argv[]) strftime(timebuf, 80, "Now setting Palm time from desktop to: " "%a %b %d %H:%M:%S %Z %Y\n", tm_ptr); - printf(timebuf); + printf("%s", timebuf); gettimeofday(&tv, 0); ltime = tv.tv_sec + 1; usleep(1000000 - tv.tv_usec); diff --git a/src/pilot-hinotes.c b/src/pilot-hinotes.c index a0336dc6..40ccf204 100644 --- a/src/pilot-hinotes.c +++ b/src/pilot-hinotes.c @@ -79,9 +79,7 @@ void write_memo_mbox(struct PilotUser User, struct HiNoteNote m, printf("...\n"); else printf("\n"); - printf("\n"); - printf(m.text); - printf("\n"); + printf("\n%s\n", m.text); } void write_memo_in_directory(char *dirname, struct HiNoteNote m, diff --git a/src/pilot-read-notepad.c b/src/pilot-read-notepad.c index 06ee26f2..e33025ab 100644 --- a/src/pilot-read-notepad.c +++ b/src/pilot-read-notepad.c @@ -39,10 +39,6 @@ #ifdef HAVE_PNG #include "png.h" -#if (PNG_LIBPNG_VER < 10201) - #define png_voidp_NULL (png_voidp)NULL - #define png_error_ptr_NULL (png_error_ptr)NULL -#endif #endif const char *progname; @@ -166,8 +162,8 @@ void write_png( FILE *f, struct NotePad *n ) width = n->body.width + 8; png_ptr = png_create_write_struct - ( PNG_LIBPNG_VER_STRING, png_voidp_NULL, - png_error_ptr_NULL, png_error_ptr_NULL); + ( PNG_LIBPNG_VER_STRING, NULL, + NULL, NULL); if(!png_ptr) return; diff --git a/src/pilot-read-palmpix.c b/src/pilot-read-palmpix.c index 2c005517..5799ab3a 100644 --- a/src/pilot-read-palmpix.c +++ b/src/pilot-read-palmpix.c @@ -42,10 +42,6 @@ #ifdef HAVE_PNG #include "png.h" -#if (PNG_LIBPNG_VER < 10201) - #define png_voidp_NULL (png_voidp)NULL - #define png_error_ptr_NULL (png_error_ptr)NULL -#endif #endif const char *progname; @@ -223,8 +219,8 @@ void write_png( FILE *f, const struct PalmPixState *state, png_infop info_ptr; png_ptr = png_create_write_struct - ( PNG_LIBPNG_VER_STRING, png_voidp_NULL, - png_error_ptr_NULL, png_error_ptr_NULL); + ( PNG_LIBPNG_VER_STRING, NULL, + NULL, NULL); if(!png_ptr) return; diff --git a/src/pilot-read-screenshot.c b/src/pilot-read-screenshot.c index a3106a30..18de0222 100644 --- a/src/pilot-read-screenshot.c +++ b/src/pilot-read-screenshot.c @@ -40,10 +40,6 @@ #ifdef HAVE_PNG # include "png.h" -# if (PNG_LIBPNG_VER < 10201) -# define png_voidp_NULL (png_voidp)NULL -# define png_error_ptr_NULL (png_error_ptr)NULL -# endif #endif #define pi_mktag(c1,c2,c3,c4) (((c1)<<24)|((c2)<<16)|((c3)<<8)|(c4)) @@ -87,8 +83,8 @@ void write_png ( char *fname, struct ss_state *state ) gray_buf = malloc( state->w ); png_ptr = png_create_write_struct - (PNG_LIBPNG_VER_STRING, png_voidp_NULL, - png_error_ptr_NULL, png_error_ptr_NULL); + (PNG_LIBPNG_VER_STRING, NULL, + NULL, NULL); if (!png_ptr) return; diff --git a/src/pilot-read-veo.c b/src/pilot-read-veo.c index 73aa53b7..6ecc79f9 100644 --- a/src/pilot-read-veo.c +++ b/src/pilot-read-veo.c @@ -41,10 +41,6 @@ #ifdef HAVE_PNG # include "png.h" -# if (PNG_LIBPNG_VER < 10201) -# define png_voidp_NULL (png_voidp)NULL -# define png_error_ptr_NULL (png_error_ptr)NULL -# endif #endif #define pi_mktag(c1,c2,c3,c4) (((c1)<<24)|((c2)<<16)|((c3)<<8)|(c4)) @@ -856,8 +852,8 @@ void write_png (FILE * f, struct Veo *v, long flags) png_infop info_ptr; png_ptr = png_create_write_struct - (PNG_LIBPNG_VER_STRING, png_voidp_NULL, - png_error_ptr_NULL, png_error_ptr_NULL); + (PNG_LIBPNG_VER_STRING, NULL, + NULL, NULL); if (!png_ptr) return; diff --git a/src/pilot-xfer.c b/src/pilot-xfer.c index 25aa05e4..096a93c7 100644 --- a/src/pilot-xfer.c +++ b/src/pilot-xfer.c @@ -2477,8 +2477,7 @@ main(int argc, const char *argv[]) { fprintf(stderr, " ERROR: '%s' is not a directory or does not exist.\n" " Please supply a directory name when performing a " - "backup or restore and try again.\n\n", dirname); - fprintf(stderr,gracias); + "backup or restore and try again.\n\n%s", dirname, gracias); return 1; } } @@ -2487,14 +2486,12 @@ main(int argc, const char *argv[]) case palm_op_list: if (rargc > 0) { - fprintf(stderr," ERROR: Do not pass additional arguments to -busrlLC.\n"); - fprintf(stderr,gracias); + fprintf(stderr," ERROR: Do not pass additional arguments to -busrlLC.\n%s", gracias); return 1; } break; case palm_op_noop: - fprintf(stderr," ERROR: Must specify one of -bursimfdlC.\n"); - fprintf(stderr,gracias); + fprintf(stderr," ERROR: Must specify one of -bursimfdlC.\n%s", gracias); return 1; break; case palm_op_merge: