dpkg.h.in 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. extern const char thisname[]; /* defined separately in each program */
  122. extern const char printforhelp[];
  123. /*** from startup.c ***/
  124. #define standard_startup(ejbuf, argc, argv, prog, loadcfg, cmdinfos) do {\
  125. setlocale(LC_ALL, "");\
  126. bindtextdomain(PACKAGE, LOCALEDIR);\
  127. textdomain(PACKAGE);\
  128. if (setjmp(*ejbuf)) { /* expect warning about possible clobbering of argv */\
  129. error_unwind(ehflag_bombout); exit(2);\
  130. }\
  131. push_error_handler(ejbuf,print_error_fatal,0);\
  132. umask(022); /* Make sure all our status databases are readable. */\
  133. if (loadcfg)\
  134. loadcfgfile(prog, cmdinfos);\
  135. myopt(argv,cmdinfos);\
  136. } while (0)
  137. #define standard_shutdown(freemem) do {\
  138. set_error_display(0,0);\
  139. error_unwind(ehflag_normaltidy);\
  140. if (freemem)\
  141. nffreeall();\
  142. } while (0)
  143. /*** from ehandle.c ***/
  144. void push_error_handler(jmp_buf *jbufp,
  145. void (*printerror)(const char *, const char *),
  146. const char *contextstring);
  147. void set_error_display(void (*printerror)(const char *, const char *),
  148. const char *contextstring);
  149. void print_error_fatal(const char *emsg, const char *contextstring);
  150. void error_unwind(int flagset);
  151. void push_cleanup(void (*f1)(int argc, void **argv), int flagmask1,
  152. void (*f2)(int argc, void **argv), int flagmask2,
  153. unsigned int nargs, ...);
  154. void push_checkpoint(int mask, int value);
  155. void pop_cleanup(int flagset);
  156. enum { ehflag_normaltidy=01, ehflag_bombout=02, ehflag_recursiveerror=04 };
  157. void do_internerr(const char *string, int line, const char *file) NONRETURNING;
  158. #define internerr(s) do_internerr(s,__LINE__,__FILE__)
  159. struct varbuf;
  160. void ohshit(const char *fmt, ...) NONRETURNPRINTFFORMAT(1,2);
  161. void ohshitv(const char *fmt, va_list al) NONRETURNING;
  162. void ohshite(const char *fmt, ...) NONRETURNPRINTFFORMAT(1,2);
  163. void ohshitvb(struct varbuf*) NONRETURNING;
  164. void badusage(const char *fmt, ...) NONRETURNPRINTFFORMAT(1,2);
  165. void werr(const char *what) NONRETURNING;
  166. /*** from mlib.c ***/
  167. void setcloexec(int fd, const char* fn);
  168. void *m_malloc(size_t);
  169. void *m_realloc(void*, size_t);
  170. int m_fork(void);
  171. void m_dup2(int oldfd, int newfd);
  172. void m_pipe(int fds[2]);
  173. #define PROCPIPE 1
  174. #define PROCWARN 2
  175. #define PROCNOERR 4
  176. int checksubprocerr(int status, const char *description, int flags);
  177. int waitsubproc(pid_t pid, const char *description, int flags);
  178. #define BUFFER_WRITE_BUF 0
  179. #define BUFFER_WRITE_VBUF 1
  180. #define BUFFER_WRITE_FD 2
  181. #define BUFFER_WRITE_NULL 3
  182. #define BUFFER_WRITE_STREAM 4
  183. #define BUFFER_WRITE_MD5 5
  184. #define BUFFER_READ_FD 0
  185. #define BUFFER_READ_STREAM 1
  186. #define BUFFER_WRITE_SETUP 1 << 16
  187. #define BUFFER_READ_SETUP 1 << 17
  188. #define BUFFER_WRITE_SHUTDOWN 1 << 18
  189. #define BUFFER_READ_SHUTDOWN 1 << 19
  190. typedef struct buffer_data *buffer_data_t;
  191. typedef off_t (*buffer_proc_t)(buffer_data_t data, void *buf, off_t size, const char *desc);
  192. typedef union buffer_arg {
  193. void *ptr;
  194. int i;
  195. } buffer_arg;
  196. struct buffer_data {
  197. buffer_proc_t proc;
  198. buffer_arg data;
  199. int type;
  200. };
  201. #define fd_md5(fd, hash, limit, desc...)\
  202. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  203. hash, BUFFER_WRITE_MD5, NULL, \
  204. limit, desc)
  205. #define stream_md5(file, hash, limit, desc...)\
  206. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  207. hash, BUFFER_WRITE_MD5, NULL, \
  208. limit, desc)
  209. #define fd_fd_copy(fd1, fd2, limit, desc...)\
  210. buffer_copy_setup_IntInt(fd1, BUFFER_READ_FD, NULL, \
  211. fd2, BUFFER_WRITE_FD, NULL, \
  212. limit, desc)
  213. #define fd_buf_copy(fd, buf, limit, desc...)\
  214. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  215. buf, BUFFER_WRITE_BUF, NULL, \
  216. limit, desc)
  217. #define fd_vbuf_copy(fd, buf, limit, desc...)\
  218. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  219. buf, BUFFER_WRITE_VBUF, NULL, \
  220. limit, desc)
  221. #define fd_null_copy(fd, limit, desc...) \
  222. if (lseek(fd, limit, SEEK_CUR) == -1) { \
  223. if(errno != ESPIPE) ohshite(desc); \
  224. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  225. 0, BUFFER_WRITE_NULL, NULL, \
  226. limit, desc);\
  227. }
  228. #define stream_null_copy(file, limit, desc...) \
  229. if (fseek(file, limit, SEEK_CUR) == -1) { \
  230. if(errno != EBADF) ohshite(desc); \
  231. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  232. 0, BUFFER_WRITE_NULL, NULL, \
  233. limit, desc);\
  234. }
  235. #define stream_fd_copy(file, fd, limit, desc...)\
  236. buffer_copy_setup_PtrInt(file, BUFFER_READ_STREAM, NULL, \
  237. fd, BUFFER_WRITE_FD, NULL, \
  238. limit, desc)
  239. off_t buffer_copy_setup_PtrInt(void *p, int typeIn, void *procIn,
  240. int i, int typeOut, void *procOut,
  241. off_t limit, const char *desc, ...);
  242. off_t buffer_copy_setup_PtrPtr(void *p1, int typeIn, void *procIn,
  243. void *p2, int typeOut, void *procOut,
  244. off_t limit, const char *desc, ...);
  245. off_t buffer_copy_setup_IntPtr(int i, int typeIn, void *procIn,
  246. void *p, int typeOut, void *procOut,
  247. off_t limit, const char *desc, ...);
  248. off_t buffer_copy_setup_IntInt(int i1, int typeIn, void *procIn,
  249. int i2, int typeOut, void *procOut,
  250. off_t limit, const char *desc, ...);
  251. off_t buffer_copy_setup(buffer_arg argIn, int typeIn, void *procIn,
  252. buffer_arg argOut, int typeOut, void *procOut,
  253. off_t limit, const char *desc);
  254. off_t buffer_write(buffer_data_t data, void *buf, off_t length, const char *desc);
  255. off_t buffer_read(buffer_data_t data, void *buf, off_t length, const char *desc);
  256. off_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data, off_t limit, const char *desc);
  257. extern volatile int onerr_abort;
  258. /*** from showcright.c ***/
  259. struct cmdinfo;
  260. void showcopyright(const struct cmdinfo*, const char*);
  261. /*** from utils.c ***/
  262. int cisdigit(int c);
  263. int cisalpha(int c);
  264. #endif /* DPKG_H */