2001-07-15 04:34:14 +04:00
|
|
|
/* $NetBSD: lib.h,v 1.36 2001/07/15 00:34:15 hubertf Exp $ */
|
1997-06-05 16:59:18 +04:00
|
|
|
|
1997-10-16 04:31:32 +04:00
|
|
|
/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
|
1997-06-05 12:54:23 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FreeBSD install - a package for the installation and maintainance
|
|
|
|
* of non-core utilities.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* Jordan K. Hubbard
|
|
|
|
* 18 July 1993
|
|
|
|
*
|
|
|
|
* Include and define various things wanted by the library routines.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INST_LIB_LIB_H_
|
|
|
|
#define _INST_LIB_LIB_H_
|
|
|
|
|
1998-07-06 10:56:06 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/file.h>
|
1999-03-22 08:02:39 +03:00
|
|
|
#include <sys/queue.h>
|
1998-07-06 10:56:06 +04:00
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <dirent.h>
|
1997-06-05 12:54:23 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
/* Macros */
|
|
|
|
#define SUCCESS (0)
|
|
|
|
#define FAIL (-1)
|
|
|
|
|
|
|
|
#ifndef TRUE
|
|
|
|
#define TRUE (1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef FALSE
|
|
|
|
#define FALSE (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Usually "rm", but often "echo" during debugging! */
|
|
|
|
#define REMOVE_CMD "rm"
|
|
|
|
|
|
|
|
/* Usually "rm", but often "echo" during debugging! */
|
|
|
|
#define RMDIR_CMD "rmdir"
|
|
|
|
|
1999-08-24 04:48:37 +04:00
|
|
|
/* Define tar as a string, in case it's called gtar or something */
|
1999-03-09 14:10:39 +03:00
|
|
|
#ifndef TAR_CMD
|
|
|
|
#define TAR_CMD "tar"
|
|
|
|
#endif
|
|
|
|
|
1999-08-24 04:48:37 +04:00
|
|
|
/* Full path name of TAR_CMD */
|
1999-03-09 14:10:39 +03:00
|
|
|
#ifndef TAR_FULLPATHNAME
|
|
|
|
#define TAR_FULLPATHNAME "/usr/bin/tar"
|
|
|
|
#endif
|
|
|
|
|
1997-06-05 12:54:23 +04:00
|
|
|
/* Where we put logging information by default, else ${PKG_DBDIR} if set */
|
|
|
|
#define DEF_LOG_DIR "/var/db/pkg"
|
|
|
|
/* just in case we change the environment variable name */
|
|
|
|
#define PKG_DBDIR "PKG_DBDIR"
|
|
|
|
|
|
|
|
/* The names of our "special" files */
|
|
|
|
#define CONTENTS_FNAME "+CONTENTS"
|
|
|
|
#define COMMENT_FNAME "+COMMENT"
|
|
|
|
#define DESC_FNAME "+DESC"
|
|
|
|
#define INSTALL_FNAME "+INSTALL"
|
|
|
|
#define DEINSTALL_FNAME "+DEINSTALL"
|
|
|
|
#define REQUIRE_FNAME "+REQUIRE"
|
|
|
|
#define REQUIRED_BY_FNAME "+REQUIRED_BY"
|
|
|
|
#define DISPLAY_FNAME "+DISPLAY"
|
|
|
|
#define MTREE_FNAME "+MTREE_DIRS"
|
1998-10-13 21:08:28 +04:00
|
|
|
#define BUILD_VERSION_FNAME "+BUILD_VERSION"
|
1998-10-21 13:54:09 +04:00
|
|
|
#define BUILD_INFO_FNAME "+BUILD_INFO"
|
1999-11-29 22:48:44 +03:00
|
|
|
#define SIZE_PKG_FNAME "+SIZE_PKG"
|
|
|
|
#define SIZE_ALL_FNAME "+SIZE_ALL"
|
1997-06-05 12:54:23 +04:00
|
|
|
|
|
|
|
#define CMD_CHAR '@' /* prefix for extended PLIST cmd */
|
|
|
|
|
|
|
|
/* The name of the "prefix" environment variable given to scripts */
|
|
|
|
#define PKG_PREFIX_VNAME "PKG_PREFIX"
|
|
|
|
|
1999-03-22 08:02:39 +03:00
|
|
|
/* This should only happen on 1.3 and 1.3.1, not 1.3.2 and up */
|
1999-08-24 04:48:37 +04:00
|
|
|
#ifndef TAILQ_FIRST
|
1999-03-22 08:02:39 +03:00
|
|
|
#define TAILQ_FIRST(head) ((head)->tqh_first)
|
|
|
|
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1999-08-24 04:48:37 +04:00
|
|
|
/* Enumerated constants for plist entry types */
|
1998-10-09 22:27:31 +04:00
|
|
|
typedef enum pl_ent_t {
|
1998-10-09 13:35:39 +04:00
|
|
|
PLIST_SHOW_ALL = -1,
|
1999-09-09 05:31:44 +04:00
|
|
|
PLIST_FILE, /* 0 */
|
|
|
|
PLIST_CWD, /* 1 */
|
|
|
|
PLIST_CMD, /* 2 */
|
|
|
|
PLIST_CHMOD, /* 3 */
|
|
|
|
PLIST_CHOWN, /* 4 */
|
|
|
|
PLIST_CHGRP, /* 5 */
|
|
|
|
PLIST_COMMENT, /* 6 */
|
|
|
|
PLIST_IGNORE, /* 7 */
|
|
|
|
PLIST_NAME, /* 8 */
|
|
|
|
PLIST_UNEXEC, /* 9 */
|
1999-11-29 23:09:54 +03:00
|
|
|
PLIST_SRC, /* 10 */
|
|
|
|
PLIST_DISPLAY, /* 11 */
|
|
|
|
PLIST_PKGDEP, /* 12 */
|
|
|
|
PLIST_MTREE, /* 13 */
|
|
|
|
PLIST_DIR_RM, /* 14 */
|
|
|
|
PLIST_IGNORE_INST, /* 15 */
|
|
|
|
PLIST_OPTION, /* 16 */
|
|
|
|
PLIST_PKGCFL /* 17 */
|
1999-08-24 04:48:37 +04:00
|
|
|
} pl_ent_t;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
|
|
|
/* Types */
|
|
|
|
typedef unsigned int Boolean;
|
|
|
|
|
1999-08-24 04:48:37 +04:00
|
|
|
/* This structure describes a packing list entry */
|
1998-10-09 22:27:31 +04:00
|
|
|
typedef struct plist_t {
|
1999-08-24 04:48:37 +04:00
|
|
|
struct plist_t *prev; /* previous entry */
|
|
|
|
struct plist_t *next; /* next entry */
|
|
|
|
char *name; /* name of entry */
|
|
|
|
Boolean marked; /* whether entry has been marked */
|
|
|
|
pl_ent_t type; /* type of entry */
|
|
|
|
} plist_t;
|
|
|
|
|
|
|
|
/* This structure describes a package's complete packing list */
|
1998-10-09 22:27:31 +04:00
|
|
|
typedef struct package_t {
|
1999-08-24 04:48:37 +04:00
|
|
|
plist_t *head; /* head of list */
|
|
|
|
plist_t *tail; /* tail of list */
|
|
|
|
} package_t;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1998-10-12 16:03:24 +04:00
|
|
|
#define CHECKSUM_HEADER "MD5:"
|
|
|
|
|
1998-10-09 22:27:31 +04:00
|
|
|
enum {
|
1999-08-24 04:48:37 +04:00
|
|
|
ChecksumHeaderLen = 4, /* strlen(CHECKSUM_HEADER) */
|
1998-10-09 22:27:31 +04:00
|
|
|
ChecksumLen = 16,
|
|
|
|
LegibleChecksumLen = 33
|
1997-06-05 12:54:23 +04:00
|
|
|
};
|
|
|
|
|
1999-03-22 08:02:39 +03:00
|
|
|
/* List of packages */
|
|
|
|
typedef struct _lpkg_t {
|
1999-08-24 04:48:37 +04:00
|
|
|
TAILQ_ENTRY(_lpkg_t) lp_link;
|
|
|
|
char *lp_name;
|
|
|
|
} lpkg_t;
|
1999-03-22 08:02:39 +03:00
|
|
|
TAILQ_HEAD(_lpkg_head_t, _lpkg_t);
|
|
|
|
typedef struct _lpkg_head_t lpkg_head_t;
|
|
|
|
|
1999-08-24 04:48:37 +04:00
|
|
|
/* Type of function to be handed to findmatchingname; return value of this
|
1998-10-03 20:24:07 +04:00
|
|
|
* is currently ignored */
|
1999-08-24 04:48:37 +04:00
|
|
|
typedef int (*matchfn) (const char *found, char *data);
|
1998-10-03 20:24:07 +04:00
|
|
|
|
1999-08-24 04:48:37 +04:00
|
|
|
/* If URLlength()>0, then there is a ftp:// or http:// in the string,
|
1999-08-23 19:17:03 +04:00
|
|
|
* and this must be an URL. Hide this behind a more obvious name. */
|
|
|
|
#define IS_URL(str) (URLlength(str) > 0)
|
|
|
|
|
1997-06-05 12:54:23 +04:00
|
|
|
/* Prototypes */
|
|
|
|
/* Misc */
|
2000-10-12 00:23:46 +04:00
|
|
|
int vsystem(const char *,...)
|
|
|
|
__attribute__((__format__(__printf__, 1, 2)));
|
1999-08-24 04:48:37 +04:00
|
|
|
void cleanup(int);
|
|
|
|
char *make_playpen(char *, size_t, size_t);
|
|
|
|
char *where_playpen(void);
|
|
|
|
void leave_playpen(char *);
|
|
|
|
off_t min_free(char *);
|
|
|
|
void save_dirs(char **c, char **p);
|
|
|
|
void restore_dirs(char *c, char *p);
|
2001-03-05 19:53:12 +03:00
|
|
|
void show_version(void);
|
1997-06-05 12:54:23 +04:00
|
|
|
|
|
|
|
/* String */
|
1999-08-24 04:48:37 +04:00
|
|
|
char *get_dash_string(char **);
|
|
|
|
void str_lowercase(char *);
|
|
|
|
char *basename_of(char *);
|
|
|
|
char *dirname_of(const char *);
|
|
|
|
int pmatch(const char *, const char *);
|
2000-01-20 02:28:28 +03:00
|
|
|
int findmatchingname(const char *, const char *, matchfn, char *); /* doesn't really belong to "strings" */
|
|
|
|
int findbestmatchingname_fn(const char *pkg, char *data); /* neither */
|
1999-08-24 04:48:37 +04:00
|
|
|
char *findbestmatchingname(const char *, const char *); /* neither */
|
|
|
|
int ispkgpattern(const char *);
|
|
|
|
char *strnncpy(char *to, size_t tosize, char *from, size_t cc);
|
2001-07-15 04:34:14 +04:00
|
|
|
void strip_txz(char *buf, char *sfx, const char *fname);
|
1997-06-05 12:54:23 +04:00
|
|
|
|
|
|
|
/* File */
|
1999-08-24 04:48:37 +04:00
|
|
|
Boolean fexists(char *);
|
|
|
|
Boolean isdir(char *);
|
|
|
|
Boolean islinktodir(char *);
|
|
|
|
Boolean isemptydir(char *fname);
|
|
|
|
Boolean isemptyfile(char *fname);
|
|
|
|
Boolean isfile(char *);
|
|
|
|
Boolean isempty(char *);
|
|
|
|
int URLlength(char *);
|
|
|
|
char *fileGetURL(char *, char *);
|
|
|
|
char *fileURLFilename(char *, char *, int);
|
|
|
|
char *fileURLHost(char *, char *, int);
|
|
|
|
char *fileFindByPath(char *, char *);
|
|
|
|
char *fileGetContents(char *);
|
|
|
|
Boolean make_preserve_name(char *, size_t, char *, char *);
|
|
|
|
void write_file(char *, char *);
|
|
|
|
void copy_file(char *, char *, char *);
|
|
|
|
void move_file(char *, char *, char *);
|
|
|
|
int delete_hierarchy(char *, Boolean, Boolean);
|
|
|
|
int unpack(char *, char *);
|
|
|
|
void format_cmd(char *, size_t, char *, char *, char *);
|
1997-06-05 12:54:23 +04:00
|
|
|
|
2000-01-20 02:28:28 +03:00
|
|
|
/* ftpio.c: FTP handling */
|
|
|
|
int expandURL(char *expandedurl, const char *wildcardurl);
|
|
|
|
int unpackURL(const char *url, const char *dir);
|
2000-08-29 01:35:14 +04:00
|
|
|
int ftp_cmd(const char *cmd, const char *expectstr);
|
|
|
|
int ftp_start(char *base);
|
2000-01-20 02:28:28 +03:00
|
|
|
void ftp_stop(void);
|
|
|
|
|
1997-06-05 12:54:23 +04:00
|
|
|
/* Packing list */
|
1999-08-24 04:48:37 +04:00
|
|
|
plist_t *new_plist_entry(void);
|
|
|
|
plist_t *last_plist(package_t *);
|
|
|
|
plist_t *find_plist(package_t *, pl_ent_t);
|
|
|
|
char *find_plist_option(package_t *, char *name);
|
|
|
|
void plist_delete(package_t *, Boolean, pl_ent_t, char *);
|
|
|
|
void free_plist(package_t *);
|
|
|
|
void mark_plist(package_t *);
|
|
|
|
void csum_plist_entry(char *, plist_t *);
|
|
|
|
void add_plist(package_t *, pl_ent_t, char *);
|
|
|
|
void add_plist_top(package_t *, pl_ent_t, char *);
|
|
|
|
void delete_plist(package_t *pkg, Boolean all, pl_ent_t type, char *name);
|
2001-05-21 13:17:28 +04:00
|
|
|
void write_plist(package_t *, FILE *, char *);
|
1999-08-24 04:48:37 +04:00
|
|
|
void read_plist(package_t *, FILE *);
|
|
|
|
int plist_cmd(char *, char **);
|
|
|
|
int delete_package(Boolean, Boolean, package_t *);
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1999-01-19 20:01:56 +03:00
|
|
|
/* Package Database */
|
1999-08-24 04:48:37 +04:00
|
|
|
int pkgdb_open(int);
|
|
|
|
void pkgdb_close(void);
|
|
|
|
int pkgdb_store(const char *, const char *);
|
|
|
|
char *pkgdb_retrieve(const char *);
|
|
|
|
int pkgdb_remove(const char *);
|
|
|
|
char *pkgdb_iter(void);
|
|
|
|
char *_pkgdb_getPKGDB_FILE(void);
|
|
|
|
char *_pkgdb_getPKGDB_DIR(void);
|
1999-01-19 20:01:56 +03:00
|
|
|
|
1999-03-22 08:02:39 +03:00
|
|
|
/* List of packages functions */
|
1999-08-24 04:48:37 +04:00
|
|
|
lpkg_t *alloc_lpkg(const char *);
|
|
|
|
lpkg_t *find_on_queue(lpkg_head_t *, const char *);
|
|
|
|
void free_lpkg(lpkg_t *);
|
1999-03-22 08:02:39 +03:00
|
|
|
|
1997-06-05 12:54:23 +04:00
|
|
|
/* For all */
|
1999-08-24 04:48:37 +04:00
|
|
|
int pkg_perform(lpkg_head_t *);
|
1997-06-05 12:54:23 +04:00
|
|
|
|
|
|
|
/* Externs */
|
1999-08-24 04:48:37 +04:00
|
|
|
extern Boolean Verbose;
|
|
|
|
extern Boolean Fake;
|
|
|
|
extern Boolean Force;
|
2001-03-18 06:20:28 +03:00
|
|
|
extern int upgrade;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1999-08-24 04:48:37 +04:00
|
|
|
#endif /* _INST_LIB_LIB_H_ */
|