diff options
author | James Booth <boothj5@gmail.com> | 2013-02-04 02:19:31 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2013-02-04 02:19:31 +0000 |
commit | b94dc5ecdd2bc10125d06ceeb6d9d8fd70ab34c5 (patch) | |
tree | d79e5f010eea2134b8919f652f06a450f68628a4 | |
parent | eb26cab7396f472306981a052896fc20cb35464a (diff) | |
download | profani-tty-b94dc5ecdd2bc10125d06ceeb6d9d8fd70ab34c5.tar.gz |
Moved setting presence status and show into functions
-rw-r--r-- | src/xmpp/presence.c | 8 | ||||
-rw-r--r-- | src/xmpp/stanza.c | 93 | ||||
-rw-r--r-- | src/xmpp/stanza.h | 20 |
3 files changed, 58 insertions, 63 deletions
diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index d8425cd7..fc7f4293 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -123,7 +123,9 @@ presence_update(jabber_presence_t presence_type, const char * const msg, connection_set_presence_message(msg); connection_set_priority(pri); - xmpp_stanza_t *presence = stanza_create_presence(ctx, show, msg); + xmpp_stanza_t *presence = stanza_create_presence(ctx); + stanza_attach_show(ctx, presence, show); + stanza_attach_status(ctx, presence, msg); stanza_attach_priority(ctx, presence, pri); stanza_attach_last_activity(ctx, presence, idle); stanza_attach_caps(ctx, presence); @@ -165,7 +167,9 @@ presence_join_room(Jid *jid) int pri = accounts_get_priority_for_presence_type(jabber_get_account_name(), presence_type); - xmpp_stanza_t *presence = stanza_create_room_join_presence(ctx, jid->fulljid, show, status); + xmpp_stanza_t *presence = stanza_create_room_join_presence(ctx, jid->fulljid); + stanza_attach_show(ctx, presence, show); + stanza_attach_status(ctx, presence, status); stanza_attach_priority(ctx, presence, pri); stanza_attach_caps(ctx, presence); diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index f4824a0b..f7fe712c 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -86,9 +86,8 @@ stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient, } xmpp_stanza_t * -stanza_create_room_join_presence(xmpp_ctx_t *ctx, - const char * const full_room_jid, const char * const show, - const char * const status) +stanza_create_room_join_presence(xmpp_ctx_t * const ctx, + const char * const full_room_jid) { xmpp_stanza_t *presence = xmpp_stanza_new(ctx); xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE); @@ -97,31 +96,8 @@ stanza_create_room_join_presence(xmpp_ctx_t *ctx, xmpp_stanza_t *x = xmpp_stanza_new(ctx); xmpp_stanza_set_name(x, STANZA_NAME_X); xmpp_stanza_set_ns(x, STANZA_NS_MUC); - xmpp_stanza_add_child(presence, x); - if (show != NULL) { - xmpp_stanza_t *show_stanza = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(show_stanza, STANZA_NAME_SHOW); - xmpp_stanza_t *text = xmpp_stanza_new(ctx); - xmpp_stanza_set_text(text, show); - xmpp_stanza_add_child(show_stanza, text); - xmpp_stanza_add_child(presence, show_stanza); - xmpp_stanza_release(text); - xmpp_stanza_release(show_stanza); - } - - if (status != NULL) { - xmpp_stanza_t *status_stanza = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(status_stanza, STANZA_NAME_STATUS); - xmpp_stanza_t *text = xmpp_stanza_new(ctx); - xmpp_stanza_set_text(text, status); - xmpp_stanza_add_child(status_stanza, text); - xmpp_stanza_add_child(presence, status_stanza); - xmpp_stanza_release(text); - xmpp_stanza_release(status_stanza); - } - return presence; } @@ -155,34 +131,11 @@ stanza_create_room_leave_presence(xmpp_ctx_t *ctx, const char * const room, } xmpp_stanza_t * -stanza_create_presence(xmpp_ctx_t *ctx, const char * const show, - const char * const status) +stanza_create_presence(xmpp_ctx_t * const ctx) { xmpp_stanza_t *presence = xmpp_stanza_new(ctx); xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE); - if (show != NULL) { - xmpp_stanza_t *show_stanza = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(show_stanza, STANZA_NAME_SHOW); - xmpp_stanza_t *text = xmpp_stanza_new(ctx); - xmpp_stanza_set_text(text, show); - xmpp_stanza_add_child(show_stanza, text); - xmpp_stanza_add_child(presence, show_stanza); - xmpp_stanza_release(text); - xmpp_stanza_release(show_stanza); - } - - if (status != NULL) { - xmpp_stanza_t *status_stanza = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(status_stanza, STANZA_NAME_STATUS); - xmpp_stanza_t *text = xmpp_stanza_new(ctx); - xmpp_stanza_set_text(text, status); - xmpp_stanza_add_child(status_stanza, text); - xmpp_stanza_add_child(presence, status_stanza); - xmpp_stanza_release(text); - xmpp_stanza_release(status_stanza); - } - return presence; } @@ -626,7 +579,8 @@ stanza_destroy_form(DataForm *form) } void -stanza_attach_priority(xmpp_ctx_t *ctx, xmpp_stanza_t *presence, int pri) +stanza_attach_priority(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence, + const int pri) { if (pri != 0) { xmpp_stanza_t *priority, *value; @@ -644,7 +598,40 @@ stanza_attach_priority(xmpp_ctx_t *ctx, xmpp_stanza_t *presence, int pri) } void -stanza_attach_last_activity(xmpp_ctx_t *ctx, xmpp_stanza_t *presence, int idle) +stanza_attach_show(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence, + const char * const show) +{ + if (show != NULL) { + xmpp_stanza_t *show_stanza = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(show_stanza, STANZA_NAME_SHOW); + xmpp_stanza_t *text = xmpp_stanza_new(ctx); + xmpp_stanza_set_text(text, show); + xmpp_stanza_add_child(show_stanza, text); + xmpp_stanza_add_child(presence, show_stanza); + xmpp_stanza_release(text); + xmpp_stanza_release(show_stanza); + } +} + +void +stanza_attach_status(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence, + const char * const status) +{ + if (status != NULL) { + xmpp_stanza_t *status_stanza = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(status_stanza, STANZA_NAME_STATUS); + xmpp_stanza_t *text = xmpp_stanza_new(ctx); + xmpp_stanza_set_text(text, status); + xmpp_stanza_add_child(status_stanza, text); + xmpp_stanza_add_child(presence, status_stanza); + xmpp_stanza_release(text); + xmpp_stanza_release(status_stanza); + } +} + +void +stanza_attach_last_activity(xmpp_ctx_t * const ctx, + xmpp_stanza_t * const presence, const int idle) { if (idle > 0) { xmpp_stanza_t *query = xmpp_stanza_new(ctx); @@ -659,7 +646,7 @@ stanza_attach_last_activity(xmpp_ctx_t *ctx, xmpp_stanza_t *presence, int idle) } void -stanza_attach_caps(xmpp_ctx_t *ctx, xmpp_stanza_t *presence) +stanza_attach_caps(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence) { xmpp_stanza_t *caps = xmpp_stanza_new(ctx); xmpp_stanza_set_name(caps, STANZA_NAME_C); diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index 549e951c..03bd9eec 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -111,9 +111,8 @@ xmpp_stanza_t* stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient, const char * const type, const char * const message, const char * const state); -xmpp_stanza_t* stanza_create_room_join_presence(xmpp_ctx_t *ctx, - const char * const full_room_jid, const char * const show, - const char * const status); +xmpp_stanza_t* stanza_create_room_join_presence(xmpp_ctx_t * const ctx, + const char * const full_room_jid); xmpp_stanza_t* stanza_create_room_newnick_presence(xmpp_ctx_t *ctx, const char * const full_room_jid); @@ -121,8 +120,7 @@ xmpp_stanza_t* stanza_create_room_newnick_presence(xmpp_ctx_t *ctx, xmpp_stanza_t* stanza_create_room_leave_presence(xmpp_ctx_t *ctx, const char * const room, const char * const nick); -xmpp_stanza_t* stanza_create_presence(xmpp_ctx_t *ctx, const char * const show, - const char * const status); +xmpp_stanza_t* stanza_create_presence(xmpp_ctx_t * const ctx); xmpp_stanza_t* stanza_create_roster_iq(xmpp_ctx_t *ctx); xmpp_stanza_t* stanza_create_ping_iq(xmpp_ctx_t *ctx); @@ -150,9 +148,15 @@ gboolean stanza_is_version_request(xmpp_stanza_t * const stanza); DataForm * stanza_create_form(xmpp_stanza_t * const stanza); void stanza_destroy_form(DataForm *form); -void stanza_attach_priority(xmpp_ctx_t *ctx, xmpp_stanza_t *presence, int pri); -void stanza_attach_last_activity(xmpp_ctx_t *ctx, xmpp_stanza_t *presence, int idle); -void stanza_attach_caps(xmpp_ctx_t *ctx, xmpp_stanza_t *presence); +void stanza_attach_priority(xmpp_ctx_t * const ctx, + xmpp_stanza_t * const presence, const int pri); +void stanza_attach_last_activity(xmpp_ctx_t * const ctx, + xmpp_stanza_t * const presence, const int idle); +void stanza_attach_caps(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence); +void stanza_attach_show(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence, + const char * const show); +void stanza_attach_status(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence, + const char * const status); const char * stanza_get_presence_string_from_type(jabber_presence_t presence_type); |