cross-tools:
.for _tool in ${_btxld} ${_binutils} \
- usr.bin/objformat usr.sbin/crunch/crunchide \
+ usr.bin/objformat usr.bin/crunch/crunchide \
${_gcc34_cross} ${_gcc41_cross}
${ECHODIR} "===> ${_tool} (cross-tools)"; \
cd ${.CURDIR}/${_tool}; \
TO_REMOVE+=/usr/lib/gcc41/crt1.o
TO_REMOVE+=/usr/lib/gcc41/crti.o
TO_REMOVE+=/usr/lib/gcc41/crtn.o
+TO_REMOVE+=/etc/rc.d/atm2.sh
+TO_REMOVE+=/etc/rc.d/atm3.sh
+TO_REMOVE+=/etc/rc.d/rcconf.sh
+TO_REMOVE+=/usr/share/man/cat9/namei.9.gz
+TO_REMOVE+=/usr/share/man/man9/namei.9.gz
+TO_REMOVE+=/usr/share/man/cat5/host.conf.5.gz
+TO_REMOVE+=/usr/share/man/man5/host.conf.5.gz
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/time.h>
-#include <sys/dir.h>
+#include <sys/dirent.h>
#include <sys/socket.h>
#ifndef _KERNEL
# include <stdio.h>
# if (__FreeBSD_version >= 300000)
# include <sys/dirent.h>
# else
-# include <sys/dir.h>
+# include <sys/dirent.h>
# endif
#else
# include <sys/filio.h>
#include <malloc.h>
#include <netdb.h>
#include <string.h>
-#include <sys/dir.h>
+#include <sys/dirent.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#if BSD < 199103
#include <sys/fcntlcom.h>
#endif
-#include <sys/dir.h>
+#include <sys/dirent.h>
#include <net/bpf.h>
#include <net/if.h>
#include <sys/socket.h>
#include <sys/file.h>
#include <sys/ioctl.h>
-#include <sys/dir.h>
+#include <sys/dirent.h>
#include <linux/netdevice.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <net/nit.h>
#include <sys/fcntlcom.h>
-#include <sys/dir.h>
+#include <sys/dirent.h>
#include <net/nit_if.h>
#include <net/nit_pf.h>
#include <net/nit_buf.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <fcntl.h>
-#include <sys/dir.h>
+#include <sys/dirent.h>
#define __KERNEL__
#if LINUX >= 0200
# undef UINT_MAX
#if (__FreeBSD_version >= 300000)
# include <sys/dirent.h>
#else
-# include <sys/dir.h>
+# include <sys/dirent.h>
#endif
#include <net/bpf.h>
#include <sys/socket.h>
#include <sys/file.h>
#include <sys/ioctl.h>
-#include <sys/dir.h>
+#include <sys/dirent.h>
#include <linux/netdevice.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <net/nit.h>
#include <sys/fcntlcom.h>
-#include <sys/dir.h>
+#include <sys/dirent.h>
#include <net/nit_if.h>
#include <net/nit_pf.h>
#include <net/nit_buf.h>
#if (__FreeBSD_version >= 300000)
# include <sys/dirent.h>
#else
-# include <sys/dir.h>
+# include <sys/dirent.h>
#endif
#define _KERNEL
#define KERNEL
/* fix_options - get rid of IP-level socket options */
+void
fix_options(request)
struct request_info *request;
{
sendmail_msp_queue_enable="YES" # Dequeue stuck clientmqueue mail (YES/NO).
sendmail_msp_queue_flags="-L sm-msp-queue -Ac -q30m"
# Flags for sendmail_msp_queue daemon.
+sendmail_rebuild_aliases="YES" # Run newaliases if necessary (YES/NO).
##############################################################
# note: bgfsk, devfs, and lomac left out (from 5.0)
#
FILES= DAEMON LOGIN NETWORKING SERVERS abi accounting addswap adjkerntz \
- amd apm apmd atm1 atm2.sh atm3.sh \
+ amd apm apmd atm1 atm2 atm3 \
battd bootconf bootparams btconfig bthcid ccd cleanvar \
cleartmp cron devd dhclient diskless dmesg dumpon \
fsck ftpd hostapd hostname \
named netif netoptions newsyslog \
network_ipv6 nfsclient nfsd nfsserver nisdomain nscd nsswitch \
dntpd othermta pf pflog ppp ppp-user pppoed pwcheck \
- quota random rarpd rcconf.sh resident rndcontrol root route6d routed \
+ quota random rarpd rcconf resident rndcontrol root route6d routed \
routing rpcbind rtadvd rtsold rwho sysdb savecore sdpd securelevel \
sendmail sensorsd serial sppp sshd statd swap1 syscons sysctl syslogd \
timed ttys usbd varsym vinum virecover watchdogd wpa_supplicant \
done
fi
- # XXX - required by atm3.sh. I don't like having one script depend
+ # XXX - required by atm3. I don't like having one script depend
# on variables in another script (especially in a dynamic
# ordered system like this), but it's necessary for the moment.
#
echo "+++ create lastlog"
/usr/bin/touch /var/log/lastlog
-# Make sure our aliases database is uptodate, the aliases may have
-# been overridden in /conf.
-#
-/usr/bin/newaliases
-
# XXX make sure to create one dir for each printer as requested by lpd
#
# If we do not have a writable /tmp, create a memory
name="sendmail"
rcvar=`set_rcvar`
required_files="/etc/mail/${name}.cf"
+start_precmd="sendmail_precmd"
command=${sendmail_program:-/usr/sbin/sendmail}
pidfile=${sendmail_pidfile:-/var/run/sendmail.pid}
load_rc_config $name
fi
# check modifications on /etc/mail/aliases
- if [ -f "/etc/mail/aliases.db" ]; then
- if [ "/etc/mail/aliases" -nt "/etc/mail/aliases.db" ]; then
- echo \
+ if checkyesno sendmail_rebuild_aliases; then
+ if [ -f "/etc/mail/aliases.db" ]; then
+ if [ "/etc/mail/aliases" -nt "/etc/mail/aliases.db" ]; then
+ echo \
"${name}: /etc/mail/aliases newer than /etc/mail/aliases.db, regenerating"
- /usr/bin/newaliases
- fi
- else
- echo \
+ /usr/bin/newaliases
+ fi
+ else
+ echo \
"${name}: /etc/mail/aliases.db not present, generating"
- /usr/bin/newaliases
+ /usr/bin/newaliases
+ fi
fi
# check couple of common db files, too
THRHDRSDIR= ${INCLUDEDIR}/c++/4.1/bits
gthr.h: ${GCCDIR}/gcc/gthr.h
- sed -e '/^#/s/\([ABCDEFGHIJKLMNOPQRSTUVWXYZ_][ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*\)/_GLIBCPP_\1/g' \
+ sed -e '/^#pragma/b' \
+ -e '/^#/s/\([ABCDEFGHIJKLMNOPQRSTUVWXYZ_][ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*\)/_GLIBCXX_\1/g' \
+ -e 's/_GLIBCXX_SUPPORTS_WEAK/__GXX_WEAK__/g' \
-e 's,^#include "\(.*\)",#include <bits/\1>,g' \
< ${GCCDIR}/gcc/gthr.h > gthr.h
gthr-single.h: ${GCCDIR}/gcc/gthr-single.h
- sed -e 's/\(UNUSED\)/_GLIBCPP_\1/g' \
- -e 's/\(GCC[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*_H\)/_GLIBCPP_\1/g' \
+ sed -e 's/\(UNUSED\)/_GLIBCXX_\1/g' \
+ -e 's/\(GCC[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*_H\)/_GLIBCXX_\1/g' \
< ${GCCDIR}/gcc/gthr-single.h > gthr-single.h
gthr-posix.h: ${GCCDIR}/gcc/gthr-posix.h
- sed -e 's/\(UNUSED\)/_GLIBCPP_\1/g' \
- -e 's/\(GCC[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*_H\)/_GLIBCPP_\1/g' \
- -e 's/\([ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*WEAK\)/_GLIBCPP_\1/g' \
+ sed -e 's/\(UNUSED\)/_GLIBCXX_\1/g' \
+ -e 's/\(GCC[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*_H\)/_GLIBCXX_\1/g' \
+ -e 's/SUPPORTS_WEAK/__GXX_WEAK__/g' \
+ -e 's/\([ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*USE_WEAK\)/_GLIBCXX_\1/g' \
< ${GCCDIR}/gcc/gthr-posix.h > gthr-posix.h
gthr-default.h: ${GCCDIR}/gcc/gthr-posix.h
- sed -e 's/\(UNUSED\)/_GLIBCPP_\1/g' \
- -e 's/\(GCC[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*_H\)/_GLIBCPP_\1/g' \
- -e 's/\([ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*WEAK\)/_GLIBCPP_\1/g' \
+ sed -e 's/\(UNUSED\)/_GLIBCXX_\1/g' \
+ -e 's/\(GCC[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*_H\)/_GLIBCXX_\1/g' \
+ -e 's/SUPPORTS_WEAK/__GXX_WEAK__/g' \
+ -e 's/\([ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*USE_WEAK\)/_GLIBCXX_\1/g' \
-e 's,^#include "\(.*\)",#include <bits/\1>,g' \
< ${GCCDIR}/gcc/gthr-posix.h > gthr-default.h
/* Provide a LIB_SPEC appropriate for DragonFly. Just select the appropriate
libc, depending on whether we're doing profiling or need threads support.
- (simular to the default, except no -lg, and no -p). */
+ (similar to the default, except no -lg, and no -p). */
#ifdef DFBSD_NO_THREADS
#define DFBSD_LIB_SPEC " \
#define PTHREAD_CANCEL_ASYNCHRONOUS 2
#define PTHREAD_CANCELED ((void *) 1)
-/*
- * Forward structure definitions.
- *
- * These are mostly opaque to the user.
- */
-struct pthread;
-struct pthread_attr;
-struct pthread_cond;
-struct pthread_cond_attr;
-struct pthread_mutex;
-struct pthread_mutex_attr;
-struct pthread_once;
-struct pthread_rwlock;
-struct pthread_rwlockattr;
-struct pthread_barrier;
-struct pthread_barrier_attr;
-
-/*
- * Primitive system data type definitions required by P1003.1c.
- *
- * Note that P1003.1c specifies that there are no defined comparison
- * or assignment operators for the types pthread_attr_t, pthread_cond_t,
- * pthread_condattr_t, pthread_mutex_t, pthread_mutexattr_t.
- */
-typedef struct pthread *pthread_t;
-typedef struct pthread_attr *pthread_attr_t;
-typedef struct pthread_mutex *pthread_mutex_t;
-typedef struct pthread_mutex_attr *pthread_mutexattr_t;
-typedef struct pthread_cond *pthread_cond_t;
-typedef struct pthread_cond_attr *pthread_condattr_t;
-typedef int pthread_key_t;
-typedef struct pthread_once pthread_once_t;
-typedef struct pthread_rwlock *pthread_rwlock_t;
-typedef struct pthread_rwlockattr *pthread_rwlockattr_t;
-typedef struct pthread_barrier *pthread_barrier_t;
-typedef struct pthread_barrierattr *pthread_barrierattr_t;
-
-/*
- * Additional type definitions:
- *
- * Note that P1003.1c reserves the prefixes pthread_ and PTHREAD_ for
- * use in header symbols.
- */
-typedef void *pthread_addr_t;
-typedef void *(*pthread_startroutine_t) (void *);
-
-/*
- * Once definitions.
- */
-struct pthread_once {
- int state;
- pthread_mutex_t mutex;
-};
-
/*
* Flags for once initialization.
*/
typedef __uint_least32_t uint_least32_t;
typedef __uint_least64_t uint_least64_t;
+#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)
+#include <machine/int_const.h>
+#endif /* !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) */
+
+#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
+#include <machine/int_limits.h>
+#endif
+
#endif
msgget.c msgrcv.c msgsnd.c nftw.c nice.c \
nlist.c nrand48.c ntp_gettime.c opendir.c \
pause.c pmadvise.c popen.c posix_spawn.c posixshm.c \
- psignal.c pthread_fake.c pw_scan.c pwcache.c \
+ psignal.c pw_scan.c pwcache.c \
raise.c readdir.c readpassphrase.c rewinddir.c \
scandir.c seed48.c seekdir.c semconfig.c semctl.c semget.c semop.c \
setdomainname.c sethostname.c setjmperr.c setmode.c setprogname.c \
* $DragonFly: src/lib/libc/gen/_pthread_stubs.c,v 1.4 2005/05/09 12:43:40 davidxu Exp $
*/
-#include <signal.h>
-#include <pthread.h>
-#include <pthread_np.h>
-
-int _pthread_cond_init_stub(pthread_cond_t *, const pthread_condattr_t *);
-int _pthread_cond_signal_stub(pthread_cond_t *);
-int _pthread_cond_wait_stub(pthread_cond_t *, pthread_mutex_t *);
-void *_pthread_getspecific_stub(pthread_key_t);
-int _pthread_key_create_stub(pthread_key_t *, void (*)(void *));
-int _pthread_key_delete_stub(pthread_key_t);
-int _pthread_main_np_stub(void);
-int _pthread_mutex_destroy_stub(pthread_mutex_t *);
-int _pthread_mutex_init_stub(pthread_mutex_t *,
- const pthread_mutexattr_t *);
-int _pthread_mutex_lock_stub(pthread_mutex_t *);
-int _pthread_mutex_trylock_stub(pthread_mutex_t *);
-int _pthread_mutex_unlock_stub(pthread_mutex_t *);
-int _pthread_mutexattr_init_stub(pthread_mutexattr_t *);
-int _pthread_mutexattr_destroy_stub(pthread_mutexattr_t *);
-int _pthread_mutexattr_settype_stub(pthread_mutexattr_t *, int);
-int _pthread_once_stub(pthread_once_t *, void (*)(void));
-int _pthread_rwlock_init_stub(pthread_rwlock_t *,
- const pthread_rwlockattr_t *);
-int _pthread_rwlock_destroy_stub(pthread_rwlock_t *);
-int _pthread_rwlock_rdlock_stub(pthread_rwlock_t *);
-int _pthread_rwlock_tryrdlock_stub(pthread_rwlock_t *);
-int _pthread_rwlock_trywrlock_stub(pthread_rwlock_t *);
-int _pthread_rwlock_unlock_stub(pthread_rwlock_t *);
-int _pthread_rwlock_wrlock_stub(pthread_rwlock_t *);
-int _pthread_setspecific_stub(pthread_key_t, const void *);
-int _pthread_sigmask_stub(int, const sigset_t *, sigset_t *);
-
-/* define a null pthread structure just to satisfy _pthread_self */
-struct pthread {
-};
-
-static struct pthread main_thread;
+#include <sys/cdefs.h>
+#include <stdlib.h>
/*
* Weak symbols: All libc internal usage of these functions should
* between application locks and libc locks (threads holding the
* latter can't be allowed to exit/terminate).
*/
-__weak_reference(_pthread_cond_init_stub, _pthread_cond_init);
-__weak_reference(_pthread_cond_signal_stub, _pthread_cond_signal);
-__weak_reference(_pthread_cond_wait_stub, _pthread_cond_wait);
-__weak_reference(_pthread_getspecific_stub, _pthread_getspecific);
-__weak_reference(_pthread_key_create_stub, _pthread_key_create);
-__weak_reference(_pthread_key_delete_stub, _pthread_key_delete);
-__weak_reference(_pthread_main_np_stub, _pthread_main_np);
-__weak_reference(_pthread_mutex_destroy_stub, _pthread_mutex_destroy);
-__weak_reference(_pthread_mutex_init_stub, _pthread_mutex_init);
-__weak_reference(_pthread_mutex_lock_stub, _pthread_mutex_lock);
-__weak_reference(_pthread_mutex_trylock_stub, _pthread_mutex_trylock);
-__weak_reference(_pthread_mutex_unlock_stub, _pthread_mutex_unlock);
-__weak_reference(_pthread_mutexattr_init_stub, _pthread_mutexattr_init);
-__weak_reference(_pthread_mutexattr_destroy_stub, _pthread_mutexattr_destroy);
-__weak_reference(_pthread_mutexattr_settype_stub, _pthread_mutexattr_settype);
-__weak_reference(_pthread_once_stub, _pthread_once);
-__weak_reference(_pthread_self_stub, _pthread_self);
-__weak_reference(_pthread_rwlock_init_stub, _pthread_rwlock_init);
-__weak_reference(_pthread_rwlock_rdlock_stub, _pthread_rwlock_rdlock);
-__weak_reference(_pthread_rwlock_tryrdlock_stub, _pthread_rwlock_tryrdlock);
-__weak_reference(_pthread_rwlock_trywrlock_stub, _pthread_rwlock_trywrlock);
-__weak_reference(_pthread_rwlock_unlock_stub, _pthread_rwlock_unlock);
-__weak_reference(_pthread_rwlock_wrlock_stub, _pthread_rwlock_wrlock);
-__weak_reference(_pthread_setspecific_stub, _pthread_setspecific);
-__weak_reference(_pthread_sigmask_stub, _pthread_sigmask);
-
-int
-_pthread_cond_init_stub(pthread_cond_t *cond __unused,
- const pthread_condattr_t *cond_attr __unused)
-{
- return (0);
-}
-
-int
-_pthread_cond_signal_stub(pthread_cond_t *cond __unused)
-{
- return (0);
-}
-int
-_pthread_cond_wait_stub(pthread_cond_t *cond __unused,
- pthread_mutex_t *mutex __unused)
-{
- return (0);
-}
-
-void *
-_pthread_getspecific_stub(pthread_key_t key __unused)
+#define WR(f, n) \
+ __weak_reference(f, _ ## n); \
+ __weak_reference(f, n)
+
+
+WR(stub_zero, pthread_atfork);
+WR(stub_zero, pthread_attr_destroy);
+WR(stub_zero, pthread_attr_get_np);
+WR(stub_zero, pthread_attr_getdetachstate);
+WR(stub_zero, pthread_attr_getinheritsched);
+WR(stub_zero, pthread_attr_getschedparam);
+WR(stub_zero, pthread_attr_getschedpolicy);
+WR(stub_zero, pthread_attr_getscope);
+WR(stub_zero, pthread_attr_getstack);
+WR(stub_zero, pthread_attr_getstackaddr);
+WR(stub_zero, pthread_attr_getstacksize);
+WR(stub_zero, pthread_attr_init);
+WR(stub_zero, pthread_attr_setcreatesuspend_np);
+WR(stub_zero, pthread_attr_setdetachstate);
+WR(stub_zero, pthread_attr_setinheritsched);
+WR(stub_zero, pthread_attr_setschedparam);
+WR(stub_zero, pthread_attr_setschedpolicy);
+WR(stub_zero, pthread_attr_setscope);
+WR(stub_zero, pthread_attr_setstack);
+WR(stub_zero, pthread_attr_setstackaddr);
+WR(stub_zero, pthread_attr_setstacksize);
+WR(stub_zero, pthread_cancel);
+WR(stub_zero, pthread_cleanup_pop);
+WR(stub_zero, pthread_cleanup_push);
+WR(stub_zero, pthread_cond_broadcast);
+WR(stub_zero, pthread_cond_destroy);
+WR(stub_zero, pthread_cond_init);
+WR(stub_zero, pthread_cond_signal);
+WR(stub_zero, pthread_cond_timedwait);
+WR(stub_zero, pthread_cond_wait);
+WR(stub_zero, pthread_condattr_destroy);
+WR(stub_zero, pthread_condattr_init);
+WR(stub_zero, pthread_detach);
+WR(stub_true, pthread_equal);
+WR(stub_exit, pthread_exit);
+WR(stub_zero, pthread_getconcurrency);
+WR(stub_zero, pthread_getprio);
+WR(stub_zero, pthread_getschedparam);
+WR(stub_null, pthread_getspecific);
+WR(stub_zero, pthread_join);
+WR(stub_zero, pthread_key_create);
+WR(stub_zero, pthread_key_delete);
+WR(stub_zero, pthread_kill);
+WR(stub_main, pthread_main_np);
+WR(stub_zero, pthread_multi_np);
+WR(stub_zero, pthread_mutex_destroy);
+WR(stub_zero, pthread_mutex_getprioceiling);
+WR(stub_zero, pthread_mutex_init);
+WR(stub_zero, pthread_mutex_lock);
+WR(stub_zero, pthread_mutex_setprioceiling);
+WR(stub_zero, pthread_mutex_trylock);
+WR(stub_zero, pthread_mutex_unlock);
+WR(stub_zero, pthread_mutexattr_destroy);
+WR(stub_zero, pthread_mutexattr_getkind_np);
+WR(stub_zero, pthread_mutexattr_getprioceiling);
+WR(stub_zero, pthread_mutexattr_getprotocol);
+WR(stub_zero, pthread_mutexattr_getpshared);
+WR(stub_zero, pthread_mutexattr_gettype);
+WR(stub_zero, pthread_mutexattr_init);
+WR(stub_zero, pthread_mutexattr_setkind_np);
+WR(stub_zero, pthread_mutexattr_setprioceiling);
+WR(stub_zero, pthread_mutexattr_setprotocol);
+WR(stub_zero, pthread_mutexattr_setpshared);
+WR(stub_zero, pthread_mutexattr_settype);
+WR(stub_zero, pthread_once);
+WR(stub_zero, pthread_resume_all_np);
+WR(stub_zero, pthread_resume_np);
+WR(stub_zero, pthread_rwlock_destroy);
+WR(stub_zero, pthread_rwlock_init);
+WR(stub_zero, pthread_rwlock_rdlock);
+WR(stub_zero, pthread_rwlock_tryrdlock);
+WR(stub_zero, pthread_rwlock_trywrlock);
+WR(stub_zero, pthread_rwlock_unlock);
+WR(stub_zero, pthread_rwlock_wrlock);
+WR(stub_zero, pthread_rwlockattr_destroy);
+WR(stub_zero, pthread_rwlockattr_getpshared);
+WR(stub_zero, pthread_rwlockattr_init);
+WR(stub_zero, pthread_rwlockattr_setpshared);
+WR(stub_self, pthread_self);
+WR(stub_zero, pthread_set_name_np);
+WR(stub_zero, pthread_setcancelstate);
+WR(stub_zero, pthread_setcanceltype);
+WR(stub_zero, pthread_setconcurrency);
+WR(stub_zero, pthread_setprio);
+WR(stub_zero, pthread_setschedparam);
+WR(stub_zero, pthread_setspecific);
+WR(stub_zero, pthread_sigmask);
+WR(stub_zero, pthread_single_np);
+WR(stub_zero, pthread_suspend_all_np);
+WR(stub_zero, pthread_suspend_np);
+WR(stub_zero, pthread_switch_add_np);
+WR(stub_zero, pthread_switch_delete_np);
+WR(stub_zero, pthread_testcancel);
+WR(stub_zero, pthread_yield);
+WR(stub_zero, sched_yield);
+WR(stub_zero, sem_close);
+WR(stub_zero, sem_destroy);
+WR(stub_zero, sem_getvalue);
+WR(stub_zero, sem_init);
+WR(stub_zero, sem_open);
+WR(stub_zero, sem_post);
+WR(stub_zero, sem_trywait);
+WR(stub_zero, sem_unlink);
+WR(stub_zero, sem_wait);
+
+
+static int __used
+stub_zero(void)
+{
+ return (0);
+}
+
+static void * __used
+stub_null(void)
{
return (NULL);
}
-int
-_pthread_key_create_stub(pthread_key_t *key __unused,
- void (*destructor) (void *) __unused)
+static void * __used
+stub_self(void)
{
- return (0);
-}
+ static struct {} main_thread;
-int
-_pthread_key_delete_stub(pthread_key_t key __unused)
-{
- return (0);
+ return (&main_thread);
}
-int
-_pthread_main_np_stub(void)
+static int __used
+stub_main(void)
{
return (-1);
}
-int
-_pthread_mutex_destroy_stub(pthread_mutex_t *mattr __unused)
+static int __used
+stub_true(void)
{
- return (0);
-}
-
-int
-_pthread_mutex_init_stub(pthread_mutex_t *mutex __unused,
- const pthread_mutexattr_t *mattr __unused)
-{
- return (0);
-}
-
-int
-_pthread_mutex_lock_stub(pthread_mutex_t *mutex __unused)
-{
- return (0);
-}
-
-int
-_pthread_mutex_trylock_stub(pthread_mutex_t *mutex __unused)
-{
- return (0);
-}
-
-int
-_pthread_mutex_unlock_stub(pthread_mutex_t *mutex __unused)
-{
- return (0);
-}
-
-int
-_pthread_mutexattr_init_stub(pthread_mutexattr_t *mattr __unused)
-{
- return (0);
-}
-
-int
-_pthread_mutexattr_destroy_stub(pthread_mutexattr_t *mattr __unused)
-{
- return (0);
+ return (1);
}
-int
-_pthread_mutexattr_settype_stub(pthread_mutexattr_t *mattr __unused,
- int type __unused)
+static void __used
+stub_exit(void)
{
- return (0);
-}
-
-int
-_pthread_once_stub(pthread_once_t *once_control __unused,
- void (*init_routine) (void) __unused)
-{
- return (0);
-}
-
-int
-_pthread_rwlock_init_stub(pthread_rwlock_t *rwlock __unused,
- const pthread_rwlockattr_t *attr __unused)
-{
- return (0);
-}
-
-int
-_pthread_rwlock_destroy_stub(pthread_rwlock_t *rwlock __unused)
-{
- return (0);
-}
-
-int
-_pthread_rwlock_rdlock_stub(pthread_rwlock_t *rwlock __unused)
-{
- return (0);
-}
-
-int
-_pthread_rwlock_tryrdlock_stub(pthread_rwlock_t *rwlock __unused)
-{
- return (0);
-}
-
-int
-_pthread_rwlock_trywrlock_stub(pthread_rwlock_t *rwlock __unused)
-{
- return (0);
-}
-
-int
-_pthread_rwlock_unlock_stub(pthread_rwlock_t *rwlock __unused)
-{
- return (0);
-}
-
-int
-_pthread_rwlock_wrlock_stub(pthread_rwlock_t *rwlock __unused)
-{
- return (0);
-}
-
-pthread_t
-_pthread_self_stub(void)
-{
- return (&main_thread);
-}
-int
-_pthread_setspecific_stub(pthread_key_t key __unused,
- const void *value __unused)
-{
- return (0);
-}
-
-int
-_pthread_sigmask_stub(int how __unused, const sigset_t *set __unused,
- sigset_t *oset __unused)
-{
- return (0);
+ exit(0);
}
.\" $FreeBSD: src/lib/libc/gen/getobjformat.3,v 1.3.2.6 2003/03/13 18:05:37 trhodes Exp $
.\" $DragonFly: src/lib/libc/gen/getobjformat.3,v 1.2 2003/06/17 04:26:42 dillon Exp $
.\"
-.Dd September 7, 1998
+.Dd May 23, 2009
.Dt GETOBJFORMAT 3
.Os
.Sh NAME
.Sh SYNOPSIS
.In objformat.h
.Ft int
-.Fn getobjformat "char *buf" "size_t bufsize" "int *argcp" "char **argv"
+.Fn getobjformat "char *buf" "size_t bufsize" "int *argcp __unused" "char **argv __unused"
.Sh DESCRIPTION
The
.Fn getobjformat
-function
-queries several sources to determine the preferred object file
-format, and copies its name into a buffer provided by the caller.
-.Pp
-The object file format is determined as follows. If
-.Va argv
-is
-.No non- Ns Ev NULL
-and an explicit command line argument such as
-.Fl aout
-or
-.Fl elf
-is present, then that determines the object file format.
-.Pp
-Otherwise, if the variable
-.Ev OBJFORMAT
-is set in the environment, the object file format is taken from its
-value.
-.Pp
-Otherwise, if the file
-.Pa /etc/objformat
-is readable and contains a line of the form
-.Ql OBJFORMAT=xxx ,
-the object file format is taken from there.
-.Pp
-Otherwise, a built-in system default object file format is returned.
+function copies the name of the preferred object file format
+.Dq ( elf )
+into a buffer provided by the caller.
+The function is currently provided only for backward compatibility.
.Pp
.Va buf
points to a user-supplied buffer into which the name of the object
file format is copied.
.Va bufsize
-gives the size of the buffer in bytes. The string placed in
+gives the size of the buffer in bytes.
+The string placed in
.Va buf
-is always null-terminated. It is an error if the buffer is too
-small to hold the null-terminated name.
+is always null-terminated.
+It is an error if the buffer is too small to hold the null-terminated name.
.Pp
.Va argv
-points to a
-.Dv NULL Ns -terminated
-argument vector to be scanned for object
-format options.
-.Va argv
-may be
-.Dv NULL ,
-in which case the argument vector is not scanned.
-.Pp
-If
-.Va argcp
-is non-NULL, any object format options are deleted from the
-argument vector, and the updated argument count is stored into
-the integer referenced by
-.Va argcp .
-If
+and
.Va argcp
-is
-.Dv NULL ,
-the argument vector is left unchanged.
+are unused and new applications should set them to
+.Dv NULL .
.Sh RETURN VALUES
On success,
.Fn getobjformat
If the supplied buffer is too small to hold the object file format
and its null terminator,
.Fn getobjformat
-returns -1. In that case, the contents of the buffer and argument
+returns -1.
+In that case, the contents of the buffer and argument
vector supplied by the caller are indeterminate.
-.Sh ENVIRONMENT
-.Bl -tag -width OBJFORMAT
-.It Ev OBJFORMAT
-If the environment variable
-.Ev OBJFORMAT
-is set, it overrides the default object file format.
-.Ev OBJFORMAT takes precedence over
-.Pa /etc/objformat .
-.El
-.Sh FILES
-.Bl -tag -width /etc/objformat -compact
-.It Pa /etc/objformat
-If present, specifies the object file format to use. Syntax is
-.Ql OBJFORMAT=xxx .
-.El
.Sh SEE ALSO
.Xr objformat 1
.Sh HISTORY
+++ /dev/null
-/*
- * Copyright (c) 2004 The DragonFly Project. All rights reserved.
- *
- * This code is derived from software contributed to The DragonFly Project
- * by Simon Schubert <corecode@fs.ei.tum.de>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of The DragonFly Project nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific, prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $DragonFly: src/lib/libc/gen/pthread_fake.c,v 1.3 2008/05/25 21:34:49 hasso Exp $
- */
-
-#ifndef _THREAD_SAFE
-/*
- * Provide the functions for non-threaded programs using
- * thread-aware dynamic modules.
- *
- * This list explicitly lakes pthread_create, since an application
- * using this function clearly should be linked against -lc_r.
- * Leaving this function out allows the linker to catch this.
- * Same reason applies for thread-aware modules.
- */
-
-#include <sys/cdefs.h>
-
-#include <errno.h>
-#include <stddef.h>
-
-int _pthread_fake_inval(void);
-void *_pthread_fake_null(void);
-
-__weak_reference(_pthread_fake_inval, pthread_atfork);
-__weak_reference(_pthread_fake_inval, pthread_attr_destroy);
-__weak_reference(_pthread_fake_inval, pthread_attr_get_np);
-__weak_reference(_pthread_fake_inval, pthread_attr_getdetachstate);
-__weak_reference(_pthread_fake_inval, pthread_attr_getinheritsched);
-__weak_reference(_pthread_fake_inval, pthread_attr_getschedparam);
-__weak_reference(_pthread_fake_inval, pthread_attr_getschedpolicy);
-__weak_reference(_pthread_fake_inval, pthread_attr_getscope);
-__weak_reference(_pthread_fake_inval, pthread_attr_getstack);
-__weak_reference(_pthread_fake_inval, pthread_attr_getstackaddr);
-__weak_reference(_pthread_fake_inval, pthread_attr_getstacksize);
-__weak_reference(_pthread_fake_inval, pthread_attr_init);
-__weak_reference(_pthread_fake_inval, pthread_attr_setcreatesuspend_np);
-__weak_reference(_pthread_fake_inval, pthread_attr_setdetachstate);
-__weak_reference(_pthread_fake_inval, pthread_attr_setinheritsched);
-__weak_reference(_pthread_fake_inval, pthread_attr_setschedparam);
-__weak_reference(_pthread_fake_inval, pthread_attr_setschedpolicy);
-__weak_reference(_pthread_fake_inval, pthread_attr_setscope);
-__weak_reference(_pthread_fake_inval, pthread_attr_setstack);
-__weak_reference(_pthread_fake_inval, pthread_attr_setstackaddr);
-__weak_reference(_pthread_fake_inval, pthread_attr_setstacksize);
-__weak_reference(_pthread_fake_inval, pthread_cancel);
-__weak_reference(_pthread_fake_inval, pthread_setcancelstate);
-__weak_reference(_pthread_fake_inval, pthread_setcanceltype);
-__weak_reference(_pthread_fake_inval, pthread_testcancel);/*XXX void */
-__weak_reference(_pthread_fake_inval, pthread_cleanup_push);/*XXX void */
-__weak_reference(_pthread_fake_inval, pthread_cleanup_pop);/*XXX void */
-__weak_reference(_pthread_fake_inval, pthread_getconcurrency);
-__weak_reference(_pthread_fake_inval, pthread_setconcurrency);
-__weak_reference(_pthread_fake_inval, pthread_cond_init);
-__weak_reference(_pthread_fake_inval, pthread_cond_destroy);
-__weak_reference(_pthread_fake_inval, pthread_cond_wait);
-__weak_reference(_pthread_fake_inval, pthread_cond_timedwait);
-__weak_reference(_pthread_fake_inval, pthread_cond_signal);
-__weak_reference(_pthread_fake_inval, pthread_cond_broadcast);
-__weak_reference(_pthread_fake_inval, pthread_condattr_destroy);
-__weak_reference(_pthread_fake_inval, pthread_condattr_init);
-__weak_reference(_pthread_fake_inval, pthread_detach);
-__weak_reference(_pthread_fake_inval, pthread_equal);/*XXX*/
-__weak_reference(_pthread_fake_inval, pthread_exit);/*XXX void*/
-__weak_reference(_pthread_fake_inval, pthread_getprio);
-__weak_reference(_pthread_fake_inval, pthread_getschedparam);
-__weak_reference(_pthread_fake_inval, pthread_set_name_np);/*XXX void*/
-__weak_reference(_pthread_fake_inval, pthread_join);
-__weak_reference(_pthread_fake_inval, pthread_kill);
-__weak_reference(_pthread_fake_inval, pthread_main_np);
-__weak_reference(_pthread_fake_inval, pthread_mutexattr_init);
-__weak_reference(_pthread_fake_inval, pthread_mutexattr_setkind_np);
-__weak_reference(_pthread_fake_inval, pthread_mutexattr_getkind_np);
-__weak_reference(_pthread_fake_inval, pthread_mutexattr_gettype);
-__weak_reference(_pthread_fake_inval, pthread_mutexattr_settype);
-__weak_reference(_pthread_fake_inval, pthread_multi_np);
-__weak_reference(_pthread_fake_inval, pthread_mutex_init);
-__weak_reference(_pthread_fake_inval, pthread_mutex_destroy);
-__weak_reference(_pthread_fake_inval, pthread_mutex_trylock);
-__weak_reference(_pthread_fake_inval, pthread_mutex_lock);
-__weak_reference(_pthread_fake_inval, pthread_mutex_unlock);
-__weak_reference(_pthread_fake_inval, pthread_mutexattr_getprioceiling);
-__weak_reference(_pthread_fake_inval, pthread_mutexattr_setprioceiling);
-__weak_reference(_pthread_fake_inval, pthread_mutex_getprioceiling);
-__weak_reference(_pthread_fake_inval, pthread_mutex_setprioceiling);
-__weak_reference(_pthread_fake_inval, pthread_mutexattr_getprotocol);
-__weak_reference(_pthread_fake_inval, pthread_mutexattr_setprotocol);
-__weak_reference(_pthread_fake_inval, pthread_mutexattr_destroy);
-__weak_reference(_pthread_fake_inval, pthread_once);
-__weak_reference(_pthread_fake_inval, pthread_resume_np);
-__weak_reference(_pthread_fake_inval, pthread_resume_all_np);/*XXX void*/
-__weak_reference(_pthread_fake_inval, pthread_rwlock_destroy);
-__weak_reference(_pthread_fake_inval, pthread_rwlock_init);
-__weak_reference(_pthread_fake_inval, pthread_rwlock_rdlock);
-__weak_reference(_pthread_fake_inval, pthread_rwlock_tryrdlock);
-__weak_reference(_pthread_fake_inval, pthread_rwlock_trywrlock);
-__weak_reference(_pthread_fake_inval, pthread_rwlock_unlock);
-__weak_reference(_pthread_fake_inval, pthread_rwlock_wrlock);
-__weak_reference(_pthread_fake_inval, pthread_rwlockattr_destroy);
-__weak_reference(_pthread_fake_inval, pthread_rwlockattr_getpshared);
-__weak_reference(_pthread_fake_inval, pthread_rwlockattr_init);
-__weak_reference(_pthread_fake_inval, pthread_rwlockattr_setpshared);
-__weak_reference(_pthread_fake_null, pthread_self);/*XXX pthread_t */
-__weak_reference(_pthread_fake_inval, sem_init);
-__weak_reference(_pthread_fake_inval, sem_destroy);
-__weak_reference(_pthread_fake_inval, sem_open);
-__weak_reference(_pthread_fake_inval, sem_close);
-__weak_reference(_pthread_fake_inval, sem_unlink);
-__weak_reference(_pthread_fake_inval, sem_wait);
-__weak_reference(_pthread_fake_inval, sem_trywait);
-__weak_reference(_pthread_fake_inval, sem_post);
-__weak_reference(_pthread_fake_inval, sem_getvalue);
-__weak_reference(_pthread_fake_inval, pthread_setprio);
-__weak_reference(_pthread_fake_inval, pthread_setschedparam);
-__weak_reference(_pthread_fake_inval, pthread_sigmask);
-__weak_reference(_pthread_fake_inval, pthread_single_np);
-__weak_reference(_pthread_fake_inval, pthread_key_create);
-__weak_reference(_pthread_fake_inval, pthread_key_delete);
-__weak_reference(_pthread_fake_inval, pthread_getspecific);
-__weak_reference(_pthread_fake_inval, pthread_setspecific);
-__weak_reference(_pthread_fake_inval, pthread_suspend_np);
-__weak_reference(_pthread_fake_inval, pthread_suspend_all_np);/*XXX void*/
-__weak_reference(_pthread_fake_inval, pthread_switch_add_np);
-__weak_reference(_pthread_fake_inval, pthread_switch_delete_np);
-__weak_reference(_pthread_fake_inval, sched_yield);
-__weak_reference(_pthread_fake_inval, pthread_yield);/*XXX void*/
-
-int
-_pthread_fake_inval(void)
-{
- return EINVAL;
-}
-
-void *
-_pthread_fake_null(void)
-{
- return NULL;
-}
-
-#endif /* _THREAD_SAFE */
.Xr alloca 3 ,
.Xr getpagesize 3 ,
.Xr memory 3 ,
-.Xr posix_memalign
+.Xr posix_memalign 3
.Sh STANDARDS
The
.Fn malloc ,
{
int hv;
- hv = ((int)ptr >> PAGE_SHIFT) ^ ((int)ptr >> (PAGE_SHIFT + BIGHSHIFT));
+ hv = ((int)(intptr_t)ptr >> PAGE_SHIFT) ^
+ ((int)(intptr_t)ptr >> (PAGE_SHIFT + BIGHSHIFT));
return(hv);
}
{
bigalloc_t *bigp;
bigalloc_t big;
- int chunking;
+ size_t chunking;
int zi;
/*
slzone_t z;
slchunk_t chunk;
slglobaldata_t slgd;
- int chunking;
+ size_t chunking;
int zi;
#ifdef INVARIANTS
int i;
static int
differ_by_repeat(const time_t t1, const time_t t0)
{
+ int_fast64_t _t0 = t0;
+ int_fast64_t _t1 = t1;
+
if (TYPE_INTEGRAL(time_t) &&
TYPE_BIT(time_t) - TYPE_SIGNED(time_t) < SECSPERREPEAT_BITS)
return 0;
- return t1 - t0 == SECSPERREPEAT;
+ return _t1 - _t0 == SECSPERREPEAT;
}
static int
* thread stack that is just beyond.
*/
if (mmap(_usrstack - PTHREAD_STACK_INITIAL -
- PTHREAD_STACK_GUARD, PTHREAD_STACK_GUARD, 0, MAP_ANON,
- -1, 0) == MAP_FAILED)
+ PTHREAD_STACK_GUARD, PTHREAD_STACK_GUARD, 0,
+ MAP_ANON | MAP_TRYFIXED, -1, 0) == MAP_FAILED)
PANIC("Cannot allocate red zone for initial thread");
_thread_initial->tcb = tls_get_tcb();
-# $FreeBSD: src/lib/libfetch/Makefile,v 1.14.2.5 2003/01/09 11:50:32 des Exp $
+# $FreeBSD: src/lib/libfetch/Makefile,v 1.51 2007/12/19 05:10:07 ru Exp $
# $DragonFly: src/lib/libfetch/Makefile,v 1.9 2007/08/05 21:48:12 swildner Exp $
LIB= fetch
SHLIB_MAJOR= 4
-ftperr.h: ftp.errors
- @echo "static struct fetcherr _ftp_errlist[] = {" > ${.TARGET}
- @cat ${.ALLSRC} \
+ftperr.h: ftp.errors ${.CURDIR}/Makefile
+ @echo "static struct fetcherr ftp_errlist[] = {" > ${.TARGET}
+ @cat ${.CURDIR}/ftp.errors \
| grep -v ^# \
| sort \
| while read NUM CAT STRING; do \
@echo " { -1, FETCH_UNKNOWN, \"Unknown FTP error\" }" >> ${.TARGET}
@echo "};" >> ${.TARGET}
-httperr.h: http.errors
- @echo "static struct fetcherr _http_errlist[] = {" > ${.TARGET}
- @cat ${.ALLSRC} \
+httperr.h: http.errors ${.CURDIR}/Makefile
+ @echo "static struct fetcherr http_errlist[] = {" > ${.TARGET}
+ @cat ${.CURDIR}/http.errors \
| grep -v ^# \
| sort \
| while read NUM CAT STRING; do \
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/lib/libfetch/common.c,v 1.50 2005/02/16 12:46:46 des Exp $
+ * $FreeBSD: src/lib/libfetch/common.c,v 1.56 2008/04/15 23:29:51 cperciva Exp $
* $DragonFly: src/lib/libfetch/common.c,v 1.5 2008/04/02 14:46:37 joerg Exp $
*/
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/uio.h>
+
#include <netinet/in.h>
+#include <ctype.h>
#include <errno.h>
#include <netdb.h>
#include <pwd.h>
/*
* Error messages for resolver errors
*/
-static struct fetcherr _netdb_errlist[] = {
+static struct fetcherr netdb_errlist[] = {
#ifdef EAI_NODATA
{ EAI_NODATA, FETCH_RESOLV, "Host not found" },
#endif
* Map error code to string
*/
static struct fetcherr *
-_fetch_finderr(struct fetcherr *p, int e)
+fetch_finderr(struct fetcherr *p, int e)
{
while (p->num != -1 && p->num != e)
p++;
* Set error code
*/
void
-_fetch_seterr(struct fetcherr *p, int e)
+fetch_seterr(struct fetcherr *p, int e)
{
- p = _fetch_finderr(p, e);
+ p = fetch_finderr(p, e);
fetchLastErrCode = p->cat;
snprintf(fetchLastErrString, MAXERRSTRING, "%s", p->string);
}
* Set error code according to errno
*/
void
-_fetch_syserr(void)
+fetch_syserr(void)
{
switch (errno) {
case 0:
* Emit status message
*/
void
-_fetch_info(const char *fmt, ...)
+fetch_info(const char *fmt, ...)
{
va_list ap;
* Return the default port for a scheme
*/
int
-_fetch_default_port(const char *scheme)
+fetch_default_port(const char *scheme)
{
struct servent *se;
* Return the default proxy port for a scheme
*/
int
-_fetch_default_proxy_port(const char *scheme)
+fetch_default_proxy_port(const char *scheme)
{
if (strcasecmp(scheme, SCHEME_FTP) == 0)
return (FTP_DEFAULT_PROXY_PORT);
* Create a connection for an existing descriptor.
*/
conn_t *
-_fetch_reopen(int sd)
+fetch_reopen(int sd)
{
conn_t *conn;
* Bump a connection's reference count.
*/
conn_t *
-_fetch_ref(conn_t *conn)
+fetch_ref(conn_t *conn)
{
++conn->ref;
* Bind a socket to a specific local address
*/
int
-_fetch_bind(int sd, int af, const char *addr)
+fetch_bind(int sd, int af, const char *addr)
{
struct addrinfo hints, *res, *res0;
int err;
* Establish a TCP connection to the specified port on the specified host.
*/
conn_t *
-_fetch_connect(const char *host, int port, int af, int verbose)
+fetch_connect(const char *host, int port, int af, int verbose)
{
conn_t *conn;
char pbuf[10];
DEBUG(fprintf(stderr, "---> %s:%d\n", host, port));
if (verbose)
- _fetch_info("looking up %s", host);
+ fetch_info("looking up %s", host);
/* look up host name and set up socket address structure */
snprintf(pbuf, sizeof(pbuf), "%d", port);
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
if ((err = getaddrinfo(host, pbuf, &hints, &res0)) != 0) {
- _netdb_seterr(err);
+ netdb_seterr(err);
return (NULL);
}
bindaddr = getenv("FETCH_BIND_ADDRESS");
if (verbose)
- _fetch_info("connecting to %s:%d", host, port);
+ fetch_info("connecting to %s:%d", host, port);
/* try to connect */
for (sd = -1, res = res0; res; sd = -1, res = res->ai_next) {
res->ai_protocol)) == -1)
continue;
if (bindaddr != NULL && *bindaddr != '\0' &&
- _fetch_bind(sd, res->ai_family, bindaddr) != 0) {
- _fetch_info("failed to bind to '%s'", bindaddr);
+ fetch_bind(sd, res->ai_family, bindaddr) != 0) {
+ fetch_info("failed to bind to '%s'", bindaddr);
close(sd);
continue;
}
}
freeaddrinfo(res0);
if (sd == -1) {
- _fetch_syserr();
+ fetch_syserr();
return (NULL);
}
- if ((conn = _fetch_reopen(sd)) == NULL) {
- _fetch_syserr();
+ if ((conn = fetch_reopen(sd)) == NULL) {
+ fetch_syserr();
close(sd);
}
return (conn);
* Enable SSL on a connection.
*/
int
-_fetch_ssl(conn_t *conn, int verbose)
+fetch_ssl(conn_t *conn, int verbose)
{
#ifdef WITH_SSL
* Read a character from a connection w/ timeout
*/
ssize_t
-_fetch_read(conn_t *conn, char *buf, size_t len)
+fetch_read(conn_t *conn, char *buf, size_t len)
{
- struct timeval now, timeout, wait;
+ struct timeval now, timeout, delta;
fd_set readfds;
ssize_t rlen, total;
int r;
while (fetchTimeout && !FD_ISSET(conn->sd, &readfds)) {
FD_SET(conn->sd, &readfds);
gettimeofday(&now, NULL);
- wait.tv_sec = timeout.tv_sec - now.tv_sec;
- wait.tv_usec = timeout.tv_usec - now.tv_usec;
- if (wait.tv_usec < 0) {
- wait.tv_usec += 1000000;
- wait.tv_sec--;
+ delta.tv_sec = timeout.tv_sec - now.tv_sec;
+ delta.tv_usec = timeout.tv_usec - now.tv_usec;
+ if (delta.tv_usec < 0) {
+ delta.tv_usec += 1000000;
+ delta.tv_sec--;
}
- if (wait.tv_sec < 0) {
+ if (delta.tv_sec < 0) {
errno = ETIMEDOUT;
- _fetch_syserr();
+ fetch_syserr();
return (-1);
}
errno = 0;
- r = select(conn->sd + 1, &readfds, NULL, NULL, &wait);
+ r = select(conn->sd + 1, &readfds, NULL, NULL, &delta);
if (r == -1) {
if (errno == EINTR && fetchRestartCalls)
continue;
- _fetch_syserr();
+ fetch_syserr();
return (-1);
}
}
#define MIN_BUF_SIZE 1024
int
-_fetch_getln(conn_t *conn)
+fetch_getln(conn_t *conn)
{
char *tmp;
size_t tmpsize;
conn->buflen = 0;
do {
- len = _fetch_read(conn, &c, 1);
+ len = fetch_read(conn, &c, 1);
if (len == -1)
return (-1);
if (len == 0)
* Write to a connection w/ timeout
*/
ssize_t
-_fetch_write(conn_t *conn, const char *buf, size_t len)
+fetch_write(conn_t *conn, const char *buf, size_t len)
{
struct iovec iov;
iov.iov_base = __DECONST(char *, buf);
iov.iov_len = len;
- return _fetch_writev(conn, &iov, 1);
+ return fetch_writev(conn, &iov, 1);
}
/*
* Note: can modify the iovec.
*/
ssize_t
-_fetch_writev(conn_t *conn, struct iovec *iov, int iovcnt)
+fetch_writev(conn_t *conn, struct iovec *iov, int iovcnt)
{
- struct timeval now, timeout, wait;
+ struct timeval now, timeout, delta;
fd_set writefds;
ssize_t wlen, total;
int r;
while (fetchTimeout && !FD_ISSET(conn->sd, &writefds)) {
FD_SET(conn->sd, &writefds);
gettimeofday(&now, NULL);
- wait.tv_sec = timeout.tv_sec - now.tv_sec;
- wait.tv_usec = timeout.tv_usec - now.tv_usec;
- if (wait.tv_usec < 0) {
- wait.tv_usec += 1000000;
- wait.tv_sec--;
+ delta.tv_sec = timeout.tv_sec - now.tv_sec;
+ delta.tv_usec = timeout.tv_usec - now.tv_usec;
+ if (delta.tv_usec < 0) {
+ delta.tv_usec += 1000000;
+ delta.tv_sec--;
}
- if (wait.tv_sec < 0) {
+ if (delta.tv_sec < 0) {
errno = ETIMEDOUT;
- _fetch_syserr();
+ fetch_syserr();
return (-1);
}
errno = 0;
- r = select(conn->sd + 1, NULL, &writefds, NULL, &wait);
+ r = select(conn->sd + 1, NULL, &writefds, NULL, &delta);
if (r == -1) {
if (errno == EINTR && fetchRestartCalls)
continue;
if (wlen == 0) {
/* we consider a short write a failure */
errno = EPIPE;
- _fetch_syserr();
+ fetch_syserr();
return (-1);
}
if (wlen < 0) {
* Write a line of text to a connection w/ timeout
*/
int
-_fetch_putln(conn_t *conn, const char *str, size_t len)
+fetch_putln(conn_t *conn, const char *str, size_t len)
{
struct iovec iov[2];
int ret;
iov[1].iov_base = __DECONST(char *, ENDL);
iov[1].iov_len = sizeof(ENDL);
if (len == 0)
- ret = _fetch_writev(conn, &iov[1], 1);
+ ret = fetch_writev(conn, &iov[1], 1);
else
- ret = _fetch_writev(conn, iov, 2);
+ ret = fetch_writev(conn, iov, 2);
if (ret == -1)
return (-1);
return (0);
* Close connection
*/
int
-_fetch_close(conn_t *conn)
+fetch_close(conn_t *conn)
{
int ret;
/*** Directory-related utility functions *************************************/
int
-_fetch_add_entry(struct url_ent **p, int *size, int *len,
+fetch_add_entry(struct url_ent **p, int *size, int *len,
const char *name, struct url_stat *us)
{
struct url_ent *tmp;
tmp = realloc(*p, (*size * 2 + 1) * sizeof(**p));
if (tmp == NULL) {
errno = ENOMEM;
- _fetch_syserr();
+ fetch_syserr();
return (-1);
}
*size = (*size * 2 + 1);
tmp = *p + *len;
snprintf(tmp->name, PATH_MAX, "%s", name);
- bcopy(us, &tmp->stat, sizeof(*us));
+ memcpy(&tmp->stat, us, sizeof(*us));
(*len)++;
(++tmp)->name[0] = 0;
/*** Authentication-related utility functions ********************************/
static const char *
-_fetch_read_word(FILE *f)
+fetch_read_word(FILE *f)
{
static char word[1024];
* Get authentication data for a URL from .netrc
*/
int
-_fetch_netrc_auth(struct url *url)
+fetch_netrc_auth(struct url *url)
{
char fn[PATH_MAX];
const char *word;
if ((p = getenv("NETRC")) != NULL) {
if (snprintf(fn, sizeof(fn), "%s", p) >= (int)sizeof(fn)) {
- _fetch_info("$NETRC specifies a file name "
+ fetch_info("$NETRC specifies a file name "
"longer than PATH_MAX");
return (-1);
}
if ((f = fopen(fn, "r")) == NULL)
return (-1);
- while ((word = _fetch_read_word(f)) != NULL) {
+ while ((word = fetch_read_word(f)) != NULL) {
if (strcmp(word, "default") == 0) {
- DEBUG(_fetch_info("Using default .netrc settings"));
+ DEBUG(fetch_info("Using default .netrc settings"));
break;
}
if (strcmp(word, "machine") == 0 &&
- (word = _fetch_read_word(f)) != NULL &&
+ (word = fetch_read_word(f)) != NULL &&
strcasecmp(word, url->host) == 0) {
- DEBUG(_fetch_info("Using .netrc settings for %s", word));
+ DEBUG(fetch_info("Using .netrc settings for %s", word));
break;
}
}
if (word == NULL)
goto ferr;
- while ((word = _fetch_read_word(f)) != NULL) {
+ while ((word = fetch_read_word(f)) != NULL) {
if (strcmp(word, "login") == 0) {
- if ((word = _fetch_read_word(f)) == NULL)
+ if ((word = fetch_read_word(f)) == NULL)
goto ferr;
if (snprintf(url->user, sizeof(url->user),
"%s", word) > (int)sizeof(url->user)) {
- _fetch_info("login name in .netrc is too long");
+ fetch_info("login name in .netrc is too long");
url->user[0] = '\0';
}
} else if (strcmp(word, "password") == 0) {
- if ((word = _fetch_read_word(f)) == NULL)
+ if ((word = fetch_read_word(f)) == NULL)
goto ferr;
if (snprintf(url->pwd, sizeof(url->pwd),
"%s", word) > (int)sizeof(url->pwd)) {
- _fetch_info("password in .netrc is too long");
+ fetch_info("password in .netrc is too long");
url->pwd[0] = '\0';
}
} else if (strcmp(word, "account") == 0) {
- if ((word = _fetch_read_word(f)) == NULL)
+ if ((word = fetch_read_word(f)) == NULL)
goto ferr;
/* XXX not supported! */
} else {
fclose(f);
return (-1);
}
+
+/*
+ * The no_proxy environment variable specifies a set of domains for
+ * which the proxy should not be consulted; the contents is a comma-,
+ * or space-separated list of domain names. A single asterisk will
+ * override all proxy variables and no transactions will be proxied
+ * (for compatability with lynx and curl, see the discussion at
+ * <http://curl.haxx.se/mail/archive_pre_oct_99/0009.html>).
+ */
+int
+fetch_no_proxy_match(const char *host)
+{
+ const char *no_proxy, *p, *q;
+ size_t h_len, d_len;
+
+ if ((no_proxy = getenv("NO_PROXY")) == NULL &&
+ (no_proxy = getenv("no_proxy")) == NULL)
+ return (0);
+
+ /* asterisk matches any hostname */
+ if (strcmp(no_proxy, "*") == 0)
+ return (1);
+
+ h_len = strlen(host);
+ p = no_proxy;
+ do {
+ /* position p at the beginning of a domain suffix */
+ while (*p == ',' || isspace((unsigned char)*p))
+ p++;
+
+ /* position q at the first separator character */
+ for (q = p; *q; ++q)
+ if (*q == ',' || isspace((unsigned char)*q))
+ break;
+
+ d_len = q - p;
+ if (d_len > 0 && h_len > d_len &&
+ strncasecmp(host + h_len - d_len,
+ p, d_len) == 0) {
+ /* domain name matches */
+ return (1);
+ }
+
+ p = q + 1;
+ } while (*q);
+
+ return (0);
+}
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/lib/libfetch/common.h,v 1.28 2004/09/21 18:35:20 des Exp $
+ * $FreeBSD: src/lib/libfetch/common.h,v 1.30 2007/12/18 11:03:07 des Exp $
* $DragonFly: src/lib/libfetch/common.h,v 1.3 2007/08/05 21:48:12 swildner Exp $
*/
const char *string;
};
-/* for _fetch_writev */
+/* for fetch_writev */
struct iovec;
-void _fetch_seterr(struct fetcherr *, int);
-void _fetch_syserr(void);
-void _fetch_info(const char *, ...);
-int _fetch_default_port(const char *);
-int _fetch_default_proxy_port(const char *);
-int _fetch_bind(int, int, const char *);
-conn_t *_fetch_connect(const char *, int, int, int);
-conn_t *_fetch_reopen(int);
-conn_t *_fetch_ref(conn_t *);
-int _fetch_ssl(conn_t *, int);
-ssize_t _fetch_read(conn_t *, char *, size_t);
-int _fetch_getln(conn_t *);
-ssize_t _fetch_write(conn_t *, const char *, size_t);
-ssize_t _fetch_writev(conn_t *, struct iovec *, int);
-int _fetch_putln(conn_t *, const char *, size_t);
-int _fetch_close(conn_t *);
-int _fetch_add_entry(struct url_ent **, int *, int *,
+void fetch_seterr(struct fetcherr *, int);
+void fetch_syserr(void);
+void fetch_info(const char *, ...);
+int fetch_default_port(const char *);
+int fetch_default_proxy_port(const char *);
+int fetch_bind(int, int, const char *);
+conn_t *fetch_connect(const char *, int, int, int);
+conn_t *fetch_reopen(int);
+conn_t *fetch_ref(conn_t *);
+int fetch_ssl(conn_t *, int);
+ssize_t fetch_read(conn_t *, char *, size_t);
+int fetch_getln(conn_t *);
+ssize_t fetch_write(conn_t *, const char *, size_t);
+ssize_t fetch_writev(conn_t *, struct iovec *, int);
+int fetch_putln(conn_t *, const char *, size_t);
+int fetch_close(conn_t *);
+int fetch_add_entry(struct url_ent **, int *, int *,
const char *, struct url_stat *);
-int _fetch_netrc_auth(struct url *url);
+int fetch_netrc_auth(struct url *url);
+int fetch_no_proxy_match(const char *);
-#define _ftp_seterr(n) _fetch_seterr(_ftp_errlist, n)
-#define _http_seterr(n) _fetch_seterr(_http_errlist, n)
-#define _netdb_seterr(n) _fetch_seterr(_netdb_errlist, n)
-#define _url_seterr(n) _fetch_seterr(_url_errlist, n)
+#define ftp_seterr(n) fetch_seterr(ftp_errlist, n)
+#define http_seterr(n) fetch_seterr(http_errlist, n)
+#define netdb_seterr(n) fetch_seterr(netdb_errlist, n)
+#define url_seterr(n) fetch_seterr(url_errlist, n)
#ifndef NDEBUG
#define DEBUG(x) do { if (fetchDebug) { x; } } while (0)
#endif
/*
- * I don't really like exporting _http_request() and _ftp_request(),
+ * I don't really like exporting http_request() and ftp_request(),
* but the HTTP and FTP code occasionally needs to cross-call
* eachother, and this saves me from adding a lot of special-case code
* to handle those cases.
* Note that _*_request() free purl, which is way ugly but saves us a
* whole lot of trouble.
*/
-FILE *_http_request(struct url *, const char *,
+FILE *http_request(struct url *, const char *,
struct url_stat *, struct url *, const char *);
-FILE *_ftp_request(struct url *, const char *,
+FILE *ftp_request(struct url *, const char *,
struct url_stat *, struct url *, const char *);
/*
-.\" Copyright (c) 1998 Dag-Erling Coïdan Smørgrav
+.\"-
+.\" Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/lib/libfetch/fetch.3,v 1.63 2007/05/24 20:28:14 des Exp $
+.\" $FreeBSD: src/lib/libfetch/fetch.3,v 1.66 2008/12/15 08:27:44 murray Exp $
.\" $DragonFly: src/lib/libfetch/fetch.3,v 1.5 2007/11/23 23:16:36 swildner Exp $
.\"
-.Dd July 1, 1998
+.Dd May 10, 2009
.Dt FETCH 3
.Os
.Sh NAME
char *doc;
off_t offset;
size_t length;
+ time_t ims_time;
};
.Ed
.Pp
+The
+.Va ims_time
+field stores the time value for
+.Li If-Modified-Since
+HTTP requests.
+.Pp
The pointer returned by
.Fn fetchMakeURL
or
.In fetch.h :
.Bd -literal
struct url_ent {
- char name[MAXPATHLEN];
+ char name[PATH_MAX];
struct url_stat stat;
};
.Ed
.Fn fetchPutHTTP
will use a direct connection even if a proxy server is defined.
.Pp
+If the
+.Ql i
+(if-modified-since) flag is specified, and
+the
+.Va ims_time
+field is set in
+.Vt "struct url" ,
+then
+.Fn fetchXGetHTTP
+and
+.Fn fetchGetHTTP
+will send a conditional
+.Li If-Modified-Since
+HTTP header to only fetch the content if it is newer than
+.Va ims_time .
+.Pp
Since there seems to be no good way of implementing the HTTP PUT
method in a manner consistent with the rest of the
.Nm fetch
.Xr ftp 1
for a description of the file format.
This feature is experimental.
+.It Ev NO_PROXY
+Either a single asterisk, which disables the use of proxies
+altogether, or a comma- or whitespace-separated list of hosts for
+which proxies should not be used.
+.It Ev no_proxy
+Same as
+.Ev NO_PROXY ,
+for compatibility.
.El
.Sh EXAMPLES
To access a proxy server on
HTTP_PROXY=http://proxy.example.com:8080
HTTP_PROXY_AUTH=basic:*:<user>:<pwd>
.Ed
+.Pp
+To disable the use of a proxy for an HTTP server running on the local
+host, define
+.Ev NO_PROXY
+as follows:
+.Bd -literal -offset indent
+NO_PROXY=localhost,127.0.0.1
+.Ed
.Sh SEE ALSO
.Xr fetch 1 ,
.Xr ftpio 3 ,
.An Jordan K. Hubbard Aq jkh@FreeBSD.org .
.Pp
This manual page was written by
-.An Dag-Erling Co\(:idan Sm\(/orgrav Aq des@FreeBSD.org .
+.An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org .
.Sh BUGS
Some parts of the library are not yet implemented.
The most notable
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/lib/libfetch/fetch.c,v 1.38 2004/09/21 18:35:20 des Exp $
+ * $FreeBSD: src/lib/libfetch/fetch.c,v 1.42 2008/12/17 18:00:18 murray Exp $
* $DragonFly: src/lib/libfetch/fetch.c,v 1.3 2007/08/05 21:48:12 swildner Exp $
*/
#define URL_MALFORMED 1
#define URL_BAD_SCHEME 2
#define URL_BAD_PORT 3
-static struct fetcherr _url_errlist[] = {
+static struct fetcherr url_errlist[] = {
{ URL_MALFORMED, FETCH_URL, "Malformed URL" },
{ URL_BAD_SCHEME, FETCH_URL, "Invalid URL scheme" },
{ URL_BAD_PORT, FETCH_URL, "Invalid server port" },
FILE *
fetchXGet(struct url *URL, struct url_stat *us, const char *flags)
{
- int direct;
- direct = CHECK_FLAG('d');
if (us != NULL) {
us->size = -1;
us->atime = us->mtime = 0;
return (fetchXGetHTTP(URL, us, flags));
else if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0)
return (fetchXGetHTTP(URL, us, flags));
- _url_seterr(URL_BAD_SCHEME);
+ url_seterr(URL_BAD_SCHEME);
return (NULL);
}
FILE *
fetchPut(struct url *URL, const char *flags)
{
- int direct;
- direct = CHECK_FLAG('d');
if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
return (fetchPutFile(URL, flags));
else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0)
return (fetchPutHTTP(URL, flags));
else if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0)
return (fetchPutHTTP(URL, flags));
- _url_seterr(URL_BAD_SCHEME);
+ url_seterr(URL_BAD_SCHEME);
return (NULL);
}
int
fetchStat(struct url *URL, struct url_stat *us, const char *flags)
{
- int direct;
- direct = CHECK_FLAG('d');
if (us != NULL) {
us->size = -1;
us->atime = us->mtime = 0;
return (fetchStatHTTP(URL, us, flags));
else if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0)
return (fetchStatHTTP(URL, us, flags));
- _url_seterr(URL_BAD_SCHEME);
+ url_seterr(URL_BAD_SCHEME);
return (-1);
}
struct url_ent *
fetchList(struct url *URL, const char *flags)
{
- int direct;
- direct = CHECK_FLAG('d');
if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
return (fetchListFile(URL, flags));
else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0)
return (fetchListHTTP(URL, flags));
else if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0)
return (fetchListHTTP(URL, flags));
- _url_seterr(URL_BAD_SCHEME);
+ url_seterr(URL_BAD_SCHEME);
return (NULL);
}
struct url *u;
if (!scheme || (!host && !doc)) {
- _url_seterr(URL_MALFORMED);
+ url_seterr(URL_MALFORMED);
return (NULL);
}
if (port < 0 || port > 65535) {
- _url_seterr(URL_BAD_PORT);
+ url_seterr(URL_BAD_PORT);
return (NULL);
}
/* allocate struct url */
if ((u = calloc(1, sizeof(*u))) == NULL) {
- _fetch_syserr();
+ fetch_syserr();
return (NULL);
}
if ((u->doc = strdup(doc ? doc : "/")) == NULL) {
- _fetch_syserr();
+ fetch_syserr();
free(u);
return (NULL);
}
/* allocate struct url */
if ((u = calloc(1, sizeof(*u))) == NULL) {
- _fetch_syserr();
+ fetch_syserr();
return (NULL);
}
/* port */
if (*p == ':') {
for (q = ++p; *q && (*q != '/'); q++)
- if (isdigit(*q))
+ if (isdigit((unsigned char)*q))
u->port = u->port * 10 + (*q - '0');
else {
/* invalid port */
- _url_seterr(URL_BAD_PORT);
+ url_seterr(URL_BAD_PORT);
goto ouch;
}
p = q;
/* percent-escape whitespace. */
if ((doc = malloc(strlen(p) * 3 + 1)) == NULL) {
- _fetch_syserr();
+ fetch_syserr();
goto ouch;
}
u->doc = doc;
while (*p != '\0') {
- if (!isspace(*p)) {
+ if (!isspace((unsigned char)*p)) {
*doc++ = *p++;
} else {
*doc++ = '%';
}
*doc = '\0';
} else if ((u->doc = strdup(p)) == NULL) {
- _fetch_syserr();
+ fetch_syserr();
goto ouch;
}
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/lib/libfetch/fetch.h,v 1.26 2004/09/21 18:35:20 des Exp $
+ * $FreeBSD: src/lib/libfetch/fetch.h,v 1.27 2008/12/15 08:27:44 murray Exp $
* $DragonFly: src/lib/libfetch/fetch.h,v 1.3 2007/08/05 21:48:12 swildner Exp $
*/
char *doc;
off_t offset;
size_t length;
+ time_t ims_time;
};
struct url_stat {
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/lib/libfetch/file.c,v 1.17 2004/09/21 18:35:20 des Exp $
+ * $FreeBSD: src/lib/libfetch/file.c,v 1.18 2007/12/14 10:26:58 des Exp $
* $DragonFly: src/lib/libfetch/file.c,v 1.3 2007/08/05 21:48:12 swildner Exp $
*/
f = fopen(u->doc, "r");
if (f == NULL)
- _fetch_syserr();
+ fetch_syserr();
if (u->offset && fseeko(f, u->offset, SEEK_SET) == -1) {
fclose(f);
- _fetch_syserr();
+ fetch_syserr();
}
return (f);
f = fopen(u->doc, "w+");
if (f == NULL)
- _fetch_syserr();
+ fetch_syserr();
if (u->offset && fseeko(f, u->offset, SEEK_SET) == -1) {
fclose(f);
- _fetch_syserr();
+ fetch_syserr();
}
return (f);
}
static int
-_fetch_stat_file(const char *fn, struct url_stat *us)
+fetch_stat_file(const char *fn, struct url_stat *us)
{
struct stat sb;
us->size = -1;
us->atime = us->mtime = 0;
if (stat(fn, &sb) == -1) {
- _fetch_syserr();
+ fetch_syserr();
return (-1);
}
us->size = sb.st_size;
int
fetchStatFile(struct url *u, struct url_stat *us, const char *flags __unused)
{
- return (_fetch_stat_file(u->doc, us));
+ return (fetch_stat_file(u->doc, us));
}
struct url_ent *
int l;
if ((dir = opendir(u->doc)) == NULL) {
- _fetch_syserr();
+ fetch_syserr();
return (NULL);
}
while ((de = readdir(dir)) != NULL) {
strncpy(p, de->d_name, l - 1);
p[l - 1] = 0;
- if (_fetch_stat_file(fn, &us) == -1)
+ if (fetch_stat_file(fn, &us) == -1)
/* should I return a partial result, or abort? */
break;
- _fetch_add_entry(&ue, &size, &len, de->d_name, &us);
+ fetch_add_entry(&ue, &size, &len, de->d_name, &us);
}
return (ue);
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/lib/libfetch/ftp.c,v 1.96 2007/04/22 22:33:29 njl Exp $
+ * $FreeBSD: src/lib/libfetch/ftp.c,v 1.102 2008/02/08 09:48:48 des Exp $
* $DragonFly: src/lib/libfetch/ftp.c,v 1.4 2007/08/05 21:48:12 swildner Exp $
*/
static struct url cached_host;
static conn_t *cached_connection;
-#define isftpreply(foo) (isdigit(foo[0]) && isdigit(foo[1]) \
- && isdigit(foo[2]) \
- && (foo[3] == ' ' || foo[3] == '\0'))
-#define isftpinfo(foo) (isdigit(foo[0]) && isdigit(foo[1]) \
- && isdigit(foo[2]) && foo[3] == '-')
+#define isftpreply(foo) \
+ (isdigit((unsigned char)foo[0]) && \
+ isdigit((unsigned char)foo[1]) && \
+ isdigit((unsigned char)foo[2]) && \
+ (foo[3] == ' ' || foo[3] == '\0'))
+#define isftpinfo(foo) \
+ (isdigit((unsigned char)foo[0]) && \
+ isdigit((unsigned char)foo[1]) && \
+ isdigit((unsigned char)foo[2]) && \
+ foo[3] == '-')
/*
* Translate IPv4 mapped IPv6 address to IPv4 address
* Get server response
*/
static int
-_ftp_chkerr(conn_t *conn)
+ftp_chkerr(conn_t *conn)
{
- if (_fetch_getln(conn) == -1) {
- _fetch_syserr();
+ if (fetch_getln(conn) == -1) {
+ fetch_syserr();
return (-1);
}
if (isftpinfo(conn->buf)) {
while (conn->buflen && !isftpreply(conn->buf)) {
- if (_fetch_getln(conn) == -1) {
- _fetch_syserr();
+ if (fetch_getln(conn) == -1) {
+ fetch_syserr();
return (-1);
}
}
}
- while (conn->buflen && isspace(conn->buf[conn->buflen - 1]))
+ while (conn->buflen &&
+ isspace((unsigned char)conn->buf[conn->buflen - 1]))
conn->buflen--;
conn->buf[conn->buflen] = '\0';
if (!isftpreply(conn->buf)) {
- _ftp_seterr(FTP_PROTOCOL_ERROR);
+ ftp_seterr(FTP_PROTOCOL_ERROR);
return (-1);
}
* Send a command and check reply
*/
static int
-_ftp_cmd(conn_t *conn, const char *fmt, ...)
+ftp_cmd(conn_t *conn, const char *fmt, ...)
{
va_list ap;
size_t len;
if (msg == NULL) {
errno = ENOMEM;
- _fetch_syserr();
+ fetch_syserr();
return (-1);
}
- r = _fetch_putln(conn, msg, len);
+ r = fetch_putln(conn, msg, len);
free(msg);
if (r == -1) {
- _fetch_syserr();
+ fetch_syserr();
return (-1);
}
- return (_ftp_chkerr(conn));
+ return (ftp_chkerr(conn));
}
/*
* Return a pointer to the filename part of a path
*/
static const char *
-_ftp_filename(const char *file, int *len, int *type)
+ftp_filename(const char *file, int *len, int *type)
{
const char *s;
* command.
*/
static int
-_ftp_pwd(conn_t *conn, char *pwd, size_t pwdlen)
+ftp_pwd(conn_t *conn, char *pwd, size_t pwdlen)
{
char *src, *dst, *end;
int q;
* file.
*/
static int
-_ftp_cwd(conn_t *conn, const char *file)
+ftp_cwd(conn_t *conn, const char *file)
{
const char *beg, *end;
char pwd[PATH_MAX];
/* If no slashes in name, no need to change dirs. */
if ((end = strrchr(file, '/')) == NULL)
return (0);
- if ((e = _ftp_cmd(conn, "PWD")) != FTP_WORKING_DIRECTORY ||
- (e = _ftp_pwd(conn, pwd, sizeof(pwd))) != FTP_OK) {
- _ftp_seterr(e);
+ if ((e = ftp_cmd(conn, "PWD")) != FTP_WORKING_DIRECTORY ||
+ (e = ftp_pwd(conn, pwd, sizeof(pwd))) != FTP_OK) {
+ ftp_seterr(e);
return (-1);
}
for (;;) {
/* Keep going up a dir until we have a matching prefix. */
if (pwd[i] == '\0' && (file[i - 1] == '/' || file[i] == '/'))
break;
- if ((e = _ftp_cmd(conn, "CDUP")) != FTP_FILE_ACTION_OK ||
- (e = _ftp_cmd(conn, "PWD")) != FTP_WORKING_DIRECTORY ||
- (e = _ftp_pwd(conn, pwd, sizeof(pwd))) != FTP_OK) {
- _ftp_seterr(e);
+ if ((e = ftp_cmd(conn, "CDUP")) != FTP_FILE_ACTION_OK ||
+ (e = ftp_cmd(conn, "PWD")) != FTP_WORKING_DIRECTORY ||
+ (e = ftp_pwd(conn, pwd, sizeof(pwd))) != FTP_OK) {
+ ftp_seterr(e);
return (-1);
}
}
return (0);
/* Change to the directory all in one chunk (e.g., foo/bar/baz). */
- e = _ftp_cmd(conn, "CWD %.*s", (int)(end - beg), beg);
+ e = ftp_cmd(conn, "CWD %.*s", (int)(end - beg), beg);
if (e == FTP_FILE_ACTION_OK)
return (0);
#endif /* FTP_COMBINE_CWDS */
++beg, ++i;
for (++i; file + i < end && file[i] != '/'; ++i)
/* nothing */ ;
- e = _ftp_cmd(conn, "CWD %.*s", file + i - beg, beg);
+ e = ftp_cmd(conn, "CWD %.*s", file + i - beg, beg);
if (e != FTP_FILE_ACTION_OK) {
- _ftp_seterr(e);
+ ftp_seterr(e);
return (-1);
}
}
* Set transfer mode and data type
*/
static int
-_ftp_mode_type(conn_t *conn, int mode, int type)
+ftp_mode_type(conn_t *conn, int mode, int type)
{
int e;
default:
return (FTP_PROTOCOL_ERROR);
}
- if ((e = _ftp_cmd(conn, "MODE %c", mode)) != FTP_OK) {
+ if ((e = ftp_cmd(conn, "MODE %c", mode)) != FTP_OK) {
if (mode == 'S') {
/*
* Stream mode is supposed to be the default - so
default:
return (FTP_PROTOCOL_ERROR);
}
- if ((e = _ftp_cmd(conn, "TYPE %c", type)) != FTP_OK)
+ if ((e = ftp_cmd(conn, "TYPE %c", type)) != FTP_OK)
return (e);
return (FTP_OK);
* Request and parse file stats
*/
static int
-_ftp_stat(conn_t *conn, const char *file, struct url_stat *us)
+ftp_stat(conn_t *conn, const char *file, struct url_stat *us)
{
char *ln;
const char *filename;
us->size = -1;
us->atime = us->mtime = 0;
- filename = _ftp_filename(file, &filenamelen, &type);
+ filename = ftp_filename(file, &filenamelen, &type);
- if ((e = _ftp_mode_type(conn, 0, type)) != FTP_OK) {
- _ftp_seterr(e);
+ if ((e = ftp_mode_type(conn, 0, type)) != FTP_OK) {
+ ftp_seterr(e);
return (-1);
}
- e = _ftp_cmd(conn, "SIZE %.*s", filenamelen, filename);
+ e = ftp_cmd(conn, "SIZE %.*s", filenamelen, filename);
if (e != FTP_FILE_STATUS) {
- _ftp_seterr(e);
+ ftp_seterr(e);
return (-1);
}
- for (ln = conn->buf + 4; *ln && isspace(*ln); ln++)
+ for (ln = conn->buf + 4; *ln && isspace((unsigned char)*ln); ln++)
/* nothing */ ;
- for (us->size = 0; *ln && isdigit(*ln); ln++)
+ for (us->size = 0; *ln && isdigit((unsigned char)*ln); ln++)
us->size = us->size * 10 + *ln - '0';
- if (*ln && !isspace(*ln)) {
- _ftp_seterr(FTP_PROTOCOL_ERROR);
+ if (*ln && !isspace((unsigned char)*ln)) {
+ ftp_seterr(FTP_PROTOCOL_ERROR);
us->size = -1;
return (-1);
}
us->size = -1;
DEBUG(fprintf(stderr, "size: [%lld]\n", (long long)us->size));
- e = _ftp_cmd(conn, "MDTM %.*s", filenamelen, filename);
+ e = ftp_cmd(conn, "MDTM %.*s", filenamelen, filename);
if (e != FTP_FILE_STATUS) {
- _ftp_seterr(e);
+ ftp_seterr(e);
return (-1);
}
- for (ln = conn->buf + 4; *ln && isspace(*ln); ln++)
+ for (ln = conn->buf + 4; *ln && isspace((unsigned char)*ln); ln++)
/* nothing */ ;
switch (strspn(ln, "0123456789")) {
case 14:
ln[1] = '0';
break;
default:
- _ftp_seterr(FTP_PROTOCOL_ERROR);
+ ftp_seterr(FTP_PROTOCOL_ERROR);
return (-1);
}
if (sscanf(ln, "%04d%02d%02d%02d%02d%02d",
&tm.tm_year, &tm.tm_mon, &tm.tm_mday,
&tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
- _ftp_seterr(FTP_PROTOCOL_ERROR);
+ ftp_seterr(FTP_PROTOCOL_ERROR);
return (-1);
}
tm.tm_mon--;
int err; /* Error code */
};
-static int _ftp_readfn(void *, char *, int);
-static int _ftp_writefn(void *, const char *, int);
-static fpos_t _ftp_seekfn(void *, fpos_t, int);
-static int _ftp_closefn(void *);
+static int ftp_readfn(void *, char *, int);
+static int ftp_writefn(void *, const char *, int);
+static fpos_t ftp_seekfn(void *, fpos_t, int);
+static int ftp_closefn(void *);
static int
-_ftp_readfn(void *v, char *buf, int len)
+ftp_readfn(void *v, char *buf, int len)
{
struct ftpio *io;
int r;
}
if (io->eof)
return (0);
- r = _fetch_read(io->dconn, buf, len);
+ r = fetch_read(io->dconn, buf, len);
if (r > 0)
return (r);
if (r == 0) {
}
static int
-_ftp_writefn(void *v, const char *buf, int len)
+ftp_writefn(void *v, const char *buf, int len)
{
struct ftpio *io;
int w;
errno = io->err;
return (-1);
}
- w = _fetch_write(io->dconn, buf, len);
+ w = fetch_write(io->dconn, buf, len);
if (w >= 0)
return (w);
if (errno != EINTR)
}
static fpos_t
-_ftp_seekfn(void *v, fpos_t pos __unused, int whence __unused)
+ftp_seekfn(void *v, fpos_t pos __unused, int whence __unused)
{
struct ftpio *io;
}
static int
-_ftp_closefn(void *v)
+ftp_closefn(void *v)
{
struct ftpio *io;
int r;
errno = EBADF;
return (-1);
}
- _fetch_close(io->dconn);
+ fetch_close(io->dconn);
io->dir = -1;
io->dconn = NULL;
DEBUG(fprintf(stderr, "Waiting for final status\n"));
- r = _ftp_chkerr(io->cconn);
+ r = ftp_chkerr(io->cconn);
if (io->cconn == cached_connection && io->cconn->ref == 1)
cached_connection = NULL;
- _fetch_close(io->cconn);
+ fetch_close(io->cconn);
free(io);
return (r == FTP_TRANSFER_COMPLETE) ? 0 : -1;
}
static FILE *
-_ftp_setup(conn_t *cconn, conn_t *dconn, int mode)
+ftp_setup(conn_t *cconn, conn_t *dconn, int mode)
{
struct ftpio *io;
FILE *f;
io->dconn = dconn;
io->dir = mode;
io->eof = io->err = 0;
- f = funopen(io, _ftp_readfn, _ftp_writefn, _ftp_seekfn, _ftp_closefn);
+ f = funopen(io, ftp_readfn, ftp_writefn, ftp_seekfn, ftp_closefn);
if (f == NULL)
free(io);
return (f);
* Transfer file
*/
static FILE *
-_ftp_transfer(conn_t *conn, const char *oper, const char *file,
+ftp_transfer(conn_t *conn, const char *oper, const char *file,
int mode, off_t offset, const char *flags)
{
struct sockaddr_storage sa;
strncasecmp(s, "no", 2) != 0);
/* isolate filename */
- filename = _ftp_filename(file, &filenamelen, &type);
+ filename = ftp_filename(file, &filenamelen, &type);
/* set transfer mode and data type */
- if ((e = _ftp_mode_type(conn, 0, type)) != FTP_OK)
+ if ((e = ftp_mode_type(conn, 0, type)) != FTP_OK)
goto ouch;
/* find our own address, bind, and listen */
/* open data socket */
if ((sd = socket(sa.ss_family, SOCK_STREAM, IPPROTO_TCP)) == -1) {
- _fetch_syserr();
+ fetch_syserr();
return (NULL);
}
/* send PASV command */
if (verbose)
- _fetch_info("setting passive mode");
+ fetch_info("setting passive mode");
switch (sa.ss_family) {
case AF_INET:
- if ((e = _ftp_cmd(conn, "PASV")) != FTP_PASSIVE_MODE)
+ if ((e = ftp_cmd(conn, "PASV")) != FTP_PASSIVE_MODE)
goto ouch;
break;
case AF_INET6:
- if ((e = _ftp_cmd(conn, "EPSV")) != FTP_EPASSIVE_MODE) {
+ if ((e = ftp_cmd(conn, "EPSV")) != FTP_EPASSIVE_MODE) {
if (e == -1)
goto ouch;
- if ((e = _ftp_cmd(conn, "LPSV")) !=
+ if ((e = ftp_cmd(conn, "LPSV")) !=
FTP_LPASSIVE_MODE)
goto ouch;
}
switch (e) {
case FTP_PASSIVE_MODE:
case FTP_LPASSIVE_MODE:
- for (p = ln + 3; *p && !isdigit(*p); p++)
+ for (p = ln + 3; *p && !isdigit((unsigned char)*p); p++)
/* nothing */ ;
if (!*p) {
e = FTP_PROTOCOL_ERROR;
/* seek to required offset */
if (offset)
- if (_ftp_cmd(conn, "REST %lu", (u_long)offset) != FTP_FILE_OK)
+ if (ftp_cmd(conn, "REST %lu", (u_long)offset) != FTP_FILE_OK)
goto sysouch;
/* construct sockaddr for data socket */
if (e == FTP_EPASSIVE_MODE)
sin6->sin6_port = htons(port);
else {
- bcopy(addr + 2, (char *)&sin6->sin6_addr, 16);
- bcopy(addr + 19, (char *)&sin6->sin6_port, 2);
+ memcpy(&sin6->sin6_addr, addr + 2, 16);
+ memcpy(&sin6->sin6_port, addr + 19, 2);
}
break;
case AF_INET:
if (e == FTP_EPASSIVE_MODE)
sin4->sin_port = htons(port);
else {
- bcopy(addr, (char *)&sin4->sin_addr, 4);
- bcopy(addr + 4, (char *)&sin4->sin_port, 2);
+ memcpy(&sin4->sin_addr, addr, 4);
+ memcpy(&sin4->sin_port, addr + 4, 2);
}
break;
default:
/* connect to data port */
if (verbose)
- _fetch_info("opening data connection");
+ fetch_info("opening data connection");
bindaddr = getenv("FETCH_BIND_ADDRESS");
if (bindaddr != NULL && *bindaddr != '\0' &&
- _fetch_bind(sd, sa.ss_family, bindaddr) != 0)
+ fetch_bind(sd, sa.ss_family, bindaddr) != 0)
goto sysouch;
if (connect(sd, (struct sockaddr *)&sa, sa.ss_len) == -1)
goto sysouch;
/* make the server initiate the transfer */
if (verbose)
- _fetch_info("initiating transfer");
- e = _ftp_cmd(conn, "%s %.*s", oper, filenamelen, filename);
+ fetch_info("initiating transfer");
+ e = ftp_cmd(conn, "%s %.*s", oper, filenamelen, filename);
if (e != FTP_CONNECTION_ALREADY_OPEN && e != FTP_OPEN_DATA_CONNECTION)
goto ouch;
break;
}
if (verbose)
- _fetch_info("binding data socket");
+ fetch_info("binding data socket");
if (bind(sd, (struct sockaddr *)&sa, sa.ss_len) == -1)
goto sysouch;
if (listen(sd, 1) == -1)
sin4 = (struct sockaddr_in *)&sa;
a = ntohl(sin4->sin_addr.s_addr);
p = ntohs(sin4->sin_port);
- e = _ftp_cmd(conn, "PORT %d,%d,%d,%d,%d,%d",
+ e = ftp_cmd(conn, "PORT %d,%d,%d,%d,%d,%d",
(a >> 24) & 0xff, (a >> 16) & 0xff,
(a >> 8) & 0xff, a & 0xff,
(p >> 8) & 0xff, p & 0xff);
if (getnameinfo((struct sockaddr *)&sa, sa.ss_len,
hname, sizeof(hname),
NULL, 0, NI_NUMERICHOST) == 0) {
- e = _ftp_cmd(conn, "EPRT |%d|%s|%d|", 2, hname,
+ e = ftp_cmd(conn, "EPRT |%d|%s|%d|", 2, hname,
htons(sin6->sin6_port));
if (e == -1)
goto ouch;
}
if (e != FTP_OK) {
ap = (char *)&sin6->sin6_addr;
- e = _ftp_cmd(conn,
+ e = ftp_cmd(conn,
"LPRT %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
6, 16,
UC(ap[0]), UC(ap[1]), UC(ap[2]), UC(ap[3]),
/* seek to required offset */
if (offset)
- if (_ftp_cmd(conn, "REST %ju", (uintmax_t)offset) != FTP_FILE_OK)
+ if (ftp_cmd(conn, "REST %ju", (uintmax_t)offset) != FTP_FILE_OK)
goto sysouch;
/* make the server initiate the transfer */
if (verbose)
- _fetch_info("initiating transfer");
- e = _ftp_cmd(conn, "%s %.*s", oper, filenamelen, filename);
+ fetch_info("initiating transfer");
+ e = ftp_cmd(conn, "%s %.*s", oper, filenamelen, filename);
if (e != FTP_CONNECTION_ALREADY_OPEN && e != FTP_OPEN_DATA_CONNECTION)
goto ouch;
sd = d;
}
- if ((df = _ftp_setup(conn, _fetch_reopen(sd), mode)) == NULL)
+ if ((df = ftp_setup(conn, fetch_reopen(sd), mode)) == NULL)
goto sysouch;
return (df);
sysouch:
- _fetch_syserr();
+ fetch_syserr();
if (sd >= 0)
close(sd);
return (NULL);
ouch:
if (e != -1)
- _ftp_seterr(e);
+ ftp_seterr(e);
if (sd >= 0)
close(sd);
return (NULL);
* Authenticate
*/
static int
-_ftp_authenticate(conn_t *conn, struct url *url, struct url *purl)
+ftp_authenticate(conn_t *conn, struct url *url, struct url *purl)
{
const char *user, *pwd, *logname;
char pbuf[MAXHOSTNAMELEN + MAXLOGNAME + 1];
/* send user name and password */
if (url->user[0] == '\0')
- _fetch_netrc_auth(url);
+ fetch_netrc_auth(url);
user = url->user;
if (*user == '\0')
user = getenv("FTP_LOGIN");
if (user == NULL || *user == '\0')
user = FTP_ANONYMOUS_USER;
- if (purl && url->port == _fetch_default_port(url->scheme))
- e = _ftp_cmd(conn, "USER %s@%s", user, url->host);
+ if (purl && url->port == fetch_default_port(url->scheme))
+ e = ftp_cmd(conn, "USER %s@%s", user, url->host);
else if (purl)
- e = _ftp_cmd(conn, "USER %s@%s@%d", user, url->host, url->port);
+ e = ftp_cmd(conn, "USER %s@%s@%d", user, url->host, url->port);
else
- e = _ftp_cmd(conn, "USER %s", user);
+ e = ftp_cmd(conn, "USER %s", user);
/* did the server request a password? */
if (e == FTP_NEED_PASSWORD) {
gethostname(pbuf + len, sizeof(pbuf) - len);
pwd = pbuf;
}
- e = _ftp_cmd(conn, "PASS %s", pwd);
+ e = ftp_cmd(conn, "PASS %s", pwd);
}
return (e);
* Log on to FTP server
*/
static conn_t *
-_ftp_connect(struct url *url, struct url *purl, const char *flags)
+ftp_connect(struct url *url, struct url *purl, const char *flags)
{
conn_t *conn;
int e, direct, verbose;
/* check for proxy */
if (purl) {
/* XXX proxy authentication! */
- conn = _fetch_connect(purl->host, purl->port, af, verbose);
+ conn = fetch_connect(purl->host, purl->port, af, verbose);
} else {
/* no proxy, go straight to target */
- conn = _fetch_connect(url->host, url->port, af, verbose);
+ conn = fetch_connect(url->host, url->port, af, verbose);
purl = NULL;
}
/* check connection */
if (conn == NULL)
- /* _fetch_connect() has already set an error code */
+ /* fetch_connect() has already set an error code */
return (NULL);
/* expect welcome message */
- if ((e = _ftp_chkerr(conn)) != FTP_SERVICE_READY)
+ if ((e = ftp_chkerr(conn)) != FTP_SERVICE_READY)
goto fouch;
/* authenticate */
- if ((e = _ftp_authenticate(conn, url, purl)) != FTP_LOGGED_IN)
+ if ((e = ftp_authenticate(conn, url, purl)) != FTP_LOGGED_IN)
goto fouch;
/* TODO: Request extended features supported, if any (RFC 3659). */
fouch:
if (e != -1)
- _ftp_seterr(e);
- _fetch_close(conn);
+ ftp_seterr(e);
+ fetch_close(conn);
return (NULL);
}
* Disconnect from server
*/
static void
-_ftp_disconnect(conn_t *conn)
+ftp_disconnect(conn_t *conn)
{
- (void)_ftp_cmd(conn, "QUIT");
+ (void)ftp_cmd(conn, "QUIT");
if (conn == cached_connection && conn->ref == 1)
cached_connection = NULL;
- _fetch_close(conn);
+ fetch_close(conn);
}
/*
* Check if we're already connected
*/
static int
-_ftp_isconnected(struct url *url)
+ftp_isconnected(struct url *url)
{
return (cached_connection
&& (strcmp(url->host, cached_host.host) == 0)
* Check the cache, reconnect if no luck
*/
static conn_t *
-_ftp_cached_connect(struct url *url, struct url *purl, const char *flags)
+ftp_cached_connect(struct url *url, struct url *purl, const char *flags)
{
conn_t *conn;
int e;
/* set default port */
if (!url->port)
- url->port = _fetch_default_port(url->scheme);
+ url->port = fetch_default_port(url->scheme);
/* try to use previously cached connection */
- if (_ftp_isconnected(url)) {
- e = _ftp_cmd(cached_connection, "NOOP");
+ if (ftp_isconnected(url)) {
+ e = ftp_cmd(cached_connection, "NOOP");
if (e == FTP_OK || e == FTP_SYNTAX_ERROR)
- return (_fetch_ref(cached_connection));
+ return (fetch_ref(cached_connection));
}
/* connect to server */
- if ((conn = _ftp_connect(url, purl, flags)) == NULL)
+ if ((conn = ftp_connect(url, purl, flags)) == NULL)
return (NULL);
if (cached_connection)
- _ftp_disconnect(cached_connection);
- cached_connection = _fetch_ref(conn);
+ ftp_disconnect(cached_connection);
+ cached_connection = fetch_ref(conn);
memcpy(&cached_host, url, sizeof(*url));
return (conn);
}
* Check the proxy settings
*/
static struct url *
-_ftp_get_proxy(const char *flags)
+ftp_get_proxy(struct url * url, const char *flags)
{
struct url *purl;
char *p;
if (flags != NULL && strchr(flags, 'd') != NULL)
return (NULL);
+ if (fetch_no_proxy_match(url->host))
+ return (NULL);
if (((p = getenv("FTP_PROXY")) || (p = getenv("ftp_proxy")) ||
(p = getenv("HTTP_PROXY")) || (p = getenv("http_proxy"))) &&
*p && (purl = fetchParseURL(p)) != NULL) {
strcpy(purl->scheme, SCHEME_HTTP);
}
if (!purl->port)
- purl->port = _fetch_default_proxy_port(purl->scheme);
+ purl->port = fetch_default_proxy_port(purl->scheme);
if (strcasecmp(purl->scheme, SCHEME_FTP) == 0 ||
strcasecmp(purl->scheme, SCHEME_HTTP) == 0)
return (purl);
* Process an FTP request
*/
FILE *
-_ftp_request(struct url *url, const char *op, struct url_stat *us,
+ftp_request(struct url *url, const char *op, struct url_stat *us,
struct url *purl, const char *flags)
{
conn_t *conn;
/* check if we should use HTTP instead */
if (purl && strcasecmp(purl->scheme, SCHEME_HTTP) == 0) {
if (strcmp(op, "STAT") == 0)
- return (_http_request(url, "HEAD", us, purl, flags));
+ return (http_request(url, "HEAD", us, purl, flags));
else if (strcmp(op, "RETR") == 0)
- return (_http_request(url, "GET", us, purl, flags));
+ return (http_request(url, "GET", us, purl, flags));
/*
* Our HTTP code doesn't support PUT requests yet, so try
* a direct connection.
}
/* connect to server */
- conn = _ftp_cached_connect(url, purl, flags);
+ conn = ftp_cached_connect(url, purl, flags);
if (purl)
fetchFreeURL(purl);
if (conn == NULL)
return (NULL);
/* change directory */
- if (_ftp_cwd(conn, url->doc) == -1)
+ if (ftp_cwd(conn, url->doc) == -1)
return (NULL);
/* stat file */
- if (us && _ftp_stat(conn, url->doc, us) == -1
+ if (us && ftp_stat(conn, url->doc, us) == -1
&& fetchLastErrCode != FETCH_PROTO
&& fetchLastErrCode != FETCH_UNAVAIL)
return (NULL);
oflag = O_RDONLY;
/* initiate the transfer */
- return (_ftp_transfer(conn, op, url->doc, oflag, url->offset, flags));
+ return (ftp_transfer(conn, op, url->doc, oflag, url->offset, flags));
}
/*
FILE *
fetchXGetFTP(struct url *url, struct url_stat *us, const char *flags)
{
- return (_ftp_request(url, "RETR", us, _ftp_get_proxy(flags), flags));
+ return (ftp_request(url, "RETR", us, ftp_get_proxy(url, flags), flags));
}
/*
FILE *
fetchPutFTP(struct url *url, const char *flags)
{
-
- return (_ftp_request(url, CHECK_FLAG('a') ? "APPE" : "STOR", NULL,
- _ftp_get_proxy(flags), flags));
+ return (ftp_request(url, CHECK_FLAG('a') ? "APPE" : "STOR", NULL,
+ ftp_get_proxy(url, flags), flags));
}
/*
{
FILE *f;
- f = _ftp_request(url, "STAT", us, _ftp_get_proxy(flags), flags);
+ f = ftp_request(url, "STAT", us, ftp_get_proxy(url, flags), flags);
if (f == NULL)
return (-1);
+ /*
+ * When op is "STAT", ftp_request() will return either NULL or
+ * (FILE *)1, never a valid FILE *, so we mustn't fclose(f) before
+ * returning, as it would cause a segfault.
+ */
return (0);
}
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/lib/libfetch/http.c,v 1.78 2007/05/08 19:28:03 des Exp $
+ * $FreeBSD: src/lib/libfetch/http.c,v 1.86 2008/12/15 08:27:44 murray Exp $
* $DragonFly: src/lib/libfetch/http.c,v 1.4 2007/08/05 21:48:12 swildner Exp $
*/
#include <sys/param.h>
#include <sys/socket.h>
+#include <sys/time.h>
#include <ctype.h>
#include <err.h>
#define HTTP_MOVED_PERM 301
#define HTTP_MOVED_TEMP 302
#define HTTP_SEE_OTHER 303
+#define HTTP_NOT_MODIFIED 304
#define HTTP_TEMP_REDIRECT 307
#define HTTP_NEED_AUTH 401
#define HTTP_NEED_PROXY_AUTH 407
* Get next chunk header
*/
static int
-_http_new_chunk(struct httpio *io)
+http_new_chunk(struct httpio *io)
{
char *p;
- if (_fetch_getln(io->conn) == -1)
+ if (fetch_getln(io->conn) == -1)
return (-1);
- if (io->conn->buflen < 2 || !isxdigit(*io->conn->buf))
+ if (io->conn->buflen < 2 || !isxdigit((unsigned char)*io->conn->buf))
return (-1);
- for (p = io->conn->buf; *p && !isspace(*p); ++p) {
+ for (p = io->conn->buf; *p && !isspace((unsigned char)*p); ++p) {
if (*p == ';')
break;
- if (!isxdigit(*p))
+ if (!isxdigit((unsigned char)*p))
return (-1);
- if (isdigit(*p)) {
+ if (isdigit((unsigned char)*p)) {
io->chunksize = io->chunksize * 16 +
*p - '0';
} else {
io->chunksize = io->chunksize * 16 +
- 10 + tolower(*p) - 'a';
+ 10 + tolower((unsigned char)*p) - 'a';
}
}
* Grow the input buffer to at least len bytes
*/
static inline int
-_http_growbuf(struct httpio *io, size_t len)
+http_growbuf(struct httpio *io, size_t len)
{
char *tmp;
* Fill the input buffer, do chunk decoding on the fly
*/
static int
-_http_fillbuf(struct httpio *io, size_t len)
+http_fillbuf(struct httpio *io, size_t len)
{
if (io->error)
return (-1);
return (0);
if (io->chunked == 0) {
- if (_http_growbuf(io, len) == -1)
+ if (http_growbuf(io, len) == -1)
return (-1);
- if ((io->buflen = _fetch_read(io->conn, io->buf, len)) == -1) {
+ if ((io->buflen = fetch_read(io->conn, io->buf, len)) == -1) {
io->error = 1;
return (-1);
}
}
if (io->chunksize == 0) {
- switch (_http_new_chunk(io)) {
+ switch (http_new_chunk(io)) {
case -1:
io->error = 1;
return (-1);
if (len > io->chunksize)
len = io->chunksize;
- if (_http_growbuf(io, len) == -1)
+ if (http_growbuf(io, len) == -1)
return (-1);
- if ((io->buflen = _fetch_read(io->conn, io->buf, len)) == -1) {
+ if ((io->buflen = fetch_read(io->conn, io->buf, len)) == -1) {
io->error = 1;
return (-1);
}
if (io->chunksize == 0) {
char endl[2];
- if (_fetch_read(io->conn, endl, 2) != 2 ||
+ if (fetch_read(io->conn, endl, 2) != 2 ||
endl[0] != '\r' || endl[1] != '\n')
return (-1);
}
* Read function
*/
static int
-_http_readfn(void *v, char *buf, int len)
+http_readfn(void *v, char *buf, int len)
{
struct httpio *io = (struct httpio *)v;
int l, pos;
for (pos = 0; len > 0; pos += l, len -= l) {
/* empty buffer */
if (!io->buf || io->bufpos == io->buflen)
- if (_http_fillbuf(io, len) < 1)
+ if (http_fillbuf(io, len) < 1)
break;
l = io->buflen - io->bufpos;
if (len < l)
l = len;
- bcopy(io->buf + io->bufpos, buf + pos, l);
+ memcpy(buf + pos, io->buf + io->bufpos, l);
io->bufpos += l;
}
* Write function
*/
static int
-_http_writefn(void *v, const char *buf, int len)
+http_writefn(void *v, const char *buf, int len)
{
struct httpio *io = (struct httpio *)v;
- return (_fetch_write(io->conn, buf, len));
+ return (fetch_write(io->conn, buf, len));
}
/*
* Close function
*/
static int
-_http_closefn(void *v)
+http_closefn(void *v)
{
struct httpio *io = (struct httpio *)v;
int r;
- r = _fetch_close(io->conn);
+ r = fetch_close(io->conn);
if (io->buf)
free(io->buf);
free(io);
* Wrap a file descriptor up
*/
static FILE *
-_http_funopen(conn_t *conn, int chunked)
+http_funopen(conn_t *conn, int chunked)
{
struct httpio *io;
FILE *f;
if ((io = calloc(1, sizeof(*io))) == NULL) {
- _fetch_syserr();
+ fetch_syserr();
return (NULL);
}
io->conn = conn;
io->chunked = chunked;
- f = funopen(io, _http_readfn, _http_writefn, NULL, _http_closefn);
+ f = funopen(io, http_readfn, http_writefn, NULL, http_closefn);
if (f == NULL) {
- _fetch_syserr();
+ fetch_syserr();
free(io);
return (NULL);
}
* Send a formatted line; optionally echo to terminal
*/
static int
-_http_cmd(conn_t *conn, const char *fmt, ...)
+http_cmd(conn_t *conn, const char *fmt, ...)
{
va_list ap;
size_t len;
if (msg == NULL) {
errno = ENOMEM;
- _fetch_syserr();
+ fetch_syserr();
return (-1);
}
- r = _fetch_putln(conn, msg, len);
+ r = fetch_putln(conn, msg, len);
free(msg);
if (r == -1) {
- _fetch_syserr();
+ fetch_syserr();
return (-1);
}
* Get and parse status line
*/
static int
-_http_get_reply(conn_t *conn)
+http_get_reply(conn_t *conn)
{
char *p;
- if (_fetch_getln(conn) == -1)
+ if (fetch_getln(conn) == -1)
return (-1);
/*
* A valid status line looks like "HTTP/m.n xyz reason" where m
return (HTTP_PROTOCOL_ERROR);
p += 4;
}
- if (*p != ' ' || !isdigit(p[1]) || !isdigit(p[2]) || !isdigit(p[3]))
+ if (*p != ' ' ||
+ !isdigit((unsigned char)p[1]) ||
+ !isdigit((unsigned char)p[2]) ||
+ !isdigit((unsigned char)p[3]))
return (HTTP_PROTOCOL_ERROR);
conn->err = (p[1] - '0') * 100 + (p[2] - '0') * 10 + (p[3] - '0');
* to the beginning of the value.
*/
static const char *
-_http_match(const char *str, const char *hdr)
+http_match(const char *str, const char *hdr)
{
- while (*str && *hdr && tolower(*str++) == tolower(*hdr++))
+ while (*str && *hdr &&
+ tolower((unsigned char)*str++) == tolower((unsigned char)*hdr++))
/* nothing */;
if (*str || *hdr != ':')
return (NULL);
- while (*hdr && isspace(*++hdr))
+ while (*hdr && isspace((unsigned char)*++hdr))
/* nothing */;
return (hdr);
}
* Get the next header and return the appropriate symbolic code.
*/
static hdr_t
-_http_next_header(conn_t *conn, const char **p)
+http_next_header(conn_t *conn, const char **p)
{
int i;
- if (_fetch_getln(conn) == -1)
+ if (fetch_getln(conn) == -1)
return (hdr_syserror);
- while (conn->buflen && isspace(conn->buf[conn->buflen - 1]))
+ while (conn->buflen && isspace((unsigned char)conn->buf[conn->buflen - 1]))
conn->buflen--;
conn->buf[conn->buflen] = '\0';
if (conn->buflen == 0)
* characters except "()<>@,;:\\\"{}".
*/
for (i = 0; hdr_names[i].num != hdr_unknown; i++)
- if ((*p = _http_match(hdr_names[i].name, conn->buf)) != NULL)
+ if ((*p = http_match(hdr_names[i].name, conn->buf)) != NULL)
return (hdr_names[i].num);
return (hdr_unknown);
}
* Parse a last-modified header
*/
static int
-_http_parse_mtime(const char *p, time_t *mtime)
+http_parse_mtime(const char *p, time_t *mtime)
{
char locale[64], *r;
struct tm tm;
* Parse a content-length header
*/
static int
-_http_parse_length(const char *p, off_t *length)
+http_parse_length(const char *p, off_t *length)
{
off_t len;
- for (len = 0; *p && isdigit(*p); ++p)
+ for (len = 0; *p && isdigit((unsigned char)*p); ++p)
len = len * 10 + (*p - '0');
if (*p)
return (-1);
* Parse a content-range header
*/
static int
-_http_parse_range(const char *p, off_t *offset, off_t *length, off_t *size)
+http_parse_range(const char *p, off_t *offset, off_t *length, off_t *size)
{
off_t first, last, len;
first = last = -1;
++p;
} else {
- for (first = 0; *p && isdigit(*p); ++p)
+ for (first = 0; *p && isdigit((unsigned char)*p); ++p)
first = first * 10 + *p - '0';
if (*p != '-')
return (-1);
- for (last = 0, ++p; *p && isdigit(*p); ++p)
+ for (last = 0, ++p; *p && isdigit((unsigned char)*p); ++p)
last = last * 10 + *p - '0';
}
if (first > last || *p != '/')
return (-1);
- for (len = 0, ++p; *p && isdigit(*p); ++p)
+ for (len = 0, ++p; *p && isdigit((unsigned char)*p); ++p)
len = len * 10 + *p - '0';
if (*p || len < last - first + 1)
return (-1);
* Base64 encoding
*/
static char *
-_http_base64(const char *src)
+http_base64(const char *src)
{
static const char base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
* Encode username and password
*/
static int
-_http_basic_auth(conn_t *conn, const char *hdr, const char *usr, const char *pwd)
+http_basic_auth(conn_t *conn, const char *hdr, const char *usr, const char *pwd)
{
char *upw, *auth;
int r;
DEBUG(fprintf(stderr, "pwd: [%s]\n", pwd));
if (asprintf(&upw, "%s:%s", usr, pwd) == -1)
return (-1);
- auth = _http_base64(upw);
+ auth = http_base64(upw);
free(upw);
if (auth == NULL)
return (-1);
- r = _http_cmd(conn, "%s: Basic %s", hdr, auth);
+ r = http_cmd(conn, "%s: Basic %s", hdr, auth);
free(auth);
return (r);
}
* Send an authorization header
*/
static int
-_http_authorize(conn_t *conn, const char *hdr, const char *p)
+http_authorize(conn_t *conn, const char *hdr, const char *p)
{
/* basic authorization */
if (strncasecmp(p, "basic:", 6) == 0) {
user = str;
pwd = strchr(str, ':');
*pwd++ = '\0';
- r = _http_basic_auth(conn, hdr, user, pwd);
+ r = http_basic_auth(conn, hdr, user, pwd);
free(str);
return (r);
}
* Connect to the correct HTTP server or proxy.
*/
static conn_t *
-_http_connect(struct url *URL, struct url *purl, const char *flags)
+http_connect(struct url *URL, struct url *purl, const char *flags)
{
conn_t *conn;
int verbose;
return (NULL);
}
- if ((conn = _fetch_connect(URL->host, URL->port, af, verbose)) == NULL)
- /* _fetch_connect() has already set an error code */
+ if ((conn = fetch_connect(URL->host, URL->port, af, verbose)) == NULL)
+ /* fetch_connect() has already set an error code */
return (NULL);
if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0 &&
- _fetch_ssl(conn, verbose) == -1) {
- _fetch_close(conn);
+ fetch_ssl(conn, verbose) == -1) {
+ fetch_close(conn);
/* grrr */
errno = EAUTH;
- _fetch_syserr();
+ fetch_syserr();
return (NULL);
}
}
static struct url *
-_http_get_proxy(const char *flags)
+http_get_proxy(struct url * url, const char *flags)
{
struct url *purl;
char *p;
if (flags != NULL && strchr(flags, 'd') != NULL)
return (NULL);
+ if (fetch_no_proxy_match(url->host))
+ return (NULL);
if (((p = getenv("HTTP_PROXY")) || (p = getenv("http_proxy"))) &&
*p && (purl = fetchParseURL(p))) {
if (!*purl->scheme)
strcpy(purl->scheme, SCHEME_HTTP);
if (!purl->port)
- purl->port = _fetch_default_proxy_port(purl->scheme);
+ purl->port = fetch_default_proxy_port(purl->scheme);
if (strcasecmp(purl->scheme, SCHEME_HTTP) == 0)
return (purl);
fetchFreeURL(purl);
}
static void
-_http_print_html(FILE *out, FILE *in)
+http_print_html(FILE *out, FILE *in)
{
size_t len;
char *line, *p, *q;
comment = tag = 0;
while ((line = fgetln(in, &len)) != NULL) {
- while (len && isspace(line[len - 1]))
+ while (len && isspace((unsigned char)line[len - 1]))
--len;
for (p = q = line; q < line + len; ++q) {
if (comment && *q == '-') {
* XXX off into a separate function.
*/
FILE *
-_http_request(struct url *URL, const char *op, struct url_stat *us,
+http_request(struct url *URL, const char *op, struct url_stat *us,
struct url *purl, const char *flags)
{
+ char timebuf[80];
+ char hbuf[MAXHOSTNAMELEN + 7], *host;
conn_t *conn;
struct url *url, *new;
- int chunked, direct, need_auth, noredirect, verbose;
+ int chunked, direct, ims, need_auth, noredirect, verbose;
int e, i, n, val;
off_t offset, clength, length, size;
time_t mtime;
const char *p;
FILE *f;
hdr_t h;
- char hbuf[MAXHOSTNAMELEN + 7], *host;
+ struct tm *timestruct;
direct = CHECK_FLAG('d');
noredirect = CHECK_FLAG('A');
verbose = CHECK_FLAG('v');
+ ims = CHECK_FLAG('i');
if (direct && purl) {
fetchFreeURL(purl);
/* check port */
if (!url->port)
- url->port = _fetch_default_port(url->scheme);
+ url->port = fetch_default_port(url->scheme);
/* were we redirected to an FTP URL? */
if (purl == NULL && strcmp(url->scheme, SCHEME_FTP) == 0) {
if (strcmp(op, "GET") == 0)
- return (_ftp_request(url, "RETR", us, purl, flags));
+ return (ftp_request(url, "RETR", us, purl, flags));
else if (strcmp(op, "HEAD") == 0)
- return (_ftp_request(url, "STAT", us, purl, flags));
+ return (ftp_request(url, "STAT", us, purl, flags));
}
/* connect to server or proxy */
- if ((conn = _http_connect(url, purl, flags)) == NULL)
+ if ((conn = http_connect(url, purl, flags)) == NULL)
goto ouch;
host = url->host;
host = hbuf;
}
#endif
- if (url->port != _fetch_default_port(url->scheme)) {
+ if (url->port != fetch_default_port(url->scheme)) {
if (host != hbuf) {
strcpy(hbuf, host);
host = hbuf;
/* send request */
if (verbose)
- _fetch_info("requesting %s://%s%s",
+ fetch_info("requesting %s://%s%s",
url->scheme, host, url->doc);
if (purl) {
- _http_cmd(conn, "%s %s://%s%s HTTP/1.1",
+ http_cmd(conn, "%s %s://%s%s HTTP/1.1",
op, url->scheme, host, url->doc);
} else {
- _http_cmd(conn, "%s %s HTTP/1.1",
+ http_cmd(conn, "%s %s HTTP/1.1",
op, url->doc);
}
+ if (ims && url->ims_time) {
+ timestruct = gmtime((time_t *)&url->ims_time);
+ (void)strftime(timebuf, 80, "%a, %d %b %Y %T GMT",
+ timestruct);
+ if (verbose)
+ fetch_info("If-Modified-Since: %s", timebuf);
+ http_cmd(conn, "If-Modified-Since: %s", timebuf);
+ }
/* virtual host */
- _http_cmd(conn, "Host: %s", host);
+ http_cmd(conn, "Host: %s", host);
/* proxy authorization */
if (purl) {
if (*purl->user || *purl->pwd)
- _http_basic_auth(conn, "Proxy-Authorization",
+ http_basic_auth(conn, "Proxy-Authorization",
purl->user, purl->pwd);
else if ((p = getenv("HTTP_PROXY_AUTH")) != NULL && *p != '\0')
- _http_authorize(conn, "Proxy-Authorization", p);
+ http_authorize(conn, "Proxy-Authorization", p);
}
/* server authorization */
if (need_auth || *url->user || *url->pwd) {
if (*url->user || *url->pwd)
- _http_basic_auth(conn, "Authorization", url->user, url->pwd);
+ http_basic_auth(conn, "Authorization", url->user, url->pwd);
else if ((p = getenv("HTTP_AUTH")) != NULL && *p != '\0')
- _http_authorize(conn, "Authorization", p);
+ http_authorize(conn, "Authorization", p);
else if (fetchAuthMethod && fetchAuthMethod(url) == 0) {
- _http_basic_auth(conn, "Authorization", url->user, url->pwd);
+ http_basic_auth(conn, "Authorization", url->user, url->pwd);
} else {
- _http_seterr(HTTP_NEED_AUTH);
+ http_seterr(HTTP_NEED_AUTH);
goto ouch;
}
}
/* other headers */
if ((p = getenv("HTTP_REFERER")) != NULL && *p != '\0') {
if (strcasecmp(p, "auto") == 0)
- _http_cmd(conn, "Referer: %s://%s%s",
+ http_cmd(conn, "Referer: %s://%s%s",
url->scheme, host, url->doc);
else
- _http_cmd(conn, "Referer: %s", p);
+ http_cmd(conn, "Referer: %s", p);
}
if ((p = getenv("HTTP_USER_AGENT")) != NULL && *p != '\0')
- _http_cmd(conn, "User-Agent: %s", p);
+ http_cmd(conn, "User-Agent: %s", p);
else
- _http_cmd(conn, "User-Agent: %s " _LIBFETCH_VER, getprogname());
+ http_cmd(conn, "User-Agent: %s " _LIBFETCH_VER, getprogname());
if (url->offset > 0)
- _http_cmd(conn, "Range: bytes=%lld-", (long long)url->offset);
- _http_cmd(conn, "Connection: close");
- _http_cmd(conn, "");
+ http_cmd(conn, "Range: bytes=%lld-", (long long)url->offset);
+ http_cmd(conn, "Connection: close");
+ http_cmd(conn, "");
/*
* Force the queued request to be dispatched. Normally, one
sizeof(val));
/* get reply */
- switch (_http_get_reply(conn)) {
+ switch (http_get_reply(conn)) {
case HTTP_OK:
case HTTP_PARTIAL:
+ case HTTP_NOT_MODIFIED:
/* fine */
&