1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Implemented add bookmark for XEP-0223

Issue #194
This commit is contained in:
James Booth 2014-02-02 02:39:36 +00:00
parent 3dc5f60f3d
commit 9394091f04
3 changed files with 106 additions and 2 deletions

View File

@ -6,6 +6,7 @@
#include <glib.h> #include <glib.h>
#include <strophe.h> #include <strophe.h>
#include "common.h"
#include "log.h" #include "log.h"
#include "muc.h" #include "muc.h"
#include "ui/ui.h" #include "ui/ui.h"
@ -65,7 +66,103 @@ _bookmark_add(const char *jid, const char *nick, gboolean autojoin)
if (autocomplete_contains(bookmark_ac, jid)) { if (autocomplete_contains(bookmark_ac, jid)) {
added = FALSE; added = FALSE;
} }
xmpp_conn_t *conn = connection_get_conn();
xmpp_ctx_t *ctx = connection_get_ctx();
/* TODO: send request */ /* TODO: send request */
xmpp_stanza_t *stanza = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(stanza, STANZA_NAME_IQ);
char *id = generate_unique_id("bookmark_add");
xmpp_stanza_set_id(stanza, id);
xmpp_stanza_set_type(stanza, STANZA_TYPE_SET);
xmpp_stanza_t *pubsub = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(pubsub, STANZA_NAME_PUBSUB);
xmpp_stanza_set_ns(pubsub, STANZA_NS_PUBSUB);
xmpp_stanza_add_child(stanza, pubsub);
xmpp_stanza_t *publish = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(publish, STANZA_NAME_PUBLISH);
xmpp_stanza_set_attribute(publish, STANZA_ATTR_NODE, "storage:bookmarks");
xmpp_stanza_add_child(pubsub, publish);
xmpp_stanza_t *item = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(item, STANZA_NAME_ITEM);
xmpp_stanza_set_attribute(item, STANZA_ATTR_ID, "current");
xmpp_stanza_add_child(publish, item);
xmpp_stanza_t *storage = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(storage, STANZA_NAME_STORAGE);
xmpp_stanza_set_ns(storage, "storage;bookmarks");
xmpp_stanza_add_child(item, storage);
xmpp_stanza_t *conference = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(conference, STANZA_NAME_CONFERENCE);
xmpp_stanza_set_attribute(conference, STANZA_ATTR_JID, jid);
if (autojoin) {
xmpp_stanza_set_attribute(conference, STANZA_ATTR_AUTOJOIN, "true");
} else {
xmpp_stanza_set_attribute(conference, STANZA_ATTR_AUTOJOIN, "false");
}
xmpp_stanza_add_child(storage, conference);
if (nick != NULL) {
xmpp_stanza_t *nick_st = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(nick_st, STANZA_NAME_NICK);
xmpp_stanza_set_text(nick_st, nick);
xmpp_stanza_add_child(conference, nick_st);
}
xmpp_stanza_t *publish_options = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(publish_options, STANZA_NAME_PUBLISH_OPTIONS);
xmpp_stanza_add_child(pubsub, publish_options);
xmpp_stanza_t *x = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(x, STANZA_NAME_X);
xmpp_stanza_set_ns(x, STANZA_NS_DATA);
xmpp_stanza_set_attribute(x, STANZA_ATTR_TYPE, "submit");
xmpp_stanza_add_child(publish_options, x);
xmpp_stanza_t *form_type = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(form_type, STANZA_NAME_FIELD);
xmpp_stanza_set_attribute(form_type, STANZA_ATTR_VAR, "FORM_TYPE");
xmpp_stanza_set_attribute(form_type, STANZA_ATTR_TYPE, "hidden");
xmpp_stanza_t *form_type_value = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(form_type_value, STANZA_NAME_VALUE);
xmpp_stanza_t *form_type_value_text = xmpp_stanza_new(ctx);
xmpp_stanza_set_text(form_type_value_text, "http://jabber.org/protocol/pubsub#publish-options");
xmpp_stanza_add_child(form_type_value, form_type_value_text);
xmpp_stanza_add_child(form_type, form_type_value);
xmpp_stanza_add_child(x, form_type);
xmpp_stanza_t *persist_items = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(persist_items, STANZA_NAME_FIELD);
xmpp_stanza_set_attribute(persist_items, STANZA_ATTR_VAR, "pubsub#persist_items");
xmpp_stanza_t *persist_items_value = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(persist_items_value, STANZA_NAME_VALUE);
xmpp_stanza_t *persist_items_value_text = xmpp_stanza_new(ctx);
xmpp_stanza_set_text(persist_items_value_text, "true");
xmpp_stanza_add_child(persist_items_value, persist_items_value_text);
xmpp_stanza_add_child(persist_items, persist_items_value);
xmpp_stanza_add_child(x, persist_items);
xmpp_stanza_t *access_model = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(access_model, STANZA_NAME_FIELD);
xmpp_stanza_set_attribute(access_model, STANZA_ATTR_VAR, "pubsub#access_model");
xmpp_stanza_t *access_model_value = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(access_model_value, STANZA_NAME_VALUE);
xmpp_stanza_t *access_model_value_text = xmpp_stanza_new(ctx);
xmpp_stanza_set_text(access_model_value_text, "whitelist");
xmpp_stanza_add_child(access_model_value, access_model_value_text);
xmpp_stanza_add_child(access_model, access_model_value);
xmpp_stanza_add_child(x, access_model);
xmpp_send(conn, stanza);
xmpp_stanza_release(stanza);
/* TODO: manage bookmark_list */ /* TODO: manage bookmark_list */
/* this may be command for modifying */ /* this may be command for modifying */

View File

@ -36,7 +36,6 @@
static int _field_compare(FormField *f1, FormField *f2); static int _field_compare(FormField *f1, FormField *f2);
#if 0
xmpp_stanza_t * xmpp_stanza_t *
stanza_create_storage_bookmarks(xmpp_ctx_t *ctx) stanza_create_storage_bookmarks(xmpp_ctx_t *ctx)
{ {
@ -63,8 +62,8 @@ stanza_create_storage_bookmarks(xmpp_ctx_t *ctx)
return iq; return iq;
} }
#endif
#if 0
xmpp_stanza_t * xmpp_stanza_t *
stanza_create_storage_bookmarks(xmpp_ctx_t *ctx) stanza_create_storage_bookmarks(xmpp_ctx_t *ctx)
{ {
@ -92,6 +91,7 @@ stanza_create_storage_bookmarks(xmpp_ctx_t *ctx)
return iq; return iq;
} }
#endif
xmpp_stanza_t * xmpp_stanza_t *
stanza_create_chat_state(xmpp_ctx_t *ctx, const char * const recipient, stanza_create_chat_state(xmpp_ctx_t *ctx, const char * const recipient,

View File

@ -46,6 +46,7 @@
#define STANZA_NAME_TEXT "text" #define STANZA_NAME_TEXT "text"
#define STANZA_NAME_SUBJECT "subject" #define STANZA_NAME_SUBJECT "subject"
#define STANZA_NAME_ITEM "item" #define STANZA_NAME_ITEM "item"
#define STANZA_NAME_ITEMS "items"
#define STANZA_NAME_C "c" #define STANZA_NAME_C "c"
#define STANZA_NAME_IDENTITY "identity" #define STANZA_NAME_IDENTITY "identity"
#define STANZA_NAME_FEATURE "feature" #define STANZA_NAME_FEATURE "feature"
@ -53,8 +54,13 @@
#define STANZA_NAME_REASON "reason" #define STANZA_NAME_REASON "reason"
#define STANZA_NAME_GROUP "group" #define STANZA_NAME_GROUP "group"
#define STANZA_NAME_PUBSUB "pubsub" #define STANZA_NAME_PUBSUB "pubsub"
#define STANZA_NAME_PUBLISH "publish"
#define STANZA_NAME_PUBLISH_OPTIONS "publish-options"
#define STANZA_NAME_FIELD "field"
#define STANZA_NAME_STORAGE "storage" #define STANZA_NAME_STORAGE "storage"
#define STANZA_NAME_NICK "nick"
#define STANZA_NAME_CONFERENCE "conference" #define STANZA_NAME_CONFERENCE "conference"
#define STANZA_NAME_VALUE "value"
// error conditions // error conditions
#define STANZA_NAME_BAD_REQUEST "bad-request" #define STANZA_NAME_BAD_REQUEST "bad-request"
@ -110,6 +116,7 @@
#define STANZA_ATTR_HASH "hash" #define STANZA_ATTR_HASH "hash"
#define STANZA_ATTR_CATEGORY "category" #define STANZA_ATTR_CATEGORY "category"
#define STANZA_ATTR_REASON "reason" #define STANZA_ATTR_REASON "reason"
#define STANZA_ATTR_AUTOJOIN "autojoin"
#define STANZA_TEXT_AWAY "away" #define STANZA_TEXT_AWAY "away"
#define STANZA_TEXT_DND "dnd" #define STANZA_TEXT_DND "dnd"