From: Felix Fietkau Date: Fri, 5 Oct 2007 00:27:49 +0000 (+0000) Subject: Upgrade busybox to 1.7.2 - clean up insmod crap - add some lineno/programname fixes... X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=fe313941ac5ef2a4e80d22be43a9d5dc667276b7;p=openwrt%2Fstaging%2Fjow.git Upgrade busybox to 1.7.2 - clean up insmod crap - add some lineno/programname fixes for awx - clean up awk getopt stuff - remove unnecessary patches SVN-Revision: 9130 --- diff --git a/package/busybox/Makefile b/package/busybox/Makefile index 3844e879ef..8fefb60293 100644 --- a/package/busybox/Makefile +++ b/package/busybox/Makefile @@ -9,13 +9,13 @@ include $(TOPDIR)/rules.mk PKG_NAME:=busybox -PKG_VERSION:=1.4.2 +PKG_VERSION:=1.7.2 PKG_RELEASE:=3 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2 PKG_SOURCE_URL:=http://www.busybox.net/downloads \ http://distfiles.gentoo.org/distfiles/ -PKG_MD5SUM:=b4c61fb15642be9dde20e8493788c585 +PKG_MD5SUM:=c91ec9756e2000073a9dd8fa9fc3f89e include $(INCLUDE_DIR)/package.mk diff --git a/package/busybox/config/Config.in b/package/busybox/config/Config.in index 4df12cc8bb..d3c1cb6341 100644 --- a/package/busybox/config/Config.in +++ b/package/busybox/config/Config.in @@ -100,8 +100,7 @@ config BUSYBOX_CONFIG_FEATURE_INSTALLER help Enable 'busybox --install [-s]' support. This will allow you to use busybox at runtime to create hard links or symlinks for all the - applets that are compiled into busybox. This feature requires the - /proc filesystem. + applets that are compiled into busybox. config BUSYBOX_CONFIG_LOCALE_SUPPORT bool "Enable locale support (system needs locale for this to work)" @@ -140,6 +139,13 @@ config BUSYBOX_CONFIG_FEATURE_CLEAN_UP Don't enable this unless you have a really good reason to clean things up manually. +config BUSYBOX_CONFIG_FEATURE_PIDFILE + bool "Support writing pidfiles" + default y + help + This option makes some applets (e.g. crond, syslogd, inetd) write + a pidfile in /var/run. Some applications rely on them. + config BUSYBOX_CONFIG_FEATURE_SUID bool "Support for SUID/SGID handling" default y @@ -155,13 +161,6 @@ config BUSYBOX_CONFIG_FEATURE_SUID are login, passwd, su, ping, traceroute, crontab, dnsd, ipcrm, ipcs, and vlock. -config BUSYBOX_CONFIG_FEATURE_SYSLOG - bool "Support for syslog" - default y - help - This option is auto-selected when you select any applet which may - send its output to syslog. You do not need to select it manually. - config BUSYBOX_CONFIG_FEATURE_SUID_CONFIG bool "Runtime SUID/SGID configuration via /etc/busybox.conf" default n if BUSYBOX_CONFIG_FEATURE_SUID @@ -202,14 +201,6 @@ config BUSYBOX_CONFIG_FEATURE_SUID_CONFIG_QUIET /etc/busybox.conf should be readable by the user needing the SUID, check this option to avoid users to be notified about missing permissions. -config BUSYBOX_CONFIG_FEATURE_HAVE_RPC - bool "RPC support" - default y - help - Select this if you have rpc support. - This automatically turns off all configuration options that rely - on RPC. - config BUSYBOX_CONFIG_SELINUX bool "Support NSA Security Enhanced Linux" default n @@ -230,6 +221,20 @@ config BUSYBOX_CONFIG_SELINUX Most people will leave this set to 'N'. +config BUSYBOX_CONFIG_FEATURE_PREFER_APPLETS + bool "exec prefers applets" + default y + help + This is an experimental option which directs applets about to + call 'exec' to try and find an applicable busybox applet before + searching the PATH. This is typically done by exec'ing + /proc/self/exe. + This may affect shell, find -exec, xargs and similar applets. + They will use applets even if /bin/ -> busybox link + is missing (or is not a link to busybox). However, this causes + problems in chroot jails without mounted /proc and with ps/top + (command name can be shown as 'exe' for applets started this way). + config BUSYBOX_CONFIG_BUSYBOX_EXEC_PATH string "Path to BusyBox executable" default "/proc/self/exe" @@ -240,6 +245,22 @@ config BUSYBOX_CONFIG_BUSYBOX_EXEC_PATH executable. If you haven't got /proc, set this to wherever you want to run BusyBox from. +# These are auto-selected by other options + +config BUSYBOX_CONFIG_FEATURE_SYSLOG + bool "Support for logging to syslog" + default y + help + This option is auto-selected when you select any applet which may + send its output to syslog. You do not need to select it manually. + +config BUSYBOX_CONFIG_FEATURE_HAVE_RPC + bool "RPC support" + default y + help + This is automatically selected if any of enabled applets need it. + You do not need to select it manually. + endmenu menu 'Build Options' @@ -298,7 +319,7 @@ config BUSYBOX_CONFIG_FEATURE_SHARED_BUSYBOX You need to have a working dynamic linker to use this variant. config BUSYBOX_CONFIG_LFS - bool "Support large files over 2 GB" + bool default y select BUSYBOX_CONFIG_FDISK_SUPPORT_LARGE_DISKS help @@ -343,21 +364,29 @@ config BUSYBOX_CONFIG_DEBUG Most people should answer N. -config BUSYBOX_CONFIG_DEBUG_PESSIMIZE - bool "Disable compiler optimizations." +config BUSYBOX_CONFIG_WERROR + bool "Abort compilation on any warning" default n - depends on BUSYBOX_CONFIG_DEBUG help - The compiler's optimization of source code can eliminate and reorder - code, resulting in an executable that's hard to understand when - stepping through it with a debugger. This switches it off, resulting - in a much bigger executable that more closely matches the source - code. + Selecting this will add -Werror to gcc command line. + + Most people should answer N. + +# Seems to be unused +#config DEBUG_PESSIMIZE +# bool "Disable compiler optimizations." +# default n +# depends on DEBUG +# help +# The compiler's optimization of source code can eliminate and reorder +# code, resulting in an executable that's hard to understand when +# stepping through it with a debugger. This switches it off, resulting +# in a much bigger executable that more closely matches the source +# code. choice prompt "Additional debugging library" default BUSYBOX_CONFIG_NO_DEBUG_LIB - depends on BUSYBOX_CONFIG_DEBUG help Using an additional debugging library will make BusyBox become considerable larger and will cause it to run more slowly. You @@ -417,31 +446,30 @@ config BUSYBOX_CONFIG_INSTALL_NO_USR that you really want this behaviour. choice - prompt "Applets links" - default BUSYBOX_CONFIG_INSTALL_APPLET_SYMLINKS - help - Choose how you install applets links. + prompt "Applets links" + default BUSYBOX_CONFIG_INSTALL_APPLET_SYMLINKS + help + Choose how you install applets links. config BUSYBOX_CONFIG_INSTALL_APPLET_SYMLINKS - bool "as soft-links" - help - Install applets as soft-links to the busybox binary. This needs some - free inodes on the filesystem, but might help with filesystem - generators that can't cope with hard-links. + bool "as soft-links" + help + Install applets as soft-links to the busybox binary. This needs some + free inodes on the filesystem, but might help with filesystem + generators that can't cope with hard-links. config BUSYBOX_CONFIG_INSTALL_APPLET_HARDLINKS - bool "as hard-links" - help - Install applets as hard-links to the busybox binary. This might count - on a filesystem with few inodes. + bool "as hard-links" + help + Install applets as hard-links to the busybox binary. This might count + on a filesystem with few inodes. config BUSYBOX_CONFIG_INSTALL_APPLET_DONT - bool - prompt "not installed" - depends on BUSYBOX_CONFIG_FEATURE_INSTALLER || BUSYBOX_CONFIG_FEATURE_SH_STANDALONE_SHELL - help - Do not install applet links. Useful when using the -install feature - or a standalone shell for rescue pruposes. + bool "not installed" + depends on BUSYBOX_CONFIG_FEATURE_INSTALLER || BUSYBOX_CONFIG_FEATURE_SH_STANDALONE || BUSYBOX_CONFIG_FEATURE_PREFER_APPLETS + help + Do not install applet links. Useful when using the -install feature + or a standalone shell for rescue purposes. endchoice @@ -476,3 +504,5 @@ source package/busybox/config/procps/Config.in source package/busybox/config/shell/Config.in source package/busybox/config/sysklogd/Config.in source package/busybox/config/runit/Config.in +source package/busybox/config/selinux/Config.in +source package/busybox/config/ipsvd/Config.in diff --git a/package/busybox/config/archival/Config.in b/package/busybox/config/archival/Config.in index 989d8d5c7e..9895dba04b 100644 --- a/package/busybox/config/archival/Config.in +++ b/package/busybox/config/archival/Config.in @@ -142,6 +142,13 @@ config BUSYBOX_CONFIG_RPM help Mini RPM applet - queries and extracts RPM packages. +config BUSYBOX_CONFIG_FEATURE_RPM_BZ2 + bool "Enable handling of rpms with bzip2-compressed data inside" + default n + depends on BUSYBOX_CONFIG_RPM + help + Enable handling of rpms with bzip2-compressed data inside. + config BUSYBOX_CONFIG_TAR bool "tar" default y @@ -207,6 +214,15 @@ config BUSYBOX_CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY the old GNU format; help to kill this old format by repacking your ancient archives with the new format. +config BUSYBOX_CONFIG_FEATURE_TAR_OLDSUN_COMPATIBILITY + bool "Enable untarring of tarballs with checksums produced by buggy Sun tar" + default n + depends on BUSYBOX_CONFIG_TAR + help + This option is required to unpack archives created by some old + version of Sun's tar (it was calculating checksum using signed arithmetic). + It is said to be fixed in newer Sun tar, but "old" tarballs still exist. + config BUSYBOX_CONFIG_FEATURE_TAR_GNU_EXTENSIONS bool "Enable support for some GNU tar extensions" default y diff --git a/package/busybox/config/console-tools/Config.in b/package/busybox/config/console-tools/Config.in index 661e8947c6..7b044ead9c 100644 --- a/package/busybox/config/console-tools/Config.in +++ b/package/busybox/config/console-tools/Config.in @@ -85,7 +85,7 @@ config BUSYBOX_CONFIG_SETCONSOLE config BUSYBOX_CONFIG_FEATURE_SETCONSOLE_LONG_OPTIONS bool "Enable long options" default n - depends on BUSYBOX_CONFIG_SET_CONSOLE && BUSYBOX_CONFIG_GETOPT_LONG + depends on BUSYBOX_CONFIG_SETCONSOLE && BUSYBOX_CONFIG_GETOPT_LONG help Support long options for the setconsole applet. diff --git a/package/busybox/config/coreutils/Config.in b/package/busybox/config/coreutils/Config.in index 91f93e19bd..5a0220cdd7 100644 --- a/package/busybox/config/coreutils/Config.in +++ b/package/busybox/config/coreutils/Config.in @@ -65,13 +65,6 @@ config BUSYBOX_CONFIG_CKSUM help cksum is used to calculate the CRC32 checksum of a file. -config BUSYBOX_CONFIG_CMP - bool "cmp" - default n - help - cmp is used to compare two files and returns the result - to standard output. - config BUSYBOX_CONFIG_COMM bool "comm" default n @@ -142,38 +135,6 @@ config BUSYBOX_CONFIG_DF df reports the amount of disk space used and available on filesystems. -config BUSYBOX_CONFIG_DIFF - bool "diff" - default n - help - diff compares two files or directories and outputs the - differences between them in a form that can be given to - the patch command. - -config BUSYBOX_CONFIG_FEATURE_DIFF_BINARY - bool "Enable checks for binary files" - default n - depends on BUSYBOX_CONFIG_DIFF - help - This option enables support for checking for binary files - before a comparison is carried out. - -config BUSYBOX_CONFIG_FEATURE_DIFF_DIR - bool "Enable directory support" - default n - depends on BUSYBOX_CONFIG_DIFF - help - This option enables support for directory and subdirectory - comparison. - -config BUSYBOX_CONFIG_FEATURE_DIFF_MINIMAL - bool "Enable -d option to find smaller sets of changes" - default n - depends on BUSYBOX_CONFIG_DIFF - help - Enabling this option allows the use of -d to make diff - try hard to find the smallest possible set of changes. - config BUSYBOX_CONFIG_DIRNAME bool "dirname" default y @@ -239,6 +200,19 @@ config BUSYBOX_CONFIG_FEATURE_ENV_LONG_OPTIONS help Support long options for the env applet. +config BUSYBOX_CONFIG_EXPAND + bool "expand" + default n + help + By default, convert all tabs to spaces. + +config BUSYBOX_CONFIG_FEATURE_EXPAND_LONG_OPTIONS + bool "Enable long options" + default n + depends on BUSYBOX_CONFIG_EXPAND && BUSYBOX_CONFIG_GETOPT_LONG + help + Support long options for the expand applet. + config BUSYBOX_CONFIG_EXPR bool "expr" default y @@ -474,6 +448,20 @@ config BUSYBOX_CONFIG_PWD help pwd is used to print the current directory. +config BUSYBOX_CONFIG_READLINK + bool "readlink" + default n + help + This program reads a symbolic link and returns the name + of the file it points to + +config BUSYBOX_CONFIG_FEATURE_READLINK_FOLLOW + bool "Enable canonicalization by following all symlinks (-f)" + default n + depends on BUSYBOX_CONFIG_READLINK + help + Enable the readlink option (-f). + config BUSYBOX_CONFIG_REALPATH bool "realpath" default n @@ -536,6 +524,21 @@ config BUSYBOX_CONFIG_FEATURE_SORT_BIG The SuSv3 sort standard is available at: http://www.opengroup.org/onlinepubs/007904975/utilities/sort.html +config BUSYBOX_CONFIG_SPLIT + bool "split" + default n + help + split a file into pieces. + +config BUSYBOX_CONFIG_FEATURE_SPLIT_FANCY + bool "fancy extensions" + default n + depends on BUSYBOX_CONFIG_SPLIT + help + Add support for features not required by SUSv3. + Supports additional suffixes 'b' for 512 bytes, + 'g' for 1GiB for the -b option. + config BUSYBOX_CONFIG_STAT bool "stat" default n @@ -665,6 +668,19 @@ config BUSYBOX_CONFIG_UNAME help uname is used to print system information. +config BUSYBOX_CONFIG_UNEXPAND + bool "unexpand" + default n + help + By default, convert only leading sequences of blanks to tabs. + +config BUSYBOX_CONFIG_FEATURE_UNEXPAND_LONG_OPTIONS + bool "Enable long options" + default n + depends on BUSYBOX_CONFIG_UNEXPAND && BUSYBOX_CONFIG_GETOPT_LONG + help + Support long options for the unexpand applet. + config BUSYBOX_CONFIG_UNIQ bool "uniq" default y @@ -689,14 +705,6 @@ config BUSYBOX_CONFIG_UUENCODE help uuencode is used to uuencode a file. -config BUSYBOX_CONFIG_WATCH - bool "watch" - default n - select BUSYBOX_CONFIG_DATE - help - watch is used to execute a program periodically, showing - output to the screen. - config BUSYBOX_CONFIG_WC bool "wc" default y diff --git a/package/busybox/config/debianutils/Config.in b/package/busybox/config/debianutils/Config.in index f047a90f22..bc37c15fbe 100644 --- a/package/busybox/config/debianutils/Config.in +++ b/package/busybox/config/debianutils/Config.in @@ -17,20 +17,6 @@ config BUSYBOX_CONFIG_PIPE_PROGRESS help Display a dot to indicate pipe activity. -config BUSYBOX_CONFIG_READLINK - bool "readlink" - default n - help - This program reads a symbolic link and returns the name - of the file it points to - -config BUSYBOX_CONFIG_FEATURE_READLINK_FOLLOW - bool "Enable canonicalization by following all symlinks (-f)" - default n - depends on BUSYBOX_CONFIG_READLINK - help - Enable the readlink option (-f). - config BUSYBOX_CONFIG_RUN_PARTS bool "run-parts" default n @@ -53,6 +39,15 @@ config BUSYBOX_CONFIG_FEATURE_RUN_PARTS_LONG_OPTIONS help Support long options for the run-parts applet. +config BUSYBOX_CONFIG_FEATURE_RUN_PARTS_FANCY + bool "Support additional arguments" + default n + depends on BUSYBOX_CONFIG_RUN_PARTS + help + Support additional options: + -l --list print the names of the all matching files (not + limited to executables), but don't actually run them. + config BUSYBOX_CONFIG_START_STOP_DAEMON bool "start-stop-daemon" default y diff --git a/package/busybox/config/editors/Config.in b/package/busybox/config/editors/Config.in index 8973c3667b..6d1f6f2bc4 100644 --- a/package/busybox/config/editors/Config.in +++ b/package/busybox/config/editors/Config.in @@ -27,6 +27,45 @@ config BUSYBOX_CONFIG_FEATURE_AWK_MATH Enable math functions of the Awk programming language. NOTE: This will require libm to be present for linking. +config BUSYBOX_CONFIG_CMP + bool "cmp" + default n + help + cmp is used to compare two files and returns the result + to standard output. + +config BUSYBOX_CONFIG_DIFF + bool "diff" + default y + help + diff compares two files or directories and outputs the + differences between them in a form that can be given to + the patch command. + +config BUSYBOX_CONFIG_FEATURE_DIFF_BINARY + bool "Enable checks for binary files" + default n + depends on BUSYBOX_CONFIG_DIFF + help + This option enables support for checking for binary files + before a comparison is carried out. + +config BUSYBOX_CONFIG_FEATURE_DIFF_DIR + bool "Enable directory support" + default n + depends on BUSYBOX_CONFIG_DIFF + help + This option enables support for directory and subdirectory + comparison. + +config BUSYBOX_CONFIG_FEATURE_DIFF_MINIMAL + bool "Enable -d option to find smaller sets of changes" + default n + depends on BUSYBOX_CONFIG_DIFF + help + Enabling this option allows the use of -d to make diff + try hard to find the smallest possible set of changes. + config BUSYBOX_CONFIG_ED bool "ed" default n @@ -57,6 +96,16 @@ config BUSYBOX_CONFIG_VI learning curve. If you are not already comfortable with 'vi' you may wish to use something else. +config BUSYBOX_CONFIG_FEATURE_VI_MAX_LEN + int "Maximum line length in vi" + range 256 16384 + default 1024 + depends on BUSYBOX_CONFIG_VI + help + vi uses on-stack buffers for intermediate line buffers. + You may want to decrease this parameter if your target machine + benefits from smaller stack usage. + config BUSYBOX_CONFIG_FEATURE_VI_COLON bool "Enable \":\" colon commands (no \"ex\" mode)" default y diff --git a/package/busybox/config/findutils/Config.in b/package/busybox/config/findutils/Config.in index dc0bbcec3f..3f89c336fa 100644 --- a/package/busybox/config/findutils/Config.in +++ b/package/busybox/config/findutils/Config.in @@ -30,7 +30,7 @@ config BUSYBOX_CONFIG_FEATURE_FIND_MTIME files, in days. config BUSYBOX_CONFIG_FEATURE_FIND_MMIN - bool "Enable modified time matching (-min) option" + bool "Enable modified time matching (-mmin) option" default n depends on BUSYBOX_CONFIG_FIND help @@ -57,8 +57,14 @@ config BUSYBOX_CONFIG_FEATURE_FIND_XDEV default y depends on BUSYBOX_CONFIG_FIND help - This option will allow find to restrict searches to a single - filesystem. + This option allows find to restrict searches to a single filesystem. + +config BUSYBOX_CONFIG_FEATURE_FIND_MAXDEPTH + bool "Enable -maxdepth N option" + default y + depends on BUSYBOX_CONFIG_FIND + help + This option enables -maxdepth N option. config BUSYBOX_CONFIG_FEATURE_FIND_NEWER bool "Enable -newer option for comparing file mtimes" @@ -83,6 +89,88 @@ config BUSYBOX_CONFIG_FEATURE_FIND_EXEC Support the 'find -exec' option for executing commands based upon the files matched. +config BUSYBOX_CONFIG_FEATURE_FIND_USER + bool "Enable username/uid matching (-user) option" + default y + depends on BUSYBOX_CONFIG_FIND + help + Support the 'find -user' option for searching by username or uid. + +config BUSYBOX_CONFIG_FEATURE_FIND_GROUP + bool "Enable group/gid matching (-group) option" + default y + depends on BUSYBOX_CONFIG_FIND + help + Support the 'find -group' option for searching by group name or gid. + +config BUSYBOX_CONFIG_FEATURE_FIND_NOT + bool "Enable the 'not' (!) operator" + default y + depends on BUSYBOX_CONFIG_FIND + help + Support the '!' operator to invert the test results. + If 'Enable full-blown desktop' is enabled, then will also support + the non-POSIX notation '-not'. + +config BUSYBOX_CONFIG_FEATURE_FIND_DEPTH + bool "Enable the -depth option" + default y + depends on BUSYBOX_CONFIG_FIND + help + Process each directory's contents before the directory itself. + +config BUSYBOX_CONFIG_FEATURE_FIND_PAREN + bool "Enable parens in options" + default y + depends on BUSYBOX_CONFIG_FIND + help + Enable usage of parens '(' to specify logical order of arguments. + +config BUSYBOX_CONFIG_FEATURE_FIND_SIZE + bool "Enable (-size) option allowing matching for file size" + default y + depends on BUSYBOX_CONFIG_FIND + help + Support the 'find -size' option for searching by file size. + +config BUSYBOX_CONFIG_FEATURE_FIND_PRUNE + bool "Enable (-prune) option allowing to exclude subdirectories" + default y + depends on BUSYBOX_CONFIG_FIND + help + If the file is a directory, dont descend into it. Useful for + exclusion .svn and CVS directories. + +config BUSYBOX_CONFIG_FEATURE_FIND_DELETE + bool "Enable -delete option allowing to delete files" + default n + depends on BUSYBOX_CONFIG_FIND && BUSYBOX_CONFIG_FEATURE_FIND_DEPTH + help + Support the 'find -delete' option for deleting files and direcotries. + WARNING: This option can do much harm if used wrong. Busybox will not + try to protect the user from doing stupid things. Use with care. + +config BUSYBOX_CONFIG_FEATURE_FIND_PATH + bool "Enable -path option allowing to match pathname patterns" + default y + depends on BUSYBOX_CONFIG_FIND + help + The -path option matches whole pathname instead of just filename. + +config BUSYBOX_CONFIG_FEATURE_FIND_REGEX + bool "Enable -regex: match pathname to regex" + default y + depends on BUSYBOX_CONFIG_FIND + help + The -regex option matches whole pathname against regular expression. + +config BUSYBOX_CONFIG_FEATURE_FIND_CONTEXT + bool "Enable (-context) option for matching security context" + default n + depends on BUSYBOX_CONFIG_FIND && BUSYBOX_CONFIG_SELINUX + help + Support the 'find -context' option for matching security context. + config BUSYBOX_CONFIG_GREP bool "grep" default y diff --git a/package/busybox/config/init/Config.in b/package/busybox/config/init/Config.in index b8ad0d664e..104af2614b 100644 --- a/package/busybox/config/init/Config.in +++ b/package/busybox/config/init/Config.in @@ -38,6 +38,11 @@ config BUSYBOX_CONFIG_FEATURE_INIT_SCTTY behavour, but is often what you want in an embedded system where the console is only accessed during development or for maintenance. +config BUSYBOX_CONFIG_FEATURE_INIT_SYSLOG + bool "Enable init to write to syslog" + default y + depends on BUSYBOX_CONFIG_INIT + config BUSYBOX_CONFIG_FEATURE_EXTRA_QUIET bool "Be _extra_ quiet on boot" default n diff --git a/package/busybox/config/ipsvd/Config.in b/package/busybox/config/ipsvd/Config.in new file mode 100644 index 0000000000..d163ade492 --- /dev/null +++ b/package/busybox/config/ipsvd/Config.in @@ -0,0 +1,20 @@ +# +# For a description of the syntax of this configuration file, +# see scripts/kbuild/config-language.txt. +# + +menu "ipsvd utilities" + +config BUSYBOX_CONFIG_TCPSVD + bool "tcpsvd" + default n + help + tcpsvd listens on a tcp port and runs a program for each new connection + +config BUSYBOX_CONFIG_UDPSVD + bool "udpsvd" + default n + help + udpsvd listens on a udp port and runs a program for each new connection + +endmenu diff --git a/package/busybox/config/libbb/Config.in b/package/busybox/config/libbb/Config.in index 4919f9b0b5..4e23b8a969 100644 --- a/package/busybox/config/libbb/Config.in +++ b/package/busybox/config/libbb/Config.in @@ -26,4 +26,105 @@ config BUSYBOX_CONFIG_MD5_SIZE_VS_SPEED 2 3.0 5088 3 (smallest) 5.1 4912 +config BUSYBOX_CONFIG_FEATURE_FAST_TOP + bool "Faster /proc scanning code (+100 bytes)" + default y + help + This option makes top (and ps) ~20% faster (or 20% less CPU hungry), + but code size is slightly bigger. + +config BUSYBOX_CONFIG_FEATURE_ETC_NETWORKS + bool "Support for /etc/networks" + default n + help + Enable support for network names in /etc/networks. This is + a rarely used feature which allows you to use names + instead of IP/mask pairs in route command. + +config BUSYBOX_CONFIG_FEATURE_EDITING + bool "Command line editing" + default y + help + Enable line editing (mainly for shell command line). + +config BUSYBOX_CONFIG_FEATURE_EDITING_MAX_LEN + int "Maximum length of input" + range 128 8192 + default 512 + depends on BUSYBOX_CONFIG_FEATURE_EDITING + help + Line editing code uses on-stack buffers for storage. + You may want to decrease this parameter if your target machine + benefits from smaller stack usage. + +config BUSYBOX_CONFIG_FEATURE_EDITING_FANCY_KEYS + bool "Additional editing keys" + default y + depends on BUSYBOX_CONFIG_FEATURE_EDITING + help + Enable additonal editing keys (Ctrl-E, Ctrl-U etc). + Arrow keys, Home/End/Delete and Ctrl-W work even without this option. + +config BUSYBOX_CONFIG_FEATURE_EDITING_VI + bool "vi-style line editing commands" + default n + depends on BUSYBOX_CONFIG_FEATURE_EDITING + help + Enable vi-style line editing. In shells, this mode can be + turned on and off with "set -o vi" and "set +o vi". + +config BUSYBOX_CONFIG_FEATURE_EDITING_HISTORY + int "History size" + range 0 99999 + default 256 + depends on BUSYBOX_CONFIG_FEATURE_EDITING + help + Specify command history size. + +config BUSYBOX_CONFIG_FEATURE_EDITING_SAVEHISTORY + bool "History saving" + default n + depends on BUSYBOX_CONFIG_ASH && BUSYBOX_CONFIG_FEATURE_EDITING + help + Enable history saving in ash shell. + +config BUSYBOX_CONFIG_FEATURE_TAB_COMPLETION + bool "Tab completion" + default y + depends on BUSYBOX_CONFIG_FEATURE_EDITING + help + Enable tab completion. + +config BUSYBOX_CONFIG_FEATURE_USERNAME_COMPLETION + bool "Username completion" + default n + depends on BUSYBOX_CONFIG_FEATURE_TAB_COMPLETION + help + Enable username completion. + +config BUSYBOX_CONFIG_FEATURE_EDITING_FANCY_PROMPT + bool "Fancy shell prompts" + default y + depends on BUSYBOX_CONFIG_FEATURE_EDITING + help + Setting this option allows for prompts to use things like \w and + \$ and escape codes. + +config BUSYBOX_CONFIG_MONOTONIC_SYSCALL + bool "Use clock_gettime(CLOCK_MONOTONIC) syscall" + default n + help + Use clock_gettime(CLOCK_MONOTONIC) syscall for measuring + time intervals (time, ping, traceroute etc need this). + Probably requires Linux 2.6+. If not selected, gettimeofday + will be used instead (which gives wrong results if date/time + is reset). + +config BUSYBOX_CONFIG_IOCTL_HEX2STR_ERROR + bool "Use ioctl names rather than hex values in error messages" + default y + help + Use ioctl names rather than hex values in error messages + (e.g. VT_DISALLOCATE rather than 0x5608). If disabled this + saves about 1400 bytes. endmenu diff --git a/package/busybox/config/loginutils/Config.in b/package/busybox/config/loginutils/Config.in index 6171d02909..15019c1251 100644 --- a/package/busybox/config/loginutils/Config.in +++ b/package/busybox/config/loginutils/Config.in @@ -59,12 +59,29 @@ config BUSYBOX_CONFIG_ADDGROUP help Utility for creating a new group account. +config BUSYBOX_CONFIG_FEATURE_ADDUSER_TO_GROUP + bool "Support for adding users to groups" + default n + depends on BUSYBOX_CONFIG_ADDGROUP + help + If called with two non-option arguments, + addgroup will add an existing user to an + existing group. + config BUSYBOX_CONFIG_DELGROUP bool "delgroup" default n help Utility for deleting a group account. +config BUSYBOX_CONFIG_FEATURE_DEL_USER_FROM_GROUP + bool "Support for removing users from groups." + default n + depends on BUSYBOX_CONFIG_DELGROUP + help + If called with two non-option arguments, deluser + or delgroup will remove an user from a specified group. + config BUSYBOX_CONFIG_ADDUSER bool "adduser" default n @@ -111,6 +128,13 @@ config BUSYBOX_CONFIG_LOGIN Note that Busybox binary must be setuid root for this applet to work properly. +config BUSYBOX_CONFIG_PAM + bool "Support for PAM (Pluggable Authentication Modules)" + default n + depends on BUSYBOX_CONFIG_LOGIN + help + Use PAM in login(1) instead of direct access to password database. + config BUSYBOX_CONFIG_LOGIN_SCRIPTS bool "Support for login scripts" depends on BUSYBOX_CONFIG_LOGIN @@ -119,12 +143,20 @@ config BUSYBOX_CONFIG_LOGIN_SCRIPTS Enable this if you want login to execute $LOGIN_PRE_SUID_SCRIPT just prior to switching from root to logged-in user. +config BUSYBOX_CONFIG_FEATURE_NOLOGIN + bool "Support for /etc/nologin" + default n + depends on BUSYBOX_CONFIG_LOGIN + help + The file /etc/nologin is used by (some versions of) login(1). + If it exists, non-root logins are prohibited. + config BUSYBOX_CONFIG_FEATURE_SECURETTY bool "Support for /etc/securetty" default n depends on BUSYBOX_CONFIG_LOGIN help - The file /etc/securetty is used by (some versions of) login(1). + The file /etc/securetty is used by (some versions of) login(1). The file contains the device names of tty lines (one per line, without leading /dev/) on which root is allowed to login. @@ -149,6 +181,20 @@ config BUSYBOX_CONFIG_FEATURE_PASSWD_WEAK_CHECK help With this option passwd will refuse new passwords which are "weak". +config BUSYBOX_CONFIG_CRYPTPW + bool "cryptpw" + default n + help + Applet for crypting a string. + +config BUSYBOX_CONFIG_CHPASSWD + bool "chpasswd" + default n + help + chpasswd reads a file of user name and password pairs from + standard input and uses this information to update a group of + existing users. + config BUSYBOX_CONFIG_SU bool "su" default n diff --git a/package/busybox/config/miscutils/Config.in b/package/busybox/config/miscutils/Config.in index 7784a82973..44f11a98d1 100644 --- a/package/busybox/config/miscutils/Config.in +++ b/package/busybox/config/miscutils/Config.in @@ -19,6 +19,13 @@ config BUSYBOX_CONFIG_BBCONFIG The bbconfig applet will print the config file with which busybox was built. +config BUSYBOX_CONFIG_CHRT + bool "chrt" + default n + help + manipulate real-time attributes of a process. + This requires sched_{g,s}etparam support in your libc. + config BUSYBOX_CONFIG_CROND bool "crond" default y @@ -256,19 +263,19 @@ config BUSYBOX_CONFIG_MAKEDEVS 'leaf' is traditionally what busybox follows, it allows multiple devices of a particluar type to be created per command. e.g. /dev/hda[0-9] - Device properties are passed as command line arguments. + Device properties are passed as command line arguments. . 'table' reads device properties from a file or stdin, allowing a batch of unrelated devices to be made with one command. - User/group names are allowed as an alternative to uid/gid. + User/group names are allowed as an alternative to uid/gid. choice prompt "Choose makedevs behaviour" - depends BUSYBOX_CONFIG_MAKEDEVS + depends on BUSYBOX_CONFIG_MAKEDEVS default BUSYBOX_CONFIG_FEATURE_MAKEDEVS_TABLE config BUSYBOX_CONFIG_FEATURE_MAKEDEVS_LEAF - bool "leaf" + bool "leaf" config BUSYBOX_CONFIG_FEATURE_MAKEDEVS_TABLE bool "table" @@ -289,12 +296,6 @@ config BUSYBOX_CONFIG_MT to advance or rewind a tape past a specified number of archive files on the tape. -config BUSYBOX_CONFIG_NMETER - bool "nmeter" - default n - help - nmeter prints various system parameters continuously. - config BUSYBOX_CONFIG_RAIDAUTORUN bool "raidautorun" default n @@ -303,11 +304,11 @@ config BUSYBOX_CONFIG_RAIDAUTORUN search and start RAID arrays. config BUSYBOX_CONFIG_READAHEAD - bool "readahead" + bool "readahead" default n - depends on LFS + depends on BUSYBOX_CONFIG_LFS help - Preload the files listed on the command line into RAM cache so that + Preload the files listed on the command line into RAM cache so that subsequent reads on these files will not block on disk I/O. This applet just calls the readahead(2) system call on each file. @@ -320,19 +321,19 @@ config BUSYBOX_CONFIG_READAHEAD run this applet as a background job. config BUSYBOX_CONFIG_RUNLEVEL - bool "runlevel" + bool "runlevel" default n help - find the current and previous system runlevel. + find the current and previous system runlevel. This applet uses utmp but does not rely on busybox supporing utmp on purpose. It is used by e.g. emdebian via /etc/init.d/rc. config BUSYBOX_CONFIG_RX - bool "rx" + bool "rx" default n help - Receive files using the Xmodem protocol. + Receive files using the Xmodem protocol. config BUSYBOX_CONFIG_STRINGS bool "strings" @@ -371,6 +372,14 @@ config BUSYBOX_CONFIG_TIME When the command finishes, time writes a message to standard output giving timing statistics about this program run. +config BUSYBOX_CONFIG_TTYSIZE + bool "ttysize" + default n + help + A replacement for "stty size". Unlike stty, can report only width, + only height, or both, in any order. It also does not complain on error, + but returns default 80x24. Usage in shell scripts: width=`ttysize w`. + config BUSYBOX_CONFIG_WATCHDOG bool "watchdog" default y diff --git a/package/busybox/config/modutils/Config.in b/package/busybox/config/modutils/Config.in index 9183145c5b..7ffca9384d 100644 --- a/package/busybox/config/modutils/Config.in +++ b/package/busybox/config/modutils/Config.in @@ -134,7 +134,7 @@ config BUSYBOX_CONFIG_FEATURE_CHECK_TAINTED_MODULE config BUSYBOX_CONFIG_FEATURE_2_4_MODULES # Simulate indentation bool "Support version 2.2.x to 2.4.x Linux kernels" - default y + default n depends on BUSYBOX_CONFIG_INSMOD || BUSYBOX_CONFIG_RMMOD || BUSYBOX_CONFIG_MODPROBE help Support module loading for 2.2.x and 2.4.x Linux kernels. diff --git a/package/busybox/config/networking/Config.in b/package/busybox/config/networking/Config.in index 6c88baf193..1da1dc56f2 100644 --- a/package/busybox/config/networking/Config.in +++ b/package/busybox/config/networking/Config.in @@ -12,17 +12,25 @@ config BUSYBOX_CONFIG_FEATURE_IPV6 Enable IPv6 support in busybox. This adds IPv6 support in the networking applets. +config BUSYBOX_CONFIG_VERBOSE_RESOLUTION_ERRORS + bool "Verbose resolution errors" + default y + help + Enable if you are not satisfied with simplistic + "can't resolve 'hostname.com'" and want to know more. + This may increase size of your executable a bit. + config BUSYBOX_CONFIG_ARP bool "arp" default n help - Manipulate the system ARP cache + Manipulate the system ARP cache. config BUSYBOX_CONFIG_ARPING bool "arping" default y help - Ping hosts by ARP packets + Ping hosts by ARP packets. config BUSYBOX_CONFIG_DNSD bool "dnsd" @@ -67,7 +75,7 @@ config BUSYBOX_CONFIG_HOSTNAME bool "hostname" default n help - Show or set the system's host name + Show or set the system's host name. config BUSYBOX_CONFIG_HTTPD bool "httpd" @@ -75,6 +83,14 @@ config BUSYBOX_CONFIG_HTTPD help Serve web pages via an HTTP server. +config BUSYBOX_CONFIG_FEATURE_HTTPD_USE_SENDFILE + bool "Use sendfile system call" + default y + depends on BUSYBOX_CONFIG_HTTPD + help + When enabled, httpd will use the kernel sendfile() function + instead of read/write loop. + config BUSYBOX_CONFIG_FEATURE_HTTPD_RELOAD_CONFIG_SIGHUP bool "Support reloading the global config file using hup signal" default y @@ -132,7 +148,7 @@ config BUSYBOX_CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR help This option enables support for running scripts through an interpreter. Turn this on if you want PHP scripts to work - properly. You need to supply an addition line in your httpd + properly. You need to supply an additional line in your httpd config file: *.php:/path/to/your/php @@ -154,6 +170,19 @@ config BUSYBOX_CONFIG_FEATURE_HTTPD_ENCODE_URL_STR For example, httpd -e "" as "<Hello World>". +config BUSYBOX_CONFIG_FEATURE_HTTPD_ERROR_PAGES + bool "Enable support for custom error pages" + default y + depends on BUSYBOX_CONFIG_HTTPD + help + This option allows you to define custom error pages in + the configuration file instead of the default HTTP status + error pages. For instance, if you add the line: + E404:/path/e404.html + in the config file, the server will respond the specified + '/path/e404.html' file instead of the terse '404 NOT FOUND' + message. + config BUSYBOX_CONFIG_IFCONFIG bool "ifconfig" default y @@ -204,7 +233,6 @@ config BUSYBOX_CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS config BUSYBOX_CONFIG_IFUPDOWN bool "ifupdown" default n - select BUSYBOX_CONFIG_RUN_PARTS help Activate or deactivate the specified interfaces. This applet makes use of either "ifconfig" and "route" or the "ip" command to actually @@ -215,8 +243,18 @@ config BUSYBOX_CONFIG_IFUPDOWN against my better judgement (since this will surely result in plenty of support questions on the mailing list), I do not force you to enable these additional options. It is up to you to supply either - "ifconfig" and "route" or the "ip" command, either via busybox or via - standalone utilities. + "ifconfig", "route" and "run-parts" or the "ip" command, either + via busybox or via standalone utilities. + +config BUSYBOX_CONFIG_IFUPDOWN_IFSTATE_PATH + string "Absolute path to ifstate file" + default "/var/run/ifstate" + help + ifupdown keeps state information in a file called ifstate. + Typically it is located in /var/run/ifstate, however + some distributions tend to put it in other places + (debian, for example, uses /etc/network/run/ifstate). + This config option defines location of ifstate. config BUSYBOX_CONFIG_FEATURE_IFUPDOWN_IP bool "Use ip applet" @@ -259,7 +297,7 @@ config BUSYBOX_CONFIG_FEATURE_IFUPDOWN_IPV4 default n depends on BUSYBOX_CONFIG_IFUPDOWN help - If you want busybox to talk IPv4, leave this on. + If you want ifup/ifdown to talk IPv4, leave this on. config BUSYBOX_CONFIG_FEATURE_IFUPDOWN_IPV6 bool "Enable support for IPv6" @@ -268,13 +306,14 @@ config BUSYBOX_CONFIG_FEATURE_IFUPDOWN_IPV6 help If you need support for IPv6, turn this option on. -config BUSYBOX_CONFIG_FEATURE_IFUPDOWN_IPX - bool "Enable support for IPX" - default n - depends on BUSYBOX_CONFIG_IFUPDOWN - help - If this option is selected you can use busybox to work with IPX - networks. +### UNUSED +### config FEATURE_IFUPDOWN_IPX +### bool "Enable support for IPX" +### default n +### depends on IFUPDOWN +### help +### If this option is selected you can use busybox to work with IPX +### networks. config BUSYBOX_CONFIG_FEATURE_IFUPDOWN_MAPPING bool "Enable mapping support" @@ -284,6 +323,16 @@ config BUSYBOX_CONFIG_FEATURE_IFUPDOWN_MAPPING This enables support for the "mapping" stanza, unless you have a weird network setup you don't need it. +config BUSYBOX_CONFIG_FEATURE_IFUPDOWN_EXTERNAL_DHCP + bool "Enable support for external dhcp clients" + default n + depends on BUSYBOX_CONFIG_IFUPDOWN + help + This enables support for the external dhcp clients. Clients are + tried in the following order: dhcpcd, dhclient, pump and udhcpc. + Otherwise, if udhcpc applet is enabled, it is used. + Otherwise, ifup/ifdown will have no support for DHCP. + config BUSYBOX_CONFIG_INETD bool "inetd" default n @@ -330,7 +379,7 @@ config BUSYBOX_CONFIG_FEATURE_INETD_RPC bool "Support RPC services" default n depends on BUSYBOX_CONFIG_INETD - depends on BUSYBOX_CONFIG_FEATURE_HAVE_RPC + select BUSYBOX_CONFIG_FEATURE_HAVE_RPC help Support Sun-RPC based services @@ -387,6 +436,7 @@ config BUSYBOX_CONFIG_FEATURE_IP_SHORT_FORMS ip link -> iplink ip route -> iproute ip tunnel -> iptunnel + ip rule -> iprule Say N unless you desparately need the short form of the ip object commands. @@ -466,7 +516,7 @@ config BUSYBOX_CONFIG_NETMSG simple program for sending udp broadcast messages config BUSYBOX_CONFIG_NC_SERVER - bool "Netcat server options (-lp)" + bool "Netcat server options (-l)" default n depends on BUSYBOX_CONFIG_NC help @@ -487,6 +537,14 @@ config BUSYBOX_CONFIG_NETSTAT help netstat prints information about the Linux networking subsystem. +config BUSYBOX_CONFIG_FEATURE_NETSTAT_WIDE + bool " Enable wide netstat output" + default y + depends on BUSYBOX_CONFIG_NETSTAT + help + Add support for wide columns. Useful when displaying IPv6 addresses + (-W option). + config BUSYBOX_CONFIG_NSLOOKUP bool "nslookup" default y @@ -500,27 +558,25 @@ config BUSYBOX_CONFIG_PING ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway. -config BUSYBOX_CONFIG_FEATURE_FANCY_PING - bool "Enable fancy ping output" - default y - depends on BUSYBOX_CONFIG_PING - help - Make the output from the ping applet include statistics, and at the - same time provide full support for ICMP packets. - config BUSYBOX_CONFIG_PING6 bool "ping6" default y - depends on BUSYBOX_CONFIG_FEATURE_IPV6 + depends on BUSYBOX_CONFIG_FEATURE_IPV6 && BUSYBOX_CONFIG_PING help This will give you a ping that can talk IPv6. -config BUSYBOX_CONFIG_FEATURE_FANCY_PING6 - bool "Enable fancy ping6 output" +config BUSYBOX_CONFIG_PSCAN + bool "pscan" + default n + help + Simple network port scanner. + +config BUSYBOX_CONFIG_FEATURE_FANCY_PING + bool "Enable fancy ping output" default y - depends on BUSYBOX_CONFIG_PING6 + depends on BUSYBOX_CONFIG_PING help - Make the output from the ping6 applet include statistics, and at the + Make the output from the ping applet include statistics, and at the same time provide full support for ICMP packets. config BUSYBOX_CONFIG_ROUTE @@ -529,6 +585,12 @@ config BUSYBOX_CONFIG_ROUTE help Route displays or manipulates the kernel's IP routing tables. +config BUSYBOX_CONFIG_SLATTACH + bool "slattach" + default n + help + slattach is a small utility to attach network interfaces to serial lines. + config BUSYBOX_CONFIG_TELNET bool "telnet" default y @@ -703,13 +765,6 @@ config BUSYBOX_CONFIG_FEATURE_WGET_AUTHENTICATION help Support authenticated HTTP transfers. -config BUSYBOX_CONFIG_FEATURE_WGET_IP6_LITERAL - bool "Enable IPv6 literal addresses" - default y - depends on BUSYBOX_CONFIG_WGET && BUSYBOX_CONFIG_FEATURE_IPV6 - help - Support IPv6 address literal notation in URLs. - config BUSYBOX_CONFIG_FEATURE_WGET_LONG_OPTIONS bool "Enable long options" default y diff --git a/package/busybox/config/networking/udhcp/Config.in b/package/busybox/config/networking/udhcp/Config.in index 04a2ada170..65462efee7 100644 --- a/package/busybox/config/networking/udhcp/Config.in +++ b/package/busybox/config/networking/udhcp/Config.in @@ -32,6 +32,16 @@ config BUSYBOX_CONFIG_APP_DUMPLEASES See http://udhcp.busybox.net for further details. +config BUSYBOX_CONFIG_FEATURE_UDHCPD_WRITE_LEASES_EARLY + bool "Rewrite the lease file at every new acknowledge" + default n + depends on BUSYBOX_CONFIG_APP_UDHCPD + help + If selected, udhcpd will write a new file with leases every + time a new lease has been accepted, thus eleminating the need + to send SIGUSR1 for the initial writing, or updating. Any timed + rewriting remains undisturbed + config BUSYBOX_CONFIG_APP_UDHCPC bool "udhcp Client (udhcpc)" default y @@ -44,17 +54,6 @@ config BUSYBOX_CONFIG_APP_UDHCPC See http://udhcp.busybox.net for further details. -config BUSYBOX_CONFIG_FEATURE_UDHCP_SYSLOG - bool "Log udhcp messages to syslog" - default n - depends on BUSYBOX_CONFIG_APP_UDHCPD || BUSYBOX_CONFIG_APP_UDHCPC - select BUSYBOX_CONFIG_FEATURE_SYSLOG - help - If not daemonized, udhcpd prints its messages to stdout/stderr. - If this option is selected, it will also log them to syslog. - - See http://udhcp.busybox.net for further details. - config BUSYBOX_CONFIG_FEATURE_UDHCP_DEBUG bool "Compile udhcp with noisy debugging messages" default n @@ -65,3 +64,11 @@ config BUSYBOX_CONFIG_FEATURE_UDHCP_DEBUG the background. See http://udhcp.busybox.net for further details. + +config BUSYBOX_CONFIG_FEATURE_RFC3397 + bool "Support for RFC3397 domain search (experimental)" + default y + depends on BUSYBOX_CONFIG_APP_UDHCPD || BUSYBOX_CONFIG_APP_UDHCPC + help + If selected, both client and server will support passing of domain + search lists via option 119, specified in RFC3397. diff --git a/package/busybox/config/procps/Config.in b/package/busybox/config/procps/Config.in index ef0c6a2dcd..cd063dbf0b 100644 --- a/package/busybox/config/procps/Config.in +++ b/package/busybox/config/procps/Config.in @@ -43,6 +43,12 @@ config BUSYBOX_CONFIG_KILLALL5 default y depends on BUSYBOX_CONFIG_KILL +config BUSYBOX_CONFIG_NMETER + bool "nmeter" + default n + help + Prints selected system stats continuously, one line per update. + config BUSYBOX_CONFIG_PIDOF bool "pidof" default y @@ -74,7 +80,7 @@ config BUSYBOX_CONFIG_PS config BUSYBOX_CONFIG_FEATURE_PS_WIDE bool "Enable argument for wide output (-w)" - default y + default n depends on BUSYBOX_CONFIG_PS help Support argument 'w' for wide output. @@ -102,11 +108,25 @@ config BUSYBOX_CONFIG_TOP system. config BUSYBOX_CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE - bool "Support showing CPU usage percentage (add 2k bytes)" + bool "Show CPU per-process usage percentage (adds 2k bytes)" default y depends on BUSYBOX_CONFIG_TOP help - Make top display CPU usage. + Make top display CPU usage for each process. + +config BUSYBOX_CONFIG_FEATURE_TOP_CPU_GLOBAL_PERCENTS + bool "Show CPU global usage percentage (adds 0.5k bytes)" + default y + depends on BUSYBOX_CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE + help + Makes top display "CPU: NN% usr NN% sys..." line. + +config BUSYBOX_CONFIG_FEATURE_TOP_DECIMALS + bool "Show 1/10th of a percent in CPU/mem statistics (adds 0.3k bytes)" + default n + depends on BUSYBOX_CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE + help + Show 1/10th of a percent in CPU/mem statistics. config BUSYBOX_CONFIG_UPTIME bool "uptime" @@ -116,6 +136,14 @@ config BUSYBOX_CONFIG_UPTIME the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes. +config BUSYBOX_CONFIG_WATCH + bool "watch" + default n + #huh?? select DATE + help + watch is used to execute a program periodically, showing + output to the screen. + endmenu diff --git a/package/busybox/config/selinux/Config.in b/package/busybox/config/selinux/Config.in new file mode 100644 index 0000000000..907c9753ec --- /dev/null +++ b/package/busybox/config/selinux/Config.in @@ -0,0 +1,108 @@ +# +# For a description of the syntax of this configuration file, +# see scripts/kbuild/config-language.txt. +# + +menu "Selinux Utilities" + depends on BUSYBOX_CONFIG_SELINUX + +config BUSYBOX_CONFIG_CHCON + bool "chcon" + default n + depends on BUSYBOX_CONFIG_SELINUX + help + Enable support to change the security context of file. + +config BUSYBOX_CONFIG_FEATURE_CHCON_LONG_OPTIONS + bool "Enable long options" + default n + depends on BUSYBOX_CONFIG_CHCON && BUSYBOX_CONFIG_GETOPT_LONG + help + Support long options for the chcon applet. + +config BUSYBOX_CONFIG_GETENFORCE + bool "getenforce" + default n + depends on BUSYBOX_CONFIG_SELINUX + help + Enable support to get the current mode of SELinux. + +config BUSYBOX_CONFIG_GETSEBOOL + bool "getsebool" + default n + depends on BUSYBOX_CONFIG_SELINUX + help + Enable support to get SELinux boolean values. + +config BUSYBOX_CONFIG_LOAD_POLICY + bool "load_policy" + default n + depends on BUSYBOX_CONFIG_SELINUX + help + Enable support to load SELinux policy. + +config BUSYBOX_CONFIG_MATCHPATHCON + bool "matchpathcon" + default n + depends on BUSYBOX_CONFIG_SELINUX + help + Enable support to get default security context of the + specified path from the file contexts configuration. + +config BUSYBOX_CONFIG_RESTORECON + bool "restorecon" + default n + depends on BUSYBOX_CONFIG_SELINUX + help + Enable support to relabel files. The feature is almost + the same as setfiles, but usage is a little different. + +config BUSYBOX_CONFIG_RUNCON + bool "runcon" + default n + depends on BUSYBOX_CONFIG_SELINUX + help + Enable support to run command in speficied security context. + +config BUSYBOX_CONFIG_FEATURE_RUNCON_LONG_OPTIONS + bool "Enable long options" + default n + depends on BUSYBOX_CONFIG_RUNCON && BUSYBOX_CONFIG_GETOPT_LONG + help + Support long options for the runcon applet. + +config BUSYBOX_CONFIG_SELINUXENABLED + bool "selinuxenabled" + default n + depends on BUSYBOX_CONFIG_SELINUX + help + Enable support for this command to be used within shell scripts + to determine if selinux is enabled. + +config BUSYBOX_CONFIG_SETENFORCE + bool "setenforce" + default n + depends on BUSYBOX_CONFIG_SELINUX + help + Enable support to modify the mode SELinux is running in. + +config BUSYBOX_CONFIG_SETFILES + bool "setfiles" + default n + depends on BUSYBOX_CONFIG_SELINUX + help + Enable support to modify to relabel files. + Notice: If you built libselinux with -D_FILE_OFFSET_BITS=64, + (It is default in libselinux's Makefile), you _must_ enable + CONFIG_LFS. + +config BUSYBOX_CONFIG_FEATURE_SETFILES_CHECK_OPTION + bool "Enable check option" + default n + depends on BUSYBOX_CONFIG_SETFILES + help + Support "-c" option (check the validity of the contexts against + the specified binary policy) for setfiles. Requires libsepol. + +endmenu + diff --git a/package/busybox/config/shell/Config.in b/package/busybox/config/shell/Config.in index d4cd52dade..d2b1056615 100644 --- a/package/busybox/config/shell/Config.in +++ b/package/busybox/config/shell/Config.in @@ -87,7 +87,7 @@ config BUSYBOX_CONFIG_ASH_MATH_SUPPORT config BUSYBOX_CONFIG_ASH_MATH_SUPPORT_64 bool "Extend Posix math support to 64 bit" - default n + default y depends on BUSYBOX_CONFIG_ASH_MATH_SUPPORT help Enable 64-bit math support in the ash shell. This will make @@ -107,7 +107,7 @@ config BUSYBOX_CONFIG_ASH_BUILTIN_ECHO select BUSYBOX_CONFIG_ECHO depends on BUSYBOX_CONFIG_ASH help - Enable support for echo, built in to ash. + Enable support for echo, builtin to ash. config BUSYBOX_CONFIG_ASH_BUILTIN_TEST bool "Builtin version of 'test'" @@ -115,7 +115,7 @@ config BUSYBOX_CONFIG_ASH_BUILTIN_TEST select BUSYBOX_CONFIG_TEST depends on BUSYBOX_CONFIG_ASH help - Enable support for test, built in to ash. + Enable support for test, builtin to ash. config BUSYBOX_CONFIG_ASH_CMDCMD bool "'command' command to override shell builtins" @@ -135,7 +135,7 @@ config BUSYBOX_CONFIG_ASH_MAIL config BUSYBOX_CONFIG_ASH_OPTIMIZE_FOR_SIZE bool "Optimize for size instead of speed" - default y + default n depends on BUSYBOX_CONFIG_ASH help Compile ash for reduced size at the price of speed. @@ -153,7 +153,7 @@ config BUSYBOX_CONFIG_ASH_RANDOM_SUPPORT config BUSYBOX_CONFIG_ASH_EXPAND_PRMT bool "Expand prompt string" - default n + default y depends on BUSYBOX_CONFIG_ASH help "PS#" may be contain volatile content, such as backquote commands. @@ -176,6 +176,54 @@ config BUSYBOX_CONFIG_HUSH word ), arithmetic expansion, aliases, brace expansion, tilde expansion, &> and >& redirection of stdout+stderr, etc. +config BUSYBOX_CONFIG_HUSH_HELP + bool "help builtin" + default n + depends on BUSYBOX_CONFIG_HUSH + help + Enable help builtin in hush. Code size + ~1 kbyte. + +config BUSYBOX_CONFIG_HUSH_INTERACTIVE + bool "Interactive mode" + default n + depends on BUSYBOX_CONFIG_HUSH + help + Enable interactive mode (prompt and command editing). + Without this, hush simply reads and executes commands + from stdin just like a shell script from the file. + No prompt, no PS1/PS2 magic shell variables. + +config BUSYBOX_CONFIG_HUSH_JOB + bool "Job control" + default n + depends on BUSYBOX_CONFIG_HUSH_INTERACTIVE + help + Enable job control: Ctrl-Z backgrounds, Ctrl-C interrupts current + command (not entire shell), fg/bg builtins work. Without this option, + "cmd &" still works by simply spawning a process and immediately + prompting for next command (or executing next command in a script), + but no separate process group is formed. + +config BUSYBOX_CONFIG_HUSH_TICK + bool "Process substitution" + default n + depends on BUSYBOX_CONFIG_HUSH + help + Enable process substitution `command` and $(command) in hush. + +config BUSYBOX_CONFIG_HUSH_IF + bool "Support if/then/elif/else/fi" + default n + depends on BUSYBOX_CONFIG_HUSH + help + Enable if/then/elif/else/fi in hush. + +config BUSYBOX_CONFIG_HUSH_LOOPS + bool "Support for, while and until loops" + default n + depends on BUSYBOX_CONFIG_HUSH + help + Enable for, while and until loops in hush. config BUSYBOX_CONFIG_LASH bool "lash" @@ -216,12 +264,12 @@ config BUSYBOX_CONFIG_FEATURE_SH_EXTRA_QUIET help Remove the busybox introduction when starting a shell. -config BUSYBOX_CONFIG_FEATURE_SH_STANDALONE_SHELL +config BUSYBOX_CONFIG_FEATURE_SH_STANDALONE bool "Standalone shell" default n - depends on BUSYBOX_CONFIG_MSH || BUSYBOX_CONFIG_LASH || BUSYBOX_CONFIG_HUSH || BUSYBOX_CONFIG_ASH + depends on (BUSYBOX_CONFIG_MSH || BUSYBOX_CONFIG_LASH || BUSYBOX_CONFIG_HUSH || BUSYBOX_CONFIG_ASH) && BUSYBOX_CONFIG_FEATURE_PREFER_APPLETS help - This option causes the selected busybox shell to use busybox applets + This option causes busybox shells to use busybox applets in preference to executables in the PATH whenever possible. For example, entering the command 'ifconfig' into the shell would cause busybox to use the ifconfig busybox applet. Specifying the fully @@ -230,66 +278,43 @@ config BUSYBOX_CONFIG_FEATURE_SH_STANDALONE_SHELL is generally used when creating a statically linked version of busybox for use as a rescue shell, in the event that you screw up your system. - Note that this will *also* cause applets to take precedence - over shell builtins of the same name. So turning this on will - eliminate any performance gained by turning on the builtin "echo" - and "test" commands in ash. - - Note that when using this option, the shell will attempt to directly - run '/bin/busybox'. If you do not have the busybox binary sitting in - that exact location with that exact name, this option will not work at - all. - -config BUSYBOX_CONFIG_FEATURE_COMMAND_EDITING - bool "Command line editing" - default y - depends on BUSYBOX_CONFIG_MSH || BUSYBOX_CONFIG_LASH || BUSYBOX_CONFIG_HUSH || BUSYBOX_CONFIG_ASH - help - Enable command editing in shell. - -config BUSYBOX_CONFIG_FEATURE_COMMAND_EDITING_VI - bool "vi-style line editing commands" + This is implemented by re-execing /proc/self/exe (typically) + with right parameters. Some selected applets ("NOFORK" applets) + can even be executed without creating new process. + Instead, busybox will call _main() internally. + + However, this causes problems in chroot jails without mounted /proc + and with ps/top (command name can be shown as 'exe' for applets + started this way). +# untrue? +# Note that this will *also* cause applets to take precedence +# over shell builtins of the same name. So turning this on will +# eliminate any performance gained by turning on the builtin "echo" +# and "test" commands in ash. +# untrue? +# Note that when using this option, the shell will attempt to directly +# run '/bin/busybox'. If you do not have the busybox binary sitting in +# that exact location with that exact name, this option will not work at +# all. + +config BUSYBOX_CONFIG_CTTYHACK + bool "cttyhack" default n - depends on BUSYBOX_CONFIG_FEATURE_COMMAND_EDITING help - Enable vi-style line editing in the shell. This mode can be - turned on and off with "set -o vi" and "set +o vi". - -config BUSYBOX_CONFIG_FEATURE_COMMAND_HISTORY - int "History size" - range 0 99999 - default 15 - depends on BUSYBOX_CONFIG_FEATURE_COMMAND_EDITING - help - Specify command history size in shell. + One common problem reported on the mailing list is "can't access tty; + job control turned off" error message which typically appears when + one tries to use shell with stdin/stdout opened to /dev/console. + This device is special - it cannot be a controlling tty. -config BUSYBOX_CONFIG_FEATURE_COMMAND_SAVEHISTORY - bool "History saving" - default n - depends on BUSYBOX_CONFIG_ASH && BUSYBOX_CONFIG_FEATURE_COMMAND_EDITING - help - Enable history saving in ash shell. - -config BUSYBOX_CONFIG_FEATURE_COMMAND_TAB_COMPLETION - bool "Tab completion" - default y - depends on BUSYBOX_CONFIG_FEATURE_COMMAND_EDITING - help - Enable tab completion in shell. + Proper solution is to use correct device instead of /dev/console. -config BUSYBOX_CONFIG_FEATURE_COMMAND_USERNAME_COMPLETION - bool "Username completion" - default n - depends on BUSYBOX_CONFIG_FEATURE_COMMAND_TAB_COMPLETION - help - Enable username completion in shell. + cttyhack provides "quick and dirty" solution to this problem. + It analyzes stdin with various ioctls, trying to determine whether + it is a /dev/ttyN or /dev/ttySN (virtual terminal or serial line). + If it detects one, it closes stdin/out/err and reopens that device. + Then it executes given program. Usage example for /etc/inittab + (for busybox init): -config BUSYBOX_CONFIG_FEATURE_SH_FANCY_PROMPT - bool "Fancy shell prompts" - default y - depends on BUSYBOX_CONFIG_FEATURE_COMMAND_EDITING - help - Setting this option allows for prompts to use things like \w and - \$ and also using escape codes. + ::respawn:/bin/cttyhack /bin/sh endmenu diff --git a/package/busybox/config/sysklogd/Config.in b/package/busybox/config/sysklogd/Config.in index 12e08d3a93..9eebd77430 100644 --- a/package/busybox/config/sysklogd/Config.in +++ b/package/busybox/config/sysklogd/Config.in @@ -59,6 +59,7 @@ config BUSYBOX_CONFIG_FEATURE_IPC_SYSLOG config BUSYBOX_CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE int " Circular buffer size in Kbytes (minimum 4KB)" default 16 + range 4 2147483647 depends on BUSYBOX_CONFIG_FEATURE_IPC_SYSLOG help This option sets the size of the circular buffer @@ -88,8 +89,6 @@ config BUSYBOX_CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING config BUSYBOX_CONFIG_KLOGD bool "klogd" default y - depends on BUSYBOX_CONFIG_SYSLOGD - select BUSYBOX_CONFIG_FEATURE_SYSLOG help klogd is a utility which intercepts and logs all messages from the Linux kernel and sends the messages diff --git a/package/busybox/config/util-linux/Config.in b/package/busybox/config/util-linux/Config.in index ab3dc3731d..28dc7b7fdb 100644 --- a/package/busybox/config/util-linux/Config.in +++ b/package/busybox/config/util-linux/Config.in @@ -127,7 +127,7 @@ config BUSYBOX_CONFIG_FEATURE_SGI_LABEL config BUSYBOX_CONFIG_FEATURE_SUN_LABEL bool "Support SUN disklabels" default n - depends on BUSYBOX_CONFIG_FDISK && BUSYBOX_CONFIG_FEATURE_FDISK_WRITABLE + depends on BUSYBOX_CONFIG_FDISK && BUSYBOX_CONFIG_FEATURE_FDISK_WRITABLE help Enabling this option allows you to create or change SUN disklabels. Most people can safely leave this option disabled. @@ -181,7 +181,7 @@ config BUSYBOX_CONFIG_MKFS_MINIX this utility will do the job for you. comment "Minix filesystem support" - depends on BUSYBOX_CONFIG_FSCK_MINIX || BUSYBOX_CONFIG_MKFS_MINIX + depends on BUSYBOX_CONFIG_FSCK_MINIX || BUSYBOX_CONFIG_MKFS_MINIX config BUSYBOX_CONFIG_FEATURE_MINIX2 bool "Support Minix fs v2 (fsck_minix/mkfs_minix)" @@ -269,46 +269,41 @@ config BUSYBOX_CONFIG_MDEV bool "mdev" default n help - mdev is a mini-udev implementation: call it with -s to populate - /dev from /sys, then "echo /sbin/mdev > /proc/sys/kernel/hotplug" to - have it handle hotplug events afterwards. Device names are taken - from sysfs. + mdev is a mini-udev implementation for dynamically creating device + nodes in the /dev directory. + + For more information, please see docs/mdev.txt config BUSYBOX_CONFIG_FEATURE_MDEV_CONF bool "Support /etc/mdev.conf" default n depends on BUSYBOX_CONFIG_MDEV help - The mdev config file contains lines that look like: - - hd[a-z][0-9]* 0:3 660 - - That's device name (with regex match), uid:gid, and permissions. + Add support for the mdev config file to control ownership and + permissions of the device nodes. - Config file parsing stops on the first matching line. If no config - entry is matched, devices are created with default 0:0 660. (Make - the last line match .* to override this.) + For more information, please see docs/mdev.txt config BUSYBOX_CONFIG_FEATURE_MDEV_EXEC bool "Support command execution at device addition/removal" default n depends on BUSYBOX_CONFIG_FEATURE_MDEV_CONF help - This adds support for an optional field to /etc/mdev.conf, consisting - of a special character and a command line to run after creating the - corresponding device(s) and before removing, ala: + This adds support for an optional field to /etc/mdev.conf for + executing commands when devices are created/removed. - hdc root:cdrom 660 *ln -s $MDEV cdrom + For more information, please see docs/mdev.txt - The $MDEV environment variable is set to the name of the device. - - The special characters and their meanings are: - @ Run after creating the device. - $ Run before removing the device. - * Run both after creating and before removing the device. +config BUSYBOX_CONFIG_FEATURE_MDEV_LOAD_FIRMWARE + bool "Support loading of firmwares" + default n + depends on BUSYBOX_CONFIG_MDEV + help + Some devices need to load firmware before they can be usable. - Commands are executed via system() so you need /bin/sh, meaning you - probably want to select a default shell in the Shells menu. + These devices will request userspace look up the files in + /lib/firmware/ and if it exists, send it to the kernel for + loading into the hardware. config BUSYBOX_CONFIG_MKSWAP bool "mkswap" @@ -369,7 +364,7 @@ config BUSYBOX_CONFIG_FEATURE_MOUNT_NFS bool "Support mounting NFS file systems" default y depends on BUSYBOX_CONFIG_MOUNT - depends on BUSYBOX_CONFIG_FEATURE_HAVE_RPC + select BUSYBOX_CONFIG_FEATURE_HAVE_RPC select BUSYBOX_CONFIG_FEATURE_SYSLOG help Enable mounting of NFS file systems. @@ -495,7 +490,7 @@ config BUSYBOX_CONFIG_FEATURE_MOUNT_LOOP The umount command will also free that loopback device. You can still use the 'losetup' utility (to manually associate files - with loop devices) if you need to do something advanced, such as + with loop devices) if you need to do something advanced, such as specify an offset or cryptographic options to the loopback device. (If you don't want umount to free the loop device, use "umount -D".) diff --git a/package/busybox/patches/000-autoconf.patch b/package/busybox/patches/000-autoconf.patch index d19cf0ce53..52fd92a631 100644 --- a/package/busybox/patches/000-autoconf.patch +++ b/package/busybox/patches/000-autoconf.patch @@ -1,12 +1,13 @@ -Index: busybox-1.4.2/applets/Kbuild +Index: busybox-1.7.2/applets/Kbuild =================================================================== ---- busybox-1.4.2.orig/applets/Kbuild 2007-06-04 13:21:32.429046704 +0200 -+++ busybox-1.4.2/applets/Kbuild 2007-06-04 13:21:32.495036672 +0200 -@@ -10,6 +10,7 @@ +--- busybox-1.7.2.orig/applets/Kbuild 2007-10-04 14:30:23.484330073 +0200 ++++ busybox-1.7.2/applets/Kbuild 2007-10-04 14:33:47.751970627 +0200 +@@ -20,6 +20,6 @@ + HOSTCFLAGS_usage.o = -I$(srctree)/include - # Generated file needs additional love - -+applets/usage: include/autoconf.h - applets/applets.o: include/usage_compressed.h - - hostprogs-y += usage + applets/applets.o: include/usage_compressed.h +-applets/usage: .config $(srctree)/applets/usage_compressed +-include/usage_compressed.h: applets/usage $(srctree)/applets/usage_compressed ++applets/usage: .config $(srctree)/applets/usage_compressed include/autoconf.h ++include/usage_compressed.h: applets/usage $(srctree)/applets/usage_compressed include/autoconf.h + $(call cmd,gen_usage_compressed) diff --git a/package/busybox/patches/110-wget_getopt_fix.patch b/package/busybox/patches/110-wget_getopt_fix.patch index fd530df9d3..657f83a71a 100644 --- a/package/busybox/patches/110-wget_getopt_fix.patch +++ b/package/busybox/patches/110-wget_getopt_fix.patch @@ -1,13 +1,13 @@ -Index: busybox-1.4.2/networking/wget.c +Index: busybox-1.7.2/networking/wget.c =================================================================== ---- busybox-1.4.2.orig/networking/wget.c 2007-06-04 13:21:32.408049896 +0200 -+++ busybox-1.4.2/networking/wget.c 2007-06-04 13:21:32.681008400 +0200 -@@ -136,7 +136,7 @@ - { "directory-prefix", required_argument, NULL, 'P' }, - { "proxy", required_argument, NULL, 'Y' }, - { "user-agent", required_argument, NULL, 'U' }, -- { "passive-ftp", no_argument, NULL, 0xff }, -+ { "passive-ftp", no_argument, NULL, 0xfd }, - { "header", required_argument, NULL, 0xfe }, - { 0, 0, 0, 0 } - }; +--- busybox-1.7.2.orig/networking/wget.c 2007-10-04 14:35:17.057059834 +0200 ++++ busybox-1.7.2/networking/wget.c 2007-10-04 14:35:27.013627222 +0200 +@@ -140,7 +140,7 @@ + "directory-prefix\0" Required_argument "P" + "proxy\0" Required_argument "Y" + "user-agent\0" Required_argument "U" +- "passive-ftp\0" No_argument "\xff" ++ "passive-ftp\0" No_argument "\xfd" + "header\0" Required_argument "\xfe" + ; + applet_long_options = wget_longopts; diff --git a/package/busybox/patches/130-drop_werror.patch b/package/busybox/patches/130-drop_werror.patch deleted file mode 100644 index cd3a67b5d8..0000000000 --- a/package/busybox/patches/130-drop_werror.patch +++ /dev/null @@ -1,13 +0,0 @@ -Index: busybox-1.4.2/Makefile.flags -=================================================================== ---- busybox-1.4.2.orig/Makefile.flags 2007-06-04 13:21:32.387053088 +0200 -+++ busybox-1.4.2/Makefile.flags 2007-06-04 13:21:32.871979368 +0200 -@@ -16,7 +16,7 @@ - -D"BB_VER=KBUILD_STR($(BB_VER))" -DBB_BT=AUTOCONF_TIMESTAMP - - CFLAGS += \ -- -Wall -Wstrict-prototypes -Wshadow -Werror -Wundef \ -+ -Wall -Wstrict-prototypes -Wshadow -Wundef \ - -funsigned-char -fno-builtin-strlen -finline-limit=0 -static-libgcc \ - -Os -falign-functions=1 -falign-jumps=1 -falign-loops=1 \ - -fomit-frame-pointer -ffunction-sections -fdata-sections diff --git a/package/busybox/patches/243-udhcpc_changed_ifindex.patch b/package/busybox/patches/243-udhcpc_changed_ifindex.patch index 3a9517418f..b304604232 100644 --- a/package/busybox/patches/243-udhcpc_changed_ifindex.patch +++ b/package/busybox/patches/243-udhcpc_changed_ifindex.patch @@ -1,9 +1,9 @@ -Index: busybox-1.4.2/networking/udhcp/dhcpc.c +Index: busybox-1.7.2/networking/udhcp/dhcpc.c =================================================================== ---- busybox-1.4.2.orig/networking/udhcp/dhcpc.c 2007-07-18 10:07:20.161035443 +0200 -+++ busybox-1.4.2/networking/udhcp/dhcpc.c 2007-07-18 10:09:15.515609124 +0200 -@@ -273,6 +273,12 @@ - tv.tv_sec = timeout - uptime(); +--- busybox-1.7.2.orig/networking/udhcp/dhcpc.c 2007-10-04 14:36:41.521873204 +0200 ++++ busybox-1.7.2/networking/udhcp/dhcpc.c 2007-10-04 14:38:28.231954268 +0200 +@@ -309,6 +309,12 @@ + jump_in: tv.tv_usec = 0; + /* When running on a bridge, the ifindex may have changed (e.g. if @@ -12,6 +12,6 @@ Index: busybox-1.4.2/networking/udhcp/dhcpc.c + * Workaround: refresh it here before processing the next packet */ + read_interface(client_config.interface, &client_config.ifindex, NULL, client_config.arp); + - if (listen_mode != LISTEN_NONE && fd < 0) { + if (listen_mode != LISTEN_NONE && sockfd < 0) { if (listen_mode == LISTEN_KERNEL) - fd = listen_socket(INADDR_ANY, CLIENT_PORT, client_config.interface); + sockfd = listen_socket(/*INADDR_ANY,*/ CLIENT_PORT, client_config.interface); diff --git a/package/busybox/patches/250-ash_export-n.patch b/package/busybox/patches/250-ash_export-n.patch index b5a8794f5a..8ee2aee5ef 100644 --- a/package/busybox/patches/250-ash_export-n.patch +++ b/package/busybox/patches/250-ash_export-n.patch @@ -1,37 +1,37 @@ -Index: busybox-1.4.2/shell/ash.c +Index: busybox-1.7.2/shell/ash.c =================================================================== ---- busybox-1.4.2.orig/shell/ash.c 2007-06-04 13:21:32.248074216 +0200 -+++ busybox-1.4.2/shell/ash.c 2007-06-04 13:21:34.000807760 +0200 -@@ -12237,9 +12237,18 @@ +--- busybox-1.7.2.orig/shell/ash.c 2007-09-03 13:48:38.000000000 +0200 ++++ busybox-1.7.2/shell/ash.c 2007-10-04 14:47:41.607489342 +0200 +@@ -11310,8 +11310,18 @@ const char *p; char **aptr; int flag = argv[0][0] == 'r'? VREADONLY : VEXPORT; + int mask = ~0; - int notp; ++ int nopt; -- notp = nextopt("p") - 'p'; -+ while ((notp = nextopt("np"))) { -+ if (notp == 'n') { +- if (nextopt("p") != 'p') { ++ while ((nopt = nextopt("np"))) { ++ if (nopt == 'n') { + mask = ~flag; + } else { /* p */ + break; + } + } + -+ notp -= 'p'; - if (notp && ((name = *(aptr = argptr)))) { - do { - if ((p = strchr(name, '=')) != NULL) { -@@ -12247,10 +12256,11 @@ - } else { - if ((vp = *findvar(hashvar(name), name))) { - vp->flags |= flag; -+ vp->flags &= mask; - continue; ++ if (nopt != 'p') { + aptr = argptr; + name = *aptr; + if (name) { +@@ -11323,10 +11333,11 @@ + vp = *findvar(hashvar(name), name); + if (vp) { + vp->flags |= flag; ++ vp->flags &= mask; + continue; + } } - } -- setvar(name, p, flag); -+ setvar(name, p, flag & mask); - } while ((name = *++aptr) != NULL); - } else { - showvars(argv[0], flag, 0); +- setvar(name, p, flag); ++ setvar(name, p, flag & mask); + } while ((name = *++aptr) != NULL); + return 0; + } diff --git a/package/busybox/patches/260-broadcast_plus.patch b/package/busybox/patches/260-broadcast_plus.patch deleted file mode 100644 index 60b2afc242..0000000000 --- a/package/busybox/patches/260-broadcast_plus.patch +++ /dev/null @@ -1,29 +0,0 @@ -Index: busybox-1.4.2/networking/ifconfig.c -=================================================================== ---- busybox-1.4.2.orig/networking/ifconfig.c 2007-06-29 02:03:17.046772952 +0200 -+++ busybox-1.4.2/networking/ifconfig.c 2007-06-29 02:03:49.938772608 +0200 -@@ -376,18 +376,18 @@ - #endif - sai.sin_family = AF_INET; - sai.sin_port = 0; -- if (!strcmp(host, bb_str_default)) { -- /* Default is special, meaning 0.0.0.0. */ -- sai.sin_addr.s_addr = INADDR_ANY; -- } - #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS -- else if ((host[0] == '+' && !host[1]) && (mask & A_BROADCAST) -+ if ((host[0] == '+' && !host[1]) && (mask & A_BROADCAST) - && (did_flags & (A_NETMASK|A_HOSTNAME)) == (A_NETMASK|A_HOSTNAME) - ) { - /* + is special, meaning broadcast is derived. */ - sai.sin_addr.s_addr = (~sai_netmask) | (sai_hostname & sai_netmask); -- } -+ } else - #endif -+ if (!strcmp(host, bb_str_default)) { -+ /* Default is special, meaning 0.0.0.0. */ -+ sai.sin_addr.s_addr = INADDR_ANY; -+ } - #if ENABLE_FEATURE_IPV6 - else if (inet_pton(AF_INET6, host, &sai6.sin6_addr) > 0) { - int sockfd6; diff --git a/package/busybox/patches/270-ash_performance.patch b/package/busybox/patches/270-ash_performance.patch deleted file mode 100644 index eff7a5bb11..0000000000 --- a/package/busybox/patches/270-ash_performance.patch +++ /dev/null @@ -1,30 +0,0 @@ -Index: busybox-1.4.2/shell/ash.c -=================================================================== ---- busybox-1.4.2.orig/shell/ash.c 2007-07-01 05:33:08.371737750 +0200 -+++ busybox-1.4.2/shell/ash.c 2007-07-01 05:33:11.703946000 +0200 -@@ -3957,12 +3957,6 @@ - } - #endif - -- if (is_safe_applet(name)) { -- entry->cmdtype = CMDNORMAL; -- entry->u.index = -1; -- return; -- } -- - updatetbl = (path == pathval()); - if (!updatetbl) { - act |= DO_ALTPATH; -@@ -4074,6 +4068,12 @@ - goto success; - } - -+ if (is_safe_applet(name)) { -+ entry->cmdtype = CMDNORMAL; -+ entry->u.index = -1; -+ return; -+ } -+ - /* We failed. If there was an entry for this command, delete it */ - if (cmdp && updatetbl) - delete_cmd_entry(); diff --git a/package/busybox/patches/280-printf.patch b/package/busybox/patches/280-printf.patch deleted file mode 100644 index d8442dc575..0000000000 --- a/package/busybox/patches/280-printf.patch +++ /dev/null @@ -1,18 +0,0 @@ -Index: busybox-1.4.2/coreutils/printf.c -=================================================================== ---- busybox-1.4.2.orig/coreutils/printf.c 2007-07-09 03:00:31.808788500 +0200 -+++ busybox-1.4.2/coreutils/printf.c 2007-07-09 03:00:42.257441500 +0200 -@@ -60,11 +60,11 @@ - - static void conv_strtoul(char *arg, void *result) - { -- *(unsigned long*)result = bb_strtoul(arg, NULL, 10); -+ *(unsigned long*)result = bb_strtoul(arg, NULL, 0); - } - static void conv_strtol(char *arg, void *result) - { -- *(long*)result = bb_strtol(arg, NULL, 10); -+ *(long*)result = bb_strtol(arg, NULL, 0); - } - static void conv_strtod(char *arg, void *result) - { diff --git a/package/busybox/patches/310-passwd_access.patch b/package/busybox/patches/310-passwd_access.patch index 22e6abcb01..b8c8db7387 100644 --- a/package/busybox/patches/310-passwd_access.patch +++ b/package/busybox/patches/310-passwd_access.patch @@ -1,19 +1,19 @@ Copyright (C) 2006 OpenWrt.org -Index: busybox-1.4.2/networking/httpd.c +Index: busybox-1.7.2/networking/httpd.c =================================================================== ---- busybox-1.4.2.orig/networking/httpd.c 2007-06-04 13:21:32.190083032 +0200 -+++ busybox-1.4.2/networking/httpd.c 2007-06-04 13:21:34.401746808 +0200 -@@ -1402,12 +1402,26 @@ +--- busybox-1.7.2.orig/networking/httpd.c 2007-09-30 01:54:12.000000000 +0200 ++++ busybox-1.7.2/networking/httpd.c 2007-10-04 14:59:20.287304836 +0200 +@@ -1527,12 +1527,26 @@ if (ENABLE_FEATURE_HTTPD_AUTH_MD5) { char *cipher; char *pp; + char *ppnew = NULL; + struct passwd *pwd = NULL; - if (strncmp(p, request, u-request) != 0) { - /* user uncompared */ + if (strncmp(p, request, u - request) != 0) { + /* user doesn't match */ continue; } pp = strchr(p, ':'); @@ -29,10 +29,10 @@ Index: busybox-1.4.2/networking/httpd.c + strcpy(ppnew + 1, pwd->pw_passwd); + pp = ppnew; + } - if (pp && pp[1] == '$' && pp[2] == '1' && - pp[3] == '$' && pp[4]) { - pp++; -@@ -1417,6 +1431,10 @@ + if (pp && pp[1] == '$' && pp[2] == '1' + && pp[3] == '$' && pp[4] + ) { +@@ -1543,6 +1557,10 @@ /* unauthorized */ continue; } diff --git a/package/busybox/patches/330-httpd_user_agent.patch b/package/busybox/patches/330-httpd_user_agent.patch deleted file mode 100644 index d9fa874af5..0000000000 --- a/package/busybox/patches/330-httpd_user_agent.patch +++ /dev/null @@ -1,29 +0,0 @@ -Index: busybox-1.4.2/networking/httpd.c -=================================================================== ---- busybox-1.4.2.orig/networking/httpd.c 2007-06-04 13:21:34.401746808 +0200 -+++ busybox-1.4.2/networking/httpd.c 2007-06-04 13:21:34.588718384 +0200 -@@ -137,6 +137,7 @@ - const char *query; - - USE_FEATURE_HTTPD_CGI(char *referer;) -+ USE_FEATURE_HTTPD_CGI(char *user_agent;) - - const char *configFile; - -@@ -1066,6 +1067,7 @@ - if (cp) *cp = '\0'; /* delete :PORT */ - setenv1("REMOTE_ADDR", p); - } -+ setenv1("HTTP_USER_AGENT", config->user_agent); - #if ENABLE_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV - setenv_long("REMOTE_PORT", config->port); - #endif -@@ -1647,6 +1649,8 @@ - content_type = strdup(skip_whitespace(buf + sizeof("Content-Type:")-1)); - } else if ((STRNCASECMP(buf, "Referer:") == 0)) { - config->referer = strdup(skip_whitespace(buf + sizeof("Referer:")-1)); -+ } else if ((STRNCASECMP(buf, "User-Agent:") == 0)) { -+ config->user_agent = strdup(skip_whitespace(buf + sizeof("User-Agent:")-1)); - } - #endif - diff --git a/package/busybox/patches/350-httpd_redir.patch b/package/busybox/patches/350-httpd_redir.patch index d8f430b89d..7cb82461b7 100644 --- a/package/busybox/patches/350-httpd_redir.patch +++ b/package/busybox/patches/350-httpd_redir.patch @@ -1,69 +1,76 @@ -Index: busybox-1.4.2/include/usage.h +Index: busybox-1.7.2/include/usage.h =================================================================== ---- busybox-1.4.2.orig/include/usage.h 2007-06-04 13:21:32.103096256 +0200 -+++ busybox-1.4.2/include/usage.h 2007-06-04 13:21:35.005655000 +0200 -@@ -1257,7 +1257,8 @@ - USE_FEATURE_HTTPD_BASIC_AUTH(" [-r ]") \ +--- busybox-1.7.2.orig/include/usage.h 2007-10-04 17:12:35.230910708 +0200 ++++ busybox-1.7.2/include/usage.h 2007-10-04 17:32:12.994027602 +0200 +@@ -1350,7 +1350,8 @@ + USE_FEATURE_HTTPD_BASIC_AUTH(" [-r realm]") \ USE_FEATURE_HTTPD_AUTH_MD5(" [-m pass]") \ " [-h home]" \ -- " [-d/-e ]" -+ " [-d/-e ]" \ +- " [-d/-e string]" ++ " [-d/-e string]" \ + " [-R [-H ]]" #define httpd_full_usage \ - "Listen for incoming http server requests" \ - "\n\nOptions:\n" \ -@@ -1273,7 +1274,9 @@ - " -m PASS Crypt PASS with md5 algorithm\n") \ - " -h HOME Specifies http HOME directory (default ./)\n" \ - " -e STRING HTML encode STRING\n" \ -- " -d STRING URL decode STRING" -+ " -d STRING URL decode STRING\n" \ -+ " -R PATH Redirect target path\n" \ -+ " -H HOST Redirect target host" + "Listen for incoming HTTP requests" \ + "\n\nOptions:" \ +@@ -1368,6 +1369,8 @@ + "\n -h HOME Home directory (default .)" \ + "\n -e STRING HTML encode STRING" \ + "\n -d STRING URL decode STRING" \ ++ "\n -R PATH Redirect target path" \ ++ "\n -H HOST Redirect target host" \ #define hwclock_trivial_usage \ - "[-r|--show] [-s|--hctosys] [-w|--systohc] [-l|--localtime] [-u|--utc]" -Index: busybox-1.4.2/networking/httpd.c + "[-r|--show] [-s|--hctosys] [-w|--systohc]" \ +Index: busybox-1.7.2/networking/httpd.c =================================================================== ---- busybox-1.4.2.orig/networking/httpd.c 2007-06-04 13:21:34.588718384 +0200 -+++ busybox-1.4.2/networking/httpd.c 2007-06-04 13:21:35.006654848 +0200 -@@ -140,6 +140,8 @@ - USE_FEATURE_HTTPD_CGI(char *user_agent;) +--- busybox-1.7.2.orig/networking/httpd.c 2007-10-04 17:13:12.509035065 +0200 ++++ busybox-1.7.2/networking/httpd.c 2007-10-04 17:32:33.711208213 +0200 +@@ -230,6 +230,8 @@ - const char *configFile; -+ const char *redirectPath; -+ const char *redirectHost; + const char *found_mime_type; + const char *found_moved_temporarily; ++ const char *redirect_path; ++ const char *redirect_host; + Htaccess_IP *ip_a_d; /* config allow/deny lines */ - unsigned int rmt_ip; - #if ENABLE_FEATURE_HTTPD_CGI || DEBUG -@@ -880,8 +882,11 @@ + USE_FEATURE_HTTPD_BASIC_AUTH(const char *g_realm;) +@@ -264,6 +266,8 @@ + #define home_httpd (G.home_httpd ) + #define found_mime_type (G.found_mime_type ) + #define found_moved_temporarily (G.found_moved_temporarily) ++#define redirect_path (G.redirect_path ) ++#define redirect_host (G.redirect_host ) + #define ContentLength (G.ContentLength ) + #define last_mod (G.last_mod ) + #define ip_a_d (G.ip_a_d ) +@@ -901,8 +905,11 @@ } #endif if (responseNum == HTTP_MOVED_TEMPORARILY) { -- len += sprintf(buf+len, "Location: %s/%s%s\r\n", -+ len += sprintf(buf+len, "Location: %s%s%s%s%s%s\r\n", -+ (config->redirectHost ? "http://" : ""), -+ (config->redirectHost ? config->redirectHost : ""), - config->found_moved_temporarily, -+ (config->redirectHost ? "" : "/"), - (config->query ? "?" : ""), - (config->query ? config->query : "")); +- len += sprintf(iobuf + len, "Location: %s/%s%s\r\n", ++ len += sprintf(iobuf + len, "Location: %s%s%s%s%s%s\r\n", ++ (redirect_host ? "http://" : ""), ++ (redirect_host ? redirect_host : ""), + found_moved_temporarily, ++ (redirect_host ? "" : "/"), + (g_query ? "?" : ""), + (g_query ? g_query : "")); } -@@ -1594,8 +1599,12 @@ - *++purl = '\0'; /* so keep last character */ - test = purl; /* end ptr */ +@@ -1730,8 +1737,12 @@ + *++urlp = '\0'; /* so keep last character */ + tptr = urlp; /* end ptr */ -+ /* redirect active */ -+ if (config->redirectPath && (strncmp(url, config->redirectPath, strlen(config->redirectPath)) != 0)) -+ config->found_moved_temporarily = config->redirectPath; ++ /* redirect active */ ++ if (redirect_path && (strncmp(urlcopy, redirect_path, strlen(redirect_path)) != 0)) ++ found_moved_temporarily = redirect_path; + - /* If URL is directory, adding '/' */ -- if (test[-1] != '/') { -+ if(!config->redirectPath && (test[-1] != '/')) { - if (is_directory(url + 1, 1, &sb)) { - config->found_moved_temporarily = url; - } -@@ -1897,7 +1906,9 @@ + /* If URL is a directory, add '/' */ +- if (tptr[-1] != '/') { ++ if (!redirect_path && (tptr[-1] != '/')) { + if (is_directory(urlcopy + 1, 1, &sb)) { + found_moved_temporarily = urlcopy; + } +@@ -2004,7 +2015,9 @@ #endif enum { @@ -74,20 +81,18 @@ Index: busybox-1.4.2/networking/httpd.c d_opt_decode_url, h_opt_home_httpd, USE_FEATURE_HTTPD_ENCODE_URL_STR(e_opt_encode_url,) -@@ -1919,7 +1930,7 @@ - OPT_FOREGROUND = 1 << p_opt_foreground, - }; - --static const char httpd_opts[] = "c:d:h:" -+static const char httpd_opts[] = "R:H:c:d:h:" - USE_FEATURE_HTTPD_ENCODE_URL_STR("e:") - USE_FEATURE_HTTPD_BASIC_AUTH("r:") - USE_FEATURE_HTTPD_AUTH_MD5("m:") -@@ -1951,6 +1962,7 @@ - config->ContentLength = -1; - - opt = getopt32(argc, argv, httpd_opts, -+ &(config->redirectPath), &(config->redirectHost), - &(config->configFile), &url_for_decode, &home_httpd +@@ -2053,12 +2066,13 @@ + /* We do not "absolutize" path given by -h (home) opt. + * If user gives relative path in -h, $SCRIPT_FILENAME can end up + * relative too. */ +- opt = getopt32(argv, "c:d:h:" ++ opt = getopt32(argv, "R:H:c:d:h:" + USE_FEATURE_HTTPD_ENCODE_URL_STR("e:") + USE_FEATURE_HTTPD_BASIC_AUTH("r:") + USE_FEATURE_HTTPD_AUTH_MD5("m:") + USE_FEATURE_HTTPD_SETUID("u:") + "p:ifv", ++ &redirect_path, &redirect_host, + &configFile, &url_for_decode, &home_httpd USE_FEATURE_HTTPD_ENCODE_URL_STR(, &url_for_encode) - USE_FEATURE_HTTPD_BASIC_AUTH(, &(config->realm)) + USE_FEATURE_HTTPD_BASIC_AUTH(, &g_realm) diff --git a/package/busybox/patches/360-awk_multi_f.patch b/package/busybox/patches/360-awk_multi_f.patch new file mode 100644 index 0000000000..8f738a6ffb --- /dev/null +++ b/package/busybox/patches/360-awk_multi_f.patch @@ -0,0 +1,72 @@ +Index: busybox-1.7.2/editors/awk.c +=================================================================== +--- busybox-1.7.2.orig/editors/awk.c 2007-10-04 19:57:46.859742242 +0200 ++++ busybox-1.7.2/editors/awk.c 2007-10-05 02:20:02.910793305 +0200 +@@ -2757,6 +2757,7 @@ + { + unsigned opt; + char *opt_F, *opt_W; ++ llist_t *opt_f = NULL; + llist_t *opt_v = NULL; + int i, j, flen; + var *v; +@@ -2816,8 +2817,8 @@ + *s1 = '='; + } + } +- opt_complementary = "v::"; +- opt = getopt32(argv, "F:v:f:W:", &opt_F, &opt_v, &g_progname, &opt_W); ++ opt_complementary = "v::f::"; ++ opt = getopt32(argv, "F:v:f:W:", &opt_F, &opt_v, &opt_f, &opt_W); + argv += optind; + argc -= optind; + if (opt & 0x1) +@@ -2826,25 +2827,31 @@ + if (!is_assignment(llist_pop(&opt_v))) + bb_show_usage(); + } +- if (opt & 0x4) { // -f +- char *s = s; /* die, gcc, die */ +- FILE *from_file = afopen(g_progname, "r"); +- /* one byte is reserved for some trick in next_token */ +- if (fseek(from_file, 0, SEEK_END) == 0) { +- flen = ftell(from_file); +- s = xmalloc(flen + 4); +- fseek(from_file, 0, SEEK_SET); +- i = 1 + fread(s + 1, 1, flen, from_file); +- } else { +- for (i = j = 1; j > 0; i += j) { +- s = xrealloc(s, i + 4096); +- j = fread(s + i, 1, 4094, from_file); ++ if (opt_f != NULL) { // -f ++ while (opt_f != NULL) { ++ char *s = NULL; ++ FILE *from_file; ++ ++ g_progname = opt_f->data; ++ from_file = afopen(g_progname, "r"); ++ /* one byte is reserved for some trick in next_token */ ++ if (fseek(from_file, 0, SEEK_END) == 0) { ++ flen = ftell(from_file); ++ s = xmalloc(flen + 4); ++ fseek(from_file, 0, SEEK_SET); ++ i = 1 + fread(s + 1, 1, flen, from_file); ++ } else { ++ for (i = j = 1; j > 0; i += j) { ++ s = xrealloc(s, i + 4096); ++ j = fread(s + i, 1, 4094, from_file); ++ } + } ++ s[i] = '\0'; ++ fclose(from_file); ++ parse_program(s + 1); ++ free(s); ++ opt_f = opt_f->link; + } +- s[i] = '\0'; +- fclose(from_file); +- parse_program(s + 1); +- free(s); + } else { // no -f: take program from 1st parameter + if (!argc) + bb_show_usage(); diff --git a/package/busybox/patches/400-revert_awk_getopt.patch b/package/busybox/patches/400-revert_awk_getopt.patch deleted file mode 100644 index 33c6790fe1..0000000000 --- a/package/busybox/patches/400-revert_awk_getopt.patch +++ /dev/null @@ -1,103 +0,0 @@ -Index: busybox-1.4.2/editors/awk.c -=================================================================== ---- busybox-1.4.2.orig/editors/awk.c 2007-06-15 23:43:26.460690280 +0200 -+++ busybox-1.4.2/editors/awk.c 2007-06-15 23:45:26.283474448 +0200 -@@ -2639,14 +2639,13 @@ - - int awk_main(int argc, char **argv) - { -- unsigned opt; -- char *opt_F, *opt_v, *opt_W; - int i, j, flen; - var *v; - var tv; - char **envp; - char *vnames = (char *)vNames; /* cheat */ - char *vvalues = (char *)vValues; -+ int c; - - /* Undo busybox.c, or else strtod may eat ','! This breaks parsing: - * $1,$2 == '$1,' '$2', NOT '$1' ',' '$2' */ -@@ -2694,40 +2693,56 @@ - free(s); - } - -- opt = getopt32(argc, argv, "F:v:f:W:", &opt_F, &opt_v, &programname, &opt_W); -- argv += optind; -- argc -= optind; -- if (opt & 0x1) setvar_s(V[FS], opt_F); // -F -- if (opt & 0x2) if (!is_assignment(opt_v)) bb_show_usage(); // -v -- if (opt & 0x4) { // -f -- char *s = s; /* die, gcc, die */ -- FILE *from_file = afopen(programname, "r"); -- /* one byte is reserved for some trick in next_token */ -- if (fseek(from_file, 0, SEEK_END) == 0) { -- flen = ftell(from_file); -- s = xmalloc(flen + 4); -- fseek(from_file, 0, SEEK_SET); -- i = 1 + fread(s + 1, 1, flen, from_file); -- } else { -- for (i = j = 1; j > 0; i += j) { -- s = xrealloc(s, i + 4096); -- j = fread(s + i, 1, 4094, from_file); -+ programname = NULL; -+ while((c = getopt(argc, argv, "F:v:f:W:")) != EOF) { -+ switch (c) { -+ case 'F': -+ setvar_s(V[FS], optarg); -+ break; -+ case 'v': -+ if (! is_assignment(optarg)) -+ bb_show_usage(); -+ break; -+ case 'f': { -+ FILE *F = afopen(programname = optarg, "r"); -+ char *s = NULL; -+ /* one byte is reserved for some trick in next_token */ -+ if (fseek(F, 0, SEEK_END) == 0) { -+ flen = ftell(F); -+ s = (char *)xmalloc(flen+4); -+ fseek(F, 0, SEEK_SET); -+ i = 1 + fread(s+1, 1, flen, F); -+ } else { -+ for (i=j=1; j>0; i+=j) { -+ s = (char *)xrealloc(s, i+4096); -+ j = fread(s+i, 1, 4094, F); -+ } -+ } -+ s[i] = '\0'; -+ fclose(F); -+ parse_program(s+1); -+ free(s); -+ break; - } -+ case 'W': -+ bb_error_msg("Warning: unrecognized option '-W %s' ignored\n", optarg); -+ break; -+ -+ default: -+ bb_show_usage(); - } -- s[i] = '\0'; -- fclose(from_file); -- parse_program(s + 1); -- free(s); -- } else { // no -f: take program from 1st parameter -+ } -+ argc -= optind; -+ argv += optind; -+ -+ if (!programname) { - if (!argc) - bb_show_usage(); - programname = "cmd. line"; - parse_program(*argv++); - argc--; - } -- if (opt & 0x8) // -W -- bb_error_msg("warning: unrecognized option '-W %s' ignored", opt_W); -- -+ - /* fill in ARGV array */ - setvar_i(V[ARGC], argc + 1); - setari_u(V[ARGV], 0, "awk"); diff --git a/package/busybox/patches/401-darwin_includes.patch b/package/busybox/patches/401-darwin_includes.patch index f563e10863..6506f279b5 100644 --- a/package/busybox/patches/401-darwin_includes.patch +++ b/package/busybox/patches/401-darwin_includes.patch @@ -1,8 +1,8 @@ -Index: busybox-1.4.2/include/platform.h +Index: busybox-1.7.2/include/platform.h =================================================================== ---- busybox-1.4.2.orig/include/platform.h 2007-06-04 13:21:32.055103552 +0200 -+++ busybox-1.4.2/include/platform.h 2007-06-04 13:21:35.387596936 +0200 -@@ -128,9 +128,11 @@ +--- busybox-1.7.2.orig/include/platform.h 2007-09-03 13:48:46.000000000 +0200 ++++ busybox-1.7.2/include/platform.h 2007-10-04 15:20:58.301274440 +0200 +@@ -137,9 +137,11 @@ # include #endif @@ -14,30 +14,20 @@ Index: busybox-1.4.2/include/platform.h /* ---- Compiler dependent settings ------------------------- */ #if (defined __digital__ && defined __unix__) -@@ -161,7 +163,7 @@ +@@ -179,7 +181,7 @@ #define HAVE_STDINT_H #else /* Largest integral types. */ -#if __BIG_ENDIAN__ +#if __BIG_ENDIAN__ && !__APPLE__ - typedef long int intmax_t; - typedef unsigned long int uintmax_t; + typedef long intmax_t; + typedef unsigned long uintmax_t; #else -Index: busybox-1.4.2/include/libbb.h +Index: busybox-1.7.2/include/libbb.h =================================================================== ---- busybox-1.4.2.orig/include/libbb.h 2007-06-04 13:21:32.062102488 +0200 -+++ busybox-1.4.2/include/libbb.h 2007-06-04 13:21:35.388596784 +0200 -@@ -17,7 +17,9 @@ - #include - #include - #include -+#ifndef __APPLE__ - #include -+#endif - #include - #include - #include -@@ -30,7 +32,9 @@ +--- busybox-1.7.2.orig/include/libbb.h 2007-09-16 20:48:10.000000000 +0200 ++++ busybox-1.7.2/include/libbb.h 2007-10-04 15:20:22.275221430 +0200 +@@ -31,7 +31,9 @@ #include #include #include diff --git a/package/busybox/patches/410-httpd_cgi_headers.patch b/package/busybox/patches/410-httpd_cgi_headers.patch index 98f094ee58..cfbbed6234 100644 --- a/package/busybox/patches/410-httpd_cgi_headers.patch +++ b/package/busybox/patches/410-httpd_cgi_headers.patch @@ -1,26 +1,18 @@ -Index: busybox-1.4.2/networking/httpd.c +Index: busybox-1.7.2/networking/httpd.c =================================================================== ---- busybox-1.4.2.orig/networking/httpd.c 2007-06-04 13:21:35.006654848 +0200 -+++ busybox-1.4.2/networking/httpd.c 2007-06-04 13:21:35.585566840 +0200 -@@ -1231,7 +1231,7 @@ - * "chopped up into small chunks" syndrome here */ - rbuf[count] = '\0'; - /* check to see if the user script added headers */ --#define HTTP_200 "HTTP/1.0 200 OK\r\n\r\n" -+#define HTTP_200 "HTTP/1.0 200 OK\r\n" - if (memcmp(rbuf, HTTP_200, 4) != 0) { - /* there is no "HTTP", do it ourself */ - full_write(s, HTTP_200, sizeof(HTTP_200)-1); -@@ -1242,9 +1242,9 @@ - * echo -en "Location: http://www.busybox.net\r\n" - * echo -en "\r\n" - */ -- //if (!strstr(rbuf, "ontent-")) { -- // full_write(s, "Content-type: text/plain\r\n\r\n", 28); -- //} -+ if (!strstr(rbuf, "ontent-")) { -+ full_write(s, "Content-type: text/plain\r\n\r\n", 28); -+ } - firstLine = 0; - } - if (full_write(s, rbuf, count) != count) +--- busybox-1.7.2.orig/networking/httpd.c 2007-10-04 15:06:51.993046080 +0200 ++++ busybox-1.7.2/networking/httpd.c 2007-10-04 15:25:10.815664410 +0200 +@@ -1314,10 +1314,10 @@ + if (full_write(1, HTTP_200, sizeof(HTTP_200)-1) != sizeof(HTTP_200)-1) + break; + } +- /* Commented out: +- if (!strstr(rbuf, "ontent-")) { +- full_write(s, "Content-type: text/plain\r\n\r\n", 28); ++ if (!strstr(rbuf, "ontent-") && !strstr(rbuf, "ocation:")) { ++ full_write(1, "Content-type: text/plain\r\n\r\n", 28); + } ++ /* Previously commented out: + * Counter-example of valid CGI without Content-type: + * echo -en "HTTP/1.0 302 Found\r\n" + * echo -en "Location: http://www.busybox.net\r\n" diff --git a/package/busybox/patches/420-httpd_sendcgi_fix.patch b/package/busybox/patches/420-httpd_sendcgi_fix.patch deleted file mode 100644 index 9998cc2455..0000000000 --- a/package/busybox/patches/420-httpd_sendcgi_fix.patch +++ /dev/null @@ -1,18 +0,0 @@ -Index: busybox-1.4.2/networking/httpd.c -=================================================================== ---- busybox-1.4.2.orig/networking/httpd.c 2007-06-04 13:21:35.585566840 +0200 -+++ busybox-1.4.2/networking/httpd.c 2007-06-04 13:21:35.775537960 +0200 -@@ -1218,9 +1218,10 @@ - #if PIPESIZE >= MAX_MEMORY_BUFF - # error "PIPESIZE >= MAX_MEMORY_BUFF" - #endif -- /* NB: was safe_read. If it *has to be* safe_read, */ -- /* please explain why in this comment... */ -- count = full_read(inFd, rbuf, PIPESIZE); -+ /* reverted back to safe_read, otherwise httpd may block if the */ -+ /* cgi-script outputs page date before it has fully received all */ -+ /* (eg POST) data */ -+ count = safe_read(inFd, rbuf, PIPESIZE); - if (count == 0) - break; /* closed */ - if (count < 0) diff --git a/package/busybox/patches/440-httpd_chdir.patch b/package/busybox/patches/440-httpd_chdir.patch index 8ef70b84d3..b3eb3081c6 100644 --- a/package/busybox/patches/440-httpd_chdir.patch +++ b/package/busybox/patches/440-httpd_chdir.patch @@ -1,29 +1,12 @@ -Index: busybox-1.4.2/networking/httpd.c +Index: busybox-1.7.2/networking/httpd.c =================================================================== ---- busybox-1.4.2.orig/networking/httpd.c 2007-06-04 13:21:35.775537960 +0200 -+++ busybox-1.4.2/networking/httpd.c 2007-06-04 13:21:36.144481872 +0200 -@@ -102,6 +102,7 @@ - static const char default_path_httpd_conf[] = "/etc"; - static const char httpd_conf[] = "httpd.conf"; - static const char home[] = "./"; -+static const char *home_httpd = home; - - #define TIMEOUT 60 - -@@ -1505,6 +1506,8 @@ +--- busybox-1.7.2.orig/networking/httpd.c 2007-10-04 15:25:10.815664410 +0200 ++++ busybox-1.7.2/networking/httpd.c 2007-10-04 15:31:22.936870392 +0200 +@@ -1616,6 +1616,7 @@ #if ENABLE_FEATURE_HTTPD_BASIC_AUTH int credentials = -1; /* if not required this is Ok */ #endif -+ + xchdir(home_httpd); - sa.sa_handler = handle_sigalrm; - sigemptyset(&sa.sa_mask); -@@ -1942,7 +1945,6 @@ - int httpd_main(int argc, char *argv[]) - { - unsigned opt; -- const char *home_httpd = home; - char *url_for_decode; - USE_FEATURE_HTTPD_ENCODE_URL_STR(const char *url_for_encode;) - const char *s_port; + /* Allocation of iobuf is postponed until now + * (IOW, server process doesn't need to waste 8k) */ diff --git a/package/busybox/patches/440-usage_compressed_fix.patch b/package/busybox/patches/440-usage_compressed_fix.patch deleted file mode 100644 index c9e29cec00..0000000000 --- a/package/busybox/patches/440-usage_compressed_fix.patch +++ /dev/null @@ -1,12 +0,0 @@ -Index: busybox-1.4.2/applets/usage_compressed -=================================================================== ---- busybox-1.4.2.orig/applets/usage_compressed 2007-06-04 13:21:31.952119208 +0200 -+++ busybox-1.4.2/applets/usage_compressed 2007-06-04 13:21:36.331453448 +0200 -@@ -14,6 +14,6 @@ - - echo 'static const char packed_usage[] = ' - "$loc/usage" | bzip2 -1 | od -v -t x1 \ --| $SED -e 's/^[^ ]*//' -e 's/ \(..\)/\\x\1/g' -e 's/^\(.*\)$/"\1"/' -+| $SED -e 's/^[^ ]*//' -e 's/ \([a-f0-9][a-f0-9]\)/\\x\1/g' -e 's/^\(.*\)$/"\1"/' - echo ';' - echo '#define SIZEOF_usage_messages' `expr 0 + $sz` diff --git a/package/busybox/patches/450-truncated_ping_results.patch b/package/busybox/patches/450-truncated_ping_results.patch deleted file mode 100644 index 34582c2ba9..0000000000 --- a/package/busybox/patches/450-truncated_ping_results.patch +++ /dev/null @@ -1,33 +0,0 @@ -Index: busybox-1.4.2/networking/ping.c -=================================================================== ---- busybox-1.4.2.orig/networking/ping.c 2007-06-04 13:21:31.931122400 +0200 -+++ busybox-1.4.2/networking/ping.c 2007-06-04 13:21:36.518425024 +0200 -@@ -70,7 +70,7 @@ - struct sockaddr_in pingaddr; - struct icmp *pkt; - int pingsock, c; -- char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; -+ char packet[datalen + ICMP_MINLEN + MAXIPLEN + MAXICMPLEN]; - - pingsock = create_icmp_socket(); - -@@ -86,7 +86,7 @@ - pkt->icmp_type = ICMP_ECHO; - pkt->icmp_cksum = in_cksum((unsigned short *) pkt, sizeof(packet)); - -- c = sendto(pingsock, packet, DEFDATALEN + ICMP_MINLEN, 0, -+ c = sendto(pingsock, packet, datalen + ICMP_MINLEN, 0, - (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in)); - - if (c < 0) { -@@ -274,6 +274,10 @@ - ++nreceived; - tp = (struct timeval *) icmppkt->icmp_data; - -+ /* If packet is too short, results will be truncated */ -+ if (sz < (ICMP_MINLEN + sizeof(tv.tv_sec) + sizeof(tv.tv_usec))) -+ return; -+ - if ((tv.tv_usec -= tp->tv_usec) < 0) { - --tv.tv_sec; - tv.tv_usec += 1000000; diff --git a/package/busybox/patches/450-usage_compressed_fix.patch b/package/busybox/patches/450-usage_compressed_fix.patch new file mode 100644 index 0000000000..3a9d2ad9e8 --- /dev/null +++ b/package/busybox/patches/450-usage_compressed_fix.patch @@ -0,0 +1,12 @@ +Index: busybox-1.7.2/applets/usage_compressed +=================================================================== +--- busybox-1.7.2.orig/applets/usage_compressed 2007-09-03 13:48:55.000000000 +0200 ++++ busybox-1.7.2/applets/usage_compressed 2007-10-04 15:32:54.578092727 +0200 +@@ -14,6 +14,6 @@ + + echo 'static const char packed_usage[] ALIGN1 = ' + "$loc/usage" | bzip2 -1 | od -v -t x1 \ +-| $SED -e 's/^[^ ]*//' -e 's/ *\(..\)/\\x\1/g' -e 's/^\(.*\)$/"\1"/' ++| $SED -e 's/^[^ ]*//' -e 's/ *\([a-f0-9][a-f0-9]\)/\\x\1/g' -e 's/^\(.*\)$/"\1"/' + echo ';' + echo '#define SIZEOF_usage_messages' `expr 0 + $sz` diff --git a/package/busybox/patches/460-httpd_cgi_bin.patch b/package/busybox/patches/460-httpd_cgi_bin.patch deleted file mode 100644 index d21c518348..0000000000 --- a/package/busybox/patches/460-httpd_cgi_bin.patch +++ /dev/null @@ -1,15 +0,0 @@ -Index: busybox-1.4.2/networking/httpd.c -=================================================================== ---- busybox-1.4.2.orig/networking/httpd.c 2007-06-21 18:12:06.791080496 +0200 -+++ busybox-1.4.2/networking/httpd.c 2007-06-21 18:14:48.914434000 +0200 -@@ -1715,8 +1715,8 @@ - test = url + 1; /* skip first '/' */ - - #if ENABLE_FEATURE_HTTPD_CGI -- if (strncmp(test, "cgi-bin", 7) == 0) { -- if (test[7] == '/' && test[8] == 0) -+ if (strncmp(test, "cgi-bin/", 8) == 0) { -+ if (test[8] == 0) - goto FORBIDDEN; /* protect listing cgi-bin/ */ - sendCgi(url, prequest, length, cookie, content_type); - break; diff --git a/package/busybox/patches/460-truncated_ping_results.patch b/package/busybox/patches/460-truncated_ping_results.patch new file mode 100644 index 0000000000..e655acfdf2 --- /dev/null +++ b/package/busybox/patches/460-truncated_ping_results.patch @@ -0,0 +1,40 @@ +Index: busybox-1.7.2/networking/ping.c +=================================================================== +--- busybox-1.7.2.orig/networking/ping.c 2007-09-03 13:48:27.000000000 +0200 ++++ busybox-1.7.2/networking/ping.c 2007-10-04 15:38:15.424376713 +0200 +@@ -91,7 +91,7 @@ + struct sockaddr_in pingaddr; + struct icmp *pkt; + int pingsock, c; +- char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; ++ char packet[datalen + ICMP_MINLEN + MAXIPLEN + MAXICMPLEN]; + + pingsock = create_icmp_socket(); + pingaddr = lsa->sin; +@@ -101,7 +101,7 @@ + pkt->icmp_type = ICMP_ECHO; + pkt->icmp_cksum = in_cksum((unsigned short *) pkt, sizeof(packet)); + +- c = xsendto(pingsock, packet, DEFDATALEN + ICMP_MINLEN, ++ c = xsendto(pingsock, packet, datalen + ICMP_MINLEN, + (struct sockaddr *) &pingaddr, sizeof(pingaddr)); + + /* listen for replies */ +@@ -135,7 +135,7 @@ + struct icmp6_hdr *pkt; + int pingsock, c; + int sockopt; +- char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; ++ char packet[datalen + ICMP_MINLEN + MAXIPLEN + MAXICMPLEN]; + + pingsock = create_icmp6_socket(); + pingaddr = lsa->sin6; +@@ -147,7 +147,7 @@ + sockopt = offsetof(struct icmp6_hdr, icmp6_cksum); + setsockopt(pingsock, SOL_RAW, IPV6_CHECKSUM, &sockopt, sizeof(sockopt)); + +- c = xsendto(pingsock, packet, DEFDATALEN + sizeof (struct icmp6_hdr), ++ c = xsendto(pingsock, packet, datalen + sizeof (struct icmp6_hdr), + (struct sockaddr *) &pingaddr, sizeof(pingaddr)); + + /* listen for replies */ diff --git a/package/busybox/patches/470-insmod_search.patch b/package/busybox/patches/470-insmod_search.patch new file mode 100644 index 0000000000..26c5650eb6 --- /dev/null +++ b/package/busybox/patches/470-insmod_search.patch @@ -0,0 +1,488 @@ +Index: busybox-1.7.2/modutils/insmod.c +=================================================================== +--- busybox-1.7.2.orig/modutils/insmod.c 2007-09-03 13:48:35.000000000 +0200 ++++ busybox-1.7.2/modutils/insmod.c 2007-10-05 01:43:47.686834357 +0200 +@@ -61,19 +61,107 @@ + #include "libbb.h" + #include + #include ++#if ENABLE_FEATURE_2_6_MODULES ++#include ++#include ++#include ++#endif + + #if !ENABLE_FEATURE_2_4_MODULES && !ENABLE_FEATURE_2_6_MODULES + #undef ENABLE_FEATURE_2_4_MODULES + #define ENABLE_FEATURE_2_4_MODULES 1 + #endif + +-#if !ENABLE_FEATURE_2_4_MODULES +-#define insmod_ng_main insmod_main ++#if ENABLE_FEATURE_2_4_MODULES ++int insmod_main_24(int argc, char **argv); + #endif +- + #if ENABLE_FEATURE_2_6_MODULES +-extern int insmod_ng_main( int argc, char **argv); ++int insmod_main_26(int argc, char **argv); + #endif ++int insmod_main(int argc, char **argv); ++ ++static char *g_filename = NULL; ++#define _PATH_MODULES "/lib/modules" ++ ++static int check_module_name_match(const char *filename, struct stat *statbuf, ++ void *userdata, int depth) ++{ ++ char *fullname = (char *) userdata; ++ ++ if (fullname[0] == '\0') ++ return FALSE; ++ else { ++ char *tmp, *tmp1 = xstrdup(filename); ++ tmp = bb_get_last_path_component(tmp1); ++ if (strcmp(tmp, fullname) == 0) { ++ free(tmp1); ++ /* Stop searching if we find a match */ ++ g_filename = xstrdup(filename); ++ return FALSE; ++ } ++ free(tmp1); ++ } ++ return TRUE; ++} ++ ++static int find_module(char *filename) ++{ ++ char *module_dir, real_module_dir[FILENAME_MAX]; ++ int len, slen, ret = ENOENT, k_version; ++ struct utsname myuname; ++ const char *suffix; ++ struct stat st; ++ ++ /* check the kernel version */ ++ if ((uname(&myuname) != 0) || (myuname.release[0] != '2')) ++ return EINVAL; ++ ++ k_version = myuname.release[2] - '0'; ++#if ENABLE_FEATURE_2_4_MODULES ++ if (k_version <= 4) ++ suffix = ".o"; ++ else ++#endif ++ suffix = ".ko"; ++ ++ len = strlen(filename); ++ slen = strlen(suffix); ++ ++ /* check for suffix and absolute path first */ ++ if ((len < slen + 2) || (strcmp(filename + len - slen, suffix) != 0)) { ++ filename = xasprintf("%s%s", filename, suffix); ++ } else { ++ filename = strdup(filename); ++ if ((stat(filename, &st) == 0) && S_ISREG(st.st_mode)) ++ return 0; ++ } ++ ++ /* next: scan /lib/modules/ */ ++ /* Jump through hoops in case /lib/modules/`uname -r` ++ * is a symlink. We do not want recursive_action to ++ * follow symlinks, but we do want to follow the ++ * /lib/modules/`uname -r` dir, So resolve it ourselves ++ * if it is a link... */ ++ module_dir = concat_path_file(_PATH_MODULES, myuname.release); ++ if (realpath(module_dir, real_module_dir) != NULL) { ++ free(module_dir); ++ module_dir = real_module_dir; ++ } ++ ++ recursive_action(module_dir, ACTION_RECURSE, ++ check_module_name_match, 0, filename, 0); ++ ++ /* Check if we have a complete path */ ++ if (g_filename != NULL) { ++ if ((stat(g_filename, &st) == 0) && S_ISREG(st.st_mode)) ++ ret = 0; ++ else ++ free(g_filename); ++ } ++ free(filename); ++ ++ return ret; ++} + + + #if ENABLE_FEATURE_2_4_MODULES +@@ -677,7 +765,6 @@ + #endif + + +-#define _PATH_MODULES "/lib/modules" + enum { STRVERSIONLEN = 64 }; + + /*======================================================================*/ +@@ -790,37 +877,6 @@ + static int n_ext_modules_used; + extern int delete_module(const char *); + +-static char *m_filename; +-static char *m_fullName; +- +- +-/*======================================================================*/ +- +- +-static int check_module_name_match(const char *filename, struct stat *statbuf, +- void *userdata, int depth) +-{ +- char *fullname = (char *) userdata; +- +- if (fullname[0] == '\0') +- return FALSE; +- else { +- char *tmp, *tmp1 = xstrdup(filename); +- tmp = bb_get_last_path_component(tmp1); +- if (strcmp(tmp, fullname) == 0) { +- free(tmp1); +- /* Stop searching if we find a match */ +- m_filename = xstrdup(filename); +- return FALSE; +- } +- free(tmp1); +- } +- return TRUE; +-} +- +- +-/*======================================================================*/ +- + static struct obj_file *arch_new_file(void) + { + struct arch_file *f; +@@ -3952,33 +4008,35 @@ + void print_load_map(struct obj_file *f); + #endif + +-int insmod_main( int argc, char **argv); +-int insmod_main( int argc, char **argv) ++int insmod_main_24( int argc, char **argv) + { + char *opt_o, *arg1; + int len; + int k_crcs; +- char *tmp, *tmp1; + unsigned long m_size; + ElfW(Addr) m_addr; + struct obj_file *f; + struct stat st; + char *m_name = 0; +- int exit_status = EXIT_FAILURE; ++ int ret = EINVAL; + int m_has_modinfo; + #if ENABLE_FEATURE_INSMOD_VERSION_CHECKING + struct utsname uts_info; + char m_strversion[STRVERSIONLEN]; + int m_version, m_crcs; + #endif +-#if ENABLE_FEATURE_CLEAN_UP +- FILE *fp = 0; +-#else +- FILE *fp; +-#endif +- int k_version = 0; ++ FILE *fp = NULL; ++ int k_version; + struct utsname myuname; + ++ /* check the kernel version */ ++ if ((uname(&myuname) != 0) || (myuname.release[0] != '2')) ++ return EINVAL; ++ ++ k_version = myuname.release[2] - '0'; ++ if (k_version > 4) ++ return ENOTSUP; ++ + /* Parse any options */ + getopt32(argv, OPTION_STR, &opt_o); + arg1 = argv[optind]; +@@ -3987,110 +4045,18 @@ + m_name = xstrdup(opt_o); + } + +- if (arg1 == NULL) { ++ if (arg1 == NULL) + bb_show_usage(); +- } +- +- /* Grab the module name */ +- tmp1 = xstrdup(arg1); +- tmp = basename(tmp1); +- len = strlen(tmp); +- +- if (uname(&myuname) == 0) { +- if (myuname.release[0] == '2') { +- k_version = myuname.release[2] - '0'; +- } +- } +- +-#if ENABLE_FEATURE_2_6_MODULES +- if (k_version > 4 && len > 3 && tmp[len - 3] == '.' +- && tmp[len - 2] == 'k' && tmp[len - 1] == 'o' +- ) { +- len -= 3; +- tmp[len] = '\0'; +- } else +-#endif +- if (len > 2 && tmp[len - 2] == '.' && tmp[len - 1] == 'o') { +- len -= 2; +- tmp[len] = '\0'; +- } +- +- +-#if ENABLE_FEATURE_2_6_MODULES +- if (k_version > 4) +- m_fullName = xasprintf("%s.ko", tmp); +- else +-#endif +- m_fullName = xasprintf("%s.o", tmp); + +- if (!m_name) { +- m_name = tmp; +- } else { +- free(tmp1); +- tmp1 = 0; /* flag for free(m_name) before exit() */ +- } +- +- /* Get a filedesc for the module. Check we we have a complete path */ +- if (stat(arg1, &st) < 0 || !S_ISREG(st.st_mode) +- || (fp = fopen(arg1, "r")) == NULL +- ) { +- /* Hmm. Could not open it. First search under /lib/modules/`uname -r`, +- * but do not error out yet if we fail to find it... */ +- if (k_version) { /* uname succeedd */ +- char *module_dir; +- char *tmdn; +- char real_module_dir[FILENAME_MAX]; +- +- tmdn = concat_path_file(_PATH_MODULES, myuname.release); +- /* Jump through hoops in case /lib/modules/`uname -r` +- * is a symlink. We do not want recursive_action to +- * follow symlinks, but we do want to follow the +- * /lib/modules/`uname -r` dir, So resolve it ourselves +- * if it is a link... */ +- if (realpath(tmdn, real_module_dir) == NULL) +- module_dir = tmdn; +- else +- module_dir = real_module_dir; +- recursive_action(module_dir, ACTION_RECURSE, +- check_module_name_match, 0, m_fullName, 0); +- free(tmdn); +- } +- +- /* Check if we have found anything yet */ +- if (m_filename == 0 || ((fp = fopen(m_filename, "r")) == NULL)) { +- char module_dir[FILENAME_MAX]; +- +- free(m_filename); +- m_filename = 0; +- if (realpath (_PATH_MODULES, module_dir) == NULL) +- strcpy(module_dir, _PATH_MODULES); +- /* No module found under /lib/modules/`uname -r`, this +- * time cast the net a bit wider. Search /lib/modules/ */ +- if (!recursive_action(module_dir, ACTION_RECURSE, +- check_module_name_match, 0, m_fullName, 0) +- ) { +- if (m_filename == 0 +- || ((fp = fopen(m_filename, "r")) == NULL) +- ) { +- bb_error_msg("%s: no module by that name found", m_fullName); +- goto out; +- } +- } else +- bb_error_msg_and_die("%s: no module by that name found", m_fullName); +- } +- } else +- m_filename = xstrdup(arg1); +- +- if (flag_verbose) +- printf("Using %s\n", m_filename); ++ ret = find_module(arg1); ++ if (ret) ++ goto out; + +-#if ENABLE_FEATURE_2_6_MODULES +- if (k_version > 4) { +- argv[optind] = m_filename; +- optind--; +- return insmod_ng_main(argc - optind, argv + optind); ++ fp = fopen(g_filename, "r"); ++ if (!fp) { ++ ret = errno; ++ goto out; + } +-#endif + + f = obj_load(fp, LOADBITS); + if (f == NULL) +@@ -4120,7 +4086,7 @@ + "\t%s was compiled for kernel version %s\n" + "\twhile this kernel is version %s", + flag_force_load ? "warning: " : "", +- m_filename, m_strversion, uts_info.release); ++ g_filename, m_strversion, uts_info.release); + if (!flag_force_load) + goto out; + } +@@ -4173,7 +4139,7 @@ + hide_special_symbols(f); + + #if ENABLE_FEATURE_INSMOD_KSYMOOPS_SYMBOLS +- add_ksymoops_symbols(f, m_filename, m_name); ++ add_ksymoops_symbols(f, g_filename, m_name); + #endif /* FEATURE_INSMOD_KSYMOOPS_SYMBOLS */ + + new_create_module_ksymtab(f); +@@ -4220,8 +4186,7 @@ + if (flag_print_load_map) + print_load_map(f); + +- exit_status = EXIT_SUCCESS; +- ++ ret = 0; + out: + #if ENABLE_FEATURE_CLEAN_UP + if (fp) +@@ -4229,21 +4194,13 @@ + free(tmp1); + if (!tmp1) + free(m_name); +- free(m_filename); ++ free(g_filename); + #endif + return exit_status; + } +- +- + #endif + +- + #if ENABLE_FEATURE_2_6_MODULES +- +-#include +-#include +-#include +- + /* We use error numbers in a loose translation... */ + static const char *moderror(int err) + { +@@ -4261,19 +4218,33 @@ + } + } + +-int insmod_ng_main(int argc, char **argv); +-int insmod_ng_main(int argc, char **argv) ++int insmod_main_26(int argc, char **argv) + { +- long ret; +- size_t len; ++ char *filename, *options; ++ struct utsname myuname; ++ int k_version; + int optlen; ++ size_t len; + void *map; +- char *filename, *options; ++ long ret = 0; ++ ++ /* check the kernel version */ ++ if ((uname(&myuname) != 0) || (myuname.release[0] != '2')) ++ return EINVAL; ++ ++ k_version = myuname.release[2] - '0'; ++ if (k_version <= 4) ++ return ENOTSUP; + + filename = *++argv; + if (!filename) + bb_show_usage(); + ++ g_filename = filename; ++ ret = find_module(filename); ++ if (ret) ++ goto done; ++ + /* Rest is options */ + options = xzalloc(1); + optlen = 0; +@@ -4283,36 +4254,46 @@ + optlen += sprintf(options + optlen, (strchr(*argv,' ') ? "\"%s\" " : "%s "), *argv); + } + +-#if 0 +- /* Any special reason why mmap? It isn't performace critical... */ +- int fd; +- struct stat st; +- unsigned long len; +- fd = xopen(filename, O_RDONLY); +- fstat(fd, &st); +- len = st.st_size; +- map = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0); +- if (map == MAP_FAILED) { +- bb_perror_msg_and_die("cannot mmap '%s'", filename); +- } +- +- /* map == NULL on Blackfin, probably on other MMU-less systems too. Workaround. */ +- if (map == NULL) { +- map = xmalloc(len); +- xread(fd, map, len); +- } +-#else + len = MAXINT(ssize_t); +- map = xmalloc_open_read_close(filename, &len); +-#endif +- ++ map = xmalloc_open_read_close(g_filename, &len); + ret = syscall(__NR_init_module, map, len, options); + if (ret != 0) { + bb_perror_msg_and_die("cannot insert '%s': %s (%li)", +- filename, moderror(errno), ret); ++ g_filename, moderror(errno), ret); + } ++done: ++ if (g_filename && (g_filename != filename)) ++ free(g_filename); + +- return 0; ++ return ret; + } + + #endif ++ ++int insmod_main(int argc, char **argv) ++{ ++ int ret; ++ ++#if ENABLE_FEATURE_2_6_MODULES ++ ret = insmod_main_26(argc, argv); ++ if (ret != ENOTSUP) ++ goto done; ++#endif ++ ++#if ENABLE_FEATURE_2_4_MODULES ++ ret = insmod_main_24(argc, argv); ++ if (ret != ENOTSUP) ++ goto done; ++#endif ++ ++ fprintf(stderr, "Error: Kernel version not supported\n"); ++ return 1; ++ ++done: ++ if (ret) { ++ errno = ret; ++ bb_perror_msg("Loading module failed"); ++ return ret; ++ } else ++ return 0; ++} diff --git a/package/busybox/patches/500-ipkg.patch b/package/busybox/patches/500-ipkg.patch new file mode 100644 index 0000000000..a18616261e --- /dev/null +++ b/package/busybox/patches/500-ipkg.patch @@ -0,0 +1,13753 @@ +Index: busybox-1.7.2/archival/Config.in +=================================================================== +--- busybox-1.7.2.orig/archival/Config.in 2007-10-04 17:12:34.094845964 +0200 ++++ busybox-1.7.2/archival/Config.in 2007-10-04 17:14:22.056998379 +0200 +@@ -121,6 +121,15 @@ + gzip is used to compress files. + It's probably the most widely used UNIX compression program. + ++config IPKG ++ bool "ipkg" ++ default n ++ select MD5SUM ++ select WGET ++ select DIFF ++ help ++ ipkg is the itsy package management system. ++ + config RPM2CPIO + bool "rpm2cpio" + default n +Index: busybox-1.7.2/archival/dpkg.c +=================================================================== +--- busybox-1.7.2.orig/archival/dpkg.c 2007-10-04 17:12:34.102846422 +0200 ++++ busybox-1.7.2/archival/dpkg.c 2007-10-04 17:14:22.060998604 +0200 +@@ -1455,6 +1455,10 @@ + return ar_handle->sub_archive->buffer; + } + ++/* ++ ++// moved to data_extract_all.c ++ + static void data_extract_all_prefix(archive_handle_t *archive_handle) + { + char *name_ptr = archive_handle->file_header->name; +@@ -1466,6 +1470,8 @@ + } + } + ++*/ ++ + static void unpack_package(deb_file_t *deb_file) + { + const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name]; +Index: busybox-1.7.2/archival/ipkg.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/ipkg.c 2007-10-04 17:14:22.084999973 +0200 +@@ -0,0 +1,26 @@ ++/* ipkg.c - the itsy package management system ++ ++ Florina Boor ++ ++ Copyright (C) 2003 kernel concepts ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++ ++ ipkg command line frontend using libipkg ++ ++*/ ++ ++#include "libipkg/libipkg.h" ++ ++int ipkg_main(int argc, char **argv) ++{ ++ return ipkg_op(argc, argv); ++} +Index: busybox-1.7.2/archival/Kbuild +=================================================================== +--- busybox-1.7.2.orig/archival/Kbuild 2007-10-04 17:12:34.110846879 +0200 ++++ busybox-1.7.2/archival/Kbuild 2007-10-04 17:14:22.109001341 +0200 +@@ -15,6 +15,7 @@ + lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o + lib-$(CONFIG_GUNZIP) += bbunzip.o + lib-$(CONFIG_GZIP) += gzip.o bbunzip.o ++lib-$(CONFIG_IPKG) += ipkg.o + lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o + lib-$(CONFIG_RPM) += rpm.o + lib-$(CONFIG_TAR) += tar.o +Index: busybox-1.7.2/archival/libipkg/args.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/args.c 2007-10-04 17:14:22.145003392 +0200 +@@ -0,0 +1,242 @@ ++/* args.c - parse command-line args ++ ++ Carl D. Worth ++ ++ Copyright 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation; either version 2, or (at your option) ++ any later version. ++ ++ This program 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 General Public License for more details. ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include "ipkg.h" ++#include "ipkg_message.h" ++ ++#include "args.h" ++#include "sprintf_alloc.h" ++ ++#include "libbb.h" ++ ++ ++static void print_version(void); ++ ++enum long_args_opt ++{ ++ ARGS_OPT_FORCE_DEFAULTS = 129, ++ ARGS_OPT_FORCE_DEPENDS, ++ ARGS_OPT_FORCE_OVERWRITE, ++ ARGS_OPT_FORCE_DOWNGRADE, ++ ARGS_OPT_FORCE_REINSTALL, ++ ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES, ++ ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES, ++ ARGS_OPT_FORCE_SPACE, ++ ARGS_OPT_NOACTION, ++ ARGS_OPT_NODEPS, ++ ARGS_OPT_VERBOSE_WGET, ++ ARGS_OPT_VERBOSITY, ++ ARGS_OPT_MULTIPLE_PROVIDERS ++}; ++ ++int args_init(args_t *args) ++{ ++ char *conf_file_dir; ++ ++ memset(args, 0, sizeof(args_t)); ++ ++ args->dest = ARGS_DEFAULT_DEST; ++ ++ conf_file_dir = getenv("IPKG_CONF_DIR"); ++ if (conf_file_dir == NULL || conf_file_dir[0] == '\0') { ++ conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR; ++ } ++ sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir, ++ ARGS_DEFAULT_CONF_FILE_NAME); ++ ++ args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS; ++ args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS; ++ args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE; ++ args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE; ++ args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL; ++ args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES; ++ args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES; ++ args->noaction = ARGS_DEFAULT_NOACTION; ++ args->nodeps = ARGS_DEFAULT_NODEPS; ++ args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET; ++ args->verbosity = ARGS_DEFAULT_VERBOSITY; ++ args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT; ++ args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD; ++ args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD; ++ args->multiple_providers = 0; ++ args->nocheckfordirorfile = 0; ++ args->noreadfeedsfile = 0; ++ ++ return 1; ++} ++ ++void args_deinit(args_t *args) ++{ ++ free(args->conf_file); ++ args->conf_file = NULL; ++} ++ ++int args_parse(args_t *args, int argc, char *argv[]) ++{ ++ int c; ++ int option_index = 0; ++ int parse_err = 0; ++ static struct option long_options[] = { ++ {"query-all", 0, 0, 'A'}, ++ {"conf-file", 1, 0, 'f'}, ++ {"conf", 1, 0, 'f'}, ++ {"dest", 1, 0, 'd'}, ++ {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS}, ++ {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS}, ++ {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS}, ++ {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS}, ++ {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE}, ++ {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE}, ++ {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE}, ++ {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE}, ++ {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL}, ++ {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL}, ++ {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE}, ++ {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE}, ++ {"recursive", 0, 0, ++ ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES}, ++ {"force-removal-of-dependent-packages", 0, 0, ++ ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES}, ++ {"force_removal_of_dependent_packages", 0, 0, ++ ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES}, ++ {"force-removal-of-essential-packages", 0, 0, ++ ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES}, ++ {"force_removal_of_essential_packages", 0, 0, ++ ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES}, ++ {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS}, ++ {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS}, ++ {"noaction", 0, 0, ARGS_OPT_NOACTION}, ++ {"nodeps", 0, 0, ARGS_OPT_NODEPS}, ++ {"offline", 1, 0, 'o'}, ++ {"offline-root", 1, 0, 'o'}, ++ {"test", 0, 0, ARGS_OPT_NOACTION}, ++ {"tmp-dir", 1, 0, 't'}, ++ {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET}, ++ {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET}, ++ {"verbosity", 2, 0, 'V'}, ++ {"version", 0, 0, 'v'}, ++ {0, 0, 0, 0} ++ }; ++ ++ while (1) { ++ c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index); ++ if (c == -1) ++ break; ++ ++ switch (c) { ++ case 'A': ++ args->query_all = 1; ++ break; ++ case 'd': ++ args->dest = optarg; ++ break; ++ case 'f': ++ free(args->conf_file); ++ args->conf_file = strdup(optarg); ++ break; ++ case 'o': ++ args->offline_root = optarg; ++ break; ++ case 'n': ++ args->noaction = 1; ++ break; ++ case 't': ++ args->tmp_dir = strdup(optarg); ++ break; ++ case 'v': ++ print_version(); ++ exit(0); ++ case 'V': ++ case ARGS_OPT_VERBOSITY: ++ if (optarg) ++ args->verbosity = atoi(optarg); ++ else ++ args->verbosity += 1; ++ break; ++ case ARGS_OPT_FORCE_DEFAULTS: ++ args->force_defaults = 1; ++ break; ++ case ARGS_OPT_FORCE_DEPENDS: ++ args->force_depends = 1; ++ break; ++ case ARGS_OPT_FORCE_OVERWRITE: ++ args->force_overwrite = 1; ++ break; ++ case ARGS_OPT_FORCE_DOWNGRADE: ++ args->force_downgrade = 1; ++ break; ++ case ARGS_OPT_FORCE_REINSTALL: ++ args->force_reinstall = 1; ++ break; ++ case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES: ++ args->force_removal_of_essential_packages = 1; ++ break; ++ case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES: ++ args->force_removal_of_dependent_packages = 1; ++ break; ++ case ARGS_OPT_FORCE_SPACE: ++ args->force_space = 1; ++ break; ++ case ARGS_OPT_VERBOSE_WGET: ++ args->verbose_wget = 1; ++ break; ++ case ARGS_OPT_MULTIPLE_PROVIDERS: ++ args->multiple_providers = 1; ++ break; ++ case ARGS_OPT_NODEPS: ++ args->nodeps = 1; ++ break; ++ case ARGS_OPT_NOACTION: ++ args->noaction = 1; ++ break; ++ case ':': ++ parse_err++; ++ break; ++ case '?': ++ parse_err++; ++ break; ++ default: ++ bb_error_msg("Confusion: getopt_long returned %d\n", c); ++ } ++ } ++ ++ if (parse_err) { ++ return -parse_err; ++ } else { ++ return optind; ++ } ++} ++ ++void args_usage(char *complaint) ++{ ++ if (complaint) { ++ bb_error_msg("%s\n", complaint); ++ } ++ print_version(); ++ bb_show_usage(); ++ exit(1); ++} ++ ++static void print_version(void) ++{ ++ bb_error_msg("version %s\n", IPKG_VERSION); ++} +Index: busybox-1.7.2/archival/libipkg/args.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/args.h 2007-10-04 17:14:22.173004992 +0200 +@@ -0,0 +1,72 @@ ++/* args.h - parse command-line args ++ ++ Carl D. Worth ++ ++ Copyright 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation; either version 2, or (at your option) ++ any later version. ++ ++ This program 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 General Public License for more details. ++*/ ++ ++#ifndef ARGS_H ++#define ARGS_H ++ ++struct args ++{ ++ char *conf_file; ++ char *dest; ++ char *tmp_dir; ++ int force_defaults; ++ int force_depends; ++ int force_overwrite; ++ int force_downgrade; ++ int force_reinstall; ++ int force_removal_of_essential_packages; ++ int force_removal_of_dependent_packages; ++ int force_space; ++ int noaction; ++ int nodeps; ++ int multiple_providers; ++ int query_all; ++ int verbose_wget; ++ int verbosity; ++ int nocheckfordirorfile; ++ int noreadfeedsfile; ++ char *offline_root; ++ char *offline_root_pre_script_cmd; ++ char *offline_root_post_script_cmd; ++}; ++typedef struct args args_t; ++ ++#define ARGS_DEFAULT_CONF_FILE_DIR "/etc" ++#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf" ++#define ARGS_DEFAULT_DEST NULL ++#define ARGS_DEFAULT_FORCE_DEFAULTS 0 ++#define ARGS_DEFAULT_FORCE_DEPENDS 0 ++#define ARGS_DEFAULT_FORCE_OVERWRITE 0 ++#define ARGS_DEFAULT_FORCE_DOWNGRADE 0 ++#define ARGS_DEFAULT_FORCE_REINSTALL 0 ++#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0 ++#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0 ++#define ARGS_DEFAULT_FORCE_SPACE 0 ++#define ARGS_DEFAULT_OFFLINE_ROOT NULL ++#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL ++#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL ++#define ARGS_DEFAULT_NOACTION 0 ++#define ARGS_DEFAULT_NODEPS 0 ++#define ARGS_DEFAULT_VERBOSE_WGET 0 ++#define ARGS_DEFAULT_VERBOSITY 1 ++ ++int args_init(args_t *args); ++void args_deinit(args_t *args); ++int args_parse(args_t *args, int argc, char *argv[]); ++void args_usage(char *complaint); ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/conffile.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/conffile.c 2007-10-04 17:14:22.249009320 +0200 +@@ -0,0 +1,64 @@ ++/* conffile.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include ++#include ++ ++#include "ipkg.h" ++#include "ipkg_message.h" ++ ++#include "conffile.h" ++#include "file_util.h" ++#include "sprintf_alloc.h" ++ ++int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum) ++{ ++ return nv_pair_init(conffile, file_name, md5sum); ++} ++ ++void conffile_deinit(conffile_t *conffile) ++{ ++ nv_pair_deinit(conffile); ++} ++ ++int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile) ++{ ++ char *md5sum; ++ char *filename = conffile->name; ++ char *root_filename; ++ int ret; ++ ++ if (conffile->value == NULL) { ++ ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name); ++ return 1; ++ } ++ ++ root_filename = root_filename_alloc(conf, filename); ++ ++ md5sum = file_md5sum_alloc(root_filename); ++ ++ ret = strcmp(md5sum, conffile->value); ++ if (ret) { ++ ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__, ++ conffile->name, md5sum, conffile->value); ++ } ++ ++ free(root_filename); ++ free(md5sum); ++ ++ return ret; ++} +Index: busybox-1.7.2/archival/libipkg/conffile.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/conffile.h 2007-10-04 17:14:22.277010917 +0200 +@@ -0,0 +1,30 @@ ++/* conffile.h - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef CONFFILE_H ++#define CONFFILE_H ++ ++#include "nv_pair.h" ++ ++typedef struct nv_pair conffile_t; ++ ++int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum); ++void conffile_deinit(conffile_t *conffile); ++int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile); ++ ++#endif ++ +Index: busybox-1.7.2/archival/libipkg/conffile_list.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/conffile_list.c 2007-10-04 17:14:22.301012282 +0200 +@@ -0,0 +1,47 @@ ++/* conffile_list.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++ ++#include "conffile_list.h" ++ ++int conffile_list_init(conffile_list_t *list) ++{ ++ return nv_pair_list_init(list); ++} ++ ++void conffile_list_deinit(conffile_list_t *list) ++{ ++ nv_pair_list_deinit(list); ++} ++ ++conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name, ++ const char *md5sum) ++{ ++ return nv_pair_list_append(list, file_name, md5sum); ++} ++ ++int conffile_list_push(conffile_list_t *list, conffile_t *data) ++{ ++ return nv_pair_list_push(list, data); ++} ++ ++conffile_list_elt_t *conffile_list_pop(conffile_list_t *list) ++{ ++ return nv_pair_list_pop(list); ++} ++ +Index: busybox-1.7.2/archival/libipkg/conffile_list.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/conffile_list.h 2007-10-04 17:14:22.325013650 +0200 +@@ -0,0 +1,36 @@ ++/* conffile_list.h - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef CONFFILE_LIST_H ++#define CONFFILE_LIST_H ++ ++#include "conffile.h" ++#include "nv_pair_list.h" ++ ++typedef struct nv_pair_list_elt conffile_list_elt_t; ++typedef struct nv_pair_list conffile_list_t; ++ ++int conffile_list_init(conffile_list_t *list); ++void conffile_list_deinit(conffile_list_t *list); ++ ++conffile_t *conffile_list_append(conffile_list_t *list, const char *name, ++ const char *root_dir); ++int conffile_list_push(conffile_list_t *list, conffile_t *data); ++conffile_list_elt_t *conffile_list_pop(conffile_list_t *list); ++ ++#endif ++ +Index: busybox-1.7.2/archival/libipkg/file_util.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/file_util.c 2007-10-04 17:14:22.353015250 +0200 +@@ -0,0 +1,132 @@ ++/* file_util.c - convenience routines for common stat operations ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++#include ++#include ++ ++#include "sprintf_alloc.h" ++#include "file_util.h" ++#include "libbb.h" ++#undef strlen ++ ++int file_exists(const char *file_name) ++{ ++ int err; ++ struct stat stat_buf; ++ ++ err = stat(file_name, &stat_buf); ++ if (err == 0) { ++ return 1; ++ } else { ++ return 0; ++ } ++} ++ ++int file_is_dir(const char *file_name) ++{ ++ int err; ++ struct stat stat_buf; ++ ++ err = stat(file_name, &stat_buf); ++ if (err) { ++ return 0; ++ } ++ ++ return S_ISDIR(stat_buf.st_mode); ++} ++ ++/* read a single line from a file, stopping at a newline or EOF. ++ If a newline is read, it will appear in the resulting string. ++ Return value is a malloc'ed char * which should be freed at ++ some point by the caller. ++ ++ Return value is NULL if the file is at EOF when called. ++*/ ++#define FILE_READ_LINE_BUF_SIZE 1024 ++char *file_read_line_alloc(FILE *file) ++{ ++ char buf[FILE_READ_LINE_BUF_SIZE]; ++ int buf_len; ++ char *line = NULL; ++ int line_size = 0; ++ ++ memset(buf, 0, FILE_READ_LINE_BUF_SIZE); ++ while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) { ++ buf_len = strlen(buf); ++ if (line) { ++ line_size += buf_len; ++ line = realloc(line, line_size); ++ if (line == NULL) { ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ break; ++ } ++ strcat(line, buf); ++ } else { ++ line_size = buf_len + 1; ++ line = strdup(buf); ++ } ++ if (buf[buf_len - 1] == '\n') { ++ break; ++ } ++ } ++ ++ return line; ++} ++ ++int file_move(const char *src, const char *dest) ++{ ++ int err; ++ ++ err = rename(src, dest); ++ ++ if (err && errno == EXDEV) { ++ err = file_copy(src, dest); ++ unlink(src); ++ } else if (err) { ++ fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n", ++ __FUNCTION__, src, dest, strerror(errno)); ++ } ++ ++ return err; ++} ++ ++/* I put these here to keep libbb dependencies from creeping all over ++ the ipkg code */ ++int file_copy(const char *src, const char *dest) ++{ ++ int err; ++ ++ err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS); ++ if (err) { ++ fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n", ++ __FUNCTION__, src, dest); ++ } ++ ++ return err; ++} ++ ++int file_mkdir_hier(const char *path, long mode) ++{ ++ return bb_make_directory((char *)path, mode, FILEUTILS_RECUR); ++} ++ ++char *file_md5sum_alloc(const char *file_name) ++{ ++ return hash_file(file_name, HASH_MD5); ++} ++ +Index: busybox-1.7.2/archival/libipkg/file_util.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/file_util.h 2007-10-04 17:14:22.377016616 +0200 +@@ -0,0 +1,29 @@ ++/* file_util.h - convenience routines for common file operations ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef FILE_UTIL_H ++#define FILE_UTIL_H ++ ++int file_exists(const char *file_name); ++int file_is_dir(const char *file_name); ++char *file_read_line_alloc(FILE *file); ++int file_move(const char *src, const char *dest); ++int file_copy(const char *src, const char *dest); ++int file_mkdir_hier(const char *path, long mode); ++char *file_md5sum_alloc(const char *file_name); ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/hash_table.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/hash_table.c 2007-10-04 17:14:22.397017756 +0200 +@@ -0,0 +1,155 @@ ++/* hash.c - hash tables for ipkg ++ ++ Steven M. Ayer, Jamey Hicks ++ ++ Copyright (C) 2002 Compaq Computer Corporation ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include ++#include ++#include ++#include ++#include "hash_table.h" ++#include "ipkg_message.h" ++ ++ ++static int hash_index(hash_table_t *hash, const char *pkg_name); ++static int rotating(const char *key, int len, int prime); ++ ++static int hash_index(hash_table_t *hash, const char *pkg_name) ++{ ++ return rotating(pkg_name, strlen(pkg_name), hash->n_entries); ++} ++ ++static int rotating(const char *key, int len, int prime) ++{ ++ unsigned int hash, i; ++ for (hash=len, i=0; i>28)^key[i]; ++ return (hash % prime); ++} ++ ++ ++/* ++ * this is an open table keyed by strings ++ */ ++int hash_table_init(const char *name, hash_table_t *hash, int len) ++{ ++ static int primes_table[] = { ++ 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587, ++ 19471, 23143, 33961, 46499, 49727, 99529, 0 ++ }; ++ int *picker; ++ ++ if (hash->entries != NULL) { ++ /* we have been here already */ ++ return 0; ++ } ++ ++ hash->name = name; ++ hash->entries = NULL; ++ hash->n_entries = 0; ++ hash->hash_entry_key = NULL; ++ ++ picker = primes_table; ++ while(*picker && (*picker++ < len)); ++ if(!*picker) ++ fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len); ++ --picker; ++ ++ hash->n_entries = *picker; ++ hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t)); ++ if (hash->entries == NULL) { ++ fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__); ++ return ENOMEM; ++ } ++ return 0; ++} ++ ++void hash_table_deinit(hash_table_t *hash) ++{ ++ free(hash->entries); ++ hash->entries = NULL; ++ hash->n_entries = 0; ++} ++ ++void *hash_table_get(hash_table_t *hash, const char *key) ++{ ++ int ndx= hash_index(hash, key); ++ hash_entry_t *hash_entry = hash->entries + ndx; ++ while (hash_entry) ++ { ++ if (hash_entry->key) ++ { ++ if (strcmp(key, hash_entry->key) == 0) { ++ // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key); ++ return hash_entry->data; ++ } ++ } ++ hash_entry = hash_entry->next; ++ } ++ return NULL; ++} ++ ++int hash_table_insert(hash_table_t *hash, const char *key, void *value) ++{ ++ int ndx= hash_index(hash, key); ++ hash_entry_t *hash_entry = hash->entries + ndx; ++ if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key); ++ if (hash_entry->key) { ++ if (strcmp(hash_entry->key, key) == 0) { ++ /* alread in table, update the value */ ++ if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key); ++ hash_entry->data = value; ++ return 0; ++ } else { ++ /* ++ * if this is a collision, we have to go to the end of the ll, ++ * then add a new entry ++ * before we can hook up the value ++ */ ++ if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key); ++ while (hash_entry->next) ++ hash_entry = hash_entry->next; ++ hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t)); ++ if (!hash_entry->next) { ++ return -ENOMEM; ++ } ++ hash_entry = hash_entry->next; ++ hash_entry->next = NULL; ++ } ++ } ++ hash->n_elements++; ++ hash_entry->key = strdup(key); ++ hash_entry->data = value; ++ ++ return 0; ++} ++ ++ ++void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data) ++{ ++ int i; ++ if (!hash || !f) ++ return; ++ ++ for (i = 0; i < hash->n_entries; i++) { ++ hash_entry_t *hash_entry = (hash->entries + i); ++ do { ++ if(hash_entry->key) { ++ f(hash_entry->key, hash_entry->data, data); ++ } ++ } while((hash_entry = hash_entry->next)); ++ } ++} ++ +Index: busybox-1.7.2/archival/libipkg/hash_table.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/hash_table.h 2007-10-04 17:14:22.425019349 +0200 +@@ -0,0 +1,44 @@ ++/* hash.h - hash tables for ipkg ++ ++ Steven M. Ayer, Jamey Hicks ++ ++ Copyright (C) 2002 Compaq Computer Corporation ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef _HASH_TABLE_H_ ++#define _HASH_TABLE_H_ ++ ++typedef struct hash_entry hash_entry_t; ++typedef struct hash_table hash_table_t; ++ ++struct hash_entry { ++ const char * key; ++ void * data; ++ struct hash_entry * next; ++}; ++ ++struct hash_table { ++ const char *name; ++ hash_entry_t * entries; ++ int n_entries; /* number of buckets */ ++ int n_elements; ++ const char * (*hash_entry_key)(void * data); ++}; ++ ++int hash_table_init(const char *name, hash_table_t *hash, int len); ++void hash_table_deinit(hash_table_t *hash); ++void *hash_table_get(hash_table_t *hash, const char *key); ++int hash_table_insert(hash_table_t *hash, const char *key, void *value); ++void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data); ++ ++#endif /* _HASH_TABLE_H_ */ +Index: busybox-1.7.2/archival/libipkg/ipkg_cmd.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg_cmd.c 2007-10-04 17:14:22.449020718 +0200 +@@ -0,0 +1,1431 @@ ++/* ipkg_cmd.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include ++ ++#include "ipkg.h" ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include "ipkg_conf.h" ++#include "ipkg_cmd.h" ++#include "ipkg_message.h" ++#include "pkg.h" ++#include "pkg_dest.h" ++#include "pkg_parse.h" ++#include "sprintf_alloc.h" ++#include "pkg.h" ++#include "file_util.h" ++#include "str_util.h" ++#include "libbb.h" ++#include "unarchive.h" ++ ++#include ++ ++ ++#include "ipkg_download.h" ++#include "ipkg_install.h" ++#include "ipkg_upgrade.h" ++#include "ipkg_remove.h" ++#include "ipkg_configure.h" ++#include "ipkg_message.h" ++ ++#ifdef IPKG_LIB ++#include "libipkg.h" ++static void *p_userdata = NULL; ++#endif ++ ++static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv); ++static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv); ++ ++/* XXX: CLEANUP: The usage strings should be incorporated into this ++ array for easier maintenance */ ++static ipkg_cmd_t cmds[] = { ++ {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd}, ++ {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd}, ++ {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd}, ++ {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd}, ++ {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd}, ++ {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd}, ++ {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd}, ++ {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd}, ++ {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd}, ++ {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd}, ++ {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd}, ++ {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd}, ++ {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd}, ++ {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd}, ++ {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd}, ++ {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd}, ++ {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd}, ++ {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd}, ++ {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd}, ++ {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd}, ++ {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd}, ++ {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd}, ++ {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd}, ++ {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd}, ++ {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd}, ++ {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd}, ++ {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd}, ++ {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd}, ++ {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd}, ++}; ++ ++int ipkg_state_changed; ++static void write_status_files_if_changed(ipkg_conf_t *conf) ++{ ++ if (ipkg_state_changed && !conf->noaction) { ++ ipkg_message(conf, IPKG_INFO, ++ " writing status file\n"); ++ ipkg_conf_write_status_files(conf); ++ pkg_write_changed_filelists(conf); ++ } else { ++ ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n"); ++ } ++} ++ ++ ++static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t); ++ ++ipkg_cmd_t *ipkg_cmd_find(const char *name) ++{ ++ int i; ++ ipkg_cmd_t *cmd; ++ ++ for (i=0; i < num_cmds; i++) { ++ cmd = &cmds[i]; ++ if (strcmp(name, cmd->name) == 0) { ++ return cmd; ++ } ++ } ++ ++ return NULL; ++} ++ ++#ifdef IPKG_LIB ++int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata) ++{ ++ int result; ++ p_userdata = userdata; ++ ++ ++ result = (cmd->fun)(conf, argc, argv); ++ if ( result == 0 ) { ++ ipkg_message(conf, IPKG_NOTICE, "Done.\n"); ++ } else { ++ ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result); ++ ++ } ++ if ( error_list ) { ++ reverse_error_list(&error_list); ++ ++ ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n"); ++ /* Here we print the errors collected and free the list */ ++ while (error_list != NULL) { ++ ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg); ++ error_list = error_list->next; ++ ++ } ++ free_error_list(&error_list); ++ ++ } ++ ++ p_userdata = NULL; ++ return result; ++} ++#else ++int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv) ++{ ++ return (cmd->fun)(conf, argc, argv); ++} ++#endif ++ ++static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ int err; ++ int failures; ++ char *lists_dir; ++ pkg_src_list_elt_t *iter; ++ pkg_src_t *src; ++ ++ ++ sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir); ++ ++ if (! file_is_dir(lists_dir)) { ++ if (file_exists(lists_dir)) { ++ ipkg_message(conf, IPKG_ERROR, ++ "%s: ERROR: %s exists, but is not a directory\n", ++ __FUNCTION__, lists_dir); ++ free(lists_dir); ++ return EINVAL; ++ } ++ err = file_mkdir_hier(lists_dir, 0755); ++ if (err) { ++ ipkg_message(conf, IPKG_ERROR, ++ "%s: ERROR: failed to make directory %s: %s\n", ++ __FUNCTION__, lists_dir, strerror(errno)); ++ free(lists_dir); ++ return EINVAL; ++ } ++ } ++ ++ failures = 0; ++ for (iter = conf->pkg_src_list.head; iter; iter = iter->next) { ++ char *url, *list_file_name; ++ ++ src = iter->data; ++ ++ if (src->extra_data) /* debian style? */ ++ sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data, ++ src->gzip ? "Packages.gz" : "Packages"); ++ else ++ sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages"); ++ ++ sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name); ++ if (src->gzip) { ++ char *tmp; ++ char *tmp_file_name; ++ FILE *in, *out; ++ ++ tmp = strdup ("/tmp/ipkg.XXXXXX"); ++ ++ if (mkdtemp (tmp) == NULL) { ++ perror ("mkdtemp"); ++ failures++; ++ continue; ++ } ++ ++ sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name); ++ err = ipkg_download(conf, url, tmp_file_name); ++ if (err == 0) { ++ ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url); ++ in = fopen (tmp_file_name, "r"); ++ out = fopen (list_file_name, "w"); ++ if (in && out) { ++ inflate_unzip_result res; ++ inflate_unzip (&res, 0x8000, fileno(in), fileno(out)); ++ } else ++ err = 1; ++ if (in) ++ fclose (in); ++ if (out) ++ fclose (out); ++ unlink (tmp_file_name); ++ rmdir (tmp); ++ free (tmp); ++ } ++ } else ++ err = ipkg_download(conf, url, list_file_name); ++ if (err) { ++ failures++; ++ } else { ++ ipkg_message(conf, IPKG_NOTICE, ++ "Updated list of available packages in %s\n", ++ list_file_name); ++ } ++ free(url); ++ free(list_file_name); ++ } ++ free(lists_dir); ++ ++#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG ++#warning here ++ /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED. ++ * this is a hack to work around poor bookkeeping in old ipkg upgrade code ++ * -Jamey 3/1/03 ++ */ ++ { ++ int i; ++ int changed = 0; ++ pkg_vec_t *available = pkg_vec_alloc(); ++ pkg_hash_fetch_available(&conf->pkg_hash, available); ++ ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n"); ++ for (i = 0; i < available->len; i++) { ++ pkg_t *pkg = available->pkgs[i]; ++ if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) { ++ ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name); ++ pkg->state_want = SW_UNKNOWN; ++ changed = 1; ++ } ++ } ++ pkg_vec_free(available); ++ if (changed) { ++ write_status_files_if_changed(conf); ++ } ++ } ++#endif ++ ++ return failures; ++} ++ ++ ++/* scan the args passed and cache the local filenames of the packages */ ++int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ int i; ++ int err; ++ ++ /* ++ * First scan through package names/urls ++ * For any urls, download the packages and install in database. ++ * For any files, install package info in database. ++ */ ++ for (i = 0; i < argc; i ++) { ++ char *filename = argv [i]; ++ //char *tmp = basename (tmp); ++ //int tmplen = strlen (tmp); ++ ++ //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0) ++ // continue; ++ //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0) ++ // continue; ++ ++ ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename ); ++ ++ err = ipkg_prepare_url_for_install(conf, filename, &argv[i]); ++ if (err) ++ return err; ++ } ++ return 0; ++} ++ ++struct ipkg_intercept ++{ ++ char *oldpath; ++ char *statedir; ++}; ++ ++typedef struct ipkg_intercept *ipkg_intercept_t; ++ ++ipkg_intercept_t ipkg_prep_intercepts(ipkg_conf_t *conf) ++{ ++ ipkg_intercept_t ctx; ++ char *newpath; ++ int gen; ++ ++ ctx = malloc (sizeof (*ctx)); ++ ctx->oldpath = strdup (getenv ("PATH")); ++ ++ sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath); ++ setenv ("PATH", newpath, 1); ++ free (newpath); ++ ++ gen = 0; ++ retry: ++ sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen); ++ if (mkdir (ctx->statedir, 0770) < 0) { ++ if (errno == EEXIST) { ++ free (ctx->statedir); ++ gen++; ++ goto retry; ++ } ++ perror (ctx->statedir); ++ return NULL; ++ } ++ setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1); ++ return ctx; ++} ++ ++int ipkg_finalize_intercepts(ipkg_intercept_t ctx) ++{ ++ char *cmd; ++ DIR *dir; ++ int err = 0; ++ ++ setenv ("PATH", ctx->oldpath, 1); ++ free (ctx->oldpath); ++ ++ dir = opendir (ctx->statedir); ++ if (dir) { ++ struct dirent *de; ++ while (de = readdir (dir), de != NULL) { ++ char *path; ++ ++ if (de->d_name[0] == '.') ++ continue; ++ ++ sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name); ++ if (access (path, X_OK) == 0) { ++ if (system (path)) { ++ err = errno; ++ perror (de->d_name); ++ } ++ } ++ free (path); ++ } ++ } else ++ perror (ctx->statedir); ++ ++ sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir); ++ system (cmd); ++ free (cmd); ++ ++ free (ctx->statedir); ++ free (ctx); ++ ++ return err; ++} ++ ++int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name) ++{ ++ pkg_vec_t *all; ++ int i; ++ pkg_t *pkg; ++ ipkg_intercept_t ic; ++ int r, err = 0; ++ ++ ipkg_message(conf, IPKG_INFO, ++ "Configuring unpacked packages\n"); ++ fflush( stdout ); ++ ++ all = pkg_vec_alloc(); ++ pkg_hash_fetch_available(&conf->pkg_hash, all); ++ ++ ic = ipkg_prep_intercepts (conf); ++ ++ for(i = 0; i < all->len; i++) { ++ pkg = all->pkgs[i]; ++ ++ if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) ++ continue; ++ ++ if (pkg->state_status == SS_UNPACKED) { ++ ipkg_message(conf, IPKG_NOTICE, ++ "Configuring %s\n", pkg->name); ++ fflush( stdout ); ++ r = ipkg_configure(conf, pkg); ++ if (r == 0) { ++ pkg->state_status = SS_INSTALLED; ++ pkg->parent->state_status = SS_INSTALLED; ++ pkg->state_flag &= ~SF_PREFER; ++ } else { ++ if (!err) ++ err = r; ++ } ++ } ++ } ++ ++ r = ipkg_finalize_intercepts (ic); ++ if (r && !err) ++ err = r; ++ ++ pkg_vec_free(all); ++ return err; ++} ++ ++static void sigint_handler(int sig) ++{ ++ signal(sig, SIG_DFL); ++ ipkg_message(NULL, IPKG_NOTICE, ++ "ipkg: interrupted. writing out status database\n"); ++ write_status_files_if_changed(global_conf); ++ exit(128 + sig); ++} ++ ++static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ int i; ++ char *arg; ++ int err=0; ++ ++ global_conf = conf; ++ signal(SIGINT, sigint_handler); ++ ++ /* ++ * Now scan through package names and install ++ */ ++ for (i=0; i < argc; i++) { ++ arg = argv[i]; ++ ++ ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg ); ++ err = ipkg_prepare_url_for_install(conf, arg, &argv[i]); ++ if (err != EINVAL && err != 0) ++ return err; ++ } ++ pkg_info_preinstall_check(conf); ++ ++ for (i=0; i < argc; i++) { ++ arg = argv[i]; ++ if (conf->multiple_providers) ++ err = ipkg_install_multi_by_name(conf, arg); ++ else{ ++ err = ipkg_install_by_name(conf, arg); ++ } ++ if (err == IPKG_PKG_HAS_NO_CANDIDATE) { ++ ipkg_message(conf, IPKG_ERROR, ++ "Cannot find package %s.\n" ++ "Check the spelling or perhaps run 'ipkg update'\n", ++ arg); ++ } ++ } ++ ++ /* recheck to verify that all dependences are satisfied */ ++ if (0) ipkg_satisfy_all_dependences(conf); ++ ++ ipkg_configure_packages(conf, NULL); ++ ++ write_status_files_if_changed(conf); ++ ++ return err; ++} ++ ++static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ int i; ++ pkg_t *pkg; ++ int err; ++ ++ global_conf = conf; ++ signal(SIGINT, sigint_handler); ++ ++ if (argc) { ++ for (i=0; i < argc; i++) { ++ char *arg = argv[i]; ++ ++ err = ipkg_prepare_url_for_install(conf, arg, &arg); ++ if (err != EINVAL && err != 0) ++ return err; ++ } ++ pkg_info_preinstall_check(conf); ++ ++ for (i=0; i < argc; i++) { ++ char *arg = argv[i]; ++ if (conf->restrict_to_default_dest) { ++ pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash, ++ argv[i], ++ conf->default_dest); ++ if (pkg == NULL) { ++ ipkg_message(conf, IPKG_NOTICE, ++ "Package %s not installed in %s\n", ++ argv[i], conf->default_dest->name); ++ continue; ++ } ++ } else { ++ pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, ++ argv[i]); ++ } ++ if (pkg) ++ ipkg_upgrade_pkg(conf, pkg); ++ else { ++ ipkg_install_by_name(conf, arg); ++ } ++ } ++ } else { ++ pkg_vec_t *installed = pkg_vec_alloc(); ++ ++ pkg_info_preinstall_check(conf); ++ ++ pkg_hash_fetch_all_installed(&conf->pkg_hash, installed); ++ for (i = 0; i < installed->len; i++) { ++ pkg = installed->pkgs[i]; ++ ipkg_upgrade_pkg(conf, pkg); ++ } ++ pkg_vec_free(installed); ++ } ++ ++ /* recheck to verify that all dependences are satisfied */ ++ if (0) ipkg_satisfy_all_dependences(conf); ++ ++ ipkg_configure_packages(conf, NULL); ++ ++ write_status_files_if_changed(conf); ++ ++ return 0; ++} ++ ++static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ int i, err; ++ char *arg; ++ pkg_t *pkg; ++ ++ pkg_info_preinstall_check(conf); ++ for (i = 0; i < argc; i++) { ++ arg = argv[i]; ++ ++ pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg); ++ if (pkg == NULL) { ++ ipkg_message(conf, IPKG_ERROR, ++ "Cannot find package %s.\n" ++ "Check the spelling or perhaps run 'ipkg update'\n", ++ arg); ++ continue; ++ } ++ ++ err = ipkg_download_pkg(conf, pkg, "."); ++ ++ if (err) { ++ ipkg_message(conf, IPKG_ERROR, ++ "Failed to download %s\n", pkg->name); ++ } else { ++ ipkg_message(conf, IPKG_NOTICE, ++ "Downloaded %s as %s\n", ++ pkg->name, pkg->local_filename); ++ } ++ } ++ ++ return 0; ++} ++ ++ ++static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ int i ; ++ pkg_vec_t *available; ++ pkg_t *pkg; ++ char desc_short[IPKG_LIST_DESCRIPTION_LENGTH]; ++ char *newline; ++ char *pkg_name = NULL; ++ char *version_str; ++ ++ if (argc > 0) { ++ pkg_name = argv[0]; ++ } ++ available = pkg_vec_alloc(); ++ pkg_hash_fetch_available(&conf->pkg_hash, available); ++ for (i=0; i < available->len; i++) { ++ pkg = available->pkgs[i]; ++ /* if we have package name or pattern and pkg does not match, then skip it */ ++ if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) ++ continue; ++ if (pkg->description) { ++ strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH); ++ } else { ++ desc_short[0] = '\0'; ++ } ++ desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0'; ++ newline = strchr(desc_short, '\n'); ++ if (newline) { ++ *newline = '\0'; ++ } ++#ifndef IPKG_LIB ++ printf("%s - %s\n", pkg->name, desc_short); ++#else ++ if (ipkg_cb_list) { ++ version_str = pkg_version_str_alloc(pkg); ++ ipkg_cb_list(pkg->name,desc_short, ++ version_str, ++ pkg->state_status, ++ p_userdata); ++ free(version_str); ++ } ++#endif ++ } ++ pkg_vec_free(available); ++ ++ return 0; ++} ++ ++ ++static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ int i ; ++ pkg_vec_t *available; ++ pkg_t *pkg; ++ char desc_short[IPKG_LIST_DESCRIPTION_LENGTH]; ++ char *newline; ++ char *pkg_name = NULL; ++ char *version_str; ++ ++ if (argc > 0) { ++ pkg_name = argv[0]; ++ } ++ available = pkg_vec_alloc(); ++ pkg_hash_fetch_all_installed(&conf->pkg_hash, available); ++ for (i=0; i < available->len; i++) { ++ pkg = available->pkgs[i]; ++ /* if we have package name or pattern and pkg does not match, then skip it */ ++ if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) ++ continue; ++ if (pkg->description) { ++ strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH); ++ } else { ++ desc_short[0] = '\0'; ++ } ++ desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0'; ++ newline = strchr(desc_short, '\n'); ++ if (newline) { ++ *newline = '\0'; ++ } ++#ifndef IPKG_LIB ++ printf("%s - %s\n", pkg->name, desc_short); ++#else ++ if (ipkg_cb_list) { ++ version_str = pkg_version_str_alloc(pkg); ++ ipkg_cb_list(pkg->name,desc_short, ++ version_str, ++ pkg->state_status, ++ p_userdata); ++ free(version_str); ++ } ++#endif ++ } ++ ++ return 0; ++} ++ ++static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only) ++{ ++ int i; ++ pkg_vec_t *available; ++ pkg_t *pkg; ++ char *pkg_name = NULL; ++ char **pkg_fields = NULL; ++ int n_fields = 0; ++ char *buff ; // = (char *)malloc(1); ++ ++ if (argc > 0) { ++ pkg_name = argv[0]; ++ } ++ if (argc > 1) { ++ pkg_fields = &argv[1]; ++ n_fields = argc - 1; ++ } ++ ++ available = pkg_vec_alloc(); ++ if (installed_only) ++ pkg_hash_fetch_all_installed(&conf->pkg_hash, available); ++ else ++ pkg_hash_fetch_available(&conf->pkg_hash, available); ++ for (i=0; i < available->len; i++) { ++ pkg = available->pkgs[i]; ++ if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) { ++ continue; ++ } ++#ifndef IPKG_LIB ++ if (n_fields) { ++ for (j = 0; j < n_fields; j++) ++ pkg_print_field(pkg, stdout, pkg_fields[j]); ++ } else { ++ pkg_print_info(pkg, stdout); ++ } ++#else ++ ++ buff = pkg_formatted_info(pkg); ++ if ( buff ) { ++ if (ipkg_cb_status) ipkg_cb_status(pkg->name, ++ pkg->state_status, ++ buff, ++ p_userdata); ++/* ++ We should not forget that actually the pointer is allocated. ++ We need to free it :) ( Thanks florian for seeing the error ) ++*/ ++ free(buff); ++ } ++#endif ++ if (conf->verbosity > 1) { ++ conffile_list_elt_t *iter; ++ for (iter = pkg->conffiles.head; iter; iter = iter->next) { ++ conffile_t *cf = iter->data; ++ int modified = conffile_has_been_modified(conf, cf); ++ ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n", ++ cf->name, cf->value, modified); ++ } ++ } ++ } ++#ifndef IPKG_LIB ++ if (buff) ++ free(buff); ++#endif ++ pkg_vec_free(available); ++ ++ return 0; ++} ++ ++static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ return ipkg_info_status_cmd(conf, argc, argv, 0); ++} ++ ++static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ return ipkg_info_status_cmd(conf, argc, argv, 1); ++} ++ ++static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ ++ int err; ++ if (argc > 0) { ++ char *pkg_name = NULL; ++ ++ pkg_name = argv[0]; ++ ++ err = ipkg_configure_packages (conf, pkg_name); ++ ++ } else { ++ err = ipkg_configure_packages (conf, NULL); ++ } ++ ++ write_status_files_if_changed(conf); ++ ++ return err; ++} ++ ++static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ int i, err; ++ char *globpattern; ++ glob_t globbuf; ++ ++ sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir); ++ err = glob(globpattern, 0, NULL, &globbuf); ++ free(globpattern); ++ if (err) { ++ return 0; ++ } ++ ++ ipkg_message(conf, IPKG_NOTICE, ++ "The following packages in %s will now be installed.\n", ++ conf->pending_dir); ++ for (i = 0; i < globbuf.gl_pathc; i++) { ++ ipkg_message(conf, IPKG_NOTICE, ++ "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]); ++ } ++ ipkg_message(conf, IPKG_NOTICE, "\n"); ++ for (i = 0; i < globbuf.gl_pathc; i++) { ++ err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]); ++ if (err == 0) { ++ err = unlink(globbuf.gl_pathv[i]); ++ if (err) { ++ ipkg_message(conf, IPKG_ERROR, ++ "%s: ERROR: failed to unlink %s: %s\n", ++ __FUNCTION__, globbuf.gl_pathv[i], strerror(err)); ++ return err; ++ } ++ } ++ } ++ globfree(&globbuf); ++ ++ return err; ++} ++ ++static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ int i,a,done; ++ pkg_t *pkg; ++ pkg_t *pkg_to_remove; ++ pkg_vec_t *available; ++ char *pkg_name = NULL; ++ global_conf = conf; ++ signal(SIGINT, sigint_handler); ++ ++// ENH: Add the "no pkg removed" just in case. ++ ++ done = 0; ++ ++ available = pkg_vec_alloc(); ++ pkg_info_preinstall_check(conf); ++ if ( argc > 0 ) { ++ pkg_hash_fetch_all_installed(&conf->pkg_hash, available); ++ for (i=0; i < argc; i++) { ++ pkg_name = malloc(strlen(argv[i])+2); ++ strcpy(pkg_name,argv[i]); ++ for (a=0; a < available->len; a++) { ++ pkg = available->pkgs[a]; ++ if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) { ++ continue; ++ } ++ if (conf->restrict_to_default_dest) { ++ pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash, ++ pkg->name, ++ conf->default_dest); ++ } else { ++ pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name ); ++ } ++ ++ if (pkg == NULL) { ++ ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name); ++ continue; ++ } ++ if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped ++ ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name); ++ continue; ++ } ++ ipkg_remove_pkg(conf, pkg_to_remove,0); ++ done = 1; ++ } ++ free (pkg_name); ++ } ++ pkg_vec_free(available); ++ } else { ++ pkg_vec_t *installed_pkgs = pkg_vec_alloc(); ++ int flagged_pkg_count = 0; ++ int removed; ++ ++ pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs); ++ ++ for (i = 0; i < installed_pkgs->len; i++) { ++ pkg = installed_pkgs->pkgs[i]; ++ if (pkg->state_flag & SF_USER) { ++ flagged_pkg_count++; ++ } else { ++ if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) ++ ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name); ++ } ++ } ++ if (!flagged_pkg_count) { ++ ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n" ++ "so refusing to uninstall unflagged non-leaf packages\n"); ++ return 0; ++ } ++ ++ /* find packages not flagged SF_USER (i.e., installed to ++ * satisfy a dependence) and not having any dependents, and ++ * remove them */ ++ do { ++ removed = 0; ++ for (i = 0; i < installed_pkgs->len; i++) { ++ pkg = installed_pkgs->pkgs[i]; ++ if (!(pkg->state_flag & SF_USER) ++ && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) { ++ removed++; ++ ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n"); ++ ipkg_remove_pkg(conf, pkg,0); ++ done = 1; ++ } ++ } ++ } while (removed); ++ pkg_vec_free(installed_pkgs); ++ } ++ ++ if ( done == 0 ) ++ ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n"); ++ ++ write_status_files_if_changed(conf); ++ return 0; ++} ++ ++static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ int i; ++ pkg_t *pkg; ++ ++ global_conf = conf; ++ signal(SIGINT, sigint_handler); ++ ++ pkg_info_preinstall_check(conf); ++ ++ for (i=0; i < argc; i++) { ++ if (conf->restrict_to_default_dest) { ++ pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash, ++ argv[i], ++ conf->default_dest); ++ } else { ++ pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]); ++ } ++ ++ if (pkg == NULL) { ++ ipkg_message(conf, IPKG_ERROR, ++ "Package %s is not installed.\n", argv[i]); ++ continue; ++ } ++ ipkg_purge_pkg(conf, pkg); ++ } ++ ++ write_status_files_if_changed(conf); ++ return 0; ++} ++ ++static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ int i; ++ pkg_t *pkg; ++ char *flags = argv[0]; ++ ++ global_conf = conf; ++ signal(SIGINT, sigint_handler); ++ ++ for (i=1; i < argc; i++) { ++ if (conf->restrict_to_default_dest) { ++ pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash, ++ argv[i], ++ conf->default_dest); ++ } else { ++ pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]); ++ } ++ ++ if (pkg == NULL) { ++ ipkg_message(conf, IPKG_ERROR, ++ "Package %s is not installed.\n", argv[i]); ++ continue; ++ } ++ if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)|| ++ ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) { ++ pkg->state_flag = pkg_state_flag_from_str(flags); ++ } ++/* pb_ asked this feature 03292004 */ ++/* Actually I will use only this two, but this is an open for various status */ ++ if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){ ++ pkg->state_status = pkg_state_status_from_str(flags); ++ } ++ ipkg_state_changed++; ++ ipkg_message(conf, IPKG_NOTICE, ++ "Setting flags for package %s to %s\n", ++ pkg->name, flags); ++ } ++ ++ write_status_files_if_changed(conf); ++ return 0; ++} ++ ++static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ pkg_t *pkg; ++ str_list_t *installed_files; ++ str_list_elt_t *iter; ++ char *pkg_version; ++ size_t buff_len = 8192; ++ size_t used_len; ++ char *buff ; ++ ++ buff = (char *)malloc(buff_len); ++ if ( buff == NULL ) { ++ fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__); ++ return ENOMEM; ++ } ++ ++ if (argc < 1) { ++ return EINVAL; ++ } ++ ++ pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, ++ argv[0]); ++ if (pkg == NULL) { ++ ipkg_message(conf, IPKG_ERROR, ++ "Package %s not installed.\n", argv[0]); ++ return 0; ++ } ++ ++ installed_files = pkg_get_installed_files(pkg); ++ pkg_version = pkg_version_str_alloc(pkg); ++ ++#ifndef IPKG_LIB ++ printf("Package %s (%s) is installed on %s and has the following files:\n", ++ pkg->name, pkg_version, pkg->dest->name); ++ for (iter = installed_files->head; iter; iter = iter->next) { ++ puts(iter->data); ++ } ++#else ++ if (buff) { ++ try_again: ++ used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n", ++ pkg->name, pkg_version, pkg->dest->name) + 1; ++ if (used_len > buff_len) { ++ buff_len *= 2; ++ buff = realloc (buff, buff_len); ++ goto try_again; ++ } ++ for (iter = installed_files->head; iter; iter = iter->next) { ++ used_len += strlen (iter->data) + 1; ++ while (buff_len <= used_len) { ++ buff_len *= 2; ++ buff = realloc (buff, buff_len); ++ } ++ strncat(buff, iter->data, buff_len); ++ strncat(buff, "\n", buff_len); ++ } ++ if (ipkg_cb_list) ipkg_cb_list(pkg->name, ++ buff, ++ pkg_version_str_alloc(pkg), ++ pkg->state_status, ++ p_userdata); ++ free(buff); ++ } ++#endif ++ ++ free(pkg_version); ++ pkg_free_installed_files(pkg); ++ ++ return 0; ++} ++ ++static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ ++ if (argc > 0) { ++ pkg_vec_t *available_pkgs = pkg_vec_alloc(); ++ const char *rel_str = "depends on"; ++ int i; ++ ++ pkg_info_preinstall_check(conf); ++ ++ if (conf->query_all) ++ pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs); ++ else ++ pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs); ++ for (i = 0; i < argc; i++) { ++ const char *target = argv[i]; ++ int j; ++ ++ ipkg_message(conf, IPKG_ERROR, "target=%s\n", target); ++ ++ for (j = 0; j < available_pkgs->len; j++) { ++ pkg_t *pkg = available_pkgs->pkgs[j]; ++ if (fnmatch(target, pkg->name, 0) == 0) { ++ int k; ++ int count = pkg->depends_count + pkg->pre_depends_count; ++ ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n", ++ target, pkg->architecture, rel_str); ++ for (k = 0; k < count; k++) { ++ compound_depend_t *cdepend = &pkg->depends[k]; ++ int l; ++ for (l = 0; l < cdepend->possibility_count; l++) { ++ depend_t *possibility = cdepend->possibilities[l]; ++ ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name); ++ if (conf->verbosity > 0) { ++ // char *ver = abstract_pkg_version_str_alloc(possibility->pkg); ++ ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version); ++ if (possibility->version) { ++ char *typestr = NULL; ++ switch (possibility->constraint) { ++ case NONE: typestr = "none"; break; ++ case EARLIER: typestr = "<"; break; ++ case EARLIER_EQUAL: typestr = "<="; break; ++ case EQUAL: typestr = "="; break; ++ case LATER_EQUAL: typestr = ">="; break; ++ case LATER: typestr = ">"; break; ++ } ++ ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version); ++ } ++ // free(ver); ++ } ++ ipkg_message(conf, IPKG_ERROR, "\n"); ++ } ++ } ++ } ++ } ++ } ++ pkg_vec_free(available_pkgs); ++ } ++ return 0; ++} ++ ++enum what_field_type { ++ WHATDEPENDS, ++ WHATCONFLICTS, ++ WHATPROVIDES, ++ WHATREPLACES, ++ WHATRECOMMENDS, ++ WHATSUGGESTS ++}; ++ ++static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv) ++{ ++ ++ if (argc > 0) { ++ pkg_vec_t *available_pkgs = pkg_vec_alloc(); ++ const char *rel_str = NULL; ++ int i; ++ int changed; ++ ++ switch (what_field_type) { ++ case WHATDEPENDS: rel_str = "depends on"; break; ++ case WHATCONFLICTS: rel_str = "conflicts with"; break; ++ case WHATSUGGESTS: rel_str = "suggests"; break; ++ case WHATRECOMMENDS: rel_str = "recommends"; break; ++ case WHATPROVIDES: rel_str = "provides"; break; ++ case WHATREPLACES: rel_str = "replaces"; break; ++ } ++ ++ if (conf->query_all) ++ pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs); ++ else ++ pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs); ++ ++ /* mark the root set */ ++ pkg_vec_clear_marks(available_pkgs); ++ ipkg_message(conf, IPKG_NOTICE, "Root set:\n"); ++ for (i = 0; i < argc; i++) { ++ const char *dependee_pattern = argv[i]; ++ pkg_vec_mark_if_matches(available_pkgs, dependee_pattern); ++ } ++ for (i = 0; i < available_pkgs->len; i++) { ++ pkg_t *pkg = available_pkgs->pkgs[i]; ++ if (pkg->state_flag & SF_MARKED) { ++ /* mark the parent (abstract) package */ ++ pkg_mark_provides(pkg); ++ ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name); ++ } ++ } ++ ++ ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str); ++ do { ++ int j; ++ changed = 0; ++ ++ for (j = 0; j < available_pkgs->len; j++) { ++ pkg_t *pkg = available_pkgs->pkgs[j]; ++ int k; ++ int count = ((what_field_type == WHATCONFLICTS) ++ ? pkg->conflicts_count ++ : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count); ++ /* skip this package if it is already marked */ ++ if (pkg->parent->state_flag & SF_MARKED) { ++ continue; ++ } ++ for (k = 0; k < count; k++) { ++ compound_depend_t *cdepend = ++ (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k]; ++ int l; ++ for (l = 0; l < cdepend->possibility_count; l++) { ++ depend_t *possibility = cdepend->possibilities[l]; ++ if (possibility->pkg->state_flag & SF_MARKED) { ++ /* mark the depending package so we won't visit it again */ ++ pkg->state_flag |= SF_MARKED; ++ pkg_mark_provides(pkg); ++ changed++; ++ ++ ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name); ++ if (conf->verbosity > 0) { ++ char *ver = pkg_version_str_alloc(pkg); ++ ipkg_message(conf, IPKG_NOTICE, " %s", ver); ++ ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name); ++ if (possibility->version) { ++ char *typestr = NULL; ++ switch (possibility->constraint) { ++ case NONE: typestr = "none"; break; ++ case EARLIER: typestr = "<"; break; ++ case EARLIER_EQUAL: typestr = "<="; break; ++ case EQUAL: typestr = "="; break; ++ case LATER_EQUAL: typestr = ">="; break; ++ case LATER: typestr = ">"; break; ++ } ++ ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version); ++ } ++ free(ver); ++ if (!pkg_dependence_satisfiable(conf, possibility)) ++ ipkg_message(conf, IPKG_NOTICE, " unsatisfiable"); ++ } ++ ipkg_message(conf, IPKG_NOTICE, "\n"); ++ goto next_package; ++ } ++ } ++ } ++ next_package: ++ ; ++ } ++ } while (changed && recursive); ++ pkg_vec_free(available_pkgs); ++ } ++ ++ return 0; ++} ++ ++int pkg_mark_provides(pkg_t *pkg) ++{ ++ int provides_count = pkg->provides_count; ++ abstract_pkg_t **provides = pkg->provides; ++ int i; ++ pkg->parent->state_flag |= SF_MARKED; ++ for (i = 0; i < provides_count; i++) { ++ provides[i]->state_flag |= SF_MARKED; ++ } ++ return 0; ++} ++ ++static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv); ++} ++static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv); ++} ++ ++static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv); ++} ++ ++static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv); ++} ++ ++static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv); ++} ++ ++static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv) ++{ ++ ++ if (argc > 0) { ++ pkg_vec_t *available_pkgs = pkg_vec_alloc(); ++ const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces"); ++ int i; ++ ++ pkg_info_preinstall_check(conf); ++ ++ if (conf->query_all) ++ pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs); ++ else ++ pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs); ++ for (i = 0; i < argc; i++) { ++ const char *target = argv[i]; ++ int j; ++ ++ ipkg_message(conf, IPKG_ERROR, "What %s %s\n", ++ rel_str, target); ++ for (j = 0; j < available_pkgs->len; j++) { ++ pkg_t *pkg = available_pkgs->pkgs[j]; ++ int k; ++ int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count; ++ for (k = 0; k < count; k++) { ++ abstract_pkg_t *apkg = ++ ((what_field_type == WHATPROVIDES) ++ ? pkg->provides[k] ++ : pkg->replaces[k]); ++ if (fnmatch(target, apkg->name, 0) == 0) { ++ ipkg_message(conf, IPKG_ERROR, " %s", pkg->name); ++ if (strcmp(target, apkg->name) != 0) ++ ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name); ++ ipkg_message(conf, IPKG_ERROR, "\n"); ++ } ++ } ++ } ++ } ++ pkg_vec_free(available_pkgs); ++ } ++ return 0; ++} ++ ++static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv); ++} ++ ++static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv); ++} ++ ++static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ int i; ++ ++ pkg_vec_t *installed; ++ pkg_t *pkg; ++ str_list_t *installed_files; ++ str_list_elt_t *iter; ++ char *installed_file; ++ ++ if (argc < 1) { ++ return EINVAL; ++ } ++ ++ installed = pkg_vec_alloc(); ++ pkg_hash_fetch_all_installed(&conf->pkg_hash, installed); ++ ++ for (i=0; i < installed->len; i++) { ++ pkg = installed->pkgs[i]; ++ ++ installed_files = pkg_get_installed_files(pkg); ++ ++ for (iter = installed_files->head; iter; iter = iter->next) { ++ installed_file = iter->data; ++ if (fnmatch(argv[0], installed_file, 0)==0) { ++#ifndef IPKG_LIB ++ printf("%s: %s\n", pkg->name, installed_file); ++#else ++ if (ipkg_cb_list) ipkg_cb_list(pkg->name, ++ installed_file, ++ pkg_version_str_alloc(pkg), ++ pkg->state_status, p_userdata); ++#endif ++ } ++ } ++ ++ pkg_free_installed_files(pkg); ++ } ++ ++ /* XXX: CLEANUP: It's not obvious from the name of ++ pkg_hash_fetch_all_installed that we need to call ++ pkg_vec_free to avoid a memory leak. */ ++ pkg_vec_free(installed); ++ ++ return 0; ++} ++ ++static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ if (argc == 3) { ++ /* this is a bit gross */ ++ struct pkg p1, p2; ++ parseVersion(&p1, argv[0]); ++ parseVersion(&p2, argv[2]); ++ return pkg_version_satisfied(&p1, &p2, argv[1]); ++ } else { ++ ipkg_message(conf, IPKG_ERROR, ++ "ipkg compare_versions \n" ++ " is one of <= >= << >> =\n"); ++ return -1; ++ } ++} ++ ++#ifndef HOST_CPU_STR ++#define HOST_CPU_STR__(X) #X ++#define HOST_CPU_STR_(X) HOST_CPU_STR__(X) ++#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO) ++#endif ++ ++static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv) ++{ ++ nv_pair_list_elt_t *l; ++ ++ l = conf->arch_list.head; ++ while (l) { ++ nv_pair_t *nv = l->data; ++ printf("arch %s %s\n", nv->name, nv->value); ++ l = l->next; ++ } ++ return 0; ++} ++ ++ +Index: busybox-1.7.2/archival/libipkg/ipkg_cmd.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg_cmd.h 2007-10-04 17:14:22.493023228 +0200 +@@ -0,0 +1,46 @@ ++/* ipkg_cmd.h - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef IPKG_CMD_H ++#define IPKG_CMD_H ++ ++typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv); ++ ++struct ipkg_cmd ++{ ++ char *name; ++ int requires_args; ++ ipkg_cmd_fun_t fun; ++}; ++typedef struct ipkg_cmd ipkg_cmd_t; ++ ++ipkg_cmd_t *ipkg_cmd_find(const char *name); ++#ifdef IPKG_LIB ++int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, ++ const char **argv, void *userdata); ++#else ++int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv); ++#endif ++int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]); ++/* install any packges with state_want == SW_INSTALL */ ++int ipkg_install_wanted_packages(ipkg_conf_t *conf); ++/* ensure that all dependences are satisfied */ ++int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name); ++ ++int pkg_mark_provides(pkg_t *pkg); ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/ipkg_conf.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg_conf.c 2007-10-04 17:14:22.513024368 +0200 +@@ -0,0 +1,711 @@ ++/* ipkg_conf.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include ++ ++#include "ipkg.h" ++#include "ipkg_conf.h" ++ ++#include "xregex.h" ++#include "sprintf_alloc.h" ++#include "ipkg_conf.h" ++#include "ipkg_message.h" ++#include "file_util.h" ++#include "str_util.h" ++#include "xsystem.h" ++ ++ ++ipkg_conf_t *global_conf; ++ ++static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename, ++ pkg_src_list_t *pkg_src_list, ++ nv_pair_list_t *tmp_dest_nv_pair_list, ++ char **tmp_lists_dir); ++static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options); ++static int ipkg_conf_set_option(const ipkg_option_t *options, ++ const char *name, const char *value); ++static int ipkg_conf_set_default_dest(ipkg_conf_t *conf, ++ const char *default_dest_name); ++static int set_and_load_pkg_src_list(ipkg_conf_t *conf, ++ pkg_src_list_t *nv_pair_list); ++static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, ++ nv_pair_list_t *nv_pair_list, char * lists_dir); ++ ++int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options) ++{ ++ ipkg_option_t tmp[] = { ++ { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults }, ++ { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends }, ++ { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite }, ++ { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade }, ++ { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall }, ++ { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space }, ++ { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy }, ++ { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy }, ++ { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers }, ++ { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy }, ++ { "test", IPKG_OPT_TYPE_INT, &conf->noaction }, ++ { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction }, ++ { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps }, ++ { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root }, ++ { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd }, ++ { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd }, ++ { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd }, ++ { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user }, ++ { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all }, ++ { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget }, ++ { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity }, ++ { NULL } ++ }; ++ ++ *options = (ipkg_option_t *)malloc(sizeof(tmp)); ++ if ( options == NULL ){ ++ fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__); ++ return -1; ++ } ++ ++ memcpy(*options, tmp, sizeof(tmp)); ++ return 0; ++}; ++ ++static void ipkg_conf_override_string(char **conf_str, char *arg_str) ++{ ++ if (arg_str) { ++ if (*conf_str) { ++ free(*conf_str); ++ } ++ *conf_str = strdup(arg_str); ++ } ++} ++ ++static void ipkg_conf_free_string(char **conf_str) ++{ ++ if (*conf_str) { ++ free(*conf_str); ++ *conf_str = NULL; ++ } ++} ++ ++int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args) ++{ ++ int err; ++ char *tmp_dir_base; ++ nv_pair_list_t tmp_dest_nv_pair_list; ++ char * lists_dir =NULL; ++ glob_t globbuf; ++ char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf"; ++ char *pending_dir =NULL; ++ ++ memset(conf, 0, sizeof(ipkg_conf_t)); ++ ++ pkg_src_list_init(&conf->pkg_src_list); ++ ++ nv_pair_list_init(&tmp_dest_nv_pair_list); ++ pkg_dest_list_init(&conf->pkg_dest_list); ++ ++ nv_pair_list_init(&conf->arch_list); ++ ++ conf->restrict_to_default_dest = 0; ++ conf->default_dest = NULL; ++ ++ ++ if (args->tmp_dir) ++ tmp_dir_base = args->tmp_dir; ++ else ++ tmp_dir_base = getenv("TMPDIR"); ++ sprintf_alloc(&conf->tmp_dir, "%s/%s", ++ tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE, ++ IPKG_CONF_TMP_DIR_SUFFIX); ++ conf->tmp_dir = mkdtemp(conf->tmp_dir); ++ if (conf->tmp_dir == NULL) { ++ fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n", ++ __FUNCTION__, conf->tmp_dir, strerror(errno)); ++ return errno; ++ } ++ ++ conf->force_depends = 0; ++ conf->force_defaults = 0; ++ conf->force_overwrite = 0; ++ conf->force_downgrade = 0; ++ conf->force_reinstall = 0; ++ conf->force_space = 0; ++ conf->force_removal_of_essential_packages = 0; ++ conf->force_removal_of_dependent_packages = 0; ++ conf->nodeps = 0; ++ conf->verbose_wget = 0; ++ conf->offline_root = NULL; ++ conf->offline_root_pre_script_cmd = NULL; ++ conf->offline_root_post_script_cmd = NULL; ++ conf->multiple_providers = 0; ++ conf->verbosity = 1; ++ conf->noaction = 0; ++ ++ conf->http_proxy = NULL; ++ conf->ftp_proxy = NULL; ++ conf->no_proxy = NULL; ++ conf->proxy_user = NULL; ++ conf->proxy_passwd = NULL; ++ ++ pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN); ++ hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN); ++ hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN); ++ lists_dir=(char *)malloc(1); ++ lists_dir[0]='\0'; ++ if (args->conf_file) { ++ struct stat stat_buf; ++ err = stat(args->conf_file, &stat_buf); ++ if (err == 0) ++ if (ipkg_conf_parse_file(conf, args->conf_file, ++ &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) { ++ /* Memory leakage from ipkg_conf_parse-file */ ++ return -1; ++ } ++ ++ } ++ ++ /* if (!lists_dir ){*/ ++ if (strlen(lists_dir)<=1 ){ ++ lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2); ++ sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR); ++ } ++ ++ if (args->offline_root) { ++ char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1); ++ sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir); ++ free(lists_dir); ++ lists_dir = tmp; ++ } ++ ++ pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5); ++ snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending"); ++ ++ conf->lists_dir = strdup(lists_dir); ++ conf->pending_dir = strdup(pending_dir); ++ ++ if (args->offline_root) ++ sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root); ++ memset(&globbuf, 0, sizeof(globbuf)); ++ err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf); ++ if (!err) { ++ int i; ++ for (i = 0; i < globbuf.gl_pathc; i++) { ++ if (globbuf.gl_pathv[i]) ++ if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i], ++ &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) { ++ /* Memory leakage from ipkg_conf_parse-file */ ++ return -1; ++ } ++ } ++ } ++ globfree(&globbuf); ++ ++ /* if no architectures were defined, then default all, noarch, and host architecture */ ++ if (nv_pair_list_empty(&conf->arch_list)) { ++ nv_pair_list_append(&conf->arch_list, "all", "1"); ++ nv_pair_list_append(&conf->arch_list, "noarch", "1"); ++ nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10"); ++ } ++ ++ /* Even if there is no conf file, we'll need at least one dest. */ ++ if (tmp_dest_nv_pair_list.head == NULL) { ++ nv_pair_list_append(&tmp_dest_nv_pair_list, ++ IPKG_CONF_DEFAULT_DEST_NAME, ++ IPKG_CONF_DEFAULT_DEST_ROOT_DIR); ++ } ++ ++ /* After parsing the file, set options from command-line, (so that ++ command-line arguments take precedence) */ ++ /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c ++ really needs to be cleaned up. There is so much duplication ++ right now it is ridiculous. Maybe ipkg_conf_t should just save ++ a pointer to args_t (which could then not be freed), rather ++ than duplicating every field here? */ ++ if (args->force_depends) { ++ conf->force_depends = 1; ++ } ++ if (args->force_defaults) { ++ conf->force_defaults = 1; ++ } ++ if (args->force_overwrite) { ++ conf->force_overwrite = 1; ++ } ++ if (args->force_downgrade) { ++ conf->force_downgrade = 1; ++ } ++ if (args->force_reinstall) { ++ conf->force_reinstall = 1; ++ } ++ if (args->force_removal_of_dependent_packages) { ++ conf->force_removal_of_dependent_packages = 1; ++ } ++ if (args->force_removal_of_essential_packages) { ++ conf->force_removal_of_essential_packages = 1; ++ } ++ if (args->nodeps) { ++ conf->nodeps = 1; ++ } ++ if (args->noaction) { ++ conf->noaction = 1; ++ } ++ if (args->query_all) { ++ conf->query_all = 1; ++ } ++ if (args->verbose_wget) { ++ conf->verbose_wget = 1; ++ } ++ if (args->multiple_providers) { ++ conf->multiple_providers = 1; ++ } ++ if (args->verbosity != conf->verbosity) { ++ conf->verbosity = args->verbosity; ++ } ++ ++ ipkg_conf_override_string(&conf->offline_root, ++ args->offline_root); ++ ipkg_conf_override_string(&conf->offline_root_pre_script_cmd, ++ args->offline_root_pre_script_cmd); ++ ipkg_conf_override_string(&conf->offline_root_post_script_cmd, ++ args->offline_root_post_script_cmd); ++ ++/* Pigi: added a flag to disable the checking of structures if the command does not need to ++ read anything from there. ++*/ ++ if ( !(args->nocheckfordirorfile)){ ++ /* need to run load the source list before dest list -Jamey */ ++ if ( !(args->noreadfeedsfile)) ++ set_and_load_pkg_src_list(conf, &conf->pkg_src_list); ++ ++ /* Now that we have resolved conf->offline_root, we can commit to ++ the directory names for the dests and load in all the package ++ lists. */ ++ set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir); ++ ++ if (args->dest) { ++ err = ipkg_conf_set_default_dest(conf, args->dest); ++ if (err) { ++ return err; ++ } ++ } ++ } ++ nv_pair_list_deinit(&tmp_dest_nv_pair_list); ++ free(lists_dir); ++ free(pending_dir); ++ ++ return 0; ++} ++ ++void ipkg_conf_deinit(ipkg_conf_t *conf) ++{ ++#ifdef IPKG_DEBUG_NO_TMP_CLEANUP ++#error ++ fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled " ++ "with IPKG_DEBUG_NO_TMP_CLEANUP\n", ++ __FUNCTION__, conf->tmp_dir); ++#else ++ int err; ++ ++ err = rmdir(conf->tmp_dir); ++ if (err) { ++ if (errno == ENOTEMPTY) { ++ char *cmd; ++ sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir); ++ err = xsystem(cmd); ++ free(cmd); ++ } ++ if (err) ++ fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno)); ++ } ++#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */ ++ ++ free(conf->tmp_dir); /*XXX*/ ++ ++ pkg_src_list_deinit(&conf->pkg_src_list); ++ pkg_dest_list_deinit(&conf->pkg_dest_list); ++ nv_pair_list_deinit(&conf->arch_list); ++ if (&conf->pkg_hash) ++ pkg_hash_deinit(&conf->pkg_hash); ++ if (&conf->file_hash) ++ hash_table_deinit(&conf->file_hash); ++ if (&conf->obs_file_hash) ++ hash_table_deinit(&conf->obs_file_hash); ++ ++ ipkg_conf_free_string(&conf->offline_root); ++ ipkg_conf_free_string(&conf->offline_root_pre_script_cmd); ++ ipkg_conf_free_string(&conf->offline_root_post_script_cmd); ++ ++ if (conf->verbosity > 1) { ++ int i; ++ hash_table_t *hashes[] = { ++ &conf->pkg_hash, ++ &conf->file_hash, ++ &conf->obs_file_hash }; ++ for (i = 0; i < 3; i++) { ++ hash_table_t *hash = hashes[i]; ++ int c = 0; ++ int n_conflicts = 0; ++ int j; ++ for (j = 0; j < hash->n_entries; j++) { ++ int len = 0; ++ hash_entry_t *e = &hash->entries[j]; ++ if (e->next) ++ n_conflicts++; ++ while (e && e->key) { ++ len++; ++ e = e->next; ++ } ++ if (len > c) ++ c = len; ++ } ++ ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n", ++ hash->name, hash->n_entries, hash->n_elements, c, n_conflicts); ++ hash_table_deinit(hash); ++ } ++ } ++} ++ ++static int ipkg_conf_set_default_dest(ipkg_conf_t *conf, ++ const char *default_dest_name) ++{ ++ pkg_dest_list_elt_t *iter; ++ pkg_dest_t *dest; ++ ++ for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) { ++ dest = iter->data; ++ if (strcmp(dest->name, default_dest_name) == 0) { ++ conf->default_dest = dest; ++ conf->restrict_to_default_dest = 1; ++ return 0; ++ } ++ } ++ ++ fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name); ++ ++ return 1; ++} ++ ++static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list) ++{ ++ pkg_src_list_elt_t *iter; ++ pkg_src_t *src; ++ char *list_file; ++ ++ for (iter = pkg_src_list->head; iter; iter = iter->next) { ++ src = iter->data; ++ if (src == NULL) { ++ continue; ++ } ++ ++ sprintf_alloc(&list_file, "%s/%s", ++ conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir, ++ src->name); ++ ++ if (file_exists(list_file)) { ++ pkg_hash_add_from_file(conf, list_file, src, NULL, 0); ++ } ++ free(list_file); ++ } ++ ++ return 0; ++} ++ ++static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir ) ++{ ++ nv_pair_list_elt_t *iter; ++ nv_pair_t *nv_pair; ++ pkg_dest_t *dest; ++ char *root_dir; ++ ++ for (iter = nv_pair_list->head; iter; iter = iter->next) { ++ nv_pair = iter->data; ++ ++ if (conf->offline_root) { ++ sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value); ++ } else { ++ root_dir = strdup(nv_pair->value); ++ } ++ dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir); ++ free(root_dir); ++ if (dest == NULL) { ++ continue; ++ } ++ if (conf->default_dest == NULL) { ++ conf->default_dest = dest; ++ } ++ if (file_exists(dest->status_file_name)) { ++ pkg_hash_add_from_file(conf, dest->status_file_name, ++ NULL, dest, 1); ++ } ++ } ++ ++ return 0; ++} ++ ++static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename, ++ pkg_src_list_t *pkg_src_list, ++ nv_pair_list_t *tmp_dest_nv_pair_list, ++ char **lists_dir) ++{ ++ ipkg_option_t * options; ++ FILE *file = fopen(filename, "r"); ++ regex_t valid_line_re, comment_re; ++#define regmatch_size 12 ++ regmatch_t regmatch[regmatch_size]; ++ ++ if (ipkg_init_options_array(conf, &options)<0) ++ return ENOMEM; ++ ++ if (file == NULL) { ++ fprintf(stderr, "%s: failed to open %s: %s\n", ++ __FUNCTION__, filename, strerror(errno)); ++ free(options); ++ return errno; ++ } ++ ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename); ++ ++ xregcomp(&comment_re, ++ "^[[:space:]]*(#.*|[[:space:]]*)$", ++ REG_EXTENDED); ++ xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED); ++ ++ while(1) { ++ int line_num = 0; ++ char *line; ++ char *type, *name, *value, *extra; ++ ++ line = file_read_line_alloc(file); ++ line_num++; ++ if (line == NULL) { ++ break; ++ } ++ ++ str_chomp(line); ++ ++ if (regexec(&comment_re, line, 0, 0, 0) == 0) { ++ goto NEXT_LINE; ++ } ++ ++ if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) { ++ str_chomp(line); ++ fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n", ++ filename, line_num, line); ++ goto NEXT_LINE; ++ } ++ ++ /* This has to be so ugly to deal with optional quotation marks */ ++ if (regmatch[2].rm_so > 0) { ++ type = strndup(line + regmatch[2].rm_so, ++ regmatch[2].rm_eo - regmatch[2].rm_so); ++ } else { ++ type = strndup(line + regmatch[3].rm_so, ++ regmatch[3].rm_eo - regmatch[3].rm_so); ++ } ++ if (regmatch[5].rm_so > 0) { ++ name = strndup(line + regmatch[5].rm_so, ++ regmatch[5].rm_eo - regmatch[5].rm_so); ++ } else { ++ name = strndup(line + regmatch[6].rm_so, ++ regmatch[6].rm_eo - regmatch[6].rm_so); ++ } ++ if (regmatch[8].rm_so > 0) { ++ value = strndup(line + regmatch[8].rm_so, ++ regmatch[8].rm_eo - regmatch[8].rm_so); ++ } else { ++ value = strndup(line + regmatch[9].rm_so, ++ regmatch[9].rm_eo - regmatch[9].rm_so); ++ } ++ extra = NULL; ++ if (regmatch[11].rm_so > 0) { ++ extra = strndup (line + regmatch[11].rm_so, ++ regmatch[11].rm_eo - regmatch[11].rm_so); ++ } ++ ++ /* We use the tmp_dest_nv_pair_list below instead of ++ conf->pkg_dest_list because we might encounter an ++ offline_root option later and that would invalidate the ++ directories we would have computed in ++ pkg_dest_list_init. (We do a similar thing with ++ tmp_src_nv_pair_list for sake of symmetry.) */ ++ if (strcmp(type, "option") == 0) { ++ ipkg_conf_set_option(options, name, value); ++ } else if (strcmp(type, "src") == 0) { ++ if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) { ++ pkg_src_list_append (pkg_src_list, name, value, extra, 0); ++ } else { ++ ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n", ++ name, value); ++ } ++ } else if (strcmp(type, "src/gz") == 0) { ++ if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) { ++ pkg_src_list_append (pkg_src_list, name, value, extra, 1); ++ } else { ++ ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n", ++ name, value); ++ } ++ } else if (strcmp(type, "dest") == 0) { ++ nv_pair_list_append(tmp_dest_nv_pair_list, name, value); ++ } else if (strcmp(type, "lists_dir") == 0) { ++ *lists_dir = realloc(*lists_dir,strlen(value)+1); ++ if (*lists_dir == NULL) { ++ ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n"); ++ free(options); ++ return EINVAL; ++ } ++ sprintf (*lists_dir,"%s",value); ++ } else if (strcmp(type, "arch") == 0) { ++ ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value); ++ if (!value) { ++ ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name); ++ value = strdup("10"); ++ } ++ nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value)); ++ } else { ++ fprintf(stderr, "WARNING: Ignoring unknown configuration " ++ "parameter: %s %s %s\n", type, name, value); ++ free(options); ++ return EINVAL; ++ } ++ ++ free(type); ++ free(name); ++ free(value); ++ if (extra) ++ free (extra); ++ ++ NEXT_LINE: ++ free(line); ++ } ++ ++ free(options); ++ regfree(&comment_re); ++ regfree(&valid_line_re); ++ fclose(file); ++ ++ return 0; ++} ++ ++static int ipkg_conf_set_option(const ipkg_option_t *options, ++ const char *name, const char *value) ++{ ++ int i = 0; ++ while (options[i].name) { ++ if (strcmp(options[i].name, name) == 0) { ++ switch (options[i].type) { ++ case IPKG_OPT_TYPE_BOOL: ++ *((int *)options[i].value) = 1; ++ return 0; ++ case IPKG_OPT_TYPE_INT: ++ if (value) { ++ *((int *)options[i].value) = atoi(value); ++ return 0; ++ } else { ++ printf("%s: Option %s need an argument\n", ++ __FUNCTION__, name); ++ return EINVAL; ++ } ++ case IPKG_OPT_TYPE_STRING: ++ if (value) { ++ *((char **)options[i].value) = strdup(value); ++ return 0; ++ } else { ++ printf("%s: Option %s need an argument\n", ++ __FUNCTION__, name); ++ return EINVAL; ++ } ++ } ++ } ++ i++; ++ } ++ ++ fprintf(stderr, "%s: Unrecognized option: %s=%s\n", ++ __FUNCTION__, name, value); ++ return EINVAL; ++} ++ ++int ipkg_conf_write_status_files(ipkg_conf_t *conf) ++{ ++ pkg_dest_list_elt_t *iter; ++ pkg_dest_t *dest; ++ pkg_vec_t *all; ++ pkg_t *pkg; ++ register int i; ++ int err; ++ ++ if (conf->noaction) ++ return 0; ++ for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) { ++ dest = iter->data; ++ dest->status_file = fopen(dest->status_file_tmp_name, "w"); ++ if (dest->status_file == NULL) { ++ fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n", ++ __FUNCTION__, dest->status_file_name, strerror(errno)); ++ } ++ } ++ ++ all = pkg_vec_alloc(); ++ pkg_hash_fetch_available(&conf->pkg_hash, all); ++ ++ for(i = 0; i < all->len; i++) { ++ pkg = all->pkgs[i]; ++ /* We don't need most uninstalled packages in the status file */ ++ if (pkg->state_status == SS_NOT_INSTALLED ++ && (pkg->state_want == SW_UNKNOWN ++ || pkg->state_want == SW_DEINSTALL ++ || pkg->state_want == SW_PURGE)) { ++ continue; ++ } ++ if (!pkg) { ++ fprintf(stderr, "Null package\n"); ++ } ++ if (pkg->dest == NULL) { ++ fprintf(stderr, "%s: ERROR: Can't write status for " ++ "package %s since it has a NULL dest\n", ++ __FUNCTION__, pkg->name); ++ continue; ++ } ++ if (pkg->dest->status_file) { ++ pkg_print_status(pkg, pkg->dest->status_file); ++ } ++ } ++ ++ pkg_vec_free(all); ++ ++ for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) { ++ dest = iter->data; ++ if (dest->status_file) { ++ err = ferror(dest->status_file); ++ fclose(dest->status_file); ++ dest->status_file = NULL; ++ if (!err) { ++ file_move(dest->status_file_tmp_name, dest->status_file_name); ++ } else { ++ fprintf(stderr, "%s: ERROR: An error has occurred writing %s, " ++ "retaining old %s\n", __FUNCTION__, ++ dest->status_file_tmp_name, dest->status_file_name); ++ } ++ } ++ } ++ ++ return 0; ++} ++ ++ ++char *root_filename_alloc(ipkg_conf_t *conf, char *filename) ++{ ++ char *root_filename; ++ sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename); ++ return root_filename; ++} +Index: busybox-1.7.2/archival/libipkg/ipkg_conf.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg_conf.h 2007-10-04 17:14:22.545026188 +0200 +@@ -0,0 +1,107 @@ ++/* ipkg_conf.h - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef IPKG_CONF_H ++#define IPKG_CONF_H ++ ++typedef struct ipkg_conf ipkg_conf_t; ++ ++#include "hash_table.h" ++#include "ipkg.h" ++#include "args.h" ++#include "pkg.h" ++#include "pkg_hash.h" ++#include "pkg_src_list.h" ++#include "pkg_dest_list.h" ++#include "nv_pair_list.h" ++ ++#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp" ++#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX" ++#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists" ++#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending" ++ ++/* In case the config file defines no dest */ ++#define IPKG_CONF_DEFAULT_DEST_NAME "root" ++#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/" ++ ++#define IPKG_CONF_DEFAULT_HASH_LEN 1024 ++ ++struct ipkg_conf ++{ ++ pkg_src_list_t pkg_src_list; ++ pkg_dest_list_t pkg_dest_list; ++ nv_pair_list_t arch_list; ++ ++ int restrict_to_default_dest; ++ pkg_dest_t *default_dest; ++ ++ char *tmp_dir; ++ const char *lists_dir; ++ const char *pending_dir; ++ ++ /* options */ ++ int force_depends; ++ int force_defaults; ++ int force_overwrite; ++ int force_downgrade; ++ int force_reinstall; ++ int force_space; ++ int force_removal_of_dependent_packages; ++ int force_removal_of_essential_packages; ++ int nodeps; /* do not follow dependences */ ++ int verbose_wget; ++ int multiple_providers; ++ char *offline_root; ++ char *offline_root_pre_script_cmd; ++ char *offline_root_post_script_cmd; ++ int query_all; ++ int verbosity; ++ int noaction; ++ ++ /* proxy options */ ++ char *http_proxy; ++ char *ftp_proxy; ++ char *no_proxy; ++ char *proxy_user; ++ char *proxy_passwd; ++ ++ hash_table_t pkg_hash; ++ hash_table_t file_hash; ++ hash_table_t obs_file_hash; ++}; ++ ++enum ipkg_option_type { ++ IPKG_OPT_TYPE_BOOL, ++ IPKG_OPT_TYPE_INT, ++ IPKG_OPT_TYPE_STRING ++}; ++typedef enum ipkg_option_type ipkg_option_type_t; ++ ++typedef struct ipkg_option ipkg_option_t; ++struct ipkg_option { ++ const char *name; ++ const ipkg_option_type_t type; ++ const void *value; ++}; ++ ++int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args); ++void ipkg_conf_deinit(ipkg_conf_t *conf); ++ ++int ipkg_conf_write_status_files(ipkg_conf_t *conf); ++char *root_filename_alloc(ipkg_conf_t *conf, char *filename); ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/ipkg_configure.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg_configure.c 2007-10-04 17:14:22.569027557 +0200 +@@ -0,0 +1,40 @@ ++/* ipkg_configure.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++ ++#include "ipkg_configure.h" ++ ++int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg) ++{ ++ int err; ++ ++ /* DPKG_INCOMPATIBILITY: ++ dpkg actually does some conffile handling here, rather than at the ++ end of ipkg_install(). Do we care? */ ++ /* DPKG_INCOMPATIBILITY: ++ dpkg actually includes a version number to this script call */ ++ err = pkg_run_script(conf, pkg, "postinst", "configure"); ++ if (err) { ++ printf("ERROR: %s.postinst returned %d\n", pkg->name, err); ++ return err; ++ } ++ ++ ipkg_state_changed++; ++ return 0; ++} ++ +Index: busybox-1.7.2/archival/libipkg/ipkg_configure.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg_configure.h 2007-10-04 17:14:22.593028927 +0200 +@@ -0,0 +1,25 @@ ++/* ipkg_configure.h - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef IPKG_CONFIGURE_H ++#define IPKG_CONFIGURE_H ++ ++#include "ipkg_conf.h" ++ ++int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg); ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/ipkg_download.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg_download.c 2007-10-04 17:14:22.617030294 +0200 +@@ -0,0 +1,195 @@ ++/* ipkg_download.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++#include "ipkg_download.h" ++#include "ipkg_message.h" ++ ++#include "sprintf_alloc.h" ++#include "xsystem.h" ++#include "file_util.h" ++#include "str_util.h" ++ ++int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name) ++{ ++ int err = 0; ++ ++ char *src_basec = strdup(src); ++ char *src_base = basename(src_basec); ++ char *tmp_file_location; ++ char *cmd; ++ ++ ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src); ++ ++ fflush(stdout); ++ ++ if (str_starts_with(src, "file:")) { ++ int ret; ++ const char *file_src = src + 5; ++ ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name); ++ ret = file_copy(src + 5, dest_file_name); ++ ipkg_message(conf,IPKG_INFO,"Done.\n"); ++ return ret; ++ } ++ ++ sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base); ++ err = unlink(tmp_file_location); ++ if (err && errno != ENOENT) { ++ ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n", ++ __FUNCTION__, tmp_file_location, strerror(errno)); ++ free(tmp_file_location); ++ return errno; ++ } ++ ++ if (conf->http_proxy) { ++ ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy); ++ setenv("http_proxy", conf->http_proxy, 1); ++ } ++ if (conf->ftp_proxy) { ++ ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy); ++ setenv("ftp_proxy", conf->ftp_proxy, 1); ++ } ++ if (conf->no_proxy) { ++ ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy); ++ setenv("no_proxy", conf->no_proxy, 1); ++ } ++ ++ /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */ ++ sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s", ++ (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "", ++ conf->proxy_user ? "--proxy-user=" : "", ++ conf->proxy_user ? conf->proxy_user : "", ++ conf->proxy_passwd ? "--proxy-passwd=" : "", ++ conf->proxy_passwd ? conf->proxy_passwd : "", ++ conf->verbose_wget ? "" : "-q", ++ conf->tmp_dir, ++ src); ++ err = xsystem(cmd); ++ if (err) { ++ if (err != -1) { ++ ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n", ++ __FUNCTION__, err, cmd); ++ } ++ unlink(tmp_file_location); ++ free(tmp_file_location); ++ free(src_basec); ++ free(cmd); ++ return EINVAL; ++ } ++ free(cmd); ++ ++ err = file_move(tmp_file_location, dest_file_name); ++ ++ free(tmp_file_location); ++ free(src_basec); ++ ++ if (err) { ++ return err; ++ } ++ ++ return 0; ++} ++ ++int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir) ++{ ++ int err; ++ char *url; ++ ++ if (pkg->src == NULL) { ++ ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n", ++ pkg->name, pkg->parent->name); ++ return -1; ++ } ++ ++ sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename); ++ ++ /* XXX: BUG: The pkg->filename might be something like ++ "../../foo.ipk". While this is correct, and exactly what we ++ want to use to construct url above, here we actually need to ++ use just the filename part, without any directory. */ ++ sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename); ++ ++ err = ipkg_download(conf, url, pkg->local_filename); ++ free(url); ++ ++ return err; ++} ++ ++/* ++ * Downloads file from url, installs in package database, return package name. ++ */ ++int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep) ++{ ++ int err = 0; ++ pkg_t *pkg; ++ pkg = pkg_new(); ++ if (pkg == NULL) ++ return ENOMEM; ++ ++ if (str_starts_with(url, "http://") ++ || str_starts_with(url, "ftp://")) { ++ char *tmp_file; ++ char *file_basec = strdup(url); ++ char *file_base = basename(file_basec); ++ ++ sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base); ++ err = ipkg_download(conf, url, tmp_file); ++ if (err) ++ return err; ++ ++ err = pkg_init_from_file(pkg, tmp_file); ++ if (err) ++ return err; ++ pkg->local_filename = strdup(tmp_file); ++ ++ free(tmp_file); ++ free(file_basec); ++ ++ } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0 ++ || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) { ++ ++ err = pkg_init_from_file(pkg, url); ++ if (err) ++ return err; ++ pkg->local_filename = strdup(url); ++ ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename); ++ pkg->provided_by_hand = 1; ++ ++ } else { ++ pkg_deinit(pkg); ++ free(pkg); ++ return 0; ++ } ++ ++ if (!pkg->architecture) { ++ ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name); ++ return -EINVAL; ++ } ++ ++ pkg->dest = conf->default_dest; ++ pkg->state_want = SW_INSTALL; ++ pkg->state_flag |= SF_PREFER; ++ pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf); ++ if ( pkg == NULL ){ ++ fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__); ++ return 0; ++ } ++ if (namep) { ++ *namep = strdup(pkg->name); ++ } ++ return 0; ++} +Index: busybox-1.7.2/archival/libipkg/ipkg_download.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg_download.h 2007-10-04 17:14:22.645031887 +0200 +@@ -0,0 +1,30 @@ ++/* ipkg_download.h - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef IPKG_DOWNLOAD_H ++#define IPKG_DOWNLOAD_H ++ ++#include "ipkg_conf.h" ++ ++int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name); ++int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir); ++/* ++ * Downloads file from url, installs in package database, return package name. ++ */ ++int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep); ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/ipkg.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg.h 2007-10-04 17:14:22.669033256 +0200 +@@ -0,0 +1,74 @@ ++/* ipkg.h - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef IPKG_H ++#define IPKG_H ++ ++/* ++#ifdef HAVE_CONFIG_H ++#include "config.h" ++#endif ++*/ ++ ++#if 0 ++#define IPKG_DEBUG_NO_TMP_CLEANUP ++#endif ++ ++#include "ipkg_includes.h" ++#include "ipkg_conf.h" ++#include "ipkg_message.h" ++ ++#define IPKG_PKG_EXTENSION ".ipk" ++#define DPKG_PKG_EXTENSION ".deb" ++ ++#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-" ++#define IPKG_PKG_VERSION_SEP_CHAR '_' ++ ++#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg" ++#define IPKG_LISTS_DIR_SUFFIX "lists" ++#define IPKG_INFO_DIR_SUFFIX "info" ++#define IPKG_STATUS_FILE_SUFFIX "status" ++ ++#define IPKG_BACKUP_SUFFIX "-ipkg.backup" ++ ++#define IPKG_LIST_DESCRIPTION_LENGTH 128 ++ ++#define IPKG_VERSION "0.99.162" ++ ++ ++enum ipkg_error { ++ IPKG_SUCCESS = 0, ++ IPKG_PKG_DEPS_UNSATISFIED, ++ IPKG_PKG_IS_ESSENTIAL, ++ IPKG_PKG_HAS_DEPENDENTS, ++ IPKG_PKG_HAS_NO_CANDIDATE ++}; ++typedef enum ipkg_error ipkg_error_t; ++ ++extern int ipkg_state_changed; ++ ++ ++struct errlist { ++ char * errmsg; ++ struct errlist * next; ++} ; ++ ++extern struct errlist* error_list; ++ ++extern ipkg_conf_t *global_conf; ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/ipkg_includes.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg_includes.h 2007-10-04 17:14:22.685034167 +0200 +@@ -0,0 +1,79 @@ ++#ifndef IPKG_INCLUDES_H ++#define IPKG_INCLUDES_H ++ ++/* Define to 1 if you have the header file. */ ++#define HAVE_MEMORY_H 1 ++ ++/* Define to 1 if you have the header file. */ ++#define HAVE_REGEX_H 1 ++ ++/* Define to 1 if you have the header file. */ ++#define HAVE_STDLIB_H 1 ++ ++/* Define to 1 if you have the header file. */ ++#define HAVE_STRINGS_H 1 ++ ++/* Define to 1 if you have the header file. */ ++#define HAVE_STRING_H 1 ++ ++/* Define to 1 if you have the header file. */ ++#define HAVE_SYS_STAT_H 1 ++ ++/* Define to 1 if you have that is POSIX.1 compatible. */ ++#define HAVE_SYS_WAIT_H 1 ++ ++/* Define to 1 if you have the header file. */ ++#define HAVE_UNISTD_H 1 ++ ++/* Define to 1 if you have the ANSI C header files. */ ++#define STDC_HEADERS 1 ++ ++ ++#include ++ ++#if STDC_HEADERS ++# include ++# include ++# include ++# include ++# include ++#else ++# if HAVE_STDLIB_H ++# include ++# endif ++#endif ++ ++#if HAVE_REGEX_H ++# include ++#endif ++ ++#if HAVE_STRING_H ++# if !STDC_HEADERS && HAVE_MEMORY_H ++# include ++# endif ++/* XXX: What's the right way to pick up GNU's strndup declaration? */ ++# if __GNUC__ ++# define __USE_GNU 1 ++# endif ++# include ++# undef __USE_GNU ++#endif ++ ++#if HAVE_STRINGS_H ++# include ++#endif ++ ++#if HAVE_SYS_STAT_H ++# include ++#endif ++ ++#if HAVE_SYS_WAIT_H ++# include ++#endif ++ ++#if HAVE_UNISTD_H ++# include ++# include ++#endif ++ ++#endif /* IPKG_INCLUDES_H */ +Index: busybox-1.7.2/archival/libipkg/ipkg_install.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg_install.c 2007-10-04 17:14:22.725036446 +0200 +@@ -0,0 +1,1942 @@ ++/* ipkg_install.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++#include ++#include ++#include ++#include ++#include ++typedef void (*sighandler_t)(int); ++ ++#include "pkg.h" ++#include "pkg_hash.h" ++#include "pkg_extract.h" ++ ++#include "ipkg_install.h" ++#include "ipkg_configure.h" ++#include "ipkg_download.h" ++#include "ipkg_remove.h" ++ ++#include "ipkg_utils.h" ++#include "ipkg_message.h" ++ ++#include "sprintf_alloc.h" ++#include "file_util.h" ++#include "str_util.h" ++#include "xsystem.h" ++#include "user.h" ++ ++int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg); ++static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg); ++static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg); ++ ++static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); ++static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); ++static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors); ++static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors); ++static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); ++static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); ++static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); ++static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); ++static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); ++static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); ++static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); ++static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); ++static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); ++ ++static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); ++static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); ++static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg); ++static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg); ++static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg); ++ ++static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg); ++ ++static int user_prefers_old_conffile(const char *file, const char *backup); ++ ++static char *backup_filename_alloc(const char *file_name); ++static int backup_make_backup(ipkg_conf_t *conf, const char *file_name); ++static int backup_exists_for(const char *file_name); ++static int backup_remove(const char *file_name); ++ ++ ++int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename) ++{ ++ int err, cmp; ++ pkg_t *pkg, *old; ++ char *old_version, *new_version; ++ ++ pkg = pkg_new(); ++ if (pkg == NULL) { ++ return ENOMEM; ++ } ++ ++ err = pkg_init_from_file(pkg, filename); ++ if (err) { ++ return err; ++ } ++ ++ if (!pkg->architecture) { ++ ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name); ++ return -EINVAL; ++ } ++ ++ /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly ++ freeing the pkg that we pass in. It might be nice to clean this up ++ if possible. */ ++ pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf); ++ old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name); ++ ++ pkg->local_filename = strdup(filename); ++ ++ if (old) { ++ old_version = pkg_version_str_alloc(old); ++ new_version = pkg_version_str_alloc(pkg); ++ ++ cmp = pkg_compare_versions(old, pkg); ++ if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */ ++ cmp = -1 ; /* then we force ipkg to downgrade */ ++ /* We need to use a value < 0 because in the 0 case we are asking to */ ++ /* reinstall, and some check could fail asking the "force-reinstall" option */ ++ } ++ if (cmp > 0) { ++ ipkg_message(conf, IPKG_NOTICE, ++ "Not downgrading package %s on %s from %s to %s.\n", ++ old->name, old->dest->name, old_version, new_version); ++ pkg->state_want = SW_DEINSTALL; ++ pkg->state_flag |= SF_OBSOLETE; ++ free(old_version); ++ free(new_version); ++ return 0; ++ } else { ++ free(old_version); ++ free(new_version); ++ } ++ } ++ ++ ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__); ++ return ipkg_install_pkg(conf, pkg,0); ++} ++ ++ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name) ++{ ++ int cmp; ++ pkg_t *old, *new; ++ char *old_version, *new_version; ++ ++ ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" ); ++ old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name); ++ if ( old ) ++ ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version ); ++ ++ ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" ); ++ new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name); ++ if ( new ) ++ ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version ); ++ ++/* Pigi Basically here is broken the version stuff. ++ What's happening is that nothing provide the version to differents ++ functions, so the returned struct is always the latest. ++ That's why the install by name don't work. ++*/ ++ ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ ); ++ ++ if ( old ) ++ ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version ); ++ if ( new ) ++ ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version ); ++ ipkg_message(conf, IPKG_DEBUG2, " \n"); ++ ++ if (new == NULL) { ++ return IPKG_PKG_HAS_NO_CANDIDATE; ++ } ++ ++ new->state_flag |= SF_USER; ++ if (old) { ++ old_version = pkg_version_str_alloc(old); ++ new_version = pkg_version_str_alloc(new); ++ ++ cmp = pkg_compare_versions(old, new); ++ if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */ ++ ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n"); ++ cmp = -1 ; /* then we force ipkg to downgrade */ ++ /* We need to use a value < 0 because in the 0 case we are asking to */ ++ /* reinstall, and some check could fail asking the "force-reinstall" option */ ++ } ++ ipkg_message(conf, IPKG_DEBUG, ++ "Comparing visible versions of pkg %s:" ++ "\n\t%s is installed " ++ "\n\t%s is available " ++ "\n\t%d was comparison result\n", ++ pkg_name, old_version, new_version, cmp); ++ if (cmp == 0 && !conf->force_reinstall) { ++ ipkg_message(conf, IPKG_NOTICE, ++ "Package %s (%s) installed in %s is up to date.\n", ++ old->name, old_version, old->dest->name); ++ free(old_version); ++ free(new_version); ++ return 0; ++ } else if (cmp > 0) { ++ ipkg_message(conf, IPKG_NOTICE, ++ "Not downgrading package %s on %s from %s to %s.\n", ++ old->name, old->dest->name, old_version, new_version); ++ free(old_version); ++ free(new_version); ++ return 0; ++ } else if (cmp < 0) { ++ new->dest = old->dest; ++ old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */ ++ } ++ } ++ ++ /* XXX: CLEANUP: The error code of ipkg_install_by_name is really ++ supposed to be an ipkg_error_t, but ipkg_install_pkg could ++ return any kind of integer, (might be errno from a syscall, ++ etc.). This is a real mess and will need to be cleaned up if ++ anyone ever wants to make a nice libipkg. */ ++ ++ ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__); ++ return ipkg_install_pkg(conf, new,0); ++} ++ ++ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name) ++{ ++ abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name); ++ int i; ++ ipkg_error_t err; ++ abstract_pkg_t *ppkg ; ++ ++ if (providers == NULL) ++ return IPKG_PKG_HAS_NO_CANDIDATE; ++ ++ for (i = 0; i < providers->len; i++) { ++ ppkg = abstract_pkg_vec_get(providers, i); ++ ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i); ++ err = ipkg_install_by_name(conf, ppkg->name); ++ if (err) ++ return err; ++/* XXX Maybe ppkg should be freed ? */ ++ } ++ return 0; ++} ++ ++/* ++ * Walk dependence graph starting with pkg, collect packages to be ++ * installed into pkgs_needed, in dependence order. ++ */ ++int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed) ++{ ++ int i, err; ++ pkg_vec_t *depends = pkg_vec_alloc(); ++ char **unresolved = NULL; ++ int ndepends; ++ ++ ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf, ++ pkg, depends, ++ &unresolved); ++ ++ if (unresolved) { ++ ipkg_message(conf, IPKG_ERROR, ++ "%s: Cannot satisfy the following dependencies for %s:\n\t", ++ conf->force_depends ? "Warning" : "ERROR", pkg->name); ++ while (*unresolved) { ++ ipkg_message(conf, IPKG_ERROR, " %s", *unresolved); ++ unresolved++; ++ } ++ ipkg_message(conf, IPKG_ERROR, "\n"); ++ if (! conf->force_depends) { ++ ipkg_message(conf, IPKG_INFO, ++ "This could mean that your package list is out of date or that the packages\n" ++ "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n" ++ "of this problem try again with the '-force-depends' option.\n"); ++ pkg_vec_free(depends); ++ return IPKG_PKG_DEPS_UNSATISFIED; ++ } ++ } ++ ++ if (ndepends <= 0) { ++ pkg_vec_free(depends); ++ return 0; ++ } ++ ++ for (i = 0; i < depends->len; i++) { ++ pkg_t *dep = depends->pkgs[i]; ++ /* The package was uninstalled when we started, but another ++ dep earlier in this loop may have depended on it and pulled ++ it in, so check first. */ ++ if ((dep->state_status != SS_INSTALLED) ++ && (dep->state_status != SS_UNPACKED) ++ && (dep->state_want != SW_INSTALL)) { ++ ++ /* Mark packages as to-be-installed */ ++ dep->state_want = SW_INSTALL; ++ ++ /* Dependencies should be installed the same place as pkg */ ++ if (dep->dest == NULL) { ++ dep->dest = pkg->dest; ++ } ++ ++ err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed); ++ if (err) { ++ pkg_vec_free(depends); ++ return err; ++ } ++ } ++ } ++ if (pkgs_needed) ++ pkg_vec_insert(pkgs_needed, pkg); ++ ++ pkg_vec_free(depends); ++ ++ return 0; ++} ++ ++int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed) ++{ ++ int cmp; ++ pkg_t *old, *new; ++ char *old_version, *new_version; ++ ++ old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name); ++ ++ new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name); ++ if (new == NULL) { ++ return IPKG_PKG_HAS_NO_CANDIDATE; ++ } ++ if (old) { ++ old_version = pkg_version_str_alloc(old); ++ new_version = pkg_version_str_alloc(new); ++ ++ cmp = pkg_compare_versions(old, new); ++ if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */ ++ ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade "); ++ cmp = -1 ; /* then we force ipkg to downgrade */ ++ /* We need to use a value < 0 because in the 0 case we are asking to */ ++ /* reinstall, and some check could fail asking the "force-reinstall" option */ ++ } ++ ipkg_message(conf, IPKG_DEBUG, ++ "comparing visible versions of pkg %s:" ++ "\n\t%s is installed " ++ "\n\t%s is available " ++ "\n\t%d was comparison result\n", ++ pkg_name, old_version, new_version, cmp); ++ if (cmp == 0 && !conf->force_reinstall) { ++ ipkg_message(conf, IPKG_NOTICE, ++ "Package %s (%s) installed in %s is up to date.\n", ++ old->name, old_version, old->dest->name); ++ free(old_version); ++ free(new_version); ++ return 0; ++ } else if (cmp > 0) { ++ ipkg_message(conf, IPKG_NOTICE, ++ "Not downgrading package %s on %s from %s to %s.\n", ++ old->name, old->dest->name, old_version, new_version); ++ free(old_version); ++ free(new_version); ++ return 0; ++ } else if (cmp < 0) { ++ new->dest = old->dest; ++ old->state_want = SW_DEINSTALL; ++ old->state_flag |= SF_OBSOLETE; ++ } ++ } ++ return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed); ++} ++ ++ ++ ++int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg) ++{ ++ int i, err; ++ pkg_vec_t *depends = pkg_vec_alloc(); ++ pkg_t *dep; ++ char **unresolved = NULL; ++ int ndepends; ++ ++ ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf, ++ pkg, depends, ++ &unresolved); ++ ++ if (unresolved) { ++ ipkg_message(conf, IPKG_ERROR, ++ "%s: Cannot satisfy the following dependencies for %s:\n\t", ++ conf->force_depends ? "Warning" : "ERROR", pkg->name); ++ while (*unresolved) { ++ ipkg_message(conf, IPKG_ERROR, " %s", *unresolved); ++ unresolved++; ++ } ++ ipkg_message(conf, IPKG_ERROR, "\n"); ++ if (! conf->force_depends) { ++ ipkg_message(conf, IPKG_INFO, ++ "This could mean that your package list is out of date or that the packages\n" ++ "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n" ++ "of this problem try again with the '-force-depends' option.\n"); ++ pkg_vec_free(depends); ++ return IPKG_PKG_DEPS_UNSATISFIED; ++ } ++ } ++ ++ if (ndepends <= 0) { ++ return 0; ++ } ++ ++ /* Mark packages as to-be-installed */ ++ for (i=0; i < depends->len; i++) { ++ /* Dependencies should be installed the same place as pkg */ ++ if (depends->pkgs[i]->dest == NULL) { ++ depends->pkgs[i]->dest = pkg->dest; ++ } ++ depends->pkgs[i]->state_want = SW_INSTALL; ++ } ++ ++ for (i = 0; i < depends->len; i++) { ++ dep = depends->pkgs[i]; ++ /* The package was uninstalled when we started, but another ++ dep earlier in this loop may have depended on it and pulled ++ it in, so check first. */ ++ if ((dep->state_status != SS_INSTALLED) ++ && (dep->state_status != SS_UNPACKED)) { ++ ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__); ++ err = ipkg_install_pkg(conf, dep,0); ++ if (err) { ++ pkg_vec_free(depends); ++ return err; ++ } ++ } ++ } ++ ++ pkg_vec_free(depends); ++ ++ return 0; ++} ++ ++ ++/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */ ++int ipkg_satisfy_all_dependences(ipkg_conf_t *conf) ++{ ++ if (conf->nodeps == 0) { ++ int i; ++ pkg_vec_t *installed = pkg_vec_alloc(); ++ pkg_hash_fetch_all_installed(&conf->pkg_hash, installed); ++ for (i = 0; i < installed->len; i++) { ++ pkg_t *pkg = installed->pkgs[i]; ++ satisfy_dependencies_for(conf, pkg); ++ } ++ pkg_vec_free(installed); ++ } ++ return 0; ++} ++ ++ ++ ++static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg) ++{ ++ int i; ++ pkg_vec_t *conflicts = NULL; ++ int level; ++ const char *prefix; ++ if (conf->force_depends) { ++ level = IPKG_NOTICE; ++ prefix = "Warning"; ++ } else { ++ level = IPKG_ERROR; ++ prefix = "ERROR"; ++ } ++ ++ if (!conf->force_depends) ++ conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg); ++ ++ if (conflicts) { ++ ipkg_message(conf, level, ++ "%s: The following packages conflict with %s:\n\t", prefix, pkg->name); ++ i = 0; ++ while (i < conflicts->len) ++ ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name); ++ ipkg_message(conf, level, "\n"); ++ pkg_vec_free(conflicts); ++ return IPKG_PKG_DEPS_UNSATISFIED; ++ } ++ return 0; ++} ++ ++static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg) ++{ ++ str_list_t *new_list = pkg_get_installed_files(new_pkg); ++ str_list_elt_t *iter; ++ ++ for (iter = new_list->head; iter; iter = iter->next) { ++ char *new_file = iter->data; ++ pkg_t *owner = file_hash_get_file_owner(conf, new_file); ++ if (!new_file) ++ ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name); ++ if (!owner || (owner == old_pkg)) ++ file_hash_set_file_owner(conf, new_file, new_pkg); ++ } ++ if (old_pkg) { ++ str_list_t *old_list = pkg_get_installed_files(old_pkg); ++ for (iter = old_list->head; iter; iter = iter->next) { ++ char *old_file = iter->data; ++ pkg_t *owner = file_hash_get_file_owner(conf, old_file); ++ if (owner == old_pkg) { ++ /* obsolete */ ++ hash_table_insert(&conf->obs_file_hash, old_file, old_pkg); ++ } ++ } ++ } ++ return 0; ++} ++ ++static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg) ++{ ++ /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */ ++ ++ /* sma 6.20.02: yup; here's the first bit */ ++ /* ++ * XXX: BUG easy for cworth ++ * 1) please point the call below to the correct current root destination ++ * 2) we need to resolve how to check the required space for a pending pkg, ++ * my diddling with the .ipk file size below isn't going to cut it. ++ * 3) return a proper error code instead of 1 ++ */ ++ int comp_size, blocks_available; ++ ++ if (!conf->force_space && pkg->installed_size != NULL) { ++ blocks_available = get_available_blocks(conf->default_dest->root_dir); ++ ++ comp_size = strtoul(pkg->installed_size, NULL, 0); ++ /* round up a blocks count without doing fancy-but-slow casting jazz */ ++ comp_size = (int)((comp_size + 1023) / 1024); ++ ++ if (comp_size >= blocks_available) { ++ ipkg_message(conf, IPKG_ERROR, ++ "Only have %d available blocks on filesystem %s, pkg %s needs %d\n", ++ blocks_available, conf->default_dest->root_dir, pkg->name, comp_size); ++ return ENOSPC; ++ } ++ } ++ return 0; ++} ++ ++static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg) ++{ ++ int err; ++ char *conffiles_file_name; ++ char *root_dir; ++ FILE *conffiles_file; ++ ++ sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name); ++ ++ pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir); ++ if (pkg->tmp_unpack_dir == NULL) { ++ ipkg_message(conf, IPKG_ERROR, ++ "%s: Failed to create temporary directory '%s': %s\n", ++ __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno)); ++ return errno; ++ } ++ ++ err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir); ++ if (err) { ++ return err; ++ } ++ ++ /* XXX: CLEANUP: There might be a cleaner place to read in the ++ conffiles. Seems like I should be able to get everything to go ++ through pkg_init_from_file. If so, maybe it would make sense to ++ move all of unpack_pkg_control_files to that function. */ ++ ++ /* Don't need to re-read conffiles if we already have it */ ++ if (pkg->conffiles.head) { ++ return 0; ++ } ++ ++ sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir); ++ if (! file_exists(conffiles_file_name)) { ++ free(conffiles_file_name); ++ return 0; ++ } ++ ++ conffiles_file = fopen(conffiles_file_name, "r"); ++ if (conffiles_file == NULL) { ++ fprintf(stderr, "%s: failed to open %s: %s\n", ++ __FUNCTION__, conffiles_file_name, strerror(errno)); ++ free(conffiles_file_name); ++ return errno; ++ } ++ free(conffiles_file_name); ++ ++ while (1) { ++ char *cf_name; ++ char *cf_name_in_dest; ++ ++ cf_name = file_read_line_alloc(conffiles_file); ++ if (cf_name == NULL) { ++ break; ++ } ++ str_chomp(cf_name); ++ if (cf_name[0] == '\0') { ++ continue; ++ } ++ ++ /* Prepend dest->root_dir to conffile name. ++ Take pains to avoid multiple slashes. */ ++ root_dir = pkg->dest->root_dir; ++ if (conf->offline_root) ++ /* skip the offline_root prefix */ ++ root_dir = pkg->dest->root_dir + strlen(conf->offline_root); ++ sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir, ++ cf_name[0] == '/' ? (cf_name + 1) : cf_name); ++ ++ /* Can't get an md5sum now, (file isn't extracted yet). ++ We'll wait until resolve_conffiles */ ++ conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL); ++ ++ free(cf_name); ++ free(cf_name_in_dest); ++ } ++ ++ fclose(conffiles_file); ++ ++ return 0; ++} ++ ++/* returns number of installed replacees */ ++int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees) ++{ ++ abstract_pkg_t **replaces = pkg->replaces; ++ int replaces_count = pkg->replaces_count; ++ int i, j; ++ for (i = 0; i < replaces_count; i++) { ++ abstract_pkg_t *ab_pkg = replaces[i]; ++ pkg_vec_t *pkg_vec = ab_pkg->pkgs; ++ if (pkg_vec) { ++ for (j = 0; j < pkg_vec->len; j++) { ++ pkg_t *replacee = pkg_vec->pkgs[j]; ++ if (!pkg_conflicts(pkg, replacee)) ++ continue; ++ if (replacee->state_status == SS_INSTALLED) { ++ pkg_vec_insert(installed_replacees, replacee); ++ } ++ } ++ } ++ } ++ return installed_replacees->len; ++} ++ ++int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees) ++{ ++ int i; ++ int replaces_count = replacees->len; ++ for (i = 0; i < replaces_count; i++) { ++ pkg_t *replacee = replacees->pkgs[i]; ++ int err; ++ replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */ ++ err = ipkg_remove_pkg(conf, replacee,0); ++ if (err) ++ return err; ++ } ++ return 0; ++} ++ ++/* to unwind the removal: make sure they are installed */ ++int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees) ++{ ++ int i, err; ++ int replaces_count = replacees->len; ++ for (i = 0; i < replaces_count; i++) { ++ pkg_t *replacee = replacees->pkgs[i]; ++ if (replacee->state_status != SS_INSTALLED) { ++ ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__); ++ err = ipkg_install_pkg(conf, replacee,0); ++ if (err) ++ return err; ++ } ++ } ++ return 0; ++} ++ ++int caught_sigint = 0; ++static void ipkg_install_pkg_sigint_handler(int sig) ++{ ++ caught_sigint = sig; ++} ++ ++/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */ ++static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message) ++{ ++ if (old_pkg) { ++ char message_out[15]; ++ char *old_version = pkg_version_str_alloc(old_pkg); ++ char *new_version = pkg_version_str_alloc(pkg); ++ int cmp = pkg_compare_versions(old_pkg, pkg); ++ int rc = 0; ++ ++ memset(message_out,'\x0',15); ++ strncpy (message_out,"Upgrading ",strlen("Upgrading ")); ++ if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */ ++ cmp = -1 ; /* then we force ipkg to downgrade */ ++ strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */ ++ /* reinstall, and some check could fail asking the "force-reinstall" option */ ++ } ++ ++ if (cmp > 0) { ++ ipkg_message(conf, IPKG_NOTICE, ++ "Not downgrading package %s on %s from %s to %s.\n", ++ old_pkg->name, old_pkg->dest->name, old_version, new_version); ++ rc = 1; ++ } else if (cmp < 0) { ++ ipkg_message(conf, IPKG_NOTICE, ++ "%s%s on %s from %s to %s...\n", ++ message_out, pkg->name, old_pkg->dest->name, old_version, new_version); ++ pkg->dest = old_pkg->dest; ++ rc = 0; ++ } else /* cmp == 0 */ { ++ if (conf->force_reinstall) { ++ ipkg_message(conf, IPKG_NOTICE, ++ "Reinstalling %s (%s) on %s...\n", ++ pkg->name, new_version, old_pkg->dest->name); ++ pkg->dest = old_pkg->dest; ++ rc = 0; ++ } else { ++ ipkg_message(conf, IPKG_NOTICE, ++ "Not installing %s (%s) on %s -- already installed.\n", ++ pkg->name, new_version, old_pkg->dest->name); ++ rc = 1; ++ } ++ } ++ free(old_version); ++ free(new_version); ++ return rc; ++ } else { ++ char message_out[15], *version ; ++ memset(message_out,'\x0',15); ++ if ( message ) ++ strncpy( message_out,"Upgrading ",strlen("Upgrading ") ); ++ else ++ strncpy( message_out,"Installing ",strlen("Installing ") ); ++ version = pkg_version_str_alloc(pkg); ++ ++ ipkg_message(conf, IPKG_NOTICE, ++ "%s%s (%s) to %s...\n", message_out, ++ pkg->name, version, pkg->dest->name); ++ free(version); ++ return 0; ++ } ++} ++ ++/* and now the meat... */ ++int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade) ++{ ++ int err = 0; ++ int message = 0; ++ pkg_t *old_pkg = NULL; ++ pkg_vec_t *replacees; ++ abstract_pkg_t *ab_pkg = NULL; ++ int old_state_flag; ++ char* file_md5; ++ ++ ++ if ( from_upgrade ) ++ message = 1; /* Coming from an upgrade, and should change the output message */ ++ ++ if (!pkg) { ++ ipkg_message(conf, IPKG_ERROR, ++ "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n"); ++ return -EINVAL; ++ } ++ ++ ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__); ++ ++ if (!pkg_arch_supported(conf, pkg)) { ++ ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n", ++ pkg->architecture, pkg->name); ++ return -EINVAL; ++ } ++ if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) { ++ err = satisfy_dependencies_for(conf, pkg); ++ if (err) { return err; } ++ ++ ipkg_message(conf, IPKG_NOTICE, ++ "Package %s is already installed in %s.\n", ++ pkg->name, pkg->dest->name); ++ return 0; ++ } ++ ++ if (pkg->dest == NULL) { ++ pkg->dest = conf->default_dest; ++ } ++ ++ old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name); ++ ++ err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message); ++ if (err) { return err; } ++ ++ pkg->state_want = SW_INSTALL; ++ if (old_pkg){ ++ old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */ ++ } ++ ++ ++ /* Abhaya: conflicts check */ ++ err = check_conflicts_for(conf, pkg); ++ if (err) { return err; } ++ ++ /* this setup is to remove the upgrade scenario in the end when ++ installing pkg A, A deps B & B deps on A. So both B and A are ++ installed. Then A's installation is started resulting in an ++ uncecessary upgrade */ ++ if (pkg->state_status == SS_INSTALLED ++ && conf->force_reinstall == 0) return 0; ++ ++ err = verify_pkg_installable(conf, pkg); ++ if (err) { return err; } ++ ++ if (pkg->local_filename == NULL) { ++ err = ipkg_download_pkg(conf, pkg, conf->tmp_dir); ++ if (err) { ++ ipkg_message(conf, IPKG_ERROR, ++ "Failed to download %s. Perhaps you need to run 'ipkg update'?\n", ++ pkg->name); ++ return err; ++ } ++ } ++ ++/* Check for md5 values */ ++ if (pkg->md5sum) ++ { ++ file_md5 = file_md5sum_alloc(pkg->local_filename); ++ if (strcmp(file_md5, pkg->md5sum)) ++ { ++ ipkg_message(conf, IPKG_ERROR, ++ "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n", ++ pkg->name); ++ free(file_md5); ++ return err; ++ } ++ free(file_md5); ++ } ++ ++ if (pkg->tmp_unpack_dir == NULL) { ++ unpack_pkg_control_files(conf, pkg); ++ } ++ ++ /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */ ++/* Pigi: check if it will pass from here when replacing. It seems to fail */ ++/* That's rather strange that files don't change owner. Investigate !!!!!!*/ ++ err = update_file_ownership(conf, pkg, old_pkg); ++ if (err) { return err; } ++ ++ if (conf->nodeps == 0) { ++ err = satisfy_dependencies_for(conf, pkg); ++ if (err) { return err; } ++ } ++ ++ replacees = pkg_vec_alloc(); ++ pkg_get_installed_replacees(conf, pkg, replacees); ++ ++ /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */ ++ { ++ sigset_t newset, oldset; ++ sighandler_t old_handler = NULL; ++ int use_signal = 0; ++ caught_sigint = 0; ++ if (use_signal) { ++ old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler); ++ } else { ++ sigemptyset(&newset); ++ sigaddset(&newset, SIGINT); ++ sigprocmask(SIG_BLOCK, &newset, &oldset); ++ } ++ ++ ipkg_state_changed++; ++ pkg->state_flag |= SF_FILELIST_CHANGED; ++ ++ /* XXX: BUG: we really should treat replacement more like an upgrade ++ * Instead, we're going to remove the replacees ++ */ ++ err = pkg_remove_installed_replacees(conf, replacees); ++ if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES; ++ ++ err = prerm_upgrade_old_pkg(conf, pkg, old_pkg); ++ if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG; ++ ++ err = prerm_deconfigure_conflictors(conf, pkg, replacees); ++ if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS; ++ ++ err = preinst_configure(conf, pkg, old_pkg); ++ if (err) goto UNWIND_PREINST_CONFIGURE; ++ ++ err = backup_modified_conffiles(conf, pkg, old_pkg); ++ if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES; ++ ++ err = check_data_file_clashes(conf, pkg, old_pkg); ++ if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES; ++ ++ err = postrm_upgrade_old_pkg(conf, pkg, old_pkg); ++ if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG; ++ ++ if (conf->noaction) return 0; ++ ++ /* point of no return: no unwinding after this */ ++ if (old_pkg && !conf->force_reinstall) { ++ old_pkg->state_want = SW_DEINSTALL; ++ ++ if (old_pkg->state_flag & SF_NOPRUNE) { ++ ipkg_message(conf, IPKG_INFO, ++ " not removing obsolesced files because package marked noprune\n"); ++ } else { ++ ipkg_message(conf, IPKG_INFO, ++ " removing obsolesced files\n"); ++ remove_obsolesced_files(conf, pkg, old_pkg); ++ } ++ /* removing files from old package, to avoid ghost files */ ++ remove_data_files_and_list(conf, old_pkg); ++/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/ ++ remove_maintainer_scripts_except_postrm(conf, old_pkg); ++ remove_postrm(conf, old_pkg); ++/* Pigi */ ++ ++ } ++ ++ ++ ipkg_message(conf, IPKG_INFO, ++ " installing maintainer scripts\n"); ++ install_maintainer_scripts(conf, pkg, old_pkg); ++ ++ /* the following just returns 0 */ ++ remove_disappeared(conf, pkg); ++ ++ ipkg_message(conf, IPKG_INFO, ++ " installing data files\n"); ++ install_data_files(conf, pkg); ++ ++/* read comments from function for detail but I will execute this here as all other tests are ok.*/ ++ err = check_data_file_clashes_change(conf, pkg, old_pkg); ++ ++ ipkg_message(conf, IPKG_INFO, ++ " resolving conf files\n"); ++ resolve_conffiles(conf, pkg); ++ ++ pkg->state_status = SS_UNPACKED; ++ old_state_flag = pkg->state_flag; ++ pkg->state_flag &= ~SF_PREFER; ++ ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag); ++ ++ if (old_pkg && !conf->force_reinstall) { ++ old_pkg->state_status = SS_NOT_INSTALLED; ++ } ++ ++ time(&pkg->installed_time); ++ ++ ipkg_message(conf, IPKG_INFO, ++ " cleanup temp files\n"); ++ cleanup_temporary_files(conf, pkg); ++ ++ ab_pkg = pkg->parent; ++ if (ab_pkg) ++ ab_pkg->state_status = pkg->state_status; ++ ++ ipkg_message(conf, IPKG_INFO, "Done.\n"); ++ ++ if (use_signal) ++ signal(SIGINT, old_handler); ++ else ++ sigprocmask(SIG_UNBLOCK, &newset, &oldset); ++ ++ return 0; ++ ++ ++ UNWIND_POSTRM_UPGRADE_OLD_PKG: ++ postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg); ++ UNWIND_CHECK_DATA_FILE_CLASHES: ++ check_data_file_clashes_unwind(conf, pkg, old_pkg); ++ UNWIND_BACKUP_MODIFIED_CONFFILES: ++ backup_modified_conffiles_unwind(conf, pkg, old_pkg); ++ UNWIND_PREINST_CONFIGURE: ++ preinst_configure_unwind(conf, pkg, old_pkg); ++ UNWIND_PRERM_DECONFIGURE_CONFLICTORS: ++ prerm_deconfigure_conflictors_unwind(conf, pkg, replacees); ++ UNWIND_PRERM_UPGRADE_OLD_PKG: ++ prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg); ++ UNWIND_REMOVE_INSTALLED_REPLACEES: ++ pkg_remove_installed_replacees_unwind(conf, replacees); ++ ++ ipkg_message(conf, IPKG_INFO, ++ " cleanup temp files\n"); ++ cleanup_temporary_files(conf, pkg); ++ ++ ipkg_message(conf, IPKG_INFO, ++ "Failed.\n"); ++ if (use_signal) ++ signal(SIGINT, old_handler); ++ else ++ sigprocmask(SIG_UNBLOCK, &newset, &oldset); ++ ++ return err; ++ } ++} ++ ++static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) ++{ ++ /* DPKG_INCOMPATIBILITY: ++ dpkg does some things here that we don't do yet. Do we care? ++ ++ 1. If a version of the package is already installed, call ++ old-prerm upgrade new-version ++ 2. If the script runs but exits with a non-zero exit status ++ new-prerm failed-upgrade old-version ++ Error unwind, for both the above cases: ++ old-postinst abort-upgrade new-version ++ */ ++ return 0; ++} ++ ++static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) ++{ ++ /* DPKG_INCOMPATIBILITY: ++ dpkg does some things here that we don't do yet. Do we care? ++ (See prerm_upgrade_old_package for details) ++ */ ++ return 0; ++} ++ ++static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors) ++{ ++ /* DPKG_INCOMPATIBILITY: ++ dpkg does some things here that we don't do yet. Do we care? ++ 2. If a 'conflicting' package is being removed at the same time: ++ 1. If any packages depended on that conflicting package and ++ --auto-deconfigure is specified, call, for each such package: ++ deconfigured's-prerm deconfigure \ ++ in-favour package-being-installed version \ ++ removing conflicting-package version ++ Error unwind: ++ deconfigured's-postinst abort-deconfigure \ ++ in-favour package-being-installed-but-failed version \ ++ removing conflicting-package version ++ ++ The deconfigured packages are marked as requiring ++ configuration, so that if --install is used they will be ++ configured again if possible. ++ 2. To prepare for removal of the conflicting package, call: ++ conflictor's-prerm remove in-favour package new-version ++ Error unwind: ++ conflictor's-postinst abort-remove in-favour package new-version ++ */ ++ return 0; ++} ++ ++static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors) ++{ ++ /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't ++ do yet. Do we care? (See prerm_deconfigure_conflictors for ++ details) */ ++ return 0; ++} ++ ++static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) ++{ ++ int err; ++ char *preinst_args; ++ ++ if (old_pkg) { ++ char *old_version = pkg_version_str_alloc(old_pkg); ++ sprintf_alloc(&preinst_args, "upgrade %s", old_version); ++ free(old_version); ++ } else if (pkg->state_status == SS_CONFIG_FILES) { ++ char *pkg_version = pkg_version_str_alloc(pkg); ++ sprintf_alloc(&preinst_args, "install %s", pkg_version); ++ free(pkg_version); ++ } else { ++ preinst_args = strdup("install"); ++ } ++ ++ err = pkg_run_script(conf, pkg, "preinst", preinst_args); ++ if (err) { ++ ipkg_message(conf, IPKG_ERROR, ++ "Aborting installation of %s\n", pkg->name); ++ return 1; ++ } ++ ++ free(preinst_args); ++ ++ return 0; ++} ++ ++static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) ++{ ++ /* DPKG_INCOMPATIBILITY: ++ dpkg does the following error unwind, should we? ++ pkg->postrm abort-upgrade old-version ++ OR pkg->postrm abort-install old-version ++ OR pkg->postrm abort-install ++ */ ++ return 0; ++} ++ ++static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) ++{ ++ int err; ++ conffile_list_elt_t *iter; ++ conffile_t *cf; ++ ++ if (conf->noaction) return 0; ++ ++ /* Backup all modified conffiles */ ++ if (old_pkg) { ++ for (iter = old_pkg->conffiles.head; iter; iter = iter->next) { ++ char *cf_name; ++ ++ cf = iter->data; ++ cf_name = root_filename_alloc(conf, cf->name); ++ ++ /* Don't worry if the conffile is just plain gone */ ++ if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) { ++ err = backup_make_backup(conf, cf_name); ++ if (err) { ++ return err; ++ } ++ } ++ free(cf_name); ++ } ++ } ++ ++ /* Backup all conffiles that were not conffiles in old_pkg */ ++ for (iter = pkg->conffiles.head; iter; iter = iter->next) { ++ char *cf_name; ++ cf = iter->data; ++ cf_name = root_filename_alloc(conf, cf->name); ++ /* Ignore if this was a conffile in old_pkg as well */ ++ if (pkg_get_conffile(old_pkg, cf->name)) { ++ continue; ++ } ++ ++ if (file_exists(cf_name) && (! backup_exists_for(cf_name))) { ++ err = backup_make_backup(conf, cf_name); ++ if (err) { ++ return err; ++ } ++ } ++ free(cf_name); ++ } ++ ++ return 0; ++} ++ ++static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) ++{ ++ conffile_list_elt_t *iter; ++ ++ if (old_pkg) { ++ for (iter = old_pkg->conffiles.head; iter; iter = iter->next) { ++ backup_remove(iter->data->name); ++ } ++ } ++ ++ for (iter = pkg->conffiles.head; iter; iter = iter->next) { ++ backup_remove(iter->data->name); ++ } ++ ++ return 0; ++} ++ ++ ++static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) ++{ ++ /* DPKG_INCOMPATIBILITY: ++ ipkg takes a slightly different approach than dpkg at this ++ point. dpkg installs each file in the new package while ++ creating a backup for any file that is replaced, (so that it ++ can unwind if necessary). To avoid complexity and redundant ++ storage, ipkg doesn't do any installation until later, (at the ++ point at which dpkg removes the backups. ++ ++ But, we do have to check for data file clashes, since after ++ installing a package with a file clash, removing either of the ++ packages involved in the clash has the potential to break the ++ other package. ++ */ ++ str_list_t *files_list; ++ str_list_elt_t *iter; ++ ++ int clashes = 0; ++ ++ files_list = pkg_get_installed_files(pkg); ++ for (iter = files_list->head; iter; iter = iter->next) { ++ char *root_filename; ++ char *filename = iter->data; ++ root_filename = root_filename_alloc(conf, filename); ++ if (file_exists(root_filename) && (! file_is_dir(root_filename))) { ++ pkg_t *owner; ++ pkg_t *obs; ++ /* Pre-existing conffiles are OK */ ++ /* @@@@ should have way to check that it is a conffile -Jamey */ ++ if (backup_exists_for(root_filename)) { ++ continue; ++ } ++ ++ /* Pre-existing files are OK if force-overwrite was asserted. */ ++ if (conf->force_overwrite) { ++ /* but we need to change who owns this file */ ++ file_hash_set_file_owner(conf, filename, pkg); ++ continue; ++ } ++ ++ owner = file_hash_get_file_owner(conf, filename); ++ ++ /* Pre-existing files are OK if owned by the pkg being upgraded. */ ++ if (owner && old_pkg) { ++ if (strcmp(owner->name, old_pkg->name) == 0) { ++ continue; ++ } ++ } ++ ++ /* Pre-existing files are OK if owned by a package replaced by new pkg. */ ++ if (owner) { ++ ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name); ++ if (pkg_replaces(pkg, owner)) { ++ continue; ++ } ++/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar ) ++ then it's ok to overwrite. */ ++ if (strcmp(owner->name,pkg->name)==0){ ++ ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name); ++ continue; ++ } ++ } ++ ++ /* Pre-existing files are OK if they are obsolete */ ++ obs = hash_table_get(&conf->obs_file_hash, filename); ++ if (obs) { ++ ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name); ++ continue; ++ } ++ ++ /* We have found a clash. */ ++ ipkg_message(conf, IPKG_ERROR, ++ "Package %s wants to install file %s\n" ++ "\tBut that file is already provided by package ", ++ pkg->name, filename); ++ if (owner) { ++ ipkg_message(conf, IPKG_ERROR, ++ "%s\n", owner->name); ++ } else { ++ ipkg_message(conf, IPKG_ERROR, ++ "\nPlease move this file out of the way and try again.\n"); ++ } ++ clashes++; ++ } ++ free(root_filename); ++ } ++ pkg_free_installed_files(pkg); ++ ++ return clashes; ++} ++ ++static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) ++{ ++ /* Basically that's the worst hack I could do to be able to change ownership of ++ file list, but, being that we have no way to unwind the mods, due to structure ++ of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much. ++ What we do here is change the ownership of file in hash if a replace ( or similar events ++ happens ) ++ Only the action that are needed to change name should be considered. ++ @@@ To change after 1.0 release. ++ */ ++ str_list_t *files_list; ++ str_list_elt_t *iter; ++ ++ int clashes = 0; ++ ++ files_list = pkg_get_installed_files(pkg); ++ for (iter = files_list->head; iter; iter = iter->next) { ++ char *root_filename; ++ char *filename = iter->data; ++ root_filename = root_filename_alloc(conf, filename); ++ if (file_exists(root_filename) && (! file_is_dir(root_filename))) { ++ pkg_t *owner; ++ ++ if (conf->force_overwrite) { ++ /* but we need to change who owns this file */ ++ file_hash_set_file_owner(conf, filename, pkg); ++ continue; ++ } ++ ++ owner = file_hash_get_file_owner(conf, filename); ++ ++ /* Pre-existing files are OK if owned by a package replaced by new pkg. */ ++ if (owner) { ++ if (pkg_replaces(pkg, owner)) { ++/* It's now time to change the owner of that file. ++ It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */ ++ ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name); ++ file_hash_set_file_owner(conf, filename, pkg); ++ continue; ++ } ++ } ++ ++ } ++ free(root_filename); ++ } ++ pkg_free_installed_files(pkg); ++ ++ return clashes; ++} ++ ++static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) ++{ ++ /* Nothing to do since check_data_file_clashes doesn't change state */ ++ return 0; ++} ++ ++static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) ++{ ++ /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we? ++ 1. If the package is being upgraded, call ++ old-postrm upgrade new-version ++ 2. If this fails, attempt: ++ new-postrm failed-upgrade old-version ++ Error unwind, for both cases: ++ old-preinst abort-upgrade new-version */ ++ return 0; ++} ++ ++static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) ++{ ++ /* DPKG_INCOMPATIBILITY: ++ dpkg does some things here that we don't do yet. Do we care? ++ (See postrm_upgrade_old_pkg for details) ++ */ ++ return 0; ++} ++ ++static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) ++{ ++ int err; ++ str_list_t *old_files; ++ str_list_elt_t *of; ++ str_list_t *new_files; ++ str_list_elt_t *nf; ++ ++ if (old_pkg == NULL) { ++ return 0; ++ } ++ ++ old_files = pkg_get_installed_files(old_pkg); ++ new_files = pkg_get_installed_files(pkg); ++ ++ for (of = old_files->head; of; of = of->next) { ++ pkg_t *owner; ++ char *old, *new; ++ old = of->data; ++ for (nf = new_files->head; nf; nf = nf->next) { ++ new = nf->data; ++ if (strcmp(old, new) == 0) { ++ goto NOT_OBSOLETE; ++ } ++ } ++ if (file_is_dir(old)) { ++ continue; ++ } ++ owner = file_hash_get_file_owner(conf, old); ++ if (owner != old_pkg) { ++ /* in case obsolete file no longer belongs to old_pkg */ ++ continue; ++ } ++ ++ /* old file is obsolete */ ++ ipkg_message(conf, IPKG_INFO, ++ " removing obsolete file %s\n", old); ++ if (!conf->noaction) { ++ err = unlink(old); ++ if (err) { ++ ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old, ++ strerror(errno)); ++ } ++ } ++ ++ NOT_OBSOLETE: ++ ; ++ } ++ ++ pkg_free_installed_files(old_pkg); ++ pkg_free_installed_files(pkg); ++ ++ return 0; ++} ++ ++static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) ++{ ++ int i; ++ int err = 0; ++ char *globpattern; ++ glob_t globbuf; ++ if (0) { ++ if (!pkg->dest) { ++ ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name); ++ return -1; ++ } ++ sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name); ++ err = glob(globpattern, 0, NULL, &globbuf); ++ free(globpattern); ++ if (err) { ++ return err; ++ } ++ /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */ ++ for (i = 0; i < globbuf.gl_pathc; i++) { ++ ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n", ++ globbuf.gl_pathv[i], old_pkg->name); ++ if (!conf->noaction) ++ unlink(globbuf.gl_pathv[i]); ++ } ++ globfree(&globbuf); ++ } ++ return err; ++} ++ ++static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) ++{ ++ int ret; ++ char *prefix; ++ ++ if (old_pkg) ++ remove_obsolete_maintainer_scripts(conf, pkg, old_pkg); ++ sprintf_alloc(&prefix, "%s.", pkg->name); ++ ret = pkg_extract_control_files_to_dir_with_prefix(pkg, ++ pkg->dest->info_dir, ++ prefix); ++ free(prefix); ++ return ret; ++} ++ ++static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg) ++{ ++ /* DPKG_INCOMPATIBILITY: ++ This is a fairly sophisticated dpkg operation. Shall we ++ skip it? */ ++ ++ /* Any packages all of whose files have been overwritten during the ++ installation, and which aren't required for dependencies, are ++ considered to have been removed. For each such package ++ 1. disappearer's-postrm disappear overwriter overwriter-version ++ 2. The package's maintainer scripts are removed ++ 3. It is noted in the status database as being in a sane state, ++ namely not installed (any conffiles it may have are ignored, ++ rather than being removed by dpkg). Note that disappearing ++ packages do not have their prerm called, because dpkg doesn't ++ know in advance that the package is going to vanish. ++ */ ++ return 0; ++} ++ ++static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg) ++{ ++ int err; ++ ++ /* ipkg takes a slightly different approach to data file backups ++ than dpkg. Rather than removing backups at this point, we ++ actually do the data file installation now. See comments in ++ check_data_file_clashes() for more details. */ ++ ++ ipkg_message(conf, IPKG_INFO, ++ " extracting data files to %s\n", pkg->dest->root_dir); ++ err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir); ++ if (err) { ++ return err; ++ } ++ ++ /* XXX: BUG or FEATURE : We are actually loosing the Essential flag, ++ so we can't save ourself from removing important packages ++ At this point we (should) have extracted the .control file, so it ++ would be a good idea to reload the data in it, and set the Essential ++ state in *pkg. From now on the Essential is back in status file and ++ we can protect again. ++ We should operate this way: ++ fopen the file ( pkg->dest->root_dir/pkg->name.control ) ++ check for "Essential" in it ++ set the value in pkg->essential. ++ This new routine could be useful also for every other flag ++ Pigi: 16/03/2004 */ ++ set_flags_from_control(conf, pkg) ; ++ ++ ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__); ++ err = pkg_write_filelist(conf, pkg); ++ if (err) ++ return err; ++ ++ /* XXX: FEATURE: ipkg should identify any files which existed ++ before installation and which were overwritten, (see ++ check_data_file_clashes()). What it must do is remove any such ++ files from the filelist of the old package which provided the ++ file. Otherwise, if the old package were removed at some point ++ it would break the new package. Removing the new package will ++ also break the old one, but this cannot be helped since the old ++ package's file has already been deleted. This is the importance ++ of check_data_file_clashes(), and only allowing ipkg to install ++ a clashing package with a user force. */ ++ ++ return 0; ++} ++ ++static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg) ++{ ++ conffile_list_elt_t *iter; ++ conffile_t *cf; ++ char *cf_backup; ++ ++ char *md5sum; ++ ++ ++ if (conf->noaction) return 0; ++ ++ for (iter = pkg->conffiles.head; iter; iter = iter->next) { ++ char *root_filename; ++ cf = iter->data; ++ root_filename = root_filename_alloc(conf, cf->name); ++ ++ /* Might need to initialize the md5sum for each conffile */ ++ if (cf->value == NULL) { ++ cf->value = file_md5sum_alloc(root_filename); ++ } ++ ++ if (!file_exists(root_filename)) { ++ free(root_filename); ++ continue; ++ } ++ ++ cf_backup = backup_filename_alloc(root_filename); ++ ++ ++ if (file_exists(cf_backup)) { ++ /* Let's compute md5 to test if files are changed */ ++ md5sum = file_md5sum_alloc(cf_backup); ++ if (strcmp( cf->value,md5sum) != 0 ) { ++ if (conf->force_defaults ++ || user_prefers_old_conffile(cf->name, cf_backup) ) { ++ rename(cf_backup, root_filename); ++ } ++ } ++ unlink(cf_backup); ++ free(md5sum); ++ } ++ ++ free(cf_backup); ++ free(root_filename); ++ } ++ ++ return 0; ++} ++ ++static int user_prefers_old_conffile(const char *file_name, const char *backup) ++{ ++ char *response; ++ const char *short_file_name; ++ ++ short_file_name = strrchr(file_name, '/'); ++ if (short_file_name) { ++ short_file_name++; ++ } else { ++ short_file_name = file_name; ++ } ++ ++ while (1) { ++ response = get_user_response(" Configuration file '%s'\n" ++ " ==> File on system created by you or by a script.\n" ++ " ==> File also in package provided by package maintainer.\n" ++ " What would you like to do about it ? Your options are:\n" ++ " Y or I : install the package maintainer's version\n" ++ " N or O : keep your currently-installed version\n" ++ " D : show the differences between the versions (if diff is installed)\n" ++ " The default action is to keep your current version.\n" ++ " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name); ++ if (strcmp(response, "y") == 0 ++ || strcmp(response, "i") == 0 ++ || strcmp(response, "yes") == 0) { ++ free(response); ++ return 0; ++ } ++ ++ if (strcmp(response, "d") == 0) { ++ char *cmd; ++ ++ free(response); ++ /* XXX: BUG rewrite to use exec or busybox's internal diff */ ++ sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name); ++ xsystem(cmd); ++ free(cmd); ++ printf(" [Press ENTER to continue]\n"); ++ response = file_read_line_alloc(stdin); ++ free(response); ++ continue; ++ } ++ ++ free(response); ++ return 1; ++ } ++} ++ ++/* XXX: CLEANUP: I'd like to move all of the code for ++ creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then, ++ it would make sense to cleanup pkg->tmp_unpack_dir directly from ++ pkg_deinit for example). */ ++static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg) ++{ ++ DIR *tmp_dir; ++ struct dirent *dirent; ++ char *tmp_file; ++ ++#ifdef IPKG_DEBUG_NO_TMP_CLEANUP ++#error ++ ipkg_message(conf, IPKG_DEBUG, ++ "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n", ++ __FUNCTION__, pkg->tmp_unpack_dir); ++ return 0; ++#endif ++ ++ if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) { ++ tmp_dir = opendir(pkg->tmp_unpack_dir); ++ if (tmp_dir) { ++ while (1) { ++ dirent = readdir(tmp_dir); ++ if (dirent == NULL) { ++ break; ++ } ++ sprintf_alloc(&tmp_file, "%s/%s", ++ pkg->tmp_unpack_dir, dirent->d_name); ++ if (! file_is_dir(tmp_file)) { ++ unlink(tmp_file); ++ } ++ free(tmp_file); ++ } ++ closedir(tmp_dir); ++ rmdir(pkg->tmp_unpack_dir); ++ free(pkg->tmp_unpack_dir); ++ pkg->tmp_unpack_dir = NULL; ++ } ++ } ++ ++ ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n", ++ pkg->name, pkg->local_filename, conf->tmp_dir); ++ if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) { ++ unlink(pkg->local_filename); ++ free(pkg->local_filename); ++ pkg->local_filename = NULL; ++ } ++ ++ return 0; ++} ++ ++static char *backup_filename_alloc(const char *file_name) ++{ ++ char *backup; ++ ++ sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX); ++ ++ return backup; ++} ++ ++int backup_make_backup(ipkg_conf_t *conf, const char *file_name) ++{ ++ int err; ++ char *backup; ++ ++ backup = backup_filename_alloc(file_name); ++ err = file_copy(file_name, backup); ++ if (err) { ++ ipkg_message(conf, IPKG_ERROR, ++ "%s: Failed to copy %s to %s\n", ++ __FUNCTION__, file_name, backup); ++ } ++ ++ free(backup); ++ ++ return err; ++} ++ ++static int backup_exists_for(const char *file_name) ++{ ++ int ret; ++ char *backup; ++ ++ backup = backup_filename_alloc(file_name); ++ ++ ret = file_exists(backup); ++ ++ free(backup); ++ ++ return ret; ++} ++ ++static int backup_remove(const char *file_name) ++{ ++ char *backup; ++ ++ backup = backup_filename_alloc(file_name); ++ unlink(backup); ++ free(backup); ++ ++ return 0; ++} ++ ++ ++ ++#ifdef CONFIG_IPKG_PROCESS_ACTIONS ++ ++int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove) ++{ ++ /* first, remove the packages that need removing */ ++ for (i = 0 ; i < pkgs_to_remove->len; i++ ) { ++ pkg_t *pkg = pkgs_to_remove->pkgs[i]; ++ err = ipkg_remove_pkg(conf, pkg,0); ++ if (err) return err; ++ } ++ return 0; ++} ++ ++int ipkg_process_actions_sanity_check(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install) ++{ ++ int i; ++ /* now one more pass checking on the ones that need to be installed */ ++ for (i = 0 ; i < pkgs_to_install->len; i++ ) { ++ pkg_t *pkg = pkgs_to_install->pkgs[i]; ++ if (pkg->dest == NULL) ++ pkg->dest = conf->default_dest; ++ ++ pkg->state_want = SW_INSTALL; ++ ++ /* Abhaya: conflicts check */ ++ err = check_conflicts_for(conf, pkg); ++ if (err) { return err; } ++ } ++ return 0; ++} ++ ++int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install) ++{ ++ int i; ++ /* now one more pass checking on the ones that need to be installed */ ++ for (i = 0 ; i < pkgs_to_install->len; i++ ) { ++ pkg_t *pkg = pkgs_to_install->pkgs[i]; ++ ++ /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */ ++ pkg_vec_t *replacees = pkg_vec_alloc(); ++ pkg_get_installed_replacees(conf, pkg, replacees); ++ ++ /* XXX: BUG: we really should treat replacement more like an upgrade ++ * Instead, we're going to remove the replacees ++ */ ++ err = pkg_remove_installed_replacees(conf, replacees); ++ if (err) return err; ++ pkg->state_flag |= SF_REMOVED_REPLACEES; ++ } ++ return 0; ++} ++ ++int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install) ++{ ++ int i; ++ /* now one more pass checking on the ones that need to be installed */ ++ for (i = 0 ; i < pkgs_to_install->len; i++ ) { ++ pkg_t *pkg = pkgs_to_install->pkgs[i]; ++ if (pkg->local_filename == NULL) { ++ err = ipkg_download_pkg(conf, pkg, conf->tmp_dir); ++ if (err) { ++ ipkg_message(conf, IPKG_ERROR, ++ "Failed to download %s. Perhaps you need to run 'ipkg update'?\n", ++ pkg->name); ++ return err; ++ } ++ } ++ if (pkg->tmp_unpack_dir == NULL) { ++ err = unpack_pkg_control_files(conf, pkg); ++ if (err) return err; ++ } ++ } ++ return 0; ++} ++ ++int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install) ++{ ++ int i; ++ /* now one more pass checking on the ones that need to be installed */ ++ for (i = 0 ; i < pkgs_to_install->len; i++ ) { ++ pkg_t *pkg = pkgs_to_install->pkgs[i]; ++ pkg_t *old_pkg = pkg->old_pkg; ++ ++ err = prerm_upgrade_old_pkg(conf, pkg, old_pkg); ++ if (err) return err; ++ ++ err = prerm_deconfigure_conflictors(conf, pkg, replacees); ++ if (err) return err; ++ ++ err = preinst_configure(conf, pkg, old_pkg); ++ if (err) return err; ++ ++ err = backup_modified_conffiles(conf, pkg, old_pkg); ++ if (err) return err; ++ ++ err = postrm_upgrade_old_pkg(conf, pkg, old_pkg); ++ if (err) return err; ++ } ++ return 0; ++} ++ ++int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install) ++{ ++ int i; ++ /* now one more pass checking on the ones that need to be installed */ ++ for (i = 0 ; i < pkgs_to_install->len; i++ ) { ++ pkg_t *pkg = pkgs_to_install->pkgs[i]; ++ pkg_t *old_pkg = pkg->old_pkg; ++ ++ if (old_pkg) { ++ old_pkg->state_want = SW_DEINSTALL; ++ ++ if (old_pkg->state_flag & SF_NOPRUNE) { ++ ipkg_message(conf, IPKG_INFO, ++ " not removing obsolesced files because package marked noprune\n"); ++ } else { ++ ipkg_message(conf, IPKG_INFO, ++ " removing obsolesced files\n"); ++ remove_obsolesced_files(conf, pkg, old_pkg); ++ } ++ } ++ ++ ipkg_message(conf, IPKG_INFO, ++ " installing maintainer scripts\n"); ++ install_maintainer_scripts(conf, pkg, old_pkg); ++ ++ /* the following just returns 0 */ ++ remove_disappeared(conf, pkg); ++ ++ ipkg_message(conf, IPKG_INFO, ++ " installing data files\n"); ++ install_data_files(conf, pkg); ++ ++ ipkg_message(conf, IPKG_INFO, ++ " resolving conf files\n"); ++ resolve_conffiles(conf, pkg); ++ ++ pkg->state_status = SS_UNPACKED; ++ ++ if (old_pkg) { ++ old_pkg->state_status = SS_NOT_INSTALLED; ++ } ++ ++ time(&pkg->installed_time); ++ ++ ipkg_message(conf, IPKG_INFO, ++ " cleanup temp files\n"); ++ cleanup_temporary_files(conf, pkg); ++ ++ if (pkg->parent) ++ pkg->parent->state_status = pkg->state_status; ++ } ++ return 0; ++} ++ ++int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install) ++{ ++ int i; ++ /* now one more pass checking on the ones that need to be installed */ ++ for (i = 0 ; i < pkgs_to_install->len; i++ ) { ++ pkg_t *pkg = pkgs_to_install->pkgs[i]; ++ pkg_t *old_pkg = pkg->old_pkg; ++ ++ if (old_pkg) { ++ if (old_pkg->state_flags & SF_POSTRM_UPGRADE) ++ postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg); ++ if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES) ++ check_data_file_clashes_unwind(conf, pkg, old_pkg); ++ if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES) ++ backup_modified_conffiles_unwind(conf, pkg, old_pkg); ++ if (old_pkg->state_flags & SF_PREINST_CONFIGURE) ++ preinst_configure_unwind(conf, pkg, old_pkg); ++ if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS) ++ prerm_deconfigure_conflictors_unwind(conf, pkg, replacees); ++ if (old_pkg->state_flags & SF_PRERM_UPGRADE) ++ prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg); ++ ++ if (old_pkg->state_flags & SF_REMOVED_REPLACEES) ++ remove_installed_replacees_unwind(conf, pkg, old_pkg); ++ ++ } ++ } ++ return 0; ++} ++ ++/* ++ * Perform all the actions. ++ * ++ * pkgs_to_remove are packages marked for removal. ++ * pkgs_superseded are the old packages being replaced by upgrades. ++ * ++ * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order. ++ */ ++int ipkg_process_actions(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install) ++{ ++ int err; ++ int i; ++ ++ err = ipkg_remove_packages(conf, pkgs_to_remove); ++ if (err) return err; ++ ++ err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install); ++ if (err) return err; ++ ++ err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install); ++ if (err) goto UNWIND; ++ ++ /* @@@@ look at ipkg_install_pkg for handling replacements */ ++ err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install); ++ if (err) goto UNWIND; ++ ++ /* ++ * Now that we have the packages unpacked, we can look for data ++ * file clashes. First, we mark the files from the superseded ++ * packages as obsolete. Then we scan the files in ++ * pkgs_to_install, and only complain about clashes with ++ * non-obsolete files. ++ */ ++ ++ err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install); ++ if (err) goto UNWIND; ++ ++ /* this was before checking data file clashes */ ++ err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install); ++ if (err) goto UNWIND; ++ ++ /* point of no return: no unwinding after this */ ++ err = ipkg_process_actions_install(conf, pkgs_to_install); ++ if (err) return err; ++ ++ ipkg_message(conf, IPKG_INFO, "Done.\n"); ++ return 0; ++ ++ UNWIND: ++ ipkg_process_actions_unwind(conf, pkgs_to_install); ++ ++ ipkg_message(conf, IPKG_INFO, ++ " cleanup temp files\n"); ++ cleanup_temporary_files(conf, pkg); ++ ++ ipkg_message(conf, IPKG_INFO, ++ "Failed.\n"); ++ return err; ++} ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/ipkg_install.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg_install.h 2007-10-04 17:14:22.753038046 +0200 +@@ -0,0 +1,35 @@ ++/* ipkg_install.h - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef IPKG_INSTALL_H ++#define IPKG_INSTALL_H ++ ++#include "pkg.h" ++#include "ipkg_conf.h" ++ ++ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name); ++ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name); ++int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename); ++int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading); ++int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg); ++ ++int ipkg_satisfy_all_dependences(ipkg_conf_t *conf); ++ ++int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed); ++int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed); ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/ipkg_message.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg_message.c 2007-10-04 17:24:58.037240829 +0200 +@@ -0,0 +1,61 @@ ++/* ipkg_message.c - the itsy package management system ++ ++ Copyright (C) 2003 Daniele Nicolodi ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++ ++#include "ipkg.h" ++#include "ipkg_conf.h" ++#include "ipkg_message.h" ++ ++#ifndef IPKG_LIB ++ ++void ++ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...) ++{ ++ va_list ap; ++ ++ if (conf && (conf->verbosity < level)) ++ { ++ return; ++ } ++ else ++ { ++ ++ va_start (ap, fmt); ++ vprintf (fmt, ap); ++ va_end (ap); ++ } ++} ++ ++#else ++ ++#include "libipkg.h" ++ ++//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg) ++ ++void ++ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...) ++{ ++ va_list ap; ++ char ts[256]; ++ ++ if (ipkg_cb_message) ++ { ++ va_start (ap, fmt); ++ vsnprintf (ts,256,fmt, ap); ++ va_end (ap); ++ ipkg_cb_message(conf,level,ts); ++ } ++} ++#endif +Index: busybox-1.7.2/archival/libipkg/ipkg_message.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg_message.h 2007-10-04 17:23:42.072911866 +0200 +@@ -0,0 +1,32 @@ ++/* ipkg_message.h - the itsy package management system ++ ++ Copyright (C) 2003 Daniele Nicolodi ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef _IPKG_MESSAGE_H_ ++#define _IPKG_MESSAGE_H_ ++ ++#include "ipkg.h" ++#include "ipkg_conf.h" ++ ++typedef enum { ++ IPKG_ERROR, /* error conditions */ ++ IPKG_NOTICE, /* normal but significant condition */ ++ IPKG_INFO, /* informational message */ ++ IPKG_DEBUG, /* debug level message */ ++ IPKG_DEBUG2, /* more debug level message */ ++} message_level_t; ++ ++extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...); ++ ++#endif /* _IPKG_MESSAGE_H_ */ +Index: busybox-1.7.2/archival/libipkg/ipkg_remove.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg_remove.c 2007-10-04 17:14:22.801040776 +0200 +@@ -0,0 +1,383 @@ ++/* ipkg_remove.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++#include "ipkg_message.h" ++ ++#include ++ ++#include "ipkg_remove.h" ++ ++#include "file_util.h" ++#include "sprintf_alloc.h" ++#include "str_util.h" ++ ++#include "ipkg_cmd.h" ++ ++/* ++ * Returns number of the number of packages depending on the packages provided by this package. ++ * Every package implicitly provides itself. ++ */ ++int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents) ++{ ++ int nprovides = pkg->provides_count; ++ abstract_pkg_t **provides = pkg->provides; ++ int n_installed_dependents = 0; ++ int i; ++ for (i = 0; i <= nprovides; i++) { ++ abstract_pkg_t *providee = provides[i]; ++ abstract_pkg_t **dependers = providee->depended_upon_by; ++ abstract_pkg_t *dep_ab_pkg; ++ if (dependers == NULL) ++ continue; ++ while ((dep_ab_pkg = *dependers++) != NULL) { ++ if (dep_ab_pkg->state_status == SS_INSTALLED){ ++ n_installed_dependents++; ++ } ++ } ++ ++ } ++ /* if caller requested the set of installed dependents */ ++ if (pdependents) { ++ int p = 0; ++ abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *)); ++ ++ if ( dependents == NULL ){ ++ fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__); ++ return -1; ++ } ++ ++ *pdependents = dependents; ++ for (i = 0; i <= nprovides; i++) { ++ abstract_pkg_t *providee = provides[i]; ++ abstract_pkg_t **dependers = providee->depended_upon_by; ++ abstract_pkg_t *dep_ab_pkg; ++ if (dependers == NULL) ++ continue; ++ while ((dep_ab_pkg = *dependers++) != NULL) { ++ if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) { ++ dependents[p++] = dep_ab_pkg; ++ dep_ab_pkg->state_flag |= SF_MARKED; ++ } ++ } ++ } ++ dependents[p] = NULL; ++ /* now clear the marks */ ++ for (i = 0; i < p; i++) { ++ abstract_pkg_t *dep_ab_pkg = dependents[i]; ++ dep_ab_pkg->state_flag &= ~SF_MARKED; ++ } ++ } ++ return n_installed_dependents; ++} ++ ++int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents) ++{ ++ int i; ++ int a; ++ int count; ++ pkg_vec_t *dependent_pkgs = pkg_vec_alloc(); ++ abstract_pkg_t * ab_pkg; ++ ++ if((ab_pkg = pkg->parent) == NULL){ ++ fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n", ++ __FUNCTION__, pkg->name); ++ return 0; ++ } ++ ++ if (dependents == NULL) ++ return 0; ++ ++ // here i am using the dependencies_checked ++ if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package ++ return 0; // has already been encountered in the process ++ // of marking packages for removal - Karthik ++ ab_pkg->dependencies_checked = 2; ++ ++ i = 0; ++ count = 1; ++ while (dependents [i] != NULL) { ++ abstract_pkg_t *dep_ab_pkg = dependents[i]; ++ ++ if (dep_ab_pkg->dependencies_checked == 2){ ++ i++; ++ continue; ++ } ++ if (dep_ab_pkg->state_status == SS_INSTALLED) { ++ for (a = 0; a < dep_ab_pkg->pkgs->len; a++) { ++ pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a]; ++ if (dep_pkg->state_status == SS_INSTALLED) { ++ pkg_vec_insert(dependent_pkgs, dep_pkg); ++ count++; ++ } ++ } ++ } ++ i++; ++ /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs. ++ * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */ ++ } ++ ++ if (count == 1) ++ return 0; ++ ++ ++ for (i = 0; i < dependent_pkgs->len; i++) { ++ int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0); ++ if (err) ++ return err; ++ } ++ return 0; ++} ++ ++static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents) ++{ ++ abstract_pkg_t *dep_ab_pkg; ++ ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name); ++ while ((dep_ab_pkg = *dependents++) != NULL) { ++ if (dep_ab_pkg->state_status == SS_INSTALLED) ++ ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name); ++ } ++ ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name); ++ ipkg_message(conf, IPKG_ERROR, ""); ++ ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n"); ++ ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n"); ++ ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n"); ++ ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n"); ++ ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n"); ++ return 0; ++} ++ ++int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message) ++{ ++/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove ++ thus I wan't check for essential, as I'm upgrading. ++ I hope it won't break anything :) ++*/ ++ int err; ++ abstract_pkg_t *parent_pkg = NULL; ++ ++ if (pkg->essential && !message) { ++ if (conf->force_removal_of_essential_packages) { ++ fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n" ++ "\tIf your system breaks, you get to keep both pieces\n", ++ pkg->name); ++ } else { ++ fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n" ++ "\tRemoving an essential package may lead to an unusable system, but if\n" ++ "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n" ++ "\tits will with the option: -force-removal-of-essential-packages\n", ++ pkg->name); ++ return IPKG_PKG_IS_ESSENTIAL; ++ } ++ } ++ ++ if ((parent_pkg = pkg->parent) == NULL) ++ return 0; ++ ++ /* only attempt to remove dependent installed packages if ++ * force_depends is not specified or the package is being ++ * replaced. ++ */ ++ if (!conf->force_depends ++ && !(pkg->state_flag & SF_REPLACE)) { ++ abstract_pkg_t **dependents; ++ int has_installed_dependents = ++ pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents); ++ ++ if (has_installed_dependents) { ++ /* ++ * if this package is depended up by others, then either we should ++ * not remove it or we should remove it and all of its dependents ++ */ ++ ++ if (!conf->force_removal_of_dependent_packages ++ && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) { ++ return IPKG_PKG_HAS_DEPENDENTS; ++ } ++ ++ /* remove packages depending on this package - Karthik */ ++ err = ipkg_remove_dependent_pkgs (conf, pkg, dependents); ++ free(dependents); ++ if (err) return err; ++ } ++ } ++ ++ if ( message==0 ){ ++ printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name); ++ fflush(stdout); ++ } ++ pkg->state_flag |= SF_FILELIST_CHANGED; ++ ++ pkg->state_want = SW_DEINSTALL; ++ ipkg_state_changed++; ++ ++ pkg_run_script(conf, pkg, "prerm", "remove"); ++ ++ /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It ++ maintains an empty filelist rather than deleting it. That seems ++ like a big pain, and I don't see that that should make a big ++ difference, but for anyone who wants tighter compatibility, ++ feel free to fix this. */ ++ remove_data_files_and_list(conf, pkg); ++ ++ pkg_run_script(conf, pkg, "postrm", "remove"); ++ ++ remove_maintainer_scripts_except_postrm(conf, pkg); ++ ++ /* Aman Gupta - Since ipkg is made for handheld devices with limited ++ * space, it doesn't make sense to leave extra configurations, files, ++ * and maintainer scripts left around. So, we make remove like purge, ++ * and take out all the crap :) */ ++ ++ remove_postrm(conf, pkg); ++ pkg->state_status = SS_NOT_INSTALLED; ++ ++ if (parent_pkg) ++ parent_pkg->state_status = SS_NOT_INSTALLED; ++ ++ return 0; ++} ++ ++int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg) ++{ ++ ipkg_remove_pkg(conf, pkg,0); ++ return 0; ++} ++ ++int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg) ++{ ++ str_list_t installed_dirs; ++ str_list_t *installed_files; ++ str_list_elt_t *iter; ++ char *file_name; ++ conffile_t *conffile; ++ int removed_a_dir; ++ pkg_t *owner; ++ ++ str_list_init(&installed_dirs); ++ installed_files = pkg_get_installed_files(pkg); ++ ++ for (iter = installed_files->head; iter; iter = iter->next) { ++ file_name = iter->data; ++ ++ if (file_is_dir(file_name)) { ++ str_list_append(&installed_dirs, strdup(file_name)); ++ continue; ++ } ++ ++ conffile = pkg_get_conffile(pkg, file_name); ++ if (conffile) { ++ /* XXX: QUESTION: Is this right? I figure we only need to ++ save the conffile if it has been modified. Is that what ++ dpkg does? Or does dpkg preserve all conffiles? If so, ++ this seems like a better thing to do to conserve ++ space. */ ++ if (conffile_has_been_modified(conf, conffile)) { ++ printf(" not deleting modified conffile %s\n", file_name); ++ fflush(stdout); ++ continue; ++ } ++ } ++ ++ ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction); ++ if (!conf->noaction) ++ unlink(file_name); ++ } ++ ++ if (!conf->noaction) { ++ do { ++ removed_a_dir = 0; ++ for (iter = installed_dirs.head; iter; iter = iter->next) { ++ file_name = iter->data; ++ ++ if (rmdir(file_name) == 0) { ++ ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name); ++ removed_a_dir = 1; ++ str_list_remove(&installed_dirs, &iter); ++ } ++ } ++ } while (removed_a_dir); ++ } ++ ++ pkg_free_installed_files(pkg); ++ /* We have to remove the file list now, so that ++ find_pkg_owning_file does not always just report this package */ ++ pkg_remove_installed_files_list(conf, pkg); ++ ++ /* Don't print warning for dirs that are provided by other packages */ ++ for (iter = installed_dirs.head; iter; iter = iter->next) { ++ file_name = iter->data; ++ ++ owner = file_hash_get_file_owner(conf, file_name); ++ if (owner) { ++ free(iter->data); ++ iter->data = NULL; ++ str_list_remove(&installed_dirs, &iter); ++ } ++ } ++ ++ /* cleanup */ ++ for (iter = installed_dirs.head; iter; iter = iter->next) { ++ free(iter->data); ++ iter->data = NULL; ++ } ++ str_list_deinit(&installed_dirs); ++ ++ return 0; ++} ++ ++int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg) ++{ ++ int i, err; ++ char *globpattern; ++ glob_t globbuf; ++ ++ if (conf->noaction) return 0; ++ ++ sprintf_alloc(&globpattern, "%s/%s.*", ++ pkg->dest->info_dir, pkg->name); ++ err = glob(globpattern, 0, NULL, &globbuf); ++ free(globpattern); ++ if (err) { ++ return 0; ++ } ++ ++ for (i = 0; i < globbuf.gl_pathc; i++) { ++ if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) { ++ continue; ++ } ++ ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]); ++ unlink(globbuf.gl_pathv[i]); ++ } ++ globfree(&globbuf); ++ ++ return 0; ++} ++ ++int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg) ++{ ++ char *postrm_file_name; ++ ++ if (conf->noaction) return 0; ++ ++ sprintf_alloc(&postrm_file_name, "%s/%s.postrm", ++ pkg->dest->info_dir, pkg->name); ++ unlink(postrm_file_name); ++ free(postrm_file_name); ++ ++ return 0; ++} +Index: busybox-1.7.2/archival/libipkg/ipkg_remove.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg_remove.h 2007-10-04 17:14:22.821041916 +0200 +@@ -0,0 +1,33 @@ ++/* ipkg_remove.h - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef IPKG_REMOVE_H ++#define IPKG_REMOVE_H ++ ++#include "pkg.h" ++#include "ipkg_conf.h" ++ ++int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message); ++int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg); ++int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg); ++int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents); ++int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg); ++int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg); ++int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg); ++ ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/ipkg_upgrade.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg_upgrade.c 2007-10-04 17:14:22.837042832 +0200 +@@ -0,0 +1,77 @@ ++/* ipkg_upgrade.c - the itsy package management system ++ ++ Carl D. Worth ++ Copyright (C) 2001 University of Southern California ++ ++ Copyright (C) 2003 Daniele Nicolodi ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++#include "ipkg_install.h" ++#include "ipkg_message.h" ++ ++int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old) ++{ ++ pkg_t *new; ++ int cmp; ++ char *old_version, *new_version; ++ ++ if (old->state_flag & SF_HOLD) { ++ ipkg_message(conf, IPKG_NOTICE, ++ "Not upgrading package %s which is marked " ++ "hold (flags=%#x)\n", old->name, old->state_flag); ++ return 0; ++ } ++ ++ new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name); ++ if (new == NULL) { ++ old_version = pkg_version_str_alloc(old); ++ ipkg_message(conf, IPKG_NOTICE, ++ "Assuming locally installed package %s (%s) " ++ "is up to date.\n", old->name, old_version); ++ free(old_version); ++ return 0; ++ } ++ ++ old_version = pkg_version_str_alloc(old); ++ new_version = pkg_version_str_alloc(new); ++ ++ cmp = pkg_compare_versions(old, new); ++ ipkg_message(conf, IPKG_DEBUG, ++ "comparing visible versions of pkg %s:" ++ "\n\t%s is installed " ++ "\n\t%s is available " ++ "\n\t%d was comparison result\n", ++ old->name, old_version, new_version, cmp); ++ if (cmp == 0) { ++ ipkg_message(conf, IPKG_INFO, ++ "Package %s (%s) installed in %s is up to date.\n", ++ old->name, old_version, old->dest->name); ++ free(old_version); ++ free(new_version); ++ return 0; ++ } else if (cmp > 0) { ++ ipkg_message(conf, IPKG_NOTICE, ++ "Not downgrading package %s on %s from %s to %s.\n", ++ old->name, old->dest->name, old_version, new_version); ++ free(old_version); ++ free(new_version); ++ return 0; ++ } else if (cmp < 0) { ++ new->dest = old->dest; ++ old->state_want = SW_DEINSTALL; ++ } ++ ++ new->state_flag |= SF_USER; ++ return ipkg_install_pkg(conf, new,1); ++} +Index: busybox-1.7.2/archival/libipkg/ipkg_upgrade.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg_upgrade.h 2007-10-04 17:14:22.877045111 +0200 +@@ -0,0 +1,18 @@ ++/* ipkg_upgrade.c - the itsy package management system ++ ++ Copyright (C) 2003 Daniele Nicolodi ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++ ++int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old); +Index: busybox-1.7.2/archival/libipkg/ipkg_utils.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg_utils.c 2007-10-04 17:14:22.897046251 +0200 +@@ -0,0 +1,181 @@ ++/* ipkg_utils.c - the itsy package management system ++ ++ Steven M. Ayer ++ ++ Copyright (C) 2002 Compaq Computer Corporation ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++#include ++#include ++#include ++ ++#include "ipkg_utils.h" ++#include "pkg.h" ++#include "pkg_hash.h" ++ ++struct errlist* error_list; ++ ++int get_available_blocks(char * filesystem) ++{ ++ struct statfs sfs; ++ ++ if(statfs(filesystem, &sfs)){ ++ fprintf(stderr, "bad statfs\n"); ++ return 0; ++ } ++ /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */ ++ return ((sfs.f_bavail * sfs.f_bsize) / 1024); ++} ++ ++char **read_raw_pkgs_from_file(const char *file_name) ++{ ++ FILE *fp; ++ char **ret; ++ ++ if(!(fp = fopen(file_name, "r"))){ ++ fprintf(stderr, "can't get %s open for read\n", file_name); ++ return NULL; ++ } ++ ++ ret = read_raw_pkgs_from_stream(fp); ++ ++ fclose(fp); ++ ++ return ret; ++} ++ ++char **read_raw_pkgs_from_stream(FILE *fp) ++{ ++ char **raw = NULL, *buf, *scout; ++ int count = 0; ++ size_t size = 512; ++ ++ buf = malloc (size); ++ ++ while (fgets(buf, size, fp)) { ++ while (strlen (buf) == (size - 1) ++ && buf[size-2] != '\n') { ++ size_t o = size - 1; ++ size *= 2; ++ buf = realloc (buf, size); ++ if (fgets (buf + o, size - o, fp) == NULL) ++ break; ++ } ++ ++ if(!(count % 50)) ++ raw = realloc(raw, (count + 50) * sizeof(char *)); ++ ++ if((scout = strchr(buf, '\n'))) ++ *scout = '\0'; ++ ++ raw[count++] = strdup(buf); ++ } ++ ++ raw = realloc(raw, (count + 1) * sizeof(char *)); ++ raw[count] = NULL; ++ ++ free (buf); ++ ++ return raw; ++} ++ ++/* something to remove whitespace, a hash pooper */ ++char *trim_alloc(char *line) ++{ ++ char *new; ++ char *dest, *src, *end; ++ ++ new = malloc(strlen(line) + 1); ++ if ( new == NULL ){ ++ fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__); ++ return NULL; ++ } ++ dest = new, src = line, end = line + (strlen(line) - 1); ++ ++ /* remove it from the front */ ++ while(src && ++ isspace(*src) && ++ *src) ++ src++; ++ /* and now from the back */ ++ while((end > src) && ++ isspace(*end)) ++ end--; ++ end++; ++ *end = '\0'; ++ strcpy(new, src); ++ /* this does from the first space ++ * blasting away any versions stuff in depends ++ while(src && ++ !isspace(*src) && ++ *src) ++ *dest++ = *src++; ++ *dest = '\0'; ++ */ ++ ++ return new; ++} ++ ++int line_is_blank(const char *line) ++{ ++ const char *s; ++ ++ for (s = line; *s; s++) { ++ if (!isspace(*s)) ++ return 0; ++ } ++ return 1; ++} ++ ++void push_error_list(struct errlist ** errors, char * msg){ ++ struct errlist *err_lst_tmp; ++ ++ ++ err_lst_tmp = malloc ( sizeof (err_lst_tmp) ); ++ err_lst_tmp->errmsg=strdup(msg) ; ++ err_lst_tmp->next = *errors; ++ *errors = err_lst_tmp; ++} ++ ++ ++void reverse_error_list(struct errlist **errors){ ++ struct errlist *result=NULL; ++ struct errlist *current= *errors; ++ struct errlist *next; ++ ++ while ( current != NULL ) { ++ next = current->next; ++ current->next=result; ++ result=current; ++ current=next; ++ } ++ *errors=result; ++ ++} ++ ++ ++void free_error_list(struct errlist **errors){ ++ struct errlist *current = *errors; ++ ++ while (current != NULL) { ++ free(current->errmsg); ++ current = (*errors)->next; ++ free(*errors); ++ *errors = current; ++ } ++ ++ ++} ++ ++ +Index: busybox-1.7.2/archival/libipkg/ipkg_utils.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/ipkg_utils.h 2007-10-04 17:14:22.921047615 +0200 +@@ -0,0 +1,29 @@ ++/* ipkg_utils.h - the itsy package management system ++ ++ Steven M. Ayer ++ ++ Copyright (C) 2002 Compaq Computer Corporation ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef IPKG_UTILS_H ++#define IPKG_UTILS_H ++ ++#include "pkg.h" ++ ++int get_available_blocks(char * filesystem); ++char **read_raw_pkgs_from_file(const char *file_name); ++char **read_raw_pkgs_from_stream(FILE *fp); ++char *trim_alloc(char * line); ++int line_is_blank(const char *line); ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/Kbuild +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/Kbuild 2007-10-04 17:14:22.937048531 +0200 +@@ -0,0 +1,60 @@ ++# Makefile for busybox ++# ++# Copyright (C) 1999-2004 by Erik Andersen ++# Copyright (C) 2006 OpenWrt.org ++# ++# Licensed under the GPL v2 or later, see the file LICENSE in this tarball. ++ ++LIBIPKG_CORE_OBJS:= \ ++ args.o \ ++ libipkg.o \ ++ user.o \ ++ ++LIBIPKG_CMD_OBJS:= \ ++ ipkg_cmd.o \ ++ ipkg_configure.o \ ++ ipkg_download.o \ ++ ipkg_install.o \ ++ ipkg_remove.o \ ++ ipkg_upgrade.o \ ++ ++LIBIPKG_DB_OBJS:= \ ++ hash_table.o \ ++ ipkg_conf.o \ ++ ipkg_utils.o \ ++ pkg.o \ ++ pkg_depends.o \ ++ pkg_extract.o \ ++ pkg_hash.o \ ++ pkg_parse.o \ ++ pkg_vec.o \ ++ ++LIBIPKG_LIST_OBJS:= \ ++ conffile.o \ ++ conffile_list.o \ ++ nv_pair.o \ ++ nv_pair_list.o \ ++ pkg_dest.o \ ++ pkg_dest_list.o \ ++ pkg_src.o \ ++ pkg_src_list.o \ ++ str_list.o \ ++ void_list.o \ ++ ++LIBIPKG_UTIL_OBJS:= \ ++ file_util.o \ ++ ipkg_message.o \ ++ str_util.o \ ++ xsystem.o \ ++ ++lib-y := ++lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS) ++lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS) ++lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS) ++lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS) ++lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS) ++ ++ifeq ($(strip $(IPKG_ARCH)),) ++IPKG_ARCH:=$(TARGET_ARCH) ++endif ++CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\"" +Index: busybox-1.7.2/archival/libipkg/libipkg.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/libipkg.c 2007-10-04 17:14:22.949049213 +0200 +@@ -0,0 +1,527 @@ ++/* ipkglib.c - the itsy package management system ++ ++ Florina Boor ++ ++ Copyright (C) 2003 kernel concepts ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifdef IPKG_LIB ++ ++#include "ipkg.h" ++#include "ipkg_includes.h" ++#include "libipkg.h" ++ ++#include "args.h" ++#include "ipkg_conf.h" ++#include "ipkg_cmd.h" ++#include "file_util.h" ++ ++ ++ ++ipkg_message_callback ipkg_cb_message = NULL; ++ipkg_response_callback ipkg_cb_response = NULL; ++ipkg_status_callback ipkg_cb_status = NULL; ++ipkg_list_callback ipkg_cb_list = NULL; ++ ++ ++int ++ipkg_init (ipkg_message_callback mcall, ++ ipkg_response_callback rcall, ++ args_t * args) ++{ ++ ipkg_cb_message = mcall; ++ ipkg_cb_response = rcall; ++ ++ args_init (args); ++ ++ return 0; ++} ++ ++ ++int ++ipkg_deinit (args_t * args) ++{ ++ args_deinit (args); ++ ipkg_cb_message = NULL; ++ ipkg_cb_response = NULL; ++ ++ /* place other cleanup stuff here */ ++ ++ return 0; ++} ++ ++ ++int ++ipkg_packages_list(args_t *args, ++ const char *packages, ++ ipkg_list_callback cblist, ++ void *userdata) ++{ ++ ipkg_cmd_t *cmd; ++ ipkg_conf_t ipkg_conf; ++ int err; ++ ++ err = ipkg_conf_init (&ipkg_conf, args); ++ if (err) ++ { ++ return err; ++ } ++ ++ ipkg_cb_list = cblist; ++ /* we need to do this because of static declarations, ++ * maybe a good idea to change */ ++ cmd = ipkg_cmd_find ("list"); ++ if (packages) ++ err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata); ++ else ++ err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata); ++ ipkg_cb_list = NULL; ++ ipkg_conf_deinit (&ipkg_conf); ++ return (err); ++} ++ ++ ++int ++ipkg_packages_status(args_t *args, ++ const char *packages, ++ ipkg_status_callback cbstatus, ++ void *userdata) ++{ ++ ipkg_cmd_t *cmd; ++ ipkg_conf_t ipkg_conf; ++ int err; ++ ++ err = ipkg_conf_init (&ipkg_conf, args); ++ if (err) ++ { ++ return err; ++ } ++ ++ ipkg_cb_status = cbstatus; ++ ++ /* we need to do this because of static declarations, ++ * maybe a good idea to change */ ++ cmd = ipkg_cmd_find ("status"); ++ if (packages) ++ err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata); ++ else ++ err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata); ++ ++ ipkg_cb_status = NULL; ++ ipkg_conf_deinit (&ipkg_conf); ++ return (err); ++} ++ ++ ++int ++ipkg_packages_info(args_t *args, ++ const char *packages, ++ ipkg_status_callback cbstatus, ++ void *userdata) ++{ ++ ipkg_cmd_t *cmd; ++ ipkg_conf_t ipkg_conf; ++ int err; ++ ++ err = ipkg_conf_init (&ipkg_conf, args); ++ if (err) ++ { ++ return err; ++ } ++ ++ ipkg_cb_status = cbstatus; ++ ++ /* we need to do this because of static declarations, ++ * maybe a good idea to change */ ++ cmd = ipkg_cmd_find ("info"); ++ if (packages) ++ err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata); ++ else ++ err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata); ++ ++ ipkg_cb_status = NULL; ++ ipkg_conf_deinit (&ipkg_conf); ++ return (err); ++} ++ ++ ++int ++ipkg_packages_install (args_t * args, const char *name) ++{ ++ ipkg_cmd_t *cmd; ++ ipkg_conf_t ipkg_conf; ++ int err; ++ ++ /* this error should be handled in application */ ++ if (!name || !strlen (name)) ++ return (-1); ++ ++ err = ipkg_conf_init (&ipkg_conf, args); ++ if (err) ++ { ++ return err; ++ } ++ ++ /* we need to do this because of static declarations, ++ * maybe a good idea to change */ ++ cmd = ipkg_cmd_find ("install"); ++ err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL); ++ ++ ipkg_conf_deinit(&ipkg_conf); ++ return (err); ++} ++ ++ ++int ++ipkg_packages_remove(args_t *args, const char *name, int purge) ++{ ++ ipkg_cmd_t *cmd; ++ ipkg_conf_t ipkg_conf; ++ int err; ++ ++ /* this error should be handled in application */ ++ if (!name || !strlen (name)) ++ return (-1); ++ ++ err = ipkg_conf_init (&ipkg_conf, args); ++ if (err) ++ { ++ return err; ++ } ++ ++ /* we need to do this because of static declarations, ++ * maybe a good idea to change */ ++ if (purge) ++ cmd = ipkg_cmd_find ("purge"); ++ else ++ cmd = ipkg_cmd_find ("remove"); ++ ++ err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL); ++ ++ ipkg_conf_deinit(&ipkg_conf); ++ return (err); ++} ++ ++ ++int ++ipkg_lists_update(args_t *args) ++{ ++ ipkg_cmd_t *cmd; ++ ipkg_conf_t ipkg_conf; ++ int err; ++ ++ err = ipkg_conf_init (&ipkg_conf, args); ++ if (err) ++ { ++ return err; ++ } ++ ++ /* we need to do this because of static declarations, ++ * maybe a good idea to change */ ++ cmd = ipkg_cmd_find ("update"); ++ ++ err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL); ++ ++ ipkg_conf_deinit(&ipkg_conf); ++ return (err); ++} ++ ++ ++int ++ipkg_packages_upgrade(args_t *args) ++{ ++ ipkg_cmd_t *cmd; ++ ipkg_conf_t ipkg_conf; ++ int err; ++ ++ err = ipkg_conf_init (&ipkg_conf, args); ++ if (err) ++ { ++ return err; ++ } ++ ++ /* we need to do this because of static declarations, ++ * maybe a good idea to change */ ++ cmd = ipkg_cmd_find ("upgrade"); ++ ++ err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL); ++ ++ ipkg_conf_deinit(&ipkg_conf); ++ return (err); ++} ++ ++ ++int ++ipkg_packages_download (args_t * args, const char *name) ++{ ++ ipkg_cmd_t *cmd; ++ ipkg_conf_t ipkg_conf; ++ int err; ++ ++ /* this error should be handled in application */ ++ if (!name || !strlen (name)) ++ return (-1); ++ ++ err = ipkg_conf_init (&ipkg_conf, args); ++ if (err) ++ { ++ return err; ++ } ++ ++ /* we need to do this because of static declarations, ++ * maybe a good idea to change */ ++ cmd = ipkg_cmd_find ("download"); ++ err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL); ++ ++ ipkg_conf_deinit(&ipkg_conf); ++ return (err); ++} ++ ++ ++int ++ipkg_package_files(args_t *args, ++ const char *name, ++ ipkg_list_callback cblist, ++ void *userdata) ++{ ++ ipkg_cmd_t *cmd; ++ ipkg_conf_t ipkg_conf; ++ int err; ++ ++ /* this error should be handled in application */ ++ if (!name || !strlen (name)) ++ return (-1); ++ ++ err = ipkg_conf_init (&ipkg_conf, args); ++ if (err) ++ { ++ return err; ++ } ++ ++ ipkg_cb_list = cblist; ++ ++ /* we need to do this because of static declarations, ++ * maybe a good idea to change */ ++ cmd = ipkg_cmd_find ("files"); ++ ++ err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata); ++ ++ ipkg_cb_list = NULL; ++ ipkg_conf_deinit(&ipkg_conf); ++ return (err); ++} ++ ++ ++int ++ipkg_file_search(args_t *args, ++ const char *file, ++ ipkg_list_callback cblist, ++ void *userdata) ++{ ++ ipkg_cmd_t *cmd; ++ ipkg_conf_t ipkg_conf; ++ int err; ++ ++ /* this error should be handled in application */ ++ if (!file || !strlen (file)) ++ return (-1); ++ ++ err = ipkg_conf_init (&ipkg_conf, args); ++ if (err) ++ { ++ return err; ++ } ++ ++ ipkg_cb_list = cblist; ++ ++ /* we need to do this because of static declarations, ++ * maybe a good idea to change */ ++ cmd = ipkg_cmd_find ("search"); ++ err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata); ++ ++ ipkg_cb_list = NULL; ++ ipkg_conf_deinit(&ipkg_conf); ++ return(err); ++} ++ ++ ++int ++ipkg_file_what(args_t *args, const char *file, const char* command) ++{ ++ ipkg_cmd_t *cmd; ++ ipkg_conf_t ipkg_conf; ++ int err; ++ ++ /* this error should be handled in application */ ++ if (!file || !strlen (file)) ++ return (-1); ++ ++ err = ipkg_conf_init (&ipkg_conf, args); ++ if (err) ++ { ++ return err; ++ } ++ ++ /* we need to do this because of static declarations, ++ * maybe a good idea to change */ ++ cmd = ipkg_cmd_find (command); ++ err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL); ++ ++ ipkg_conf_deinit(&ipkg_conf); ++ return(err); ++} ++ ++#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends") ++#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends") ++#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides") ++#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts") ++#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces") ++ ++ ++int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level, ++ char *msg) ++{ ++ if (conf && (conf->verbosity < level)) { ++ return 0; ++ } else { ++#ifdef IPKG_LIB ++ if ( level == IPKG_ERROR ){ ++ push_error_list(&error_list, msg); ++// printf(msg); ++ } else ++#endif ++ printf(msg); ++ } ++ return 0; ++} ++ ++int default_ipkg_list_callback(char *name, char *desc, char *version, ++ pkg_state_status_t status, void *userdata) ++{ ++ if (desc) ++ printf("%s - %s - %s\n", name, version, desc); ++ else ++ printf("%s - %s\n", name, version); ++ return 0; ++} ++ ++int default_ipkg_files_callback(char *name, char *desc, char *version, ++ pkg_state_status_t status, void *userdata) ++{ ++ if (desc) ++ printf("%s\n", desc); ++ return 0; ++} ++ ++int default_ipkg_status_callback(char *name, int istatus, char *desc, ++ void *userdata) ++{ ++ printf("%s\n", desc); ++ return 0; ++} ++ ++char* default_ipkg_response_callback(char *question) ++{ ++ char *response = NULL; ++ printf(question); ++ fflush(stdout); ++ do { ++ response = (char *)file_read_line_alloc(stdin); ++ } while (response == NULL); ++ return response; ++} ++ ++/* This is used for backward compatibility */ ++int ++ipkg_op (int argc, char *argv[]) ++{ ++ int err, opt_index; ++ args_t args; ++ char *cmd_name; ++ ipkg_cmd_t *cmd; ++ ipkg_conf_t ipkg_conf; ++ ++ args_init (&args); ++ ++ opt_index = args_parse (&args, argc, argv); ++ if (opt_index == argc || opt_index < 0) ++ { ++ args_usage ("ipkg must have one sub-command argument"); ++ } ++ ++ cmd_name = argv[opt_index++]; ++/* Pigi: added a flag to disable the checking of structures if the command does not need to ++ read anything from there. ++*/ ++ if ( !strcmp(cmd_name,"print-architecture") || ++ !strcmp(cmd_name,"print_architecture") || ++ !strcmp(cmd_name,"print-installation-architecture") || ++ !strcmp(cmd_name,"print_installation_architecture") ) ++ args.nocheckfordirorfile = 1; ++ ++/* Pigi: added a flag to disable the reading of feed files if the command does not need to ++ read anything from there. ++*/ ++ if ( !strcmp(cmd_name,"flag") || ++ !strcmp(cmd_name,"configure") || ++ !strcmp(cmd_name,"remove") || ++ !strcmp(cmd_name,"files") || ++ !strcmp(cmd_name,"search") || ++ !strcmp(cmd_name,"compare_versions") || ++ !strcmp(cmd_name,"compare-versions") || ++ !strcmp(cmd_name,"list_installed") || ++ !strcmp(cmd_name,"list-installed") || ++ !strcmp(cmd_name,"status") ) ++ args.noreadfeedsfile = 1; ++ ++ ++ err = ipkg_conf_init (&ipkg_conf, &args); ++ if (err) ++ { ++ return err; ++ } ++ ++ args_deinit (&args); ++ ++ ipkg_cb_message = default_ipkg_message_callback; ++ ipkg_cb_response = default_ipkg_response_callback; ++ ipkg_cb_status = default_ipkg_status_callback; ++ if ( strcmp(cmd_name, "files")==0) ++ ipkg_cb_list = default_ipkg_files_callback; ++ else ++ ipkg_cb_list = default_ipkg_list_callback; ++ ++ cmd = ipkg_cmd_find (cmd_name); ++ if (cmd == NULL) ++ { ++ fprintf (stderr, "%s: unknown sub-command %s\n", argv[0], ++ cmd_name); ++ args_usage (NULL); ++ } ++ ++ if (cmd->requires_args && opt_index == argc) ++ { ++ fprintf (stderr, ++ "%s: the ``%s'' command requires at least one argument\n", ++ __FUNCTION__, cmd_name); ++ args_usage (NULL); ++ } ++ ++ err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - opt_index, (const char **) (argv + opt_index), NULL); ++ ++ ipkg_conf_deinit (&ipkg_conf); ++ ++ return err; ++} ++ ++#endif /* IPKG_LIB */ +Index: busybox-1.7.2/archival/libipkg/libipkg.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/libipkg.h 2007-10-04 17:20:55.967446056 +0200 +@@ -0,0 +1,88 @@ ++/* ipkglib.h - the itsy package management system ++ ++ Florian Boor ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef IPKGLIB_H ++#define IPKGLIB_H ++ ++#ifdef IPKG_LIB ++ ++#include "ipkg_conf.h" ++#include "ipkg_message.h" ++ ++#include "libbb.h" ++#include "args.h" ++#include "pkg.h" ++ ++typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level, ++ char *msg); ++typedef int (*ipkg_list_callback)(char *name, char *desc, char *version, ++ pkg_state_status_t status, void *userdata); ++typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc, ++ void *userdata); ++typedef char* (*ipkg_response_callback)(char *question); ++ ++extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */ ++extern int ipkg_init (ipkg_message_callback mcall, ++ ipkg_response_callback rcall, ++ args_t * args); ++ ++extern int ipkg_deinit (args_t *args); ++extern int ipkg_packages_list(args_t *args, ++ const char *packages, ++ ipkg_list_callback cblist, ++ void *userdata); ++extern int ipkg_packages_status(args_t *args, ++ const char *packages, ++ ipkg_status_callback cbstatus, ++ void *userdata); ++extern int ipkg_packages_info(args_t *args, ++ const char *packages, ++ ipkg_status_callback cbstatus, ++ void *userdata); ++extern int ipkg_packages_install(args_t *args, const char *name); ++extern int ipkg_packages_remove(args_t *args, const char *name, int purge); ++extern int ipkg_lists_update(args_t *args); ++extern int ipkg_packages_upgrade(args_t *args); ++extern int ipkg_packages_download(args_t *args, const char *name); ++extern int ipkg_package_files(args_t *args, ++ const char *name, ++ ipkg_list_callback cblist, ++ void *userdata); ++extern int ipkg_file_search(args_t *args, ++ const char *file, ++ ipkg_list_callback cblist, ++ void *userdata); ++extern int ipkg_package_whatdepends(args_t *args, const char *file); ++extern int ipkg_package_whatrecommends(args_t *args, const char *file); ++extern int ipkg_package_whatprovides(args_t *args, const char *file); ++extern int ipkg_package_whatconflicts(args_t *args, const char *file); ++extern int ipkg_package_whatreplaces(args_t *args, const char *file); ++ ++extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */ ++extern ipkg_response_callback ipkg_cb_response; ++extern ipkg_status_callback ipkg_cb_status; ++extern ipkg_list_callback ipkg_cb_list; ++extern void push_error_list(struct errlist **errors,char * msg); ++extern void reverse_error_list(struct errlist **errors); ++extern void free_error_list(struct errlist **errors); ++ ++#else ++ ++extern int ipkg_op(int argc, char *argv[]); ++ ++#endif ++ ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/nv_pair.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/nv_pair.c 2007-10-04 17:14:22.989051492 +0200 +@@ -0,0 +1,40 @@ ++/* nv_pair.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++ ++#include "nv_pair.h" ++#include "str_util.h" ++ ++int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value) ++{ ++ nv_pair->name = str_dup_safe(name); ++ nv_pair->value = str_dup_safe(value); ++ ++ return 0; ++} ++ ++void nv_pair_deinit(nv_pair_t *nv_pair) ++{ ++ free(nv_pair->name); ++ nv_pair->name = NULL; ++ ++ free(nv_pair->value); ++ nv_pair->value = NULL; ++} ++ ++ +Index: busybox-1.7.2/archival/libipkg/nv_pair.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/nv_pair.h 2007-10-04 17:14:23.037054223 +0200 +@@ -0,0 +1,32 @@ ++/* nv_pair.h - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef NV_PAIR_H ++#define NV_PAIR_H ++ ++typedef struct nv_pair nv_pair_t; ++struct nv_pair ++{ ++ char *name; ++ char *value; ++}; ++ ++int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value); ++void nv_pair_deinit(nv_pair_t *nv_pair); ++ ++#endif ++ +Index: busybox-1.7.2/archival/libipkg/nv_pair_list.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/nv_pair_list.c 2007-10-04 17:14:23.053055147 +0200 +@@ -0,0 +1,98 @@ ++/* nv_pair_list.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++ ++#include "nv_pair.h" ++#include "void_list.h" ++#include "nv_pair_list.h" ++ ++int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data) ++{ ++ return void_list_elt_init((void_list_elt_t *) elt, data); ++} ++ ++void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt) ++{ ++ void_list_elt_deinit((void_list_elt_t *) elt); ++} ++ ++int nv_pair_list_init(nv_pair_list_t *list) ++{ ++ return void_list_init((void_list_t *) list); ++} ++ ++void nv_pair_list_deinit(nv_pair_list_t *list) ++{ ++ nv_pair_list_elt_t *iter; ++ nv_pair_t *nv_pair; ++ ++ for (iter = list->head; iter; iter = iter->next) { ++ nv_pair = iter->data; ++ nv_pair_deinit(nv_pair); ++ ++ /* malloced in nv_pair_list_append */ ++ free(nv_pair); ++ iter->data = NULL; ++ } ++ void_list_deinit((void_list_t *) list); ++} ++ ++nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value) ++{ ++ int err; ++ ++ /* freed in nv_pair_list_deinit */ ++ nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t)); ++ ++ if (nv_pair == NULL) { ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ nv_pair_init(nv_pair, name, value); ++ ++ err = void_list_append((void_list_t *) list, nv_pair); ++ if (err) { ++ return NULL; ++ } ++ ++ return nv_pair; ++} ++ ++int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data) ++{ ++ return void_list_push((void_list_t *) list, data); ++} ++ ++nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list) ++{ ++ return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list); ++} ++ ++char *nv_pair_list_find(nv_pair_list_t *list, char *name) ++{ ++ nv_pair_list_elt_t *iter; ++ nv_pair_t *nv_pair; ++ ++ for (iter = list->head; iter; iter = iter->next) { ++ nv_pair = iter->data; ++ if (strcmp(nv_pair->name, name) == 0) { ++ return nv_pair->value; ++ } ++ } ++ return NULL; ++} +Index: busybox-1.7.2/archival/libipkg/nv_pair_list.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/nv_pair_list.h 2007-10-04 17:14:23.073056281 +0200 +@@ -0,0 +1,60 @@ ++/* nv_pair_list.h - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef NV_PAIR_LIST_H ++#define NV_PAIR_LIST_H ++ ++#include "nv_pair.h" ++#include "void_list.h" ++ ++typedef struct nv_pair_list_elt nv_pair_list_elt_t; ++struct nv_pair_list_elt ++{ ++ nv_pair_list_elt_t *next; ++ nv_pair_t *data; ++}; ++ ++typedef struct nv_pair_list nv_pair_list_t; ++struct nv_pair_list ++{ ++ nv_pair_list_elt_t pre_head; ++ nv_pair_list_elt_t *head; ++ nv_pair_list_elt_t *tail; ++}; ++ ++static inline int nv_pair_list_empty(nv_pair_list_t *list) ++{ ++ if (list->head == NULL) ++ return 1; ++ else ++ return 0; ++} ++ ++int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data); ++void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt); ++ ++int nv_pair_list_init(nv_pair_list_t *list); ++void nv_pair_list_deinit(nv_pair_list_t *list); ++ ++nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, ++ const char *name, const char *value); ++int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data); ++nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list); ++char *nv_pair_list_find(nv_pair_list_t *list, char *name); ++ ++#endif ++ +Index: busybox-1.7.2/archival/libipkg/pkg.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg.c 2007-10-04 17:14:23.093057411 +0200 +@@ -0,0 +1,1747 @@ ++/* pkg.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++#include ++#include ++#include ++ ++#include "pkg.h" ++ ++#include "pkg_parse.h" ++#include "pkg_extract.h" ++#include "ipkg_message.h" ++#include "ipkg_utils.h" ++ ++#include "sprintf_alloc.h" ++#include "file_util.h" ++#include "str_util.h" ++#include "xsystem.h" ++#include "ipkg_conf.h" ++ ++typedef struct enum_map enum_map_t; ++struct enum_map ++{ ++ int value; ++ char *str; ++}; ++ ++static const enum_map_t pkg_state_want_map[] = { ++ { SW_UNKNOWN, "unknown"}, ++ { SW_INSTALL, "install"}, ++ { SW_DEINSTALL, "deinstall"}, ++ { SW_PURGE, "purge"} ++}; ++ ++static const enum_map_t pkg_state_flag_map[] = { ++ { SF_OK, "ok"}, ++ { SF_REINSTREQ, "reinstreq"}, ++ { SF_HOLD, "hold"}, ++ { SF_REPLACE, "replace"}, ++ { SF_NOPRUNE, "noprune"}, ++ { SF_PREFER, "prefer"}, ++ { SF_OBSOLETE, "obsolete"}, ++ { SF_USER, "user"}, ++}; ++ ++static const enum_map_t pkg_state_status_map[] = { ++ { SS_NOT_INSTALLED, "not-installed" }, ++ { SS_UNPACKED, "unpacked" }, ++ { SS_HALF_CONFIGURED, "half-configured" }, ++ { SS_INSTALLED, "installed" }, ++ { SS_HALF_INSTALLED, "half-installed" }, ++ { SS_CONFIG_FILES, "config-files" }, ++ { SS_POST_INST_FAILED, "post-inst-failed" }, ++ { SS_REMOVAL_FAILED, "removal-failed" } ++}; ++ ++static int verrevcmp(const char *val, const char *ref); ++ ++ ++pkg_t *pkg_new(void) ++{ ++ pkg_t *pkg; ++ ++ pkg = malloc(sizeof(pkg_t)); ++ if (pkg == NULL) { ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ ++ pkg_init(pkg); ++ ++ return pkg; ++} ++ ++int pkg_init(pkg_t *pkg) ++{ ++ memset(pkg, 0, sizeof(pkg_t)); ++ pkg->name = NULL; ++ pkg->epoch = 0; ++ pkg->version = NULL; ++ pkg->revision = NULL; ++ pkg->familiar_revision = NULL; ++ pkg->dest = NULL; ++ pkg->src = NULL; ++ pkg->architecture = NULL; ++ pkg->maintainer = NULL; ++ pkg->section = NULL; ++ pkg->description = NULL; ++ pkg->state_want = SW_UNKNOWN; ++ pkg->state_flag = SF_OK; ++ pkg->state_status = SS_NOT_INSTALLED; ++ pkg->depends_str = NULL; ++ pkg->provides_str = NULL; ++ pkg->depends_count = 0; ++ pkg->depends = NULL; ++ pkg->suggests_str = NULL; ++ pkg->recommends_str = NULL; ++ pkg->suggests_count = 0; ++ pkg->recommends_count = 0; ++ ++ /* Abhaya: added init for conflicts fields */ ++ pkg->conflicts = NULL; ++ pkg->conflicts_count = 0; ++ ++ /* added for replaces. Jamey 7/23/2002 */ ++ pkg->replaces = NULL; ++ pkg->replaces_count = 0; ++ ++ pkg->pre_depends_count = 0; ++ pkg->pre_depends_str = NULL; ++ pkg->provides_count = 0; ++ pkg->provides = NULL; ++ pkg->filename = NULL; ++ pkg->local_filename = NULL; ++ pkg->tmp_unpack_dir = NULL; ++ pkg->md5sum = NULL; ++ pkg->size = NULL; ++ pkg->installed_size = NULL; ++ pkg->priority = NULL; ++ pkg->source = NULL; ++ conffile_list_init(&pkg->conffiles); ++ pkg->installed_files = NULL; ++ pkg->installed_files_ref_cnt = 0; ++ pkg->essential = 0; ++ pkg->provided_by_hand = 0; ++ ++ return 0; ++} ++ ++void pkg_deinit(pkg_t *pkg) ++{ ++ free(pkg->name); ++ pkg->name = NULL; ++ pkg->epoch = 0; ++ free(pkg->version); ++ pkg->version = NULL; ++ /* revision and familiar_revision share storage with version, so ++ don't free */ ++ pkg->revision = NULL; ++ pkg->familiar_revision = NULL; ++ /* owned by ipkg_conf_t */ ++ pkg->dest = NULL; ++ /* owned by ipkg_conf_t */ ++ pkg->src = NULL; ++ free(pkg->architecture); ++ pkg->architecture = NULL; ++ free(pkg->maintainer); ++ pkg->maintainer = NULL; ++ free(pkg->section); ++ pkg->section = NULL; ++ free(pkg->description); ++ pkg->description = NULL; ++ pkg->state_want = SW_UNKNOWN; ++ pkg->state_flag = SF_OK; ++ pkg->state_status = SS_NOT_INSTALLED; ++ free(pkg->depends_str); ++ pkg->depends_str = NULL; ++ free(pkg->provides_str); ++ pkg->provides_str = NULL; ++ pkg->depends_count = 0; ++ /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */ ++ pkg->pre_depends_count = 0; ++ free(pkg->pre_depends_str); ++ pkg->pre_depends_str = NULL; ++ pkg->provides_count = 0; ++ /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */ ++ /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */ ++ free(pkg->filename); ++ pkg->filename = NULL; ++ free(pkg->local_filename); ++ pkg->local_filename = NULL; ++ /* CLEANUP: It'd be nice to pullin the cleanup function from ++ ipkg_install.c here. See comment in ++ ipkg_install.c:cleanup_temporary_files */ ++ free(pkg->tmp_unpack_dir); ++ pkg->tmp_unpack_dir = NULL; ++ free(pkg->md5sum); ++ pkg->md5sum = NULL; ++ free(pkg->size); ++ pkg->size = NULL; ++ free(pkg->installed_size); ++ pkg->installed_size = NULL; ++ free(pkg->priority); ++ pkg->priority = NULL; ++ free(pkg->source); ++ pkg->source = NULL; ++ conffile_list_deinit(&pkg->conffiles); ++ /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so, ++ since if they are calling deinit, they should know. Maybe do an ++ assertion here instead? */ ++ pkg->installed_files_ref_cnt = 1; ++ pkg_free_installed_files(pkg); ++ pkg->essential = 0; ++} ++ ++int pkg_init_from_file(pkg_t *pkg, const char *filename) ++{ ++ int err; ++ char **raw; ++ FILE *control_file; ++ ++ err = pkg_init(pkg); ++ if (err) { return err; } ++ ++ pkg->local_filename = strdup(filename); ++ ++ control_file = tmpfile(); ++ err = pkg_extract_control_file_to_stream(pkg, control_file); ++ if (err) { return err; } ++ ++ rewind(control_file); ++ raw = read_raw_pkgs_from_stream(control_file); ++ pkg_parse_raw(pkg, &raw, NULL, NULL); ++ ++ fclose(control_file); ++ ++ return 0; ++} ++ ++/* Merge any new information in newpkg into oldpkg */ ++/* XXX: CLEANUP: This function shouldn't actually modify anything in ++ newpkg, but should leave it usable. This rework is so that ++ pkg_hash_insert doesn't clobber the pkg that you pass into it. */ ++/* ++ * uh, i thought that i had originally written this so that it took ++ * two pkgs and returned a new one? we can do that again... -sma ++ */ ++int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status) ++{ ++ if (oldpkg == newpkg) { ++ return 0; ++ } ++ ++ if (!oldpkg->src) ++ oldpkg->src = newpkg->src; ++ if (!oldpkg->dest) ++ oldpkg->dest = newpkg->dest; ++ if (!oldpkg->architecture) ++ oldpkg->architecture = str_dup_safe(newpkg->architecture); ++ if (!oldpkg->arch_priority) ++ oldpkg->arch_priority = newpkg->arch_priority; ++ if (!oldpkg->section) ++ oldpkg->section = str_dup_safe(newpkg->section); ++ if(!oldpkg->maintainer) ++ oldpkg->maintainer = str_dup_safe(newpkg->maintainer); ++ if(!oldpkg->description) ++ oldpkg->description = str_dup_safe(newpkg->description); ++ if (set_status) { ++ /* merge the state_flags from the new package */ ++ oldpkg->state_want = newpkg->state_want; ++ oldpkg->state_status = newpkg->state_status; ++ oldpkg->state_flag = newpkg->state_flag; ++ } else { ++ if (oldpkg->state_want == SW_UNKNOWN) ++ oldpkg->state_want = newpkg->state_want; ++ if (oldpkg->state_status == SS_NOT_INSTALLED) ++ oldpkg->state_status = newpkg->state_status; ++ oldpkg->state_flag |= newpkg->state_flag; ++ } ++ ++ if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) { ++ oldpkg->depends_str = newpkg->depends_str; ++ newpkg->depends_str = NULL; ++ oldpkg->depends_count = newpkg->depends_count; ++ newpkg->depends_count = 0; ++ ++ oldpkg->depends = newpkg->depends; ++ newpkg->depends = NULL; ++ ++ oldpkg->pre_depends_str = newpkg->pre_depends_str; ++ newpkg->pre_depends_str = NULL; ++ oldpkg->pre_depends_count = newpkg->pre_depends_count; ++ newpkg->pre_depends_count = 0; ++ ++ oldpkg->recommends_str = newpkg->recommends_str; ++ newpkg->recommends_str = NULL; ++ oldpkg->recommends_count = newpkg->recommends_count; ++ newpkg->recommends_count = 0; ++ ++ oldpkg->suggests_str = newpkg->suggests_str; ++ newpkg->suggests_str = NULL; ++ oldpkg->suggests_count = newpkg->suggests_count; ++ newpkg->suggests_count = 0; ++ } ++ ++ if (!oldpkg->provides_str) { ++ oldpkg->provides_str = newpkg->provides_str; ++ newpkg->provides_str = NULL; ++ oldpkg->provides_count = newpkg->provides_count; ++ newpkg->provides_count = 0; ++ ++ oldpkg->provides = newpkg->provides; ++ newpkg->provides = NULL; ++ } ++ ++ if (!oldpkg->conflicts_str) { ++ oldpkg->conflicts_str = newpkg->conflicts_str; ++ newpkg->conflicts_str = NULL; ++ oldpkg->conflicts_count = newpkg->conflicts_count; ++ newpkg->conflicts_count = 0; ++ ++ oldpkg->conflicts = newpkg->conflicts; ++ newpkg->conflicts = NULL; ++ } ++ ++ if (!oldpkg->replaces_str) { ++ oldpkg->replaces_str = newpkg->replaces_str; ++ newpkg->replaces_str = NULL; ++ oldpkg->replaces_count = newpkg->replaces_count; ++ newpkg->replaces_count = 0; ++ ++ oldpkg->replaces = newpkg->replaces; ++ newpkg->replaces = NULL; ++ } ++ ++ if (!oldpkg->filename) ++ oldpkg->filename = str_dup_safe(newpkg->filename); ++ if (0) ++ fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n", ++ oldpkg->name, oldpkg->local_filename, newpkg->local_filename); ++ if (!oldpkg->local_filename) ++ oldpkg->local_filename = str_dup_safe(newpkg->local_filename); ++ if (!oldpkg->tmp_unpack_dir) ++ oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir); ++ if (!oldpkg->md5sum) ++ oldpkg->md5sum = str_dup_safe(newpkg->md5sum); ++ if (!oldpkg->size) ++ oldpkg->size = str_dup_safe(newpkg->size); ++ if (!oldpkg->installed_size) ++ oldpkg->installed_size = str_dup_safe(newpkg->installed_size); ++ if (!oldpkg->priority) ++ oldpkg->priority = str_dup_safe(newpkg->priority); ++ if (!oldpkg->source) ++ oldpkg->source = str_dup_safe(newpkg->source); ++ if (oldpkg->conffiles.head == NULL){ ++ oldpkg->conffiles = newpkg->conffiles; ++ conffile_list_init(&newpkg->conffiles); ++ } ++ if (!oldpkg->installed_files){ ++ oldpkg->installed_files = newpkg->installed_files; ++ oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt; ++ newpkg->installed_files = NULL; ++ } ++ if (!oldpkg->essential) ++ oldpkg->essential = newpkg->essential; ++ ++ oldpkg->provided_by_hand |= newpkg->provided_by_hand; ++ ++ return 0; ++} ++ ++abstract_pkg_t *abstract_pkg_new(void) ++{ ++ abstract_pkg_t * ab_pkg; ++ ++ ab_pkg = malloc(sizeof(abstract_pkg_t)); ++ ++ if (ab_pkg == NULL) { ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ ++ if ( abstract_pkg_init(ab_pkg) < 0 ) ++ return NULL; ++ ++ return ab_pkg; ++} ++ ++int abstract_pkg_init(abstract_pkg_t *ab_pkg) ++{ ++ memset(ab_pkg, 0, sizeof(abstract_pkg_t)); ++ ++ ab_pkg->provided_by = abstract_pkg_vec_alloc(); ++ if (ab_pkg->provided_by==NULL){ ++ return -1; ++ } ++ ab_pkg->dependencies_checked = 0; ++ ab_pkg->state_status = SS_NOT_INSTALLED; ++ ++ return 0; ++} ++ ++void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){ ++ char * temp_str; ++ char **raw =NULL; ++ char **raw_start=NULL; ++ ++ temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12); ++ if (temp_str == NULL ){ ++ ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__); ++ return; ++ } ++ sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name); ++ ++ raw = raw_start = read_raw_pkgs_from_file(temp_str); ++ if (raw == NULL ){ ++ ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__); ++ return; ++ } ++ ++ while(*raw){ ++ if (!pkg_valorize_other_field(pkg, &raw ) == 0) { ++ ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name); ++ } ++ } ++ raw = raw_start; ++ while (*raw) { ++ if (raw!=NULL) ++ free(*raw++); ++ } ++ ++ free(raw_start); ++ free(temp_str); ++ ++ return ; ++ ++} ++ ++char * pkg_formatted_info(pkg_t *pkg ) ++{ ++ char *line; ++ char * buff; ++ ++ buff = malloc(8192); ++ if (buff == NULL) { ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ ++ buff[0] = '\0'; ++ ++ line = pkg_formatted_field(pkg, "Package"); ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ line = pkg_formatted_field(pkg, "Version"); ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ line = pkg_formatted_field(pkg, "Depends"); ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ line = pkg_formatted_field(pkg, "Recommends"); ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ line = pkg_formatted_field(pkg, "Suggests"); ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ line = pkg_formatted_field(pkg, "Provides"); ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ line = pkg_formatted_field(pkg, "Replaces"); ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ line = pkg_formatted_field(pkg, "Conflicts"); ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ line = pkg_formatted_field(pkg, "Status"); ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ line = pkg_formatted_field(pkg, "Section"); ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/ ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ line = pkg_formatted_field(pkg, "Architecture"); ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ line = pkg_formatted_field(pkg, "Maintainer"); ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ line = pkg_formatted_field(pkg, "MD5sum"); ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ line = pkg_formatted_field(pkg, "Size"); ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ line = pkg_formatted_field(pkg, "Filename"); ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ line = pkg_formatted_field(pkg, "Conffiles"); ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ line = pkg_formatted_field(pkg, "Source"); ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ line = pkg_formatted_field(pkg, "Description"); ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ line = pkg_formatted_field(pkg, "Installed-Time"); ++ strncat(buff ,line, strlen(line)); ++ free(line); ++ ++ return buff; ++} ++ ++char * pkg_formatted_field(pkg_t *pkg, const char *field ) ++{ ++ static size_t LINE_LEN = 128; ++ char line_str[LINE_LEN]; ++ char * temp = (char *)malloc(1); ++ int len = 0; ++ int flag_provide_false = 0; ++ ++/* ++ Pigi: After some discussion with Florian we decided to modify the full procedure in ++ dynamic memory allocation. This should avoid any other segv in this area ( except for bugs ) ++*/ ++ ++ if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) { ++ goto UNKNOWN_FMT_FIELD; ++ } ++ ++ temp[0]='\0'; ++ ++ switch (field[0]) ++ { ++ case 'a': ++ case 'A': ++ if (strcasecmp(field, "Architecture") == 0) { ++ /* Architecture */ ++ if (pkg->architecture) { ++ temp = (char *)realloc(temp,strlen(pkg->architecture)+17); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture); ++ } ++ } else { ++ goto UNKNOWN_FMT_FIELD; ++ } ++ break; ++ case 'c': ++ case 'C': ++ if (strcasecmp(field, "Conffiles") == 0) { ++ /* Conffiles */ ++ conffile_list_elt_t *iter; ++ ++ if (pkg->conffiles.head == NULL) { ++ return temp; ++ } ++ ++ len = 14 ; ++ for (iter = pkg->conffiles.head; iter; iter = iter->next) { ++ if (iter->data->name && iter->data->value) { ++ len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5); ++ } ++ } ++ temp = (char *)realloc(temp,len); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ strncpy(temp, "Conffiles:\n", 12); ++ for (iter = pkg->conffiles.head; iter; iter = iter->next) { ++ if (iter->data->name && iter->data->value) { ++ snprintf(line_str, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value); ++ strncat(temp, line_str, strlen(line_str)); ++ } ++ } ++ } else if (strcasecmp(field, "Conflicts") == 0) { ++ int i; ++ ++ if (pkg->conflicts_count) { ++ len = 14 ; ++ for(i = 0; i < pkg->conflicts_count; i++) { ++ len = len + (strlen(pkg->conflicts_str[i])+5); ++ } ++ temp = (char *)realloc(temp,len); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ strncpy(temp, "Conflicts:", 11); ++ for(i = 0; i < pkg->conflicts_count; i++) { ++ snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]); ++ strncat(temp, line_str, strlen(line_str)); ++ } ++ strncat(temp, "\n", strlen("\n")); ++ } ++ } else { ++ goto UNKNOWN_FMT_FIELD; ++ } ++ break; ++ case 'd': ++ case 'D': ++ if (strcasecmp(field, "Depends") == 0) { ++ /* Depends */ ++ int i; ++ ++ if (pkg->depends_count) { ++ len = 14 ; ++ for(i = 0; i < pkg->depends_count; i++) { ++ len = len + (strlen(pkg->depends_str[i])+4); ++ } ++ temp = (char *)realloc(temp,len); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ strncpy(temp, "Depends:", 10); ++ for(i = 0; i < pkg->depends_count; i++) { ++ snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]); ++ strncat(temp, line_str, strlen(line_str)); ++ } ++ strncat(temp, "\n", strlen("\n")); ++ } ++ } else if (strcasecmp(field, "Description") == 0) { ++ /* Description */ ++ if (pkg->description) { ++ temp = (char *)realloc(temp,strlen(pkg->description)+16); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description); ++ } ++ } else { ++ goto UNKNOWN_FMT_FIELD; ++ } ++ break; ++ case 'e': ++ case 'E': { ++ /* Essential */ ++ if (pkg->essential) { ++ temp = (char *)realloc(temp,16); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ snprintf(temp, (16), "Essential: yes\n"); ++ } ++ } ++ break; ++ case 'f': ++ case 'F': { ++ /* Filename */ ++ if (pkg->filename) { ++ temp = (char *)realloc(temp,strlen(pkg->filename)+12); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename); ++ } ++ } ++ break; ++ case 'i': ++ case 'I': { ++ if (strcasecmp(field, "Installed-Size") == 0) { ++ /* Installed-Size */ ++ temp = (char *)realloc(temp,strlen(pkg->installed_size)+17); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size); ++ } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) { ++ temp = (char *)realloc(temp,29); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time); ++ } ++ } ++ break; ++ case 'm': ++ case 'M': { ++ /* Maintainer | MD5sum */ ++ if (strcasecmp(field, "Maintainer") == 0) { ++ /* Maintainer */ ++ if (pkg->maintainer) { ++ temp = (char *)realloc(temp,strlen(pkg->maintainer)+14); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer); ++ } ++ } else if (strcasecmp(field, "MD5sum") == 0) { ++ /* MD5sum */ ++ if (pkg->md5sum) { ++ temp = (char *)realloc(temp,strlen(pkg->md5sum)+11); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum); ++ } ++ } else { ++ goto UNKNOWN_FMT_FIELD; ++ } ++ } ++ break; ++ case 'p': ++ case 'P': { ++ if (strcasecmp(field, "Package") == 0) { ++ /* Package */ ++ temp = (char *)realloc(temp,strlen(pkg->name)+11); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name); ++ } else if (strcasecmp(field, "Priority") == 0) { ++ /* Priority */ ++ temp = (char *)realloc(temp,strlen(pkg->priority)+12); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority); ++ } else if (strcasecmp(field, "Provides") == 0) { ++ /* Provides */ ++ int i; ++ ++ if (pkg->provides_count) { ++ /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/ ++ for ( i=0; i < pkg->provides_count; i++ ){ ++ if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) { ++ memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */ ++ flag_provide_false = 1; ++ } ++ } ++ if ( !flag_provide_false || /* Pigi there is not my trick flag */ ++ ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */ ++ char provstr[LINE_LEN]; ++ len = 15; ++ for(i = 0; i < pkg->provides_count; i++) { ++ len = len + (strlen(pkg->provides_str[i])+5); ++ } ++ temp = (char *)realloc(temp,len); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ strncpy(temp, "Provides:", 12); ++ for(i = 0; i < pkg->provides_count; i++) { ++ if (strlen(pkg->provides_str[i])>0){; ++ snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]); ++ strncat(temp, provstr, strlen(provstr)); ++ } ++ } ++ strncat(temp, "\n", strlen("\n")); ++ } ++ } ++ } else { ++ goto UNKNOWN_FMT_FIELD; ++ } ++ } ++ break; ++ case 'r': ++ case 'R': { ++ int i; ++ /* Replaces | Recommends*/ ++ if (strcasecmp (field, "Replaces") == 0) { ++ if (pkg->replaces_count) { ++ len = 14; ++ for (i = 0; i < pkg->replaces_count; i++) { ++ len = len + (strlen(pkg->replaces_str[i])+5); ++ } ++ temp = (char *)realloc(temp,len); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ strncpy(temp, "Replaces:", 12); ++ for (i = 0; i < pkg->replaces_count; i++) { ++ snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]); ++ strncat(temp, line_str, strlen(line_str)); ++ } ++ strncat(temp, "\n", strlen("\n")); ++ } ++ } else if (strcasecmp (field, "Recommends") == 0) { ++ if (pkg->recommends_count) { ++ len = 15; ++ for(i = 0; i < pkg->recommends_count; i++) { ++ len = len + (strlen( pkg->recommends_str[i])+5); ++ } ++ temp = (char *)realloc(temp,len); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ strncpy(temp, "Recommends:", 13); ++ for(i = 0; i < pkg->recommends_count; i++) { ++ snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]); ++ strncat(temp, line_str, strlen(line_str)); ++ } ++ strncat(temp, "\n", strlen("\n")); ++ } ++ } else { ++ goto UNKNOWN_FMT_FIELD; ++ } ++ } ++ break; ++ case 's': ++ case 'S': { ++ /* Section | Size | Source | Status | Suggests */ ++ if (strcasecmp(field, "Section") == 0) { ++ /* Section */ ++ if (pkg->section) { ++ temp = (char *)realloc(temp,strlen(pkg->section)+11); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section); ++ } ++ } else if (strcasecmp(field, "Size") == 0) { ++ /* Size */ ++ if (pkg->size) { ++ temp = (char *)realloc(temp,strlen(pkg->size)+8); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size); ++ } ++ } else if (strcasecmp(field, "Source") == 0) { ++ /* Source */ ++ if (pkg->source) { ++ temp = (char *)realloc(temp,strlen(pkg->source)+10); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source); ++ } ++ } else if (strcasecmp(field, "Status") == 0) { ++ /* Status */ ++ /* Benjamin Pineau note: we should avoid direct usage of ++ * strlen(arg) without keeping "arg" for later free() ++ */ ++ char *pflag=pkg_state_flag_to_str(pkg->state_flag); ++ char *pstat=pkg_state_status_to_str(pkg->state_status); ++ char *pwant=pkg_state_want_to_str(pkg->state_want); ++ ++ size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 ); ++ temp = (char *)realloc(temp,sum_of_sizes); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat); ++ free(pflag); ++ free(pwant); ++ if(pstat) /* pfstat can be NULL if ENOMEM */ ++ free(pstat); ++ } else if (strcasecmp(field, "Suggests") == 0) { ++ if (pkg->suggests_count) { ++ int i; ++ len = 13; ++ for(i = 0; i < pkg->suggests_count; i++) { ++ len = len + (strlen(pkg->suggests_str[i])+5); ++ } ++ temp = (char *)realloc(temp,len); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ strncpy(temp, "Suggests:", 10); ++ for(i = 0; i < pkg->suggests_count; i++) { ++ snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]); ++ strncat(temp, line_str, strlen(line_str)); ++ } ++ strncat(temp, "\n", strlen("\n")); ++ } ++ } else { ++ goto UNKNOWN_FMT_FIELD; ++ } ++ } ++ break; ++ case 'v': ++ case 'V': { ++ /* Version */ ++ char *version = pkg_version_str_alloc(pkg); ++ temp = (char *)realloc(temp,strlen(version)+14); ++ if ( temp == NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ temp[0]='\0'; ++ snprintf(temp, (strlen(version)+12), "Version: %s\n", version); ++ free(version); ++ } ++ break; ++ default: ++ goto UNKNOWN_FMT_FIELD; ++ } ++ ++ if ( strlen(temp)<2 ) { ++ temp[0]='\0'; ++ } ++ return temp; ++ ++ UNKNOWN_FMT_FIELD: ++ fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field); ++ if ( strlen(temp)<2 ) { ++ temp[0]='\0'; ++ } ++ ++ return temp; ++} ++ ++void pkg_print_info(pkg_t *pkg, FILE *file) ++{ ++ char * buff; ++ if (pkg == NULL) { ++ return; ++ } ++ ++ buff = pkg_formatted_info(pkg); ++ if ( buff == NULL ) ++ return; ++ if (strlen(buff)>2){ ++ fwrite(buff, 1, strlen(buff), file); ++ } ++ free(buff); ++} ++ ++void pkg_print_status(pkg_t * pkg, FILE * file) ++{ ++ if (pkg == NULL) { ++ return; ++ } ++ ++ /* XXX: QUESTION: Do we actually want more fields here? The ++ original idea was to save space by installing only what was ++ needed for actual computation, (package, version, status, ++ essential, conffiles). The assumption is that all other fields ++ can be found in th available file. ++ ++ But, someone proposed the idea to make it possible to ++ reconstruct a .ipk from an installed package, (ie. for beaming ++ from one handheld to another). So, maybe we actually want a few ++ more fields here, (depends, suggests, etc.), so that that would ++ be guaranteed to work even in the absence of more information ++ from the available file. ++ ++ 28-MAR-03: kergoth and I discussed this yesterday. We think ++ the essential info needs to be here for all installed packages ++ because they may not appear in the Packages files on various ++ feeds. Furthermore, one should be able to install from URL or ++ local storage without requiring a Packages file from any feed. ++ -Jamey ++ */ ++ pkg_print_field(pkg, file, "Package"); ++ pkg_print_field(pkg, file, "Version"); ++ pkg_print_field(pkg, file, "Depends"); ++ pkg_print_field(pkg, file, "Recommends"); ++ pkg_print_field(pkg, file, "Suggests"); ++ pkg_print_field(pkg, file, "Provides"); ++ pkg_print_field(pkg, file, "Replaces"); ++ pkg_print_field(pkg, file, "Conflicts"); ++ pkg_print_field(pkg, file, "Status"); ++ pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */ ++ pkg_print_field(pkg, file, "Architecture"); ++ pkg_print_field(pkg, file, "Conffiles"); ++ pkg_print_field(pkg, file, "Installed-Time"); ++ fputs("\n", file); ++} ++ ++void pkg_print_field(pkg_t *pkg, FILE *file, const char *field) ++{ ++ char *buff; ++ if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) { ++ fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", ++ __FUNCTION__, field); ++ } ++ buff = pkg_formatted_field(pkg, field); ++ if (strlen(buff)>2) { ++ fprintf(file, "%s", buff); ++ fflush(file); ++ } ++ free(buff); ++ return; ++} ++ ++/* ++ * libdpkg - Debian packaging suite library routines ++ * vercmp.c - comparison of version numbers ++ * ++ * Copyright (C) 1995 Ian Jackson ++ */ ++int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg) ++{ ++ int r; ++ ++ if (pkg->epoch > ref_pkg->epoch) { ++ return 1; ++ } ++ ++ if (pkg->epoch < ref_pkg->epoch) { ++ return -1; ++ } ++ ++ r = verrevcmp(pkg->version, ref_pkg->version); ++ if (r) { ++ return r; ++ } ++ ++#ifdef USE_DEBVERSION ++ r = verrevcmp(pkg->revision, ref_pkg->revision); ++ if (r) { ++ return r; ++ } ++ ++ r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision); ++#endif ++ ++ return r; ++} ++ ++int verrevcmp(const char *val, const char *ref) ++{ ++ int vc, rc; ++ long vl, rl; ++ const char *vp, *rp; ++ const char *vsep, *rsep; ++ ++ if (!val) val= ""; ++ if (!ref) ref= ""; ++ for (;;) { ++ vp= val; while (*vp && !isdigit(*vp)) vp++; ++ rp= ref; while (*rp && !isdigit(*rp)) rp++; ++ for (;;) { ++ vc= (val == vp) ? 0 : *val++; ++ rc= (ref == rp) ? 0 : *ref++; ++ if (!rc && !vc) break; ++ if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */ ++ if (rc && !isalpha(rc)) rc += 256; ++ if (vc != rc) return vc - rc; ++ } ++ val= vp; ++ ref= rp; ++ vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10); ++ rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10); ++ if (vl != rl) return vl - rl; ++ ++ vc = *val; ++ rc = *ref; ++ vsep = strchr(".-", vc); ++ rsep = strchr(".-", rc); ++ if (vsep && !rsep) return -1; ++ if (!vsep && rsep) return +1; ++ ++ if (!*val && !*ref) return 0; ++ if (!*val) return -1; ++ if (!*ref) return +1; ++ } ++} ++ ++int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op) ++{ ++ int r; ++ ++ r = pkg_compare_versions(it, ref); ++ ++ if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) { ++ return r <= 0; ++ } ++ ++ if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) { ++ return r >= 0; ++ } ++ ++ if (strcmp(op, "<<") == 0) { ++ return r < 0; ++ } ++ ++ if (strcmp(op, ">>") == 0) { ++ return r > 0; ++ } ++ ++ if (strcmp(op, "=") == 0) { ++ return r == 0; ++ } ++ ++ fprintf(stderr, "unknown operator: %s", op); ++ return 0; ++} ++ ++int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b) ++{ ++ int namecmp; ++ int vercmp; ++ if (!a->name || !b->name) { ++ fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n", ++ a, a->name, b, b->name); ++ return 0; ++ } ++ ++ namecmp = strcmp(a->name, b->name); ++ if (namecmp) ++ return namecmp; ++ vercmp = pkg_compare_versions(a, b); ++ if (vercmp) ++ return vercmp; ++ if (!a->arch_priority || !b->arch_priority) { ++ fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n", ++ a, a->arch_priority, b, b->arch_priority); ++ return 0; ++ } ++ if (a->arch_priority > b->arch_priority) ++ return 1; ++ if (a->arch_priority < b->arch_priority) ++ return -1; ++ return 0; ++} ++ ++int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b) ++{ ++ if (!a->name || !b->name) { ++ fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n", ++ a, a->name, b, b->name); ++ return 0; ++ } ++ return strcmp(a->name, b->name); ++} ++ ++ ++char *pkg_version_str_alloc(pkg_t *pkg) ++{ ++ char *complete_version; ++ char *epoch_str; ++#ifdef USE_DEBVERSION ++ char *revision_str; ++ char *familiar_revision_str; ++#endif ++ ++ if (pkg->epoch) { ++ sprintf_alloc(&epoch_str, "%d:", (int)(pkg->epoch)); ++ } else { ++ epoch_str = strdup(""); ++ } ++ ++#ifdef USE_DEBVERSION ++ if (pkg->revision && strlen(pkg->revision)) { ++ sprintf_alloc(&revision_str, "-%s", pkg->revision); ++ } else { ++ revision_str = strdup(""); ++ } ++ ++ if (pkg->familiar_revision && strlen(pkg->familiar_revision)) { ++ sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision); ++ } else { ++ familiar_revision_str = strdup(""); ++ } ++#endif ++ ++#ifdef USE_DEBVERSION ++ sprintf_alloc(&complete_version, "%s%s%s%s", ++ epoch_str, pkg->version, revision_str, familiar_revision_str); ++#else ++ sprintf_alloc(&complete_version, "%s%s", ++ epoch_str, pkg->version); ++#endif ++ ++ free(epoch_str); ++#ifdef USE_DEBVERSION ++ free(revision_str); ++ free(familiar_revision_str); ++#endif ++ ++ return complete_version; ++} ++ ++str_list_t *pkg_get_installed_files(pkg_t *pkg) ++{ ++ int err; ++ char *list_file_name = NULL; ++ FILE *list_file = NULL; ++ char *line; ++ char *installed_file_name; ++ int rootdirlen; ++ ++ pkg->installed_files_ref_cnt++; ++ ++ if (pkg->installed_files) { ++ return pkg->installed_files; ++ } ++ ++ pkg->installed_files = str_list_alloc(); ++ if (pkg->installed_files == NULL) { ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ ++ /* For uninstalled packages, get the file list firectly from the package. ++ For installed packages, look at the package.list file in the database. ++ */ ++ if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) { ++ if (pkg->local_filename == NULL) { ++ return pkg->installed_files; ++ } ++ /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary ++ file. In other words, change deb_extract so that it can ++ simply return the file list as a char *[] rather than ++ insisting on writing in to a FILE * as it does now. */ ++ list_file = tmpfile(); ++ err = pkg_extract_data_file_names_to_stream(pkg, list_file); ++ if (err) { ++ fclose(list_file); ++ fprintf(stderr, "%s: Error extracting file list from %s: %s\n", ++ __FUNCTION__, pkg->local_filename, strerror(err)); ++ return pkg->installed_files; ++ } ++ rewind(list_file); ++ } else { ++ sprintf_alloc(&list_file_name, "%s/%s.list", ++ pkg->dest->info_dir, pkg->name); ++ if (! file_exists(list_file_name)) { ++ free(list_file_name); ++ return pkg->installed_files; ++ } ++ ++ list_file = fopen(list_file_name, "r"); ++ if (list_file == NULL) { ++ fprintf(stderr, "WARNING: Cannot open %s: %s\n", ++ list_file_name, strerror(errno)); ++ free(list_file_name); ++ return pkg->installed_files; ++ } ++ free(list_file_name); ++ } ++ ++ rootdirlen = strlen( pkg->dest->root_dir ); ++ while (1) { ++ char *file_name; ++ ++ line = file_read_line_alloc(list_file); ++ if (line == NULL) { ++ break; ++ } ++ str_chomp(line); ++ file_name = line; ++ ++ /* Take pains to avoid uglies like "/./" in the middle of file_name. */ ++ if( strncmp( pkg->dest->root_dir, ++ file_name, ++ rootdirlen ) ) { ++ if (*file_name == '.') { ++ file_name++; ++ } ++ if (*file_name == '/') { ++ file_name++; ++ } ++ ++ /* Freed in pkg_free_installed_files */ ++ sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name); ++ } else { ++ // already contains root_dir as header -> ABSOLUTE ++ sprintf_alloc(&installed_file_name, "%s", file_name); ++ } ++ str_list_append(pkg->installed_files, installed_file_name); ++ free(line); ++ } ++ ++ fclose(list_file); ++ ++ return pkg->installed_files; ++} ++ ++/* XXX: CLEANUP: This function and it's counterpart, ++ (pkg_get_installed_files), do not match our init/deinit naming ++ convention. Nor the alloc/free convention. But, then again, neither ++ of these conventions currrently fit the way these two functions ++ work. */ ++int pkg_free_installed_files(pkg_t *pkg) ++{ ++ str_list_elt_t *iter; ++ ++ pkg->installed_files_ref_cnt--; ++ if (pkg->installed_files_ref_cnt > 0) { ++ return 0; ++ } ++ ++ if (pkg->installed_files) { ++ ++ for (iter = pkg->installed_files->head; iter; iter = iter->next) { ++ /* malloced in pkg_get_installed_files */ ++ free (iter->data); ++ iter->data = NULL; ++ } ++ ++ str_list_deinit(pkg->installed_files); ++ } ++ ++ pkg->installed_files = NULL; ++ ++ return 0; ++} ++ ++int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg) ++{ ++ int err; ++ char *list_file_name; ++ ++ //I don't think pkg_free_installed_files should be called here. Jamey ++ //pkg_free_installed_files(pkg); ++ ++ sprintf_alloc(&list_file_name, "%s/%s.list", ++ pkg->dest->info_dir, pkg->name); ++ if (!conf->noaction) { ++ err = unlink(list_file_name); ++ free(list_file_name); ++ ++ if (err) { ++ return errno; ++ } ++ } ++ return 0; ++} ++ ++conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name) ++{ ++ conffile_list_elt_t *iter; ++ conffile_t *conffile; ++ ++ if (pkg == NULL) { ++ return NULL; ++ } ++ ++ for (iter = pkg->conffiles.head; iter; iter = iter->next) { ++ conffile = iter->data; ++ ++ if (strcmp(conffile->name, file_name) == 0) { ++ return conffile; ++ } ++ } ++ ++ return NULL; ++} ++ ++int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg, ++ const char *script, const char *args) ++{ ++ int err; ++ char *path; ++ char *cmd; ++ ++ /* XXX: FEATURE: When conf->offline_root is set, we should run the ++ maintainer script within a chroot environment. */ ++ ++ /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages ++ have scripts in pkg->tmp_unpack_dir. */ ++ if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) { ++ if (pkg->dest == NULL) { ++ fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n", ++ __FUNCTION__, pkg->name); ++ return EINVAL; ++ } ++ sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script); ++ } else { ++ if (pkg->tmp_unpack_dir == NULL) { ++ fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n", ++ __FUNCTION__, pkg->name); ++ return EINVAL; ++ } ++ sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script); ++ } ++ ++ ipkg_message(conf, IPKG_INFO, "Running script %s\n", path); ++ if (conf->noaction) return 0; ++ ++ /* XXX: CLEANUP: There must be a better way to handle maintainer ++ scripts when running with offline_root mode and/or a dest other ++ than '/'. I've been playing around with some clever chroot ++ tricks and I might come up with something workable. */ ++ if (conf->offline_root) { ++ setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1); ++ } ++ ++ setenv("PKG_ROOT", ++ pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1); ++ ++ if (! file_exists(path)) { ++ free(path); ++ return 0; ++ } ++ ++ if (conf->offline_root) { ++ fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script); ++ free(path); ++ return 0; ++ } ++ ++ sprintf_alloc(&cmd, "%s %s", path, args); ++ free(path); ++ ++ err = xsystem(cmd); ++ free(cmd); ++ ++ if (err) { ++ fprintf(stderr, "%s script returned status %d\n", script, err); ++ return err; ++ } ++ ++ return 0; ++} ++ ++char *pkg_state_want_to_str(pkg_state_want_t sw) ++{ ++ int i; ++ ++ for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) { ++ if (pkg_state_want_map[i].value == sw) { ++ return strdup(pkg_state_want_map[i].str); ++ } ++ } ++ ++ fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n", ++ __FUNCTION__, sw); ++ return strdup(""); ++} ++ ++pkg_state_want_t pkg_state_want_from_str(char *str) ++{ ++ int i; ++ ++ for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) { ++ if (strcmp(str, pkg_state_want_map[i].str) == 0) { ++ return pkg_state_want_map[i].value; ++ } ++ } ++ ++ fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n", ++ __FUNCTION__, str); ++ return SW_UNKNOWN; ++} ++ ++char *pkg_state_flag_to_str(pkg_state_flag_t sf) ++{ ++ int i; ++ int len = 3; /* ok\000 is minimum */ ++ char *str = NULL; ++ ++ /* clear the temporary flags before converting to string */ ++ sf &= SF_NONVOLATILE_FLAGS; ++ ++ if (sf == 0) { ++ return strdup("ok"); ++ } else { ++ ++ for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) { ++ if (sf & pkg_state_flag_map[i].value) { ++ len += strlen(pkg_state_flag_map[i].str) + 1; ++ } ++ } ++ str = malloc(len); ++ if ( str == NULL ) { ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ str[0] = 0; ++ for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) { ++ if (sf & pkg_state_flag_map[i].value) { ++ strcat(str, pkg_state_flag_map[i].str); ++ strcat(str, ","); ++ } ++ } ++ len = strlen(str); ++ str[len-1] = 0; /* squash last comma */ ++ return str; ++ } ++} ++ ++pkg_state_flag_t pkg_state_flag_from_str(char *str) ++{ ++ int i; ++ int sf = SF_OK; ++ ++ if (strcmp(str, "ok") == 0) { ++ return SF_OK; ++ } ++ for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) { ++ const char *sfname = pkg_state_flag_map[i].str; ++ int sfname_len = strlen(sfname); ++ if (strncmp(str, sfname, sfname_len) == 0) { ++ sf |= pkg_state_flag_map[i].value; ++ str += sfname_len; ++ if (str[0] == ',') { ++ str++; ++ } else { ++ break; ++ } ++ } ++ } ++ ++ return sf; ++} ++ ++char *pkg_state_status_to_str(pkg_state_status_t ss) ++{ ++ int i; ++ ++ for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) { ++ if (pkg_state_status_map[i].value == ss) { ++ return strdup(pkg_state_status_map[i].str); ++ } ++ } ++ ++ fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n", ++ __FUNCTION__, ss); ++ return strdup(""); ++} ++ ++pkg_state_status_t pkg_state_status_from_str(char *str) ++{ ++ int i; ++ ++ for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) { ++ if (strcmp(str, pkg_state_status_map[i].str) == 0) { ++ return pkg_state_status_map[i].value; ++ } ++ } ++ ++ fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n", ++ __FUNCTION__, str); ++ return SS_NOT_INSTALLED; ++} ++ ++int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg) ++{ ++ nv_pair_list_elt_t *l; ++ ++ if (!pkg->architecture) ++ return 1; ++ ++ l = conf->arch_list.head; ++ ++ while (l) { ++ nv_pair_t *nv = l->data; ++ if (strcmp(nv->name, pkg->architecture) == 0) { ++ ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name); ++ return 1; ++ } ++ l = l->next; ++ } ++ ++ ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name); ++ return 0; ++} ++ ++int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname) ++{ ++ nv_pair_list_elt_t *l; ++ ++ l = conf->arch_list.head; ++ ++ while (l) { ++ nv_pair_t *nv = l->data; ++ if (strcmp(nv->name, archname) == 0) { ++ int priority = strtol(nv->value, NULL, 0); ++ return priority; ++ } ++ l = l->next; ++ } ++ return 0; ++} ++ ++int pkg_info_preinstall_check(ipkg_conf_t *conf) ++{ ++ int i; ++ hash_table_t *pkg_hash = &conf->pkg_hash; ++ pkg_vec_t *available_pkgs = pkg_vec_alloc(); ++ pkg_vec_t *installed_pkgs = pkg_vec_alloc(); ++ ++ ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n"); ++ pkg_hash_fetch_available(pkg_hash, available_pkgs); ++ /* update arch_priority for each package */ ++ for (i = 0; i < available_pkgs->len; i++) { ++ pkg_t *pkg = available_pkgs->pkgs[i]; ++ int arch_priority = 1; ++ if (!pkg) ++ continue; ++ // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture); ++ if (pkg->architecture) ++ arch_priority = pkg_get_arch_priority(conf, pkg->architecture); ++ else ++ ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name); ++ // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority); ++ pkg->arch_priority = arch_priority; ++ } ++ ++ for (i = 0; i < available_pkgs->len; i++) { ++ pkg_t *pkg = available_pkgs->pkgs[i]; ++ if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) { ++ /* clear flags and want for any uninstallable package */ ++ ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n", ++ pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want); ++ pkg->state_want = SW_UNKNOWN; ++ pkg->state_flag = 0; ++ } ++ } ++ pkg_vec_free(available_pkgs); ++ ++ /* update the file owner data structure */ ++ ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n"); ++ pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs); ++ for (i = 0; i < installed_pkgs->len; i++) { ++ pkg_t *pkg = installed_pkgs->pkgs[i]; ++ str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */ ++ str_list_elt_t *iter; ++ if (installed_files == NULL) { ++ ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name); ++ break; ++ } ++ for (iter = installed_files->head; iter; iter = iter->next) { ++ char *installed_file = iter->data; ++ // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file); ++ file_hash_set_file_owner(conf, installed_file, pkg); ++ } ++ } ++ pkg_vec_free(installed_pkgs); ++ ++ return 0; ++} ++ ++struct pkg_write_filelist_data { ++ ipkg_conf_t *conf; ++ pkg_t *pkg; ++ FILE *stream; ++}; ++ ++void pkg_write_filelist_helper(const char *key, void *entry_, void *data_) ++{ ++ struct pkg_write_filelist_data *data = data_; ++ pkg_t *entry = entry_; ++ if (entry == data->pkg) { ++ fprintf(data->stream, "%s\n", key); ++ } ++} ++ ++int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg) ++{ ++ struct pkg_write_filelist_data data; ++ char *list_file_name = NULL; ++ int err = 0; ++ ++ if (!pkg) { ++ ipkg_message(conf, IPKG_ERROR, "Null pkg\n"); ++ return -EINVAL; ++ } ++ ipkg_message(conf, IPKG_INFO, ++ " creating %s.list file\n", pkg->name); ++ sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name); ++ if (!list_file_name) { ++ ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n"); ++ return -ENOMEM; ++ } ++ ipkg_message(conf, IPKG_INFO, ++ " creating %s file for pkg %s\n", list_file_name, pkg->name); ++ data.stream = fopen(list_file_name, "w"); ++ if (!data.stream) { ++ ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n", ++ list_file_name, strerror(errno)); ++ return errno; ++ } ++ data.pkg = pkg; ++ data.conf = conf; ++ hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data); ++ fclose(data.stream); ++ free(list_file_name); ++ ++ return err; ++} ++ ++int pkg_write_changed_filelists(ipkg_conf_t *conf) ++{ ++ pkg_vec_t *installed_pkgs = pkg_vec_alloc(); ++ hash_table_t *pkg_hash = &conf->pkg_hash; ++ int i; ++ int err; ++ if (conf->noaction) ++ return 0; ++ ++ ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__); ++ pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs); ++ for (i = 0; i < installed_pkgs->len; i++) { ++ pkg_t *pkg = installed_pkgs->pkgs[i]; ++ if (pkg->state_flag & SF_FILELIST_CHANGED) { ++ ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__); ++ err = pkg_write_filelist(conf, pkg); ++ if (err) ++ ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err); ++ } ++ } ++ return 0; ++} +Index: busybox-1.7.2/archival/libipkg/pkg_depends.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg_depends.c 2007-10-04 17:14:23.109058340 +0200 +@@ -0,0 +1,1031 @@ ++/* pkg_depends.c - the itsy package management system ++ ++ Steven M. Ayer ++ ++ Copyright (C) 2002 Compaq Computer Corporation ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++#include ++#include ++ ++#include "pkg.h" ++#include "ipkg_utils.h" ++#include "pkg_hash.h" ++#include "ipkg_message.h" ++#include "pkg_parse.h" ++#include "hash_table.h" ++ ++static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str); ++static depend_t * depend_init(void); ++static void depend_deinit(depend_t *d); ++static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx); ++static char ** merge_unresolved(char ** oldstuff, char ** newstuff); ++static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg); ++ ++static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata) ++{ ++ depend_t *depend = (depend_t *)cdata; ++ if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg)) ++ return 1; ++ else ++ return 0; ++} ++ ++static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata) ++{ ++ depend_t *depend = (depend_t *)cdata; ++#if 0 ++ pkg_t * temp = pkg_new(); ++ int comparison; ++ parseVersion(temp, depend->version); ++ comparison = pkg_compare_versions(pkg, temp); ++ free(temp); ++ ++ fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n", ++ __FUNCTION__, pkg->name, pkg->version, ++ depend, depend->constraint, depend->version, ++ comparison, version_constraints_satisfied(depend, pkg)); ++#endif ++ if (version_constraints_satisfied(depend, pkg)) ++ return 1; ++ else ++ return 0; ++} ++ ++/* returns ndependences or negative error value */ ++int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, ++ pkg_vec_t *unsatisfied, char *** unresolved) ++{ ++ pkg_t * satisfier_entry_pkg; ++ register int i, j, k, l; ++ int count, found; ++ char ** the_lost; ++ abstract_pkg_t * ab_pkg; ++ ++ /* ++ * this is a setup to check for redundant/cyclic dependency checks, ++ * which are marked at the abstract_pkg level ++ */ ++ if (!(ab_pkg = pkg->parent)) { ++ fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name); ++ *unresolved = NULL; ++ return 0; ++ } ++ if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */ ++ *unresolved = NULL; ++ return 0; ++ } else { ++ ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */ ++ } ++ /**/ ++ ++ count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count; ++ if (!count){ ++ *unresolved = NULL; ++ return 0; ++ } ++ ++ the_lost = NULL; ++ ++ /* foreach dependency */ ++ for (i = 0; i < count; i++) { ++ compound_depend_t * compound_depend = &pkg->depends[i]; ++ depend_t ** possible_satisfiers = compound_depend->possibilities;; ++ found = 0; ++ satisfier_entry_pkg = NULL; ++ ++ if (compound_depend->type == GREEDY_DEPEND) { ++ /* foreach possible satisfier */ ++ for (j = 0; j < compound_depend->possibility_count; j++) { ++ /* foreach provided_by, which includes the abstract_pkg itself */ ++ abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg; ++ abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by; ++ int nposs = ab_provider_vec->len; ++ abstract_pkg_t **ab_providers = ab_provider_vec->pkgs; ++ for (l = 0; l < nposs; l++) { ++ pkg_vec_t *test_vec = ab_providers[l]->pkgs; ++ /* if no depends on this one, try the first package that Provides this one */ ++ if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */ ++ continue; ++ } ++ ++ /* cruise this possiblity's pkg_vec looking for an installed version */ ++ for (k = 0; k < test_vec->len; k++) { ++ pkg_t *pkg_scout = test_vec->pkgs[k]; ++ /* not installed, and not already known about? */ ++ if ((pkg_scout->state_want != SW_INSTALL) ++ && !pkg_scout->parent->dependencies_checked ++ && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) { ++ char ** newstuff = NULL; ++ int rc; ++ pkg_vec_t *tmp_vec = pkg_vec_alloc (); ++ /* check for not-already-installed dependencies */ ++ rc = pkg_hash_fetch_unsatisfied_dependencies(conf, ++ pkg_scout, ++ tmp_vec, ++ &newstuff); ++ if (newstuff == NULL) { ++ int ok = 1; ++ for (l = 0; l < rc; l++) { ++ pkg_t *p = tmp_vec->pkgs[l]; ++ if (p->state_want == SW_INSTALL) ++ continue; ++ ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name); ++ ok = 0; ++ break; ++ } ++ pkg_vec_free (tmp_vec); ++ if (ok) { ++ /* mark this one for installation */ ++ ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name); ++ pkg_vec_insert(unsatisfied, pkg_scout); ++ } ++ } else { ++ ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name); ++ free (newstuff); ++ } ++ } ++ } ++ } ++ } ++ ++ continue; ++ } ++ ++ /* foreach possible satisfier, look for installed package */ ++ for (j = 0; j < compound_depend->possibility_count; j++) { ++ /* foreach provided_by, which includes the abstract_pkg itself */ ++ depend_t *dependence_to_satisfy = possible_satisfiers[j]; ++ abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg; ++ pkg_t *satisfying_pkg = ++ pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg, ++ pkg_installed_and_constraint_satisfied, ++ dependence_to_satisfy, 1); ++ /* Being that I can't test constraing in pkg_hash, I will test it here */ ++ if (satisfying_pkg != NULL) { ++ if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) { ++ satisfying_pkg = NULL; ++ } ++ } ++ ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg); ++ if (satisfying_pkg != NULL) { ++ found = 1; ++ break; ++ } ++ ++ } ++ /* if nothing installed matches, then look for uninstalled satisfier */ ++ if (!found) { ++ /* foreach possible satisfier, look for installed package */ ++ for (j = 0; j < compound_depend->possibility_count; j++) { ++ /* foreach provided_by, which includes the abstract_pkg itself */ ++ depend_t *dependence_to_satisfy = possible_satisfiers[j]; ++ abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg; ++ pkg_t *satisfying_pkg = ++ pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg, ++ pkg_constraint_satisfied, ++ dependence_to_satisfy, 1); ++ /* Being that I can't test constraing in pkg_hash, I will test it here too */ ++ if (satisfying_pkg != NULL) { ++ if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) { ++ satisfying_pkg = NULL; ++ } ++ } ++ ++ /* user request overrides package recommendation */ ++ if (satisfying_pkg != NULL ++ && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST) ++ && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) { ++ ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n", ++ pkg->name, satisfying_pkg->name); ++ continue; ++ } ++ ++ ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg); ++ if (satisfying_pkg != NULL) { ++ satisfier_entry_pkg = satisfying_pkg; ++ break; ++ } ++ } ++ } ++ ++ /* we didn't find one, add something to the unsatisfied vector */ ++ if (!found) { ++ if (!satisfier_entry_pkg) { ++ /* failure to meet recommendations is not an error */ ++ if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST) ++ the_lost = add_unresolved_dep(pkg, the_lost, i); ++ else ++ ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n", ++ pkg->name, compound_depend->possibilities[0]->pkg->name); ++ } ++ else { ++ if (compound_depend->type == SUGGEST) { ++ /* just mention it politely */ ++ ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n", ++ pkg->name, satisfier_entry_pkg->name); ++ } else { ++ char ** newstuff = NULL; ++ ++ if (satisfier_entry_pkg != pkg && ++ !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) { ++ pkg_vec_insert(unsatisfied, satisfier_entry_pkg); ++ pkg_hash_fetch_unsatisfied_dependencies(conf, ++ satisfier_entry_pkg, ++ unsatisfied, ++ &newstuff); ++ the_lost = merge_unresolved(the_lost, newstuff); ++ } ++ } ++ } ++ } ++ } ++ *unresolved = the_lost; ++ ++ return unsatisfied->len; ++} ++ ++/*checking for conflicts !in replaces ++ If a packages conflicts with another but is also replacing it, I should not consider it a ++ really conflicts ++ returns 0 if conflicts <> replaces or 1 if conflicts == replaces ++*/ ++int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg) ++{ ++ int i ; ++ int replaces_count = pkg->replaces_count; ++ abstract_pkg_t **replaces; ++ ++ if (pkg->replaces_count==0) // No replaces, it's surely a conflict ++ return 0; ++ ++ replaces = pkg->replaces; ++ ++ for (i = 0; i < replaces_count; i++) { ++ if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found ++ ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name); ++ return 1; ++ } ++ } ++ return 0; ++ ++} ++ ++ ++/* Abhaya: added support for conflicts */ ++pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg) ++{ ++ pkg_vec_t * installed_conflicts, * test_vec; ++ compound_depend_t * conflicts; ++ depend_t ** possible_satisfiers; ++ depend_t * possible_satisfier; ++ register int i, j, k; ++ int count; ++ abstract_pkg_t * ab_pkg; ++ pkg_t **pkg_scouts; ++ pkg_t *pkg_scout; ++ ++ /* ++ * this is a setup to check for redundant/cyclic dependency checks, ++ * which are marked at the abstract_pkg level ++ */ ++ if(!(ab_pkg = pkg->parent)){ ++ fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name); ++ return (pkg_vec_t *)NULL; ++ } ++ ++ conflicts = pkg->conflicts; ++ if(!conflicts){ ++ return (pkg_vec_t *)NULL; ++ } ++ installed_conflicts = pkg_vec_alloc(); ++ ++ count = pkg->conflicts_count; ++ ++ ++ ++ /* foreach conflict */ ++ for(i = 0; i < pkg->conflicts_count; i++){ ++ ++ possible_satisfiers = conflicts->possibilities; ++ ++ /* foreach possible satisfier */ ++ for(j = 0; j < conflicts->possibility_count; j++){ ++ possible_satisfier = possible_satisfiers[j]; ++ if (!possible_satisfier) ++ fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__); ++ if (!possible_satisfier->pkg) ++ fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__); ++ test_vec = possible_satisfier->pkg->pkgs; ++ if (test_vec) { ++ /* pkg_vec found, it is an actual package conflict ++ * cruise this possiblity's pkg_vec looking for an installed version */ ++ pkg_scouts = test_vec->pkgs; ++ for(k = 0; k < test_vec->len; k++){ ++ pkg_scout = pkg_scouts[k]; ++ if (!pkg_scout) { ++ fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__); ++ continue; ++ } ++ if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) && ++ version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){ ++ if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){ ++ pkg_vec_insert(installed_conflicts, pkg_scout); ++ } ++ } ++ } ++ } ++ } ++ conflicts++; ++ } ++ ++ if (installed_conflicts->len) ++ return installed_conflicts; ++ pkg_vec_free(installed_conflicts); ++ return (pkg_vec_t *)NULL; ++} ++ ++int version_constraints_satisfied(depend_t * depends, pkg_t * pkg) ++{ ++ pkg_t * temp; ++ int comparison; ++ ++ if(depends->constraint == NONE) ++ return 1; ++ ++ temp = pkg_new(); ++ ++ parseVersion(temp, depends->version); ++ ++ comparison = pkg_compare_versions(pkg, temp); ++ ++ free(temp); ++ ++ if((depends->constraint == EARLIER) && ++ (comparison < 0)) ++ return 1; ++ else if((depends->constraint == LATER) && ++ (comparison > 0)) ++ return 1; ++ else if(comparison == 0) ++ return 1; ++ else if((depends->constraint == LATER_EQUAL) && ++ (comparison >= 0)) ++ return 1; ++ else if((depends->constraint == EARLIER_EQUAL) && ++ (comparison <= 0)) ++ return 1; ++ ++ return 0; ++} ++ ++int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend) ++{ ++ abstract_pkg_t *apkg = depend->pkg; ++ abstract_pkg_vec_t *provider_apkgs = apkg->provided_by; ++ int n_providers = provider_apkgs->len; ++ abstract_pkg_t **apkgs = provider_apkgs->pkgs; ++ pkg_vec_t *pkg_vec; ++ int n_pkgs ; ++ int i; ++ int j; ++ ++ for (i = 0; i < n_providers; i++) { ++ abstract_pkg_t *papkg = apkgs[i]; ++ pkg_vec = papkg->pkgs; ++ if (pkg_vec) { ++ n_pkgs = pkg_vec->len; ++ for (j = 0; j < n_pkgs; j++) { ++ pkg_t *pkg = pkg_vec->pkgs[j]; ++ if (version_constraints_satisfied(depend, pkg)) { ++ return 1; ++ } ++ } ++ } ++ } ++ return 0; ++} ++ ++int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend) ++{ ++ abstract_pkg_t *apkg = depend->pkg; ++ abstract_pkg_vec_t *provider_apkgs = apkg->provided_by; ++ int n_providers = provider_apkgs->len; ++ abstract_pkg_t **apkgs = provider_apkgs->pkgs; ++ int i; ++ int n_pkgs; ++ int j; ++ ++ for (i = 0; i < n_providers; i++) { ++ abstract_pkg_t *papkg = apkgs[i]; ++ pkg_vec_t *pkg_vec = papkg->pkgs; ++ if (pkg_vec) { ++ n_pkgs = pkg_vec->len; ++ for (j = 0; j < n_pkgs; j++) { ++ pkg_t *pkg = pkg_vec->pkgs[j]; ++ if (version_constraints_satisfied(depend, pkg)) { ++ if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) ++ return 1; ++ } ++ } ++ } ++ } ++ return 0; ++} ++ ++static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg) ++{ ++ register int i; ++ pkg_t ** pkgs = vec->pkgs; ++ ++ for(i = 0; i < vec->len; i++) ++ if((strcmp(pkg->name, (*(pkgs + i))->name) == 0) ++ && (pkg_compare_versions(pkg, *(pkgs + i)) == 0) ++ && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0)) ++ return 1; ++ return 0; ++} ++ ++ ++#ifdef DeadCode ++/** ++ * pkg_has_common_provides returns 1 if pkg and replacee both provide ++ * the same abstract package and 0 otherwise. ++ */ ++int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee) ++{ ++ abstract_pkg_t **provides = pkg->provides; ++ int provides_count = pkg->provides_count; ++ abstract_pkg_t **replacee_provides = replacee->provides; ++ int replacee_provides_count = replacee->provides_count; ++ int i, j; ++ for (i = 0; i < provides_count; i++) { ++ abstract_pkg_t *apkg = provides[i]; ++ for (j = 0; j < replacee_provides_count; j++) { ++ abstract_pkg_t *replacee_apkg = replacee_provides[i]; ++ if (apkg == replacee_apkg) ++ return 1; ++ } ++ } ++ return 0; ++} ++#endif ++ ++/** ++ * pkg_provides_abstract returns 1 if pkg->provides contains providee ++ * and 0 otherwise. ++ */ ++int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee) ++{ ++ abstract_pkg_t **provides = pkg->provides; ++ int provides_count = pkg->provides_count; ++ int i; ++ for (i = 0; i < provides_count; i++) { ++ if (provides[i] == providee) ++ return 1; ++ } ++ return 0; ++} ++ ++/** ++ * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0 ++ * otherwise. ++ */ ++int pkg_replaces(pkg_t *pkg, pkg_t *replacee) ++{ ++ abstract_pkg_t **replaces = pkg->replaces; ++ int replaces_count = pkg->replaces_count; ++ /* abstract_pkg_t **replacee_provides = pkg->provides; ++ int replacee_provides_count = pkg->provides_count; */ ++ int i, j; ++ for (i = 0; i < replaces_count; i++) { ++ abstract_pkg_t *abstract_replacee = replaces[i]; ++ for (j = 0; j < replaces_count; j++) { ++ /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n", ++ pkg->name,replacee->provides[j]->name, abstract_replacee->name); */ ++ if (replacee->provides[j] == abstract_replacee) ++ return 1; ++ } ++ } ++ return 0; ++} ++ ++ ++/** ++ * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0 ++ * otherwise. ++ */ ++int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee) ++{ ++ compound_depend_t *conflicts = pkg->conflicts; ++ int conflicts_count = pkg->conflicts_count; ++ int i, j; ++ for (i = 0; i < conflicts_count; i++) { ++ int possibility_count = conflicts[i].possibility_count; ++ struct depend **possibilities = conflicts[i].possibilities; ++ for (j = 0; j < possibility_count; j++) { ++ if (possibilities[j]->pkg == conflictee) { ++ return 1; ++ } ++ } ++ } ++ return 0; ++} ++ ++/** ++ * pkg_conflicts returns 1 if pkg->conflicts contains one of ++ * conflictee's provides and 0 otherwise. ++ */ ++int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee) ++{ ++ compound_depend_t *conflicts = pkg->conflicts; ++ int conflicts_count = pkg->conflicts_count; ++ abstract_pkg_t **conflictee_provides = conflictee->provides; ++ int conflictee_provides_count = conflictee->provides_count; ++ int i, j, k; ++ int possibility_count; ++ struct depend **possibilities; ++ abstract_pkg_t *possibility ; ++ ++ for (i = 0; i < conflicts_count; i++) { ++ possibility_count = conflicts[i].possibility_count; ++ possibilities = conflicts[i].possibilities; ++ for (j = 0; j < possibility_count; j++) { ++ possibility = possibilities[j]->pkg; ++ for (k = 0; k < conflictee_provides_count; k++) { ++ if (possibility == conflictee_provides[k]) { ++ return 1; ++ } ++ } ++ } ++ } ++ return 0; ++} ++ ++static char ** merge_unresolved(char ** oldstuff, char ** newstuff) ++{ ++ int oldlen = 0, newlen = 0; ++ char ** result; ++ register int i, j; ++ ++ if(!newstuff) ++ return oldstuff; ++ ++ while(oldstuff && oldstuff[oldlen]) oldlen++; ++ while(newstuff && newstuff[newlen]) newlen++; ++ ++ result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1)); ++ if (result == NULL) { ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ ++ for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++) ++ *(result + i) = *(newstuff + j); ++ ++ *(result + i) = NULL; ++ ++ return result; ++} ++ ++/* ++ * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre) ++ * this is null terminated, no count is carried around ++ */ ++char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx) ++{ ++ int count; ++ char ** resized; ++ char *depend_str = pkg_depend_str(pkg, ref_ndx); ++ ++ count = 0; ++ while(the_lost && the_lost[count]) count++; ++ ++ count++; /* need one to hold the null */ ++ resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1)); ++ if (resized == NULL) { ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ resized[count - 1] = strdup(depend_str); ++ resized[count] = NULL; ++ ++ return resized; ++} ++ ++void printDepends(pkg_t * pkg) ++{ ++ register int i, j; ++ compound_depend_t * depend; ++ int count; ++ ++ count = pkg->pre_depends_count + pkg->depends_count; ++ ++ depend = pkg->depends; ++ if(!depend){ ++ fprintf(stderr, "Depends pointer is NULL\n"); ++ return; ++ } ++ for(i = 0; i < count; i++){ ++ fprintf(stderr, "%s has %d possibilities:\n", ++ (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"), ++ depend->possibility_count); ++ for(j = 0; j < depend->possibility_count; j++) ++ fprintf(stderr, "\t%s version %s (%d)\n", ++ depend->possibilities[j]->pkg->name, ++ depend->possibilities[j]->version, ++ depend->possibilities[j]->constraint); ++ depend++; ++ } ++} ++ ++int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) ++{ ++ register int i, j; ++ ++ /* every pkg provides itself */ ++ abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg); ++ ++ if (!pkg->provides_count) ++ return 0; ++ ++ pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1)); ++ if (pkg->provides == NULL) { ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return -1 ; ++ } ++ pkg->provides[0] = ab_pkg; ++ ++ // if (strcmp(ab_pkg->name, pkg->name)) ++ // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name); ++ ++ for(i = 0; i < pkg->provides_count; i++){ ++ abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]); ++ ++ pkg->provides[i+1] = provided_abpkg; ++ ++ j = 0; ++ abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg); ++ } ++ return 0; ++} ++ ++/* Abhaya: added conflicts support */ ++int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) ++{ ++ register int i; ++ compound_depend_t * conflicts; ++ ++ if (!pkg->conflicts_count) ++ return 0; ++ ++ conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) * ++ pkg->conflicts_count); ++ if (conflicts == NULL) { ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return -1; ++ } ++ for (i = 0; i < pkg->conflicts_count; i++) { ++ conflicts->type = CONFLICTS; ++ parseDepends(conflicts, hash, ++ pkg->conflicts_str[i]); ++#if 0 ++ for (j = 0; j < conflicts->possibility_count; j++) { ++ depend_t *possibility = conflicts->possibilities[j]; ++ abstract_pkg_t *conflicting_apkg = possibility->pkg; ++ pkg_add_conflict_pair(ab_pkg, conflicting_apkg); ++ } ++#endif ++ conflicts++; ++ } ++ return 0; ++} ++ ++int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) ++{ ++ register int i, j; ++ ++ if (!pkg->replaces_count) ++ return 0; ++ ++ pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count); ++ if (pkg->replaces == NULL) { ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return -1; ++ } ++ ++ // if (strcmp(ab_pkg->name, pkg->name)) ++ // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name); ++ ++ for(i = 0; i < pkg->replaces_count; i++){ ++ abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]); ++ ++ pkg->replaces[i] = old_abpkg; ++ ++ j = 0; ++ if (!old_abpkg->replaced_by) ++ old_abpkg->replaced_by = abstract_pkg_vec_alloc(); ++ if ( old_abpkg->replaced_by == NULL ){ ++ return -1; ++ } ++ /* if a package pkg both replaces and conflicts old_abpkg, ++ * then add it to the replaced_by vector so that old_abpkg ++ * will be upgraded to ab_pkg automatically */ ++ if (pkg_conflicts_abstract(pkg, old_abpkg)) ++ abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg); ++ } ++ return 0; ++} ++ ++int buildDepends(hash_table_t * hash, pkg_t * pkg) ++{ ++ int count; ++ register int i; ++ compound_depend_t * depends; ++ ++ if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count)) ++ return 0; ++ ++ if (0 && pkg->pre_depends_count) ++ fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n", ++ pkg->name, pkg->pre_depends_count, pkg->depends_count); ++ depends = pkg->depends = malloc(sizeof(compound_depend_t) * count); ++ if (depends == NULL) { ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return -1; ++ } ++ ++ ++ for(i = 0; i < pkg->pre_depends_count; i++){ ++ parseDepends(depends, hash, pkg->pre_depends_str[i]); ++ if (0 && pkg->pre_depends_count) ++ fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n", ++ pkg->pre_depends_str[i], depends, depends->possibility_count); ++ depends->type = PREDEPEND; ++ depends++; ++ } ++ ++ for(i = 0; i < pkg->recommends_count; i++){ ++ parseDepends(depends, hash, pkg->recommends_str[i]); ++ if (0 && pkg->recommends_count) ++ fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n", ++ pkg->recommends_str[i], depends, depends->possibility_count); ++ depends->type = RECOMMEND; ++ depends++; ++ } ++ ++ for(i = 0; i < pkg->suggests_count; i++){ ++ parseDepends(depends, hash, pkg->suggests_str[i]); ++ if (0 && pkg->suggests_count) ++ fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n", ++ pkg->suggests_str[i], depends, depends->possibility_count); ++ depends->type = SUGGEST; ++ depends++; ++ } ++ ++ for(i = 0; i < pkg->depends_count; i++){ ++ parseDepends(depends, hash, pkg->depends_str[i]); ++ if (0 && pkg->depends_count) ++ fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n", ++ pkg->depends_str[i], depends, depends->possibility_count); ++ depends++; ++ } ++ return 0; ++} ++ ++/* ++ * pkg_depend_string: returns the depends string specified by index. ++ * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0. ++ * [0,npredepends) -> returns pre_depends_str[index] ++ * [npredepends,npredepends+nrecommends) -> returns recommends_str[index] ++ * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index] ++ * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index] ++ */ ++char *pkg_depend_str(pkg_t *pkg, int pkg_index) ++{ ++ if (pkg_index < pkg->pre_depends_count) { ++ return pkg->pre_depends_str[pkg_index]; ++ } ++ pkg_index -= pkg->pre_depends_count; ++ ++ if (pkg_index < pkg->recommends_count) { ++ return pkg->recommends_str[pkg_index]; ++ } ++ pkg_index -= pkg->recommends_count; ++ ++ if (pkg_index < pkg->suggests_count) { ++ return pkg->suggests_str[pkg_index]; ++ } ++ pkg_index -= pkg->suggests_count; ++ ++ if (pkg_index < pkg->depends_count) { ++ return pkg->depends_str[pkg_index]; ++ } ++ fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", pkg_index, pkg->name); ++ return NULL; ++} ++ ++void freeDepends(pkg_t *pkg) ++{ ++ int i; ++ ++ if (pkg == NULL || pkg->depends == NULL) { ++ return; ++ } ++ ++ fprintf(stderr, "Freeing depends=%p\n", pkg->depends); ++ for (i=0; i < pkg->depends->possibility_count; i++) { ++ depend_deinit(pkg->depends->possibilities[i]); ++ } ++ free(pkg->depends->possibilities); ++ free(pkg->depends); ++ pkg->depends = NULL; ++} ++ ++void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg) ++{ ++ compound_depend_t * depends; ++ int count, othercount; ++ register int i, j; ++ abstract_pkg_t * ab_depend; ++ abstract_pkg_t ** temp; ++ ++ count = pkg->pre_depends_count + pkg->depends_count; ++ depends = pkg->depends; ++ ++ if (0 && pkg->pre_depends_count) ++ fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n", ++ pkg->name, pkg->pre_depends_count, pkg->depends_count); ++ for (i = 0; i < count; i++) { ++ if (0 && pkg->pre_depends_count) ++ fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends); ++ for (j = 0; j < depends->possibility_count; j++){ ++ ab_depend = depends->possibilities[j]->pkg; ++ if(!ab_depend->depended_upon_by) ++ ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *)); ++ ++ temp = ab_depend->depended_upon_by; ++ othercount = 1; ++ while(*temp){ ++ temp++; ++ othercount++; ++ } ++ *temp = ab_pkg; ++ ++ ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by, ++ (othercount + 1) * sizeof(abstract_pkg_t *)); ++ /* the array may have moved */ ++ temp = ab_depend->depended_upon_by + othercount; ++ *temp = NULL; ++ } ++ depends++; ++ } ++} ++ ++static depend_t * depend_init(void) ++{ ++ depend_t * d = (depend_t *)malloc(sizeof(depend_t)); ++ if ( d==NULL ){ ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ d->constraint = NONE; ++ d->version = NULL; ++ d->pkg = NULL; ++ ++ return d; ++} ++ ++static void depend_deinit(depend_t *d) ++{ ++ free(d); ++} ++ ++static int parseDepends(compound_depend_t *compound_depend, ++ hash_table_t * hash, char * depend_str) ++{ ++ char * pkg_name, buffer[2048]; ++ int num_of_ors = 0; ++ register int i; ++ register char * src, * dest; ++ depend_t ** possibilities; ++ ++ /* first count the number of ored possibilities for satisfying dependency */ ++ src = depend_str; ++ while(*src) ++ if(*src++ == '|') ++ num_of_ors++; ++ ++ compound_depend->type = DEPEND; ++ ++ compound_depend->possibility_count = num_of_ors + 1; ++ possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1)); ++ if (!possibilities) ++ return -ENOMEM; ++ compound_depend->possibilities = possibilities; ++ ++ src = depend_str; ++ for(i = 0; i < num_of_ors + 1; i++){ ++ possibilities[i] = depend_init(); ++ if (!possibilities[i]) ++ return -ENOMEM; ++ /* gobble up just the name first */ ++ dest = buffer; ++ while(*src && ++ !isspace(*src) && ++ (*src != '(') && ++ (*src != '*') && ++ (*src != '|')) ++ *dest++ = *src++; ++ *dest = '\0'; ++ pkg_name = trim_alloc(buffer); ++ if (pkg_name == NULL ) ++ return -ENOMEM; ++ ++ /* now look at possible version info */ ++ ++ /* skip to next chars */ ++ if(isspace(*src)) ++ while(*src && isspace(*src)) src++; ++ ++ /* extract constraint and version */ ++ if(*src == '('){ ++ src++; ++ if(!strncmp(src, "<<", 2)){ ++ possibilities[i]->constraint = EARLIER; ++ src += 2; ++ } ++ else if(!strncmp(src, "<=", 2)){ ++ possibilities[i]->constraint = EARLIER_EQUAL; ++ src += 2; ++ } ++ else if(!strncmp(src, ">=", 2)){ ++ possibilities[i]->constraint = LATER_EQUAL; ++ src += 2; ++ } ++ else if(!strncmp(src, ">>", 2)){ ++ possibilities[i]->constraint = LATER; ++ src += 2; ++ } ++ else if(!strncmp(src, "=", 1)){ ++ possibilities[i]->constraint = EQUAL; ++ src++; ++ } ++ /* should these be here to support deprecated designations; dpkg does */ ++ else if(!strncmp(src, "<", 1)){ ++ possibilities[i]->constraint = EARLIER_EQUAL; ++ src++; ++ } ++ else if(!strncmp(src, ">", 1)){ ++ possibilities[i]->constraint = LATER_EQUAL; ++ src++; ++ } ++ ++ /* now we have any constraint, pass space to version string */ ++ while(isspace(*src)) src++; ++ ++ /* this would be the version string */ ++ dest = buffer; ++ while(*src && *src != ')') ++ *dest++ = *src++; ++ *dest = '\0'; ++ ++ possibilities[i]->version = trim_alloc(buffer); ++ /* fprintf(stderr, "let's print the depends version string:"); ++ fprintf(stderr, "version %s\n", possibilities[i]->version);*/ ++ if (possibilities[i]->version == NULL ) ++ return -ENOMEM; ++ ++ ++ } ++ /* hook up the dependency to its abstract pkg */ ++ possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name); ++ ++ free(pkg_name); ++ ++ /* now get past the ) and any possible | chars */ ++ while(*src && ++ (isspace(*src) || ++ (*src == ')') || ++ (*src == '|'))) ++ src++; ++ if (*src == '*') ++ { ++ compound_depend->type = GREEDY_DEPEND; ++ src++; ++ } ++ } ++ ++ return 0; ++} +Index: busybox-1.7.2/archival/libipkg/pkg_depends.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg_depends.h 2007-10-04 17:14:23.129059469 +0200 +@@ -0,0 +1,105 @@ ++/* pkg_depends.h - the itsy package management system ++ ++ Steven M. Ayer ++ ++ Copyright (C) 2002 Compaq Computer Corporation ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef PKG_DEPENDS_H ++#define PKG_DEPENDS_H ++ ++#include "pkg.h" ++#include "pkg_hash.h" ++ ++enum depend_type { ++ PREDEPEND, ++ DEPEND, ++ CONFLICTS, ++ GREEDY_DEPEND, ++ RECOMMEND, ++ SUGGEST ++}; ++typedef enum depend_type depend_type_t; ++ ++enum version_constraint { ++ NONE, ++ EARLIER, ++ EARLIER_EQUAL, ++ EQUAL, ++ LATER_EQUAL, ++ LATER ++}; ++typedef enum version_constraint version_constraint_t; ++ ++struct depend{ ++ version_constraint_t constraint; ++ char * version; ++ abstract_pkg_t * pkg; ++}; ++typedef struct depend depend_t; ++ ++struct compound_depend{ ++ depend_type_t type; ++ int possibility_count; ++ struct depend ** possibilities; ++}; ++typedef struct compound_depend compound_depend_t; ++ ++#include "hash_table.h" ++ ++int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg); ++int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg); ++int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg); ++int buildDepends(hash_table_t * hash, pkg_t * pkg); ++ ++/** ++ * pkg_has_common_provides returns 1 if pkg and replacee both provide ++ * the same abstract package and 0 otherwise. ++ */ ++int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee); ++ ++/** ++ * pkg_provides returns 1 if pkg->provides contains providee and 0 ++ * otherwise. ++ */ ++int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee); ++ ++/** ++ * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0 ++ * otherwise. ++ */ ++int pkg_replaces(pkg_t *pkg, pkg_t *replacee); ++ ++/** ++ * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0 ++ * otherwise. ++ */ ++int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts); ++ ++/** ++ * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0 ++ * otherwise. ++ */ ++int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts); ++ ++char *pkg_depend_str(pkg_t *pkg, int pkg_index); ++void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg); ++void freeDepends(pkg_t *pkg); ++void printDepends(pkg_t * pkg); ++int version_constraints_satisfied(depend_t * depends, pkg_t * pkg); ++int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved); ++pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg); ++int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend); ++int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend); ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/pkg_dest.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg_dest.c 2007-10-04 17:14:23.173061979 +0200 +@@ -0,0 +1,92 @@ ++/* pkg_dest.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++ ++#include "pkg_dest.h" ++#include "file_util.h" ++#include "str_util.h" ++#include "sprintf_alloc.h" ++ ++int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir) ++{ ++ dest->name = strdup(name); ++ ++ /* Guarantee that dest->root_dir ends with a '/' */ ++ if (str_ends_with(root_dir, "/")) { ++ dest->root_dir = strdup(root_dir); ++ } else { ++ sprintf_alloc(&dest->root_dir, "%s/", root_dir); ++ } ++ file_mkdir_hier(dest->root_dir, 0755); ++ ++ sprintf_alloc(&dest->ipkg_dir, "%s%s", ++ dest->root_dir, IPKG_STATE_DIR_PREFIX); ++ file_mkdir_hier(dest->ipkg_dir, 0755); ++ ++ if (str_starts_with (lists_dir, "/")) ++ sprintf_alloc(&dest->lists_dir, "%s", lists_dir); ++ else ++ sprintf_alloc(&dest->lists_dir, "/%s", lists_dir); ++ ++ file_mkdir_hier(dest->lists_dir, 0755); ++ ++ sprintf_alloc(&dest->info_dir, "%s/%s", ++ dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX); ++ file_mkdir_hier(dest->info_dir, 0755); ++ ++ sprintf_alloc(&dest->status_file_name, "%s/%s", ++ dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX); ++ ++ sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp", ++ dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX); ++ ++ dest->status_file = NULL; ++ ++ return 0; ++} ++ ++void pkg_dest_deinit(pkg_dest_t *dest) ++{ ++ free(dest->name); ++ dest->name = NULL; ++ ++ free(dest->root_dir); ++ dest->root_dir = NULL; ++ ++ free(dest->ipkg_dir); ++ dest->ipkg_dir = NULL; ++ ++ free(dest->lists_dir); ++ dest->lists_dir = NULL; ++ ++ free(dest->info_dir); ++ dest->info_dir = NULL; ++ ++ free(dest->status_file_name); ++ dest->status_file_name = NULL; ++ ++ free(dest->status_file_tmp_name); ++ dest->status_file_tmp_name = NULL; ++ ++ if (dest->status_file) { ++ fclose(dest->status_file); ++ } ++ dest->status_file = NULL; ++ ++ dest->root_dir = NULL; ++} +Index: busybox-1.7.2/archival/libipkg/pkg_dest.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg_dest.h 2007-10-04 17:14:23.197063348 +0200 +@@ -0,0 +1,38 @@ ++/* pkg_dest.h - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef PKG_DEST_H ++#define PKG_DEST_H ++ ++typedef struct pkg_dest pkg_dest_t; ++struct pkg_dest ++{ ++ char *name; ++ char *root_dir; ++ char *ipkg_dir; ++ char *lists_dir; ++ char *info_dir; ++ char *status_file_name; ++ char *status_file_tmp_name; ++ FILE *status_file; ++}; ++ ++int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir); ++void pkg_dest_deinit(pkg_dest_t *dest); ++ ++#endif ++ +Index: busybox-1.7.2/archival/libipkg/pkg_dest_list.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg_dest_list.c 2007-10-04 17:14:23.213064259 +0200 +@@ -0,0 +1,85 @@ ++/* pkg_dest_list.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++ ++#include "pkg_dest.h" ++#include "void_list.h" ++#include "pkg_dest_list.h" ++ ++int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data) ++{ ++ return void_list_elt_init((void_list_elt_t *) elt, data); ++} ++ ++void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt) ++{ ++ void_list_elt_deinit((void_list_elt_t *) elt); ++} ++ ++int pkg_dest_list_init(pkg_dest_list_t *list) ++{ ++ return void_list_init((void_list_t *) list); ++} ++ ++void pkg_dest_list_deinit(pkg_dest_list_t *list) ++{ ++ pkg_dest_list_elt_t *iter; ++ pkg_dest_t *pkg_dest; ++ ++ for (iter = list->head; iter; iter = iter->next) { ++ pkg_dest = iter->data; ++ pkg_dest_deinit(pkg_dest); ++ ++ /* malloced in pkg_dest_list_append */ ++ free(pkg_dest); ++ iter->data = NULL; ++ } ++ void_list_deinit((void_list_t *) list); ++} ++ ++pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name, ++ const char *root_dir,const char *lists_dir) ++{ ++ int err; ++ pkg_dest_t *pkg_dest; ++ ++ /* freed in plg_dest_list_deinit */ ++ pkg_dest = malloc(sizeof(pkg_dest_t)); ++ if (pkg_dest == NULL) { ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ ++ pkg_dest_init(pkg_dest, name, root_dir,lists_dir); ++ err = void_list_append((void_list_t *) list, pkg_dest); ++ if (err) { ++ return NULL; ++ } ++ ++ return pkg_dest; ++} ++ ++int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data) ++{ ++ return void_list_push((void_list_t *) list, data); ++} ++ ++pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list) ++{ ++ return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list); ++} +Index: busybox-1.7.2/archival/libipkg/pkg_dest_list.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg_dest_list.h 2007-10-04 17:14:23.229065168 +0200 +@@ -0,0 +1,50 @@ ++/* pkg_dest_list.h - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef PKG_DEST_LIST_H ++#define PKG_DEST_LIST_H ++ ++#include "pkg_dest.h" ++ ++typedef struct pkg_dest_list_elt pkg_dest_list_elt_t; ++struct pkg_dest_list_elt ++{ ++ pkg_dest_list_elt_t *next; ++ pkg_dest_t *data; ++}; ++ ++typedef struct pkg_dest_list pkg_dest_list_t; ++struct pkg_dest_list ++{ ++ pkg_dest_list_elt_t pre_head; ++ pkg_dest_list_elt_t *head; ++ pkg_dest_list_elt_t *tail; ++}; ++ ++int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data); ++void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt); ++ ++int pkg_dest_list_init(pkg_dest_list_t *list); ++void pkg_dest_list_deinit(pkg_dest_list_t *list); ++ ++pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name, ++ const char *root_dir,const char* lists_dir); ++int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data); ++pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list); ++ ++#endif ++ +Index: busybox-1.7.2/archival/libipkg/pkg_extract.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg_extract.c 2007-10-04 17:14:23.245066087 +0200 +@@ -0,0 +1,224 @@ ++/* pkg_extract.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++#include ++#include ++#include ++ ++#include "pkg_extract.h" ++ ++#include "libbb.h" ++#include "file_util.h" ++#include "sprintf_alloc.h" ++#include "unarchive.h" ++ ++#define IPKG_CONTROL_ARCHIVE "control.tar.gz" ++#define IPKG_DATA_ARCHIVE "data.tar.gz" ++#define IPKG_CONTROL_FILE "control" ++ ++static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename) ++{ ++ archive_handle_t *archive; ++ char *path; ++ ++ sprintf_alloc(&path, "%s/", dir); ++ archive = init_handle(); ++ archive->src_fd = xopen(pkg->local_filename, O_RDONLY); ++ archive->filter = filter_accept_list; ++ llist_add_to(&(archive->accept), (char *)filename); ++ archive->buffer = path; ++ archive->action_data = data_extract_all_prefix; ++ archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL; ++ while( get_header_tar_gz(archive) == EXIT_SUCCESS ); ++ close(archive->src_fd); ++ free(archive->accept); ++ free(archive); ++ free(path); ++} ++ ++static void data_extract_file_name_to_buffer(archive_handle_t *archive) ++{ ++ unsigned int size = strlen(archive->file_header->name) + 2; ++ ++ if (archive->buffer == NULL) { ++ archive->buffer = xmalloc(size); ++ strcpy(archive->buffer, archive->file_header->name); ++ } else { ++ size += strlen(archive->buffer); ++ archive->buffer = xrealloc(archive->buffer, size); ++ strcat(archive->buffer, archive->file_header->name); ++ } ++ strcat(archive->buffer, "\n"); ++ data_skip(archive); ++} ++ ++int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream) ++{ ++ archive_handle_t *archive; ++ char *name; ++ ++ extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE); ++ sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE); ++ archive = init_handle(); ++ archive->src_fd = xopen(name, O_RDONLY); ++ archive->filter = filter_accept_list; ++ llist_add_to(&(archive->accept), "./" IPKG_CONTROL_FILE); ++ archive->action_data = data_extract_to_buffer; ++ while( get_header_tar_gz(archive) == EXIT_SUCCESS ); ++ close(archive->src_fd); ++ fputs(archive->buffer, stream); ++ free(archive->buffer); ++ free(archive->accept); ++ free(archive); ++ free(name); ++ ++ return 0; ++} ++ ++int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir) ++{ ++ return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, ""); ++} ++ ++int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix) ++{ ++ archive_handle_t *archive; ++ char *name; ++ char *path; ++ ++ extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE); ++ sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE); ++ sprintf_alloc(&path, "%s/%s", dir, prefix); ++ archive = init_handle(); ++ archive->src_fd = xopen(name, O_RDONLY); ++ archive->filter = filter_accept_all; ++ archive->buffer = path; ++ archive->action_data = data_extract_all_prefix; ++ archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL; ++ while( get_header_tar_gz(archive) == EXIT_SUCCESS ); ++ close(archive->src_fd); ++ free(archive); ++ free(path); ++ free(name); ++ ++ return 0; ++} ++ ++int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir) ++{ ++ archive_handle_t *archive; ++ char *name; ++ char *path; ++ ++ extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE); ++ sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE); ++ sprintf_alloc(&path, "%s/", dir); ++ archive = init_handle(); ++ archive->src_fd = xopen(name, O_RDONLY); ++ archive->filter = filter_accept_all; ++ archive->buffer = path; ++ archive->action_data = data_extract_all_prefix; ++ archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL; ++ while( get_header_tar_gz(archive) == EXIT_SUCCESS ); ++ close(archive->src_fd); ++ free(archive); ++ free(path); ++ free(name); ++ ++ return 0; ++} ++ ++int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name) ++{ ++ int err=0; ++ char *line, *data_file; ++ FILE *file; ++ FILE *tmp; ++ ++ file = fopen(file_name, "w"); ++ if (file == NULL) { ++ fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n", ++ __FUNCTION__, file_name); ++ return EINVAL; ++ } ++ ++ tmp = tmpfile(); ++ if (pkg->installed_files) { ++ str_list_elt_t *elt; ++ for (elt = pkg->installed_files->head; elt; elt = elt->next) { ++ fprintf(file, "%s\n", elt->data); ++ } ++ } else { ++ err = pkg_extract_data_file_names_to_stream(pkg, tmp); ++ if (err) { ++ fclose(file); ++ fclose(tmp); ++ return err; ++ } ++ ++ /* Fixup data file names by removing the initial '.' */ ++ rewind(tmp); ++ while (1) { ++ line = file_read_line_alloc(tmp); ++ if (line == NULL) { ++ break; ++ } ++ ++ data_file = line; ++ if (*data_file == '.') { ++ data_file++; ++ } ++ ++ if (*data_file != '/') { ++ fputs("/", file); ++ } ++ ++ /* I have no idea why, but this is what dpkg does */ ++ if (strcmp(data_file, "/\n") == 0) { ++ fputs("/.\n", file); ++ } else { ++ fputs(data_file, file); ++ } ++ } ++ } ++ fclose(tmp); ++ fclose(file); ++ ++ return err; ++} ++ ++int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file) ++{ ++ archive_handle_t *archive; ++ char *name; ++ ++ extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE); ++ sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE); ++ archive = init_handle(); ++ archive->src_fd = xopen(name, O_RDONLY); ++ archive->filter = filter_accept_all; ++ archive->action_data = data_extract_file_name_to_buffer; ++ while( get_header_tar_gz(archive) == EXIT_SUCCESS ); ++ close(archive->src_fd); ++ fputs(archive->buffer, file); ++ free(archive->buffer); ++ free(archive); ++ free(name); ++ ++ return 0; ++} +Index: busybox-1.7.2/archival/libipkg/pkg_extract.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg_extract.h 2007-10-04 17:14:23.265067225 +0200 +@@ -0,0 +1,32 @@ ++/* pkg_extract.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef PKG_EXTRACT_H ++#define PKG_EXTRACT_H ++ ++#include "pkg.h" ++ ++int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream); ++int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir); ++int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, ++ const char *dir, ++ const char *prefix); ++int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir); ++int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name); ++int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file); ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/pkg.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg.h 2007-10-04 17:22:15.623985424 +0200 +@@ -0,0 +1,229 @@ ++/* pkg.h - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef PKG_H ++#define PKG_H ++ ++#include ++#include ++#include ++ ++#include "pkg_vec.h" ++#include "str_list.h" ++#include "pkg_src.h" ++#include "pkg_dest.h" ++#include "ipkg_conf.h" ++#include "conffile_list.h" ++ ++struct ipkg_conf; ++ ++/* I think "Size" is currently the shortest field name */ ++#define PKG_MINIMUM_FIELD_NAME_LEN 4 ++ ++enum pkg_state_want ++{ ++ SW_UNKNOWN = 1, ++ SW_INSTALL, ++ SW_DEINSTALL, ++ SW_PURGE, ++ SW_LAST_STATE_WANT ++}; ++typedef enum pkg_state_want pkg_state_want_t; ++ ++enum pkg_state_flag ++{ ++ SF_OK = 0, ++ SF_REINSTREQ = 1, ++ SF_HOLD = 2, /* do not upgrade version */ ++ SF_REPLACE = 4, /* replace this package */ ++ SF_NOPRUNE = 8, /* do not remove obsolete files */ ++ SF_PREFER = 16, /* prefer this version */ ++ SF_OBSOLETE = 32, /* old package in upgrade pair */ ++ SF_MARKED = 64, /* temporary mark */ ++ SF_FILELIST_CHANGED = 128, /* needs filelist written */ ++ SF_USER = 256, ++ SF_LAST_STATE_FLAG ++}; ++typedef enum pkg_state_flag pkg_state_flag_t; ++#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER) ++ ++enum pkg_state_status ++{ ++ SS_NOT_INSTALLED = 1, ++ SS_UNPACKED, ++ SS_HALF_CONFIGURED, ++ SS_INSTALLED, ++ SS_HALF_INSTALLED, ++ SS_CONFIG_FILES, ++ SS_POST_INST_FAILED, ++ SS_REMOVAL_FAILED, ++ SS_LAST_STATE_STATUS ++}; ++typedef enum pkg_state_status pkg_state_status_t; ++ ++struct abstract_pkg{ ++ char * name; ++ int dependencies_checked; ++ pkg_vec_t * pkgs; ++ pkg_state_status_t state_status; ++ pkg_state_flag_t state_flag; ++ struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */ ++ abstract_pkg_vec_t * provided_by; ++ abstract_pkg_vec_t * replaced_by; ++}; ++ ++#include "pkg_depends.h" ++ ++/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways: ++ ++ The 3 version fields should go into a single version struct. (This ++ is especially important since, currently, pkg->version can easily ++ be mistaken for pkg_verson_str_alloc(pkg) although they are very ++ distinct. This has been the source of multiple bugs. ++ ++ The 3 state fields could possibly also go into their own struct. ++ ++ All fields which deal with lists of packages, (Depends, ++ Pre-Depends, Provides, Suggests, Recommends, Enhances), should each ++ be handled by a single struct in pkg_t ++ ++ All string fields for which there is a small set of possible ++ values, (section, maintainer, architecture, maybe version?), that ++ are reused among different packages -- for all such packages we ++ should move from "char *"s to some atom datatype to share data ++ storage and use less memory. We might even do reference counting, ++ but probably not since most often we only create new pkg_t structs, ++ we don't often free them. */ ++struct pkg ++{ ++ char *name; ++ unsigned long epoch; ++ char *version; ++ char *revision; ++ char *familiar_revision; ++ pkg_src_t *src; ++ pkg_dest_t *dest; ++ char *architecture; ++ char *section; ++ char *maintainer; ++ char *description; ++ pkg_state_want_t state_want; ++ pkg_state_flag_t state_flag; ++ pkg_state_status_t state_status; ++ char **depends_str; ++ int depends_count; ++ char **pre_depends_str; ++ int pre_depends_count; ++ char **recommends_str; ++ int recommends_count; ++ char **suggests_str; ++ int suggests_count; ++ compound_depend_t * depends; ++ ++ /* Abhaya: new conflicts */ ++ char **conflicts_str; ++ compound_depend_t * conflicts; ++ int conflicts_count; ++ ++ char **replaces_str; ++ int replaces_count; ++ abstract_pkg_t ** replaces; ++ ++ char **provides_str; ++ int provides_count; ++ abstract_pkg_t ** provides; ++ ++ abstract_pkg_t *parent; ++ ++ pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */ ++ ++ char *filename; ++ char *local_filename; ++ char *url; ++ char *tmp_unpack_dir; ++ char *md5sum; ++ char *size; ++ char *installed_size; ++ char *priority; ++ char *source; ++ conffile_list_t conffiles; ++ time_t installed_time; ++ /* As pointer for lazy evaluation */ ++ str_list_t *installed_files; ++ /* XXX: CLEANUP: I'd like to perhaps come up with a better ++ mechanism to avoid the problem here, (which is that the ++ installed_files list was being freed from an inner loop while ++ still being used within an outer loop. */ ++ int installed_files_ref_cnt; ++ int essential; ++ int arch_priority; ++/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */ ++ int provided_by_hand; ++}; ++ ++pkg_t *pkg_new(void); ++int pkg_init(pkg_t *pkg); ++void pkg_deinit(pkg_t *pkg); ++int pkg_init_from_file(pkg_t *pkg, const char *filename); ++abstract_pkg_t *abstract_pkg_new(void); ++int abstract_pkg_init(abstract_pkg_t *ab_pkg); ++ ++/* ++ * merges fields from newpkg into oldpkg. ++ * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero ++ */ ++int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status); ++ ++char *pkg_version_str_alloc(pkg_t *pkg); ++ ++int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg); ++int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b); ++int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b); ++ ++char * pkg_formatted_info(pkg_t *pkg ); ++char * pkg_formatted_field(pkg_t *pkg, const char *field ); ++ ++void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg); ++ ++void pkg_print_info(pkg_t *pkg, FILE *file); ++void pkg_print_status(pkg_t * pkg, FILE * file); ++void pkg_print_field(pkg_t *pkg, FILE *file, const char *field); ++str_list_t *pkg_get_installed_files(pkg_t *pkg); ++int pkg_free_installed_files(pkg_t *pkg); ++int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg); ++conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name); ++int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg, ++ const char *script, const char *args); ++ ++/* enum mappings */ ++char *pkg_state_want_to_str(pkg_state_want_t sw); ++pkg_state_want_t pkg_state_want_from_str(char *str); ++char *pkg_state_flag_to_str(pkg_state_flag_t sf); ++pkg_state_flag_t pkg_state_flag_from_str(char *str); ++char *pkg_state_status_to_str(pkg_state_status_t ss); ++pkg_state_status_t pkg_state_status_from_str(char *str); ++ ++int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op); ++ ++int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg); ++int pkg_info_preinstall_check(ipkg_conf_t *conf); ++int pkg_free_installed_files(pkg_t *pkg); ++ ++int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg); ++int pkg_write_changed_filelists(ipkg_conf_t *conf); ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/pkg_hash.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg_hash.c 2007-10-04 17:14:23.329070878 +0200 +@@ -0,0 +1,616 @@ ++/* ipkg_hash.c - the itsy package management system ++ ++ Steven M. Ayer ++ ++ Copyright (C) 2002 Compaq Computer Corporation ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++#include ++#include ++#include ++#include ++ ++#include "hash_table.h" ++#include "pkg.h" ++#include "ipkg_message.h" ++#include "pkg_vec.h" ++#include "pkg_hash.h" ++#include "pkg_parse.h" ++#include "ipkg_utils.h" ++ ++static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name); ++ ++/* ++ * this will talk to both feeds-lists files and installed status files ++ * example api: ++ * ++ * hash_table_t hash; ++ * pkg_hash_init(name, &hash, 1000); ++ * pkg_hash_add_from_file(); ++ * ++ * the query function is just there as a shell to prove to me that this ++ * sort of works, but isn't far from doing something useful ++ * ++ * -sma, 12/21/01 ++ * modified: CDW 3 Jan. 2002 ++ */ ++ ++ ++ ++int pkg_hash_init(const char *name, hash_table_t *hash, int len) ++{ ++ return hash_table_init(name, hash, len); ++} ++ ++void pkg_hash_deinit(hash_table_t *hash) ++{ ++ hash_table_deinit(hash); ++} ++ ++ ++/* Find the default arch for a given package status file if none is given. */ ++static char *pkg_get_default_arch(ipkg_conf_t *conf) ++{ ++ nv_pair_list_elt_t *l; ++ char *def_arch = HOST_CPU_STR; /* Default arch */ ++ int def_prio = 0; /* Other archs override this */ ++ ++ l = conf->arch_list.head; ++ ++ while (l) { ++ nv_pair_t *nv = l->data; ++ int priority = strtol(nv->value, NULL, 0); ++ ++ /* Check if this arch has higher priority, and is valid */ ++ if ((priority > def_prio) && ++ (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) { ++ /* Our new default */ ++ def_prio = priority; ++ def_arch = nv->name; ++ } ++ l = l->next; ++ } ++ ++ return strdup(def_arch); ++} ++ ++int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name, ++ pkg_src_t *src, pkg_dest_t *dest, int is_status_file) ++{ ++ hash_table_t *hash = &conf->pkg_hash; ++ char **raw; ++ char **raw_start; ++ pkg_t *pkg; ++ ++ raw = raw_start = read_raw_pkgs_from_file(file_name); ++ if (!raw) ++ return -ENOMEM; ++ ++ while(*raw){ /* don't worry, we'll increment raw in the parsing function */ ++ pkg = pkg_new(); ++ if (!pkg) ++ return -ENOMEM; ++ ++ if (pkg_parse_raw(pkg, &raw, src, dest) == 0) { ++ if (!pkg->architecture) { ++ char *version_str = pkg_version_str_alloc(pkg); ++ pkg->architecture = pkg_get_default_arch(conf); ++ ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n", ++ pkg->name, version_str, pkg->architecture); ++ free(version_str); ++ } ++ hash_insert_pkg(hash, pkg, is_status_file,conf); ++ } else { ++ free(pkg); ++ } ++ } ++ ++ /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up ++ memory after read_raw_pkgs_from_file */ ++ raw = raw_start; ++ while (*raw) { ++ free(*raw++); ++ } ++ free(raw_start); ++ return 0; ++} ++ ++abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name) ++{ ++ return (abstract_pkg_t *)hash_table_get(hash, pkg_name); ++} ++ ++abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name) ++{ ++ abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name); ++ if (apkg) ++ return NULL; ++ return apkg->provided_by; ++} ++ ++ ++pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg, ++ int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet) ++{ ++ int i, j; ++ int nprovides = 0; ++ int nmatching = 0; ++ pkg_vec_t *matching_pkgs = pkg_vec_alloc(); ++ abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc(); ++ abstract_pkg_vec_t *provided_apkg_vec; ++ abstract_pkg_t **provided_apkgs; ++ abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc(); ++ pkg_t *latest_installed_parent = NULL; ++ pkg_t *latest_matching = NULL; ++ pkg_t *held_pkg = NULL; ++ pkg_t *good_pkg_by_name = NULL; ++ ++ if (matching_apkgs == NULL || providers == NULL || ++ apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0)) ++ return NULL; ++ ++ ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name); ++ ++ provided_apkg_vec = apkg->provided_by; ++ nprovides = provided_apkg_vec->len; ++ provided_apkgs = provided_apkg_vec->pkgs; ++ if (nprovides > 1) ++ ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides); ++ ++ /* accumulate all the providers */ ++ for (i = 0; i < nprovides; i++) { ++ abstract_pkg_t *provider_apkg = provided_apkgs[i]; ++ ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name); ++ abstract_pkg_vec_insert(providers, provider_apkg); ++ } ++ nprovides = providers->len; ++ ++ for (i = 0; i < nprovides; i++) { ++ abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i); ++ abstract_pkg_t *replacement_apkg = NULL; ++ pkg_vec_t *vec; ++ ++ if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) { ++ replacement_apkg = provider_apkg->replaced_by->pkgs[0]; ++ if (provider_apkg->replaced_by->len > 1) { ++ ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n", ++ provider_apkg->name, replacement_apkg->name); ++ } ++ } ++ ++ if (replacement_apkg) ++ ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n", ++ replacement_apkg->name, provider_apkg->name); ++ ++ if (replacement_apkg && (replacement_apkg != provider_apkg)) { ++ if (abstract_pkg_vec_contains(providers, replacement_apkg)) ++ continue; ++ else ++ provider_apkg = replacement_apkg; ++ } ++ ++ if (!(vec = provider_apkg->pkgs)) { ++ ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name); ++ continue; ++ } ++ ++ ++ /* now check for supported architecture */ ++ { ++ int max_count = 0; ++ ++ /* count packages matching max arch priority and keep track of last one */ ++ for (j = 0; j < vec->len; j++) { ++ pkg_t *maybe = vec->pkgs[j]; ++ ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n", ++ maybe->name, maybe->architecture, maybe->arch_priority, maybe->version); ++ if (maybe->arch_priority > 0) { ++ max_count++; ++ abstract_pkg_vec_insert(matching_apkgs, maybe->parent); ++ pkg_vec_insert(matching_pkgs, maybe); ++ } ++ } ++ } ++ } ++ ++ if (matching_pkgs->len > 1) ++ pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare); ++ if (matching_apkgs->len > 1) ++ abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare); ++ ++/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the ++ needed package. In this case, I would return it for install, otherwise I will continue with the procedure */ ++/* The problem is what to do when there are more than a mathing package, with the same name and several version ? ++ Until now I always got the latest, but that breaks the downgrade option. ++ If I stop at the first one, I would probably miss the new ones ++ Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file, ++ or from a Packages feed. ++ It it is from a file it always need to be checked whatever version I have in feeds or everywhere, according to force-down or whatever options*/ ++/*Pigi*/ ++ ++ for (i = 0; i < matching_pkgs->len; i++) { ++ pkg_t *matching = matching_pkgs->pkgs[i]; ++ if (constraint_fcn(matching, cdata)) { /* We found it */ ++ ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ; ++ good_pkg_by_name = matching; ++ if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */ ++ break; ++ } ++ } ++ ++ ++ for (i = 0; i < matching_pkgs->len; i++) { ++ pkg_t *matching = matching_pkgs->pkgs[i]; ++ latest_matching = matching; ++ if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED) ++ latest_installed_parent = matching; ++ if (matching->state_flag & (SF_HOLD|SF_PREFER)) { ++ if (held_pkg) ++ ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n", ++ held_pkg->name, matching->name); ++ held_pkg = matching; ++ } ++ } ++ ++ if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) { ++ ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n", ++ apkg->name, matching_apkgs->len); ++ for (i = 0; i < matching_apkgs->len; i++) { ++ abstract_pkg_t *matching = matching_apkgs->pkgs[i]; ++ ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name); ++ } ++ ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n"); ++ } ++ ++ if (matching_apkgs->len > 1 && conf->verbosity > 1) { ++ ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n", ++ __FUNCTION__, apkg->name, matching_pkgs->len); ++ for (i = 0; i < matching_pkgs->len; i++) { ++ pkg_t *matching = matching_pkgs->pkgs[i]; ++ ipkg_message(conf, IPKG_INFO, " %s %s %s\n", ++ matching->name, matching->version, matching->architecture); ++ } ++ } ++ ++ nmatching = matching_apkgs->len; ++ ++ pkg_vec_free(matching_pkgs); ++ abstract_pkg_vec_free(matching_apkgs); ++ abstract_pkg_vec_free(providers); ++ ++ if (good_pkg_by_name) { /* We found a good candidate, we will install it */ ++ return good_pkg_by_name; ++ } ++ if (held_pkg) { ++ ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name); ++ return held_pkg; ++ } ++ if (latest_installed_parent) { ++ ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name); ++ return latest_installed_parent; ++ } ++ if (nmatching > 1) { ++ ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching); ++ return NULL; ++ } ++ if (latest_matching) { ++ ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n", ++ latest_matching->name, latest_matching->version, latest_matching->architecture); ++ return latest_matching; ++ } ++ return NULL; ++} ++ ++static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata) ++{ ++ const char *name = (const char *)cdata; ++ if (strcmp(pkg->name, name) == 0) ++ return 1; ++ else ++ return 0; ++} ++ ++pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name) ++{ ++ hash_table_t *hash = &conf->pkg_hash; ++ abstract_pkg_t *apkg = NULL; ++ ++ if (!(apkg = abstract_pkg_fetch_by_name(hash, name))) ++ return NULL; ++ ++ return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0); ++} ++ ++ ++pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash, ++ const char *pkg_name, ++ const char * version) ++{ ++ pkg_vec_t * vec; ++ register int i; ++ char *version_str = NULL; ++ ++ if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) ++ return NULL; ++ ++ for(i = 0; i < vec->len; i++) { ++ version_str = pkg_version_str_alloc(vec->pkgs[i]); ++ if(!strcmp(version_str, version)) { ++ free(version_str); ++ break; ++ } ++ free(version_str); ++ } ++ ++ if(i == vec->len) ++ return NULL; ++ ++ return vec->pkgs[i]; ++} ++ ++pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash, ++ const char *pkg_name, ++ pkg_dest_t *dest) ++{ ++ pkg_vec_t * vec; ++ register int i; ++ ++ if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) { ++ return NULL; ++ } ++ ++ for(i = 0; i < vec->len; i++) ++ if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) { ++ return vec->pkgs[i]; ++ } ++ return NULL; ++} ++ ++pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash, ++ const char *pkg_name) ++{ ++ pkg_vec_t * vec; ++ register int i; ++ ++ if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){ ++ return NULL; ++ } ++ ++ for(i = 0; i < vec->len; i++) ++ if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){ ++ return vec->pkgs[i]; ++ } ++ ++ return NULL; ++} ++ ++pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name) ++{ ++ abstract_pkg_t * ab_pkg; ++ ++ if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){ ++ return NULL; ++ } ++ ++ if (ab_pkg->pkgs) { ++ return ab_pkg->pkgs; ++ } else if (ab_pkg->provided_by) { ++ abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0); ++ if (abpkg != NULL){ ++ return abpkg->pkgs; ++ } else { ++ return ab_pkg->pkgs; ++ } ++ } else { ++ return NULL; ++ } ++} ++ ++static int pkg_compare_names(const void *p1, const void *p2) ++{ ++ const pkg_t *pkg1 = *(const pkg_t **)p1; ++ const pkg_t *pkg2 = *(const pkg_t **)p2; ++ if (pkg1->name == NULL) ++ return 1; ++ if (pkg2->name == NULL) ++ return -1; ++ return(strcmp(pkg1->name, pkg2->name)); ++} ++ ++ ++static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data) ++{ ++ int j; ++ abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry; ++ pkg_vec_t *all = (pkg_vec_t *)data; ++ pkg_vec_t *pkg_vec = ab_pkg->pkgs; ++ if (pkg_vec) { ++ for (j = 0; j < pkg_vec->len; j++) { ++ pkg_t *pkg = pkg_vec->pkgs[j]; ++ pkg_vec_insert(all, pkg); ++ } ++ } ++} ++ ++void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all) ++{ ++ hash_table_foreach(hash, pkg_hash_fetch_available_helper, all); ++ qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names); ++} ++ ++static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data) ++{ ++ abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry; ++ pkg_vec_t *all = (pkg_vec_t *)data; ++ pkg_vec_t *pkg_vec = ab_pkg->pkgs; ++ int j; ++ if (pkg_vec) { ++ for (j = 0; j < pkg_vec->len; j++) { ++ pkg_t *pkg = pkg_vec->pkgs[j]; ++ if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) { ++ pkg_vec_insert(all, pkg); ++ } ++ } ++ } ++} ++void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all) ++{ ++ hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all); ++ qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names); ++} ++ ++static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data) ++{ ++ int i; ++ pkg_t *pkg; ++ abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry; ++ ipkg_conf_t *conf = (ipkg_conf_t *)data; ++ abstract_pkg_t ** dependents = ab_pkg->depended_upon_by; ++ fprintf(stdout, "%s\n", ab_pkg->name); ++ i = 0; ++ if (dependents != NULL) ++ while (dependents [i] != NULL) ++ printf ("\tdepended upon by - %s\n", dependents [i ++]->name); ++ dependents = ab_pkg->provided_by->pkgs; ++ i = 0; ++ if (dependents != NULL) ++ while (dependents [i] != NULL && i < ab_pkg->provided_by->len) ++ printf ("\tprovided by - %s\n", dependents [i ++]->name); ++ pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name); ++ if (pkg) { ++ i = 0; ++ while (i < pkg->depends_count) ++ printf ("\tdepends on - %s\n", pkg->depends_str [i ++]); ++ } ++} ++void pkg_hash_dump(hash_table_t *hash, void *data) ++{ ++ ++ printf ("\n\n+=+%s+=+\n\n", __FUNCTION__); ++ hash_table_foreach(hash, pkg_hash_dump_helper, data); ++ printf ("\n+=+%s+=+\n\n", __FUNCTION__); ++} ++ ++abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name) ++{ ++ abstract_pkg_t * ab_pkg; ++ ++ if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))) ++ ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name); ++ ++ return ab_pkg; ++} ++ ++pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf) ++{ ++ abstract_pkg_t * ab_pkg; ++ int arch_priority; ++ ++ if(!pkg) ++ return pkg; ++ ++ arch_priority = pkg->arch_priority; ++ ++ if (buildDepends(hash, pkg)<0){ ++ fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__); ++ return NULL; ++ } ++ ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name); ++ ++ if (set_status) { ++ if (pkg->state_status == SS_INSTALLED) { ++ ab_pkg->state_status = SS_INSTALLED; ++ } else if (pkg->state_status == SS_UNPACKED) { ++ ab_pkg->state_status = SS_UNPACKED; ++ } ++ } ++ ++ if(!ab_pkg->pkgs) ++ ab_pkg->pkgs = pkg_vec_alloc(); ++ ++ /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */ ++ pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf ); ++ pkg->parent = ab_pkg; ++ ++ if (buildProvides(hash, ab_pkg, pkg)<0){ ++ fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__); ++ return NULL; ++ } ++ /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */ ++ if (buildConflicts(hash, ab_pkg, pkg)<0){ ++ fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__); ++ return NULL; ++ } ++ if (buildReplaces(hash, ab_pkg, pkg)<0) { ++ fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__); ++ return NULL; ++ } ++ ++ buildDependedUponBy(pkg, ab_pkg); ++ return pkg; ++} ++ ++/* ++ * this will assume that we've already determined that ++ * the abstract pkg doesn't exist, 'cause we should know these things... ++ */ ++static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name) ++{ ++ abstract_pkg_t * ab_pkg; ++ ++ ab_pkg = abstract_pkg_new(); ++ if (ab_pkg == NULL) { return NULL; } ++ ++ ab_pkg->name = strdup(pkg_name); ++ hash_table_insert(hash, pkg_name, ab_pkg); ++ ++ return ab_pkg; ++} ++ ++ ++pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name) ++{ ++ hash_table_t *file_hash = &conf->file_hash; ++ ++ return hash_table_get(file_hash, file_name); ++} ++ ++int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg) ++{ ++ hash_table_t *file_hash = &conf->file_hash; ++ pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name); ++ int file_name_len = strlen(file_name); ++ ++ if (file_name[file_name_len -1] == '/') ++ return 0; ++ ++ if (conf->offline_root) { ++ int len = strlen(conf->offline_root); ++ if (strncmp(file_name, conf->offline_root, len) == 0) { ++ file_name += len; ++ } ++ } ++ ++ // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name); ++ hash_table_insert(file_hash, file_name, owning_pkg); ++ if (old_owning_pkg) { ++ str_list_remove_elt(old_owning_pkg->installed_files, file_name); ++ /* mark this package to have its filelist written */ ++ old_owning_pkg->state_flag |= SF_FILELIST_CHANGED; ++ owning_pkg->state_flag |= SF_FILELIST_CHANGED; ++ } ++ return 0; ++} ++ ++ +Index: busybox-1.7.2/archival/libipkg/pkg_hash.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg_hash.h 2007-10-04 17:14:23.349072007 +0200 +@@ -0,0 +1,61 @@ ++/* pkg_hash.h - the itsy package management system ++ ++ Steven M. Ayer ++ ++ Copyright (C) 2002 Compaq Computer Corporation ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef PKG_HASH_H ++#define PKG_HASH_H ++ ++#include "pkg.h" ++#include "pkg_vec.h" ++#include "hash_table.h" ++ ++ ++int pkg_hash_init(const char *name, hash_table_t *hash, int len); ++void pkg_hash_deinit(hash_table_t *hash); ++void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data); ++ ++void pkg_hash_dump(hash_table_t *hash, void *data); ++void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available); ++ ++int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name, ++ pkg_src_t *src, pkg_dest_t *dest, int is_status_file); ++pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf); ++ ++abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name); ++abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name); ++pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name); ++void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed); ++pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash, ++ const char *pkg_name, ++ const char * version); ++abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name); ++pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg, ++ int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet); ++pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name); ++pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash, ++ const char *pkg_name); ++pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash, ++ const char *pkg_name, ++ pkg_dest_t *dest); ++ ++pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name); ++int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg); ++ ++/* XXX: shouldn't this go in pkg_vec.[ch]? */ ++pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name); ++ ++#endif ++ +Index: busybox-1.7.2/archival/libipkg/pkg_parse.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg_parse.c 2007-10-04 17:14:23.369073144 +0200 +@@ -0,0 +1,366 @@ ++/* pkg_parse.c - the itsy package management system ++ ++ Steven M. Ayer ++ ++ Copyright (C) 2002 Compaq Computer Corporation ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++#include ++#include ++ ++#include "pkg.h" ++#include "ipkg_utils.h" ++#include "pkg_parse.h" ++ ++int isGenericFieldType(char * type, char * line) ++{ ++ if(!strncmp(line, type, strlen(type))) ++ return 1; ++ return 0; ++} ++ ++char * parseGenericFieldType(char * type, char * raw) ++{ ++ char * field_value = raw + (strlen(type) + 1); ++ return trim_alloc(field_value); ++} ++ ++void parseStatus(pkg_t *pkg, char * raw) ++{ ++ char sw_str[64], sf_str[64], ss_str[64]; ++ ++ sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str); ++ pkg->state_want = pkg_state_want_from_str(sw_str); ++ pkg->state_flag = pkg_state_flag_from_str(sf_str); ++ pkg->state_status = pkg_state_status_from_str(ss_str); ++} ++ ++char ** parseDependsString(char * raw, int * depends_count) ++{ ++ char ** depends = NULL; ++ int line_count = 0; ++ char buff[2048], * dest; ++ ++ while(raw && *raw && !isspace(*raw)) { ++ raw++; ++ } ++ ++ if(line_is_blank(raw)){ ++ *depends_count = line_count; ++ return NULL; ++ } ++ while(raw && *raw){ ++ depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1)); ++ ++ while(isspace(*raw)) raw++; ++ ++ dest = buff; ++ while((*raw != ',') && *raw) ++ *dest++ = *raw++; ++ ++ *dest = '\0'; ++ depends[line_count] = trim_alloc(buff); ++ if(depends[line_count] ==NULL) ++ return NULL; ++ line_count++; ++ if(*raw == ',') ++ raw++; ++ } ++ *depends_count = line_count; ++ return depends; ++} ++ ++void parseConffiles(pkg_t * pkg, char * raw) ++{ ++ char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */ ++ ++ if(!strncmp(raw, "Conffiles:", 10)) ++ raw += strlen("Conffiles:"); ++ ++ while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){ ++ conffile_list_append(&pkg->conffiles, file_name, md5sum); ++ /* fprintf(stderr, "%s %s ", file_name, md5sum);*/ ++ while (*raw && isspace(*raw)) { ++ raw++; ++ } ++ raw += strlen(file_name); ++ while (*raw && isspace(*raw)) { ++ raw++; ++ } ++ raw += strlen(md5sum); ++ } ++} ++ ++int parseVersion(pkg_t *pkg, char *raw) ++{ ++ char *colon, *eepochcolon; ++#ifdef USE_DEBVERSION ++ char *hyphen; ++#endif ++ unsigned long epoch; ++ ++ if (!*raw) { ++ fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__); ++ return EINVAL; ++ } ++ ++ if (strncmp(raw, "Version:", 8) == 0) { ++ raw += 8; ++ } ++ while (*raw && isspace(*raw)) { ++ raw++; ++ } ++ ++ colon= strchr(raw,':'); ++ if (colon) { ++ epoch= strtoul(raw,&eepochcolon,10); ++ if (colon != eepochcolon) { ++ fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__); ++ return EINVAL; ++ } ++ if (!*++colon) { ++ fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__); ++ return EINVAL; ++ } ++ raw= colon; ++ pkg->epoch= epoch; ++ } else { ++ pkg->epoch= 0; ++ } ++ ++ pkg->revision = ""; ++ pkg->familiar_revision = ""; ++ ++ pkg->version= malloc(strlen(raw)+1); ++ if ( pkg->version == NULL ) { ++ fprintf(stderr, "%s: out of memory \n", __FUNCTION__); ++ return ENOMEM; ++ } ++ strcpy(pkg->version, raw); ++ ++#ifdef USE_DEBVERSION ++ hyphen= strrchr(pkg->version,'-'); ++ ++ if (hyphen) { ++ *hyphen++= 0; ++ if (strncmp("fam", hyphen, 3) == 0) { ++ pkg->familiar_revision=hyphen+3; ++ hyphen= strrchr(pkg->version,'-'); ++ if (hyphen) { ++ *hyphen++= 0; ++ pkg->revision = hyphen; ++ } ++ } else { ++ pkg->revision = hyphen; ++ } ++ } ++#endif ++ ++/* ++ fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n", ++ pkg->epoch, ++ pkg->version, ++ pkg->revision, ++ pkg->familiar_revision); ++*/ ++ ++ return 0; ++} ++ ++ ++/* This code is needed to insert in first position the keyword for the aligning bug */ ++ ++int alterProvidesLine(char *raw, char *temp) ++{ ++ ++ ++ if (!*raw) { ++ fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__); ++ return -EINVAL; ++ } ++ ++ if ( temp == NULL ) { ++ fprintf(stderr, "%s: out of memory \n", __FUNCTION__); ++ return -ENOMEM; ++ } ++ ++ if (strncmp(raw, "Provides:", 9) == 0) { ++ raw += 9; ++ } ++ while (*raw && isspace(*raw)) { ++ raw++; ++ } ++ ++ snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */ ++ while (*raw) { ++ strncat( temp, raw++, 1); ++ } ++ return 0; ++ ++} ++ ++/* Some random thoughts from Carl: ++ ++ This function could be considerably simplified if we just kept ++ an array of all the generic string-valued field names, and looped ++ through those looking for a match. Also, these fields could perhaps ++ be stored in the package as an array as well, (or, probably better, ++ as an nv_pair_list_t). ++ ++ Fields which require special parsing or storage, (such as Depends: ++ and Status:) could be handled as they are now. ++*/ ++/* XXX: FEATURE: The Suggests: field needs to be changed from a string ++ to a dependency list. And, since we already have ++ Depends/Pre-Depends and need to add Conflicts, Recommends, and ++ Enhances, perhaps we could generalize all of these and save some ++ code duplication. ++*/ ++int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest) ++{ ++ int reading_conffiles, reading_description; ++ int pkg_false_provides=1; ++ char ** lines; ++ char * provide=NULL; ++ ++ pkg->src = src; ++ pkg->dest = dest; ++ ++ reading_conffiles = reading_description = 0; ++ ++ for (lines = *raw; *lines; lines++) { ++ /* fprintf(stderr, "PARSING %s\n", *lines);*/ ++ if(isGenericFieldType("Package:", *lines)) ++ pkg->name = parseGenericFieldType("Package", *lines); ++ else if(isGenericFieldType("Architecture:", *lines)) ++ pkg->architecture = parseGenericFieldType("Architecture", *lines); ++ else if(isGenericFieldType("Filename:", *lines)) ++ pkg->filename = parseGenericFieldType("Filename", *lines); ++ else if(isGenericFieldType("Section:", *lines)) ++ pkg->section = parseGenericFieldType("Section", *lines); ++ else if(isGenericFieldType("MD5sum:", *lines)) ++ pkg->md5sum = parseGenericFieldType("MD5sum", *lines); ++ /* The old ipkg wrote out status files with the wrong case for MD5sum, ++ let's parse it either way */ ++ else if(isGenericFieldType("MD5Sum:", *lines)) ++ pkg->md5sum = parseGenericFieldType("MD5Sum", *lines); ++ else if(isGenericFieldType("Size:", *lines)) ++ pkg->size = parseGenericFieldType("Size", *lines); ++ else if(isGenericFieldType("Source:", *lines)) ++ pkg->source = parseGenericFieldType("Source", *lines); ++ else if(isGenericFieldType("Installed-Size:", *lines)) ++ pkg->installed_size = parseGenericFieldType("Installed-Size", *lines); ++ else if(isGenericFieldType("Installed-Time:", *lines)) { ++ char *time_str = parseGenericFieldType("Installed-Time", *lines); ++ pkg->installed_time = strtoul(time_str, NULL, 0); ++ } else if(isGenericFieldType("Priority:", *lines)) ++ pkg->priority = parseGenericFieldType("Priority", *lines); ++ else if(isGenericFieldType("Essential:", *lines)) { ++ char *essential_value; ++ essential_value = parseGenericFieldType("Essential", *lines); ++ if (strcmp(essential_value, "yes") == 0) { ++ pkg->essential = 1; ++ } ++ free(essential_value); ++ } ++ else if(isGenericFieldType("Status", *lines)) ++ parseStatus(pkg, *lines); ++ else if(isGenericFieldType("Version", *lines)) ++ parseVersion(pkg, *lines); ++ else if(isGenericFieldType("Maintainer", *lines)) ++ pkg->maintainer = parseGenericFieldType("Maintainer", *lines); ++ else if(isGenericFieldType("Conffiles", *lines)){ ++ parseConffiles(pkg, *lines); ++ reading_conffiles = 1; ++ } ++ else if(isGenericFieldType("Description", *lines)) { ++ pkg->description = parseGenericFieldType("Description", *lines); ++ reading_conffiles = 0; ++ reading_description = 1; ++ } ++ ++ else if(isGenericFieldType("Provides", *lines)){ ++/* Here we add the internal_use to align the off by one problem between provides_str and provides */ ++ provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */ ++ if ( alterProvidesLine(*lines,provide) ){ ++ return EINVAL; ++ } ++ pkg->provides_str = parseDependsString( provide, &pkg->provides_count); ++/* Let's try to hack a bit here. ++ The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies ++ in alot of other places. We will remove it before writing down the status database */ ++ pkg_false_provides=0; ++ free(provide); ++ } ++ ++ else if(isGenericFieldType("Depends", *lines)) ++ pkg->depends_str = parseDependsString(*lines, &pkg->depends_count); ++ else if(isGenericFieldType("Pre-Depends", *lines)) ++ pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count); ++ else if(isGenericFieldType("Recommends", *lines)) ++ pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count); ++ else if(isGenericFieldType("Suggests", *lines)) ++ pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count); ++ /* Abhaya: support for conflicts */ ++ else if(isGenericFieldType("Conflicts", *lines)) ++ pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count); ++ else if(isGenericFieldType("Replaces", *lines)) ++ pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count); ++ else if(line_is_blank(*lines)) { ++ lines++; ++ break; ++ } ++ else if(**lines == ' '){ ++ if(reading_description) { ++ /* we already know it's not blank, so the rest of description */ ++ pkg->description = realloc(pkg->description, ++ strlen(pkg->description) ++ + 1 + strlen(*lines) + 1); ++ strcat(pkg->description, "\n"); ++ strcat(pkg->description, (*lines)); ++ } ++ else if(reading_conffiles) ++ parseConffiles(pkg, *lines); ++ } ++ } ++ *raw = lines; ++/* If the ipk has not a Provides line, we insert our false line */ ++ if ( pkg_false_provides==1) ++ pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count); ++ ++ if (pkg->name) { ++ return 0; ++ } else { ++ return EINVAL; ++ } ++} ++ ++int pkg_valorize_other_field(pkg_t *pkg, char ***raw) ++{ ++ char ** lines; ++ ++ for (lines = *raw; *lines; lines++) { ++ if(isGenericFieldType("Essential:", *lines)) { ++ char *essential_value; ++ essential_value = parseGenericFieldType("Essential", *lines); ++ if (strcmp(essential_value, "yes") == 0) { ++ pkg->essential = 1; ++ } ++ free(essential_value); ++ } ++ } ++ *raw = lines; ++ ++ return 0; ++} +Index: busybox-1.7.2/archival/libipkg/pkg_parse.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg_parse.h 2007-10-04 17:14:23.389074295 +0200 +@@ -0,0 +1,31 @@ ++/* pkg_parse.h - the itsy package management system ++ ++ Steven M. Ayer ++ ++ Copyright (C) 2002 Compaq Computer Corporation ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef PKG_PARSE_H ++#define PKG_PARSE_H ++ ++int isGenericFieldType(char * type, char * line); ++char * parseGenericFieldType(char * type, char * raw); ++void parseStatus(pkg_t *pkg, char * raw); ++int parseVersion(pkg_t *pkg, char *raw); ++char ** parseDependsString(char * raw, int * depends_count); ++int parseVersion(pkg_t *pkg, char *raw); ++void parseConffiles(pkg_t * pkg, char * raw); ++int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest); ++int pkg_valorize_other_field(pkg_t *pkg, char ***raw); ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/pkg_src.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg_src.c 2007-10-04 17:14:23.433076797 +0200 +@@ -0,0 +1,43 @@ ++/* pkg_src.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++ ++#include "pkg_src.h" ++#include "str_util.h" ++ ++int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip) ++{ ++ src->gzip = gzip; ++ src->name = str_dup_safe (name); ++ src->value = str_dup_safe (base_url); ++ if (extra_data) ++ src->extra_data = str_dup_safe (extra_data); ++ else ++ src->extra_data = NULL; ++ return 0; ++} ++ ++void pkg_src_deinit(pkg_src_t *src) ++{ ++ free (src->name); ++ free (src->value); ++ if (src->extra_data) ++ free (src->extra_data); ++} ++ ++ +Index: busybox-1.7.2/archival/libipkg/pkg_src.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg_src.h 2007-10-04 17:14:23.457078165 +0200 +@@ -0,0 +1,34 @@ ++/* pkg_src.h - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef PKG_SRC_H ++#define PKG_SRC_H ++ ++#include "nv_pair.h" ++ ++typedef struct ++{ ++ char *name; ++ char *value; ++ char *extra_data; ++ int gzip; ++} pkg_src_t; ++ ++int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip); ++void pkg_src_deinit(pkg_src_t *src); ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/pkg_src_list.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg_src_list.c 2007-10-04 17:14:23.481079530 +0200 +@@ -0,0 +1,75 @@ ++/* pkg_src_list.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++ ++#include "pkg_src_list.h" ++#include "void_list.h" ++ ++int pkg_src_list_init(pkg_src_list_t *list) ++{ ++ return void_list_init((void_list_t *) list); ++} ++ ++void pkg_src_list_deinit(pkg_src_list_t *list) ++{ ++ pkg_src_list_elt_t *iter; ++ pkg_src_t *pkg_src; ++ ++ for (iter = list->head; iter; iter = iter->next) { ++ pkg_src = iter->data; ++ pkg_src_deinit(pkg_src); ++ ++ /* malloced in pkg_src_list_append */ ++ free(pkg_src); ++ iter->data = NULL; ++ } ++ void_list_deinit((void_list_t *) list); ++} ++ ++pkg_src_t *pkg_src_list_append(pkg_src_list_t *list, ++ const char *name, const char *base_url, const char *extra_data, ++ int gzip) ++{ ++ int err; ++ ++ /* freed in pkg_src_list_deinit */ ++ pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t)); ++ ++ if (pkg_src == NULL) { ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ pkg_src_init(pkg_src, name, base_url, extra_data, gzip); ++ ++ err = void_list_append((void_list_t *) list, pkg_src); ++ if (err) { ++ return NULL; ++ } ++ ++ return pkg_src; ++} ++ ++int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data) ++{ ++ return void_list_push((void_list_t *) list, data); ++} ++ ++pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list) ++{ ++ return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list); ++} +Index: busybox-1.7.2/archival/libipkg/pkg_src_list.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg_src_list.h 2007-10-04 17:14:23.497080447 +0200 +@@ -0,0 +1,57 @@ ++/* pkg_src_list.h - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef PKG_SRC_LIST_H ++#define PKG_SRC_LIST_H ++ ++#include "pkg_src.h" ++ ++typedef struct pkg_src_list_elt pkg_src_list_elt_t; ++struct pkg_src_list_elt ++{ ++ pkg_src_list_elt_t *next; ++ pkg_src_t *data; ++}; ++ ++typedef struct pkg_src_list pkg_src_list_t; ++struct pkg_src_list ++{ ++ pkg_src_list_elt_t pre_head; ++ pkg_src_list_elt_t *head; ++ pkg_src_list_elt_t *tail; ++}; ++ ++static inline int pkg_src_list_empty(pkg_src_list_t *list) ++{ ++ if (list->head == NULL) ++ return 1; ++ else ++ return 0; ++} ++ ++int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data); ++void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt); ++ ++int pkg_src_list_init(pkg_src_list_t *list); ++void pkg_src_list_deinit(pkg_src_list_t *list); ++ ++pkg_src_t *pkg_src_list_append(pkg_src_list_t *list, const char *name, const char *root_dir, const char *extra_data, int gzip); ++int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data); ++pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list); ++ ++#endif ++ +Index: busybox-1.7.2/archival/libipkg/pkg_vec.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg_vec.c 2007-10-04 17:14:23.513081356 +0200 +@@ -0,0 +1,230 @@ ++/* pkg_vec.c - the itsy package management system ++ ++ Steven M. Ayer ++ ++ Copyright (C) 2002 Compaq Computer Corporation ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include ++#include ++#include "xregex.h" ++#include "ipkg.h" ++#include "pkg.h" ++ ++pkg_vec_t * pkg_vec_alloc(void) ++{ ++ pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t)); ++ if (!vec) { ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ vec->pkgs = NULL; ++ vec->len = 0; ++ ++ return vec; ++} ++ ++void pkg_vec_free(pkg_vec_t *vec) ++{ ++ free(vec->pkgs); ++ free(vec); ++} ++ ++/* ++ * assumption: all names in a vector are identical ++ * assumption: all version strings are trimmed, ++ * so identical versions have identical version strings, ++ * implying identical packages; let's marry these ++ */ ++pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf) ++{ ++ int i; ++ int found = 0; ++ ++ /* look for a duplicate pkg by name, version, and architecture */ ++ for (i = 0; i < vec->len; i++){ ++ ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n", ++ __FUNCTION__, pkg->name, pkg->version, pkg->architecture, ++ vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture ); ++ if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0) ++ && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0) ++ && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) { ++ found = 1; ++ ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n", ++ __FUNCTION__, pkg->name, pkg->version, pkg->architecture); ++ break; ++ } ++ } ++ ++ /* we didn't find one, add it */ ++ if (!found){ ++ ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n", ++ __FUNCTION__, pkg->name, pkg->version, pkg->architecture); ++ ++ vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *)); ++ vec->pkgs[vec->len] = pkg; ++ vec->len++; ++ return pkg; ++ } ++ /* update the one that we have */ ++ else { ++ ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s", ++ __FUNCTION__, pkg->name, pkg->version, pkg->architecture); ++ if (set_status) { ++ /* this is from the status file, so need to merge with existing database */ ++ ipkg_message(conf, IPKG_DEBUG2, " with set_status\n"); ++ pkg_merge(vec->pkgs[i], pkg, set_status); ++ /* XXX: CLEANUP: It's not so polite to free something here ++ that was passed in from above. */ ++ pkg_deinit(pkg); ++ free(pkg); ++ } else { ++ ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n"); ++ /* just overwrite the old one */ ++ pkg_deinit(vec->pkgs[i]); ++ free(vec->pkgs[i]); ++ vec->pkgs[i] = pkg; ++ } ++ return vec->pkgs[i]; ++ } ++} ++ ++void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg) ++{ ++ int i; ++ int found = 0; ++ ++ /* look for a duplicate pkg by name, version, and architecture */ ++ for (i = 0; i < vec->len; i++) ++ if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0) ++ && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0) ++ && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) { ++ found = 1; ++ break; ++ } ++ ++ /* we didn't find one, add it */ ++ if(!found){ ++ vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *)); ++ *(const pkg_t **)&vec->pkgs[vec->len] = pkg; ++ vec->len++; ++ } ++} ++ ++int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg) ++{ ++ int i; ++ for (i = 0; i < vec->len; i++) ++ if (vec->pkgs[i] == apkg) ++ return 1; ++ return 0; ++} ++ ++typedef int (*compare_fcn_t)(const void *, const void *); ++void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *)) ++{ ++ qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar); ++} ++ ++int pkg_vec_clear_marks(pkg_vec_t *vec) ++{ ++ int npkgs = vec->len; ++ int i; ++ for (i = 0; i < npkgs; i++) { ++ pkg_t *pkg = vec->pkgs[i]; ++ pkg->state_flag &= ~SF_MARKED; ++ } ++ return 0; ++} ++ ++int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern) ++{ ++ int matching_count = 0; ++ pkg_t **pkgs = vec->pkgs; ++ int npkgs = vec->len; ++ int i; ++ for (i = 0; i < npkgs; i++) { ++ pkg_t *pkg = pkgs[i]; ++ if (fnmatch(pattern, pkg->name, 0)==0) { ++ pkg->state_flag |= SF_MARKED; ++ matching_count++; ++ } ++ } ++ return matching_count; ++} ++ ++ ++abstract_pkg_vec_t * abstract_pkg_vec_alloc(void) ++{ ++ abstract_pkg_vec_t * vec ; ++ vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t)); ++ if (!vec) { ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return NULL; ++ } ++ vec->pkgs = NULL; ++ vec->len = 0; ++ ++ return vec; ++} ++ ++void abstract_pkg_vec_free(abstract_pkg_vec_t *vec) ++{ ++ free(vec->pkgs); ++ free(vec); ++} ++ ++/* ++ * assumption: all names in a vector are unique ++ */ ++void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg) ++{ ++ int i; ++ ++ /* look for a duplicate pkg by name */ ++ for(i = 0; i < vec->len; i++) ++ if (strcmp(pkg->name, vec->pkgs[i]->name) == 0) ++ break; ++ ++ /* we didn't find one, add it */ ++ if(i == vec->len){ ++ vec->pkgs = ++ (abstract_pkg_t **) ++ realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *)); ++ vec->pkgs[vec->len] = pkg; ++ vec->len++; ++ } ++} ++ ++abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i) ++{ ++ if (vec->len > i) ++ return vec->pkgs[i]; ++ else ++ return NULL; ++} ++ ++int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg) ++{ ++ int i; ++ for (i = 0; i < vec->len; i++) ++ if (vec->pkgs[i] == apkg) ++ return 1; ++ return 0; ++} ++ ++void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *)) ++{ ++ qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar); ++} ++ +Index: busybox-1.7.2/archival/libipkg/pkg_vec.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/pkg_vec.h 2007-10-04 17:14:23.565084313 +0200 +@@ -0,0 +1,64 @@ ++/* pkg_vec.h - the itsy package management system ++ ++ Steven M. Ayer ++ ++ Copyright (C) 2002 Compaq Computer Corporation ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef PKG_VEC_H ++#define PKG_VEC_H ++ ++typedef struct pkg pkg_t; ++typedef struct abstract_pkg abstract_pkg_t; ++ ++struct pkg_vec ++{ ++ pkg_t **pkgs; ++ int len; ++}; ++typedef struct pkg_vec pkg_vec_t; ++ ++struct abstract_pkg_vec ++{ ++ abstract_pkg_t **pkgs; ++ int len; ++}; ++typedef struct abstract_pkg_vec abstract_pkg_vec_t; ++ ++typedef int (*pkg_compar_t)(pkg_t *, pkg_t *); ++typedef int (*abstract_pkg_compar_t)(abstract_pkg_t *, abstract_pkg_t *); ++ ++pkg_vec_t * pkg_vec_alloc(void); ++void pkg_vec_free(pkg_vec_t *vec); ++void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg); ++ ++void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg); ++/* pkg_vec_insert_merge: might munge pkg. ++* returns the pkg that is in the pkg graph */ ++pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf); ++/* this one never munges pkg */ ++void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg); ++int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg); ++void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *)); ++ ++int pkg_vec_clear_marks(pkg_vec_t *vec); ++int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern); ++ ++abstract_pkg_vec_t * abstract_pkg_vec_alloc(void); ++void abstract_pkg_vec_free(abstract_pkg_vec_t *vec); ++void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg); ++abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i); ++int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg); ++void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *)); ++#endif ++ +Index: busybox-1.7.2/archival/libipkg/sprintf_alloc.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/sprintf_alloc.h 2007-10-04 17:14:23.589085682 +0200 +@@ -0,0 +1,25 @@ ++/* sprintf_alloca.c -- like sprintf with memory allocation ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation; either version 2, or (at your option) ++ any later version. ++ ++ This program 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 General Public License for more details. ++*/ ++ ++#ifndef SPRINTF_ALLOC_H ++#define SPRINTF_ALLOC_H ++ ++#include "libbb.h" ++ ++#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args) ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/str_list.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/str_list.c 2007-10-04 17:14:23.609086833 +0200 +@@ -0,0 +1,76 @@ ++/* str_list.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++ ++#include "str_list.h" ++ ++int str_list_elt_init(str_list_elt_t *elt, char *data) ++{ ++ return void_list_elt_init((void_list_elt_t *) elt, data); ++} ++ ++void str_list_elt_deinit(str_list_elt_t *elt) ++{ ++ void_list_elt_deinit((void_list_elt_t *) elt); ++} ++ ++str_list_t *str_list_alloc() ++{ ++ str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t)); ++ if (list) ++ str_list_init(list); ++ return list; ++} ++ ++int str_list_init(str_list_t *list) ++{ ++ return void_list_init((void_list_t *) list); ++} ++ ++void str_list_deinit(str_list_t *list) ++{ ++ void_list_deinit((void_list_t *) list); ++} ++ ++int str_list_append(str_list_t *list, char *data) ++{ ++ return void_list_append((void_list_t *) list, data); ++} ++ ++int str_list_push(str_list_t *list, char *data) ++{ ++ return void_list_push((void_list_t *) list, data); ++} ++ ++str_list_elt_t *str_list_pop(str_list_t *list) ++{ ++ return (str_list_elt_t *) void_list_pop((void_list_t *) list); ++} ++ ++str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter) ++{ ++ return (str_list_elt_t *) void_list_remove((void_list_t *) list, ++ (void_list_elt_t **) iter); ++} ++ ++char *str_list_remove_elt(str_list_t *list, const char *target_str) ++{ ++ return (char *)void_list_remove_elt((void_list_t *) list, ++ (void *)target_str, ++ (void_list_cmp_t)strcmp); ++} +Index: busybox-1.7.2/archival/libipkg/str_list.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/str_list.h 2007-10-04 17:14:23.673090470 +0200 +@@ -0,0 +1,51 @@ ++/* str_list.h - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef STR_LIST_H ++#define STR_LIST_H ++ ++#include "void_list.h" ++ ++typedef struct str_list_elt str_list_elt_t; ++struct str_list_elt ++{ ++ str_list_elt_t *next; ++ char *data; ++}; ++ ++typedef struct xstr_list str_list_t; ++struct xstr_list ++{ ++ str_list_elt_t pre_head; ++ str_list_elt_t *head; ++ str_list_elt_t *tail; ++}; ++ ++int str_list_elt_init(str_list_elt_t *elt, char *data); ++void str_list_elt_deinit(str_list_elt_t *elt); ++ ++str_list_t *str_list_alloc(void); ++int str_list_init(str_list_t *list); ++void str_list_deinit(str_list_t *list); ++ ++int str_list_append(str_list_t *list, char *data); ++int str_list_push(str_list_t *list, char *data); ++str_list_elt_t *str_list_pop(str_list_t *list); ++str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter); ++char *str_list_remove_elt(str_list_t *list, const char *target_str); ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/str_util.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/str_util.c 2007-10-04 17:20:30.425990533 +0200 +@@ -0,0 +1,63 @@ ++/* str_utils.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++ ++int str_starts_with(const char *str, const char *prefix) ++{ ++ return (strncmp(str, prefix, strlen(prefix)) == 0); ++} ++ ++int str_ends_with(const char *str, const char *suffix) ++{ ++ int suffix_len; ++ int str_len; ++ ++ str_len = strlen(str); ++ suffix_len = strlen(suffix); ++ ++ if (str_len < suffix_len) { ++ return 0; ++ } ++ ++ return (strcmp(str + str_len - suffix_len, suffix) == 0); ++} ++ ++int str_chomp(char *str) ++{ ++ if (str[strlen(str) - 1] == '\n') { ++ str[strlen(str) - 1] = '\0'; ++ return 1; ++ } ++ return 0; ++} ++ ++int str_toupper(char *str) ++{ ++ while (*str) { ++ *str = toupper(*str); ++ str++; ++ } ++ ++ return 0; ++} ++ ++char *str_dup_safe(const char *str) ++{ ++ return str ? strdup(str) : NULL; ++} ++ +Index: busybox-1.7.2/archival/libipkg/str_util.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/str_util.h 2007-10-04 17:20:40.670574336 +0200 +@@ -0,0 +1,27 @@ ++/* str_utils.h - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef STR_UTILS_H ++#define STR_UTILS_H ++ ++int str_starts_with(const char *str, const char *prefix); ++int str_ends_with(const char *str, const char *suffix); ++int str_chomp(char *str); ++int str_toupper(char *str); ++char *str_dup_safe(const char *str); ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/user.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/user.c 2007-10-04 17:14:23.757095256 +0200 +@@ -0,0 +1,58 @@ ++/* user.c - the itsy package management system ++ ++ Jamey Hicks ++ ++ Copyright (C) 2002 Hewlett Packard Company ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include ++#include ++#include "file_util.h" ++#include "str_util.h" ++#ifdef IPKG_LIB ++#include "libipkg.h" ++#endif ++ ++ ++#ifdef IPKG_LIB ++static char *question = NULL; ++static int question_len = 255; ++#endif ++char *get_user_response(const char *format, ...) ++{ ++ int len = question_len; ++ va_list ap; ++ char *response; ++ va_start(ap, format); ++ ++#ifndef IPKG_LIB ++ vprintf(format, ap); ++ do { ++ response = file_read_line_alloc(stdin); ++ } while (response == NULL); ++#else ++ do { ++ if (question == NULL || len > question_len) { ++ question = realloc(question, len + 1); ++ question_len = len; ++ } ++ len = vsnprintf(question,question_len,format,ap); ++ } while (len > question_len); ++ response = strdup(ipkg_cb_response(question)); ++#endif ++ str_chomp(response); ++ str_tolower(response); ++ ++ return response; ++} +Index: busybox-1.7.2/archival/libipkg/user.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/user.h 2007-10-04 17:14:23.785096849 +0200 +@@ -0,0 +1,23 @@ ++/* user.c - the itsy package management system ++ ++ Jamey Hicks ++ ++ Copyright (C) 2002 Hewlett Packard Company ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include ++#include ++ ++char *get_user_response(const char *format, ...); ++ +Index: busybox-1.7.2/archival/libipkg/void_list.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/void_list.c 2007-10-04 17:14:23.805098002 +0200 +@@ -0,0 +1,194 @@ ++/* void_list.c - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++#include ++ ++#include "void_list.h" ++ ++int void_list_elt_init(void_list_elt_t *elt, void *data) ++{ ++ elt->next = NULL; ++ elt->data = data; ++ ++ return 0; ++} ++ ++void void_list_elt_deinit(void_list_elt_t *elt) ++{ ++ void_list_elt_init(elt, NULL); ++} ++ ++int void_list_init(void_list_t *list) ++{ ++ void_list_elt_init(&list->pre_head, NULL); ++ list->head = NULL; ++ list->pre_head.next = list->head; ++ list->tail = NULL; ++ ++ return 0; ++} ++ ++void void_list_deinit(void_list_t *list) ++{ ++ void_list_elt_t *elt; ++ ++ while (list->head) { ++ elt = void_list_pop(list); ++ void_list_elt_deinit(elt); ++ /* malloced in void_list_append */ ++ free(elt); ++ } ++} ++ ++int void_list_append(void_list_t *list, void *data) ++{ ++ void_list_elt_t *elt; ++ ++ /* freed in void_list_deinit */ ++ elt = malloc(sizeof(void_list_elt_t)); ++ if (elt == NULL) { ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return ENOMEM; ++ } ++ ++ void_list_elt_init(elt, data); ++ ++ if (list->tail) { ++ list->tail->next = elt; ++ list->tail = elt; ++ } else { ++ list->head = elt; ++ list->pre_head.next = list->head; ++ list->tail = elt; ++ } ++ ++ return 0; ++} ++ ++int void_list_push(void_list_t *list, void *data) ++{ ++ void_list_elt_t *elt; ++ ++ elt = malloc(sizeof(void_list_elt_t)); ++ if (elt == NULL) { ++ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); ++ return ENOMEM; ++ } ++ ++ void_list_elt_init(elt, data); ++ ++ elt->next = list->head; ++ list->head->next = elt; ++ if (list->tail == NULL) { ++ list->tail = list->head; ++ } ++ ++ return 0; ++} ++ ++void_list_elt_t *void_list_pop(void_list_t *list) ++{ ++ void_list_elt_t *elt; ++ ++ elt = list->head; ++ ++ if (list->head) { ++ list->head = list->head->next; ++ list->pre_head.next = list->head; ++ if (list->head == NULL) { ++ list->tail = NULL; ++ } ++ } ++ ++ return elt; ++} ++ ++void *void_list_remove(void_list_t *list, void_list_elt_t **iter) ++{ ++ void_list_elt_t *prior; ++ void_list_elt_t *old_elt; ++ void *old_data; ++ ++ old_elt = *iter; ++ old_data = old_elt->data; ++ ++ if (old_elt == list->head) { ++ prior = &list->pre_head; ++ void_list_pop(list); ++ } else { ++ for (prior = list->head; prior; prior = prior->next) { ++ if (prior->next == old_elt) { ++ break; ++ } ++ } ++ if (prior == NULL || prior->next != old_elt) { ++ fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__); ++ return NULL; ++ } ++ prior->next = old_elt->next; ++ ++ if (old_elt == list->tail) { ++ list->tail = prior; ++ } ++ } ++ ++ void_list_elt_deinit(old_elt); ++ *iter = prior; ++ ++ return old_data; ++} ++ ++/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */ ++void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp) ++{ ++ void_list_elt_t *prior; ++ void_list_elt_t *old_elt = NULL; ++ void *old_data = NULL; ++ ++ /* first element */ ++ if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) { ++ old_elt = list->head; ++ old_data = list->head->data; ++ void_list_pop(list); ++ } else { ++ int found = 0; ++ for (prior = list->head; prior && prior->next; prior = prior->next) { ++ if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) { ++ old_elt = prior->next; ++ old_data = old_elt->data; ++ found = 1; ++ break; ++ } ++ } ++ if (!found) { ++ return NULL; ++ } ++ prior->next = old_elt->next; ++ ++ if (old_elt == list->tail) { ++ list->tail = prior; ++ } ++ } ++ if (old_elt) ++ void_list_elt_deinit(old_elt); ++ ++ if (old_data) ++ return old_data; ++ else ++ return NULL; ++} +Index: busybox-1.7.2/archival/libipkg/void_list.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/void_list.h 2007-10-04 17:14:23.841100046 +0200 +@@ -0,0 +1,59 @@ ++/* void_list.h - the itsy package management system ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef VOID_LIST_H ++#define VOID_LIST_H ++ ++typedef struct void_list_elt void_list_elt_t; ++struct void_list_elt ++{ ++ void_list_elt_t *next; ++ void *data; ++}; ++ ++typedef struct void_list void_list_t; ++struct void_list ++{ ++ void_list_elt_t pre_head; ++ void_list_elt_t *head; ++ void_list_elt_t *tail; ++}; ++ ++static inline int void_list_empty(void_list_t *list) ++{ ++ if (list->head == NULL) ++ return 1; ++ else ++ return 0; ++} ++ ++int void_list_elt_init(void_list_elt_t *elt, void *data); ++void void_list_elt_deinit(void_list_elt_t *elt); ++ ++int void_list_init(void_list_t *list); ++void void_list_deinit(void_list_t *list); ++ ++int void_list_append(void_list_t *list, void *data); ++int void_list_push(void_list_t *list, void *data); ++void_list_elt_t *void_list_pop(void_list_t *list); ++ ++void *void_list_remove(void_list_t *list, void_list_elt_t **iter); ++/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */ ++typedef int (*void_list_cmp_t)(const void *, const void *); ++void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp); ++ ++#endif +Index: busybox-1.7.2/archival/libipkg/xsystem.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/xsystem.c 2007-10-04 17:14:23.865101421 +0200 +@@ -0,0 +1,64 @@ ++/* xsystem.c - system(3) with error messages ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#include "ipkg.h" ++#include ++ ++#include "xsystem.h" ++ ++/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't ++ really need the /bin/sh invocation which takes resources and ++ introduces security problems. I should switch all of this to a sort ++ of execl() or execv() interface/implementation. ++*/ ++ ++/* Like system(3), but with error messages printed if the fork fails ++ or if the child process dies due to an uncaught signal. Also, the ++ return value is a bit simpler: ++ ++ -1 if there was any problem ++ Otherwise, the 8-bit return value of the program ala WEXITSTATUS ++ as defined in . ++*/ ++int xsystem(const char *cmd) ++{ ++ int err; ++ ++ err = system(cmd); ++ ++ if (err == -1) { ++ fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n", ++ __FUNCTION__, cmd); ++ return -1; ++ } ++ ++ if (WIFSIGNALED(err)) { ++ fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n", ++ __FUNCTION__, WTERMSIG(err), cmd); ++ return -1; ++ } ++ ++ if (WIFEXITED(err)) { ++ /* Normal child exit */ ++ return WEXITSTATUS(err); ++ } ++ ++ fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d", ++ __FUNCTION__, err); ++ return -1; ++} ++ +Index: busybox-1.7.2/archival/libipkg/xsystem.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/archival/libipkg/xsystem.h 2007-10-04 17:14:23.885102559 +0200 +@@ -0,0 +1,34 @@ ++/* xsystem.h - system(3) with error messages ++ ++ Carl D. Worth ++ ++ Copyright (C) 2001 University of Southern California ++ ++ This program is free software; you can redistribute it and/or ++ modify it under the terms of the GNU General Public License as ++ published by the Free Software Foundation; either version 2, or (at ++ your option) any later version. ++ ++ This program 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 ++ General Public License for more details. ++*/ ++ ++#ifndef XSYSTEM_H ++#define XSYSTEM_H ++ ++#include ++ ++/* Like system(3), but with error messages printed if the fork fails ++ or if the child process dies due to an uncaught signal. Also, the ++ return value is a bit simpler: ++ ++ -1 if there was any problem ++ Otherwise, the 8-bit return value of the program ala WEXITSTATUS ++ as defined in . ++*/ ++int xsystem(const char *cmd); ++ ++#endif ++ +Index: busybox-1.7.2/archival/libunarchive/data_extract_all.c +=================================================================== +--- busybox-1.7.2.orig/archival/libunarchive/data_extract_all.c 2007-10-04 17:12:34.462866938 +0200 ++++ busybox-1.7.2/archival/libunarchive/data_extract_all.c 2007-10-04 17:14:23.905103687 +0200 +@@ -129,3 +129,17 @@ + } + } + } ++ ++extern void data_extract_all_prefix(archive_handle_t *archive_handle) ++{ ++ char *name_ptr = archive_handle->file_header->name; ++ ++ name_ptr += strspn(name_ptr, "./"); ++ if (name_ptr[0] != '\0') { ++ archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1); ++ strcpy(archive_handle->file_header->name, archive_handle->buffer); ++ strcat(archive_handle->file_header->name, name_ptr); ++ data_extract_all(archive_handle); ++ } ++} ++ +Index: busybox-1.7.2/archival/libunarchive/Kbuild +=================================================================== +--- busybox-1.7.2.orig/archival/libunarchive/Kbuild 2007-10-04 17:12:34.474867620 +0200 ++++ busybox-1.7.2/archival/libunarchive/Kbuild 2007-10-04 17:14:23.925104840 +0200 +@@ -55,6 +55,7 @@ + lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o + lib-$(CONFIG_GUNZIP) += $(GUNZIP_FILES) + lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o ++lib-$(CONFIG_IPKG) += $(GUNZIP_FILES) get_header_tar.o get_header_tar_gz.o + lib-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o + lib-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o + lib-$(CONFIG_FEATURE_RPM_BZ2) += decompress_bunzip2.o +Index: busybox-1.7.2/include/applets.h +=================================================================== +--- busybox-1.7.2.orig/include/applets.h 2007-10-04 17:13:12.525035978 +0200 ++++ busybox-1.7.2/include/applets.h 2007-10-04 17:24:51.052842811 +0200 +@@ -190,6 +190,7 @@ + USE_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_NEVER)) + USE_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS)) + USE_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS)) ++USE_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) + USE_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_NEVER)) + USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER)) + USE_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_NEVER)) +Index: busybox-1.7.2/include/unarchive.h +=================================================================== +--- busybox-1.7.2.orig/include/unarchive.h 2007-10-04 17:12:34.486868309 +0200 ++++ busybox-1.7.2/include/unarchive.h 2007-10-04 17:14:23.989108482 +0200 +@@ -74,6 +74,7 @@ + + extern void data_skip(archive_handle_t *archive_handle); + extern void data_extract_all(archive_handle_t *archive_handle); ++extern void data_extract_all_prefix(archive_handle_t *archive_handle); + extern void data_extract_to_stdout(archive_handle_t *archive_handle); + extern void data_extract_to_buffer(archive_handle_t *archive_handle); + +Index: busybox-1.7.2/include/usage.h +=================================================================== +--- busybox-1.7.2.orig/include/usage.h 2007-10-04 17:13:12.629041904 +0200 ++++ busybox-1.7.2/include/usage.h 2007-10-04 17:14:23.993108707 +0200 +@@ -1226,6 +1226,82 @@ + "$ ls -la /tmp/busybox*\n" \ + "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n" + ++#define ipkg_trivial_usage \ ++ "[options]... sub-command [arguments]..." ++#define ipkg_full_usage \ ++ "ipkg is an utility to install, remove and manage .ipk packages.\n" \ ++ "\n" \ ++ "Sub-commands:\n" \ ++ "\nPackage Manipulation:\n" \ ++ "\tupdate Update list of available packages\n" \ ++ "\tupgrade Upgrade all installed packages to latest version\n" \ ++ "\tinstall Download and install (and dependencies)\n" \ ++ "\tinstall Install package \n" \ ++ "\tconfigure [] Configure unpacked packages\n" \ ++ "\tremove Remove package \n" \ ++ "\tflag ... Flag package(s) \n" \ ++ "\t =hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \ ++ "\n" \ ++ "Informational Commands:\n" \ ++ "\tlist List available packages and descriptions\n" \ ++ "\tlist_installed List all and only the installed packages and description \n" \ ++ "\tfiles List all files belonging to \n" \ ++ "\tsearch Search for a package providing \n" \ ++ "\tinfo [pkg|regexp []] Display all/some info fields for or all\n" \ ++ "\tstatus [pkg|regexp []] Display all/some status fields for or all\n" \ ++ "\tdownload Download to current directory.\n" \ ++ "\tcompare_versions \n" \ ++ "\t compare versions using <= < > >= = << >>\n" \ ++ "\tprint_architecture prints the architecture.\n" \ ++ "\tprint_installation_architecture\n" \ ++ "\twhatdepends [-A] [pkgname|pat]+\n" \ ++ "\twhatdependsrec [-A] [pkgname|pat]+\n" \ ++ "\twhatprovides [-A] [pkgname|pat]+\n" \ ++ "\twhatconflicts [-A] [pkgname|pat]+\n" \ ++ "\twhatreplaces [-A] [pkgname|pat]+\n" \ ++ "\t prints the installation architecture.\n" \ ++ "\n" \ ++ "\nOptions:\n" \ ++ "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \ ++ "\t-V Set verbosity level to . If no value is\n" \ ++ "\t--verbosity provided increase verbosity by one. Verbosity levels:\n" \ ++ "\t 0 errors only\n" \ ++ "\t 1 normal messages (default)\n" \ ++ "\t 2 informative messages\n" \ ++ "\t 3 debug output\n" \ ++ "\t-f Use as the ipkg configuration file\n" \ ++ "\t-conf Default configuration file location\n" \ ++ " is /etc/ipkg.conf\n" \ ++ "\t-d Use as the the root directory for\n" \ ++ "\t-dest package installation, removal, upgrading.\n" \ ++ " should be a defined dest name from\n" \ ++ " the configuration file, (but can also be a\n" \ ++ " directory name in a pinch).\n" \ ++ "\t-o Use as the root directory for\n" \ ++ "\t-offline offline installation of packages.\n" \ ++ "\t-verbose_wget more wget messages\n" \ ++ "\n" \ ++ "Force Options (use when ipkg is too smart for its own good):\n" \ ++ "\t-force-depends Make dependency checks warnings instead of errors\n" \ ++ "\t Install/remove package in spite of failed dependences\n" \ ++ "\t-force-defaults Use default options for questions asked by ipkg.\n" \ ++ " (no prompts). Note that this will not prevent\n" \ ++ " package installation scripts from prompting.\n" \ ++ "\t-force-reinstall Allow ipkg to reinstall a package.\n" \ ++ "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \ ++ "\t-force-downgrade Allow ipkg to downgrade packages.\n" \ ++ "\t-force_space Install even if there does not seem to be enough space.\n" \ ++ "\t-noaction No action -- test only\n" \ ++ "\t-nodeps Do not follow dependences\n" \ ++ "\t-force-removal-of-dependent-packages\n" \ ++ "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \ ++ "\t-test No action -- test only\n" \ ++ "\t-t Specify tmp-dir.\n" \ ++ "\t--tmp-dir Specify tmp-dir.\n" \ ++ "\n" \ ++ "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \ ++ "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n" ++ + #define halt_trivial_usage \ + "[-d delay] [-n] [-f]" + #define halt_full_usage \ +Index: busybox-1.7.2/Makefile +=================================================================== +--- busybox-1.7.2.orig/Makefile 2007-10-04 17:12:34.502869218 +0200 ++++ busybox-1.7.2/Makefile 2007-10-04 17:14:24.021110304 +0200 +@@ -428,6 +428,7 @@ + + libs-y := \ + archival/ \ ++ archival/libipkg/ \ + archival/libunarchive/ \ + console-tools/ \ + coreutils/ \ diff --git a/package/busybox/patches/501-libbb_hash.patch b/package/busybox/patches/501-libbb_hash.patch new file mode 100644 index 0000000000..c6c36fc355 --- /dev/null +++ b/package/busybox/patches/501-libbb_hash.patch @@ -0,0 +1,199 @@ +Index: busybox-1.7.2/coreutils/md5_sha1_sum.c +=================================================================== +--- busybox-1.7.2.orig/coreutils/md5_sha1_sum.c 2007-09-03 13:48:39.000000000 +0200 ++++ busybox-1.7.2/coreutils/md5_sha1_sum.c 2007-10-04 15:45:02.423570273 +0200 +@@ -8,75 +8,10 @@ + + #include "libbb.h" + +-typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t; +- + #define FLAG_SILENT 1 + #define FLAG_CHECK 2 + #define FLAG_WARN 4 + +-/* This might be useful elsewhere */ +-static unsigned char *hash_bin_to_hex(unsigned char *hash_value, +- unsigned hash_length) +-{ +- /* xzalloc zero-terminates */ +- char *hex_value = xzalloc((hash_length * 2) + 1); +- bin2hex(hex_value, (char*)hash_value, hash_length); +- return hex_value; +-} +- +-static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo) +-{ +- int src_fd, hash_len, count; +- union _ctx_ { +- sha1_ctx_t sha1; +- md5_ctx_t md5; +- } context; +- uint8_t *hash_value = NULL; +- RESERVE_CONFIG_UBUFFER(in_buf, 4096); +- void (*update)(const void*, size_t, void*); +- void (*final)(void*, void*); +- +- src_fd = STDIN_FILENO; +- if (NOT_LONE_DASH(filename)) { +- src_fd = open_or_warn(filename, O_RDONLY); +- if (src_fd < 0) { +- return NULL; +- } +- } +- +- /* figure specific hash algorithims */ +- if (ENABLE_MD5SUM && hash_algo==HASH_MD5) { +- md5_begin(&context.md5); +- update = (void (*)(const void*, size_t, void*))md5_hash; +- final = (void (*)(void*, void*))md5_end; +- hash_len = 16; +- } else if (ENABLE_SHA1SUM && hash_algo==HASH_SHA1) { +- sha1_begin(&context.sha1); +- update = (void (*)(const void*, size_t, void*))sha1_hash; +- final = (void (*)(void*, void*))sha1_end; +- hash_len = 20; +- } else { +- bb_error_msg_and_die("algorithm not supported"); +- } +- +- while (0 < (count = safe_read(src_fd, in_buf, 4096))) { +- update(in_buf, count, &context); +- } +- +- if (count == 0) { +- final(in_buf, &context); +- hash_value = hash_bin_to_hex(in_buf, hash_len); +- } +- +- RELEASE_CONFIG_BUFFER(in_buf); +- +- if (src_fd != STDIN_FILENO) { +- close(src_fd); +- } +- +- return hash_value; +-} +- + int md5_sha1_sum_main(int argc, char **argv); + int md5_sha1_sum_main(int argc, char **argv) + { +Index: busybox-1.7.2/include/libbb.h +=================================================================== +--- busybox-1.7.2.orig/include/libbb.h 2007-10-04 15:20:22.275221430 +0200 ++++ busybox-1.7.2/include/libbb.h 2007-10-04 15:42:10.585777803 +0200 +@@ -947,6 +947,7 @@ + extern const char bb_uuenc_tbl_std[]; + void bb_uuencode(char *store, const void *s, int length, const char *tbl); + ++typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t; + typedef struct sha1_ctx_t { + uint32_t count[2]; + uint32_t hash[5]; +@@ -968,6 +969,8 @@ + void md5_begin(md5_ctx_t *ctx); + void md5_hash(const void *data, size_t length, md5_ctx_t *ctx); + void *md5_end(void *resbuf, md5_ctx_t *ctx); ++unsigned char *hash_bin_to_hex(unsigned char *hash_value, unsigned hash_length); ++uint8_t *hash_file(const char *filename, hash_algo_t hash_algo); + + uint32_t *crc32_filltable(uint32_t *tbl256, int endian); + +Index: busybox-1.7.2/libbb/Kbuild +=================================================================== +--- busybox-1.7.2.orig/libbb/Kbuild 2007-09-03 13:48:41.000000000 +0200 ++++ busybox-1.7.2/libbb/Kbuild 2007-10-04 15:42:10.613779401 +0200 +@@ -38,6 +38,7 @@ + lib-y += get_last_path_component.o + lib-y += get_line_from_file.o + lib-y += getopt32.o ++lib-y += hash.o + lib-y += herror_msg.o + lib-y += herror_msg_and_die.o + lib-y += human_readable.o +Index: busybox-1.7.2/libbb/hash.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/libbb/hash.c 2007-10-04 15:45:08.279904000 +0200 +@@ -0,0 +1,81 @@ ++/* ++ * Copyright (C) 2003 Glenn L. McGrath ++ * Copyright (C) 2003-2004 Erik Andersen ++ * ++ * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include "busybox.h" ++ ++/* This might be useful elsewhere */ ++unsigned char *hash_bin_to_hex(unsigned char *hash_value, ++ unsigned hash_length) ++{ ++ /* xzalloc zero-terminates */ ++ char *hex_value = xzalloc((hash_length * 2) + 1); ++ bin2hex(hex_value, (char*)hash_value, hash_length); ++ return hex_value; ++} ++ ++uint8_t *hash_file(const char *filename, hash_algo_t hash_algo) ++{ ++ int src_fd, hash_len, count; ++ union _ctx_ { ++ sha1_ctx_t sha1; ++ md5_ctx_t md5; ++ } context; ++ uint8_t *hash_value = NULL; ++ RESERVE_CONFIG_UBUFFER(in_buf, 4096); ++ void (*update)(const void*, size_t, void*); ++ void (*final)(void*, void*); ++ ++ src_fd = STDIN_FILENO; ++ if (NOT_LONE_DASH(filename)) { ++ src_fd = open_or_warn(filename, O_RDONLY); ++ if (src_fd < 0) { ++ return NULL; ++ } ++ } ++ ++ /* figure specific hash algorithims */ ++ if (ENABLE_MD5SUM && hash_algo==HASH_MD5) { ++ md5_begin(&context.md5); ++ update = (void (*)(const void*, size_t, void*))md5_hash; ++ final = (void (*)(void*, void*))md5_end; ++ hash_len = 16; ++ } else if (ENABLE_SHA1SUM && hash_algo==HASH_SHA1) { ++ sha1_begin(&context.sha1); ++ update = (void (*)(const void*, size_t, void*))sha1_hash; ++ final = (void (*)(void*, void*))sha1_end; ++ hash_len = 20; ++ } else { ++ bb_error_msg_and_die("algorithm not supported"); ++ } ++ ++ while (0 < (count = safe_read(src_fd, in_buf, 4096))) { ++ update(in_buf, count, &context); ++ } ++ ++ if (count == 0) { ++ final(in_buf, &context); ++ hash_value = hash_bin_to_hex(in_buf, hash_len); ++ } ++ ++ RELEASE_CONFIG_BUFFER(in_buf); ++ ++ if (src_fd != STDIN_FILENO) { ++ close(src_fd); ++ } ++ ++ return hash_value; ++} ++ ++ diff --git a/package/busybox/patches/510-awx.patch b/package/busybox/patches/510-awx.patch new file mode 100644 index 0000000000..571b32397d --- /dev/null +++ b/package/busybox/patches/510-awx.patch @@ -0,0 +1,1624 @@ +Index: busybox-1.7.2/editors/awk.c +=================================================================== +--- busybox-1.7.2.orig/editors/awk.c 2007-10-05 01:39:50.073293533 +0200 ++++ busybox-1.7.2/editors/awk.c 2007-10-05 02:16:42.539374788 +0200 +@@ -33,6 +33,11 @@ + /* these flags are static, don't change them when value is changed */ + #define VF_DONTTOUCH (VF_ARRAY | VF_SPECIAL | VF_WALK | VF_CHILD | VF_DIRTY) + ++#ifdef CONFIG_AWX ++#define fputs(s, stream) fputs_hook(s, stream) ++static inline int fputs_hook (__const char *__restrict __s, FILE *__restrict __stream); ++#endif ++ + /* Variable */ + typedef struct var_s { + unsigned type; /* flags */ +@@ -54,9 +59,14 @@ + } chain; + + /* Function */ ++typedef var *(*awk_cfunc)(var *res, var *args, int nargs); + typedef struct func_s { + unsigned nargs; +- struct chain_s body; ++ enum { AWKFUNC, CFUNC } type; ++ union { ++ awk_cfunc cfunc; ++ struct chain_s body; ++ } x; + } func; + + /* I/O stream */ +@@ -1400,7 +1410,8 @@ + next_token(TC_FUNCTION); + g_pos++; + f = newfunc(t_string); +- f->body.first = NULL; ++ f->type = AWKFUNC; ++ f->x.body.first = NULL; + f->nargs = 0; + while (next_token(TC_VARIABLE | TC_SEQTERM) & TC_VARIABLE) { + v = findvar(ahash, t_string); +@@ -1409,7 +1420,7 @@ + if (next_token(TC_COMMA | TC_SEQTERM) & TC_SEQTERM) + break; + } +- seq = &(f->body); ++ seq = &(f->x.body); + chain_group(); + clear_array(ahash); + +@@ -2372,7 +2383,8 @@ + break; + + case XC( OC_FUNC ): +- if (!op->r.f->body.first) ++ if ((op->r.f->type == AWKFUNC) && ++ !op->r.f->x.body.first) + syntax_error(EMSG_UNDEF_FUNC); + + X.v = R.v = nvalloc(op->r.f->nargs+1); +@@ -2389,7 +2401,10 @@ + fnargs = X.v; + + L.s = g_progname; +- res = evaluate(op->r.f->body.first, res); ++ if (op->r.f->type == AWKFUNC) ++ res = evaluate(op->r.f->x.body.first, res); ++ else if (op->r.f->type == CFUNC) ++ res = op->r.f->x.cfunc(res, fnargs, op->r.f->nargs); + g_progname = L.s; + + nvfree(fnargs); +@@ -2753,6 +2768,13 @@ + } + + int awk_main(int argc, char **argv); ++int awx_main(int argc, char **argv); ++ ++#ifdef CONFIG_AWX ++static int is_awx = 0; ++#include "awx.c" ++#endif ++ + int awk_main(int argc, char **argv) + { + unsigned opt; +@@ -2817,6 +2839,11 @@ + *s1 = '='; + } + } ++ ++#ifdef CONFIG_AWX ++ do_awx(argc, argv); ++#endif ++ + opt_complementary = "v::f::"; + opt = getopt32(argv, "F:v:f:W:", &opt_F, &opt_v, &opt_f, &opt_W); + argv += optind; +Index: busybox-1.7.2/editors/awx.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/editors/awx.c 2007-10-05 02:10:16.393369582 +0200 +@@ -0,0 +1,636 @@ ++/* ++ * awk web extension ++ * ++ * Copyright (C) 2007 by Felix Fietkau ++ * ++ * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. ++ */ ++ ++#include ++#include ++#include "awx_parser.h" ++ ++#define LINE_BUF 2048 ++#define HASH_MAX 1536 ++#define TR_START "@TR<<" ++#define TR_END ">>" ++#define MAX_TR 32 ++ ++#undef fputs ++ ++static xhash *lstr = NULL; ++static xhash *formvar = NULL; ++static int lang_inuse = 0; ++ ++/* look up a translation symbol from the hash */ ++static inline const char *translate_lookup(char *str) ++{ ++ char *name, *def, *p; ++ hash_item *hi; ++ var *v; ++ ++ def = name = str; ++ if (((p = strchr(str, '|')) != NULL) ++ || ((p = strchr(str, '#')) != NULL)) { ++ def = p + 1; ++ *p = 0; ++ } ++ ++ hi = hash_search(lstr, name); ++ if (!hi) ++ return def; ++ ++ v = &hi->data.v; ++ ++ return getvar_s(v); ++} ++ ++/* look for translation markers in the line and return the translated string */ ++static char *translate_line(char *line) ++{ ++ const char *tok[MAX_TR * 3]; ++ char *l, *p, *p2 = NULL, *res; ++ int len = 0, _pos = 0, i, tr_abort = 0; ++ static char *backlog = NULL; ++ ++ if (backlog && line) { ++ backlog = xrealloc(backlog, strlen(backlog) + strlen(line) + 1); ++ sprintf(backlog + strlen(backlog), line); ++ l = backlog; ++ } else { ++ l = line; ++ } ++ ++ while (l != NULL) { ++ if ((p = strstr(l, TR_START)) == NULL) { ++ len += strlen((tok[_pos++] = l)); ++ break; ++ } ++ ++ p2 = strstr(p, TR_END); ++ if (p2 == NULL) { ++ p2 = xstrdup(l); ++ tr_abort = 1; ++ break; ++ } ++ ++ *p = 0; ++ len += strlen((tok[_pos++] = l)); ++ *p2 = 0; ++ len += strlen((tok[_pos++] = translate_lookup(p + strlen(TR_START)))); ++ ++ l = p2; ++ l += strlen(TR_END); ++ } ++ len++; ++ ++ p = xmalloc(len + 1); ++ *p = 0; ++ res = p; ++ for (i = 0; i < _pos; i++) { ++ strcat(p, tok[i]); ++ p += strlen(tok[i]); ++ } ++ if (backlog) { ++ free(backlog); ++ backlog = NULL; ++ } ++ if (tr_abort && p2) ++ backlog = p2; ++ ++ return res; ++} ++ ++/* hook for intercepting awk's use of puts. used for running all printed strings ++ * through the translation system */ ++static inline int fputs_hook (__const char *__restrict __s, FILE *__restrict __stream) ++{ ++ if (lang_inuse && (__stream == stdout)) { ++ int ret; ++ char *str; ++ ++ str = translate_line((char *) __s); ++ ret = fputs(str, __stream); ++ free(str); ++ ++ return ret; ++ } ++ ++ return fputs(__s, __stream); ++} ++ ++static var *init_lang(var *res, var *args, int nargs) ++{ ++ if (!lstr) ++ lstr = hash_init(); ++ ++ lang_inuse = 1; ++ return res; ++} ++ ++ ++/* load and parse language file */ ++static void load_lang_file(char *file) ++{ ++ FILE *f; ++ char *b, *name, *value; ++ char buf1[LINE_BUF]; ++ ++ if ((f = fopen(file, "r")) == NULL) ++ return; ++ ++ while (!feof(f) && (fgets(buf1, LINE_BUF - 1, f) != NULL)) { ++ b = buf1; ++ if (*b == '#') ++ continue; /* skip comments */ ++ ++ while (isspace(*b)) ++ b++; /* skip leading spaces */ ++ if (!*b) ++ continue; ++ ++ name = b; ++ if ((b = strstr(name, "=>")) == NULL) ++ continue; /* separator not found */ ++ ++ value = b + 2; ++ if (!*value) ++ continue; ++ ++ *b = 0; ++ for (b--; isspace(*b); b--) ++ *b = 0; /* remove trailing spaces */ ++ ++ while (isspace(*value)) ++ value++; /* skip leading spaces */ ++ ++ for (b = value + strlen(value) - 1; isspace(*b); b--) ++ *b = 0; /* remove trailing spaces */ ++ ++ if (!*value) ++ continue; ++ ++ setvar_s(findvar(lstr,name), value); ++ } ++ ++ fclose(f); ++} ++ ++static var *load_lang(var *res, var *args, int nargs) ++{ ++ const char *langfmt = "/usr/lib/webif/lang/%s.txt"; ++ char lbuf[LINE_BUF]; ++ const char *lang; ++ ++ if (!lang_inuse) ++ init_lang(res, args, nargs); ++ ++ lang = getvar_s(args); ++ if (!lang || !strcmp(lang, "")) ++ return res; ++ ++ sprintf(lbuf, langfmt, lang); ++ load_lang_file(lbuf); ++ ++ return res; ++} ++ ++/* read the contents of an entire file */ ++static char *get_file(const char *fname) ++{ ++ FILE *F; ++ char *s = NULL; ++ int i, j, flen; ++ ++ F = fopen(fname, "r"); ++ if (!F) { ++ return NULL; ++ } ++ ++ if (fseek(F, 0, SEEK_END) == 0) { ++ flen = ftell(F); ++ s = (char *)xmalloc(flen+4); ++ fseek(F, 0, SEEK_SET); ++ i = 1 + fread(s+1, 1, flen, F); ++ } else { ++ for (i=j=1; j>0; i+=j) { ++ s = (char *)xrealloc(s, i+4096); ++ j = fread(s+i, 1, 4094, F); ++ } ++ } ++ ++ s[i] = '\0'; ++ fclose(F); ++ return s; ++} ++ ++ ++/* parse_include(): ++ * ++ * taken from parse_program from awk.c ++ * END{} is not parsed here, and BEGIN{} is executed immediately ++ */ ++static void parse_include(char *p) ++{ ++ uint32_t tclass; ++ chain *initseq = NULL; ++ chain tmp; ++ func *f; ++ var *v, *tv; ++ ++ tv = nvalloc(1); ++ memset(&tmp, 0, sizeof(tmp)); ++ g_pos = p; ++ t_lineno = 1; ++ while ((tclass = next_token(TC_EOF | TC_OPSEQ | ++ TC_OPTERM | TC_BEGIN | TC_FUNCDECL)) != TC_EOF) { ++ if (tclass & TC_OPTERM) ++ continue; ++ ++ seq = &tmp; ++ if (tclass & TC_BEGIN) { ++ initseq = xzalloc(sizeof(chain)); ++ seq = initseq; ++ chain_group(); ++ } else if (tclass & TC_FUNCDECL) { ++ next_token(TC_FUNCTION); ++ g_pos++; ++ f = newfunc(t_string); ++ f->type = AWKFUNC; ++ f->x.body.first = NULL; ++ f->nargs = 0; ++ while (next_token(TC_VARIABLE | TC_SEQTERM) & TC_VARIABLE) { ++ v = findvar(ahash, t_string); ++ v->x.aidx = (f->nargs)++; ++ ++ if (next_token(TC_COMMA | TC_SEQTERM) & TC_SEQTERM) ++ break; ++ } ++ seq = &(f->x.body); ++ chain_group(); ++ clear_array(ahash); ++ } ++ } ++ if (initseq && initseq->first) ++ tv = evaluate(initseq->first, tv); ++ nvfree(tv); ++} ++ ++ ++/* include an awk file and run its BEGIN{} section */ ++static xhash *includes = NULL; ++static void include_file(const char *filename) ++{ ++ char *s; ++ var *v; ++ int oldlnr = g_lineno; ++ const char *oldprg = g_progname; ++ ++ if (!includes) ++ includes = hash_init(); ++ ++ /* find out if the file has been included already */ ++ v = findvar(includes, filename); ++ if (istrue(v)) ++ return; ++ setvar_s(v, "1"); ++ ++ /* read include file */ ++ s = get_file(filename); ++ if (!s) { ++ fprintf(stderr, "Could not open file.\n"); ++ return; ++ } ++ g_lineno = 1; ++ g_progname = xstrdup(filename); ++ parse_include(s+1); ++ free(s); ++ g_lineno = oldlnr; ++ g_progname = oldprg; ++} ++ ++static var *include(var *res, var *args, int nargs) ++{ ++ const char *s; ++ ++ s = getvar_s(args); ++ if (s && (strlen(s) > 0)) ++ include_file(s); ++ ++ return res; ++} ++ ++/* parse an awk expression */ ++static var *parse_awk(char *str, var *tv) ++{ ++ chain body; ++ node *n; ++ ++ memset(&body, 0, sizeof(body)); ++ g_pos = str; ++ seq = &body; ++ ++ /* end of expression, assume that there's going to be a free byte ++ * at the end of the string that can be used for the ')' */ ++ strcat(str + strlen(str), "}"); ++ n = parse_expr(TC_GRPTERM); ++ if (!n) ++ return NULL; ++ ++ return evaluate(n, tv); ++} ++ ++static inline void print_translate(char *s) ++{ ++ char *str = s; ++ if (lang_inuse) ++ str = translate_line(s); ++ fputs(str, stdout); ++ fflush(stdout); ++ if (lang_inuse) ++ free(str); ++} ++ ++static void render_element(struct template_cb *tcb, struct template_element *e) ++{ ++ var *v; ++ char *s, *s2; ++ int i; ++ ++ if (!e || !e->var) ++ return; ++ g_lineno = e->line; ++ switch (e->t) { ++ case T_TEXT: ++ s = malloc(strlen(e->var) + 2); ++ strcpy(s, e->var); ++ print_translate(s); ++ free(s); ++ break; ++ case T_CODE: ++ s = malloc(strlen(e->var) + 2); ++ strcpy(s, e->var); ++ v = nvalloc(1); ++ s2 = strdup(getvar_s(parse_awk(s, v))); ++ nvfree(v); ++ print_translate(s2); ++ free(s); ++ free(s2); ++ break; ++ case T_IF: ++ s = malloc(strlen(e->var) + 2); ++ strcpy(s, e->var); ++ v = nvalloc(1); ++ i = istrue(parse_awk(s, v)); ++ nvfree(v); ++ free(s); ++ ++ if (i) ++ execute_template(tcb, e->sub); ++ else if (e->sub2) ++ execute_template(tcb, e->sub2); ++ break; ++ case T_FOR: { ++ v = newvar(e->var); ++ hashwalk_init(v, iamarray(findvar(vhash, e->in))); ++ while (hashwalk_next(v)) { ++ execute_template(tcb, e->sub); ++ } ++ clrvar(v); ++ } ++ break; ++ default: ++ break; ++ } ++} ++ ++/* awk method render(), which opens a template file and processes all awk ssi calls */ ++static void render_file(const char *filename) ++{ ++ struct template_cb tcb; ++ struct template_element *e; ++ FILE *f; ++ const char *oldprg = g_progname; ++ int oldlnr = g_lineno; ++ ++ if (!filename) ++ return; ++ ++ f = fopen(filename, "r"); ++ if (!f) ++ return; ++ ++ g_progname = xstrdup(filename); ++ g_lineno = 1; ++ memset(&tcb, 0, sizeof(tcb)); ++ tcb.handle_element = render_element; ++ e = parse_template(&tcb, f); ++ execute_template(&tcb, e); ++ free_template(&tcb, e); ++ fclose(f); ++ g_progname = oldprg; ++ g_lineno = oldlnr; ++} ++ ++static var *render(var *res, var *args, int nargs) ++{ ++ const char *s; ++ ++ s = getvar_s(args); ++ if (!s) ++ return res; ++ ++ render_file(s); ++ ++ return res; ++} ++ ++/* Call render, but only if this function hasn't been called already */ ++static int layout_rendered = 0; ++static var *render_layout(var *res, var *args, int nargs) ++{ ++ if (layout_rendered) ++ return res; ++ layout_rendered = 1; ++ return render(res, args, nargs); ++} ++ ++/* registers a global c function for the awk interpreter */ ++static void register_cfunc(const char *name, awk_cfunc cfunc, int nargs) ++{ ++ func *f; ++ ++ f = newfunc(name); ++ f->type = CFUNC; ++ f->x.cfunc = cfunc; ++ f->nargs = nargs; ++} ++ ++static void putvar(vartype type, char *name, char *value) ++{ ++ if (type != FORM_VAR) ++ return; ++ ++ setvar_u(findvar(formvar, name), value); ++} ++ ++static const char *cgi_getvar(const char *name) ++{ ++ if (!formvar) { ++ formvar = hash_init(); ++ cgi_init(putvar); ++ } ++ ++ if (!formvar || !name) ++ return NULL; ++ ++ return getvar_s(findvar(formvar, name)); ++} ++ ++/* function call for accessing cgi form variables */ ++static var *getvar(var *res, var *args, int nargs) ++{ ++ const char *s, *svar; ++ ++ s = getvar_s(args); ++ if (!s) ++ return res; ++ ++ svar = cgi_getvar(s); ++ if (!svar) ++ return res; ++ ++ setvar_u(res, svar); ++ ++ return res; ++} ++ ++/* call an awk function without arguments by string reference */ ++static var *call(var *res, var *args, int nargs) ++{ ++ const char *s = getvar_s(args); ++ func *f; ++ ++ if (!s) ++ goto done; ++ ++ f = newfunc(s); ++ if (f && f->type == AWKFUNC && f->x.body.first) ++ return evaluate(f->x.body.first, res); ++ ++done: ++ return res; ++} ++ ++ ++static int run_awxscript(char *name) ++{ ++ var tv, *layout, *action; ++ char *tmp, *s = NULL; ++ ++ zero_out_var(&tv); ++ g_progname = name; ++ ++ /* read the main controller source */ ++ s = get_file(g_progname); ++ if (!s) { ++ fprintf(stderr, "Could not open file\n"); ++ return 1; ++ } ++ parse_program(s+1); ++ free(s); ++ ++ ++ /* set some defaults for ACTION and LAYOUT, which will have special meaning */ ++ layout = newvar("LAYOUT"); ++ setvar_s(layout, "views/layout.ahtml"); ++ ++ /* run the BEGIN {} block */ ++ evaluate(beginseq.first, &tv); ++ ++ action = newvar("ACTION"); ++ if (!(strlen(getvar_s(action)) > 0)) { ++ tmp = (char *) cgi_getvar("action"); ++ if (!tmp || (strlen(tmp) <= 0)) ++ tmp = strdup("default"); ++ ++ setvar_p(action, tmp); ++ } ++ ++ /* call the action (precedence: begin block override > cgi parameter > "default") */ ++ tmp = xmalloc(strlen(getvar_s(action)) + 7); ++ sprintf(tmp, "handle_%s", getvar_s(action)); ++ setvar_s(action, tmp); ++ call(&tv, action, 1); ++ free(tmp); ++ ++ /* render the selected layout, will do nothing if render_layout has been called from awk */ ++ render_layout(&tv, layout, 1); ++ ++ return 0; ++} ++ ++ ++/* main awx processing function. called from awk_main() */ ++static int do_awx(int argc, char **argv) ++{ ++ int ret = -1; ++ var tv; ++ int i, c; ++ char **args = argv; ++ ++ zero_out_var(&tv); ++ ++ /* register awk C callbacks */ ++ register_cfunc("getvar", getvar, 1); ++ register_cfunc("render", render, 1); ++ register_cfunc("render_layout", render_layout, 1); ++ register_cfunc("call", call, 1); ++ register_cfunc("include", include, 1); ++ register_cfunc("init_lang", init_lang, 1); ++ register_cfunc("load_lang", load_lang, 1); ++ ++ if (!is_awx) ++ return 0; ++ ++ /* fill in ARGV array */ ++ setvar_i(intvar[ARGC], argc + 1); ++ setari_u(intvar[ARGV], 0, "awx"); ++ i = 0; ++ while (*args) ++ setari_u(intvar[ARGV], ++i, *args++); ++ ++ while((c = getopt(argc, argv, "i:f:")) != EOF) { ++ switch(c) { ++ case 'i': ++ g_progname = optarg; ++ include_file(optarg); ++ break; ++ case 'f': ++ ret = 0; ++ g_progname = optarg; ++ render_file(optarg); ++ goto done; ++ } ++ } ++ argc -= optind; ++ argv += optind; ++ ++ if (argc < 1) { ++ fprintf(stderr, "Invalid argument.\n"); ++ goto done; ++ } ++ ++ ret = run_awxscript(*argv); ++ ++done: ++ exit(ret); ++} ++ ++/* entry point for awx applet */ ++int awx_main(int argc, char **argv) ++{ ++ is_awx = 1; ++ return awk_main(argc, argv); ++} ++ +Index: busybox-1.7.2/editors/awx_parser.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/editors/awx_parser.h 2007-10-05 01:43:59.487506840 +0200 +@@ -0,0 +1,38 @@ ++#ifndef __TEMPLATE_PARSER_H ++#define __TEMPLATE_PARSER_H ++ ++enum type { ++ T_TEXT, ++ T_FOR, ++ T_IF, ++ T_CODE ++}; ++ ++struct template_element; ++struct template_cb; ++ ++struct template_cb { ++ void *(*prepare_code)(struct template_element *); ++ void (*handle_element)(struct template_cb *, struct template_element *); ++ void (*free_code)(struct template_element *); ++}; ++ ++struct template_element { ++ enum type t; ++ char *var; ++ char *in; ++ int line; ++ void *priv; ++ struct template_element *parent; ++ struct template_element *sub; ++ struct template_element *sub2; ++ struct template_element *prev; ++ struct template_element *next; ++}; ++ ++ ++struct template_element *parse_template(struct template_cb *cb, FILE *in); ++void execute_template(struct template_cb *cb, struct template_element *e); ++void free_template(struct template_cb *cb, struct template_element *e); ++ ++#endif +Index: busybox-1.7.2/editors/awx_parser.l +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/editors/awx_parser.l 2007-10-05 01:43:59.547510259 +0200 +@@ -0,0 +1,302 @@ ++%{ ++#include ++#include ++#include ++#include "busybox.h" ++#include "awx_parser.h" ++ ++enum { ++ S_INIT, ++ S_TEXT, ++ S_CODE, ++ S_IF_START, ++ S_FOR_START, ++ S_FOR_IN, ++ S_END, ++ S_ELSE, ++ S_EOF ++}; ++int state; ++ ++#undef DEBUG ++#ifdef DEBUG ++char *statestr[] = { ++ [S_INIT] = "S_INIT", ++ [S_TEXT] = "S_TEXT", ++ [S_CODE] = "S_CODE", ++ [S_IF_START] = "S_IF_START", ++ [S_FOR_START] = "S_FOR_START", ++ [S_FOR_IN] = "S_FOR_IN", ++ [S_EOF] = "S_EOF" ++}; ++ ++char *typestr[] = { ++ [T_TEXT] = "T_TEXT", ++ [T_FOR] = "T_FOR", ++ [T_IF] = "T_IF", ++ [T_CODE] = "T_CODE" ++}; ++#endif ++ ++static struct template_cb *parse_cb; ++static struct template_element *cur, *head; ++static char *textbuf; ++static unsigned int buflen; ++static unsigned int buf_offset; ++static int _lnr = 0; ++ ++static void buf_realloc(void) ++{ ++ buflen *= 2; ++ textbuf = xrealloc(textbuf, buflen); ++} ++ ++static void parse_error(char *str) ++{ ++ fprintf(stderr, "Parse error%s%s\n", (str ? ": " : "!"), (str ?: "")); ++ exit(255); ++} ++ ++ ++static struct template_element *new_template_element(struct template_element *parent) ++{ ++ struct template_element *ptr; ++ ++ ptr = xzalloc(sizeof(struct template_element)); ++ ptr->parent = parent; ++ return ptr; ++} ++ ++static inline void next_template_element(void) ++{ ++ cur->next = new_template_element(cur->parent); ++ cur->next->prev = cur; ++ cur = cur->next; ++} ++ ++static void addtext(char *text) ++{ ++ while(buf_offset + strlen(text) + 1 > buflen) ++ buf_realloc(); ++ ++ buf_offset += sprintf(&textbuf[buf_offset], "%s", text); ++} ++ ++static void set_state(int newstate) ++{ ++ char *ptr; ++ ++#ifdef DEBUG ++ static int _rec = 0; ++ fprintf(stderr, "DEBUG(%d): %s => %s: %s\n", _rec, statestr[state], statestr[newstate], textbuf); ++#endif ++ ptr = xstrdup(textbuf); ++ if (state == S_FOR_IN) ++ cur->in = ptr; ++ else ++ cur->var = ptr; ++ ++ if (parse_cb && (cur->t == T_CODE) && parse_cb->prepare_code) ++ parse_cb->prepare_code(cur); ++ ++ buf_offset = 0; ++ *textbuf = 0; ++ ++ switch(newstate) { ++#if 0 ++ case S_EOF: ++ if (cur->parent) ++ parse_error(); ++ break; ++#endif ++ case S_FOR_START: ++ if (ptr || !cur->prev) ++ next_template_element(); ++ cur->t = T_FOR; ++ break; ++ case S_IF_START: ++ if (ptr || !cur->prev) ++ next_template_element(); ++ cur->t = T_IF; ++ break; ++ case S_ELSE: ++ cur = cur->parent; ++ if (!cur) ++ parse_error("'@else' without parent element"); ++ cur->sub2 = new_template_element(cur); ++ cur = cur->sub2; ++ newstate = S_TEXT; ++ break; ++ case S_END: ++#ifdef DEBUG ++ _rec--; ++#endif ++ cur = cur->parent; ++ if (!cur) ++ parse_error("'@end' without parent element"); ++ ++ next_template_element(); ++ cur->t = T_TEXT; ++ newstate = S_TEXT; ++ break; ++ case S_TEXT: ++ switch (cur->t) { ++ case T_CODE: ++ next_template_element(); ++ break; ++ case T_IF: ++ case T_FOR: ++#ifdef DEBUG ++ _rec++; ++#endif ++ cur->sub = new_template_element(cur); ++ cur = cur->sub; ++ break; ++ default: ++ break; ++ } ++ cur->t = T_TEXT; ++ break; ++ case S_CODE: ++ if (ptr || !cur->prev) ++ next_template_element(); ++ cur->t = T_CODE; ++ break; ++ default: ++ break; ++ } ++ cur->line = _lnr; ++ state = newstate; ++} ++ ++%} ++ ++%% ++"<%"[ \n\t]*"@if"[ \n\t]+ { ++ if (state == S_TEXT) ++ set_state(S_IF_START); ++ else ++ REJECT; ++} ++ ++"<%"[ \n\t]*"@for"[ \n\t]+ { ++ if (state == S_TEXT) ++ set_state(S_FOR_START); ++ else ++ REJECT; ++} ++ ++[ \n\t]+"in"[ \n\t]+ { ++ if (state == S_FOR_START) ++ set_state(S_FOR_IN); ++ else ++ REJECT; ++} ++ ++"<%"[ \n\t]*"@end"[ \n\t]*%> { ++ if (state != S_TEXT) ++ REJECT; ++ set_state(S_END); ++} ++ ++"<%"[ \n\t]*"@else"[ \n\t]*%> { ++ if (state != S_TEXT) ++ REJECT; ++ set_state(S_ELSE); ++} ++ ++"<%" { ++ if (state != S_TEXT) ++ parse_error("'<%' cannot be nested"); ++ set_state(S_CODE); ++} ++ ++[ \n\t]"%>" { ++ if (state == S_TEXT) ++ REJECT; ++ set_state(S_TEXT); ++} ++ ++\n { ++ _lnr++; ++ if (state == S_TEXT) ++ addtext(yytext); ++} ++. { ++ addtext(yytext); ++} ++ ++ ++%% ++ ++ ++void execute_template(struct template_cb *cb, struct template_element *e) ++{ ++ static int rec = 0; ++ ++ while (e) { ++#ifdef DEBUG ++ fprintf(stderr, "DEBUG: execute(%d)\t%s\n", rec, typestr[e->t]); ++#endif ++ rec++; ++ if (cb->handle_element) ++ cb->handle_element(cb, e); ++ rec--; ++ e = e->next; ++ } ++} ++ ++int yywrap() ++{ ++ set_state(S_EOF); ++ return 1; ++} ++ ++struct template_element *parse_template(struct template_cb *cb, FILE *in) ++{ ++ _lnr = 1; ++ buf_offset = 0; ++ state = S_TEXT; ++ parse_cb = cb; ++ ++ buflen = 4096; ++ textbuf = xzalloc(buflen); ++ ++ head = xzalloc(sizeof(struct template_element)); ++ head->t = T_TEXT; ++ cur = head; ++ ++ yyin = in; ++ yylex(); ++ ++ return head; ++} ++ ++void free_template(struct template_cb *cb, struct template_element *e) ++{ ++ struct template_element *next; ++ return; ++ if (!e) ++ return; ++ ++ switch (e->t) { ++ case T_CODE: ++ if (cb->free_code) ++ cb->free_code(e); ++ break; ++ case T_FOR: ++ case T_IF: ++ free_template(cb, e->sub); ++ break; ++ default: ++ break; ++ } ++ if (e->var) ++ free(e->var); ++ if (e->in) ++ free(e->in); ++ ++ next = e->next; ++ free(e); ++ return free_template(cb, next); ++} +Index: busybox-1.7.2/editors/Config.in +=================================================================== +--- busybox-1.7.2.orig/editors/Config.in 2007-10-05 01:39:50.097294897 +0200 ++++ busybox-1.7.2/editors/Config.in 2007-10-05 01:43:59.583512308 +0200 +@@ -12,6 +12,13 @@ + Awk is used as a pattern scanning and processing language. This is + the BusyBox implementation of that programming language. + ++config AWX ++ bool "Enable awx (awk web extension)" ++ default n ++ depends on AWK ++ help ++ awx - awk web extension ++ + config FEATURE_AWK_MATH + bool "Enable math functions (requires libm)" + default y +Index: busybox-1.7.2/editors/Kbuild +=================================================================== +--- busybox-1.7.2.orig/editors/Kbuild 2007-10-05 01:39:50.105295361 +0200 ++++ busybox-1.7.2/editors/Kbuild 2007-10-05 01:43:59.627514818 +0200 +@@ -12,3 +12,12 @@ + lib-$(CONFIG_PATCH) += patch.o + lib-$(CONFIG_SED) += sed.o + lib-$(CONFIG_VI) += vi.o ++lib-$(CONFIG_AWX) += awx_parser.o ++ ++editors/awx_parser.c: editors/awx_parser.l editors/awx_parser.h ++ @flex $< ++ @mv lex.yy.c $@ ++ ++editors/awx_parser.o: editors/awx_parser.c FORCE ++ $(call cmd,force_checksrc) ++ $(call if_changed_rule,cc_o_c) +Index: busybox-1.7.2/include/applets.h +=================================================================== +--- busybox-1.7.2.orig/include/applets.h 2007-10-05 01:43:59.203490652 +0200 ++++ busybox-1.7.2/include/applets.h 2007-10-05 01:43:59.647515958 +0200 +@@ -76,6 +76,7 @@ + USE_ARPING(APPLET(arping, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) + USE_ASH(APPLET_NOUSAGE(ash, ash, _BB_DIR_BIN, _BB_SUID_NEVER)) + USE_AWK(APPLET_NOEXEC(awk, awk, _BB_DIR_USR_BIN, _BB_SUID_NEVER, awk)) ++USE_AWX(APPLET_NOUSAGE(awx, awx, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) + USE_BASENAME(APPLET_NOFORK(basename, basename, _BB_DIR_USR_BIN, _BB_SUID_NEVER, basename)) + USE_BBCONFIG(APPLET(bbconfig, _BB_DIR_BIN, _BB_SUID_NEVER)) + //USE_BBSH(APPLET(bbsh, _BB_DIR_BIN, _BB_SUID_NEVER)) +Index: busybox-1.7.2/include/cgi.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/include/cgi.h 2007-10-05 01:43:59.667517098 +0200 +@@ -0,0 +1,8 @@ ++#ifndef CGI_H ++#define CGI_H ++ ++typedef enum { FORM_VAR, COOKIE_VAR } vartype; ++typedef void (*var_handler) (vartype, char *, char *); ++int cgi_init(var_handler); ++ ++#endif +Index: busybox-1.7.2/libbb/cgi.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ busybox-1.7.2/libbb/cgi.c 2007-10-05 01:43:59.707519378 +0200 +@@ -0,0 +1,457 @@ ++/* -------------------------------------------------------------------------- ++ * functions for processing cgi form data ++ * Copyright (C) 2007 by Felix Fietkau ++ * ++ * parts taken from the core of haserl.cgi - a poor-man's php for embedded/lightweight environments ++ * $Id: haserl.c,v 1.13 2004/11/10 17:59:35 nangel Exp $ ++ * Copyright (c) 2003,2004 Nathan Angelacos (nangel@users.sourceforge.net) ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program 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 ++ * General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ * ++ * ----- ++ * The x2c() and unescape_url() routines were taken from ++ * http://www.jmarshall.com/easy/cgi/getcgi.c.txt ++ * ++ * The comments in that text file state: ++ * ++ *** Written in 1996 by James Marshall, james@jmarshall.com, except ++ *** that the x2c() and unescape_url() routines were lifted directly ++ *** from NCSA's sample program util.c, packaged with their HTTPD. ++ *** For the latest, see http://www.jmarshall.com/easy/cgi/ ++ * ----- ++ * ++ ------------------------------------------------------------------------- */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#ifndef MAX_UPLOAD_KB ++#define MAX_UPLOAD_KB 2048 ++#endif ++#define TEMPDIR "/tmp" ++ ++static int global_upload_size = 0; ++static int ReadMimeEncodedInput(char *qs); ++static var_handler do_putvar = NULL; ++ ++/* ++ * Convert 2 char hex string into char it represents ++ * (from http://www.jmarshall.com/easy/cgi) ++ */ ++static char x2c (char *what) { ++ char digit; ++ ++ digit=(what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0')); ++ digit *=16; ++ digit+=(what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0')); ++ ++ return digit; ++} ++ ++/* ++ * unsescape %xx to the characters they represent ++ */ ++ ++static void unescape_url (char *url) { ++ int i,j; ++ ++ for (i=0, j=0; url[j]; ++i, ++j) { ++ if ((url[i] = url[j]) == '%') { ++ url[i] = x2c(&url[j+1]); ++ j+=2; ++ } ++ } ++ url[i]='\0'; ++} ++ ++static inline void put_var(vartype type, char *var) ++{ ++ char *val; ++ ++ if (!do_putvar) ++ return; ++ ++ val = strchr(var, '='); ++ if (!val) ++ return; ++ ++ *val = 0; ++ val++; ++ do_putvar(type, var, val); ++ ++ return; ++} ++ ++ ++/* CookieVars () ++ * if HTTP_COOKIE is passed as an environment variable, ++ * attempt to parse its values into environment variables ++ */ ++static void CookieVars (void) ++{ ++ char *qs; ++ char *token; ++ ++ if (getenv("HTTP_COOKIE") != NULL) ++ qs=strdup(getenv("HTTP_COOKIE")); ++ else ++ return; ++ ++ /** split on; to extract name value pairs */ ++ token=strtok(qs, ";"); ++ while (token) { ++ // skip leading spaces ++ while ( token[0] == ' ' ) ++ token++; ++ ++ put_var(COOKIE_VAR, token); ++ ++ token = strtok(NULL, ";"); ++ } ++ free (qs); ++} ++ ++/* ++ * Read cgi variables from query string, and put in environment ++ */ ++static int ReadCGIQueryString (void) ++{ ++ char *qs; ++ char *token; ++ int i; ++ ++ if (getenv("QUERY_STRING") != NULL) ++ qs=strdup(getenv("QUERY_STRING")); ++ else ++ return 0; ++ ++ /* change plusses into spaces */ ++ for (i=0; qs[i]; i++ ) { if (qs[i] == '+' ) { qs[i] = ' ';} }; ++ ++ /** split on & and ; to extract name value pairs */ ++ ++ token=strtok(qs, "&;"); ++ while (token) { ++ unescape_url(token); ++ put_var(FORM_VAR, token); ++ token=strtok(NULL, "&;"); ++ } ++ free(qs); ++ ++ return 0; ++} ++ ++ ++/* ++ * Read cgi variables from stdin (for POST queries) ++ * (oh... and if its mime-encoded file upload, we save the ++ * file to /tmp; and return the name of the tmp file ++ * the cgi script is responsible for disposing of the tmp file ++ */ ++ ++static int ReadCGIPOSTValues (void) { ++ char *qs; ++ int content_length; ++ int i; ++ char *token; ++ ++ ++ if (getenv("CONTENT_LENGTH") == NULL) ++ return(-1); ++ else ++ content_length = atoi(getenv("CONTENT_LENGTH")); ++ ++ /* protect ourselves from 20GB file uploads */ ++ if (content_length > MAX_UPLOAD_KB * 1024 ) { ++ /* But we need to finish reading the content */ ++ while ( fread( &i, sizeof(int), 1, stdin) == 1 ); ++ return -1; ++ } ++ ++ if (!(qs=malloc(content_length+1))) ++ return -1; ++ ++ /* set the buffer to null, so that a browser messing with less ++ data than content_length won't buffer underrun us */ ++ memset(qs, 0 ,content_length+1); ++ ++ if ((!fread(qs,content_length,1,stdin) && ++ (content_length > 0) ++ && !feof(stdin))) { ++ ++ free(qs); ++ return -1; ++ } ++ ++ if (getenv("CONTENT_TYPE") && (strncasecmp(getenv("CONTENT_TYPE"), "multipart/form-data", 19) == 0)) { ++ /* This is a mime request, we need to go to the mime handler */ ++ i=ReadMimeEncodedInput(qs); ++ free(qs); ++ ++ return i; ++ } ++ ++ /* change plusses into spaces */ ++ for (i=0; qs[i]; i++ ) { if (qs[i] == '+' ) { qs[i] = ' ';} }; ++ ++ /** split on & and ; to extract name value pairs */ ++ token=strtok(qs, "&;"); ++ while (token) { ++ unescape_url(token); ++ put_var(FORM_VAR, token); ++ token=strtok(NULL, "&;"); ++ } ++ ++ free(qs); ++ ++ return 0; ++} ++ ++/* ++ * LineToStr - Scans char and replaces the first "\n" with a "\0"; ++ * If it finds a "\r", it does that to; (fix DOS brokennes) returns ++ * the length of the string; ++ */ ++static int LineToStr (char *string, size_t max) { ++ size_t offset=0; ++ ++ while ((offset < max) && (string[offset] != '\n') && (string[offset] != '\r')) ++ offset++; ++ ++ if (string[offset] == '\r') { ++ string[offset]='\0'; ++ offset++; ++ } ++ if (string[offset] == '\n') { ++ string[offset]='\0'; ++ offset++; ++ } ++ ++ return offset; ++} ++ ++ ++/* ++ * ReadMimeEncodedInput - handles things that are mime encoded ++ * takes a pointer to the input; returns 0 on success ++ */ ++ ++static int ReadMimeEncodedInput(char *qs) ++{ ++ char *boundary; ++ char *ct; ++ int i; ++ int datastart; ++ size_t cl; ++ size_t offset; ++ char *envname; ++ char *filename; ++ char *ptr; ++ int line; ++ char tmpname[] = TEMPDIR "/XXXXXX"; ++ int fd; ++ /* we should only get here if the content type was set. Segfaults happen ++ if Content_Type is null */ ++ ++ if (getenv("CONTENT_LENGTH") == NULL) ++ /* No content length?! */ ++ return(-1); ++ ++ cl=atoi(getenv("CONTENT_LENGTH")); ++ ++ /* we do this 'cause we can't mess with the real env. variable - it would ++ * overwrite the environment - I tried. ++ */ ++ i=strlen(getenv("CONTENT_TYPE"))+1; ++ ct=malloc(i); ++ if (ct) ++ memcpy(ct, getenv("CONTENT_TYPE"), i); ++ else ++ return(-1); ++ ++ i=(int) NULL; ++ if (ct != NULL) { ++ while (i < strlen(ct) && (strncmp("boundary=", &ct[i], 9) != 0)) ++ i++; ++ } ++ if (i == strlen(ct)) { ++ /* no boundary informaiton found */ ++ free(ct); ++ return -1; ++ } ++ boundary=&ct[i+7]; ++ /* add two leading -- to the boundary */ ++ boundary[0]='-'; ++ boundary[1]='-'; ++ ++ /* begin the big loop. Look for: ++ --boundary ++ Content-Disposition: form-data; name="......." ++ .... ++ ++ content ++ --boundary ++ Content-Disposition: form-data; name="....." filename="....." ++ ... ++ ++ --boundary-- ++ eof ++ */ ++ ++ offset=0; ++ while (offset < cl) { ++ /* first look for boundary */ ++ while ((offset < cl) && (memcmp(&qs[offset], boundary, strlen(boundary)))) ++ offset++; ++ ++ /* if we got here and we ran off the end, its an error */ ++ if (offset >= cl) { ++ free(ct); ++ return -1; ++ } ++ ++ /* if the two characters following the boundary are --, */ ++ /* then we are at the end, exit */ ++ if (memcmp(&qs[offset+strlen(boundary)], "--", 2) == 0) { ++ offset+=2; ++ break; ++ } ++ /* find where the offset should be */ ++ line=LineToStr(&qs[offset], cl-offset); ++ offset+=line; ++ ++ /* Now we're going to look for content-disposition */ ++ line=LineToStr(&qs[offset], cl-offset); ++ if (strncasecmp(&qs[offset], "Content-Disposition", 19) != 0) { ++ /* hmm... content disposition was not where we expected it */ ++ free(ct); ++ return -1; ++ } ++ /* Found it, so let's go find "name=" */ ++ if (!(envname=strstr(&qs[offset], "name="))) { ++ /* now name= is missing?! */ ++ free(ct); ++ return(-1); ++ } else ++ envname+=6; ++ ++ /* is there a filename tag? */ ++ if ((filename=strstr(&qs[offset], "filename="))!= NULL) ++ filename+=10; ++ else ++ filename=NULL; ++ ++ /* make envname and filename ASCIIZ */ ++ for (i=0; (envname[i] != '"') && (envname[i] != '\0'); i++); ++ ++ envname[i] = '\0'; ++ if (filename) { ++ for (i=0; (filename[i] != '"') && (filename[i] != '\0'); i++); ++ filename[i] = '\0'; ++ } ++ offset+=line; ++ ++ /* Ok, by some miracle, we have the name; let's skip till we */ ++ /* come to a blank line */ ++ line=LineToStr(&qs[offset], cl-offset); ++ while (strlen(&qs[offset]) > 1) { ++ offset+=line; ++ line=LineToStr(&qs[offset], cl-offset); ++ } ++ offset+=line; ++ datastart=offset; ++ /* And we go back to looking for a boundary */ ++ while ((offset < cl) && (memcmp(&qs[offset], boundary, strlen(boundary)))) ++ offset++; ++ ++ /* strip [cr] lf */ ++ if ((qs[offset-1] == '\n') && (qs[offset-2] == '\r')) ++ offset-=2; ++ else ++ offset-=1; ++ ++ qs[offset]=0; ++ ++ /* ok, at this point, we know where the name is, and we know */ ++ /* where the content is... we have to do one of two things */ ++ /* based on whether its a file or not */ ++ if (filename==NULL) { /* its not a file, so its easy */ ++ /* just jam the content after the name */ ++ memcpy(&envname[strlen(envname)+1], &qs[datastart], offset-datastart+1); ++ envname[strlen(envname)]='='; ++ put_var(FORM_VAR, envname); ++ } else { /* handle the fileupload case */ ++ if (offset-datastart) { /* only if they uploaded */ ++ if ( global_upload_size == 0 ) { ++ return -1; ++ } ++ /* stuff in the filename */ ++ ptr= calloc ( sizeof (char), strlen(envname)+strlen(filename)+2+5 ); ++ sprintf (ptr, "%s_name=%s", envname, filename); ++ put_var(FORM_VAR, ptr); ++ free(ptr); ++ ++ fd=mkstemp(tmpname); ++ ++ if (fd == -1) ++ return(-1); ++ ++ write(fd, &qs[datastart], offset-datastart); ++ close(fd); ++ ptr= calloc (sizeof(char), strlen(envname)+strlen(tmpname)+2); ++ sprintf (ptr, "%s=%s", envname, tmpname); ++ put_var(FORM_VAR, ptr); ++ free(ptr); ++ } ++ } ++ } ++ free(ct); ++ return 0; ++} ++ ++ ++/*------------------------------------------------------------------------- ++ * ++ * Main ++ * ++ *------------------------------------------------------------------------*/ ++ ++int cgi_init(var_handler putvar_handler) ++{ ++ int retval = 0; ++ ++ do_putvar = putvar_handler; ++ ++ /* Read the current environment into our chain */ ++ CookieVars(); ++ if (getenv("REQUEST_METHOD")) { ++ if (strcasecmp(getenv("REQUEST_METHOD"), "GET") == 0) ++ retval = ReadCGIQueryString(); ++ ++ if (strcasecmp(getenv("REQUEST_METHOD"), "POST") == 0) ++ retval = ReadCGIPOSTValues(); ++ } ++ ++ return retval; ++} +Index: busybox-1.7.2/libbb/Kbuild +=================================================================== +--- busybox-1.7.2.orig/libbb/Kbuild 2007-10-05 01:43:59.387501141 +0200 ++++ busybox-1.7.2/libbb/Kbuild 2007-10-05 01:43:59.751521884 +0200 +@@ -99,6 +99,7 @@ + lib-y += xreadlink.o + + # conditionally compiled objects: ++lib-$(CONFIG_AWX) += cgi.o + lib-$(CONFIG_FEATURE_MOUNT_LOOP) += loop.o + lib-$(CONFIG_LOSETUP) += loop.o + lib-$(CONFIG_FEATURE_MTAB_SUPPORT) += mtab.o diff --git a/package/busybox/patches/911-ipkg.patch b/package/busybox/patches/911-ipkg.patch deleted file mode 100644 index d96063b233..0000000000 --- a/package/busybox/patches/911-ipkg.patch +++ /dev/null @@ -1,13765 +0,0 @@ -Index: busybox-1.4.2/archival/Config.in -=================================================================== ---- busybox-1.4.2.orig/archival/Config.in 2007-06-04 13:21:31.573176816 +0200 -+++ busybox-1.4.2/archival/Config.in 2007-06-04 13:21:36.706396448 +0200 -@@ -121,6 +121,14 @@ - gzip is used to compress files. - It's probably the most widely used UNIX compression program. - -+config IPKG -+ bool "ipkg" -+ default n -+ select MD5SUM -+ select WGET -+ help -+ ipkg is the itsy package management system. -+ - config RPM2CPIO - bool "rpm2cpio" - default n -Index: busybox-1.4.2/archival/dpkg.c -=================================================================== ---- busybox-1.4.2.orig/archival/dpkg.c 2007-06-04 13:21:31.579175904 +0200 -+++ busybox-1.4.2/archival/dpkg.c 2007-06-04 13:21:36.706396448 +0200 -@@ -1463,6 +1463,10 @@ - return ar_handle->sub_archive->buffer; - } - -+/* -+ -+// moved to data_extract_all.c -+ - static void data_extract_all_prefix(archive_handle_t *archive_handle) - { - char *name_ptr = archive_handle->file_header->name; -@@ -1475,6 +1479,8 @@ - return; - } - -+*/ -+ - static void unpack_package(deb_file_t *deb_file) - { - const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name]; -Index: busybox-1.4.2/archival/ipkg.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/ipkg.c 2007-06-04 13:21:36.707396296 +0200 -@@ -0,0 +1,26 @@ -+/* ipkg.c - the itsy package management system -+ -+ Florina Boor -+ -+ Copyright (C) 2003 kernel concepts -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+ -+ ipkg command line frontend using libipkg -+ -+*/ -+ -+#include "libipkg/libipkg.h" -+ -+int ipkg_main(int argc, char **argv) -+{ -+ return ipkg_op(argc, argv); -+} -Index: busybox-1.4.2/archival/Kbuild -=================================================================== ---- busybox-1.4.2.orig/archival/Kbuild 2007-06-04 13:21:31.588174536 +0200 -+++ busybox-1.4.2/archival/Kbuild 2007-06-04 13:21:36.707396296 +0200 -@@ -15,6 +15,7 @@ - lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o - lib-$(CONFIG_GUNZIP) += gunzip.o - lib-$(CONFIG_GZIP) += gzip.o -+lib-$(CONFIG_IPKG) += ipkg.o - lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o - lib-$(CONFIG_RPM) += rpm.o - lib-$(CONFIG_TAR) += tar.o -Index: busybox-1.4.2/archival/libipkg/args.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/args.c 2007-06-04 13:21:36.707396296 +0200 -@@ -0,0 +1,242 @@ -+/* args.c - parse command-line args -+ -+ Carl D. Worth -+ -+ Copyright 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or modify -+ it under the terms of the GNU General Public License as published by -+ the Free Software Foundation; either version 2, or (at your option) -+ any later version. -+ -+ This program 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 General Public License for more details. -+ */ -+ -+#include -+#include -+#include -+#include -+ -+#include "ipkg.h" -+#include "ipkg_message.h" -+ -+#include "args.h" -+#include "sprintf_alloc.h" -+ -+#include "libbb.h" -+ -+ -+static void print_version(void); -+ -+enum long_args_opt -+{ -+ ARGS_OPT_FORCE_DEFAULTS = 129, -+ ARGS_OPT_FORCE_DEPENDS, -+ ARGS_OPT_FORCE_OVERWRITE, -+ ARGS_OPT_FORCE_DOWNGRADE, -+ ARGS_OPT_FORCE_REINSTALL, -+ ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES, -+ ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES, -+ ARGS_OPT_FORCE_SPACE, -+ ARGS_OPT_NOACTION, -+ ARGS_OPT_NODEPS, -+ ARGS_OPT_VERBOSE_WGET, -+ ARGS_OPT_VERBOSITY, -+ ARGS_OPT_MULTIPLE_PROVIDERS -+}; -+ -+int args_init(args_t *args) -+{ -+ char *conf_file_dir; -+ -+ memset(args, 0, sizeof(args_t)); -+ -+ args->dest = ARGS_DEFAULT_DEST; -+ -+ conf_file_dir = getenv("IPKG_CONF_DIR"); -+ if (conf_file_dir == NULL || conf_file_dir[0] == '\0') { -+ conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR; -+ } -+ sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir, -+ ARGS_DEFAULT_CONF_FILE_NAME); -+ -+ args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS; -+ args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS; -+ args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE; -+ args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE; -+ args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL; -+ args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES; -+ args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES; -+ args->noaction = ARGS_DEFAULT_NOACTION; -+ args->nodeps = ARGS_DEFAULT_NODEPS; -+ args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET; -+ args->verbosity = ARGS_DEFAULT_VERBOSITY; -+ args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT; -+ args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD; -+ args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD; -+ args->multiple_providers = 0; -+ args->nocheckfordirorfile = 0; -+ args->noreadfeedsfile = 0; -+ -+ return 1; -+} -+ -+void args_deinit(args_t *args) -+{ -+ free(args->conf_file); -+ args->conf_file = NULL; -+} -+ -+int args_parse(args_t *args, int argc, char *argv[]) -+{ -+ int c; -+ int option_index = 0; -+ int parse_err = 0; -+ static struct option long_options[] = { -+ {"query-all", 0, 0, 'A'}, -+ {"conf-file", 1, 0, 'f'}, -+ {"conf", 1, 0, 'f'}, -+ {"dest", 1, 0, 'd'}, -+ {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS}, -+ {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS}, -+ {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS}, -+ {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS}, -+ {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE}, -+ {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE}, -+ {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE}, -+ {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE}, -+ {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL}, -+ {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL}, -+ {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE}, -+ {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE}, -+ {"recursive", 0, 0, -+ ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES}, -+ {"force-removal-of-dependent-packages", 0, 0, -+ ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES}, -+ {"force_removal_of_dependent_packages", 0, 0, -+ ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES}, -+ {"force-removal-of-essential-packages", 0, 0, -+ ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES}, -+ {"force_removal_of_essential_packages", 0, 0, -+ ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES}, -+ {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS}, -+ {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS}, -+ {"noaction", 0, 0, ARGS_OPT_NOACTION}, -+ {"nodeps", 0, 0, ARGS_OPT_NODEPS}, -+ {"offline", 1, 0, 'o'}, -+ {"offline-root", 1, 0, 'o'}, -+ {"test", 0, 0, ARGS_OPT_NOACTION}, -+ {"tmp-dir", 1, 0, 't'}, -+ {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET}, -+ {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET}, -+ {"verbosity", 2, 0, 'V'}, -+ {"version", 0, 0, 'v'}, -+ {0, 0, 0, 0} -+ }; -+ -+ while (1) { -+ c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index); -+ if (c == -1) -+ break; -+ -+ switch (c) { -+ case 'A': -+ args->query_all = 1; -+ break; -+ case 'd': -+ args->dest = optarg; -+ break; -+ case 'f': -+ free(args->conf_file); -+ args->conf_file = strdup(optarg); -+ break; -+ case 'o': -+ args->offline_root = optarg; -+ break; -+ case 'n': -+ args->noaction = 1; -+ break; -+ case 't': -+ args->tmp_dir = strdup(optarg); -+ break; -+ case 'v': -+ print_version(); -+ exit(0); -+ case 'V': -+ case ARGS_OPT_VERBOSITY: -+ if (optarg) -+ args->verbosity = atoi(optarg); -+ else -+ args->verbosity += 1; -+ break; -+ case ARGS_OPT_FORCE_DEFAULTS: -+ args->force_defaults = 1; -+ break; -+ case ARGS_OPT_FORCE_DEPENDS: -+ args->force_depends = 1; -+ break; -+ case ARGS_OPT_FORCE_OVERWRITE: -+ args->force_overwrite = 1; -+ break; -+ case ARGS_OPT_FORCE_DOWNGRADE: -+ args->force_downgrade = 1; -+ break; -+ case ARGS_OPT_FORCE_REINSTALL: -+ args->force_reinstall = 1; -+ break; -+ case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES: -+ args->force_removal_of_essential_packages = 1; -+ break; -+ case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES: -+ args->force_removal_of_dependent_packages = 1; -+ break; -+ case ARGS_OPT_FORCE_SPACE: -+ args->force_space = 1; -+ break; -+ case ARGS_OPT_VERBOSE_WGET: -+ args->verbose_wget = 1; -+ break; -+ case ARGS_OPT_MULTIPLE_PROVIDERS: -+ args->multiple_providers = 1; -+ break; -+ case ARGS_OPT_NODEPS: -+ args->nodeps = 1; -+ break; -+ case ARGS_OPT_NOACTION: -+ args->noaction = 1; -+ break; -+ case ':': -+ parse_err++; -+ break; -+ case '?': -+ parse_err++; -+ break; -+ default: -+ bb_error_msg("Confusion: getopt_long returned %d\n", c); -+ } -+ } -+ -+ if (parse_err) { -+ return -parse_err; -+ } else { -+ return optind; -+ } -+} -+ -+void args_usage(char *complaint) -+{ -+ if (complaint) { -+ bb_error_msg("%s\n", complaint); -+ } -+ print_version(); -+ bb_show_usage(); -+ exit(1); -+} -+ -+static void print_version(void) -+{ -+ bb_error_msg("version %s\n", IPKG_VERSION); -+} -Index: busybox-1.4.2/archival/libipkg/args.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/args.h 2007-06-04 13:21:36.707396296 +0200 -@@ -0,0 +1,72 @@ -+/* args.h - parse command-line args -+ -+ Carl D. Worth -+ -+ Copyright 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or modify -+ it under the terms of the GNU General Public License as published by -+ the Free Software Foundation; either version 2, or (at your option) -+ any later version. -+ -+ This program 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 General Public License for more details. -+*/ -+ -+#ifndef ARGS_H -+#define ARGS_H -+ -+struct args -+{ -+ char *conf_file; -+ char *dest; -+ char *tmp_dir; -+ int force_defaults; -+ int force_depends; -+ int force_overwrite; -+ int force_downgrade; -+ int force_reinstall; -+ int force_removal_of_essential_packages; -+ int force_removal_of_dependent_packages; -+ int force_space; -+ int noaction; -+ int nodeps; -+ int multiple_providers; -+ int query_all; -+ int verbose_wget; -+ int verbosity; -+ int nocheckfordirorfile; -+ int noreadfeedsfile; -+ char *offline_root; -+ char *offline_root_pre_script_cmd; -+ char *offline_root_post_script_cmd; -+}; -+typedef struct args args_t; -+ -+#define ARGS_DEFAULT_CONF_FILE_DIR "/etc" -+#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf" -+#define ARGS_DEFAULT_DEST NULL -+#define ARGS_DEFAULT_FORCE_DEFAULTS 0 -+#define ARGS_DEFAULT_FORCE_DEPENDS 0 -+#define ARGS_DEFAULT_FORCE_OVERWRITE 0 -+#define ARGS_DEFAULT_FORCE_DOWNGRADE 0 -+#define ARGS_DEFAULT_FORCE_REINSTALL 0 -+#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0 -+#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0 -+#define ARGS_DEFAULT_FORCE_SPACE 0 -+#define ARGS_DEFAULT_OFFLINE_ROOT NULL -+#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL -+#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL -+#define ARGS_DEFAULT_NOACTION 0 -+#define ARGS_DEFAULT_NODEPS 0 -+#define ARGS_DEFAULT_VERBOSE_WGET 0 -+#define ARGS_DEFAULT_VERBOSITY 1 -+ -+int args_init(args_t *args); -+void args_deinit(args_t *args); -+int args_parse(args_t *args, int argc, char *argv[]); -+void args_usage(char *complaint); -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/conffile.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/conffile.c 2007-06-04 13:21:36.708396144 +0200 -@@ -0,0 +1,64 @@ -+/* conffile.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include -+#include -+ -+#include "ipkg.h" -+#include "ipkg_message.h" -+ -+#include "conffile.h" -+#include "file_util.h" -+#include "sprintf_alloc.h" -+ -+int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum) -+{ -+ return nv_pair_init(conffile, file_name, md5sum); -+} -+ -+void conffile_deinit(conffile_t *conffile) -+{ -+ nv_pair_deinit(conffile); -+} -+ -+int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile) -+{ -+ char *md5sum; -+ char *filename = conffile->name; -+ char *root_filename; -+ int ret; -+ -+ if (conffile->value == NULL) { -+ ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name); -+ return 1; -+ } -+ -+ root_filename = root_filename_alloc(conf, filename); -+ -+ md5sum = file_md5sum_alloc(root_filename); -+ -+ ret = strcmp(md5sum, conffile->value); -+ if (ret) { -+ ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__, -+ conffile->name, md5sum, conffile->value); -+ } -+ -+ free(root_filename); -+ free(md5sum); -+ -+ return ret; -+} -Index: busybox-1.4.2/archival/libipkg/conffile.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/conffile.h 2007-06-04 13:21:36.708396144 +0200 -@@ -0,0 +1,30 @@ -+/* conffile.h - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef CONFFILE_H -+#define CONFFILE_H -+ -+#include "nv_pair.h" -+ -+typedef struct nv_pair conffile_t; -+ -+int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum); -+void conffile_deinit(conffile_t *conffile); -+int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile); -+ -+#endif -+ -Index: busybox-1.4.2/archival/libipkg/conffile_list.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/conffile_list.c 2007-06-04 13:21:36.708396144 +0200 -@@ -0,0 +1,47 @@ -+/* conffile_list.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+ -+#include "conffile_list.h" -+ -+int conffile_list_init(conffile_list_t *list) -+{ -+ return nv_pair_list_init(list); -+} -+ -+void conffile_list_deinit(conffile_list_t *list) -+{ -+ nv_pair_list_deinit(list); -+} -+ -+conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name, -+ const char *md5sum) -+{ -+ return nv_pair_list_append(list, file_name, md5sum); -+} -+ -+int conffile_list_push(conffile_list_t *list, conffile_t *data) -+{ -+ return nv_pair_list_push(list, data); -+} -+ -+conffile_list_elt_t *conffile_list_pop(conffile_list_t *list) -+{ -+ return nv_pair_list_pop(list); -+} -+ -Index: busybox-1.4.2/archival/libipkg/conffile_list.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/conffile_list.h 2007-06-04 13:21:36.708396144 +0200 -@@ -0,0 +1,36 @@ -+/* conffile_list.h - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef CONFFILE_LIST_H -+#define CONFFILE_LIST_H -+ -+#include "conffile.h" -+#include "nv_pair_list.h" -+ -+typedef struct nv_pair_list_elt conffile_list_elt_t; -+typedef struct nv_pair_list conffile_list_t; -+ -+int conffile_list_init(conffile_list_t *list); -+void conffile_list_deinit(conffile_list_t *list); -+ -+conffile_t *conffile_list_append(conffile_list_t *list, const char *name, -+ const char *root_dir); -+int conffile_list_push(conffile_list_t *list, conffile_t *data); -+conffile_list_elt_t *conffile_list_pop(conffile_list_t *list); -+ -+#endif -+ -Index: busybox-1.4.2/archival/libipkg/file_util.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/file_util.c 2007-06-04 13:21:36.708396144 +0200 -@@ -0,0 +1,132 @@ -+/* file_util.c - convenience routines for common stat operations -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+#include -+#include -+ -+#include "sprintf_alloc.h" -+#include "file_util.h" -+#include "libbb.h" -+#undef strlen -+ -+int file_exists(const char *file_name) -+{ -+ int err; -+ struct stat stat_buf; -+ -+ err = stat(file_name, &stat_buf); -+ if (err == 0) { -+ return 1; -+ } else { -+ return 0; -+ } -+} -+ -+int file_is_dir(const char *file_name) -+{ -+ int err; -+ struct stat stat_buf; -+ -+ err = stat(file_name, &stat_buf); -+ if (err) { -+ return 0; -+ } -+ -+ return S_ISDIR(stat_buf.st_mode); -+} -+ -+/* read a single line from a file, stopping at a newline or EOF. -+ If a newline is read, it will appear in the resulting string. -+ Return value is a malloc'ed char * which should be freed at -+ some point by the caller. -+ -+ Return value is NULL if the file is at EOF when called. -+*/ -+#define FILE_READ_LINE_BUF_SIZE 1024 -+char *file_read_line_alloc(FILE *file) -+{ -+ char buf[FILE_READ_LINE_BUF_SIZE]; -+ int buf_len; -+ char *line = NULL; -+ int line_size = 0; -+ -+ memset(buf, 0, FILE_READ_LINE_BUF_SIZE); -+ while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) { -+ buf_len = strlen(buf); -+ if (line) { -+ line_size += buf_len; -+ line = realloc(line, line_size); -+ if (line == NULL) { -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ break; -+ } -+ strcat(line, buf); -+ } else { -+ line_size = buf_len + 1; -+ line = strdup(buf); -+ } -+ if (buf[buf_len - 1] == '\n') { -+ break; -+ } -+ } -+ -+ return line; -+} -+ -+int file_move(const char *src, const char *dest) -+{ -+ int err; -+ -+ err = rename(src, dest); -+ -+ if (err && errno == EXDEV) { -+ err = file_copy(src, dest); -+ unlink(src); -+ } else if (err) { -+ fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n", -+ __FUNCTION__, src, dest, strerror(errno)); -+ } -+ -+ return err; -+} -+ -+/* I put these here to keep libbb dependencies from creeping all over -+ the ipkg code */ -+int file_copy(const char *src, const char *dest) -+{ -+ int err; -+ -+ err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS); -+ if (err) { -+ fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n", -+ __FUNCTION__, src, dest); -+ } -+ -+ return err; -+} -+ -+int file_mkdir_hier(const char *path, long mode) -+{ -+ return bb_make_directory((char *)path, mode, FILEUTILS_RECUR); -+} -+ -+char *file_md5sum_alloc(const char *file_name) -+{ -+ return hash_file(file_name, HASH_MD5); -+} -+ -Index: busybox-1.4.2/archival/libipkg/file_util.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/file_util.h 2007-06-04 13:21:36.708396144 +0200 -@@ -0,0 +1,29 @@ -+/* file_util.h - convenience routines for common file operations -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef FILE_UTIL_H -+#define FILE_UTIL_H -+ -+int file_exists(const char *file_name); -+int file_is_dir(const char *file_name); -+char *file_read_line_alloc(FILE *file); -+int file_move(const char *src, const char *dest); -+int file_copy(const char *src, const char *dest); -+int file_mkdir_hier(const char *path, long mode); -+char *file_md5sum_alloc(const char *file_name); -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/hash_table.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/hash_table.c 2007-06-04 13:21:36.709395992 +0200 -@@ -0,0 +1,155 @@ -+/* hash.c - hash tables for ipkg -+ -+ Steven M. Ayer, Jamey Hicks -+ -+ Copyright (C) 2002 Compaq Computer Corporation -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include -+#include -+#include -+#include -+#include "hash_table.h" -+#include "ipkg_message.h" -+ -+ -+static int hash_index(hash_table_t *hash, const char *pkg_name); -+static int rotating(const char *key, int len, int prime); -+ -+static int hash_index(hash_table_t *hash, const char *pkg_name) -+{ -+ return rotating(pkg_name, strlen(pkg_name), hash->n_entries); -+} -+ -+static int rotating(const char *key, int len, int prime) -+{ -+ unsigned int hash, i; -+ for (hash=len, i=0; i>28)^key[i]; -+ return (hash % prime); -+} -+ -+ -+/* -+ * this is an open table keyed by strings -+ */ -+int hash_table_init(const char *name, hash_table_t *hash, int len) -+{ -+ static int primes_table[] = { -+ 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587, -+ 19471, 23143, 33961, 46499, 49727, 99529, 0 -+ }; -+ int *picker; -+ -+ if (hash->entries != NULL) { -+ /* we have been here already */ -+ return 0; -+ } -+ -+ hash->name = name; -+ hash->entries = NULL; -+ hash->n_entries = 0; -+ hash->hash_entry_key = NULL; -+ -+ picker = primes_table; -+ while(*picker && (*picker++ < len)); -+ if(!*picker) -+ fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len); -+ --picker; -+ -+ hash->n_entries = *picker; -+ hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t)); -+ if (hash->entries == NULL) { -+ fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__); -+ return ENOMEM; -+ } -+ return 0; -+} -+ -+void hash_table_deinit(hash_table_t *hash) -+{ -+ free(hash->entries); -+ hash->entries = NULL; -+ hash->n_entries = 0; -+} -+ -+void *hash_table_get(hash_table_t *hash, const char *key) -+{ -+ int ndx= hash_index(hash, key); -+ hash_entry_t *hash_entry = hash->entries + ndx; -+ while (hash_entry) -+ { -+ if (hash_entry->key) -+ { -+ if (strcmp(key, hash_entry->key) == 0) { -+ // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key); -+ return hash_entry->data; -+ } -+ } -+ hash_entry = hash_entry->next; -+ } -+ return NULL; -+} -+ -+int hash_table_insert(hash_table_t *hash, const char *key, void *value) -+{ -+ int ndx= hash_index(hash, key); -+ hash_entry_t *hash_entry = hash->entries + ndx; -+ if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key); -+ if (hash_entry->key) { -+ if (strcmp(hash_entry->key, key) == 0) { -+ /* alread in table, update the value */ -+ if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key); -+ hash_entry->data = value; -+ return 0; -+ } else { -+ /* -+ * if this is a collision, we have to go to the end of the ll, -+ * then add a new entry -+ * before we can hook up the value -+ */ -+ if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key); -+ while (hash_entry->next) -+ hash_entry = hash_entry->next; -+ hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t)); -+ if (!hash_entry->next) { -+ return -ENOMEM; -+ } -+ hash_entry = hash_entry->next; -+ hash_entry->next = NULL; -+ } -+ } -+ hash->n_elements++; -+ hash_entry->key = strdup(key); -+ hash_entry->data = value; -+ -+ return 0; -+} -+ -+ -+void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data) -+{ -+ int i; -+ if (!hash || !f) -+ return; -+ -+ for (i = 0; i < hash->n_entries; i++) { -+ hash_entry_t *hash_entry = (hash->entries + i); -+ do { -+ if(hash_entry->key) { -+ f(hash_entry->key, hash_entry->data, data); -+ } -+ } while((hash_entry = hash_entry->next)); -+ } -+} -+ -Index: busybox-1.4.2/archival/libipkg/hash_table.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/hash_table.h 2007-06-04 13:21:36.709395992 +0200 -@@ -0,0 +1,44 @@ -+/* hash.h - hash tables for ipkg -+ -+ Steven M. Ayer, Jamey Hicks -+ -+ Copyright (C) 2002 Compaq Computer Corporation -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef _HASH_TABLE_H_ -+#define _HASH_TABLE_H_ -+ -+typedef struct hash_entry hash_entry_t; -+typedef struct hash_table hash_table_t; -+ -+struct hash_entry { -+ const char * key; -+ void * data; -+ struct hash_entry * next; -+}; -+ -+struct hash_table { -+ const char *name; -+ hash_entry_t * entries; -+ int n_entries; /* number of buckets */ -+ int n_elements; -+ const char * (*hash_entry_key)(void * data); -+}; -+ -+int hash_table_init(const char *name, hash_table_t *hash, int len); -+void hash_table_deinit(hash_table_t *hash); -+void *hash_table_get(hash_table_t *hash, const char *key); -+int hash_table_insert(hash_table_t *hash, const char *key, void *value); -+void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data); -+ -+#endif /* _HASH_TABLE_H_ */ -Index: busybox-1.4.2/archival/libipkg/ipkg_cmd.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg_cmd.c 2007-06-04 13:21:36.710395840 +0200 -@@ -0,0 +1,1431 @@ -+/* ipkg_cmd.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include -+ -+#include "ipkg.h" -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#include "ipkg_conf.h" -+#include "ipkg_cmd.h" -+#include "ipkg_message.h" -+#include "pkg.h" -+#include "pkg_dest.h" -+#include "pkg_parse.h" -+#include "sprintf_alloc.h" -+#include "pkg.h" -+#include "file_util.h" -+#include "str_util.h" -+#include "libbb.h" -+#include "unarchive.h" -+ -+#include -+ -+ -+#include "ipkg_download.h" -+#include "ipkg_install.h" -+#include "ipkg_upgrade.h" -+#include "ipkg_remove.h" -+#include "ipkg_configure.h" -+#include "ipkg_message.h" -+ -+#ifdef IPKG_LIB -+#include "libipkg.h" -+static void *p_userdata = NULL; -+#endif -+ -+static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv); -+static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv); -+ -+/* XXX: CLEANUP: The usage strings should be incorporated into this -+ array for easier maintenance */ -+static ipkg_cmd_t cmds[] = { -+ {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd}, -+ {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd}, -+ {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd}, -+ {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd}, -+ {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd}, -+ {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd}, -+ {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd}, -+ {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd}, -+ {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd}, -+ {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd}, -+ {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd}, -+ {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd}, -+ {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd}, -+ {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd}, -+ {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd}, -+ {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd}, -+ {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd}, -+ {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd}, -+ {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd}, -+ {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd}, -+ {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd}, -+ {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd}, -+ {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd}, -+ {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd}, -+ {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd}, -+ {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd}, -+ {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd}, -+ {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd}, -+ {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd}, -+}; -+ -+int ipkg_state_changed; -+static void write_status_files_if_changed(ipkg_conf_t *conf) -+{ -+ if (ipkg_state_changed && !conf->noaction) { -+ ipkg_message(conf, IPKG_INFO, -+ " writing status file\n"); -+ ipkg_conf_write_status_files(conf); -+ pkg_write_changed_filelists(conf); -+ } else { -+ ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n"); -+ } -+} -+ -+ -+static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t); -+ -+ipkg_cmd_t *ipkg_cmd_find(const char *name) -+{ -+ int i; -+ ipkg_cmd_t *cmd; -+ -+ for (i=0; i < num_cmds; i++) { -+ cmd = &cmds[i]; -+ if (strcmp(name, cmd->name) == 0) { -+ return cmd; -+ } -+ } -+ -+ return NULL; -+} -+ -+#ifdef IPKG_LIB -+int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata) -+{ -+ int result; -+ p_userdata = userdata; -+ -+ -+ result = (cmd->fun)(conf, argc, argv); -+ if ( result == 0 ) { -+ ipkg_message(conf, IPKG_NOTICE, "Done.\n"); -+ } else { -+ ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result); -+ -+ } -+ if ( error_list ) { -+ reverse_error_list(&error_list); -+ -+ ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n"); -+ /* Here we print the errors collected and free the list */ -+ while (error_list != NULL) { -+ ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg); -+ error_list = error_list->next; -+ -+ } -+ free_error_list(&error_list); -+ -+ } -+ -+ p_userdata = NULL; -+ return result; -+} -+#else -+int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv) -+{ -+ return (cmd->fun)(conf, argc, argv); -+} -+#endif -+ -+static int ipkg_update_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ int err; -+ int failures; -+ char *lists_dir; -+ pkg_src_list_elt_t *iter; -+ pkg_src_t *src; -+ -+ -+ sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir); -+ -+ if (! file_is_dir(lists_dir)) { -+ if (file_exists(lists_dir)) { -+ ipkg_message(conf, IPKG_ERROR, -+ "%s: ERROR: %s exists, but is not a directory\n", -+ __FUNCTION__, lists_dir); -+ free(lists_dir); -+ return EINVAL; -+ } -+ err = file_mkdir_hier(lists_dir, 0755); -+ if (err) { -+ ipkg_message(conf, IPKG_ERROR, -+ "%s: ERROR: failed to make directory %s: %s\n", -+ __FUNCTION__, lists_dir, strerror(errno)); -+ free(lists_dir); -+ return EINVAL; -+ } -+ } -+ -+ failures = 0; -+ for (iter = conf->pkg_src_list.head; iter; iter = iter->next) { -+ char *url, *list_file_name; -+ -+ src = iter->data; -+ -+ if (src->extra_data) /* debian style? */ -+ sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data, -+ src->gzip ? "Packages.gz" : "Packages"); -+ else -+ sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages"); -+ -+ sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name); -+ if (src->gzip) { -+ char *tmp; -+ char *tmp_file_name; -+ FILE *in, *out; -+ -+ tmp = strdup ("/tmp/ipkg.XXXXXX"); -+ -+ if (mkdtemp (tmp) == NULL) { -+ perror ("mkdtemp"); -+ failures++; -+ continue; -+ } -+ -+ sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name); -+ err = ipkg_download(conf, url, tmp_file_name); -+ if (err == 0) { -+ ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url); -+ in = fopen (tmp_file_name, "r"); -+ out = fopen (list_file_name, "w"); -+ if (in && out) { -+ inflate_unzip_result res; -+ inflate_unzip (&res, 0x8000, fileno(in), fileno(out)); -+ } else -+ err = 1; -+ if (in) -+ fclose (in); -+ if (out) -+ fclose (out); -+ unlink (tmp_file_name); -+ rmdir (tmp); -+ free (tmp); -+ } -+ } else -+ err = ipkg_download(conf, url, list_file_name); -+ if (err) { -+ failures++; -+ } else { -+ ipkg_message(conf, IPKG_NOTICE, -+ "Updated list of available packages in %s\n", -+ list_file_name); -+ } -+ free(url); -+ free(list_file_name); -+ } -+ free(lists_dir); -+ -+#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG -+#warning here -+ /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED. -+ * this is a hack to work around poor bookkeeping in old ipkg upgrade code -+ * -Jamey 3/1/03 -+ */ -+ { -+ int i; -+ int changed = 0; -+ pkg_vec_t *available = pkg_vec_alloc(); -+ pkg_hash_fetch_available(&conf->pkg_hash, available); -+ ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n"); -+ for (i = 0; i < available->len; i++) { -+ pkg_t *pkg = available->pkgs[i]; -+ if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) { -+ ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name); -+ pkg->state_want = SW_UNKNOWN; -+ changed = 1; -+ } -+ } -+ pkg_vec_free(available); -+ if (changed) { -+ write_status_files_if_changed(conf); -+ } -+ } -+#endif -+ -+ return failures; -+} -+ -+ -+/* scan the args passed and cache the local filenames of the packages */ -+int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ int i; -+ int err; -+ -+ /* -+ * First scan through package names/urls -+ * For any urls, download the packages and install in database. -+ * For any files, install package info in database. -+ */ -+ for (i = 0; i < argc; i ++) { -+ char *filename = argv [i]; -+ //char *tmp = basename (tmp); -+ //int tmplen = strlen (tmp); -+ -+ //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0) -+ // continue; -+ //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0) -+ // continue; -+ -+ ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename ); -+ -+ err = ipkg_prepare_url_for_install(conf, filename, &argv[i]); -+ if (err) -+ return err; -+ } -+ return 0; -+} -+ -+struct ipkg_intercept -+{ -+ char *oldpath; -+ char *statedir; -+}; -+ -+typedef struct ipkg_intercept *ipkg_intercept_t; -+ -+ipkg_intercept_t ipkg_prep_intercepts(ipkg_conf_t *conf) -+{ -+ ipkg_intercept_t ctx; -+ char *newpath; -+ int gen; -+ -+ ctx = malloc (sizeof (*ctx)); -+ ctx->oldpath = strdup (getenv ("PATH")); -+ -+ sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath); -+ setenv ("PATH", newpath, 1); -+ free (newpath); -+ -+ gen = 0; -+ retry: -+ sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen); -+ if (mkdir (ctx->statedir, 0770) < 0) { -+ if (errno == EEXIST) { -+ free (ctx->statedir); -+ gen++; -+ goto retry; -+ } -+ perror (ctx->statedir); -+ return NULL; -+ } -+ setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1); -+ return ctx; -+} -+ -+int ipkg_finalize_intercepts(ipkg_intercept_t ctx) -+{ -+ char *cmd; -+ DIR *dir; -+ int err = 0; -+ -+ setenv ("PATH", ctx->oldpath, 1); -+ free (ctx->oldpath); -+ -+ dir = opendir (ctx->statedir); -+ if (dir) { -+ struct dirent *de; -+ while (de = readdir (dir), de != NULL) { -+ char *path; -+ -+ if (de->d_name[0] == '.') -+ continue; -+ -+ sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name); -+ if (access (path, X_OK) == 0) { -+ if (system (path)) { -+ err = errno; -+ perror (de->d_name); -+ } -+ } -+ free (path); -+ } -+ } else -+ perror (ctx->statedir); -+ -+ sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir); -+ system (cmd); -+ free (cmd); -+ -+ free (ctx->statedir); -+ free (ctx); -+ -+ return err; -+} -+ -+int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name) -+{ -+ pkg_vec_t *all; -+ int i; -+ pkg_t *pkg; -+ ipkg_intercept_t ic; -+ int r, err = 0; -+ -+ ipkg_message(conf, IPKG_INFO, -+ "Configuring unpacked packages\n"); -+ fflush( stdout ); -+ -+ all = pkg_vec_alloc(); -+ pkg_hash_fetch_available(&conf->pkg_hash, all); -+ -+ ic = ipkg_prep_intercepts (conf); -+ -+ for(i = 0; i < all->len; i++) { -+ pkg = all->pkgs[i]; -+ -+ if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) -+ continue; -+ -+ if (pkg->state_status == SS_UNPACKED) { -+ ipkg_message(conf, IPKG_NOTICE, -+ "Configuring %s\n", pkg->name); -+ fflush( stdout ); -+ r = ipkg_configure(conf, pkg); -+ if (r == 0) { -+ pkg->state_status = SS_INSTALLED; -+ pkg->parent->state_status = SS_INSTALLED; -+ pkg->state_flag &= ~SF_PREFER; -+ } else { -+ if (!err) -+ err = r; -+ } -+ } -+ } -+ -+ r = ipkg_finalize_intercepts (ic); -+ if (r && !err) -+ err = r; -+ -+ pkg_vec_free(all); -+ return err; -+} -+ -+static void sigint_handler(int sig) -+{ -+ signal(sig, SIG_DFL); -+ ipkg_message(NULL, IPKG_NOTICE, -+ "ipkg: interrupted. writing out status database\n"); -+ write_status_files_if_changed(global_conf); -+ exit(128 + sig); -+} -+ -+static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ int i; -+ char *arg; -+ int err=0; -+ -+ global_conf = conf; -+ signal(SIGINT, sigint_handler); -+ -+ /* -+ * Now scan through package names and install -+ */ -+ for (i=0; i < argc; i++) { -+ arg = argv[i]; -+ -+ ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg ); -+ err = ipkg_prepare_url_for_install(conf, arg, &argv[i]); -+ if (err != EINVAL && err != 0) -+ return err; -+ } -+ pkg_info_preinstall_check(conf); -+ -+ for (i=0; i < argc; i++) { -+ arg = argv[i]; -+ if (conf->multiple_providers) -+ err = ipkg_install_multi_by_name(conf, arg); -+ else{ -+ err = ipkg_install_by_name(conf, arg); -+ } -+ if (err == IPKG_PKG_HAS_NO_CANDIDATE) { -+ ipkg_message(conf, IPKG_ERROR, -+ "Cannot find package %s.\n" -+ "Check the spelling or perhaps run 'ipkg update'\n", -+ arg); -+ } -+ } -+ -+ /* recheck to verify that all dependences are satisfied */ -+ if (0) ipkg_satisfy_all_dependences(conf); -+ -+ ipkg_configure_packages(conf, NULL); -+ -+ write_status_files_if_changed(conf); -+ -+ return err; -+} -+ -+static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ int i; -+ pkg_t *pkg; -+ int err; -+ -+ global_conf = conf; -+ signal(SIGINT, sigint_handler); -+ -+ if (argc) { -+ for (i=0; i < argc; i++) { -+ char *arg = argv[i]; -+ -+ err = ipkg_prepare_url_for_install(conf, arg, &arg); -+ if (err != EINVAL && err != 0) -+ return err; -+ } -+ pkg_info_preinstall_check(conf); -+ -+ for (i=0; i < argc; i++) { -+ char *arg = argv[i]; -+ if (conf->restrict_to_default_dest) { -+ pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash, -+ argv[i], -+ conf->default_dest); -+ if (pkg == NULL) { -+ ipkg_message(conf, IPKG_NOTICE, -+ "Package %s not installed in %s\n", -+ argv[i], conf->default_dest->name); -+ continue; -+ } -+ } else { -+ pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, -+ argv[i]); -+ } -+ if (pkg) -+ ipkg_upgrade_pkg(conf, pkg); -+ else { -+ ipkg_install_by_name(conf, arg); -+ } -+ } -+ } else { -+ pkg_vec_t *installed = pkg_vec_alloc(); -+ -+ pkg_info_preinstall_check(conf); -+ -+ pkg_hash_fetch_all_installed(&conf->pkg_hash, installed); -+ for (i = 0; i < installed->len; i++) { -+ pkg = installed->pkgs[i]; -+ ipkg_upgrade_pkg(conf, pkg); -+ } -+ pkg_vec_free(installed); -+ } -+ -+ /* recheck to verify that all dependences are satisfied */ -+ if (0) ipkg_satisfy_all_dependences(conf); -+ -+ ipkg_configure_packages(conf, NULL); -+ -+ write_status_files_if_changed(conf); -+ -+ return 0; -+} -+ -+static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ int i, err; -+ char *arg; -+ pkg_t *pkg; -+ -+ pkg_info_preinstall_check(conf); -+ for (i = 0; i < argc; i++) { -+ arg = argv[i]; -+ -+ pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg); -+ if (pkg == NULL) { -+ ipkg_message(conf, IPKG_ERROR, -+ "Cannot find package %s.\n" -+ "Check the spelling or perhaps run 'ipkg update'\n", -+ arg); -+ continue; -+ } -+ -+ err = ipkg_download_pkg(conf, pkg, "."); -+ -+ if (err) { -+ ipkg_message(conf, IPKG_ERROR, -+ "Failed to download %s\n", pkg->name); -+ } else { -+ ipkg_message(conf, IPKG_NOTICE, -+ "Downloaded %s as %s\n", -+ pkg->name, pkg->local_filename); -+ } -+ } -+ -+ return 0; -+} -+ -+ -+static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ int i ; -+ pkg_vec_t *available; -+ pkg_t *pkg; -+ char desc_short[IPKG_LIST_DESCRIPTION_LENGTH]; -+ char *newline; -+ char *pkg_name = NULL; -+ char *version_str; -+ -+ if (argc > 0) { -+ pkg_name = argv[0]; -+ } -+ available = pkg_vec_alloc(); -+ pkg_hash_fetch_available(&conf->pkg_hash, available); -+ for (i=0; i < available->len; i++) { -+ pkg = available->pkgs[i]; -+ /* if we have package name or pattern and pkg does not match, then skip it */ -+ if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) -+ continue; -+ if (pkg->description) { -+ strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH); -+ } else { -+ desc_short[0] = '\0'; -+ } -+ desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0'; -+ newline = strchr(desc_short, '\n'); -+ if (newline) { -+ *newline = '\0'; -+ } -+#ifndef IPKG_LIB -+ printf("%s - %s\n", pkg->name, desc_short); -+#else -+ if (ipkg_cb_list) { -+ version_str = pkg_version_str_alloc(pkg); -+ ipkg_cb_list(pkg->name,desc_short, -+ version_str, -+ pkg->state_status, -+ p_userdata); -+ free(version_str); -+ } -+#endif -+ } -+ pkg_vec_free(available); -+ -+ return 0; -+} -+ -+ -+static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ int i ; -+ pkg_vec_t *available; -+ pkg_t *pkg; -+ char desc_short[IPKG_LIST_DESCRIPTION_LENGTH]; -+ char *newline; -+ char *pkg_name = NULL; -+ char *version_str; -+ -+ if (argc > 0) { -+ pkg_name = argv[0]; -+ } -+ available = pkg_vec_alloc(); -+ pkg_hash_fetch_all_installed(&conf->pkg_hash, available); -+ for (i=0; i < available->len; i++) { -+ pkg = available->pkgs[i]; -+ /* if we have package name or pattern and pkg does not match, then skip it */ -+ if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) -+ continue; -+ if (pkg->description) { -+ strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH); -+ } else { -+ desc_short[0] = '\0'; -+ } -+ desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0'; -+ newline = strchr(desc_short, '\n'); -+ if (newline) { -+ *newline = '\0'; -+ } -+#ifndef IPKG_LIB -+ printf("%s - %s\n", pkg->name, desc_short); -+#else -+ if (ipkg_cb_list) { -+ version_str = pkg_version_str_alloc(pkg); -+ ipkg_cb_list(pkg->name,desc_short, -+ version_str, -+ pkg->state_status, -+ p_userdata); -+ free(version_str); -+ } -+#endif -+ } -+ -+ return 0; -+} -+ -+static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only) -+{ -+ int i; -+ pkg_vec_t *available; -+ pkg_t *pkg; -+ char *pkg_name = NULL; -+ char **pkg_fields = NULL; -+ int n_fields = 0; -+ char *buff ; // = (char *)malloc(1); -+ -+ if (argc > 0) { -+ pkg_name = argv[0]; -+ } -+ if (argc > 1) { -+ pkg_fields = &argv[1]; -+ n_fields = argc - 1; -+ } -+ -+ available = pkg_vec_alloc(); -+ if (installed_only) -+ pkg_hash_fetch_all_installed(&conf->pkg_hash, available); -+ else -+ pkg_hash_fetch_available(&conf->pkg_hash, available); -+ for (i=0; i < available->len; i++) { -+ pkg = available->pkgs[i]; -+ if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) { -+ continue; -+ } -+#ifndef IPKG_LIB -+ if (n_fields) { -+ for (j = 0; j < n_fields; j++) -+ pkg_print_field(pkg, stdout, pkg_fields[j]); -+ } else { -+ pkg_print_info(pkg, stdout); -+ } -+#else -+ -+ buff = pkg_formatted_info(pkg); -+ if ( buff ) { -+ if (ipkg_cb_status) ipkg_cb_status(pkg->name, -+ pkg->state_status, -+ buff, -+ p_userdata); -+/* -+ We should not forget that actually the pointer is allocated. -+ We need to free it :) ( Thanks florian for seeing the error ) -+*/ -+ free(buff); -+ } -+#endif -+ if (conf->verbosity > 1) { -+ conffile_list_elt_t *iter; -+ for (iter = pkg->conffiles.head; iter; iter = iter->next) { -+ conffile_t *cf = iter->data; -+ int modified = conffile_has_been_modified(conf, cf); -+ ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n", -+ cf->name, cf->value, modified); -+ } -+ } -+ } -+#ifndef IPKG_LIB -+ if (buff) -+ free(buff); -+#endif -+ pkg_vec_free(available); -+ -+ return 0; -+} -+ -+static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ return ipkg_info_status_cmd(conf, argc, argv, 0); -+} -+ -+static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ return ipkg_info_status_cmd(conf, argc, argv, 1); -+} -+ -+static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ -+ int err; -+ if (argc > 0) { -+ char *pkg_name = NULL; -+ -+ pkg_name = argv[0]; -+ -+ err = ipkg_configure_packages (conf, pkg_name); -+ -+ } else { -+ err = ipkg_configure_packages (conf, NULL); -+ } -+ -+ write_status_files_if_changed(conf); -+ -+ return err; -+} -+ -+static int ipkg_install_pending_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ int i, err; -+ char *globpattern; -+ glob_t globbuf; -+ -+ sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir); -+ err = glob(globpattern, 0, NULL, &globbuf); -+ free(globpattern); -+ if (err) { -+ return 0; -+ } -+ -+ ipkg_message(conf, IPKG_NOTICE, -+ "The following packages in %s will now be installed.\n", -+ conf->pending_dir); -+ for (i = 0; i < globbuf.gl_pathc; i++) { -+ ipkg_message(conf, IPKG_NOTICE, -+ "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]); -+ } -+ ipkg_message(conf, IPKG_NOTICE, "\n"); -+ for (i = 0; i < globbuf.gl_pathc; i++) { -+ err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]); -+ if (err == 0) { -+ err = unlink(globbuf.gl_pathv[i]); -+ if (err) { -+ ipkg_message(conf, IPKG_ERROR, -+ "%s: ERROR: failed to unlink %s: %s\n", -+ __FUNCTION__, globbuf.gl_pathv[i], strerror(err)); -+ return err; -+ } -+ } -+ } -+ globfree(&globbuf); -+ -+ return err; -+} -+ -+static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ int i,a,done; -+ pkg_t *pkg; -+ pkg_t *pkg_to_remove; -+ pkg_vec_t *available; -+ char *pkg_name = NULL; -+ global_conf = conf; -+ signal(SIGINT, sigint_handler); -+ -+// ENH: Add the "no pkg removed" just in case. -+ -+ done = 0; -+ -+ available = pkg_vec_alloc(); -+ pkg_info_preinstall_check(conf); -+ if ( argc > 0 ) { -+ pkg_hash_fetch_all_installed(&conf->pkg_hash, available); -+ for (i=0; i < argc; i++) { -+ pkg_name = malloc(strlen(argv[i])+2); -+ strcpy(pkg_name,argv[i]); -+ for (a=0; a < available->len; a++) { -+ pkg = available->pkgs[a]; -+ if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) { -+ continue; -+ } -+ if (conf->restrict_to_default_dest) { -+ pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash, -+ pkg->name, -+ conf->default_dest); -+ } else { -+ pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name ); -+ } -+ -+ if (pkg == NULL) { -+ ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name); -+ continue; -+ } -+ if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped -+ ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name); -+ continue; -+ } -+ ipkg_remove_pkg(conf, pkg_to_remove,0); -+ done = 1; -+ } -+ free (pkg_name); -+ } -+ pkg_vec_free(available); -+ } else { -+ pkg_vec_t *installed_pkgs = pkg_vec_alloc(); -+ int flagged_pkg_count = 0; -+ int removed; -+ -+ pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs); -+ -+ for (i = 0; i < installed_pkgs->len; i++) { -+ pkg = installed_pkgs->pkgs[i]; -+ if (pkg->state_flag & SF_USER) { -+ flagged_pkg_count++; -+ } else { -+ if (!pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) -+ ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name); -+ } -+ } -+ if (!flagged_pkg_count) { -+ ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n" -+ "so refusing to uninstall unflagged non-leaf packages\n"); -+ return 0; -+ } -+ -+ /* find packages not flagged SF_USER (i.e., installed to -+ * satisfy a dependence) and not having any dependents, and -+ * remove them */ -+ do { -+ removed = 0; -+ for (i = 0; i < installed_pkgs->len; i++) { -+ pkg = installed_pkgs->pkgs[i]; -+ if (!(pkg->state_flag & SF_USER) -+ && !pkg_has_installed_dependents(conf, pkg->parent, pkg, NULL)) { -+ removed++; -+ ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n"); -+ ipkg_remove_pkg(conf, pkg,0); -+ done = 1; -+ } -+ } -+ } while (removed); -+ pkg_vec_free(installed_pkgs); -+ } -+ -+ if ( done == 0 ) -+ ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n"); -+ -+ write_status_files_if_changed(conf); -+ return 0; -+} -+ -+static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ int i; -+ pkg_t *pkg; -+ -+ global_conf = conf; -+ signal(SIGINT, sigint_handler); -+ -+ pkg_info_preinstall_check(conf); -+ -+ for (i=0; i < argc; i++) { -+ if (conf->restrict_to_default_dest) { -+ pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash, -+ argv[i], -+ conf->default_dest); -+ } else { -+ pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]); -+ } -+ -+ if (pkg == NULL) { -+ ipkg_message(conf, IPKG_ERROR, -+ "Package %s is not installed.\n", argv[i]); -+ continue; -+ } -+ ipkg_purge_pkg(conf, pkg); -+ } -+ -+ write_status_files_if_changed(conf); -+ return 0; -+} -+ -+static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ int i; -+ pkg_t *pkg; -+ char *flags = argv[0]; -+ -+ global_conf = conf; -+ signal(SIGINT, sigint_handler); -+ -+ for (i=1; i < argc; i++) { -+ if (conf->restrict_to_default_dest) { -+ pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash, -+ argv[i], -+ conf->default_dest); -+ } else { -+ pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]); -+ } -+ -+ if (pkg == NULL) { -+ ipkg_message(conf, IPKG_ERROR, -+ "Package %s is not installed.\n", argv[i]); -+ continue; -+ } -+ if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)|| -+ ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) { -+ pkg->state_flag = pkg_state_flag_from_str(flags); -+ } -+/* pb_ asked this feature 03292004 */ -+/* Actually I will use only this two, but this is an open for various status */ -+ if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){ -+ pkg->state_status = pkg_state_status_from_str(flags); -+ } -+ ipkg_state_changed++; -+ ipkg_message(conf, IPKG_NOTICE, -+ "Setting flags for package %s to %s\n", -+ pkg->name, flags); -+ } -+ -+ write_status_files_if_changed(conf); -+ return 0; -+} -+ -+static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ pkg_t *pkg; -+ str_list_t *installed_files; -+ str_list_elt_t *iter; -+ char *pkg_version; -+ size_t buff_len = 8192; -+ size_t used_len; -+ char *buff ; -+ -+ buff = (char *)malloc(buff_len); -+ if ( buff == NULL ) { -+ fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__); -+ return ENOMEM; -+ } -+ -+ if (argc < 1) { -+ return EINVAL; -+ } -+ -+ pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, -+ argv[0]); -+ if (pkg == NULL) { -+ ipkg_message(conf, IPKG_ERROR, -+ "Package %s not installed.\n", argv[0]); -+ return 0; -+ } -+ -+ installed_files = pkg_get_installed_files(pkg); -+ pkg_version = pkg_version_str_alloc(pkg); -+ -+#ifndef IPKG_LIB -+ printf("Package %s (%s) is installed on %s and has the following files:\n", -+ pkg->name, pkg_version, pkg->dest->name); -+ for (iter = installed_files->head; iter; iter = iter->next) { -+ puts(iter->data); -+ } -+#else -+ if (buff) { -+ try_again: -+ used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n", -+ pkg->name, pkg_version, pkg->dest->name) + 1; -+ if (used_len > buff_len) { -+ buff_len *= 2; -+ buff = realloc (buff, buff_len); -+ goto try_again; -+ } -+ for (iter = installed_files->head; iter; iter = iter->next) { -+ used_len += strlen (iter->data) + 1; -+ while (buff_len <= used_len) { -+ buff_len *= 2; -+ buff = realloc (buff, buff_len); -+ } -+ strncat(buff, iter->data, buff_len); -+ strncat(buff, "\n", buff_len); -+ } -+ if (ipkg_cb_list) ipkg_cb_list(pkg->name, -+ buff, -+ pkg_version_str_alloc(pkg), -+ pkg->state_status, -+ p_userdata); -+ free(buff); -+ } -+#endif -+ -+ free(pkg_version); -+ pkg_free_installed_files(pkg); -+ -+ return 0; -+} -+ -+static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ -+ if (argc > 0) { -+ pkg_vec_t *available_pkgs = pkg_vec_alloc(); -+ const char *rel_str = "depends on"; -+ int i; -+ -+ pkg_info_preinstall_check(conf); -+ -+ if (conf->query_all) -+ pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs); -+ else -+ pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs); -+ for (i = 0; i < argc; i++) { -+ const char *target = argv[i]; -+ int j; -+ -+ ipkg_message(conf, IPKG_ERROR, "target=%s\n", target); -+ -+ for (j = 0; j < available_pkgs->len; j++) { -+ pkg_t *pkg = available_pkgs->pkgs[j]; -+ if (fnmatch(target, pkg->name, 0) == 0) { -+ int k; -+ int count = pkg->depends_count + pkg->pre_depends_count; -+ ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n", -+ target, pkg->architecture, rel_str); -+ for (k = 0; k < count; k++) { -+ compound_depend_t *cdepend = &pkg->depends[k]; -+ int l; -+ for (l = 0; l < cdepend->possibility_count; l++) { -+ depend_t *possibility = cdepend->possibilities[l]; -+ ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name); -+ if (conf->verbosity > 0) { -+ // char *ver = abstract_pkg_version_str_alloc(possibility->pkg); -+ ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version); -+ if (possibility->version) { -+ char *typestr = NULL; -+ switch (possibility->constraint) { -+ case NONE: typestr = "none"; break; -+ case EARLIER: typestr = "<"; break; -+ case EARLIER_EQUAL: typestr = "<="; break; -+ case EQUAL: typestr = "="; break; -+ case LATER_EQUAL: typestr = ">="; break; -+ case LATER: typestr = ">"; break; -+ } -+ ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version); -+ } -+ // free(ver); -+ } -+ ipkg_message(conf, IPKG_ERROR, "\n"); -+ } -+ } -+ } -+ } -+ } -+ pkg_vec_free(available_pkgs); -+ } -+ return 0; -+} -+ -+enum what_field_type { -+ WHATDEPENDS, -+ WHATCONFLICTS, -+ WHATPROVIDES, -+ WHATREPLACES, -+ WHATRECOMMENDS, -+ WHATSUGGESTS -+}; -+ -+static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv) -+{ -+ -+ if (argc > 0) { -+ pkg_vec_t *available_pkgs = pkg_vec_alloc(); -+ const char *rel_str = NULL; -+ int i; -+ int changed; -+ -+ switch (what_field_type) { -+ case WHATDEPENDS: rel_str = "depends on"; break; -+ case WHATCONFLICTS: rel_str = "conflicts with"; break; -+ case WHATSUGGESTS: rel_str = "suggests"; break; -+ case WHATRECOMMENDS: rel_str = "recommends"; break; -+ case WHATPROVIDES: rel_str = "provides"; break; -+ case WHATREPLACES: rel_str = "replaces"; break; -+ } -+ -+ if (conf->query_all) -+ pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs); -+ else -+ pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs); -+ -+ /* mark the root set */ -+ pkg_vec_clear_marks(available_pkgs); -+ ipkg_message(conf, IPKG_NOTICE, "Root set:\n"); -+ for (i = 0; i < argc; i++) { -+ const char *dependee_pattern = argv[i]; -+ pkg_vec_mark_if_matches(available_pkgs, dependee_pattern); -+ } -+ for (i = 0; i < available_pkgs->len; i++) { -+ pkg_t *pkg = available_pkgs->pkgs[i]; -+ if (pkg->state_flag & SF_MARKED) { -+ /* mark the parent (abstract) package */ -+ pkg_mark_provides(pkg); -+ ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name); -+ } -+ } -+ -+ ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str); -+ do { -+ int j; -+ changed = 0; -+ -+ for (j = 0; j < available_pkgs->len; j++) { -+ pkg_t *pkg = available_pkgs->pkgs[j]; -+ int k; -+ int count = ((what_field_type == WHATCONFLICTS) -+ ? pkg->conflicts_count -+ : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count); -+ /* skip this package if it is already marked */ -+ if (pkg->parent->state_flag & SF_MARKED) { -+ continue; -+ } -+ for (k = 0; k < count; k++) { -+ compound_depend_t *cdepend = -+ (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k]; -+ int l; -+ for (l = 0; l < cdepend->possibility_count; l++) { -+ depend_t *possibility = cdepend->possibilities[l]; -+ if (possibility->pkg->state_flag & SF_MARKED) { -+ /* mark the depending package so we won't visit it again */ -+ pkg->state_flag |= SF_MARKED; -+ pkg_mark_provides(pkg); -+ changed++; -+ -+ ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name); -+ if (conf->verbosity > 0) { -+ char *ver = pkg_version_str_alloc(pkg); -+ ipkg_message(conf, IPKG_NOTICE, " %s", ver); -+ ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name); -+ if (possibility->version) { -+ char *typestr = NULL; -+ switch (possibility->constraint) { -+ case NONE: typestr = "none"; break; -+ case EARLIER: typestr = "<"; break; -+ case EARLIER_EQUAL: typestr = "<="; break; -+ case EQUAL: typestr = "="; break; -+ case LATER_EQUAL: typestr = ">="; break; -+ case LATER: typestr = ">"; break; -+ } -+ ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version); -+ } -+ free(ver); -+ if (!pkg_dependence_satisfiable(conf, possibility)) -+ ipkg_message(conf, IPKG_NOTICE, " unsatisfiable"); -+ } -+ ipkg_message(conf, IPKG_NOTICE, "\n"); -+ goto next_package; -+ } -+ } -+ } -+ next_package: -+ ; -+ } -+ } while (changed && recursive); -+ pkg_vec_free(available_pkgs); -+ } -+ -+ return 0; -+} -+ -+int pkg_mark_provides(pkg_t *pkg) -+{ -+ int provides_count = pkg->provides_count; -+ abstract_pkg_t **provides = pkg->provides; -+ int i; -+ pkg->parent->state_flag |= SF_MARKED; -+ for (i = 0; i < provides_count; i++) { -+ provides[i]->state_flag |= SF_MARKED; -+ } -+ return 0; -+} -+ -+static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv); -+} -+static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv); -+} -+ -+static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv); -+} -+ -+static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv); -+} -+ -+static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv); -+} -+ -+static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv) -+{ -+ -+ if (argc > 0) { -+ pkg_vec_t *available_pkgs = pkg_vec_alloc(); -+ const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces"); -+ int i; -+ -+ pkg_info_preinstall_check(conf); -+ -+ if (conf->query_all) -+ pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs); -+ else -+ pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs); -+ for (i = 0; i < argc; i++) { -+ const char *target = argv[i]; -+ int j; -+ -+ ipkg_message(conf, IPKG_ERROR, "What %s %s\n", -+ rel_str, target); -+ for (j = 0; j < available_pkgs->len; j++) { -+ pkg_t *pkg = available_pkgs->pkgs[j]; -+ int k; -+ int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count; -+ for (k = 0; k < count; k++) { -+ abstract_pkg_t *apkg = -+ ((what_field_type == WHATPROVIDES) -+ ? pkg->provides[k] -+ : pkg->replaces[k]); -+ if (fnmatch(target, apkg->name, 0) == 0) { -+ ipkg_message(conf, IPKG_ERROR, " %s", pkg->name); -+ if (strcmp(target, apkg->name) != 0) -+ ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name); -+ ipkg_message(conf, IPKG_ERROR, "\n"); -+ } -+ } -+ } -+ } -+ pkg_vec_free(available_pkgs); -+ } -+ return 0; -+} -+ -+static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv); -+} -+ -+static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv); -+} -+ -+static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ int i; -+ -+ pkg_vec_t *installed; -+ pkg_t *pkg; -+ str_list_t *installed_files; -+ str_list_elt_t *iter; -+ char *installed_file; -+ -+ if (argc < 1) { -+ return EINVAL; -+ } -+ -+ installed = pkg_vec_alloc(); -+ pkg_hash_fetch_all_installed(&conf->pkg_hash, installed); -+ -+ for (i=0; i < installed->len; i++) { -+ pkg = installed->pkgs[i]; -+ -+ installed_files = pkg_get_installed_files(pkg); -+ -+ for (iter = installed_files->head; iter; iter = iter->next) { -+ installed_file = iter->data; -+ if (fnmatch(argv[0], installed_file, 0)==0) { -+#ifndef IPKG_LIB -+ printf("%s: %s\n", pkg->name, installed_file); -+#else -+ if (ipkg_cb_list) ipkg_cb_list(pkg->name, -+ installed_file, -+ pkg_version_str_alloc(pkg), -+ pkg->state_status, p_userdata); -+#endif -+ } -+ } -+ -+ pkg_free_installed_files(pkg); -+ } -+ -+ /* XXX: CLEANUP: It's not obvious from the name of -+ pkg_hash_fetch_all_installed that we need to call -+ pkg_vec_free to avoid a memory leak. */ -+ pkg_vec_free(installed); -+ -+ return 0; -+} -+ -+static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ if (argc == 3) { -+ /* this is a bit gross */ -+ struct pkg p1, p2; -+ parseVersion(&p1, argv[0]); -+ parseVersion(&p2, argv[2]); -+ return pkg_version_satisfied(&p1, &p2, argv[1]); -+ } else { -+ ipkg_message(conf, IPKG_ERROR, -+ "ipkg compare_versions \n" -+ " is one of <= >= << >> =\n"); -+ return -1; -+ } -+} -+ -+#ifndef HOST_CPU_STR -+#define HOST_CPU_STR__(X) #X -+#define HOST_CPU_STR_(X) HOST_CPU_STR__(X) -+#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO) -+#endif -+ -+static int ipkg_print_architecture_cmd(ipkg_conf_t *conf, int argc, char **argv) -+{ -+ nv_pair_list_elt_t *l; -+ -+ l = conf->arch_list.head; -+ while (l) { -+ nv_pair_t *nv = l->data; -+ printf("arch %s %s\n", nv->name, nv->value); -+ l = l->next; -+ } -+ return 0; -+} -+ -+ -Index: busybox-1.4.2/archival/libipkg/ipkg_cmd.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg_cmd.h 2007-06-04 13:21:36.710395840 +0200 -@@ -0,0 +1,46 @@ -+/* ipkg_cmd.h - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef IPKG_CMD_H -+#define IPKG_CMD_H -+ -+typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv); -+ -+struct ipkg_cmd -+{ -+ char *name; -+ int requires_args; -+ ipkg_cmd_fun_t fun; -+}; -+typedef struct ipkg_cmd ipkg_cmd_t; -+ -+ipkg_cmd_t *ipkg_cmd_find(const char *name); -+#ifdef IPKG_LIB -+int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, -+ const char **argv, void *userdata); -+#else -+int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv); -+#endif -+int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]); -+/* install any packges with state_want == SW_INSTALL */ -+int ipkg_install_wanted_packages(ipkg_conf_t *conf); -+/* ensure that all dependences are satisfied */ -+int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name); -+ -+int pkg_mark_provides(pkg_t *pkg); -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/ipkg_conf.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg_conf.c 2007-06-04 13:21:36.711395688 +0200 -@@ -0,0 +1,711 @@ -+/* ipkg_conf.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include -+ -+#include "ipkg.h" -+#include "ipkg_conf.h" -+ -+#include "xregex.h" -+#include "sprintf_alloc.h" -+#include "ipkg_conf.h" -+#include "ipkg_message.h" -+#include "file_util.h" -+#include "str_util.h" -+#include "xsystem.h" -+ -+ -+ipkg_conf_t *global_conf; -+ -+static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename, -+ pkg_src_list_t *pkg_src_list, -+ nv_pair_list_t *tmp_dest_nv_pair_list, -+ char **tmp_lists_dir); -+static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options); -+static int ipkg_conf_set_option(const ipkg_option_t *options, -+ const char *name, const char *value); -+static int ipkg_conf_set_default_dest(ipkg_conf_t *conf, -+ const char *default_dest_name); -+static int set_and_load_pkg_src_list(ipkg_conf_t *conf, -+ pkg_src_list_t *nv_pair_list); -+static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, -+ nv_pair_list_t *nv_pair_list, char * lists_dir); -+ -+int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options) -+{ -+ ipkg_option_t tmp[] = { -+ { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults }, -+ { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends }, -+ { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite }, -+ { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade }, -+ { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall }, -+ { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space }, -+ { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy }, -+ { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy }, -+ { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers }, -+ { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy }, -+ { "test", IPKG_OPT_TYPE_INT, &conf->noaction }, -+ { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction }, -+ { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps }, -+ { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root }, -+ { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd }, -+ { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd }, -+ { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd }, -+ { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user }, -+ { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all }, -+ { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget }, -+ { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity }, -+ { NULL } -+ }; -+ -+ *options = (ipkg_option_t *)malloc(sizeof(tmp)); -+ if ( options == NULL ){ -+ fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__); -+ return -1; -+ } -+ -+ memcpy(*options, tmp, sizeof(tmp)); -+ return 0; -+}; -+ -+static void ipkg_conf_override_string(char **conf_str, char *arg_str) -+{ -+ if (arg_str) { -+ if (*conf_str) { -+ free(*conf_str); -+ } -+ *conf_str = strdup(arg_str); -+ } -+} -+ -+static void ipkg_conf_free_string(char **conf_str) -+{ -+ if (*conf_str) { -+ free(*conf_str); -+ *conf_str = NULL; -+ } -+} -+ -+int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args) -+{ -+ int err; -+ char *tmp_dir_base; -+ nv_pair_list_t tmp_dest_nv_pair_list; -+ char * lists_dir =NULL; -+ glob_t globbuf; -+ char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf"; -+ char *pending_dir =NULL; -+ -+ memset(conf, 0, sizeof(ipkg_conf_t)); -+ -+ pkg_src_list_init(&conf->pkg_src_list); -+ -+ nv_pair_list_init(&tmp_dest_nv_pair_list); -+ pkg_dest_list_init(&conf->pkg_dest_list); -+ -+ nv_pair_list_init(&conf->arch_list); -+ -+ conf->restrict_to_default_dest = 0; -+ conf->default_dest = NULL; -+ -+ -+ if (args->tmp_dir) -+ tmp_dir_base = args->tmp_dir; -+ else -+ tmp_dir_base = getenv("TMPDIR"); -+ sprintf_alloc(&conf->tmp_dir, "%s/%s", -+ tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE, -+ IPKG_CONF_TMP_DIR_SUFFIX); -+ conf->tmp_dir = mkdtemp(conf->tmp_dir); -+ if (conf->tmp_dir == NULL) { -+ fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n", -+ __FUNCTION__, conf->tmp_dir, strerror(errno)); -+ return errno; -+ } -+ -+ conf->force_depends = 0; -+ conf->force_defaults = 0; -+ conf->force_overwrite = 0; -+ conf->force_downgrade = 0; -+ conf->force_reinstall = 0; -+ conf->force_space = 0; -+ conf->force_removal_of_essential_packages = 0; -+ conf->force_removal_of_dependent_packages = 0; -+ conf->nodeps = 0; -+ conf->verbose_wget = 0; -+ conf->offline_root = NULL; -+ conf->offline_root_pre_script_cmd = NULL; -+ conf->offline_root_post_script_cmd = NULL; -+ conf->multiple_providers = 0; -+ conf->verbosity = 1; -+ conf->noaction = 0; -+ -+ conf->http_proxy = NULL; -+ conf->ftp_proxy = NULL; -+ conf->no_proxy = NULL; -+ conf->proxy_user = NULL; -+ conf->proxy_passwd = NULL; -+ -+ pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN); -+ hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN); -+ hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN); -+ lists_dir=(char *)malloc(1); -+ lists_dir[0]='\0'; -+ if (args->conf_file) { -+ struct stat stat_buf; -+ err = stat(args->conf_file, &stat_buf); -+ if (err == 0) -+ if (ipkg_conf_parse_file(conf, args->conf_file, -+ &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) { -+ /* Memory leakage from ipkg_conf_parse-file */ -+ return -1; -+ } -+ -+ } -+ -+ /* if (!lists_dir ){*/ -+ if (strlen(lists_dir)<=1 ){ -+ lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2); -+ sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR); -+ } -+ -+ if (args->offline_root) { -+ char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1); -+ sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir); -+ free(lists_dir); -+ lists_dir = tmp; -+ } -+ -+ pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5); -+ snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending"); -+ -+ conf->lists_dir = strdup(lists_dir); -+ conf->pending_dir = strdup(pending_dir); -+ -+ if (args->offline_root) -+ sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root); -+ memset(&globbuf, 0, sizeof(globbuf)); -+ err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf); -+ if (!err) { -+ int i; -+ for (i = 0; i < globbuf.gl_pathc; i++) { -+ if (globbuf.gl_pathv[i]) -+ if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i], -+ &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) { -+ /* Memory leakage from ipkg_conf_parse-file */ -+ return -1; -+ } -+ } -+ } -+ globfree(&globbuf); -+ -+ /* if no architectures were defined, then default all, noarch, and host architecture */ -+ if (nv_pair_list_empty(&conf->arch_list)) { -+ nv_pair_list_append(&conf->arch_list, "all", "1"); -+ nv_pair_list_append(&conf->arch_list, "noarch", "1"); -+ nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10"); -+ } -+ -+ /* Even if there is no conf file, we'll need at least one dest. */ -+ if (tmp_dest_nv_pair_list.head == NULL) { -+ nv_pair_list_append(&tmp_dest_nv_pair_list, -+ IPKG_CONF_DEFAULT_DEST_NAME, -+ IPKG_CONF_DEFAULT_DEST_ROOT_DIR); -+ } -+ -+ /* After parsing the file, set options from command-line, (so that -+ command-line arguments take precedence) */ -+ /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c -+ really needs to be cleaned up. There is so much duplication -+ right now it is ridiculous. Maybe ipkg_conf_t should just save -+ a pointer to args_t (which could then not be freed), rather -+ than duplicating every field here? */ -+ if (args->force_depends) { -+ conf->force_depends = 1; -+ } -+ if (args->force_defaults) { -+ conf->force_defaults = 1; -+ } -+ if (args->force_overwrite) { -+ conf->force_overwrite = 1; -+ } -+ if (args->force_downgrade) { -+ conf->force_downgrade = 1; -+ } -+ if (args->force_reinstall) { -+ conf->force_reinstall = 1; -+ } -+ if (args->force_removal_of_dependent_packages) { -+ conf->force_removal_of_dependent_packages = 1; -+ } -+ if (args->force_removal_of_essential_packages) { -+ conf->force_removal_of_essential_packages = 1; -+ } -+ if (args->nodeps) { -+ conf->nodeps = 1; -+ } -+ if (args->noaction) { -+ conf->noaction = 1; -+ } -+ if (args->query_all) { -+ conf->query_all = 1; -+ } -+ if (args->verbose_wget) { -+ conf->verbose_wget = 1; -+ } -+ if (args->multiple_providers) { -+ conf->multiple_providers = 1; -+ } -+ if (args->verbosity != conf->verbosity) { -+ conf->verbosity = args->verbosity; -+ } -+ -+ ipkg_conf_override_string(&conf->offline_root, -+ args->offline_root); -+ ipkg_conf_override_string(&conf->offline_root_pre_script_cmd, -+ args->offline_root_pre_script_cmd); -+ ipkg_conf_override_string(&conf->offline_root_post_script_cmd, -+ args->offline_root_post_script_cmd); -+ -+/* Pigi: added a flag to disable the checking of structures if the command does not need to -+ read anything from there. -+*/ -+ if ( !(args->nocheckfordirorfile)){ -+ /* need to run load the source list before dest list -Jamey */ -+ if ( !(args->noreadfeedsfile)) -+ set_and_load_pkg_src_list(conf, &conf->pkg_src_list); -+ -+ /* Now that we have resolved conf->offline_root, we can commit to -+ the directory names for the dests and load in all the package -+ lists. */ -+ set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir); -+ -+ if (args->dest) { -+ err = ipkg_conf_set_default_dest(conf, args->dest); -+ if (err) { -+ return err; -+ } -+ } -+ } -+ nv_pair_list_deinit(&tmp_dest_nv_pair_list); -+ free(lists_dir); -+ free(pending_dir); -+ -+ return 0; -+} -+ -+void ipkg_conf_deinit(ipkg_conf_t *conf) -+{ -+#ifdef IPKG_DEBUG_NO_TMP_CLEANUP -+#error -+ fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled " -+ "with IPKG_DEBUG_NO_TMP_CLEANUP\n", -+ __FUNCTION__, conf->tmp_dir); -+#else -+ int err; -+ -+ err = rmdir(conf->tmp_dir); -+ if (err) { -+ if (errno == ENOTEMPTY) { -+ char *cmd; -+ sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir); -+ err = xsystem(cmd); -+ free(cmd); -+ } -+ if (err) -+ fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno)); -+ } -+#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */ -+ -+ free(conf->tmp_dir); /*XXX*/ -+ -+ pkg_src_list_deinit(&conf->pkg_src_list); -+ pkg_dest_list_deinit(&conf->pkg_dest_list); -+ nv_pair_list_deinit(&conf->arch_list); -+ if (&conf->pkg_hash) -+ pkg_hash_deinit(&conf->pkg_hash); -+ if (&conf->file_hash) -+ hash_table_deinit(&conf->file_hash); -+ if (&conf->obs_file_hash) -+ hash_table_deinit(&conf->obs_file_hash); -+ -+ ipkg_conf_free_string(&conf->offline_root); -+ ipkg_conf_free_string(&conf->offline_root_pre_script_cmd); -+ ipkg_conf_free_string(&conf->offline_root_post_script_cmd); -+ -+ if (conf->verbosity > 1) { -+ int i; -+ hash_table_t *hashes[] = { -+ &conf->pkg_hash, -+ &conf->file_hash, -+ &conf->obs_file_hash }; -+ for (i = 0; i < 3; i++) { -+ hash_table_t *hash = hashes[i]; -+ int c = 0; -+ int n_conflicts = 0; -+ int j; -+ for (j = 0; j < hash->n_entries; j++) { -+ int len = 0; -+ hash_entry_t *e = &hash->entries[j]; -+ if (e->next) -+ n_conflicts++; -+ while (e && e->key) { -+ len++; -+ e = e->next; -+ } -+ if (len > c) -+ c = len; -+ } -+ ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n", -+ hash->name, hash->n_entries, hash->n_elements, c, n_conflicts); -+ hash_table_deinit(hash); -+ } -+ } -+} -+ -+static int ipkg_conf_set_default_dest(ipkg_conf_t *conf, -+ const char *default_dest_name) -+{ -+ pkg_dest_list_elt_t *iter; -+ pkg_dest_t *dest; -+ -+ for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) { -+ dest = iter->data; -+ if (strcmp(dest->name, default_dest_name) == 0) { -+ conf->default_dest = dest; -+ conf->restrict_to_default_dest = 1; -+ return 0; -+ } -+ } -+ -+ fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name); -+ -+ return 1; -+} -+ -+static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list) -+{ -+ pkg_src_list_elt_t *iter; -+ pkg_src_t *src; -+ char *list_file; -+ -+ for (iter = pkg_src_list->head; iter; iter = iter->next) { -+ src = iter->data; -+ if (src == NULL) { -+ continue; -+ } -+ -+ sprintf_alloc(&list_file, "%s/%s", -+ conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir, -+ src->name); -+ -+ if (file_exists(list_file)) { -+ pkg_hash_add_from_file(conf, list_file, src, NULL, 0); -+ } -+ free(list_file); -+ } -+ -+ return 0; -+} -+ -+static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir ) -+{ -+ nv_pair_list_elt_t *iter; -+ nv_pair_t *nv_pair; -+ pkg_dest_t *dest; -+ char *root_dir; -+ -+ for (iter = nv_pair_list->head; iter; iter = iter->next) { -+ nv_pair = iter->data; -+ -+ if (conf->offline_root) { -+ sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value); -+ } else { -+ root_dir = strdup(nv_pair->value); -+ } -+ dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir); -+ free(root_dir); -+ if (dest == NULL) { -+ continue; -+ } -+ if (conf->default_dest == NULL) { -+ conf->default_dest = dest; -+ } -+ if (file_exists(dest->status_file_name)) { -+ pkg_hash_add_from_file(conf, dest->status_file_name, -+ NULL, dest, 1); -+ } -+ } -+ -+ return 0; -+} -+ -+static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename, -+ pkg_src_list_t *pkg_src_list, -+ nv_pair_list_t *tmp_dest_nv_pair_list, -+ char **lists_dir) -+{ -+ ipkg_option_t * options; -+ FILE *file = fopen(filename, "r"); -+ regex_t valid_line_re, comment_re; -+#define regmatch_size 12 -+ regmatch_t regmatch[regmatch_size]; -+ -+ if (ipkg_init_options_array(conf, &options)<0) -+ return ENOMEM; -+ -+ if (file == NULL) { -+ fprintf(stderr, "%s: failed to open %s: %s\n", -+ __FUNCTION__, filename, strerror(errno)); -+ free(options); -+ return errno; -+ } -+ ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename); -+ -+ xregcomp(&comment_re, -+ "^[[:space:]]*(#.*|[[:space:]]*)$", -+ REG_EXTENDED); -+ xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED); -+ -+ while(1) { -+ int line_num = 0; -+ char *line; -+ char *type, *name, *value, *extra; -+ -+ line = file_read_line_alloc(file); -+ line_num++; -+ if (line == NULL) { -+ break; -+ } -+ -+ str_chomp(line); -+ -+ if (regexec(&comment_re, line, 0, 0, 0) == 0) { -+ goto NEXT_LINE; -+ } -+ -+ if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) { -+ str_chomp(line); -+ fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n", -+ filename, line_num, line); -+ goto NEXT_LINE; -+ } -+ -+ /* This has to be so ugly to deal with optional quotation marks */ -+ if (regmatch[2].rm_so > 0) { -+ type = strndup(line + regmatch[2].rm_so, -+ regmatch[2].rm_eo - regmatch[2].rm_so); -+ } else { -+ type = strndup(line + regmatch[3].rm_so, -+ regmatch[3].rm_eo - regmatch[3].rm_so); -+ } -+ if (regmatch[5].rm_so > 0) { -+ name = strndup(line + regmatch[5].rm_so, -+ regmatch[5].rm_eo - regmatch[5].rm_so); -+ } else { -+ name = strndup(line + regmatch[6].rm_so, -+ regmatch[6].rm_eo - regmatch[6].rm_so); -+ } -+ if (regmatch[8].rm_so > 0) { -+ value = strndup(line + regmatch[8].rm_so, -+ regmatch[8].rm_eo - regmatch[8].rm_so); -+ } else { -+ value = strndup(line + regmatch[9].rm_so, -+ regmatch[9].rm_eo - regmatch[9].rm_so); -+ } -+ extra = NULL; -+ if (regmatch[11].rm_so > 0) { -+ extra = strndup (line + regmatch[11].rm_so, -+ regmatch[11].rm_eo - regmatch[11].rm_so); -+ } -+ -+ /* We use the tmp_dest_nv_pair_list below instead of -+ conf->pkg_dest_list because we might encounter an -+ offline_root option later and that would invalidate the -+ directories we would have computed in -+ pkg_dest_list_init. (We do a similar thing with -+ tmp_src_nv_pair_list for sake of symmetry.) */ -+ if (strcmp(type, "option") == 0) { -+ ipkg_conf_set_option(options, name, value); -+ } else if (strcmp(type, "src") == 0) { -+ if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) { -+ pkg_src_list_append (pkg_src_list, name, value, extra, 0); -+ } else { -+ ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n", -+ name, value); -+ } -+ } else if (strcmp(type, "src/gz") == 0) { -+ if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) { -+ pkg_src_list_append (pkg_src_list, name, value, extra, 1); -+ } else { -+ ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n", -+ name, value); -+ } -+ } else if (strcmp(type, "dest") == 0) { -+ nv_pair_list_append(tmp_dest_nv_pair_list, name, value); -+ } else if (strcmp(type, "lists_dir") == 0) { -+ *lists_dir = realloc(*lists_dir,strlen(value)+1); -+ if (*lists_dir == NULL) { -+ ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n"); -+ free(options); -+ return EINVAL; -+ } -+ sprintf (*lists_dir,"%s",value); -+ } else if (strcmp(type, "arch") == 0) { -+ ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value); -+ if (!value) { -+ ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name); -+ value = strdup("10"); -+ } -+ nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value)); -+ } else { -+ fprintf(stderr, "WARNING: Ignoring unknown configuration " -+ "parameter: %s %s %s\n", type, name, value); -+ free(options); -+ return EINVAL; -+ } -+ -+ free(type); -+ free(name); -+ free(value); -+ if (extra) -+ free (extra); -+ -+ NEXT_LINE: -+ free(line); -+ } -+ -+ free(options); -+ regfree(&comment_re); -+ regfree(&valid_line_re); -+ fclose(file); -+ -+ return 0; -+} -+ -+static int ipkg_conf_set_option(const ipkg_option_t *options, -+ const char *name, const char *value) -+{ -+ int i = 0; -+ while (options[i].name) { -+ if (strcmp(options[i].name, name) == 0) { -+ switch (options[i].type) { -+ case IPKG_OPT_TYPE_BOOL: -+ *((int *)options[i].value) = 1; -+ return 0; -+ case IPKG_OPT_TYPE_INT: -+ if (value) { -+ *((int *)options[i].value) = atoi(value); -+ return 0; -+ } else { -+ printf("%s: Option %s need an argument\n", -+ __FUNCTION__, name); -+ return EINVAL; -+ } -+ case IPKG_OPT_TYPE_STRING: -+ if (value) { -+ *((char **)options[i].value) = strdup(value); -+ return 0; -+ } else { -+ printf("%s: Option %s need an argument\n", -+ __FUNCTION__, name); -+ return EINVAL; -+ } -+ } -+ } -+ i++; -+ } -+ -+ fprintf(stderr, "%s: Unrecognized option: %s=%s\n", -+ __FUNCTION__, name, value); -+ return EINVAL; -+} -+ -+int ipkg_conf_write_status_files(ipkg_conf_t *conf) -+{ -+ pkg_dest_list_elt_t *iter; -+ pkg_dest_t *dest; -+ pkg_vec_t *all; -+ pkg_t *pkg; -+ register int i; -+ int err; -+ -+ if (conf->noaction) -+ return 0; -+ for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) { -+ dest = iter->data; -+ dest->status_file = fopen(dest->status_file_tmp_name, "w"); -+ if (dest->status_file == NULL) { -+ fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n", -+ __FUNCTION__, dest->status_file_name, strerror(errno)); -+ } -+ } -+ -+ all = pkg_vec_alloc(); -+ pkg_hash_fetch_available(&conf->pkg_hash, all); -+ -+ for(i = 0; i < all->len; i++) { -+ pkg = all->pkgs[i]; -+ /* We don't need most uninstalled packages in the status file */ -+ if (pkg->state_status == SS_NOT_INSTALLED -+ && (pkg->state_want == SW_UNKNOWN -+ || pkg->state_want == SW_DEINSTALL -+ || pkg->state_want == SW_PURGE)) { -+ continue; -+ } -+ if (!pkg) { -+ fprintf(stderr, "Null package\n"); -+ } -+ if (pkg->dest == NULL) { -+ fprintf(stderr, "%s: ERROR: Can't write status for " -+ "package %s since it has a NULL dest\n", -+ __FUNCTION__, pkg->name); -+ continue; -+ } -+ if (pkg->dest->status_file) { -+ pkg_print_status(pkg, pkg->dest->status_file); -+ } -+ } -+ -+ pkg_vec_free(all); -+ -+ for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) { -+ dest = iter->data; -+ if (dest->status_file) { -+ err = ferror(dest->status_file); -+ fclose(dest->status_file); -+ dest->status_file = NULL; -+ if (!err) { -+ file_move(dest->status_file_tmp_name, dest->status_file_name); -+ } else { -+ fprintf(stderr, "%s: ERROR: An error has occurred writing %s, " -+ "retaining old %s\n", __FUNCTION__, -+ dest->status_file_tmp_name, dest->status_file_name); -+ } -+ } -+ } -+ -+ return 0; -+} -+ -+ -+char *root_filename_alloc(ipkg_conf_t *conf, char *filename) -+{ -+ char *root_filename; -+ sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename); -+ return root_filename; -+} -Index: busybox-1.4.2/archival/libipkg/ipkg_conf.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg_conf.h 2007-06-04 13:21:36.711395688 +0200 -@@ -0,0 +1,107 @@ -+/* ipkg_conf.h - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef IPKG_CONF_H -+#define IPKG_CONF_H -+ -+typedef struct ipkg_conf ipkg_conf_t; -+ -+#include "hash_table.h" -+#include "ipkg.h" -+#include "args.h" -+#include "pkg.h" -+#include "pkg_hash.h" -+#include "pkg_src_list.h" -+#include "pkg_dest_list.h" -+#include "nv_pair_list.h" -+ -+#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp" -+#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX" -+#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists" -+#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending" -+ -+/* In case the config file defines no dest */ -+#define IPKG_CONF_DEFAULT_DEST_NAME "root" -+#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/" -+ -+#define IPKG_CONF_DEFAULT_HASH_LEN 1024 -+ -+struct ipkg_conf -+{ -+ pkg_src_list_t pkg_src_list; -+ pkg_dest_list_t pkg_dest_list; -+ nv_pair_list_t arch_list; -+ -+ int restrict_to_default_dest; -+ pkg_dest_t *default_dest; -+ -+ char *tmp_dir; -+ const char *lists_dir; -+ const char *pending_dir; -+ -+ /* options */ -+ int force_depends; -+ int force_defaults; -+ int force_overwrite; -+ int force_downgrade; -+ int force_reinstall; -+ int force_space; -+ int force_removal_of_dependent_packages; -+ int force_removal_of_essential_packages; -+ int nodeps; /* do not follow dependences */ -+ int verbose_wget; -+ int multiple_providers; -+ char *offline_root; -+ char *offline_root_pre_script_cmd; -+ char *offline_root_post_script_cmd; -+ int query_all; -+ int verbosity; -+ int noaction; -+ -+ /* proxy options */ -+ char *http_proxy; -+ char *ftp_proxy; -+ char *no_proxy; -+ char *proxy_user; -+ char *proxy_passwd; -+ -+ hash_table_t pkg_hash; -+ hash_table_t file_hash; -+ hash_table_t obs_file_hash; -+}; -+ -+enum ipkg_option_type { -+ IPKG_OPT_TYPE_BOOL, -+ IPKG_OPT_TYPE_INT, -+ IPKG_OPT_TYPE_STRING -+}; -+typedef enum ipkg_option_type ipkg_option_type_t; -+ -+typedef struct ipkg_option ipkg_option_t; -+struct ipkg_option { -+ const char *name; -+ const ipkg_option_type_t type; -+ const void *value; -+}; -+ -+int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args); -+void ipkg_conf_deinit(ipkg_conf_t *conf); -+ -+int ipkg_conf_write_status_files(ipkg_conf_t *conf); -+char *root_filename_alloc(ipkg_conf_t *conf, char *filename); -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/ipkg_configure.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg_configure.c 2007-06-04 13:21:36.712395536 +0200 -@@ -0,0 +1,40 @@ -+/* ipkg_configure.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+ -+#include "ipkg_configure.h" -+ -+int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg) -+{ -+ int err; -+ -+ /* DPKG_INCOMPATIBILITY: -+ dpkg actually does some conffile handling here, rather than at the -+ end of ipkg_install(). Do we care? */ -+ /* DPKG_INCOMPATIBILITY: -+ dpkg actually includes a version number to this script call */ -+ err = pkg_run_script(conf, pkg, "postinst", "configure"); -+ if (err) { -+ printf("ERROR: %s.postinst returned %d\n", pkg->name, err); -+ return err; -+ } -+ -+ ipkg_state_changed++; -+ return 0; -+} -+ -Index: busybox-1.4.2/archival/libipkg/ipkg_configure.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg_configure.h 2007-06-04 13:21:36.712395536 +0200 -@@ -0,0 +1,25 @@ -+/* ipkg_configure.h - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef IPKG_CONFIGURE_H -+#define IPKG_CONFIGURE_H -+ -+#include "ipkg_conf.h" -+ -+int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg); -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/ipkg_download.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg_download.c 2007-06-04 13:21:36.712395536 +0200 -@@ -0,0 +1,195 @@ -+/* ipkg_download.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+#include "ipkg_download.h" -+#include "ipkg_message.h" -+ -+#include "sprintf_alloc.h" -+#include "xsystem.h" -+#include "file_util.h" -+#include "str_util.h" -+ -+int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name) -+{ -+ int err = 0; -+ -+ char *src_basec = strdup(src); -+ char *src_base = basename(src_basec); -+ char *tmp_file_location; -+ char *cmd; -+ -+ ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src); -+ -+ fflush(stdout); -+ -+ if (str_starts_with(src, "file:")) { -+ int ret; -+ const char *file_src = src + 5; -+ ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name); -+ ret = file_copy(src + 5, dest_file_name); -+ ipkg_message(conf,IPKG_INFO,"Done.\n"); -+ return ret; -+ } -+ -+ sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base); -+ err = unlink(tmp_file_location); -+ if (err && errno != ENOENT) { -+ ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n", -+ __FUNCTION__, tmp_file_location, strerror(errno)); -+ free(tmp_file_location); -+ return errno; -+ } -+ -+ if (conf->http_proxy) { -+ ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy); -+ setenv("http_proxy", conf->http_proxy, 1); -+ } -+ if (conf->ftp_proxy) { -+ ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy); -+ setenv("ftp_proxy", conf->ftp_proxy, 1); -+ } -+ if (conf->no_proxy) { -+ ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy); -+ setenv("no_proxy", conf->no_proxy, 1); -+ } -+ -+ /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */ -+ sprintf_alloc(&cmd, "wget --passive-ftp %s %s%s %s%s %s -P %s %s", -+ (conf->http_proxy || conf->ftp_proxy) ? "--proxy=on" : "", -+ conf->proxy_user ? "--proxy-user=" : "", -+ conf->proxy_user ? conf->proxy_user : "", -+ conf->proxy_passwd ? "--proxy-passwd=" : "", -+ conf->proxy_passwd ? conf->proxy_passwd : "", -+ conf->verbose_wget ? "" : "-q", -+ conf->tmp_dir, -+ src); -+ err = xsystem(cmd); -+ if (err) { -+ if (err != -1) { -+ ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n", -+ __FUNCTION__, err, cmd); -+ } -+ unlink(tmp_file_location); -+ free(tmp_file_location); -+ free(src_basec); -+ free(cmd); -+ return EINVAL; -+ } -+ free(cmd); -+ -+ err = file_move(tmp_file_location, dest_file_name); -+ -+ free(tmp_file_location); -+ free(src_basec); -+ -+ if (err) { -+ return err; -+ } -+ -+ return 0; -+} -+ -+int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir) -+{ -+ int err; -+ char *url; -+ -+ if (pkg->src == NULL) { -+ ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n", -+ pkg->name, pkg->parent->name); -+ return -1; -+ } -+ -+ sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename); -+ -+ /* XXX: BUG: The pkg->filename might be something like -+ "../../foo.ipk". While this is correct, and exactly what we -+ want to use to construct url above, here we actually need to -+ use just the filename part, without any directory. */ -+ sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename); -+ -+ err = ipkg_download(conf, url, pkg->local_filename); -+ free(url); -+ -+ return err; -+} -+ -+/* -+ * Downloads file from url, installs in package database, return package name. -+ */ -+int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep) -+{ -+ int err = 0; -+ pkg_t *pkg; -+ pkg = pkg_new(); -+ if (pkg == NULL) -+ return ENOMEM; -+ -+ if (str_starts_with(url, "http://") -+ || str_starts_with(url, "ftp://")) { -+ char *tmp_file; -+ char *file_basec = strdup(url); -+ char *file_base = basename(file_basec); -+ -+ sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base); -+ err = ipkg_download(conf, url, tmp_file); -+ if (err) -+ return err; -+ -+ err = pkg_init_from_file(pkg, tmp_file); -+ if (err) -+ return err; -+ pkg->local_filename = strdup(tmp_file); -+ -+ free(tmp_file); -+ free(file_basec); -+ -+ } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0 -+ || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) { -+ -+ err = pkg_init_from_file(pkg, url); -+ if (err) -+ return err; -+ pkg->local_filename = strdup(url); -+ ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename); -+ pkg->provided_by_hand = 1; -+ -+ } else { -+ pkg_deinit(pkg); -+ free(pkg); -+ return 0; -+ } -+ -+ if (!pkg->architecture) { -+ ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name); -+ return -EINVAL; -+ } -+ -+ pkg->dest = conf->default_dest; -+ pkg->state_want = SW_INSTALL; -+ pkg->state_flag |= SF_PREFER; -+ pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf); -+ if ( pkg == NULL ){ -+ fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__); -+ return 0; -+ } -+ if (namep) { -+ *namep = strdup(pkg->name); -+ } -+ return 0; -+} -Index: busybox-1.4.2/archival/libipkg/ipkg_download.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg_download.h 2007-06-04 13:21:36.712395536 +0200 -@@ -0,0 +1,30 @@ -+/* ipkg_download.h - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef IPKG_DOWNLOAD_H -+#define IPKG_DOWNLOAD_H -+ -+#include "ipkg_conf.h" -+ -+int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name); -+int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir); -+/* -+ * Downloads file from url, installs in package database, return package name. -+ */ -+int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep); -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/ipkg.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg.h 2007-06-04 13:21:36.712395536 +0200 -@@ -0,0 +1,74 @@ -+/* ipkg.h - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef IPKG_H -+#define IPKG_H -+ -+/* -+#ifdef HAVE_CONFIG_H -+#include "config.h" -+#endif -+*/ -+ -+#if 0 -+#define IPKG_DEBUG_NO_TMP_CLEANUP -+#endif -+ -+#include "ipkg_includes.h" -+#include "ipkg_conf.h" -+#include "ipkg_message.h" -+ -+#define IPKG_PKG_EXTENSION ".ipk" -+#define DPKG_PKG_EXTENSION ".deb" -+ -+#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-" -+#define IPKG_PKG_VERSION_SEP_CHAR '_' -+ -+#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg" -+#define IPKG_LISTS_DIR_SUFFIX "lists" -+#define IPKG_INFO_DIR_SUFFIX "info" -+#define IPKG_STATUS_FILE_SUFFIX "status" -+ -+#define IPKG_BACKUP_SUFFIX "-ipkg.backup" -+ -+#define IPKG_LIST_DESCRIPTION_LENGTH 128 -+ -+#define IPKG_VERSION "0.99.162" -+ -+ -+enum ipkg_error { -+ IPKG_SUCCESS = 0, -+ IPKG_PKG_DEPS_UNSATISFIED, -+ IPKG_PKG_IS_ESSENTIAL, -+ IPKG_PKG_HAS_DEPENDENTS, -+ IPKG_PKG_HAS_NO_CANDIDATE -+}; -+typedef enum ipkg_error ipkg_error_t; -+ -+extern int ipkg_state_changed; -+ -+ -+struct errlist { -+ char * errmsg; -+ struct errlist * next; -+} ; -+ -+extern struct errlist* error_list; -+ -+extern ipkg_conf_t *global_conf; -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/ipkg_includes.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg_includes.h 2007-06-04 13:21:36.713395384 +0200 -@@ -0,0 +1,79 @@ -+#ifndef IPKG_INCLUDES_H -+#define IPKG_INCLUDES_H -+ -+/* Define to 1 if you have the header file. */ -+#define HAVE_MEMORY_H 1 -+ -+/* Define to 1 if you have the header file. */ -+#define HAVE_REGEX_H 1 -+ -+/* Define to 1 if you have the header file. */ -+#define HAVE_STDLIB_H 1 -+ -+/* Define to 1 if you have the header file. */ -+#define HAVE_STRINGS_H 1 -+ -+/* Define to 1 if you have the header file. */ -+#define HAVE_STRING_H 1 -+ -+/* Define to 1 if you have the header file. */ -+#define HAVE_SYS_STAT_H 1 -+ -+/* Define to 1 if you have that is POSIX.1 compatible. */ -+#define HAVE_SYS_WAIT_H 1 -+ -+/* Define to 1 if you have the header file. */ -+#define HAVE_UNISTD_H 1 -+ -+/* Define to 1 if you have the ANSI C header files. */ -+#define STDC_HEADERS 1 -+ -+ -+#include -+ -+#if STDC_HEADERS -+# include -+# include -+# include -+# include -+# include -+#else -+# if HAVE_STDLIB_H -+# include -+# endif -+#endif -+ -+#if HAVE_REGEX_H -+# include -+#endif -+ -+#if HAVE_STRING_H -+# if !STDC_HEADERS && HAVE_MEMORY_H -+# include -+# endif -+/* XXX: What's the right way to pick up GNU's strndup declaration? */ -+# if __GNUC__ -+# define __USE_GNU 1 -+# endif -+# include -+# undef __USE_GNU -+#endif -+ -+#if HAVE_STRINGS_H -+# include -+#endif -+ -+#if HAVE_SYS_STAT_H -+# include -+#endif -+ -+#if HAVE_SYS_WAIT_H -+# include -+#endif -+ -+#if HAVE_UNISTD_H -+# include -+# include -+#endif -+ -+#endif /* IPKG_INCLUDES_H */ -Index: busybox-1.4.2/archival/libipkg/ipkg_install.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg_install.c 2007-06-04 13:21:36.714395232 +0200 -@@ -0,0 +1,1942 @@ -+/* ipkg_install.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+#include -+#include -+#include -+#include -+#include -+typedef void (*sighandler_t)(int); -+ -+#include "pkg.h" -+#include "pkg_hash.h" -+#include "pkg_extract.h" -+ -+#include "ipkg_install.h" -+#include "ipkg_configure.h" -+#include "ipkg_download.h" -+#include "ipkg_remove.h" -+ -+#include "ipkg_utils.h" -+#include "ipkg_message.h" -+ -+#include "sprintf_alloc.h" -+#include "file_util.h" -+#include "str_util.h" -+#include "xsystem.h" -+#include "user.h" -+ -+int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg); -+static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg); -+static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg); -+ -+static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); -+static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); -+static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors); -+static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors); -+static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); -+static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); -+static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); -+static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); -+static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); -+static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); -+static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); -+static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); -+static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); -+ -+static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); -+static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg); -+static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg); -+static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg); -+static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg); -+ -+static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg); -+ -+static int user_prefers_old_conffile(const char *file, const char *backup); -+ -+static char *backup_filename_alloc(const char *file_name); -+static int backup_make_backup(ipkg_conf_t *conf, const char *file_name); -+static int backup_exists_for(const char *file_name); -+static int backup_remove(const char *file_name); -+ -+ -+int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename) -+{ -+ int err, cmp; -+ pkg_t *pkg, *old; -+ char *old_version, *new_version; -+ -+ pkg = pkg_new(); -+ if (pkg == NULL) { -+ return ENOMEM; -+ } -+ -+ err = pkg_init_from_file(pkg, filename); -+ if (err) { -+ return err; -+ } -+ -+ if (!pkg->architecture) { -+ ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name); -+ return -EINVAL; -+ } -+ -+ /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly -+ freeing the pkg that we pass in. It might be nice to clean this up -+ if possible. */ -+ pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf); -+ old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name); -+ -+ pkg->local_filename = strdup(filename); -+ -+ if (old) { -+ old_version = pkg_version_str_alloc(old); -+ new_version = pkg_version_str_alloc(pkg); -+ -+ cmp = pkg_compare_versions(old, pkg); -+ if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */ -+ cmp = -1 ; /* then we force ipkg to downgrade */ -+ /* We need to use a value < 0 because in the 0 case we are asking to */ -+ /* reinstall, and some check could fail asking the "force-reinstall" option */ -+ } -+ if (cmp > 0) { -+ ipkg_message(conf, IPKG_NOTICE, -+ "Not downgrading package %s on %s from %s to %s.\n", -+ old->name, old->dest->name, old_version, new_version); -+ pkg->state_want = SW_DEINSTALL; -+ pkg->state_flag |= SF_OBSOLETE; -+ free(old_version); -+ free(new_version); -+ return 0; -+ } else { -+ free(old_version); -+ free(new_version); -+ } -+ } -+ -+ ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__); -+ return ipkg_install_pkg(conf, pkg,0); -+} -+ -+ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name) -+{ -+ int cmp; -+ pkg_t *old, *new; -+ char *old_version, *new_version; -+ -+ ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" ); -+ old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name); -+ if ( old ) -+ ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version ); -+ -+ ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" ); -+ new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name); -+ if ( new ) -+ ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version ); -+ -+/* Pigi Basically here is broken the version stuff. -+ What's happening is that nothing provide the version to differents -+ functions, so the returned struct is always the latest. -+ That's why the install by name don't work. -+*/ -+ ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ ); -+ -+ if ( old ) -+ ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version ); -+ if ( new ) -+ ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version ); -+ ipkg_message(conf, IPKG_DEBUG2, " \n"); -+ -+ if (new == NULL) { -+ return IPKG_PKG_HAS_NO_CANDIDATE; -+ } -+ -+ new->state_flag |= SF_USER; -+ if (old) { -+ old_version = pkg_version_str_alloc(old); -+ new_version = pkg_version_str_alloc(new); -+ -+ cmp = pkg_compare_versions(old, new); -+ if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */ -+ ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n"); -+ cmp = -1 ; /* then we force ipkg to downgrade */ -+ /* We need to use a value < 0 because in the 0 case we are asking to */ -+ /* reinstall, and some check could fail asking the "force-reinstall" option */ -+ } -+ ipkg_message(conf, IPKG_DEBUG, -+ "Comparing visible versions of pkg %s:" -+ "\n\t%s is installed " -+ "\n\t%s is available " -+ "\n\t%d was comparison result\n", -+ pkg_name, old_version, new_version, cmp); -+ if (cmp == 0 && !conf->force_reinstall) { -+ ipkg_message(conf, IPKG_NOTICE, -+ "Package %s (%s) installed in %s is up to date.\n", -+ old->name, old_version, old->dest->name); -+ free(old_version); -+ free(new_version); -+ return 0; -+ } else if (cmp > 0) { -+ ipkg_message(conf, IPKG_NOTICE, -+ "Not downgrading package %s on %s from %s to %s.\n", -+ old->name, old->dest->name, old_version, new_version); -+ free(old_version); -+ free(new_version); -+ return 0; -+ } else if (cmp < 0) { -+ new->dest = old->dest; -+ old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */ -+ } -+ } -+ -+ /* XXX: CLEANUP: The error code of ipkg_install_by_name is really -+ supposed to be an ipkg_error_t, but ipkg_install_pkg could -+ return any kind of integer, (might be errno from a syscall, -+ etc.). This is a real mess and will need to be cleaned up if -+ anyone ever wants to make a nice libipkg. */ -+ -+ ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__); -+ return ipkg_install_pkg(conf, new,0); -+} -+ -+ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name) -+{ -+ abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name); -+ int i; -+ ipkg_error_t err; -+ abstract_pkg_t *ppkg ; -+ -+ if (providers == NULL) -+ return IPKG_PKG_HAS_NO_CANDIDATE; -+ -+ for (i = 0; i < providers->len; i++) { -+ ppkg = abstract_pkg_vec_get(providers, i); -+ ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i); -+ err = ipkg_install_by_name(conf, ppkg->name); -+ if (err) -+ return err; -+/* XXX Maybe ppkg should be freed ? */ -+ } -+ return 0; -+} -+ -+/* -+ * Walk dependence graph starting with pkg, collect packages to be -+ * installed into pkgs_needed, in dependence order. -+ */ -+int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed) -+{ -+ int i, err; -+ pkg_vec_t *depends = pkg_vec_alloc(); -+ char **unresolved = NULL; -+ int ndepends; -+ -+ ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf, -+ pkg, depends, -+ &unresolved); -+ -+ if (unresolved) { -+ ipkg_message(conf, IPKG_ERROR, -+ "%s: Cannot satisfy the following dependencies for %s:\n\t", -+ conf->force_depends ? "Warning" : "ERROR", pkg->name); -+ while (*unresolved) { -+ ipkg_message(conf, IPKG_ERROR, " %s", *unresolved); -+ unresolved++; -+ } -+ ipkg_message(conf, IPKG_ERROR, "\n"); -+ if (! conf->force_depends) { -+ ipkg_message(conf, IPKG_INFO, -+ "This could mean that your package list is out of date or that the packages\n" -+ "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n" -+ "of this problem try again with the '-force-depends' option.\n"); -+ pkg_vec_free(depends); -+ return IPKG_PKG_DEPS_UNSATISFIED; -+ } -+ } -+ -+ if (ndepends <= 0) { -+ pkg_vec_free(depends); -+ return 0; -+ } -+ -+ for (i = 0; i < depends->len; i++) { -+ pkg_t *dep = depends->pkgs[i]; -+ /* The package was uninstalled when we started, but another -+ dep earlier in this loop may have depended on it and pulled -+ it in, so check first. */ -+ if ((dep->state_status != SS_INSTALLED) -+ && (dep->state_status != SS_UNPACKED) -+ && (dep->state_want != SW_INSTALL)) { -+ -+ /* Mark packages as to-be-installed */ -+ dep->state_want = SW_INSTALL; -+ -+ /* Dependencies should be installed the same place as pkg */ -+ if (dep->dest == NULL) { -+ dep->dest = pkg->dest; -+ } -+ -+ err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed); -+ if (err) { -+ pkg_vec_free(depends); -+ return err; -+ } -+ } -+ } -+ if (pkgs_needed) -+ pkg_vec_insert(pkgs_needed, pkg); -+ -+ pkg_vec_free(depends); -+ -+ return 0; -+} -+ -+int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed) -+{ -+ int cmp; -+ pkg_t *old, *new; -+ char *old_version, *new_version; -+ -+ old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name); -+ -+ new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name); -+ if (new == NULL) { -+ return IPKG_PKG_HAS_NO_CANDIDATE; -+ } -+ if (old) { -+ old_version = pkg_version_str_alloc(old); -+ new_version = pkg_version_str_alloc(new); -+ -+ cmp = pkg_compare_versions(old, new); -+ if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */ -+ ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade "); -+ cmp = -1 ; /* then we force ipkg to downgrade */ -+ /* We need to use a value < 0 because in the 0 case we are asking to */ -+ /* reinstall, and some check could fail asking the "force-reinstall" option */ -+ } -+ ipkg_message(conf, IPKG_DEBUG, -+ "comparing visible versions of pkg %s:" -+ "\n\t%s is installed " -+ "\n\t%s is available " -+ "\n\t%d was comparison result\n", -+ pkg_name, old_version, new_version, cmp); -+ if (cmp == 0 && !conf->force_reinstall) { -+ ipkg_message(conf, IPKG_NOTICE, -+ "Package %s (%s) installed in %s is up to date.\n", -+ old->name, old_version, old->dest->name); -+ free(old_version); -+ free(new_version); -+ return 0; -+ } else if (cmp > 0) { -+ ipkg_message(conf, IPKG_NOTICE, -+ "Not downgrading package %s on %s from %s to %s.\n", -+ old->name, old->dest->name, old_version, new_version); -+ free(old_version); -+ free(new_version); -+ return 0; -+ } else if (cmp < 0) { -+ new->dest = old->dest; -+ old->state_want = SW_DEINSTALL; -+ old->state_flag |= SF_OBSOLETE; -+ } -+ } -+ return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed); -+} -+ -+ -+ -+int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg) -+{ -+ int i, err; -+ pkg_vec_t *depends = pkg_vec_alloc(); -+ pkg_t *dep; -+ char **unresolved = NULL; -+ int ndepends; -+ -+ ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf, -+ pkg, depends, -+ &unresolved); -+ -+ if (unresolved) { -+ ipkg_message(conf, IPKG_ERROR, -+ "%s: Cannot satisfy the following dependencies for %s:\n\t", -+ conf->force_depends ? "Warning" : "ERROR", pkg->name); -+ while (*unresolved) { -+ ipkg_message(conf, IPKG_ERROR, " %s", *unresolved); -+ unresolved++; -+ } -+ ipkg_message(conf, IPKG_ERROR, "\n"); -+ if (! conf->force_depends) { -+ ipkg_message(conf, IPKG_INFO, -+ "This could mean that your package list is out of date or that the packages\n" -+ "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n" -+ "of this problem try again with the '-force-depends' option.\n"); -+ pkg_vec_free(depends); -+ return IPKG_PKG_DEPS_UNSATISFIED; -+ } -+ } -+ -+ if (ndepends <= 0) { -+ return 0; -+ } -+ -+ /* Mark packages as to-be-installed */ -+ for (i=0; i < depends->len; i++) { -+ /* Dependencies should be installed the same place as pkg */ -+ if (depends->pkgs[i]->dest == NULL) { -+ depends->pkgs[i]->dest = pkg->dest; -+ } -+ depends->pkgs[i]->state_want = SW_INSTALL; -+ } -+ -+ for (i = 0; i < depends->len; i++) { -+ dep = depends->pkgs[i]; -+ /* The package was uninstalled when we started, but another -+ dep earlier in this loop may have depended on it and pulled -+ it in, so check first. */ -+ if ((dep->state_status != SS_INSTALLED) -+ && (dep->state_status != SS_UNPACKED)) { -+ ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__); -+ err = ipkg_install_pkg(conf, dep,0); -+ if (err) { -+ pkg_vec_free(depends); -+ return err; -+ } -+ } -+ } -+ -+ pkg_vec_free(depends); -+ -+ return 0; -+} -+ -+ -+/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */ -+int ipkg_satisfy_all_dependences(ipkg_conf_t *conf) -+{ -+ if (conf->nodeps == 0) { -+ int i; -+ pkg_vec_t *installed = pkg_vec_alloc(); -+ pkg_hash_fetch_all_installed(&conf->pkg_hash, installed); -+ for (i = 0; i < installed->len; i++) { -+ pkg_t *pkg = installed->pkgs[i]; -+ satisfy_dependencies_for(conf, pkg); -+ } -+ pkg_vec_free(installed); -+ } -+ return 0; -+} -+ -+ -+ -+static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg) -+{ -+ int i; -+ pkg_vec_t *conflicts = NULL; -+ int level; -+ const char *prefix; -+ if (conf->force_depends) { -+ level = IPKG_NOTICE; -+ prefix = "Warning"; -+ } else { -+ level = IPKG_ERROR; -+ prefix = "ERROR"; -+ } -+ -+ if (!conf->force_depends) -+ conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg); -+ -+ if (conflicts) { -+ ipkg_message(conf, level, -+ "%s: The following packages conflict with %s:\n\t", prefix, pkg->name); -+ i = 0; -+ while (i < conflicts->len) -+ ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name); -+ ipkg_message(conf, level, "\n"); -+ pkg_vec_free(conflicts); -+ return IPKG_PKG_DEPS_UNSATISFIED; -+ } -+ return 0; -+} -+ -+static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg) -+{ -+ str_list_t *new_list = pkg_get_installed_files(new_pkg); -+ str_list_elt_t *iter; -+ -+ for (iter = new_list->head; iter; iter = iter->next) { -+ char *new_file = iter->data; -+ pkg_t *owner = file_hash_get_file_owner(conf, new_file); -+ if (!new_file) -+ ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name); -+ if (!owner || (owner == old_pkg)) -+ file_hash_set_file_owner(conf, new_file, new_pkg); -+ } -+ if (old_pkg) { -+ str_list_t *old_list = pkg_get_installed_files(old_pkg); -+ for (iter = old_list->head; iter; iter = iter->next) { -+ char *old_file = iter->data; -+ pkg_t *owner = file_hash_get_file_owner(conf, old_file); -+ if (owner == old_pkg) { -+ /* obsolete */ -+ hash_table_insert(&conf->obs_file_hash, old_file, old_pkg); -+ } -+ } -+ } -+ return 0; -+} -+ -+static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg) -+{ -+ /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */ -+ -+ /* sma 6.20.02: yup; here's the first bit */ -+ /* -+ * XXX: BUG easy for cworth -+ * 1) please point the call below to the correct current root destination -+ * 2) we need to resolve how to check the required space for a pending pkg, -+ * my diddling with the .ipk file size below isn't going to cut it. -+ * 3) return a proper error code instead of 1 -+ */ -+ int comp_size, blocks_available; -+ -+ if (!conf->force_space && pkg->installed_size != NULL) { -+ blocks_available = get_available_blocks(conf->default_dest->root_dir); -+ -+ comp_size = strtoul(pkg->installed_size, NULL, 0); -+ /* round up a blocks count without doing fancy-but-slow casting jazz */ -+ comp_size = (int)((comp_size + 1023) / 1024); -+ -+ if (comp_size >= blocks_available) { -+ ipkg_message(conf, IPKG_ERROR, -+ "Only have %d available blocks on filesystem %s, pkg %s needs %d\n", -+ blocks_available, conf->default_dest->root_dir, pkg->name, comp_size); -+ return ENOSPC; -+ } -+ } -+ return 0; -+} -+ -+static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg) -+{ -+ int err; -+ char *conffiles_file_name; -+ char *root_dir; -+ FILE *conffiles_file; -+ -+ sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name); -+ -+ pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir); -+ if (pkg->tmp_unpack_dir == NULL) { -+ ipkg_message(conf, IPKG_ERROR, -+ "%s: Failed to create temporary directory '%s': %s\n", -+ __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno)); -+ return errno; -+ } -+ -+ err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir); -+ if (err) { -+ return err; -+ } -+ -+ /* XXX: CLEANUP: There might be a cleaner place to read in the -+ conffiles. Seems like I should be able to get everything to go -+ through pkg_init_from_file. If so, maybe it would make sense to -+ move all of unpack_pkg_control_files to that function. */ -+ -+ /* Don't need to re-read conffiles if we already have it */ -+ if (pkg->conffiles.head) { -+ return 0; -+ } -+ -+ sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir); -+ if (! file_exists(conffiles_file_name)) { -+ free(conffiles_file_name); -+ return 0; -+ } -+ -+ conffiles_file = fopen(conffiles_file_name, "r"); -+ if (conffiles_file == NULL) { -+ fprintf(stderr, "%s: failed to open %s: %s\n", -+ __FUNCTION__, conffiles_file_name, strerror(errno)); -+ free(conffiles_file_name); -+ return errno; -+ } -+ free(conffiles_file_name); -+ -+ while (1) { -+ char *cf_name; -+ char *cf_name_in_dest; -+ -+ cf_name = file_read_line_alloc(conffiles_file); -+ if (cf_name == NULL) { -+ break; -+ } -+ str_chomp(cf_name); -+ if (cf_name[0] == '\0') { -+ continue; -+ } -+ -+ /* Prepend dest->root_dir to conffile name. -+ Take pains to avoid multiple slashes. */ -+ root_dir = pkg->dest->root_dir; -+ if (conf->offline_root) -+ /* skip the offline_root prefix */ -+ root_dir = pkg->dest->root_dir + strlen(conf->offline_root); -+ sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir, -+ cf_name[0] == '/' ? (cf_name + 1) : cf_name); -+ -+ /* Can't get an md5sum now, (file isn't extracted yet). -+ We'll wait until resolve_conffiles */ -+ conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL); -+ -+ free(cf_name); -+ free(cf_name_in_dest); -+ } -+ -+ fclose(conffiles_file); -+ -+ return 0; -+} -+ -+/* returns number of installed replacees */ -+int pkg_get_installed_replacees(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees) -+{ -+ abstract_pkg_t **replaces = pkg->replaces; -+ int replaces_count = pkg->replaces_count; -+ int i, j; -+ for (i = 0; i < replaces_count; i++) { -+ abstract_pkg_t *ab_pkg = replaces[i]; -+ pkg_vec_t *pkg_vec = ab_pkg->pkgs; -+ if (pkg_vec) { -+ for (j = 0; j < pkg_vec->len; j++) { -+ pkg_t *replacee = pkg_vec->pkgs[j]; -+ if (!pkg_conflicts(pkg, replacee)) -+ continue; -+ if (replacee->state_status == SS_INSTALLED) { -+ pkg_vec_insert(installed_replacees, replacee); -+ } -+ } -+ } -+ } -+ return installed_replacees->len; -+} -+ -+int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees) -+{ -+ int i; -+ int replaces_count = replacees->len; -+ for (i = 0; i < replaces_count; i++) { -+ pkg_t *replacee = replacees->pkgs[i]; -+ int err; -+ replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */ -+ err = ipkg_remove_pkg(conf, replacee,0); -+ if (err) -+ return err; -+ } -+ return 0; -+} -+ -+/* to unwind the removal: make sure they are installed */ -+int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees) -+{ -+ int i, err; -+ int replaces_count = replacees->len; -+ for (i = 0; i < replaces_count; i++) { -+ pkg_t *replacee = replacees->pkgs[i]; -+ if (replacee->state_status != SS_INSTALLED) { -+ ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__); -+ err = ipkg_install_pkg(conf, replacee,0); -+ if (err) -+ return err; -+ } -+ } -+ return 0; -+} -+ -+int caught_sigint = 0; -+static void ipkg_install_pkg_sigint_handler(int sig) -+{ -+ caught_sigint = sig; -+} -+ -+/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */ -+static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message) -+{ -+ if (old_pkg) { -+ char message_out[15]; -+ char *old_version = pkg_version_str_alloc(old_pkg); -+ char *new_version = pkg_version_str_alloc(pkg); -+ int cmp = pkg_compare_versions(old_pkg, pkg); -+ int rc = 0; -+ -+ memset(message_out,'\x0',15); -+ strncpy (message_out,"Upgrading ",strlen("Upgrading ")); -+ if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */ -+ cmp = -1 ; /* then we force ipkg to downgrade */ -+ strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */ -+ /* reinstall, and some check could fail asking the "force-reinstall" option */ -+ } -+ -+ if (cmp > 0) { -+ ipkg_message(conf, IPKG_NOTICE, -+ "Not downgrading package %s on %s from %s to %s.\n", -+ old_pkg->name, old_pkg->dest->name, old_version, new_version); -+ rc = 1; -+ } else if (cmp < 0) { -+ ipkg_message(conf, IPKG_NOTICE, -+ "%s%s on %s from %s to %s...\n", -+ message_out, pkg->name, old_pkg->dest->name, old_version, new_version); -+ pkg->dest = old_pkg->dest; -+ rc = 0; -+ } else /* cmp == 0 */ { -+ if (conf->force_reinstall) { -+ ipkg_message(conf, IPKG_NOTICE, -+ "Reinstalling %s (%s) on %s...\n", -+ pkg->name, new_version, old_pkg->dest->name); -+ pkg->dest = old_pkg->dest; -+ rc = 0; -+ } else { -+ ipkg_message(conf, IPKG_NOTICE, -+ "Not installing %s (%s) on %s -- already installed.\n", -+ pkg->name, new_version, old_pkg->dest->name); -+ rc = 1; -+ } -+ } -+ free(old_version); -+ free(new_version); -+ return rc; -+ } else { -+ char message_out[15], *version ; -+ memset(message_out,'\x0',15); -+ if ( message ) -+ strncpy( message_out,"Upgrading ",strlen("Upgrading ") ); -+ else -+ strncpy( message_out,"Installing ",strlen("Installing ") ); -+ version = pkg_version_str_alloc(pkg); -+ -+ ipkg_message(conf, IPKG_NOTICE, -+ "%s%s (%s) to %s...\n", message_out, -+ pkg->name, version, pkg->dest->name); -+ free(version); -+ return 0; -+ } -+} -+ -+/* and now the meat... */ -+int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade) -+{ -+ int err = 0; -+ int message = 0; -+ pkg_t *old_pkg = NULL; -+ pkg_vec_t *replacees; -+ abstract_pkg_t *ab_pkg = NULL; -+ int old_state_flag; -+ char* file_md5; -+ -+ -+ if ( from_upgrade ) -+ message = 1; /* Coming from an upgrade, and should change the output message */ -+ -+ if (!pkg) { -+ ipkg_message(conf, IPKG_ERROR, -+ "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n"); -+ return -EINVAL; -+ } -+ -+ ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__); -+ -+ if (!pkg_arch_supported(conf, pkg)) { -+ ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n", -+ pkg->architecture, pkg->name); -+ return -EINVAL; -+ } -+ if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) { -+ err = satisfy_dependencies_for(conf, pkg); -+ if (err) { return err; } -+ -+ ipkg_message(conf, IPKG_NOTICE, -+ "Package %s is already installed in %s.\n", -+ pkg->name, pkg->dest->name); -+ return 0; -+ } -+ -+ if (pkg->dest == NULL) { -+ pkg->dest = conf->default_dest; -+ } -+ -+ old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name); -+ -+ err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message); -+ if (err) { return err; } -+ -+ pkg->state_want = SW_INSTALL; -+ if (old_pkg){ -+ old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */ -+ } -+ -+ -+ /* Abhaya: conflicts check */ -+ err = check_conflicts_for(conf, pkg); -+ if (err) { return err; } -+ -+ /* this setup is to remove the upgrade scenario in the end when -+ installing pkg A, A deps B & B deps on A. So both B and A are -+ installed. Then A's installation is started resulting in an -+ uncecessary upgrade */ -+ if (pkg->state_status == SS_INSTALLED -+ && conf->force_reinstall == 0) return 0; -+ -+ err = verify_pkg_installable(conf, pkg); -+ if (err) { return err; } -+ -+ if (pkg->local_filename == NULL) { -+ err = ipkg_download_pkg(conf, pkg, conf->tmp_dir); -+ if (err) { -+ ipkg_message(conf, IPKG_ERROR, -+ "Failed to download %s. Perhaps you need to run 'ipkg update'?\n", -+ pkg->name); -+ return err; -+ } -+ } -+ -+/* Check for md5 values */ -+ if (pkg->md5sum) -+ { -+ file_md5 = file_md5sum_alloc(pkg->local_filename); -+ if (strcmp(file_md5, pkg->md5sum)) -+ { -+ ipkg_message(conf, IPKG_ERROR, -+ "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n", -+ pkg->name); -+ free(file_md5); -+ return err; -+ } -+ free(file_md5); -+ } -+ -+ if (pkg->tmp_unpack_dir == NULL) { -+ unpack_pkg_control_files(conf, pkg); -+ } -+ -+ /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */ -+/* Pigi: check if it will pass from here when replacing. It seems to fail */ -+/* That's rather strange that files don't change owner. Investigate !!!!!!*/ -+ err = update_file_ownership(conf, pkg, old_pkg); -+ if (err) { return err; } -+ -+ if (conf->nodeps == 0) { -+ err = satisfy_dependencies_for(conf, pkg); -+ if (err) { return err; } -+ } -+ -+ replacees = pkg_vec_alloc(); -+ pkg_get_installed_replacees(conf, pkg, replacees); -+ -+ /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */ -+ { -+ sigset_t newset, oldset; -+ sighandler_t old_handler = NULL; -+ int use_signal = 0; -+ caught_sigint = 0; -+ if (use_signal) { -+ old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler); -+ } else { -+ sigemptyset(&newset); -+ sigaddset(&newset, SIGINT); -+ sigprocmask(SIG_BLOCK, &newset, &oldset); -+ } -+ -+ ipkg_state_changed++; -+ pkg->state_flag |= SF_FILELIST_CHANGED; -+ -+ /* XXX: BUG: we really should treat replacement more like an upgrade -+ * Instead, we're going to remove the replacees -+ */ -+ err = pkg_remove_installed_replacees(conf, replacees); -+ if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES; -+ -+ err = prerm_upgrade_old_pkg(conf, pkg, old_pkg); -+ if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG; -+ -+ err = prerm_deconfigure_conflictors(conf, pkg, replacees); -+ if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS; -+ -+ err = preinst_configure(conf, pkg, old_pkg); -+ if (err) goto UNWIND_PREINST_CONFIGURE; -+ -+ err = backup_modified_conffiles(conf, pkg, old_pkg); -+ if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES; -+ -+ err = check_data_file_clashes(conf, pkg, old_pkg); -+ if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES; -+ -+ err = postrm_upgrade_old_pkg(conf, pkg, old_pkg); -+ if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG; -+ -+ if (conf->noaction) return 0; -+ -+ /* point of no return: no unwinding after this */ -+ if (old_pkg && !conf->force_reinstall) { -+ old_pkg->state_want = SW_DEINSTALL; -+ -+ if (old_pkg->state_flag & SF_NOPRUNE) { -+ ipkg_message(conf, IPKG_INFO, -+ " not removing obsolesced files because package marked noprune\n"); -+ } else { -+ ipkg_message(conf, IPKG_INFO, -+ " removing obsolesced files\n"); -+ remove_obsolesced_files(conf, pkg, old_pkg); -+ } -+ /* removing files from old package, to avoid ghost files */ -+ remove_data_files_and_list(conf, old_pkg); -+/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/ -+ remove_maintainer_scripts_except_postrm(conf, old_pkg); -+ remove_postrm(conf, old_pkg); -+/* Pigi */ -+ -+ } -+ -+ -+ ipkg_message(conf, IPKG_INFO, -+ " installing maintainer scripts\n"); -+ install_maintainer_scripts(conf, pkg, old_pkg); -+ -+ /* the following just returns 0 */ -+ remove_disappeared(conf, pkg); -+ -+ ipkg_message(conf, IPKG_INFO, -+ " installing data files\n"); -+ install_data_files(conf, pkg); -+ -+/* read comments from function for detail but I will execute this here as all other tests are ok.*/ -+ err = check_data_file_clashes_change(conf, pkg, old_pkg); -+ -+ ipkg_message(conf, IPKG_INFO, -+ " resolving conf files\n"); -+ resolve_conffiles(conf, pkg); -+ -+ pkg->state_status = SS_UNPACKED; -+ old_state_flag = pkg->state_flag; -+ pkg->state_flag &= ~SF_PREFER; -+ ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag); -+ -+ if (old_pkg && !conf->force_reinstall) { -+ old_pkg->state_status = SS_NOT_INSTALLED; -+ } -+ -+ time(&pkg->installed_time); -+ -+ ipkg_message(conf, IPKG_INFO, -+ " cleanup temp files\n"); -+ cleanup_temporary_files(conf, pkg); -+ -+ ab_pkg = pkg->parent; -+ if (ab_pkg) -+ ab_pkg->state_status = pkg->state_status; -+ -+ ipkg_message(conf, IPKG_INFO, "Done.\n"); -+ -+ if (use_signal) -+ signal(SIGINT, old_handler); -+ else -+ sigprocmask(SIG_UNBLOCK, &newset, &oldset); -+ -+ return 0; -+ -+ -+ UNWIND_POSTRM_UPGRADE_OLD_PKG: -+ postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg); -+ UNWIND_CHECK_DATA_FILE_CLASHES: -+ check_data_file_clashes_unwind(conf, pkg, old_pkg); -+ UNWIND_BACKUP_MODIFIED_CONFFILES: -+ backup_modified_conffiles_unwind(conf, pkg, old_pkg); -+ UNWIND_PREINST_CONFIGURE: -+ preinst_configure_unwind(conf, pkg, old_pkg); -+ UNWIND_PRERM_DECONFIGURE_CONFLICTORS: -+ prerm_deconfigure_conflictors_unwind(conf, pkg, replacees); -+ UNWIND_PRERM_UPGRADE_OLD_PKG: -+ prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg); -+ UNWIND_REMOVE_INSTALLED_REPLACEES: -+ pkg_remove_installed_replacees_unwind(conf, replacees); -+ -+ ipkg_message(conf, IPKG_INFO, -+ " cleanup temp files\n"); -+ cleanup_temporary_files(conf, pkg); -+ -+ ipkg_message(conf, IPKG_INFO, -+ "Failed.\n"); -+ if (use_signal) -+ signal(SIGINT, old_handler); -+ else -+ sigprocmask(SIG_UNBLOCK, &newset, &oldset); -+ -+ return err; -+ } -+} -+ -+static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) -+{ -+ /* DPKG_INCOMPATIBILITY: -+ dpkg does some things here that we don't do yet. Do we care? -+ -+ 1. If a version of the package is already installed, call -+ old-prerm upgrade new-version -+ 2. If the script runs but exits with a non-zero exit status -+ new-prerm failed-upgrade old-version -+ Error unwind, for both the above cases: -+ old-postinst abort-upgrade new-version -+ */ -+ return 0; -+} -+ -+static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) -+{ -+ /* DPKG_INCOMPATIBILITY: -+ dpkg does some things here that we don't do yet. Do we care? -+ (See prerm_upgrade_old_package for details) -+ */ -+ return 0; -+} -+ -+static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors) -+{ -+ /* DPKG_INCOMPATIBILITY: -+ dpkg does some things here that we don't do yet. Do we care? -+ 2. If a 'conflicting' package is being removed at the same time: -+ 1. If any packages depended on that conflicting package and -+ --auto-deconfigure is specified, call, for each such package: -+ deconfigured's-prerm deconfigure \ -+ in-favour package-being-installed version \ -+ removing conflicting-package version -+ Error unwind: -+ deconfigured's-postinst abort-deconfigure \ -+ in-favour package-being-installed-but-failed version \ -+ removing conflicting-package version -+ -+ The deconfigured packages are marked as requiring -+ configuration, so that if --install is used they will be -+ configured again if possible. -+ 2. To prepare for removal of the conflicting package, call: -+ conflictor's-prerm remove in-favour package new-version -+ Error unwind: -+ conflictor's-postinst abort-remove in-favour package new-version -+ */ -+ return 0; -+} -+ -+static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors) -+{ -+ /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't -+ do yet. Do we care? (See prerm_deconfigure_conflictors for -+ details) */ -+ return 0; -+} -+ -+static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) -+{ -+ int err; -+ char *preinst_args; -+ -+ if (old_pkg) { -+ char *old_version = pkg_version_str_alloc(old_pkg); -+ sprintf_alloc(&preinst_args, "upgrade %s", old_version); -+ free(old_version); -+ } else if (pkg->state_status == SS_CONFIG_FILES) { -+ char *pkg_version = pkg_version_str_alloc(pkg); -+ sprintf_alloc(&preinst_args, "install %s", pkg_version); -+ free(pkg_version); -+ } else { -+ preinst_args = strdup("install"); -+ } -+ -+ err = pkg_run_script(conf, pkg, "preinst", preinst_args); -+ if (err) { -+ ipkg_message(conf, IPKG_ERROR, -+ "Aborting installation of %s\n", pkg->name); -+ return 1; -+ } -+ -+ free(preinst_args); -+ -+ return 0; -+} -+ -+static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) -+{ -+ /* DPKG_INCOMPATIBILITY: -+ dpkg does the following error unwind, should we? -+ pkg->postrm abort-upgrade old-version -+ OR pkg->postrm abort-install old-version -+ OR pkg->postrm abort-install -+ */ -+ return 0; -+} -+ -+static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) -+{ -+ int err; -+ conffile_list_elt_t *iter; -+ conffile_t *cf; -+ -+ if (conf->noaction) return 0; -+ -+ /* Backup all modified conffiles */ -+ if (old_pkg) { -+ for (iter = old_pkg->conffiles.head; iter; iter = iter->next) { -+ char *cf_name; -+ -+ cf = iter->data; -+ cf_name = root_filename_alloc(conf, cf->name); -+ -+ /* Don't worry if the conffile is just plain gone */ -+ if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) { -+ err = backup_make_backup(conf, cf_name); -+ if (err) { -+ return err; -+ } -+ } -+ free(cf_name); -+ } -+ } -+ -+ /* Backup all conffiles that were not conffiles in old_pkg */ -+ for (iter = pkg->conffiles.head; iter; iter = iter->next) { -+ char *cf_name; -+ cf = iter->data; -+ cf_name = root_filename_alloc(conf, cf->name); -+ /* Ignore if this was a conffile in old_pkg as well */ -+ if (pkg_get_conffile(old_pkg, cf->name)) { -+ continue; -+ } -+ -+ if (file_exists(cf_name) && (! backup_exists_for(cf_name))) { -+ err = backup_make_backup(conf, cf_name); -+ if (err) { -+ return err; -+ } -+ } -+ free(cf_name); -+ } -+ -+ return 0; -+} -+ -+static int backup_modified_conffiles_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) -+{ -+ conffile_list_elt_t *iter; -+ -+ if (old_pkg) { -+ for (iter = old_pkg->conffiles.head; iter; iter = iter->next) { -+ backup_remove(iter->data->name); -+ } -+ } -+ -+ for (iter = pkg->conffiles.head; iter; iter = iter->next) { -+ backup_remove(iter->data->name); -+ } -+ -+ return 0; -+} -+ -+ -+static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) -+{ -+ /* DPKG_INCOMPATIBILITY: -+ ipkg takes a slightly different approach than dpkg at this -+ point. dpkg installs each file in the new package while -+ creating a backup for any file that is replaced, (so that it -+ can unwind if necessary). To avoid complexity and redundant -+ storage, ipkg doesn't do any installation until later, (at the -+ point at which dpkg removes the backups. -+ -+ But, we do have to check for data file clashes, since after -+ installing a package with a file clash, removing either of the -+ packages involved in the clash has the potential to break the -+ other package. -+ */ -+ str_list_t *files_list; -+ str_list_elt_t *iter; -+ -+ int clashes = 0; -+ -+ files_list = pkg_get_installed_files(pkg); -+ for (iter = files_list->head; iter; iter = iter->next) { -+ char *root_filename; -+ char *filename = iter->data; -+ root_filename = root_filename_alloc(conf, filename); -+ if (file_exists(root_filename) && (! file_is_dir(root_filename))) { -+ pkg_t *owner; -+ pkg_t *obs; -+ /* Pre-existing conffiles are OK */ -+ /* @@@@ should have way to check that it is a conffile -Jamey */ -+ if (backup_exists_for(root_filename)) { -+ continue; -+ } -+ -+ /* Pre-existing files are OK if force-overwrite was asserted. */ -+ if (conf->force_overwrite) { -+ /* but we need to change who owns this file */ -+ file_hash_set_file_owner(conf, filename, pkg); -+ continue; -+ } -+ -+ owner = file_hash_get_file_owner(conf, filename); -+ -+ /* Pre-existing files are OK if owned by the pkg being upgraded. */ -+ if (owner && old_pkg) { -+ if (strcmp(owner->name, old_pkg->name) == 0) { -+ continue; -+ } -+ } -+ -+ /* Pre-existing files are OK if owned by a package replaced by new pkg. */ -+ if (owner) { -+ ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name); -+ if (pkg_replaces(pkg, owner)) { -+ continue; -+ } -+/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar ) -+ then it's ok to overwrite. */ -+ if (strcmp(owner->name,pkg->name)==0){ -+ ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name); -+ continue; -+ } -+ } -+ -+ /* Pre-existing files are OK if they are obsolete */ -+ obs = hash_table_get(&conf->obs_file_hash, filename); -+ if (obs) { -+ ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name); -+ continue; -+ } -+ -+ /* We have found a clash. */ -+ ipkg_message(conf, IPKG_ERROR, -+ "Package %s wants to install file %s\n" -+ "\tBut that file is already provided by package ", -+ pkg->name, filename); -+ if (owner) { -+ ipkg_message(conf, IPKG_ERROR, -+ "%s\n", owner->name); -+ } else { -+ ipkg_message(conf, IPKG_ERROR, -+ "\nPlease move this file out of the way and try again.\n"); -+ } -+ clashes++; -+ } -+ free(root_filename); -+ } -+ pkg_free_installed_files(pkg); -+ -+ return clashes; -+} -+ -+static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) -+{ -+ /* Basically that's the worst hack I could do to be able to change ownership of -+ file list, but, being that we have no way to unwind the mods, due to structure -+ of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much. -+ What we do here is change the ownership of file in hash if a replace ( or similar events -+ happens ) -+ Only the action that are needed to change name should be considered. -+ @@@ To change after 1.0 release. -+ */ -+ str_list_t *files_list; -+ str_list_elt_t *iter; -+ -+ int clashes = 0; -+ -+ files_list = pkg_get_installed_files(pkg); -+ for (iter = files_list->head; iter; iter = iter->next) { -+ char *root_filename; -+ char *filename = iter->data; -+ root_filename = root_filename_alloc(conf, filename); -+ if (file_exists(root_filename) && (! file_is_dir(root_filename))) { -+ pkg_t *owner; -+ -+ if (conf->force_overwrite) { -+ /* but we need to change who owns this file */ -+ file_hash_set_file_owner(conf, filename, pkg); -+ continue; -+ } -+ -+ owner = file_hash_get_file_owner(conf, filename); -+ -+ /* Pre-existing files are OK if owned by a package replaced by new pkg. */ -+ if (owner) { -+ if (pkg_replaces(pkg, owner)) { -+/* It's now time to change the owner of that file. -+ It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */ -+ ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name); -+ file_hash_set_file_owner(conf, filename, pkg); -+ continue; -+ } -+ } -+ -+ } -+ free(root_filename); -+ } -+ pkg_free_installed_files(pkg); -+ -+ return clashes; -+} -+ -+static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) -+{ -+ /* Nothing to do since check_data_file_clashes doesn't change state */ -+ return 0; -+} -+ -+static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) -+{ -+ /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we? -+ 1. If the package is being upgraded, call -+ old-postrm upgrade new-version -+ 2. If this fails, attempt: -+ new-postrm failed-upgrade old-version -+ Error unwind, for both cases: -+ old-preinst abort-upgrade new-version */ -+ return 0; -+} -+ -+static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) -+{ -+ /* DPKG_INCOMPATIBILITY: -+ dpkg does some things here that we don't do yet. Do we care? -+ (See postrm_upgrade_old_pkg for details) -+ */ -+ return 0; -+} -+ -+static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) -+{ -+ int err; -+ str_list_t *old_files; -+ str_list_elt_t *of; -+ str_list_t *new_files; -+ str_list_elt_t *nf; -+ -+ if (old_pkg == NULL) { -+ return 0; -+ } -+ -+ old_files = pkg_get_installed_files(old_pkg); -+ new_files = pkg_get_installed_files(pkg); -+ -+ for (of = old_files->head; of; of = of->next) { -+ pkg_t *owner; -+ char *old, *new; -+ old = of->data; -+ for (nf = new_files->head; nf; nf = nf->next) { -+ new = nf->data; -+ if (strcmp(old, new) == 0) { -+ goto NOT_OBSOLETE; -+ } -+ } -+ if (file_is_dir(old)) { -+ continue; -+ } -+ owner = file_hash_get_file_owner(conf, old); -+ if (owner != old_pkg) { -+ /* in case obsolete file no longer belongs to old_pkg */ -+ continue; -+ } -+ -+ /* old file is obsolete */ -+ ipkg_message(conf, IPKG_INFO, -+ " removing obsolete file %s\n", old); -+ if (!conf->noaction) { -+ err = unlink(old); -+ if (err) { -+ ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old, -+ strerror(errno)); -+ } -+ } -+ -+ NOT_OBSOLETE: -+ ; -+ } -+ -+ pkg_free_installed_files(old_pkg); -+ pkg_free_installed_files(pkg); -+ -+ return 0; -+} -+ -+static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) -+{ -+ int i; -+ int err = 0; -+ char *globpattern; -+ glob_t globbuf; -+ if (0) { -+ if (!pkg->dest) { -+ ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name); -+ return -1; -+ } -+ sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name); -+ err = glob(globpattern, 0, NULL, &globbuf); -+ free(globpattern); -+ if (err) { -+ return err; -+ } -+ /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */ -+ for (i = 0; i < globbuf.gl_pathc; i++) { -+ ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n", -+ globbuf.gl_pathv[i], old_pkg->name); -+ if (!conf->noaction) -+ unlink(globbuf.gl_pathv[i]); -+ } -+ globfree(&globbuf); -+ } -+ return err; -+} -+ -+static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) -+{ -+ int ret; -+ char *prefix; -+ -+ if (old_pkg) -+ remove_obsolete_maintainer_scripts(conf, pkg, old_pkg); -+ sprintf_alloc(&prefix, "%s.", pkg->name); -+ ret = pkg_extract_control_files_to_dir_with_prefix(pkg, -+ pkg->dest->info_dir, -+ prefix); -+ free(prefix); -+ return ret; -+} -+ -+static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg) -+{ -+ /* DPKG_INCOMPATIBILITY: -+ This is a fairly sophisticated dpkg operation. Shall we -+ skip it? */ -+ -+ /* Any packages all of whose files have been overwritten during the -+ installation, and which aren't required for dependencies, are -+ considered to have been removed. For each such package -+ 1. disappearer's-postrm disappear overwriter overwriter-version -+ 2. The package's maintainer scripts are removed -+ 3. It is noted in the status database as being in a sane state, -+ namely not installed (any conffiles it may have are ignored, -+ rather than being removed by dpkg). Note that disappearing -+ packages do not have their prerm called, because dpkg doesn't -+ know in advance that the package is going to vanish. -+ */ -+ return 0; -+} -+ -+static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg) -+{ -+ int err; -+ -+ /* ipkg takes a slightly different approach to data file backups -+ than dpkg. Rather than removing backups at this point, we -+ actually do the data file installation now. See comments in -+ check_data_file_clashes() for more details. */ -+ -+ ipkg_message(conf, IPKG_INFO, -+ " extracting data files to %s\n", pkg->dest->root_dir); -+ err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir); -+ if (err) { -+ return err; -+ } -+ -+ /* XXX: BUG or FEATURE : We are actually loosing the Essential flag, -+ so we can't save ourself from removing important packages -+ At this point we (should) have extracted the .control file, so it -+ would be a good idea to reload the data in it, and set the Essential -+ state in *pkg. From now on the Essential is back in status file and -+ we can protect again. -+ We should operate this way: -+ fopen the file ( pkg->dest->root_dir/pkg->name.control ) -+ check for "Essential" in it -+ set the value in pkg->essential. -+ This new routine could be useful also for every other flag -+ Pigi: 16/03/2004 */ -+ set_flags_from_control(conf, pkg) ; -+ -+ ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__); -+ err = pkg_write_filelist(conf, pkg); -+ if (err) -+ return err; -+ -+ /* XXX: FEATURE: ipkg should identify any files which existed -+ before installation and which were overwritten, (see -+ check_data_file_clashes()). What it must do is remove any such -+ files from the filelist of the old package which provided the -+ file. Otherwise, if the old package were removed at some point -+ it would break the new package. Removing the new package will -+ also break the old one, but this cannot be helped since the old -+ package's file has already been deleted. This is the importance -+ of check_data_file_clashes(), and only allowing ipkg to install -+ a clashing package with a user force. */ -+ -+ return 0; -+} -+ -+static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg) -+{ -+ conffile_list_elt_t *iter; -+ conffile_t *cf; -+ char *cf_backup; -+ -+ char *md5sum; -+ -+ -+ if (conf->noaction) return 0; -+ -+ for (iter = pkg->conffiles.head; iter; iter = iter->next) { -+ char *root_filename; -+ cf = iter->data; -+ root_filename = root_filename_alloc(conf, cf->name); -+ -+ /* Might need to initialize the md5sum for each conffile */ -+ if (cf->value == NULL) { -+ cf->value = file_md5sum_alloc(root_filename); -+ } -+ -+ if (!file_exists(root_filename)) { -+ free(root_filename); -+ continue; -+ } -+ -+ cf_backup = backup_filename_alloc(root_filename); -+ -+ -+ if (file_exists(cf_backup)) { -+ /* Let's compute md5 to test if files are changed */ -+ md5sum = file_md5sum_alloc(cf_backup); -+ if (strcmp( cf->value,md5sum) != 0 ) { -+ if (conf->force_defaults -+ || user_prefers_old_conffile(cf->name, cf_backup) ) { -+ rename(cf_backup, root_filename); -+ } -+ } -+ unlink(cf_backup); -+ free(md5sum); -+ } -+ -+ free(cf_backup); -+ free(root_filename); -+ } -+ -+ return 0; -+} -+ -+static int user_prefers_old_conffile(const char *file_name, const char *backup) -+{ -+ char *response; -+ const char *short_file_name; -+ -+ short_file_name = strrchr(file_name, '/'); -+ if (short_file_name) { -+ short_file_name++; -+ } else { -+ short_file_name = file_name; -+ } -+ -+ while (1) { -+ response = get_user_response(" Configuration file '%s'\n" -+ " ==> File on system created by you or by a script.\n" -+ " ==> File also in package provided by package maintainer.\n" -+ " What would you like to do about it ? Your options are:\n" -+ " Y or I : install the package maintainer's version\n" -+ " N or O : keep your currently-installed version\n" -+ " D : show the differences between the versions (if diff is installed)\n" -+ " The default action is to keep your current version.\n" -+ " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name); -+ if (strcmp(response, "y") == 0 -+ || strcmp(response, "i") == 0 -+ || strcmp(response, "yes") == 0) { -+ free(response); -+ return 0; -+ } -+ -+ if (strcmp(response, "d") == 0) { -+ char *cmd; -+ -+ free(response); -+ /* XXX: BUG rewrite to use exec or busybox's internal diff */ -+ sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name); -+ xsystem(cmd); -+ free(cmd); -+ printf(" [Press ENTER to continue]\n"); -+ response = file_read_line_alloc(stdin); -+ free(response); -+ continue; -+ } -+ -+ free(response); -+ return 1; -+ } -+} -+ -+/* XXX: CLEANUP: I'd like to move all of the code for -+ creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then, -+ it would make sense to cleanup pkg->tmp_unpack_dir directly from -+ pkg_deinit for example). */ -+static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg) -+{ -+ DIR *tmp_dir; -+ struct dirent *dirent; -+ char *tmp_file; -+ -+#ifdef IPKG_DEBUG_NO_TMP_CLEANUP -+#error -+ ipkg_message(conf, IPKG_DEBUG, -+ "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n", -+ __FUNCTION__, pkg->tmp_unpack_dir); -+ return 0; -+#endif -+ -+ if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) { -+ tmp_dir = opendir(pkg->tmp_unpack_dir); -+ if (tmp_dir) { -+ while (1) { -+ dirent = readdir(tmp_dir); -+ if (dirent == NULL) { -+ break; -+ } -+ sprintf_alloc(&tmp_file, "%s/%s", -+ pkg->tmp_unpack_dir, dirent->d_name); -+ if (! file_is_dir(tmp_file)) { -+ unlink(tmp_file); -+ } -+ free(tmp_file); -+ } -+ closedir(tmp_dir); -+ rmdir(pkg->tmp_unpack_dir); -+ free(pkg->tmp_unpack_dir); -+ pkg->tmp_unpack_dir = NULL; -+ } -+ } -+ -+ ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n", -+ pkg->name, pkg->local_filename, conf->tmp_dir); -+ if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) { -+ unlink(pkg->local_filename); -+ free(pkg->local_filename); -+ pkg->local_filename = NULL; -+ } -+ -+ return 0; -+} -+ -+static char *backup_filename_alloc(const char *file_name) -+{ -+ char *backup; -+ -+ sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX); -+ -+ return backup; -+} -+ -+int backup_make_backup(ipkg_conf_t *conf, const char *file_name) -+{ -+ int err; -+ char *backup; -+ -+ backup = backup_filename_alloc(file_name); -+ err = file_copy(file_name, backup); -+ if (err) { -+ ipkg_message(conf, IPKG_ERROR, -+ "%s: Failed to copy %s to %s\n", -+ __FUNCTION__, file_name, backup); -+ } -+ -+ free(backup); -+ -+ return err; -+} -+ -+static int backup_exists_for(const char *file_name) -+{ -+ int ret; -+ char *backup; -+ -+ backup = backup_filename_alloc(file_name); -+ -+ ret = file_exists(backup); -+ -+ free(backup); -+ -+ return ret; -+} -+ -+static int backup_remove(const char *file_name) -+{ -+ char *backup; -+ -+ backup = backup_filename_alloc(file_name); -+ unlink(backup); -+ free(backup); -+ -+ return 0; -+} -+ -+ -+ -+#ifdef CONFIG_IPKG_PROCESS_ACTIONS -+ -+int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove) -+{ -+ /* first, remove the packages that need removing */ -+ for (i = 0 ; i < pkgs_to_remove->len; i++ ) { -+ pkg_t *pkg = pkgs_to_remove->pkgs[i]; -+ err = ipkg_remove_pkg(conf, pkg,0); -+ if (err) return err; -+ } -+ return 0; -+} -+ -+int ipkg_process_actions_sanity_check(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install) -+{ -+ int i; -+ /* now one more pass checking on the ones that need to be installed */ -+ for (i = 0 ; i < pkgs_to_install->len; i++ ) { -+ pkg_t *pkg = pkgs_to_install->pkgs[i]; -+ if (pkg->dest == NULL) -+ pkg->dest = conf->default_dest; -+ -+ pkg->state_want = SW_INSTALL; -+ -+ /* Abhaya: conflicts check */ -+ err = check_conflicts_for(conf, pkg); -+ if (err) { return err; } -+ } -+ return 0; -+} -+ -+int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install) -+{ -+ int i; -+ /* now one more pass checking on the ones that need to be installed */ -+ for (i = 0 ; i < pkgs_to_install->len; i++ ) { -+ pkg_t *pkg = pkgs_to_install->pkgs[i]; -+ -+ /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */ -+ pkg_vec_t *replacees = pkg_vec_alloc(); -+ pkg_get_installed_replacees(conf, pkg, replacees); -+ -+ /* XXX: BUG: we really should treat replacement more like an upgrade -+ * Instead, we're going to remove the replacees -+ */ -+ err = pkg_remove_installed_replacees(conf, replacees); -+ if (err) return err; -+ pkg->state_flag |= SF_REMOVED_REPLACEES; -+ } -+ return 0; -+} -+ -+int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install) -+{ -+ int i; -+ /* now one more pass checking on the ones that need to be installed */ -+ for (i = 0 ; i < pkgs_to_install->len; i++ ) { -+ pkg_t *pkg = pkgs_to_install->pkgs[i]; -+ if (pkg->local_filename == NULL) { -+ err = ipkg_download_pkg(conf, pkg, conf->tmp_dir); -+ if (err) { -+ ipkg_message(conf, IPKG_ERROR, -+ "Failed to download %s. Perhaps you need to run 'ipkg update'?\n", -+ pkg->name); -+ return err; -+ } -+ } -+ if (pkg->tmp_unpack_dir == NULL) { -+ err = unpack_pkg_control_files(conf, pkg); -+ if (err) return err; -+ } -+ } -+ return 0; -+} -+ -+int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install) -+{ -+ int i; -+ /* now one more pass checking on the ones that need to be installed */ -+ for (i = 0 ; i < pkgs_to_install->len; i++ ) { -+ pkg_t *pkg = pkgs_to_install->pkgs[i]; -+ pkg_t *old_pkg = pkg->old_pkg; -+ -+ err = prerm_upgrade_old_pkg(conf, pkg, old_pkg); -+ if (err) return err; -+ -+ err = prerm_deconfigure_conflictors(conf, pkg, replacees); -+ if (err) return err; -+ -+ err = preinst_configure(conf, pkg, old_pkg); -+ if (err) return err; -+ -+ err = backup_modified_conffiles(conf, pkg, old_pkg); -+ if (err) return err; -+ -+ err = postrm_upgrade_old_pkg(conf, pkg, old_pkg); -+ if (err) return err; -+ } -+ return 0; -+} -+ -+int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install) -+{ -+ int i; -+ /* now one more pass checking on the ones that need to be installed */ -+ for (i = 0 ; i < pkgs_to_install->len; i++ ) { -+ pkg_t *pkg = pkgs_to_install->pkgs[i]; -+ pkg_t *old_pkg = pkg->old_pkg; -+ -+ if (old_pkg) { -+ old_pkg->state_want = SW_DEINSTALL; -+ -+ if (old_pkg->state_flag & SF_NOPRUNE) { -+ ipkg_message(conf, IPKG_INFO, -+ " not removing obsolesced files because package marked noprune\n"); -+ } else { -+ ipkg_message(conf, IPKG_INFO, -+ " removing obsolesced files\n"); -+ remove_obsolesced_files(conf, pkg, old_pkg); -+ } -+ } -+ -+ ipkg_message(conf, IPKG_INFO, -+ " installing maintainer scripts\n"); -+ install_maintainer_scripts(conf, pkg, old_pkg); -+ -+ /* the following just returns 0 */ -+ remove_disappeared(conf, pkg); -+ -+ ipkg_message(conf, IPKG_INFO, -+ " installing data files\n"); -+ install_data_files(conf, pkg); -+ -+ ipkg_message(conf, IPKG_INFO, -+ " resolving conf files\n"); -+ resolve_conffiles(conf, pkg); -+ -+ pkg->state_status = SS_UNPACKED; -+ -+ if (old_pkg) { -+ old_pkg->state_status = SS_NOT_INSTALLED; -+ } -+ -+ time(&pkg->installed_time); -+ -+ ipkg_message(conf, IPKG_INFO, -+ " cleanup temp files\n"); -+ cleanup_temporary_files(conf, pkg); -+ -+ if (pkg->parent) -+ pkg->parent->state_status = pkg->state_status; -+ } -+ return 0; -+} -+ -+int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install) -+{ -+ int i; -+ /* now one more pass checking on the ones that need to be installed */ -+ for (i = 0 ; i < pkgs_to_install->len; i++ ) { -+ pkg_t *pkg = pkgs_to_install->pkgs[i]; -+ pkg_t *old_pkg = pkg->old_pkg; -+ -+ if (old_pkg) { -+ if (old_pkg->state_flags & SF_POSTRM_UPGRADE) -+ postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg); -+ if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES) -+ check_data_file_clashes_unwind(conf, pkg, old_pkg); -+ if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES) -+ backup_modified_conffiles_unwind(conf, pkg, old_pkg); -+ if (old_pkg->state_flags & SF_PREINST_CONFIGURE) -+ preinst_configure_unwind(conf, pkg, old_pkg); -+ if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS) -+ prerm_deconfigure_conflictors_unwind(conf, pkg, replacees); -+ if (old_pkg->state_flags & SF_PRERM_UPGRADE) -+ prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg); -+ -+ if (old_pkg->state_flags & SF_REMOVED_REPLACEES) -+ remove_installed_replacees_unwind(conf, pkg, old_pkg); -+ -+ } -+ } -+ return 0; -+} -+ -+/* -+ * Perform all the actions. -+ * -+ * pkgs_to_remove are packages marked for removal. -+ * pkgs_superseded are the old packages being replaced by upgrades. -+ * -+ * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order. -+ */ -+int ipkg_process_actions(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install) -+{ -+ int err; -+ int i; -+ -+ err = ipkg_remove_packages(conf, pkgs_to_remove); -+ if (err) return err; -+ -+ err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install); -+ if (err) return err; -+ -+ err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install); -+ if (err) goto UNWIND; -+ -+ /* @@@@ look at ipkg_install_pkg for handling replacements */ -+ err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install); -+ if (err) goto UNWIND; -+ -+ /* -+ * Now that we have the packages unpacked, we can look for data -+ * file clashes. First, we mark the files from the superseded -+ * packages as obsolete. Then we scan the files in -+ * pkgs_to_install, and only complain about clashes with -+ * non-obsolete files. -+ */ -+ -+ err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install); -+ if (err) goto UNWIND; -+ -+ /* this was before checking data file clashes */ -+ err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install); -+ if (err) goto UNWIND; -+ -+ /* point of no return: no unwinding after this */ -+ err = ipkg_process_actions_install(conf, pkgs_to_install); -+ if (err) return err; -+ -+ ipkg_message(conf, IPKG_INFO, "Done.\n"); -+ return 0; -+ -+ UNWIND: -+ ipkg_process_actions_unwind(conf, pkgs_to_install); -+ -+ ipkg_message(conf, IPKG_INFO, -+ " cleanup temp files\n"); -+ cleanup_temporary_files(conf, pkg); -+ -+ ipkg_message(conf, IPKG_INFO, -+ "Failed.\n"); -+ return err; -+} -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/ipkg_install.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg_install.h 2007-06-04 13:21:36.715395080 +0200 -@@ -0,0 +1,35 @@ -+/* ipkg_install.h - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef IPKG_INSTALL_H -+#define IPKG_INSTALL_H -+ -+#include "pkg.h" -+#include "ipkg_conf.h" -+ -+ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name); -+ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name); -+int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename); -+int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading); -+int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg); -+ -+int ipkg_satisfy_all_dependences(ipkg_conf_t *conf); -+ -+int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed); -+int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed); -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/ipkg_message.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg_message.c 2007-06-04 13:21:36.715395080 +0200 -@@ -0,0 +1,61 @@ -+/* ipkg_message.c - the itsy package management system -+ -+ Copyright (C) 2003 Daniele Nicolodi -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+ -+#include "ipkg.h" -+#include "ipkg_conf.h" -+#include "ipkg_message.h" -+ -+#ifndef IPKG_LIB -+ -+void -+ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...) -+{ -+ va_list ap; -+ -+ if (conf && (conf->verbosity < level)) -+ { -+ return; -+ } -+ else -+ { -+ -+ va_start (ap, fmt); -+ vprintf (fmt, ap); -+ va_end (ap); -+ } -+} -+ -+#else -+ -+#include "libipkg.h" -+ -+//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg) -+ -+void -+ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...) -+{ -+ va_list ap; -+ char ts[256]; -+ -+ if (ipkg_cb_message) -+ { -+ va_start (ap, fmt); -+ vsnprintf (ts,256,fmt, ap); -+ va_end (ap); -+ ipkg_cb_message(conf,level,ts); -+ } -+} -+#endif -Index: busybox-1.4.2/archival/libipkg/ipkg_message.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg_message.h 2007-06-04 13:21:36.715395080 +0200 -@@ -0,0 +1,32 @@ -+/* ipkg_message.h - the itsy package management system -+ -+ Copyright (C) 2003 Daniele Nicolodi -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef _IPKG_MESSAGE_H_ -+#define _IPKG_MESSAGE_H_ -+ -+#include "ipkg.h" -+#include "ipkg_conf.h" -+ -+typedef enum { -+ IPKG_ERROR, /* error conditions */ -+ IPKG_NOTICE, /* normal but significant condition */ -+ IPKG_INFO, /* informational message */ -+ IPKG_DEBUG, /* debug level message */ -+ IPKG_DEBUG2, /* more debug level message */ -+} message_level_t; -+ -+extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, char *fmt, ...); -+ -+#endif /* _IPKG_MESSAGE_H_ */ -Index: busybox-1.4.2/archival/libipkg/ipkg_remove.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg_remove.c 2007-06-04 13:21:36.716394928 +0200 -@@ -0,0 +1,383 @@ -+/* ipkg_remove.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+#include "ipkg_message.h" -+ -+#include -+ -+#include "ipkg_remove.h" -+ -+#include "file_util.h" -+#include "sprintf_alloc.h" -+#include "str_util.h" -+ -+#include "ipkg_cmd.h" -+ -+/* -+ * Returns number of the number of packages depending on the packages provided by this package. -+ * Every package implicitly provides itself. -+ */ -+int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents) -+{ -+ int nprovides = pkg->provides_count; -+ abstract_pkg_t **provides = pkg->provides; -+ int n_installed_dependents = 0; -+ int i; -+ for (i = 0; i <= nprovides; i++) { -+ abstract_pkg_t *providee = provides[i]; -+ abstract_pkg_t **dependers = providee->depended_upon_by; -+ abstract_pkg_t *dep_ab_pkg; -+ if (dependers == NULL) -+ continue; -+ while ((dep_ab_pkg = *dependers++) != NULL) { -+ if (dep_ab_pkg->state_status == SS_INSTALLED){ -+ n_installed_dependents++; -+ } -+ } -+ -+ } -+ /* if caller requested the set of installed dependents */ -+ if (pdependents) { -+ int p = 0; -+ abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *)); -+ -+ if ( dependents == NULL ){ -+ fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__); -+ return -1; -+ } -+ -+ *pdependents = dependents; -+ for (i = 0; i <= nprovides; i++) { -+ abstract_pkg_t *providee = provides[i]; -+ abstract_pkg_t **dependers = providee->depended_upon_by; -+ abstract_pkg_t *dep_ab_pkg; -+ if (dependers == NULL) -+ continue; -+ while ((dep_ab_pkg = *dependers++) != NULL) { -+ if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) { -+ dependents[p++] = dep_ab_pkg; -+ dep_ab_pkg->state_flag |= SF_MARKED; -+ } -+ } -+ } -+ dependents[p] = NULL; -+ /* now clear the marks */ -+ for (i = 0; i < p; i++) { -+ abstract_pkg_t *dep_ab_pkg = dependents[i]; -+ dep_ab_pkg->state_flag &= ~SF_MARKED; -+ } -+ } -+ return n_installed_dependents; -+} -+ -+int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents) -+{ -+ int i; -+ int a; -+ int count; -+ pkg_vec_t *dependent_pkgs = pkg_vec_alloc(); -+ abstract_pkg_t * ab_pkg; -+ -+ if((ab_pkg = pkg->parent) == NULL){ -+ fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n", -+ __FUNCTION__, pkg->name); -+ return 0; -+ } -+ -+ if (dependents == NULL) -+ return 0; -+ -+ // here i am using the dependencies_checked -+ if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package -+ return 0; // has already been encountered in the process -+ // of marking packages for removal - Karthik -+ ab_pkg->dependencies_checked = 2; -+ -+ i = 0; -+ count = 1; -+ while (dependents [i] != NULL) { -+ abstract_pkg_t *dep_ab_pkg = dependents[i]; -+ -+ if (dep_ab_pkg->dependencies_checked == 2){ -+ i++; -+ continue; -+ } -+ if (dep_ab_pkg->state_status == SS_INSTALLED) { -+ for (a = 0; a < dep_ab_pkg->pkgs->len; a++) { -+ pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a]; -+ if (dep_pkg->state_status == SS_INSTALLED) { -+ pkg_vec_insert(dependent_pkgs, dep_pkg); -+ count++; -+ } -+ } -+ } -+ i++; -+ /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs. -+ * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */ -+ } -+ -+ if (count == 1) -+ return 0; -+ -+ -+ for (i = 0; i < dependent_pkgs->len; i++) { -+ int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0); -+ if (err) -+ return err; -+ } -+ return 0; -+} -+ -+static int user_prefers_removing_dependents(ipkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents) -+{ -+ abstract_pkg_t *dep_ab_pkg; -+ ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name); -+ while ((dep_ab_pkg = *dependents++) != NULL) { -+ if (dep_ab_pkg->state_status == SS_INSTALLED) -+ ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name); -+ } -+ ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name); -+ ipkg_message(conf, IPKG_ERROR, ""); -+ ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n"); -+ ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n"); -+ ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n"); -+ ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n"); -+ ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n"); -+ return 0; -+} -+ -+int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message) -+{ -+/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove -+ thus I wan't check for essential, as I'm upgrading. -+ I hope it won't break anything :) -+*/ -+ int err; -+ abstract_pkg_t *parent_pkg = NULL; -+ -+ if (pkg->essential && !message) { -+ if (conf->force_removal_of_essential_packages) { -+ fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n" -+ "\tIf your system breaks, you get to keep both pieces\n", -+ pkg->name); -+ } else { -+ fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n" -+ "\tRemoving an essential package may lead to an unusable system, but if\n" -+ "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n" -+ "\tits will with the option: -force-removal-of-essential-packages\n", -+ pkg->name); -+ return IPKG_PKG_IS_ESSENTIAL; -+ } -+ } -+ -+ if ((parent_pkg = pkg->parent) == NULL) -+ return 0; -+ -+ /* only attempt to remove dependent installed packages if -+ * force_depends is not specified or the package is being -+ * replaced. -+ */ -+ if (!conf->force_depends -+ && !(pkg->state_flag & SF_REPLACE)) { -+ abstract_pkg_t **dependents; -+ int has_installed_dependents = -+ pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents); -+ -+ if (has_installed_dependents) { -+ /* -+ * if this package is depended up by others, then either we should -+ * not remove it or we should remove it and all of its dependents -+ */ -+ -+ if (!conf->force_removal_of_dependent_packages -+ && !user_prefers_removing_dependents(conf, parent_pkg, pkg, dependents)) { -+ return IPKG_PKG_HAS_DEPENDENTS; -+ } -+ -+ /* remove packages depending on this package - Karthik */ -+ err = ipkg_remove_dependent_pkgs (conf, pkg, dependents); -+ free(dependents); -+ if (err) return err; -+ } -+ } -+ -+ if ( message==0 ){ -+ printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name); -+ fflush(stdout); -+ } -+ pkg->state_flag |= SF_FILELIST_CHANGED; -+ -+ pkg->state_want = SW_DEINSTALL; -+ ipkg_state_changed++; -+ -+ pkg_run_script(conf, pkg, "prerm", "remove"); -+ -+ /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It -+ maintains an empty filelist rather than deleting it. That seems -+ like a big pain, and I don't see that that should make a big -+ difference, but for anyone who wants tighter compatibility, -+ feel free to fix this. */ -+ remove_data_files_and_list(conf, pkg); -+ -+ pkg_run_script(conf, pkg, "postrm", "remove"); -+ -+ remove_maintainer_scripts_except_postrm(conf, pkg); -+ -+ /* Aman Gupta - Since ipkg is made for handheld devices with limited -+ * space, it doesn't make sense to leave extra configurations, files, -+ * and maintainer scripts left around. So, we make remove like purge, -+ * and take out all the crap :) */ -+ -+ remove_postrm(conf, pkg); -+ pkg->state_status = SS_NOT_INSTALLED; -+ -+ if (parent_pkg) -+ parent_pkg->state_status = SS_NOT_INSTALLED; -+ -+ return 0; -+} -+ -+int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg) -+{ -+ ipkg_remove_pkg(conf, pkg,0); -+ return 0; -+} -+ -+int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg) -+{ -+ str_list_t installed_dirs; -+ str_list_t *installed_files; -+ str_list_elt_t *iter; -+ char *file_name; -+ conffile_t *conffile; -+ int removed_a_dir; -+ pkg_t *owner; -+ -+ str_list_init(&installed_dirs); -+ installed_files = pkg_get_installed_files(pkg); -+ -+ for (iter = installed_files->head; iter; iter = iter->next) { -+ file_name = iter->data; -+ -+ if (file_is_dir(file_name)) { -+ str_list_append(&installed_dirs, strdup(file_name)); -+ continue; -+ } -+ -+ conffile = pkg_get_conffile(pkg, file_name); -+ if (conffile) { -+ /* XXX: QUESTION: Is this right? I figure we only need to -+ save the conffile if it has been modified. Is that what -+ dpkg does? Or does dpkg preserve all conffiles? If so, -+ this seems like a better thing to do to conserve -+ space. */ -+ if (conffile_has_been_modified(conf, conffile)) { -+ printf(" not deleting modified conffile %s\n", file_name); -+ fflush(stdout); -+ continue; -+ } -+ } -+ -+ ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction); -+ if (!conf->noaction) -+ unlink(file_name); -+ } -+ -+ if (!conf->noaction) { -+ do { -+ removed_a_dir = 0; -+ for (iter = installed_dirs.head; iter; iter = iter->next) { -+ file_name = iter->data; -+ -+ if (rmdir(file_name) == 0) { -+ ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name); -+ removed_a_dir = 1; -+ str_list_remove(&installed_dirs, &iter); -+ } -+ } -+ } while (removed_a_dir); -+ } -+ -+ pkg_free_installed_files(pkg); -+ /* We have to remove the file list now, so that -+ find_pkg_owning_file does not always just report this package */ -+ pkg_remove_installed_files_list(conf, pkg); -+ -+ /* Don't print warning for dirs that are provided by other packages */ -+ for (iter = installed_dirs.head; iter; iter = iter->next) { -+ file_name = iter->data; -+ -+ owner = file_hash_get_file_owner(conf, file_name); -+ if (owner) { -+ free(iter->data); -+ iter->data = NULL; -+ str_list_remove(&installed_dirs, &iter); -+ } -+ } -+ -+ /* cleanup */ -+ for (iter = installed_dirs.head; iter; iter = iter->next) { -+ free(iter->data); -+ iter->data = NULL; -+ } -+ str_list_deinit(&installed_dirs); -+ -+ return 0; -+} -+ -+int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg) -+{ -+ int i, err; -+ char *globpattern; -+ glob_t globbuf; -+ -+ if (conf->noaction) return 0; -+ -+ sprintf_alloc(&globpattern, "%s/%s.*", -+ pkg->dest->info_dir, pkg->name); -+ err = glob(globpattern, 0, NULL, &globbuf); -+ free(globpattern); -+ if (err) { -+ return 0; -+ } -+ -+ for (i = 0; i < globbuf.gl_pathc; i++) { -+ if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) { -+ continue; -+ } -+ ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]); -+ unlink(globbuf.gl_pathv[i]); -+ } -+ globfree(&globbuf); -+ -+ return 0; -+} -+ -+int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg) -+{ -+ char *postrm_file_name; -+ -+ if (conf->noaction) return 0; -+ -+ sprintf_alloc(&postrm_file_name, "%s/%s.postrm", -+ pkg->dest->info_dir, pkg->name); -+ unlink(postrm_file_name); -+ free(postrm_file_name); -+ -+ return 0; -+} -Index: busybox-1.4.2/archival/libipkg/ipkg_remove.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg_remove.h 2007-06-04 13:21:36.716394928 +0200 -@@ -0,0 +1,33 @@ -+/* ipkg_remove.h - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef IPKG_REMOVE_H -+#define IPKG_REMOVE_H -+ -+#include "pkg.h" -+#include "ipkg_conf.h" -+ -+int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message); -+int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg); -+int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg); -+int pkg_has_installed_dependents(ipkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents); -+int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg); -+int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg); -+int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg); -+ -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/ipkg_upgrade.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg_upgrade.c 2007-06-04 13:21:36.716394928 +0200 -@@ -0,0 +1,77 @@ -+/* ipkg_upgrade.c - the itsy package management system -+ -+ Carl D. Worth -+ Copyright (C) 2001 University of Southern California -+ -+ Copyright (C) 2003 Daniele Nicolodi -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+#include "ipkg_install.h" -+#include "ipkg_message.h" -+ -+int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old) -+{ -+ pkg_t *new; -+ int cmp; -+ char *old_version, *new_version; -+ -+ if (old->state_flag & SF_HOLD) { -+ ipkg_message(conf, IPKG_NOTICE, -+ "Not upgrading package %s which is marked " -+ "hold (flags=%#x)\n", old->name, old->state_flag); -+ return 0; -+ } -+ -+ new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name); -+ if (new == NULL) { -+ old_version = pkg_version_str_alloc(old); -+ ipkg_message(conf, IPKG_NOTICE, -+ "Assuming locally installed package %s (%s) " -+ "is up to date.\n", old->name, old_version); -+ free(old_version); -+ return 0; -+ } -+ -+ old_version = pkg_version_str_alloc(old); -+ new_version = pkg_version_str_alloc(new); -+ -+ cmp = pkg_compare_versions(old, new); -+ ipkg_message(conf, IPKG_DEBUG, -+ "comparing visible versions of pkg %s:" -+ "\n\t%s is installed " -+ "\n\t%s is available " -+ "\n\t%d was comparison result\n", -+ old->name, old_version, new_version, cmp); -+ if (cmp == 0) { -+ ipkg_message(conf, IPKG_INFO, -+ "Package %s (%s) installed in %s is up to date.\n", -+ old->name, old_version, old->dest->name); -+ free(old_version); -+ free(new_version); -+ return 0; -+ } else if (cmp > 0) { -+ ipkg_message(conf, IPKG_NOTICE, -+ "Not downgrading package %s on %s from %s to %s.\n", -+ old->name, old->dest->name, old_version, new_version); -+ free(old_version); -+ free(new_version); -+ return 0; -+ } else if (cmp < 0) { -+ new->dest = old->dest; -+ old->state_want = SW_DEINSTALL; -+ } -+ -+ new->state_flag |= SF_USER; -+ return ipkg_install_pkg(conf, new,1); -+} -Index: busybox-1.4.2/archival/libipkg/ipkg_upgrade.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg_upgrade.h 2007-06-04 13:21:36.716394928 +0200 -@@ -0,0 +1,18 @@ -+/* ipkg_upgrade.c - the itsy package management system -+ -+ Copyright (C) 2003 Daniele Nicolodi -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+ -+int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old); -Index: busybox-1.4.2/archival/libipkg/ipkg_utils.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg_utils.c 2007-06-04 13:21:36.716394928 +0200 -@@ -0,0 +1,181 @@ -+/* ipkg_utils.c - the itsy package management system -+ -+ Steven M. Ayer -+ -+ Copyright (C) 2002 Compaq Computer Corporation -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+#include -+#include -+#include -+ -+#include "ipkg_utils.h" -+#include "pkg.h" -+#include "pkg_hash.h" -+ -+struct errlist* error_list; -+ -+int get_available_blocks(char * filesystem) -+{ -+ struct statfs sfs; -+ -+ if(statfs(filesystem, &sfs)){ -+ fprintf(stderr, "bad statfs\n"); -+ return 0; -+ } -+ /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */ -+ return ((sfs.f_bavail * sfs.f_bsize) / 1024); -+} -+ -+char **read_raw_pkgs_from_file(const char *file_name) -+{ -+ FILE *fp; -+ char **ret; -+ -+ if(!(fp = fopen(file_name, "r"))){ -+ fprintf(stderr, "can't get %s open for read\n", file_name); -+ return NULL; -+ } -+ -+ ret = read_raw_pkgs_from_stream(fp); -+ -+ fclose(fp); -+ -+ return ret; -+} -+ -+char **read_raw_pkgs_from_stream(FILE *fp) -+{ -+ char **raw = NULL, *buf, *scout; -+ int count = 0; -+ size_t size = 512; -+ -+ buf = malloc (size); -+ -+ while (fgets(buf, size, fp)) { -+ while (strlen (buf) == (size - 1) -+ && buf[size-2] != '\n') { -+ size_t o = size - 1; -+ size *= 2; -+ buf = realloc (buf, size); -+ if (fgets (buf + o, size - o, fp) == NULL) -+ break; -+ } -+ -+ if(!(count % 50)) -+ raw = realloc(raw, (count + 50) * sizeof(char *)); -+ -+ if((scout = strchr(buf, '\n'))) -+ *scout = '\0'; -+ -+ raw[count++] = strdup(buf); -+ } -+ -+ raw = realloc(raw, (count + 1) * sizeof(char *)); -+ raw[count] = NULL; -+ -+ free (buf); -+ -+ return raw; -+} -+ -+/* something to remove whitespace, a hash pooper */ -+char *trim_alloc(char *line) -+{ -+ char *new; -+ char *dest, *src, *end; -+ -+ new = malloc(strlen(line) + 1); -+ if ( new == NULL ){ -+ fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__); -+ return NULL; -+ } -+ dest = new, src = line, end = line + (strlen(line) - 1); -+ -+ /* remove it from the front */ -+ while(src && -+ isspace(*src) && -+ *src) -+ src++; -+ /* and now from the back */ -+ while((end > src) && -+ isspace(*end)) -+ end--; -+ end++; -+ *end = '\0'; -+ strcpy(new, src); -+ /* this does from the first space -+ * blasting away any versions stuff in depends -+ while(src && -+ !isspace(*src) && -+ *src) -+ *dest++ = *src++; -+ *dest = '\0'; -+ */ -+ -+ return new; -+} -+ -+int line_is_blank(const char *line) -+{ -+ const char *s; -+ -+ for (s = line; *s; s++) { -+ if (!isspace(*s)) -+ return 0; -+ } -+ return 1; -+} -+ -+void push_error_list(struct errlist ** errors, char * msg){ -+ struct errlist *err_lst_tmp; -+ -+ -+ err_lst_tmp = malloc ( sizeof (err_lst_tmp) ); -+ err_lst_tmp->errmsg=strdup(msg) ; -+ err_lst_tmp->next = *errors; -+ *errors = err_lst_tmp; -+} -+ -+ -+void reverse_error_list(struct errlist **errors){ -+ struct errlist *result=NULL; -+ struct errlist *current= *errors; -+ struct errlist *next; -+ -+ while ( current != NULL ) { -+ next = current->next; -+ current->next=result; -+ result=current; -+ current=next; -+ } -+ *errors=result; -+ -+} -+ -+ -+void free_error_list(struct errlist **errors){ -+ struct errlist *current = *errors; -+ -+ while (current != NULL) { -+ free(current->errmsg); -+ current = (*errors)->next; -+ free(*errors); -+ *errors = current; -+ } -+ -+ -+} -+ -+ -Index: busybox-1.4.2/archival/libipkg/ipkg_utils.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/ipkg_utils.h 2007-06-04 13:21:36.717394776 +0200 -@@ -0,0 +1,29 @@ -+/* ipkg_utils.h - the itsy package management system -+ -+ Steven M. Ayer -+ -+ Copyright (C) 2002 Compaq Computer Corporation -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef IPKG_UTILS_H -+#define IPKG_UTILS_H -+ -+#include "pkg.h" -+ -+int get_available_blocks(char * filesystem); -+char **read_raw_pkgs_from_file(const char *file_name); -+char **read_raw_pkgs_from_stream(FILE *fp); -+char *trim_alloc(char * line); -+int line_is_blank(const char *line); -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/Kbuild -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/Kbuild 2007-06-04 13:21:36.717394776 +0200 -@@ -0,0 +1,60 @@ -+# Makefile for busybox -+# -+# Copyright (C) 1999-2004 by Erik Andersen -+# Copyright (C) 2006 OpenWrt.org -+# -+# Licensed under the GPL v2 or later, see the file LICENSE in this tarball. -+ -+LIBIPKG_CORE_OBJS:= \ -+ args.o \ -+ libipkg.o \ -+ user.o \ -+ -+LIBIPKG_CMD_OBJS:= \ -+ ipkg_cmd.o \ -+ ipkg_configure.o \ -+ ipkg_download.o \ -+ ipkg_install.o \ -+ ipkg_remove.o \ -+ ipkg_upgrade.o \ -+ -+LIBIPKG_DB_OBJS:= \ -+ hash_table.o \ -+ ipkg_conf.o \ -+ ipkg_utils.o \ -+ pkg.o \ -+ pkg_depends.o \ -+ pkg_extract.o \ -+ pkg_hash.o \ -+ pkg_parse.o \ -+ pkg_vec.o \ -+ -+LIBIPKG_LIST_OBJS:= \ -+ conffile.o \ -+ conffile_list.o \ -+ nv_pair.o \ -+ nv_pair_list.o \ -+ pkg_dest.o \ -+ pkg_dest_list.o \ -+ pkg_src.o \ -+ pkg_src_list.o \ -+ str_list.o \ -+ void_list.o \ -+ -+LIBIPKG_UTIL_OBJS:= \ -+ file_util.o \ -+ ipkg_message.o \ -+ str_util.o \ -+ xsystem.o \ -+ -+lib-y := -+lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS) -+lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS) -+lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS) -+lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS) -+lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS) -+ -+ifeq ($(strip $(IPKG_ARCH)),) -+IPKG_ARCH:=$(TARGET_ARCH) -+endif -+CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\"" -Index: busybox-1.4.2/archival/libipkg/libipkg.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/libipkg.c 2007-06-04 13:21:36.717394776 +0200 -@@ -0,0 +1,527 @@ -+/* ipkglib.c - the itsy package management system -+ -+ Florina Boor -+ -+ Copyright (C) 2003 kernel concepts -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifdef IPKG_LIB -+ -+#include "ipkg.h" -+#include "ipkg_includes.h" -+#include "libipkg.h" -+ -+#include "args.h" -+#include "ipkg_conf.h" -+#include "ipkg_cmd.h" -+#include "file_util.h" -+ -+ -+ -+ipkg_message_callback ipkg_cb_message = NULL; -+ipkg_response_callback ipkg_cb_response = NULL; -+ipkg_status_callback ipkg_cb_status = NULL; -+ipkg_list_callback ipkg_cb_list = NULL; -+ -+ -+int -+ipkg_init (ipkg_message_callback mcall, -+ ipkg_response_callback rcall, -+ args_t * args) -+{ -+ ipkg_cb_message = mcall; -+ ipkg_cb_response = rcall; -+ -+ args_init (args); -+ -+ return 0; -+} -+ -+ -+int -+ipkg_deinit (args_t * args) -+{ -+ args_deinit (args); -+ ipkg_cb_message = NULL; -+ ipkg_cb_response = NULL; -+ -+ /* place other cleanup stuff here */ -+ -+ return 0; -+} -+ -+ -+int -+ipkg_packages_list(args_t *args, -+ const char *packages, -+ ipkg_list_callback cblist, -+ void *userdata) -+{ -+ ipkg_cmd_t *cmd; -+ ipkg_conf_t ipkg_conf; -+ int err; -+ -+ err = ipkg_conf_init (&ipkg_conf, args); -+ if (err) -+ { -+ return err; -+ } -+ -+ ipkg_cb_list = cblist; -+ /* we need to do this because of static declarations, -+ * maybe a good idea to change */ -+ cmd = ipkg_cmd_find ("list"); -+ if (packages) -+ err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata); -+ else -+ err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata); -+ ipkg_cb_list = NULL; -+ ipkg_conf_deinit (&ipkg_conf); -+ return (err); -+} -+ -+ -+int -+ipkg_packages_status(args_t *args, -+ const char *packages, -+ ipkg_status_callback cbstatus, -+ void *userdata) -+{ -+ ipkg_cmd_t *cmd; -+ ipkg_conf_t ipkg_conf; -+ int err; -+ -+ err = ipkg_conf_init (&ipkg_conf, args); -+ if (err) -+ { -+ return err; -+ } -+ -+ ipkg_cb_status = cbstatus; -+ -+ /* we need to do this because of static declarations, -+ * maybe a good idea to change */ -+ cmd = ipkg_cmd_find ("status"); -+ if (packages) -+ err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata); -+ else -+ err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata); -+ -+ ipkg_cb_status = NULL; -+ ipkg_conf_deinit (&ipkg_conf); -+ return (err); -+} -+ -+ -+int -+ipkg_packages_info(args_t *args, -+ const char *packages, -+ ipkg_status_callback cbstatus, -+ void *userdata) -+{ -+ ipkg_cmd_t *cmd; -+ ipkg_conf_t ipkg_conf; -+ int err; -+ -+ err = ipkg_conf_init (&ipkg_conf, args); -+ if (err) -+ { -+ return err; -+ } -+ -+ ipkg_cb_status = cbstatus; -+ -+ /* we need to do this because of static declarations, -+ * maybe a good idea to change */ -+ cmd = ipkg_cmd_find ("info"); -+ if (packages) -+ err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata); -+ else -+ err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata); -+ -+ ipkg_cb_status = NULL; -+ ipkg_conf_deinit (&ipkg_conf); -+ return (err); -+} -+ -+ -+int -+ipkg_packages_install (args_t * args, const char *name) -+{ -+ ipkg_cmd_t *cmd; -+ ipkg_conf_t ipkg_conf; -+ int err; -+ -+ /* this error should be handled in application */ -+ if (!name || !strlen (name)) -+ return (-1); -+ -+ err = ipkg_conf_init (&ipkg_conf, args); -+ if (err) -+ { -+ return err; -+ } -+ -+ /* we need to do this because of static declarations, -+ * maybe a good idea to change */ -+ cmd = ipkg_cmd_find ("install"); -+ err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL); -+ -+ ipkg_conf_deinit(&ipkg_conf); -+ return (err); -+} -+ -+ -+int -+ipkg_packages_remove(args_t *args, const char *name, int purge) -+{ -+ ipkg_cmd_t *cmd; -+ ipkg_conf_t ipkg_conf; -+ int err; -+ -+ /* this error should be handled in application */ -+ if (!name || !strlen (name)) -+ return (-1); -+ -+ err = ipkg_conf_init (&ipkg_conf, args); -+ if (err) -+ { -+ return err; -+ } -+ -+ /* we need to do this because of static declarations, -+ * maybe a good idea to change */ -+ if (purge) -+ cmd = ipkg_cmd_find ("purge"); -+ else -+ cmd = ipkg_cmd_find ("remove"); -+ -+ err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL); -+ -+ ipkg_conf_deinit(&ipkg_conf); -+ return (err); -+} -+ -+ -+int -+ipkg_lists_update(args_t *args) -+{ -+ ipkg_cmd_t *cmd; -+ ipkg_conf_t ipkg_conf; -+ int err; -+ -+ err = ipkg_conf_init (&ipkg_conf, args); -+ if (err) -+ { -+ return err; -+ } -+ -+ /* we need to do this because of static declarations, -+ * maybe a good idea to change */ -+ cmd = ipkg_cmd_find ("update"); -+ -+ err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL); -+ -+ ipkg_conf_deinit(&ipkg_conf); -+ return (err); -+} -+ -+ -+int -+ipkg_packages_upgrade(args_t *args) -+{ -+ ipkg_cmd_t *cmd; -+ ipkg_conf_t ipkg_conf; -+ int err; -+ -+ err = ipkg_conf_init (&ipkg_conf, args); -+ if (err) -+ { -+ return err; -+ } -+ -+ /* we need to do this because of static declarations, -+ * maybe a good idea to change */ -+ cmd = ipkg_cmd_find ("upgrade"); -+ -+ err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL); -+ -+ ipkg_conf_deinit(&ipkg_conf); -+ return (err); -+} -+ -+ -+int -+ipkg_packages_download (args_t * args, const char *name) -+{ -+ ipkg_cmd_t *cmd; -+ ipkg_conf_t ipkg_conf; -+ int err; -+ -+ /* this error should be handled in application */ -+ if (!name || !strlen (name)) -+ return (-1); -+ -+ err = ipkg_conf_init (&ipkg_conf, args); -+ if (err) -+ { -+ return err; -+ } -+ -+ /* we need to do this because of static declarations, -+ * maybe a good idea to change */ -+ cmd = ipkg_cmd_find ("download"); -+ err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL); -+ -+ ipkg_conf_deinit(&ipkg_conf); -+ return (err); -+} -+ -+ -+int -+ipkg_package_files(args_t *args, -+ const char *name, -+ ipkg_list_callback cblist, -+ void *userdata) -+{ -+ ipkg_cmd_t *cmd; -+ ipkg_conf_t ipkg_conf; -+ int err; -+ -+ /* this error should be handled in application */ -+ if (!name || !strlen (name)) -+ return (-1); -+ -+ err = ipkg_conf_init (&ipkg_conf, args); -+ if (err) -+ { -+ return err; -+ } -+ -+ ipkg_cb_list = cblist; -+ -+ /* we need to do this because of static declarations, -+ * maybe a good idea to change */ -+ cmd = ipkg_cmd_find ("files"); -+ -+ err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata); -+ -+ ipkg_cb_list = NULL; -+ ipkg_conf_deinit(&ipkg_conf); -+ return (err); -+} -+ -+ -+int -+ipkg_file_search(args_t *args, -+ const char *file, -+ ipkg_list_callback cblist, -+ void *userdata) -+{ -+ ipkg_cmd_t *cmd; -+ ipkg_conf_t ipkg_conf; -+ int err; -+ -+ /* this error should be handled in application */ -+ if (!file || !strlen (file)) -+ return (-1); -+ -+ err = ipkg_conf_init (&ipkg_conf, args); -+ if (err) -+ { -+ return err; -+ } -+ -+ ipkg_cb_list = cblist; -+ -+ /* we need to do this because of static declarations, -+ * maybe a good idea to change */ -+ cmd = ipkg_cmd_find ("search"); -+ err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata); -+ -+ ipkg_cb_list = NULL; -+ ipkg_conf_deinit(&ipkg_conf); -+ return(err); -+} -+ -+ -+int -+ipkg_file_what(args_t *args, const char *file, const char* command) -+{ -+ ipkg_cmd_t *cmd; -+ ipkg_conf_t ipkg_conf; -+ int err; -+ -+ /* this error should be handled in application */ -+ if (!file || !strlen (file)) -+ return (-1); -+ -+ err = ipkg_conf_init (&ipkg_conf, args); -+ if (err) -+ { -+ return err; -+ } -+ -+ /* we need to do this because of static declarations, -+ * maybe a good idea to change */ -+ cmd = ipkg_cmd_find (command); -+ err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL); -+ -+ ipkg_conf_deinit(&ipkg_conf); -+ return(err); -+} -+ -+#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends") -+#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends") -+#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides") -+#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts") -+#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces") -+ -+ -+int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level, -+ char *msg) -+{ -+ if (conf && (conf->verbosity < level)) { -+ return 0; -+ } else { -+#ifdef IPKG_LIB -+ if ( level == IPKG_ERROR ){ -+ push_error_list(&error_list, msg); -+// printf(msg); -+ } else -+#endif -+ printf(msg); -+ } -+ return 0; -+} -+ -+int default_ipkg_list_callback(char *name, char *desc, char *version, -+ pkg_state_status_t status, void *userdata) -+{ -+ if (desc) -+ printf("%s - %s - %s\n", name, version, desc); -+ else -+ printf("%s - %s\n", name, version); -+ return 0; -+} -+ -+int default_ipkg_files_callback(char *name, char *desc, char *version, -+ pkg_state_status_t status, void *userdata) -+{ -+ if (desc) -+ printf("%s\n", desc); -+ return 0; -+} -+ -+int default_ipkg_status_callback(char *name, int istatus, char *desc, -+ void *userdata) -+{ -+ printf("%s\n", desc); -+ return 0; -+} -+ -+char* default_ipkg_response_callback(char *question) -+{ -+ char *response = NULL; -+ printf(question); -+ fflush(stdout); -+ do { -+ response = (char *)file_read_line_alloc(stdin); -+ } while (response == NULL); -+ return response; -+} -+ -+/* This is used for backward compatibility */ -+int -+ipkg_op (int argc, char *argv[]) -+{ -+ int err, opt_index; -+ args_t args; -+ char *cmd_name; -+ ipkg_cmd_t *cmd; -+ ipkg_conf_t ipkg_conf; -+ -+ args_init (&args); -+ -+ opt_index = args_parse (&args, argc, argv); -+ if (opt_index == argc || opt_index < 0) -+ { -+ args_usage ("ipkg must have one sub-command argument"); -+ } -+ -+ cmd_name = argv[opt_index++]; -+/* Pigi: added a flag to disable the checking of structures if the command does not need to -+ read anything from there. -+*/ -+ if ( !strcmp(cmd_name,"print-architecture") || -+ !strcmp(cmd_name,"print_architecture") || -+ !strcmp(cmd_name,"print-installation-architecture") || -+ !strcmp(cmd_name,"print_installation_architecture") ) -+ args.nocheckfordirorfile = 1; -+ -+/* Pigi: added a flag to disable the reading of feed files if the command does not need to -+ read anything from there. -+*/ -+ if ( !strcmp(cmd_name,"flag") || -+ !strcmp(cmd_name,"configure") || -+ !strcmp(cmd_name,"remove") || -+ !strcmp(cmd_name,"files") || -+ !strcmp(cmd_name,"search") || -+ !strcmp(cmd_name,"compare_versions") || -+ !strcmp(cmd_name,"compare-versions") || -+ !strcmp(cmd_name,"list_installed") || -+ !strcmp(cmd_name,"list-installed") || -+ !strcmp(cmd_name,"status") ) -+ args.noreadfeedsfile = 1; -+ -+ -+ err = ipkg_conf_init (&ipkg_conf, &args); -+ if (err) -+ { -+ return err; -+ } -+ -+ args_deinit (&args); -+ -+ ipkg_cb_message = default_ipkg_message_callback; -+ ipkg_cb_response = default_ipkg_response_callback; -+ ipkg_cb_status = default_ipkg_status_callback; -+ if ( strcmp(cmd_name, "files")==0) -+ ipkg_cb_list = default_ipkg_files_callback; -+ else -+ ipkg_cb_list = default_ipkg_list_callback; -+ -+ cmd = ipkg_cmd_find (cmd_name); -+ if (cmd == NULL) -+ { -+ fprintf (stderr, "%s: unknown sub-command %s\n", argv[0], -+ cmd_name); -+ args_usage (NULL); -+ } -+ -+ if (cmd->requires_args && opt_index == argc) -+ { -+ fprintf (stderr, -+ "%s: the ``%s'' command requires at least one argument\n", -+ __FUNCTION__, cmd_name); -+ args_usage (NULL); -+ } -+ -+ err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - opt_index, (const char **) (argv + opt_index), NULL); -+ -+ ipkg_conf_deinit (&ipkg_conf); -+ -+ return err; -+} -+ -+#endif /* IPKG_LIB */ -Index: busybox-1.4.2/archival/libipkg/libipkg.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/libipkg.h 2007-06-04 13:21:36.718394624 +0200 -@@ -0,0 +1,87 @@ -+/* ipkglib.h - the itsy package management system -+ -+ Florian Boor -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef IPKGLIB_H -+#define IPKGLIB_H -+ -+#ifdef IPKG_LIB -+ -+#include "ipkg_conf.h" -+#include "ipkg_message.h" -+ -+#include "args.h" -+#include "pkg.h" -+ -+typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level, -+ char *msg); -+typedef int (*ipkg_list_callback)(char *name, char *desc, char *version, -+ pkg_state_status_t status, void *userdata); -+typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc, -+ void *userdata); -+typedef char* (*ipkg_response_callback)(char *question); -+ -+extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */ -+extern int ipkg_init (ipkg_message_callback mcall, -+ ipkg_response_callback rcall, -+ args_t * args); -+ -+extern int ipkg_deinit (args_t *args); -+extern int ipkg_packages_list(args_t *args, -+ const char *packages, -+ ipkg_list_callback cblist, -+ void *userdata); -+extern int ipkg_packages_status(args_t *args, -+ const char *packages, -+ ipkg_status_callback cbstatus, -+ void *userdata); -+extern int ipkg_packages_info(args_t *args, -+ const char *packages, -+ ipkg_status_callback cbstatus, -+ void *userdata); -+extern int ipkg_packages_install(args_t *args, const char *name); -+extern int ipkg_packages_remove(args_t *args, const char *name, int purge); -+extern int ipkg_lists_update(args_t *args); -+extern int ipkg_packages_upgrade(args_t *args); -+extern int ipkg_packages_download(args_t *args, const char *name); -+extern int ipkg_package_files(args_t *args, -+ const char *name, -+ ipkg_list_callback cblist, -+ void *userdata); -+extern int ipkg_file_search(args_t *args, -+ const char *file, -+ ipkg_list_callback cblist, -+ void *userdata); -+extern int ipkg_package_whatdepends(args_t *args, const char *file); -+extern int ipkg_package_whatrecommends(args_t *args, const char *file); -+extern int ipkg_package_whatprovides(args_t *args, const char *file); -+extern int ipkg_package_whatconflicts(args_t *args, const char *file); -+extern int ipkg_package_whatreplaces(args_t *args, const char *file); -+ -+extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */ -+extern ipkg_response_callback ipkg_cb_response; -+extern ipkg_status_callback ipkg_cb_status; -+extern ipkg_list_callback ipkg_cb_list; -+extern void push_error_list(struct errlist **errors,char * msg); -+extern void reverse_error_list(struct errlist **errors); -+extern void free_error_list(struct errlist **errors); -+ -+#else -+ -+extern int ipkg_op(int argc, char *argv[]); -+ -+#endif -+ -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/nv_pair.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/nv_pair.c 2007-06-04 13:21:36.718394624 +0200 -@@ -0,0 +1,40 @@ -+/* nv_pair.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+ -+#include "nv_pair.h" -+#include "str_util.h" -+ -+int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value) -+{ -+ nv_pair->name = str_dup_safe(name); -+ nv_pair->value = str_dup_safe(value); -+ -+ return 0; -+} -+ -+void nv_pair_deinit(nv_pair_t *nv_pair) -+{ -+ free(nv_pair->name); -+ nv_pair->name = NULL; -+ -+ free(nv_pair->value); -+ nv_pair->value = NULL; -+} -+ -+ -Index: busybox-1.4.2/archival/libipkg/nv_pair.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/nv_pair.h 2007-06-04 13:21:36.718394624 +0200 -@@ -0,0 +1,32 @@ -+/* nv_pair.h - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef NV_PAIR_H -+#define NV_PAIR_H -+ -+typedef struct nv_pair nv_pair_t; -+struct nv_pair -+{ -+ char *name; -+ char *value; -+}; -+ -+int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value); -+void nv_pair_deinit(nv_pair_t *nv_pair); -+ -+#endif -+ -Index: busybox-1.4.2/archival/libipkg/nv_pair_list.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/nv_pair_list.c 2007-06-04 13:21:36.718394624 +0200 -@@ -0,0 +1,98 @@ -+/* nv_pair_list.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+ -+#include "nv_pair.h" -+#include "void_list.h" -+#include "nv_pair_list.h" -+ -+int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data) -+{ -+ return void_list_elt_init((void_list_elt_t *) elt, data); -+} -+ -+void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt) -+{ -+ void_list_elt_deinit((void_list_elt_t *) elt); -+} -+ -+int nv_pair_list_init(nv_pair_list_t *list) -+{ -+ return void_list_init((void_list_t *) list); -+} -+ -+void nv_pair_list_deinit(nv_pair_list_t *list) -+{ -+ nv_pair_list_elt_t *iter; -+ nv_pair_t *nv_pair; -+ -+ for (iter = list->head; iter; iter = iter->next) { -+ nv_pair = iter->data; -+ nv_pair_deinit(nv_pair); -+ -+ /* malloced in nv_pair_list_append */ -+ free(nv_pair); -+ iter->data = NULL; -+ } -+ void_list_deinit((void_list_t *) list); -+} -+ -+nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value) -+{ -+ int err; -+ -+ /* freed in nv_pair_list_deinit */ -+ nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t)); -+ -+ if (nv_pair == NULL) { -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ nv_pair_init(nv_pair, name, value); -+ -+ err = void_list_append((void_list_t *) list, nv_pair); -+ if (err) { -+ return NULL; -+ } -+ -+ return nv_pair; -+} -+ -+int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data) -+{ -+ return void_list_push((void_list_t *) list, data); -+} -+ -+nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list) -+{ -+ return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list); -+} -+ -+char *nv_pair_list_find(nv_pair_list_t *list, char *name) -+{ -+ nv_pair_list_elt_t *iter; -+ nv_pair_t *nv_pair; -+ -+ for (iter = list->head; iter; iter = iter->next) { -+ nv_pair = iter->data; -+ if (strcmp(nv_pair->name, name) == 0) { -+ return nv_pair->value; -+ } -+ } -+ return NULL; -+} -Index: busybox-1.4.2/archival/libipkg/nv_pair_list.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/nv_pair_list.h 2007-06-04 13:21:36.718394624 +0200 -@@ -0,0 +1,60 @@ -+/* nv_pair_list.h - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef NV_PAIR_LIST_H -+#define NV_PAIR_LIST_H -+ -+#include "nv_pair.h" -+#include "void_list.h" -+ -+typedef struct nv_pair_list_elt nv_pair_list_elt_t; -+struct nv_pair_list_elt -+{ -+ nv_pair_list_elt_t *next; -+ nv_pair_t *data; -+}; -+ -+typedef struct nv_pair_list nv_pair_list_t; -+struct nv_pair_list -+{ -+ nv_pair_list_elt_t pre_head; -+ nv_pair_list_elt_t *head; -+ nv_pair_list_elt_t *tail; -+}; -+ -+static inline int nv_pair_list_empty(nv_pair_list_t *list) -+{ -+ if (list->head == NULL) -+ return 1; -+ else -+ return 0; -+} -+ -+int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data); -+void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt); -+ -+int nv_pair_list_init(nv_pair_list_t *list); -+void nv_pair_list_deinit(nv_pair_list_t *list); -+ -+nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, -+ const char *name, const char *value); -+int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data); -+nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list); -+char *nv_pair_list_find(nv_pair_list_t *list, char *name); -+ -+#endif -+ -Index: busybox-1.4.2/archival/libipkg/pkg.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg.c 2007-06-04 13:21:36.720394320 +0200 -@@ -0,0 +1,1747 @@ -+/* pkg.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+#include -+#include -+#include -+ -+#include "pkg.h" -+ -+#include "pkg_parse.h" -+#include "pkg_extract.h" -+#include "ipkg_message.h" -+#include "ipkg_utils.h" -+ -+#include "sprintf_alloc.h" -+#include "file_util.h" -+#include "str_util.h" -+#include "xsystem.h" -+#include "ipkg_conf.h" -+ -+typedef struct enum_map enum_map_t; -+struct enum_map -+{ -+ int value; -+ char *str; -+}; -+ -+static const enum_map_t pkg_state_want_map[] = { -+ { SW_UNKNOWN, "unknown"}, -+ { SW_INSTALL, "install"}, -+ { SW_DEINSTALL, "deinstall"}, -+ { SW_PURGE, "purge"} -+}; -+ -+static const enum_map_t pkg_state_flag_map[] = { -+ { SF_OK, "ok"}, -+ { SF_REINSTREQ, "reinstreq"}, -+ { SF_HOLD, "hold"}, -+ { SF_REPLACE, "replace"}, -+ { SF_NOPRUNE, "noprune"}, -+ { SF_PREFER, "prefer"}, -+ { SF_OBSOLETE, "obsolete"}, -+ { SF_USER, "user"}, -+}; -+ -+static const enum_map_t pkg_state_status_map[] = { -+ { SS_NOT_INSTALLED, "not-installed" }, -+ { SS_UNPACKED, "unpacked" }, -+ { SS_HALF_CONFIGURED, "half-configured" }, -+ { SS_INSTALLED, "installed" }, -+ { SS_HALF_INSTALLED, "half-installed" }, -+ { SS_CONFIG_FILES, "config-files" }, -+ { SS_POST_INST_FAILED, "post-inst-failed" }, -+ { SS_REMOVAL_FAILED, "removal-failed" } -+}; -+ -+static int verrevcmp(const char *val, const char *ref); -+ -+ -+pkg_t *pkg_new(void) -+{ -+ pkg_t *pkg; -+ -+ pkg = malloc(sizeof(pkg_t)); -+ if (pkg == NULL) { -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ -+ pkg_init(pkg); -+ -+ return pkg; -+} -+ -+int pkg_init(pkg_t *pkg) -+{ -+ memset(pkg, 0, sizeof(pkg_t)); -+ pkg->name = NULL; -+ pkg->epoch = 0; -+ pkg->version = NULL; -+ pkg->revision = NULL; -+ pkg->familiar_revision = NULL; -+ pkg->dest = NULL; -+ pkg->src = NULL; -+ pkg->architecture = NULL; -+ pkg->maintainer = NULL; -+ pkg->section = NULL; -+ pkg->description = NULL; -+ pkg->state_want = SW_UNKNOWN; -+ pkg->state_flag = SF_OK; -+ pkg->state_status = SS_NOT_INSTALLED; -+ pkg->depends_str = NULL; -+ pkg->provides_str = NULL; -+ pkg->depends_count = 0; -+ pkg->depends = NULL; -+ pkg->suggests_str = NULL; -+ pkg->recommends_str = NULL; -+ pkg->suggests_count = 0; -+ pkg->recommends_count = 0; -+ -+ /* Abhaya: added init for conflicts fields */ -+ pkg->conflicts = NULL; -+ pkg->conflicts_count = 0; -+ -+ /* added for replaces. Jamey 7/23/2002 */ -+ pkg->replaces = NULL; -+ pkg->replaces_count = 0; -+ -+ pkg->pre_depends_count = 0; -+ pkg->pre_depends_str = NULL; -+ pkg->provides_count = 0; -+ pkg->provides = NULL; -+ pkg->filename = NULL; -+ pkg->local_filename = NULL; -+ pkg->tmp_unpack_dir = NULL; -+ pkg->md5sum = NULL; -+ pkg->size = NULL; -+ pkg->installed_size = NULL; -+ pkg->priority = NULL; -+ pkg->source = NULL; -+ conffile_list_init(&pkg->conffiles); -+ pkg->installed_files = NULL; -+ pkg->installed_files_ref_cnt = 0; -+ pkg->essential = 0; -+ pkg->provided_by_hand = 0; -+ -+ return 0; -+} -+ -+void pkg_deinit(pkg_t *pkg) -+{ -+ free(pkg->name); -+ pkg->name = NULL; -+ pkg->epoch = 0; -+ free(pkg->version); -+ pkg->version = NULL; -+ /* revision and familiar_revision share storage with version, so -+ don't free */ -+ pkg->revision = NULL; -+ pkg->familiar_revision = NULL; -+ /* owned by ipkg_conf_t */ -+ pkg->dest = NULL; -+ /* owned by ipkg_conf_t */ -+ pkg->src = NULL; -+ free(pkg->architecture); -+ pkg->architecture = NULL; -+ free(pkg->maintainer); -+ pkg->maintainer = NULL; -+ free(pkg->section); -+ pkg->section = NULL; -+ free(pkg->description); -+ pkg->description = NULL; -+ pkg->state_want = SW_UNKNOWN; -+ pkg->state_flag = SF_OK; -+ pkg->state_status = SS_NOT_INSTALLED; -+ free(pkg->depends_str); -+ pkg->depends_str = NULL; -+ free(pkg->provides_str); -+ pkg->provides_str = NULL; -+ pkg->depends_count = 0; -+ /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */ -+ pkg->pre_depends_count = 0; -+ free(pkg->pre_depends_str); -+ pkg->pre_depends_str = NULL; -+ pkg->provides_count = 0; -+ /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */ -+ /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */ -+ free(pkg->filename); -+ pkg->filename = NULL; -+ free(pkg->local_filename); -+ pkg->local_filename = NULL; -+ /* CLEANUP: It'd be nice to pullin the cleanup function from -+ ipkg_install.c here. See comment in -+ ipkg_install.c:cleanup_temporary_files */ -+ free(pkg->tmp_unpack_dir); -+ pkg->tmp_unpack_dir = NULL; -+ free(pkg->md5sum); -+ pkg->md5sum = NULL; -+ free(pkg->size); -+ pkg->size = NULL; -+ free(pkg->installed_size); -+ pkg->installed_size = NULL; -+ free(pkg->priority); -+ pkg->priority = NULL; -+ free(pkg->source); -+ pkg->source = NULL; -+ conffile_list_deinit(&pkg->conffiles); -+ /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so, -+ since if they are calling deinit, they should know. Maybe do an -+ assertion here instead? */ -+ pkg->installed_files_ref_cnt = 1; -+ pkg_free_installed_files(pkg); -+ pkg->essential = 0; -+} -+ -+int pkg_init_from_file(pkg_t *pkg, const char *filename) -+{ -+ int err; -+ char **raw; -+ FILE *control_file; -+ -+ err = pkg_init(pkg); -+ if (err) { return err; } -+ -+ pkg->local_filename = strdup(filename); -+ -+ control_file = tmpfile(); -+ err = pkg_extract_control_file_to_stream(pkg, control_file); -+ if (err) { return err; } -+ -+ rewind(control_file); -+ raw = read_raw_pkgs_from_stream(control_file); -+ pkg_parse_raw(pkg, &raw, NULL, NULL); -+ -+ fclose(control_file); -+ -+ return 0; -+} -+ -+/* Merge any new information in newpkg into oldpkg */ -+/* XXX: CLEANUP: This function shouldn't actually modify anything in -+ newpkg, but should leave it usable. This rework is so that -+ pkg_hash_insert doesn't clobber the pkg that you pass into it. */ -+/* -+ * uh, i thought that i had originally written this so that it took -+ * two pkgs and returned a new one? we can do that again... -sma -+ */ -+int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status) -+{ -+ if (oldpkg == newpkg) { -+ return 0; -+ } -+ -+ if (!oldpkg->src) -+ oldpkg->src = newpkg->src; -+ if (!oldpkg->dest) -+ oldpkg->dest = newpkg->dest; -+ if (!oldpkg->architecture) -+ oldpkg->architecture = str_dup_safe(newpkg->architecture); -+ if (!oldpkg->arch_priority) -+ oldpkg->arch_priority = newpkg->arch_priority; -+ if (!oldpkg->section) -+ oldpkg->section = str_dup_safe(newpkg->section); -+ if(!oldpkg->maintainer) -+ oldpkg->maintainer = str_dup_safe(newpkg->maintainer); -+ if(!oldpkg->description) -+ oldpkg->description = str_dup_safe(newpkg->description); -+ if (set_status) { -+ /* merge the state_flags from the new package */ -+ oldpkg->state_want = newpkg->state_want; -+ oldpkg->state_status = newpkg->state_status; -+ oldpkg->state_flag = newpkg->state_flag; -+ } else { -+ if (oldpkg->state_want == SW_UNKNOWN) -+ oldpkg->state_want = newpkg->state_want; -+ if (oldpkg->state_status == SS_NOT_INSTALLED) -+ oldpkg->state_status = newpkg->state_status; -+ oldpkg->state_flag |= newpkg->state_flag; -+ } -+ -+ if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) { -+ oldpkg->depends_str = newpkg->depends_str; -+ newpkg->depends_str = NULL; -+ oldpkg->depends_count = newpkg->depends_count; -+ newpkg->depends_count = 0; -+ -+ oldpkg->depends = newpkg->depends; -+ newpkg->depends = NULL; -+ -+ oldpkg->pre_depends_str = newpkg->pre_depends_str; -+ newpkg->pre_depends_str = NULL; -+ oldpkg->pre_depends_count = newpkg->pre_depends_count; -+ newpkg->pre_depends_count = 0; -+ -+ oldpkg->recommends_str = newpkg->recommends_str; -+ newpkg->recommends_str = NULL; -+ oldpkg->recommends_count = newpkg->recommends_count; -+ newpkg->recommends_count = 0; -+ -+ oldpkg->suggests_str = newpkg->suggests_str; -+ newpkg->suggests_str = NULL; -+ oldpkg->suggests_count = newpkg->suggests_count; -+ newpkg->suggests_count = 0; -+ } -+ -+ if (!oldpkg->provides_str) { -+ oldpkg->provides_str = newpkg->provides_str; -+ newpkg->provides_str = NULL; -+ oldpkg->provides_count = newpkg->provides_count; -+ newpkg->provides_count = 0; -+ -+ oldpkg->provides = newpkg->provides; -+ newpkg->provides = NULL; -+ } -+ -+ if (!oldpkg->conflicts_str) { -+ oldpkg->conflicts_str = newpkg->conflicts_str; -+ newpkg->conflicts_str = NULL; -+ oldpkg->conflicts_count = newpkg->conflicts_count; -+ newpkg->conflicts_count = 0; -+ -+ oldpkg->conflicts = newpkg->conflicts; -+ newpkg->conflicts = NULL; -+ } -+ -+ if (!oldpkg->replaces_str) { -+ oldpkg->replaces_str = newpkg->replaces_str; -+ newpkg->replaces_str = NULL; -+ oldpkg->replaces_count = newpkg->replaces_count; -+ newpkg->replaces_count = 0; -+ -+ oldpkg->replaces = newpkg->replaces; -+ newpkg->replaces = NULL; -+ } -+ -+ if (!oldpkg->filename) -+ oldpkg->filename = str_dup_safe(newpkg->filename); -+ if (0) -+ fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n", -+ oldpkg->name, oldpkg->local_filename, newpkg->local_filename); -+ if (!oldpkg->local_filename) -+ oldpkg->local_filename = str_dup_safe(newpkg->local_filename); -+ if (!oldpkg->tmp_unpack_dir) -+ oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir); -+ if (!oldpkg->md5sum) -+ oldpkg->md5sum = str_dup_safe(newpkg->md5sum); -+ if (!oldpkg->size) -+ oldpkg->size = str_dup_safe(newpkg->size); -+ if (!oldpkg->installed_size) -+ oldpkg->installed_size = str_dup_safe(newpkg->installed_size); -+ if (!oldpkg->priority) -+ oldpkg->priority = str_dup_safe(newpkg->priority); -+ if (!oldpkg->source) -+ oldpkg->source = str_dup_safe(newpkg->source); -+ if (oldpkg->conffiles.head == NULL){ -+ oldpkg->conffiles = newpkg->conffiles; -+ conffile_list_init(&newpkg->conffiles); -+ } -+ if (!oldpkg->installed_files){ -+ oldpkg->installed_files = newpkg->installed_files; -+ oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt; -+ newpkg->installed_files = NULL; -+ } -+ if (!oldpkg->essential) -+ oldpkg->essential = newpkg->essential; -+ -+ oldpkg->provided_by_hand |= newpkg->provided_by_hand; -+ -+ return 0; -+} -+ -+abstract_pkg_t *abstract_pkg_new(void) -+{ -+ abstract_pkg_t * ab_pkg; -+ -+ ab_pkg = malloc(sizeof(abstract_pkg_t)); -+ -+ if (ab_pkg == NULL) { -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ -+ if ( abstract_pkg_init(ab_pkg) < 0 ) -+ return NULL; -+ -+ return ab_pkg; -+} -+ -+int abstract_pkg_init(abstract_pkg_t *ab_pkg) -+{ -+ memset(ab_pkg, 0, sizeof(abstract_pkg_t)); -+ -+ ab_pkg->provided_by = abstract_pkg_vec_alloc(); -+ if (ab_pkg->provided_by==NULL){ -+ return -1; -+ } -+ ab_pkg->dependencies_checked = 0; -+ ab_pkg->state_status = SS_NOT_INSTALLED; -+ -+ return 0; -+} -+ -+void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){ -+ char * temp_str; -+ char **raw =NULL; -+ char **raw_start=NULL; -+ -+ temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12); -+ if (temp_str == NULL ){ -+ ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__); -+ return; -+ } -+ sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name); -+ -+ raw = raw_start = read_raw_pkgs_from_file(temp_str); -+ if (raw == NULL ){ -+ ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__); -+ return; -+ } -+ -+ while(*raw){ -+ if (!pkg_valorize_other_field(pkg, &raw ) == 0) { -+ ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name); -+ } -+ } -+ raw = raw_start; -+ while (*raw) { -+ if (raw!=NULL) -+ free(*raw++); -+ } -+ -+ free(raw_start); -+ free(temp_str); -+ -+ return ; -+ -+} -+ -+char * pkg_formatted_info(pkg_t *pkg ) -+{ -+ char *line; -+ char * buff; -+ -+ buff = malloc(8192); -+ if (buff == NULL) { -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ -+ buff[0] = '\0'; -+ -+ line = pkg_formatted_field(pkg, "Package"); -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ line = pkg_formatted_field(pkg, "Version"); -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ line = pkg_formatted_field(pkg, "Depends"); -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ line = pkg_formatted_field(pkg, "Recommends"); -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ line = pkg_formatted_field(pkg, "Suggests"); -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ line = pkg_formatted_field(pkg, "Provides"); -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ line = pkg_formatted_field(pkg, "Replaces"); -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ line = pkg_formatted_field(pkg, "Conflicts"); -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ line = pkg_formatted_field(pkg, "Status"); -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ line = pkg_formatted_field(pkg, "Section"); -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/ -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ line = pkg_formatted_field(pkg, "Architecture"); -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ line = pkg_formatted_field(pkg, "Maintainer"); -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ line = pkg_formatted_field(pkg, "MD5sum"); -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ line = pkg_formatted_field(pkg, "Size"); -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ line = pkg_formatted_field(pkg, "Filename"); -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ line = pkg_formatted_field(pkg, "Conffiles"); -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ line = pkg_formatted_field(pkg, "Source"); -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ line = pkg_formatted_field(pkg, "Description"); -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ line = pkg_formatted_field(pkg, "Installed-Time"); -+ strncat(buff ,line, strlen(line)); -+ free(line); -+ -+ return buff; -+} -+ -+char * pkg_formatted_field(pkg_t *pkg, const char *field ) -+{ -+ static size_t LINE_LEN = 128; -+ char line_str[LINE_LEN]; -+ char * temp = (char *)malloc(1); -+ int len = 0; -+ int flag_provide_false = 0; -+ -+/* -+ Pigi: After some discussion with Florian we decided to modify the full procedure in -+ dynamic memory allocation. This should avoid any other segv in this area ( except for bugs ) -+*/ -+ -+ if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) { -+ goto UNKNOWN_FMT_FIELD; -+ } -+ -+ temp[0]='\0'; -+ -+ switch (field[0]) -+ { -+ case 'a': -+ case 'A': -+ if (strcasecmp(field, "Architecture") == 0) { -+ /* Architecture */ -+ if (pkg->architecture) { -+ temp = (char *)realloc(temp,strlen(pkg->architecture)+17); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture); -+ } -+ } else { -+ goto UNKNOWN_FMT_FIELD; -+ } -+ break; -+ case 'c': -+ case 'C': -+ if (strcasecmp(field, "Conffiles") == 0) { -+ /* Conffiles */ -+ conffile_list_elt_t *iter; -+ -+ if (pkg->conffiles.head == NULL) { -+ return temp; -+ } -+ -+ len = 14 ; -+ for (iter = pkg->conffiles.head; iter; iter = iter->next) { -+ if (iter->data->name && iter->data->value) { -+ len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5); -+ } -+ } -+ temp = (char *)realloc(temp,len); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ strncpy(temp, "Conffiles:\n", 12); -+ for (iter = pkg->conffiles.head; iter; iter = iter->next) { -+ if (iter->data->name && iter->data->value) { -+ snprintf(line_str, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value); -+ strncat(temp, line_str, strlen(line_str)); -+ } -+ } -+ } else if (strcasecmp(field, "Conflicts") == 0) { -+ int i; -+ -+ if (pkg->conflicts_count) { -+ len = 14 ; -+ for(i = 0; i < pkg->conflicts_count; i++) { -+ len = len + (strlen(pkg->conflicts_str[i])+5); -+ } -+ temp = (char *)realloc(temp,len); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ strncpy(temp, "Conflicts:", 11); -+ for(i = 0; i < pkg->conflicts_count; i++) { -+ snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]); -+ strncat(temp, line_str, strlen(line_str)); -+ } -+ strncat(temp, "\n", strlen("\n")); -+ } -+ } else { -+ goto UNKNOWN_FMT_FIELD; -+ } -+ break; -+ case 'd': -+ case 'D': -+ if (strcasecmp(field, "Depends") == 0) { -+ /* Depends */ -+ int i; -+ -+ if (pkg->depends_count) { -+ len = 14 ; -+ for(i = 0; i < pkg->depends_count; i++) { -+ len = len + (strlen(pkg->depends_str[i])+4); -+ } -+ temp = (char *)realloc(temp,len); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ strncpy(temp, "Depends:", 10); -+ for(i = 0; i < pkg->depends_count; i++) { -+ snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]); -+ strncat(temp, line_str, strlen(line_str)); -+ } -+ strncat(temp, "\n", strlen("\n")); -+ } -+ } else if (strcasecmp(field, "Description") == 0) { -+ /* Description */ -+ if (pkg->description) { -+ temp = (char *)realloc(temp,strlen(pkg->description)+16); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description); -+ } -+ } else { -+ goto UNKNOWN_FMT_FIELD; -+ } -+ break; -+ case 'e': -+ case 'E': { -+ /* Essential */ -+ if (pkg->essential) { -+ temp = (char *)realloc(temp,16); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ snprintf(temp, (16), "Essential: yes\n"); -+ } -+ } -+ break; -+ case 'f': -+ case 'F': { -+ /* Filename */ -+ if (pkg->filename) { -+ temp = (char *)realloc(temp,strlen(pkg->filename)+12); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename); -+ } -+ } -+ break; -+ case 'i': -+ case 'I': { -+ if (strcasecmp(field, "Installed-Size") == 0) { -+ /* Installed-Size */ -+ temp = (char *)realloc(temp,strlen(pkg->installed_size)+17); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size); -+ } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) { -+ temp = (char *)realloc(temp,29); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time); -+ } -+ } -+ break; -+ case 'm': -+ case 'M': { -+ /* Maintainer | MD5sum */ -+ if (strcasecmp(field, "Maintainer") == 0) { -+ /* Maintainer */ -+ if (pkg->maintainer) { -+ temp = (char *)realloc(temp,strlen(pkg->maintainer)+14); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer); -+ } -+ } else if (strcasecmp(field, "MD5sum") == 0) { -+ /* MD5sum */ -+ if (pkg->md5sum) { -+ temp = (char *)realloc(temp,strlen(pkg->md5sum)+11); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum); -+ } -+ } else { -+ goto UNKNOWN_FMT_FIELD; -+ } -+ } -+ break; -+ case 'p': -+ case 'P': { -+ if (strcasecmp(field, "Package") == 0) { -+ /* Package */ -+ temp = (char *)realloc(temp,strlen(pkg->name)+11); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name); -+ } else if (strcasecmp(field, "Priority") == 0) { -+ /* Priority */ -+ temp = (char *)realloc(temp,strlen(pkg->priority)+12); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority); -+ } else if (strcasecmp(field, "Provides") == 0) { -+ /* Provides */ -+ int i; -+ -+ if (pkg->provides_count) { -+ /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/ -+ for ( i=0; i < pkg->provides_count; i++ ){ -+ if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) { -+ memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */ -+ flag_provide_false = 1; -+ } -+ } -+ if ( !flag_provide_false || /* Pigi there is not my trick flag */ -+ ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */ -+ char provstr[LINE_LEN]; -+ len = 15; -+ for(i = 0; i < pkg->provides_count; i++) { -+ len = len + (strlen(pkg->provides_str[i])+5); -+ } -+ temp = (char *)realloc(temp,len); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ strncpy(temp, "Provides:", 12); -+ for(i = 0; i < pkg->provides_count; i++) { -+ if (strlen(pkg->provides_str[i])>0){; -+ snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]); -+ strncat(temp, provstr, strlen(provstr)); -+ } -+ } -+ strncat(temp, "\n", strlen("\n")); -+ } -+ } -+ } else { -+ goto UNKNOWN_FMT_FIELD; -+ } -+ } -+ break; -+ case 'r': -+ case 'R': { -+ int i; -+ /* Replaces | Recommends*/ -+ if (strcasecmp (field, "Replaces") == 0) { -+ if (pkg->replaces_count) { -+ len = 14; -+ for (i = 0; i < pkg->replaces_count; i++) { -+ len = len + (strlen(pkg->replaces_str[i])+5); -+ } -+ temp = (char *)realloc(temp,len); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ strncpy(temp, "Replaces:", 12); -+ for (i = 0; i < pkg->replaces_count; i++) { -+ snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]); -+ strncat(temp, line_str, strlen(line_str)); -+ } -+ strncat(temp, "\n", strlen("\n")); -+ } -+ } else if (strcasecmp (field, "Recommends") == 0) { -+ if (pkg->recommends_count) { -+ len = 15; -+ for(i = 0; i < pkg->recommends_count; i++) { -+ len = len + (strlen( pkg->recommends_str[i])+5); -+ } -+ temp = (char *)realloc(temp,len); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ strncpy(temp, "Recommends:", 13); -+ for(i = 0; i < pkg->recommends_count; i++) { -+ snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]); -+ strncat(temp, line_str, strlen(line_str)); -+ } -+ strncat(temp, "\n", strlen("\n")); -+ } -+ } else { -+ goto UNKNOWN_FMT_FIELD; -+ } -+ } -+ break; -+ case 's': -+ case 'S': { -+ /* Section | Size | Source | Status | Suggests */ -+ if (strcasecmp(field, "Section") == 0) { -+ /* Section */ -+ if (pkg->section) { -+ temp = (char *)realloc(temp,strlen(pkg->section)+11); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section); -+ } -+ } else if (strcasecmp(field, "Size") == 0) { -+ /* Size */ -+ if (pkg->size) { -+ temp = (char *)realloc(temp,strlen(pkg->size)+8); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size); -+ } -+ } else if (strcasecmp(field, "Source") == 0) { -+ /* Source */ -+ if (pkg->source) { -+ temp = (char *)realloc(temp,strlen(pkg->source)+10); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source); -+ } -+ } else if (strcasecmp(field, "Status") == 0) { -+ /* Status */ -+ /* Benjamin Pineau note: we should avoid direct usage of -+ * strlen(arg) without keeping "arg" for later free() -+ */ -+ char *pflag=pkg_state_flag_to_str(pkg->state_flag); -+ char *pstat=pkg_state_status_to_str(pkg->state_status); -+ char *pwant=pkg_state_want_to_str(pkg->state_want); -+ -+ size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 ); -+ temp = (char *)realloc(temp,sum_of_sizes); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat); -+ free(pflag); -+ free(pwant); -+ if(pstat) /* pfstat can be NULL if ENOMEM */ -+ free(pstat); -+ } else if (strcasecmp(field, "Suggests") == 0) { -+ if (pkg->suggests_count) { -+ int i; -+ len = 13; -+ for(i = 0; i < pkg->suggests_count; i++) { -+ len = len + (strlen(pkg->suggests_str[i])+5); -+ } -+ temp = (char *)realloc(temp,len); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ strncpy(temp, "Suggests:", 10); -+ for(i = 0; i < pkg->suggests_count; i++) { -+ snprintf(line_str, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]); -+ strncat(temp, line_str, strlen(line_str)); -+ } -+ strncat(temp, "\n", strlen("\n")); -+ } -+ } else { -+ goto UNKNOWN_FMT_FIELD; -+ } -+ } -+ break; -+ case 'v': -+ case 'V': { -+ /* Version */ -+ char *version = pkg_version_str_alloc(pkg); -+ temp = (char *)realloc(temp,strlen(version)+14); -+ if ( temp == NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ temp[0]='\0'; -+ snprintf(temp, (strlen(version)+12), "Version: %s\n", version); -+ free(version); -+ } -+ break; -+ default: -+ goto UNKNOWN_FMT_FIELD; -+ } -+ -+ if ( strlen(temp)<2 ) { -+ temp[0]='\0'; -+ } -+ return temp; -+ -+ UNKNOWN_FMT_FIELD: -+ fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field); -+ if ( strlen(temp)<2 ) { -+ temp[0]='\0'; -+ } -+ -+ return temp; -+} -+ -+void pkg_print_info(pkg_t *pkg, FILE *file) -+{ -+ char * buff; -+ if (pkg == NULL) { -+ return; -+ } -+ -+ buff = pkg_formatted_info(pkg); -+ if ( buff == NULL ) -+ return; -+ if (strlen(buff)>2){ -+ fwrite(buff, 1, strlen(buff), file); -+ } -+ free(buff); -+} -+ -+void pkg_print_status(pkg_t * pkg, FILE * file) -+{ -+ if (pkg == NULL) { -+ return; -+ } -+ -+ /* XXX: QUESTION: Do we actually want more fields here? The -+ original idea was to save space by installing only what was -+ needed for actual computation, (package, version, status, -+ essential, conffiles). The assumption is that all other fields -+ can be found in th available file. -+ -+ But, someone proposed the idea to make it possible to -+ reconstruct a .ipk from an installed package, (ie. for beaming -+ from one handheld to another). So, maybe we actually want a few -+ more fields here, (depends, suggests, etc.), so that that would -+ be guaranteed to work even in the absence of more information -+ from the available file. -+ -+ 28-MAR-03: kergoth and I discussed this yesterday. We think -+ the essential info needs to be here for all installed packages -+ because they may not appear in the Packages files on various -+ feeds. Furthermore, one should be able to install from URL or -+ local storage without requiring a Packages file from any feed. -+ -Jamey -+ */ -+ pkg_print_field(pkg, file, "Package"); -+ pkg_print_field(pkg, file, "Version"); -+ pkg_print_field(pkg, file, "Depends"); -+ pkg_print_field(pkg, file, "Recommends"); -+ pkg_print_field(pkg, file, "Suggests"); -+ pkg_print_field(pkg, file, "Provides"); -+ pkg_print_field(pkg, file, "Replaces"); -+ pkg_print_field(pkg, file, "Conflicts"); -+ pkg_print_field(pkg, file, "Status"); -+ pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */ -+ pkg_print_field(pkg, file, "Architecture"); -+ pkg_print_field(pkg, file, "Conffiles"); -+ pkg_print_field(pkg, file, "Installed-Time"); -+ fputs("\n", file); -+} -+ -+void pkg_print_field(pkg_t *pkg, FILE *file, const char *field) -+{ -+ char *buff; -+ if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) { -+ fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", -+ __FUNCTION__, field); -+ } -+ buff = pkg_formatted_field(pkg, field); -+ if (strlen(buff)>2) { -+ fprintf(file, "%s", buff); -+ fflush(file); -+ } -+ free(buff); -+ return; -+} -+ -+/* -+ * libdpkg - Debian packaging suite library routines -+ * vercmp.c - comparison of version numbers -+ * -+ * Copyright (C) 1995 Ian Jackson -+ */ -+int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg) -+{ -+ int r; -+ -+ if (pkg->epoch > ref_pkg->epoch) { -+ return 1; -+ } -+ -+ if (pkg->epoch < ref_pkg->epoch) { -+ return -1; -+ } -+ -+ r = verrevcmp(pkg->version, ref_pkg->version); -+ if (r) { -+ return r; -+ } -+ -+#ifdef USE_DEBVERSION -+ r = verrevcmp(pkg->revision, ref_pkg->revision); -+ if (r) { -+ return r; -+ } -+ -+ r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision); -+#endif -+ -+ return r; -+} -+ -+int verrevcmp(const char *val, const char *ref) -+{ -+ int vc, rc; -+ long vl, rl; -+ const char *vp, *rp; -+ const char *vsep, *rsep; -+ -+ if (!val) val= ""; -+ if (!ref) ref= ""; -+ for (;;) { -+ vp= val; while (*vp && !isdigit(*vp)) vp++; -+ rp= ref; while (*rp && !isdigit(*rp)) rp++; -+ for (;;) { -+ vc= (val == vp) ? 0 : *val++; -+ rc= (ref == rp) ? 0 : *ref++; -+ if (!rc && !vc) break; -+ if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */ -+ if (rc && !isalpha(rc)) rc += 256; -+ if (vc != rc) return vc - rc; -+ } -+ val= vp; -+ ref= rp; -+ vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10); -+ rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10); -+ if (vl != rl) return vl - rl; -+ -+ vc = *val; -+ rc = *ref; -+ vsep = strchr(".-", vc); -+ rsep = strchr(".-", rc); -+ if (vsep && !rsep) return -1; -+ if (!vsep && rsep) return +1; -+ -+ if (!*val && !*ref) return 0; -+ if (!*val) return -1; -+ if (!*ref) return +1; -+ } -+} -+ -+int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op) -+{ -+ int r; -+ -+ r = pkg_compare_versions(it, ref); -+ -+ if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) { -+ return r <= 0; -+ } -+ -+ if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) { -+ return r >= 0; -+ } -+ -+ if (strcmp(op, "<<") == 0) { -+ return r < 0; -+ } -+ -+ if (strcmp(op, ">>") == 0) { -+ return r > 0; -+ } -+ -+ if (strcmp(op, "=") == 0) { -+ return r == 0; -+ } -+ -+ fprintf(stderr, "unknown operator: %s", op); -+ return 0; -+} -+ -+int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b) -+{ -+ int namecmp; -+ int vercmp; -+ if (!a->name || !b->name) { -+ fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n", -+ a, a->name, b, b->name); -+ return 0; -+ } -+ -+ namecmp = strcmp(a->name, b->name); -+ if (namecmp) -+ return namecmp; -+ vercmp = pkg_compare_versions(a, b); -+ if (vercmp) -+ return vercmp; -+ if (!a->arch_priority || !b->arch_priority) { -+ fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n", -+ a, a->arch_priority, b, b->arch_priority); -+ return 0; -+ } -+ if (a->arch_priority > b->arch_priority) -+ return 1; -+ if (a->arch_priority < b->arch_priority) -+ return -1; -+ return 0; -+} -+ -+int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b) -+{ -+ if (!a->name || !b->name) { -+ fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n", -+ a, a->name, b, b->name); -+ return 0; -+ } -+ return strcmp(a->name, b->name); -+} -+ -+ -+char *pkg_version_str_alloc(pkg_t *pkg) -+{ -+ char *complete_version; -+ char *epoch_str; -+#ifdef USE_DEBVERSION -+ char *revision_str; -+ char *familiar_revision_str; -+#endif -+ -+ if (pkg->epoch) { -+ sprintf_alloc(&epoch_str, "%d:", (int)(pkg->epoch)); -+ } else { -+ epoch_str = strdup(""); -+ } -+ -+#ifdef USE_DEBVERSION -+ if (pkg->revision && strlen(pkg->revision)) { -+ sprintf_alloc(&revision_str, "-%s", pkg->revision); -+ } else { -+ revision_str = strdup(""); -+ } -+ -+ if (pkg->familiar_revision && strlen(pkg->familiar_revision)) { -+ sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision); -+ } else { -+ familiar_revision_str = strdup(""); -+ } -+#endif -+ -+#ifdef USE_DEBVERSION -+ sprintf_alloc(&complete_version, "%s%s%s%s", -+ epoch_str, pkg->version, revision_str, familiar_revision_str); -+#else -+ sprintf_alloc(&complete_version, "%s%s", -+ epoch_str, pkg->version); -+#endif -+ -+ free(epoch_str); -+#ifdef USE_DEBVERSION -+ free(revision_str); -+ free(familiar_revision_str); -+#endif -+ -+ return complete_version; -+} -+ -+str_list_t *pkg_get_installed_files(pkg_t *pkg) -+{ -+ int err; -+ char *list_file_name = NULL; -+ FILE *list_file = NULL; -+ char *line; -+ char *installed_file_name; -+ int rootdirlen; -+ -+ pkg->installed_files_ref_cnt++; -+ -+ if (pkg->installed_files) { -+ return pkg->installed_files; -+ } -+ -+ pkg->installed_files = str_list_alloc(); -+ if (pkg->installed_files == NULL) { -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ -+ /* For uninstalled packages, get the file list firectly from the package. -+ For installed packages, look at the package.list file in the database. -+ */ -+ if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) { -+ if (pkg->local_filename == NULL) { -+ return pkg->installed_files; -+ } -+ /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary -+ file. In other words, change deb_extract so that it can -+ simply return the file list as a char *[] rather than -+ insisting on writing in to a FILE * as it does now. */ -+ list_file = tmpfile(); -+ err = pkg_extract_data_file_names_to_stream(pkg, list_file); -+ if (err) { -+ fclose(list_file); -+ fprintf(stderr, "%s: Error extracting file list from %s: %s\n", -+ __FUNCTION__, pkg->local_filename, strerror(err)); -+ return pkg->installed_files; -+ } -+ rewind(list_file); -+ } else { -+ sprintf_alloc(&list_file_name, "%s/%s.list", -+ pkg->dest->info_dir, pkg->name); -+ if (! file_exists(list_file_name)) { -+ free(list_file_name); -+ return pkg->installed_files; -+ } -+ -+ list_file = fopen(list_file_name, "r"); -+ if (list_file == NULL) { -+ fprintf(stderr, "WARNING: Cannot open %s: %s\n", -+ list_file_name, strerror(errno)); -+ free(list_file_name); -+ return pkg->installed_files; -+ } -+ free(list_file_name); -+ } -+ -+ rootdirlen = strlen( pkg->dest->root_dir ); -+ while (1) { -+ char *file_name; -+ -+ line = file_read_line_alloc(list_file); -+ if (line == NULL) { -+ break; -+ } -+ str_chomp(line); -+ file_name = line; -+ -+ /* Take pains to avoid uglies like "/./" in the middle of file_name. */ -+ if( strncmp( pkg->dest->root_dir, -+ file_name, -+ rootdirlen ) ) { -+ if (*file_name == '.') { -+ file_name++; -+ } -+ if (*file_name == '/') { -+ file_name++; -+ } -+ -+ /* Freed in pkg_free_installed_files */ -+ sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name); -+ } else { -+ // already contains root_dir as header -> ABSOLUTE -+ sprintf_alloc(&installed_file_name, "%s", file_name); -+ } -+ str_list_append(pkg->installed_files, installed_file_name); -+ free(line); -+ } -+ -+ fclose(list_file); -+ -+ return pkg->installed_files; -+} -+ -+/* XXX: CLEANUP: This function and it's counterpart, -+ (pkg_get_installed_files), do not match our init/deinit naming -+ convention. Nor the alloc/free convention. But, then again, neither -+ of these conventions currrently fit the way these two functions -+ work. */ -+int pkg_free_installed_files(pkg_t *pkg) -+{ -+ str_list_elt_t *iter; -+ -+ pkg->installed_files_ref_cnt--; -+ if (pkg->installed_files_ref_cnt > 0) { -+ return 0; -+ } -+ -+ if (pkg->installed_files) { -+ -+ for (iter = pkg->installed_files->head; iter; iter = iter->next) { -+ /* malloced in pkg_get_installed_files */ -+ free (iter->data); -+ iter->data = NULL; -+ } -+ -+ str_list_deinit(pkg->installed_files); -+ } -+ -+ pkg->installed_files = NULL; -+ -+ return 0; -+} -+ -+int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg) -+{ -+ int err; -+ char *list_file_name; -+ -+ //I don't think pkg_free_installed_files should be called here. Jamey -+ //pkg_free_installed_files(pkg); -+ -+ sprintf_alloc(&list_file_name, "%s/%s.list", -+ pkg->dest->info_dir, pkg->name); -+ if (!conf->noaction) { -+ err = unlink(list_file_name); -+ free(list_file_name); -+ -+ if (err) { -+ return errno; -+ } -+ } -+ return 0; -+} -+ -+conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name) -+{ -+ conffile_list_elt_t *iter; -+ conffile_t *conffile; -+ -+ if (pkg == NULL) { -+ return NULL; -+ } -+ -+ for (iter = pkg->conffiles.head; iter; iter = iter->next) { -+ conffile = iter->data; -+ -+ if (strcmp(conffile->name, file_name) == 0) { -+ return conffile; -+ } -+ } -+ -+ return NULL; -+} -+ -+int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg, -+ const char *script, const char *args) -+{ -+ int err; -+ char *path; -+ char *cmd; -+ -+ /* XXX: FEATURE: When conf->offline_root is set, we should run the -+ maintainer script within a chroot environment. */ -+ -+ /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages -+ have scripts in pkg->tmp_unpack_dir. */ -+ if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) { -+ if (pkg->dest == NULL) { -+ fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n", -+ __FUNCTION__, pkg->name); -+ return EINVAL; -+ } -+ sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script); -+ } else { -+ if (pkg->tmp_unpack_dir == NULL) { -+ fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n", -+ __FUNCTION__, pkg->name); -+ return EINVAL; -+ } -+ sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script); -+ } -+ -+ ipkg_message(conf, IPKG_INFO, "Running script %s\n", path); -+ if (conf->noaction) return 0; -+ -+ /* XXX: CLEANUP: There must be a better way to handle maintainer -+ scripts when running with offline_root mode and/or a dest other -+ than '/'. I've been playing around with some clever chroot -+ tricks and I might come up with something workable. */ -+ if (conf->offline_root) { -+ setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1); -+ } -+ -+ setenv("PKG_ROOT", -+ pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1); -+ -+ if (! file_exists(path)) { -+ free(path); -+ return 0; -+ } -+ -+ if (conf->offline_root) { -+ fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script); -+ free(path); -+ return 0; -+ } -+ -+ sprintf_alloc(&cmd, "%s %s", path, args); -+ free(path); -+ -+ err = xsystem(cmd); -+ free(cmd); -+ -+ if (err) { -+ fprintf(stderr, "%s script returned status %d\n", script, err); -+ return err; -+ } -+ -+ return 0; -+} -+ -+char *pkg_state_want_to_str(pkg_state_want_t sw) -+{ -+ int i; -+ -+ for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) { -+ if (pkg_state_want_map[i].value == sw) { -+ return strdup(pkg_state_want_map[i].str); -+ } -+ } -+ -+ fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n", -+ __FUNCTION__, sw); -+ return strdup(""); -+} -+ -+pkg_state_want_t pkg_state_want_from_str(char *str) -+{ -+ int i; -+ -+ for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) { -+ if (strcmp(str, pkg_state_want_map[i].str) == 0) { -+ return pkg_state_want_map[i].value; -+ } -+ } -+ -+ fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n", -+ __FUNCTION__, str); -+ return SW_UNKNOWN; -+} -+ -+char *pkg_state_flag_to_str(pkg_state_flag_t sf) -+{ -+ int i; -+ int len = 3; /* ok\000 is minimum */ -+ char *str = NULL; -+ -+ /* clear the temporary flags before converting to string */ -+ sf &= SF_NONVOLATILE_FLAGS; -+ -+ if (sf == 0) { -+ return strdup("ok"); -+ } else { -+ -+ for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) { -+ if (sf & pkg_state_flag_map[i].value) { -+ len += strlen(pkg_state_flag_map[i].str) + 1; -+ } -+ } -+ str = malloc(len); -+ if ( str == NULL ) { -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ str[0] = 0; -+ for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) { -+ if (sf & pkg_state_flag_map[i].value) { -+ strcat(str, pkg_state_flag_map[i].str); -+ strcat(str, ","); -+ } -+ } -+ len = strlen(str); -+ str[len-1] = 0; /* squash last comma */ -+ return str; -+ } -+} -+ -+pkg_state_flag_t pkg_state_flag_from_str(char *str) -+{ -+ int i; -+ int sf = SF_OK; -+ -+ if (strcmp(str, "ok") == 0) { -+ return SF_OK; -+ } -+ for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) { -+ const char *sfname = pkg_state_flag_map[i].str; -+ int sfname_len = strlen(sfname); -+ if (strncmp(str, sfname, sfname_len) == 0) { -+ sf |= pkg_state_flag_map[i].value; -+ str += sfname_len; -+ if (str[0] == ',') { -+ str++; -+ } else { -+ break; -+ } -+ } -+ } -+ -+ return sf; -+} -+ -+char *pkg_state_status_to_str(pkg_state_status_t ss) -+{ -+ int i; -+ -+ for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) { -+ if (pkg_state_status_map[i].value == ss) { -+ return strdup(pkg_state_status_map[i].str); -+ } -+ } -+ -+ fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n", -+ __FUNCTION__, ss); -+ return strdup(""); -+} -+ -+pkg_state_status_t pkg_state_status_from_str(char *str) -+{ -+ int i; -+ -+ for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) { -+ if (strcmp(str, pkg_state_status_map[i].str) == 0) { -+ return pkg_state_status_map[i].value; -+ } -+ } -+ -+ fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n", -+ __FUNCTION__, str); -+ return SS_NOT_INSTALLED; -+} -+ -+int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg) -+{ -+ nv_pair_list_elt_t *l; -+ -+ if (!pkg->architecture) -+ return 1; -+ -+ l = conf->arch_list.head; -+ -+ while (l) { -+ nv_pair_t *nv = l->data; -+ if (strcmp(nv->name, pkg->architecture) == 0) { -+ ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name); -+ return 1; -+ } -+ l = l->next; -+ } -+ -+ ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name); -+ return 0; -+} -+ -+int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname) -+{ -+ nv_pair_list_elt_t *l; -+ -+ l = conf->arch_list.head; -+ -+ while (l) { -+ nv_pair_t *nv = l->data; -+ if (strcmp(nv->name, archname) == 0) { -+ int priority = strtol(nv->value, NULL, 0); -+ return priority; -+ } -+ l = l->next; -+ } -+ return 0; -+} -+ -+int pkg_info_preinstall_check(ipkg_conf_t *conf) -+{ -+ int i; -+ hash_table_t *pkg_hash = &conf->pkg_hash; -+ pkg_vec_t *available_pkgs = pkg_vec_alloc(); -+ pkg_vec_t *installed_pkgs = pkg_vec_alloc(); -+ -+ ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n"); -+ pkg_hash_fetch_available(pkg_hash, available_pkgs); -+ /* update arch_priority for each package */ -+ for (i = 0; i < available_pkgs->len; i++) { -+ pkg_t *pkg = available_pkgs->pkgs[i]; -+ int arch_priority = 1; -+ if (!pkg) -+ continue; -+ // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture); -+ if (pkg->architecture) -+ arch_priority = pkg_get_arch_priority(conf, pkg->architecture); -+ else -+ ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name); -+ // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority); -+ pkg->arch_priority = arch_priority; -+ } -+ -+ for (i = 0; i < available_pkgs->len; i++) { -+ pkg_t *pkg = available_pkgs->pkgs[i]; -+ if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) { -+ /* clear flags and want for any uninstallable package */ -+ ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n", -+ pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want); -+ pkg->state_want = SW_UNKNOWN; -+ pkg->state_flag = 0; -+ } -+ } -+ pkg_vec_free(available_pkgs); -+ -+ /* update the file owner data structure */ -+ ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n"); -+ pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs); -+ for (i = 0; i < installed_pkgs->len; i++) { -+ pkg_t *pkg = installed_pkgs->pkgs[i]; -+ str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */ -+ str_list_elt_t *iter; -+ if (installed_files == NULL) { -+ ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name); -+ break; -+ } -+ for (iter = installed_files->head; iter; iter = iter->next) { -+ char *installed_file = iter->data; -+ // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file); -+ file_hash_set_file_owner(conf, installed_file, pkg); -+ } -+ } -+ pkg_vec_free(installed_pkgs); -+ -+ return 0; -+} -+ -+struct pkg_write_filelist_data { -+ ipkg_conf_t *conf; -+ pkg_t *pkg; -+ FILE *stream; -+}; -+ -+void pkg_write_filelist_helper(const char *key, void *entry_, void *data_) -+{ -+ struct pkg_write_filelist_data *data = data_; -+ pkg_t *entry = entry_; -+ if (entry == data->pkg) { -+ fprintf(data->stream, "%s\n", key); -+ } -+} -+ -+int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg) -+{ -+ struct pkg_write_filelist_data data; -+ char *list_file_name = NULL; -+ int err = 0; -+ -+ if (!pkg) { -+ ipkg_message(conf, IPKG_ERROR, "Null pkg\n"); -+ return -EINVAL; -+ } -+ ipkg_message(conf, IPKG_INFO, -+ " creating %s.list file\n", pkg->name); -+ sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name); -+ if (!list_file_name) { -+ ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n"); -+ return -ENOMEM; -+ } -+ ipkg_message(conf, IPKG_INFO, -+ " creating %s file for pkg %s\n", list_file_name, pkg->name); -+ data.stream = fopen(list_file_name, "w"); -+ if (!data.stream) { -+ ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n", -+ list_file_name, strerror(errno)); -+ return errno; -+ } -+ data.pkg = pkg; -+ data.conf = conf; -+ hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data); -+ fclose(data.stream); -+ free(list_file_name); -+ -+ return err; -+} -+ -+int pkg_write_changed_filelists(ipkg_conf_t *conf) -+{ -+ pkg_vec_t *installed_pkgs = pkg_vec_alloc(); -+ hash_table_t *pkg_hash = &conf->pkg_hash; -+ int i; -+ int err; -+ if (conf->noaction) -+ return 0; -+ -+ ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__); -+ pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs); -+ for (i = 0; i < installed_pkgs->len; i++) { -+ pkg_t *pkg = installed_pkgs->pkgs[i]; -+ if (pkg->state_flag & SF_FILELIST_CHANGED) { -+ ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__); -+ err = pkg_write_filelist(conf, pkg); -+ if (err) -+ ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err); -+ } -+ } -+ return 0; -+} -Index: busybox-1.4.2/archival/libipkg/pkg_depends.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg_depends.c 2007-06-04 13:21:36.724393712 +0200 -@@ -0,0 +1,1031 @@ -+/* pkg_depends.c - the itsy package management system -+ -+ Steven M. Ayer -+ -+ Copyright (C) 2002 Compaq Computer Corporation -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+#include -+#include -+ -+#include "pkg.h" -+#include "ipkg_utils.h" -+#include "pkg_hash.h" -+#include "ipkg_message.h" -+#include "pkg_parse.h" -+#include "hash_table.h" -+ -+static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str); -+static depend_t * depend_init(void); -+static void depend_deinit(depend_t *d); -+static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx); -+static char ** merge_unresolved(char ** oldstuff, char ** newstuff); -+static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg); -+ -+static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata) -+{ -+ depend_t *depend = (depend_t *)cdata; -+ if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg)) -+ return 1; -+ else -+ return 0; -+} -+ -+static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata) -+{ -+ depend_t *depend = (depend_t *)cdata; -+#if 0 -+ pkg_t * temp = pkg_new(); -+ int comparison; -+ parseVersion(temp, depend->version); -+ comparison = pkg_compare_versions(pkg, temp); -+ free(temp); -+ -+ fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n", -+ __FUNCTION__, pkg->name, pkg->version, -+ depend, depend->constraint, depend->version, -+ comparison, version_constraints_satisfied(depend, pkg)); -+#endif -+ if (version_constraints_satisfied(depend, pkg)) -+ return 1; -+ else -+ return 0; -+} -+ -+/* returns ndependences or negative error value */ -+int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, -+ pkg_vec_t *unsatisfied, char *** unresolved) -+{ -+ pkg_t * satisfier_entry_pkg; -+ register int i, j, k, l; -+ int count, found; -+ char ** the_lost; -+ abstract_pkg_t * ab_pkg; -+ -+ /* -+ * this is a setup to check for redundant/cyclic dependency checks, -+ * which are marked at the abstract_pkg level -+ */ -+ if (!(ab_pkg = pkg->parent)) { -+ fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name); -+ *unresolved = NULL; -+ return 0; -+ } -+ if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */ -+ *unresolved = NULL; -+ return 0; -+ } else { -+ ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */ -+ } -+ /**/ -+ -+ count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count; -+ if (!count){ -+ *unresolved = NULL; -+ return 0; -+ } -+ -+ the_lost = NULL; -+ -+ /* foreach dependency */ -+ for (i = 0; i < count; i++) { -+ compound_depend_t * compound_depend = &pkg->depends[i]; -+ depend_t ** possible_satisfiers = compound_depend->possibilities;; -+ found = 0; -+ satisfier_entry_pkg = NULL; -+ -+ if (compound_depend->type == GREEDY_DEPEND) { -+ /* foreach possible satisfier */ -+ for (j = 0; j < compound_depend->possibility_count; j++) { -+ /* foreach provided_by, which includes the abstract_pkg itself */ -+ abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg; -+ abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by; -+ int nposs = ab_provider_vec->len; -+ abstract_pkg_t **ab_providers = ab_provider_vec->pkgs; -+ for (l = 0; l < nposs; l++) { -+ pkg_vec_t *test_vec = ab_providers[l]->pkgs; -+ /* if no depends on this one, try the first package that Provides this one */ -+ if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */ -+ continue; -+ } -+ -+ /* cruise this possiblity's pkg_vec looking for an installed version */ -+ for (k = 0; k < test_vec->len; k++) { -+ pkg_t *pkg_scout = test_vec->pkgs[k]; -+ /* not installed, and not already known about? */ -+ if ((pkg_scout->state_want != SW_INSTALL) -+ && !pkg_scout->parent->dependencies_checked -+ && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) { -+ char ** newstuff = NULL; -+ int rc; -+ pkg_vec_t *tmp_vec = pkg_vec_alloc (); -+ /* check for not-already-installed dependencies */ -+ rc = pkg_hash_fetch_unsatisfied_dependencies(conf, -+ pkg_scout, -+ tmp_vec, -+ &newstuff); -+ if (newstuff == NULL) { -+ int ok = 1; -+ for (l = 0; l < rc; l++) { -+ pkg_t *p = tmp_vec->pkgs[l]; -+ if (p->state_want == SW_INSTALL) -+ continue; -+ ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name); -+ ok = 0; -+ break; -+ } -+ pkg_vec_free (tmp_vec); -+ if (ok) { -+ /* mark this one for installation */ -+ ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name); -+ pkg_vec_insert(unsatisfied, pkg_scout); -+ } -+ } else { -+ ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name); -+ free (newstuff); -+ } -+ } -+ } -+ } -+ } -+ -+ continue; -+ } -+ -+ /* foreach possible satisfier, look for installed package */ -+ for (j = 0; j < compound_depend->possibility_count; j++) { -+ /* foreach provided_by, which includes the abstract_pkg itself */ -+ depend_t *dependence_to_satisfy = possible_satisfiers[j]; -+ abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg; -+ pkg_t *satisfying_pkg = -+ pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg, -+ pkg_installed_and_constraint_satisfied, -+ dependence_to_satisfy, 1); -+ /* Being that I can't test constraing in pkg_hash, I will test it here */ -+ if (satisfying_pkg != NULL) { -+ if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) { -+ satisfying_pkg = NULL; -+ } -+ } -+ ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg); -+ if (satisfying_pkg != NULL) { -+ found = 1; -+ break; -+ } -+ -+ } -+ /* if nothing installed matches, then look for uninstalled satisfier */ -+ if (!found) { -+ /* foreach possible satisfier, look for installed package */ -+ for (j = 0; j < compound_depend->possibility_count; j++) { -+ /* foreach provided_by, which includes the abstract_pkg itself */ -+ depend_t *dependence_to_satisfy = possible_satisfiers[j]; -+ abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg; -+ pkg_t *satisfying_pkg = -+ pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg, -+ pkg_constraint_satisfied, -+ dependence_to_satisfy, 1); -+ /* Being that I can't test constraing in pkg_hash, I will test it here too */ -+ if (satisfying_pkg != NULL) { -+ if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) { -+ satisfying_pkg = NULL; -+ } -+ } -+ -+ /* user request overrides package recommendation */ -+ if (satisfying_pkg != NULL -+ && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST) -+ && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) { -+ ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n", -+ pkg->name, satisfying_pkg->name); -+ continue; -+ } -+ -+ ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg); -+ if (satisfying_pkg != NULL) { -+ satisfier_entry_pkg = satisfying_pkg; -+ break; -+ } -+ } -+ } -+ -+ /* we didn't find one, add something to the unsatisfied vector */ -+ if (!found) { -+ if (!satisfier_entry_pkg) { -+ /* failure to meet recommendations is not an error */ -+ if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST) -+ the_lost = add_unresolved_dep(pkg, the_lost, i); -+ else -+ ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n", -+ pkg->name, compound_depend->possibilities[0]->pkg->name); -+ } -+ else { -+ if (compound_depend->type == SUGGEST) { -+ /* just mention it politely */ -+ ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n", -+ pkg->name, satisfier_entry_pkg->name); -+ } else { -+ char ** newstuff = NULL; -+ -+ if (satisfier_entry_pkg != pkg && -+ !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) { -+ pkg_vec_insert(unsatisfied, satisfier_entry_pkg); -+ pkg_hash_fetch_unsatisfied_dependencies(conf, -+ satisfier_entry_pkg, -+ unsatisfied, -+ &newstuff); -+ the_lost = merge_unresolved(the_lost, newstuff); -+ } -+ } -+ } -+ } -+ } -+ *unresolved = the_lost; -+ -+ return unsatisfied->len; -+} -+ -+/*checking for conflicts !in replaces -+ If a packages conflicts with another but is also replacing it, I should not consider it a -+ really conflicts -+ returns 0 if conflicts <> replaces or 1 if conflicts == replaces -+*/ -+int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg) -+{ -+ int i ; -+ int replaces_count = pkg->replaces_count; -+ abstract_pkg_t **replaces; -+ -+ if (pkg->replaces_count==0) // No replaces, it's surely a conflict -+ return 0; -+ -+ replaces = pkg->replaces; -+ -+ for (i = 0; i < replaces_count; i++) { -+ if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found -+ ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name); -+ return 1; -+ } -+ } -+ return 0; -+ -+} -+ -+ -+/* Abhaya: added support for conflicts */ -+pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg) -+{ -+ pkg_vec_t * installed_conflicts, * test_vec; -+ compound_depend_t * conflicts; -+ depend_t ** possible_satisfiers; -+ depend_t * possible_satisfier; -+ register int i, j, k; -+ int count; -+ abstract_pkg_t * ab_pkg; -+ pkg_t **pkg_scouts; -+ pkg_t *pkg_scout; -+ -+ /* -+ * this is a setup to check for redundant/cyclic dependency checks, -+ * which are marked at the abstract_pkg level -+ */ -+ if(!(ab_pkg = pkg->parent)){ -+ fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name); -+ return (pkg_vec_t *)NULL; -+ } -+ -+ conflicts = pkg->conflicts; -+ if(!conflicts){ -+ return (pkg_vec_t *)NULL; -+ } -+ installed_conflicts = pkg_vec_alloc(); -+ -+ count = pkg->conflicts_count; -+ -+ -+ -+ /* foreach conflict */ -+ for(i = 0; i < pkg->conflicts_count; i++){ -+ -+ possible_satisfiers = conflicts->possibilities; -+ -+ /* foreach possible satisfier */ -+ for(j = 0; j < conflicts->possibility_count; j++){ -+ possible_satisfier = possible_satisfiers[j]; -+ if (!possible_satisfier) -+ fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__); -+ if (!possible_satisfier->pkg) -+ fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__); -+ test_vec = possible_satisfier->pkg->pkgs; -+ if (test_vec) { -+ /* pkg_vec found, it is an actual package conflict -+ * cruise this possiblity's pkg_vec looking for an installed version */ -+ pkg_scouts = test_vec->pkgs; -+ for(k = 0; k < test_vec->len; k++){ -+ pkg_scout = pkg_scouts[k]; -+ if (!pkg_scout) { -+ fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__); -+ continue; -+ } -+ if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) && -+ version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){ -+ if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){ -+ pkg_vec_insert(installed_conflicts, pkg_scout); -+ } -+ } -+ } -+ } -+ } -+ conflicts++; -+ } -+ -+ if (installed_conflicts->len) -+ return installed_conflicts; -+ pkg_vec_free(installed_conflicts); -+ return (pkg_vec_t *)NULL; -+} -+ -+int version_constraints_satisfied(depend_t * depends, pkg_t * pkg) -+{ -+ pkg_t * temp; -+ int comparison; -+ -+ if(depends->constraint == NONE) -+ return 1; -+ -+ temp = pkg_new(); -+ -+ parseVersion(temp, depends->version); -+ -+ comparison = pkg_compare_versions(pkg, temp); -+ -+ free(temp); -+ -+ if((depends->constraint == EARLIER) && -+ (comparison < 0)) -+ return 1; -+ else if((depends->constraint == LATER) && -+ (comparison > 0)) -+ return 1; -+ else if(comparison == 0) -+ return 1; -+ else if((depends->constraint == LATER_EQUAL) && -+ (comparison >= 0)) -+ return 1; -+ else if((depends->constraint == EARLIER_EQUAL) && -+ (comparison <= 0)) -+ return 1; -+ -+ return 0; -+} -+ -+int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend) -+{ -+ abstract_pkg_t *apkg = depend->pkg; -+ abstract_pkg_vec_t *provider_apkgs = apkg->provided_by; -+ int n_providers = provider_apkgs->len; -+ abstract_pkg_t **apkgs = provider_apkgs->pkgs; -+ pkg_vec_t *pkg_vec; -+ int n_pkgs ; -+ int i; -+ int j; -+ -+ for (i = 0; i < n_providers; i++) { -+ abstract_pkg_t *papkg = apkgs[i]; -+ pkg_vec = papkg->pkgs; -+ if (pkg_vec) { -+ n_pkgs = pkg_vec->len; -+ for (j = 0; j < n_pkgs; j++) { -+ pkg_t *pkg = pkg_vec->pkgs[j]; -+ if (version_constraints_satisfied(depend, pkg)) { -+ return 1; -+ } -+ } -+ } -+ } -+ return 0; -+} -+ -+int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend) -+{ -+ abstract_pkg_t *apkg = depend->pkg; -+ abstract_pkg_vec_t *provider_apkgs = apkg->provided_by; -+ int n_providers = provider_apkgs->len; -+ abstract_pkg_t **apkgs = provider_apkgs->pkgs; -+ int i; -+ int n_pkgs; -+ int j; -+ -+ for (i = 0; i < n_providers; i++) { -+ abstract_pkg_t *papkg = apkgs[i]; -+ pkg_vec_t *pkg_vec = papkg->pkgs; -+ if (pkg_vec) { -+ n_pkgs = pkg_vec->len; -+ for (j = 0; j < n_pkgs; j++) { -+ pkg_t *pkg = pkg_vec->pkgs[j]; -+ if (version_constraints_satisfied(depend, pkg)) { -+ if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) -+ return 1; -+ } -+ } -+ } -+ } -+ return 0; -+} -+ -+static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg) -+{ -+ register int i; -+ pkg_t ** pkgs = vec->pkgs; -+ -+ for(i = 0; i < vec->len; i++) -+ if((strcmp(pkg->name, (*(pkgs + i))->name) == 0) -+ && (pkg_compare_versions(pkg, *(pkgs + i)) == 0) -+ && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0)) -+ return 1; -+ return 0; -+} -+ -+ -+#ifdef DeadCode -+/** -+ * pkg_has_common_provides returns 1 if pkg and replacee both provide -+ * the same abstract package and 0 otherwise. -+ */ -+int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee) -+{ -+ abstract_pkg_t **provides = pkg->provides; -+ int provides_count = pkg->provides_count; -+ abstract_pkg_t **replacee_provides = replacee->provides; -+ int replacee_provides_count = replacee->provides_count; -+ int i, j; -+ for (i = 0; i < provides_count; i++) { -+ abstract_pkg_t *apkg = provides[i]; -+ for (j = 0; j < replacee_provides_count; j++) { -+ abstract_pkg_t *replacee_apkg = replacee_provides[i]; -+ if (apkg == replacee_apkg) -+ return 1; -+ } -+ } -+ return 0; -+} -+#endif -+ -+/** -+ * pkg_provides_abstract returns 1 if pkg->provides contains providee -+ * and 0 otherwise. -+ */ -+int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee) -+{ -+ abstract_pkg_t **provides = pkg->provides; -+ int provides_count = pkg->provides_count; -+ int i; -+ for (i = 0; i < provides_count; i++) { -+ if (provides[i] == providee) -+ return 1; -+ } -+ return 0; -+} -+ -+/** -+ * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0 -+ * otherwise. -+ */ -+int pkg_replaces(pkg_t *pkg, pkg_t *replacee) -+{ -+ abstract_pkg_t **replaces = pkg->replaces; -+ int replaces_count = pkg->replaces_count; -+ /* abstract_pkg_t **replacee_provides = pkg->provides; -+ int replacee_provides_count = pkg->provides_count; */ -+ int i, j; -+ for (i = 0; i < replaces_count; i++) { -+ abstract_pkg_t *abstract_replacee = replaces[i]; -+ for (j = 0; j < replaces_count; j++) { -+ /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n", -+ pkg->name,replacee->provides[j]->name, abstract_replacee->name); */ -+ if (replacee->provides[j] == abstract_replacee) -+ return 1; -+ } -+ } -+ return 0; -+} -+ -+ -+/** -+ * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0 -+ * otherwise. -+ */ -+int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee) -+{ -+ compound_depend_t *conflicts = pkg->conflicts; -+ int conflicts_count = pkg->conflicts_count; -+ int i, j; -+ for (i = 0; i < conflicts_count; i++) { -+ int possibility_count = conflicts[i].possibility_count; -+ struct depend **possibilities = conflicts[i].possibilities; -+ for (j = 0; j < possibility_count; j++) { -+ if (possibilities[j]->pkg == conflictee) { -+ return 1; -+ } -+ } -+ } -+ return 0; -+} -+ -+/** -+ * pkg_conflicts returns 1 if pkg->conflicts contains one of -+ * conflictee's provides and 0 otherwise. -+ */ -+int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee) -+{ -+ compound_depend_t *conflicts = pkg->conflicts; -+ int conflicts_count = pkg->conflicts_count; -+ abstract_pkg_t **conflictee_provides = conflictee->provides; -+ int conflictee_provides_count = conflictee->provides_count; -+ int i, j, k; -+ int possibility_count; -+ struct depend **possibilities; -+ abstract_pkg_t *possibility ; -+ -+ for (i = 0; i < conflicts_count; i++) { -+ possibility_count = conflicts[i].possibility_count; -+ possibilities = conflicts[i].possibilities; -+ for (j = 0; j < possibility_count; j++) { -+ possibility = possibilities[j]->pkg; -+ for (k = 0; k < conflictee_provides_count; k++) { -+ if (possibility == conflictee_provides[k]) { -+ return 1; -+ } -+ } -+ } -+ } -+ return 0; -+} -+ -+static char ** merge_unresolved(char ** oldstuff, char ** newstuff) -+{ -+ int oldlen = 0, newlen = 0; -+ char ** result; -+ register int i, j; -+ -+ if(!newstuff) -+ return oldstuff; -+ -+ while(oldstuff && oldstuff[oldlen]) oldlen++; -+ while(newstuff && newstuff[newlen]) newlen++; -+ -+ result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1)); -+ if (result == NULL) { -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ -+ for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++) -+ *(result + i) = *(newstuff + j); -+ -+ *(result + i) = NULL; -+ -+ return result; -+} -+ -+/* -+ * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre) -+ * this is null terminated, no count is carried around -+ */ -+char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx) -+{ -+ int count; -+ char ** resized; -+ char *depend_str = pkg_depend_str(pkg, ref_ndx); -+ -+ count = 0; -+ while(the_lost && the_lost[count]) count++; -+ -+ count++; /* need one to hold the null */ -+ resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1)); -+ if (resized == NULL) { -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ resized[count - 1] = strdup(depend_str); -+ resized[count] = NULL; -+ -+ return resized; -+} -+ -+void printDepends(pkg_t * pkg) -+{ -+ register int i, j; -+ compound_depend_t * depend; -+ int count; -+ -+ count = pkg->pre_depends_count + pkg->depends_count; -+ -+ depend = pkg->depends; -+ if(!depend){ -+ fprintf(stderr, "Depends pointer is NULL\n"); -+ return; -+ } -+ for(i = 0; i < count; i++){ -+ fprintf(stderr, "%s has %d possibilities:\n", -+ (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"), -+ depend->possibility_count); -+ for(j = 0; j < depend->possibility_count; j++) -+ fprintf(stderr, "\t%s version %s (%d)\n", -+ depend->possibilities[j]->pkg->name, -+ depend->possibilities[j]->version, -+ depend->possibilities[j]->constraint); -+ depend++; -+ } -+} -+ -+int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) -+{ -+ register int i, j; -+ -+ /* every pkg provides itself */ -+ abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg); -+ -+ if (!pkg->provides_count) -+ return 0; -+ -+ pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1)); -+ if (pkg->provides == NULL) { -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return -1 ; -+ } -+ pkg->provides[0] = ab_pkg; -+ -+ // if (strcmp(ab_pkg->name, pkg->name)) -+ // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name); -+ -+ for(i = 0; i < pkg->provides_count; i++){ -+ abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]); -+ -+ pkg->provides[i+1] = provided_abpkg; -+ -+ j = 0; -+ abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg); -+ } -+ return 0; -+} -+ -+/* Abhaya: added conflicts support */ -+int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) -+{ -+ register int i; -+ compound_depend_t * conflicts; -+ -+ if (!pkg->conflicts_count) -+ return 0; -+ -+ conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) * -+ pkg->conflicts_count); -+ if (conflicts == NULL) { -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return -1; -+ } -+ for (i = 0; i < pkg->conflicts_count; i++) { -+ conflicts->type = CONFLICTS; -+ parseDepends(conflicts, hash, -+ pkg->conflicts_str[i]); -+#if 0 -+ for (j = 0; j < conflicts->possibility_count; j++) { -+ depend_t *possibility = conflicts->possibilities[j]; -+ abstract_pkg_t *conflicting_apkg = possibility->pkg; -+ pkg_add_conflict_pair(ab_pkg, conflicting_apkg); -+ } -+#endif -+ conflicts++; -+ } -+ return 0; -+} -+ -+int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) -+{ -+ register int i, j; -+ -+ if (!pkg->replaces_count) -+ return 0; -+ -+ pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count); -+ if (pkg->replaces == NULL) { -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return -1; -+ } -+ -+ // if (strcmp(ab_pkg->name, pkg->name)) -+ // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name); -+ -+ for(i = 0; i < pkg->replaces_count; i++){ -+ abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]); -+ -+ pkg->replaces[i] = old_abpkg; -+ -+ j = 0; -+ if (!old_abpkg->replaced_by) -+ old_abpkg->replaced_by = abstract_pkg_vec_alloc(); -+ if ( old_abpkg->replaced_by == NULL ){ -+ return -1; -+ } -+ /* if a package pkg both replaces and conflicts old_abpkg, -+ * then add it to the replaced_by vector so that old_abpkg -+ * will be upgraded to ab_pkg automatically */ -+ if (pkg_conflicts_abstract(pkg, old_abpkg)) -+ abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg); -+ } -+ return 0; -+} -+ -+int buildDepends(hash_table_t * hash, pkg_t * pkg) -+{ -+ int count; -+ register int i; -+ compound_depend_t * depends; -+ -+ if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count)) -+ return 0; -+ -+ if (0 && pkg->pre_depends_count) -+ fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n", -+ pkg->name, pkg->pre_depends_count, pkg->depends_count); -+ depends = pkg->depends = malloc(sizeof(compound_depend_t) * count); -+ if (depends == NULL) { -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return -1; -+ } -+ -+ -+ for(i = 0; i < pkg->pre_depends_count; i++){ -+ parseDepends(depends, hash, pkg->pre_depends_str[i]); -+ if (0 && pkg->pre_depends_count) -+ fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n", -+ pkg->pre_depends_str[i], depends, depends->possibility_count); -+ depends->type = PREDEPEND; -+ depends++; -+ } -+ -+ for(i = 0; i < pkg->recommends_count; i++){ -+ parseDepends(depends, hash, pkg->recommends_str[i]); -+ if (0 && pkg->recommends_count) -+ fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n", -+ pkg->recommends_str[i], depends, depends->possibility_count); -+ depends->type = RECOMMEND; -+ depends++; -+ } -+ -+ for(i = 0; i < pkg->suggests_count; i++){ -+ parseDepends(depends, hash, pkg->suggests_str[i]); -+ if (0 && pkg->suggests_count) -+ fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n", -+ pkg->suggests_str[i], depends, depends->possibility_count); -+ depends->type = SUGGEST; -+ depends++; -+ } -+ -+ for(i = 0; i < pkg->depends_count; i++){ -+ parseDepends(depends, hash, pkg->depends_str[i]); -+ if (0 && pkg->depends_count) -+ fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n", -+ pkg->depends_str[i], depends, depends->possibility_count); -+ depends++; -+ } -+ return 0; -+} -+ -+/* -+ * pkg_depend_string: returns the depends string specified by index. -+ * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0. -+ * [0,npredepends) -> returns pre_depends_str[index] -+ * [npredepends,npredepends+nrecommends) -> returns recommends_str[index] -+ * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index] -+ * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index] -+ */ -+char *pkg_depend_str(pkg_t *pkg, int pkg_index) -+{ -+ if (pkg_index < pkg->pre_depends_count) { -+ return pkg->pre_depends_str[pkg_index]; -+ } -+ pkg_index -= pkg->pre_depends_count; -+ -+ if (pkg_index < pkg->recommends_count) { -+ return pkg->recommends_str[pkg_index]; -+ } -+ pkg_index -= pkg->recommends_count; -+ -+ if (pkg_index < pkg->suggests_count) { -+ return pkg->suggests_str[pkg_index]; -+ } -+ pkg_index -= pkg->suggests_count; -+ -+ if (pkg_index < pkg->depends_count) { -+ return pkg->depends_str[pkg_index]; -+ } -+ fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", pkg_index, pkg->name); -+ return NULL; -+} -+ -+void freeDepends(pkg_t *pkg) -+{ -+ int i; -+ -+ if (pkg == NULL || pkg->depends == NULL) { -+ return; -+ } -+ -+ fprintf(stderr, "Freeing depends=%p\n", pkg->depends); -+ for (i=0; i < pkg->depends->possibility_count; i++) { -+ depend_deinit(pkg->depends->possibilities[i]); -+ } -+ free(pkg->depends->possibilities); -+ free(pkg->depends); -+ pkg->depends = NULL; -+} -+ -+void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg) -+{ -+ compound_depend_t * depends; -+ int count, othercount; -+ register int i, j; -+ abstract_pkg_t * ab_depend; -+ abstract_pkg_t ** temp; -+ -+ count = pkg->pre_depends_count + pkg->depends_count; -+ depends = pkg->depends; -+ -+ if (0 && pkg->pre_depends_count) -+ fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n", -+ pkg->name, pkg->pre_depends_count, pkg->depends_count); -+ for (i = 0; i < count; i++) { -+ if (0 && pkg->pre_depends_count) -+ fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends); -+ for (j = 0; j < depends->possibility_count; j++){ -+ ab_depend = depends->possibilities[j]->pkg; -+ if(!ab_depend->depended_upon_by) -+ ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *)); -+ -+ temp = ab_depend->depended_upon_by; -+ othercount = 1; -+ while(*temp){ -+ temp++; -+ othercount++; -+ } -+ *temp = ab_pkg; -+ -+ ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by, -+ (othercount + 1) * sizeof(abstract_pkg_t *)); -+ /* the array may have moved */ -+ temp = ab_depend->depended_upon_by + othercount; -+ *temp = NULL; -+ } -+ depends++; -+ } -+} -+ -+static depend_t * depend_init(void) -+{ -+ depend_t * d = (depend_t *)malloc(sizeof(depend_t)); -+ if ( d==NULL ){ -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ d->constraint = NONE; -+ d->version = NULL; -+ d->pkg = NULL; -+ -+ return d; -+} -+ -+static void depend_deinit(depend_t *d) -+{ -+ free(d); -+} -+ -+static int parseDepends(compound_depend_t *compound_depend, -+ hash_table_t * hash, char * depend_str) -+{ -+ char * pkg_name, buffer[2048]; -+ int num_of_ors = 0; -+ register int i; -+ register char * src, * dest; -+ depend_t ** possibilities; -+ -+ /* first count the number of ored possibilities for satisfying dependency */ -+ src = depend_str; -+ while(*src) -+ if(*src++ == '|') -+ num_of_ors++; -+ -+ compound_depend->type = DEPEND; -+ -+ compound_depend->possibility_count = num_of_ors + 1; -+ possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1)); -+ if (!possibilities) -+ return -ENOMEM; -+ compound_depend->possibilities = possibilities; -+ -+ src = depend_str; -+ for(i = 0; i < num_of_ors + 1; i++){ -+ possibilities[i] = depend_init(); -+ if (!possibilities[i]) -+ return -ENOMEM; -+ /* gobble up just the name first */ -+ dest = buffer; -+ while(*src && -+ !isspace(*src) && -+ (*src != '(') && -+ (*src != '*') && -+ (*src != '|')) -+ *dest++ = *src++; -+ *dest = '\0'; -+ pkg_name = trim_alloc(buffer); -+ if (pkg_name == NULL ) -+ return -ENOMEM; -+ -+ /* now look at possible version info */ -+ -+ /* skip to next chars */ -+ if(isspace(*src)) -+ while(*src && isspace(*src)) src++; -+ -+ /* extract constraint and version */ -+ if(*src == '('){ -+ src++; -+ if(!strncmp(src, "<<", 2)){ -+ possibilities[i]->constraint = EARLIER; -+ src += 2; -+ } -+ else if(!strncmp(src, "<=", 2)){ -+ possibilities[i]->constraint = EARLIER_EQUAL; -+ src += 2; -+ } -+ else if(!strncmp(src, ">=", 2)){ -+ possibilities[i]->constraint = LATER_EQUAL; -+ src += 2; -+ } -+ else if(!strncmp(src, ">>", 2)){ -+ possibilities[i]->constraint = LATER; -+ src += 2; -+ } -+ else if(!strncmp(src, "=", 1)){ -+ possibilities[i]->constraint = EQUAL; -+ src++; -+ } -+ /* should these be here to support deprecated designations; dpkg does */ -+ else if(!strncmp(src, "<", 1)){ -+ possibilities[i]->constraint = EARLIER_EQUAL; -+ src++; -+ } -+ else if(!strncmp(src, ">", 1)){ -+ possibilities[i]->constraint = LATER_EQUAL; -+ src++; -+ } -+ -+ /* now we have any constraint, pass space to version string */ -+ while(isspace(*src)) src++; -+ -+ /* this would be the version string */ -+ dest = buffer; -+ while(*src && *src != ')') -+ *dest++ = *src++; -+ *dest = '\0'; -+ -+ possibilities[i]->version = trim_alloc(buffer); -+ /* fprintf(stderr, "let's print the depends version string:"); -+ fprintf(stderr, "version %s\n", possibilities[i]->version);*/ -+ if (possibilities[i]->version == NULL ) -+ return -ENOMEM; -+ -+ -+ } -+ /* hook up the dependency to its abstract pkg */ -+ possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name); -+ -+ free(pkg_name); -+ -+ /* now get past the ) and any possible | chars */ -+ while(*src && -+ (isspace(*src) || -+ (*src == ')') || -+ (*src == '|'))) -+ src++; -+ if (*src == '*') -+ { -+ compound_depend->type = GREEDY_DEPEND; -+ src++; -+ } -+ } -+ -+ return 0; -+} -Index: busybox-1.4.2/archival/libipkg/pkg_depends.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg_depends.h 2007-06-04 13:21:36.724393712 +0200 -@@ -0,0 +1,105 @@ -+/* pkg_depends.h - the itsy package management system -+ -+ Steven M. Ayer -+ -+ Copyright (C) 2002 Compaq Computer Corporation -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef PKG_DEPENDS_H -+#define PKG_DEPENDS_H -+ -+#include "pkg.h" -+#include "pkg_hash.h" -+ -+enum depend_type { -+ PREDEPEND, -+ DEPEND, -+ CONFLICTS, -+ GREEDY_DEPEND, -+ RECOMMEND, -+ SUGGEST -+}; -+typedef enum depend_type depend_type_t; -+ -+enum version_constraint { -+ NONE, -+ EARLIER, -+ EARLIER_EQUAL, -+ EQUAL, -+ LATER_EQUAL, -+ LATER -+}; -+typedef enum version_constraint version_constraint_t; -+ -+struct depend{ -+ version_constraint_t constraint; -+ char * version; -+ abstract_pkg_t * pkg; -+}; -+typedef struct depend depend_t; -+ -+struct compound_depend{ -+ depend_type_t type; -+ int possibility_count; -+ struct depend ** possibilities; -+}; -+typedef struct compound_depend compound_depend_t; -+ -+#include "hash_table.h" -+ -+int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg); -+int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg); -+int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg); -+int buildDepends(hash_table_t * hash, pkg_t * pkg); -+ -+/** -+ * pkg_has_common_provides returns 1 if pkg and replacee both provide -+ * the same abstract package and 0 otherwise. -+ */ -+int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee); -+ -+/** -+ * pkg_provides returns 1 if pkg->provides contains providee and 0 -+ * otherwise. -+ */ -+int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee); -+ -+/** -+ * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0 -+ * otherwise. -+ */ -+int pkg_replaces(pkg_t *pkg, pkg_t *replacee); -+ -+/** -+ * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0 -+ * otherwise. -+ */ -+int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts); -+ -+/** -+ * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0 -+ * otherwise. -+ */ -+int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts); -+ -+char *pkg_depend_str(pkg_t *pkg, int pkg_index); -+void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg); -+void freeDepends(pkg_t *pkg); -+void printDepends(pkg_t * pkg); -+int version_constraints_satisfied(depend_t * depends, pkg_t * pkg); -+int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved); -+pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg); -+int pkg_dependence_satisfiable(ipkg_conf_t *conf, depend_t *depend); -+int pkg_dependence_satisfied(ipkg_conf_t *conf, depend_t *depend); -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/pkg_dest.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg_dest.c 2007-06-04 13:21:36.725393560 +0200 -@@ -0,0 +1,92 @@ -+/* pkg_dest.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+ -+#include "pkg_dest.h" -+#include "file_util.h" -+#include "str_util.h" -+#include "sprintf_alloc.h" -+ -+int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir) -+{ -+ dest->name = strdup(name); -+ -+ /* Guarantee that dest->root_dir ends with a '/' */ -+ if (str_ends_with(root_dir, "/")) { -+ dest->root_dir = strdup(root_dir); -+ } else { -+ sprintf_alloc(&dest->root_dir, "%s/", root_dir); -+ } -+ file_mkdir_hier(dest->root_dir, 0755); -+ -+ sprintf_alloc(&dest->ipkg_dir, "%s%s", -+ dest->root_dir, IPKG_STATE_DIR_PREFIX); -+ file_mkdir_hier(dest->ipkg_dir, 0755); -+ -+ if (str_starts_with (lists_dir, "/")) -+ sprintf_alloc(&dest->lists_dir, "%s", lists_dir); -+ else -+ sprintf_alloc(&dest->lists_dir, "/%s", lists_dir); -+ -+ file_mkdir_hier(dest->lists_dir, 0755); -+ -+ sprintf_alloc(&dest->info_dir, "%s/%s", -+ dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX); -+ file_mkdir_hier(dest->info_dir, 0755); -+ -+ sprintf_alloc(&dest->status_file_name, "%s/%s", -+ dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX); -+ -+ sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp", -+ dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX); -+ -+ dest->status_file = NULL; -+ -+ return 0; -+} -+ -+void pkg_dest_deinit(pkg_dest_t *dest) -+{ -+ free(dest->name); -+ dest->name = NULL; -+ -+ free(dest->root_dir); -+ dest->root_dir = NULL; -+ -+ free(dest->ipkg_dir); -+ dest->ipkg_dir = NULL; -+ -+ free(dest->lists_dir); -+ dest->lists_dir = NULL; -+ -+ free(dest->info_dir); -+ dest->info_dir = NULL; -+ -+ free(dest->status_file_name); -+ dest->status_file_name = NULL; -+ -+ free(dest->status_file_tmp_name); -+ dest->status_file_tmp_name = NULL; -+ -+ if (dest->status_file) { -+ fclose(dest->status_file); -+ } -+ dest->status_file = NULL; -+ -+ dest->root_dir = NULL; -+} -Index: busybox-1.4.2/archival/libipkg/pkg_dest.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg_dest.h 2007-06-04 13:21:36.725393560 +0200 -@@ -0,0 +1,38 @@ -+/* pkg_dest.h - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef PKG_DEST_H -+#define PKG_DEST_H -+ -+typedef struct pkg_dest pkg_dest_t; -+struct pkg_dest -+{ -+ char *name; -+ char *root_dir; -+ char *ipkg_dir; -+ char *lists_dir; -+ char *info_dir; -+ char *status_file_name; -+ char *status_file_tmp_name; -+ FILE *status_file; -+}; -+ -+int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir); -+void pkg_dest_deinit(pkg_dest_t *dest); -+ -+#endif -+ -Index: busybox-1.4.2/archival/libipkg/pkg_dest_list.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg_dest_list.c 2007-06-04 13:21:36.725393560 +0200 -@@ -0,0 +1,85 @@ -+/* pkg_dest_list.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+ -+#include "pkg_dest.h" -+#include "void_list.h" -+#include "pkg_dest_list.h" -+ -+int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data) -+{ -+ return void_list_elt_init((void_list_elt_t *) elt, data); -+} -+ -+void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt) -+{ -+ void_list_elt_deinit((void_list_elt_t *) elt); -+} -+ -+int pkg_dest_list_init(pkg_dest_list_t *list) -+{ -+ return void_list_init((void_list_t *) list); -+} -+ -+void pkg_dest_list_deinit(pkg_dest_list_t *list) -+{ -+ pkg_dest_list_elt_t *iter; -+ pkg_dest_t *pkg_dest; -+ -+ for (iter = list->head; iter; iter = iter->next) { -+ pkg_dest = iter->data; -+ pkg_dest_deinit(pkg_dest); -+ -+ /* malloced in pkg_dest_list_append */ -+ free(pkg_dest); -+ iter->data = NULL; -+ } -+ void_list_deinit((void_list_t *) list); -+} -+ -+pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name, -+ const char *root_dir,const char *lists_dir) -+{ -+ int err; -+ pkg_dest_t *pkg_dest; -+ -+ /* freed in plg_dest_list_deinit */ -+ pkg_dest = malloc(sizeof(pkg_dest_t)); -+ if (pkg_dest == NULL) { -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ -+ pkg_dest_init(pkg_dest, name, root_dir,lists_dir); -+ err = void_list_append((void_list_t *) list, pkg_dest); -+ if (err) { -+ return NULL; -+ } -+ -+ return pkg_dest; -+} -+ -+int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data) -+{ -+ return void_list_push((void_list_t *) list, data); -+} -+ -+pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list) -+{ -+ return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list); -+} -Index: busybox-1.4.2/archival/libipkg/pkg_dest_list.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg_dest_list.h 2007-06-04 13:21:36.725393560 +0200 -@@ -0,0 +1,50 @@ -+/* pkg_dest_list.h - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef PKG_DEST_LIST_H -+#define PKG_DEST_LIST_H -+ -+#include "pkg_dest.h" -+ -+typedef struct pkg_dest_list_elt pkg_dest_list_elt_t; -+struct pkg_dest_list_elt -+{ -+ pkg_dest_list_elt_t *next; -+ pkg_dest_t *data; -+}; -+ -+typedef struct pkg_dest_list pkg_dest_list_t; -+struct pkg_dest_list -+{ -+ pkg_dest_list_elt_t pre_head; -+ pkg_dest_list_elt_t *head; -+ pkg_dest_list_elt_t *tail; -+}; -+ -+int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data); -+void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt); -+ -+int pkg_dest_list_init(pkg_dest_list_t *list); -+void pkg_dest_list_deinit(pkg_dest_list_t *list); -+ -+pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name, -+ const char *root_dir,const char* lists_dir); -+int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data); -+pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list); -+ -+#endif -+ -Index: busybox-1.4.2/archival/libipkg/pkg_extract.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg_extract.c 2007-06-04 13:21:36.726393408 +0200 -@@ -0,0 +1,224 @@ -+/* pkg_extract.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+#include -+#include -+#include -+ -+#include "pkg_extract.h" -+ -+#include "libbb.h" -+#include "file_util.h" -+#include "sprintf_alloc.h" -+#include "unarchive.h" -+ -+#define IPKG_CONTROL_ARCHIVE "control.tar.gz" -+#define IPKG_DATA_ARCHIVE "data.tar.gz" -+#define IPKG_CONTROL_FILE "control" -+ -+static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename) -+{ -+ archive_handle_t *archive; -+ char *path; -+ -+ sprintf_alloc(&path, "%s/", dir); -+ archive = init_handle(); -+ archive->src_fd = xopen(pkg->local_filename, O_RDONLY); -+ archive->filter = filter_accept_list; -+ llist_add_to(&(archive->accept), (char *)filename); -+ archive->buffer = path; -+ archive->action_data = data_extract_all_prefix; -+ archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL; -+ while( get_header_tar_gz(archive) == EXIT_SUCCESS ); -+ close(archive->src_fd); -+ free(archive->accept); -+ free(archive); -+ free(path); -+} -+ -+static void data_extract_file_name_to_buffer(archive_handle_t *archive) -+{ -+ unsigned int size = strlen(archive->file_header->name) + 2; -+ -+ if (archive->buffer == NULL) { -+ archive->buffer = xmalloc(size); -+ strcpy(archive->buffer, archive->file_header->name); -+ } else { -+ size += strlen(archive->buffer); -+ archive->buffer = xrealloc(archive->buffer, size); -+ strcat(archive->buffer, archive->file_header->name); -+ } -+ strcat(archive->buffer, "\n"); -+ data_skip(archive); -+} -+ -+int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream) -+{ -+ archive_handle_t *archive; -+ char *name; -+ -+ extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE); -+ sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE); -+ archive = init_handle(); -+ archive->src_fd = xopen(name, O_RDONLY); -+ archive->filter = filter_accept_list; -+ llist_add_to(&(archive->accept), "./" IPKG_CONTROL_FILE); -+ archive->action_data = data_extract_to_buffer; -+ while( get_header_tar_gz(archive) == EXIT_SUCCESS ); -+ close(archive->src_fd); -+ fputs(archive->buffer, stream); -+ free(archive->buffer); -+ free(archive->accept); -+ free(archive); -+ free(name); -+ -+ return 0; -+} -+ -+int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir) -+{ -+ return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, ""); -+} -+ -+int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix) -+{ -+ archive_handle_t *archive; -+ char *name; -+ char *path; -+ -+ extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE); -+ sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE); -+ sprintf_alloc(&path, "%s/%s", dir, prefix); -+ archive = init_handle(); -+ archive->src_fd = xopen(name, O_RDONLY); -+ archive->filter = filter_accept_all; -+ archive->buffer = path; -+ archive->action_data = data_extract_all_prefix; -+ archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL; -+ while( get_header_tar_gz(archive) == EXIT_SUCCESS ); -+ close(archive->src_fd); -+ free(archive); -+ free(path); -+ free(name); -+ -+ return 0; -+} -+ -+int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir) -+{ -+ archive_handle_t *archive; -+ char *name; -+ char *path; -+ -+ extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE); -+ sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE); -+ sprintf_alloc(&path, "%s/", dir); -+ archive = init_handle(); -+ archive->src_fd = xopen(name, O_RDONLY); -+ archive->filter = filter_accept_all; -+ archive->buffer = path; -+ archive->action_data = data_extract_all_prefix; -+ archive->flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL; -+ while( get_header_tar_gz(archive) == EXIT_SUCCESS ); -+ close(archive->src_fd); -+ free(archive); -+ free(path); -+ free(name); -+ -+ return 0; -+} -+ -+int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name) -+{ -+ int err=0; -+ char *line, *data_file; -+ FILE *file; -+ FILE *tmp; -+ -+ file = fopen(file_name, "w"); -+ if (file == NULL) { -+ fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n", -+ __FUNCTION__, file_name); -+ return EINVAL; -+ } -+ -+ tmp = tmpfile(); -+ if (pkg->installed_files) { -+ str_list_elt_t *elt; -+ for (elt = pkg->installed_files->head; elt; elt = elt->next) { -+ fprintf(file, "%s\n", elt->data); -+ } -+ } else { -+ err = pkg_extract_data_file_names_to_stream(pkg, tmp); -+ if (err) { -+ fclose(file); -+ fclose(tmp); -+ return err; -+ } -+ -+ /* Fixup data file names by removing the initial '.' */ -+ rewind(tmp); -+ while (1) { -+ line = file_read_line_alloc(tmp); -+ if (line == NULL) { -+ break; -+ } -+ -+ data_file = line; -+ if (*data_file == '.') { -+ data_file++; -+ } -+ -+ if (*data_file != '/') { -+ fputs("/", file); -+ } -+ -+ /* I have no idea why, but this is what dpkg does */ -+ if (strcmp(data_file, "/\n") == 0) { -+ fputs("/.\n", file); -+ } else { -+ fputs(data_file, file); -+ } -+ } -+ } -+ fclose(tmp); -+ fclose(file); -+ -+ return err; -+} -+ -+int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file) -+{ -+ archive_handle_t *archive; -+ char *name; -+ -+ extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE); -+ sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE); -+ archive = init_handle(); -+ archive->src_fd = xopen(name, O_RDONLY); -+ archive->filter = filter_accept_all; -+ archive->action_data = data_extract_file_name_to_buffer; -+ while( get_header_tar_gz(archive) == EXIT_SUCCESS ); -+ close(archive->src_fd); -+ fputs(archive->buffer, file); -+ free(archive->buffer); -+ free(archive); -+ free(name); -+ -+ return 0; -+} -Index: busybox-1.4.2/archival/libipkg/pkg_extract.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg_extract.h 2007-06-04 13:21:36.726393408 +0200 -@@ -0,0 +1,32 @@ -+/* pkg_extract.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef PKG_EXTRACT_H -+#define PKG_EXTRACT_H -+ -+#include "pkg.h" -+ -+int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream); -+int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir); -+int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, -+ const char *dir, -+ const char *prefix); -+int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir); -+int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name); -+int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file); -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/pkg.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg.h 2007-06-04 13:21:36.726393408 +0200 -@@ -0,0 +1,232 @@ -+/* pkg.h - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef PKG_H -+#define PKG_H -+ -+#include -+#include -+#include -+ -+#include "pkg_vec.h" -+#include "str_list.h" -+#include "pkg_src.h" -+#include "pkg_dest.h" -+#include "ipkg_conf.h" -+#include "conffile_list.h" -+ -+struct ipkg_conf; -+ -+ -+#define ARRAY_SIZE(array) sizeof(array) / sizeof((array)[0]) -+ -+/* I think "Size" is currently the shortest field name */ -+#define PKG_MINIMUM_FIELD_NAME_LEN 4 -+ -+enum pkg_state_want -+{ -+ SW_UNKNOWN = 1, -+ SW_INSTALL, -+ SW_DEINSTALL, -+ SW_PURGE, -+ SW_LAST_STATE_WANT -+}; -+typedef enum pkg_state_want pkg_state_want_t; -+ -+enum pkg_state_flag -+{ -+ SF_OK = 0, -+ SF_REINSTREQ = 1, -+ SF_HOLD = 2, /* do not upgrade version */ -+ SF_REPLACE = 4, /* replace this package */ -+ SF_NOPRUNE = 8, /* do not remove obsolete files */ -+ SF_PREFER = 16, /* prefer this version */ -+ SF_OBSOLETE = 32, /* old package in upgrade pair */ -+ SF_MARKED = 64, /* temporary mark */ -+ SF_FILELIST_CHANGED = 128, /* needs filelist written */ -+ SF_USER = 256, -+ SF_LAST_STATE_FLAG -+}; -+typedef enum pkg_state_flag pkg_state_flag_t; -+#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER) -+ -+enum pkg_state_status -+{ -+ SS_NOT_INSTALLED = 1, -+ SS_UNPACKED, -+ SS_HALF_CONFIGURED, -+ SS_INSTALLED, -+ SS_HALF_INSTALLED, -+ SS_CONFIG_FILES, -+ SS_POST_INST_FAILED, -+ SS_REMOVAL_FAILED, -+ SS_LAST_STATE_STATUS -+}; -+typedef enum pkg_state_status pkg_state_status_t; -+ -+struct abstract_pkg{ -+ char * name; -+ int dependencies_checked; -+ pkg_vec_t * pkgs; -+ pkg_state_status_t state_status; -+ pkg_state_flag_t state_flag; -+ struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */ -+ abstract_pkg_vec_t * provided_by; -+ abstract_pkg_vec_t * replaced_by; -+}; -+ -+#include "pkg_depends.h" -+ -+/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways: -+ -+ The 3 version fields should go into a single version struct. (This -+ is especially important since, currently, pkg->version can easily -+ be mistaken for pkg_verson_str_alloc(pkg) although they are very -+ distinct. This has been the source of multiple bugs. -+ -+ The 3 state fields could possibly also go into their own struct. -+ -+ All fields which deal with lists of packages, (Depends, -+ Pre-Depends, Provides, Suggests, Recommends, Enhances), should each -+ be handled by a single struct in pkg_t -+ -+ All string fields for which there is a small set of possible -+ values, (section, maintainer, architecture, maybe version?), that -+ are reused among different packages -- for all such packages we -+ should move from "char *"s to some atom datatype to share data -+ storage and use less memory. We might even do reference counting, -+ but probably not since most often we only create new pkg_t structs, -+ we don't often free them. */ -+struct pkg -+{ -+ char *name; -+ unsigned long epoch; -+ char *version; -+ char *revision; -+ char *familiar_revision; -+ pkg_src_t *src; -+ pkg_dest_t *dest; -+ char *architecture; -+ char *section; -+ char *maintainer; -+ char *description; -+ pkg_state_want_t state_want; -+ pkg_state_flag_t state_flag; -+ pkg_state_status_t state_status; -+ char **depends_str; -+ int depends_count; -+ char **pre_depends_str; -+ int pre_depends_count; -+ char **recommends_str; -+ int recommends_count; -+ char **suggests_str; -+ int suggests_count; -+ compound_depend_t * depends; -+ -+ /* Abhaya: new conflicts */ -+ char **conflicts_str; -+ compound_depend_t * conflicts; -+ int conflicts_count; -+ -+ char **replaces_str; -+ int replaces_count; -+ abstract_pkg_t ** replaces; -+ -+ char **provides_str; -+ int provides_count; -+ abstract_pkg_t ** provides; -+ -+ abstract_pkg_t *parent; -+ -+ pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */ -+ -+ char *filename; -+ char *local_filename; -+ char *url; -+ char *tmp_unpack_dir; -+ char *md5sum; -+ char *size; -+ char *installed_size; -+ char *priority; -+ char *source; -+ conffile_list_t conffiles; -+ time_t installed_time; -+ /* As pointer for lazy evaluation */ -+ str_list_t *installed_files; -+ /* XXX: CLEANUP: I'd like to perhaps come up with a better -+ mechanism to avoid the problem here, (which is that the -+ installed_files list was being freed from an inner loop while -+ still being used within an outer loop. */ -+ int installed_files_ref_cnt; -+ int essential; -+ int arch_priority; -+/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */ -+ int provided_by_hand; -+}; -+ -+pkg_t *pkg_new(void); -+int pkg_init(pkg_t *pkg); -+void pkg_deinit(pkg_t *pkg); -+int pkg_init_from_file(pkg_t *pkg, const char *filename); -+abstract_pkg_t *abstract_pkg_new(void); -+int abstract_pkg_init(abstract_pkg_t *ab_pkg); -+ -+/* -+ * merges fields from newpkg into oldpkg. -+ * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero -+ */ -+int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status); -+ -+char *pkg_version_str_alloc(pkg_t *pkg); -+ -+int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg); -+int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b); -+int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b); -+ -+char * pkg_formatted_info(pkg_t *pkg ); -+char * pkg_formatted_field(pkg_t *pkg, const char *field ); -+ -+void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg); -+ -+void pkg_print_info(pkg_t *pkg, FILE *file); -+void pkg_print_status(pkg_t * pkg, FILE * file); -+void pkg_print_field(pkg_t *pkg, FILE *file, const char *field); -+str_list_t *pkg_get_installed_files(pkg_t *pkg); -+int pkg_free_installed_files(pkg_t *pkg); -+int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg); -+conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name); -+int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg, -+ const char *script, const char *args); -+ -+/* enum mappings */ -+char *pkg_state_want_to_str(pkg_state_want_t sw); -+pkg_state_want_t pkg_state_want_from_str(char *str); -+char *pkg_state_flag_to_str(pkg_state_flag_t sf); -+pkg_state_flag_t pkg_state_flag_from_str(char *str); -+char *pkg_state_status_to_str(pkg_state_status_t ss); -+pkg_state_status_t pkg_state_status_from_str(char *str); -+ -+int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op); -+ -+int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg); -+int pkg_info_preinstall_check(ipkg_conf_t *conf); -+int pkg_free_installed_files(pkg_t *pkg); -+ -+int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg); -+int pkg_write_changed_filelists(ipkg_conf_t *conf); -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/pkg_hash.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg_hash.c 2007-06-04 13:21:36.727393256 +0200 -@@ -0,0 +1,616 @@ -+/* ipkg_hash.c - the itsy package management system -+ -+ Steven M. Ayer -+ -+ Copyright (C) 2002 Compaq Computer Corporation -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+#include -+#include -+#include -+#include -+ -+#include "hash_table.h" -+#include "pkg.h" -+#include "ipkg_message.h" -+#include "pkg_vec.h" -+#include "pkg_hash.h" -+#include "pkg_parse.h" -+#include "ipkg_utils.h" -+ -+static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name); -+ -+/* -+ * this will talk to both feeds-lists files and installed status files -+ * example api: -+ * -+ * hash_table_t hash; -+ * pkg_hash_init(name, &hash, 1000); -+ * pkg_hash_add_from_file(); -+ * -+ * the query function is just there as a shell to prove to me that this -+ * sort of works, but isn't far from doing something useful -+ * -+ * -sma, 12/21/01 -+ * modified: CDW 3 Jan. 2002 -+ */ -+ -+ -+ -+int pkg_hash_init(const char *name, hash_table_t *hash, int len) -+{ -+ return hash_table_init(name, hash, len); -+} -+ -+void pkg_hash_deinit(hash_table_t *hash) -+{ -+ hash_table_deinit(hash); -+} -+ -+ -+/* Find the default arch for a given package status file if none is given. */ -+static char *pkg_get_default_arch(ipkg_conf_t *conf) -+{ -+ nv_pair_list_elt_t *l; -+ char *def_arch = HOST_CPU_STR; /* Default arch */ -+ int def_prio = 0; /* Other archs override this */ -+ -+ l = conf->arch_list.head; -+ -+ while (l) { -+ nv_pair_t *nv = l->data; -+ int priority = strtol(nv->value, NULL, 0); -+ -+ /* Check if this arch has higher priority, and is valid */ -+ if ((priority > def_prio) && -+ (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) { -+ /* Our new default */ -+ def_prio = priority; -+ def_arch = nv->name; -+ } -+ l = l->next; -+ } -+ -+ return strdup(def_arch); -+} -+ -+int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name, -+ pkg_src_t *src, pkg_dest_t *dest, int is_status_file) -+{ -+ hash_table_t *hash = &conf->pkg_hash; -+ char **raw; -+ char **raw_start; -+ pkg_t *pkg; -+ -+ raw = raw_start = read_raw_pkgs_from_file(file_name); -+ if (!raw) -+ return -ENOMEM; -+ -+ while(*raw){ /* don't worry, we'll increment raw in the parsing function */ -+ pkg = pkg_new(); -+ if (!pkg) -+ return -ENOMEM; -+ -+ if (pkg_parse_raw(pkg, &raw, src, dest) == 0) { -+ if (!pkg->architecture) { -+ char *version_str = pkg_version_str_alloc(pkg); -+ pkg->architecture = pkg_get_default_arch(conf); -+ ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n", -+ pkg->name, version_str, pkg->architecture); -+ free(version_str); -+ } -+ hash_insert_pkg(hash, pkg, is_status_file,conf); -+ } else { -+ free(pkg); -+ } -+ } -+ -+ /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up -+ memory after read_raw_pkgs_from_file */ -+ raw = raw_start; -+ while (*raw) { -+ free(*raw++); -+ } -+ free(raw_start); -+ return 0; -+} -+ -+abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name) -+{ -+ return (abstract_pkg_t *)hash_table_get(hash, pkg_name); -+} -+ -+abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name) -+{ -+ abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name); -+ if (apkg) -+ return NULL; -+ return apkg->provided_by; -+} -+ -+ -+pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg, -+ int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet) -+{ -+ int i, j; -+ int nprovides = 0; -+ int nmatching = 0; -+ pkg_vec_t *matching_pkgs = pkg_vec_alloc(); -+ abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc(); -+ abstract_pkg_vec_t *provided_apkg_vec; -+ abstract_pkg_t **provided_apkgs; -+ abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc(); -+ pkg_t *latest_installed_parent = NULL; -+ pkg_t *latest_matching = NULL; -+ pkg_t *held_pkg = NULL; -+ pkg_t *good_pkg_by_name = NULL; -+ -+ if (matching_apkgs == NULL || providers == NULL || -+ apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0)) -+ return NULL; -+ -+ ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name); -+ -+ provided_apkg_vec = apkg->provided_by; -+ nprovides = provided_apkg_vec->len; -+ provided_apkgs = provided_apkg_vec->pkgs; -+ if (nprovides > 1) -+ ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides); -+ -+ /* accumulate all the providers */ -+ for (i = 0; i < nprovides; i++) { -+ abstract_pkg_t *provider_apkg = provided_apkgs[i]; -+ ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name); -+ abstract_pkg_vec_insert(providers, provider_apkg); -+ } -+ nprovides = providers->len; -+ -+ for (i = 0; i < nprovides; i++) { -+ abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i); -+ abstract_pkg_t *replacement_apkg = NULL; -+ pkg_vec_t *vec; -+ -+ if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) { -+ replacement_apkg = provider_apkg->replaced_by->pkgs[0]; -+ if (provider_apkg->replaced_by->len > 1) { -+ ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n", -+ provider_apkg->name, replacement_apkg->name); -+ } -+ } -+ -+ if (replacement_apkg) -+ ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n", -+ replacement_apkg->name, provider_apkg->name); -+ -+ if (replacement_apkg && (replacement_apkg != provider_apkg)) { -+ if (abstract_pkg_vec_contains(providers, replacement_apkg)) -+ continue; -+ else -+ provider_apkg = replacement_apkg; -+ } -+ -+ if (!(vec = provider_apkg->pkgs)) { -+ ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name); -+ continue; -+ } -+ -+ -+ /* now check for supported architecture */ -+ { -+ int max_count = 0; -+ -+ /* count packages matching max arch priority and keep track of last one */ -+ for (j = 0; j < vec->len; j++) { -+ pkg_t *maybe = vec->pkgs[j]; -+ ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n", -+ maybe->name, maybe->architecture, maybe->arch_priority, maybe->version); -+ if (maybe->arch_priority > 0) { -+ max_count++; -+ abstract_pkg_vec_insert(matching_apkgs, maybe->parent); -+ pkg_vec_insert(matching_pkgs, maybe); -+ } -+ } -+ } -+ } -+ -+ if (matching_pkgs->len > 1) -+ pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare); -+ if (matching_apkgs->len > 1) -+ abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare); -+ -+/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the -+ needed package. In this case, I would return it for install, otherwise I will continue with the procedure */ -+/* The problem is what to do when there are more than a mathing package, with the same name and several version ? -+ Until now I always got the latest, but that breaks the downgrade option. -+ If I stop at the first one, I would probably miss the new ones -+ Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file, -+ or from a Packages feed. -+ It it is from a file it always need to be checked whatever version I have in feeds or everywhere, according to force-down or whatever options*/ -+/*Pigi*/ -+ -+ for (i = 0; i < matching_pkgs->len; i++) { -+ pkg_t *matching = matching_pkgs->pkgs[i]; -+ if (constraint_fcn(matching, cdata)) { /* We found it */ -+ ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ; -+ good_pkg_by_name = matching; -+ if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */ -+ break; -+ } -+ } -+ -+ -+ for (i = 0; i < matching_pkgs->len; i++) { -+ pkg_t *matching = matching_pkgs->pkgs[i]; -+ latest_matching = matching; -+ if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED) -+ latest_installed_parent = matching; -+ if (matching->state_flag & (SF_HOLD|SF_PREFER)) { -+ if (held_pkg) -+ ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n", -+ held_pkg->name, matching->name); -+ held_pkg = matching; -+ } -+ } -+ -+ if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) { -+ ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n", -+ apkg->name, matching_apkgs->len); -+ for (i = 0; i < matching_apkgs->len; i++) { -+ abstract_pkg_t *matching = matching_apkgs->pkgs[i]; -+ ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name); -+ } -+ ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n"); -+ } -+ -+ if (matching_apkgs->len > 1 && conf->verbosity > 1) { -+ ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n", -+ __FUNCTION__, apkg->name, matching_pkgs->len); -+ for (i = 0; i < matching_pkgs->len; i++) { -+ pkg_t *matching = matching_pkgs->pkgs[i]; -+ ipkg_message(conf, IPKG_INFO, " %s %s %s\n", -+ matching->name, matching->version, matching->architecture); -+ } -+ } -+ -+ nmatching = matching_apkgs->len; -+ -+ pkg_vec_free(matching_pkgs); -+ abstract_pkg_vec_free(matching_apkgs); -+ abstract_pkg_vec_free(providers); -+ -+ if (good_pkg_by_name) { /* We found a good candidate, we will install it */ -+ return good_pkg_by_name; -+ } -+ if (held_pkg) { -+ ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name); -+ return held_pkg; -+ } -+ if (latest_installed_parent) { -+ ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name); -+ return latest_installed_parent; -+ } -+ if (nmatching > 1) { -+ ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching); -+ return NULL; -+ } -+ if (latest_matching) { -+ ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n", -+ latest_matching->name, latest_matching->version, latest_matching->architecture); -+ return latest_matching; -+ } -+ return NULL; -+} -+ -+static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata) -+{ -+ const char *name = (const char *)cdata; -+ if (strcmp(pkg->name, name) == 0) -+ return 1; -+ else -+ return 0; -+} -+ -+pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name) -+{ -+ hash_table_t *hash = &conf->pkg_hash; -+ abstract_pkg_t *apkg = NULL; -+ -+ if (!(apkg = abstract_pkg_fetch_by_name(hash, name))) -+ return NULL; -+ -+ return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0); -+} -+ -+ -+pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash, -+ const char *pkg_name, -+ const char * version) -+{ -+ pkg_vec_t * vec; -+ register int i; -+ char *version_str = NULL; -+ -+ if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) -+ return NULL; -+ -+ for(i = 0; i < vec->len; i++) { -+ version_str = pkg_version_str_alloc(vec->pkgs[i]); -+ if(!strcmp(version_str, version)) { -+ free(version_str); -+ break; -+ } -+ free(version_str); -+ } -+ -+ if(i == vec->len) -+ return NULL; -+ -+ return vec->pkgs[i]; -+} -+ -+pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash, -+ const char *pkg_name, -+ pkg_dest_t *dest) -+{ -+ pkg_vec_t * vec; -+ register int i; -+ -+ if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) { -+ return NULL; -+ } -+ -+ for(i = 0; i < vec->len; i++) -+ if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) { -+ return vec->pkgs[i]; -+ } -+ return NULL; -+} -+ -+pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash, -+ const char *pkg_name) -+{ -+ pkg_vec_t * vec; -+ register int i; -+ -+ if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){ -+ return NULL; -+ } -+ -+ for(i = 0; i < vec->len; i++) -+ if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){ -+ return vec->pkgs[i]; -+ } -+ -+ return NULL; -+} -+ -+pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name) -+{ -+ abstract_pkg_t * ab_pkg; -+ -+ if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){ -+ return NULL; -+ } -+ -+ if (ab_pkg->pkgs) { -+ return ab_pkg->pkgs; -+ } else if (ab_pkg->provided_by) { -+ abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0); -+ if (abpkg != NULL){ -+ return abpkg->pkgs; -+ } else { -+ return ab_pkg->pkgs; -+ } -+ } else { -+ return NULL; -+ } -+} -+ -+static int pkg_compare_names(const void *p1, const void *p2) -+{ -+ const pkg_t *pkg1 = *(const pkg_t **)p1; -+ const pkg_t *pkg2 = *(const pkg_t **)p2; -+ if (pkg1->name == NULL) -+ return 1; -+ if (pkg2->name == NULL) -+ return -1; -+ return(strcmp(pkg1->name, pkg2->name)); -+} -+ -+ -+static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data) -+{ -+ int j; -+ abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry; -+ pkg_vec_t *all = (pkg_vec_t *)data; -+ pkg_vec_t *pkg_vec = ab_pkg->pkgs; -+ if (pkg_vec) { -+ for (j = 0; j < pkg_vec->len; j++) { -+ pkg_t *pkg = pkg_vec->pkgs[j]; -+ pkg_vec_insert(all, pkg); -+ } -+ } -+} -+ -+void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all) -+{ -+ hash_table_foreach(hash, pkg_hash_fetch_available_helper, all); -+ qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names); -+} -+ -+static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data) -+{ -+ abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry; -+ pkg_vec_t *all = (pkg_vec_t *)data; -+ pkg_vec_t *pkg_vec = ab_pkg->pkgs; -+ int j; -+ if (pkg_vec) { -+ for (j = 0; j < pkg_vec->len; j++) { -+ pkg_t *pkg = pkg_vec->pkgs[j]; -+ if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) { -+ pkg_vec_insert(all, pkg); -+ } -+ } -+ } -+} -+void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all) -+{ -+ hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all); -+ qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names); -+} -+ -+static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data) -+{ -+ int i; -+ pkg_t *pkg; -+ abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry; -+ ipkg_conf_t *conf = (ipkg_conf_t *)data; -+ abstract_pkg_t ** dependents = ab_pkg->depended_upon_by; -+ fprintf(stdout, "%s\n", ab_pkg->name); -+ i = 0; -+ if (dependents != NULL) -+ while (dependents [i] != NULL) -+ printf ("\tdepended upon by - %s\n", dependents [i ++]->name); -+ dependents = ab_pkg->provided_by->pkgs; -+ i = 0; -+ if (dependents != NULL) -+ while (dependents [i] != NULL && i < ab_pkg->provided_by->len) -+ printf ("\tprovided by - %s\n", dependents [i ++]->name); -+ pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name); -+ if (pkg) { -+ i = 0; -+ while (i < pkg->depends_count) -+ printf ("\tdepends on - %s\n", pkg->depends_str [i ++]); -+ } -+} -+void pkg_hash_dump(hash_table_t *hash, void *data) -+{ -+ -+ printf ("\n\n+=+%s+=+\n\n", __FUNCTION__); -+ hash_table_foreach(hash, pkg_hash_dump_helper, data); -+ printf ("\n+=+%s+=+\n\n", __FUNCTION__); -+} -+ -+abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name) -+{ -+ abstract_pkg_t * ab_pkg; -+ -+ if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))) -+ ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name); -+ -+ return ab_pkg; -+} -+ -+pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf) -+{ -+ abstract_pkg_t * ab_pkg; -+ int arch_priority; -+ -+ if(!pkg) -+ return pkg; -+ -+ arch_priority = pkg->arch_priority; -+ -+ if (buildDepends(hash, pkg)<0){ -+ fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__); -+ return NULL; -+ } -+ ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name); -+ -+ if (set_status) { -+ if (pkg->state_status == SS_INSTALLED) { -+ ab_pkg->state_status = SS_INSTALLED; -+ } else if (pkg->state_status == SS_UNPACKED) { -+ ab_pkg->state_status = SS_UNPACKED; -+ } -+ } -+ -+ if(!ab_pkg->pkgs) -+ ab_pkg->pkgs = pkg_vec_alloc(); -+ -+ /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */ -+ pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf ); -+ pkg->parent = ab_pkg; -+ -+ if (buildProvides(hash, ab_pkg, pkg)<0){ -+ fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__); -+ return NULL; -+ } -+ /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */ -+ if (buildConflicts(hash, ab_pkg, pkg)<0){ -+ fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__); -+ return NULL; -+ } -+ if (buildReplaces(hash, ab_pkg, pkg)<0) { -+ fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__); -+ return NULL; -+ } -+ -+ buildDependedUponBy(pkg, ab_pkg); -+ return pkg; -+} -+ -+/* -+ * this will assume that we've already determined that -+ * the abstract pkg doesn't exist, 'cause we should know these things... -+ */ -+static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name) -+{ -+ abstract_pkg_t * ab_pkg; -+ -+ ab_pkg = abstract_pkg_new(); -+ if (ab_pkg == NULL) { return NULL; } -+ -+ ab_pkg->name = strdup(pkg_name); -+ hash_table_insert(hash, pkg_name, ab_pkg); -+ -+ return ab_pkg; -+} -+ -+ -+pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name) -+{ -+ hash_table_t *file_hash = &conf->file_hash; -+ -+ return hash_table_get(file_hash, file_name); -+} -+ -+int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg) -+{ -+ hash_table_t *file_hash = &conf->file_hash; -+ pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name); -+ int file_name_len = strlen(file_name); -+ -+ if (file_name[file_name_len -1] == '/') -+ return 0; -+ -+ if (conf->offline_root) { -+ int len = strlen(conf->offline_root); -+ if (strncmp(file_name, conf->offline_root, len) == 0) { -+ file_name += len; -+ } -+ } -+ -+ // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name); -+ hash_table_insert(file_hash, file_name, owning_pkg); -+ if (old_owning_pkg) { -+ str_list_remove_elt(old_owning_pkg->installed_files, file_name); -+ /* mark this package to have its filelist written */ -+ old_owning_pkg->state_flag |= SF_FILELIST_CHANGED; -+ owning_pkg->state_flag |= SF_FILELIST_CHANGED; -+ } -+ return 0; -+} -+ -+ -Index: busybox-1.4.2/archival/libipkg/pkg_hash.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg_hash.h 2007-06-04 13:21:36.727393256 +0200 -@@ -0,0 +1,61 @@ -+/* pkg_hash.h - the itsy package management system -+ -+ Steven M. Ayer -+ -+ Copyright (C) 2002 Compaq Computer Corporation -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef PKG_HASH_H -+#define PKG_HASH_H -+ -+#include "pkg.h" -+#include "pkg_vec.h" -+#include "hash_table.h" -+ -+ -+int pkg_hash_init(const char *name, hash_table_t *hash, int len); -+void pkg_hash_deinit(hash_table_t *hash); -+void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data); -+ -+void pkg_hash_dump(hash_table_t *hash, void *data); -+void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available); -+ -+int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name, -+ pkg_src_t *src, pkg_dest_t *dest, int is_status_file); -+pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf); -+ -+abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name); -+abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name); -+pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name); -+void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed); -+pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash, -+ const char *pkg_name, -+ const char * version); -+abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name); -+pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg, -+ int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet); -+pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name); -+pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash, -+ const char *pkg_name); -+pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash, -+ const char *pkg_name, -+ pkg_dest_t *dest); -+ -+pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name); -+int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg); -+ -+/* XXX: shouldn't this go in pkg_vec.[ch]? */ -+pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name); -+ -+#endif -+ -Index: busybox-1.4.2/archival/libipkg/pkg_parse.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg_parse.c 2007-06-04 13:21:36.727393256 +0200 -@@ -0,0 +1,366 @@ -+/* pkg_parse.c - the itsy package management system -+ -+ Steven M. Ayer -+ -+ Copyright (C) 2002 Compaq Computer Corporation -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+#include -+#include -+ -+#include "pkg.h" -+#include "ipkg_utils.h" -+#include "pkg_parse.h" -+ -+int isGenericFieldType(char * type, char * line) -+{ -+ if(!strncmp(line, type, strlen(type))) -+ return 1; -+ return 0; -+} -+ -+char * parseGenericFieldType(char * type, char * raw) -+{ -+ char * field_value = raw + (strlen(type) + 1); -+ return trim_alloc(field_value); -+} -+ -+void parseStatus(pkg_t *pkg, char * raw) -+{ -+ char sw_str[64], sf_str[64], ss_str[64]; -+ -+ sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str); -+ pkg->state_want = pkg_state_want_from_str(sw_str); -+ pkg->state_flag = pkg_state_flag_from_str(sf_str); -+ pkg->state_status = pkg_state_status_from_str(ss_str); -+} -+ -+char ** parseDependsString(char * raw, int * depends_count) -+{ -+ char ** depends = NULL; -+ int line_count = 0; -+ char buff[2048], * dest; -+ -+ while(raw && *raw && !isspace(*raw)) { -+ raw++; -+ } -+ -+ if(line_is_blank(raw)){ -+ *depends_count = line_count; -+ return NULL; -+ } -+ while(raw && *raw){ -+ depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1)); -+ -+ while(isspace(*raw)) raw++; -+ -+ dest = buff; -+ while((*raw != ',') && *raw) -+ *dest++ = *raw++; -+ -+ *dest = '\0'; -+ depends[line_count] = trim_alloc(buff); -+ if(depends[line_count] ==NULL) -+ return NULL; -+ line_count++; -+ if(*raw == ',') -+ raw++; -+ } -+ *depends_count = line_count; -+ return depends; -+} -+ -+void parseConffiles(pkg_t * pkg, char * raw) -+{ -+ char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */ -+ -+ if(!strncmp(raw, "Conffiles:", 10)) -+ raw += strlen("Conffiles:"); -+ -+ while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){ -+ conffile_list_append(&pkg->conffiles, file_name, md5sum); -+ /* fprintf(stderr, "%s %s ", file_name, md5sum);*/ -+ while (*raw && isspace(*raw)) { -+ raw++; -+ } -+ raw += strlen(file_name); -+ while (*raw && isspace(*raw)) { -+ raw++; -+ } -+ raw += strlen(md5sum); -+ } -+} -+ -+int parseVersion(pkg_t *pkg, char *raw) -+{ -+ char *colon, *eepochcolon; -+#ifdef USE_DEBVERSION -+ char *hyphen; -+#endif -+ unsigned long epoch; -+ -+ if (!*raw) { -+ fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__); -+ return EINVAL; -+ } -+ -+ if (strncmp(raw, "Version:", 8) == 0) { -+ raw += 8; -+ } -+ while (*raw && isspace(*raw)) { -+ raw++; -+ } -+ -+ colon= strchr(raw,':'); -+ if (colon) { -+ epoch= strtoul(raw,&eepochcolon,10); -+ if (colon != eepochcolon) { -+ fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__); -+ return EINVAL; -+ } -+ if (!*++colon) { -+ fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__); -+ return EINVAL; -+ } -+ raw= colon; -+ pkg->epoch= epoch; -+ } else { -+ pkg->epoch= 0; -+ } -+ -+ pkg->revision = ""; -+ pkg->familiar_revision = ""; -+ -+ pkg->version= malloc(strlen(raw)+1); -+ if ( pkg->version == NULL ) { -+ fprintf(stderr, "%s: out of memory \n", __FUNCTION__); -+ return ENOMEM; -+ } -+ strcpy(pkg->version, raw); -+ -+#ifdef USE_DEBVERSION -+ hyphen= strrchr(pkg->version,'-'); -+ -+ if (hyphen) { -+ *hyphen++= 0; -+ if (strncmp("fam", hyphen, 3) == 0) { -+ pkg->familiar_revision=hyphen+3; -+ hyphen= strrchr(pkg->version,'-'); -+ if (hyphen) { -+ *hyphen++= 0; -+ pkg->revision = hyphen; -+ } -+ } else { -+ pkg->revision = hyphen; -+ } -+ } -+#endif -+ -+/* -+ fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n", -+ pkg->epoch, -+ pkg->version, -+ pkg->revision, -+ pkg->familiar_revision); -+*/ -+ -+ return 0; -+} -+ -+ -+/* This code is needed to insert in first position the keyword for the aligning bug */ -+ -+int alterProvidesLine(char *raw, char *temp) -+{ -+ -+ -+ if (!*raw) { -+ fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__); -+ return -EINVAL; -+ } -+ -+ if ( temp == NULL ) { -+ fprintf(stderr, "%s: out of memory \n", __FUNCTION__); -+ return -ENOMEM; -+ } -+ -+ if (strncmp(raw, "Provides:", 9) == 0) { -+ raw += 9; -+ } -+ while (*raw && isspace(*raw)) { -+ raw++; -+ } -+ -+ snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */ -+ while (*raw) { -+ strncat( temp, raw++, 1); -+ } -+ return 0; -+ -+} -+ -+/* Some random thoughts from Carl: -+ -+ This function could be considerably simplified if we just kept -+ an array of all the generic string-valued field names, and looped -+ through those looking for a match. Also, these fields could perhaps -+ be stored in the package as an array as well, (or, probably better, -+ as an nv_pair_list_t). -+ -+ Fields which require special parsing or storage, (such as Depends: -+ and Status:) could be handled as they are now. -+*/ -+/* XXX: FEATURE: The Suggests: field needs to be changed from a string -+ to a dependency list. And, since we already have -+ Depends/Pre-Depends and need to add Conflicts, Recommends, and -+ Enhances, perhaps we could generalize all of these and save some -+ code duplication. -+*/ -+int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest) -+{ -+ int reading_conffiles, reading_description; -+ int pkg_false_provides=1; -+ char ** lines; -+ char * provide=NULL; -+ -+ pkg->src = src; -+ pkg->dest = dest; -+ -+ reading_conffiles = reading_description = 0; -+ -+ for (lines = *raw; *lines; lines++) { -+ /* fprintf(stderr, "PARSING %s\n", *lines);*/ -+ if(isGenericFieldType("Package:", *lines)) -+ pkg->name = parseGenericFieldType("Package", *lines); -+ else if(isGenericFieldType("Architecture:", *lines)) -+ pkg->architecture = parseGenericFieldType("Architecture", *lines); -+ else if(isGenericFieldType("Filename:", *lines)) -+ pkg->filename = parseGenericFieldType("Filename", *lines); -+ else if(isGenericFieldType("Section:", *lines)) -+ pkg->section = parseGenericFieldType("Section", *lines); -+ else if(isGenericFieldType("MD5sum:", *lines)) -+ pkg->md5sum = parseGenericFieldType("MD5sum", *lines); -+ /* The old ipkg wrote out status files with the wrong case for MD5sum, -+ let's parse it either way */ -+ else if(isGenericFieldType("MD5Sum:", *lines)) -+ pkg->md5sum = parseGenericFieldType("MD5Sum", *lines); -+ else if(isGenericFieldType("Size:", *lines)) -+ pkg->size = parseGenericFieldType("Size", *lines); -+ else if(isGenericFieldType("Source:", *lines)) -+ pkg->source = parseGenericFieldType("Source", *lines); -+ else if(isGenericFieldType("Installed-Size:", *lines)) -+ pkg->installed_size = parseGenericFieldType("Installed-Size", *lines); -+ else if(isGenericFieldType("Installed-Time:", *lines)) { -+ char *time_str = parseGenericFieldType("Installed-Time", *lines); -+ pkg->installed_time = strtoul(time_str, NULL, 0); -+ } else if(isGenericFieldType("Priority:", *lines)) -+ pkg->priority = parseGenericFieldType("Priority", *lines); -+ else if(isGenericFieldType("Essential:", *lines)) { -+ char *essential_value; -+ essential_value = parseGenericFieldType("Essential", *lines); -+ if (strcmp(essential_value, "yes") == 0) { -+ pkg->essential = 1; -+ } -+ free(essential_value); -+ } -+ else if(isGenericFieldType("Status", *lines)) -+ parseStatus(pkg, *lines); -+ else if(isGenericFieldType("Version", *lines)) -+ parseVersion(pkg, *lines); -+ else if(isGenericFieldType("Maintainer", *lines)) -+ pkg->maintainer = parseGenericFieldType("Maintainer", *lines); -+ else if(isGenericFieldType("Conffiles", *lines)){ -+ parseConffiles(pkg, *lines); -+ reading_conffiles = 1; -+ } -+ else if(isGenericFieldType("Description", *lines)) { -+ pkg->description = parseGenericFieldType("Description", *lines); -+ reading_conffiles = 0; -+ reading_description = 1; -+ } -+ -+ else if(isGenericFieldType("Provides", *lines)){ -+/* Here we add the internal_use to align the off by one problem between provides_str and provides */ -+ provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */ -+ if ( alterProvidesLine(*lines,provide) ){ -+ return EINVAL; -+ } -+ pkg->provides_str = parseDependsString( provide, &pkg->provides_count); -+/* Let's try to hack a bit here. -+ The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies -+ in alot of other places. We will remove it before writing down the status database */ -+ pkg_false_provides=0; -+ free(provide); -+ } -+ -+ else if(isGenericFieldType("Depends", *lines)) -+ pkg->depends_str = parseDependsString(*lines, &pkg->depends_count); -+ else if(isGenericFieldType("Pre-Depends", *lines)) -+ pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count); -+ else if(isGenericFieldType("Recommends", *lines)) -+ pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count); -+ else if(isGenericFieldType("Suggests", *lines)) -+ pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count); -+ /* Abhaya: support for conflicts */ -+ else if(isGenericFieldType("Conflicts", *lines)) -+ pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count); -+ else if(isGenericFieldType("Replaces", *lines)) -+ pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count); -+ else if(line_is_blank(*lines)) { -+ lines++; -+ break; -+ } -+ else if(**lines == ' '){ -+ if(reading_description) { -+ /* we already know it's not blank, so the rest of description */ -+ pkg->description = realloc(pkg->description, -+ strlen(pkg->description) -+ + 1 + strlen(*lines) + 1); -+ strcat(pkg->description, "\n"); -+ strcat(pkg->description, (*lines)); -+ } -+ else if(reading_conffiles) -+ parseConffiles(pkg, *lines); -+ } -+ } -+ *raw = lines; -+/* If the ipk has not a Provides line, we insert our false line */ -+ if ( pkg_false_provides==1) -+ pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count); -+ -+ if (pkg->name) { -+ return 0; -+ } else { -+ return EINVAL; -+ } -+} -+ -+int pkg_valorize_other_field(pkg_t *pkg, char ***raw) -+{ -+ char ** lines; -+ -+ for (lines = *raw; *lines; lines++) { -+ if(isGenericFieldType("Essential:", *lines)) { -+ char *essential_value; -+ essential_value = parseGenericFieldType("Essential", *lines); -+ if (strcmp(essential_value, "yes") == 0) { -+ pkg->essential = 1; -+ } -+ free(essential_value); -+ } -+ } -+ *raw = lines; -+ -+ return 0; -+} -Index: busybox-1.4.2/archival/libipkg/pkg_parse.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg_parse.h 2007-06-04 13:21:36.728393104 +0200 -@@ -0,0 +1,31 @@ -+/* pkg_parse.h - the itsy package management system -+ -+ Steven M. Ayer -+ -+ Copyright (C) 2002 Compaq Computer Corporation -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef PKG_PARSE_H -+#define PKG_PARSE_H -+ -+int isGenericFieldType(char * type, char * line); -+char * parseGenericFieldType(char * type, char * raw); -+void parseStatus(pkg_t *pkg, char * raw); -+int parseVersion(pkg_t *pkg, char *raw); -+char ** parseDependsString(char * raw, int * depends_count); -+int parseVersion(pkg_t *pkg, char *raw); -+void parseConffiles(pkg_t * pkg, char * raw); -+int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest); -+int pkg_valorize_other_field(pkg_t *pkg, char ***raw); -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/pkg_src.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg_src.c 2007-06-04 13:21:36.728393104 +0200 -@@ -0,0 +1,43 @@ -+/* pkg_src.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+ -+#include "pkg_src.h" -+#include "str_util.h" -+ -+int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip) -+{ -+ src->gzip = gzip; -+ src->name = str_dup_safe (name); -+ src->value = str_dup_safe (base_url); -+ if (extra_data) -+ src->extra_data = str_dup_safe (extra_data); -+ else -+ src->extra_data = NULL; -+ return 0; -+} -+ -+void pkg_src_deinit(pkg_src_t *src) -+{ -+ free (src->name); -+ free (src->value); -+ if (src->extra_data) -+ free (src->extra_data); -+} -+ -+ -Index: busybox-1.4.2/archival/libipkg/pkg_src.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg_src.h 2007-06-04 13:21:36.728393104 +0200 -@@ -0,0 +1,34 @@ -+/* pkg_src.h - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef PKG_SRC_H -+#define PKG_SRC_H -+ -+#include "nv_pair.h" -+ -+typedef struct -+{ -+ char *name; -+ char *value; -+ char *extra_data; -+ int gzip; -+} pkg_src_t; -+ -+int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip); -+void pkg_src_deinit(pkg_src_t *src); -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/pkg_src_list.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg_src_list.c 2007-06-04 13:21:36.728393104 +0200 -@@ -0,0 +1,75 @@ -+/* pkg_src_list.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+ -+#include "pkg_src_list.h" -+#include "void_list.h" -+ -+int pkg_src_list_init(pkg_src_list_t *list) -+{ -+ return void_list_init((void_list_t *) list); -+} -+ -+void pkg_src_list_deinit(pkg_src_list_t *list) -+{ -+ pkg_src_list_elt_t *iter; -+ pkg_src_t *pkg_src; -+ -+ for (iter = list->head; iter; iter = iter->next) { -+ pkg_src = iter->data; -+ pkg_src_deinit(pkg_src); -+ -+ /* malloced in pkg_src_list_append */ -+ free(pkg_src); -+ iter->data = NULL; -+ } -+ void_list_deinit((void_list_t *) list); -+} -+ -+pkg_src_t *pkg_src_list_append(pkg_src_list_t *list, -+ const char *name, const char *base_url, const char *extra_data, -+ int gzip) -+{ -+ int err; -+ -+ /* freed in pkg_src_list_deinit */ -+ pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t)); -+ -+ if (pkg_src == NULL) { -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ pkg_src_init(pkg_src, name, base_url, extra_data, gzip); -+ -+ err = void_list_append((void_list_t *) list, pkg_src); -+ if (err) { -+ return NULL; -+ } -+ -+ return pkg_src; -+} -+ -+int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data) -+{ -+ return void_list_push((void_list_t *) list, data); -+} -+ -+pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list) -+{ -+ return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list); -+} -Index: busybox-1.4.2/archival/libipkg/pkg_src_list.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg_src_list.h 2007-06-04 13:21:36.728393104 +0200 -@@ -0,0 +1,57 @@ -+/* pkg_src_list.h - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef PKG_SRC_LIST_H -+#define PKG_SRC_LIST_H -+ -+#include "pkg_src.h" -+ -+typedef struct pkg_src_list_elt pkg_src_list_elt_t; -+struct pkg_src_list_elt -+{ -+ pkg_src_list_elt_t *next; -+ pkg_src_t *data; -+}; -+ -+typedef struct pkg_src_list pkg_src_list_t; -+struct pkg_src_list -+{ -+ pkg_src_list_elt_t pre_head; -+ pkg_src_list_elt_t *head; -+ pkg_src_list_elt_t *tail; -+}; -+ -+static inline int pkg_src_list_empty(pkg_src_list_t *list) -+{ -+ if (list->head == NULL) -+ return 1; -+ else -+ return 0; -+} -+ -+int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data); -+void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt); -+ -+int pkg_src_list_init(pkg_src_list_t *list); -+void pkg_src_list_deinit(pkg_src_list_t *list); -+ -+pkg_src_t *pkg_src_list_append(pkg_src_list_t *list, const char *name, const char *root_dir, const char *extra_data, int gzip); -+int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data); -+pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list); -+ -+#endif -+ -Index: busybox-1.4.2/archival/libipkg/pkg_vec.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg_vec.c 2007-06-04 13:21:36.729392952 +0200 -@@ -0,0 +1,230 @@ -+/* pkg_vec.c - the itsy package management system -+ -+ Steven M. Ayer -+ -+ Copyright (C) 2002 Compaq Computer Corporation -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include -+#include -+#include "xregex.h" -+#include "ipkg.h" -+#include "pkg.h" -+ -+pkg_vec_t * pkg_vec_alloc(void) -+{ -+ pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t)); -+ if (!vec) { -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ vec->pkgs = NULL; -+ vec->len = 0; -+ -+ return vec; -+} -+ -+void pkg_vec_free(pkg_vec_t *vec) -+{ -+ free(vec->pkgs); -+ free(vec); -+} -+ -+/* -+ * assumption: all names in a vector are identical -+ * assumption: all version strings are trimmed, -+ * so identical versions have identical version strings, -+ * implying identical packages; let's marry these -+ */ -+pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf) -+{ -+ int i; -+ int found = 0; -+ -+ /* look for a duplicate pkg by name, version, and architecture */ -+ for (i = 0; i < vec->len; i++){ -+ ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n", -+ __FUNCTION__, pkg->name, pkg->version, pkg->architecture, -+ vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture ); -+ if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0) -+ && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0) -+ && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) { -+ found = 1; -+ ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n", -+ __FUNCTION__, pkg->name, pkg->version, pkg->architecture); -+ break; -+ } -+ } -+ -+ /* we didn't find one, add it */ -+ if (!found){ -+ ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n", -+ __FUNCTION__, pkg->name, pkg->version, pkg->architecture); -+ -+ vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *)); -+ vec->pkgs[vec->len] = pkg; -+ vec->len++; -+ return pkg; -+ } -+ /* update the one that we have */ -+ else { -+ ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s", -+ __FUNCTION__, pkg->name, pkg->version, pkg->architecture); -+ if (set_status) { -+ /* this is from the status file, so need to merge with existing database */ -+ ipkg_message(conf, IPKG_DEBUG2, " with set_status\n"); -+ pkg_merge(vec->pkgs[i], pkg, set_status); -+ /* XXX: CLEANUP: It's not so polite to free something here -+ that was passed in from above. */ -+ pkg_deinit(pkg); -+ free(pkg); -+ } else { -+ ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n"); -+ /* just overwrite the old one */ -+ pkg_deinit(vec->pkgs[i]); -+ free(vec->pkgs[i]); -+ vec->pkgs[i] = pkg; -+ } -+ return vec->pkgs[i]; -+ } -+} -+ -+void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg) -+{ -+ int i; -+ int found = 0; -+ -+ /* look for a duplicate pkg by name, version, and architecture */ -+ for (i = 0; i < vec->len; i++) -+ if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0) -+ && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0) -+ && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) { -+ found = 1; -+ break; -+ } -+ -+ /* we didn't find one, add it */ -+ if(!found){ -+ vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *)); -+ *(const pkg_t **)&vec->pkgs[vec->len] = pkg; -+ vec->len++; -+ } -+} -+ -+int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg) -+{ -+ int i; -+ for (i = 0; i < vec->len; i++) -+ if (vec->pkgs[i] == apkg) -+ return 1; -+ return 0; -+} -+ -+typedef int (*compare_fcn_t)(const void *, const void *); -+void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *)) -+{ -+ qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar); -+} -+ -+int pkg_vec_clear_marks(pkg_vec_t *vec) -+{ -+ int npkgs = vec->len; -+ int i; -+ for (i = 0; i < npkgs; i++) { -+ pkg_t *pkg = vec->pkgs[i]; -+ pkg->state_flag &= ~SF_MARKED; -+ } -+ return 0; -+} -+ -+int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern) -+{ -+ int matching_count = 0; -+ pkg_t **pkgs = vec->pkgs; -+ int npkgs = vec->len; -+ int i; -+ for (i = 0; i < npkgs; i++) { -+ pkg_t *pkg = pkgs[i]; -+ if (fnmatch(pattern, pkg->name, 0)==0) { -+ pkg->state_flag |= SF_MARKED; -+ matching_count++; -+ } -+ } -+ return matching_count; -+} -+ -+ -+abstract_pkg_vec_t * abstract_pkg_vec_alloc(void) -+{ -+ abstract_pkg_vec_t * vec ; -+ vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t)); -+ if (!vec) { -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return NULL; -+ } -+ vec->pkgs = NULL; -+ vec->len = 0; -+ -+ return vec; -+} -+ -+void abstract_pkg_vec_free(abstract_pkg_vec_t *vec) -+{ -+ free(vec->pkgs); -+ free(vec); -+} -+ -+/* -+ * assumption: all names in a vector are unique -+ */ -+void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg) -+{ -+ int i; -+ -+ /* look for a duplicate pkg by name */ -+ for(i = 0; i < vec->len; i++) -+ if (strcmp(pkg->name, vec->pkgs[i]->name) == 0) -+ break; -+ -+ /* we didn't find one, add it */ -+ if(i == vec->len){ -+ vec->pkgs = -+ (abstract_pkg_t **) -+ realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *)); -+ vec->pkgs[vec->len] = pkg; -+ vec->len++; -+ } -+} -+ -+abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i) -+{ -+ if (vec->len > i) -+ return vec->pkgs[i]; -+ else -+ return NULL; -+} -+ -+int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg) -+{ -+ int i; -+ for (i = 0; i < vec->len; i++) -+ if (vec->pkgs[i] == apkg) -+ return 1; -+ return 0; -+} -+ -+void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *)) -+{ -+ qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar); -+} -+ -Index: busybox-1.4.2/archival/libipkg/pkg_vec.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/pkg_vec.h 2007-06-04 13:21:36.729392952 +0200 -@@ -0,0 +1,64 @@ -+/* pkg_vec.h - the itsy package management system -+ -+ Steven M. Ayer -+ -+ Copyright (C) 2002 Compaq Computer Corporation -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef PKG_VEC_H -+#define PKG_VEC_H -+ -+typedef struct pkg pkg_t; -+typedef struct abstract_pkg abstract_pkg_t; -+ -+struct pkg_vec -+{ -+ pkg_t **pkgs; -+ int len; -+}; -+typedef struct pkg_vec pkg_vec_t; -+ -+struct abstract_pkg_vec -+{ -+ abstract_pkg_t **pkgs; -+ int len; -+}; -+typedef struct abstract_pkg_vec abstract_pkg_vec_t; -+ -+typedef int (*pkg_compar_t)(pkg_t *, pkg_t *); -+typedef int (*abstract_pkg_compar_t)(abstract_pkg_t *, abstract_pkg_t *); -+ -+pkg_vec_t * pkg_vec_alloc(void); -+void pkg_vec_free(pkg_vec_t *vec); -+void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg); -+ -+void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg); -+/* pkg_vec_insert_merge: might munge pkg. -+* returns the pkg that is in the pkg graph */ -+pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf); -+/* this one never munges pkg */ -+void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg); -+int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg); -+void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *)); -+ -+int pkg_vec_clear_marks(pkg_vec_t *vec); -+int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern); -+ -+abstract_pkg_vec_t * abstract_pkg_vec_alloc(void); -+void abstract_pkg_vec_free(abstract_pkg_vec_t *vec); -+void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg); -+abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i); -+int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg); -+void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *)); -+#endif -+ -Index: busybox-1.4.2/archival/libipkg/sprintf_alloc.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/sprintf_alloc.h 2007-06-04 13:21:36.729392952 +0200 -@@ -0,0 +1,25 @@ -+/* sprintf_alloca.c -- like sprintf with memory allocation -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or modify -+ it under the terms of the GNU General Public License as published by -+ the Free Software Foundation; either version 2, or (at your option) -+ any later version. -+ -+ This program 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 General Public License for more details. -+*/ -+ -+#ifndef SPRINTF_ALLOC_H -+#define SPRINTF_ALLOC_H -+ -+#include "libbb.h" -+ -+#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args) -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/str_list.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/str_list.c 2007-06-04 13:21:36.729392952 +0200 -@@ -0,0 +1,76 @@ -+/* str_list.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+ -+#include "str_list.h" -+ -+int str_list_elt_init(str_list_elt_t *elt, char *data) -+{ -+ return void_list_elt_init((void_list_elt_t *) elt, data); -+} -+ -+void str_list_elt_deinit(str_list_elt_t *elt) -+{ -+ void_list_elt_deinit((void_list_elt_t *) elt); -+} -+ -+str_list_t *str_list_alloc() -+{ -+ str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t)); -+ if (list) -+ str_list_init(list); -+ return list; -+} -+ -+int str_list_init(str_list_t *list) -+{ -+ return void_list_init((void_list_t *) list); -+} -+ -+void str_list_deinit(str_list_t *list) -+{ -+ void_list_deinit((void_list_t *) list); -+} -+ -+int str_list_append(str_list_t *list, char *data) -+{ -+ return void_list_append((void_list_t *) list, data); -+} -+ -+int str_list_push(str_list_t *list, char *data) -+{ -+ return void_list_push((void_list_t *) list, data); -+} -+ -+str_list_elt_t *str_list_pop(str_list_t *list) -+{ -+ return (str_list_elt_t *) void_list_pop((void_list_t *) list); -+} -+ -+str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter) -+{ -+ return (str_list_elt_t *) void_list_remove((void_list_t *) list, -+ (void_list_elt_t **) iter); -+} -+ -+char *str_list_remove_elt(str_list_t *list, const char *target_str) -+{ -+ return (char *)void_list_remove_elt((void_list_t *) list, -+ (void *)target_str, -+ (void_list_cmp_t)strcmp); -+} -Index: busybox-1.4.2/archival/libipkg/str_list.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/str_list.h 2007-06-04 13:21:36.729392952 +0200 -@@ -0,0 +1,51 @@ -+/* str_list.h - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef STR_LIST_H -+#define STR_LIST_H -+ -+#include "void_list.h" -+ -+typedef struct str_list_elt str_list_elt_t; -+struct str_list_elt -+{ -+ str_list_elt_t *next; -+ char *data; -+}; -+ -+typedef struct xstr_list str_list_t; -+struct xstr_list -+{ -+ str_list_elt_t pre_head; -+ str_list_elt_t *head; -+ str_list_elt_t *tail; -+}; -+ -+int str_list_elt_init(str_list_elt_t *elt, char *data); -+void str_list_elt_deinit(str_list_elt_t *elt); -+ -+str_list_t *str_list_alloc(void); -+int str_list_init(str_list_t *list); -+void str_list_deinit(str_list_t *list); -+ -+int str_list_append(str_list_t *list, char *data); -+int str_list_push(str_list_t *list, char *data); -+str_list_elt_t *str_list_pop(str_list_t *list); -+str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter); -+char *str_list_remove_elt(str_list_t *list, const char *target_str); -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/str_util.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/str_util.c 2007-06-04 13:21:36.730392800 +0200 -@@ -0,0 +1,73 @@ -+/* str_utils.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+ -+int str_starts_with(const char *str, const char *prefix) -+{ -+ return (strncmp(str, prefix, strlen(prefix)) == 0); -+} -+ -+int str_ends_with(const char *str, const char *suffix) -+{ -+ int suffix_len; -+ int str_len; -+ -+ str_len = strlen(str); -+ suffix_len = strlen(suffix); -+ -+ if (str_len < suffix_len) { -+ return 0; -+ } -+ -+ return (strcmp(str + str_len - suffix_len, suffix) == 0); -+} -+ -+int str_chomp(char *str) -+{ -+ if (str[strlen(str) - 1] == '\n') { -+ str[strlen(str) - 1] = '\0'; -+ return 1; -+ } -+ return 0; -+} -+ -+int str_tolower(char *str) -+{ -+ while (*str) { -+ *str = tolower(*str); -+ str++; -+ } -+ -+ return 0; -+} -+ -+int str_toupper(char *str) -+{ -+ while (*str) { -+ *str = toupper(*str); -+ str++; -+ } -+ -+ return 0; -+} -+ -+char *str_dup_safe(const char *str) -+{ -+ return str ? strdup(str) : NULL; -+} -+ -Index: busybox-1.4.2/archival/libipkg/str_util.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/str_util.h 2007-06-04 13:21:36.730392800 +0200 -@@ -0,0 +1,28 @@ -+/* str_utils.h - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef STR_UTILS_H -+#define STR_UTILS_H -+ -+int str_starts_with(const char *str, const char *prefix); -+int str_ends_with(const char *str, const char *suffix); -+int str_chomp(char *str); -+int str_tolower(char *str); -+int str_toupper(char *str); -+char *str_dup_safe(const char *str); -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/user.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/user.c 2007-06-04 13:21:36.730392800 +0200 -@@ -0,0 +1,58 @@ -+/* user.c - the itsy package management system -+ -+ Jamey Hicks -+ -+ Copyright (C) 2002 Hewlett Packard Company -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include -+#include -+#include "file_util.h" -+#include "str_util.h" -+#ifdef IPKG_LIB -+#include "libipkg.h" -+#endif -+ -+ -+#ifdef IPKG_LIB -+static char *question = NULL; -+static int question_len = 255; -+#endif -+char *get_user_response(const char *format, ...) -+{ -+ int len = question_len; -+ va_list ap; -+ char *response; -+ va_start(ap, format); -+ -+#ifndef IPKG_LIB -+ vprintf(format, ap); -+ do { -+ response = file_read_line_alloc(stdin); -+ } while (response == NULL); -+#else -+ do { -+ if (question == NULL || len > question_len) { -+ question = realloc(question, len + 1); -+ question_len = len; -+ } -+ len = vsnprintf(question,question_len,format,ap); -+ } while (len > question_len); -+ response = strdup(ipkg_cb_response(question)); -+#endif -+ str_chomp(response); -+ str_tolower(response); -+ -+ return response; -+} -Index: busybox-1.4.2/archival/libipkg/user.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/user.h 2007-06-04 13:21:36.730392800 +0200 -@@ -0,0 +1,23 @@ -+/* user.c - the itsy package management system -+ -+ Jamey Hicks -+ -+ Copyright (C) 2002 Hewlett Packard Company -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include -+#include -+ -+char *get_user_response(const char *format, ...); -+ -Index: busybox-1.4.2/archival/libipkg/void_list.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/void_list.c 2007-06-04 13:21:36.731392648 +0200 -@@ -0,0 +1,194 @@ -+/* void_list.c - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+#include -+ -+#include "void_list.h" -+ -+int void_list_elt_init(void_list_elt_t *elt, void *data) -+{ -+ elt->next = NULL; -+ elt->data = data; -+ -+ return 0; -+} -+ -+void void_list_elt_deinit(void_list_elt_t *elt) -+{ -+ void_list_elt_init(elt, NULL); -+} -+ -+int void_list_init(void_list_t *list) -+{ -+ void_list_elt_init(&list->pre_head, NULL); -+ list->head = NULL; -+ list->pre_head.next = list->head; -+ list->tail = NULL; -+ -+ return 0; -+} -+ -+void void_list_deinit(void_list_t *list) -+{ -+ void_list_elt_t *elt; -+ -+ while (list->head) { -+ elt = void_list_pop(list); -+ void_list_elt_deinit(elt); -+ /* malloced in void_list_append */ -+ free(elt); -+ } -+} -+ -+int void_list_append(void_list_t *list, void *data) -+{ -+ void_list_elt_t *elt; -+ -+ /* freed in void_list_deinit */ -+ elt = malloc(sizeof(void_list_elt_t)); -+ if (elt == NULL) { -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return ENOMEM; -+ } -+ -+ void_list_elt_init(elt, data); -+ -+ if (list->tail) { -+ list->tail->next = elt; -+ list->tail = elt; -+ } else { -+ list->head = elt; -+ list->pre_head.next = list->head; -+ list->tail = elt; -+ } -+ -+ return 0; -+} -+ -+int void_list_push(void_list_t *list, void *data) -+{ -+ void_list_elt_t *elt; -+ -+ elt = malloc(sizeof(void_list_elt_t)); -+ if (elt == NULL) { -+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__); -+ return ENOMEM; -+ } -+ -+ void_list_elt_init(elt, data); -+ -+ elt->next = list->head; -+ list->head->next = elt; -+ if (list->tail == NULL) { -+ list->tail = list->head; -+ } -+ -+ return 0; -+} -+ -+void_list_elt_t *void_list_pop(void_list_t *list) -+{ -+ void_list_elt_t *elt; -+ -+ elt = list->head; -+ -+ if (list->head) { -+ list->head = list->head->next; -+ list->pre_head.next = list->head; -+ if (list->head == NULL) { -+ list->tail = NULL; -+ } -+ } -+ -+ return elt; -+} -+ -+void *void_list_remove(void_list_t *list, void_list_elt_t **iter) -+{ -+ void_list_elt_t *prior; -+ void_list_elt_t *old_elt; -+ void *old_data; -+ -+ old_elt = *iter; -+ old_data = old_elt->data; -+ -+ if (old_elt == list->head) { -+ prior = &list->pre_head; -+ void_list_pop(list); -+ } else { -+ for (prior = list->head; prior; prior = prior->next) { -+ if (prior->next == old_elt) { -+ break; -+ } -+ } -+ if (prior == NULL || prior->next != old_elt) { -+ fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__); -+ return NULL; -+ } -+ prior->next = old_elt->next; -+ -+ if (old_elt == list->tail) { -+ list->tail = prior; -+ } -+ } -+ -+ void_list_elt_deinit(old_elt); -+ *iter = prior; -+ -+ return old_data; -+} -+ -+/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */ -+void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp) -+{ -+ void_list_elt_t *prior; -+ void_list_elt_t *old_elt = NULL; -+ void *old_data = NULL; -+ -+ /* first element */ -+ if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) { -+ old_elt = list->head; -+ old_data = list->head->data; -+ void_list_pop(list); -+ } else { -+ int found = 0; -+ for (prior = list->head; prior && prior->next; prior = prior->next) { -+ if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) { -+ old_elt = prior->next; -+ old_data = old_elt->data; -+ found = 1; -+ break; -+ } -+ } -+ if (!found) { -+ return NULL; -+ } -+ prior->next = old_elt->next; -+ -+ if (old_elt == list->tail) { -+ list->tail = prior; -+ } -+ } -+ if (old_elt) -+ void_list_elt_deinit(old_elt); -+ -+ if (old_data) -+ return old_data; -+ else -+ return NULL; -+} -Index: busybox-1.4.2/archival/libipkg/void_list.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/void_list.h 2007-06-04 13:21:36.731392648 +0200 -@@ -0,0 +1,59 @@ -+/* void_list.h - the itsy package management system -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef VOID_LIST_H -+#define VOID_LIST_H -+ -+typedef struct void_list_elt void_list_elt_t; -+struct void_list_elt -+{ -+ void_list_elt_t *next; -+ void *data; -+}; -+ -+typedef struct void_list void_list_t; -+struct void_list -+{ -+ void_list_elt_t pre_head; -+ void_list_elt_t *head; -+ void_list_elt_t *tail; -+}; -+ -+static inline int void_list_empty(void_list_t *list) -+{ -+ if (list->head == NULL) -+ return 1; -+ else -+ return 0; -+} -+ -+int void_list_elt_init(void_list_elt_t *elt, void *data); -+void void_list_elt_deinit(void_list_elt_t *elt); -+ -+int void_list_init(void_list_t *list); -+void void_list_deinit(void_list_t *list); -+ -+int void_list_append(void_list_t *list, void *data); -+int void_list_push(void_list_t *list, void *data); -+void_list_elt_t *void_list_pop(void_list_t *list); -+ -+void *void_list_remove(void_list_t *list, void_list_elt_t **iter); -+/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */ -+typedef int (*void_list_cmp_t)(const void *, const void *); -+void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp); -+ -+#endif -Index: busybox-1.4.2/archival/libipkg/xsystem.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/xsystem.c 2007-06-04 13:21:36.731392648 +0200 -@@ -0,0 +1,64 @@ -+/* xsystem.c - system(3) with error messages -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#include "ipkg.h" -+#include -+ -+#include "xsystem.h" -+ -+/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't -+ really need the /bin/sh invocation which takes resources and -+ introduces security problems. I should switch all of this to a sort -+ of execl() or execv() interface/implementation. -+*/ -+ -+/* Like system(3), but with error messages printed if the fork fails -+ or if the child process dies due to an uncaught signal. Also, the -+ return value is a bit simpler: -+ -+ -1 if there was any problem -+ Otherwise, the 8-bit return value of the program ala WEXITSTATUS -+ as defined in . -+*/ -+int xsystem(const char *cmd) -+{ -+ int err; -+ -+ err = system(cmd); -+ -+ if (err == -1) { -+ fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n", -+ __FUNCTION__, cmd); -+ return -1; -+ } -+ -+ if (WIFSIGNALED(err)) { -+ fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n", -+ __FUNCTION__, WTERMSIG(err), cmd); -+ return -1; -+ } -+ -+ if (WIFEXITED(err)) { -+ /* Normal child exit */ -+ return WEXITSTATUS(err); -+ } -+ -+ fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d", -+ __FUNCTION__, err); -+ return -1; -+} -+ -Index: busybox-1.4.2/archival/libipkg/xsystem.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/archival/libipkg/xsystem.h 2007-06-04 13:21:36.731392648 +0200 -@@ -0,0 +1,34 @@ -+/* xsystem.h - system(3) with error messages -+ -+ Carl D. Worth -+ -+ Copyright (C) 2001 University of Southern California -+ -+ This program is free software; you can redistribute it and/or -+ modify it under the terms of the GNU General Public License as -+ published by the Free Software Foundation; either version 2, or (at -+ your option) any later version. -+ -+ This program 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 -+ General Public License for more details. -+*/ -+ -+#ifndef XSYSTEM_H -+#define XSYSTEM_H -+ -+#include -+ -+/* Like system(3), but with error messages printed if the fork fails -+ or if the child process dies due to an uncaught signal. Also, the -+ return value is a bit simpler: -+ -+ -1 if there was any problem -+ Otherwise, the 8-bit return value of the program ala WEXITSTATUS -+ as defined in . -+*/ -+int xsystem(const char *cmd); -+ -+#endif -+ -Index: busybox-1.4.2/archival/libunarchive/data_extract_all.c -=================================================================== ---- busybox-1.4.2.orig/archival/libunarchive/data_extract_all.c 2007-06-04 13:21:31.879130304 +0200 -+++ busybox-1.4.2/archival/libunarchive/data_extract_all.c 2007-06-04 13:21:36.731392648 +0200 -@@ -117,3 +117,17 @@ - utime(file_header->name, &t); - } - } -+ -+extern void data_extract_all_prefix(archive_handle_t *archive_handle) -+{ -+ char *name_ptr = archive_handle->file_header->name; -+ -+ name_ptr += strspn(name_ptr, "./"); -+ if (name_ptr[0] != '\0') { -+ archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1); -+ strcpy(archive_handle->file_header->name, archive_handle->buffer); -+ strcat(archive_handle->file_header->name, name_ptr); -+ data_extract_all(archive_handle); -+ } -+} -+ -Index: busybox-1.4.2/archival/libunarchive/Kbuild -=================================================================== ---- busybox-1.4.2.orig/archival/libunarchive/Kbuild 2007-06-04 13:21:31.886129240 +0200 -+++ busybox-1.4.2/archival/libunarchive/Kbuild 2007-06-04 13:21:36.732392496 +0200 -@@ -47,6 +47,7 @@ - lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o - lib-$(CONFIG_GUNZIP) += $(GUNZIP_FILES) - lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o -+lib-$(CONFIG_IPKG) += $(GUNZIP_FILES) get_header_tar.o get_header_tar_gz.o - lib-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o - lib-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o - lib-$(CONFIG_TAR) += get_header_tar.o -Index: busybox-1.4.2/include/applets.h -=================================================================== ---- busybox-1.4.2.orig/include/applets.h 2007-06-04 13:21:34.786688288 +0200 -+++ busybox-1.4.2/include/applets.h 2007-06-04 13:21:36.732392496 +0200 -@@ -160,6 +160,7 @@ - USE_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_NEVER)) - USE_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS)) - USE_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS)) -+USE_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) - USE_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_NEVER)) - USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER)) - USE_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_NEVER)) -Index: busybox-1.4.2/include/unarchive.h -=================================================================== ---- busybox-1.4.2.orig/include/unarchive.h 2007-06-04 13:21:31.897127568 +0200 -+++ busybox-1.4.2/include/unarchive.h 2007-06-04 13:21:36.732392496 +0200 -@@ -76,6 +76,7 @@ - - extern void data_skip(archive_handle_t *archive_handle); - extern void data_extract_all(archive_handle_t *archive_handle); -+extern void data_extract_all_prefix(archive_handle_t *archive_handle); - extern void data_extract_to_stdout(archive_handle_t *archive_handle); - extern void data_extract_to_buffer(archive_handle_t *archive_handle); - -Index: busybox-1.4.2/include/usage.h -=================================================================== ---- busybox-1.4.2.orig/include/usage.h 2007-06-04 13:21:35.005655000 +0200 -+++ busybox-1.4.2/include/usage.h 2007-06-04 13:21:36.734392192 +0200 -@@ -1133,6 +1133,82 @@ - "$ ls -la /tmp/busybox*\n" \ - "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n" - -+#define ipkg_trivial_usage \ -+ "[options]... sub-command [arguments]..." -+#define ipkg_full_usage \ -+ "ipkg is an utility to install, remove and manage .ipk packages.\n" \ -+ "\n" \ -+ "Sub-commands:\n" \ -+ "\nPackage Manipulation:\n" \ -+ "\tupdate Update list of available packages\n" \ -+ "\tupgrade Upgrade all installed packages to latest version\n" \ -+ "\tinstall Download and install (and dependencies)\n" \ -+ "\tinstall Install package \n" \ -+ "\tconfigure [] Configure unpacked packages\n" \ -+ "\tremove Remove package \n" \ -+ "\tflag ... Flag package(s) \n" \ -+ "\t =hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \ -+ "\n" \ -+ "Informational Commands:\n" \ -+ "\tlist List available packages and descriptions\n" \ -+ "\tlist_installed List all and only the installed packages and description \n" \ -+ "\tfiles List all files belonging to \n" \ -+ "\tsearch Search for a package providing \n" \ -+ "\tinfo [pkg|regexp []] Display all/some info fields for or all\n" \ -+ "\tstatus [pkg|regexp []] Display all/some status fields for or all\n" \ -+ "\tdownload Download to current directory.\n" \ -+ "\tcompare_versions \n" \ -+ "\t compare versions using <= < > >= = << >>\n" \ -+ "\tprint_architecture prints the architecture.\n" \ -+ "\tprint_installation_architecture\n" \ -+ "\twhatdepends [-A] [pkgname|pat]+\n" \ -+ "\twhatdependsrec [-A] [pkgname|pat]+\n" \ -+ "\twhatprovides [-A] [pkgname|pat]+\n" \ -+ "\twhatconflicts [-A] [pkgname|pat]+\n" \ -+ "\twhatreplaces [-A] [pkgname|pat]+\n" \ -+ "\t prints the installation architecture.\n" \ -+ "\n" \ -+ "\nOptions:\n" \ -+ "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \ -+ "\t-V Set verbosity level to . If no value is\n" \ -+ "\t--verbosity provided increase verbosity by one. Verbosity levels:\n" \ -+ "\t 0 errors only\n" \ -+ "\t 1 normal messages (default)\n" \ -+ "\t 2 informative messages\n" \ -+ "\t 3 debug output\n" \ -+ "\t-f Use as the ipkg configuration file\n" \ -+ "\t-conf Default configuration file location\n" \ -+ " is /etc/ipkg.conf\n" \ -+ "\t-d Use as the the root directory for\n" \ -+ "\t-dest package installation, removal, upgrading.\n" \ -+ " should be a defined dest name from\n" \ -+ " the configuration file, (but can also be a\n" \ -+ " directory name in a pinch).\n" \ -+ "\t-o Use as the root directory for\n" \ -+ "\t-offline offline installation of packages.\n" \ -+ "\t-verbose_wget more wget messages\n" \ -+ "\n" \ -+ "Force Options (use when ipkg is too smart for its own good):\n" \ -+ "\t-force-depends Make dependency checks warnings instead of errors\n" \ -+ "\t Install/remove package in spite of failed dependences\n" \ -+ "\t-force-defaults Use default options for questions asked by ipkg.\n" \ -+ " (no prompts). Note that this will not prevent\n" \ -+ " package installation scripts from prompting.\n" \ -+ "\t-force-reinstall Allow ipkg to reinstall a package.\n" \ -+ "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \ -+ "\t-force-downgrade Allow ipkg to downgrade packages.\n" \ -+ "\t-force_space Install even if there does not seem to be enough space.\n" \ -+ "\t-noaction No action -- test only\n" \ -+ "\t-nodeps Do not follow dependences\n" \ -+ "\t-force-removal-of-dependent-packages\n" \ -+ "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \ -+ "\t-test No action -- test only\n" \ -+ "\t-t Specify tmp-dir.\n" \ -+ "\t--tmp-dir Specify tmp-dir.\n" \ -+ "\n" \ -+ "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \ -+ "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n" -+ - #define halt_trivial_usage \ - "[-d] [-n] [-f]" - #define halt_full_usage \ -Index: busybox-1.4.2/Makefile -=================================================================== ---- busybox-1.4.2.orig/Makefile 2007-06-04 13:21:31.910125592 +0200 -+++ busybox-1.4.2/Makefile 2007-06-04 13:21:36.734392192 +0200 -@@ -423,6 +423,7 @@ - - libs-y := \ - archival/ \ -+ archival/libipkg/ \ - archival/libunarchive/ \ - console-tools/ \ - coreutils/ \ diff --git a/package/busybox/patches/913-libbb_hash.patch b/package/busybox/patches/913-libbb_hash.patch deleted file mode 100644 index e371b32838..0000000000 --- a/package/busybox/patches/913-libbb_hash.patch +++ /dev/null @@ -1,201 +0,0 @@ -Index: busybox-1.4.2/coreutils/md5_sha1_sum.c -=================================================================== ---- busybox-1.4.2.orig/coreutils/md5_sha1_sum.c 2007-06-04 13:21:31.536182440 +0200 -+++ busybox-1.4.2/coreutils/md5_sha1_sum.c 2007-06-04 13:21:37.709243992 +0200 -@@ -8,76 +8,10 @@ - - #include "busybox.h" - --typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t; -- - #define FLAG_SILENT 1 - #define FLAG_CHECK 2 - #define FLAG_WARN 4 - --/* This might be useful elsewhere */ --static unsigned char *hash_bin_to_hex(unsigned char *hash_value, -- unsigned hash_length) --{ -- /* xzalloc zero-terminates */ -- char *hex_value = xzalloc((hash_length * 2) + 1); -- bin2hex(hex_value, (char*)hash_value, hash_length); -- return hex_value; --} -- --static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo) --{ -- int src_fd, hash_len, count; -- union _ctx_ { -- sha1_ctx_t sha1; -- md5_ctx_t md5; -- } context; -- uint8_t *hash_value = NULL; -- RESERVE_CONFIG_UBUFFER(in_buf, 4096); -- void (*update)(const void*, size_t, void*); -- void (*final)(void*, void*); -- -- src_fd = STDIN_FILENO; -- if (NOT_LONE_DASH(filename)) { -- src_fd = open(filename, O_RDONLY); -- if (src_fd < 0) { -- bb_perror_msg("%s", filename); -- return NULL; -- } -- } -- -- /* figure specific hash algorithims */ -- if (ENABLE_MD5SUM && hash_algo==HASH_MD5) { -- md5_begin(&context.md5); -- update = (void (*)(const void*, size_t, void*))md5_hash; -- final = (void (*)(void*, void*))md5_end; -- hash_len = 16; -- } else if (ENABLE_SHA1SUM && hash_algo==HASH_SHA1) { -- sha1_begin(&context.sha1); -- update = (void (*)(const void*, size_t, void*))sha1_hash; -- final = (void (*)(void*, void*))sha1_end; -- hash_len = 20; -- } else { -- bb_error_msg_and_die("algorithm not supported"); -- } -- -- while (0 < (count = safe_read(src_fd, in_buf, 4096))) { -- update(in_buf, count, &context); -- } -- -- if (count == 0) { -- final(in_buf, &context); -- hash_value = hash_bin_to_hex(in_buf, hash_len); -- } -- -- RELEASE_CONFIG_BUFFER(in_buf); -- -- if (src_fd != STDIN_FILENO) { -- close(src_fd); -- } -- -- return hash_value; --} -- - int md5_sha1_sum_main(int argc, char **argv) - { - int return_value = EXIT_SUCCESS; -Index: busybox-1.4.2/include/libbb.h -=================================================================== ---- busybox-1.4.2.orig/include/libbb.h 2007-06-04 13:21:35.388596784 +0200 -+++ busybox-1.4.2/include/libbb.h 2007-06-04 13:21:37.709243992 +0200 -@@ -641,6 +641,7 @@ - extern const char bb_uuenc_tbl_std[]; - void bb_uuencode(const unsigned char *s, char *store, const int length, const char *tbl); - -+typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t; - typedef struct sha1_ctx_t { - uint32_t count[2]; - uint32_t hash[5]; -@@ -662,6 +663,8 @@ - void md5_begin(md5_ctx_t *ctx); - void md5_hash(const void *data, size_t length, md5_ctx_t *ctx); - void *md5_end(void *resbuf, md5_ctx_t *ctx); -+unsigned char *hash_bin_to_hex(unsigned char *hash_value, unsigned hash_length); -+uint8_t *hash_file(const char *filename, hash_algo_t hash_algo); - - uint32_t *crc32_filltable(int endian); - -Index: busybox-1.4.2/libbb/Kbuild -=================================================================== ---- busybox-1.4.2.orig/libbb/Kbuild 2007-06-04 13:21:31.548180616 +0200 -+++ busybox-1.4.2/libbb/Kbuild 2007-06-04 13:21:37.710243840 +0200 -@@ -37,6 +37,7 @@ - lib-y += get_last_path_component.o - lib-y += get_line_from_file.o - lib-y += getopt32.o -+lib-y += hash.o - lib-y += herror_msg.o - lib-y += herror_msg_and_die.o - lib-y += human_readable.o -Index: busybox-1.4.2/libbb/hash.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/libbb/hash.c 2007-06-04 13:21:37.710243840 +0200 -@@ -0,0 +1,82 @@ -+/* -+ * Copyright (C) 2003 Glenn L. McGrath -+ * Copyright (C) 2003-2004 Erik Andersen -+ * -+ * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. -+ */ -+ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#include "busybox.h" -+ -+/* This might be useful elsewhere */ -+unsigned char *hash_bin_to_hex(unsigned char *hash_value, -+ unsigned hash_length) -+{ -+ /* xzalloc zero-terminates */ -+ char *hex_value = xzalloc((hash_length * 2) + 1); -+ bin2hex(hex_value, (char*)hash_value, hash_length); -+ return hex_value; -+} -+ -+uint8_t *hash_file(const char *filename, hash_algo_t hash_algo) -+{ -+ int src_fd, hash_len, count; -+ union _ctx_ { -+ sha1_ctx_t sha1; -+ md5_ctx_t md5; -+ } context; -+ uint8_t *hash_value = NULL; -+ RESERVE_CONFIG_UBUFFER(in_buf, 4096); -+ void (*update)(const void*, size_t, void*); -+ void (*final)(void*, void*); -+ -+ src_fd = STDIN_FILENO; -+ if (NOT_LONE_DASH(filename)) { -+ src_fd = open(filename, O_RDONLY); -+ if (src_fd < 0) { -+ bb_perror_msg("%s", filename); -+ return NULL; -+ } -+ } -+ -+ /* figure specific hash algorithims */ -+ if (hash_algo==HASH_MD5) { -+ md5_begin(&context.md5); -+ update = (void (*)(const void*, size_t, void*))md5_hash; -+ final = (void (*)(void*, void*))md5_end; -+ hash_len = 16; -+ } else if (hash_algo==HASH_SHA1) { -+ sha1_begin(&context.sha1); -+ update = (void (*)(const void*, size_t, void*))sha1_hash; -+ final = (void (*)(void*, void*))sha1_end; -+ hash_len = 20; -+ } else { -+ bb_error_msg_and_die("algorithm not supported"); -+ } -+ -+ while (0 < (count = safe_read(src_fd, in_buf, 4096))) { -+ update(in_buf, count, &context); -+ } -+ -+ if (count == 0) { -+ final(in_buf, &context); -+ hash_value = hash_bin_to_hex(in_buf, hash_len); -+ } -+ -+ RELEASE_CONFIG_BUFFER(in_buf); -+ -+ if (src_fd != STDIN_FILENO) { -+ close(src_fd); -+ } -+ -+ return hash_value; -+} -+ -+ diff --git a/package/busybox/patches/920-awx.patch b/package/busybox/patches/920-awx.patch deleted file mode 100644 index 2abab323e5..0000000000 --- a/package/busybox/patches/920-awx.patch +++ /dev/null @@ -1,1619 +0,0 @@ -Index: busybox-1.4.2/editors/awk.c -=================================================================== ---- busybox-1.4.2.orig/editors/awk.c 2007-06-04 13:21:35.202625056 +0200 -+++ busybox-1.4.2/editors/awk.c 2007-06-04 13:21:37.927210856 +0200 -@@ -30,6 +30,11 @@ - /* these flags are static, don't change them when value is changed */ - #define VF_DONTTOUCH (VF_ARRAY | VF_SPECIAL | VF_WALK | VF_CHILD | VF_DIRTY) - -+#ifdef CONFIG_AWX -+#define fputs(s, stream) fputs_hook(s, stream) -+static inline int fputs_hook (__const char *__restrict __s, FILE *__restrict __stream); -+#endif -+ - /* Variable */ - typedef struct var_s { - unsigned short type; /* flags */ -@@ -50,10 +55,15 @@ - char *programname; - } chain; - -+typedef var *(*awk_cfunc)(var *res, var *args, int nargs); - /* Function */ - typedef struct func_s { - unsigned short nargs; -- struct chain_s body; -+ enum { AWKFUNC, CFUNC } type; -+ union { -+ awk_cfunc cfunc; -+ struct chain_s body; -+ } x; - } func; - - /* I/O stream */ -@@ -1312,7 +1322,8 @@ - next_token(TC_FUNCTION); - pos++; - f = newfunc(t.string); -- f->body.first = NULL; -+ f->type = AWKFUNC; -+ f->x.body.first = NULL; - f->nargs = 0; - while (next_token(TC_VARIABLE | TC_SEQTERM) & TC_VARIABLE) { - v = findvar(ahash, t.string); -@@ -1321,7 +1332,7 @@ - if (next_token(TC_COMMA | TC_SEQTERM) & TC_SEQTERM) - break; - } -- seq = &(f->body); -+ seq = &(f->x.body); - chain_group(); - clear_array(ahash); - -@@ -2260,7 +2271,8 @@ - break; - - case XC( OC_FUNC ): -- if (! op->r.f->body.first) -+ if ((op->r.f->type == AWKFUNC) && -+ !op->r.f->x.body.first) - runtime_error(EMSG_UNDEF_FUNC); - - X.v = R.v = nvalloc(op->r.f->nargs+1); -@@ -2277,7 +2289,11 @@ - fnargs = X.v; - - L.s = programname; -- res = evaluate(op->r.f->body.first, res); -+ if (op->r.f->type == AWKFUNC) -+ res = evaluate(op->r.f->x.body.first, res); -+ else if (op->r.f->type == CFUNC) -+ res = op->r.f->x.cfunc(res, fnargs, op->r.f->nargs); -+ - programname = L.s; - - nvfree(fnargs); -@@ -2637,6 +2653,11 @@ - return &rsm; - } - -+#ifdef CONFIG_AWX -+static int is_awx = 0; -+#include "awx.c" -+#endif -+ - int awk_main(int argc, char **argv) - { - int i, j, flen; -@@ -2693,6 +2714,10 @@ - free(s); - } - -+#ifdef CONFIG_AWX -+ do_awx(argc, argv); -+#endif -+ - programname = NULL; - while((c = getopt(argc, argv, "F:v:f:W:")) != EOF) { - switch (c) { -Index: busybox-1.4.2/editors/awx.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/editors/awx.c 2007-06-04 13:21:37.928210704 +0200 -@@ -0,0 +1,633 @@ -+/* -+ * awk web extension -+ * -+ * Copyright (C) 2007 by Felix Fietkau -+ * -+ * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. -+ */ -+ -+#include -+#include -+#include "awx_parser.h" -+ -+#define LINE_BUF 2048 -+#define HASH_MAX 1536 -+#define TR_START "@TR<<" -+#define TR_END ">>" -+#define MAX_TR 32 -+ -+#undef fputs -+ -+static xhash *lstr = NULL; -+static xhash *formvar = NULL; -+static int lang_inuse = 0; -+ -+/* look up a translation symbol from the hash */ -+static inline char *translate_lookup(char *str) -+{ -+ char *name, *def, *p; -+ hash_item *hi; -+ var *v; -+ -+ def = name = str; -+ if (((p = strchr(str, '|')) != NULL) -+ || ((p = strchr(str, '#')) != NULL)) { -+ def = p + 1; -+ *p = 0; -+ } -+ -+ hi = hash_search(lstr, name); -+ if (!hi) -+ return def; -+ -+ v = &hi->data.v; -+ -+ return getvar_s(v); -+} -+ -+/* look for translation markers in the line and return the translated string */ -+static char *translate_line(char *line) -+{ -+ char *tok[MAX_TR * 3]; -+ char *l, *p, *p2 = NULL, *res; -+ int len = 0, _pos = 0, i, tr_abort = 0; -+ static char *backlog = NULL; -+ -+ if (backlog && line) { -+ backlog = xrealloc(backlog, strlen(backlog) + strlen(line) + 1); -+ sprintf(backlog + strlen(backlog), line); -+ l = backlog; -+ } else { -+ l = line; -+ } -+ -+ while (l != NULL) { -+ if ((p = strstr(l, TR_START)) == NULL) { -+ len += strlen((tok[_pos++] = l)); -+ break; -+ } -+ -+ p2 = strstr(p, TR_END); -+ if (p2 == NULL) { -+ p2 = xstrdup(l); -+ tr_abort = 1; -+ break; -+ } -+ -+ *p = 0; -+ len += strlen((tok[_pos++] = l)); -+ *p2 = 0; -+ len += strlen((tok[_pos++] = translate_lookup(p + strlen(TR_START)))); -+ -+ l = p2; -+ l += strlen(TR_END); -+ } -+ len++; -+ -+ p = xmalloc(len + 1); -+ *p = 0; -+ res = p; -+ for (i = 0; i < _pos; i++) { -+ strcat(p, tok[i]); -+ p += strlen(tok[i]); -+ } -+ if (backlog) { -+ free(backlog); -+ backlog = NULL; -+ } -+ if (tr_abort && p2) -+ backlog = p2; -+ -+ return res; -+} -+ -+/* hook for intercepting awk's use of puts. used for running all printed strings -+ * through the translation system */ -+static inline int fputs_hook (__const char *__restrict __s, FILE *__restrict __stream) -+{ -+ if (lang_inuse && (__stream == stdout)) { -+ int ret; -+ char *str; -+ -+ str = translate_line((char *) __s); -+ ret = fputs(str, __stream); -+ free(str); -+ -+ return ret; -+ } -+ -+ return fputs(__s, __stream); -+} -+ -+static var *init_lang(var *res, var *args, int nargs) -+{ -+ if (!lstr) -+ lstr = hash_init(); -+ -+ lang_inuse = 1; -+ return res; -+} -+ -+ -+/* load and parse language file */ -+static void load_lang_file(char *file) -+{ -+ FILE *f; -+ char *b, *name, *value; -+ char buf1[LINE_BUF]; -+ -+ if ((f = fopen(file, "r")) == NULL) -+ return; -+ -+ while (!feof(f) && (fgets(buf1, LINE_BUF - 1, f) != NULL)) { -+ b = buf1; -+ if (*b == '#') -+ continue; /* skip comments */ -+ -+ while (isspace(*b)) -+ b++; /* skip leading spaces */ -+ if (!*b) -+ continue; -+ -+ name = b; -+ if ((b = strstr(name, "=>")) == NULL) -+ continue; /* separator not found */ -+ -+ value = b + 2; -+ if (!*value) -+ continue; -+ -+ *b = 0; -+ for (b--; isspace(*b); b--) -+ *b = 0; /* remove trailing spaces */ -+ -+ while (isspace(*value)) -+ value++; /* skip leading spaces */ -+ -+ for (b = value + strlen(value) - 1; isspace(*b); b--) -+ *b = 0; /* remove trailing spaces */ -+ -+ if (!*value) -+ continue; -+ -+ setvar_s(findvar(lstr,name), value); -+ } -+ -+ fclose(f); -+} -+ -+static var *load_lang(var *res, var *args, int nargs) -+{ -+ const char *langfmt = "/usr/lib/webif/lang/%s.txt"; -+ char lbuf[LINE_BUF]; -+ char *lang; -+ -+ if (!lang_inuse) -+ init_lang(res, args, nargs); -+ -+ lang = getvar_s(args); -+ if (!lang || !strcmp(lang, "")) -+ return res; -+ -+ sprintf(lbuf, langfmt, lang); -+ load_lang_file(lbuf); -+ -+ return res; -+} -+ -+/* read the contents of an entire file */ -+static char *get_file(char *fname) -+{ -+ FILE *F; -+ char *s = NULL; -+ int i, j, flen; -+ -+ F = fopen(fname, "r"); -+ if (!F) { -+ return NULL; -+ } -+ -+ if (fseek(F, 0, SEEK_END) == 0) { -+ flen = ftell(F); -+ s = (char *)xmalloc(flen+4); -+ fseek(F, 0, SEEK_SET); -+ i = 1 + fread(s+1, 1, flen, F); -+ } else { -+ for (i=j=1; j>0; i+=j) { -+ s = (char *)xrealloc(s, i+4096); -+ j = fread(s+i, 1, 4094, F); -+ } -+ } -+ -+ s[i] = '\0'; -+ fclose(F); -+ return s; -+} -+ -+ -+/* parse_include(): -+ * -+ * taken from parse_program from awk.c -+ * END{} is not parsed here, and BEGIN{} is executed immediately -+ */ -+static void parse_include(char *p) -+{ -+ uint32_t tclass; -+ chain *initseq = NULL; -+ chain tmp; -+ func *f; -+ var *v, *tv; -+ -+ tv = nvalloc(1); -+ memset(&tmp, 0, sizeof(tmp)); -+ pos = p; -+ t.lineno = 1; -+ while ((tclass = next_token(TC_EOF | TC_OPSEQ | -+ TC_OPTERM | TC_BEGIN | TC_FUNCDECL)) != TC_EOF) { -+ if (tclass & TC_OPTERM) -+ continue; -+ -+ seq = &tmp; -+ if (tclass & TC_BEGIN) { -+ initseq = xzalloc(sizeof(chain)); -+ seq = initseq; -+ chain_group(); -+ } else if (tclass & TC_FUNCDECL) { -+ next_token(TC_FUNCTION); -+ pos++; -+ f = newfunc(t.string); -+ f->type = AWKFUNC; -+ f->x.body.first = NULL; -+ f->nargs = 0; -+ while (next_token(TC_VARIABLE | TC_SEQTERM) & TC_VARIABLE) { -+ v = findvar(ahash, t.string); -+ v->x.aidx = (f->nargs)++; -+ -+ if (next_token(TC_COMMA | TC_SEQTERM) & TC_SEQTERM) -+ break; -+ } -+ seq = &(f->x.body); -+ chain_group(); -+ clear_array(ahash); -+ } -+ } -+ if (initseq && initseq->first) -+ tv = evaluate(initseq->first, tv); -+ nvfree(tv); -+} -+ -+ -+/* include an awk file and run its BEGIN{} section */ -+static xhash *includes = NULL; -+static void include_file(char *filename) -+{ -+ char *s; -+ var *v; -+ -+ if (!includes) -+ includes = hash_init(); -+ -+ /* find out if the file has been included already */ -+ v = findvar(includes, filename); -+ if (istrue(v)) -+ return; -+ setvar_s(v, "1"); -+ -+ /* read include file */ -+ s = get_file(filename); -+ if (!s) { -+ fprintf(stderr, "Could not open file.\n"); -+ return; -+ } -+ parse_include(s+1); -+ free(s); -+} -+ -+static var *include(var *res, var *args, int nargs) -+{ -+ char *s; -+ -+ s = getvar_s(args); -+ if (s && (strlen(s) > 0)) -+ include_file(s); -+ -+ return res; -+} -+ -+/* parse an awk expression */ -+static var *parse_awk(char *str, var *tv) -+{ -+ chain body; -+ node *n; -+ -+ memset(&body, 0, sizeof(body)); -+ pos = str; -+ seq = &body; -+ -+ /* end of expression, assume that there's going to be a free byte -+ * at the end of the string that can be used for the ')' */ -+ strcat(str + strlen(str), "}"); -+ n = parse_expr(TC_GRPTERM); -+ if (!n) -+ return NULL; -+ -+ return evaluate(n, tv); -+} -+ -+static inline void print_translate(char *s) -+{ -+ char *str = s; -+ if (lang_inuse) -+ str = translate_line(s); -+ fputs(str, stdout); -+ fflush(stdout); -+ if (lang_inuse) -+ free(str); -+} -+ -+static void render_element(struct template_cb *tcb, struct template_element *e) -+{ -+ var *v; -+ char *s, *s2; -+ int i; -+ -+ if (!e || !e->var) -+ return; -+ lineno = e->line; -+ switch (e->t) { -+ case T_TEXT: -+ s = malloc(strlen(e->var) + 2); -+ strcpy(s, e->var); -+ print_translate(s); -+ free(s); -+ break; -+ case T_CODE: -+ s = malloc(strlen(e->var) + 2); -+ strcpy(s, e->var); -+ v = nvalloc(1); -+ s2 = strdup(getvar_s(parse_awk(s, v))); -+ nvfree(v); -+ print_translate(s2); -+ free(s); -+ free(s2); -+ break; -+ case T_IF: -+ s = malloc(strlen(e->var) + 2); -+ strcpy(s, e->var); -+ v = nvalloc(1); -+ i = istrue(parse_awk(s, v)); -+ nvfree(v); -+ free(s); -+ -+ if (i) -+ execute_template(tcb, e->sub); -+ else if (e->sub2) -+ execute_template(tcb, e->sub2); -+ break; -+ case T_FOR: { -+ v = newvar(e->var); -+ hashwalk_init(v, iamarray(findvar(vhash, e->in))); -+ while (hashwalk_next(v)) { -+ execute_template(tcb, e->sub); -+ } -+ clrvar(v); -+ } -+ break; -+ default: -+ break; -+ } -+} -+ -+/* awk method render(), which opens a template file and processes all awk ssi calls */ -+static void render_file(char *filename) -+{ -+ struct template_cb tcb; -+ struct template_element *e; -+ FILE *f; -+ char *oldprg; -+ int oldlnr; -+ -+ if (!filename) -+ return; -+ -+ oldlnr = lineno; -+ oldprg = programname; -+ programname = filename; -+ -+ f = fopen(filename, "r"); -+ if (!f) -+ return; -+ -+ memset(&tcb, 0, sizeof(tcb)); -+ tcb.handle_element = render_element; -+ e = parse_template(&tcb, f); -+ execute_template(&tcb, e); -+ free_template(&tcb, e); -+ fclose(f); -+ programname = oldprg; -+ lineno = oldlnr; -+} -+ -+static var *render(var *res, var *args, int nargs) -+{ -+ char *s; -+ -+ s = getvar_s(args); -+ if (!s) -+ return res; -+ -+ render_file(s); -+ -+ return res; -+} -+ -+/* Call render, but only if this function hasn't been called already */ -+static int layout_rendered = 0; -+static var *render_layout(var *res, var *args, int nargs) -+{ -+ if (layout_rendered) -+ return res; -+ layout_rendered = 1; -+ return render(res, args, nargs); -+} -+ -+/* registers a global c function for the awk interpreter */ -+static void register_cfunc(char *name, awk_cfunc cfunc, int nargs) -+{ -+ func *f; -+ -+ f = newfunc(name); -+ f->type = CFUNC; -+ f->x.cfunc = cfunc; -+ f->nargs = nargs; -+} -+ -+static void putvar(vartype type, char *name, char *value) -+{ -+ if (type != FORM_VAR) -+ return; -+ -+ setvar_u(findvar(formvar, name), value); -+} -+ -+static char *cgi_getvar(char *name) -+{ -+ if (!formvar) { -+ formvar = hash_init(); -+ cgi_init(putvar); -+ } -+ -+ if (!formvar || !name) -+ return NULL; -+ -+ return getvar_s(findvar(formvar, name)); -+} -+ -+/* function call for accessing cgi form variables */ -+static var *getvar(var *res, var *args, int nargs) -+{ -+ char *s; -+ char *svar; -+ -+ s = getvar_s(args); -+ if (!s) -+ return res; -+ -+ svar = cgi_getvar(s); -+ if (!svar) -+ return res; -+ -+ setvar_u(res, svar); -+ -+ return res; -+} -+ -+/* call an awk function without arguments by string reference */ -+static var *call(var *res, var *args, int nargs) -+{ -+ char *s = getvar_s(args); -+ func *f; -+ -+ if (!s) -+ goto done; -+ -+ f = newfunc(s); -+ if (f && f->type == AWKFUNC && f->x.body.first) -+ return evaluate(f->x.body.first, res); -+ -+done: -+ return res; -+} -+ -+ -+static int run_awxscript(char *name) -+{ -+ var tv, *layout, *action; -+ char *tmp, *s = NULL; -+ -+ zero_out_var(&tv); -+ programname = name; -+ -+ /* read the main controller source */ -+ s = get_file(programname); -+ if (!s) { -+ fprintf(stderr, "Could not open file\n"); -+ return 1; -+ } -+ parse_program(s+1); -+ free(s); -+ -+ -+ /* set some defaults for ACTION and LAYOUT, which will have special meaning */ -+ layout = newvar("LAYOUT"); -+ setvar_s(layout, "views/layout.ahtml"); -+ -+ /* run the BEGIN {} block */ -+ evaluate(beginseq.first, &tv); -+ -+ action = newvar("ACTION"); -+ if (!(strlen(getvar_s(action)) > 0)) { -+ tmp = cgi_getvar("action"); -+ if (!tmp || (strlen(tmp) <= 0)) -+ tmp = strdup("default"); -+ -+ setvar_p(action, tmp); -+ } -+ -+ /* call the action (precedence: begin block override > cgi parameter > "default") */ -+ tmp = xmalloc(strlen(getvar_s(action)) + 7); -+ sprintf(tmp, "handle_%s", getvar_s(action)); -+ setvar_s(action, tmp); -+ call(&tv, action, 1); -+ free(tmp); -+ -+ /* render the selected layout, will do nothing if render_layout has been called from awk */ -+ render_layout(&tv, layout, 1); -+ -+ return 0; -+} -+ -+ -+/* main awx processing function. called from awk_main() */ -+static int do_awx(int argc, char **argv) -+{ -+ int ret = -1; -+ var tv; -+ int i, c; -+ char **args = argv; -+ -+ zero_out_var(&tv); -+ -+ /* register awk C callbacks */ -+ register_cfunc("getvar", getvar, 1); -+ register_cfunc("render", render, 1); -+ register_cfunc("render_layout", render_layout, 1); -+ register_cfunc("call", call, 1); -+ register_cfunc("include", include, 1); -+ register_cfunc("init_lang", init_lang, 1); -+ register_cfunc("load_lang", load_lang, 1); -+ -+ if (!is_awx) -+ return 0; -+ -+ /* fill in ARGV array */ -+ setvar_i(V[ARGC], argc + 1); -+ setari_u(V[ARGV], 0, "awx"); -+ i = 0; -+ while (*args) -+ setari_u(V[ARGV], ++i, *args++); -+ -+ while((c = getopt(argc, argv, "i:f:")) != EOF) { -+ switch(c) { -+ case 'i': -+ programname = optarg; -+ include_file(optarg); -+ break; -+ case 'f': -+ ret = 0; -+ programname = optarg; -+ render_file(optarg); -+ goto done; -+ } -+ } -+ argc -= optind; -+ argv += optind; -+ -+ if (argc < 1) { -+ fprintf(stderr, "Invalid argument.\n"); -+ goto done; -+ } -+ -+ ret = run_awxscript(*argv); -+ -+done: -+ exit(ret); -+} -+ -+/* entry point for awx applet */ -+int awx_main(int argc, char **argv) -+{ -+ is_awx = 1; -+ return awk_main(argc, argv); -+} -+ -Index: busybox-1.4.2/editors/awx_parser.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/editors/awx_parser.h 2007-06-04 13:21:37.928210704 +0200 -@@ -0,0 +1,38 @@ -+#ifndef __TEMPLATE_PARSER_H -+#define __TEMPLATE_PARSER_H -+ -+enum type { -+ T_TEXT, -+ T_FOR, -+ T_IF, -+ T_CODE -+}; -+ -+struct template_element; -+struct template_cb; -+ -+struct template_cb { -+ void *(*prepare_code)(struct template_element *); -+ void (*handle_element)(struct template_cb *, struct template_element *); -+ void (*free_code)(struct template_element *); -+}; -+ -+struct template_element { -+ enum type t; -+ char *var; -+ char *in; -+ int line; -+ void *priv; -+ struct template_element *parent; -+ struct template_element *sub; -+ struct template_element *sub2; -+ struct template_element *prev; -+ struct template_element *next; -+}; -+ -+ -+struct template_element *parse_template(struct template_cb *cb, FILE *in); -+void execute_template(struct template_cb *cb, struct template_element *e); -+void free_template(struct template_cb *cb, struct template_element *e); -+ -+#endif -Index: busybox-1.4.2/editors/awx_parser.l -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/editors/awx_parser.l 2007-06-04 13:21:37.929210552 +0200 -@@ -0,0 +1,302 @@ -+%{ -+#include -+#include -+#include -+#include "busybox.h" -+#include "awx_parser.h" -+ -+enum { -+ S_INIT, -+ S_TEXT, -+ S_CODE, -+ S_IF_START, -+ S_FOR_START, -+ S_FOR_IN, -+ S_END, -+ S_ELSE, -+ S_EOF -+}; -+int state; -+ -+#undef DEBUG -+#ifdef DEBUG -+char *statestr[] = { -+ [S_INIT] = "S_INIT", -+ [S_TEXT] = "S_TEXT", -+ [S_CODE] = "S_CODE", -+ [S_IF_START] = "S_IF_START", -+ [S_FOR_START] = "S_FOR_START", -+ [S_FOR_IN] = "S_FOR_IN", -+ [S_EOF] = "S_EOF" -+}; -+ -+char *typestr[] = { -+ [T_TEXT] = "T_TEXT", -+ [T_FOR] = "T_FOR", -+ [T_IF] = "T_IF", -+ [T_CODE] = "T_CODE" -+}; -+#endif -+ -+static struct template_cb *parse_cb; -+static struct template_element *cur, *head; -+static char *textbuf; -+static unsigned int buflen; -+static unsigned int buf_offset; -+static int _lnr = 0; -+ -+static void buf_realloc(void) -+{ -+ buflen *= 2; -+ textbuf = xrealloc(textbuf, buflen); -+} -+ -+static void parse_error(char *str) -+{ -+ fprintf(stderr, "Parse error%s%s\n", (str ? ": " : "!"), (str ?: "")); -+ exit(255); -+} -+ -+ -+static struct template_element *new_template_element(struct template_element *parent) -+{ -+ struct template_element *ptr; -+ -+ ptr = xzalloc(sizeof(struct template_element)); -+ ptr->parent = parent; -+ return ptr; -+} -+ -+static inline void next_template_element(void) -+{ -+ cur->next = new_template_element(cur->parent); -+ cur->next->prev = cur; -+ cur = cur->next; -+} -+ -+static void addtext(char *text) -+{ -+ while(buf_offset + strlen(text) + 1 > buflen) -+ buf_realloc(); -+ -+ buf_offset += sprintf(&textbuf[buf_offset], "%s", text); -+} -+ -+static void set_state(int newstate) -+{ -+ char *ptr; -+ -+#ifdef DEBUG -+ static int _rec = 0; -+ fprintf(stderr, "DEBUG(%d): %s => %s: %s\n", _rec, statestr[state], statestr[newstate], textbuf); -+#endif -+ ptr = xstrdup(textbuf); -+ if (state == S_FOR_IN) -+ cur->in = ptr; -+ else -+ cur->var = ptr; -+ -+ if (parse_cb && (cur->t == T_CODE) && parse_cb->prepare_code) -+ parse_cb->prepare_code(cur); -+ -+ buf_offset = 0; -+ *textbuf = 0; -+ -+ switch(newstate) { -+#if 0 -+ case S_EOF: -+ if (cur->parent) -+ parse_error(); -+ break; -+#endif -+ case S_FOR_START: -+ if (ptr || !cur->prev) -+ next_template_element(); -+ cur->t = T_FOR; -+ break; -+ case S_IF_START: -+ if (ptr || !cur->prev) -+ next_template_element(); -+ cur->t = T_IF; -+ break; -+ case S_ELSE: -+ cur = cur->parent; -+ if (!cur) -+ parse_error("'@else' without parent element"); -+ cur->sub2 = new_template_element(cur); -+ cur = cur->sub2; -+ newstate = S_TEXT; -+ break; -+ case S_END: -+#ifdef DEBUG -+ _rec--; -+#endif -+ cur = cur->parent; -+ if (!cur) -+ parse_error("'@end' without parent element"); -+ -+ next_template_element(); -+ cur->t = T_TEXT; -+ newstate = S_TEXT; -+ break; -+ case S_TEXT: -+ switch (cur->t) { -+ case T_CODE: -+ next_template_element(); -+ break; -+ case T_IF: -+ case T_FOR: -+#ifdef DEBUG -+ _rec++; -+#endif -+ cur->sub = new_template_element(cur); -+ cur = cur->sub; -+ break; -+ default: -+ break; -+ } -+ cur->t = T_TEXT; -+ break; -+ case S_CODE: -+ if (ptr || !cur->prev) -+ next_template_element(); -+ cur->t = T_CODE; -+ break; -+ default: -+ break; -+ } -+ cur->line = _lnr; -+ state = newstate; -+} -+ -+%} -+ -+%% -+"<%"[ \n\t]*"@if"[ \n\t]+ { -+ if (state == S_TEXT) -+ set_state(S_IF_START); -+ else -+ REJECT; -+} -+ -+"<%"[ \n\t]*"@for"[ \n\t]+ { -+ if (state == S_TEXT) -+ set_state(S_FOR_START); -+ else -+ REJECT; -+} -+ -+[ \n\t]+"in"[ \n\t]+ { -+ if (state == S_FOR_START) -+ set_state(S_FOR_IN); -+ else -+ REJECT; -+} -+ -+"<%"[ \n\t]*"@end"[ \n\t]*%> { -+ if (state != S_TEXT) -+ REJECT; -+ set_state(S_END); -+} -+ -+"<%"[ \n\t]*"@else"[ \n\t]*%> { -+ if (state != S_TEXT) -+ REJECT; -+ set_state(S_ELSE); -+} -+ -+"<%" { -+ if (state != S_TEXT) -+ parse_error("'<%' cannot be nested"); -+ set_state(S_CODE); -+} -+ -+[ \n\t]"%>" { -+ if (state == S_TEXT) -+ REJECT; -+ set_state(S_TEXT); -+} -+ -+\n { -+ _lnr++; -+ if (state == S_TEXT) -+ addtext(yytext); -+} -+. { -+ addtext(yytext); -+} -+ -+ -+%% -+ -+ -+void execute_template(struct template_cb *cb, struct template_element *e) -+{ -+ static int rec = 0; -+ -+ while (e) { -+#ifdef DEBUG -+ fprintf(stderr, "DEBUG: execute(%d)\t%s\n", rec, typestr[e->t]); -+#endif -+ rec++; -+ if (cb->handle_element) -+ cb->handle_element(cb, e); -+ rec--; -+ e = e->next; -+ } -+} -+ -+int yywrap() -+{ -+ set_state(S_EOF); -+ return 1; -+} -+ -+struct template_element *parse_template(struct template_cb *cb, FILE *in) -+{ -+ _lnr = 1; -+ buf_offset = 0; -+ state = S_TEXT; -+ parse_cb = cb; -+ -+ buflen = 4096; -+ textbuf = xzalloc(buflen); -+ -+ head = xzalloc(sizeof(struct template_element)); -+ head->t = T_TEXT; -+ cur = head; -+ -+ yyin = in; -+ yylex(); -+ -+ return head; -+} -+ -+void free_template(struct template_cb *cb, struct template_element *e) -+{ -+ struct template_element *next; -+ return; -+ if (!e) -+ return; -+ -+ switch (e->t) { -+ case T_CODE: -+ if (cb->free_code) -+ cb->free_code(e); -+ break; -+ case T_FOR: -+ case T_IF: -+ free_template(cb, e->sub); -+ break; -+ default: -+ break; -+ } -+ if (e->var) -+ free(e->var); -+ if (e->in) -+ free(e->in); -+ -+ next = e->next; -+ free(e); -+ return free_template(cb, next); -+} -Index: busybox-1.4.2/editors/Config.in -=================================================================== ---- busybox-1.4.2.orig/editors/Config.in 2007-06-04 13:21:31.486190040 +0200 -+++ busybox-1.4.2/editors/Config.in 2007-06-04 13:21:37.929210552 +0200 -@@ -12,6 +12,13 @@ - Awk is used as a pattern scanning and processing language. This is - the BusyBox implementation of that programming language. - -+config AWX -+ bool "Enable awx (awk web extension)" -+ default n -+ depends on AWK -+ help -+ awx - awk web extension -+ - config FEATURE_AWK_MATH - bool "Enable math functions (requires libm)" - default y -Index: busybox-1.4.2/editors/Kbuild -=================================================================== ---- busybox-1.4.2.orig/editors/Kbuild 2007-06-04 13:21:31.492189128 +0200 -+++ busybox-1.4.2/editors/Kbuild 2007-06-04 13:21:37.929210552 +0200 -@@ -10,3 +10,12 @@ - lib-$(CONFIG_PATCH) += patch.o - lib-$(CONFIG_SED) += sed.o - lib-$(CONFIG_VI) += vi.o -+lib-$(CONFIG_AWX) += awx_parser.o -+ -+editors/awx_parser.c: editors/awx_parser.l editors/awx_parser.h -+ @flex $< -+ @mv lex.yy.c $@ -+ -+editors/awx_parser.o: editors/awx_parser.c FORCE -+ $(call cmd,force_checksrc) -+ $(call if_changed_rule,cc_o_c) -Index: busybox-1.4.2/include/applets.h -=================================================================== ---- busybox-1.4.2.orig/include/applets.h 2007-06-04 13:21:36.732392496 +0200 -+++ busybox-1.4.2/include/applets.h 2007-06-04 13:21:37.929210552 +0200 -@@ -60,6 +60,7 @@ - USE_ARPING(APPLET(arping, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) - USE_ASH(APPLET_NOUSAGE(ash, ash, _BB_DIR_BIN, _BB_SUID_NEVER)) - USE_AWK(APPLET(awk, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) -+USE_AWX(APPLET_NOUSAGE(awx, awx, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) - USE_BASENAME(APPLET(basename, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) - USE_BBCONFIG(APPLET(bbconfig, _BB_DIR_BIN, _BB_SUID_NEVER)) - //USE_BBSH(APPLET(bbsh, _BB_DIR_BIN, _BB_SUID_NEVER)) -Index: busybox-1.4.2/include/cgi.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/include/cgi.h 2007-06-04 13:21:37.929210552 +0200 -@@ -0,0 +1,8 @@ -+#ifndef CGI_H -+#define CGI_H -+ -+typedef enum { FORM_VAR, COOKIE_VAR } vartype; -+typedef void (*var_handler) (vartype, char *, char *); -+int cgi_init(var_handler); -+ -+#endif -Index: busybox-1.4.2/libbb/cgi.c -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ busybox-1.4.2/libbb/cgi.c 2007-06-04 13:21:37.930210400 +0200 -@@ -0,0 +1,457 @@ -+/* -------------------------------------------------------------------------- -+ * functions for processing cgi form data -+ * Copyright (C) 2007 by Felix Fietkau -+ * -+ * parts taken from the core of haserl.cgi - a poor-man's php for embedded/lightweight environments -+ * $Id: haserl.c,v 1.13 2004/11/10 17:59:35 nangel Exp $ -+ * Copyright (c) 2003,2004 Nathan Angelacos (nangel@users.sourceforge.net) -+ * -+ * This program is free software; you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License as published by -+ * the Free Software Foundation; either version 2 of the License, or -+ * (at your option) any later version. -+ * -+ * This program 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 -+ * General Public License for more details. -+ * -+ * You should have received a copy of the GNU General Public License -+ * along with this program; if not, write to the Free Software -+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -+ * -+ * ----- -+ * The x2c() and unescape_url() routines were taken from -+ * http://www.jmarshall.com/easy/cgi/getcgi.c.txt -+ * -+ * The comments in that text file state: -+ * -+ *** Written in 1996 by James Marshall, james@jmarshall.com, except -+ *** that the x2c() and unescape_url() routines were lifted directly -+ *** from NCSA's sample program util.c, packaged with their HTTPD. -+ *** For the latest, see http://www.jmarshall.com/easy/cgi/ -+ * ----- -+ * -+ ------------------------------------------------------------------------- */ -+ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#ifndef MAX_UPLOAD_KB -+#define MAX_UPLOAD_KB 2048 -+#endif -+#define TEMPDIR "/tmp" -+ -+static int global_upload_size = 0; -+static int ReadMimeEncodedInput(char *qs); -+static var_handler do_putvar = NULL; -+ -+/* -+ * Convert 2 char hex string into char it represents -+ * (from http://www.jmarshall.com/easy/cgi) -+ */ -+static char x2c (char *what) { -+ char digit; -+ -+ digit=(what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0')); -+ digit *=16; -+ digit+=(what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0')); -+ -+ return digit; -+} -+ -+/* -+ * unsescape %xx to the characters they represent -+ */ -+ -+static void unescape_url (char *url) { -+ int i,j; -+ -+ for (i=0, j=0; url[j]; ++i, ++j) { -+ if ((url[i] = url[j]) == '%') { -+ url[i] = x2c(&url[j+1]); -+ j+=2; -+ } -+ } -+ url[i]='\0'; -+} -+ -+static inline void put_var(vartype type, char *var) -+{ -+ char *val; -+ -+ if (!do_putvar) -+ return; -+ -+ val = strchr(var, '='); -+ if (!val) -+ return; -+ -+ *val = 0; -+ val++; -+ do_putvar(type, var, val); -+ -+ return; -+} -+ -+ -+/* CookieVars () -+ * if HTTP_COOKIE is passed as an environment variable, -+ * attempt to parse its values into environment variables -+ */ -+static void CookieVars (void) -+{ -+ char *qs; -+ char *token; -+ -+ if (getenv("HTTP_COOKIE") != NULL) -+ qs=strdup(getenv("HTTP_COOKIE")); -+ else -+ return; -+ -+ /** split on; to extract name value pairs */ -+ token=strtok(qs, ";"); -+ while (token) { -+ // skip leading spaces -+ while ( token[0] == ' ' ) -+ token++; -+ -+ put_var(COOKIE_VAR, token); -+ -+ token = strtok(NULL, ";"); -+ } -+ free (qs); -+} -+ -+/* -+ * Read cgi variables from query string, and put in environment -+ */ -+static int ReadCGIQueryString (void) -+{ -+ char *qs; -+ char *token; -+ int i; -+ -+ if (getenv("QUERY_STRING") != NULL) -+ qs=strdup(getenv("QUERY_STRING")); -+ else -+ return 0; -+ -+ /* change plusses into spaces */ -+ for (i=0; qs[i]; i++ ) { if (qs[i] == '+' ) { qs[i] = ' ';} }; -+ -+ /** split on & and ; to extract name value pairs */ -+ -+ token=strtok(qs, "&;"); -+ while (token) { -+ unescape_url(token); -+ put_var(FORM_VAR, token); -+ token=strtok(NULL, "&;"); -+ } -+ free(qs); -+ -+ return 0; -+} -+ -+ -+/* -+ * Read cgi variables from stdin (for POST queries) -+ * (oh... and if its mime-encoded file upload, we save the -+ * file to /tmp; and return the name of the tmp file -+ * the cgi script is responsible for disposing of the tmp file -+ */ -+ -+static int ReadCGIPOSTValues (void) { -+ char *qs; -+ int content_length; -+ int i; -+ char *token; -+ -+ -+ if (getenv("CONTENT_LENGTH") == NULL) -+ return(-1); -+ else -+ content_length = atoi(getenv("CONTENT_LENGTH")); -+ -+ /* protect ourselves from 20GB file uploads */ -+ if (content_length > MAX_UPLOAD_KB * 1024 ) { -+ /* But we need to finish reading the content */ -+ while ( fread( &i, sizeof(int), 1, stdin) == 1 ); -+ return -1; -+ } -+ -+ if (!(qs=malloc(content_length+1))) -+ return -1; -+ -+ /* set the buffer to null, so that a browser messing with less -+ data than content_length won't buffer underrun us */ -+ memset(qs, 0 ,content_length+1); -+ -+ if ((!fread(qs,content_length,1,stdin) && -+ (content_length > 0) -+ && !feof(stdin))) { -+ -+ free(qs); -+ return -1; -+ } -+ -+ if (getenv("CONTENT_TYPE") && (strncasecmp(getenv("CONTENT_TYPE"), "multipart/form-data", 19) == 0)) { -+ /* This is a mime request, we need to go to the mime handler */ -+ i=ReadMimeEncodedInput(qs); -+ free(qs); -+ -+ return i; -+ } -+ -+ /* change plusses into spaces */ -+ for (i=0; qs[i]; i++ ) { if (qs[i] == '+' ) { qs[i] = ' ';} }; -+ -+ /** split on & and ; to extract name value pairs */ -+ token=strtok(qs, "&;"); -+ while (token) { -+ unescape_url(token); -+ put_var(FORM_VAR, token); -+ token=strtok(NULL, "&;"); -+ } -+ -+ free(qs); -+ -+ return 0; -+} -+ -+/* -+ * LineToStr - Scans char and replaces the first "\n" with a "\0"; -+ * If it finds a "\r", it does that to; (fix DOS brokennes) returns -+ * the length of the string; -+ */ -+static int LineToStr (char *string, size_t max) { -+ size_t offset=0; -+ -+ while ((offset < max) && (string[offset] != '\n') && (string[offset] != '\r')) -+ offset++; -+ -+ if (string[offset] == '\r') { -+ string[offset]='\0'; -+ offset++; -+ } -+ if (string[offset] == '\n') { -+ string[offset]='\0'; -+ offset++; -+ } -+ -+ return offset; -+} -+ -+ -+/* -+ * ReadMimeEncodedInput - handles things that are mime encoded -+ * takes a pointer to the input; returns 0 on success -+ */ -+ -+static int ReadMimeEncodedInput(char *qs) -+{ -+ char *boundary; -+ char *ct; -+ int i; -+ int datastart; -+ size_t cl; -+ size_t offset; -+ char *envname; -+ char *filename; -+ char *ptr; -+ int line; -+ char tmpname[] = TEMPDIR "/XXXXXX"; -+ int fd; -+ /* we should only get here if the content type was set. Segfaults happen -+ if Content_Type is null */ -+ -+ if (getenv("CONTENT_LENGTH") == NULL) -+ /* No content length?! */ -+ return(-1); -+ -+ cl=atoi(getenv("CONTENT_LENGTH")); -+ -+ /* we do this 'cause we can't mess with the real env. variable - it would -+ * overwrite the environment - I tried. -+ */ -+ i=strlen(getenv("CONTENT_TYPE"))+1; -+ ct=malloc(i); -+ if (ct) -+ memcpy(ct, getenv("CONTENT_TYPE"), i); -+ else -+ return(-1); -+ -+ i=(int) NULL; -+ if (ct != NULL) { -+ while (i < strlen(ct) && (strncmp("boundary=", &ct[i], 9) != 0)) -+ i++; -+ } -+ if (i == strlen(ct)) { -+ /* no boundary informaiton found */ -+ free(ct); -+ return -1; -+ } -+ boundary=&ct[i+7]; -+ /* add two leading -- to the boundary */ -+ boundary[0]='-'; -+ boundary[1]='-'; -+ -+ /* begin the big loop. Look for: -+ --boundary -+ Content-Disposition: form-data; name="......." -+ .... -+ -+ content -+ --boundary -+ Content-Disposition: form-data; name="....." filename="....." -+ ... -+ -+ --boundary-- -+ eof -+ */ -+ -+ offset=0; -+ while (offset < cl) { -+ /* first look for boundary */ -+ while ((offset < cl) && (memcmp(&qs[offset], boundary, strlen(boundary)))) -+ offset++; -+ -+ /* if we got here and we ran off the end, its an error */ -+ if (offset >= cl) { -+ free(ct); -+ return -1; -+ } -+ -+ /* if the two characters following the boundary are --, */ -+ /* then we are at the end, exit */ -+ if (memcmp(&qs[offset+strlen(boundary)], "--", 2) == 0) { -+ offset+=2; -+ break; -+ } -+ /* find where the offset should be */ -+ line=LineToStr(&qs[offset], cl-offset); -+ offset+=line; -+ -+ /* Now we're going to look for content-disposition */ -+ line=LineToStr(&qs[offset], cl-offset); -+ if (strncasecmp(&qs[offset], "Content-Disposition", 19) != 0) { -+ /* hmm... content disposition was not where we expected it */ -+ free(ct); -+ return -1; -+ } -+ /* Found it, so let's go find "name=" */ -+ if (!(envname=strstr(&qs[offset], "name="))) { -+ /* now name= is missing?! */ -+ free(ct); -+ return(-1); -+ } else -+ envname+=6; -+ -+ /* is there a filename tag? */ -+ if ((filename=strstr(&qs[offset], "filename="))!= NULL) -+ filename+=10; -+ else -+ filename=NULL; -+ -+ /* make envname and filename ASCIIZ */ -+ for (i=0; (envname[i] != '"') && (envname[i] != '\0'); i++); -+ -+ envname[i] = '\0'; -+ if (filename) { -+ for (i=0; (filename[i] != '"') && (filename[i] != '\0'); i++); -+ filename[i] = '\0'; -+ } -+ offset+=line; -+ -+ /* Ok, by some miracle, we have the name; let's skip till we */ -+ /* come to a blank line */ -+ line=LineToStr(&qs[offset], cl-offset); -+ while (strlen(&qs[offset]) > 1) { -+ offset+=line; -+ line=LineToStr(&qs[offset], cl-offset); -+ } -+ offset+=line; -+ datastart=offset; -+ /* And we go back to looking for a boundary */ -+ while ((offset < cl) && (memcmp(&qs[offset], boundary, strlen(boundary)))) -+ offset++; -+ -+ /* strip [cr] lf */ -+ if ((qs[offset-1] == '\n') && (qs[offset-2] == '\r')) -+ offset-=2; -+ else -+ offset-=1; -+ -+ qs[offset]=0; -+ -+ /* ok, at this point, we know where the name is, and we know */ -+ /* where the content is... we have to do one of two things */ -+ /* based on whether its a file or not */ -+ if (filename==NULL) { /* its not a file, so its easy */ -+ /* just jam the content after the name */ -+ memcpy(&envname[strlen(envname)+1], &qs[datastart], offset-datastart+1); -+ envname[strlen(envname)]='='; -+ put_var(FORM_VAR, envname); -+ } else { /* handle the fileupload case */ -+ if (offset-datastart) { /* only if they uploaded */ -+ if ( global_upload_size == 0 ) { -+ return -1; -+ } -+ /* stuff in the filename */ -+ ptr= calloc ( sizeof (char), strlen(envname)+strlen(filename)+2+5 ); -+ sprintf (ptr, "%s_name=%s", envname, filename); -+ put_var(FORM_VAR, ptr); -+ free(ptr); -+ -+ fd=mkstemp(tmpname); -+ -+ if (fd == -1) -+ return(-1); -+ -+ write(fd, &qs[datastart], offset-datastart); -+ close(fd); -+ ptr= calloc (sizeof(char), strlen(envname)+strlen(tmpname)+2); -+ sprintf (ptr, "%s=%s", envname, tmpname); -+ put_var(FORM_VAR, ptr); -+ free(ptr); -+ } -+ } -+ } -+ free(ct); -+ return 0; -+} -+ -+ -+/*------------------------------------------------------------------------- -+ * -+ * Main -+ * -+ *------------------------------------------------------------------------*/ -+ -+int cgi_init(var_handler putvar_handler) -+{ -+ int retval = 0; -+ -+ do_putvar = putvar_handler; -+ -+ /* Read the current environment into our chain */ -+ CookieVars(); -+ if (getenv("REQUEST_METHOD")) { -+ if (strcasecmp(getenv("REQUEST_METHOD"), "GET") == 0) -+ retval = ReadCGIQueryString(); -+ -+ if (strcasecmp(getenv("REQUEST_METHOD"), "POST") == 0) -+ retval = ReadCGIPOSTValues(); -+ } -+ -+ return retval; -+} -Index: busybox-1.4.2/libbb/Kbuild -=================================================================== ---- busybox-1.4.2.orig/libbb/Kbuild 2007-06-04 13:21:37.710243840 +0200 -+++ busybox-1.4.2/libbb/Kbuild 2007-06-04 13:21:37.930210400 +0200 -@@ -118,3 +118,6 @@ - lib-$(CONFIG_MDEV) += xregcomp.o - lib-$(CONFIG_LESS) += xregcomp.o - lib-$(CONFIG_DEVFSD) += xregcomp.o -+ -+lib-$(CONFIG_AWX) += cgi.o -+ diff --git a/package/busybox/patches/999-insmod2.6_search.patch b/package/busybox/patches/999-insmod2.6_search.patch deleted file mode 100644 index 5a93b02887..0000000000 --- a/package/busybox/patches/999-insmod2.6_search.patch +++ /dev/null @@ -1,196 +0,0 @@ ---- busybox/modutils/insmod.c 2007-05-11 12:10:43.000000000 +0200 -+++ busybox/modutils/insmod.c 2007-05-11 12:12:15.000000000 +0200 -@@ -75,6 +75,30 @@ - extern int insmod_ng_main( int argc, char **argv); - #endif - -+static char *m_filename; -+static char *m_fullName; -+#define _PATH_MODULES "/lib/modules" -+ -+static int check_module_name_match(const char *filename, struct stat *statbuf, -+ void *userdata, int depth) -+{ -+ char *fullname = (char *) userdata; -+ -+ if (fullname[0] == '\0') -+ return FALSE; -+ else { -+ char *tmp, *tmp1 = xstrdup(filename); -+ tmp = bb_get_last_path_component(tmp1); -+ if (strcmp(tmp, fullname) == 0) { -+ free(tmp1); -+ /* Stop searching if we find a match */ -+ m_filename = xstrdup(filename); -+ return FALSE; -+ } -+ free(tmp1); -+ } -+ return TRUE; -+} - - #if ENABLE_FEATURE_2_4_MODULES - -@@ -680,7 +704,6 @@ - #endif - - --#define _PATH_MODULES "/lib/modules" - enum { STRVERSIONLEN = 64 }; - - /*======================================================================*/ -@@ -793,37 +816,6 @@ - static int n_ext_modules_used; - extern int delete_module(const char *); - --static char *m_filename; --static char *m_fullName; -- -- --/*======================================================================*/ -- -- --static int check_module_name_match(const char *filename, struct stat *statbuf, -- void *userdata, int depth) --{ -- char *fullname = (char *) userdata; -- -- if (fullname[0] == '\0') -- return FALSE; -- else { -- char *tmp, *tmp1 = xstrdup(filename); -- tmp = bb_get_last_path_component(tmp1); -- if (strcmp(tmp, fullname) == 0) { -- free(tmp1); -- /* Stop searching if we find a match */ -- m_filename = xstrdup(filename); -- return FALSE; -- } -- free(tmp1); -- } -- return TRUE; --} -- -- --/*======================================================================*/ -- - static struct obj_file *arch_new_file(void) - { - struct arch_file *f; -@@ -4265,14 +4257,97 @@ - long ret; - size_t len; - void *map; -- char *filename, *options; -+ char *options, *tmp; -+ struct stat st; -+#if ENABLE_FEATURE_CLEAN_UP -+ FILE *fp = 0; -+#else -+ FILE *fp; -+#endif -+ int k_version = 0; -+ struct utsname myuname; - -- filename = *++argv; -- if (!filename) -+ if (argc < 2) - bb_show_usage(); - -+#if !ENABLE_FEATURE_2_4_MODULES -+ /* Grab the module name */ -+ tmp = basename(xstrdup(argv[1])); -+ len = strlen(tmp); -+ -+ if (uname(&myuname) == 0) { -+ if (myuname.release[0] == '2') { -+ k_version = myuname.release[2] - '0'; -+ } -+ } -+ -+ if (len > 3 && tmp[len - 3] == '.' && tmp[len - 2] == 'k' && tmp[len - 1] == 'o') { -+ len -= 3; -+ tmp[len] = '\0'; -+ } -+ -+ -+ m_fullName = xasprintf("%s.ko", tmp); -+ -+ /* Get a filedesc for the module. Check we we have a complete path */ -+ if (stat(argv[1], &st) < 0 || !S_ISREG(st.st_mode) -+ || (fp = fopen(argv[1], "r")) == NULL -+ ) { -+ /* Hmm. Could not open it. First search under /lib/modules/`uname -r`, -+ * but do not error out yet if we fail to find it... */ -+ if (k_version) { /* uname succeedd */ -+ char *module_dir; -+ char *tmdn; -+ char real_module_dir[FILENAME_MAX]; -+ -+ tmdn = concat_path_file(_PATH_MODULES, myuname.release); -+ /* Jump through hoops in case /lib/modules/`uname -r` -+ * is a symlink. We do not want recursive_action to -+ * follow symlinks, but we do want to follow the -+ * /lib/modules/`uname -r` dir, So resolve it ourselves -+ * if it is a link... */ -+ if (realpath(tmdn, real_module_dir) == NULL) -+ module_dir = tmdn; -+ else -+ module_dir = real_module_dir; -+ recursive_action(module_dir, TRUE, FALSE, FALSE, -+ check_module_name_match, 0, m_fullName, 0); -+ free(tmdn); -+ } -+ -+ /* Check if we have found anything yet */ -+ if (m_filename == 0 || ((fp = fopen(m_filename, "r")) == NULL)) { -+ char module_dir[FILENAME_MAX]; -+ -+ free(m_filename); -+ m_filename = 0; -+ if (realpath (_PATH_MODULES, module_dir) == NULL) -+ strcpy(module_dir, _PATH_MODULES); -+ /* No module found under /lib/modules/`uname -r`, this -+ * time cast the net a bit wider. Search /lib/modules/ */ -+ if (!recursive_action(module_dir, TRUE, FALSE, FALSE, -+ check_module_name_match, 0, m_fullName, 0) -+ ) { -+ if (m_filename == 0 -+ || ((fp = fopen(m_filename, "r")) == NULL) -+ ) { -+ bb_error_msg("%s: no module by that name found", m_fullName); -+#if ENABLE_FEATURE_CLEAN_UP -+ if(fp) -+ fclose(fp); -+ free(m_filename); -+#endif -+ } -+ } else -+ bb_error_msg_and_die("%s: no module by that name found", m_fullName); -+ } -+ } else -+ m_filename = xstrdup(argv[1]); -+#endif -+ - /* Rest is options */ - options = xstrdup(""); -+ argv++; - while (*++argv) { - int optlen = strlen(options); - options = xrealloc(options, optlen + 2 + strlen(*argv) + 2); -@@ -4300,13 +4375,13 @@ - } - #else - len = MAXINT(ssize_t); -- map = xmalloc_open_read_close(filename, &len); -+ map = xmalloc_open_read_close(m_filename, &len); - #endif - - ret = syscall(__NR_init_module, map, len, options); - if (ret != 0) { - bb_perror_msg_and_die("cannot insert '%s': %s (%li)", -- filename, moderror(errno), ret); -+ m_filename, moderror(errno), ret); - } - - return 0;