Introduce generic xmpp_conn_set_*() API

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 <jaeckel-floss@eyet-services.de>
This commit is contained in:
Steffen Jaeckel
2024-01-29 12:01:34 +01:00
committed by Steffen Jaeckel
parent 5690c4ed89
commit 06f2ba19b4
12 changed files with 500 additions and 229 deletions

View File

@@ -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);

View File

@@ -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) {

View File

@@ -293,20 +293,24 @@ create_connection:
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) {

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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 */

View File

@@ -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);

View File

@@ -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);