/** * @brief Starts the KP, initializes state and cals all necessary functions. * * @return 0. */ int main() { // Sets handler for CTR+C signal(SIGINT, &signal_callback_handler); // Initialize smart space information and data about subscription. ss_info_t info; subs_t subs; ss_init_space_info(&info, KP_SS_NAME, KP_SS_ADDRESS, KP_SS_PORT); subs.is_subscribed = false; subs.new_triples = NULL; subs.old_triples = NULL; // In the smart space the name of the KP must be unique, if you try to // join without leave, then you received an error. if (ss_join(&info, KP_NAME) == -1) { printf("Can't join to SS.\n"); return 0; } printf("KP join to SS.\n"); // Create a subscription to <KP-says-*> triples. if (make_subscription(&info, &subs) != 0) { printf("Can't subscribe.\n"); ss_leave(&info); return 0; } printf("\nWaiting new data.\n"); // Start subscription processing, it is ends: // - when yo press CTRL+C; // - when unsubscription indication will be received from the SS; // - on error. handle_subscription(&info, &subs); // Before leave we need to unsubscribe our subscription. handle_unsubscription(&info, &subs); // Delete triples list. update_subscription_triples(&subs, NULL, NULL); ss_leave(&info); printf("\nKP leave SS...\n"); return 0; }
static int _subscribed_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); Jid *from_jid = jid_create(from); log_debug("Subscribed presence handler fired for %s", from); handle_subscription(from_jid->barejid, PRESENCE_SUBSCRIBED); autocomplete_remove(sub_requests_ac, from_jid->barejid); jid_destroy(from_jid); return 1; }