Skip to content

Commit 4a49aba

Browse files
committed
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 <[email protected]>
1 parent a98deac commit 4a49aba

File tree

11 files changed

+465
-217
lines changed

11 files changed

+465
-217
lines changed

examples/active.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ int main(int argc, char **argv)
115115
*/
116116

117117
/* setup authentication information */
118-
xmpp_conn_set_jid(conn, argv[1]);
119-
xmpp_conn_set_pass(conn, argv[2]);
118+
xmpp_conn_set_string(conn, XMPP_SETTING_JID, argv[1]);
119+
xmpp_conn_set_string(conn, XMPP_SETTING_PASS, argv[2]);
120120

121121
/* initiate connection */
122122
xmpp_connect_client(conn, NULL, 0, conn_handler, ctx);

examples/basic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ int main(int argc, char **argv)
116116

117117
/* setup authentication information */
118118
if (jid)
119-
xmpp_conn_set_jid(conn, jid);
119+
xmpp_conn_set_string(conn, XMPP_SETTING_JID, jid);
120120
if (password)
121-
xmpp_conn_set_pass(conn, password);
121+
xmpp_conn_set_string(conn, XMPP_SETTING_PASS, password);
122122

123123
/* initiate connection */
124124
if (xmpp_connect_client(conn, host, port, conn_handler, ctx) == XMPP_EOK) {

examples/bot.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,20 +293,24 @@ int main(int argc, char **argv)
293293
xmpp_conn_set_flags(conn, flags);
294294

295295
/* ask for a password if key is protected */
296-
xmpp_conn_set_password_callback(conn, password_callback, NULL);
296+
xmpp_conn_set_functionpointer(conn, XMPP_SETTING_PASSWORD_CALLBACK,
297+
password_callback);
297298
/* try at max 3 times in case the user enters the password wrong */
298-
xmpp_conn_set_password_retries(conn, 3);
299+
xmpp_conn_set_int(conn, XMPP_SETTING_PASSWORD_RETRIES, 3);
299300
/* setup authentication information */
300-
if (key)
301-
xmpp_conn_set_client_cert(conn, cert, key);
301+
if (key) {
302+
xmpp_conn_set_string(conn, XMPP_SETTING_CLIENT_CERT, cert);
303+
xmpp_conn_set_string(conn, XMPP_SETTING_CLIENT_KEY, key);
304+
}
302305
if (jid)
303-
xmpp_conn_set_jid(conn, jid);
306+
xmpp_conn_set_string(conn, XMPP_SETTING_JID, jid);
304307
if (password)
305-
xmpp_conn_set_pass(conn, password);
308+
xmpp_conn_set_string(conn, XMPP_SETTING_PASS, password);
306309

307310
/* enable TCP keepalive, using canned callback function */
308311
if (tcp_keepalive)
309-
xmpp_conn_set_sockopt_callback(conn, xmpp_sockopt_cb_keepalive);
312+
xmpp_conn_set_functionpointer(conn, XMPP_SETTING_SOCKOPT_CALLBACK,
313+
xmpp_sockopt_cb_keepalive);
310314

311315
/* set Stream-Mangement state if available */
312316
if (sm_state) {

examples/complex.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -331,27 +331,31 @@ int main(int argc, char **argv)
331331
xmpp_conn_set_flags(conn, flags);
332332
/* configure TCP keepalive (optional) */
333333
if (tcp_keepalive)
334-
xmpp_conn_set_sockopt_callback(conn, sockopt_cb);
334+
xmpp_conn_set_functionpointer(conn, XMPP_SETTING_SOCKOPT_CALLBACK,
335+
sockopt_cb);
335336

336337
/* ask for a password if key is protected */
337-
xmpp_conn_set_password_callback(conn, password_callback, NULL);
338+
xmpp_conn_set_functionpointer(conn, XMPP_SETTING_PASSWORD_CALLBACK,
339+
password_callback);
338340
/* try at max 3 times in case the user enters the password wrong */
339-
xmpp_conn_set_password_retries(conn, 3);
341+
xmpp_conn_set_int(conn, XMPP_SETTING_PASSWORD_RETRIES, 3);
340342
/* setup authentication information */
341343
if (key) {
342-
xmpp_conn_set_client_cert(conn, cert, key);
344+
xmpp_conn_set_string(conn, XMPP_SETTING_CLIENT_CERT, cert);
345+
xmpp_conn_set_string(conn, XMPP_SETTING_CLIENT_KEY, key);
343346
}
344347
if (jid)
345-
xmpp_conn_set_jid(conn, jid);
348+
xmpp_conn_set_string(conn, XMPP_SETTING_JID, jid);
346349
if (password)
347-
xmpp_conn_set_pass(conn, password);
350+
xmpp_conn_set_string(conn, XMPP_SETTING_PASS, password);
348351

349352
if (certfail)
350-
xmpp_conn_set_certfail_handler(conn, certfail_handler);
353+
xmpp_conn_set_functionpointer(conn, XMPP_SETTING_CERTFAIL_HANDLER,
354+
certfail_handler);
351355
if (capath)
352-
xmpp_conn_set_capath(conn, capath);
356+
xmpp_conn_set_string(conn, XMPP_SETTING_CAPATH, capath);
353357
if (cafile)
354-
xmpp_conn_set_cafile(conn, cafile);
358+
xmpp_conn_set_string(conn, XMPP_SETTING_CAFILE, cafile);
355359

356360
/* initiate connection */
357361
if (xmpp_connect_client(conn, host, port, conn_handler, ctx) == XMPP_EOK) {

examples/component.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ int main(int argc, char **argv)
8080
conn = xmpp_conn_new(ctx);
8181

8282
/* setup authentication information */
83-
xmpp_conn_set_jid(conn, jid);
84-
xmpp_conn_set_pass(conn, pass);
83+
xmpp_conn_set_string(conn, XMPP_SETTING_JID, jid);
84+
xmpp_conn_set_string(conn, XMPP_SETTING_PASS, pass);
8585

8686
/* initiate connection */
8787
xmpp_connect_component(conn, host, port, conn_handler, ctx);

examples/register.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ int main(int argc, char **argv)
342342

343343
/* jid can be a jid or domain for "raw" connection */
344344
domain = xmpp_jid_domain(ctx, jid);
345-
xmpp_conn_set_jid(conn, domain);
345+
xmpp_conn_set_string(conn, XMPP_SETTING_JID, domain);
346346
xmpp_free(ctx, domain);
347347

348348
/* private data */

examples/roster.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ int main(int argc, char **argv)
118118
*/
119119

120120
/* setup authentication information */
121-
xmpp_conn_set_jid(conn, argv[1]);
122-
xmpp_conn_set_pass(conn, argv[2]);
121+
xmpp_conn_set_string(conn, XMPP_SETTING_JID, argv[1]);
122+
xmpp_conn_set_string(conn, XMPP_SETTING_PASS, argv[2]);
123123

124124
/* initiate connection */
125125
xmpp_connect_client(conn, NULL, 0, conn_handler, ctx);

examples/vcard.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ int main(int argc, char **argv)
269269
log = xmpp_get_default_logger(XMPP_LEVEL_INFO);
270270
ctx = xmpp_ctx_new(NULL, log);
271271
conn = xmpp_conn_new(ctx);
272-
xmpp_conn_set_jid(conn, jid);
273-
xmpp_conn_set_pass(conn, pass);
272+
xmpp_conn_set_string(conn, XMPP_SETTING_JID, jid);
273+
xmpp_conn_set_string(conn, XMPP_SETTING_PASS, pass);
274274
vcard.ctx = ctx;
275275
xmpp_connect_client(conn, NULL, 0, conn_handler, &vcard);
276276
xmpp_run(ctx);

0 commit comments

Comments
 (0)