fields.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * fields.c - parsing of all the different fields, when reading in
  4. *
  5. * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright © 2001 Wichert Akkerman
  7. * Copyright © 2006-2015 Guillem Jover <guillem@debian.org>
  8. * Copyright © 2009 Canonical Ltd.
  9. * Copyright © 2011 Linaro Limited
  10. * Copyright © 2011 Raphaël Hertzog <hertzog@debian.org>
  11. *
  12. * This is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. */
  25. #include <config.h>
  26. #include <compat.h>
  27. #include <string.h>
  28. #include <stdio.h>
  29. #include <dpkg/i18n.h>
  30. #include <dpkg/c-ctype.h>
  31. #include <dpkg/dpkg.h>
  32. #include <dpkg/dpkg-db.h>
  33. #include <dpkg/arch.h>
  34. #include <dpkg/string.h>
  35. #include <dpkg/path.h>
  36. #include <dpkg/parsedump.h>
  37. #include <dpkg/pkg-spec.h>
  38. #include <dpkg/triglib.h>
  39. /**
  40. * Flags to parse a name associated to a value.
  41. */
  42. enum parse_nv_flags {
  43. /** Expect no more words (default). */
  44. PARSE_NV_LAST = 0,
  45. /** Expect another word after the parsed name. */
  46. PARSE_NV_NEXT = DPKG_BIT(0),
  47. /** Do not fail if there is no name with an associated value found. */
  48. PARSE_NV_FALLBACK = DPKG_BIT(1),
  49. };
  50. /**
  51. * Parses a name and returns its associated value.
  52. *
  53. * Gets a pointer to the string to parse in @a strp, and modifies the pointer
  54. * to the string to point to the end of the parsed text. If no value is found
  55. * for the name and #PARSE_NV_FALLBACK is set in @a flags then @a strp is set
  56. * to NULL and returns -1, otherwise a parse error is emitted.
  57. */
  58. static int
  59. parse_nv(struct parsedb_state *ps, enum parse_nv_flags flags,
  60. const char **strp, const struct namevalue *nv_head, const char *what)
  61. {
  62. const char *str_start = *strp, *str_end;
  63. const struct namevalue *nv;
  64. int value;
  65. if (str_start[0] == '\0')
  66. parse_error(ps, _("%s is missing"), what);
  67. nv = namevalue_find_by_name(nv_head, str_start);
  68. if (nv == NULL) {
  69. /* We got no match, skip further string validation. */
  70. if (!(flags & PARSE_NV_FALLBACK))
  71. parse_error(ps, _("'%.50s' is not allowed for %s"), str_start, what);
  72. str_end = NULL;
  73. value = -1;
  74. } else {
  75. str_end = str_start + nv->length;
  76. while (c_isspace(str_end[0]))
  77. str_end++;
  78. value = nv->value;
  79. }
  80. if (!(flags & PARSE_NV_NEXT) && str_is_set(str_end))
  81. parse_error(ps, _("junk after %s"), what);
  82. *strp = str_end;
  83. return value;
  84. }
  85. void
  86. f_name(struct pkginfo *pkg, struct pkgbin *pkgbin,
  87. struct parsedb_state *ps,
  88. const char *value, const struct fieldinfo *fip)
  89. {
  90. const char *e;
  91. e = pkg_name_is_illegal(value);
  92. if (e != NULL)
  93. parse_error(ps, _("invalid package name (%.250s)"), e);
  94. /* We use the new name, as pkg_db_find_set() may have done a tolower for us. */
  95. pkg->set->name = pkg_db_find_set(value)->name;
  96. }
  97. void
  98. f_filecharf(struct pkginfo *pkg, struct pkgbin *pkgbin,
  99. struct parsedb_state *ps,
  100. const char *value, const struct fieldinfo *fip)
  101. {
  102. struct filedetails *fdp, **fdpp;
  103. char *cpos, *space;
  104. int allowextend;
  105. if (!*value)
  106. parse_error(ps, _("empty file details field '%s'"), fip->name);
  107. if (!(ps->flags & pdb_recordavailable))
  108. parse_error(ps,
  109. _("file details field '%s' not allowed in status file"),
  110. fip->name);
  111. allowextend = !pkg->files;
  112. fdpp = &pkg->files;
  113. cpos= nfstrsave(value);
  114. while (*cpos) {
  115. space = cpos;
  116. while (*space && !c_isspace(*space))
  117. space++;
  118. if (*space)
  119. *space++ = '\0';
  120. fdp= *fdpp;
  121. if (!fdp) {
  122. if (!allowextend)
  123. parse_error(ps,
  124. _("too many values in file details field '%s' "
  125. "(compared to others)"), fip->name);
  126. fdp= nfmalloc(sizeof(struct filedetails));
  127. fdp->next= NULL;
  128. fdp->name= fdp->msdosname= fdp->size= fdp->md5sum= NULL;
  129. *fdpp= fdp;
  130. }
  131. STRUCTFIELD(fdp, fip->integer, const char *) = cpos;
  132. fdpp= &fdp->next;
  133. while (*space && c_isspace(*space))
  134. space++;
  135. cpos= space;
  136. }
  137. if (*fdpp)
  138. parse_error(ps,
  139. _("too few values in file details field '%s' "
  140. "(compared to others)"), fip->name);
  141. }
  142. void
  143. f_charfield(struct pkginfo *pkg, struct pkgbin *pkgbin,
  144. struct parsedb_state *ps,
  145. const char *value, const struct fieldinfo *fip)
  146. {
  147. if (*value)
  148. STRUCTFIELD(pkgbin, fip->integer, char *) = nfstrsave(value);
  149. }
  150. void
  151. f_boolean(struct pkginfo *pkg, struct pkgbin *pkgbin,
  152. struct parsedb_state *ps,
  153. const char *value, const struct fieldinfo *fip)
  154. {
  155. bool boolean;
  156. if (!*value)
  157. return;
  158. boolean = parse_nv(ps, PARSE_NV_LAST, &value, booleaninfos,
  159. _("yes/no in boolean field"));
  160. STRUCTFIELD(pkgbin, fip->integer, bool) = boolean;
  161. }
  162. void
  163. f_multiarch(struct pkginfo *pkg, struct pkgbin *pkgbin,
  164. struct parsedb_state *ps,
  165. const char *value, const struct fieldinfo *fip)
  166. {
  167. int multiarch;
  168. if (!*value)
  169. return;
  170. multiarch = parse_nv(ps, PARSE_NV_LAST, &value, multiarchinfos,
  171. _("foreign/allowed/same/no in quadstate field"));
  172. STRUCTFIELD(pkgbin, fip->integer, int) = multiarch;
  173. }
  174. void
  175. f_architecture(struct pkginfo *pkg, struct pkgbin *pkgbin,
  176. struct parsedb_state *ps,
  177. const char *value, const struct fieldinfo *fip)
  178. {
  179. pkgbin->arch = dpkg_arch_find(value);
  180. if (pkgbin->arch->type == DPKG_ARCH_ILLEGAL)
  181. parse_warn(ps, _("'%s' is not a valid architecture name: %s"),
  182. value, dpkg_arch_name_is_illegal(value));
  183. }
  184. void
  185. f_section(struct pkginfo *pkg, struct pkgbin *pkgbin,
  186. struct parsedb_state *ps,
  187. const char *value, const struct fieldinfo *fip)
  188. {
  189. if (!*value) return;
  190. pkg->section = nfstrsave(value);
  191. }
  192. void
  193. f_priority(struct pkginfo *pkg, struct pkgbin *pkgbin,
  194. struct parsedb_state *ps,
  195. const char *value, const struct fieldinfo *fip)
  196. {
  197. const char *str = value;
  198. int priority;
  199. if (!*value) return;
  200. priority = parse_nv(ps, PARSE_NV_LAST | PARSE_NV_FALLBACK, &str,
  201. priorityinfos, _("word in 'Priority' field"));
  202. if (str == NULL) {
  203. pkg->priority = PKG_PRIO_OTHER;
  204. pkg->otherpriority = nfstrsave(value);
  205. } else {
  206. pkg->priority = priority;
  207. }
  208. }
  209. void
  210. f_status(struct pkginfo *pkg, struct pkgbin *pkgbin,
  211. struct parsedb_state *ps,
  212. const char *value, const struct fieldinfo *fip)
  213. {
  214. if (ps->flags & pdb_rejectstatus)
  215. parse_error(ps,
  216. _("value for '%s' field not allowed in this context"),
  217. "Status");
  218. if (ps->flags & pdb_recordavailable)
  219. return;
  220. pkg->want = parse_nv(ps, PARSE_NV_NEXT, &value, wantinfos,
  221. _("first (want) word in 'Status' field"));
  222. pkg->eflag = parse_nv(ps, PARSE_NV_NEXT, &value, eflaginfos,
  223. _("second (error) word in 'Status' field"));
  224. pkg->status = parse_nv(ps, PARSE_NV_LAST, &value, statusinfos,
  225. _("third (status) word in 'Status' field"));
  226. }
  227. void
  228. f_version(struct pkginfo *pkg, struct pkgbin *pkgbin,
  229. struct parsedb_state *ps,
  230. const char *value, const struct fieldinfo *fip)
  231. {
  232. parse_db_version(ps, &pkgbin->version, value,
  233. _("error in '%s' field string '%.250s'"),
  234. "Version", value);
  235. }
  236. void
  237. f_revision(struct pkginfo *pkg, struct pkgbin *pkgbin,
  238. struct parsedb_state *ps,
  239. const char *value, const struct fieldinfo *fip)
  240. {
  241. char *newversion;
  242. parse_warn(ps,
  243. _("obsolete '%s' or '%s' field used"),
  244. "Revision", "Package-Revision");
  245. if (!*value) return;
  246. if (str_is_set(pkgbin->version.revision)) {
  247. newversion = nfmalloc(strlen(pkgbin->version.version) +
  248. strlen(pkgbin->version.revision) + 2);
  249. sprintf(newversion, "%s-%s", pkgbin->version.version,
  250. pkgbin->version.revision);
  251. pkgbin->version.version = newversion;
  252. }
  253. pkgbin->version.revision = nfstrsave(value);
  254. }
  255. void
  256. f_configversion(struct pkginfo *pkg, struct pkgbin *pkgbin,
  257. struct parsedb_state *ps,
  258. const char *value, const struct fieldinfo *fip)
  259. {
  260. if (ps->flags & pdb_rejectstatus)
  261. parse_error(ps,
  262. _("value for '%s' field not allowed in this context"),
  263. "Config-Version");
  264. if (ps->flags & pdb_recordavailable)
  265. return;
  266. parse_db_version(ps, &pkg->configversion, value,
  267. _("error in '%s' field string '%.250s'"),
  268. "Config-Version", value);
  269. }
  270. /*
  271. * The code in f_conffiles ensures that value[-1] == ' ', which is helpful.
  272. */
  273. static void conffvalue_lastword(const char *value, const char *from,
  274. const char *endent,
  275. const char **word_start_r, int *word_len_r,
  276. const char **new_from_r,
  277. struct parsedb_state *ps)
  278. {
  279. const char *lastspc;
  280. if (from <= value+1) goto malformed;
  281. for (lastspc= from-1; *lastspc != ' '; lastspc--);
  282. if (lastspc <= value+1 || lastspc >= endent-1) goto malformed;
  283. *new_from_r= lastspc;
  284. *word_start_r= lastspc + 1;
  285. *word_len_r= (int)(from - *word_start_r);
  286. return;
  287. malformed:
  288. parse_error(ps,
  289. _("value for '%s' field has malformatted line '%.*s'"),
  290. "Conffiles", (int)min(endent - value, 250), value);
  291. }
  292. void
  293. f_conffiles(struct pkginfo *pkg, struct pkgbin *pkgbin,
  294. struct parsedb_state *ps,
  295. const char *value, const struct fieldinfo *fip)
  296. {
  297. static const char obsolete_str[]= "obsolete";
  298. struct conffile **lastp, *newlink;
  299. const char *endent, *endfn, *hashstart;
  300. int c, namelen, hashlen;
  301. bool obsolete;
  302. char *newptr;
  303. lastp = &pkgbin->conffiles;
  304. while (*value) {
  305. c= *value++;
  306. if (c == '\n') continue;
  307. if (c != ' ')
  308. parse_error(ps,
  309. _("value for '%s' has line starting with non-space '%c'"),
  310. "Conffiles", c);
  311. for (endent = value; (c = *endent) != '\0' && c != '\n'; endent++) ;
  312. conffvalue_lastword(value, endent, endent,
  313. &hashstart, &hashlen, &endfn,
  314. ps);
  315. obsolete= (hashlen == sizeof(obsolete_str)-1 &&
  316. memcmp(hashstart, obsolete_str, hashlen) == 0);
  317. if (obsolete)
  318. conffvalue_lastword(value, endfn, endent,
  319. &hashstart, &hashlen, &endfn,
  320. ps);
  321. newlink= nfmalloc(sizeof(struct conffile));
  322. value = path_skip_slash_dotslash(value);
  323. namelen= (int)(endfn-value);
  324. if (namelen <= 0)
  325. parse_error(ps,
  326. _("root or null directory is listed as a conffile"));
  327. newptr = nfmalloc(namelen+2);
  328. newptr[0]= '/';
  329. memcpy(newptr+1,value,namelen);
  330. newptr[namelen+1] = '\0';
  331. newlink->name= newptr;
  332. newptr= nfmalloc(hashlen+1);
  333. memcpy(newptr, hashstart, hashlen);
  334. newptr[hashlen] = '\0';
  335. newlink->hash= newptr;
  336. newlink->obsolete= obsolete;
  337. newlink->next =NULL;
  338. *lastp= newlink;
  339. lastp= &newlink->next;
  340. value= endent;
  341. }
  342. }
  343. void
  344. f_dependency(struct pkginfo *pkg, struct pkgbin *pkgbin,
  345. struct parsedb_state *ps,
  346. const char *value, const struct fieldinfo *fip)
  347. {
  348. char c1, c2;
  349. const char *p, *emsg;
  350. const char *depnamestart, *versionstart;
  351. int depnamelength, versionlength;
  352. static struct varbuf depname, version;
  353. struct dependency *dyp, **ldypp;
  354. struct deppossi *dop, **ldopp;
  355. /* Empty fields are ignored. */
  356. if (!*value)
  357. return;
  358. p= value;
  359. ldypp = &pkgbin->depends;
  360. while (*ldypp)
  361. ldypp = &(*ldypp)->next;
  362. /* Loop creating new struct dependency's. */
  363. for (;;) {
  364. dyp= nfmalloc(sizeof(struct dependency));
  365. /* Set this to NULL for now, as we don't know what our real
  366. * struct pkginfo address (in the database) is going to be yet. */
  367. dyp->up = NULL;
  368. dyp->next= NULL; *ldypp= dyp; ldypp= &dyp->next;
  369. dyp->list= NULL; ldopp= &dyp->list;
  370. dyp->type= fip->integer;
  371. /* Loop creating new struct deppossi's. */
  372. for (;;) {
  373. depnamestart= p;
  374. /* Skip over package name characters. */
  375. while (*p && !c_isspace(*p) && *p != ':' && *p != '(' && *p != ',' &&
  376. *p != '|')
  377. p++;
  378. depnamelength= p - depnamestart ;
  379. if (depnamelength == 0)
  380. parse_error(ps,
  381. _("'%s' field, missing package name, or garbage where "
  382. "package name expected"), fip->name);
  383. varbuf_reset(&depname);
  384. varbuf_add_buf(&depname, depnamestart, depnamelength);
  385. varbuf_end_str(&depname);
  386. emsg = pkg_name_is_illegal(depname.buf);
  387. if (emsg)
  388. parse_error(ps,
  389. _("'%s' field, invalid package name '%.255s': %s"),
  390. fip->name, depname.buf, emsg);
  391. dop= nfmalloc(sizeof(struct deppossi));
  392. dop->up= dyp;
  393. dop->ed = pkg_db_find_set(depname.buf);
  394. dop->next= NULL; *ldopp= dop; ldopp= &dop->next;
  395. /* Don't link this (which is after all only ‘new_pkg’ from
  396. * the main parsing loop in parsedb) into the depended on
  397. * packages' lists yet. This will be done later when we
  398. * install this (in parse.c). For the moment we do the
  399. * ‘forward’ links in deppossi (‘ed’) only, and the ‘backward’
  400. * links from the depended on packages to dop are left undone. */
  401. dop->rev_next = NULL;
  402. dop->rev_prev = NULL;
  403. dop->cyclebreak = false;
  404. /* See if we have an architecture qualifier. */
  405. if (*p == ':') {
  406. static struct varbuf arch;
  407. const char *archstart;
  408. int archlength;
  409. archstart = ++p;
  410. while (*p && !c_isspace(*p) && *p != '(' && *p != ',' && *p != '|')
  411. p++;
  412. archlength = p - archstart;
  413. if (archlength == 0)
  414. parse_error(ps, _("'%s' field, missing architecture name, or garbage "
  415. "where architecture name expected"), fip->name);
  416. varbuf_reset(&arch);
  417. varbuf_add_buf(&arch, archstart, archlength);
  418. varbuf_end_str(&arch);
  419. dop->arch_is_implicit = false;
  420. dop->arch = dpkg_arch_find(arch.buf);
  421. if (dop->arch->type == DPKG_ARCH_ILLEGAL)
  422. emsg = dpkg_arch_name_is_illegal(arch.buf);
  423. if (emsg)
  424. parse_error(ps, _("'%s' field, reference to '%.255s': "
  425. "invalid architecture name '%.255s': %s"),
  426. fip->name, depname.buf, arch.buf, emsg);
  427. } else if (fip->integer == dep_conflicts || fip->integer == dep_breaks ||
  428. fip->integer == dep_replaces) {
  429. /* Conflics/Breaks/Replaces get an implicit "any" arch qualifier. */
  430. dop->arch_is_implicit = true;
  431. dop->arch = dpkg_arch_get(DPKG_ARCH_WILDCARD);
  432. } else {
  433. /* Otherwise use the pkgbin architecture, which will be assigned to
  434. * later on by parse.c, once we can guarantee we have parsed it from
  435. * the control stanza. */
  436. dop->arch_is_implicit = true;
  437. dop->arch = NULL;
  438. }
  439. /* Skip whitespace after package name. */
  440. while (c_isspace(*p))
  441. p++;
  442. /* See if we have a versioned relation. */
  443. if (*p == '(') {
  444. p++;
  445. while (c_isspace(*p))
  446. p++;
  447. c1= *p;
  448. if (c1 == '<' || c1 == '>') {
  449. c2= *++p;
  450. dop->verrel = (c1 == '<') ? DPKG_RELATION_LT : DPKG_RELATION_GT;
  451. if (c2 == '=') {
  452. dop->verrel |= DPKG_RELATION_EQ;
  453. p++;
  454. } else if (c2 == c1) {
  455. /* Either ‘<<’ or ‘>>’. */
  456. p++;
  457. } else if (c2 == '<' || c2 == '>') {
  458. parse_error(ps,
  459. _("'%s' field, reference to '%.255s':\n"
  460. " bad version relationship %c%c"),
  461. fip->name, depname.buf, c1, c2);
  462. dop->verrel = DPKG_RELATION_NONE;
  463. } else {
  464. parse_warn(ps,
  465. _("'%s' field, reference to '%.255s':\n"
  466. " '%c' is obsolete, use '%c=' or '%c%c' instead"),
  467. fip->name, depname.buf, c1, c1, c1, c1);
  468. dop->verrel |= DPKG_RELATION_EQ;
  469. }
  470. } else if (c1 == '=') {
  471. dop->verrel = DPKG_RELATION_EQ;
  472. p++;
  473. } else {
  474. parse_warn(ps,
  475. _("'%s' field, reference to '%.255s':\n"
  476. " implicit exact match on version number, "
  477. "suggest using '=' instead"),
  478. fip->name, depname.buf);
  479. dop->verrel = DPKG_RELATION_EQ;
  480. }
  481. if ((dop->verrel != DPKG_RELATION_EQ) && (fip->integer == dep_provides))
  482. parse_warn(ps,
  483. _("only exact versions may be used for '%s' field"),
  484. "Provides");
  485. if (!c_isspace(*p) && !c_isalnum(*p)) {
  486. parse_warn(ps,
  487. _("'%s' field, reference to '%.255s':\n"
  488. " version value starts with non-alphanumeric, "
  489. "suggest adding a space"),
  490. fip->name, depname.buf);
  491. }
  492. /* Skip spaces between the relation and the version. */
  493. while (c_isspace(*p))
  494. p++;
  495. versionstart= p;
  496. while (*p && *p != ')' && *p != '(') {
  497. if (c_isspace(*p))
  498. break;
  499. p++;
  500. }
  501. versionlength= p - versionstart;
  502. while (c_isspace(*p))
  503. p++;
  504. if (*p == '(')
  505. parse_error(ps,
  506. _("'%s' field, reference to '%.255s': "
  507. "version contains '%c'"), fip->name, depname.buf, ')');
  508. else if (*p != ')')
  509. parse_error(ps,
  510. _("'%s' field, reference to '%.255s': "
  511. "version contains '%c'"), fip->name, depname.buf, ' ');
  512. else if (*p == '\0')
  513. parse_error(ps,
  514. _("'%s' field, reference to '%.255s': "
  515. "version unterminated"), fip->name, depname.buf);
  516. varbuf_reset(&version);
  517. varbuf_add_buf(&version, versionstart, versionlength);
  518. varbuf_end_str(&version);
  519. parse_db_version(ps, &dop->version, version.buf,
  520. _("'%s' field, reference to '%.255s': "
  521. "error in version"), fip->name, depname.buf);
  522. p++;
  523. while (c_isspace(*p))
  524. p++;
  525. } else {
  526. dop->verrel = DPKG_RELATION_NONE;
  527. dpkg_version_blank(&dop->version);
  528. }
  529. if (!*p || *p == ',') break;
  530. if (*p != '|')
  531. parse_error(ps,
  532. _("'%s' field, syntax error after reference to package '%.255s'"),
  533. fip->name, dop->ed->name);
  534. if (fip->integer == dep_conflicts ||
  535. fip->integer == dep_breaks ||
  536. fip->integer == dep_provides ||
  537. fip->integer == dep_replaces)
  538. parse_error(ps,
  539. _("alternatives ('|') not allowed in %s field"), fip->name);
  540. p++;
  541. while (c_isspace(*p))
  542. p++;
  543. }
  544. if (!*p) break;
  545. p++;
  546. while (c_isspace(*p))
  547. p++;
  548. }
  549. }
  550. static const char *
  551. scan_word(const char **valp)
  552. {
  553. static struct varbuf word;
  554. const char *p, *start, *end;
  555. p = *valp;
  556. for (;;) {
  557. if (!*p) {
  558. *valp = p;
  559. return NULL;
  560. }
  561. if (c_iswhite(*p)) {
  562. p++;
  563. continue;
  564. }
  565. start = p;
  566. break;
  567. }
  568. for (;;) {
  569. if (*p && !c_iswhite(*p)) {
  570. p++;
  571. continue;
  572. }
  573. end = p;
  574. break;
  575. }
  576. varbuf_reset(&word);
  577. varbuf_add_buf(&word, start, end - start);
  578. varbuf_end_str(&word);
  579. *valp = p;
  580. return word.buf;
  581. }
  582. void
  583. f_trigpend(struct pkginfo *pend, struct pkgbin *pkgbin,
  584. struct parsedb_state *ps,
  585. const char *value, const struct fieldinfo *fip)
  586. {
  587. const char *word, *emsg;
  588. if (ps->flags & pdb_rejectstatus)
  589. parse_error(ps,
  590. _("value for '%s' field not allowed in this context"),
  591. "Triggers-Pending");
  592. while ((word = scan_word(&value))) {
  593. emsg = trig_name_is_illegal(word);
  594. if (emsg)
  595. parse_error(ps,
  596. _("illegal pending trigger name '%.255s': %s"), word, emsg);
  597. if (!trig_note_pend_core(pend, nfstrsave(word)))
  598. parse_error(ps,
  599. _("duplicate pending trigger '%.255s'"), word);
  600. }
  601. }
  602. void
  603. f_trigaw(struct pkginfo *aw, struct pkgbin *pkgbin,
  604. struct parsedb_state *ps,
  605. const char *value, const struct fieldinfo *fip)
  606. {
  607. const char *word;
  608. struct pkginfo *pend;
  609. if (ps->flags & pdb_rejectstatus)
  610. parse_error(ps,
  611. _("value for '%s' field not allowed in this context"),
  612. "Triggers-Awaited");
  613. while ((word = scan_word(&value))) {
  614. struct dpkg_error err;
  615. pend = pkg_spec_parse_pkg(word, &err);
  616. if (pend == NULL)
  617. parse_error(ps,
  618. _("illegal package name in awaited trigger '%.255s': %s"),
  619. word, err.str);
  620. if (!trig_note_aw(pend, aw))
  621. parse_error(ps,
  622. _("duplicate awaited trigger package '%.255s'"), word);
  623. trig_awaited_pend_enqueue(pend);
  624. }
  625. }