FieldsCore.pm 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. # Copyright © 2007-2009 Raphaël Hertzog <hertzog@debian.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. package Dpkg::Control::FieldsCore;
  16. use strict;
  17. use warnings;
  18. our $VERSION = '1.00';
  19. our @EXPORT = qw(
  20. field_capitalize
  21. field_is_official
  22. field_is_allowed_in
  23. field_transfer_single
  24. field_transfer_all
  25. field_list_src_dep
  26. field_list_pkg_dep
  27. field_get_dep_type
  28. field_get_sep_type
  29. field_ordered_list
  30. field_register
  31. field_insert_after
  32. field_insert_before
  33. FIELD_SEP_UNKNOWN
  34. FIELD_SEP_SPACE
  35. FIELD_SEP_COMMA
  36. FIELD_SEP_LINE
  37. );
  38. use Exporter qw(import);
  39. use Dpkg::Gettext;
  40. use Dpkg::ErrorHandling;
  41. use Dpkg::Control::Types;
  42. use Dpkg::Checksums;
  43. use constant {
  44. ALL_PKG => CTRL_INFO_PKG | CTRL_INDEX_PKG | CTRL_PKG_DEB | CTRL_FILE_STATUS,
  45. ALL_SRC => CTRL_INFO_SRC | CTRL_INDEX_SRC | CTRL_PKG_SRC,
  46. ALL_CHANGES => CTRL_FILE_CHANGES | CTRL_CHANGELOG,
  47. };
  48. use constant {
  49. FIELD_SEP_UNKNOWN => 0,
  50. FIELD_SEP_SPACE => 1,
  51. FIELD_SEP_COMMA => 2,
  52. FIELD_SEP_LINE => 4,
  53. };
  54. # The canonical list of fields
  55. # Note that fields used only in dpkg's available file are not listed
  56. # Deprecated fields of dpkg's status file are also not listed
  57. our %FIELDS = (
  58. 'Architecture' => {
  59. allowed => (ALL_PKG | ALL_SRC | CTRL_FILE_CHANGES) & (~CTRL_INFO_SRC),
  60. separator => FIELD_SEP_SPACE,
  61. },
  62. 'Architectures' => {
  63. allowed => CTRL_REPO_RELEASE,
  64. separator => FIELD_SEP_SPACE,
  65. },
  66. 'Binary' => {
  67. allowed => CTRL_PKG_SRC | CTRL_FILE_CHANGES,
  68. # XXX: This field values are separated either by space or comma
  69. # depending on the context.
  70. separator => FIELD_SEP_SPACE | FIELD_SEP_COMMA,
  71. },
  72. 'Binary-Only' => {
  73. allowed => ALL_CHANGES,
  74. },
  75. 'Breaks' => {
  76. allowed => ALL_PKG,
  77. separator => FIELD_SEP_COMMA,
  78. dependency => 'union',
  79. dep_order => 7,
  80. },
  81. 'Bugs' => {
  82. allowed => (ALL_PKG | CTRL_INFO_SRC | CTRL_FILE_VENDOR) & (~CTRL_INFO_PKG),
  83. },
  84. 'Build-Conflicts' => {
  85. allowed => ALL_SRC,
  86. separator => FIELD_SEP_COMMA,
  87. dependency => 'union',
  88. dep_order => 4,
  89. },
  90. 'Build-Conflicts-Arch' => {
  91. allowed => ALL_SRC,
  92. separator => FIELD_SEP_COMMA,
  93. dependency => 'union',
  94. dep_order => 5,
  95. },
  96. 'Build-Conflicts-Indep' => {
  97. allowed => ALL_SRC,
  98. separator => FIELD_SEP_COMMA,
  99. dependency => 'union',
  100. dep_order => 6,
  101. },
  102. 'Build-Depends' => {
  103. allowed => ALL_SRC,
  104. separator => FIELD_SEP_COMMA,
  105. dependency => 'normal',
  106. dep_order => 1,
  107. },
  108. 'Build-Depends-Arch' => {
  109. allowed => ALL_SRC,
  110. separator => FIELD_SEP_COMMA,
  111. dependency => 'normal',
  112. dep_order => 2,
  113. },
  114. 'Build-Depends-Indep' => {
  115. allowed => ALL_SRC,
  116. separator => FIELD_SEP_COMMA,
  117. dependency => 'normal',
  118. dep_order => 3,
  119. },
  120. 'Build-Essential' => {
  121. allowed => ALL_PKG,
  122. },
  123. 'Build-Profiles' => {
  124. allowed => CTRL_INFO_PKG,
  125. separator => FIELD_SEP_SPACE,
  126. },
  127. 'Built-For-Profiles' => {
  128. allowed => ALL_PKG | CTRL_FILE_CHANGES,
  129. separator => FIELD_SEP_SPACE,
  130. },
  131. 'Built-Using' => {
  132. allowed => ALL_PKG,
  133. separator => FIELD_SEP_COMMA,
  134. dependency => 'union',
  135. dep_order => 10,
  136. },
  137. 'Changed-By' => {
  138. allowed => CTRL_FILE_CHANGES,
  139. },
  140. 'Changelogs' => {
  141. allowed => CTRL_REPO_RELEASE,
  142. },
  143. 'Changes' => {
  144. allowed => ALL_CHANGES,
  145. },
  146. 'Closes' => {
  147. allowed => ALL_CHANGES,
  148. separator => FIELD_SEP_SPACE,
  149. },
  150. 'Codename' => {
  151. allowed => CTRL_REPO_RELEASE,
  152. },
  153. 'Components' => {
  154. allowed => CTRL_REPO_RELEASE,
  155. separator => FIELD_SEP_SPACE,
  156. },
  157. 'Conffiles' => {
  158. allowed => CTRL_FILE_STATUS,
  159. separator => FIELD_SEP_LINE | FIELD_SEP_SPACE,
  160. },
  161. 'Config-Version' => {
  162. allowed => CTRL_FILE_STATUS,
  163. },
  164. 'Conflicts' => {
  165. allowed => ALL_PKG,
  166. separator => FIELD_SEP_COMMA,
  167. dependency => 'union',
  168. dep_order => 6,
  169. },
  170. 'Date' => {
  171. allowed => ALL_CHANGES | CTRL_REPO_RELEASE,
  172. },
  173. 'Depends' => {
  174. allowed => ALL_PKG,
  175. separator => FIELD_SEP_COMMA,
  176. dependency => 'normal',
  177. dep_order => 2,
  178. },
  179. 'Description' => {
  180. allowed => ALL_PKG | CTRL_FILE_CHANGES | CTRL_REPO_RELEASE,
  181. },
  182. 'Directory' => {
  183. allowed => CTRL_INDEX_SRC,
  184. },
  185. 'Distribution' => {
  186. allowed => ALL_CHANGES,
  187. },
  188. 'Enhances' => {
  189. allowed => ALL_PKG,
  190. separator => FIELD_SEP_COMMA,
  191. dependency => 'union',
  192. dep_order => 5,
  193. },
  194. 'Essential' => {
  195. allowed => ALL_PKG,
  196. },
  197. 'Filename' => {
  198. allowed => CTRL_INDEX_PKG,
  199. separator => FIELD_SEP_LINE | FIELD_SEP_SPACE,
  200. },
  201. 'Files' => {
  202. allowed => CTRL_PKG_SRC | CTRL_FILE_CHANGES,
  203. separator => FIELD_SEP_LINE | FIELD_SEP_SPACE,
  204. },
  205. 'Format' => {
  206. allowed => CTRL_PKG_SRC | CTRL_FILE_CHANGES,
  207. },
  208. 'Homepage' => {
  209. allowed => ALL_SRC | ALL_PKG,
  210. },
  211. 'Installed-Size' => {
  212. allowed => ALL_PKG & ~CTRL_INFO_PKG,
  213. },
  214. 'Installer-Menu-Item' => {
  215. allowed => ALL_PKG,
  216. },
  217. 'Kernel-Version' => {
  218. allowed => ALL_PKG,
  219. },
  220. 'Label' => {
  221. allowed => CTRL_REPO_RELEASE,
  222. },
  223. 'Origin' => {
  224. allowed => (ALL_PKG | ALL_SRC | CTRL_REPO_RELEASE) & (~CTRL_INFO_PKG),
  225. },
  226. 'Maintainer' => {
  227. allowed => CTRL_PKG_DEB| CTRL_FILE_STATUS | ALL_SRC | ALL_CHANGES,
  228. },
  229. 'Multi-Arch' => {
  230. allowed => ALL_PKG,
  231. },
  232. 'Package' => {
  233. allowed => ALL_PKG,
  234. },
  235. 'Package-List' => {
  236. allowed => ALL_SRC & ~CTRL_INFO_SRC,
  237. separator => FIELD_SEP_LINE | FIELD_SEP_SPACE,
  238. },
  239. 'Package-Type' => {
  240. allowed => ALL_PKG,
  241. },
  242. 'Parent' => {
  243. allowed => CTRL_FILE_VENDOR,
  244. },
  245. 'Pre-Depends' => {
  246. allowed => ALL_PKG,
  247. separator => FIELD_SEP_COMMA,
  248. dependency => 'normal',
  249. dep_order => 1,
  250. },
  251. 'Priority' => {
  252. allowed => CTRL_INFO_SRC | CTRL_INDEX_SRC | ALL_PKG,
  253. },
  254. 'Provides' => {
  255. allowed => ALL_PKG,
  256. separator => FIELD_SEP_COMMA,
  257. dependency => 'union',
  258. dep_order => 9,
  259. },
  260. 'Recommends' => {
  261. allowed => ALL_PKG,
  262. separator => FIELD_SEP_COMMA,
  263. dependency => 'normal',
  264. dep_order => 3,
  265. },
  266. 'Replaces' => {
  267. allowed => ALL_PKG,
  268. separator => FIELD_SEP_COMMA,
  269. dependency => 'union',
  270. dep_order => 8,
  271. },
  272. 'Section' => {
  273. allowed => CTRL_INFO_SRC | CTRL_INDEX_SRC | ALL_PKG,
  274. },
  275. 'Size' => {
  276. allowed => CTRL_INDEX_PKG,
  277. separator => FIELD_SEP_LINE | FIELD_SEP_SPACE,
  278. },
  279. 'Source' => {
  280. allowed => (ALL_PKG | ALL_SRC | ALL_CHANGES) &
  281. (~(CTRL_INDEX_SRC | CTRL_INFO_PKG)),
  282. },
  283. 'Standards-Version' => {
  284. allowed => ALL_SRC,
  285. },
  286. 'Status' => {
  287. allowed => CTRL_FILE_STATUS,
  288. separator => FIELD_SEP_SPACE,
  289. },
  290. 'Subarchitecture' => {
  291. allowed => ALL_PKG,
  292. },
  293. 'Suite' => {
  294. allowed => CTRL_REPO_RELEASE,
  295. },
  296. 'Suggests' => {
  297. allowed => ALL_PKG,
  298. separator => FIELD_SEP_COMMA,
  299. dependency => 'normal',
  300. dep_order => 4,
  301. },
  302. 'Tag' => {
  303. allowed => ALL_PKG,
  304. separator => FIELD_SEP_COMMA,
  305. },
  306. 'Task' => {
  307. allowed => ALL_PKG,
  308. },
  309. 'Testsuite' => {
  310. allowed => ALL_SRC,
  311. separator => FIELD_SEP_COMMA,
  312. },
  313. 'Triggers-Awaited' => {
  314. allowed => CTRL_FILE_STATUS,
  315. separator => FIELD_SEP_SPACE,
  316. },
  317. 'Triggers-Pending' => {
  318. allowed => CTRL_FILE_STATUS,
  319. separator => FIELD_SEP_SPACE,
  320. },
  321. 'Uploaders' => {
  322. allowed => ALL_SRC,
  323. separator => FIELD_SEP_COMMA,
  324. },
  325. 'Urgency' => {
  326. allowed => ALL_CHANGES,
  327. },
  328. 'Valid-Until' => {
  329. allowed => CTRL_REPO_RELEASE,
  330. },
  331. 'Vcs-Browser' => {
  332. allowed => ALL_SRC,
  333. },
  334. 'Vcs-Arch' => {
  335. allowed => ALL_SRC,
  336. },
  337. 'Vcs-Bzr' => {
  338. allowed => ALL_SRC,
  339. },
  340. 'Vcs-Cvs' => {
  341. allowed => ALL_SRC,
  342. },
  343. 'Vcs-Darcs' => {
  344. allowed => ALL_SRC,
  345. },
  346. 'Vcs-Git' => {
  347. allowed => ALL_SRC,
  348. },
  349. 'Vcs-Hg' => {
  350. allowed => ALL_SRC,
  351. },
  352. 'Vcs-Mtn' => {
  353. allowed => ALL_SRC,
  354. },
  355. 'Vcs-Svn' => {
  356. allowed => ALL_SRC,
  357. },
  358. 'Vendor' => {
  359. allowed => CTRL_FILE_VENDOR,
  360. },
  361. 'Vendor-Url' => {
  362. allowed => CTRL_FILE_VENDOR,
  363. },
  364. 'Version' => {
  365. allowed => (ALL_PKG | ALL_SRC | ALL_CHANGES) &
  366. (~(CTRL_INFO_SRC | CTRL_INFO_PKG)),
  367. },
  368. );
  369. my @checksum_fields = map { &field_capitalize("Checksums-$_") } checksums_get_list();
  370. my @sum_fields = map { $_ eq 'md5' ? 'MD5sum' : &field_capitalize($_) }
  371. checksums_get_list();
  372. &field_register($_, CTRL_PKG_SRC | CTRL_FILE_CHANGES) foreach @checksum_fields;
  373. &field_register($_, CTRL_INDEX_PKG | CTRL_REPO_RELEASE,
  374. separator => FIELD_SEP_LINE | FIELD_SEP_SPACE) foreach @sum_fields;
  375. our %FIELD_ORDER = (
  376. CTRL_PKG_DEB() => [
  377. qw(Package Package-Type Source Version Built-Using Kernel-Version
  378. Built-For-Profiles Architecture Subarchitecture
  379. Installer-Menu-Item Essential Origin Bugs
  380. Maintainer Installed-Size), &field_list_pkg_dep(),
  381. qw(Section Priority Multi-Arch Homepage Description Tag Task)
  382. ],
  383. CTRL_PKG_SRC() => [
  384. qw(Format Source Binary Architecture Version Origin Maintainer
  385. Uploaders Homepage Standards-Version Vcs-Browser
  386. Vcs-Arch Vcs-Bzr Vcs-Cvs Vcs-Darcs Vcs-Git Vcs-Hg Vcs-Mtn
  387. Vcs-Svn Testsuite), &field_list_src_dep(), qw(Package-List),
  388. @checksum_fields, qw(Files)
  389. ],
  390. CTRL_FILE_CHANGES() => [
  391. qw(Format Date Source Binary Binary-Only Built-For-Profiles Architecture
  392. Version Distribution Urgency Maintainer Changed-By Description
  393. Closes Changes),
  394. @checksum_fields, qw(Files)
  395. ],
  396. CTRL_CHANGELOG() => [
  397. qw(Source Binary-Only Version Distribution Urgency Maintainer
  398. Date Closes Changes)
  399. ],
  400. CTRL_FILE_STATUS() => [ # Same as fieldinfos in lib/dpkg/parse.c
  401. qw(Package Essential Status Priority Section Installed-Size Origin
  402. Maintainer Bugs Architecture Multi-Arch Source Version Config-Version
  403. Replaces Provides Depends Pre-Depends Recommends Suggests Breaks
  404. Conflicts Enhances Conffiles Description Triggers-Pending
  405. Triggers-Awaited)
  406. ],
  407. CTRL_REPO_RELEASE() => [
  408. qw(Origin Label Suite Codename Changelogs Date Valid-Until
  409. Architectures Components Description), @sum_fields
  410. ],
  411. );
  412. # Order for CTRL_INDEX_PKG is derived from CTRL_PKG_DEB
  413. $FIELD_ORDER{CTRL_INDEX_PKG()} = [ @{$FIELD_ORDER{CTRL_PKG_DEB()}} ];
  414. &field_insert_before(CTRL_INDEX_PKG, 'Section', 'Filename', 'Size', @sum_fields);
  415. # Order for CTRL_INDEX_SRC is derived from CTRL_PKG_SRC
  416. $FIELD_ORDER{CTRL_INDEX_SRC()} = [ @{$FIELD_ORDER{CTRL_PKG_SRC()}} ];
  417. @{$FIELD_ORDER{CTRL_INDEX_SRC()}} = map { $_ eq 'Source' ? 'Package' : $_ }
  418. @{$FIELD_ORDER{CTRL_PKG_SRC()}};
  419. &field_insert_after(CTRL_INDEX_SRC, 'Version', 'Priority', 'Section');
  420. &field_insert_before(CTRL_INDEX_SRC, 'Checksums-Md5', 'Directory');
  421. =encoding utf8
  422. =head1 NAME
  423. Dpkg::Control::FieldsCore - manage (list of official) control fields
  424. =head1 DESCRIPTION
  425. The modules contains a list of fieldnames with associated meta-data explaining
  426. in which type of control information they are allowed. The types are the
  427. CTRL_* constants exported by Dpkg::Control.
  428. =head1 FUNCTIONS
  429. =over 4
  430. =item $f = field_capitalize($field_name)
  431. Returns the field name properly capitalized. All characters are lowercase,
  432. except the first of each word (words are separated by a hyphen in field names).
  433. =cut
  434. sub field_capitalize($) {
  435. my $field = lc(shift);
  436. # Some special cases due to history
  437. return 'MD5sum' if $field eq 'md5sum';
  438. return uc($field) if checksums_is_supported($field);
  439. # Generic case
  440. return join '-', map { ucfirst } split /-/, $field;
  441. }
  442. =item field_is_official($fname)
  443. Returns true if the field is official and known.
  444. =cut
  445. sub field_is_official($) {
  446. my $field = field_capitalize(shift);
  447. return exists $FIELDS{$field};
  448. }
  449. =item field_is_allowed_in($fname, @types)
  450. Returns true (1) if the field $fname is allowed in all the types listed in
  451. the list. Note that you can use type sets instead of individual types (ex:
  452. CTRL_FILE_CHANGES | CTRL_CHANGELOG).
  453. field_allowed_in(A|B, C) returns true only if the field is allowed in C
  454. and either A or B.
  455. Undef is returned for non-official fields.
  456. =cut
  457. sub field_is_allowed_in($@) {
  458. my ($field, @types) = @_;
  459. $field = field_capitalize($field);
  460. return unless field_is_official($field);
  461. return 0 if not scalar(@types);
  462. foreach my $type (@types) {
  463. next if $type == CTRL_UNKNOWN; # Always allowed
  464. return 0 unless $FIELDS{$field}{allowed} & $type;
  465. }
  466. return 1;
  467. }
  468. =item field_transfer_single($from, $to, $field)
  469. If appropriate, copy the value of the field named $field taken from the
  470. $from Dpkg::Control object to the $to Dpkg::Control object.
  471. Official fields are copied only if the field is allowed in both types of
  472. objects. Custom fields are treated in a specific manner. When the target
  473. is not among CTRL_PKG_SRC, CTRL_PKG_DEB or CTRL_FILE_CHANGES, then they
  474. are alway copied as is (the X- prefix is kept). Otherwise they are not
  475. copied except if the target object matches the target destination encoded
  476. in the field name. The initial X denoting custom fields can be followed by
  477. one or more letters among "S" (Source: corresponds to CTRL_PKG_SRC), "B"
  478. (Binary: corresponds to CTRL_PKG_DEB) or "C" (Changes: corresponds to
  479. CTRL_FILE_CHANGES).
  480. Returns undef if nothing has been copied or the name of the new field
  481. added to $to otherwise.
  482. =cut
  483. sub field_transfer_single($$;$) {
  484. my ($from, $to, $field) = @_;
  485. $field //= $_;
  486. my ($from_type, $to_type) = ($from->get_type(), $to->get_type());
  487. $field = field_capitalize($field);
  488. if (field_is_allowed_in($field, $from_type, $to_type)) {
  489. $to->{$field} = $from->{$field};
  490. return $field;
  491. } elsif ($field =~ /^X([SBC]*)-/i) {
  492. my $dest = $1;
  493. if (($dest =~ /B/i and $to_type == CTRL_PKG_DEB) or
  494. ($dest =~ /S/i and $to_type == CTRL_PKG_SRC) or
  495. ($dest =~ /C/i and $to_type == CTRL_FILE_CHANGES))
  496. {
  497. my $new = $field;
  498. $new =~ s/^X([SBC]*)-//i;
  499. $to->{$new} = $from->{$field};
  500. return $new;
  501. } elsif ($to_type != CTRL_PKG_DEB and
  502. $to_type != CTRL_PKG_SRC and
  503. $to_type != CTRL_FILE_CHANGES)
  504. {
  505. $to->{$field} = $from->{$field};
  506. return $field;
  507. }
  508. } elsif (not field_is_allowed_in($field, $from_type)) {
  509. warning(g_("unknown information field '%s' in input data in %s"),
  510. $field, $from->get_option('name') || g_('control information'));
  511. }
  512. return;
  513. }
  514. =item field_transfer_all($from, $to)
  515. Transfer all appropriate fields from $from to $to. Calls
  516. field_transfer_single() on all fields available in $from.
  517. Returns the list of fields that have been added to $to.
  518. =cut
  519. sub field_transfer_all($$) {
  520. my ($from, $to) = @_;
  521. my (@res, $res);
  522. foreach my $k (keys %$from) {
  523. $res = field_transfer_single($from, $to, $k);
  524. push @res, $res if $res and defined wantarray;
  525. }
  526. return @res;
  527. }
  528. =item field_ordered_list($type)
  529. Returns an ordered list of fields for a given type of control information.
  530. This list can be used to output the fields in a predictable order.
  531. The list might be empty for types where the order does not matter much.
  532. =cut
  533. sub field_ordered_list($) {
  534. my $type = shift;
  535. return @{$FIELD_ORDER{$type}} if exists $FIELD_ORDER{$type};
  536. return ();
  537. }
  538. =item field_list_src_dep()
  539. List of fields that contains dependencies-like information in a source
  540. Debian package.
  541. =cut
  542. sub field_list_src_dep() {
  543. my @list = sort {
  544. $FIELDS{$a}{dep_order} <=> $FIELDS{$b}{dep_order}
  545. } grep {
  546. field_is_allowed_in($_, CTRL_PKG_SRC) and
  547. exists $FIELDS{$_}{dependency}
  548. } keys %FIELDS;
  549. return @list;
  550. }
  551. =item field_list_pkg_dep()
  552. List of fields that contains dependencies-like information in a binary
  553. Debian package. The fields that express real dependencies are sorted from
  554. the stronger to the weaker.
  555. =cut
  556. sub field_list_pkg_dep() {
  557. my @keys = keys %FIELDS;
  558. my @list = sort {
  559. $FIELDS{$a}{dep_order} <=> $FIELDS{$b}{dep_order}
  560. } grep {
  561. field_is_allowed_in($_, CTRL_PKG_DEB) and
  562. exists $FIELDS{$_}{dependency}
  563. } @keys;
  564. return @list;
  565. }
  566. =item field_get_dep_type($field)
  567. Return the type of the dependency expressed by the given field. Can
  568. either be "normal" for a real dependency field (Pre-Depends, Depends, ...)
  569. or "union" for other relation fields sharing the same syntax (Conflicts,
  570. Breaks, ...). Returns undef for fields which are not dependencies.
  571. =cut
  572. sub field_get_dep_type($) {
  573. my $field = field_capitalize(shift);
  574. return unless field_is_official($field);
  575. return $FIELDS{$field}{dependency} if exists $FIELDS{$field}{dependency};
  576. return;
  577. }
  578. =item field_get_sep_type($field)
  579. Return the type of the field value separator. Can be one of FIELD_SEP_UNKNOWN,
  580. FIELD_SEP_SPACE, FIELD_SEP_COMMA or FIELD_SEP_LINE.
  581. =cut
  582. sub field_get_sep_type($) {
  583. my $field = field_capitalize(shift);
  584. return $FIELDS{$field}{separator} if exists $FIELDS{$field}{separator};
  585. return FIELD_SEP_UNKNOWN;
  586. }
  587. =item field_register($field, $allowed_types, %opts)
  588. Register a new field as being allowed in control information of specified
  589. types. %opts is optional
  590. =cut
  591. sub field_register($$;@) {
  592. my ($field, $types, %opts) = @_;
  593. $field = field_capitalize($field);
  594. $FIELDS{$field} = {
  595. allowed => $types,
  596. %opts
  597. };
  598. }
  599. =item field_insert_after($type, $ref, @fields)
  600. Place field after another one ($ref) in output of control information of
  601. type $type.
  602. =cut
  603. sub field_insert_after($$@) {
  604. my ($type, $field, @fields) = @_;
  605. return 0 if not exists $FIELD_ORDER{$type};
  606. ($field, @fields) = map { field_capitalize($_) } ($field, @fields);
  607. @{$FIELD_ORDER{$type}} = map {
  608. ($_ eq $field) ? ($_, @fields) : $_
  609. } @{$FIELD_ORDER{$type}};
  610. return 1;
  611. }
  612. =item field_insert_before($type, $ref, @fields)
  613. Place field before another one ($ref) in output of control information of
  614. type $type.
  615. =cut
  616. sub field_insert_before($$@) {
  617. my ($type, $field, @fields) = @_;
  618. return 0 if not exists $FIELD_ORDER{$type};
  619. ($field, @fields) = map { field_capitalize($_) } ($field, @fields);
  620. @{$FIELD_ORDER{$type}} = map {
  621. ($_ eq $field) ? (@fields, $_) : $_
  622. } @{$FIELD_ORDER{$type}};
  623. return 1;
  624. }
  625. =back
  626. =head1 CHANGES
  627. =head2 Version 1.00 (dpkg 1.17.0)
  628. Mark the module as public.
  629. =head1 AUTHOR
  630. Raphaël Hertzog <hertzog@debian.org>.
  631. =cut
  632. 1;