FieldsCore.pm 19 KB

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