[package] opkg:
[openwrt/svn-archive/archive.git] / package / opkg / patches / 008-fix_parsing_insanity.patch
1 --- a/libopkg/opkg_utils.c
2 +++ b/libopkg/opkg_utils.c
3 @@ -44,58 +44,6 @@
4 return 0;
5 }
6
7 -char **read_raw_pkgs_from_file(const char *file_name)
8 -{
9 - FILE *fp;
10 - char **ret;
11 -
12 - if(!(fp = fopen(file_name, "r"))){
13 - fprintf(stderr, "can't get %s open for read\n", file_name);
14 - return NULL;
15 - }
16 -
17 - ret = read_raw_pkgs_from_stream(fp);
18 -
19 - fclose(fp);
20 -
21 - return ret;
22 -}
23 -
24 -char **read_raw_pkgs_from_stream(FILE *fp)
25 -{
26 - char **raw = NULL, *buf, *scout;
27 - int count = 0;
28 - size_t size = 512;
29 -
30 - buf = calloc (1, size);
31 -
32 - while (fgets(buf, size, fp)) {
33 - while (strlen (buf) == (size - 1)
34 - && buf[size-2] != '\n') {
35 - size_t o = size - 1;
36 - size *= 2;
37 - buf = realloc (buf, size);
38 - if (fgets (buf + o, size - o, fp) == NULL)
39 - break;
40 - }
41 -
42 - if(!(count % 50))
43 - raw = realloc(raw, (count + 50) * sizeof(char *));
44 -
45 - if((scout = strchr(buf, '\n')))
46 - *scout = '\0';
47 -
48 - raw[count++] = strdup(buf);
49 - }
50 -
51 - raw = realloc(raw, (count + 1) * sizeof(char *));
52 - raw[count] = NULL;
53 -
54 - free (buf);
55 -
56 - return raw;
57 -}
58 -
59 /* something to remove whitespace, a hash pooper */
60 char *trim_alloc(char *line)
61 {
62 --- a/libopkg/pkg.c
63 +++ b/libopkg/pkg.c
64 @@ -20,6 +20,8 @@
65 #include <alloca.h>
66 #include <string.h>
67 #include <stdbool.h>
68 +#include <unistd.h>
69 +#include <fcntl.h>
70 #include <errno.h>
71
72 #include "pkg.h"
73 @@ -277,7 +279,6 @@
74 int pkg_init_from_file(pkg_t *pkg, const char *filename)
75 {
76 int err;
77 - char **raw;
78 FILE *control_file;
79
80 err = pkg_init(pkg);
81 @@ -290,8 +291,7 @@
82 if (err) { return err; }
83
84 rewind(control_file);
85 - raw = read_raw_pkgs_from_stream(control_file);
86 - pkg_parse_raw(pkg, &raw, NULL, NULL);
87 + pkg_parse_fd(pkg, fileno(control_file), NULL, NULL);
88
89 fclose(control_file);
90
91 @@ -459,8 +459,7 @@
92
93 void set_flags_from_control(opkg_conf_t *conf, pkg_t *pkg){
94 char * temp_str;
95 - char **raw =NULL;
96 - char **raw_start=NULL;
97 + int fd;
98
99 size_t str_size = strlen(pkg->dest->info_dir)+strlen(pkg->name)+12;
100 temp_str = (char *) alloca (str_size);
101 @@ -471,28 +470,23 @@
102 return;
103 }
104 sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
105 -
106 - raw = raw_start = read_raw_pkgs_from_file(temp_str);
107 - if (raw == NULL ){
108 - opkg_message(conf, OPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
109 - return;
110 - }
111
112 - while(*raw){
113 - if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
114 - opkg_message(conf, OPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
115 - }
116 - }
117 - raw = raw_start;
118 - while (*raw) {
119 - if (raw!=NULL)
120 - free(*raw++);
121 - }
122 + if( (fd = open(temp_str, O_RDONLY)) > 0 )
123 + {
124 + if( pkg_valorize_other_field(pkg, fd) )
125 + {
126 + opkg_message(conf, OPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
127 + }
128
129 - free(raw_start);
130 + close(fd);
131 + }
132 + else
133 + {
134 + opkg_message(conf, OPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
135 + return;
136 + }
137
138 return ;
139 -
140 }
141
142 #define CHECK_BUFF_SIZE(buff, line, buf_size, page_size) do { \
143 --- a/libopkg/pkg_hash.c
144 +++ b/libopkg/pkg_hash.c
145 @@ -20,6 +20,8 @@
146 #include <ctype.h>
147 #include <stdlib.h>
148 #include <string.h>
149 +#include <unistd.h>
150 +#include <fcntl.h>
151
152 #include "hash_table.h"
153 #include "pkg.h"
154 @@ -112,43 +114,50 @@
155 int pkg_hash_add_from_file(opkg_conf_t *conf, const char *file_name,
156 pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
157 {
158 - hash_table_t *hash = &conf->pkg_hash;
159 - char **raw;
160 - char **raw_start;
161 - pkg_t *pkg;
162 -
163 - raw = raw_start = read_raw_pkgs_from_file(file_name);
164 - if (!raw)
165 - return -ENOMEM;
166 -
167 - while(*raw){ /* don't worry, we'll increment raw in the parsing function */
168 - pkg = pkg_new();
169 - if (!pkg)
170 - return -ENOMEM;
171 -
172 - if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
173 - if (!pkg->architecture) {
174 - char *version_str = pkg_version_str_alloc(pkg);
175 - pkg->architecture = pkg_get_default_arch(conf);
176 - opkg_message(conf, OPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
177 - pkg->name, version_str, pkg->architecture);
178 - free(version_str);
179 - }
180 - hash_insert_pkg(hash, pkg, is_status_file,conf);
181 - } else {
182 - pkg_deinit (pkg);
183 - free(pkg);
184 - }
185 - }
186 + hash_table_t *hash = &conf->pkg_hash;
187 + pkg_t *pkg;
188
189 - /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
190 - memory after read_raw_pkgs_from_file */
191 - raw = raw_start;
192 - while (*raw) {
193 - free(*raw++);
194 - }
195 - free(raw_start);
196 - return 0;
197 + int fd;
198 + int rv = 0;
199 +
200 + if( (fd = open(file_name, O_RDONLY)) > 0 )
201 + {
202 + while(1)
203 + {
204 + pkg = pkg_new();
205 + if(!pkg) {
206 + rv = -ENOMEM;
207 + break;
208 + }
209 +
210 + if (pkg_parse_fd(pkg, fd, src, dest) == 0) {
211 + if (!pkg->architecture) {
212 + char *version_str = pkg_version_str_alloc(pkg);
213 + pkg->architecture = pkg_get_default_arch(conf);
214 + opkg_message(conf, OPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
215 + pkg->name, version_str, pkg->architecture);
216 + free(version_str);
217 + }
218 +
219 + hash_insert_pkg(hash, pkg, is_status_file, conf);
220 + } else {
221 + pkg_deinit (pkg);
222 + free(pkg);
223 + break;
224 + }
225 + }
226 +
227 + close(fd);
228 + }
229 + else
230 + {
231 + opkg_message (conf, OPKG_ERROR,
232 + "Unable to open package list %s\n", file_name);
233 +
234 + rv = -EINVAL;
235 + }
236 +
237 + return rv;
238 }
239
240 abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
241 --- a/libopkg/pkg_parse.c
242 +++ b/libopkg/pkg_parse.c
243 @@ -191,214 +191,297 @@
244
245 }
246
247 -/* Some random thoughts from Carl:
248 -
249 - This function could be considerably simplified if we just kept
250 - an array of all the generic string-valued field names, and looped
251 - through those looking for a match. Also, these fields could perhaps
252 - be stored in the package as an array as well, (or, probably better,
253 - as an nv_pair_list_t).
254 -
255 - Fields which require special parsing or storage, (such as Depends:
256 - and Status:) could be handled as they are now.
257 -*/
258 -/* XXX: FEATURE: The Suggests: field needs to be changed from a string
259 - to a dependency list. And, since we already have
260 - Depends/Pre-Depends and need to add Conflicts, Recommends, and
261 - Enhances, perhaps we could generalize all of these and save some
262 - code duplication.
263 -*/
264 -int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
265 +int pkg_parse_fd(pkg_t *pkg, int fd, pkg_src_t *src, pkg_dest_t *dest)
266 {
267 - int reading_conffiles, reading_description;
268 - int pkg_false_provides=1;
269 - char ** lines;
270 - char * provide=NULL;
271 -
272 - pkg->src = src;
273 - pkg->dest = dest;
274 -
275 - reading_conffiles = reading_description = 0;
276 -
277 - for (lines = *raw; *lines; lines++) {
278 - /* fprintf(stderr, "PARSING %s\n", *lines);*/
279 - switch (**lines) {
280 - case 'P':
281 - if(isGenericFieldType("Package:", *lines))
282 - pkg->name = parseGenericFieldType("Package", *lines);
283 - else if(isGenericFieldType("Priority:", *lines))
284 - pkg->priority = parseGenericFieldType("Priority", *lines);
285 - else if(isGenericFieldType("Provides", *lines)){
286 -/* Here we add the internal_use to align the off by one problem between provides_str and provides */
287 - provide = (char * ) calloc(1, strlen(*lines)+ 35 ); /* Preparing the space for the new opkg_internal_use_only */
288 - if ( alterProvidesLine(*lines,provide) ){
289 - return EINVAL;
290 - }
291 - pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
292 -/* Let's try to hack a bit here.
293 - The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
294 - in alot of other places. We will remove it before writing down the status database */
295 - pkg_false_provides=0;
296 - free(provide);
297 - }
298 - else if(isGenericFieldType("Pre-Depends", *lines))
299 - pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
300 - break;
301 -
302 - case 'A':
303 - if(isGenericFieldType("Architecture:", *lines))
304 - pkg->architecture = parseGenericFieldType("Architecture", *lines);
305 - else if(isGenericFieldType("Auto-Installed:", *lines)) {
306 - char *auto_installed_value;
307 - auto_installed_value = parseGenericFieldType("Auto-Installed:", *lines);
308 - if (strcmp(auto_installed_value, "yes") == 0) {
309 - pkg->auto_installed = 1;
310 - }
311 - free(auto_installed_value);
312 - }
313 - break;
314 -
315 - case 'F':
316 - if(isGenericFieldType("Filename:", *lines))
317 - pkg->filename = parseGenericFieldType("Filename", *lines);
318 - break;
319 -
320 - case 'S':
321 - if(isGenericFieldType("Section:", *lines))
322 - pkg->section = parseGenericFieldType("Section", *lines);
323 - else if(isGenericFieldType("Size:", *lines))
324 - pkg->size = parseGenericFieldType("Size", *lines);
325 - else if(isGenericFieldType("Source:", *lines))
326 - pkg->source = parseGenericFieldType("Source", *lines);
327 - else if(isGenericFieldType("Status", *lines))
328 - parseStatus(pkg, *lines);
329 - else if(isGenericFieldType("Suggests", *lines))
330 - pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
331 - break;
332 -
333 - case 'T':
334 - if(isGenericFieldType("Tags:", *lines))
335 - pkg->tags = parseGenericFieldType("Tags", *lines);
336 - break;
337 -
338 - case 'M':
339 - if(isGenericFieldType("MD5sum:", *lines))
340 - pkg->md5sum = parseGenericFieldType("MD5sum", *lines);
341 - /* The old opkg wrote out status files with the wrong case for MD5sum,
342 - let's parse it either way */
343 - else if(isGenericFieldType("MD5Sum:", *lines))
344 - pkg->md5sum = parseGenericFieldType("MD5Sum", *lines);
345 - else if(isGenericFieldType("Maintainer", *lines))
346 - pkg->maintainer = parseGenericFieldType("Maintainer", *lines);
347 - break;
348 -
349 - case 'I':
350 - if(isGenericFieldType("Installed-Size:", *lines))
351 - pkg->installed_size = parseGenericFieldType("Installed-Size", *lines);
352 - else if(isGenericFieldType("Installed-Time:", *lines)) {
353 - char *time_str = parseGenericFieldType("Installed-Time", *lines);
354 - pkg->installed_time = strtoul(time_str, NULL, 0);
355 - free (time_str);
356 - }
357 - break;
358 -
359 - case 'E':
360 - if(isGenericFieldType("Essential:", *lines)) {
361 - char *essential_value;
362 - essential_value = parseGenericFieldType("Essential", *lines);
363 - if (strcmp(essential_value, "yes") == 0) {
364 - pkg->essential = 1;
365 - }
366 - free(essential_value);
367 - }
368 - break;
369 -
370 - case 'V':
371 - if(isGenericFieldType("Version", *lines))
372 - parseVersion(pkg, *lines);
373 - break;
374 -
375 - case 'C':
376 - if(isGenericFieldType("Conffiles", *lines)){
377 - parseConffiles(pkg, *lines);
378 - reading_conffiles = 1;
379 - }
380 - else if(isGenericFieldType("Conflicts", *lines))
381 - pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
382 - break;
383 -
384 - case 'D':
385 - if(isGenericFieldType("Description", *lines)) {
386 - pkg->description = parseGenericFieldType("Description", *lines);
387 - reading_conffiles = 0;
388 - reading_description = 1;
389 - }
390 - else if(isGenericFieldType("Depends", *lines))
391 - pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
392 - break;
393 -
394 - case 'R':
395 - if(isGenericFieldType("Recommends", *lines))
396 - pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
397 - else if(isGenericFieldType("Replaces", *lines))
398 - pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
399 -
400 - break;
401 -
402 - case ' ':
403 - if(reading_description) {
404 - /* we already know it's not blank, so the rest of description */
405 - pkg->description = realloc(pkg->description,
406 - strlen(pkg->description)
407 - + 1 + strlen(*lines) + 1);
408 - strcat(pkg->description, "\n");
409 - strcat(pkg->description, (*lines));
410 - }
411 - else if(reading_conffiles)
412 - parseConffiles(pkg, *lines);
413 -
414 - break;
415 -
416 - default:
417 - if(line_is_blank(*lines)) {
418 - lines++;
419 - goto out;
420 - }
421 + char buf[4096];
422 + char line[4096];
423 + char *nl;
424 + int bsz = 0;
425 + int eof = 0;
426 + int rv = EINVAL;
427 +
428 + int reading_conffiles, reading_description;
429 + int pkg_false_provides=1;
430 + char *provide = NULL;
431 +
432 + pkg->src = src;
433 + pkg->dest = dest;
434 +
435 + reading_conffiles = reading_description = 0;
436 +
437 + memset(buf, 0, sizeof(buf));
438 +
439 + while(!eof || (bsz > 0))
440 + {
441 + if(!eof)
442 + {
443 + rv = read(fd, &buf[bsz], sizeof(buf) - bsz - 1);
444 +
445 + if( rv == 0 )
446 + {
447 + eof = 1;
448 +
449 + if( bsz == 0 )
450 + {
451 + rv = EINVAL;
452 + break;
453 + }
454 + }
455 + else if( rv < 0 )
456 + {
457 + /*opkg_message(conf, OPKG_ERROR, "I/O error while parsing package list\n");*/
458 + printf("I/O error while parsing package list\n");
459 + rv = EINVAL;
460 + break;
461 + }
462 + else
463 + {
464 + bsz += rv;
465 + buf[bsz] = 0;
466 + rv = 0;
467 + }
468 + }
469 +
470 + if( (nl = strchr(buf, '\n')) != NULL )
471 + {
472 + bsz -= (int)(nl - buf) + 1;
473 +
474 + memset(line, 0, sizeof(line));
475 + memcpy(line, buf, (int)(nl - buf));
476 + memmove(buf, &buf[(int)(nl - buf) + 1], bsz);
477 +
478 + switch(line[0])
479 + {
480 + case 'P':
481 + if(isGenericFieldType("Package:", line))
482 + pkg->name = parseGenericFieldType("Package", line);
483 + else if(isGenericFieldType("Priority:", line))
484 + pkg->priority = parseGenericFieldType("Priority", line);
485 + else if(isGenericFieldType("Provides", line)){
486 + /* Here we add the internal_use to align the off by one problem between provides_str and provides */
487 + provide = (char * ) calloc(1, strlen(line)+ 35 ); /* Preparing the space for the new opkg_internal_use_only */
488 + if ( alterProvidesLine(line,provide) ){
489 + rv = EINVAL;
490 + break;
491 + }
492 + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
493 + /* Let's try to hack a bit here.
494 + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
495 + in alot of other places. We will remove it before writing down the status database */
496 + pkg_false_provides=0;
497 + free(provide);
498 + }
499 + else if(isGenericFieldType("Pre-Depends", line))
500 + pkg->pre_depends_str = parseDependsString(line, &pkg->pre_depends_count);
501 + break;
502 +
503 + case 'A':
504 + if(isGenericFieldType("Architecture:", line))
505 + pkg->architecture = parseGenericFieldType("Architecture", line);
506 + else if(isGenericFieldType("Auto-Installed:", line)) {
507 + char *auto_installed_value;
508 + auto_installed_value = parseGenericFieldType("Auto-Installed:", line);
509 + if (strcmp(auto_installed_value, "yes") == 0) {
510 + pkg->auto_installed = 1;
511 + }
512 + free(auto_installed_value);
513 + }
514 + break;
515 +
516 + case 'F':
517 + if(isGenericFieldType("Filename:", line))
518 + pkg->filename = parseGenericFieldType("Filename", line);
519 + break;
520 +
521 + case 'S':
522 + if(isGenericFieldType("Section:", line))
523 + pkg->section = parseGenericFieldType("Section", line);
524 + else if(isGenericFieldType("Size:", line))
525 + pkg->size = parseGenericFieldType("Size", line);
526 + else if(isGenericFieldType("Source:", line))
527 + pkg->source = parseGenericFieldType("Source", line);
528 + else if(isGenericFieldType("Status", line))
529 + parseStatus(pkg, line);
530 + else if(isGenericFieldType("Suggests", line))
531 + pkg->suggests_str = parseDependsString(line, &pkg->suggests_count);
532 + break;
533 +
534 + case 'T':
535 + if(isGenericFieldType("Tags:", line))
536 + pkg->tags = parseGenericFieldType("Tags", line);
537 + break;
538 +
539 + case 'M':
540 + if(isGenericFieldType("MD5sum:", line))
541 + pkg->md5sum = parseGenericFieldType("MD5sum", line);
542 + /* The old opkg wrote out status files with the wrong case for MD5sum,
543 + let's parse it either way */
544 + else if(isGenericFieldType("MD5Sum:", line))
545 + pkg->md5sum = parseGenericFieldType("MD5Sum", line);
546 + else if(isGenericFieldType("Maintainer", line))
547 + pkg->maintainer = parseGenericFieldType("Maintainer", line);
548 + break;
549 +
550 + case 'I':
551 + if(isGenericFieldType("Installed-Size:", line))
552 + pkg->installed_size = parseGenericFieldType("Installed-Size", line);
553 + else if(isGenericFieldType("Installed-Time:", line)) {
554 + char *time_str = parseGenericFieldType("Installed-Time", line);
555 + pkg->installed_time = strtoul(time_str, NULL, 0);
556 + free (time_str);
557 + }
558 + break;
559 +
560 + case 'E':
561 + if(isGenericFieldType("Essential:", line)) {
562 + char *essential_value;
563 + essential_value = parseGenericFieldType("Essential", line);
564 + if (strcmp(essential_value, "yes") == 0) {
565 + pkg->essential = 1;
566 + }
567 + free(essential_value);
568 + }
569 + break;
570 +
571 + case 'V':
572 + if(isGenericFieldType("Version", line))
573 + parseVersion(pkg, line);
574 + break;
575 +
576 + case 'C':
577 + if(isGenericFieldType("Conffiles", line)){
578 + parseConffiles(pkg, line);
579 + reading_conffiles = 1;
580 + }
581 + else if(isGenericFieldType("Conflicts", line))
582 + pkg->conflicts_str = parseDependsString(line, &pkg->conflicts_count);
583 + break;
584 +
585 + case 'D':
586 + if(isGenericFieldType("Description", line)) {
587 + pkg->description = parseGenericFieldType("Description", line);
588 + reading_conffiles = 0;
589 + reading_description = 1;
590 + }
591 + else if(isGenericFieldType("Depends", line))
592 + pkg->depends_str = parseDependsString(line, &pkg->depends_count);
593 + break;
594 +
595 + case 'R':
596 + if(isGenericFieldType("Recommends", line))
597 + pkg->recommends_str = parseDependsString(line, &pkg->recommends_count);
598 + else if(isGenericFieldType("Replaces", line))
599 + pkg->replaces_str = parseDependsString(line, &pkg->replaces_count);
600 + break;
601 +
602 + case ' ':
603 + if(reading_description) {
604 + /* we already know it's not blank, so the rest of description */
605 + pkg->description = realloc(pkg->description,
606 + strlen(pkg->description) + 1 + strlen(line) + 1);
607 + strcat(pkg->description, "\n");
608 + strcat(pkg->description, (line));
609 + }
610 + else if(reading_conffiles)
611 + parseConffiles(pkg, line);
612 + break;
613 +
614 + default:
615 + if(line_is_blank(line))
616 + goto out;
617 + }
618 + }
619 + else
620 + {
621 + /*opkg_message(conf, OPKG_ERROR, "Buffer exceeded while parsing line:\n[%s]\n", buf);*/
622 + printf("Buffer exceeded while parsing line:\n[%s]\n", buf);
623 + rv = EINVAL;
624 + break;
625 + }
626 }
627 - }
628 -out:;
629 -
630 - *raw = lines;
631 -/* If the opk has not a Provides line, we insert our false line */
632 - if ( pkg_false_provides==1)
633 - {
634 - pkg->provides_count = 1;
635 - pkg->provides_str = calloc (1, sizeof (char*));
636 - pkg->provides_str[0] = strdup ("opkg_internal_use_only");
637 - }
638 -
639 - if (pkg->name) {
640 - return 0;
641 - } else {
642 - return EINVAL;
643 - }
644 +
645 + out:
646 +
647 + if (bsz)
648 + lseek(fd, -(off_t)bsz, SEEK_CUR);
649 +
650 + if (!rv && pkg->name)
651 + return 0;
652 + else
653 + return EINVAL;
654 }
655
656 -int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
657 +int pkg_valorize_other_field(pkg_t *pkg, int fd)
658 {
659 - char ** lines;
660 + char buf[4096];
661 + char line[4096];
662 + char *nl;
663 + int bsz = 0;
664 + int eof = 0;
665 + int rv = EINVAL;
666 +
667 + memset(buf, 0, sizeof(buf));
668 +
669 + while(!eof || (bsz > 0))
670 + {
671 + if(!eof)
672 + {
673 + rv = read(fd, &buf[bsz], sizeof(buf) - bsz - 1);
674 +
675 + if( rv == 0 )
676 + {
677 + eof = 1;
678 +
679 + if( bsz == 0 )
680 + {
681 + rv = EINVAL;
682 + break;
683 + }
684 + }
685 + else if( rv < 0 )
686 + {
687 + rv = EINVAL;
688 + break;
689 + }
690 + else
691 + {
692 + bsz += rv;
693 + buf[bsz] = 0;
694 + rv = 0;
695 + }
696 + }
697
698 - for (lines = *raw; *lines; lines++) {
699 - if(isGenericFieldType("Essential:", *lines)) {
700 - char *essential_value;
701 - essential_value = parseGenericFieldType("Essential", *lines);
702 - if (strcmp(essential_value, "yes") == 0) {
703 - pkg->essential = 1;
704 - }
705 - free(essential_value);
706 + if( (nl = strchr(buf, '\n')) != NULL )
707 + {
708 + bsz -= (int)(nl - buf) + 1;
709 +
710 + memset(line, 0, sizeof(line));
711 + memcpy(line, buf, (int)(nl - buf));
712 + memmove(buf, &buf[(int)(nl - buf) + 1], bsz);
713 +
714 + if(isGenericFieldType("Essential:", line))
715 + {
716 + char *essential_value;
717 + essential_value = parseGenericFieldType("Essential", line);
718 + if (strcmp(essential_value, "yes") == 0) {
719 + pkg->essential = 1;
720 + }
721 + free(essential_value);
722 + }
723 + }
724 + else
725 + {
726 + rv = EINVAL;
727 + break;
728 + }
729 }
730 - }
731 - *raw = lines;
732
733 - return 0;
734 + if (bsz)
735 + lseek(fd, -(off_t)bsz, SEEK_CUR);
736 +
737 + if (!rv && pkg->name)
738 + return 0;
739 + else
740 + return EINVAL;
741 }
742 +
743 --- a/libopkg/pkg_parse.h
744 +++ b/libopkg/pkg_parse.h
745 @@ -25,7 +25,7 @@
746 char ** parseDependsString(char * raw, int * depends_count);
747 int parseVersion(pkg_t *pkg, char *raw);
748 void parseConffiles(pkg_t * pkg, char * raw);
749 -int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
750 -int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
751 +int pkg_parse_fd(pkg_t *pkg, int fd, pkg_src_t *src, pkg_dest_t *dest);
752 +int pkg_valorize_other_field(pkg_t *pkg, int fd);
753
754 #endif
755 --- a/libopkg/opkg_utils.h
756 +++ b/libopkg/opkg_utils.h
757 @@ -26,8 +26,6 @@
758 void free_error_list();
759
760 long unsigned int get_available_blocks(char * filesystem);
761 -char **read_raw_pkgs_from_file(const char *file_name);
762 -char **read_raw_pkgs_from_stream(FILE *fp);
763 char *trim_alloc(char * line);
764 int line_is_blank(const char *line);
765