Skip to content

Commit

Permalink
Introduce generic xmpp_conn_set_*() API
Browse files Browse the repository at this point in the history
Instead of having a multitude of setter API functions for configuration
options, provide generic ones for the different types we have.

Signed-off-by: Steffen Jaeckel <[email protected]>
  • Loading branch information
sjaeckel committed Jan 31, 2024
1 parent 0d573b4 commit fa92893
Show file tree
Hide file tree
Showing 11 changed files with 477 additions and 217 deletions.
4 changes: 2 additions & 2 deletions examples/active.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ int main(int argc, char **argv)
*/

/* setup authentication information */
xmpp_conn_set_jid(conn, argv[1]);
xmpp_conn_set_pass(conn, argv[2]);
xmpp_conn_set_string(conn, XMPP_SETTING_JID, argv[1]);
xmpp_conn_set_string(conn, XMPP_SETTING_PASS, argv[2]);

/* initiate connection */
xmpp_connect_client(conn, NULL, 0, conn_handler, ctx);
Expand Down
4 changes: 2 additions & 2 deletions examples/basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ int main(int argc, char **argv)

/* setup authentication information */
if (jid)
xmpp_conn_set_jid(conn, jid);
xmpp_conn_set_string(conn, XMPP_SETTING_JID, jid);
if (password)
xmpp_conn_set_pass(conn, password);
xmpp_conn_set_string(conn, XMPP_SETTING_PASS, password);

/* initiate connection */
if (xmpp_connect_client(conn, host, port, conn_handler, ctx) == XMPP_EOK) {
Expand Down
18 changes: 11 additions & 7 deletions examples/bot.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,20 +293,24 @@ int main(int argc, char **argv)
xmpp_conn_set_flags(conn, flags);

/* ask for a password if key is protected */
xmpp_conn_set_password_callback(conn, password_callback, NULL);
xmpp_conn_set_functionpointer(conn, XMPP_SETTING_PASSWORD_CALLBACK,
password_callback);
/* try at max 3 times in case the user enters the password wrong */
xmpp_conn_set_password_retries(conn, 3);
xmpp_conn_set_int(conn, XMPP_SETTING_PASSWORD_RETRIES, 3);
/* setup authentication information */
if (key)
xmpp_conn_set_client_cert(conn, cert, key);
if (key) {
xmpp_conn_set_string(conn, XMPP_SETTING_CLIENT_CERT, cert);
xmpp_conn_set_string(conn, XMPP_SETTING_CLIENT_KEY, key);
}
if (jid)
xmpp_conn_set_jid(conn, jid);
xmpp_conn_set_string(conn, XMPP_SETTING_JID, jid);
if (password)
xmpp_conn_set_pass(conn, password);
xmpp_conn_set_string(conn, XMPP_SETTING_PASS, password);

/* enable TCP keepalive, using canned callback function */
if (tcp_keepalive)
xmpp_conn_set_sockopt_callback(conn, xmpp_sockopt_cb_keepalive);
xmpp_conn_set_functionpointer(conn, XMPP_SETTING_SOCKOPT_CALLBACK,
xmpp_sockopt_cb_keepalive);

/* set Stream-Mangement state if available */
if (sm_state) {
Expand Down
22 changes: 13 additions & 9 deletions examples/complex.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,27 +331,31 @@ int main(int argc, char **argv)
xmpp_conn_set_flags(conn, flags);
/* configure TCP keepalive (optional) */
if (tcp_keepalive)
xmpp_conn_set_sockopt_callback(conn, sockopt_cb);
xmpp_conn_set_functionpointer(conn, XMPP_SETTING_SOCKOPT_CALLBACK,
sockopt_cb);

/* ask for a password if key is protected */
xmpp_conn_set_password_callback(conn, password_callback, NULL);
xmpp_conn_set_functionpointer(conn, XMPP_SETTING_PASSWORD_CALLBACK,
password_callback);
/* try at max 3 times in case the user enters the password wrong */
xmpp_conn_set_password_retries(conn, 3);
xmpp_conn_set_int(conn, XMPP_SETTING_PASSWORD_RETRIES, 3);
/* setup authentication information */
if (key) {
xmpp_conn_set_client_cert(conn, cert, key);
xmpp_conn_set_string(conn, XMPP_SETTING_CLIENT_CERT, cert);
xmpp_conn_set_string(conn, XMPP_SETTING_CLIENT_KEY, key);
}
if (jid)
xmpp_conn_set_jid(conn, jid);
xmpp_conn_set_string(conn, XMPP_SETTING_JID, jid);
if (password)
xmpp_conn_set_pass(conn, password);
xmpp_conn_set_string(conn, XMPP_SETTING_PASS, password);

if (certfail)
xmpp_conn_set_certfail_handler(conn, certfail_handler);
xmpp_conn_set_functionpointer(conn, XMPP_SETTING_CERTFAIL_HANDLER,
certfail_handler);
if (capath)
xmpp_conn_set_capath(conn, capath);
xmpp_conn_set_string(conn, XMPP_SETTING_CAPATH, capath);
if (cafile)
xmpp_conn_set_cafile(conn, cafile);
xmpp_conn_set_string(conn, XMPP_SETTING_CAFILE, cafile);

/* initiate connection */
if (xmpp_connect_client(conn, host, port, conn_handler, ctx) == XMPP_EOK) {
Expand Down
4 changes: 2 additions & 2 deletions examples/component.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ int main(int argc, char **argv)
conn = xmpp_conn_new(ctx);

/* setup authentication information */
xmpp_conn_set_jid(conn, jid);
xmpp_conn_set_pass(conn, pass);
xmpp_conn_set_string(conn, XMPP_SETTING_JID, jid);
xmpp_conn_set_string(conn, XMPP_SETTING_PASS, pass);

/* initiate connection */
xmpp_connect_component(conn, host, port, conn_handler, ctx);
Expand Down
2 changes: 1 addition & 1 deletion examples/register.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ int main(int argc, char **argv)

/* jid can be a jid or domain for "raw" connection */
domain = xmpp_jid_domain(ctx, jid);
xmpp_conn_set_jid(conn, domain);
xmpp_conn_set_string(conn, XMPP_SETTING_JID, domain);
xmpp_free(ctx, domain);

/* private data */
Expand Down
4 changes: 2 additions & 2 deletions examples/roster.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ int main(int argc, char **argv)
*/

/* setup authentication information */
xmpp_conn_set_jid(conn, argv[1]);
xmpp_conn_set_pass(conn, argv[2]);
xmpp_conn_set_string(conn, XMPP_SETTING_JID, argv[1]);
xmpp_conn_set_string(conn, XMPP_SETTING_PASS, argv[2]);

/* initiate connection */
xmpp_connect_client(conn, NULL, 0, conn_handler, ctx);
Expand Down
4 changes: 2 additions & 2 deletions examples/vcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ int main(int argc, char **argv)
log = xmpp_get_default_logger(XMPP_LEVEL_INFO);
ctx = xmpp_ctx_new(NULL, log);
conn = xmpp_conn_new(ctx);
xmpp_conn_set_jid(conn, jid);
xmpp_conn_set_pass(conn, pass);
xmpp_conn_set_string(conn, XMPP_SETTING_JID, jid);
xmpp_conn_set_string(conn, XMPP_SETTING_PASS, pass);
vcard.ctx = ctx;
xmpp_connect_client(conn, NULL, 0, conn_handler, &vcard);
xmpp_run(ctx);
Expand Down
Loading

0 comments on commit fa92893

Please sign in to comment.