Sanitize python object -> tag number exception handling
[platform/upstream/rpm.git] / lib / fsm.h
index f2c7513..3c819b4 100644 (file)
--- a/lib/fsm.h
+++ b/lib/fsm.h
@@ -1,11 +1,14 @@
 #ifndef H_FSM
 #define H_FSM
 
-/** \file lib/fsm.h
+/** \ingroup payload
+ * \file lib/fsm.h
+ * File state machine to handle a payload within an rpm package.
  */
 
-#include <rpmlib.h>
-#include "cpio.h"
+#include <rpm/rpmfi.h>
+
+extern int _fsm_debug;
 
 /**
  */
 #define        FSM_INTERNAL    0x4000
 #define        FSM_SYSCALL     0x2000
 #define        FSM_DEAD        0x1000
+
 #define        _fv(_a)         ((_a) | FSM_VERBOSE)
 #define        _fi(_a)         ((_a) | FSM_INTERNAL)
 #define        _fs(_a)         ((_a) | (FSM_INTERNAL | FSM_SYSCALL))
 #define        _fd(_a)         ((_a) | (FSM_INTERNAL | FSM_DEAD))
+
 typedef enum fileStage_e {
     FSM_UNKNOWN =   0,
     FSM_INIT   =  _fd(1),
@@ -46,18 +51,20 @@ typedef enum fileStage_e {
     FSM_RENAME =  _fs(34),
     FSM_MKDIR  =  _fs(35),
     FSM_RMDIR  =  _fs(36),
-    FSM_CHOWN  =  _fs(37),
-    FSM_LCHOWN =  _fs(38),
-    FSM_CHMOD  =  _fs(39),
-    FSM_UTIME  =  _fs(40),
-    FSM_SYMLINK        =  _fs(41),
-    FSM_LINK   =  _fs(42),
-    FSM_MKFIFO =  _fs(43),
-    FSM_MKNOD  =  _fs(44),
-    FSM_LSTAT  =  _fs(45),
-    FSM_STAT   =  _fs(46),
-    FSM_READLINK=  _fs(47),
-    FSM_CHROOT =  _fs(48),
+    FSM_LSETFCON=  _fs(39),
+    FSM_CHOWN  =  _fs(40),
+    FSM_LCHOWN =  _fs(41),
+    FSM_CHMOD  =  _fs(42),
+    FSM_UTIME  =  _fs(43),
+    FSM_SYMLINK        =  _fs(44),
+    FSM_LINK   =  _fs(45),
+    FSM_MKFIFO =  _fs(46),
+    FSM_MKNOD  =  _fs(47),
+    FSM_LSTAT  =  _fs(48),
+    FSM_STAT   =  _fs(49),
+    FSM_READLINK=  _fs(50),
+    FSM_CHROOT =  _fs(51),
+    FSM_SETCAP =  _fs(52),
 
     FSM_NEXT   =  _fd(65),
     FSM_EAT    =  _fd(66),
@@ -74,7 +81,7 @@ typedef enum fileStage_e {
     FSM_RCLOSE =  _fs(131),
     FSM_WOPEN  =  _fs(132),
     FSM_WRITE  =  _fs(133),
-    FSM_WCLOSE =  _fs(134),
+    FSM_WCLOSE =  _fs(134)
 } fileStage;
 #undef _fv
 #undef _fi
@@ -82,83 +89,81 @@ typedef enum fileStage_e {
 #undef _fd
 
 /** \ingroup payload
- * Keeps track of the set of all hard links to a file in an archive.
- */
-struct hardLink {
-/*@owned@*/ struct hardLink * next;
-/*@owned@*/ const char ** nsuffix;
-/*@owned@*/ int * filex;
-    dev_t dev;
-    ino_t inode;
-    int nlink;
-    int linksLeft;
-    int linkIndex;
-    int createdPath;
-};
-
-/** \ingroup payload
- * Iterator across package file info, forward on install, backward on erase.
  */
-struct fsmIterator_s {
-/*@kept@*/ rpmTransactionSet ts;       /*!< transaction set. */
-/*@kept@*/ TFI_t fi;                   /*!< transaction element file info. */
-    int isave;                         /*!< last returned iterator index. */
-    int i;                             /*!< iterator index. */
-};
+typedef enum cpioMapFlags_e {
+    CPIO_MAP_PATH      = (1 << 0),
+    CPIO_MAP_MODE      = (1 << 1),
+    CPIO_MAP_UID       = (1 << 2),
+    CPIO_MAP_GID       = (1 << 3),
+    CPIO_FOLLOW_SYMLINKS= (1 << 4), /*!< only for building. */
+    CPIO_MAP_ABSOLUTE  = (1 << 5),
+    CPIO_MAP_ADDDOT    = (1 << 6),
+    CPIO_ALL_HARDLINKS = (1 << 7), /*!< fail if hardlinks are missing. */
+    CPIO_MAP_TYPE      = (1 << 8),  /*!< only for building. */
+    CPIO_SBIT_CHECK    = (1 << 9)
+} cpioMapFlags;
+
+typedef struct fsmIterator_s * FSMI_t;
+typedef struct fsm_s * FSM_t;
+
+typedef struct hardLink_s * hardLink_t;
 
 /** \ingroup payload
  * File name and stat information.
  */
 struct fsm_s {
-/*@owned@*/ const char * path;         /*!< Current file name. */
-/*@owned@*/ const char * opath;                /*!< Original file name. */
-    FD_t cfd;                          /*!< Payload file handle. */
-    FD_t rfd;                          /*!<  read: File handle. */
-/*@dependent@*/ char * rdbuf;          /*!<  read: Buffer. */
-/*@owned@*/ char * rdb;                        /*!<  read: Buffer allocated. */
-    size_t rdsize;                     /*!<  read: Buffer allocated size. */
-    size_t rdlen;                      /*!<  read: Number of bytes requested. */
-    size_t rdnb;                       /*!<  read: Number of bytes returned. */
-    FD_t wfd;                          /*!< write: File handle. */
-/*@dependent@*/ char * wrbuf;          /*!< write: Buffer. */
-/*@owned@*/ char * wrb;                        /*!< write: Buffer allocated. */
-    size_t wrsize;                     /*!< write: Buffer allocated size. */
-    size_t wrlen;                      /*!< write: Number of bytes requested. */
-    size_t wrnb;                       /*!< write: Number of bytes returned. */
-/*@only@*/ FSMI_t iter;                        /*!< File iterator. */
-    int ix;                            /*!< Current file iterator index. */
-/*@only@*/ struct hardLink * links;    /*!< Pending hard linked file(s). */
-/*@only@*/ struct hardLink * li;       /*!< Current hard linked file(s). */
-/*@kept@*/ unsigned int * archiveSize; /*!< Pointer to archive size. */
-/*@kept@*/ const char ** failedFile;   /*!< First file name that failed. */
-/*@shared@*/ const char * subdir;      /*!< Current file sub-directory. */
-    char subbuf[64];   /* XXX eliminate */
-/*@observer@*/ const char * osuffix;   /*!< Old, preserved, file suffix. */
-/*@observer@*/ const char * nsuffix;   /*!< New, created, file suffix. */
-/*@shared@*/ const char * suffix;      /*!< Current file suffix. */
+    const char * path;         /*!< Current file name. */
+    const char * opath;                /*!< Original file name. */
+    FD_t cfd;                  /*!< Payload file handle. */
+    FD_t rfd;                  /*!<  read: File handle. */
+    char * rdbuf;              /*!<  read: Buffer. */
+    char * rdb;                        /*!<  read: Buffer allocated. */
+    size_t rdsize;             /*!<  read: Buffer allocated size. */
+    size_t rdlen;              /*!<  read: Number of bytes requested.*/
+    size_t rdnb;               /*!<  read: Number of bytes returned. */
+    FD_t wfd;                  /*!< write: File handle. */
+    char * wrbuf;              /*!< write: Buffer. */
+    char * wrb;                        /*!< write: Buffer allocated. */
+    size_t wrsize;             /*!< write: Buffer allocated size. */
+    size_t wrlen;              /*!< write: Number of bytes requested.*/
+    size_t wrnb;               /*!< write: Number of bytes returned. */
+    FSMI_t iter;               /*!< File iterator. */
+    int ix;                    /*!< Current file iterator index. */
+    hardLink_t links;          /*!< Pending hard linked file(s). */
+    hardLink_t li;             /*!< Current hard linked file(s). */
+    rpm_loff_t * archiveSize;  /*!< Pointer to archive size. */
+    rpm_loff_t archivePos;     /*!< Current archive position. */
+    char ** failedFile;                /*!< First file name that failed. */
+    const char * subdir;       /*!< Current file sub-directory. */
+    const char * osuffix;      /*!< Old, preserved, file suffix. */
+    const char * nsuffix;      /*!< New, created, file suffix. */
+    const char * suffix;       /*!< Current file suffix. */
     char sufbuf[64];   /* XXX eliminate */
-/*@only@*/ short * dnlx;               /*!< Last dirpath verified indexes. */
-/*@only@*/ char * ldn;                 /*!< Last dirpath verified. */
-    int ldnlen;                                /*!< Last dirpath current length. */
-    int ldnalloc;                      /*!< Last dirpath allocated length. */
-    int postpone;                      /*!< Skip remaining stages? */
-    int diskchecked;                   /*!< Has stat(2) been performed? */
-    int exists;                                /*!< Does current file exist on disk? */
-    int mkdirsdone;                    /*!< Have "orphan" dirs been created? */
-    int astriplen;                     /*!< Length of buildroot prefix. */
-    int rc;                            /*!< External file stage return code. */
-    int commit;                                /*!< Commit synchronously? */
-    cpioMapFlags mapFlags;             /*!< Bit(s) to control mapping. */
-/*@shared@*/ const char * archivePath; /*!< Path to store in cpio archive. */
-/*@shared@*/ const char * dirName;     /*!< File directory name. */
-/*@shared@*/ const char * baseName;    /*!< File base name. */
-/*@shared@*/ const char * fmd5sum;     /*!< File MD5 sum (NULL disables). */
-    unsigned fflags;                   /*!< File flags. */
-    fileAction action;                 /*!< File disposition. */
-    fileStage goal;                    /*!< Package state machine goal. */
-    fileStage stage;                   /*!< External file stage. */
-    struct stat sb;                    /*!< Current file stat(2) info. */
-    struct stat osb;                   /*!< Original file stat(2) info. */
+    short * dnlx;              /*!< Last dirpath verified indexes. */
+    char * ldn;                        /*!< Last dirpath verified. */
+    int ldnlen;                        /*!< Last dirpath current length. */
+    int ldnalloc;              /*!< Last dirpath allocated length. */
+    int postpone;              /*!< Skip remaining stages? */
+    int diskchecked;           /*!< Has stat(2) been performed? */
+    int exists;                        /*!< Does current file exist on disk? */
+    int mkdirsdone;            /*!< Have "orphan" dirs been created? */
+    int rc;                    /*!< External file stage return code. */
+    int commit;                        /*!< Commit synchronously? */
+    cpioMapFlags mapFlags;     /*!< Bit(s) to control mapping. */
+    const char * dirName;      /*!< File directory name. */
+    const char * baseName;     /*!< File base name. */
+    const unsigned char * digest;      /*!< Binary digest (NULL disables). */
+    security_context_t fcontext;/*!< File security context (NULL disables). */
+    cap_t fcaps;               /*!< File capabilities */
+    pgpHashAlgo digestalgo;    /*!< File digest algorithm */
+    
+    unsigned fflags;           /*!< File flags. */
+    rpmFileAction action;      /*!< File disposition. */
+    fileStage goal;            /*!< Package state machine goal. */
+    fileStage stage;           /*!< External file stage. */
+    fileStage nstage;          /*!< Next file stage. */
+    struct stat sb;            /*!< Current file stat(2) info. */
+    struct stat osb;           /*!< Original file stat(2) info. */
 };
 
 #ifdef __cplusplus
@@ -166,87 +171,55 @@ extern "C" {
 #endif
 
 /**
- * Return formatted string representation of file stages.
- * @param a            file stage
- * @return             formatted string
- */
-/*@observer@*/ const char *const fileStageString(fileStage a);
-
-/**
  * Create file state machine instance.
- * @return             file state machine data
+ * @param mapflags     CPIO map flags to use
+ * @return             file state machine
  */
-/*@only@*/ /*@null@*/ FSM_t newFSM(void);
+RPM_GNUC_INTERNAL
+FSM_t newFSM(cpioMapFlags mapflags);
 
 /**
  * Destroy file state machine instance.
- * @param fsm          file state machine data
+ * @param fsm          file state machine
  * @return             always NULL
  */
-/*@null@*/ FSM_t freeFSM(/*@only@*/ /*@null@*/ FSM_t fsm);
+RPM_GNUC_INTERNAL
+FSM_t freeFSM(FSM_t fsm);
 
 /**
  * Load external data into file state machine.
- * @param fsm          file state machine data
+ * @param fsm          file state machine
  * @param goal
  * @param ts           transaction set
  * @param fi           transaction element file info
- * @param archiveSize  pointer to archive size
- * @param failedFile   pointer to first file name that failed.
+ * @param cfd
+ * @retval archiveSize pointer to archive size
+ * @retval failedFile  pointer to first file name that failed (malloced)
  * @return             0 on success
  */
 int fsmSetup(FSM_t fsm, fileStage goal,
-       /*@kept@*/ const rpmTransactionSet ts,
-       /*@kept@*/ const TFI_t fi,
-       FD_t cfd,
-       /*@out@*/ unsigned int * archiveSize,
-       /*@out@*/ const char ** failedFile)
-               /*@modifies fsm, *archiveSize, *failedFile  @*/;
+               rpmts ts,
+               rpmte te,
+               rpmfi fi,
+               FD_t cfd,
+               rpm_loff_t * archiveSize,
+               char ** failedFile);
 
 /**
  * Clean file state machine.
- * @param fsm          file state machine data
+ * @param fsm          file state machine
  * @return             0 on success
  */
-int fsmTeardown(FSM_t fsm)
-               /*@modifies fsm @*/;
-
-/**
- * Retrieve transaction set from file state machine iterator.
- * @param fsm          file state machine data
- * @return             transaction set
- */
-/*@kept@*/ rpmTransactionSet fsmGetTs(const FSM_t fsm) /*@*/;
-
-/**
- * Retrieve transaction element file info from file state machine iterator.
- * @param fsm          file state machine data
- * @return             transaction element file info
- */
-/*@kept@*/ TFI_t fsmGetFi(const FSM_t fsm)     /*@*/;
-
-/**
- * Map next file path and action.
- * @param fsm          file state machine data
- */
-int fsmMapPath(FSM_t fsm)
-               /*@modifies fsm @*/;
-
-/**
- * Map file stat(2) info.
- * @param fsm          file state machine data
- */
-int fsmMapAttrs(FSM_t fsm)
-               /*@modifies fsm @*/;
+int fsmTeardown(FSM_t fsm);
 
 /**
  * File state machine driver.
- * @param fsm          file state machine data
- * @param stage                next stage
+ * @param fsm          file state machine
+ * @param nstage               next stage
  * @return             0 on success
  */
-int fsmStage(FSM_t fsm, fileStage stage)
-               /*@modifies fsm @*/;
+RPM_GNUC_INTERNAL
+int fsmNext(FSM_t fsm, fileStage nstage);
 
 #ifdef __cplusplus
 }