diff options
author | xengineering <mail2xengineering@protonmail.com> | 2021-01-30 11:37:16 +0100 |
---|---|---|
committer | xengineering <mail2xengineering@protonmail.com> | 2021-01-30 11:37:16 +0100 |
commit | 7897ac41444b7be10e9881ea30ed67fe14929cef (patch) | |
tree | 3d11df611d8a6aadfe543d16d083cc3b871ad061 /src/xbot.c | |
parent | 1d62b7e1cf80149dff8ae5dccf718d7b9bb71d67 (diff) | |
download | xbot-7897ac41444b7be10e9881ea30ed67fe14929cef.tar xbot-7897ac41444b7be10e9881ea30ed67fe14929cef.tar.zst xbot-7897ac41444b7be10e9881ea30ed67fe14929cef.zip |
Implement successful Stream Setup
Diffstat (limited to 'src/xbot.c')
-rw-r--r-- | src/xbot.c | 54 |
1 files changed, 36 insertions, 18 deletions
@@ -15,6 +15,7 @@ void parse_cli_args(int argc, char **argv, char **msg, char **jid, char **cfg); void read_xmpp_profile(char *path, char **jid, char **pwd); +void send_message(char *msg, char *recipient, char *sender, char *pwd); void conn_handler( xmpp_conn_t *const conn, const xmpp_conn_event_t status, @@ -34,24 +35,9 @@ int main(int argc, char **argv) char *my_jid = NULL; char *my_pwd = NULL; - parse_cli_args(argc, argv, &message, &target_jid, &profile_path); // get information from user + parse_cli_args(argc, argv, &message, &target_jid, &profile_path); read_xmpp_profile(profile_path, &my_jid, &my_pwd); - - // send message - /*xmpp_ctx_t *ctx; - xmpp_conn_t *conn; - xmpp_log_t *log; - xmpp_initialize(); - log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG); - ctx = xmpp_ctx_new(NULL, log); - conn = xmpp_conn_new(ctx); - xmpp_conn_set_jid(conn, my_jid); - xmpp_conn_set_pass(conn, my_pwd); - xmpp_connect_client(conn, NULL, 0, conn_handler, ctx); - xmpp_run(ctx); - xmpp_conn_release(conn); - xmpp_ctx_free(ctx); - xmpp_shutdown();*/ + send_message(message, target_jid, my_jid, my_pwd); // free memory if(message != NULL)free(message); @@ -113,6 +99,36 @@ void read_xmpp_profile(char *path, char **jid, char **pwd) } +void send_message(char *msg, char *recipient, char *sender, char *pwd) +{ + // setup some pointers and variables + xmpp_ctx_t *ctx; + xmpp_conn_t *conn; + xmpp_log_t *log; + long flags = 0; + + flags |= XMPP_CONN_FLAG_MANDATORY_TLS; // force transport encryption + xmpp_initialize(); // init libstrophe (xmpp library) + log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG); // create xmpp logger + ctx = xmpp_ctx_new(NULL, log); // create xmpp context + + // create xmpp connection, set own jabber id and password and connect + conn = xmpp_conn_new(ctx); + xmpp_conn_set_flags(conn, flags); + xmpp_conn_set_jid(conn, sender); + xmpp_conn_set_pass(conn, pwd); + xmpp_connect_client(conn, NULL, 0, conn_handler, ctx); + + xmpp_run(ctx); // event loop - conn_handler will trigger exit + + xmpp_conn_release(conn); + + // cleanup + xmpp_ctx_free(ctx); + xmpp_shutdown(); +} + + void conn_handler( xmpp_conn_t *const conn, const xmpp_conn_event_t status, @@ -121,7 +137,6 @@ void conn_handler( void *const userdata ) { - // TODO: Implement this stuff! xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; int secured; @@ -133,6 +148,9 @@ void conn_handler( fprintf(stderr, "DEBUG: connected\n"); secured = xmpp_conn_is_secured(conn); fprintf(stderr, "DEBUG: connection is %s.\n", secured ? "secured" : "NOT secured"); + + // time to play some stanzas + xmpp_disconnect(conn); } else |