Date: Sun, 17 Oct 2010 22:52:53 GMT From: David Forsythe <dforsyth@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 184839 for review Message-ID: <201010172252.o9HMqrGa004556@skunkworks.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@184839?ac=10 Change 184839 by dforsyth@skunk on 2010/10/17 22:51:57 drop pkg_property. fetched structs are safe from the client. Affected files ... .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/Makefile#5 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/database.c#4 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/database.h#4 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/database_internal.h#4 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/depend.c#2 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/depend.h#2 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/file.c#2 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/file.h#2 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/freebsd_database_directorydb.c#4 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/freebsd_database_directorydb.h#4 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/freebsd_plist.c#4 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/freebsd_plist.h#4 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg.c#5 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg.h#5 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg_internal.h#4 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg_pkg.h#4 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/property.c#3 delete .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/property.h#3 delete .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/util.c#3 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/util.h#3 edit .. //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_dump/pkg_dump.c#3 edit Differences ... ==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/Makefile#5 (text+ko) ==== @@ -11,7 +11,6 @@ SRCS= pkg.c \ - property.c \ database.c \ repository.c \ freebsd_plist.c \ ==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/database.c#4 (text+ko) ==== @@ -132,7 +132,8 @@ } struct pkg * -pkg_db_add(struct pkg_db *db, const char *key) +pkg_db_add(struct pkg_db *db, const char *name, const char *origin, + const char *comment, const char *description) { struct pkg *pkg; @@ -142,7 +143,7 @@ } /* Do the add and set up pkg. */ - if (db->add(db, pkg, key) != PKG_OK) { + if (db->add(db, pkg, name, origin, comment, description) != PKG_OK) { pkg_free(pkg); return (NULL); } ==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/database.h#4 (text+ko) ==== @@ -25,7 +25,8 @@ * allocates a package if the package is NOT already in the db. */ /* Create a pkg in a pkg_db. If the pkg already exists, returns NULL. */ -struct pkg *pkg_db_add(struct pkg_db *, const char *); +struct pkg *pkg_db_add(struct pkg_db *, const char *, const char *, + const char *, const char *); /* Get a pkg from a pkg_db. If the package does not exist, returns NULL. */ struct pkg *pkg_db_get(struct pkg_db *, const char *); ==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/database_internal.h#4 (text+ko) ==== @@ -15,7 +15,9 @@ /* Internal db pointer for whatever backend is in use. */ void *internal; - int (*add) (struct pkg_db *, struct pkg *, const char *); + int (*add) (struct pkg_db *, struct pkg *, + const char *, const char *, const char *, + const char *); int (*close) (struct pkg_db *); int (*contains) (struct pkg_db *, const char *); int (*get) (struct pkg_db *, struct pkg *, ==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/depend.c#2 (text+ko) ==== @@ -1,5 +1,15 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + #include "depend.h" +struct pkg_depend * +pkg_depend_alloc(void) +{ + return (calloc(1, sizeof(struct pkg_depend))); +} + const char * pkg_depend_name(struct pkg_depend *dep) { @@ -7,7 +17,25 @@ } const char * +pkg_depend_origin(struct pkg_depend *dep) +{ + return (dep->origin); +} + +const char * pkg_depend_version(struct pkg_depend *dep) { return (dep->name); } + +void +_pkg_depend_set_name(struct pkg_depend *dep, const char *name) +{ + strncpy(dep->name, name, PATH_MAX); +} + +void +_pkg_depend_set_origin(struct pkg_depend *dep, const char *origin) +{ + strncpy(dep->origin, origin, PATH_MAX); +} ==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/depend.h#2 (text+ko) ==== @@ -1,16 +1,27 @@ #ifndef __LIBPKG_DEPEND_H__ #define __LIBPKG_DEPEND_H__ +#include <limits.h> +#include <sys/queue.h> + struct pkg_depend { char name[PATH_MAX]; - char version[PATH_MAX]; + char version[256]; + char origin[PATH_MAX]; TAILQ_ENTRY(pkg_depend) next; }; TAILQ_HEAD(pkg_depend_list, pkg_depend); +struct pkg_depend *pkg_depend_alloc(void); const char *pkg_depend_name(struct pkg_depend *); +const char *pkg_depend_origin(struct pkg_depend *); const char *pkg_depend_version(struct pkg_depend *); +void _pkg_depend_set_name(struct pkg_depend *, + const char *); +void _pkg_depend_set_origin(struct pkg_depend *, + const char *); + #endif ==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/file.c#2 (text+ko) ==== @@ -1,7 +1,11 @@ #include <stdlib.h> #include <stdio.h> +#include <string.h> #include "file.h" +#include "util.h" + +/* Files can only be created or deleted, never modified. */ struct pkg_file * pkg_file_alloc(void) @@ -12,11 +16,66 @@ const char * pkg_file_prefix(struct pkg_file *file) { - return (file->prefix(file)); + return (file->prefix); +} + +void +_pkg_file_set_prefix(struct pkg_file *file, const char *prefix) +{ + strncpy(file->prefix, prefix, PATH_MAX); } const char * pkg_file_pathname(struct pkg_file *file) { - return (file->pathname(file)); + return (file->pathname); +} + +void +_pkg_file_set_pathname(struct pkg_file *file, const char *pathname) +{ + strncpy(file->pathname, pathname, PATH_MAX); +} + +int +pkg_file_ignore(struct pkg_file *file) +{ + return (file->ignore); +} + +void +_pkg_file_set_ignore(struct pkg_file *file) +{ + file->ignore = 1; +} + +const char * +pkg_file_hash(struct pkg_file *file) +{ + return (file->hash); +} + +const char * +pkg_file_update_hash(struct pkg_file *file) +{ + return (file->update_hash(file)); +} + +void +_pkg_file_set_hash(struct pkg_file *file, const char *hash) +{ + strncpy(file->hash, hash, 33); +} + +const struct stat * +pkg_file_stat(struct pkg_file *file) +{ + char final[PATH_MAX]; + + _pkg_util_path_join(final, file->prefix, file->pathname); + + /* there's no stat_r, are we thread safe? */ + if (stat(final, &file->sb) < 0) return (NULL); + + return ((const struct stat *)&file->sb); } ==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/file.h#2 (text+ko) ==== @@ -14,9 +14,14 @@ /* The package that this file is in. */ struct pkg *pkg; - - const char *(*prefix) (struct pkg_file *); - const char *(*pathname) (struct pkg_file *); + + char prefix[PATH_MAX]; + char pathname[PATH_MAX]; + int ignore; + + char hash[33]; + + const char *(*update_hash) (struct pkg_file *); TAILQ_ENTRY(pkg_file) next; }; @@ -27,7 +32,16 @@ const char *pkg_file_prefix(struct pkg_file *); const char *pkg_file_pathname(struct pkg_file *); +int pkg_file_ignore(struct pkg_file *); +const char *pkg_file_hash(struct pkg_file *); +const char *pkg_file_update_hash(struct pkg_file *); const struct stat *pkg_file_stat(struct pkg_file *); +void _pkg_file_set_prefix(struct pkg_file *, const char *); +void _pkg_file_set_pathname(struct pkg_file *, + const char *); +void _pkg_file_set_ignore(struct pkg_file *); +void _pkg_file_set_hash(struct pkg_file *, const char *); + #endif ==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/freebsd_database_directorydb.c#4 (text+ko) ==== @@ -21,6 +21,7 @@ #include "freebsd_plist.h" #include "file.h" +#include "depend.h" struct _read_plist { struct pkg_property *plist; @@ -67,26 +68,14 @@ { 0, NULL, NULL }, }; -static const char *fbsd_directorydb_pkg_origin(struct pkg *); -static const char *fbsd_directorydb_pkg_name(struct pkg *); -static const char *fbsd_directorydb_pkg_comment(struct pkg *); -static const char *fbsd_directorydb_pkg_description(struct pkg *); -static const char *fbsd_directorydb_get_string_property( - struct _directorydb *, const char *, - const char *, uint32_t); -static struct pkg_property *fbsd_directorydb_get_plist( - struct _directorydb *, const char *); static int fbsd_directorydb_read_pkg( - struct _directorydb *, const char *, - struct pkg_property *, uint32_t); + struct _directorydb *, struct pkg *); static char *read_file(const char *); static int _read_plist_cmp(struct _read_plist *, struct _read_plist *); -static int dselect(const struct dirent *ent); -static void fbsd_pkg_setup(struct pkg_db *, - struct pkg *pkg, const char *key); -static int fbsd_directorydb_property_to_file( - struct pkg_property *, struct pkg_file *file); +static int dselect(const struct dirent *); +static void fbsd_directorydb_pkg_setup(struct pkg_db *, + struct pkg *, const char *); RB_GENERATE_STATIC(plist_head, _read_plist, entry, _read_plist_cmp); @@ -187,22 +176,19 @@ } static void -fbsd_pkg_setup(struct pkg_db *db, struct pkg *pkg, const char *key) +fbsd_directorydb_pkg_setup(struct pkg_db *db, struct pkg *pkg, const char *key) { - if (pkg == NULL) { - return; - } - pkg->magic = PKG_DIRDB_MAGIC; pkg->source = db; strcpy(pkg->key, key); - pkg->name = fbsd_directorydb_pkg_name; - pkg->origin = fbsd_directorydb_pkg_origin; - pkg->comment = fbsd_directorydb_pkg_comment; - pkg->description = fbsd_directorydb_pkg_description; - - pkg->files = fbsd_directorydb_files; + pkg->add_file = fbsd_directorydb_add_file; + + pkg->files = malloc(sizeof(*pkg->files)); + TAILQ_INIT(pkg->files); + + pkg->depends = malloc(sizeof(*pkg->depends)); + TAILQ_INIT(pkg->depends); } struct pkg_list * @@ -225,7 +211,14 @@ TAILQ_INIT(list); for (int i = 0; i < c; ++i) { pkg = pkg_alloc(); - fbsd_pkg_setup(db, pkg, ents[i]->d_name); + /* XXX: I should just do a get here. */ + fbsd_directorydb_pkg_setup(db, pkg, ents[i]->d_name); + /* XXX: For now just hit every mask. */ + if (fbsd_directorydb_read_pkg(d, pkg) != PKG_OK) { + /* Do clean up */ + printf("bad read\n"); + return (NULL); + } TAILQ_INSERT_TAIL(list, pkg, next); free(ents[i]); } @@ -234,109 +227,15 @@ return (list); } -#define fbsd_directorydb_list(fn_name, list_type, type, list_name, data_loc, converter) \ -struct list_type * \ -fn_name(struct pkg *pkg) \ -{ \ - struct type *a; \ - struct pkg_property *plist; \ - struct pkg_property *property_list; \ - struct pkg_property *property_node; \ - struct list_type *list; \ - struct _directorydb *d; \ - struct pkg_db *db; \ - const char *key; \ - list = malloc(sizeof(*list)); \ - if (list == NULL) return (NULL); \ - TAILQ_INIT(list); \ - db = pkg->source; \ - d = db->internal; \ - key = pkg->key; \ - plist = fbsd_directorydb_get_plist(d, key); \ - if (plist == NULL) return (NULL); \ - property_list = pkg_property_dict_get_property(plist, list_name); \ - if (property_list == NULL) { \ - fbsd_directorydb_read_pkg(d, key, plist, data_loc); \ - property_list = pkg_property_dict_get_property(plist, \ - list_name); \ - } \ - if (property_list == NULL) return (NULL); \ - property_node = NULL; \ - while ((property_node = pkg_property_list_get_next_property( \ - property_list, property_node)) != NULL) { \ - a = malloc(sizeof(*a)); \ - converter(property_node, a); \ - TAILQ_INSERT_TAIL(list, a, next); \ - } \ - return (list); \ -} - -fbsd_directorydb_list(fbsd_directorydb_files, pkg_file_list, pkg_file, FBSD_FILES, - CONTENTS, fbsd_directorydb_property_to_file); - -#if 0 -struct pkg_file_list * -fbsd_directorydb_files(struct pkg *pkg) +struct pkg_file * +fbsd_directorydb_add_file(struct pkg *pkg, const char *prefix, + const char *pathname) { - struct pkg_file *file; - struct pkg_property *plist; - struct pkg_property *file_list; - struct pkg_property *file_node; - struct pkg_file_list *list; - struct _directorydb *d; - struct pkg_db *db; - const char *key; - - list = malloc(sizeof(*list)); - if (list == NULL) return (NULL); - TAILQ_INIT(list); - - db = pkg->source; - d = db->internal; - key = pkg->key; - - plist = fbsd_directorydb_get_plist(d, key); - if (plist == NULL) { - return (NULL); - } - - - file_list = pkg_property_dict_get_property(plist, FBSD_FILES); - if (file_list == NULL) { - fbsd_directorydb_read_pkg(d, key, plist, CONTENTS); - file_list = pkg_property_dict_get_property(plist, FBSD_FILES); - } - if (file_list == NULL) { - return (NULL); - } - - file_node = NULL; - while ((file_node = pkg_property_list_get_next_property(file_list, - file_node)) != NULL) { - file = pkg_file_alloc(); - fbsd_directorydb_property_to_file(file_node, file); - TAILQ_INSERT_TAIL(list, file, next); - } - - return (list); + (void)pkg; + (void)prefix; + (void)pathname; + return (NULL); } -#endif - -static int -fbsd_directorydb_property_to_file(struct pkg_property *node, - struct pkg_file *file) -{ - struct pkg_property *string; - - /* Should probably assert that node is a dict... */ - - string = pkg_property_dict_get_property(node, FBSD_PATHNAME); - strcpy(file->pathname, pkg_property_string_get_string(string)); - string = pkg_property_dict_get_property(node, FBSD_PREFIX); - strcpy(file->prefix, pkg_property_string_get_string(string)); - - return (PKG_OK); -} int fbsd_directorydb_contains(struct pkg_db *db, const char *key) @@ -359,7 +258,8 @@ } int -fbsd_directorydb_add(struct pkg_db *db, struct pkg *pkg, const char *name) +fbsd_directorydb_add(struct pkg_db *db, struct pkg *pkg, const char *name, + const char *origin, const char *comment, const char *description) { struct _directorydb *d; char path[PATH_MAX]; @@ -376,15 +276,17 @@ pkg->magic = PKG_DIRDB_MAGIC; pkg->source = db; pkg->plist = NULL; + + strncpy(pkg->origin, origin, PATH_MAX); + strncpy(pkg->name, name, PATH_MAX); + strncpy(pkg->comment, comment, 120); + pkg->description = strdup(description); - pkg->origin = fbsd_directorydb_pkg_origin; - pkg->name = fbsd_directorydb_pkg_name; - return (r == 0 ? PKG_OK : PKG_NOT_OK); } int -fbsd_directorydb_get(struct pkg_db *db, struct pkg *pkg, const char *name) +fbsd_directorydb_get(struct pkg_db *db, struct pkg *pkg, const char *key) { struct _directorydb *d; char path[PATH_MAX]; @@ -394,134 +296,21 @@ strcpy(path, d->path); strcat(path, "/"); - strcat(path, name); + strcat(path, key); if (stat(path, &sb) < 0) { - printf("no stat %s\n", name); + printf("no stat %s\n", key); return (PKG_NOT_OK); } - pkg->magic = PKG_DIRDB_MAGIC; - pkg->source = db; - pkg->plist = NULL; - - pkg->origin = fbsd_directorydb_pkg_origin; - pkg->name = fbsd_directorydb_pkg_name; + fbsd_directorydb_pkg_setup(db, pkg, key); + fbsd_directorydb_read_pkg(d, pkg); return (PKG_OK); } -static const char * -fbsd_directorydb_pkg_origin(struct pkg *pkg) -{ - struct pkg_db *db; - struct _directorydb *d; - - _pkg_check_magic(pkg); - - db = pkg->source; - _db_check_magic(db); - d = db->internal; - - return (fbsd_directorydb_get_string_property(d, pkg->key, FBSD_ORIGIN, - CONTENTS)); -} - -static const char * -fbsd_directorydb_pkg_name(struct pkg *pkg) -{ - struct pkg_db *db; - struct _directorydb *d; - - _pkg_check_magic(pkg); - - db = pkg->source; - _db_check_magic(db); - d = db->internal; - - - return (fbsd_directorydb_get_string_property(d, pkg->key, FBSD_NAME, - CONTENTS)); -} - -static const char * -fbsd_directorydb_pkg_comment(struct pkg *pkg) -{ - struct pkg_db *db; - struct _directorydb *d; - - _pkg_check_magic(pkg); - db = pkg->source; - _db_check_magic(db); - d = db->internal; - - return (fbsd_directorydb_get_string_property(d, pkg->key, - FBSD_METANAME_COMMENT, COMMENT)); -} - -static const char * -fbsd_directorydb_pkg_description(struct pkg *pkg) -{ - struct pkg_db *db; - struct _directorydb *d; - - _pkg_check_magic(pkg); - db = pkg->source; - _db_check_magic(db); - d = db->internal; - - return (fbsd_directorydb_get_string_property(d, pkg->key, - FBSD_METANAME_DESCRIPTION, DESCRIPTION)); -} - -static const char * -fbsd_directorydb_get_string_property(struct _directorydb *d, const char *key, - const char *pname, uint32_t from) -{ - struct pkg_property *plist; - struct pkg_property *pnode; - - if ((plist = fbsd_directorydb_get_plist(d, key)) == NULL) { - return (NULL); - } - - pnode = pkg_property_dict_get_property(plist, pname); - if (pnode == NULL) { - /* If we can't find the string property that we want, do a parse - * of from and look again. */ - fbsd_directorydb_read_pkg(d, key, plist, from); - pnode = pkg_property_dict_get_property(plist, pname); - } - if (pnode == NULL) { - return (NULL); - } - - return (pkg_property_string_get_string(pnode)); -} - -static struct pkg_property * -fbsd_directorydb_get_plist(struct _directorydb *d, const char *key) -{ - struct _read_plist needle; - struct _read_plist *found; - struct pkg_property *plist; - - strcpy(needle.key, key); - - found = RB_FIND(plist_head, &d->plist_head, &needle); - if (found == NULL) { - plist = pkg_property_dict_create(NULL, ""); - found = calloc(1, sizeof(*found)); - found->plist = plist; - RB_INSERT(plist_head, &d->plist_head, found); - } - - return (found->plist); -} - static int -fbsd_directorydb_read_pkg(struct _directorydb *d, const char *key, - struct pkg_property *plist, uint32_t from) +fbsd_directorydb_read_pkg(struct _directorydb *d, struct pkg *pkg) { struct pkg_info *pi; char path[PATH_MAX]; @@ -529,28 +318,15 @@ int r; for (pi = pkg_entries; pi->info_name != NULL; pi++) { - if (from & pi->info_mask) { - strcpy(path, d->path); - strcat(path, "/"); - strcat(path, key); - strcat(path, "/"); - strcat(path, pi->file_name); + _pkg_util_path_join(path, d->path, pkg->key); + _pkg_util_path_join(path, path, pi->file_name); + + if ((data = read_file(path)) == NULL) continue; - data = read_file(path); - /* For now... just assume a null means the file DNE... */ - if (data == NULL) { - continue; - } - - r = fbsd_plist_parse(plist, data, pi->info_name); - free(data); - if (r != PKG_OK) { - pkg_property_release(plist); - return (r); - } - } + r = fbsd_plist_parse(pkg, data, pi->info_name); + if (r != PKG_OK) return (r); } - + return (PKG_OK); } ==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/freebsd_database_directorydb.h#4 (text+ko) ==== @@ -9,7 +9,7 @@ #include "internal.h" /* For type declarations. */ int fbsd_directorydb_add(struct pkg_db *, struct pkg *, - const char *); + const char *, const char *, const char *, const char *); /* Test if a key exists. */ int fbsd_directorydb_contains(struct pkg_db *, const char *); @@ -25,6 +25,9 @@ int fbsd_directorydb_close(struct pkg_db *); /* Returns a pkg_list of all the packages in a database. */ struct pkg_list *fbsd_directorydb_all(struct pkg_db *); +/* Returns a newly created file in a package. */ +struct pkg_file *fbsd_directorydb_add_file(struct pkg *, const char *, + const char *); /* Returns a pkg_file_list of all files in a package. */ struct pkg_file_list *fbsd_directorydb_files(struct pkg *); /* Returns a pkg_depend_list of all dependencies in a package. */ @@ -34,6 +37,6 @@ const char *fbsd_directorydb_file_prefix(struct pkg_file *); const char *fbsd_directorydb_file_pathname(struct pkg_file *); -const char *fbsd_directorydb_depend_name +const char *fbsd_directorydb_depend_name(struct pkg_depend *); #endif ==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/freebsd_plist.c#4 (text+ko) ==== @@ -18,6 +18,9 @@ #include "pkg.h" +#include "file.h" +#include "depend.h" + /* * Standard Plist commands in pkg format revision 1.1. */ @@ -100,41 +103,38 @@ */ struct plist_parse_state { - struct pkg_property *current_p; /* Whatever node we're building. */ - struct pkg_property *conflict_list; char cwd[PATH_MAX]; - struct pkg_property *depend_list; - struct pkg_property *exec_list; - struct pkg_property *file_list; + int ignore; unsigned int last; unsigned long line_number; - struct pkg_property *plist; /* PList root. */ - struct pkg_property *dirrm_list; - struct pkg_property *unexec_list; + + struct pkg *pkg; + struct pkg_file *current_file; + struct pkg_depend *current_dep; }; /* CONTENTS parsers functions. */ -static int _fbsd_plist_contents_parse(struct pkg_property *pl, char *buff); +static int _fbsd_plist_contents_parse(struct pkg *, char *); /* XXX: DNE */ #if 0 static int _fbsd_plist_contents_parse_fd(struct pkg_property *pl, int fd, size_t len); #endif -static int _fbsd_plist_parse_contents_line(const char *, struct pkg_property *, +static int _fbsd_plist_parse_contents_line(const char *, struct pkg *, struct plist_parse_state *); -static inline int _fbsd_plist_parse_contents_command(struct pkg_property *, +static inline int _fbsd_plist_parse_contents_command(struct pkg *, struct plist_parse_state *, const char *, const char *); -static int _fbsd_plist_parse_contents_option(struct pkg_property *, +static int _fbsd_plist_parse_contents_option(struct pkg *, struct plist_parse_state *, const char *); -static int _fbsd_plist_parse_contents_comment(struct pkg_property *, +static int _fbsd_plist_parse_contents_comment(struct pkg *, struct plist_parse_state *, const char *); /* Initializer for the contents parse state. */ static void _fbsd_plist_parse_contents_init(struct plist_parse_state *, - struct pkg_property *); + struct pkg *); /* REQUIRED_BY parsers functions. */ -static int _fbsd_plist_required_by_parse(struct pkg_property *pl, char *); +static int _fbsd_plist_required_by_parse(struct pkg *, char *); /* XXX: DNE */ #if 0 static int _fbsd_plist_required_by_parse_fd(struct pkg_property *, int, @@ -143,7 +143,7 @@ /* Blob 'parsers' for all other meta information. These just read/copy * information into PLSTRING property nodes. */ -static int _fbsd_plist_generic_parse(struct pkg_property *, char *, const char *); +static int _fbsd_plist_generic_parse(struct pkg *, char *, const char *); /* Write contents line. */ #if 0 @@ -159,19 +159,19 @@ /* PARSE */ int -fbsd_plist_parse(struct pkg_property *plist, char *data, const char *name) +fbsd_plist_parse(struct pkg *pkg, char *data, const char *name) { switch (name[0]) { case ('C'): case ('R'): if (STRMATCH(name, "CONTENTS")) { - return (_fbsd_plist_contents_parse(plist, data)); + return (_fbsd_plist_contents_parse(pkg, data)); } else if (STRMATCH(name, "REQUIRED_BY")) { - return (_fbsd_plist_required_by_parse(plist, data)); + return (_fbsd_plist_required_by_parse(pkg, data)); } /* FALLTHROUGH */ default: - return (_fbsd_plist_generic_parse(plist, data, name)); + return (_fbsd_plist_generic_parse(pkg, data, name)); } /* NOT REACHED */ @@ -188,41 +188,28 @@ * check for them everytime we want to add a property. */ static void _fbsd_plist_parse_contents_init(struct plist_parse_state *ps, - struct pkg_property *pl) + struct pkg *pkg) { - ps->conflict_list = NULL; - ps->current_p = NULL; - ps->depend_list = NULL; - ps->file_list = NULL; + ps->current_file = NULL; + ps->current_dep = NULL; + ps->ignore = 0; ps->line_number = 0; ps->last = PLIST_NONE; - ps->plist = pl; + ps->pkg = pkg; strcpy(ps->cwd, CWD_DEFAULT); - PLDICT_GET_OR_CREATE_LIST_PROPERTY(ps->plist, ps->conflict_list, - FBSD_CONFLICTS); - PLDICT_GET_OR_CREATE_LIST_PROPERTY(ps->plist, ps->depend_list, - FBSD_DEPENDENCIES); - PLDICT_GET_OR_CREATE_LIST_PROPERTY(ps->plist, ps->file_list, - FBSD_FILES); - PLDICT_GET_OR_CREATE_LIST_PROPERTY(ps->plist, ps->exec_list, - FBSD_EXECS); - PLDICT_GET_OR_CREATE_LIST_PROPERTY(ps->plist, ps->unexec_list, - FBSD_UNEXECS); - PLDICT_GET_OR_CREATE_LIST_PROPERTY(ps->plist, ps->dirrm_list, - FBSD_DIRRMS); } static int -_fbsd_plist_contents_parse(struct pkg_property *pl, char *buff) +_fbsd_plist_contents_parse(struct pkg *pkg, char *buff) { char *line; struct plist_parse_state ps; - _fbsd_plist_parse_contents_init(&ps, pl); - while ((line = strsep(&buff, "\n")) != NULL) { - if (_fbsd_plist_parse_contents_line(line, pl, &ps) != + _fbsd_plist_parse_contents_init(&ps, pkg); + while ((line = strsep(&buff, "\n")) != NULL) { + if (_fbsd_plist_parse_contents_line(line, pkg, &ps) != PKG_OK) { PKG_CLIENT_WARNING("parse failed."); return (PKG_NOT_OK); @@ -232,40 +219,13 @@ return (PKG_OK); } -/* XXX: These DO NOT check *anything*. */ - -/* Avoid duplicate plist entries. */ -#define ADD_SET_STRING_PROPERTY(root, new, pname, pvalue) \ -new = pkg_property_dict_get_property(root, pname); \ -if (new == NULL) { \ - new = pkg_property_string_create(root, pname); \ -} \ -pkg_property_string_set_string(new, pvalue) - -#define ADD_BOOLEAN_PROPERTY(root, new, pname, pvalue) \ -new = pkg_property_boolean_create(root, pname); \ -if (pvalue) { \ - pkg_property_boolean_set_true(new); \ -} else { \ - pkg_property_boolean_set_false(new); \ -} - -#define ADD_SET_DICT_PROPERTY(root, new, pname) \ -new = pkg_property_dict_create(root, pname) - -/* Append a string property to a list. */ -#define APPEND_SET_STRING_PROPERTY(root, new, pname, pvalue) \ -new = pkg_property_string_create(root, pname); \ -pkg_property_string_set_string(new, pvalue) - static int -_fbsd_plist_parse_contents_line(const char *line, struct pkg_property *pl, +_fbsd_plist_parse_contents_line(const char *line, struct pkg *pkg, struct plist_parse_state *ps) { const char *arg; char *cmdp; char cmd[LINE_MAX]; - struct pkg_property *p; /* Instead of using sscanf() [SLOW AS BALLS], use this method from * plist.c in the current pkg_install tools. */ @@ -283,26 +243,27 @@ } ++cmdp; ++arg; } - + switch (cmd[0]) { case (CMD_PREFIX): - if (_fbsd_plist_parse_contents_command(pl, ps, - cmd + 1, arg)!= PKG_OK) { + if (_fbsd_plist_parse_contents_command(ps->pkg, ps, + cmd + 1, arg) != PKG_OK) { return (PKG_NOT_OK); } break; default: - /* Now, we create a file dictionary node in the file list. */ - ps->current_p = pkg_property_dict_create(ps->file_list, - FBSD_FILE); - if (ps->current_p == NULL) { + ps->current_file = pkg_file_alloc(); + if (ps->current_file == NULL) { PKG_CLIENT_WARNING("allocation error"); return (PKG_NOT_OK); } - /* Add whatever file properties we can from the parse state. */ - ADD_SET_STRING_PROPERTY(ps->current_p, p, FBSD_PATHNAME, cmd); - ADD_SET_STRING_PROPERTY(ps->current_p, p, FBSD_PREFIX, ps->cwd); - ADD_BOOLEAN_PROPERTY(ps->current_p, p, FBSD_IGNORE, ps->ignore); + + _pkg_file_set_prefix(ps->current_file, ps->cwd); + _pkg_file_set_pathname(ps->current_file, cmd); + if (ps->ignore) _pkg_file_set_ignore(ps->current_file); + + _pkg_append_file(pkg, ps->current_file); + /* Reset ignore. */ ps->ignore = 0; ps->last = PLIST_FILE; @@ -313,12 +274,9 @@ } static int -_fbsd_plist_parse_contents_command(struct pkg_property *pl, +_fbsd_plist_parse_contents_command(struct pkg *pkg, struct plist_parse_state *ps, const char *command, const char *argument) { - struct pkg_property *pn; - struct pkg_property *nn; - /* Use two levels of switching to try and narrow the command * possibilities down before do a complete strcmp. */ switch (command[0]) { @@ -328,14 +286,15 @@ if (STRMATCH(command, CMD_COMMENT)) { /* @comment */ return (_fbsd_plist_parse_contents_comment( - pl, ps, argument)); + pkg, ps, argument)); } else if (STRMATCH(command, CMD_CONFLICTS)) { /* @conflicts */ - /* I'd really like this to become a PLDICT at - * some point, but right now it's a waste. */ - APPEND_SET_STRING_PROPERTY(ps->conflict_list, - nn, FBSD_CONFLICT, argument); + #if 0 + ps->current_conflict = pkg_conflict_alloc(); + _pkg_conflict_set_expr(conflict, argument); + _pkg_append_conflict(pkg, conflict); ps->last = PLIST_CONFLICT; + #endif return (PKG_OK); } break; @@ -354,8 +313,6 @@ >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201010172252.o9HMqrGa004556>