Splitting up and simplifying devel/apr1

Tijl Coosemans tijl at FreeBSD.org
Wed Jun 19 13:18:50 UTC 2013


Hi,

In the discussion on src-committers about svnlite it was mentioned that
devel/subversion is too heavy to build, pulling in perl, python and
all the autotools. I've been going over its dependencies and it turns
out these are all pulled in by devel/apr1, so I've been looking into
simplifying that port.

It seems the port can easily be split up into two simple ports, one for
the APR library and one for the APR Utility library. There's no need
for autotools, libtool, python, etc.

I've attached a patch that creates devel/apr and devel/apr-util.
Please take a look at them and let me know what you think.
Another patch can then remove devel/apr1 and update all ports that
depend on it, but before I spend more time on this, do you agree this
is the right approach?
-------------- next part --------------
Index: devel/apr/Makefile
===================================================================
--- devel/apr/Makefile	(revision 0)
+++ devel/apr/Makefile	(working copy)
@@ -0,0 +1,40 @@
+# $FreeBSD$
+
+PORTNAME=	apr
+PORTVERSION=	1.4.6
+CATEGORIES=	devel
+MASTER_SITES=	${MASTER_SITE_APACHE}
+MASTER_SITE_SUBDIR=	apr
+
+MAINTAINER=	apache at FreeBSD.org
+COMMENT=	Apache Portable Runtime library
+
+CONFLICTS_INSTALL=	apr-[0-9]*.[0-9]*.[0-9]*.[0-9]*
+GNU_CONFIGURE=	yes
+MAKE_JOBS_SAFE=	yes
+USES=		pathfix
+USE_LDCONFIG=	yes
+
+OPTIONS_DEFINE=	THREADS IPV6 DEVRANDOM
+OPTIONS_DEFAULT=THREADS IPV6 DEVRANDOM
+DEVRANDOM_DESC=	Use /dev/random or compatible
+
+CONFIGURE_ARGS=	--with-installbuilddir=${DATADIR}/build-1
+THREADS_CONFIGURE_ENABLE=	threads
+IPV6_CONFIGURE_ENABLE=		ipv6
+DEVRANDOM_CONFIGURE_OFF=	--without-devrandom
+
+SHLIB_MAJOR=	4
+PLIST_SUB=	SHLIB_MAJOR="${SHLIB_MAJOR}"
+
+post-patch: .SILENT
+	${REINPLACE_CMD} -e 's/$$os_version/${OSVERSION}/g' \
+		${WRKSRC}/configure
+# Fix pthread: Please do not remove, else apr-1-config returns wrong values
+	${REINPLACE_CMD} -e 's/-lpthread/${PTHREAD_LIBS}/g' \
+		${WRKSRC}/configure
+
+regression-test: build
+	@cd ${WRKSRC} && ${MAKE} test
+
+.include <bsd.port.mk>
Index: devel/apr/distinfo
===================================================================
--- devel/apr/distinfo	(revision 0)
+++ devel/apr/distinfo	(working copy)
@@ -0,0 +1,2 @@
+SHA256 (apr-1.4.6.tar.gz) = 538d593d805c36985fc6d200d31bf6c1b5f90df2a50b917902743a13bbc10e05
+SIZE (apr-1.4.6.tar.gz) = 982243
Index: devel/apr/pkg-descr
===================================================================
--- devel/apr/pkg-descr	(revision 0)
+++ devel/apr/pkg-descr	(working copy)
@@ -0,0 +1,6 @@
+The Apache Portable Runtime library provides a predictable and consistent
+interface to underlying platform-specific implementations, relieving software
+developers of the need to code special-case conditions to work around or take
+advantage of platform-specific deficiencies or features.
+
+WWW: http://apr.apache.org/
Index: devel/apr/pkg-plist
===================================================================
--- devel/apr/pkg-plist	(revision 0)
+++ devel/apr/pkg-plist	(working copy)
@@ -0,0 +1,51 @@
+bin/apr-1-config
+include/apr-1/apr.h
+include/apr-1/apr_allocator.h
+include/apr-1/apr_atomic.h
+include/apr-1/apr_dso.h
+include/apr-1/apr_env.h
+include/apr-1/apr_errno.h
+include/apr-1/apr_file_info.h
+include/apr-1/apr_file_io.h
+include/apr-1/apr_fnmatch.h
+include/apr-1/apr_general.h
+include/apr-1/apr_getopt.h
+include/apr-1/apr_global_mutex.h
+include/apr-1/apr_hash.h
+include/apr-1/apr_inherit.h
+include/apr-1/apr_lib.h
+include/apr-1/apr_mmap.h
+include/apr-1/apr_network_io.h
+include/apr-1/apr_poll.h
+include/apr-1/apr_pools.h
+include/apr-1/apr_portable.h
+include/apr-1/apr_proc_mutex.h
+include/apr-1/apr_random.h
+include/apr-1/apr_ring.h
+include/apr-1/apr_shm.h
+include/apr-1/apr_signal.h
+include/apr-1/apr_strings.h
+include/apr-1/apr_support.h
+include/apr-1/apr_tables.h
+include/apr-1/apr_thread_cond.h
+include/apr-1/apr_thread_mutex.h
+include/apr-1/apr_thread_proc.h
+include/apr-1/apr_thread_rwlock.h
+include/apr-1/apr_time.h
+include/apr-1/apr_user.h
+include/apr-1/apr_version.h
+include/apr-1/apr_want.h
+lib/apr.exp
+lib/libapr-1.a
+lib/libapr-1.la
+lib/libapr-1.so
+lib/libapr-1.so.%%SHLIB_MAJOR%%
+libdata/pkgconfig/apr-1.pc
+%%DATADIR%%/build-1/apr_rules.mk
+%%DATADIR%%/build-1/libtool
+%%DATADIR%%/build-1/make_exports.awk
+%%DATADIR%%/build-1/make_var_export.awk
+%%DATADIR%%/build-1/mkdir.sh
+ at dirrm %%DATADIR%%/build-1
+ at dirrm %%DATADIR%%
+ at dirrm include/apr-1
Index: devel/apr-util/Makefile
===================================================================
--- devel/apr-util/Makefile	(revision 0)
+++ devel/apr-util/Makefile	(working copy)
@@ -0,0 +1,161 @@
+# $FreeBSD$
+
+PORTNAME=	apr-util
+PORTVERSION=	1.4.1
+CATEGORIES=	devel
+MASTER_SITES=	${MASTER_SITE_APACHE}
+MASTER_SITE_SUBDIR=	apr
+
+MAINTAINER=	apache at FreeBSD.org
+COMMENT=	Apache Portable Runtime Utility library
+
+LIB_DEPENDS=	apr-1:${PORTSDIR}/devel/apr \
+		expat:${PORTSDIR}/textproc/expat2
+
+CONFLICTS_INSTALL=	apr-[0-9]*.[0-9]*.[0-9]*.[0-9]*
+GNU_CONFIGURE=	yes
+MAKE_JOBS_SAFE=	yes
+USES=		iconv pathfix
+USE_LDCONFIG=	yes
+
+OPTIONS_DEFINE=	BDB GDBM LDAP MYSQL NDBM PGSQL SQLITE FREETDS
+OPTIONS_RADIO=	CRYPTO
+OPTIONS_RADIO_CRYPTO=	SSL
+OPTIONS_DEFAULT=BDB GDBM SSL
+NDBM_DESC=	NDBM support
+SSL_DESC=	OpenSSL crypto driver
+NSS_DESC=	NSS crypto driver
+
+CONFIGURE_ARGS=	--with-apr=${LOCALBASE} \
+		--with-expat=${LOCALBASE} \
+		--with-iconv=${LOCALBASE}
+
+SHLIB_MAJOR=	4
+PLIST_SUB=	SHLIB_MAJOR="${SHLIB_MAJOR}"
+
+.include <bsd.port.options.mk>
+
+.if ${PORT_OPTIONS:MGDBM}
+PLIST_SUB+=	GDBM=""
+APU_EXTRAS=	yes
+LIB_DEPENDS+=	gdbm:${PORTSDIR}/databases/gdbm
+CONFIGURE_ARGS+=	--with-gdbm=${LOCALBASE}
+.else
+PLIST_SUB+=	GDBM="@comment "
+CONFIGURE_ARGS+=	--without-gdbm
+.endif
+
+.if ${PORT_OPTIONS:MBDB}
+APU_EXTRAS=	yes
+PLIST_SUB+=	BDB=""
+USE_BDB=	42+
+CONFIGURE_ARGS+=	--with-berkeley-db=${BDB_INCLUDE_DIR}:${BDB_LIB_DIR}
+.else
+PLIST_SUB+=	BDB="@comment "
+CONFIGURE_ARGS+=	--without-berkeley-db
+.endif
+
+.if ${PORT_OPTIONS:MNDBM}
+APU_EXTRAS=	yes
+PLIST_SUB+=	NDBM=""
+CONFIGURE_ARGS+=	--with-ndbm=/usr
+.else
+PLIST_SUB+=	NDBM="@comment "
+CONFIGURE_ARGS+=	--without-ndbm
+.endif
+
+.if ${PORT_OPTIONS:MLDAP}
+APU_EXTRAS=	yes
+PLIST_SUB+=	LDAP=""
+USE_OPENLDAP=	yes
+CONFIGURE_ARGS+=	--with-ldap-include=${LOCALBASE}/include \
+	--with-ldap-lib=${LOCALBASE}/lib --with-ldap=ldap
+.else
+PLIST_SUB+=	LDAP="@comment "
+CONFIGURE_ARGS+=	--without-ldap
+.endif
+
+.if ${PORT_OPTIONS:MFREETDS}
+APU_EXTRAS=	yes
+PLIST_SUB+=	FREETDS=""
+CONFIGURE_ARGS+=	--with-freetds=${LOCALBASE}
+LIB_DEPENDS+=	sybdb:${PORTSDIR}/databases/freetds
+.else
+PLIST_SUB+=	FREETDS="@comment "
+CONFIGURE_ARGS+=	--without-freetds
+.endif
+
+.if ${PORT_OPTIONS:MMYSQL}
+APU_EXTRAS=	yes
+PLIST_SUB+=	MYSQL=""
+USE_MYSQL=	YES
+CONFIGURE_ARGS+=	--with-mysql=${LOCALBASE}
+CONFIGURE_ENV+=	LIBS="${LIBS}"
+CFLAGS+=	-I${LOCALBASE}/include -I${LOCALBASE}/include/mysql -DHAVE_MYSQL_H
+LDFLAGS+=	-L${LOCALBASE}/lib/mysql
+.else
+PLIST_SUB+=	MYSQL="@comment "
+CONFIGURE_ARGS+=	--without-mysql
+.endif
+
+.if ${PORT_OPTIONS:MPGSQL}
+APU_EXTRAS=	yes
+PLIST_SUB+=	PGSQL=""
+USE_PGSQL=	YES
+CONFIGURE_ARGS+=	--with-pgsql=${LOCALBASE}
+CONFIGURE_ENV+=	ac_cv_path_PGSQL_CONFIG=""
+.else
+PLIST_SUB+=	PGSQL="@comment "
+CONFIGURE_ARGS+=	--without-pgsql
+.endif
+
+.if ${PORT_OPTIONS:MSQLITE}
+APU_EXTRAS=	yes
+PLIST_SUB+=	SQLITE3=""
+USE_SQLITE=	YES
+CONFIGURE_ARGS+=	--with-sqlite3=${LOCALBASE}
+.else
+CONFIGURE_ARGS+=	--without-sqlite3
+PLIST_SUB+=	SQLITE3="@comment "
+.endif
+
+# crypto (apache24)
+.if ${PORT_OPTIONS:MSSL} || ${PORT_OPTIONS:MNSS}
+CONFIGURE_ARGS+=	--with-crypto
+.endif
+
+.if ${PORT_OPTIONS:MSSL}
+APU_EXTRAS=	yes
+USE_OPENSSL=	yes
+PLIST_SUB+=	SSL=""
+CFLAGS+=	-I${OPENSSLINC}
+LDFLAGS+=	-L${OPENSSLLIB}
+CONFIGURE_ARGS+=	--with-openssl=${OPENSSLBASE}
+.else
+PLIST_SUB+=	SSL="@comment "
+CONFIGURE_ARGS+=	--without-openssl
+.endif
+
+# TODO figure out why nss flag is ignored if ssl is set
+# this works on other OS as expected
+.if ${PORT_OPTIONS:MNSS}
+APU_EXTRAS=	yes
+PLIST_SUB+=	NSS=""
+LIB_DEPENDS+=	nss3:${PORTSDIR}/security/nss
+CFLAGS+=	-I${LOCALBASE}/include/nss
+LDFLAGS+=	-L${LOCALBASE}/lib/nss
+CONFIGURE_ARGS+=	--with-nss=${LOCALBASE}
+.else
+PLIST_SUB+=	NSS="@comment "
+.endif
+
+.if defined(APU_EXTRAS)
+PLIST_SUB+=	APU_EXTRAS=""
+.else
+PLIST_SUB+=	APU_EXTRAS="@comment "
+.endif
+
+regression-test: build
+	@cd ${WRKSRC} && ${MAKE} test
+
+.include <bsd.port.mk>
Index: devel/apr-util/distinfo
===================================================================
--- devel/apr-util/distinfo	(revision 0)
+++ devel/apr-util/distinfo	(working copy)
@@ -0,0 +1,2 @@
+SHA256 (apr-util-1.4.1.tar.gz) = d636d9ef95c6e50e47fc338d532aa375edd11e5d7a3c30dee48beb38ddf4ab4c
+SIZE (apr-util-1.4.1.tar.gz) = 774770
Index: devel/apr-util/files/patch-apr-util__dbd__apr_dbd_freetds.c
===================================================================
--- devel/apr-util/files/patch-apr-util__dbd__apr_dbd_freetds.c	(revision 0)
+++ devel/apr-util/files/patch-apr-util__dbd__apr_dbd_freetds.c	(working copy)
@@ -0,0 +1,560 @@
+# http://lists.freebsd.org/pipermail/freebsd-apache/2013-January/003020.html
+# 
+# From: "Mikhail T." <mi+thun at aldan.algebra.com>
+#   I've made the FreeTDS-driver work again -- and submitted the patch to Apache:
+#   https://issues.apache.org/bugzilla/show_bug.cgi?id=53666
+===================================================================================
+--- dbd/apr_dbd_freetds.c.orig
++++ dbd/apr_dbd_freetds.c
+@@ -40,12 +40,12 @@
+ #include <freetds/sybdb.h>
+ #endif
+ #ifdef HAVE_SYBDB_H
++#include <sybfront.h>
+ #include <sybdb.h>
+ #endif
+ 
+ #include <stdio.h>
+ #include <sys/types.h>
+-#include <regex.h>
+ 
+ /* This probably needs to change for different applications */
+ #define MAX_COL_LEN 256
+@@ -67,6 +67,7 @@
+     apr_dbd_transaction_t *trans;
+     apr_pool_t *pool;
+     const char *params;
++    const char *lasterror;
+     RETCODE err;
+ };
+ 
+@@ -80,20 +81,20 @@
+ 
+ struct apr_dbd_row_t {
+     apr_dbd_results_t *res;
+-    BYTE buf[MAX_COL_LEN];
++    apr_pool_t *pool;
+ };
+ 
+ struct apr_dbd_prepared_t {
+     int nargs;
+-    regex_t **taint;
+-    int *sz;
+-    char *fmt;
++    int fmtlen;
++    const char *fmt, *label;
++    apr_dbd_type_e *types;
++    int offsets[];
+ };
+ 
+-#define dbd_freetds_is_success(x) (x == SUCCEED)
++const apr_dbd_driver_t apr_dbd_freetds_driver; /* Forward declaration */
+ 
+-static int labelnum = 0; /* FIXME */
+-static regex_t dbd_freetds_find_arg;
++#define dbd_freetds_is_success(x) (x == SUCCEED)
+ 
+ /* execute a query that doesn't return a result set, mop up,
+  * and return and APR-flavoured status
+@@ -102,7 +103,11 @@
+                             int want_results, int *nrows)
+ {
+     /* TBD */
+-    RETCODE rv = dbcmd(proc, query);
++    RETCODE rv = dbcmd(proc,
++#ifndef TDS_STATIC_CAST /* if not compiling against FreeTDS, drop const :-( */
++	(char *)
++#endif
++	query);
+     if (rv != SUCCEED) {
+         return rv;
+     }
+@@ -143,6 +148,7 @@
+      * Ignore seek
+      */
+ 
++    sql->lasterror = NULL;
+     sql->err = freetds_exec(sql->proc, query, 1, NULL);
+     if (!dbd_freetds_is_success(sql->err)) {
+         if (sql->trans) {
+@@ -190,51 +196,38 @@
+ #endif
+     return (sql->err == SUCCEED) ? 0 : 1;
+ }
+-static const char *dbd_untaint(apr_pool_t *pool, regex_t *rx, const char *val)
+-{
+-    regmatch_t match[1];
+-    if (rx == NULL) {
+-        /* no untaint expression */
+-        return val;
+-    }
+-    if (regexec(rx, val, 1, match, 0) == 0) {
+-        return apr_pstrndup(pool, val+match[0].rm_so,
+-                            match[0].rm_eo - match[0].rm_so);
+-    }
+-    return "";
+-}
++
+ static const char *dbd_statement(apr_pool_t *pool,
+-                                 apr_dbd_prepared_t *stmt,
+-                                 int nargs, const char **args)
++                                 const apr_dbd_prepared_t *stmt,
++                                 const char **args)
+ {
+     int i;
+     int len;
+-    const char *var;
+     char *ret;
+-    const char *p_in;
++    const char *p_in, *format;
+     char *p_out;
+-    char *q;
+    
+-    /* compute upper bound on length (since untaint shrinks) */
+-    len  = strlen(stmt->fmt) +1;
+-    for (i=0; i<nargs; ++i) {
+-        len += strlen(args[i]) - 2;
++    len  = stmt->fmtlen;
++    for (i=0; i < stmt->nargs; ++i) {
++        len += strlen(args[i]);
++	switch (stmt->types[i]) {
++	case APR_DBD_TYPE_STRING: len += 2; break;	/* For the quotes */
++	default: break;/* Other types are all taken verbatim at the moment */
++	}
+     }
+-    i = 0;
+     p_in = stmt->fmt;
+     p_out = ret = apr_palloc(pool, len);
+-    /* FIXME silly bug - this'll catch %%s */
+-    while (q = strstr(p_in, "%s"), q != NULL) {
+-        len = q-p_in;
+-        strncpy(p_out, p_in, len);
+-        p_in += len;
+-        p_out += len;
+-        var = dbd_untaint(pool, stmt->taint[i], args[i]);
+-        len = strlen(var);
+-        strncpy(p_out, var, len);
+-        p_in += 2;
+-        p_out += len;
+-        ++i;
++    for (i = 0; i < stmt->nargs; i++) {
++        len = stmt->offsets[i];
++	switch (stmt->types[i]) {
++	case APR_DBD_TYPE_STRING:
++	    format = "%.*s'%s'";
++	    break;
++	default:
++	    format = "%.*s%s";
++	}
++	p_out += sprintf(p_out, format, len, p_in, args[i]);
++	p_in += (len + 1);
+     }
+     strcpy(p_out, p_in);
+     return ret;
+@@ -244,8 +237,7 @@
+                                apr_dbd_prepared_t *statement,
+                                int seek, const char **values)
+ {
+-    const char *query = dbd_statement(pool, statement,
+-                                      statement->nargs, values);
++    const char *query = dbd_statement(pool, statement, values);
+     return dbd_freetds_select(pool, sql, results, query, seek);
+ }
+ static int dbd_freetds_pvselect(apr_pool_t *pool, apr_dbd_t *sql,
+@@ -273,8 +265,7 @@
+                               int *nrows, apr_dbd_prepared_t *statement,
+                               const char **values)
+ {
+-    const char *query = dbd_statement(pool, statement,
+-                                      statement->nargs, values);
++    const char *query = dbd_statement(pool, statement, values);
+     return dbd_freetds_query(sql, nrows, query);
+ }
+ static int dbd_freetds_pvquery(apr_pool_t *pool, apr_dbd_t *sql, int *nrows,
+@@ -301,11 +292,13 @@
+     RETCODE rv = 0;
+     apr_dbd_row_t *row = *rowp;
+     int sequential = ((rownum >= 0) && res->random) ? 0 : 1;
++    apr_dbd_t *sql = (void *)dbgetuserdata(res->proc);
+ 
+     if (row == NULL) {
+         row = apr_palloc(pool, sizeof(apr_dbd_row_t));
+         *rowp = row;
+         row->res = res;
++	row->pool = pool; /* For subsequent calls to get_entry */
+     }
+     /*
+     else {
+@@ -321,18 +314,37 @@
+         rv = dbnextrow(res->proc);
+     }
+     else {
++	/* XXX dbgetrow() only works if DBBUFFER-option is set */
+         rv = (rownum >= 0) ? dbgetrow(res->proc, rownum) : NO_MORE_ROWS;
+     }
+     switch (rv) {
+     case SUCCEED: return 0;
+     case REG_ROW: return 0;
+     case NO_MORE_ROWS:
+-        apr_pool_cleanup_run(pool, res->proc, clear_result);
++	if (dbisopt(res->proc, DBBUFFER, NULL) || sequential) {
++	    sql->lasterror = apr_pstrcat(sql->pool,
++		"NO_MORE_ROWS (count: ", apr_itoa(sql->pool, DBCOUNT(res->proc)),
++		", first: ", apr_itoa(sql->pool, DBFIRSTROW(res->proc)),
++		", current: ", apr_itoa(sql->pool, DBCURROW(res->proc)),
++		", last: ", apr_itoa(sql->pool, DBLASTROW(res->proc)),
++		")", NULL);;
++	} else {
++	    sql->lasterror = "NO_MORE_ROWS (DBBUFFER option must be on "
++		"for dbgetrow() to work)";
++	}
++        apr_pool_cleanup_run(res->pool, res->proc, clear_result);
+         *rowp = NULL;
+         return -1;
+-    case FAIL: return 1;
+-    case BUF_FULL: return 2; /* FIXME */
+-    default: return 3;
++    case FAIL:
++	sql->lasterror = "FAIL";
++	return 1;
++    case BUF_FULL:
++	sql->lasterror = "BUF_FULL";
++	return 2; /* FIXME */
++    default:
++	sql->lasterror = apr_pstrcat(res->pool,
++	    "Unexpected error number ", apr_itoa(res->pool, rv), NULL);
++	return 3;
+     }
+ 
+     return 0;
+@@ -340,24 +352,27 @@
+ 
+ static const char *dbd_freetds_get_entry(const apr_dbd_row_t *row, int n)
+ {
+-    /* FIXME: support different data types */
+-    /* this fails - bind gets some vars but not others
+-    return (const char*)row->res->vars[n].data;
+-     */
+     DBPROCESS* proc = row->res->proc;
+-    BYTE *ptr = dbdata(proc, n+1);
++    BYTE *ptr = dbdata(proc, n+1); /* XXX No error checking! */
+     int t = dbcoltype(proc, n+1);
+-    int l = dbcollen(proc, n+1);
++    int l = dbdatlen(proc, n+1);
++    if (l == -1)
++      return NULL;
+     if (dbwillconvert(t, SYBCHAR)) {
+-      dbconvert(proc, t, ptr, l, SYBCHAR, (BYTE *)row->buf, -1);
+-      return (const char*)row->buf;
++      char *buf = apr_palloc(row->pool, l + 1);
++      dbconvert(proc, t, ptr, l, SYBCHAR, buf, -1);
++      return buf;
+     }
+     return (char*)ptr;
+ }
+ 
+ static const char *dbd_freetds_error(apr_dbd_t *sql, int n)
+ {
+-    /* XXX this doesn't seem to exist in the API ??? */
++    const char	*err = sql->lasterror;
++
++    sql->lasterror = NULL; /* Reset, so we stop appending */
++    if (err)
++	return err;
+     return apr_psprintf(sql->pool, "Error %d", sql->err);
+ }
+ 
+@@ -367,6 +382,7 @@
+         return sql->trans->errnum;
+     }
+     *nrows = 0;
++    sql->lasterror = NULL;
+     sql->err = freetds_exec(sql->proc, query, 0, nrows);
+ 
+     if (sql->err != SUCCEED) {
+@@ -384,114 +400,39 @@
+     return arg;
+ }
+ 
+-static apr_status_t freetds_regfree(void *rx)
+-{
+-    regfree((regex_t*)rx);
+-    return APR_SUCCESS;
+-}
+-static int recurse_args(apr_pool_t *pool, int n, const char *query,
+-                        apr_dbd_prepared_t *stmt, int offs)
+-{
+-
+-    /* we only support %s arguments for now */
+-    int ret;
+-    char arg[256];
+-    regmatch_t matches[3];
+-    if (regexec(&dbd_freetds_find_arg, query, 3, matches, 0) != 0) {
+-        /* No more args */
+-        stmt->nargs = n;
+-        stmt->taint = apr_palloc(pool, n*sizeof(regex_t*));
+-        stmt->sz = apr_palloc(pool, n*sizeof(int));
+-        ret = 0;
+-    }
+-    else {
+-        int i;
+-        int sz = 0;
+-        int len = matches[1].rm_eo - matches[1].rm_so - 2;
+-        if (len > 255) {
+-            return 9999;
+-        }
+-
+-        ret = recurse_args(pool, n+1, query+matches[0].rm_eo,
+-                           stmt, offs+matches[0].rm_eo);
+-
+-        memmove(stmt->fmt + offs + matches[1].rm_so,
+-                stmt->fmt + offs + matches[0].rm_eo-1,
+-                strlen(stmt->fmt+offs+matches[0].rm_eo)+2);
+-
+-        /* compile untaint to a regex if found */
+-        if (matches[1].rm_so == -1) {
+-            stmt->taint[n] = NULL;
+-        }
+-        else {
+-            strncpy(arg, query+matches[1].rm_so+1,
+-                    matches[1].rm_eo - matches[1].rm_so - 2);
+-            arg[matches[1].rm_eo - matches[1].rm_so - 2] = '\0';
+-            stmt->taint[n] = apr_palloc(pool, sizeof(regex_t));
+-            if (regcomp(stmt->taint[n], arg, REG_ICASE|REG_EXTENDED) != 0) {
+-                ++ret;
+-            }
+-            else {
+-                apr_pool_cleanup_register(pool, stmt->taint[n], freetds_regfree,
+-                                          apr_pool_cleanup_null);
+-            }
+-        }
+-
+-        /* record length if specified */
+-        for (i=matches[2].rm_so; i<matches[2].rm_eo; ++i) {
+-            sz = 10*sz + (query[i]-'\0');
+-        }
+-    }
+-    return ret;
+-}
+-
+ static int dbd_freetds_prepare(apr_pool_t *pool, apr_dbd_t *sql,
+                              const char *query, const char *label,
+                              int nargs, int nvals, apr_dbd_type_e *types,
+                              apr_dbd_prepared_t **statement)
+ {
++    int	i;
++    const char *p, *op;
+     apr_dbd_prepared_t *stmt;
+ 
+-    if (label == NULL) {
+-        label = apr_psprintf(pool, "%d", labelnum++);
++    if (!*statement &&
++	(*statement = apr_palloc(pool,
++	    sizeof(apr_dbd_prepared_t) + nargs*sizeof(int))) == NULL) {
++	return APR_EGENERAL;
+     }
+ 
+-    if (!*statement) {
+-        *statement = apr_palloc(pool, sizeof(apr_dbd_prepared_t));
+-    }
+     stmt = *statement;
++    stmt->nargs = nargs;
++    stmt->fmt = query;
++    stmt->fmtlen = strlen(query) - nargs + 1;
++    stmt->types = types;
++    stmt->label = label; /* XXX Not used anywhere at the moment */
+ 
+-#if 0
+-    /* count args */
+-    stmt->fmt = apr_pstrdup(pool, query);
+-    stmt->fmt = recurse_args(pool, 0, query, stmt, stmt->fmt);
+-
+-    /* overestimate by a byte or two to simplify */
+-    len = strlen("CREATE PROC apr.")
+-            + strlen(label)
+-            + stmt->nargs * strlen(" @arg1 varchar(len1),")
+-            + strlen(" AS begin ")
+-            + strlen(stmt->fmt)
+-            + strlen(" end "); /* extra byte for terminator */
+-
+-    pquery = apr_pcalloc(pool, len);
+-    sprintf(pquery, "CREATE PROC apr.%s", label);
+-    for (i=0; i<stmt->nargs; ++i) {
+-        sprintf(pquery+strlen(pquery), " @arg%d varchar(%d)", i, stmt->sz[i]);
+-        if (i < stmt->nargs-1) {
+-            pquery[strlen(pquery)] = ',';
+-        }
++    /*
++     * Run through the query-template looking for the special character,
++     * which the dbd_prepare inserted into it on our behalf
++     */
++    for (i = 0, op = query; i < nargs; i++) {
++	p = strchr(op, apr_dbd_freetds_driver.pformat[0]);
++	stmt->offsets[i] = p - op;
++	op = p + 1;
+     }
+-    strcat(pquery, " AS BEGIN ");
+-    strcat(pquery, stmt->fmt);
+-    strcat(pquery, " END");
+-
+-    return (freetds_exec(sql->proc, pquery, 0, &i) == SUCCEED) ? 0 : 1;
+-#else
+-    stmt->fmt = apr_pstrdup(pool, query);
+-    return recurse_args(pool, 0, query, stmt, 0);
+-#endif
+ 
++    return APR_SUCCESS;
+ }
+ 
+ static int dbd_freetds_start_transaction(apr_pool_t *pool, apr_dbd_t *handle,
+@@ -541,9 +482,9 @@
+     DBPROCESS *process;
+     LOGINREC *login;
+     static const char *delims = " \r\n\t;|,";
+-    char *ptr;
+-    char *key;
+-    char *value;
++    const char *ptr;
++    const char *key;
++    const char *value;
+     int vlen;
+     int klen;
+     char *buf;
+@@ -564,7 +505,7 @@
+         }
+         for (key = ptr-1; apr_isspace(*key); --key);
+         klen = 0;
+-        while (apr_isalpha(*key)) {
++        while (key >= params && apr_isalpha(*key)) {
+             --key;
+             ++klen;
+         }
+@@ -627,10 +568,11 @@
+     if (process == NULL) {
+         return NULL;
+     }
+-    sql = apr_palloc (pool, sizeof (apr_dbd_t));
++    sql = apr_pcalloc(pool, sizeof (apr_dbd_t));
+     sql->pool = pool;
+     sql->proc = process;
+     sql->params = params;
++    dbsetuserdata(process, (BYTE *)sql);
+     return sql;
+ }
+ 
+@@ -686,24 +628,73 @@
+ static apr_status_t freetds_term(void *dummy)
+ {
+     dbexit();
+-    regfree(&dbd_freetds_find_arg);
+     return APR_SUCCESS;
+ }
++
++static int freetds_msg_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate,
++                               int severity, char *msgtext, char *srvname,
++                               char *procname, int line)
++{
++    char	*value;
++    apr_dbd_t	*sql;
++
++    if (dbproc == NULL || (sql = (void *)dbgetuserdata(dbproc)) == NULL) {
++	/* Initial messages are not interesting */
++	return 0;
++    }
++
++    value = apr_psprintf(sql->pool, "%s: %s", srvname, msgtext);
++    if (procname && procname[0])
++	value = apr_pstrcat(sql->pool, value, " In procedure ",
++	    procname, NULL);
++    if (line)
++        value = apr_pstrcat(sql->pool, value,
++	    procname && procname[0] ? ", line " : " Line ",
++	    apr_itoa(sql->pool, line), NULL);
++
++    if (sql->lasterror)
++	sql->lasterror = apr_pstrcat(sql->pool, sql->lasterror, "\n", value, NULL);
++    else
++	sql->lasterror = value;
++
++    return 0;
++}
++
+ static int freetds_err_handler(DBPROCESS *dbproc, int severity, int dberr,
+                                int oserr, char *dberrstr, char *oserrstr)
+ {
++    char	*value;
++    apr_dbd_t	*sql;
++
++    if (dbproc == NULL || (sql = (void *)dbgetuserdata(dbproc)) == NULL) {
++	fprintf(stderr, "%s\n", dberrstr);
++	return INT_CANCEL;
++    }
++    /*
++     * Do not append the useless "general error", if details
++     * are already recorded (by the msg_handler). Just return.
++     * XXX: this skipping currently only works with Sybase's OpenClient
++     * XXX: because FreeTDS implementation uses bogus dberr values:
++     * XXX: https://sourceforge.net/tracker/?func=detail&aid=3555777&group_id=33106&atid=407806
++     */
++    if (dberr == SYBESMSG && sql->lasterror)
++	return INT_CANCEL;
++
++    value = apr_psprintf(sql->pool, "%d: %s", dberr, dberrstr);
++    if (oserrstr) {
++	value = apr_pstrcat(sql->pool, ". (", oserrstr, ")", NULL);
++    }
++    if (sql->lasterror)
++	sql->lasterror = apr_pstrcat(sql->pool, sql->lasterror, "\n", value, NULL);
++    else
++	sql->lasterror = value;
+     return INT_CANCEL; /* never exit */
+ }
+ static void dbd_freetds_init(apr_pool_t *pool)
+ {
+-    int rv = regcomp(&dbd_freetds_find_arg,
+-                     "%(\\{[^}]*\\})?([0-9]*)[A-Za-z]", REG_EXTENDED);
+-    if (rv != 0) {
+-        char errmsg[256];
+-        regerror(rv, &dbd_freetds_find_arg, errmsg, 256);
+-        fprintf(stderr, "regcomp failed: %s\n", errmsg);
+-    }
+-    dbinit();
++    if (dbinit() == FAIL)
++	fprintf(stderr, "dbinit() failed\n");
++    dbmsghandle(freetds_msg_handler);
+     dberrhandle(freetds_err_handler);
+     apr_pool_cleanup_register(pool, NULL, freetds_term, apr_pool_cleanup_null);
+ }
+@@ -765,7 +756,11 @@
+ #endif
+ 
+ APU_MODULE_DECLARE_DATA const apr_dbd_driver_t apr_dbd_freetds_driver = {
++#ifndef TI_MODULE_NAME
+     "freetds",
++#else
++    TI_MODULE_NAME,
++#endif
+     dbd_freetds_init,
+     dbd_freetds_native,
+     dbd_freetds_open,
+@@ -787,19 +782,14 @@
+     dbd_freetds_pvselect,
+     dbd_freetds_pquery,
+     dbd_freetds_pselect,
+-    /* this is only implemented to support httpd/2.2 standard usage,
+-     * as in the original DBD implementation.  Everything else is NOTIMPL.
+-     */
+-#ifdef COMPILE_STUBS
+     dbd_freetds_get_name,
+     dbd_freetds_transaction_mode_get,
+     dbd_freetds_transaction_mode_set,
+-    "",
++    "\1", /* Would not occur in a real query... */
+     dbd_freetds_pvbquery,
+     dbd_freetds_pvbselect,
+     dbd_freetds_pbquery,
+     dbd_freetds_pbselect,
+     dbd_freetds_datum_get
+-#endif
+ };
+ #endif
Index: devel/apr-util/pkg-descr
===================================================================
--- devel/apr-util/pkg-descr	(revision 0)
+++ devel/apr-util/pkg-descr	(working copy)
@@ -0,0 +1,9 @@
+The Apache Portable Runtime library provides a predictable and consistent
+interface to underlying platform-specific implementations, relieving software
+developers of the need to code special-case conditions to work around or take
+advantage of platform-specific deficiencies or features.
+
+This package contains the Apache Portable Runtime Utility library which
+provides additional interfaces on top of the Apache Portable Runtime library.
+
+WWW: http://apr.apache.org/
Index: devel/apr-util/pkg-plist
===================================================================
--- devel/apr-util/pkg-plist	(revision 0)
+++ devel/apr-util/pkg-plist	(working copy)
@@ -0,0 +1,81 @@
+bin/apu-1-config
+include/apr-1/apr_anylock.h
+include/apr-1/apr_base64.h
+include/apr-1/apr_buckets.h
+include/apr-1/apr_crypto.h
+include/apr-1/apr_date.h
+include/apr-1/apr_dbd.h
+include/apr-1/apr_dbm.h
+include/apr-1/apr_hooks.h
+include/apr-1/apr_ldap.h
+include/apr-1/apr_ldap_init.h
+include/apr-1/apr_ldap_option.h
+include/apr-1/apr_ldap_rebind.h
+include/apr-1/apr_ldap_url.h
+include/apr-1/apr_md4.h
+include/apr-1/apr_md5.h
+include/apr-1/apr_memcache.h
+include/apr-1/apr_optional.h
+include/apr-1/apr_optional_hooks.h
+include/apr-1/apr_queue.h
+include/apr-1/apr_reslist.h
+include/apr-1/apr_rmm.h
+include/apr-1/apr_sdbm.h
+include/apr-1/apr_sha1.h
+include/apr-1/apr_strmatch.h
+include/apr-1/apr_thread_pool.h
+include/apr-1/apr_uri.h
+include/apr-1/apr_uuid.h
+include/apr-1/apr_xlate.h
+include/apr-1/apr_xml.h
+include/apr-1/apu.h
+include/apr-1/apu_errno.h
+include/apr-1/apu_version.h
+include/apr-1/apu_want.h
+%%NSS%%lib/apr-util-1/apr_crypto_nss-1.so
+%%NSS%%lib/apr-util-1/apr_crypto_nss.so
+%%NSS%%lib/apr-util-1/apr_crypto_nss.la
+%%NSS%%lib/apr-util-1/apr_crypto_nss.a
+%%SSL%%lib/apr-util-1/apr_crypto_openssl-1.so
+%%SSL%%lib/apr-util-1/apr_crypto_openssl.a
+%%SSL%%lib/apr-util-1/apr_crypto_openssl.la
+%%SSL%%lib/apr-util-1/apr_crypto_openssl.so
+%%FREETDS%%lib/apr-util-1/apr_dbd_freetds-1.so
+%%FREETDS%%lib/apr-util-1/apr_dbd_freetds.a
+%%FREETDS%%lib/apr-util-1/apr_dbd_freetds.la
+%%FREETDS%%lib/apr-util-1/apr_dbd_freetds.so
+%%MYSQL%%lib/apr-util-1/apr_dbd_mysql-1.so
+%%MYSQL%%lib/apr-util-1/apr_dbd_mysql.a
+%%MYSQL%%lib/apr-util-1/apr_dbd_mysql.la
+%%MYSQL%%lib/apr-util-1/apr_dbd_mysql.so
+%%PGSQL%%lib/apr-util-1/apr_dbd_pgsql-1.so
+%%PGSQL%%lib/apr-util-1/apr_dbd_pgsql.a
+%%PGSQL%%lib/apr-util-1/apr_dbd_pgsql.la
+%%PGSQL%%lib/apr-util-1/apr_dbd_pgsql.so
+%%SQLITE3%%lib/apr-util-1/apr_dbd_sqlite3-1.so
+%%SQLITE3%%lib/apr-util-1/apr_dbd_sqlite3.a
+%%SQLITE3%%lib/apr-util-1/apr_dbd_sqlite3.la
+%%SQLITE3%%lib/apr-util-1/apr_dbd_sqlite3.so
+%%BDB%%lib/apr-util-1/apr_dbm_db-1.so
+%%BDB%%lib/apr-util-1/apr_dbm_db.a
+%%BDB%%lib/apr-util-1/apr_dbm_db.la
+%%BDB%%lib/apr-util-1/apr_dbm_db.so
+%%GDBM%%lib/apr-util-1/apr_dbm_gdbm-1.so
+%%GDBM%%lib/apr-util-1/apr_dbm_gdbm.a
+%%GDBM%%lib/apr-util-1/apr_dbm_gdbm.la
+%%GDBM%%lib/apr-util-1/apr_dbm_gdbm.so
+%%NDBM%%lib/apr-util-1/apr_dbm_ndbm-1.so
+%%NDBM%%lib/apr-util-1/apr_dbm_ndbm.a
+%%NDBM%%lib/apr-util-1/apr_dbm_ndbm.la
+%%NDBM%%lib/apr-util-1/apr_dbm_ndbm.so
+%%LDAP%%lib/apr-util-1/apr_ldap-1.so
+%%LDAP%%lib/apr-util-1/apr_ldap.a
+%%LDAP%%lib/apr-util-1/apr_ldap.la
+%%LDAP%%lib/apr-util-1/apr_ldap.so
+lib/aprutil.exp
+lib/libaprutil-1.a
+lib/libaprutil-1.la
+lib/libaprutil-1.so
+lib/libaprutil-1.so.%%SHLIB_MAJOR%%
+libdata/pkgconfig/apr-util-1.pc
+%%APU_EXTRAS%%@dirrm lib/apr-util-1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freebsd.org/pipermail/freebsd-apache/attachments/20130619/f164c9fc/attachment.sig>


More information about the freebsd-apache mailing list