1 /*- 2 * Copyright (c) 2011-2012 Baptiste Daroussin <bapt@FreeBSD.org> 3 * Copyright (c) 2013 Matthew Seaman <matthew@FreeBSD.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer 11 * in this position and unchanged. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #ifndef _PKGCLI_H 29 #define _PKGCLI_H 30 31 #include <search.h> 32 #include <stdbool.h> 33 #include <stdint.h> 34 #include <string.h> 35 #include <xstring.h> 36 #include <bsd_compat.h> 37 38 #define pkg_warnx(fmt, ...) pkg_fprintf(stderr, "%S: " fmt, getprogname(), __VA_ARGS__, -1) 39 40 extern bool quiet; 41 extern int nbactions; 42 extern int nbdone; 43 extern bool newpkgversion; 44 extern int nbtodl; 45 46 /* pkg add */ 47 int exec_add(int, char **); 48 void usage_add(void); 49 50 /* pkg alias */ 51 int exec_alias(int, char **); 52 void usage_alias(void); 53 54 /* pkg annotate */ 55 int exec_annotate(int, char **); 56 void usage_annotate(void); 57 58 /* pkg audit */ 59 int exec_audit(int, char **); 60 void usage_audit(void); 61 62 /* pkg autoremove */ 63 int exec_autoremove(int, char **); 64 void usage_autoremove(void); 65 66 /* pkg backup */ 67 int exec_backup(int, char **); 68 void usage_backup(void); 69 70 /* pkg check */ 71 int exec_check(int, char **); 72 void usage_check(void); 73 74 /* pkg clean */ 75 int exec_clean(int, char **); 76 void usage_clean(void); 77 78 /* pkg create */ 79 int exec_create(int, char **); 80 void usage_create(void); 81 82 /* pkg delete */ 83 void usage_delete(void); 84 int exec_delete(int, char **); 85 86 /* pkg info */ 87 88 int exec_info(int, char **); 89 void usage_info(void); 90 91 /* pkg install */ 92 int exec_install(int, char **); 93 void usage_install(void); 94 95 /* pkg plugins */ 96 int exec_plugins(int, char **); 97 void usage_plugins(void); 98 99 /* pkg lock */ 100 int exec_lock(int, char **); 101 int exec_unlock(int, char **); 102 void usage_lock(void); 103 104 /* pkg query */ 105 int exec_query(int, char **); 106 void usage_query(void); 107 108 /* pkg register */ 109 void usage_register(void); 110 int exec_register(int argc, char **argv); 111 112 /* pkg repo */ 113 int exec_repo(int, char **); 114 void usage_repo(void); 115 116 /* pkg rquery */ 117 int exec_rquery(int, char **); 118 void usage_rquery(void); 119 120 /* pkg set */ 121 int exec_set(int, char **); 122 void usage_set(void); 123 124 /* pkg search */ 125 int exec_search(int, char **); 126 void usage_search(void); 127 128 /* pkg shlib */ 129 int exec_shlib(int, char **); 130 void usage_shlib(void); 131 char *sanitize(char *, const char *, size_t); 132 133 /* pkg stats */ 134 #define STATS_LOCAL (1<<0) 135 #define STATS_REMOTE (1<<1) 136 137 int exec_stats(int, char **); 138 void usage_stats(void); 139 140 /* pkg triggers */ 141 int exec_triggers(int, char **); 142 void usage_triggers(void); 143 144 /* pkg update */ 145 int exec_update(int, char **); 146 void usage_update(void); 147 int pkgcli_update(bool, bool, const char *); 148 149 /* pkg updating */ 150 int exec_updating(int, char **); 151 void usage_updating(void); 152 153 /* pkg upgrade */ 154 int exec_upgrade(int, char **); 155 void usage_upgrade(void); 156 157 /* pkg fetch */ 158 int exec_fetch(int, char **); 159 void usage_fetch(void); 160 161 /* pkg shell */ 162 int exec_shell(int, char **); 163 void usage_shell(void); 164 165 /* pkg version */ 166 #define VERSION_SOURCE_INDEX (1U<<0) 167 #define VERSION_ORIGIN (1U<<1) 168 #define VERSION_QUIET (1U<<2) 169 #define VERSION_VERBOSE (1U<<3) 170 #define VERSION_STATUS (1U<<4) 171 #define VERSION_NOSTATUS (1U<<5) 172 #define VERSION_WITHORIGIN (1U<<7) 173 #define VERSION_TESTVERSION (1U<<8) 174 #define VERSION_TESTPATTERN (1U<<9) 175 #define VERSION_SOURCE_PORTS (1U<<10) 176 #define VERSION_SOURCE_REMOTE (1U<<11) 177 #define VERSION_INDEX_FILE_NAME (1U<<12) 178 #define VERSION_WITHNAME (1U<<13) 179 180 #define VERSION_SOURCES (VERSION_SOURCE_PORTS | \ 181 VERSION_SOURCE_INDEX | \ 182 VERSION_SOURCE_REMOTE) 183 184 int exec_version(int, char **); 185 void usage_version(void); 186 187 /* pkg which */ 188 int exec_which(int, char **); 189 void usage_which(void); 190 191 /* pkg ssh */ 192 int exec_ssh(int, char **); 193 void usage_ssh(void); 194 195 /* pkg config */ 196 int exec_config(int, char **); 197 void usage_config(void); 198 199 /* utils */ 200 201 /* These are the fields of the Full output, in order */ 202 #define INFO_NAME (1LL<<0) 203 #define INFO_VERSION (1LL<<1) 204 #define INFO_INSTALLED (1LL<<2) 205 #define INFO_ORIGIN (1LL<<3) 206 #define INFO_ARCH (1LL<<4) 207 #define INFO_PREFIX (1LL<<5) 208 #define INFO_REPOSITORY (1LL<<6) 209 #define INFO_CATEGORIES (1LL<<7) 210 #define INFO_LICENSES (1LL<<8) 211 #define INFO_MAINTAINER (1LL<<9) 212 #define INFO_WWW (1LL<<10) 213 #define INFO_COMMENT (1LL<<11) 214 #define INFO_OPTIONS (1LL<<12) 215 #define INFO_SHLIBS_REQUIRED (1LL<<13) 216 #define INFO_SHLIBS_PROVIDED (1LL<<14) 217 #define INFO_ANNOTATIONS (1LL<<15) 218 #define INFO_FLATSIZE (1LL<<16) 219 #define INFO_PKGSIZE (1LL<<17) 220 #define INFO_DESCR (1LL<<18) 221 #define INFO_PROVIDED (1LL<<19) 222 #define INFO_REQUIRED (1LL<<20) 223 224 /* Other fields not part of the Full output */ 225 #define INFO_MESSAGE (1LL<<21) 226 #define INFO_DEPS (1LL<<22) 227 #define INFO_RDEPS (1LL<<23) 228 #define INFO_FILES (1LL<<24) 229 #define INFO_DIRS (1LL<<25) 230 #define INFO_USERS (1LL<<26) 231 #define INFO_GROUPS (1LL<<27) 232 #define INFO_REPOURL (1LL<<28) 233 #define INFO_LOCKED (1LL<<29) 234 #define INFO_OPTION_DEFAULTS (1LL<<30) 235 #define INFO_OPTION_DESCRIPTIONS (1LL<<31) 236 237 #define INFO_LASTFIELD INFO_LOCKED 238 #define INFO_ALL (((INFO_LASTFIELD) << 1) - 1) 239 240 /* Identifying tags */ 241 #define INFO_TAG_NAME (1LL<<32) 242 #define INFO_TAG_ORIGIN (1LL<<33) 243 #define INFO_TAG_NAMEVER (1LL<<34) 244 245 /* Output YAML format */ 246 #define INFO_RAW (1LL<<35) 247 #define INFO_RAW_YAML (1LL<<36) 248 #define INFO_RAW_JSON (1LL<<37) 249 #define INFO_RAW_JSON_COMPACT (1LL<<38) 250 #define INFO_RAW_UCL (1LL<<39) 251 252 /* Everything in the 'full' package output */ 253 #define INFO_FULL (INFO_NAME|INFO_VERSION|INFO_INSTALLED|INFO_ORIGIN| \ 254 INFO_ARCH|INFO_PREFIX|INFO_REPOSITORY| \ 255 INFO_CATEGORIES|INFO_LICENSES|INFO_MAINTAINER| \ 256 INFO_WWW|INFO_COMMENT|INFO_OPTIONS| \ 257 INFO_SHLIBS_REQUIRED|INFO_SHLIBS_PROVIDED| \ 258 INFO_ANNOTATIONS|INFO_FLATSIZE|INFO_PKGSIZE| \ 259 INFO_DESCR|INFO_PROVIDED|INFO_REQUIRED) 260 261 /* Everything that can take more than one line to print */ 262 #define INFO_MULTILINE (INFO_OPTIONS|INFO_SHLIBS_REQUIRED| \ 263 INFO_SHLIBS_PROVIDED|INFO_ANNOTATIONS| \ 264 INFO_DESCR|INFO_MESSAGE|INFO_DEPS|INFO_RDEPS| \ 265 INFO_FILES|INFO_DIRS) 266 267 bool query_yesno(bool deft, const char *msg, ...); 268 int query_select(const char *msg, const char **opts, int ncnt, int deft); 269 bool query_tty_yesno(bool deft, const char *msg, ...); 270 int info_flags(uint64_t opt, bool remote); 271 void print_info(struct pkg * const pkg, uint64_t opt); 272 int print_jobs_summary(struct pkg_jobs *j, const char *msg, ...); 273 274 void job_status_begin(xstring *); 275 void job_status_end(xstring *); 276 277 int event_callback(void *data, struct pkg_event *ev); 278 int print_pkg(struct pkg *p, void *ctx); 279 void progressbar_start(const char *pmsg); 280 void progressbar_tick(int64_t current, int64_t total); 281 void progressbar_stop(void); 282 283 void drop_privileges(void); 284 285 extern xstring *messages; 286 287 288 /* pkg-query / pkg-rquery */ 289 struct query_flags { 290 const char flag; 291 const char *options; 292 const unsigned multiline; 293 const int dbflags; 294 }; 295 296 void print_query(struct pkg *pkg, char *qstr, char multiline); 297 int format_sql_condition(const char *str, xstring *sqlcond, 298 bool for_remote); 299 int analyse_query_string(char *qstr, struct query_flags *q_flags, 300 const unsigned int q_flags_len, int *flags, 301 char *multiline); 302 303 extern int default_yes; 304 extern int yes; 305 extern int dry_run; 306 extern bool auto_update; 307 extern int case_sensitive; 308 extern int force; 309 extern bool quiet; 310 extern bool newpkgversion; 311 void set_globals(void); 312 313 #endif 314