apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject svn commit: r1587045 - in /apr/apr/trunk: CHANGES include/apr_network_io.h network_io/unix/sockaddr.c
Date Sun, 13 Apr 2014 17:10:56 GMT
Author: trawick
Date: Sun Apr 13 17:10:56 2014
New Revision: 1587045

URL: http://svn.apache.org/r1587045
Log:
Add apr_sockaddr_info_copy(), for making a deep copy of an
apr_sockaddr_t into a specified pool.

Submitted by: Yann Ylavic <ylavic.dev gmail.com>
Reviewed by: trawick

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/include/apr_network_io.h
    apr/apr/trunk/network_io/unix/sockaddr.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=1587045&r1=1587044&r2=1587045&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Sun Apr 13 17:10:56 2014
@@ -1,6 +1,10 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 2.0.0
 
+  *) Add apr_sockaddr_info_copy(), for making a deep copy of an
+     apr_sockaddr_t into a specified pool.  [Yann Ylavic
+     <ylavic.dev gmail.com>]
+
   *) When using shmget-based shared memory, the ID used for ftok is
      now an APR hash of the filename instead of the constant '1'.
      We do this to help avoid collisions. PR 53996 [Jim Jagielski]

Modified: apr/apr/trunk/include/apr_network_io.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_network_io.h?rev=1587045&r1=1587044&r2=1587045&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_network_io.h (original)
+++ apr/apr/trunk/include/apr_network_io.h Sun Apr 13 17:10:56 2014
@@ -428,6 +428,15 @@ APR_DECLARE(apr_status_t) apr_sockaddr_i
                                           apr_int32_t flags,
                                           apr_pool_t *p);
 
+/**
+ * Copy apr_sockaddr_t src to dst on pool p.
+ * @param dst The destination apr_sockaddr_t.
+ * @param src The source apr_sockaddr_t.
+ * @param p The pool for the apr_sockaddr_t and associated storage.
+ */
+APR_DECLARE(apr_status_t) apr_sockaddr_info_copy(apr_sockaddr_t **dst,
+                                                 const apr_sockaddr_t *src,
+                                                 apr_pool_t *p);
 
 /**
  * Look up the host name from an apr_sockaddr_t.

Modified: apr/apr/trunk/network_io/unix/sockaddr.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/network_io/unix/sockaddr.c?rev=1587045&r1=1587044&r2=1587045&view=diff
==============================================================================
--- apr/apr/trunk/network_io/unix/sockaddr.c (original)
+++ apr/apr/trunk/network_io/unix/sockaddr.c Sun Apr 13 17:10:56 2014
@@ -660,6 +660,42 @@ APR_DECLARE(apr_status_t) apr_sockaddr_i
     return find_addresses(sa, hostname, family, port, flags, p);
 }
 
+APR_DECLARE(apr_status_t) apr_sockaddr_info_copy(apr_sockaddr_t **dst,
+                                                 const apr_sockaddr_t *src,
+                                                 apr_pool_t *p)
+{
+    apr_sockaddr_t *d;
+    const apr_sockaddr_t *s;
+
+    for (*dst = d = NULL, s = src; s; s = s->next) {
+        if (!d) {
+            *dst = d = apr_pmemdup(p, s, sizeof *s);
+        }
+        else {
+            d = d->next = apr_pmemdup(p, s, sizeof *s);
+        }
+        if (s->hostname) {
+            if (s == src || s->hostname != src->hostname) {
+                d->hostname = apr_pstrdup(p, s->hostname);
+            }
+            else {
+                d->hostname = (*dst)->hostname;
+            }
+        }
+        if (s->servname) {
+            if (s == src || s->servname != src->servname) {
+                d->servname = apr_pstrdup(p, s->servname);
+            }
+            else {
+                d->servname = (*dst)->servname;
+            }
+        }
+        d->pool = p;
+        apr_sockaddr_vars_set(d, s->family, s->port);
+    }
+    return APR_SUCCESS;
+}
+
 APR_DECLARE(apr_status_t) apr_getnameinfo(char **hostname,
                                           apr_sockaddr_t *sockaddr,
                                           apr_int32_t flags)



Mime
View raw message