Index: res/res_jabber.c =================================================================== --- res/res_jabber.c (revision 36601) +++ res/res_jabber.c (working copy) @@ -93,7 +93,6 @@ static iks *jabber_make_auth(iksid * id, const char *pass, const char *sid); static char debug_usage[] = -"Usage: JABBER debug\n" " Enables dumping of JABBER packets for debugging purposes.\n"; static char no_debug_usage[] = @@ -318,9 +317,12 @@ { struct aji_client *client = NULL; struct aji_resource *r = NULL; + struct aji_buddy *buddy = NULL; + char *s = NULL, *sender = NULL, *screenname = NULL, *resource = NULL, *variable = NULL; - int stat = 7, found = 0; + int stat = 7; char status[2]; + if (data) { s = ast_strdupa((char *) data); if (s) { @@ -340,10 +342,11 @@ return -1; } - if(!strchr(screenname, '/')) { - resource = NULL; - } else { - resource = strsep(&screenname, "/"); + s = ast_strdupa((char *) screenname); + + if (s) { + screenname = strsep(&s, "/"); + if (screenname && (screenname[0] != '\0')) resource = s; } client = ast_aji_get_client(sender); @@ -356,32 +359,21 @@ ast_log(LOG_WARNING, "No buddies for connection.\n"); return -1; } - ASTOBJ_CONTAINER_TRAVERSE(&client->buddies, 1, { - ASTOBJ_RDLOCK(iterator); - if (!strcasecmp(iterator->user, screenname)) { - found = 1; - r = iterator->resources; - if (r) { /* client has signed on */ - if (resource) { - while (r) { - if (!strcasecmp(r->resource, resource)) { - stat = r->status; - } - r = r->next; - } - if (stat == 7) ast_log(LOG_NOTICE, "Resource not found %s\n", resource); - } else { - stat = r->status; - } - } - } - ASTOBJ_UNLOCK(iterator); - }); - if (!found) { /* just a label */ - ast_log(LOG_WARNING, "Could not find Buddy in list.\n"); + buddy = ASTOBJ_CONTAINER_FIND(&client->buddies, screenname); + + if (!buddy) { /* just a label */ + ast_log(LOG_WARNING, "Could not find Buddy %s in list.\n",screenname); return -1; } + + r = aji_find_resource(buddy, resource); + + if (r) + stat = r->status; + else + ast_log(LOG_NOTICE, "Resource %s of buddy %s not found \n", resource,screenname); + sprintf(status, "%d", stat); pbx_builtin_setvar_helper(chan, variable, status); return 0;