00001
00006 #include "system.h"
00007
00008 #include <rpmcli.h>
00009
00010 #include "debug.h"
00011
00012 #define POPT_SHOWVERSION -999
00013 #define POPT_SHOWRC -998
00014 #define POPT_QUERYTAGS -997
00015 #define POPT_PREDEFINE -996
00016 #ifdef NOTYET
00017 #define POPT_RCFILE -995
00018 #endif
00019
00020
00021 static int _debug = 0;
00022
00023
00024
00025 extern int _rpmds_nopromote;
00026
00027
00028 extern int _fps_debug;
00029
00030
00031 extern int _fsm_debug;
00032
00033
00034 extern int _fsm_threads;
00035
00036
00037 extern int _hdr_debug;
00038
00039
00040 extern int _print_pkts;
00041
00042
00043 extern int _psm_debug;
00044
00045
00046 extern int _psm_threads;
00047
00048
00049 extern int _rpmal_debug;
00050
00051
00052 extern int _rpmdb_debug;
00053
00054
00055 extern int _rpmds_debug;
00056
00057
00058
00059 int _rpmfc_debug;
00060
00061
00062 extern int _rpmfi_debug;
00063
00064
00065 extern int _rpmps_debug;
00066
00067
00068 extern int _rpmsq_debug;
00069
00070
00071 extern int _rpmte_debug;
00072
00073
00074 extern int _rpmts_debug;
00075
00076
00077 extern int _rpmts_stats;
00078
00079
00080 extern int noLibio;
00081
00082
00083
00084 const char * rpmcliPipeOutput = NULL;
00085
00086
00087 const char * rpmcliRcfile = NULL;
00088
00089
00090 const char * rpmcliRootDir = "/";
00091
00092
00093 rpmQueryFlags rpmcliQueryFlags;
00094
00095
00096
00097 extern int _ftp_debug;
00098
00099 extern int noLibio;
00100
00101 extern int _rpmio_debug;
00102
00103
00104
00105 static int rpmcliInitialized = -1;
00106
00110 static void printVersion(FILE * fp)
00111
00112
00113 {
00114 fprintf(fp, _("RPM version %s\n"), rpmEVR);
00115 }
00116
00121
00122 void rpmcliConfigured(void)
00123
00124
00125
00126
00127 {
00128
00129 if (rpmcliInitialized < 0)
00130 rpmcliInitialized = rpmReadConfigFiles(rpmcliRcfile, NULL);
00131 if (rpmcliInitialized)
00132 exit(EXIT_FAILURE);
00133 }
00134
00137
00138 static void rpmcliAllArgCallback( poptContext con,
00139 enum poptCallbackReason reason,
00140 const struct poptOption * opt, const char * arg,
00141 const void * data)
00142
00143
00144
00145
00146 {
00147
00148
00149
00150 if (opt->arg == NULL)
00151 switch (opt->val) {
00152 case 'q':
00153 rpmSetVerbosity(RPMMESS_QUIET);
00154 break;
00155 case 'v':
00156 rpmIncreaseVerbosity();
00157 break;
00158 case POPT_PREDEFINE:
00159 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
00160 break;
00161 case 'D':
00162
00163 if (rpmcliInitialized < 0)
00164 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
00165 rpmcliConfigured();
00166
00167 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
00168 (void) rpmDefineMacro(rpmCLIMacroContext, arg, RMIL_CMDLINE);
00169
00170 break;
00171 case 'E':
00172 rpmcliConfigured();
00173 { const char *val = rpmExpand(arg, NULL);
00174 fprintf(stdout, "%s\n", val);
00175 val = _free(val);
00176 }
00177 break;
00178 case POPT_SHOWVERSION:
00179 printVersion(stdout);
00180 exit(EXIT_SUCCESS);
00181 break;
00182 case POPT_SHOWRC:
00183 rpmcliConfigured();
00184 (void) rpmShowRC(stdout);
00185 exit(EXIT_SUCCESS);
00186 break;
00187 case POPT_QUERYTAGS:
00188 rpmDisplayQueryTags(stdout);
00189 exit(EXIT_SUCCESS);
00190 break;
00191 #if defined(POPT_RCFILE)
00192 case POPT_RCFILE:
00193 break;
00194 #endif
00195 case RPMCLI_POPT_NODIGEST:
00196 rpmcliQueryFlags |= VERIFY_DIGEST;
00197 break;
00198
00199 case RPMCLI_POPT_NOSIGNATURE:
00200 rpmcliQueryFlags |= VERIFY_SIGNATURE;
00201 break;
00202
00203 case RPMCLI_POPT_NOHDRCHK:
00204 rpmcliQueryFlags |= VERIFY_HDRCHK;
00205 break;
00206 }
00207
00208 }
00209
00210
00211
00212 struct poptOption rpmcliAllPoptTable[] = {
00213
00214 { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
00215 rpmcliAllArgCallback, 0, NULL, NULL },
00216
00217
00218 { "debug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_debug, -1,
00219 NULL, NULL },
00220
00221 { "predefine", 'D', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_PREDEFINE,
00222 N_("predefine MACRO with value EXPR"),
00223 N_("'MACRO EXPR'") },
00224 { "define", 'D', POPT_ARG_STRING, 0, 'D',
00225 N_("define MACRO with value EXPR"),
00226 N_("'MACRO EXPR'") },
00227 { "eval", 'E', POPT_ARG_STRING, 0, 'E',
00228 N_("print macro expansion of EXPR"),
00229 N_("'EXPR'") },
00230 { "macros", '\0', POPT_ARG_STRING, ¯ofiles, 0,
00231 N_("read <FILE:...> instead of default file(s)"),
00232 N_("<FILE:...>") },
00233
00234 { "nodigest", '\0', 0, 0, RPMCLI_POPT_NODIGEST,
00235 N_("don't verify package digest(s)"), NULL },
00236 { "nohdrchk", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_NOHDRCHK,
00237 N_("don't verify database header(s) when retrieved"), NULL },
00238 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
00239 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
00240 N_("disable use of libio(3) API"), NULL},
00241 #endif
00242 { "nosignature", '\0', 0, 0, RPMCLI_POPT_NOSIGNATURE,
00243 N_("don't verify package signature(s)"), NULL },
00244
00245 { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &rpmcliPipeOutput, 0,
00246 N_("send stdout to CMD"),
00247 N_("CMD") },
00248 #if !defined(POPT_RCFILE)
00249 { "rcfile", '\0', POPT_ARG_STRING, &rpmcliRcfile, 0,
00250 N_("read <FILE:...> instead of default file(s)"),
00251 N_("<FILE:...>") },
00252 #else
00253 { "rcfile", '\0', 0, NULL, POPT_RCFILE,
00254 N_("read <FILE:...> instead of default file(s)"),
00255 N_("<FILE:...>") },
00256 #endif
00257 { "root", 'r', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &rpmcliRootDir, 0,
00258 N_("use ROOT as top level directory"),
00259 N_("ROOT") },
00260
00261 { "querytags", '\0', 0, 0, POPT_QUERYTAGS,
00262 N_("display known query tags"), NULL },
00263 { "showrc", '\0', 0, NULL, POPT_SHOWRC,
00264 N_("display final rpmrc and macro configuration"), NULL },
00265 { "quiet", '\0', 0, NULL, 'q',
00266 N_("provide less detailed output"), NULL},
00267 { "verbose", 'v', 0, NULL, 'v',
00268 N_("provide more detailed output"), NULL},
00269 { "version", '\0', 0, NULL, POPT_SHOWVERSION,
00270 N_("print the version of rpm being used"), NULL },
00271
00272 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
00273 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
00274 N_("disable use of libio(3) API"), NULL},
00275 #endif
00276
00277 { "promoteepoch", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_nopromote, 0,
00278 NULL, NULL},
00279
00280 { "fpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fps_debug, -1,
00281 NULL, NULL},
00282 { "fsmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_debug, -1,
00283 N_("debug payload file state machine"), NULL},
00284 { "fsmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_threads, -1,
00285 N_("use threads for file state machine"), NULL},
00286 { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
00287 N_("debug protocol data stream"), NULL},
00288 { "hdrdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_hdr_debug, -1,
00289 NULL, NULL},
00290 #ifdef DYING
00291 { "poptdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_popt_debug, -1,
00292 N_("debug option/argument processing"), NULL},
00293 #endif
00294 { "prtpkts", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_print_pkts, -1,
00295 NULL, NULL},
00296 { "psmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_debug, -1,
00297 N_("debug package state machine"), NULL},
00298 { "psmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_threads, -1,
00299 N_("use threads for package state machine"), NULL},
00300 { "rpmaldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmal_debug, -1,
00301 NULL, NULL},
00302 { "rpmdbdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmdb_debug, -1,
00303 NULL, NULL},
00304 { "rpmdsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_debug, -1,
00305 NULL, NULL},
00306 { "rpmfcdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfc_debug, -1,
00307 NULL, NULL},
00308 { "rpmfidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfi_debug, -1,
00309 NULL, NULL},
00310 { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
00311 N_("debug rpmio I/O"), NULL},
00312 { "rpmpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmps_debug, -1,
00313 NULL, NULL},
00314 { "rpmsqdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsq_debug, -1,
00315 NULL, NULL},
00316 { "rpmtedebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmte_debug, -1,
00317 NULL, NULL},
00318 { "rpmtsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_debug, -1,
00319 NULL, NULL},
00320 { "stats", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_stats, -1,
00321 NULL, NULL},
00322 { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
00323 N_("debug URL cache handling"), NULL},
00324
00325 POPT_TABLEEND
00326 };
00327
00328
00329 poptContext
00330 rpmcliFini(poptContext optCon)
00331 {
00332 optCon = poptFreeContext(optCon);
00333
00334 #if HAVE_MCHECK_H && HAVE_MTRACE
00335
00336 muntrace();
00337
00338 #endif
00339
00340 return NULL;
00341 }
00342
00343
00344 poptContext
00345 rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
00346 {
00347 const char * optArg;
00348 poptContext optCon;
00349 int rc;
00350
00351 #if HAVE_MCHECK_H && HAVE_MTRACE
00352
00353 mtrace();
00354
00355 #endif
00356
00357 setprogname(argv[0]);
00358
00359
00360 if (__progname == NULL) {
00361 if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
00362 else __progname = argv[0];
00363 }
00364
00365
00366 #if defined(ENABLE_NLS) && !defined(__LCLINT__)
00367 (void) setlocale(LC_ALL, "" );
00368 (void) bindtextdomain(PACKAGE, LOCALEDIR);
00369 (void) textdomain(PACKAGE);
00370 #endif
00371
00372 rpmSetVerbosity(RPMMESS_NORMAL);
00373
00374 if (optionsTable == NULL) {
00375
00376 rpmcliConfigured();
00377 return NULL;
00378 }
00379
00380
00381 optCon = poptGetContext(__progname, argc, (const char **)argv, optionsTable, 0);
00382
00383 (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
00384 (void) poptReadDefaultConfig(optCon, 1);
00385 poptSetExecPath(optCon, RPMCONFIGDIR, 1);
00386
00387
00388 while ((rc = poptGetNextOpt(optCon)) > 0) {
00389 optArg = poptGetOptArg(optCon);
00390 switch (rc) {
00391 default:
00392
00393 fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
00394 __progname, rc);
00395
00396 exit(EXIT_FAILURE);
00397
00398 break;
00399 }
00400 }
00401
00402 if (rc < -1) {
00403
00404 fprintf(stderr, "%s: %s: %s\n", __progname,
00405 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
00406 poptStrerror(rc));
00407
00408 exit(EXIT_FAILURE);
00409 }
00410
00411
00412 rpmcliConfigured();
00413
00414 if (_debug) {
00415 rpmIncreaseVerbosity();
00416 rpmIncreaseVerbosity();
00417 }
00418
00419 return optCon;
00420 }
00421