dpkg.h.in 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * dpkg.h - general header for Debian package handling
  4. *
  5. * Copyright (C) 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright (C) 2000,2001 Wichert Akkerman <wichert@debian.org>
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2,
  11. * or (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with dpkg; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #ifndef DPKG_H
  23. #define DPKG_H
  24. #include <setjmp.h>
  25. #include <stdarg.h>
  26. #include <stdio.h>
  27. #include <sys/types.h>
  28. #include <myopt.h>
  29. #define ARCHIVEVERSION "2.0"
  30. #define SPLITVERSION "2.1"
  31. #define OLDARCHIVEVERSION "0.939000"
  32. #define SPLITPARTDEFMAX (450*1024)
  33. #define MAXFIELDNAME 200
  34. #define MAXCONFFILENAME 1000
  35. #define MAXDIVERTFILENAME 1024
  36. #define MAXCONTROLFILENAME 100
  37. #define BUILDCONTROLDIR "DEBIAN"
  38. #define EXTRACTCONTROLDIR BUILDCONTROLDIR
  39. #define DEBEXT ".deb"
  40. #define OLDDBEXT "-old"
  41. #define NEWDBEXT "-new"
  42. #define OLDOLDDEBDIR ".DEBIAN"
  43. #define OLDDEBDIR "DEBIAN"
  44. #define REMOVECONFFEXTS "~", ".bak", "%", \
  45. DPKGTEMPEXT, DPKGNEWEXT, DPKGOLDEXT, DPKGDISTEXT
  46. #ifndef ARCHBINFMT
  47. #define ARCHBINFMT
  48. #endif
  49. #define DPKG_VERSION_ARCH DPKG_VERSION " (" ARCHITECTURE ARCHBINFMT ")"
  50. #define NEWCONFFILEFLAG "newconffile"
  51. #define NONEXISTENTFLAG "nonexistent"
  52. #define DPKGTEMPEXT ".dpkg-tmp"
  53. #define DPKGNEWEXT ".dpkg-new"
  54. #define DPKGOLDEXT ".dpkg-old"
  55. #define DPKGDISTEXT ".dpkg-dist"
  56. #define CONTROLFILE "control"
  57. #define CONFFILESFILE "conffiles"
  58. #define PREINSTFILE "preinst"
  59. #define POSTINSTFILE "postinst"
  60. #define PRERMFILE "prerm"
  61. #define POSTRMFILE "postrm"
  62. #define LISTFILE "list"
  63. #define ADMINDIR "#ADMINDIR#"
  64. #define CONFIGDIR "#CONFIGDIR#"
  65. #define STATUSFILE "status"
  66. #define AVAILFILE "available"
  67. #define LOCKFILE "lock"
  68. #define CMETHOPTFILE "cmethopt"
  69. #define METHLOCKFILE "methlock"
  70. #define DIVERSIONSFILE "diversions"
  71. #define STATOVERRIDEFILE "statoverride"
  72. #define UPDATESDIR "updates/"
  73. #define INFODIR "info/"
  74. #define PARTSDIR "parts/"
  75. #define CONTROLDIRTMP "tmp.ci/"
  76. #define IMPORTANTTMP "tmp.i"
  77. #define REASSEMBLETMP "reassemble" DEBEXT
  78. #define IMPORTANTMAXLEN 10
  79. #define IMPORTANTFMT "%04d" /* change => also change lib/database.c:cleanup_updates */
  80. #define MAXUPDATES 50
  81. #define LIBDIR "#LIBDIR#"
  82. #define LOCALLIBDIR "/usr/local/lib/dpkg"
  83. #define METHODSDIR "methods"
  84. #define NOJOBCTRLSTOPENV "DPKG_NO_TSTP"
  85. #define SHELLENV "SHELL"
  86. #define DEFAULTSHELL "sh"
  87. #define PAGERENV "PAGER"
  88. #define DEFAULTPAGER "pager"
  89. #define IMETHODMAXLEN 50
  90. #define IOPTIONMAXLEN IMETHODMAXLEN
  91. #define METHODOPTIONSFILE "names"
  92. #define METHODSETUPSCRIPT "setup"
  93. #define METHODUPDATESCRIPT "update"
  94. #define METHODINSTALLSCRIPT "install"
  95. #define OPTIONSDESCPFX "desc."
  96. #define OPTIONINDEXMAXLEN 5
  97. #define PKGSCRIPTMAXARGS 10
  98. #define MD5HASHLEN 32
  99. #define CONFFOPTCELLS /* int conffoptcells[2] {* 1= user edited *} \
  100. [2] {* 1= distributor edited *} = */ \
  101. /* dist not */ /* dist edited */ \
  102. /* user did not edit */ { cfo_keep, cfo_install }, \
  103. /* user did edit */ { cfo_keep, cfo_prompt_keep }
  104. #define ARCHIVE_FILENAME_PATTERN "*.deb"
  105. #define BACKEND "dpkg-deb"
  106. #define DPKGQUERY "dpkg-query"
  107. #define SPLITTER "dpkg-split"
  108. #define MD5SUM "md5sum"
  109. #define DSELECT "dselect"
  110. #define DPKG "dpkg"
  111. #define DEBSIGVERIFY "/usr/bin/debsig-verify"
  112. #define TAR "tar"
  113. #define GZIP "gzip"
  114. #define RM "rm"
  115. #define FIND "find"
  116. #define SHELL "sh"
  117. #define DIFF "diff"
  118. #define SHELLENVIR "SHELL"
  119. #define FIND_EXPRSTARTCHARS "-(),!"
  120. #define TARBLKSZ 512
  121. /* Take care of NLS matters. */
  122. #if HAVE_LOCALE_H
  123. # include <locale.h>
  124. #endif
  125. #if !HAVE_SETLOCALE
  126. # define setlocale(Category, Locale) /* empty */
  127. #endif
  128. #if ENABLE_NLS
  129. # include <libintl.h>
  130. # define _(Text) gettext (Text)
  131. # define N_(Text) Text
  132. #else
  133. # undef bindtextdomain
  134. # define bindtextdomain(Domain, Directory) /* empty */
  135. # undef textdomain
  136. # define textdomain(Domain) /* empty */
  137. # define _(Text) Text
  138. # define N_(Text) Text
  139. # define gettext(Text) Text
  140. #endif
  141. extern const char thisname[]; /* defined separately in each program */
  142. extern const char printforhelp[];
  143. /*** from startup.c ***/
  144. #define standard_startup(ejbuf, argc, argv, prog, loadcfg, cmdinfos) do {\
  145. setlocale(LC_ALL, "");\
  146. bindtextdomain(PACKAGE, LOCALEDIR);\
  147. textdomain(PACKAGE);\
  148. if (setjmp(*ejbuf)) { /* expect warning about possible clobbering of argv */\
  149. error_unwind(ehflag_bombout); exit(2);\
  150. }\
  151. push_error_handler(ejbuf,print_error_fatal,0);\
  152. umask(022); /* Make sure all our status databases are readable. */\
  153. if (loadcfg)\
  154. loadcfgfile(prog, cmdinfos);\
  155. myopt(argv,cmdinfos);\
  156. } while (0)
  157. #define standard_shutdown(freemem) do {\
  158. set_error_display(0,0);\
  159. error_unwind(ehflag_normaltidy);\
  160. if (freemem)\
  161. nffreeall();\
  162. } while (0)
  163. /*** from ehandle.c ***/
  164. void push_error_handler(jmp_buf *jbufp,
  165. void (*printerror)(const char *, const char *),
  166. const char *contextstring);
  167. void set_error_display(void (*printerror)(const char *, const char *),
  168. const char *contextstring);
  169. void print_error_fatal(const char *emsg, const char *contextstring);
  170. void error_unwind(int flagset);
  171. void push_cleanup(void (*f1)(int argc, void **argv), int flagmask1,
  172. void (*f2)(int argc, void **argv), int flagmask2,
  173. unsigned int nargs, ...);
  174. void push_checkpoint(int mask, int value);
  175. void pop_cleanup(int flagset);
  176. enum { ehflag_normaltidy=01, ehflag_bombout=02, ehflag_recursiveerror=04 };
  177. void do_internerr(const char *string, int line, const char *file) NONRETURNING;
  178. #define internerr(s) do_internerr(s,__LINE__,__FILE__)
  179. struct varbuf;
  180. void ohshit(const char *fmt, ...) NONRETURNPRINTFFORMAT(1,2);
  181. void ohshitv(const char *fmt, va_list al) NONRETURNING;
  182. void ohshite(const char *fmt, ...) NONRETURNPRINTFFORMAT(1,2);
  183. void ohshitvb(struct varbuf*) NONRETURNING;
  184. void badusage(const char *fmt, ...) NONRETURNPRINTFFORMAT(1,2);
  185. void werr(const char *what) NONRETURNING;
  186. /*** from mlib.c ***/
  187. void setcloexec(int fd, const char* fn);
  188. void *m_malloc(size_t);
  189. void *m_realloc(void*, size_t);
  190. int m_fork(void);
  191. void m_dup2(int oldfd, int newfd);
  192. void m_pipe(int fds[2]);
  193. #define PROCPIPE 1
  194. #define PROCWARN 2
  195. #define PROCNOERR 4
  196. int checksubprocerr(int status, const char *description, int flags);
  197. int waitsubproc(pid_t pid, const char *description, int flags);
  198. #define BUFFER_WRITE_BUF 0
  199. #define BUFFER_WRITE_VBUF 1
  200. #define BUFFER_WRITE_FD 2
  201. #define BUFFER_WRITE_NULL 3
  202. #define BUFFER_WRITE_STREAM 4
  203. #define BUFFER_WRITE_MD5 5
  204. #define BUFFER_READ_FD 0
  205. #define BUFFER_READ_STREAM 1
  206. #define BUFFER_WRITE_SETUP 1 << 16
  207. #define BUFFER_READ_SETUP 1 << 17
  208. #define BUFFER_WRITE_SHUTDOWN 1 << 18
  209. #define BUFFER_READ_SHUTDOWN 1 << 19
  210. typedef struct buffer_data *buffer_data_t;
  211. typedef ssize_t (*buffer_proc_t)(buffer_data_t data, void *buf, ssize_t size, const char *desc);
  212. typedef union buffer_arg {
  213. void *ptr;
  214. int i;
  215. } buffer_arg;
  216. struct buffer_data {
  217. buffer_proc_t proc;
  218. buffer_arg data;
  219. int type;
  220. };
  221. #define fd_md5(fd, hash, limit, desc...)\
  222. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  223. hash, BUFFER_WRITE_MD5, NULL, \
  224. limit, desc)
  225. #define stream_md5(file, hash, limit, desc...)\
  226. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  227. hash, BUFFER_WRITE_MD5, NULL, \
  228. limit, desc)
  229. #define fd_fd_copy(fd1, fd2, limit, desc...)\
  230. buffer_copy_setup_IntInt(fd1, BUFFER_READ_FD, NULL, \
  231. fd2, BUFFER_WRITE_FD, NULL, \
  232. limit, desc)
  233. #define fd_buf_copy(fd, buf, limit, desc...)\
  234. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  235. buf, BUFFER_WRITE_BUF, NULL, \
  236. limit, desc)
  237. #define fd_vbuf_copy(fd, buf, limit, desc...)\
  238. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  239. buf, BUFFER_WRITE_VBUF, NULL, \
  240. limit, desc)
  241. #define fd_null_copy(fd, limit, desc...) \
  242. if (lseek(fd, limit, SEEK_CUR) == -1) { \
  243. if(errno != ESPIPE) ohshite(desc); \
  244. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  245. 0, BUFFER_WRITE_NULL, NULL, \
  246. limit, desc);\
  247. }
  248. #define stream_null_copy(file, limit, desc...) \
  249. if (fseek(file, limit, SEEK_CUR) == -1) { \
  250. if(errno != EBADF) ohshite(desc); \
  251. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  252. 0, BUFFER_WRITE_NULL, NULL, \
  253. limit, desc);\
  254. }
  255. #define stream_fd_copy(file, fd, limit, desc...)\
  256. buffer_copy_setup_PtrInt(file, BUFFER_READ_STREAM, NULL, \
  257. fd, BUFFER_WRITE_FD, NULL, \
  258. limit, desc)
  259. ssize_t buffer_copy_setup_PtrInt(void *p, int typeIn, void *procIn,
  260. int i, int typeOut, void *procOut,
  261. ssize_t limit, const char *desc, ...);
  262. ssize_t buffer_copy_setup_PtrPtr(void *p1, int typeIn, void *procIn,
  263. void *p2, int typeOut, void *procOut,
  264. ssize_t limit, const char *desc, ...);
  265. ssize_t buffer_copy_setup_IntPtr(int i, int typeIn, void *procIn,
  266. void *p, int typeOut, void *procOut,
  267. ssize_t limit, const char *desc, ...);
  268. ssize_t buffer_copy_setup_IntInt(int i1, int typeIn, void *procIn,
  269. int i2, int typeOut, void *procOut,
  270. ssize_t limit, const char *desc, ...);
  271. ssize_t buffer_copy_setup(buffer_arg argIn, int typeIn, void *procIn,
  272. buffer_arg argOut, int typeOut, void *procOut,
  273. ssize_t limit, const char *desc);
  274. ssize_t buffer_write(buffer_data_t data, void *buf, ssize_t length, const char *desc);
  275. ssize_t buffer_read(buffer_data_t data, void *buf, ssize_t length, const char *desc);
  276. ssize_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data, ssize_t limit, const char *desc);
  277. extern volatile int onerr_abort;
  278. /*** from showcright.c ***/
  279. struct cmdinfo;
  280. void showcopyright(const struct cmdinfo*, const char*);
  281. /*** from utils.c ***/
  282. int cisdigit(int c);
  283. int cisalpha(int c);
  284. #endif /* DPKG_H */