Example #1
0
/*
 * Search accounts on given fields, returning results into ret_list.
 *
 * @pattern - a basic regular expression
 * @fields - which fields to search on
 */
void find_matching_regex(struct list_head *accounts, const char *pattern,
			 int fields, struct list_head *ret_list)
{
	regex_t regex;

	if (regcomp(&regex, pattern, REG_ICASE))
		die("Invalid regex '%s'", pattern);
	search_accounts(accounts, &regex, cmp_regex, fields, ret_list);
	regfree(&regex);
}
Example #2
0
/*
 * Search blob for any and all accounts matching a given name.
 * Matching accounts are appended to ret_list which should be initialized
 * by the caller.
 *
 * In the case of an id match, we return only the matching id entry.
 */
void find_matching_accounts(struct blob *blob, const char *name,
			    struct list_head *ret_list)
{
	/* look for exact id match */
	for (struct account *account = blob->account_head; account; account = account->next) {
		if (strcmp(name, "0") && !strcasecmp(account->id, name)) {
			list_add_tail(&account->match_list, ret_list);
			/* if id match, stop processing */
			return;
		}
	}

	/* search for fullname or name match */
	search_accounts(blob, name, strcmp, ACCOUNT_NAME | ACCOUNT_FULLNAME,
			ret_list);
}
Example #3
0
/*
 * Search list of accounts for any and all accounts matching a given name.
 * Matching accounts are appended to ret_list which should be initialized
 * by the caller.
 *
 * In the case of an id match, we return only the matching id entry.
 */
void find_matching_accounts(struct list_head *accounts, const char *name,
			    struct list_head *ret_list)
{
	/* look for exact id match */
	struct account *account;
	list_for_each_entry(account, accounts, match_list) {
		if (strcmp(name, "0") && !strcasecmp(account->id, name)) {
			list_del(&account->match_list);
			list_add_tail(&account->match_list, ret_list);
			/* if id match, stop processing */
			return;
		}
	}

	/* search for fullname or name match */
	search_accounts(accounts, name, strcmp,
			ACCOUNT_NAME | ACCOUNT_FULLNAME,
			ret_list);
}
Example #4
0
/*
 * Search accounts on name, username, and url fields, adding all matches
 * into ret_list.
 *
 * @pattern - a basic regular expression
 * @fields - which fields to search on
 */
void find_matching_substr(struct list_head *accounts, const char *pattern,
			  int fields, struct list_head *ret_list)
{
	search_accounts(accounts, pattern, cmp_substr, fields, ret_list);
}