Permalink
Browse files

Fixed #370 in zmsg, zcert, zcertstore, zauth

  • Loading branch information...
1 parent 3c4af39 commit 06daa0af374f522726883e358c69281a7dcfc899 @hintjens hintjens committed Jan 23, 2014
Showing with 89 additions and 87 deletions.
  1. +8 −10 include/zauth.h
  2. +3 −6 include/zcert.h
  3. +2 −3 include/zcertstore.h
  4. +12 −2 include/zmsg.h
  5. +11 −22 src/zauth.c
  6. +6 −25 src/zcert.c
  7. +4 −8 src/zcertstore.c
  8. +4 −4 src/zmonitor.c
  9. +39 −7 src/zmsg.c
View
@@ -61,21 +61,19 @@ CZMQ_EXPORT void
zauth_deny (zauth_t *self, char *address);
// Configure PLAIN authentication for a given domain. PLAIN authentication
-// uses a plain-text password file. The filename is treated as a printf
-// format. To cover all domains, use "*". You can modify the password file
-// at any time; it is reloaded automatically.
+// uses a plain-text password file. To cover all domains, use "*". You can
+// modify the password file at any time; it is reloaded automatically.
CZMQ_EXPORT void
- zauth_configure_plain (zauth_t *self, char *domain, char *filename, ...);
+ zauth_configure_plain (zauth_t *self, char *domain, char *filename);
// Configure CURVE authentication for a given domain. CURVE authentication
// uses a directory that holds all public client certificates, i.e. their
-// public keys. The certificates must be in zcert_save () format. The
-// location is treated as a printf format. To cover all domains, use "*".
-// You can add and remove certificates in that directory at any time.
-// To allow all client keys without checking, specify CURVE_ALLOW_ANY
-// for the location.
+// public keys. The certificates must be in zcert_save () format. To cover
+// all domains, use "*". You can add and remove certificates in that
+// directory at any time. To allow all client keys without checking, specify
+// CURVE_ALLOW_ANY for the location.
CZMQ_EXPORT void
- zauth_configure_curve (zauth_t *self, char *domain, char *location, ...);
+ zauth_configure_curve (zauth_t *self, char *domain, char *location);
// Enable verbose tracing of commands and activity
CZMQ_EXPORT void
View
@@ -78,20 +78,17 @@ CZMQ_EXPORT zlist_t *
zcert_meta_keys (zcert_t *self);
// 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
View
@@ -40,10 +40,9 @@ typedef struct _zcertstore_t zcertstore_t;
// 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. The location is
-// treated as a printf format.
+// can work with by inserting certificates at runtime.
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.
View
@@ -105,12 +105,22 @@ CZMQ_EXPORT int
// Push string as new frame to front of message.
// Returns 0 on success, -1 on error.
CZMQ_EXPORT int
- zmsg_pushstr (zmsg_t *self, const char *format, ...);
+ zmsg_pushstr (zmsg_t *self, const char *string);
// Push string as new frame to end of message.
// Returns 0 on success, -1 on error.
CZMQ_EXPORT int
- zmsg_addstr (zmsg_t *self, const char *format, ...);
+ zmsg_addstr (zmsg_t *self, const char *string);
+
+// Push formatted string as new frame to front of message.
+// Returns 0 on success, -1 on error.
+CZMQ_EXPORT int
+ zmsg_pushstrf (zmsg_t *self, const char *format, ...);
+
+// Push formatted string as new frame to end of message.
+// Returns 0 on success, -1 on error.
+CZMQ_EXPORT int
+ zmsg_addstrf (zmsg_t *self, const char *format, ...);
// Pop frame off front of message, return as fresh string. If there were
// no more frames in the message, returns NULL.
View
@@ -135,21 +135,16 @@ zauth_deny (zauth_t *self, char *address)
// --------------------------------------------------------------------------
// Configure PLAIN authentication for a given domain. PLAIN authentication
-// uses a plain-text password file. The filename is treated as a printf
-// format. To cover all domains, use "*". You can modify the password file
-// at any time; it is reloaded automatically.
+// uses a plain-text password file. To cover all domains, use "*". You can
+// modify the password file at any time; it is reloaded automatically.
void
-zauth_configure_plain (zauth_t *self, char *domain, char *filename, ...)
+zauth_configure_plain (zauth_t *self, char *domain, char *filename)
{
assert (self);
assert (domain);
- va_list argptr;
- va_start (argptr, filename);
- char *formatted = zsys_vprintf (filename, argptr);
- va_end (argptr);
- zstr_sendx (self->pipe, "PLAIN", domain, formatted, NULL);
- zstr_free (&formatted);
+ assert (filename);
+ zstr_sendx (self->pipe, "PLAIN", domain, filename, NULL);
// Wait for completion
free (zstr_recv (self->pipe));
}
@@ -158,24 +153,18 @@ zauth_configure_plain (zauth_t *self, char *domain, char *filename, ...)
// --------------------------------------------------------------------------
// Configure CURVE authentication for a given domain. CURVE authentication
// uses a directory that holds all public client certificates, i.e. their
-// public keys. The certificates must be in zcert_save () format. The
-// location is treated as a printf format. To cover all domains, use "*".
-// You can add and remove certificates in that directory at any time.
-// To allow all client keys without checking, specify CURVE_ALLOW_ANY for
-// the location.
+// public keys. The certificates must be in zcert_save () format. To cover
+// all domains, use "*". You can add and remove certificates in that
+// directory at any time. To allow all client keys without checking, specify
+// CURVE_ALLOW_ANY for the location.
void
-zauth_configure_curve (zauth_t *self, char *domain, char *location, ...)
+zauth_configure_curve (zauth_t *self, char *domain, char *location)
{
assert (self);
assert (domain);
assert (location);
- va_list argptr;
- va_start (argptr, location);
- char *formatted = zsys_vprintf (location, argptr);
- va_end (argptr);
- zstr_sendx (self->pipe, "CURVE", domain, formatted, NULL);
- zstr_free (&formatted);
+ zstr_sendx (self->pipe, "CURVE", domain, location, NULL);
// Wait for completion
free (zstr_recv (self->pipe));
}
View
@@ -216,17 +216,12 @@ zcert_meta_keys (zcert_t *self)
// --------------------------------------------------------------------------
// Load certificate from file (constructor)
-// The filename is treated as a printf format specifier.
zcert_t *
-zcert_load (char *format, ...)
+zcert_load (char *filename)
{
#if (ZMQ_VERSION_MAJOR == 4)
- assert (format);
- va_list argptr;
- va_start (argptr, format);
- char *filename = zsys_vprintf (format, argptr);
- va_end (argptr);
+ assert (filename);
// Try first to load secret certificate, which has both keys
// Then fallback to loading public certificate
@@ -258,7 +253,6 @@ zcert_load (char *format, ...)
}
}
zconfig_destroy (&root);
- zstr_free (&filename);
return self;
#else
return NULL;
@@ -269,7 +263,6 @@ zcert_load (char *format, ...)
// --------------------------------------------------------------------------
// 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.
static int
s_save_metadata (const char *name, void *value, void *args)
@@ -295,14 +288,10 @@ s_save_metadata_all (zcert_t *self)
int
-zcert_save (zcert_t *self, char *format, ...)
+zcert_save (zcert_t *self, char *filename)
{
assert (self);
- assert (format);
- va_list argptr;
- va_start (argptr, format);
- char *filename = zsys_vprintf (format, argptr);
- va_end (argptr);
+ assert (filename);
// Save public certificate using specified filename
zcert_save_public (self, filename);
@@ -321,25 +310,18 @@ zcert_save (zcert_t *self, char *format, ...)
zsys_file_mode_private ();
int rc = zconfig_save (self->config, filename_secret);
zsys_file_mode_default ();
-
- zstr_free (&filename);
return rc;
}
// --------------------------------------------------------------------------
// Save public certificate only to file for persistent storage.
-// The filename is treated as a printf format specifier.
int
-zcert_save_public (zcert_t *self, char *format, ...)
+zcert_save_public (zcert_t *self, char *filename)
{
assert (self);
- assert (format);
- va_list argptr;
- va_start (argptr, format);
- char *filename = zsys_vprintf (format, argptr);
- va_end (argptr);
+ assert (filename);
s_save_metadata_all (self);
zconfig_set_comment (self->config,
@@ -353,7 +335,6 @@ zcert_save_public (zcert_t *self, char *format, ...)
zconfig_put (self->config, "/curve/public-key", self->public_txt);
int rc = zconfig_save (self->config, filename);
- zstr_free (&filename);
return rc;
}
View
@@ -71,24 +71,20 @@ struct _zcertstore_t {
// 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. The location is
-// treated as a printf format.
+// can work with by inserting certificates at runtime.
static void s_load_certs_from_disk (zcertstore_t *self);
zcertstore_t *
-zcertstore_new (char *location, ...)
+zcertstore_new (char *location)
{
zcertstore_t *self = (zcertstore_t *) zmalloc (sizeof (zcertstore_t));
assert (self);
self->cert_list = zlist_new ();
self->cert_hash = zhash_new ();
if (location) {
- va_list argptr;
- va_start (argptr, location);
- self->location = zsys_vprintf (location, argptr);
- va_end (argptr);
+ self->location = strdup (location);
s_load_certs_from_disk (self);
}
return self;
@@ -244,7 +240,7 @@ zcertstore_test (bool verbose)
zsys_dir_create (TESTDIR);
// Load certificate store from disk; it will be empty
- zcertstore_t *certstore = zcertstore_new ("%s", TESTDIR);
+ zcertstore_t *certstore = zcertstore_new (TESTDIR);
# if defined (HAVE_LIBSODIUM)
// Create a single new certificate and save to disk
View
@@ -388,10 +388,10 @@ s_socket_event (agent_t *self)
printf ("I: zmonitor: %s - %s\n", description, address);
zmsg_t *msg = zmsg_new();
- zmsg_addstr (msg, "%d", (int) event.event);
- zmsg_addstr (msg, "%d", (int) event.value);
- zmsg_addstr (msg, "%s", address);
- zmsg_addstr (msg, "%s", description);
+ zmsg_addstrf (msg, "%d", (int) event.event);
+ zmsg_addstrf (msg, "%d", (int) event.value);
+ zmsg_addstrf (msg, "%s", address);
+ zmsg_addstrf (msg, "%s", description);
zmsg_send (&msg, self->pipe);
}
View
@@ -294,11 +294,41 @@ zmsg_addmem (zmsg_t *self, const void *src, size_t size)
// --------------------------------------------------------------------------
-// Push string as new frame to front of message, returns 0 if OK, -1 on
-// error. The string is formatted using sprintf.
+// Push string as new frame to front of message.
+// Returns 0 on success, -1 on error.
+
+int
+zmsg_pushstr (zmsg_t *self, const char *string)
+{
+ assert (self);
+ assert (string);
+ self->content_size += strlen (string);
+ zlist_push (self->frames, zframe_new (string, strlen (string)));
+ return 0;
+}
+
+
+// --------------------------------------------------------------------------
+// Push string as new frame to end of message.
+// Returns 0 on success, -1 on error.
int
-zmsg_pushstr (zmsg_t *self, const char *format, ...)
+zmsg_addstr (zmsg_t *self, const char *string)
+{
+ assert (self);
+ assert (string);
+ self->content_size += strlen (string);
+ zlist_append (self->frames, zframe_new (string, strlen (string)));
+ return 0;
+}
+
+
+// --------------------------------------------------------------------------
+// Push formatted string as new frame to front of message.
+// Returns 0 on success, -1 on error.
+
+int
+zmsg_pushstrf (zmsg_t *self, const char *format, ...)
{
assert (self);
assert (format);
@@ -307,7 +337,7 @@ zmsg_pushstr (zmsg_t *self, const char *format, ...)
va_start (argptr, format);
char *string = zsys_vprintf (format, argptr);
va_end (argptr);
-
+
self->content_size += strlen (string);
zlist_push (self->frames, zframe_new (string, strlen (string)));
free (string);
@@ -316,10 +346,11 @@ zmsg_pushstr (zmsg_t *self, const char *format, ...)
// --------------------------------------------------------------------------
-// Push string as new frame to end of message
+// Push formatted string as new frame to end of message.
+// Returns 0 on success, -1 on error.
int
-zmsg_addstr (zmsg_t *self, const char *format, ...)
+zmsg_addstrf (zmsg_t *self, const char *format, ...)
{
assert (self);
assert (format);
@@ -328,13 +359,14 @@ zmsg_addstr (zmsg_t *self, const char *format, ...)
va_start (argptr, format);
char *string = zsys_vprintf (format, argptr);
va_end (argptr);
-
+
self->content_size += strlen (string);
zlist_append (self->frames, zframe_new (string, strlen (string)));
free (string);
return 0;
}
+
// --------------------------------------------------------------------------
// Pop frame off front of message, return as fresh string. If there were
// no more frames in the message, returns NULL.

0 comments on commit 06daa0a

Please sign in to comment.