Merge branch 'namedpipes'
diff --git a/AUTHORS b/AUTHORS
index 5b12129..657a425 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -9,6 +9,7 @@
 David Beck <dbeck@beckground.hu>
 Dirkjan Ochtman <dirkjan@ochtman.nl>
 Dong Fang <yp.fangdong@gmail.com>
+Drew Crawford <drew@sealedabstract.com>
 Dylan Socolobsky <dsocolobsky@gmail.com>
 Emeric Chevalier <emericchevalier.pro@gmail.com>
 Emil Renner Berthing <esmil@mailme.dk>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 31f358c..c754797 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -59,7 +59,7 @@
     list (APPEND all_tests ${NAME})
     add_executable (${NAME} tests/${NAME}.c)
     target_link_libraries (${NAME} nanomsg)
-    add_test (${NAME} ${NAME})
+    add_test (NAME ${NAME} COMMAND ${NAME})
 endmacro (add_libnanomsg_test)
 
 #  Transport tests.
diff --git a/Makefile.am b/Makefile.am
index 6a4979a..6c8f320 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -490,6 +490,7 @@
 ################################################################################
 
 EXTRA_DIST += \
+    ./rfc/sp-protocol-ids-01.txt \
     ./rfc/sp-tcp-mapping-01.txt \
     ./rfc/sp-udp-mapping-01.txt \
     ./rfc/sp-tls-mapping-01.txt \
diff --git a/rfc/sp-protocol-ids-01.txt b/rfc/sp-protocol-ids-01.txt
new file mode 100644
index 0000000..0a35d3d
--- /dev/null
+++ b/rfc/sp-protocol-ids-01.txt
@@ -0,0 +1,169 @@
+
+
+
+
+Internet Engineering Task Force                          M. Sustrik, Ed.
+Internet-Draft
+Intended status: Informational                              June 5, 2014
+Expires: December 7, 2014
+
+
+                        List of SP protocol IDs
+                           sp-protocol-ids-01
+
+Abstract
+
+   This document is intended to be a central repository of SP protocol
+   IDs.  The intention is to pass the task to IANA later on.
+
+Status of This Memo
+
+   This Internet-Draft is submitted in full conformance with the
+   provisions of BCP 78 and BCP 79.
+
+   Internet-Drafts are working documents of the Internet Engineering
+   Task Force (IETF).  Note that other groups may also distribute
+   working documents as Internet-Drafts.  The list of current Internet-
+   Drafts is at http://datatracker.ietf.org/drafts/current/.
+
+   Internet-Drafts are draft documents valid for a maximum of six months
+   and may be updated, replaced, or obsoleted by other documents at any
+   time.  It is inappropriate to use Internet-Drafts as reference
+   material or to cite them other than as "work in progress."
+
+   This Internet-Draft will expire on December 7, 2014.
+
+Copyright Notice
+
+   Copyright (c) 2014 IETF Trust and the persons identified as the
+   document authors.  All rights reserved.
+
+   This document is subject to BCP 78 and the IETF Trust's Legal
+   Provisions Relating to IETF Documents
+   (http://trustee.ietf.org/license-info) in effect on the date of
+   publication of this document.  Please review these documents
+   carefully, as they describe your rights and restrictions with respect
+   to this document.  Code Components extracted from this document must
+   include Simplified BSD License text as described in Section 4.e of
+   the Trust Legal Provisions and are provided without warranty as
+   described in the Simplified BSD License.
+
+
+
+
+
+
+Sustrik                 Expires December 7, 2014                [Page 1]
+
+Internet-Draft           List of SP protocol IDs               June 2014
+
+
+1.  Introduction
+
+   Different mappings for scalability protocols (see, for example
+   SPoverTCP [SPoverTCP]) define a protocol header which in turn
+   contains SP endpoint type ID.  The ID consists of protocol ID and end
+   the endpoint role:
+
+   +-----------------------+------------------------+
+   | Protocol ID (12 bits) | Endpoint role (4 bits) |
+   +-----------------------+------------------------+
+
+   Protocol IDs denote the SP protocol used (such as request/reply or
+   publish/subscribe), while endpoint role determines the role of the
+   endpoint within the topology (requester vs. replier, publisher vs.
+   subscriber et c.)  Both numbers are in network byte order.
+
+   Protocol IDs are global, while endpoint roles are specific to any
+   given protocol.  As such, protocol IDs are defined in this document,
+   while endpoint roles are defined in specific SP protocol RFCs.
+
+   Note that there's no versioning of SP protocols.  New versions of old
+   protocols should register with new protocol ID.
+
+2.  Protocol IDs
+
+   1 - pair (v1)
+
+   2 - publish/subscribe (v1)
+
+   3 - request/reply (v1)
+
+   4 - unassigned
+
+   5 - pipeline (v1)
+
+   6 - survey (v1)
+
+   7 - bus (v1)
+
+   8-3839 - unassigned
+
+   3840-4095 local and experimental
+
+3.  IANA Considerations
+
+   This memo describes numbers that should be eventually managed by
+   IANA.
+
+
+
+
+Sustrik                 Expires December 7, 2014                [Page 2]
+
+Internet-Draft           List of SP protocol IDs               June 2014
+
+
+4.  Security Considerations
+
+   There are no security considerations.
+
+5.  References
+
+   [SPoverTCP]
+              Sustrik, M., "TCP mapping for SPs", August 2013.
+
+Author's Address
+
+   Martin Sustrik (editor)
+
+   Email: sustrik@250bpm.com
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Sustrik                 Expires December 7, 2014                [Page 3]
+
diff --git a/rfc/sp-protocol-ids-01.xml b/rfc/sp-protocol-ids-01.xml
new file mode 100644
index 0000000..5148a77
--- /dev/null
+++ b/rfc/sp-protocol-ids-01.xml
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="US-ASCII"?>
+<!DOCTYPE rfc SYSTEM "rfc2629.dtd">
+
+<rfc category="info" docName="sp-protocol-ids-01">
+
+  <front>
+
+    <title abbrev="List of SP protocol IDs">
+    List of SP protocol IDs
+    </title>
+
+    <author fullname="Martin Sustrik" initials="M." role="editor"
+            surname="Sustrik">
+      <address>
+        <email>sustrik@250bpm.com</email>
+      </address>
+    </author>
+
+    <date month="June" year="2014" />
+
+    <area>Applications</area>
+    <workgroup>Internet Engineering Task Force</workgroup>
+
+    <keyword>SP</keyword>
+    <keyword>IANA</keyword>
+
+    <abstract>
+      <t>This document is intended to be a central repository of SP protocol
+          IDs. The intention is to pass the task to IANA later on.</t>
+    </abstract>
+
+  </front>
+
+  <middle>
+
+    <section anchor="Introduction" title="Introduction">
+      <t>Different mappings for scalability protocols (see, for example
+         <xref target='SPoverTCP'>SPoverTCP</xref>) define a protocol header
+         which in turn contains SP endpoint type ID. The ID consists of
+         protocol ID and end the endpoint role:</t>
+
+      <figure>
+        <artwork>
++-----------------------+------------------------+
+| Protocol ID (12 bits) | Endpoint role (4 bits) |
++-----------------------+------------------------+
+        </artwork>
+      </figure>
+
+      <t>Protocol IDs denote the SP protocol used (such as request/reply or
+         publish/subscribe), while endpoint role determines the role of the
+         endpoint within the topology (requester vs. replier, publisher vs.
+         subscriber et c.) Both numbers are in network byte order.</t>
+
+      <t>Protocol IDs are global, while endpoint roles are specific to any given
+         protocol. As such, protocol IDs are defined in this document, while
+         endpoint roles are defined in specific SP protocol RFCs.</t>
+
+      <t>Note that there's no versioning of SP protocols. New versions of old
+         protocols should register with new protocol ID.</t>
+
+    </section>
+
+    <section anchor="ProtocolIDs" title="Protocol IDs">
+
+      <t>1 - pair (v1)</t>
+      <t>2 - publish/subscribe (v1)</t>
+      <t>3 - request/reply (v1)</t>
+      <t>4 - unassigned</t>
+      <t>5 - pipeline (v1)</t>
+      <t>6 - survey (v1)</t>
+      <t>7 - bus (v1)</t>
+      <t>8-3839 - unassigned</t>
+      <t>3840-4095 local and experimental</t>
+
+    </section>
+
+    <section anchor="IANA" title="IANA Considerations">
+      <t>This memo describes numbers that should be eventually
+         managed by IANA.</t>
+    </section>
+
+    <section anchor="Security" title="Security Considerations">
+      <t>There are no security considerations.</t>
+
+    </section>
+
+  </middle>
+
+  <back>
+    <references>
+      <reference anchor='SPoverTCP'>
+         <front>
+           <title>TCP mapping for SPs</title>
+           <author initials='M.' surname='Sustrik' fullname='M. Sustrik'/>
+           <date month='August' year='2013'/>
+         </front>
+         <format type='TXT' target='sp-tcp-mapping-01.txt'/>
+       </reference>
+    </references>
+
+  </back>
+
+</rfc>
+
diff --git a/src/utils/msg.c b/src/utils/msg.c
index 58bfb3c..a25869e 100644
--- a/src/utils/msg.c
+++ b/src/utils/msg.c
@@ -66,3 +66,9 @@
     nn_chunkref_bulkcopy_cp (&dst->body, &src->body);
 }
 
+void nn_msg_replace_body(struct nn_msg *self, struct nn_chunkref newBody) 
+{
+    nn_chunkref_term(&self->body);
+    self->body = newBody;
+}
+
diff --git a/src/utils/msg.h b/src/utils/msg.h
index 4fad8ec..9e7e58f 100644
--- a/src/utils/msg.h
+++ b/src/utils/msg.h
@@ -62,5 +62,9 @@
 void nn_msg_bulkcopy_start (struct nn_msg *self, uint32_t copies);
 void nn_msg_bulkcopy_cp (struct nn_msg *dst, struct nn_msg *src);
 
+/** Replaces the message body with entirely new data.  This allows protocols
+    that substantially rewrite or preprocess the userland message to be written. */
+void nn_msg_replace_body(struct nn_msg *self, struct nn_chunkref newBody);
+
 #endif