Exemple #1
0
static void _log_open_tag(xmpp_conn_t *conn, char **attrs)
{
    char buf[4096];
    size_t pos;
    int len;
    int i;
    char *attr;

    if (!attrs) return;

    pos = 0;
    len = xmpp_snprintf(buf, 4096, "<stream:stream");
    if (len < 0) return;

    pos += len;
    for (i = 0; attrs[i]; i += 2) {
        attr = parser_attr_name(conn->ctx, attrs[i]);
        len = xmpp_snprintf(&buf[pos], 4096 - pos, " %s='%s'",
                            attr, attrs[i+1]);
        xmpp_free(conn->ctx, attr);
        if (len < 0) return;
        pos += len;
    }

    len = xmpp_snprintf(&buf[pos], 4096 - pos, ">");
    if (len < 0) return;

    xmpp_debug(conn->ctx, "xmpp", "RECV: %s", buf);
}
Exemple #2
0
static void _conn_attributes_new(xmpp_conn_t *conn, char **attrs,
                                 char ***attributes, size_t *attributes_len)
{
    char **array = NULL;
    size_t nr = 0;
    size_t i;

    if (attrs) {
        for (; attrs[nr]; ++nr);
        array = xmpp_alloc(conn->ctx, sizeof(*array) * nr);
        for (i = 0; array && i < nr; ++i) {
            array[i] = (i & 1) == 0 ? parser_attr_name(conn->ctx, attrs[i])
                                    : xmpp_strdup(conn->ctx, attrs[i]);
            if (array[i] == NULL) break;
        }
        if (!array || i < nr) {
            xmpp_error(conn->ctx, "xmpp", "Memory allocation error.");
            _conn_attributes_destroy(conn, array, i);
            array = NULL;
            nr = 0;
        }
    }
    *attributes = array;
    *attributes_len = nr;
}