aboutsummaryrefslogtreecommitdiffstats
path: root/res/res_jabber.c
diff options
context:
space:
mode:
authorphsultan <phsultan@f38db490-d61c-443f-a65b-d21fe96a405b>2008-06-24 17:50:22 +0000
committerphsultan <phsultan@f38db490-d61c-443f-a65b-d21fe96a405b>2008-06-24 17:50:22 +0000
commita18b73d79c955957986d1d2c5dc6fda119ca709b (patch)
treec003082ee2aecca9c966e5c3ad192ec53b1dd76a /res/res_jabber.c
parenta8afa354898d5756808a5745265ea9ffd78e98d2 (diff)
Subscribe to buddy's presence only if we really need to. That is, if
the corresponding roster item has a subscription value set to "none" or "from". Make the code more readable. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@124872 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res/res_jabber.c')
-rw-r--r--res/res_jabber.c47
1 files changed, 27 insertions, 20 deletions
diff --git a/res/res_jabber.c b/res/res_jabber.c
index 85a33328d..98a21c6ab 100644
--- a/res/res_jabber.c
+++ b/res/res_jabber.c
@@ -2137,26 +2137,33 @@ static int aji_filter_roster(void *data, ikspak *pak)
ASTOBJ_UNLOCK(iterator);
});
- if (!flag) {
- buddy = ast_calloc(1, sizeof(*buddy));
- if (!buddy) {
- ast_log(LOG_WARNING, "Out of memory\n");
- return 0;
- }
- ASTOBJ_INIT(buddy);
- ASTOBJ_WRLOCK(buddy);
- ast_copy_string(buddy->name, iks_find_attrib(x, "jid"), sizeof(buddy->name));
- ast_clear_flag(&buddy->flags, AST_FLAGS_ALL);
- if(ast_test_flag(&client->flags, AJI_AUTOPRUNE)) {
- ast_set_flag(&buddy->flags, AJI_AUTOPRUNE);
- ASTOBJ_MARK(buddy);
- } else
- ast_set_flag(&buddy->flags, AJI_AUTOREGISTER);
- ASTOBJ_UNLOCK(buddy);
- if (buddy) {
- ASTOBJ_CONTAINER_LINK(&client->buddies, buddy);
- ASTOBJ_UNREF(buddy, aji_buddy_destroy);
- }
+ if (flag) {
+ /* found buddy, don't create a new one */
+ x = iks_next(x);
+ continue;
+ }
+
+ buddy = ast_calloc(1, sizeof(*buddy));
+ if (!buddy) {
+ ast_log(LOG_WARNING, "Out of memory\n");
+ return 0;
+ }
+ ASTOBJ_INIT(buddy);
+ ASTOBJ_WRLOCK(buddy);
+ ast_copy_string(buddy->name, iks_find_attrib(x, "jid"), sizeof(buddy->name));
+ ast_clear_flag(&buddy->flags, AST_FLAGS_ALL);
+ if(ast_test_flag(&client->flags, AJI_AUTOPRUNE)) {
+ ast_set_flag(&buddy->flags, AJI_AUTOPRUNE);
+ ASTOBJ_MARK(buddy);
+ } else if (!iks_strcmp(iks_find_attrib(x, "subscription"), "none") || !iks_strcmp(iks_find_attrib(x, "subscription"), "from")) {
+ /* subscribe to buddy's presence only
+ if we really need to */
+ ast_set_flag(&buddy->flags, AJI_AUTOREGISTER);
+ }
+ ASTOBJ_UNLOCK(buddy);
+ if (buddy) {
+ ASTOBJ_CONTAINER_LINK(&client->buddies, buddy);
+ ASTOBJ_UNREF(buddy, aji_buddy_destroy);
}
}
x = iks_next(x);