示例#1
0
文件: zsock.c 项目: HunterChen/czmq
int
zsock_connect (zsock_t *self, const char *format, ...)
{
    assert (self);
    assert (zsock_is (self));

    //  Expand format to get full endpoint
    va_list argptr;
    va_start (argptr, format);
    char *endpoint = zsys_vprintf (format, argptr);
    va_end (argptr);
    int rc = zmq_connect (self->handle, endpoint);
    
#if (ZMQ_VERSION < ZMQ_MAKE_VERSION (4,0,0))
    int retries = 4;
    while (rc == -1 && zmq_errno () == ECONNREFUSED && retries) {
        //  This bruteforces a synchronization between connecting and
        //  binding threads on ZeroMQ v3.2 and earlier, where the bind
        //  MUST happen before the connect on inproc transports.
        zclock_sleep (250);
        rc = zmq_connect (self->handle, endpoint);
        retries--;
    }
#endif
    free (endpoint);
    return rc;
}
示例#2
0
文件: zcert.c 项目: bakirtasa/czmq
int
zcert_save (zcert_t *self, char *format, ...)
{
    assert (self);
    assert (format);
    va_list argptr;
    va_start (argptr, format);
    char *filename = zsys_vprintf (format, argptr);
    va_end (argptr);

    //  Save public certificate using specified filename
    zcert_save_public (self, filename);

    //  Now save secret certificate using filename with "_secret" suffix
    s_save_metadata_all (self);
    zconfig_comment (self->config, "   ZeroMQ CURVE **Secret** Certificate");
    zconfig_comment (self->config, "   DO NOT PROVIDE THIS FILE TO OTHER USERS nor change its permissions.");
    zconfig_put (self->config, "/curve/public-key", self->public_txt);
    zconfig_put (self->config, "/curve/secret-key", self->secret_txt);
    
    char filename_secret [256];
    snprintf (filename_secret, 256, "%s_secret", filename);
    zsys_file_mode_private ();
    int rc = zconfig_save (self->config, filename_secret);
    zsys_file_mode_default ();
    
    zstr_free (&filename);
    return rc;
}
示例#3
0
文件: zsys.c 项目: TangCheng/czmq
int
zsys_dir_create (const char *pathname, ...)
{
    va_list argptr;
    va_start (argptr, pathname);
    char *formatted = zsys_vprintf (pathname, argptr);
    va_end (argptr);

    //  Create parent directory levels if needed
    char *slash = strchr (formatted + 1, '/');
    while (true) {
        if (slash)
            *slash = 0;         //  Cut at slash
        mode_t mode = zsys_file_mode (formatted);
        if (mode == (mode_t)-1) {
            //  Does not exist, try to create it
#if (defined (__WINDOWS__))
            if (!CreateDirectoryA (formatted, NULL))
#else
            if (mkdir (formatted, 0775))
#endif
                return -1;      //  Failed
        }
        else
        if ((mode & S_IFDIR) == 0) {
            //  Not a directory, abort
        }
        if (!slash)             //  End if last segment
            break;
        *slash = '/';
        slash = strchr (slash + 1, '/');
    }
    free (formatted);
    return 0;
}
示例#4
0
文件: zsys.c 项目: TangCheng/czmq
static char *
s_vprintf (const char *format, ...)
{
    va_list argptr;
    va_start (argptr, format);
    char *string = zsys_vprintf (format, argptr);
    va_end (argptr);
    return (string);
}
示例#5
0
文件: zsys.c 项目: wysman/czmq
void
zsys_debug (const char *format, ...)
{
    va_list argptr;
    va_start (argptr, format);
    char *string = zsys_vprintf (format, argptr);
    va_end (argptr);
    s_log ('D', string);
    free (string);
}
示例#6
0
文件: zcert.c 项目: drmplanet/kdlenv
void
zcert_set_meta (zcert_t *self, const char *name, const char *format, ...)
{
    va_list argptr;
    va_start (argptr, format);
    char *value = zsys_vprintf (format, argptr);
    va_end (argptr);
    zhash_insert (self->metadata, name, value);
    zstr_free (&value);
}
示例#7
0
void
zre_log_msg_set_data (zre_log_msg_t *self, char *format, ...)
{
    //  Format data from provided arguments
    assert (self);
    va_list argptr;
    va_start (argptr, format);
    free (self->data);
    self->data = zsys_vprintf (format, argptr);
    va_end (argptr);
}
示例#8
0
文件: zre_msg.c 项目: karinies/coast
void
zre_msg_set_ipaddress (zre_msg_t *self, const char *format, ...)
{
    //  Format ipaddress from provided arguments
    assert (self);
    va_list argptr;
    va_start (argptr, format);
    free (self->ipaddress);
    self->ipaddress = zsys_vprintf (format, argptr);
    va_end (argptr);
}
示例#9
0
文件: zre_msg.c 项目: karinies/coast
void
zre_msg_set_group (zre_msg_t *self, const char *format, ...)
{
    //  Format group from provided arguments
    assert (self);
    va_list argptr;
    va_start (argptr, format);
    free (self->group);
    self->group = zsys_vprintf (format, argptr);
    va_end (argptr);
}
示例#10
0
文件: zconfig.c 项目: RUNDSP/czmq
void
zconfig_putf (zconfig_t *self, const char *path, const char *format, ...)
{
    assert (self);
    va_list argptr;
    va_start (argptr, format);
    char *value = zsys_vprintf (format, argptr);
    va_end (argptr);
    zconfig_put (self, path, value);
    zstr_free (&value);
}
示例#11
0
void
zgossip_msg_set_value (zgossip_msg_t *self, const char *format, ...)
{
    //  Format value from provided arguments
    assert (self);
    va_list argptr;
    va_start (argptr, format);
    free (self->value);
    self->value = zsys_vprintf (format, argptr);
    va_end (argptr);
}
示例#12
0
void
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);
    free (formatted);
}
示例#13
0
文件: zyre.c 项目: VanL/zyre
void
zyre_gossip_connect (zyre_t *self, const char *format, ...)
{
    assert (self);
    va_list argptr;
    va_start (argptr, format);
    char *string = zsys_vprintf (format, argptr);
    va_end (argptr);

    zstr_sendx (self->actor, "GOSSIP CONNECT", string, NULL);
    free (string);
}
示例#14
0
文件: zyre.c 项目: VanL/zyre
void
zyre_set_announce (zyre_t *self, const char *format, ...)
{
    assert (self);
    va_list argptr;
    va_start (argptr, format);
    char *string = zsys_vprintf (format, argptr);
    va_end (argptr);

    zstr_sendx (self->actor, "SET ANNOUNCE", string, NULL);
    free (string);
}
示例#15
0
文件: zyre.c 项目: VanL/zyre
void
zyre_set_header (zyre_t *self, const char *name, const char *format, ...)
{
    assert (self);
    va_list argptr;
    va_start (argptr, format);
    char *string = zsys_vprintf (format, argptr);
    va_end (argptr);

    zstr_sendx (self->actor, "SET HEADER", name, string, NULL);
    free (string);
}
示例#16
0
void
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);
    free (formatted);
}
示例#17
0
文件: zyre.c 项目: sphaero/zyre
int
zyre_set_endpoint (zyre_t *self, const char *format, ...)
{
    assert (self);
    va_list argptr;
    va_start (argptr, format);
    char *string = zsys_vprintf (format, argptr);
    va_end (argptr);

    zstr_sendx (self->actor, "SET ENDPOINT", string, NULL);
    free (string);
    return zsock_wait (self->actor) == 0? 0: -1;
}
示例#18
0
文件: zyre_log.c 项目: mjhowell/zyre
void
zyre_log_connect (zyre_log_t *self, const char *format, ...)
{
    assert (self);
    if (self->publisher) {
        va_list argptr;
        va_start (argptr, format);
        char *endpoint = zsys_vprintf (format, argptr);
        va_end (argptr);
        int rc = zsocket_connect (self->publisher, "%s", endpoint);
        assert (rc == 0);
        free (endpoint);
    }
}
示例#19
0
文件: zconfig.c 项目: Prarrot/czmq
void
zconfig_set_value (zconfig_t *self, char *format, ...)
{
    assert (self);
    free (self->value);
    if (format) {
        va_list argptr;
        va_start (argptr, format);
        self->value = zsys_vprintf (format, argptr);
        va_end (argptr);
    }
    else
        self->value = NULL;
}
示例#20
0
文件: zstr.c 项目: DeanHH/czmq
int
zstr_sendf (void *dest, const char *format, ...)
{
    assert (dest);
    assert (format);

    va_list argptr;
    va_start (argptr, format);
    char *string = zsys_vprintf (format, argptr);
    va_end (argptr);

    int rc = s_send_string (dest, false, string);
    free (string);
    return rc;
}
示例#21
0
文件: zconfig.c 项目: RUNDSP/czmq
zconfig_t *
zconfig_loadf (const char *format, ...)
{
    va_list argptr;
    va_start (argptr, format);
    char *filename = zsys_vprintf (format, argptr);
    va_end (argptr);
    if (filename) {
        zconfig_t *config = zconfig_load (filename);
        free (filename);
        return config;
    }
    else
        return NULL;
}
示例#22
0
int
zstr_sendm (void *zocket, const char *format, ...)
{
    assert (zocket);
    assert (format);
    
    va_list argptr;
    va_start (argptr, format);
    char *string = zsys_vprintf (format, argptr);
    va_end (argptr);
    
    int rc = s_send_string (zocket, true, string);
    free (string);
    return rc;
}
示例#23
0
文件: zconfig.c 项目: RUNDSP/czmq
int
zconfig_savef (zconfig_t *self, const char *format, ...)
{
    assert (self);
    va_list argptr;
    va_start (argptr, format);
    char *filename = zsys_vprintf (format, argptr);
    va_end (argptr);
    if (filename) {
        int rc = zconfig_save (self, filename);
        zstr_free (&filename);
        return rc;
    }
    else
        return -1;
}
示例#24
0
文件: zsys.c 项目: TangCheng/czmq
int
zsys_dir_delete (const char *pathname, ...)
{
    va_list argptr;
    va_start (argptr, pathname);
    char *formatted = zsys_vprintf (pathname, argptr);
    va_end (argptr);

#if (defined (__WINDOWS__))
    int rc = RemoveDirectoryA (formatted)? 0: -1;
#else
    int rc = rmdir (formatted);
#endif
    free (formatted);
    return rc;
}
示例#25
0
文件: zcert.c 项目: bakirtasa/czmq
zcert_t *
zcert_load (char *format, ...)
{
#if (ZMQ_VERSION_MAJOR == 4)
    assert (format);
    va_list argptr;
    va_start (argptr, format);
    char *filename = zsys_vprintf (format, argptr);
    va_end (argptr);

    //  Try first to load secret certificate, which has both keys
    //  Then fallback to loading public certificate
    char filename_secret [256];
    snprintf (filename_secret, 256, "%s_secret", filename);
    zconfig_t *root = zconfig_load (filename_secret);
    if (!root)
        root = zconfig_load (filename);
        
    zcert_t *self = NULL;
    if (root) {
        char *public_text = zconfig_resolve (root, "/curve/public-key", NULL);
        char *secret_text = zconfig_resolve (root, "/curve/secret-key", NULL);
        if (public_text && strlen (public_text) == 40) {
            byte public_key [32] = { 0 };
            byte secret_key [32] = { 0 };
            zmq_z85_decode (public_key, public_text);
            if (secret_text && strlen (secret_text) == 40)
                zmq_z85_decode (secret_key, secret_text);

            //  Load metadata into certificate
            self = zcert_new_from (public_key, secret_key);
            zconfig_t *metadata = zconfig_locate (root, "/metadata");
            zconfig_t *item = metadata? zconfig_child (metadata): NULL;
            while (item) {
                zcert_set_meta (self, zconfig_name (item), zconfig_value (item));
                item = zconfig_next (item);
            }
        }
    }
    zconfig_destroy (&root);
    zstr_free (&filename);
    return self;
#else   
    return NULL;
#endif
}
示例#26
0
文件: zcertstore.c 项目: Prarrot/czmq
zcertstore_t *
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);
        s_load_certs_from_disk (self);
    }
    return self;
}
示例#27
0
文件: zhash.c 项目: Lucky7Studio/czmq
void
zhash_comment (zhash_t *self, const char *format, ...)
{
    if (format) {
        if (!self->comments) {
            self->comments = zlist_new ();
            zlist_autofree (self->comments);
        }
        va_list argptr;
        va_start (argptr, format);
        char *string = zsys_vprintf (format, argptr);
        va_end (argptr);
        zlist_append (self->comments, string);
        free (string);
    }
    else
        zlist_destroy (&self->comments);
}
示例#28
0
文件: zyre.c 项目: VanL/zyre
int
zyre_shouts (zyre_t *self, const char *group, const char *format, ...)
{
    assert (self);
    assert (group);
    assert (format);

    va_list argptr;
    va_start (argptr, format);
    char *string = zsys_vprintf (format, argptr);
    va_end (argptr);

    zstr_sendm (self->actor, "SHOUT");
    zstr_sendm (self->actor, group);
    zstr_send  (self->actor, string);
    free (string);
    return 0;
}
示例#29
0
文件: zre_msg.c 项目: karinies/coast
void
zre_msg_groups_append (zre_msg_t *self, const char *format, ...)
{
    //  Format into newly allocated string
    assert (self);
    va_list argptr;
    va_start (argptr, format);
    char *string = zsys_vprintf (format, argptr);
    va_end (argptr);

    //  Attach string to list
    if (!self->groups) {
        self->groups = zlist_new ();
        zlist_autofree (self->groups);
    }
    zlist_append (self->groups, string);
    free (string);
}
示例#30
0
文件: zre_msg.c 项目: karinies/coast
void
zre_msg_headers_insert (zre_msg_t *self, const char *key, const char *format, ...)
{
    //  Format into newly allocated string
    assert (self);
    va_list argptr;
    va_start (argptr, format);
    char *string = zsys_vprintf (format, argptr);
    va_end (argptr);

    //  Store string in hash table
    if (!self->headers) {
        self->headers = zhash_new ();
        zhash_autofree (self->headers);
    }
    zhash_update (self->headers, key, string);
    free (string);
}