1 --- a/archival/libipkg/pkg.c
2 +++ b/archival/libipkg/pkg.c
4 if (err) { return err; }
7 - raw = read_raw_pkgs_from_stream(control_file);
8 - pkg_parse_raw(pkg, &raw, NULL, NULL);
9 + pkg_parse_stream(pkg, control_file, NULL, NULL);
13 --- a/archival/libipkg/pkg_hash.c
14 +++ b/archival/libipkg/pkg_hash.c
16 pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
18 hash_table_t *hash = &conf->pkg_hash;
24 - raw = raw_start = read_raw_pkgs_from_file(file_name);
27 + if(!(fp = fopen(file_name, "r"))){
28 + fprintf(stderr, "can't get %s open for read\n", file_name);
32 - while(*raw){ /* don't worry, we'll increment raw in the parsing function */
33 + while(!feof(fp)) { /* don't worry, we'll increment raw in the parsing function */
38 - if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
39 + if (pkg_parse_stream(pkg, fp, src, dest) == 0) {
40 if (!pkg->architecture) {
41 char *version_str = pkg_version_str_alloc(pkg);
42 pkg->architecture = pkg_get_default_arch(conf);
47 - /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
48 - memory after read_raw_pkgs_from_file */
57 --- a/archival/libipkg/pkg_parse.c
58 +++ b/archival/libipkg/pkg_parse.c
60 Enhances, perhaps we could generalize all of these and save some
63 +int pkg_parse_stream(pkg_t *pkg, FILE *stream, pkg_src_t *src, pkg_dest_t *dest)
65 + int reading_conffiles, reading_description;
66 + int pkg_false_provides=1;
73 + buf = malloc (size);
78 + reading_conffiles = reading_description = 0;
80 + while (fgets(buf, size, stream)) {
81 + while (strlen (buf) == (size - 1)
82 + && buf[size-2] != '\n') {
83 + size_t o = size - 1;
85 + buf = realloc (buf, size);
86 + if (fgets (buf + o, size - o, stream) == NULL)
90 + if((scout = strchr(buf, '\n')))
94 + /* fprintf(stderr, "PARSING %s\n", *lines);*/
95 + if(isGenericFieldType("Package:", *lines))
96 + pkg->name = parseGenericFieldType("Package", *lines);
97 + else if(isGenericFieldType("Architecture:", *lines))
98 + pkg->architecture = parseGenericFieldType("Architecture", *lines);
99 + else if(isGenericFieldType("Filename:", *lines))
100 + pkg->filename = parseGenericFieldType("Filename", *lines);
101 + else if(isGenericFieldType("Section:", *lines))
102 + pkg->section = parseGenericFieldType("Section", *lines);
103 + else if(isGenericFieldType("MD5sum:", *lines))
104 + pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
105 + /* The old ipkg wrote out status files with the wrong case for MD5sum,
106 + let's parse it either way */
107 + else if(isGenericFieldType("MD5Sum:", *lines))
108 + pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
109 + else if(isGenericFieldType("Size:", *lines))
110 + pkg->size = parseGenericFieldType("Size", *lines);
111 + else if(isGenericFieldType("Source:", *lines))
112 + pkg->source = parseGenericFieldType("Source", *lines);
113 + else if(isGenericFieldType("Installed-Size:", *lines))
114 + pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
115 + else if(isGenericFieldType("Installed-Time:", *lines)) {
116 + char *time_str = parseGenericFieldType("Installed-Time", *lines);
117 + pkg->installed_time = strtoul(time_str, NULL, 0);
118 + } else if(isGenericFieldType("Priority:", *lines))
119 + pkg->priority = parseGenericFieldType("Priority", *lines);
120 + else if(isGenericFieldType("Essential:", *lines)) {
121 + char *essential_value;
122 + essential_value = parseGenericFieldType("Essential", *lines);
123 + if (strcmp(essential_value, "yes") == 0) {
124 + pkg->essential = 1;
126 + free(essential_value);
128 + else if(isGenericFieldType("Status", *lines))
129 + parseStatus(pkg, *lines);
130 + else if(isGenericFieldType("Version", *lines))
131 + parseVersion(pkg, *lines);
132 + else if(isGenericFieldType("Maintainer", *lines))
133 + pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
134 + else if(isGenericFieldType("Conffiles", *lines)){
135 + parseConffiles(pkg, *lines);
136 + reading_conffiles = 1;
138 + else if(isGenericFieldType("Description", *lines)) {
139 + pkg->description = parseGenericFieldType("Description", *lines);
140 + reading_conffiles = 0;
141 + reading_description = 1;
144 + else if(isGenericFieldType("Provides", *lines)){
145 +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
146 + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
147 + if ( alterProvidesLine(*lines,provide) ){
150 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
151 +/* Let's try to hack a bit here.
152 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
153 + in alot of other places. We will remove it before writing down the status database */
154 + pkg_false_provides=0;
158 + else if(isGenericFieldType("Depends", *lines))
159 + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
160 + else if(isGenericFieldType("Pre-Depends", *lines))
161 + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
162 + else if(isGenericFieldType("Recommends", *lines))
163 + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
164 + else if(isGenericFieldType("Suggests", *lines))
165 + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
166 + /* Abhaya: support for conflicts */
167 + else if(isGenericFieldType("Conflicts", *lines))
168 + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
169 + else if(isGenericFieldType("Replaces", *lines))
170 + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
171 + else if(line_is_blank(*lines)) {
174 + else if(**lines == ' '){
175 + if(reading_description) {
176 + /* we already know it's not blank, so the rest of description */
177 + pkg->description = realloc(pkg->description,
178 + strlen(pkg->description)
179 + + 1 + strlen(*lines) + 1);
180 + strcat(pkg->description, "\n");
181 + strcat(pkg->description, (*lines));
183 + else if(reading_conffiles)
184 + parseConffiles(pkg, *lines);
187 +/* If the ipk has not a Provides line, we insert our false line */
188 + if ( pkg_false_provides==1)
189 + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
201 +/* Some random thoughts from Carl:
203 + This function could be considerably simplified if we just kept
204 + an array of all the generic string-valued field names, and looped
205 + through those looking for a match. Also, these fields could perhaps
206 + be stored in the package as an array as well, (or, probably better,
207 + as an nv_pair_list_t).
209 + Fields which require special parsing or storage, (such as Depends:
210 + and Status:) could be handled as they are now.
212 +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
213 + to a dependency list. And, since we already have
214 + Depends/Pre-Depends and need to add Conflicts, Recommends, and
215 + Enhances, perhaps we could generalize all of these and save some
218 int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
220 int reading_conffiles, reading_description;
227 int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
229 --- a/archival/libipkg/pkg_parse.h
230 +++ b/archival/libipkg/pkg_parse.h
232 char ** parseDependsString(char * raw, int * depends_count);
233 int parseVersion(pkg_t *pkg, char *raw);
234 void parseConffiles(pkg_t * pkg, char * raw);
236 int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
238 +int pkg_parse_stream(pkg_t *pkg, FILE *stream, pkg_src_t *src, pkg_dest_t *dest);
239 int pkg_valorize_other_field(pkg_t *pkg, char ***raw);