Skip to content

Commit

Permalink
Merge pull request #235 from hintjens/master
Browse files Browse the repository at this point in the history
Updates for ZeroMQ/4.0.0
  • Loading branch information
hintjens committed Sep 21, 2013
2 parents e38abd0 + 08eeae2 commit d880d07
Show file tree
Hide file tree
Showing 9 changed files with 2,295 additions and 1,074 deletions.
9 changes: 6 additions & 3 deletions doc/zcert.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,20 @@ CZMQ_EXPORT char *
zcert_meta (zcert_t *self, char *name);

// Load certificate from file (constructor)
// The filename is treated as a printf format specifier.
CZMQ_EXPORT zcert_t *
zcert_load (char *filename);
zcert_load (char *filename, ...);

// Save full certificate (public + secret) to file for persistent storage
// This creates one public file and one secret file (filename + "_secret").
// The filename is treated as a printf format specifier.
CZMQ_EXPORT int
zcert_save (zcert_t *self, char *filename);
zcert_save (zcert_t *self, char *filename, ...);

// Save public certificate only to file for persistent storage
// The filename is treated as a printf format specifier.
CZMQ_EXPORT int
zcert_save_public (zcert_t *self, char *filename);
zcert_save_public (zcert_t *self, char *filename, ...);

// Apply certificate to socket, i.e. use for CURVE security on socket.
// If certificate was loaded from public file, the secret key will be
Expand Down
8 changes: 4 additions & 4 deletions doc/zcertstore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ SYNOPSIS
// absent, and created later, or modified at any time. The certificate store
// is automatically refreshed on any zcertstore_lookup() call. If the
// location is specified as NULL, creates a pure-memory store, which you
// can work with by inserting certificates at runtime.

// can work with by inserting certificates at runtime. The location is
// treated as a printf format.
CZMQ_EXPORT zcertstore_t *
zcertstore_new (char *location);
zcertstore_new (char *location, ...);

// Destroy a certificate store object in memory. Does not affect anything
// stored on disk.
Expand Down Expand Up @@ -77,7 +77,7 @@ EXAMPLE
zsys_dir_create (TESTDIR);

// Load certificate store from disk; it will be empty
zcertstore_t *certstore = zcertstore_new (TESTDIR);
zcertstore_t *certstore = zcertstore_new ("%s", TESTDIR);

// Create a single new certificate and save to disk
zcert_t *cert = zcert_new ();
Expand Down
16 changes: 12 additions & 4 deletions doc/zsys.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ CZMQ_EXPORT int
CZMQ_EXPORT bool
zsys_file_stable (const char *filename);

// Create a file path if it doesn't exit
// Create a file path if it doesn't exist. The file path is treated as a
// printf format.
CZMQ_EXPORT int
zsys_dir_create (const char *pathname);
zsys_dir_create (const char *pathname, ...);

// Remove a file path if empty
// Remove a file path if empty; the pathname is treated as printf format.
CZMQ_EXPORT int
zsys_dir_delete (const char *pathname);
zsys_dir_delete (const char *pathname, ...);

// Set private file creation mode; all files created from here will be
// readable/writable by the owner only.
Expand Down Expand Up @@ -114,6 +115,13 @@ EXAMPLE
time_t when = zsys_file_modified (".");
assert (when > 0);

rc = zsys_dir_create ("%s/%s", ".", ".testsys/subdir");
assert (rc == 0);
when = zsys_file_modified ("./.testsys/subdir");
assert (when > 0);
rc = zsys_dir_delete ("%s/%s", ".", ".testsys/subdir");
assert (rc == 0);

char *string = s_vprintf ("%s %02x", "Hello", 16);
assert (streq (string, "Hello 10"));
free (string);
Expand Down
2 changes: 1 addition & 1 deletion include/czmq.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

#define CZMQ_VERSION_MAJOR 2
#define CZMQ_VERSION_MINOR 0
#define CZMQ_VERSION_PATCH 0
#define CZMQ_VERSION_PATCH 1

#define CZMQ_MAKE_VERSION(major, minor, patch) \
((major) * 10000 + (minor) * 100 + (patch))
Expand Down
249 changes: 97 additions & 152 deletions include/zsockopt.h

Large diffs are not rendered by default.

174 changes: 110 additions & 64 deletions model/sockopts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,113 @@
use 'gsl sockopts'
-->
<options script = "sockopts">
<version major = "4">
<!-- New names for deprecated 3.x options -->
<option name = "ipv6" type = "int" mode = "rw" test = "SUB" />
<option name = "immediate" type = "int" mode = "w" test = "DEALER" />

<!-- Deprecated 3.x options -->
<option name = "router_raw" type = "int" mode = "w" test = "ROUTER">
<restrict type = "ROUTER" />
</option>
<option name = "ipv4only" type = "int" mode = "rw" test = "SUB" />
<option name = "delay_attach_on_connect"
type = "int" mode = "w" test = "PUB" />

<!-- Options that are new in 4.0 -->
<option name = "router_mandatory" type = "int" mode = "w" test = "ROUTER">
<restrict type = "ROUTER" />
</option>
<option name = "probe_router" type = "int" mode = "r" test = "DEALER">
<restrict type = "ROUTER" />
<restrict type = "DEALER" />
<restrict type = "REQ" />
</option>
<option name = "req_relaxed" type = "int" mode = "w" test = "REQ">
<restrict type = "REQ" />
</option>
<option name = "req_correlate" type = "int" mode = "w" test = "REQ">
<restrict type = "REQ" />
</option>
<option name = "conflate" type = "int" mode = "w" test = "PUSH">
<restrict type = "PUSH" />
<restrict type = "PULL" />
<restrict type = "PUB" />
<restrict type = "SUB" />
<restrict type = "DEALER" />
</option>

<!-- Security options -->
<option name = "plain_server" type = "int" mode = "rw" test = "PUB" />
<option name = "plain_username" type = "string" mode = "rw" test = "SUB" />
<option name = "plain_password" type = "string" mode = "rw" test = "SUB" />
<option name = "curve_server" type = "int" mode = "rw" test = "PUB"
ifdef = "HAVE_LIBSODIUM" />
<option name = "curve_publickey" type = "key" mode = "rw" test = "PUB"
ifdef = "HAVE_LIBSODIUM"
test_value = "Yne@$w-vo<fVvi]a<NY6T1ed:M$fCG*[IaLV{hID" />
<option name = "curve_secretkey" type = "key" mode = "rw" test = "PUB"
ifdef = "HAVE_LIBSODIUM"
test_value = "D:)Q[IlAW!ahhC2ac:9*A}h:p?([4%wOTJ%JR%cs" />
<option name = "curve_serverkey" type = "key" mode = "rw" test = "SUB"
ifdef = "HAVE_LIBSODIUM"
test_value = "rq:rM>}U?@Lns47E1%kR.o@n%FcmmsL/@{H8]yf7" />
<option name = "zap_domain" type = "string" mode = "rw" test = "SUB" />

<!-- Options that are the same in 3.x -->
<include name = "3-x options" />

<!-- Emulation of 2.x ZMQ_HWM option -->
<include name = "set_hwm" />
</version>

<version major = "3">
<!-- Options that are carried forward to 4.0 -->
<include name = "3-x options" />

<!-- Options that are deprecated in 4.0 -->
<option name = "router_raw" type = "int" mode = "w" test = "ROUTER">
<restrict type = "ROUTER" />
</option>
<option name = "ipv4only" type = "int" mode = "rw" test = "SUB" />
<option name = "delay_attach_on_connect"
type = "int" mode = "w" test = "PUB" />

<!-- Emulation of 2.x ZMQ_HWM option -->
<include name = "set_hwm" />
</version>

<!-- Legacy version 2 -->
<version major = "2">
<option name = "hwm" type = "uint64" mode = "rw" test = "SUB" />
<option name = "swap" type = "int64" mode = "rw" test = "SUB" />
<option name = "affinity" type = "uint64" mode = "rw" test = "SUB" />
<option name = "identity" type = "string" mode = "rw" test = "SUB" />
<option name = "rate" type = "int64" mode = "rw" test = "SUB" />
<option name = "recovery_ivl" type = "int64" mode = "rw" test = "SUB" />
<option name = "recovery_ivl_msec" type = "int64" mode = "rw" test = "SUB" />
<option name = "mcast_loop" type = "int64" mode = "rw" test = "SUB" />
<option name = "rcvtimeo" type = "int" mode = "rw" test = "SUB" minor = "2" />
<option name = "sndtimeo" type = "int" mode = "rw" test = "SUB" minor = "2" />
<option name = "sndbuf" type = "uint64" mode = "rw" test = "SUB" />
<option name = "rcvbuf" type = "uint64" mode = "rw" test = "SUB" />
<option name = "linger" type = "int" mode = "rw" test = "SUB" />
<option name = "reconnect_ivl" type = "int" mode = "rw" test = "SUB" />
<option name = "reconnect_ivl_max" type = "int" mode = "rw" test = "SUB" />
<option name = "backlog" type = "int" mode = "rw" test = "SUB" />
<option name = "subscribe" type = "string" mode = "w" test = "SUB">
<restrict type = "SUB" />
</option>
<option name = "unsubscribe" type = "string" mode = "w" test = "SUB">
<restrict type = "SUB" />
</option>
<option name = "type" type = "int" mode = "r" test = "SUB" />
<option name = "rcvmore" type = "int64" mode = "r" test = "SUB" />
<option name = "fd" type = "int" mode = "r" test = "SUB" />
<option name = "events" type = "uint32" mode = "r" test = "SUB" />
</version>

<macro name = "3-x options">
<option name = "type" type = "int" mode = "r" test = "SUB" />
<option name = "sndhwm" type = "int" mode = "rw" test = "PUB" />
<option name = "rcvhwm" type = "int" mode = "rw" test = "SUB" />
Expand Down Expand Up @@ -34,16 +140,6 @@
<option name = "multicast_hops" type = "int" mode = "rw" test = "SUB" />
<option name = "rcvtimeo" type = "int" mode = "rw" test = "SUB" />
<option name = "sndtimeo" type = "int" mode = "rw" test = "SUB" />
<option name = "ipv6" type = "int" mode = "rw" test = "SUB" />
<option name = "immediate" type = "int" mode = "w" test = "DEALER" />
<option name = "router_mandatory" type = "int" mode = "w" test = "ROUTER">
<restrict type = "ROUTER" />
</option>
<option name = "probe_router" type = "int" mode = "r" test = "DEALER">
<restrict type = "ROUTER" />
<restrict type = "DEALER" />
<restrict type = "REQ" />
</option>
<option name = "xpub_verbose" type = "int" mode = "w" test = "XPUB">
<restrict type = "XPUB" />
</option>
Expand All @@ -55,33 +151,13 @@
type = "int" mode = "rw" test = "SUB" />
<option name = "tcp_accept_filter" type = "string" mode = "rw" test = "SUB"
test_value = "127.0.0.1" />
<option name = "plain_server" type = "int" mode = "rw" test = "PUB" />
<option name = "plain_username" type = "string" mode = "rw" test = "SUB" />
<option name = "plain_password" type = "string" mode = "rw" test = "SUB" />
<option name = "curve_server" type = "int" mode = "rw" test = "PUB"
ifdef = "HAVE_LIBSODIUM" />
<option name = "curve_publickey" type = "key" mode = "rw" test = "PUB"
ifdef = "HAVE_LIBSODIUM"
test_value = "Yne@$w-vo<fVvi]a<NY6T1ed:M$fCG*[IaLV{hID" />
<option name = "curve_secretkey" type = "key" mode = "rw" test = "PUB"
ifdef = "HAVE_LIBSODIUM"
test_value = "D:)Q[IlAW!ahhC2ac:9*A}h:p?([4%wOTJ%JR%cs" />
<option name = "curve_serverkey" type = "key" mode = "rw" test = "SUB"
ifdef = "HAVE_LIBSODIUM"
test_value = "rq:rM>}U?@Lns47E1%kR.o@n%FcmmsL/@{H8]yf7" />
<option name = "zap_domain" type = "string" mode = "rw" test = "SUB" />
<option name = "rcvmore" type = "int" mode = "r" test = "SUB" />
<option name = "fd" type = "int" mode = "r" test = "SUB" />
<option name = "events" type = "int" mode = "r" test = "SUB" />
<option name = "last_endpoint" type = "string" mode = "r" test = "SUB" />

<!-- Deprecated options -->
<option name = "router_raw" type = "int" mode = "w" test = "ROUTER">
<restrict type = "ROUTER" />
</option>
<option name = "ipv4only" type = "int" mode = "rw" test = "SUB" />
<option name = "delay_attach_on_connect"
type = "int" mode = "w" test = "PUB" />
</macro>

<macro name = "set_hwm">
<header>
// Emulation of widely-used 2.x socket options
CZMQ_EXPORT void zsocket_set_hwm (void *zocket, int hwm);
Expand All @@ -106,35 +182,5 @@ zsocket_set_hwm (void *zocket, int hwm)
zocket = zsocket_new (ctx, ZMQ_SUB);
zsocket_set_hwm (zocket, 1);
</selftest>
</version>

<!-- Legacy version 2 -->
<version major = "2">
<option name = "hwm" type = "uint64" mode = "rw" test = "SUB" />
<option name = "swap" type = "int64" mode = "rw" test = "SUB" />
<option name = "affinity" type = "uint64" mode = "rw" test = "SUB" />
<option name = "identity" type = "string" mode = "rw" test = "SUB" />
<option name = "rate" type = "int64" mode = "rw" test = "SUB" />
<option name = "recovery_ivl" type = "int64" mode = "rw" test = "SUB" />
<option name = "recovery_ivl_msec" type = "int64" mode = "rw" test = "SUB" />
<option name = "mcast_loop" type = "int64" mode = "rw" test = "SUB" />
<option name = "rcvtimeo" type = "int" mode = "rw" test = "SUB" minor = "2" />
<option name = "sndtimeo" type = "int" mode = "rw" test = "SUB" minor = "2" />
<option name = "sndbuf" type = "uint64" mode = "rw" test = "SUB" />
<option name = "rcvbuf" type = "uint64" mode = "rw" test = "SUB" />
<option name = "linger" type = "int" mode = "rw" test = "SUB" />
<option name = "reconnect_ivl" type = "int" mode = "rw" test = "SUB" />
<option name = "reconnect_ivl_max" type = "int" mode = "rw" test = "SUB" />
<option name = "backlog" type = "int" mode = "rw" test = "SUB" />
<option name = "subscribe" type = "string" mode = "w" test = "SUB">
<restrict type = "SUB" />
</option>
<option name = "unsubscribe" type = "string" mode = "w" test = "SUB">
<restrict type = "SUB" />
</option>
<option name = "type" type = "int" mode = "r" test = "SUB" />
<option name = "rcvmore" type = "int64" mode = "r" test = "SUB" />
<option name = "fd" type = "int" mode = "r" test = "SUB" />
<option name = "events" type = "uint32" mode = "r" test = "SUB" />
</version>
</macro>
</options>
66 changes: 30 additions & 36 deletions scripts/sockopts.gsl
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
.output "../include/zsockopt.h"
.for version
. for option
. if type = "uint64" | type = "int64" | type = "uint32" | type = "int"
. option.ctype = "int"
. option.ctype_const = "int"
. elsif type = "string" | type = "key"
. option.ctype = "char *" # Enforce C strings
. option.ctype_const = "const char *"
. else
. echo "E: unknown type: $(type)"
. endif
. endfor
.endfor
.# This is a code generator built using the iMatix GSL code generation
.# language. See https://github.com/imatix/gsl for details. This script
.# is licensed under MIT/X11.
.#
.template 0
output "../include/zsockopt.h"
for version
# Expand any macros
for include
for options.macro where name = include.name
for . as child
copy child to version
endfor
endfor
endfor
# Preprocess options
for option
if type = "uint64" | type = "int64" | type = "uint32" | type = "int"
option.ctype = "int"
option.ctype_const = "int"
elsif type = "string" | type = "key"
option.ctype = "char *" # Enforce C strings
option.ctype_const = "const char *"
else
echo "E: unknown type: $(type)"
endif
endfor
endfor
.endtemplate
/* =========================================================================
zsockopt - get/set 0MQ socket options

Expand Down Expand Up @@ -91,27 +106,6 @@ $(string.trim(.):)
int zsockopt_test (bool verbose);
// @end

.for version
// Deprecated function names
#if (ZMQ_VERSION_MAJOR == $(major))
. for option
. if defined (.minor)
# if (ZMQ_VERSION_MINOR == $(minor))
. endif
. if mode = "rw" | mode = "r"
#define zsockopt_$(name) zsocket_$(name)
. endif
. if mode = "rw" | mode = "w"
#define zsockopt_set_$(name) zsocket_set_$(name)
. endif
. if defined (.minor)
# endif
. endif
. endfor
#endif

.endfor

#ifdef __cplusplus
}
#endif
Expand Down Expand Up @@ -187,7 +181,7 @@ zsocket_set_$(name) (void *zocket, $(ctype_const) $(name))
. else
. .close = ""
. endif
$(open)zsockopt_type (zocket) != ZMQ_$(TYPE)$(close)
$(open)zsocket_type (zocket) != ZMQ_$(TYPE)$(close)
. endfor
printf ("ZMQ_$(NAME) is not valid on %s sockets\\n", zsocket_type_str (zocket));
assert (false);
Expand Down
2 changes: 1 addition & 1 deletion src/zsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ zsocket_type_str (void *self)
"DEALER", "ROUTER", "PULL", "PUSH",
"XPUB", "XSUB", "STREAM"
};
int type = zsockopt_type (self);
int type = zsocket_type (self);
if (type < 0 || type > ZMQ_STREAM)
return "UNKNOWN";
else
Expand Down
Loading

0 comments on commit d880d07

Please sign in to comment.