Date: Fri, 12 Jul 2013 17:47:09 GMT From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r254696 - soc2013/mattbw/backend Message-ID: <201307121747.r6CHl9TZ092525@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mattbw Date: Fri Jul 12 17:47:08 2013 New Revision: 254696 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254696 Log: fix segfault with search group; search functions now use common search function. Added: soc2013/mattbw/backend/search.c soc2013/mattbw/backend/search.h Modified: soc2013/mattbw/backend/Makefile soc2013/mattbw/backend/group.c Modified: soc2013/mattbw/backend/Makefile ============================================================================== --- soc2013/mattbw/backend/Makefile Fri Jul 12 16:41:58 2013 (r254695) +++ soc2013/mattbw/backend/Makefile Fri Jul 12 17:47:08 2013 (r254696) @@ -9,6 +9,7 @@ group.c \ licenses.c \ pkgutils.c \ + search.c \ utils.c SRCS+= \ actions/get_details.c \ Modified: soc2013/mattbw/backend/group.c ============================================================================== --- soc2013/mattbw/backend/group.c Fri Jul 12 16:41:58 2013 (r254695) +++ soc2013/mattbw/backend/group.c Fri Jul 12 17:47:08 2013 (r254696) @@ -130,7 +130,7 @@ if (sb != NULL) { bool at_least_one; unsigned int i; - const struct group_mapping *map; + unsigned int j; at_least_one = false; @@ -138,13 +138,14 @@ (void)sbuf_putc(sb, '('); /* Quadratic time, any improvements welcomed */ - for (map = group_mappings; map->key[0] != '\0'; map++) { - for (i = 0; i < groupc; i++) { - if (map->group == groupv[i]) { + for (i = 0; i < num_group_mappings; i++) { + for (j = 0; j < groupc; j++) { + if (group_mappings[i].group == groupv[j]) { if (at_least_one) (void)sbuf_putc(sb, '|'); - (void)sbuf_cat(sb, map->key); + (void)sbuf_cat(sb, + group_mappings[i].key); at_least_one = true; } Added: soc2013/mattbw/backend/search.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/search.c Fri Jul 12 17:47:08 2013 (r254696) @@ -0,0 +1,63 @@ +/*- + * Copyright (C) 2013 Matt Windsor <mattbw@FreeBSD.org> + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <stdbool.h> /* bool */ +#include "pkg.h" /* pkg_... */ + +#include "pkgutils.h" /* pkgutils_... */ +#include "search.h" /* search_... */ + +/* + * Performs the search specified by the given "struct search" and emits each + * result according to the likewise-specified filter set. + */ +bool +search_do(struct search *search) +{ + bool success; + struct pkgdb_it *it; + + success = false; + it = pkgdb_search(search->db, + search->term, + search->type, + search->in, + search->sort_by, + NULL); + + if (it != NULL) { + struct pkg *pkg; + + pkg = NULL; + while (pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC) == EPKG_OK) { + pkgutils_add_old_version(search->db, pkg); + pkgutils_emit_filtered(pkg, + search->backend, + search->filters, + pkgutils_pkg_current_state(pkg)); + } + + success = true; + pkg_free(pkg); + } + + pkgdb_it_free(it); + return success; +} Added: soc2013/mattbw/backend/search.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/search.h Fri Jul 12 17:47:08 2013 (r254696) @@ -0,0 +1,43 @@ +/*- + * Copyright (C) 2013 Matt Windsor <mattbw@FreeBSD.org> + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <stdbool.h> /* bool */ +#include "pk-backend.h" /* Pk... */ +#include "pkg.h" /* match_t, pkgdb... */ + +#ifndef _PKGNG_BACKEND_SEARCH_H_ +#define _PKGNG_BACKEND_SEARCH_H_ + +/* + * Structure collating the various inputs to a search. + */ +struct search { + match_t type; + pkgdb_field in; + pkgdb_field sort_by; + PkBitfield filters; + char *term; + struct pkgdb *db; + PkBackend *backend; +}; + +bool search_do(struct search *search); + +#endif /* _PKGNG_BACKEND_SEARCH_H_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201307121747.r6CHl9TZ092525>