user = (si_SignonUserStruct *) (url->signonUser_list->ElementAt(0));
PRInt32 userCount = LIST_COUNT(url->signonUser_list); for (PRInt32 i=0; i<userCount; i++) { user = NS_STATIC_CAST(si_SignonUserStruct*, url->signonUser_list->ElementAt(i));  data = (si_SignonDataStruct *) (user->signonData_list->ElementAt(0)); if (PL_strcmp(data->name, userText)) {  continue; } break; }
si_GetUser(char* URLName, PRBool pickFirstUser, char* userText) {  si_SignonURLStruct* url;  si_SignonUserStruct* user;  si_SignonDataStruct* data;  /* get to node for this URL */  url = si_GetURL(URLName);  if (url != NULL) {    /* node for this URL was found */    PRInt32 user_count;    if ((user_count = LIST_COUNT(url->signonUser_list)) == 1) {      /* only one set of data exists for this URL so select it */      user = (si_SignonUserStruct *) (url->signonUser_list->ElementAt(0));      url->chosen_user = user;    } else if (pickFirstUser) {      user = (si_SignonUserStruct *) (url->signonUser_list->ElementAt(0));      url->chosen_user = user;    } else {      /* multiple users for this URL so a choice needs to be made */      char ** list;      char ** list2;      si_SignonUserStruct** users;      si_SignonUserStruct** users2;      list = (char**)PR_Malloc(user_count*sizeof(char*));      users = (struct _SignonUserStruct **) PR_Malloc(user_count*sizeof(si_SignonUserStruct*));      list2 = list;      users2 = users;      /* if there are multiple users, we need to load in the password file       * before creating the list of usernames that we will present for        * selection.  Otherwise the ordering of the users in the file and the       * ordering of users in the list we present for selection will disagree       */      user_count = 0;      PRInt32 userCount = LIST_COUNT(url->signonUser_list);      for (PRInt32 i=0; i<userCount; i++) {        user = NS_STATIC_CAST(si_SignonUserStruct*, url->signonUser_list->ElementAt(i));        /* consider first data node to be the identifying item */        data = (si_SignonDataStruct *) (user->signonData_list->ElementAt(0));        if (PL_strcmp(data->name, userText)) {          /* name of current data item does not match name in data node */          continue;        }        user_count++;      }      if (user_count > 1) {        SI_LoadSignonData(PR_TRUE);        url = si_GetURL(URLName);        if (url == NULL) {          /* This will happen if user fails to unlock database in SI_LoadSignonData above */          PR_Free(list);          PR_Free(users);          return NULL;        }      }      /* step through set of user nodes for this URL and create list of       * first data node of each (presumably that is the user name).       * Note that the user nodes are already ordered by       * most-recently-used so the first one in the list is the most       * likely one to be chosen.       */      PRInt32 userCount2 = LIST_COUNT(url->signonUser_list);      for (PRInt32 i2=0; i2<userCount2; i2++) {        user = NS_STATIC_CAST(si_SignonUserStruct*, url->signonUser_list->ElementAt(i2));        /* consider first data node to be the identifying item */        data = (si_SignonDataStruct *) (user->signonData_list->ElementAt(0));        if (PL_strcmp(data->name, userText)) {          /* name of current data item does not match name in data node */          continue;        }        *(list2++) = data->value;        *(users2++) = user;      }      /* have user select a username from the list */      PRUnichar * selectUser = Wallet_Localize("SelectUser");      if (user_count == 0) {        /* not first data node for any saved user, so simply pick first user */        if (url->chosen_user) {          user = (si_SignonUserStruct *) (url->signonUser_list->ElementAt(0));        } else {          /* no user selection had been made for first data node */          user = NULL;        }       } else if (user_count == 1) {        /* only one user for this form at this url, so select it */        user = users[0];      } else if ((user_count > 1) && si_SelectDialog(selectUser, list, &user_count)) {        /* user pressed OK */        if (user_count == -1) {          user_count = 0; /* user didn't select, so use first one */        }        user = users[user_count]; /* this is the selected item */        /* item selected is now most-recently used, put at head of list */        url->signonUser_list->RemoveElement(user);        url->signonUser_list->InsertElementAt(user, 0);      } else {        user = NULL;      }      Recycle(selectUser);      url->chosen_user = user;      PR_Free(list);      PR_Free(users);      /* if we don't remove the URL from the cache at this point, the       * cached copy will be brought containing the last-used username       * rather than the username that was just selected       */#ifdef junk      NET_RemoveURLFromCache(NET_CreateURLStruct((char *)URLName, NET_DONT_RELOAD));#endif    }  } else {    user = NULL;  }  return user;}