Unify coding style
@sjaeckel integrated clang-format with formal coding style. Run his script and commit changes. There are pros and cons of this commit. Mixed coding style is a "broken window". A good single style simplifies reading and writing code. On the other hand, this is a big change which will lead to conflicts.
This commit is contained in:
@@ -19,23 +19,23 @@
|
||||
|
||||
#include <strophe.h>
|
||||
|
||||
int handle_reply(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza,
|
||||
void * const userdata)
|
||||
int handle_reply(xmpp_conn_t *const conn,
|
||||
xmpp_stanza_t *const stanza,
|
||||
void *const userdata)
|
||||
{
|
||||
xmpp_stanza_t *query, *item;
|
||||
const char *type;
|
||||
|
||||
type = xmpp_stanza_get_type(stanza);
|
||||
if (strcmp(type, "error") == 0)
|
||||
fprintf(stderr, "ERROR: query failed\n");
|
||||
fprintf(stderr, "ERROR: query failed\n");
|
||||
else {
|
||||
query = xmpp_stanza_get_child_by_name(stanza, "query");
|
||||
printf("Active Sessions:\n");
|
||||
for (item = xmpp_stanza_get_children(query); item;
|
||||
item = xmpp_stanza_get_next(item))
|
||||
printf("\t %s\n", xmpp_stanza_get_attribute(item, "jid"));
|
||||
printf("END OF LIST\n");
|
||||
query = xmpp_stanza_get_child_by_name(stanza, "query");
|
||||
printf("Active Sessions:\n");
|
||||
for (item = xmpp_stanza_get_children(query); item;
|
||||
item = xmpp_stanza_get_next(item))
|
||||
printf("\t %s\n", xmpp_stanza_get_attribute(item, "jid"));
|
||||
printf("END OF LIST\n");
|
||||
}
|
||||
|
||||
/* disconnect */
|
||||
@@ -44,41 +44,43 @@ int handle_reply(xmpp_conn_t * const conn,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status,
|
||||
const int error, xmpp_stream_error_t * const stream_error,
|
||||
void * const userdata)
|
||||
void conn_handler(xmpp_conn_t *const conn,
|
||||
const xmpp_conn_event_t status,
|
||||
const int error,
|
||||
xmpp_stream_error_t *const stream_error,
|
||||
void *const userdata)
|
||||
{
|
||||
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
|
||||
xmpp_stanza_t *iq, *query;
|
||||
|
||||
if (status == XMPP_CONN_CONNECT) {
|
||||
fprintf(stderr, "DEBUG: connected\n");
|
||||
fprintf(stderr, "DEBUG: connected\n");
|
||||
|
||||
/* create iq stanza for request */
|
||||
iq = xmpp_iq_new(ctx, "get", "active1");
|
||||
xmpp_stanza_set_to(iq, "xxxxxxxxx.com");
|
||||
/* create iq stanza for request */
|
||||
iq = xmpp_iq_new(ctx, "get", "active1");
|
||||
xmpp_stanza_set_to(iq, "xxxxxxxxx.com");
|
||||
|
||||
query = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(query, "query");
|
||||
xmpp_stanza_set_ns(query, XMPP_NS_DISCO_ITEMS);
|
||||
xmpp_stanza_set_attribute(query, "node", "sessions");
|
||||
query = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(query, "query");
|
||||
xmpp_stanza_set_ns(query, XMPP_NS_DISCO_ITEMS);
|
||||
xmpp_stanza_set_attribute(query, "node", "sessions");
|
||||
|
||||
xmpp_stanza_add_child(iq, query);
|
||||
xmpp_stanza_add_child(iq, query);
|
||||
|
||||
/* we can release the stanza since it belongs to iq now */
|
||||
xmpp_stanza_release(query);
|
||||
/* we can release the stanza since it belongs to iq now */
|
||||
xmpp_stanza_release(query);
|
||||
|
||||
/* set up reply handler */
|
||||
xmpp_id_handler_add(conn, handle_reply, "active1", ctx);
|
||||
/* set up reply handler */
|
||||
xmpp_id_handler_add(conn, handle_reply, "active1", ctx);
|
||||
|
||||
/* send out the stanza */
|
||||
xmpp_send(conn, iq);
|
||||
/* send out the stanza */
|
||||
xmpp_send(conn, iq);
|
||||
|
||||
/* release the stanza */
|
||||
xmpp_stanza_release(iq);
|
||||
/* release the stanza */
|
||||
xmpp_stanza_release(iq);
|
||||
} else {
|
||||
fprintf(stderr, "DEBUG: disconnected\n");
|
||||
xmpp_stop(ctx);
|
||||
fprintf(stderr, "DEBUG: disconnected\n");
|
||||
xmpp_stop(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,8 +90,8 @@ int main(int argc, char **argv)
|
||||
xmpp_conn_t *conn;
|
||||
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "Usage: active <jid> <pass>\n\n");
|
||||
return 1;
|
||||
fprintf(stderr, "Usage: active <jid> <pass>\n\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* initialize lib */
|
||||
|
||||
@@ -19,9 +19,11 @@
|
||||
#define KA_INTERVAL 1
|
||||
|
||||
/* define a handler for connection events */
|
||||
void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status,
|
||||
const int error, xmpp_stream_error_t * const stream_error,
|
||||
void * const userdata)
|
||||
void conn_handler(xmpp_conn_t *const conn,
|
||||
const xmpp_conn_event_t status,
|
||||
const int error,
|
||||
xmpp_stream_error_t *const stream_error,
|
||||
void *const userdata)
|
||||
{
|
||||
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
|
||||
int secured;
|
||||
@@ -32,8 +34,7 @@ void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status,
|
||||
fprintf(stderr, "DEBUG: connection is %s.\n",
|
||||
secured ? "secured" : "NOT secured");
|
||||
xmpp_disconnect(conn);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fprintf(stderr, "DEBUG: disconnected\n");
|
||||
xmpp_stop(ctx);
|
||||
}
|
||||
@@ -70,7 +71,7 @@ int main(int argc, char **argv)
|
||||
" --legacy-ssl Use old style SSL.\n"
|
||||
" --tcp-keepalive Configure TCP keepalive.\n\n"
|
||||
"Note: --disable-tls conflicts with --mandatory-tls or "
|
||||
"--legacy-ssl\n");
|
||||
"--legacy-ssl\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -87,8 +88,9 @@ int main(int argc, char **argv)
|
||||
/* init library */
|
||||
xmpp_initialize();
|
||||
|
||||
/* pass NULL instead to silence output */
|
||||
log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG);
|
||||
/* create a context */
|
||||
log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG); /* pass NULL instead to silence output */
|
||||
ctx = xmpp_ctx_new(NULL, log);
|
||||
|
||||
/* create a connection */
|
||||
@@ -97,7 +99,8 @@ int main(int argc, char **argv)
|
||||
/* configure connection properties (optional) */
|
||||
xmpp_conn_set_flags(conn, flags);
|
||||
/* configure TCP keepalive (optional) */
|
||||
if (tcp_keepalive) xmpp_conn_set_keepalive(conn, KA_TIMEOUT, KA_INTERVAL);
|
||||
if (tcp_keepalive)
|
||||
xmpp_conn_set_keepalive(conn, KA_TIMEOUT, KA_INTERVAL);
|
||||
|
||||
/* setup authentication information */
|
||||
xmpp_conn_set_jid(conn, jid);
|
||||
|
||||
@@ -22,12 +22,13 @@
|
||||
|
||||
#include <strophe.h>
|
||||
|
||||
|
||||
int version_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata)
|
||||
int version_handler(xmpp_conn_t *const conn,
|
||||
xmpp_stanza_t *const stanza,
|
||||
void *const userdata)
|
||||
{
|
||||
xmpp_stanza_t *reply, *query, *name, *version, *text;
|
||||
const char *ns;
|
||||
xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata;
|
||||
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
|
||||
|
||||
printf("Received version request from %s\n", xmpp_stanza_get_from(stanza));
|
||||
|
||||
@@ -69,10 +70,11 @@ int version_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata)
|
||||
int message_handler(xmpp_conn_t *const conn,
|
||||
xmpp_stanza_t *const stanza,
|
||||
void *const userdata)
|
||||
{
|
||||
xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata;
|
||||
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
|
||||
xmpp_stanza_t *body, *reply;
|
||||
const char *type;
|
||||
char *intext, *replytext;
|
||||
@@ -87,7 +89,8 @@ int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void
|
||||
|
||||
intext = xmpp_stanza_get_text(body);
|
||||
|
||||
printf("Incoming message from %s: %s\n", xmpp_stanza_get_from(stanza), intext);
|
||||
printf("Incoming message from %s: %s\n", xmpp_stanza_get_from(stanza),
|
||||
intext);
|
||||
|
||||
reply = xmpp_stanza_reply(stanza);
|
||||
if (xmpp_stanza_get_type(reply) == NULL)
|
||||
@@ -97,7 +100,7 @@ int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void
|
||||
replytext = strdup("bye!");
|
||||
quit = 1;
|
||||
} else {
|
||||
replytext = (char *) malloc(strlen(" to you too!") + strlen(intext) + 1);
|
||||
replytext = (char *)malloc(strlen(" to you too!") + strlen(intext) + 1);
|
||||
strcpy(replytext, intext);
|
||||
strcat(replytext, " to you too!");
|
||||
}
|
||||
@@ -115,24 +118,26 @@ int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void
|
||||
}
|
||||
|
||||
/* define a handler for connection events */
|
||||
void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status,
|
||||
const int error, xmpp_stream_error_t * const stream_error,
|
||||
void * const userdata)
|
||||
void conn_handler(xmpp_conn_t *const conn,
|
||||
const xmpp_conn_event_t status,
|
||||
const int error,
|
||||
xmpp_stream_error_t *const stream_error,
|
||||
void *const userdata)
|
||||
{
|
||||
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
|
||||
|
||||
if (status == XMPP_CONN_CONNECT) {
|
||||
xmpp_stanza_t* pres;
|
||||
xmpp_stanza_t *pres;
|
||||
fprintf(stderr, "DEBUG: connected\n");
|
||||
xmpp_handler_add(conn, version_handler, "jabber:iq:version", "iq", NULL, ctx);
|
||||
xmpp_handler_add(conn, version_handler, "jabber:iq:version", "iq", NULL,
|
||||
ctx);
|
||||
xmpp_handler_add(conn, message_handler, NULL, "message", NULL, ctx);
|
||||
|
||||
/* Send initial <presence/> so that we appear online to contacts */
|
||||
pres = xmpp_presence_new(ctx);
|
||||
xmpp_send(conn, pres);
|
||||
xmpp_stanza_release(pres);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fprintf(stderr, "DEBUG: disconnected\n");
|
||||
xmpp_stop(ctx);
|
||||
}
|
||||
@@ -157,8 +162,9 @@ int main(int argc, char **argv)
|
||||
/* init library */
|
||||
xmpp_initialize();
|
||||
|
||||
/* pass NULL instead to silence output */
|
||||
log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG);
|
||||
/* create a context */
|
||||
log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG); /* pass NULL instead to silence output */
|
||||
ctx = xmpp_ctx_new(NULL, log);
|
||||
|
||||
/* create a connection */
|
||||
|
||||
@@ -19,19 +19,19 @@
|
||||
|
||||
#include <strophe.h>
|
||||
|
||||
|
||||
/* define a handler for connection events */
|
||||
void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status,
|
||||
const int error, xmpp_stream_error_t * const stream_error,
|
||||
void * const userdata)
|
||||
void conn_handler(xmpp_conn_t *const conn,
|
||||
const xmpp_conn_event_t status,
|
||||
const int error,
|
||||
xmpp_stream_error_t *const stream_error,
|
||||
void *const userdata)
|
||||
{
|
||||
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
|
||||
|
||||
if (status == XMPP_CONN_CONNECT) {
|
||||
fprintf(stderr, "DEBUG: connected\n");
|
||||
xmpp_disconnect(conn);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fprintf(stderr, "DEBUG: disconnected\n");
|
||||
xmpp_stop(ctx);
|
||||
}
|
||||
@@ -56,19 +56,20 @@ int main(int argc, char **argv)
|
||||
host = argv[3];
|
||||
|
||||
if (argc == 5) {
|
||||
short tmp_port = (short) strtol(argv[4], &port_err, 10);
|
||||
short tmp_port = (short)strtol(argv[4], &port_err, 10);
|
||||
if (tmp_port < 0 || *port_err != '\0') {
|
||||
fprintf(stderr, "Invalid value of <port> [%s].\n", argv[4]);
|
||||
return 1;
|
||||
}
|
||||
port = (unsigned short) tmp_port;
|
||||
port = (unsigned short)tmp_port;
|
||||
}
|
||||
|
||||
/* init library */
|
||||
xmpp_initialize();
|
||||
|
||||
/* pass NULL instead to silence output */
|
||||
log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG);
|
||||
/* create a context */
|
||||
log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG); /* pass NULL instead to silence output */
|
||||
ctx = xmpp_ctx_new(NULL, log);
|
||||
|
||||
/* create a connection */
|
||||
@@ -94,4 +95,3 @@ int main(int argc, char **argv)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,9 +36,8 @@ typedef struct {
|
||||
|
||||
#define FEATURES_TIMEOUT 5000 /* 5 seconds */
|
||||
|
||||
static void iq_reg_send_form(xmpp_reg_t *reg,
|
||||
xmpp_conn_t *conn,
|
||||
xmpp_stanza_t *stanza)
|
||||
static void
|
||||
iq_reg_send_form(xmpp_reg_t *reg, xmpp_conn_t *conn, xmpp_stanza_t *stanza)
|
||||
{
|
||||
xmpp_ctx_t *ctx = reg->ctx;
|
||||
xmpp_stanza_t *query;
|
||||
@@ -101,9 +100,9 @@ static void iq_reg_send_form(xmpp_reg_t *reg,
|
||||
}
|
||||
}
|
||||
|
||||
static int iq_reg2_cb(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza,
|
||||
void * const userdata)
|
||||
static int iq_reg2_cb(xmpp_conn_t *const conn,
|
||||
xmpp_stanza_t *const stanza,
|
||||
void *const userdata)
|
||||
{
|
||||
const char *type;
|
||||
|
||||
@@ -126,9 +125,9 @@ quit:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int iq_reg_cb(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza,
|
||||
void * const userdata)
|
||||
static int iq_reg_cb(xmpp_conn_t *const conn,
|
||||
xmpp_stanza_t *const stanza,
|
||||
void *const userdata)
|
||||
{
|
||||
xmpp_reg_t *reg = (xmpp_reg_t *)userdata;
|
||||
xmpp_stanza_t *registered = NULL;
|
||||
@@ -163,9 +162,9 @@ quit:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _handle_error(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza,
|
||||
void * const userdata)
|
||||
static int _handle_error(xmpp_conn_t *const conn,
|
||||
xmpp_stanza_t *const stanza,
|
||||
void *const userdata)
|
||||
{
|
||||
fprintf(stderr, "DEBUG: received stream error\n");
|
||||
xmpp_disconnect(conn);
|
||||
@@ -173,9 +172,9 @@ static int _handle_error(xmpp_conn_t * const conn,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _handle_proceedtls_default(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza,
|
||||
void * const userdata)
|
||||
static int _handle_proceedtls_default(xmpp_conn_t *const conn,
|
||||
xmpp_stanza_t *const stanza,
|
||||
void *const userdata)
|
||||
{
|
||||
const char *name = xmpp_stanza_get_name(stanza);
|
||||
|
||||
@@ -193,8 +192,8 @@ static int _handle_proceedtls_default(xmpp_conn_t * const conn,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _handle_missing_features(xmpp_conn_t * const conn,
|
||||
void * const userdata)
|
||||
static int _handle_missing_features(xmpp_conn_t *const conn,
|
||||
void *const userdata)
|
||||
{
|
||||
fprintf(stderr, "DEBUG: timeout\n");
|
||||
xmpp_disconnect(conn);
|
||||
@@ -202,9 +201,9 @@ static int _handle_missing_features(xmpp_conn_t * const conn,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _handle_features(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza,
|
||||
void * const userdata)
|
||||
static int _handle_features(xmpp_conn_t *const conn,
|
||||
xmpp_stanza_t *const stanza,
|
||||
void *const userdata)
|
||||
{
|
||||
xmpp_reg_t *reg = (xmpp_reg_t *)userdata;
|
||||
xmpp_ctx_t *ctx = reg->ctx;
|
||||
@@ -221,8 +220,8 @@ static int _handle_features(xmpp_conn_t * const conn,
|
||||
child = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(child, "starttls");
|
||||
xmpp_stanza_set_ns(child, XMPP_NS_TLS);
|
||||
xmpp_handler_add(conn, _handle_proceedtls_default,
|
||||
XMPP_NS_TLS, NULL, NULL, NULL);
|
||||
xmpp_handler_add(conn, _handle_proceedtls_default, XMPP_NS_TLS, NULL,
|
||||
NULL, NULL);
|
||||
xmpp_send(conn, child);
|
||||
xmpp_stanza_release(child);
|
||||
return 0;
|
||||
@@ -255,11 +254,11 @@ static int _handle_features(xmpp_conn_t * const conn,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void conn_handler(xmpp_conn_t * const conn,
|
||||
static void conn_handler(xmpp_conn_t *const conn,
|
||||
const xmpp_conn_event_t status,
|
||||
const int error,
|
||||
xmpp_stream_error_t * const stream_error,
|
||||
void * const userdata)
|
||||
xmpp_stream_error_t *const stream_error,
|
||||
void *const userdata)
|
||||
{
|
||||
xmpp_reg_t *reg = (xmpp_reg_t *)userdata;
|
||||
int secured;
|
||||
@@ -274,14 +273,14 @@ static void conn_handler(xmpp_conn_t * const conn,
|
||||
secured ? "secured" : "NOT secured");
|
||||
|
||||
/* setup handler for stream:error */
|
||||
xmpp_handler_add(conn, _handle_error, XMPP_NS_STREAMS,
|
||||
"error", NULL, NULL);
|
||||
xmpp_handler_add(conn, _handle_error, XMPP_NS_STREAMS, "error", NULL,
|
||||
NULL);
|
||||
|
||||
/* setup handlers for incoming <stream:features> */
|
||||
xmpp_handler_add(conn, _handle_features, XMPP_NS_STREAMS,
|
||||
"features", NULL, reg);
|
||||
xmpp_timed_handler_add(conn, _handle_missing_features,
|
||||
FEATURES_TIMEOUT, NULL);
|
||||
xmpp_handler_add(conn, _handle_features, XMPP_NS_STREAMS, "features",
|
||||
NULL, reg);
|
||||
xmpp_timed_handler_add(conn, _handle_missing_features, FEATURES_TIMEOUT,
|
||||
NULL);
|
||||
} else {
|
||||
fprintf(stderr, "DEBUG: disconnected\n");
|
||||
xmpp_stop(reg->ctx);
|
||||
|
||||
@@ -18,31 +18,29 @@
|
||||
|
||||
#include <strophe.h>
|
||||
|
||||
int handle_reply(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza,
|
||||
void * const userdata)
|
||||
int handle_reply(xmpp_conn_t *const conn,
|
||||
xmpp_stanza_t *const stanza,
|
||||
void *const userdata)
|
||||
{
|
||||
xmpp_stanza_t *query, *item;
|
||||
const char *type, *name;
|
||||
|
||||
type = xmpp_stanza_get_type(stanza);
|
||||
if (strcmp(type, "error") == 0)
|
||||
fprintf(stderr, "ERROR: query failed\n");
|
||||
fprintf(stderr, "ERROR: query failed\n");
|
||||
else {
|
||||
query = xmpp_stanza_get_child_by_name(stanza, "query");
|
||||
printf("Roster:\n");
|
||||
for (item = xmpp_stanza_get_children(query); item;
|
||||
item = xmpp_stanza_get_next(item))
|
||||
if ((name = xmpp_stanza_get_attribute(item, "name")))
|
||||
printf("\t %s (%s) sub=%s\n",
|
||||
name,
|
||||
xmpp_stanza_get_attribute(item, "jid"),
|
||||
xmpp_stanza_get_attribute(item, "subscription"));
|
||||
else
|
||||
printf("\t %s sub=%s\n",
|
||||
xmpp_stanza_get_attribute(item, "jid"),
|
||||
xmpp_stanza_get_attribute(item, "subscription"));
|
||||
printf("END OF LIST\n");
|
||||
query = xmpp_stanza_get_child_by_name(stanza, "query");
|
||||
printf("Roster:\n");
|
||||
for (item = xmpp_stanza_get_children(query); item;
|
||||
item = xmpp_stanza_get_next(item))
|
||||
if ((name = xmpp_stanza_get_attribute(item, "name")))
|
||||
printf("\t %s (%s) sub=%s\n", name,
|
||||
xmpp_stanza_get_attribute(item, "jid"),
|
||||
xmpp_stanza_get_attribute(item, "subscription"));
|
||||
else
|
||||
printf("\t %s sub=%s\n", xmpp_stanza_get_attribute(item, "jid"),
|
||||
xmpp_stanza_get_attribute(item, "subscription"));
|
||||
printf("END OF LIST\n");
|
||||
}
|
||||
|
||||
/* disconnect */
|
||||
@@ -51,39 +49,41 @@ int handle_reply(xmpp_conn_t * const conn,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status,
|
||||
const int error, xmpp_stream_error_t * const stream_error,
|
||||
void * const userdata)
|
||||
void conn_handler(xmpp_conn_t *const conn,
|
||||
const xmpp_conn_event_t status,
|
||||
const int error,
|
||||
xmpp_stream_error_t *const stream_error,
|
||||
void *const userdata)
|
||||
{
|
||||
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
|
||||
xmpp_stanza_t *iq, *query;
|
||||
|
||||
if (status == XMPP_CONN_CONNECT) {
|
||||
fprintf(stderr, "DEBUG: connected\n");
|
||||
fprintf(stderr, "DEBUG: connected\n");
|
||||
|
||||
/* create iq stanza for request */
|
||||
iq = xmpp_iq_new(ctx, "get", "roster1");
|
||||
/* create iq stanza for request */
|
||||
iq = xmpp_iq_new(ctx, "get", "roster1");
|
||||
|
||||
query = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(query, "query");
|
||||
xmpp_stanza_set_ns(query, XMPP_NS_ROSTER);
|
||||
query = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(query, "query");
|
||||
xmpp_stanza_set_ns(query, XMPP_NS_ROSTER);
|
||||
|
||||
xmpp_stanza_add_child(iq, query);
|
||||
xmpp_stanza_add_child(iq, query);
|
||||
|
||||
/* we can release the stanza since it belongs to iq now */
|
||||
xmpp_stanza_release(query);
|
||||
/* we can release the stanza since it belongs to iq now */
|
||||
xmpp_stanza_release(query);
|
||||
|
||||
/* set up reply handler */
|
||||
xmpp_id_handler_add(conn, handle_reply, "roster1", ctx);
|
||||
/* set up reply handler */
|
||||
xmpp_id_handler_add(conn, handle_reply, "roster1", ctx);
|
||||
|
||||
/* send out the stanza */
|
||||
xmpp_send(conn, iq);
|
||||
/* send out the stanza */
|
||||
xmpp_send(conn, iq);
|
||||
|
||||
/* release the stanza */
|
||||
xmpp_stanza_release(iq);
|
||||
/* release the stanza */
|
||||
xmpp_stanza_release(iq);
|
||||
} else {
|
||||
fprintf(stderr, "DEBUG: disconnected\n");
|
||||
xmpp_stop(ctx);
|
||||
fprintf(stderr, "DEBUG: disconnected\n");
|
||||
xmpp_stop(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,8 +93,8 @@ int main(int argc, char **argv)
|
||||
xmpp_conn_t *conn;
|
||||
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "Usage: roster <jid> <pass>\n\n");
|
||||
return 1;
|
||||
fprintf(stderr, "Usage: roster <jid> <pass>\n\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* initialize lib */
|
||||
|
||||
@@ -76,8 +76,8 @@ static void vcard_photo(vcard_t *vc, xmpp_stanza_t *stanza)
|
||||
xmpp_free(vc->ctx, img);
|
||||
}
|
||||
|
||||
static void vcard_print_string(vcard_t *vc, xmpp_stanza_t *stanza,
|
||||
const char *info)
|
||||
static void
|
||||
vcard_print_string(vcard_t *vc, xmpp_stanza_t *stanza, const char *info)
|
||||
{
|
||||
char *s = xmpp_stanza_get_text(stanza);
|
||||
|
||||
@@ -140,14 +140,9 @@ static vcard_cb_t vcard_cb_get(xmpp_stanza_t *stanza)
|
||||
const char *tag;
|
||||
vcard_cb_t cb;
|
||||
} vcard_tbl[] = {
|
||||
{ "PHOTO", vcard_photo },
|
||||
{ "BDAY", vcard_bday },
|
||||
{ "DESC", vcard_desc },
|
||||
{ "EMAIL", vcard_email },
|
||||
{ "FN", vcard_fn },
|
||||
{ "N", vcard_name },
|
||||
{ "NICKNAME", vcard_nick },
|
||||
{ "URL", vcard_url },
|
||||
{"PHOTO", vcard_photo}, {"BDAY", vcard_bday}, {"DESC", vcard_desc},
|
||||
{"EMAIL", vcard_email}, {"FN", vcard_fn}, {"N", vcard_name},
|
||||
{"NICKNAME", vcard_nick}, {"URL", vcard_url},
|
||||
};
|
||||
|
||||
tag = xmpp_stanza_get_name(stanza);
|
||||
@@ -165,7 +160,7 @@ exit:
|
||||
return cb;
|
||||
}
|
||||
|
||||
static int timedout(xmpp_conn_t * const conn, void * const userdata)
|
||||
static int timedout(xmpp_conn_t *const conn, void *const userdata)
|
||||
{
|
||||
fprintf(stderr, "Timeout reached.\n");
|
||||
xmpp_disconnect(conn);
|
||||
@@ -173,8 +168,9 @@ static int timedout(xmpp_conn_t * const conn, void * const userdata)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int recv_vcard(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
void * const userdata)
|
||||
static int recv_vcard(xmpp_conn_t *const conn,
|
||||
xmpp_stanza_t *const stanza,
|
||||
void *const userdata)
|
||||
{
|
||||
vcard_t *vc = userdata;
|
||||
vcard_cb_t cb;
|
||||
@@ -213,16 +209,17 @@ exit:
|
||||
static void send_vcard_req(xmpp_conn_t *conn, const char *to, const char *id)
|
||||
{
|
||||
printf("Requesting vCard from %s.\n", to);
|
||||
xmpp_send_raw_string(conn, "<iq from='%s' to='%s' type='get' id='%s'>"
|
||||
"<vCard xmlns='vcard-temp'/></iq>",
|
||||
xmpp_conn_get_bound_jid(conn), to, id);
|
||||
xmpp_send_raw_string(conn,
|
||||
"<iq from='%s' to='%s' type='get' id='%s'>"
|
||||
"<vCard xmlns='vcard-temp'/></iq>",
|
||||
xmpp_conn_get_bound_jid(conn), to, id);
|
||||
}
|
||||
|
||||
static void conn_handler(xmpp_conn_t * const conn,
|
||||
static void conn_handler(xmpp_conn_t *const conn,
|
||||
const xmpp_conn_event_t status,
|
||||
const int error,
|
||||
xmpp_stream_error_t * const stream_error,
|
||||
void * const userdata)
|
||||
xmpp_stream_error_t *const stream_error,
|
||||
void *const userdata)
|
||||
{
|
||||
vcard_t *vc = userdata;
|
||||
|
||||
@@ -235,25 +232,26 @@ static void conn_handler(xmpp_conn_t * const conn,
|
||||
fprintf(stderr, "Disconnected with error=%d.\n", error);
|
||||
if (stream_error != NULL)
|
||||
fprintf(stderr, "Stream error type=%d text=%s.\n",
|
||||
stream_error->type, stream_error->text);
|
||||
stream_error->type, stream_error->text);
|
||||
xmpp_stop(vc->ctx);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
xmpp_log_t *log;
|
||||
xmpp_ctx_t *ctx;
|
||||
xmpp_log_t *log;
|
||||
xmpp_ctx_t *ctx;
|
||||
xmpp_conn_t *conn;
|
||||
const char *jid;
|
||||
const char *pass;
|
||||
char *prog;
|
||||
vcard_t vcard;
|
||||
const char *jid;
|
||||
const char *pass;
|
||||
char *prog;
|
||||
vcard_t vcard;
|
||||
|
||||
if (argc < 4 || argc > 5) {
|
||||
prog = argc > 0 ? strdup(argv[0]) : NULL;
|
||||
printf("Usage: %s <login-jid> <password> <recipient-jid> "
|
||||
"[image-file]\n\n", prog == NULL ? "vcard" : basename(prog));
|
||||
"[image-file]\n\n",
|
||||
prog == NULL ? "vcard" : basename(prog));
|
||||
printf("If vCard contains a photo it will be stored to "
|
||||
"image-file. If you don't provide the image-file "
|
||||
"default filename will be generated.\n");
|
||||
@@ -281,4 +279,3 @@ int main(int argc, char **argv)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user